From c06e72a3e8a33fdf44c8e7af559c21b726bcf086 Mon Sep 17 00:00:00 2001 From: lxsang Date: Fri, 19 Oct 2018 12:37:26 +0200 Subject: [PATCH] allow plugin to close the connection at will --- http_server.c | 24 +----------------------- libs/handle.c | 32 ++++++++++++++++++++++++++++++++ libs/handle.h | 1 + 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/http_server.c b/http_server.c index 71db0eb..4617d7e 100644 --- a/http_server.c +++ b/http_server.c @@ -385,29 +385,7 @@ void *resolve_request(void *data) void *finish_request(void *data) { - if (!data) - return NULL; - LOG("Close request\n"); - antd_request_t *rq = (antd_request_t *)data; - // free all other thing - if (rq->request) - { - dictionary tmp = dvalue(rq->request, "COOKIE"); - if (tmp) - freedict(tmp); - tmp = dvalue(rq->request, "REQUEST_HEADER"); - if (tmp) - freedict(tmp); - tmp = dvalue(rq->request, "REQUEST_DATA"); - if (tmp) - freedict(tmp); - dput(rq->request, "REQUEST_HEADER", NULL); - dput(rq->request, "REQUEST_DATA", NULL); - dput(rq->request, "COOKIE", NULL); - freedict(rq->request); - } - antd_close(rq->client); - free(rq); + destroy_request(data); server_config.connection--; LOG("Remaining connection %d\n", server_config.connection); return NULL; diff --git a/libs/handle.c b/libs/handle.c index 6ff7603..fcf7c11 100644 --- a/libs/handle.c +++ b/libs/handle.c @@ -585,4 +585,36 @@ int read_buf(void* sock, char*buf,int size) } buf[i] = '\0'; return i; +} +/* + We put it here since we want the plugin is able + to destroy the request if it want to + in this case, the plugin should return an empty + with no data +*/ +void destroy_request(void *data) +{ + if (!data) + return; + LOG("Close request\n"); + antd_request_t *rq = (antd_request_t *)data; + // free all other thing + if (rq->request) + { + dictionary tmp = dvalue(rq->request, "COOKIE"); + if (tmp) + freedict(tmp); + tmp = dvalue(rq->request, "REQUEST_HEADER"); + if (tmp) + freedict(tmp); + tmp = dvalue(rq->request, "REQUEST_DATA"); + if (tmp) + freedict(tmp); + dput(rq->request, "REQUEST_HEADER", NULL); + dput(rq->request, "REQUEST_DATA", NULL); + dput(rq->request, "COOKIE", NULL); + freedict(rq->request); + } + antd_close(rq->client); + free(rq); } \ No newline at end of file diff --git a/libs/handle.h b/libs/handle.h index f6bf5ef..15ade27 100644 --- a/libs/handle.h +++ b/libs/handle.h @@ -111,4 +111,5 @@ int read_buf(void* sock,char* buf,int i); int antd_send( void *source, const void* data, int len); int antd_recv( void *source, void* data, int len); int antd_close(void* source); +void destroy_request(void *data); #endif