Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Add htp__evbuffer_add_iovec_ helper for libevent < 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Jan 22, 2019
1 parent cce07b8 commit 8991567
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,34 @@ htp__request_parse_fini_(htparser * p)
return 0;
} /* htp__request_parse_fini_ */

static size_t
htp__evbuffer_add_iovec_(struct evbuffer * buf, struct evbuffer_iovec * vec, int n_vec)
{
#if LIBEVENT_VERSION_NUMBER < 0x02010000
int n;
size_t res;
size_t to_alloc;

res = to_alloc = 0;

for (n = 0; n < n_vec; n++) {
to_alloc += vec[n].iov_len;
}

evbuffer_expand(buf, to_alloc);

for (n = 0; n < n_vec; n++) {
evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len);

res += vec[n].iov_len;
}

return res;
#else
return evbuffer_add_iovec(buf, vec, n_vec);
#endif
}

static int
htp__create_headers_(evhtp_header_t * header, void * arg)
{
Expand All @@ -2031,7 +2059,7 @@ htp__create_headers_(evhtp_header_t * header, void * arg)
iov[3].iov_base = "\r\n";
iov[3].iov_len = 2;

evbuffer_add_iovec(buf, iov, 4);
htp__evbuffer_add_iovec_(buf, iov, 4);

return 0;
}
Expand Down Expand Up @@ -2180,7 +2208,7 @@ htp__create_reply_(evhtp_request_t * request, evhtp_res code)
iov[8].iov_base = "\r\n";
iov[8].iov_len = 2;

evbuffer_add_iovec(buf, iov, 9);
htp__evbuffer_add_iovec_(buf, iov, 9);
}

evhtp_headers_for_each(request->headers_out, htp__create_headers_, buf);
Expand Down

0 comments on commit 8991567

Please sign in to comment.