From f8637baaeb2ea560d8818397af40a22f223ba857 Mon Sep 17 00:00:00 2001
From: Dirk Engling <erdgeist@erdgeist.org>
Date: Mon, 15 Apr 2024 15:20:21 +0200
Subject: Allow the use of iob_init if the new libowfat is not yet available

---
 Makefile  |  4 ++++
 ot_http.c | 12 +++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 59296bc..803a2e0 100644
--- a/Makefile
+++ b/Makefile
@@ -38,6 +38,10 @@ FEATURES+=-DWANT_COMPRESSION_GZIP_ALWAYS
 #FEATURES+=-DWANT_DEV_RANDOM
 FEATURES+=-DWANT_FULLSCRAPE
 
+# You need libowfat version 0.34 to allow for automatic release of chunks during
+# full scrape transfer, if you rely on an older versions, enable this flag
+#FEATURES+=-DWANT_NO_AUTO_FREE
+
 # Is enabled on BSD systems by default in trackerlogic.h
 # on Linux systems you will need -lbds
 #FEATURES+=-DWANT_ARC4RANDOM
diff --git a/ot_http.c b/ot_http.c
index 2e2a085..ddb3e81 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -30,6 +30,12 @@
 #include "scan_urlencoded_query.h"
 #include "trackerlogic.h"
 
+#ifdef WANT_NO_AUTO_FREE
+#define OT_IOB_INIT iob_init
+#else
+#define OT_IOB_INIT iob_init_autofree
+#endif
+
 #define OT_MAXMULTISCRAPE_COUNT 64
 #define OT_BATCH_LIMIT          (1024 * 1024 * 16)
 extern char *g_redirecturl;
@@ -81,7 +87,7 @@ static void http_senddata(const int64 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));
-      iob_init_autofree(cookie->batch, 0);
+      OT_IOB_INIT(cookie->batch, 0);
       cookie->batches = 1;
     }
 
@@ -179,7 +185,7 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec
         iovec_free(&iovec_entries, &iovector);
         HTTPERROR_500;
       }
-      iob_init_autofree(cookie->batch, 0);
+      OT_IOB_INIT(cookie->batch, 0);
       cookie->batches = 1;
     }
     current = cookie->batch + cookie->batches - 1;
@@ -193,7 +199,7 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec
         if (new_batch) {
           cookie->batch = new_batch;
           current       = cookie->batch + cookie->batches++;
-          iob_init_autofree(current, 0);
+          OT_IOB_INIT(current, 0);
         }
       }
       iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len);
-- 
cgit v1.2.3