diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-11-03 01:32:26 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-11-03 01:32:26 +0000 |
commit | 347d3f9d629df74b3e78ac040fab30627622fda4 (patch) | |
tree | 30f32823781127b19e9ea6a9f45a5d35a890a7fa /src/or/buffers.c | |
parent | d63d420930817470fd36b59c70b3194af20417dc (diff) | |
download | tor-347d3f9d629df74b3e78ac040fab30627622fda4.tar tor-347d3f9d629df74b3e78ac040fab30627622fda4.tar.gz |
Start implementing control interface.
svn:r2652
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index a4b429f2e..35f1ed567 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -636,6 +636,38 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { } } +/* DOCDOC: 1 if complete, 0 if pending, -1 on error. */ +int fetch_from_buf_control(buf_t *buf, uint16_t *len_out, uint16_t *type_out, + char **body_out) +{ + uint16_t len; + + tor_assert(buf); + tor_assert(len_out); + tor_assert(type_out); + tor_assert(body_out); + + if (buf->datalen < 4) + return 0; + + len = ntohs(get_uint16(buf->mem)); + if (buf->datalen < 4 + (unsigned)len) + return 0; + + *len_out = len; + *type_out = ntohs(get_uint16(buf->mem+2)); + if (len) { + *body_out = tor_malloc(len); + memcpy(*body_out, buf->mem+4, len); + } else { + *body_out = NULL; + } + + buf_remove_from_front(buf, 4+len); + + return 1; +} + /** Log an error and exit if <b>buf</b> is corrupted. */ void assert_buf_ok(buf_t *buf) |