From 94b823c3cd410abb2fa54ecbcf298550d5e2ba88 Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Fri, 11 Mar 2016 09:12:38 +0100 Subject: [PATCH 1/2] Use glob matching for activity_hide_targets spaces vs tabs! strarray_find* needs to return -1 if no index found --- src/core/misc.c | 18 ++++++++++++++++++ src/core/misc.h | 1 + src/fe-common/core/fe-common-core.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/misc.c b/src/core/misc.c index aaa470f5..2284d3b1 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -181,6 +181,24 @@ int strarray_find(char **array, const char *item) return -1; } + +int strarray_find_glob(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_pattern_match_simple(*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 7e78d3b9..dd8bb14c 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -111,6 +111,7 @@ char *replace_chars(char *str, char from, char to); int strarray_length(char **array); /* return index of `item' in `array' or -1 if not found */ int strarray_find(char **array, const char *item); +int strarray_find_glob(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 ee7f9424..f0549358 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -464,7 +464,7 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) if (dest->server_tag != NULL) { char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, dest->target); - int ret = strarray_find(array, tagtarget); + int ret = strarray_find_glob(array, tagtarget); g_free(tagtarget); if (ret != -1) return TRUE; From 857e27aef6d04edc1e47d52d74031ba279d2da1a Mon Sep 17 00:00:00 2001 From: Jari Matilainen Date: Thu, 17 Mar 2016 23:58:46 +0100 Subject: [PATCH 2/2] Don't use glob matching, just regular string comparisons --- src/core/misc.c | 20 +------------------- src/core/misc.h | 1 - src/fe-common/core/fe-common-core.c | 13 +++++++++++-- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index 2284d3b1..c26610ec 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -169,30 +169,12 @@ int strarray_find(char **array, const char *item) char **tmp; int index; - g_return_val_if_fail(array != NULL, 0); - g_return_val_if_fail(item != NULL, 0); - - index = 0; - for (tmp = array; *tmp != NULL; tmp++, index++) { - if (g_ascii_strcasecmp(*tmp, item) == 0) - return index; - } - - return -1; -} - - -int strarray_find_glob(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_pattern_match_simple(*tmp, item)) + if (g_ascii_strcasecmp(*tmp, item) == 0) return index; } diff --git a/src/core/misc.h b/src/core/misc.h index dd8bb14c..7e78d3b9 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -111,7 +111,6 @@ char *replace_chars(char *str, char from, char to); int strarray_length(char **array); /* return index of `item' in `array' or -1 if not found */ int strarray_find(char **array, const char *item); -int strarray_find_glob(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 f0549358..1b2ab1e2 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -459,12 +459,21 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) { g_return_val_if_fail(array != 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, dest->target); - int ret = strarray_find_glob(array, tagtarget); + 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;