tmisu

Notification to stdout daemon
git clone https://git.inz.fi/tmisu/
Log | Files | Refs | README | LICENSE

commit ca9b3af8d94e1f5f91c83ac4830f9c9587ec424d
parent 923830ab9a175c2d3ed2f67a4638c86d5f03ccb1
Author: bit9tream <bit6tream@cock.li>
Date:   Tue, 23 Jun 2020 15:35:00 +0300

'"' are now escaped in json output

Diffstat:
Mformat.c | 25++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/format.c b/format.c @@ -3,6 +3,17 @@ #include "config.h" #include "format.h" +void escape_quotes(char *str, char *out) { + memset(out, 0, strlen(out)); + while (*str) { + if (*str == '"') + strcat(out, "\\\""); + else + out[strlen(out)] = *str; + str++; + } +} + void output_notification(gchar *app_name, guint32 replaces_id, gchar *app_icon, gchar *summary, gchar *body, GVariant *actions, GVariant *hints, gint32 timeout) { @@ -28,17 +39,24 @@ void output_notification(gchar *app_name, guint32 replaces_id, gchar *app_icon, sprintf(string, "%s%s%d%s%s%s%s", string, OUTPUT_DELIMITER, timeout, OUTPUT_DELIMITER, summary, OUTPUT_DELIMITER, body); #else - sprintf(string, "{ \"app_name\": \"%s\"", app_name); + char *escaped_str = (char *)calloc(512, sizeof(char)); + escape_quotes(app_name, escaped_str); + sprintf(string, "{ \"app_name\": \"%s\"", escaped_str); #ifdef RECEIVE_APP_ICON - sprintf(string, "%s, \"app_icon\": \"%s\"", string, app_icon); + escape_quotes(app_icon, escaped_str); + sprintf(string, "%s, \"app_icon\": \"%s\"", string, escaped_str); #endif #ifdef RECEIVE_REPLACES_ID sprintf(string, "%s, \"replaces_id\": %lu", string, replaces_id); #endif - sprintf(string, "%s, \"timeout\": %d, \"summary\": \"%s\", \"body\": \"%s\" }", string, timeout, summary, body); + escape_quotes(summary, escaped_str); + sprintf(string, "%s, \"timeout\": %d, \"summary\": \"%s\"", string, timeout, escaped_str); + + escape_quotes(body, escaped_str); + sprintf(string, "%s, \"body\": \"%s\" }", string, escaped_str); #endif @@ -46,4 +64,5 @@ void output_notification(gchar *app_name, guint32 replaces_id, gchar *app_icon, fflush(stdout); free(string); + free(escaped_str); }