summary refs log tree commit diff
path: root/contrib/palaver/notify.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/palaver/notify.c')
-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]);
ubject'>Enable warnings in libeditJune McEnroe 2019-01-13Show full path in RPS1June McEnroe 2019-01-13Shorten $HOME to ~ in prompt expansionJune McEnroe 2019-01-13Document PSlitJune McEnroe 2019-01-13Document PS0June McEnroe 2019-01-13Set PS0 in cashJune McEnroe 2019-01-13Add PS0June McEnroe 2019-01-13Change default ENV from cashrc to env.shJune McEnroe 2019-01-13Use colours in cash promptsJune McEnroe 2019-01-12Set PSlit like NetBSD shJune McEnroe 2019-01-12Install gnupg2 from pkgsrc and symlink gpgJune McEnroe 2019-01-12Reference cash builtin man pages in cash.1 SEE ALSOJune McEnroe 2019-01-12Restore cash builtin man page datesJune McEnroe 2019-01-12Use local libeditJune McEnroe 2019-01-12Replace libedit MakefileJune McEnroe 2019-01-11Import /usr/src/lib/libedit from NetBSD 8.0June McEnroe 2019-01-11Add PSlit for prompt escapesJune McEnroe 2019-01-11Don't make depend automaticallyJune McEnroe