From 0e3a2189f65354962fc71af41f5aa52261a782e8 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 25 Oct 2026 22:30:04 +0100 Subject: Replace libowfat's iobatch with our own smaller (and probably only temporary) ot_batch --- ot_http.c | 55 +++++++++++++------------------------------------------ 1 file changed, 13 insertions(+), 42 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index 4c4121b..4675efb 100644 --- a/ot_http.c +++ b/ot_http.c @@ -15,7 +15,7 @@ #include /* Libowfat */ -#include "iob.h" +#include "io.h" /* Opentracker */ #include "ot_accesslist.h" @@ -29,14 +29,7 @@ #include "scan_urlencoded_query.h" #include "trackerlogic.h" -#ifdef WANT_NO_AUTO_FREE -#define OT_IOB_INIT(B) (bzero(B, sizeof(io_batch)), 0) -#else -#define OT_IOB_INIT(B) iob_init_autofree(B, 0) -#endif - #define OT_MAXMULTISCRAPE_COUNT 64 -#define OT_BATCH_LIMIT (1024 * 1024 * 16) extern const char *g_redirecturl; const char *g_stats_path; @@ -90,20 +83,17 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { memcpy(outbuf, ws->reply + written_size, ws->reply_size - written_size); if (!cookie->batch) { - cookie->batch = malloc(sizeof(io_batch)); - if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { - free(cookie->batch); + cookie->batch = calloc(1, sizeof(ot_batch)); + if (!cookie->batch) { free(outbuf); buf_reset(&cookie->request); free(cookie); io_close(sock); return; } - - cookie->batches = 1; } - iob_addbuf_free(cookie->batch, outbuf, ws->reply_size - written_size); + batch_add(cookie->batch, outbuf, ws->reply_size - written_size); /* writeable short data sockets just have a tcp timeout */ if (!ws->keep_alive) { @@ -146,10 +136,9 @@ ssize_t http_issue_error(const int64_t sock, struct ot_workstruct *ws, int code) ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial) { struct http_data *cookie = io_getcookie(sock); - io_batch *current; char *header; const char *encoding = ""; - size_t i, header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); + size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); tai6464 t; /* No cookie? Bad socket. Leave. */ @@ -199,42 +188,24 @@ ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t } if (!cookie->batch) { - cookie->batch = malloc(sizeof(io_batch)); - if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { - free(cookie->batch); + cookie->batch = calloc(1, sizeof(ot_batch)); + if (!cookie->batch) { free(header); iovec_free(&iovec_entries, &iovector); HTTPERROR_500; } - cookie->batches = 1; - } - current = cookie->batch + cookie->batches - 1; - iob_addbuf_free(current, header, header_size); - - /* Split huge iovectors into separate io_batches */ - for (i = 0; i < (size_t)iovec_entries; ++i) { - /* If the current batch's limit is reached, try to reallocate a new batch to work on */ - if (current->bytesleft > OT_BATCH_LIMIT) { - io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); - - if (new_batch) { - cookie->batch = new_batch; - if (OT_IOB_INIT(cookie->batch + cookie->batches) != -1) - ++cookie->batches; - } - /* realloc may have moved the batches, so current is stale either way */ - current = cookie->batch + cookie->batches - 1; - } - iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len); } + + batch_add(cookie->batch, header, header_size); + batch_add_vector(cookie->batch, iovector, iovec_entries); free(iovector); + if (cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) - iob_addbuf(current, "\r\n", 2); + batch_add_copy(cookie->batch, "\r\n", 2); } if ((cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER) && cookie->batch && !is_partial) { - current = cookie->batch + cookie->batches - 1; - iob_addbuf(current, "0\r\n\r\n", 5); + batch_add_copy(cookie->batch, "0\r\n\r\n", 5); cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; } -- cgit v1.3