Add a 0-pullup version of fetch_from_evbuffer_socks

This commit is contained in:
Nick Mathewson 2009-08-11 17:44:43 -04:00
parent f6899f3a74
commit 44375d4eb8

View File

@ -1498,7 +1498,7 @@ int
fetch_from_evbuffer_socks(struct evbuffer *buf, socks_request_t *req, fetch_from_evbuffer_socks(struct evbuffer *buf, socks_request_t *req,
int log_sockstype, int safe_socks) int log_sockstype, int safe_socks)
{ {
const char *data; char *data;
ssize_t n_drain; ssize_t n_drain;
size_t datalen, buflen, want_length; size_t datalen, buflen, want_length;
int res; int res;
@ -1507,13 +1507,15 @@ fetch_from_evbuffer_socks(struct evbuffer *buf, socks_request_t *req,
if (buflen < 2) if (buflen < 2)
return 0; return 0;
{
struct evbuffer_iovec v;
int i;
want_length = evbuffer_get_contiguous_space(buf); want_length = evbuffer_get_contiguous_space(buf);
do {
n_drain = 0; n_drain = 0;
data = (const char*) evbuffer_pullup(buf, want_length); i = evbuffer_peek(buf, want_length, NULL, &v, 1);
datalen = evbuffer_get_contiguous_space(buf); tor_assert(i == i);
want_length = 0; data = v.iov_base;
datalen = v.iov_len;
res = parse_socks(data, datalen, req, log_sockstype, res = parse_socks(data, datalen, req, log_sockstype,
safe_socks, &n_drain, &want_length); safe_socks, &n_drain, &want_length);
@ -1523,11 +1525,33 @@ fetch_from_evbuffer_socks(struct evbuffer *buf, socks_request_t *req,
else if (n_drain > 0) else if (n_drain > 0)
evbuffer_drain(buf, n_drain); evbuffer_drain(buf, n_drain);
datalen = evbuffer_get_contiguous_space(buf); if (res)
buflen = evbuffer_get_length(buf); return res;
}
} while (res == 0 && while (evbuffer_get_length(buf) > datalen) {
want_length > datalen && buflen > datalen); int free_data = 0;
n_drain = 0;
data = NULL;
datalen = inspect_evbuffer(buf, &data, want_length, &free_data, NULL);
res = parse_socks(data, datalen, req, log_sockstype,
safe_socks, &n_drain, &want_length);
if (free_data)
tor_free(data);
if (n_drain < 0)
evbuffer_drain(buf, evbuffer_get_length(buf));
else if (n_drain > 0)
evbuffer_drain(buf, n_drain);
if (res)
return res;
if (want_length <= datalen)
break;
}
return res; return res;
} }