diff options
author | Roger Dingledine <arma@torproject.org> | 2003-12-17 09:42:28 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-12-17 09:42:28 +0000 |
commit | 5ecd6b6bada6a7cd9fe7d5f82ae72bdc9577c97d (patch) | |
tree | a36d4e0a0a39a522ed682646924c0be0e775439b /src/or/buffers.c | |
parent | 4a1e05de51859e258093ff82d93609921d0a4dad (diff) | |
download | tor-5ecd6b6bada6a7cd9fe7d5f82ae72bdc9577c97d.tar.gz tor-5ecd6b6bada6a7cd9fe7d5f82ae72bdc9577c97d.zip |
make fetch_from_buf_http malloc its strings rather
than use fixed-size strings
reorganize directory_handle_command so it'll be easier to do more with
our directory servers
svn:r950
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 016e10a5db..a1ad82b50c 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -321,7 +321,7 @@ int fetch_from_buf(char *string, int string_len, buf_t *buf) { * If a) the headers include a Content-Length field and all bytes in * the body are present, or b) there's no Content-Length field and * all headers are present, then: - * copy headers and body into the supplied args (and null terminate + * strdup headers and body into the supplied args (and null terminate * them), remove them from buf, and return 1. * (If headers or body is NULL, discard that part of the buf.) * If a headers or body doesn't fit in the arg, return -1. @@ -329,8 +329,8 @@ int fetch_from_buf(char *string, int string_len, buf_t *buf) { * Else, change nothing and return 0. */ int fetch_from_buf_http(buf_t *buf, - char *headers_out, int max_headerlen, - char *body_out, int max_bodylen) { + char **headers_out, int max_headerlen, + char **body_out, int max_bodylen) { char *headers, *body; int i; int headerlen, bodylen, contentlen; @@ -346,7 +346,7 @@ int fetch_from_buf_http(buf_t *buf, body = buf->mem+i; headerlen = body-headers; /* includes the CRLFCRLF */ bodylen = buf->datalen - headerlen; - log_fn(LOG_DEBUG,"headerlen %d, bodylen %d.",headerlen,bodylen); + log_fn(LOG_DEBUG,"headerlen %d, bodylen %d.", headerlen, bodylen); if(headers_out && max_headerlen <= headerlen) { log_fn(LOG_WARN,"headerlen %d larger than %d. Failing.", headerlen, max_headerlen-1); @@ -373,12 +373,14 @@ int fetch_from_buf_http(buf_t *buf, } /* all happy. copy into the appropriate places, and return 1 */ if(headers_out) { - memcpy(headers_out,buf->mem,headerlen); - headers_out[headerlen] = 0; /* null terminate it */ + *headers_out = tor_malloc(headerlen+1); + memcpy(*headers_out,buf->mem,headerlen); + *headers_out[headerlen] = 0; /* null terminate it */ } if(body_out) { - memcpy(body_out,buf->mem+headerlen,bodylen); - body_out[bodylen] = 0; /* null terminate it */ + *body_out = tor_malloc(bodylen+1); + memcpy(*body_out,buf->mem+headerlen,bodylen); + *body_out[bodylen] = 0; /* null terminate it */ } buf_remove_from_front(buf, headerlen+bodylen); return 1; |