From 56424a335a34c6c71cb62901cdcc3a55ac375bf2 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Thu, 9 Nov 2023 07:17:00 -0500 Subject: [PATCH] --format=csv: increase default buffer size Input is percent-encoded when colon separated values mode is enabled. Account for the percent encoding overhead (each character is encoded as 3 characters) in the default buffer size. Work around for message boundary bugs in csv mode, e.g., * only the first lihe delimited value is read: multiple lines may be in the buffer * a buffer may contain a partial message --- src/xmppipe.c | 13 ++++++++++++- src/xmppipe.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/xmppipe.c b/src/xmppipe.c index ac58fcb..0a2a1a1 100644 --- a/src/xmppipe.c +++ b/src/xmppipe.c @@ -89,7 +89,7 @@ int main(int argc, char **argv) { state = xmppipe_calloc(1, sizeof(xmppipe_state_t)); xmppipe_next_state(state, XMPPIPE_S_CONNECTING); - state->bufsz = 2049; + state->bufsz = -1; state->poll = 10; state->keepalive = 60 * 1000; state->keepalive_limit = 3; @@ -240,6 +240,17 @@ int main(int argc, char **argv) { exit(2); } + if (state->bufsz == -1) { + switch (state->format) { + case XMPPIPE_FMT_CSV: + state->bufsz = 6144 + 1; + break; + default: + state->bufsz = 2048 + 1; + break; + } + } + if (state->encode && BASE64_LENGTH(state->bufsz) + 1 > 0xffff) { usage(state); exit(2); diff --git a/src/xmppipe.h b/src/xmppipe.h index 9b1afce..bb4f95f 100644 --- a/src/xmppipe.h +++ b/src/xmppipe.h @@ -85,7 +85,7 @@ typedef struct { keepalive_fail; /* number of consecutive keepalives without a reply */ u_int32_t keepalive_limit; /* number of keepalives without a reply */ u_int32_t interval; /* time since last keepalive (milliseconds) */ - size_t bufsz; /* size of read buffer */ + ssize_t bufsz; /* size of read buffer */ int sm_enabled; /* stanzas: iq, message, presence */