From adc5779b014f153b69ce5606882f5e7719bef079 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 01:04:58 +0000 Subject: [PATCH 01/16] New function to find matching prefix in char* array --- src/core/misc.c | 17 +++++++++++++++++ src/core/misc.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/core/misc.c b/src/core/misc.c index 1cfa15b6..c75f54db 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -168,6 +168,23 @@ int strarray_find(char **array, const char *item) return -1; } +int strarray_find_prefix(char **array, const char *item) +{ + char **tmp; + int index; + + g_return_val_if_fail(array != NULL, -1); + g_return_val_if_fail(item != NULL, -1); + + index = 0; + for (tmp = array; *tmp != NULL; tmp++, index++) { + if (g_str_has_prefix(*tmp, item)) + return index; + } + + return -1; +} + GSList *gslist_find_string(GSList *list, const char *key) { for (; list != NULL; list = list->next) diff --git a/src/core/misc.h b/src/core/misc.h index 00637da0..1c510c58 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -100,6 +100,9 @@ char *replace_chars(char *str, char from, char to); /* return index of `item' in `array' or -1 if not found */ int strarray_find(char **array, const char *item); +/* return index of element in `array' starting with `item' or -1 if not found */ +gboolean strarray_find_prefix(char **array, const char *item); + /* string -> uoff_t */ uoff_t str_to_uofft(const char *str); From 8b556a42e416fca8114837277f00d7fde944e519 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 01:06:27 +0000 Subject: [PATCH 02/16] Make activity_hide_targets more functional. Allow ignore of several types of targets Syntax: * Ignore activity in all windows # Ignore activity in all channels @ Ignore activity in all queries = Ignore activity in all dcc chats #chan|nick Ignore activity in named target(channel, query, dcc chat) tag/* Ignore all activity on network 'tag' tag/# Ignore activity in all channels on network 'tag' tag/@ Ignore activity in all queries on network 'tag' tag/= Ignore activity in all dcc chats on network 'tag' tag/#chan|nick Ignore activity in named channel/query/dcc chat on network 'tag' --- src/fe-common/core/fe-common-core.c | 63 ++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 512fc84c..4c9c8614 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -19,6 +19,7 @@ */ #include "module.h" +#include "modules.h" #include "module-formats.h" #include "args.h" #include "misc.h" @@ -462,25 +463,59 @@ void fe_common_core_finish_init(void) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { g_return_val_if_fail(array != NULL, FALSE); + const char *type = module_find_id_str("WINDOW ITEM TYPE", dest->window->active->type); - if (strarray_find(array, "*") != -1) + if ((strarray_find(array, "*") != -1) || // we ignore all targets + (g_ascii_strcasecmp(type, "CHANNEL") == 0 && strarray_find(array, "#") != -1) || // we ignore all channels + (g_ascii_strcasecmp(type, "QUERY") == 0 && // Is this a query? + (g_str_has_prefix("=", dest->target) ? // is it a dcc chat? + strarray_find(array, "=") != -1 : // are we ignoring dcc chat? + strarray_find(array, "@") != -1)) || // are we ognoring regular queries? + (strarray_find(array, dest->target) != -1)) // we ignore all channels with specific name return TRUE; + else if (dest->server_tag != NULL) { + char *prefix = g_strdup_printf("%s/", dest->server_tag); + if (strarray_find_prefix(array, prefix)) { + GSList *targets = NULL, *iterator = NULL; + gboolean found = FALSE; - if (strarray_find(array, dest->target) != -1) - return TRUE; + if (type != NULL) { + // create a list of types to look for + targets = g_slist_append(targets, g_strdup("*")); + if (g_ascii_strcasecmp(type, "CHANNEL") == 0) { + targets = g_slist_append(targets, g_strdup("#")); + targets = g_slist_append(targets, g_strdup(dest->target)); + } + else if (g_ascii_strcasecmp(type, "QUERY") == 0) { + if (g_str_has_prefix("=", dest->target)) + targets = g_slist_append(targets, g_strdup("=")); + else + targets = g_slist_append(targets, g_strdup("@")); + } - 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; + for (iterator = targets; iterator; iterator = iterator->next) { + char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, (char *) iterator->data); + int ret = strarray_find(array, tagtarget); + g_free(tagtarget); + if (ret != -1) { + found = TRUE; + break; + } + } - tagtarget = g_strdup_printf("%s/%s", dest->server_tag, dest->target); - ret = strarray_find(array, tagtarget); - g_free(tagtarget); - if (ret != -1) - return TRUE; + + } + + g_slist_foreach(targets, (GFunc)g_free, NULL); + g_slist_free(targets); + g_free(prefix); + + return found; + } + else { + g_free(prefix); + } } + return FALSE; } From befa2c2e082902ff4bf26b627d0ac45e06d88785 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 12:22:55 +0000 Subject: [PATCH 03/16] Changed return type to gboolean to match function definition --- src/core/misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index c75f54db..74399072 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -168,7 +168,7 @@ int strarray_find(char **array, const char *item) return -1; } -int strarray_find_prefix(char **array, const char *item) +gboolean strarray_find_prefix(char **array, const char *item) { char **tmp; int index; @@ -179,10 +179,10 @@ int strarray_find_prefix(char **array, const char *item) index = 0; for (tmp = array; *tmp != NULL; tmp++, index++) { if (g_str_has_prefix(*tmp, item)) - return index; + return TRUE; } - return -1; + return FALSE; } GSList *gslist_find_string(GSList *list, const char *key) From 17021e167ca4e7ba7dcff0a54c631d068fdef998 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 16:44:12 +0000 Subject: [PATCH 04/16] Make the prefix matching case insensitive --- src/core/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/misc.c b/src/core/misc.c index 74399072..83e11e29 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -178,7 +178,7 @@ gboolean strarray_find_prefix(char **array, const char *item) index = 0; for (tmp = array; *tmp != NULL; tmp++, index++) { - if (g_str_has_prefix(*tmp, item)) + if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), g_ascii_strdown(item, -1))) return TRUE; } From f2729765055c02cc70bfd23c982b9e8c242095ec Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 16:45:20 +0000 Subject: [PATCH 05/16] Helper function for getting window item type --- src/fe-common/core/window-items.c | 17 +++++++++++++++++ src/fe-common/core/window-items.h | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index bd6ae5e9..7d864e3e 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -138,6 +138,23 @@ void window_item_set_active(WINDOW_REC *window, WI_ITEM_REC *item) } } +WindowType window_item_get_type(WI_ITEM_REC *item) +{ + g_return_val_if_fail(item != NULL, WITEM_TYPE_OTHER); + + const char *type = module_find_id_str("WINDOW ITEM TYPE", item->type); + if (g_ascii_strcasecmp(type, "CHANNEL") == 0) + return WITEM_TYPE_CHANNEL; + else if (g_ascii_strcasecmp(type, "QUERY") == 0) { + if (g_str_has_prefix("=", item->name)) + return WITEM_TYPE_QUERY | WITEM_TYPE_DCCCHAT; + else + return WITEM_TYPE_QUERY | WITEM_TYPE_PRIVMSG; + } + else + return WITEM_TYPE_OTHER; +} + /* Return TRUE if `item' is the active window item in the window. `item' can be NULL. */ int window_item_is_active(WI_ITEM_REC *item) diff --git a/src/fe-common/core/window-items.h b/src/fe-common/core/window-items.h index f8db3c39..96f3cfe9 100644 --- a/src/fe-common/core/window-items.h +++ b/src/fe-common/core/window-items.h @@ -3,6 +3,14 @@ #include "fe-windows.h" +typedef enum { + WITEM_TYPE_CHANNEL = 1, + WITEM_TYPE_QUERY = 2, + WITEM_TYPE_PRIVMSG = 4, + WITEM_TYPE_DCCCHAT = 8, + WITEM_TYPE_OTHER = 16 +} WindowType; + /* Add/remove/destroy window item from `window' */ void window_item_add(WINDOW_REC *window, WI_ITEM_REC *item, int automatic); void window_item_remove(WI_ITEM_REC *item); @@ -23,6 +31,9 @@ int window_item_is_active(WI_ITEM_REC *item); void window_item_prev(WINDOW_REC *window); void window_item_next(WINDOW_REC *window); +// return WindowType depending on what WI_ITEM_REC is +WindowType window_item_get_type(WI_ITEM_REC *item); + /* Find wanted window item by name. `server' can be NULL. */ WI_ITEM_REC *window_item_find(void *server, const char *name); WI_ITEM_REC *window_item_find_window(WINDOW_REC *window, From 94600348cce450076fa598d0c9000c7599b77558 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 16:46:19 +0000 Subject: [PATCH 06/16] Reworked code to use helper function for window item type --- src/fe-common/core/fe-common-core.c | 86 ++++++++++++++--------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 4c9c8614..abd5fed3 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -463,58 +463,56 @@ void fe_common_core_finish_init(void) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { g_return_val_if_fail(array != NULL, FALSE); - const char *type = module_find_id_str("WINDOW ITEM TYPE", dest->window->active->type); + WindowType type = window_item_get_type(dest->window->active); - if ((strarray_find(array, "*") != -1) || // we ignore all targets - (g_ascii_strcasecmp(type, "CHANNEL") == 0 && strarray_find(array, "#") != -1) || // we ignore all channels - (g_ascii_strcasecmp(type, "QUERY") == 0 && // Is this a query? - (g_str_has_prefix("=", dest->target) ? // is it a dcc chat? - strarray_find(array, "=") != -1 : // are we ignoring dcc chat? - strarray_find(array, "@") != -1)) || // are we ognoring regular queries? - (strarray_find(array, dest->target) != -1)) // we ignore all channels with specific name + // we ignore all targets + if (strarray_find(array, "*") != -1) + return TRUE; + // we ignore all channels + else if (type & WITEM_TYPE_CHANNEL && strarray_find(array, "#") != -1) + return TRUE; + // Is this a dcc chat? + else if (type & WITEM_TYPE_DCCCHAT && strarray_find(array, "=") != -1) + return TRUE; + // Is this a private query window? + else if (type & WITEM_TYPE_PRIVMSG && strarray_find(array, "@") != -1) return TRUE; else if (dest->server_tag != NULL) { char *prefix = g_strdup_printf("%s/", dest->server_tag); - if (strarray_find_prefix(array, prefix)) { - GSList *targets = NULL, *iterator = NULL; - gboolean found = FALSE; - - if (type != NULL) { - // create a list of types to look for - targets = g_slist_append(targets, g_strdup("*")); - if (g_ascii_strcasecmp(type, "CHANNEL") == 0) { - targets = g_slist_append(targets, g_strdup("#")); - targets = g_slist_append(targets, g_strdup(dest->target)); - } - else if (g_ascii_strcasecmp(type, "QUERY") == 0) { - if (g_str_has_prefix("=", dest->target)) - targets = g_slist_append(targets, g_strdup("=")); - else - targets = g_slist_append(targets, g_strdup("@")); - } - - for (iterator = targets; iterator; iterator = iterator->next) { - char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, (char *) iterator->data); - int ret = strarray_find(array, tagtarget); - g_free(tagtarget); - if (ret != -1) { - found = TRUE; - break; - } - } + if (!strarray_find_prefix(array, prefix)) { + g_free(prefix); + return FALSE; + } + GSList *targets = NULL, *iterator = NULL; + gboolean found = FALSE; + // create a list of types to look for + targets = g_slist_append(targets, g_strdup("*")); + if (type & WITEM_TYPE_CHANNEL) { + targets = g_slist_append(targets, g_strdup("#")); + targets = g_slist_append(targets, g_strdup(dest->target)); + } + else if (type & WITEM_TYPE_QUERY) { + if (type & WITEM_TYPE_DCCCHAT) + targets = g_slist_append(targets, g_strdup("=")); + else + targets = g_slist_append(targets, g_strdup("@")); + } + for (iterator = targets; iterator; iterator = iterator->next) { + char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, (char *) iterator->data); + int ret = strarray_find(array, tagtarget); + g_free(tagtarget); + if (ret != -1) { + found = TRUE; + break; } - - g_slist_foreach(targets, (GFunc)g_free, NULL); - g_slist_free(targets); - g_free(prefix); - - return found; - } - else { - g_free(prefix); } + + g_slist_foreach(targets, (GFunc)g_free, NULL); + g_slist_free(targets); + g_free(prefix); + return found; } return FALSE; From 7d07e22a111f1e022db40d7c8302b786dd34c24f Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 18:20:49 +0000 Subject: [PATCH 07/16] Minor optimization --- src/core/misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/misc.c b/src/core/misc.c index 83e11e29..98dc2209 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -176,9 +176,10 @@ gboolean strarray_find_prefix(char **array, const char *item) g_return_val_if_fail(array != NULL, -1); g_return_val_if_fail(item != NULL, -1); + item = g_ascii_strdown(item, -1); index = 0; for (tmp = array; *tmp != NULL; tmp++, index++) { - if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), g_ascii_strdown(item, -1))) + if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) return TRUE; } From 7a9d9bd40b44c4dd01a2407a1f4f80324f54b372 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 20:16:23 +0000 Subject: [PATCH 08/16] enum name change and early exit if no server_tag --- src/fe-common/core/fe-common-core.c | 74 ++++++++++++++--------------- src/fe-common/core/window-items.c | 10 ++-- src/fe-common/core/window-items.h | 10 ++-- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index abd5fed3..423c0946 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -469,51 +469,51 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) if (strarray_find(array, "*") != -1) return TRUE; // we ignore all channels - else if (type & WITEM_TYPE_CHANNEL && strarray_find(array, "#") != -1) + else if (type & WI_TYPE_CHANNEL && strarray_find(array, "#") != -1) return TRUE; // Is this a dcc chat? - else if (type & WITEM_TYPE_DCCCHAT && strarray_find(array, "=") != -1) + else if (type & WI_TYPE_DCCCHAT && strarray_find(array, "=") != -1) return TRUE; // Is this a private query window? - else if (type & WITEM_TYPE_PRIVMSG && strarray_find(array, "@") != -1) + else if (type & WI_TYPE_PRIVMSG && strarray_find(array, "@") != -1) return TRUE; - else if (dest->server_tag != NULL) { - char *prefix = g_strdup_printf("%s/", dest->server_tag); - if (!strarray_find_prefix(array, prefix)) { - g_free(prefix); - return FALSE; - } - GSList *targets = NULL, *iterator = NULL; - gboolean found = FALSE; - // create a list of types to look for - targets = g_slist_append(targets, g_strdup("*")); - if (type & WITEM_TYPE_CHANNEL) { - targets = g_slist_append(targets, g_strdup("#")); - targets = g_slist_append(targets, g_strdup(dest->target)); - } - else if (type & WITEM_TYPE_QUERY) { - if (type & WITEM_TYPE_DCCCHAT) - targets = g_slist_append(targets, g_strdup("=")); - else - targets = g_slist_append(targets, g_strdup("@")); - } + if (dest->server_tag == NULL) + return FALSE; - for (iterator = targets; iterator; iterator = iterator->next) { - char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, (char *) iterator->data); - int ret = strarray_find(array, tagtarget); - g_free(tagtarget); - if (ret != -1) { - found = TRUE; - break; - } - } - - g_slist_foreach(targets, (GFunc)g_free, NULL); - g_slist_free(targets); + char *prefix = g_strdup_printf("%s/", dest->server_tag); + if (!strarray_find_prefix(array, prefix)) { g_free(prefix); - return found; + return FALSE; } - return FALSE; + GSList *targets = NULL, *iterator = NULL; + gboolean found = FALSE; + // create a list of types to look for + targets = g_slist_append(targets, g_strdup("*")); + if (type & WI_TYPE_CHANNEL) { + targets = g_slist_append(targets, g_strdup("#")); + targets = g_slist_append(targets, g_strdup(dest->target)); + } + else if (type & WI_TYPE_QUERY) { + if (type & WI_TYPE_DCCCHAT) + targets = g_slist_append(targets, g_strdup("=")); + else + targets = g_slist_append(targets, g_strdup("@")); + } + + for (iterator = targets; iterator; iterator = iterator->next) { + char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, (char *) iterator->data); + int ret = strarray_find(array, tagtarget); + g_free(tagtarget); + if (ret != -1) { + found = TRUE; + break; + } + } + + g_slist_foreach(targets, (GFunc)g_free, NULL); + g_slist_free(targets); + g_free(prefix); + return found; } diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index 7d864e3e..90545ea3 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -140,19 +140,19 @@ void window_item_set_active(WINDOW_REC *window, WI_ITEM_REC *item) WindowType window_item_get_type(WI_ITEM_REC *item) { - g_return_val_if_fail(item != NULL, WITEM_TYPE_OTHER); + g_return_val_if_fail(item != NULL, WI_TYPE_OTHER); const char *type = module_find_id_str("WINDOW ITEM TYPE", item->type); if (g_ascii_strcasecmp(type, "CHANNEL") == 0) - return WITEM_TYPE_CHANNEL; + return WI_TYPE_CHANNEL; else if (g_ascii_strcasecmp(type, "QUERY") == 0) { if (g_str_has_prefix("=", item->name)) - return WITEM_TYPE_QUERY | WITEM_TYPE_DCCCHAT; + return WI_TYPE_QUERY | WI_TYPE_DCCCHAT; else - return WITEM_TYPE_QUERY | WITEM_TYPE_PRIVMSG; + return WI_TYPE_QUERY | WI_TYPE_PRIVMSG; } else - return WITEM_TYPE_OTHER; + return WI_TYPE_OTHER; } /* Return TRUE if `item' is the active window item in the window. diff --git a/src/fe-common/core/window-items.h b/src/fe-common/core/window-items.h index 96f3cfe9..1ef9119e 100644 --- a/src/fe-common/core/window-items.h +++ b/src/fe-common/core/window-items.h @@ -4,11 +4,11 @@ #include "fe-windows.h" typedef enum { - WITEM_TYPE_CHANNEL = 1, - WITEM_TYPE_QUERY = 2, - WITEM_TYPE_PRIVMSG = 4, - WITEM_TYPE_DCCCHAT = 8, - WITEM_TYPE_OTHER = 16 + WI_TYPE_CHANNEL = 1, + WI_TYPE_QUERY = 2, + WI_TYPE_PRIVMSG = 4, + WI_TYPE_DCCCHAT = 8, + WI_TYPE_OTHER = 16 } WindowType; /* Add/remove/destroy window item from `window' */ From 11bc71a2eab09bdefc776499dd110fb47f75d8b1 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 20:47:27 +0000 Subject: [PATCH 09/16] Minor changes as per review --- src/core/misc.c | 10 +++++----- src/core/misc.h | 2 +- src/fe-common/core/fe-common-core.c | 19 ++++++++++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index 98dc2209..acac04d2 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -168,7 +168,7 @@ int strarray_find(char **array, const char *item) return -1; } -gboolean strarray_find_prefix(char **array, const char *item) +int strarray_find_prefix(char **array, const char *item) { char **tmp; int index; @@ -176,14 +176,14 @@ gboolean strarray_find_prefix(char **array, const char *item) g_return_val_if_fail(array != NULL, -1); g_return_val_if_fail(item != NULL, -1); - item = g_ascii_strdown(item, -1); index = 0; for (tmp = array; *tmp != NULL; tmp++, index++) { - if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) - return TRUE; + //if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) + if (g_ascii_strncasecmp(*tmp, item, length(item)) == 0) + return index; } - return FALSE; + return -1; } GSList *gslist_find_string(GSList *list, const char *key) diff --git a/src/core/misc.h b/src/core/misc.h index 1c510c58..a3bb5dd2 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -101,7 +101,7 @@ char *replace_chars(char *str, char from, char to); int strarray_find(char **array, const char *item); /* return index of element in `array' starting with `item' or -1 if not found */ -gboolean strarray_find_prefix(char **array, const char *item); +int strarray_find_prefix(char **array, const char *item); /* string -> uoff_t */ uoff_t str_to_uofft(const char *str); diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 423c0946..176be7a0 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -462,12 +462,18 @@ void fe_common_core_finish_init(void) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { + const WindowType type = window_item_get_type(dest->window->active); + GSList *targets = NULL, *iterator = NULL; + gboolean found = FALSE; + g_return_val_if_fail(array != NULL, FALSE); - WindowType type = window_item_get_type(dest->window->active); // we ignore all targets if (strarray_find(array, "*") != -1) return TRUE; + // exit if not a channel or query + else if (type & WI_TYPE_OTHER) + return FALSE; // we ignore all channels else if (type & WI_TYPE_CHANNEL && strarray_find(array, "#") != -1) return TRUE; @@ -478,17 +484,16 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) else if (type & WI_TYPE_PRIVMSG && strarray_find(array, "@") != -1) return TRUE; - if (dest->server_tag == NULL) - return FALSE; + g_return_val_if_fail(dest->server_tag != NULL, FALSE); char *prefix = g_strdup_printf("%s/", dest->server_tag); - if (!strarray_find_prefix(array, prefix)) { + if (strarray_find_prefix(array, prefix) == -1) { g_free(prefix); return FALSE; } - GSList *targets = NULL, *iterator = NULL; - gboolean found = FALSE; + g_free(prefix); + // create a list of types to look for targets = g_slist_append(targets, g_strdup("*")); if (type & WI_TYPE_CHANNEL) { @@ -514,6 +519,6 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) g_slist_foreach(targets, (GFunc)g_free, NULL); g_slist_free(targets); - g_free(prefix); + return found; } From 7c540a013995aaa76039dd89ee39e50771973d6f Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 20:52:49 +0000 Subject: [PATCH 10/16] I blame other languages --- src/core/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/misc.c b/src/core/misc.c index acac04d2..67298fa5 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -179,7 +179,7 @@ int strarray_find_prefix(char **array, const char *item) index = 0; for (tmp = array; *tmp != NULL; tmp++, index++) { //if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) - if (g_ascii_strncasecmp(*tmp, item, length(item)) == 0) + if (g_ascii_strncasecmp(*tmp, item, strlen(item)) == 0) return index; } From e80b659767cdbd278aec29136be1bd18ecfadb25 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 21:06:32 +0000 Subject: [PATCH 11/16] Minor changes as per review --- src/core/misc.c | 1 - src/fe-common/core/fe-common-core.c | 10 +++++----- src/fe-common/core/window-items.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index 67298fa5..c61c90c9 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -178,7 +178,6 @@ int strarray_find_prefix(char **array, const char *item) index = 0; for (tmp = array; *tmp != NULL; tmp++, index++) { - //if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) if (g_ascii_strncasecmp(*tmp, item, strlen(item)) == 0) return index; } diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 176be7a0..b491d55d 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -495,16 +495,16 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) g_free(prefix); // create a list of types to look for - targets = g_slist_append(targets, g_strdup("*")); + targets = g_slist_append(targets, "*"); if (type & WI_TYPE_CHANNEL) { - targets = g_slist_append(targets, g_strdup("#")); - targets = g_slist_append(targets, g_strdup(dest->target)); + targets = g_slist_append(targets, "#"); + targets = g_slist_append(targets, dest->target); } else if (type & WI_TYPE_QUERY) { if (type & WI_TYPE_DCCCHAT) - targets = g_slist_append(targets, g_strdup("=")); + targets = g_slist_append(targets, "="); else - targets = g_slist_append(targets, g_strdup("@")); + targets = g_slist_append(targets, "@"); } for (iterator = targets; iterator; iterator = iterator->next) { diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index 90545ea3..e322383b 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -140,10 +140,10 @@ void window_item_set_active(WINDOW_REC *window, WI_ITEM_REC *item) WindowType window_item_get_type(WI_ITEM_REC *item) { - g_return_val_if_fail(item != NULL, WI_TYPE_OTHER); + g_return_val_if_fail(item != NULL, WI_TYPE_OTHER); const char *type = module_find_id_str("WINDOW ITEM TYPE", item->type); - if (g_ascii_strcasecmp(type, "CHANNEL") == 0) + if (g_ascii_strcasecmp(type, "CHANNEL") == 0) return WI_TYPE_CHANNEL; else if (g_ascii_strcasecmp(type, "QUERY") == 0) { if (g_str_has_prefix("=", item->name)) From e63e0b653af038ef0eec865273be18d896102f3f Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 21:13:09 +0000 Subject: [PATCH 12/16] any other way to do that? (gpointer) dest->target? --- 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 b491d55d..7bb7c9fb 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -498,7 +498,7 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) targets = g_slist_append(targets, "*"); if (type & WI_TYPE_CHANNEL) { targets = g_slist_append(targets, "#"); - targets = g_slist_append(targets, dest->target); + targets = g_slist_append(targets, g_strdup(dest->target)); } else if (type & WI_TYPE_QUERY) { if (type & WI_TYPE_DCCCHAT) From 9288eed73a20082b6b53bee7f4bdf72b033629d8 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 21:23:37 +0000 Subject: [PATCH 13/16] Hopefully the final changes! --- src/fe-common/core/fe-common-core.c | 5 +++-- src/fe-common/core/window-items.c | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 7bb7c9fb..4f6d8907 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -484,7 +484,8 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) else if (type & WI_TYPE_PRIVMSG && strarray_find(array, "@") != -1) return TRUE; - g_return_val_if_fail(dest->server_tag != NULL, FALSE); + if (dest->server_tag == NULL) + return FALSE; char *prefix = g_strdup_printf("%s/", dest->server_tag); if (strarray_find_prefix(array, prefix) == -1) { @@ -498,7 +499,7 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) targets = g_slist_append(targets, "*"); if (type & WI_TYPE_CHANNEL) { targets = g_slist_append(targets, "#"); - targets = g_slist_append(targets, g_strdup(dest->target)); + targets = g_slist_append(targets, (gpointer) dest->target); } else if (type & WI_TYPE_QUERY) { if (type & WI_TYPE_DCCCHAT) diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index e322383b..5523b61e 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -143,10 +143,10 @@ WindowType window_item_get_type(WI_ITEM_REC *item) g_return_val_if_fail(item != NULL, WI_TYPE_OTHER); const char *type = module_find_id_str("WINDOW ITEM TYPE", item->type); - if (g_ascii_strcasecmp(type, "CHANNEL") == 0) + if (!g_ascii_strcasecmp(type, "CHANNEL")) return WI_TYPE_CHANNEL; - else if (g_ascii_strcasecmp(type, "QUERY") == 0) { - if (g_str_has_prefix("=", item->name)) + else if (!g_ascii_strcasecmp(type, "QUERY")) { + if (item->name[0] == '=') return WI_TYPE_QUERY | WI_TYPE_DCCCHAT; else return WI_TYPE_QUERY | WI_TYPE_PRIVMSG; From 56da627fcfbad07211778be3b322277a474a52c3 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 13 Jan 2017 21:25:52 +0000 Subject: [PATCH 14/16] Hopefully the final changes! --- src/fe-common/core/fe-common-core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 4f6d8907..c4c85ec2 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -518,7 +518,6 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) } } - g_slist_foreach(targets, (GFunc)g_free, NULL); g_slist_free(targets); return found; From 2c7d58586b863ceb84a775e077f181803caff604 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Wed, 29 Mar 2017 14:15:10 +0200 Subject: [PATCH 15/16] Move assertion to callpoint to work around assertion fail errors --- src/fe-common/core/fe-common-core.c | 2 +- src/fe-common/core/window-items.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index c4c85ec2..cc56b053 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -462,7 +462,7 @@ void fe_common_core_finish_init(void) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { - const WindowType type = window_item_get_type(dest->window->active); + const WindowType type = dest->window->active ? window_item_get_type(dest->window->active) : WI_ITEM_OTHER; GSList *targets = NULL, *iterator = NULL; gboolean found = FALSE; diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index 5523b61e..934d66db 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -140,8 +140,6 @@ void window_item_set_active(WINDOW_REC *window, WI_ITEM_REC *item) WindowType window_item_get_type(WI_ITEM_REC *item) { - g_return_val_if_fail(item != NULL, WI_TYPE_OTHER); - const char *type = module_find_id_str("WINDOW ITEM TYPE", item->type); if (!g_ascii_strcasecmp(type, "CHANNEL")) return WI_TYPE_CHANNEL; From 5135eee57a7572ccb36f0c126a20ac81ed717078 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Wed, 29 Mar 2017 16:46:39 +0200 Subject: [PATCH 16/16] Fixed typo --- 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 cc56b053..6eaef10d 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -462,7 +462,7 @@ void fe_common_core_finish_init(void) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { - const WindowType type = dest->window->active ? window_item_get_type(dest->window->active) : WI_ITEM_OTHER; + const WindowType type = dest->window->active ? window_item_get_type(dest->window->active) : WI_TYPE_OTHER; GSList *targets = NULL, *iterator = NULL; gboolean found = FALSE;