summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-08-15 18:14:03 +0200
committerSébastien Helleu <flashcode@flashtux.org>2022-08-15 18:14:03 +0200
commite61441081520bcada6de699229ce9af241302665 (patch)
tree36a650c58231e206ef1d4a2c3c28d9c0140dc954 /src/plugins
parentfb14e67364f603723a48b3622ccf11c89efbe951 (diff)
downloadweechat-e61441081520bcada6de699229ce9af241302665.zip
irc: fix extract of isupport value when it is last in list and without value (closes #1807)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/irc-protocol.c16
-rw-r--r--src/plugins/irc/irc-server.c67
2 files changed, 43 insertions, 40 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 5c1b314c2..3724c1216 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -3676,7 +3676,7 @@ IRC_PROTOCOL_CALLBACK(001)
IRC_PROTOCOL_CALLBACK(005)
{
- char *str_info, *error, *isupport2, *pos_start;
+ char *str_info, *error, *isupport2;
int i, arg_last, length_isupport, length, casemapping, utf8mapping;
long value;
@@ -3764,7 +3764,6 @@ IRC_PROTOCOL_CALLBACK(005)
str_info = irc_protocol_string_params (params, 1, arg_last);
if (str_info && str_info[0])
{
- pos_start = NULL;
length = strlen (str_info);
if (server->isupport)
{
@@ -3777,20 +3776,13 @@ IRC_PROTOCOL_CALLBACK(005)
if (isupport2)
{
server->isupport = isupport2;
- pos_start = server->isupport + length_isupport;
+ strcat (server->isupport, " ");
+ strcat (server->isupport, str_info);
}
}
else
{
- server->isupport = malloc (1 + length + 1);
- if (server->isupport)
- pos_start = server->isupport;
- }
- if (pos_start)
- {
- pos_start[0] = ' ';
- memcpy (pos_start + 1, str_info, length);
- pos_start[length + 1] = '\0';
+ server->isupport = strdup (str_info);
}
}
if (str_info)
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index a0f8acfe3..143d78d71 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -986,40 +986,51 @@ irc_server_get_alternate_nick (struct t_irc_server *server)
const char *
irc_server_get_isupport_value (struct t_irc_server *server, const char *feature)
{
- char feature2[64], *pos_feature, *pos_equal, *pos_space;
- int length;
+ const char *ptr_string, *pos_space;
+ int length, length_feature;
static char value[256];
- if (!server || !server->isupport || !feature)
+ if (!server || !server->isupport || !feature || !feature[0])
return NULL;
- /* search feature with value */
- snprintf (feature2, sizeof (feature2), " %s=", feature);
- pos_feature = strstr (server->isupport, feature2);
- if (pos_feature)
- {
- /* feature found with value, return value */
- pos_feature++;
- pos_equal = strchr (pos_feature, '=');
- pos_space = strchr (pos_feature, ' ');
- if (pos_space)
- length = pos_space - pos_equal - 1;
- else
- length = strlen (pos_equal) + 1;
- if (length > (int)sizeof (value) - 1)
- length = (int)sizeof (value) - 1;
- memcpy (value, pos_equal + 1, length);
- value[length] = '\0';
- return value;
- }
+ length_feature = strlen (feature);
- /* search feature without value */
- feature2[strlen (feature2) - 1] = ' ';
- pos_feature = strstr (server->isupport, feature2);
- if (pos_feature)
+ ptr_string = server->isupport;
+ while (ptr_string && ptr_string[0])
{
- value[0] = '\0';
- return value;
+ if (strncmp (ptr_string, feature, length_feature) == 0)
+ {
+ switch (ptr_string[length_feature])
+ {
+ case '=':
+ /* feature found with value, return value */
+ ptr_string += length_feature + 1;
+ pos_space = strchr (ptr_string, ' ');
+ if (pos_space)
+ length = pos_space - ptr_string;
+ else
+ length = strlen (ptr_string);
+ if (length > (int)sizeof (value) - 1)
+ length = (int)sizeof (value) - 1;
+ memcpy (value, ptr_string, length);
+ value[length] = '\0';
+ return value;
+ case ' ':
+ case '\0':
+ /* feature found without value, return empty string */
+ value[0] = '\0';
+ return value;
+ }
+ }
+ /* find start of next item */
+ pos_space = strchr (ptr_string, ' ');
+ if (!pos_space)
+ break;
+ ptr_string = pos_space + 1;
+ while (ptr_string[0] == ' ')
+ {
+ ptr_string++;
+ }
}
/* feature not found in isupport */