From 60c31219a278330498e695e4d7fca05ea69962e4 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Tue, 24 Oct 2017 12:02:30 +0200 Subject: [PATCH 1/4] Allow selection of what kind of activity targets to ignore Initialize tagtarget on declaration move code around for better flow, extra checks for uninitialized values remove unnecessary item->type checks don't strdup sign add braces around if statements, use strcmp0 with single characters and remove g_str_has_prefix refactoring changed g_ascii_strcasecmp to g_strcmp0 Add networktag/ shorthand fixed memory leaks changed from #@= to ::channels, ::queries and ::dccqueries check for empty string and continue; if found fixed bug with empty string check Clean up code --- src/fe-common/core/fe-common-core.c | 53 +++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 512fc84c..bce9ab4e 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -461,26 +461,43 @@ void fe_common_core_finish_init(void) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { + int channel_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL"); + int query_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY"); + char **tmp; + g_return_val_if_fail(array != NULL, FALSE); + g_return_val_if_fail(dest != NULL, FALSE); + g_return_val_if_fail(dest->window != NULL, FALSE); + g_return_val_if_fail(dest->target != NULL, FALSE); - if (strarray_find(array, "*") != -1) - return TRUE; - - if (strarray_find(array, dest->target) != -1) - return TRUE; - - if (dest->server_tag != NULL) { - char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, "*"); - int ret = strarray_find(array, tagtarget); - g_free(tagtarget); - if (ret != -1) - return TRUE; - - tagtarget = g_strdup_printf("%s/%s", dest->server_tag, dest->target); - ret = strarray_find(array, tagtarget); - g_free(tagtarget); - if (ret != -1) - return TRUE; + WI_ITEM_REC *item = window_item_find_window(dest->window, dest->server, dest->target); + if (item == NULL) { + return FALSE; } + + int server_tag_len = dest->server_tag ? strlen(dest->server_tag) : 0; + for (tmp = array; *tmp != NULL; tmp++) { + char *str = *tmp; + if (*str == '\0') { + continue; + } + + if (server_tag_len && !g_ascii_strncasecmp(str, dest->server_tag, server_tag_len) && str[server_tag_len] == '/') { + str += server_tag_len + 1; + } + + if (!g_strcmp0(str, "") || !g_strcmp0(str, "::all")) { + return TRUE; + } else if (!g_ascii_strcasecmp(str, dest->target)) { + return TRUE; + } else if (item->type == query_type && + !g_strcmp0(str, (dest->target[0] == '=') ? "::dccqueries" : "::queries")) { + return TRUE; + } else if (item->type == channel_type && + !g_strcmp0(str, "::channels")) { + return TRUE; + } + } + return FALSE; } From 4d5982f07d7f32585c00f1d6cca3fb425183140f Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sat, 6 Jan 2018 20:02:31 +0100 Subject: [PATCH 2/4] Update fe-common-core.c --- src/fe-common/core/fe-common-core.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index bce9ab4e..4f2d210a 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -475,26 +475,29 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) return FALSE; } - int server_tag_len = dest->server_tag ? strlen(dest->server_tag) : 0; + int server_tag_len = dest->server_tag != NULL ? strlen(dest->server_tag) : 0; for (tmp = array; *tmp != NULL; tmp++) { char *str = *tmp; if (*str == '\0') { continue; } - if (server_tag_len && !g_ascii_strncasecmp(str, dest->server_tag, server_tag_len) && str[server_tag_len] == '/') { + if (server_tag_len && + g_ascii_strncasecmp(str, dest->server_tag, server_tag_len) == 0 && + str[server_tag_len] == '/') { str += server_tag_len + 1; } - if (!g_strcmp0(str, "") || !g_strcmp0(str, "::all")) { + if (g_strcmp0(str, "") == 0 || g_strcmp0(str, "::all") == 0) { return TRUE; - } else if (!g_ascii_strcasecmp(str, dest->target)) { + } else if (g_ascii_strcasecmp(str, dest->target) == 0) { return TRUE; } else if (item->type == query_type && - !g_strcmp0(str, (dest->target[0] == '=') ? "::dccqueries" : "::queries")) { + g_strcmp0(str, dest->target[0] == '=' ? "::dccqueries" : + "::queries") == 0) { return TRUE; } else if (item->type == channel_type && - !g_strcmp0(str, "::channels")) { + g_strcmp0(str, "::channels") == 0) { return TRUE; } } From 121a4971e61176e326ee3d2f71867e87732f4519 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sat, 6 Jan 2018 20:17:51 +0100 Subject: [PATCH 3/4] Update fe-common-core.c fix mixed decls --- src/fe-common/core/fe-common-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 4f2d210a..a8726314 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -461,16 +461,19 @@ void fe_common_core_finish_init(void) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { - int channel_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL"); - int query_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY"); + WI_ITEM_REC *item; + int server_tag_len, channel_type, query_type; char **tmp; + channel_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL"); + query_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY"); + g_return_val_if_fail(array != NULL, FALSE); g_return_val_if_fail(dest != NULL, FALSE); g_return_val_if_fail(dest->window != NULL, FALSE); g_return_val_if_fail(dest->target != NULL, FALSE); - WI_ITEM_REC *item = window_item_find_window(dest->window, dest->server, dest->target); + item = window_item_find_window(dest->window, dest->server, dest->target); if (item == NULL) { return FALSE; } From f9c8365999c5319be6970dcf27f21190b0481314 Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 7 Jan 2018 01:44:48 -0300 Subject: [PATCH 4/4] fe-common-core: fix redeclaration of server_tag_len --- src/fe-common/core/fe-common-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index a8726314..791f56d4 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -478,7 +478,7 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) return FALSE; } - int server_tag_len = dest->server_tag != NULL ? strlen(dest->server_tag) : 0; + server_tag_len = dest->server_tag != NULL ? strlen(dest->server_tag) : 0; for (tmp = array; *tmp != NULL; tmp++) { char *str = *tmp; if (*str == '\0') {