diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-11-14 00:06:31 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-11-14 00:06:31 +0000 |
commit | 1913cb915ee3f91f18dfcefeb8202380ed4cfcbc (patch) | |
tree | bde729b0291e4af1621a9689e86b3ae14af627a0 /src/or/buffers.c | |
parent | fa6fbbc150a0f8e750c979af3c0d2d1278b856dd (diff) | |
download | tor-1913cb915ee3f91f18dfcefeb8202380ed4cfcbc.tar.gz tor-1913cb915ee3f91f18dfcefeb8202380ed4cfcbc.zip |
r9308@totoro: nickm | 2006-11-13 18:41:23 -0500
Add support for (Free?)BSD's natd, which was an old way to let you
have your firewall automatically redirect traffic. (Original patch
from Zajcev Evgeny, updated for 0.1.2.x by tup.)
svn:r8946
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 421ab43337..b85b79cec8 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -1304,6 +1304,34 @@ fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len) return 1; } +/** Try to read a single LF-terminated line from <b>buf</b>, and write it, + * NUL-terminated, into the *<b>data_len</b> byte buffer at <b>data_out</b>. + * Set *<b>data_len</b> to the number of bytes in the line, not counting the + * terminating NUL. Return 1 if we read a whole line, return 0 if we don't + * have a whole line yet, and return -1 if the line length exceeds + *<b>data_len</b>. + */ +int +fetch_from_buf_line_lf(buf_t *buf, char *data_out, size_t *data_len) +{ + char *cp; + size_t sz; + + size_t remaining = buf->datalen - _buf_offset(buf,buf->cur); + cp = find_char_on_buf(buf, buf->cur, remaining, '\n'); + if (!cp) + return 0; + sz = _buf_offset(buf, cp); + if (sz+2 > *data_len) { + *data_len = sz+2; + return -1; + } + fetch_from_buf(data_out, sz+1, buf); + data_out[sz+1] = '\0'; + *data_len = sz+1; + return 1; +} + /** Compress on uncompress the <b>data_len</b> bytes in <b>data</b> using the * zlib state <b>state</b>, appending the result to <b>buf</b>. If * <b>done</b> is true, flush the data in the state and finish the |