-
Notifications
You must be signed in to change notification settings - Fork 372
Allow selection of what kind of activity targets to ignore v2 #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow selection of what kind of activity targets to ignore v2 #779
Conversation
src/fe-common/core/fe-common-core.c
Outdated
|
||
char **tmp; | ||
for (tmp = array; *tmp != NULL; tmp++) { | ||
char *tagtarget; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set this to NULL, otherwise it's uninitialized access down there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/fe-common/core/fe-common-core.c
Outdated
@@ -462,25 +462,73 @@ 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); | |||
WI_ITEM_REC *item = window_item_find_window(dest->window, dest->server, dest->target); | |||
int channel_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, together with query_type
, can be made static and moved to the top of the function since we don't expect those to change between invocations.
src/fe-common/core/fe-common-core.c
Outdated
@@ -462,25 +462,73 @@ 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); | |||
WI_ITEM_REC *item = window_item_find_window(dest->window, dest->server, dest->target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line assumes that:
dest
is notNULL
dest->window
is notNULL
dest->target
is notNULL
I don't know right off the bat how likely is to end up in those situations but I'd add some checks to avoid a nasty crash.
src/fe-common/core/fe-common-core.c
Outdated
g_free(tagtarget); | ||
if (ret != -1) | ||
return TRUE; | ||
if (item->type && item->type == channel_type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the item->type
check for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a perl-ism :P I'll add a check for not null
src/fe-common/core/fe-common-core.c
Outdated
|
||
if (strarray_find(array, "*") != -1) | ||
return TRUE; | ||
if (dest->server_tag != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you can just return FALSE
if server_tag == NULL
since without that you can't really match anything (beside the "bare" #
, =
and @
) and it'd allows to simplify the following code quite a bit.
Better ask @ailin-nemui @dequis
src/fe-common/core/fe-common-core.c
Outdated
g_free(tagtarget); | ||
} | ||
else if (item->type && item->type == query_type) { | ||
if (g_str_has_prefix(dest->target, "=")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you stare at the two branches of the if
you can see that the code is the same, minus the "=" vs "@".
Can you fold the two branches together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changed a lot since the last time I looked at it, nice. Haven't verified that it still does what it is intended to do.
src/fe-common/core/fe-common-core.c
Outdated
if (strarray_find(array, dest->target) != -1) | ||
return TRUE; | ||
for (tmp = array; *tmp != NULL; tmp++) { | ||
if (dest->server_tag != NULL && g_str_has_prefix(g_ascii_strdown(*tmp, -1), g_ascii_strdown(dest->server_tag, -1))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both g_ascii_strdown leak, consider g_ascii_strncasecmp() with the length parameter set to the short one
src/fe-common/core/fe-common-core.c
Outdated
return TRUE; | ||
for (tmp = array; *tmp != NULL; tmp++) { | ||
if (dest->server_tag != NULL && g_str_has_prefix(g_ascii_strdown(*tmp, -1), g_ascii_strdown(dest->server_tag, -1))) { | ||
*tmp = (g_strsplit(*tmp, "/", 2))[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g_strsplit leaks (requires g_strfreev), consider strchr() + null result check + add 1 to get the string after /
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, the cpp-namespace-ish syntax not so much :)
src/fe-common/core/fe-common-core.c
Outdated
if (strarray_find(array, "*") != -1) | ||
return TRUE; | ||
WI_ITEM_REC *item = window_item_find_window(dest->window, dest->server, dest->target); | ||
g_return_val_if_fail(item != NULL, FALSE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turn this into a plain check + return
, we use the g_return_val
form to assert the pre-conditions on the arguments
src/fe-common/core/fe-common-core.c
Outdated
if (*str == '\0') { | ||
continue; | ||
} | ||
if (dest->server_tag != NULL && (slash = strchr(str, '/'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// compute this only once outside the loop
int server_tag_len = dest->server_tag ? strlen(dest->server_tag) : 0;
...
if (server_tag_len && !g_ascii_strncasecmp(str, dest->server_tag, server_tag_len) && str[server_tag_len] == '/') {
str += server_tag_len + 1;
}
src/fe-common/core/fe-common-core.c
Outdated
return TRUE; | ||
for (tmp = array; *tmp != NULL; tmp++) { | ||
char *str = *tmp; | ||
if (*str == '\0') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
src/fe-common/core/fe-common-core.c
Outdated
int ret = strarray_find(array, tagtarget); | ||
g_free(tagtarget); | ||
if (ret != -1) | ||
if (g_strcmp0(str, "") == 0 || g_strcmp0(str, "::all") == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the !g_strcmp0
form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LemonBoy please don't confuse everybody, we use == 0 everywhere in Irssi
src/fe-common/core/fe-common-core.c
Outdated
return TRUE; | ||
} else if (item->type == query_type && | ||
(dest->target[0] == '=' ? | ||
g_strcmp0(str, "::dccqueries") == 0 : g_strcmp0(str, "::queries") == 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can shorten the code by swapping the ternary operator and the second argument to g_strcmp0
:
g_strcmp0(str, (dest->target[0] == '=') ? "::dccqueries: : "::queries")
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
LGTM, but I think another pair of eyes should have a look before it's merged |
@irssi/developers |
Syntax: