1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 13:56:37 +02:00

irc: add hashtables to keep track of all capabilities

This commit is contained in:
Simmo Saan
2015-12-13 10:45:11 +02:00
parent 48a3baedd5
commit 453434644a
6 changed files with 49 additions and 51 deletions
+2 -2
View File
@@ -689,8 +689,8 @@ irc_channel_check_whox (struct t_irc_server *server,
{
if ((channel->type == IRC_CHANNEL_TYPE_CHANNEL) && channel->nicks)
{
if (server->cap_away_notify
|| server->cap_account_notify
if (weechat_hashtable_has_key (server->cap_list, "away-notify")
|| weechat_hashtable_has_key (server->cap_list, "account-notify")
|| ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK) > 0)
&& ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS) == 0)
|| (channel->nicks_count <= IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS)))))
+1 -1
View File
@@ -755,7 +755,7 @@ irc_nick_set_away (struct t_irc_server *server, struct t_irc_channel *channel,
struct t_irc_nick *nick, int is_away)
{
if (!is_away
|| server->cap_away_notify
|| weechat_hashtable_has_key (server->cap_list, "away-notify")
|| ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK) > 0)
&& ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS) == 0)
|| (channel->nicks_count <= IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS)))))
+12 -25
View File
@@ -207,11 +207,14 @@ IRC_PROTOCOL_CALLBACK(account)
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
char *pos_account;
int cap_account_notify;
IRC_PROTOCOL_MIN_ARGS(3);
pos_account = (strcmp (argv[2], "*") != 0) ? argv[2] : NULL;
cap_account_notify = weechat_hashtable_has_key (server->cap_list, "account-notify");
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
@@ -220,7 +223,7 @@ IRC_PROTOCOL_CALLBACK(account)
{
if (ptr_nick->account)
free (ptr_nick->account);
ptr_nick->account = (server->cap_account_notify && pos_account) ?
ptr_nick->account = (cap_account_notify && pos_account) ?
strdup (pos_account) : NULL;
}
}
@@ -478,23 +481,13 @@ IRC_PROTOCOL_CALLBACK(cap)
{
for (i = 0; i < num_caps_supported; i++)
{
weechat_hashtable_set (server->cap_list, caps_supported[i], NULL);
if (strcmp (caps_supported[i], "sasl") == 0)
{
sasl_to_do = 1;
break;
}
else if (strcmp (caps_supported[i], "away-notify") == 0)
{
server->cap_away_notify = 1;
}
else if (strcmp (caps_supported[i], "account-notify") == 0)
{
server->cap_account_notify = 1;
}
else if (strcmp (caps_supported[i], "extended-join") == 0)
{
server->cap_extended_join = 1;
}
}
weechat_string_free_split (caps_supported);
}
@@ -620,14 +613,7 @@ IRC_PROTOCOL_CALLBACK(cap)
{
for (i = 0; i < num_caps_removed; i++)
{
if (strcmp (caps_removed[i], "away-notify") == 0)
{
server->cap_away_notify = 0;
}
else if (strcmp (caps_removed[i], "account-notify") == 0)
{
server->cap_account_notify = 0;
}
weechat_hashtable_remove (server->cap_list, caps_removed[i]);
}
weechat_string_free_split (caps_removed);
}
@@ -4229,7 +4215,8 @@ IRC_PROTOCOL_CALLBACK(352)
{
if (ptr_nick->realname)
free (ptr_nick->realname);
ptr_nick->realname = (pos_realname && server->cap_extended_join) ?
ptr_nick->realname = (pos_realname &&
weechat_hashtable_has_key (server->cap_list, "extended-join")) ?
strdup (pos_realname) : NULL;
}
@@ -4456,7 +4443,7 @@ IRC_PROTOCOL_CALLBACK(354)
if (ptr_channel && ptr_nick)
{
if (pos_attr
&& (server->cap_away_notify
&& (weechat_hashtable_has_key (server->cap_list, "away-notify")
|| ((IRC_SERVER_OPTION_INTEGER(
server, IRC_SERVER_OPTION_AWAY_CHECK) > 0)
&& ((IRC_SERVER_OPTION_INTEGER(
@@ -4479,7 +4466,7 @@ IRC_PROTOCOL_CALLBACK(354)
if (ptr_nick->account)
free (ptr_nick->account);
ptr_nick->account = (ptr_channel && pos_account
&& server->cap_account_notify) ?
&& weechat_hashtable_has_key (server->cap_list, "account-notify")) ?
strdup (pos_account) : NULL;
}
@@ -4489,7 +4476,7 @@ IRC_PROTOCOL_CALLBACK(354)
if (ptr_nick->realname)
free (ptr_nick->realname);
ptr_nick->realname = (ptr_channel && pos_realname
&& server->cap_extended_join) ?
&& weechat_hashtable_has_key (server->cap_list, "extended-join")) ?
strdup (pos_realname) : NULL;
}
+23 -17
View File
@@ -1167,9 +1167,16 @@ irc_server_alloc (const char *name)
new_server->nick_alternate_number = -1;
new_server->nick = NULL;
new_server->nick_modes = NULL;
new_server->cap_away_notify = 0;
new_server->cap_account_notify = 0;
new_server->cap_extended_join = 0;
new_server->cap_ls = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
new_server->cap_list = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
new_server->isupport = NULL;
new_server->prefix_modes = NULL;
new_server->prefix_chars = NULL;
@@ -3216,7 +3223,7 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
/* check away (only if lag check was not done) */
away_check = IRC_SERVER_OPTION_INTEGER(
ptr_server, IRC_SERVER_OPTION_AWAY_CHECK);
if (!ptr_server->cap_away_notify
if (!weechat_hashtable_has_key (ptr_server->cap_list, "away-notify")
&& (away_check > 0)
&& ((ptr_server->last_away_check == 0)
|| (current_time >= ptr_server->last_away_check + (away_check * 60))))
@@ -4889,9 +4896,8 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address,
weechat_bar_item_update ("input_prompt");
weechat_bar_item_update ("irc_nick_modes");
}
server->cap_away_notify = 0;
server->cap_account_notify = 0;
server->cap_extended_join = 0;
weechat_hashtable_remove_all (server->cap_ls);
weechat_hashtable_remove_all (server->cap_list);
server->is_away = 0;
server->away_time = 0;
server->lag = 0;
@@ -5440,9 +5446,8 @@ irc_server_hdata_server_cb (const void *pointer, void *data,
WEECHAT_HDATA_VAR(struct t_irc_server, nick_alternate_number, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, nick, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, nick_modes, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_away_notify, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_account_notify, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_extended_join, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_ls, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_list, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, isupport, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, prefix_modes, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, prefix_chars, STRING, 0, NULL, NULL);
@@ -5664,11 +5669,9 @@ 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_integer (ptr_item, "cap_away_notify", server->cap_away_notify))
if (!weechat_hashtable_add_to_infolist (server->cap_ls, ptr_item, "cap_ls"))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "cap_account_notify", server->cap_account_notify))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "cap_extended_join", server->cap_extended_join))
if (!weechat_hashtable_add_to_infolist (server->cap_list, ptr_item, "cap_list"))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "isupport", server->isupport))
return 0;
@@ -6048,9 +6051,12 @@ irc_server_print_log ()
weechat_log_printf (" nick_alternate_number: %d", ptr_server->nick_alternate_number);
weechat_log_printf (" nick . . . . . . . . : '%s'", ptr_server->nick);
weechat_log_printf (" nick_modes . . . . . : '%s'", ptr_server->nick_modes);
weechat_log_printf (" cap_away_notify. . . : %d", ptr_server->cap_away_notify);
weechat_log_printf (" cap_account_notify . : %d", ptr_server->cap_account_notify);
weechat_log_printf (" cap_extended_join. . : %d", ptr_server->cap_extended_join);
weechat_log_printf (" cap_ls . . . . . . . : 0x%lx (hashtable: '%s')",
ptr_server->cap_ls,
weechat_hashtable_get_string (ptr_server->cap_ls, "keys_values"));
weechat_log_printf (" cap_list . . . . . . : 0x%lx (hashtable: '%s')",
ptr_server->cap_list,
weechat_hashtable_get_string (ptr_server->cap_list, "keys_values"));
weechat_log_printf (" isupport . . . . . . : '%s'", ptr_server->isupport);
weechat_log_printf (" prefix_modes . . . . : '%s'", ptr_server->prefix_modes);
weechat_log_printf (" prefix_chars . . . . : '%s'", ptr_server->prefix_chars);
+2 -3
View File
@@ -188,9 +188,8 @@ struct t_irc_server
/* (nick____1, nick____2, ...) */
char *nick; /* current nickname */
char *nick_modes; /* nick modes */
int cap_away_notify; /* 1 if capability away-notify is enabled*/
int cap_account_notify; /* 1 if CAP account-notify is enabled */
int cap_extended_join; /* 1 if CAP extended-join is enabled */
struct t_hashtable *cap_ls; /* list of supported capabilities */
struct t_hashtable *cap_list; /* list of enabled capabilities */
char *isupport; /* copy of message 005 (ISUPPORT) */
char *prefix_modes; /* prefix modes from msg 005 (eg "ohv") */
char *prefix_chars; /* prefix chars from msg 005 (eg "@%+") */
+9 -3
View File
@@ -375,9 +375,15 @@ irc_upgrade_read_cb (const void *pointer, void *data,
str = weechat_infolist_string (infolist, "nick_modes");
if (str)
irc_upgrade_current_server->nick_modes = strdup (str);
irc_upgrade_current_server->cap_away_notify = weechat_infolist_integer (infolist, "cap_away_notify");
irc_upgrade_current_server->cap_account_notify = weechat_infolist_integer (infolist, "cap_account_notify");
irc_upgrade_current_server->cap_extended_join = weechat_infolist_integer (infolist, "cap_extended_join");
/* TODO: "cap_list" is new in WeeChat x.y.z */
if (weechat_infolist_integer (infolist, "cap_away_notify"))
weechat_hashtable_set (irc_upgrade_current_server->cap_list, "away-notify", NULL);
if (weechat_infolist_integer (infolist, "cap_account_notify"))
weechat_hashtable_set (irc_upgrade_current_server->cap_list, "account-notify", NULL);
if (weechat_infolist_integer (infolist, "cap_extended_join"))
weechat_hashtable_set (irc_upgrade_current_server->cap_list, "extended-join", NULL);
/* TODO: transfer all of "cap_ls" and "cap_list" */
str = weechat_infolist_string (infolist, "isupport");
if (str)
irc_upgrade_current_server->isupport = strdup (str);