2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 06:55:30 +00:00

DoH: replace a custom buffer code for POST data with isc_buffer_t

This commit replaces the custom buffer code in client-side DoH code
intended to keep track of POST data, with isc_buffer_t.
This commit is contained in:
Artem Boldariev
2021-07-29 11:43:29 +03:00
parent 5b52a7e37e
commit a32faa20b4

View File

@@ -104,8 +104,7 @@ typedef struct http_cstream {
int32_t stream_id; int32_t stream_id;
bool post; /* POST or GET */ bool post; /* POST or GET */
isc_region_t postdata; isc_buffer_t *postdata;
size_t postdata_pos;
char *GET_path; char *GET_path;
size_t GET_path_len; size_t GET_path_len;
@@ -448,10 +447,12 @@ put_http_cstream(isc_mem_t *mctx, http_cstream_t *stream) {
stream->GET_path = NULL; stream->GET_path = NULL;
stream->GET_path_len = 0; stream->GET_path_len = 0;
} }
if (stream->postdata.base != NULL) {
isc_mem_put(mctx, stream->postdata.base, if (stream->postdata != NULL) {
stream->postdata.length); INSIST(stream->post);
isc_buffer_free(&stream->postdata);
} }
if (stream == stream->httpsock->h2.connect.cstream) { if (stream == stream->httpsock->h2.connect.cstream) {
stream->httpsock->h2.connect.cstream = NULL; stream->httpsock->h2.connect.cstream = NULL;
} }
@@ -863,17 +864,19 @@ client_read_callback(nghttp2_session *ngsession, int32_t stream_id,
} }
if (cstream->post) { if (cstream->post) {
size_t len = cstream->postdata.length - cstream->postdata_pos; size_t len = isc_buffer_remaininglength(cstream->postdata);
if (len > length) { if (len > length) {
len = length; len = length;
} }
memmove(buf, cstream->postdata.base + cstream->postdata_pos, if (len > 0) {
len); memmove(buf, isc_buffer_current(cstream->postdata),
cstream->postdata_pos += len; len);
isc_buffer_forward(cstream->postdata, len);
}
if (cstream->postdata_pos == cstream->postdata.length) { if (isc_buffer_remaininglength(cstream->postdata) == 0) {
*data_flags |= NGHTTP2_DATA_FLAG_EOF; *data_flags |= NGHTTP2_DATA_FLAG_EOF;
} }
@@ -898,7 +901,8 @@ client_submit_request(isc_nm_http_session_t *session, http_cstream_t *stream) {
if (stream->post) { if (stream->post) {
char p[64]; char p[64];
snprintf(p, sizeof(p), "%u", stream->postdata.length); snprintf(p, sizeof(p), "%u",
isc_buffer_usedlength(stream->postdata));
nghttp2_nv hdrs[] = { nghttp2_nv hdrs[] = {
MAKE_NV2(":method", "POST"), MAKE_NV2(":method", "POST"),
MAKE_NV(":scheme", MAKE_NV(":scheme",
@@ -1559,12 +1563,9 @@ client_send(isc_nmhandle_t *handle, const isc_region_t *region) {
if (cstream->post) { if (cstream->post) {
/* POST */ /* POST */
cstream->postdata = (isc_region_t){ isc_buffer_allocate(mctx, &cstream->postdata, region->length);
.base = isc_mem_get(mctx, region->length), isc_buffer_putmem(cstream->postdata, region->base,
.length = region->length region->length);
};
memmove(cstream->postdata.base, region->base, region->length);
cstream->postdata_pos = 0;
} else { } else {
/* GET */ /* GET */
size_t path_size = 0; size_t path_size = 0;