summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-nick.c20
-rw-r--r--src/plugins/irc/irc-nick.h1
-rw-r--r--src/plugins/irc/irc-protocol.c51
-rw-r--r--src/plugins/irc/irc-server.c51
-rw-r--r--src/plugins/irc/irc-server.h9
-rw-r--r--src/plugins/irc/irc-upgrade.c3
6 files changed, 110 insertions, 25 deletions
diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c
index 95357dfad..3e8b55c25 100644
--- a/src/plugins/irc/irc-nick.c
+++ b/src/plugins/irc/irc-nick.c
@@ -184,6 +184,26 @@ irc_nick_set_prefixes (struct t_irc_server *server, struct t_irc_nick *nick,
}
/*
+ * Sets host for nick.
+ */
+
+void
+irc_nick_set_host (struct t_irc_nick *nick, const char *host)
+{
+ /* if host is the same, just return */
+ if ((!nick->host && !host)
+ || (nick->host && host && strcmp (nick->host, host) == 0))
+ {
+ return;
+ }
+
+ /* update the host in nick */
+ if (nick->host)
+ free (nick->host);
+ nick->host = (host) ? strdup (host) : NULL;
+}
+
+/*
* Checks if nick is "op" (or better than "op", for example channel admin or
* channel owner).
*
diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h
index fb00bd906..52316891d 100644
--- a/src/plugins/irc/irc-nick.h
+++ b/src/plugins/irc/irc-nick.h
@@ -50,6 +50,7 @@ extern int irc_nick_valid (struct t_irc_channel *channel,
extern int irc_nick_is_nick (const char *string);
extern char *irc_nick_find_color (const char *nickname);
extern char *irc_nick_find_color_name (const char *nickname);
+extern void irc_nick_set_host (struct t_irc_nick *nick, const char *host);
extern int irc_nick_is_op (struct t_irc_server *server,
struct t_irc_nick *nick);
extern int irc_nick_has_prefix_mode (struct t_irc_server *server,
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 5bc2cec5c..bb16477f9 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -831,8 +831,11 @@ IRC_PROTOCOL_CALLBACK(chghost)
weechat_prefix ("error"), IRC_PLUGIN_NAME, "chghost");
return WEECHAT_RC_OK;
}
-
snprintf (str_host, length, "%s@%s", argv[2], pos_new_host);
+
+ if (local_chghost)
+ irc_server_set_nick_host (server, str_host);
+
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
@@ -869,10 +872,7 @@ IRC_PROTOCOL_CALLBACK(chghost)
IRC_COLOR_CHAT_HOST,
str_host);
}
-
- if (ptr_nick->host)
- free (ptr_nick->host);
- ptr_nick->host = strdup (str_host);
+ irc_nick_set_host (ptr_nick, str_host);
}
}
@@ -1200,7 +1200,10 @@ IRC_PROTOCOL_CALLBACK(join)
}
if (local_join)
+ {
+ irc_server_set_nick_host (server, address);
irc_bar_item_update_channel ();
+ }
return WEECHAT_RC_OK;
}
@@ -1519,7 +1522,10 @@ IRC_PROTOCOL_CALLBACK(nick)
local_nick = (irc_server_strcasecmp (server, nick, server->nick) == 0) ? 1 : 0;
if (local_nick)
+ {
irc_server_set_nick (server, new_nick);
+ irc_server_set_nick_host (server, address);
+ }
ptr_nick_found = NULL;
@@ -1586,8 +1592,7 @@ IRC_PROTOCOL_CALLBACK(nick)
weechat_buffer_set (NULL, "hotlist", "-");
/* set host in nick if needed */
- if (!ptr_nick->host)
- ptr_nick->host = strdup (address);
+ irc_nick_set_host (ptr_nick, address);
/* change nick and display message on channel */
old_color = strdup (ptr_nick->color);
@@ -2224,8 +2229,7 @@ IRC_PROTOCOL_CALLBACK(privmsg)
/* other message */
ptr_nick = irc_nick_search (server, ptr_channel, nick);
- if (ptr_nick && !ptr_nick->host)
- ptr_nick->host = strdup (address);
+ irc_nick_set_host (ptr_nick, address);
if (status_msg[0])
{
@@ -4563,7 +4567,7 @@ IRC_PROTOCOL_CALLBACK(351)
IRC_PROTOCOL_CALLBACK(352)
{
- char *pos_attr, *pos_hopcount, *pos_realname;
+ char *pos_attr, *pos_hopcount, *pos_realname, *str_host;
int arg_start, length;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
@@ -4602,12 +4606,14 @@ IRC_PROTOCOL_CALLBACK(352)
/* update host in nick */
if (ptr_nick)
{
- if (ptr_nick->host)
- free (ptr_nick->host);
length = strlen (argv[4]) + 1 + strlen (argv[5]) + 1;
- ptr_nick->host = malloc (length);
- if (ptr_nick->host)
- snprintf (ptr_nick->host, length, "%s@%s", argv[4], argv[5]);
+ str_host = malloc (length);
+ if (str_host)
+ {
+ snprintf (str_host, length, "%s@%s", argv[4], argv[5]);
+ irc_nick_set_host (ptr_nick, str_host);
+ free (str_host);
+ }
}
/* update away flag in nick */
@@ -4822,7 +4828,7 @@ IRC_PROTOCOL_CALLBACK(353)
IRC_PROTOCOL_CALLBACK(354)
{
- char *pos_attr, *pos_hopcount, *pos_account, *pos_realname;
+ char *pos_attr, *pos_hopcount, *pos_account, *pos_realname, *str_host;
int length;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
@@ -4869,15 +4875,14 @@ IRC_PROTOCOL_CALLBACK(354)
/* update host in nick */
if (ptr_nick)
{
- if (ptr_nick->host)
+ length = strlen (argv[4]) + 1 + strlen (argv[5]) + 1;
+ str_host = malloc (length);
+ if (str_host)
{
- free (ptr_nick->host);
- ptr_nick->host = NULL;
+ snprintf (str_host, length, "%s@%s", argv[4], argv[5]);
+ irc_nick_set_host (ptr_nick, str_host);
+ free (str_host);
}
- length = strlen (argv[4]) + 1 + strlen (argv[5]) + 1;
- ptr_nick->host = malloc (length);
- if (ptr_nick->host)
- snprintf (ptr_nick->host, length, "%s@%s", argv[4], argv[5]);
}
/* update away flag in nick */
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index dfa74d88f..aa23ed56e 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -735,6 +735,14 @@ irc_server_set_nick (struct t_irc_server *server, const char *nick)
{
struct t_irc_channel *ptr_channel;
+ /* if nick is the same, just return */
+ if ((!server->nick && !nick)
+ || (server->nick && nick && strcmp (server->nick, nick) == 0))
+ {
+ return;
+ }
+
+ /* update the nick in server */
if (server->nick)
free (server->nick);
server->nick = (nick) ? strdup (nick) : NULL;
@@ -751,6 +759,37 @@ irc_server_set_nick (struct t_irc_server *server, const char *nick)
}
/*
+ * Sets nick host for server.
+ */
+
+void
+irc_server_set_nick_host (struct t_irc_server *server, const char *host)
+{
+ struct t_irc_channel *ptr_channel;
+
+ /* if host is the same, just return */
+ if ((!server->nick_host && !host)
+ || (server->nick_host && host && strcmp (server->nick_host, host) == 0))
+ {
+ return;
+ }
+
+ /* update the nick host in server */
+ if (server->nick_host)
+ free (server->nick_host);
+ server->nick_host = (host) ? strdup (host) : NULL;
+
+ /* set local variable "nick_host" for server and all channels/pv */
+ weechat_buffer_set (server->buffer, "localvar_set_nick_host", host);
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ weechat_buffer_set (ptr_channel->buffer,
+ "localvar_set_nick_host", host);
+ }
+}
+
+/*
* Gets index of nick in array "nicks_array".
*
* Returns index of nick in array, -1 if nick is not set or not found in
@@ -1335,6 +1374,7 @@ irc_server_alloc (const char *name)
new_server->nick_alternate_number = -1;
new_server->nick = NULL;
new_server->nick_modes = NULL;
+ new_server->nick_host = NULL;
new_server->checking_cap_ls = 0;
new_server->cap_ls = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
@@ -1862,6 +1902,8 @@ irc_server_free_data (struct t_irc_server *server)
free (server->nick);
if (server->nick_modes)
free (server->nick_modes);
+ if (server->nick_host)
+ free (server->nick_host);
if (server->isupport)
free (server->isupport);
if (server->prefix_modes)
@@ -5069,6 +5111,11 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address,
weechat_bar_item_update ("input_prompt");
weechat_bar_item_update ("irc_nick_modes");
}
+ if (server->nick_host)
+ {
+ free (server->nick_host);
+ server->nick_host = NULL;
+ }
server->checking_cap_ls = 0;
weechat_hashtable_remove_all (server->cap_ls);
server->checking_cap_list = 0;
@@ -5627,6 +5674,7 @@ 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, nick_host, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, checking_cap_ls, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_ls, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, checking_cap_list, INTEGER, 0, NULL, NULL);
@@ -5852,6 +5900,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, "nick_host", server->nick_host))
+ return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "checking_cap_ls", server->checking_cap_ls))
return 0;
if (!weechat_hashtable_add_to_infolist (server->cap_ls, ptr_item, "cap_ls"))
@@ -6238,6 +6288,7 @@ 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 (" nick_host. . . . . . : '%s'", ptr_server->nick_host);
weechat_log_printf (" checking_cap_ls. . . : %d", ptr_server->checking_cap_ls);
weechat_log_printf (" cap_ls . . . . . . . : 0x%lx (hashtable: '%s')",
ptr_server->cap_ls,
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 356d2821f..831ce14cd 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -192,6 +192,7 @@ struct t_irc_server
/* (nick____1, nick____2, ...) */
char *nick; /* current nickname */
char *nick_modes; /* nick modes */
+ char *nick_host; /* nick host (set if known) */
int checking_cap_ls; /* 1 if checking supported capabilities */
struct t_hashtable *cap_ls; /* list of supported capabilities */
int checking_cap_list; /* 1 if checking enabled capabilities */
@@ -290,8 +291,12 @@ extern int irc_server_sasl_enabled (struct t_irc_server *server);
extern char *irc_server_get_name_without_port (const char *name);
extern int irc_server_set_addresses (struct t_irc_server *server,
const char *addresses);
-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 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 void irc_server_set_nick_host (struct t_irc_server *server,
+ const char *nick_host);
extern const char *irc_server_get_alternate_nick (struct t_irc_server *server);
extern const char *irc_server_get_isupport_value (struct t_irc_server *server,
const char *feature);
diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c
index a769c164e..35082bab4 100644
--- a/src/plugins/irc/irc-upgrade.c
+++ b/src/plugins/irc/irc-upgrade.c
@@ -420,6 +420,9 @@ 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);
+ str = weechat_infolist_string (infolist, "nick_host");
+ if (str)
+ irc_upgrade_current_server->nick_host = strdup (str);
/*
* "cap_ls" and "cap_list" replace "cap_away_notify",
* "cap_account_notify" and "cap_extended_join"