summary refs log tree commit diff
path: root/contrib/palaver
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/palaver')
-rw-r--r--contrib/palaver/notify.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/contrib/palaver/notify.c b/contrib/palaver/notify.c
index a8ca220..e41f708 100644
--- a/contrib/palaver/notify.c
+++ b/contrib/palaver/notify.c
@@ -533,16 +533,15 @@ static void handleReplyUnaway(struct Message *msg) {
 static bool noPreview;
 static bool noPrivatePreview;
 
-static void jsonBody(
-	char *buf, size_t cap,
-	struct Message *msg, const char *network, bool preview
-) {
+static char *jsonBody(struct Message *msg, const char *network, bool preview) {
 	bool private = (msg->params[0][0] != '#');
 	if (private && noPrivatePreview) preview = false;
 	if (noPreview) preview = false;
 
-	FILE *file = fmemopen(buf, cap, "w");
-	if (!file) err(EX_OSERR, "fmemopen");
+	char *buf;
+	size_t len;
+	FILE *file = open_memstream(&buf, &len);
+	if (!file) err(EX_OSERR, "open_memstream");
 
 	fprintf(file, "{\"badge\":%d", badge);
 	fprintf(file, ",\"sender\":");
@@ -570,9 +569,10 @@ static void jsonBody(
 	}
 	fprintf(file, "}");
 
-	// XXX: fmemopen only null-terminates if there is room.
-	fclose(file);
-	buf[cap - 1] = '\0';
+	int error = fclose(file);
+	if (error) err(EX_IOERR, "fclose");
+
+	return buf;
 }
 
 static void handlePrivmsg(struct Message *msg) {
@@ -600,13 +600,13 @@ static void handlePrivmsg(struct Message *msg) {
 		const char *preview = sqlite3_column_text(stmts[Notify], i++);
 		const char *network = sqlite3_column_text(stmts[Notify], i++);
 
-		char body[4096];
 		if (!badged) {
 			badge++;
 			badged = true;
 		}
-		jsonBody(body, sizeof(body), msg, network, !strcmp(preview, "true"));
+		char *body = jsonBody(msg, network, !strcmp(preview, "true"));
 		pushNotify(endpoint, token, body);
+		free(body);
 	}
 	if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db));
 	sqlite3_reset(stmts[Notify]);
t/bounce.c?h=2.4&id=d20bda982a9cedfcdfeb677a436ec8a730364650&follow=1'>Call clientConsume before clientRecvJune McEnroe 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe