From 7ae25149c7fa7f05817c8eae940c3ef9a1c7a1b7 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 30 Mar 2016 16:08:05 -0400 Subject: [PATCH] move notification text escaping into dbus notify method callback this ensures that notification text reaching the module can be considered "usable" without forcing multiple escape passes onto the same notification fix T2757 --- src/bin/e_notification.c | 161 ++++++++++++++++++++++++- src/modules/notification/e_mod_popup.c | 159 ------------------------ 2 files changed, 160 insertions(+), 160 deletions(-) diff --git a/src/bin/e_notification.c b/src/bin/e_notification.c index 305b5b7cf..fc759d81d 100644 --- a/src/bin/e_notification.c +++ b/src/bin/e_notification.c @@ -69,12 +69,169 @@ hints_dict_iter(void *data, const void *key, Eldbus_Message_Iter *var) } } + +/* this function should be external in edje for use in cases such as this module. + * + * happily, it was decided that the function would not be external so that it could + * be duplicated into the module in full. + */ + +static int +_text_escape(Eina_Strbuf *txt, const char *text) +{ + const char *escaped; + int advance; + + escaped = evas_textblock_string_escape_get(text, &advance); + if (!escaped) + { + eina_strbuf_append_char(txt, text[0]); + advance = 1; + } + else + eina_strbuf_append(txt, escaped); + return advance; +} + +/* hardcoded list of allowed tags based on + * https://people.gnome.org/~mccann/docs/notification-spec/notification-spec-latest.html#markup + */ +static const char *tags[] = +{ + "", popped[1]); + } while (cur_tag && (popped != tag)); + advance = 4; + } + else if (cur_tag) + { + /* tag match: just pop */ + popped = eina_array_pop(arr); + if (eina_array_count(arr)) + cur_tag = eina_array_data_get(arr, eina_array_count(arr) - 1); + else + cur_tag = NULL; + eina_strbuf_append_printf(txt, "", popped[1]); + advance = 4; + } + else + { + /* no current tag: escape */ + advance = _text_escape(txt, text); + } + } + else + { + if (tag) + { + cur_tag = tag; + eina_array_push(arr, tag); + eina_strbuf_append_printf(txt, "<%c>", tag[1]); + advance = 3; + } + else + advance = _text_escape(txt, text); + } + } + else if (text[0] == '&') + { + const char *s; + + s = strchr(text, ';'); + if (s) + s = evas_textblock_escape_string_range_get(text, s + 1); + if (s) + { + eina_strbuf_append_char(txt, text[0]); + advance = 1; + } + else + advance = _text_escape(txt, text); + } + else + advance = _text_escape(txt, text); + + text += advance; + } + + eina_array_free(arr); + ret = eina_strbuf_string_steal(txt); + eina_strbuf_free(txt); + return ret; +} + static Eldbus_Message * notify_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) { E_Notification_Notify *n; Eldbus_Message_Iter *actions_iter, *hints_iter; Eldbus_Message *reply; + char *txt; if (!n_data->notify_cb) return NULL; @@ -100,7 +257,9 @@ notify_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Messag n->app_name = eina_stringshare_add(n->app_name); n->icon.icon = eina_stringshare_add(n->icon.icon); n->summary = eina_stringshare_add(n->summary); - n->body = eina_stringshare_add(n->body); + txt = _nedje_text_escape(n->body); + n->body = eina_stringshare_add(txt); + free(txt); e_object_ref(E_OBJECT(n)); n->id = n_data->notify_cb(n_data->data, n); diff --git a/src/modules/notification/e_mod_popup.c b/src/modules/notification/e_mod_popup.c index 03b33e045..de86673c0 100644 --- a/src/modules/notification/e_mod_popup.c +++ b/src/modules/notification/e_mod_popup.c @@ -12,160 +12,6 @@ static void _notification_popup_del(unsigned int id, static void _notification_popdown(Popup_Data *popup, E_Notification_Notify_Closed_Reason reason); -/* this function should be external in edje for use in cases such as this module. - * - * happily, it was decided that the function would not be external so that it could - * be duplicated into the module in full. - */ - -static int -_text_escape(Eina_Strbuf *txt, const char *text) -{ - const char *escaped; - int advance; - - escaped = evas_textblock_string_escape_get(text, &advance); - if (!escaped) - { - eina_strbuf_append_char(txt, text[0]); - advance = 1; - } - else - eina_strbuf_append(txt, escaped); - return advance; -} - -/* hardcoded list of allowed tags based on - * https://people.gnome.org/~mccann/docs/notification-spec/notification-spec-latest.html#markup - */ -static const char *tags[] = -{ - "", popped[1]); - } while (cur_tag && (popped != tag)); - advance = 4; - } - else if (cur_tag) - { - /* tag match: just pop */ - popped = eina_array_pop(arr); - if (eina_array_count(arr)) - cur_tag = eina_array_data_get(arr, eina_array_count(arr) - 1); - else - cur_tag = NULL; - eina_strbuf_append_printf(txt, "", popped[1]); - advance = 4; - } - else - { - /* no current tag: escape */ - advance = _text_escape(txt, text); - } - } - else - { - if (tag) - { - cur_tag = tag; - eina_array_push(arr, tag); - eina_strbuf_append_printf(txt, "<%c>", tag[1]); - advance = 3; - } - else - advance = _text_escape(txt, text); - } - } - else if (text[0] == '&') - { - const char *s; - - s = strchr(text, ';'); - if (s) - s = evas_textblock_escape_string_range_get(text, s + 1); - if (s) - { - eina_strbuf_append_char(txt, text[0]); - advance = 1; - } - else - advance = _text_escape(txt, text); - } - else - advance = _text_escape(txt, text); - - text += advance; - } - - eina_array_free(arr); - ret = eina_strbuf_string_steal(txt); - eina_strbuf_free(txt); - return ret; -} #define POPUP_GAP 10 #define POPUP_TO_EDGE 15 @@ -259,7 +105,6 @@ notification_popup_notify(E_Notification_Notify *n, unsigned int id) { Popup_Data *popup = NULL; - char *esc; switch (n->urgency) { @@ -280,10 +125,6 @@ notification_popup_notify(E_Notification_Notify *n, if (notification_cfg->ignore_replacement) n->replaces_id = 0; - esc = _nedje_text_escape(n->body); - eina_stringshare_replace(&n->body, esc); - free(esc); - if (n->replaces_id && (popup = _notification_popup_find(n->replaces_id))) { if (popup->notif)