mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 06:16:40 +02:00
Add isupport value in IRC servers (content of IRC message 005), with new infos: irc_server_isupport and irc_server_isupport_value
This commit is contained in:
@@ -67,7 +67,7 @@ irc_info_get_info_cb (void *data, const char *info_name,
|
||||
const char *arguments)
|
||||
{
|
||||
char *pos_comma, *pos_comma2, *server, *channel, *host;
|
||||
const char *nick;
|
||||
const char *nick, *isupport_value;
|
||||
static char str_true[2] = "1";
|
||||
struct t_irc_server *ptr_server;
|
||||
struct t_irc_channel *ptr_channel;
|
||||
@@ -180,6 +180,46 @@ irc_info_get_info_cb (void *data, const char *info_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (weechat_strcasecmp (info_name, "irc_server_isupport") == 0)
|
||||
{
|
||||
isupport_value = NULL;
|
||||
pos_comma = strchr (arguments, ',');
|
||||
if (pos_comma)
|
||||
{
|
||||
server = weechat_strndup (arguments, pos_comma - arguments);
|
||||
if (server)
|
||||
{
|
||||
ptr_server = irc_server_search (server);
|
||||
if (ptr_server)
|
||||
{
|
||||
isupport_value = irc_server_get_isupport_value (ptr_server,
|
||||
pos_comma + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isupport_value)
|
||||
return str_true;
|
||||
return NULL;
|
||||
}
|
||||
else if (weechat_strcasecmp (info_name, "irc_server_isupport_value") == 0)
|
||||
{
|
||||
isupport_value = NULL;
|
||||
pos_comma = strchr (arguments, ',');
|
||||
if (pos_comma)
|
||||
{
|
||||
server = weechat_strndup (arguments, pos_comma - arguments);
|
||||
if (server)
|
||||
{
|
||||
ptr_server = irc_server_search (server);
|
||||
if (ptr_server)
|
||||
{
|
||||
isupport_value = irc_server_get_isupport_value (ptr_server,
|
||||
pos_comma + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return isupport_value;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -422,6 +462,12 @@ irc_info_init ()
|
||||
weechat_hook_info ("irc_buffer", N_("get buffer pointer for an IRC server/channel/nick"),
|
||||
N_("server,channel,nick (channel and nicks are optional)"),
|
||||
&irc_info_get_info_cb, NULL);
|
||||
weechat_hook_info ("irc_server_isupport", N_("1 if server supports this feature (from IRC message 005)"),
|
||||
N_("server,feature"),
|
||||
&irc_info_get_info_cb, NULL);
|
||||
weechat_hook_info ("irc_server_isupport_value", N_("value of feature, if supported by server (from IRC message 005)"),
|
||||
N_("server,feature"),
|
||||
&irc_info_get_info_cb, NULL);
|
||||
|
||||
/* infolist hooks */
|
||||
weechat_hook_infolist ("irc_server", N_("list of IRC servers"),
|
||||
|
||||
@@ -1868,7 +1868,8 @@ IRC_PROTOCOL_CALLBACK(001)
|
||||
|
||||
IRC_PROTOCOL_CALLBACK(005)
|
||||
{
|
||||
char *pos, *pos2;
|
||||
char *pos, *pos2, *pos_start;
|
||||
int length_isupport, length;
|
||||
|
||||
/*
|
||||
* 005 message looks like:
|
||||
@@ -1883,7 +1884,8 @@ IRC_PROTOCOL_CALLBACK(005)
|
||||
irc_protocol_cb_numeric (server,
|
||||
nick, address, host, command,
|
||||
ignored, argc, argv, argv_eol);
|
||||
|
||||
|
||||
/* save prefix */
|
||||
pos = strstr (argv_eol[3], "PREFIX=");
|
||||
if (pos)
|
||||
{
|
||||
@@ -1898,6 +1900,33 @@ IRC_PROTOCOL_CALLBACK(005)
|
||||
pos2[0] = ' ';
|
||||
}
|
||||
|
||||
/* save whole message (concatenate to existing isupport, if any) */
|
||||
pos_start = NULL;
|
||||
pos = strstr (argv_eol[3], " :");
|
||||
length = (pos) ? pos - argv_eol[3] : (int)strlen (argv_eol[3]);
|
||||
if (server->isupport)
|
||||
{
|
||||
length_isupport = strlen (server->isupport);
|
||||
server->isupport = realloc (server->isupport,
|
||||
length_isupport + /* existing */
|
||||
1 + length + 1); /* new */
|
||||
if (server->isupport)
|
||||
pos_start = server->isupport + length_isupport;
|
||||
}
|
||||
else
|
||||
{
|
||||
server->isupport = malloc (1 + length + 1);
|
||||
if (server->isupport)
|
||||
pos_start = server->isupport;
|
||||
}
|
||||
|
||||
if (pos_start)
|
||||
{
|
||||
pos_start[0] = ' ';
|
||||
memcpy (pos_start + 1, argv_eol[3], length);
|
||||
pos_start[length + 1] = '\0';
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -297,6 +297,57 @@ irc_server_get_nick_index (struct t_irc_server *server)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_server_get_isupport_value: return value of an item in "isupport" (copy
|
||||
* of IRC message 005)
|
||||
* if featureis found but has no value, empty
|
||||
* string is returned
|
||||
* if feature is not found, NULL is returned
|
||||
*/
|
||||
|
||||
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;
|
||||
static char value[256];
|
||||
|
||||
if (!server || !server->isupport || !feature)
|
||||
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;
|
||||
}
|
||||
|
||||
/* search feature without value */
|
||||
feature2[strlen (feature2) - 1] = ' ';
|
||||
pos_feature = strstr (server->isupport, feature2);
|
||||
if (pos_feature)
|
||||
{
|
||||
value[0] = '\0';
|
||||
return value;
|
||||
}
|
||||
|
||||
/* feature not found in isupport */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_server_alloc: allocate a new server and add it to the servers queue
|
||||
*/
|
||||
@@ -355,6 +406,7 @@ irc_server_alloc (const char *name)
|
||||
new_server->nick_first_tried = 0;
|
||||
new_server->nick = NULL;
|
||||
new_server->nick_modes = NULL;
|
||||
new_server->isupport = NULL;
|
||||
new_server->prefix = NULL;
|
||||
new_server->reconnect_delay = 0;
|
||||
new_server->reconnect_start = 0;
|
||||
@@ -754,6 +806,8 @@ irc_server_free_data (struct t_irc_server *server)
|
||||
free (server->nick);
|
||||
if (server->nick_modes)
|
||||
free (server->nick_modes);
|
||||
if (server->isupport)
|
||||
free (server->isupport);
|
||||
if (server->prefix)
|
||||
free (server->prefix);
|
||||
if (server->away_message)
|
||||
@@ -2965,6 +3019,11 @@ irc_server_disconnect (struct t_irc_server *server, int reconnect)
|
||||
server->nick_modes = NULL;
|
||||
weechat_bar_item_update ("input_prompt");
|
||||
}
|
||||
if (server->isupport)
|
||||
{
|
||||
free (server->isupport);
|
||||
server->isupport = NULL;
|
||||
}
|
||||
if (server->prefix)
|
||||
{
|
||||
free (server->prefix);
|
||||
@@ -3553,6 +3612,8 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "nick_modes", server->nick_modes))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "isupport", server->isupport))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "prefix", server->prefix))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay))
|
||||
@@ -3791,6 +3852,7 @@ irc_server_print_log ()
|
||||
weechat_log_printf (" nick_first_tried . . : %d", ptr_server->nick_first_tried);
|
||||
weechat_log_printf (" nick . . . . . . . . : '%s'", ptr_server->nick);
|
||||
weechat_log_printf (" nick_modes . . . . . : '%s'", ptr_server->nick_modes);
|
||||
weechat_log_printf (" isupport . . . . . . : '%s'", ptr_server->isupport);
|
||||
weechat_log_printf (" prefix . . . . . . . : '%s'", ptr_server->prefix);
|
||||
weechat_log_printf (" reconnect_delay. . . : %d", ptr_server->reconnect_delay);
|
||||
weechat_log_printf (" reconnect_start. . . : %ld", ptr_server->reconnect_start);
|
||||
|
||||
@@ -137,6 +137,7 @@ struct t_irc_server
|
||||
/* when (re-)connecting to server */
|
||||
char *nick; /* current nickname */
|
||||
char *nick_modes; /* nick modes */
|
||||
char *isupport; /* copy of message 005 (ISUPPORT) */
|
||||
char *prefix; /* nick prefix allowed (from msg 005) */
|
||||
int reconnect_delay; /* current reconnect delay (growing) */
|
||||
time_t reconnect_start; /* this time + delay = reconnect time */
|
||||
@@ -190,6 +191,8 @@ extern void irc_server_set_addresses (struct t_irc_server *server,
|
||||
extern void irc_server_set_nicks (struct t_irc_server *server, const char *nicks);
|
||||
extern void irc_server_set_nick (struct t_irc_server *server, const char *nick);
|
||||
extern int irc_server_get_nick_index (struct t_irc_server *server);
|
||||
extern const char *irc_server_get_isupport_value (struct t_irc_server *server,
|
||||
const char *feature);
|
||||
extern struct t_irc_server *irc_server_alloc (const char *name);
|
||||
extern int irc_server_alloc_with_url (const char *irc_url);
|
||||
extern void irc_server_apply_command_line_options (struct t_irc_server *server,
|
||||
|
||||
@@ -253,6 +253,9 @@ irc_upgrade_read_cb (void *data,
|
||||
str = weechat_infolist_string (infolist, "nick_modes");
|
||||
if (str)
|
||||
irc_upgrade_current_server->nick_modes = strdup (str);
|
||||
str = weechat_infolist_string (infolist, "isupport");
|
||||
if (str)
|
||||
irc_upgrade_current_server->isupport = strdup (str);
|
||||
str = weechat_infolist_string (infolist, "prefix");
|
||||
if (str)
|
||||
irc_upgrade_current_server->prefix = strdup (str);
|
||||
|
||||
Reference in New Issue
Block a user