--- ./src/xfce4-notifyd/xfce4-notifyd/xfce-notify-daemon.c 2018-03-05 17:32:27.538918899 +0500 +++ /home/hxss/xfce-notify-daemon.patched.c 2018-03-05 17:31:17.000000000 +0500 @@ -46,6 +46,8 @@ #include "xfce-notify-window.h" #include "xfce-notify-marshal.h" +#include + #define SPACE 16 #define XND_N_MONITORS xfce_notify_daemon_get_n_monitors_quark() #define KNOWN_APPLICATIONS_PROP "/applications/known_applications" @@ -1117,6 +1119,77 @@ } static gboolean +eval_ascii (const GMatchInfo *info, + GString *res, + gpointer data) +{ + gchar *ascii_code = g_match_info_fetch (info, 1); + + gchar* c = calloc(2, sizeof(gchar)); + c[0] = strtoul(ascii_code, NULL, 16); // convert string with ascii_code of char into char + c[1] = '\0'; + + g_string_append (res, c); + g_free(ascii_code); + g_free(c); + + return FALSE; +} + +static gboolean +eval_ahref (const GMatchInfo *info, + GString *res, + gpointer data) +{ + gchar *ahrefs = g_match_info_fetch (info, 1); // ahref start + gchar *link = g_match_info_fetch (info, 2); // link + gchar *ahrefe = g_match_info_fetch (info, 3); // ahref end + + // replace ascii_codes by chars + GRegex *reg_ascii = g_regex_new ("%(\\w{2})", 0, 0, NULL); + link = g_regex_replace_eval (reg_ascii, link, -1, 0, 0, eval_ascii, NULL, NULL); + g_regex_unref (reg_ascii); + + // TEST: replace '&' by '&'(from error logs) + GRegex *reg_amp = g_regex_new ("&", 0, 0, NULL); + link = g_regex_replace (reg_amp, link, -1, 0, "&", 0, NULL); + g_regex_unref (reg_amp); + + // use "http://" as default protocol for links without specified protocol + GRegex *reg_protocol = g_regex_new ("^(\\w+:\\/\\/)(.*)", 0, 0, NULL); + if (!g_regex_match (reg_protocol, link, 0, NULL)) { + gchar *new_link = calloc((strlen(link)+8)/sizeof(gchar),sizeof(gchar)); + g_sprintf(new_link, "http://%s", link); + g_free(link); + link = new_link; + } + g_regex_unref (reg_protocol); + + gchar *r = calloc( + (strlen(ahrefs) + strlen(link) + strlen(ahrefe) + 1) / sizeof(gchar), + sizeof(gchar) + ); + + r = g_strconcat(ahrefs, link, ahrefe, NULL); + g_string_append (res, r); + + g_free (r); + + return FALSE; +} + +const gchar * +prepare_body(const gchar *body) { + const gchar *res; + + // find and prepare all links in string + GRegex *reg_ahref = g_regex_new ("()", 0, 0, NULL); + res = g_regex_replace_eval (reg_ahref, body, -1, 0, 0, eval_ahref, NULL, NULL); + + return res; +} + +static gboolean notify_notify (XfceNotifyGBus *skeleton, GDBusMethodInvocation *invocation, const gchar *app_name, @@ -1230,6 +1303,10 @@ else new_app_name = g_strdup (app_name); + syslog(LOG_NOTICE, body); + body = prepare_body(body); + syslog(LOG_NOTICE, body); + notify_update_known_applications (xndaemon->settings, new_app_name); if(expire_timeout == -1)