summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2015-08-14 21:25:27 +0200
committerSébastien Helleu <flashcode@flashtux.org>2015-08-14 21:25:27 +0200
commit15218ed294af2c1d0657e475539395e7862fd32c (patch)
tree0b8f3e3bf8e30b0e1dec85ab611453a15c63efcd /src/plugins/irc
parentbe3025f5699110c675951e5d4b50b1b5f1d54325 (diff)
downloadweechat-15218ed294af2c1d0657e475539395e7862fd32c.zip
irc: add option irc.network.channel_encode (issue #218, issue #482)
This is a workaround (disabled by default) to join and chat on ISO encoded channels (or another charset different from UTF-8). This option may be removed in future if a better solution is implemented.
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-config.c10
-rw-r--r--src/plugins/irc/irc-config.h1
-rw-r--r--src/plugins/irc/irc-info.c21
-rw-r--r--src/plugins/irc/irc-message.c53
-rw-r--r--src/plugins/irc/irc-message.h3
-rw-r--r--src/plugins/irc/irc-notify.c5
-rw-r--r--src/plugins/irc/irc-server.c32
7 files changed, 99 insertions, 26 deletions
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 5f9dfc451..1affe899f 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -135,6 +135,7 @@ struct t_config_option *irc_config_network_alternate_nick;
struct t_config_option *irc_config_network_autoreconnect_delay_growing;
struct t_config_option *irc_config_network_autoreconnect_delay_max;
struct t_config_option *irc_config_network_ban_mask_default;
+struct t_config_option *irc_config_network_channel_encode;
struct t_config_option *irc_config_network_colors_receive;
struct t_config_option *irc_config_network_colors_send;
struct t_config_option *irc_config_network_lag_check;
@@ -2971,6 +2972,15 @@ irc_config_init ()
"default mask is used only if WeeChat knows the host for the nick"),
NULL, 0, 0, "*!$ident@$host", NULL, 0, NULL, NULL,
NULL, NULL, NULL, NULL);
+ irc_config_network_channel_encode = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "channel_encode", "boolean",
+ N_("decode/encode channel name inside messages using charset options "
+ "(like it was done in WeeChat <= 1.2); it is recommended to keep "
+ "that off if you use only UTF-8 in channel names; you can enable "
+ "this option if you are using an exotic charset like ISO in "
+ "channel names"),
+ NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
irc_config_network_colors_receive = weechat_config_new_option (
irc_config_file, ptr_section,
"colors_receive", "boolean",
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index 4193ed1d8..cd0a766b5 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -176,6 +176,7 @@ extern struct t_config_option *irc_config_network_alternate_nick;
extern struct t_config_option *irc_config_network_autoreconnect_delay_growing;
extern struct t_config_option *irc_config_network_autoreconnect_delay_max;
extern struct t_config_option *irc_config_network_ban_mask_default;
+extern struct t_config_option *irc_config_network_channel_encode;
extern struct t_config_option *irc_config_network_colors_receive;
extern struct t_config_option *irc_config_network_colors_send;
extern struct t_config_option *irc_config_network_lag_check;
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c
index b235e1f50..f905a6a4b 100644
--- a/src/plugins/irc/irc-info.c
+++ b/src/plugins/irc/irc-info.c
@@ -844,11 +844,22 @@ irc_info_init ()
N_("parse an IRC message"),
N_("\"message\": IRC message, \"server\": server name (optional)"),
/* TRANSLATORS: please do not translate key names (enclosed by quotes) */
- N_("\"tags\": tags, \"message_without_tags\": message without the "
- "tags, \"nick\": nick, \"host\": host, \"command\": command, "
- "\"channel\": channel, \"arguments\": arguments (includes channel), "
- "\"text\": text (for example user message), \"pos_text\": index of "
- "text in message (\"-1\" if no text found)"),
+ N_("\"tags\": tags, "
+ "\"message_without_tags\": message without the tags, "
+ "\"nick\": nick, "
+ "\"host\": host, "
+ "\"command\": command, "
+ "\"channel\": channel, "
+ "\"arguments\": arguments (includes channel), "
+ "\"text\": text (for example user message), "
+ "\"pos_command\": index of \"command\" message (\"-1\" if "
+ "\"command\" was not found), "
+ "\"pos_arguments\": index of \"arguments\" message (\"-1\" if "
+ "\"arguments\" was not found), "
+ "\"pos_channel\": index of \"channel\" message (\"-1\" if "
+ "\"channel\" was not found), "
+ "\"pos_text\": index of \"text\" message (\"-1\" if "
+ "\"text\" was not found)"),
&irc_info_info_hashtable_irc_message_parse_cb, NULL);
weechat_hook_info_hashtable (
"irc_message_split",
diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c
index 855ac045e..e0c4dcf4f 100644
--- a/src/plugins/irc/irc-message.c
+++ b/src/plugins/irc/irc-message.c
@@ -39,6 +39,9 @@
* - channel (string)
* - arguments (string)
* - text (string)
+ * - pos_command (integer: command index in message)
+ * - pos_arguments (integer: arguments index in message)
+ * - pos_channel (integer: channel index in message)
* - pos_text (integer: text index in message)
*
* Example:
@@ -53,6 +56,9 @@
* channel: "#weechat"
* arguments: "#weechat :hello!"
* text: "hello!"
+ * pos_command: 47
+ * pos_arguments: 55
+ * pos_channel: 55
* pos_text: 65
*/
@@ -60,7 +66,9 @@ void
irc_message_parse (struct t_irc_server *server, const char *message,
char **tags, char **message_without_tags, char **nick,
char **host, char **command, char **channel,
- char **arguments, char **text, int *pos_text)
+ char **arguments, char **text,
+ int *pos_command, int *pos_arguments, int *pos_channel,
+ int *pos_text)
{
const char *ptr_message, *pos, *pos2, *pos3, *pos4;
@@ -80,6 +88,12 @@ irc_message_parse (struct t_irc_server *server, const char *message,
*arguments = NULL;
if (text)
*text = NULL;
+ if (pos_command)
+ *pos_command = -1;
+ if (pos_arguments)
+ *pos_arguments = -1;
+ if (pos_channel)
+ *pos_channel = -1;
if (pos_text)
*pos_text = -1;
@@ -166,6 +180,8 @@ irc_message_parse (struct t_irc_server *server, const char *message,
{
if (command)
*command = weechat_strndup (ptr_message, pos - ptr_message);
+ if (pos_command)
+ *pos_command = ptr_message - message;
pos++;
while (pos[0] == ' ')
{
@@ -174,6 +190,8 @@ irc_message_parse (struct t_irc_server *server, const char *message,
/* now we have: pos --> "#weechat :hello!" */
if (arguments)
*arguments = strdup (pos);
+ if (pos_arguments)
+ *pos_arguments = pos - message;
if ((pos[0] == ':')
&& ((strncmp (ptr_message, "JOIN ", 5) == 0)
|| (strncmp (ptr_message, "PART ", 5) == 0)))
@@ -199,6 +217,8 @@ irc_message_parse (struct t_irc_server *server, const char *message,
else
*channel = strdup (pos);
}
+ if (pos_channel)
+ *pos_channel = pos - message;
if (pos2)
{
while (pos2[0] == ' ')
@@ -241,6 +261,8 @@ irc_message_parse (struct t_irc_server *server, const char *message,
else
*channel = strdup (pos2);
}
+ if (pos_channel)
+ *pos_channel = pos2 - message;
if (pos4)
{
while (pos4[0] == ' ')
@@ -255,9 +277,13 @@ irc_message_parse (struct t_irc_server *server, const char *message,
*pos_text = pos4 - message;
}
}
- else if (channel && !*channel)
+ else if ((channel && !*channel)
+ || (pos_channel && (*pos_channel < 0)))
{
- *channel = weechat_strndup (pos, pos3 - pos);
+ if (channel)
+ *channel = weechat_strndup (pos, pos3 - pos);
+ if (pos_channel)
+ *pos_channel = pos - message;
}
}
}
@@ -267,6 +293,8 @@ irc_message_parse (struct t_irc_server *server, const char *message,
{
if (command)
*command = strdup (ptr_message);
+ if (pos_command)
+ *pos_command = ptr_message - message;
}
}
}
@@ -281,6 +309,9 @@ irc_message_parse (struct t_irc_server *server, const char *message,
* - channel
* - arguments
* - text
+ * - pos_command
+ * - pos_arguments
+ * - pos_channel
* - pos_text
*
* Note: hashtable must be freed after use.
@@ -291,14 +322,14 @@ irc_message_parse_to_hashtable (struct t_irc_server *server,
const char *message)
{
char *tags,*message_without_tags, *nick, *host, *command, *channel;
- char *arguments, *text, str_pos_text[32];
+ char *arguments, *text, str_pos[32];
char empty_str[1] = { '\0' };
- int pos_text;
+ int pos_command, pos_arguments, pos_channel, pos_text;
struct t_hashtable *hashtable;
irc_message_parse (server, message, &tags, &message_without_tags, &nick,
&host, &command, &channel, &arguments, &text,
- &pos_text);
+ &pos_command, &pos_arguments, &pos_channel, &pos_text);
hashtable = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
@@ -324,8 +355,14 @@ irc_message_parse_to_hashtable (struct t_irc_server *server,
(arguments) ? arguments : empty_str);
weechat_hashtable_set (hashtable, "text",
(text) ? text : empty_str);
- snprintf (str_pos_text, sizeof (str_pos_text), "%d", pos_text);
- weechat_hashtable_set (hashtable, "pos_text", str_pos_text);
+ snprintf (str_pos, sizeof (str_pos), "%d", pos_command);
+ weechat_hashtable_set (hashtable, "pos_command", str_pos);
+ snprintf (str_pos, sizeof (str_pos), "%d", pos_arguments);
+ weechat_hashtable_set (hashtable, "pos_arguments", str_pos);
+ snprintf (str_pos, sizeof (str_pos), "%d", pos_channel);
+ weechat_hashtable_set (hashtable, "pos_channel", str_pos);
+ snprintf (str_pos, sizeof (str_pos), "%d", pos_text);
+ weechat_hashtable_set (hashtable, "pos_text", str_pos);
if (tags)
free (tags);
diff --git a/src/plugins/irc/irc-message.h b/src/plugins/irc/irc-message.h
index bb3051d57..026595b7e 100644
--- a/src/plugins/irc/irc-message.h
+++ b/src/plugins/irc/irc-message.h
@@ -27,7 +27,8 @@ extern void irc_message_parse (struct t_irc_server *server, const char *message,
char **tags, char **message_without_tags,
char **nick, char **host, char **command,
char **channel, char **arguments, char **text,
- int *pos_text);
+ int *pos_command, int *pos_arguments,
+ int *pos_channel, int *pos_text);
extern struct t_hashtable *irc_message_parse_to_hashtable (struct t_irc_server *server,
const char *message);
extern char *irc_message_convert_charset (const char *message,
diff --git a/src/plugins/irc/irc-notify.c b/src/plugins/irc/irc-notify.c
index 653df5a11..cb9a2e590 100644
--- a/src/plugins/irc/irc-notify.c
+++ b/src/plugins/irc/irc-notify.c
@@ -835,7 +835,8 @@ irc_notify_hsignal_cb (void *data, const char *signal,
for (i = 0; i < num_messages; i++)
{
irc_message_parse (ptr_server, messages[i], NULL, NULL, NULL,
- NULL, NULL, NULL, &arguments, NULL, NULL);
+ NULL, NULL, NULL, &arguments, NULL, NULL,
+ NULL, NULL, NULL);
if (arguments)
{
pos = strchr (arguments, ' ');
@@ -918,7 +919,7 @@ irc_notify_hsignal_cb (void *data, const char *signal,
{
irc_message_parse (ptr_server, messages[0], NULL, NULL,
NULL, NULL, &irc_cmd, NULL, &arguments,
- NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL);
if (irc_cmd && arguments)
{
if (strcmp (irc_cmd, "401") == 0)
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 16fa9e104..83759ee53 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -2059,7 +2059,8 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
const char *ptr_msg, *ptr_chan_nick;
char *new_msg, *pos, *tags_to_send, *msg_encoded;
char str_modifier[128], modifier_data[256];
- int rc, queue_msg, add_to_queue, first_message, anti_flood, pos_text;
+ int rc, queue_msg, add_to_queue, first_message, anti_flood;
+ int pos_channel, pos_text, pos_encode;
time_t time_now;
struct t_irc_redirect *ptr_redirect;
@@ -2088,8 +2089,12 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
msg_encoded = NULL;
irc_message_parse (server, ptr_msg, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, &pos_text);
- if (pos_text >= 0)
+ NULL, NULL, NULL, NULL, &pos_channel, &pos_text);
+ if (weechat_config_boolean (irc_config_network_channel_encode))
+ pos_encode = (pos_channel >= 0) ? pos_channel : pos_text;
+ else
+ pos_encode = pos_text;
+ if (pos_encode >= 0)
{
ptr_chan_nick = (channel) ? channel : nick;
if (ptr_chan_nick)
@@ -2107,7 +2112,7 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
weechat_plugin->name,
server->name);
}
- msg_encoded = irc_message_convert_charset (ptr_msg, pos_text,
+ msg_encoded = irc_message_convert_charset (ptr_msg, pos_encode,
"charset_encode",
modifier_data);
}
@@ -2283,7 +2288,8 @@ irc_server_sendf (struct t_irc_server *server, int flags, const char *tags,
{
/* run modifier "irc_out1_xxx" (like "irc_out_xxx", but before split) */
irc_message_parse (server, items[i], NULL, NULL,
- &nick, NULL, &command, &channel, NULL, NULL, NULL);
+ &nick, NULL, &command, &channel, NULL, NULL, NULL,
+ NULL, NULL, NULL);
snprintf (str_modifier, sizeof (str_modifier),
"irc_out1_%s",
(command) ? command : "unknown");
@@ -2520,7 +2526,7 @@ irc_server_msgq_flush ()
char *tags, *nick, *host, *command, *channel, *arguments;
char *msg_decoded, *msg_decoded_without_color;
char str_modifier[128], modifier_data[256];
- int pos_text;
+ int pos_channel, pos_text, pos_decode;
while (irc_recv_msgq)
{
@@ -2542,7 +2548,8 @@ irc_server_msgq_flush ()
irc_message_parse (irc_recv_msgq->server,
ptr_data, NULL, NULL, NULL, NULL,
- &command, NULL, NULL, NULL, NULL);
+ &command, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL);
snprintf (str_modifier, sizeof (str_modifier),
"irc_in_%s",
(command) ? command : "unknown");
@@ -2583,10 +2590,15 @@ irc_server_msgq_flush ()
irc_message_parse (irc_recv_msgq->server, ptr_msg,
&tags, NULL, &nick, &host,
&command, &channel, &arguments,
- NULL, &pos_text);
+ NULL, NULL, NULL,
+ &pos_channel, &pos_text);
msg_decoded = NULL;
- if (pos_text >= 0)
+ if (weechat_config_boolean (irc_config_network_channel_encode))
+ pos_decode = (pos_channel >= 0) ? pos_channel : pos_text;
+ else
+ pos_decode = pos_text;
+ if (pos_decode >= 0)
{
/* convert charset for message */
if (channel
@@ -2620,7 +2632,7 @@ irc_server_msgq_flush ()
}
}
msg_decoded = irc_message_convert_charset (
- ptr_msg, pos_text,
+ ptr_msg, pos_decode,
"charset_decode", modifier_data);
}