summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2004-08-20 00:03:40 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2004-08-20 00:03:40 +0000
commit226a567562cf1f9a95ea08383838e11c20fb98c3 (patch)
tree484a82b46cf0ae9e93002b567c8dd43e70fefaf8 /src/irc
parent924ac8f91f87d9034dedb711ec33fe714f91a860 (diff)
downloadirssi-226a567562cf1f9a95ea08383838e11c20fb98c3.zip
Recode patch by decadix/senneth
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3283 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/core/channel-events.c10
-rw-r--r--src/irc/core/irc-commands.c76
-rw-r--r--src/irc/proxy/dump.c4
-rw-r--r--src/irc/proxy/listen.c15
4 files changed, 80 insertions, 25 deletions
diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c
index edaa3f9e..ac71e85f 100644
--- a/src/irc/core/channel-events.c
+++ b/src/irc/core/channel-events.c
@@ -23,6 +23,7 @@
#include "misc.h"
#include "channels-setup.h"
#include "settings.h"
+#include "recode.h"
#include "irc-servers.h"
#include "irc-channels.h"
@@ -136,13 +137,16 @@ static void channel_change_topic(IRC_SERVER_REC *server, const char *channel,
time_t settime)
{
CHANNEL_REC *chanrec;
-
+ char *recoded = NULL;
+
chanrec = channel_find(SERVER(server), channel);
if (chanrec == NULL) return;
-
+ /* the topic may be send out encoded, so we need to
+ recode it back or /topic <tab> will not work properly */
+ recoded = recode_in(topic, channel);
if (topic != NULL) {
g_free_not_null(chanrec->topic);
- chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
+ chanrec->topic = recoded == NULL ? NULL : g_strdup(recoded);
}
g_free_not_null(chanrec->topic_by);
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index d398a4e7..bdd45d3b 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -20,6 +20,7 @@
#include "module.h"
#include "misc.h"
+#include "recode.h"
#include "special-vars.h"
#include "settings.h"
#include "window-item-def.h"
@@ -63,6 +64,7 @@ static void cmd_notice(const char *data, IRC_SERVER_REC *server,
WI_ITEM_REC *item)
{
const char *target, *msg;
+ char *recoded;
void *free_arg;
CMD_IRC_SERVER(server);
@@ -75,7 +77,10 @@ static void cmd_notice(const char *data, IRC_SERVER_REC *server,
if (*target == '\0' || *msg == '\0')
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- g_string_sprintf(tmpstr, "NOTICE %s :%s", target, msg);
+ recoded = recode_out(msg, target);
+ g_string_sprintf(tmpstr, "NOTICE %s :%s", target, recoded);
+ g_free(recoded);
+
irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);
cmd_params_free(free_arg);
@@ -102,8 +107,14 @@ static void cmd_ctcp(const char *data, IRC_SERVER_REC *server,
g_strup(ctcpcmd);
if (*ctcpdata == '\0')
g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s\001", target, ctcpcmd);
- else
- g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s %s\001", target, ctcpcmd, ctcpdata);
+ else {
+ char *recoded;
+
+ recoded = recode_out(ctcpdata, target);
+ g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s %s\001", target, ctcpcmd, recoded);
+ g_free(recoded);
+ }
+
irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);
cmd_params_free(free_arg);
@@ -114,7 +125,7 @@ static void cmd_nctcp(const char *data, IRC_SERVER_REC *server,
WI_ITEM_REC *item)
{
const char *target;
- char *ctcpcmd, *ctcpdata;
+ char *ctcpcmd, *ctcpdata, *recoded;
void *free_arg;
CMD_IRC_SERVER(server);
@@ -128,7 +139,10 @@ static void cmd_nctcp(const char *data, IRC_SERVER_REC *server,
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
g_strup(ctcpcmd);
- g_string_sprintf(tmpstr, "NOTICE %s :\001%s %s\001", target, ctcpcmd, ctcpdata);
+ recoded = recode_out(ctcpdata, target);
+ g_string_sprintf(tmpstr, "NOTICE %s :\001%s %s\001", target, ctcpcmd, recoded);
+ g_free(recoded);
+
irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);
cmd_params_free(free_arg);
@@ -139,6 +153,7 @@ static void cmd_part(const char *data, IRC_SERVER_REC *server,
WI_ITEM_REC *item)
{
char *channame, *msg;
+ char *recoded = NULL;
void *free_arg;
CMD_IRC_SERVER(server);
@@ -153,16 +168,19 @@ static void cmd_part(const char *data, IRC_SERVER_REC *server,
if (server->cmdcount > MAX_COMMANDS_ON_PART_UNTIL_PURGE)
irc_server_purge_output(server, channame);
- irc_send_cmdv(server, *msg == '\0' ? "PART %s" : "PART %s :%s",
- channame, msg);
+ if (*msg != '\0')
+ recoded = recode_out(msg, channame);
+ irc_send_cmdv(server, ! recoded ? "PART %s" : "PART %s :%s",
+ channame, recoded);
+ g_free(recoded);
cmd_params_free(free_arg);
}
/* SYNTAX: KICK [<channel>] <nicks> [<reason>] */
static void cmd_kick(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
- char *channame, *nicks, *reason;
+ char *channame, *nicks, *reason, *recoded;
void *free_arg;
CMD_IRC_SERVER(server);
@@ -175,7 +193,10 @@ static void cmd_kick(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item
if (*channame == '\0' || *nicks == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (!ischannel(*channame)) cmd_param_error(CMDERR_NOT_JOINED);
- g_string_sprintf(tmpstr, "KICK %s %s :%s", channame, nicks, reason);
+ recoded = recode_out(reason, channame);
+ g_string_sprintf(tmpstr, "KICK %s %s :%s", channame, nicks, recoded);
+ g_free(recoded);
+
irc_send_cmd_split(server, tmpstr->str, 3, server->max_kicks_in_cmd);
cmd_params_free(free_arg);
@@ -186,6 +207,7 @@ static void cmd_topic(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *ite
{
GHashTable *optlist;
char *channame, *topic;
+ char *recoded = NULL;
void *free_arg;
CMD_IRC_SERVER(server);
@@ -195,9 +217,11 @@ static void cmd_topic(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *ite
item, "topic", &optlist, &channame, &topic))
return;
- irc_send_cmdv(server, *topic == '\0' &&
- g_hash_table_lookup(optlist, "delete") == NULL ?
- "TOPIC %s" : "TOPIC %s :%s", channame, topic);
+ if (*topic != '\0' || g_hash_table_lookup(optlist, "delete") != NULL)
+ recoded = recode_out(topic, channame);
+ irc_send_cmdv(server, recoded == NULL ? "TOPIC %s" : "TOPIC %s :%s",
+ channame, recoded);
+ g_free(recoded);
cmd_params_free(free_arg);
}
@@ -619,7 +643,7 @@ static void cmd_wait(const char *data, IRC_SERVER_REC *server)
/* SYNTAX: WALL [<channel>] <message> */
static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
- char *channame, *msg, *args;
+ char *channame, *msg, *args, *recoded;
void *free_arg;
IRC_CHANNEL_REC *chanrec;
GSList *tmp, *nicks;
@@ -649,14 +673,18 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item
SERVER(server), item, args, NULL, 0);
g_free(args);
+ recoded = recode_out(msg, channame);
+
for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
NICK_REC *rec = tmp->data;
if (rec != chanrec->ownnick) {
irc_send_cmdv(server, "NOTICE %s :%s",
- rec->nick, msg);
+ rec->nick, recoded);
}
}
+
+ g_free(recoded);
g_free(msg);
g_slist_free(nicks);
}
@@ -669,7 +697,7 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item
and it supports NOTICE @#channel anyway */
static void cmd_wallchops(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
- char *channame, *msg;
+ char *channame, *msg, *recoded;
void *free_arg;
CMD_IRC_SERVER(server);
@@ -679,8 +707,10 @@ static void cmd_wallchops(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC
return;
if (*msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- irc_send_cmdv(server, "WALLCHOPS %s :%s", channame, msg);
+ recoded = recode_out(msg, channame);
+ irc_send_cmdv(server, "WALLCHOPS %s :%s", channame, recoded);
+ g_free(recoded);
cmd_params_free(free_arg);
}
@@ -689,7 +719,7 @@ static void cmd_kickban(const char *data, IRC_SERVER_REC *server,
WI_ITEM_REC *item)
{
IRC_CHANNEL_REC *chanrec;
- char *channel, *nicks, *reason, *kickcmd, *bancmd;
+ char *channel, *nicks, *reason, *kickcmd, *bancmd, *recoded;
char **nicklist, *spacenicks;
void *free_arg;
@@ -712,7 +742,10 @@ static void cmd_kickban(const char *data, IRC_SERVER_REC *server,
spacenicks = g_strjoinv(" ", nicklist);
g_strfreev(nicklist);
- kickcmd = g_strdup_printf("%s %s %s", chanrec->name, nicks, reason);
+ recoded = recode_out(reason, channel);
+ kickcmd = g_strdup_printf("%s %s %s", chanrec->name, nicks, recoded);
+ g_free(recoded);
+
bancmd = g_strdup_printf("%s %s", chanrec->name, spacenicks);
g_free(spacenicks);
@@ -771,7 +804,7 @@ static void cmd_knockout(const char *data, IRC_SERVER_REC *server,
IRC_CHANNEL_REC *channel)
{
KNOCKOUT_REC *rec;
- char *nicks, *reason, *timeoutstr, *kickcmd, *bancmd;
+ char *nicks, *reason, *timeoutstr, *kickcmd, *bancmd, *recoded;
char **nicklist, *spacenicks, *banmasks;
void *free_arg;
int timeleft;
@@ -807,7 +840,10 @@ static void cmd_knockout(const char *data, IRC_SERVER_REC *server,
banmasks = ban_get_masks(channel, spacenicks, 0);
g_free(spacenicks);
- kickcmd = g_strdup_printf("%s %s %s", channel->name, nicks, reason);
+ recoded = recode_out(reason, channel->name);
+ kickcmd = g_strdup_printf("%s %s %s", channel->name, nicks, recoded);
+ g_free(recoded);
+
bancmd = *banmasks == '\0'? NULL :
g_strdup_printf("%s %s", channel->name, banmasks);
diff --git a/src/irc/proxy/dump.c b/src/irc/proxy/dump.c
index f98bee94..1aeea5e5 100644
--- a/src/irc/proxy/dump.c
+++ b/src/irc/proxy/dump.c
@@ -22,6 +22,7 @@
#include "network.h"
#include "settings.h"
#include "irssi-version.h"
+#include "recode.h"
#include "irc-servers.h"
#include "irc-channels.h"
@@ -195,10 +196,11 @@ static void dump_join(IRC_CHANNEL_REC *channel, CLIENT_REC *client)
proxy_outdata(client, ":%s 366 %s %s :End of /NAMES list.\n",
client->proxy_address, client->nick, channel->name);
+ /* this is needed because the topic may be encoded into other charsets internaly */
if (channel->topic != NULL) {
proxy_outdata(client, ":%s 332 %s %s :%s\n",
client->proxy_address, client->nick,
- channel->name, channel->topic);
+ channel->name, recode_out(channel->topic, channel->name));
}
}
diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c
index 2ab1373c..cf9b2f2d 100644
--- a/src/irc/proxy/listen.c
+++ b/src/irc/proxy/listen.c
@@ -257,7 +257,8 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args,
ignore_next = TRUE;
if (*msg != '\001' || msg[strlen(msg)-1] != '\001') {
- signal_emit("message own_public", 4,
+ signal_emit(ischannel(*target) ?
+ "message own_public" : "message own_private", 4,
client->server, msg, target, target);
} else if (strncmp(msg+1, "ACTION ", 7) == 0) {
/* action */
@@ -528,6 +529,16 @@ static void sig_message_own_public(IRC_SERVER_REC *server, const char *msg,
proxy_outserver_all(server, "PRIVMSG %s :%s", target, msg);
}
+static void sig_message_own_private(IRC_SERVER_REC *server, const char *msg,
+ const char *target, const char *origtarget)
+{
+ if (!IS_IRC_SERVER(server))
+ return;
+
+ if (!ignore_next)
+ proxy_outserver_all(server, "PRIVMSG %s :%s", target, msg);
+}
+
static void sig_message_own_action(IRC_SERVER_REC *server, const char *msg,
const char *target)
{
@@ -659,6 +670,7 @@ void proxy_listen_init(void)
signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
signal_add("event nick", (SIGNAL_FUNC) event_nick);
signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private);
signal_add("message irc own_action", (SIGNAL_FUNC) sig_message_own_action);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
}
@@ -675,6 +687,7 @@ void proxy_listen_deinit(void)
signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
signal_remove("event nick", (SIGNAL_FUNC) event_nick);
signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private);
signal_remove("message irc own_action", (SIGNAL_FUNC) sig_message_own_action);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
}