diff options
Diffstat (limited to 'ot_http.c')
-rw-r--r-- | ot_http.c | 57 |
1 files changed, 41 insertions, 16 deletions
@@ -4,9 +4,9 @@ | |||
4 | $id$ */ | 4 | $id$ */ |
5 | 5 | ||
6 | /* System */ | 6 | /* System */ |
7 | #define _GNU_SOURCE | ||
7 | #include <arpa/inet.h> | 8 | #include <arpa/inet.h> |
8 | #include <pthread.h> | 9 | #include <pthread.h> |
9 | #define _GNU_SOURCE | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
12 | #include <string.h> | 12 | #include <string.h> |
@@ -32,7 +32,7 @@ | |||
32 | #include "trackerlogic.h" | 32 | #include "trackerlogic.h" |
33 | 33 | ||
34 | #ifdef WANT_NO_AUTO_FREE | 34 | #ifdef WANT_NO_AUTO_FREE |
35 | #define OT_IOB_INIT(B) bzero(B, sizeof(io_batch)) | 35 | #define OT_IOB_INIT(B) (bzero(B, sizeof(io_batch)), 0) |
36 | #else | 36 | #else |
37 | #define OT_IOB_INIT(B) iob_init_autofree(B, 0) | 37 | #define OT_IOB_INIT(B) iob_init_autofree(B, 0) |
38 | #endif | 38 | #endif |
@@ -88,7 +88,15 @@ static void http_senddata(const int64 sock, struct ot_workstruct *ws) { | |||
88 | memcpy(outbuf, ws->reply + written_size, ws->reply_size - written_size); | 88 | memcpy(outbuf, ws->reply + written_size, ws->reply_size - written_size); |
89 | if (!cookie->batch) { | 89 | if (!cookie->batch) { |
90 | cookie->batch = malloc(sizeof(io_batch)); | 90 | cookie->batch = malloc(sizeof(io_batch)); |
91 | OT_IOB_INIT(cookie->batch); | 91 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { |
92 | free(cookie->batch); | ||
93 | free(outbuf); | ||
94 | array_reset(&cookie->request); | ||
95 | free(cookie); | ||
96 | io_close(sock); | ||
97 | return; | ||
98 | } | ||
99 | |||
92 | cookie->batches = 1; | 100 | cookie->batches = 1; |
93 | } | 101 | } |
94 | 102 | ||
@@ -159,7 +167,9 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec | |||
159 | 167 | ||
160 | if (iovec_entries) { | 168 | if (iovec_entries) { |
161 | 169 | ||
162 | if (cookie->flag & STRUCT_HTTP_FLAG_GZIP) | 170 | if (cookie->flag & STRUCT_HTTP_FLAG_ZSTD) |
171 | encoding = "Content-Encoding: zstd\r\n"; | ||
172 | else if (cookie->flag & STRUCT_HTTP_FLAG_GZIP) | ||
163 | encoding = "Content-Encoding: gzip\r\n"; | 173 | encoding = "Content-Encoding: gzip\r\n"; |
164 | else if (cookie->flag & STRUCT_HTTP_FLAG_BZIP2) | 174 | else if (cookie->flag & STRUCT_HTTP_FLAG_BZIP2) |
165 | encoding = "Content-Encoding: bzip2\r\n"; | 175 | encoding = "Content-Encoding: bzip2\r\n"; |
@@ -181,12 +191,12 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec | |||
181 | 191 | ||
182 | if (!cookie->batch) { | 192 | if (!cookie->batch) { |
183 | cookie->batch = malloc(sizeof(io_batch)); | 193 | cookie->batch = malloc(sizeof(io_batch)); |
184 | if (!cookie->batch) { | 194 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { |
195 | free(cookie->batch); | ||
185 | free(header); | 196 | free(header); |
186 | iovec_free(&iovec_entries, &iovector); | 197 | iovec_free(&iovec_entries, &iovector); |
187 | HTTPERROR_500; | 198 | HTTPERROR_500; |
188 | } | 199 | } |
189 | OT_IOB_INIT(cookie->batch); | ||
190 | cookie->batches = 1; | 200 | cookie->batches = 1; |
191 | } | 201 | } |
192 | current = cookie->batch + cookie->batches - 1; | 202 | current = cookie->batch + cookie->batches - 1; |
@@ -199,8 +209,8 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec | |||
199 | io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); | 209 | io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); |
200 | if (new_batch) { | 210 | if (new_batch) { |
201 | cookie->batch = new_batch; | 211 | cookie->batch = new_batch; |
202 | current = cookie->batch + cookie->batches++; | 212 | if (OT_IOB_INIT(current) != -1) |
203 | OT_IOB_INIT(current); | 213 | current = cookie->batch + cookie->batches++; |
204 | } | 214 | } |
205 | } | 215 | } |
206 | iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len); | 216 | iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len); |
@@ -369,19 +379,34 @@ static ssize_t http_handle_fullscrape(const int64 sock, struct ot_workstruct *ws | |||
369 | } | 379 | } |
370 | #endif | 380 | #endif |
371 | 381 | ||
372 | #ifdef WANT_COMPRESSION_GZIP | 382 | |
383 | #if defined(WANT_COMPRESSION_GZIP) || defined(WANT_COMPRESSION_ZSTD) | ||
373 | ws->request[ws->request_size - 1] = 0; | 384 | ws->request[ws->request_size - 1] = 0; |
374 | #ifndef WANT_COMPRESSION_GZIP_ALWAYS | 385 | #ifdef WANT_COMPRESSION_GZIP |
375 | if (strstr(ws->request, "gzip")) { | 386 | if (strstr(ws->request, "gzip")) { |
376 | #endif | ||
377 | cookie->flag |= STRUCT_HTTP_FLAG_GZIP; | 387 | cookie->flag |= STRUCT_HTTP_FLAG_GZIP; |
378 | format = TASK_FLAG_GZIP; | 388 | format |= TASK_FLAG_GZIP; |
379 | stats_issue_event(EVENT_FULLSCRAPE_REQUEST_GZIP, 0, (uintptr_t)cookie->ip); | 389 | } |
380 | #ifndef WANT_COMPRESSION_GZIP_ALWAYS | ||
381 | } else | ||
382 | #endif | 390 | #endif |
391 | #ifdef WANT_COMPRESSION_ZSTD | ||
392 | if (strstr(ws->request, "zstd")) { | ||
393 | cookie->flag |= STRUCT_HTTP_FLAG_ZSTD; | ||
394 | format |= TASK_FLAG_ZSTD; | ||
395 | } | ||
396 | #endif | ||
397 | |||
398 | #if defined(WANT_COMPRESSION_ZSTD) && defined(WANT_COMPRESSION_ZSTD_ALWAYS) | ||
399 | cookie->flag |= STRUCT_HTTP_FLAG_ZSTD; | ||
400 | format |= TASK_FLAG_ZSTD; | ||
383 | #endif | 401 | #endif |
384 | stats_issue_event(EVENT_FULLSCRAPE_REQUEST, 0, (uintptr_t)cookie->ip); | 402 | |
403 | #if defined(WANT_COMPRESSION_GZIP) && defined(WANT_COMPRESSION_GZIP_ALWAYS) | ||
404 | cookie->flag |= STRUCT_HTTP_FLAG_GZIP; | ||
405 | format |= TASK_FLAG_GZIP; | ||
406 | #endif | ||
407 | #endif | ||
408 | |||
409 | stats_issue_event(EVENT_FULLSCRAPE_REQUEST, 0, (uintptr_t)cookie->ip); | ||
385 | 410 | ||
386 | #ifdef _DEBUG_HTTPERROR | 411 | #ifdef _DEBUG_HTTPERROR |
387 | fprintf(stderr, "%s", ws->debugbuf); | 412 | fprintf(stderr, "%s", ws->debugbuf); |