diff options
author | Roger Dingledine <arma@torproject.org> | 2002-09-28 05:53:00 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2002-09-28 05:53:00 +0000 |
commit | 827c7444f8c6759388e8b137d98c740dc3d5eae7 (patch) | |
tree | 5746d19f31b69b76827c8fb8dbf4cdb368fffc49 /src/or/buffers.c | |
parent | e0f77fc36b9df2824c83435f131e637afe103a22 (diff) | |
download | tor-827c7444f8c6759388e8b137d98c740dc3d5eae7.tar.gz tor-827c7444f8c6759388e8b137d98c740dc3d5eae7.zip |
more robust http(ish) handling
svn:r123
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 30b476e200..5b4053c90d 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -129,9 +129,9 @@ int write_to_buf(char *string, int string_len, } int fetch_from_buf(char *string, int string_len, - char **buf, int *buflen, int *buf_datalen) { + char **buf, int *buflen, int *buf_datalen) { - /* if there is string_len bytes in buf, write them onto string, + /* if there are string_len bytes in buf, write them onto string, * then memmove buf back (that is, remove them from buf) */ assert(string && buf && *buf && buflen && buf_datalen); @@ -147,3 +147,25 @@ int fetch_from_buf(char *string, int string_len, return *buf_datalen; } +int find_on_inbuf(char *string, int string_len, + char *buf, int buf_datalen) { + /* find first instance of needle 'string' on haystack 'buf'. return how + * many bytes from the beginning of buf to the end of string. + * If it's not there, return -1. + */ + + char *location; + char *last_possible = buf + buf_datalen - string_len; + + assert(string && string_len > 0 && buf); + + if(buf_datalen < string_len) + return -1; + + for(location = buf; location <= last_possible; location++) + if((*location == *string) && !memcmp(location+1, string+1, string_len-1)) + return location-buf+string_len; + + return -1; +} + |