--- /home/hxss/xfce4-notifyd-origin/xfce4-notifyd/xfce4-notifyd/xfce-notify-window.c 2018-03-03 16:47:55.848318085 +0500 +++ src/xfce4-notifyd/xfce4-notifyd/xfce-notify-window.c 2018-03-03 17:28:29.074352392 +0500 @@ -34,6 +34,8 @@ #include "xfce-notify-window.h" #include "xfce-notify-enum-types.h" +#include + #define DEFAULT_EXPIRE_TIMEOUT 10000 #define DEFAULT_NORMAL_OPACITY 0.85 #define DEFAULT_DO_FADEOUT TRUE @@ -747,10 +749,84 @@ gtk_widget_queue_draw(GTK_WIDGET(window)); } +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; +} + void xfce_notify_window_set_body(XfceNotifyWindow *window, const gchar *body) { + // syslog(LOG_NOTICE, body); + body = prepare_body(body); + // syslog(LOG_NOTICE, body); g_return_if_fail(XFCE_IS_NOTIFY_WINDOW(window)); if(body && *body) {