mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Merge branch '3553-httpd-cleanup-v9_18' into 'v9_18'
additional code cleanups in httpd.c See merge request isc-projects/bind9!6799
This commit is contained in:
commit
f05297fe5a
1 changed files with 21 additions and 31 deletions
|
|
@ -820,7 +820,7 @@ render_500(const char *url, isc_httpdurl_t *urlinfo, const char *querystring,
|
|||
|
||||
#ifdef HAVE_ZLIB
|
||||
/*%<
|
||||
* Reallocates compbuffer to size, does nothing if compbuffer is already
|
||||
* Reallocates compbuffer to size; does nothing if compbuffer is already
|
||||
* larger than size.
|
||||
*/
|
||||
static void
|
||||
|
|
@ -828,11 +828,11 @@ alloc_compspace(isc_httpd_t *httpd, unsigned int size) {
|
|||
char *newspace = NULL;
|
||||
isc_region_t r;
|
||||
|
||||
isc_buffer_region(&httpd->compbuffer, &r);
|
||||
if (size < r.length) {
|
||||
if (size <= isc_buffer_length(&httpd->compbuffer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
isc_buffer_region(&httpd->compbuffer, &r);
|
||||
newspace = isc_mem_get(httpd->mgr->mctx, size);
|
||||
isc_buffer_reinit(&httpd->compbuffer, newspace, size);
|
||||
|
||||
|
|
@ -857,25 +857,23 @@ alloc_compspace(isc_httpd_t *httpd, unsigned int size) {
|
|||
static isc_result_t
|
||||
httpd_compress(isc_httpd_t *httpd) {
|
||||
z_stream zstr;
|
||||
isc_region_t r;
|
||||
int ret;
|
||||
int inputlen;
|
||||
|
||||
inputlen = isc_buffer_usedlength(&httpd->bodybuffer);
|
||||
alloc_compspace(httpd, inputlen);
|
||||
isc_buffer_clear(&httpd->compbuffer);
|
||||
isc_buffer_region(&httpd->compbuffer, &r);
|
||||
int ret, inputlen;
|
||||
|
||||
/*
|
||||
* We're setting output buffer size to input size so it fails if the
|
||||
* compressed data size would be bigger than the input size.
|
||||
*/
|
||||
memset(&zstr, 0, sizeof(zstr));
|
||||
zstr.total_in = zstr.avail_in = zstr.total_out = zstr.avail_out =
|
||||
inputlen;
|
||||
inputlen = isc_buffer_usedlength(&httpd->bodybuffer);
|
||||
alloc_compspace(httpd, inputlen);
|
||||
isc_buffer_clear(&httpd->compbuffer);
|
||||
|
||||
zstr.next_in = isc_buffer_base(&httpd->bodybuffer);
|
||||
zstr.next_out = r.base;
|
||||
zstr = (z_stream){
|
||||
.total_in = inputlen,
|
||||
.avail_out = inputlen,
|
||||
.avail_in = inputlen,
|
||||
.next_in = isc_buffer_base(&httpd->bodybuffer),
|
||||
.next_out = isc_buffer_base(&httpd->compbuffer),
|
||||
};
|
||||
|
||||
ret = deflateInit(&zstr, Z_DEFAULT_COMPRESSION);
|
||||
if (ret == Z_OK) {
|
||||
|
|
@ -883,7 +881,7 @@ httpd_compress(isc_httpd_t *httpd) {
|
|||
}
|
||||
deflateEnd(&zstr);
|
||||
if (ret == Z_STREAM_END) {
|
||||
isc_buffer_add(&httpd->compbuffer, inputlen - zstr.avail_out);
|
||||
isc_buffer_add(&httpd->compbuffer, zstr.total_out);
|
||||
return (ISC_R_SUCCESS);
|
||||
} else {
|
||||
return (ISC_R_FAILURE);
|
||||
|
|
@ -1022,9 +1020,8 @@ httpd_request(isc_nmhandle_t *handle, isc_result_t eresult,
|
|||
isc_buffer_clear(&httpd->headerbuffer);
|
||||
isc_buffer_setautorealloc(httpd->sendbuffer, true);
|
||||
databuffer = (is_compressed ? &httpd->compbuffer : &httpd->bodybuffer);
|
||||
isc_buffer_usedregion(databuffer, &r);
|
||||
result = isc_buffer_copyregion(httpd->sendbuffer, &r);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
isc_buffer_putmem(httpd->sendbuffer, isc_buffer_base(databuffer),
|
||||
isc_buffer_usedlength(databuffer));
|
||||
|
||||
/* Consume the request from the recv buffer. */
|
||||
if (httpd->consume != 0U) {
|
||||
|
|
@ -1201,18 +1198,11 @@ httpd_senddone(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
|
|||
REQUIRE(VALID_HTTPD(httpd));
|
||||
REQUIRE(httpd->handle == handle);
|
||||
|
||||
/* Clean up buffers */
|
||||
isc_buffer_free(&httpd->sendbuffer);
|
||||
|
||||
/*
|
||||
* We will always want to clean up our receive buffer, even if we
|
||||
* got an error on send or we are shutting down.
|
||||
*/
|
||||
if (httpd->freecb != NULL) {
|
||||
isc_buffer_t *b = NULL;
|
||||
if (isc_buffer_length(&httpd->bodybuffer) > 0) {
|
||||
b = &httpd->bodybuffer;
|
||||
httpd->freecb(b, httpd->freecb_arg);
|
||||
}
|
||||
if (httpd->freecb != NULL && isc_buffer_length(&httpd->bodybuffer) > 0)
|
||||
{
|
||||
httpd->freecb(&httpd->bodybuffer, httpd->freecb_arg);
|
||||
}
|
||||
|
||||
isc_nmhandle_detach(&httpd->sendhandle);
|
||||
|
|
|
|||
Loading…
Reference in a new issue