summaryrefslogtreecommitdiff
path: root/src/themes/slider
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-03-17 20:23:08 +0100
committerraveit65 <[email protected]>2020-04-16 14:37:16 +0200
commit51bb1b6a708971e74833b2efff14f399e307c697 (patch)
tree6d3f6fb27f791a7caf191d70a2e19fb8bd8f7962 /src/themes/slider
parentc835ece90b74fd31d8c6d60652861e43305c0c2d (diff)
downloadmate-notification-daemon-51bb1b6a708971e74833b2efff14f399e307c697.tar.bz2
mate-notification-daemon-51bb1b6a708971e74833b2efff14f399e307c697.tar.xz
Filter-out img elements from notification body
Diffstat (limited to 'src/themes/slider')
-rw-r--r--src/themes/slider/theme.c59
1 files changed, 54 insertions, 5 deletions
diff --git a/src/themes/slider/theme.c b/src/themes/slider/theme.c
index 9edb1d7..438049b 100644
--- a/src/themes/slider/theme.c
+++ b/src/themes/slider/theme.c
@@ -25,6 +25,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <libxml/xpath.h>
+
typedef void (*ActionInvokedCb) (GtkWindow* nw, const char* key);
typedef void (*UrlClickedCb) (GtkWindow* nw, const char* url);
@@ -494,7 +496,6 @@ void set_notification_text(GtkWindow* nw, const char* summary, const char* body)
{
char* str;
char* quoted;
- const char *body_label_text;
GtkRequisition req;
WindowData* windata;
int summary_width;
@@ -510,10 +511,58 @@ void set_notification_text(GtkWindow* nw, const char* summary, const char* body)
gtk_label_set_markup(GTK_LABEL(windata->summary_label), str);
g_free(str);
- gtk_label_set_markup (GTK_LABEL (windata->body_label), body);
- body_label_text = gtk_label_get_text (GTK_LABEL (windata->body_label));
- if ((body_label_text == NULL) || (strlen (body_label_text) == 0))
- gtk_label_set_text (GTK_LABEL (windata->body_label), body);
+ /* body */
+ xmlDocPtr doc;
+ xmlInitParser();
+ str = g_strconcat ("<markup>", body, "</markup>", NULL);
+ /* parse notification body */
+ doc = xmlReadMemory(str, strlen (str), "noname.xml", NULL, 0);
+ g_free (str);
+ if (doc != NULL) {
+ xmlXPathContextPtr xpathCtx;
+ xmlXPathObjectPtr xpathObj;
+ xmlNodeSetPtr nodes;
+ const char *body_label_text;
+ int i, size;
+
+ /* filterout img nodes */
+ xpathCtx = xmlXPathNewContext(doc);
+ xpathObj = xmlXPathEvalExpression((unsigned char *)"//img", xpathCtx);
+ nodes = xpathObj->nodesetval;
+ size = (nodes) ? nodes->nodeNr : 0;
+ for(i = size - 1; i >= 0; i--) {
+ xmlUnlinkNode (nodes->nodeTab[i]);
+ xmlFreeNode (nodes->nodeTab[i]);
+ }
+
+ /* write doc to string */
+ xmlBufferPtr buf = xmlBufferCreate();
+ (void) xmlNodeDump(buf, doc, xmlDocGetRootElement (doc), 0, 0);
+ str = (char *)buf->content;
+ gtk_label_set_markup (GTK_LABEL (windata->body_label), str);
+
+ /* cleanup */
+ xmlBufferFree (buf);
+ xmlXPathFreeObject (xpathObj);
+ xmlXPathFreeContext (xpathCtx);
+ xmlFreeDoc (doc);
+
+ /* Does it render properly? */
+ body_label_text = gtk_label_get_text (GTK_LABEL (windata->body_label));
+ if ((body_label_text == NULL) || (strlen (body_label_text) == 0)) {
+ goto render_fail;
+ }
+ goto renrer_ok;
+ }
+
+render_fail:
+ /* could not parse notification body */
+ quoted = g_markup_escape_text(body, -1);
+ gtk_label_set_markup (GTK_LABEL (windata->body_label), quoted);
+ g_free (quoted);
+
+renrer_ok:
+ xmlCleanupParser ();
if (body == NULL || *body == '\0')
gtk_widget_hide(windata->body_label);