Wed, 06 Jul 2011 22:04:06 +0000
Fix debug message for IRC periodic WHO
| 6333 | 1 | /** |
| 2 | * @file parse.c | |
| 8351 | 3 | * |
| 15884 | 4 | * purple |
| 6333 | 5 | * |
| 6 | * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> | |
| 8351 | 7 | * |
| 6333 | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17409
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6333 | 21 | */ |
| 22 | ||
| 23 | #include "internal.h" | |
| 24 | ||
| 25 | #include "accountopt.h" | |
| 26 | #include "conversation.h" | |
| 27 | #include "notify.h" | |
| 28 | #include "debug.h" | |
| 10258 | 29 | #include "util.h" |
| 9130 | 30 | #include "cmds.h" |
| 6333 | 31 | #include "irc.h" |
| 32 | ||
| 33 | #include <stdio.h> | |
| 34 | #include <stdlib.h> | |
| 35 | #include <ctype.h> | |
| 36 | ||
| 37 | static char *irc_send_convert(struct irc_conn *irc, const char *string); | |
| 38 | static char *irc_recv_convert(struct irc_conn *irc, const char *string); | |
| 39 | ||
| 40 | static void irc_parse_error_cb(struct irc_conn *irc, char *input); | |
| 41 | ||
| 42 | static char *irc_mirc_colors[16] = { | |
| 43 | "white", "black", "blue", "dark green", "red", "brown", "purple", | |
| 44 | "orange", "yellow", "green", "teal", "cyan", "light blue", | |
| 45 | "pink", "grey", "light grey" }; | |
| 46 | ||
| 15884 | 47 | extern PurplePlugin *_irc_plugin; |
| 14683 | 48 | |
| 6333 | 49 | /*typedef void (*IRCMsgCallback)(struct irc_conn *irc, char *from, char *name, char **args);*/ |
| 50 | static struct _irc_msg { | |
| 51 | char *name; | |
| 52 | char *format; | |
| 53 | void (*cb)(struct irc_conn *irc, const char *name, const char *from, char **args); | |
| 54 | } _irc_msgs[] = { | |
|
15501
8547fa591578
Recognize non-standard mode characters communicated in an 005 numeric for IRC
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
55 | { "005", "n*", irc_msg_features }, /* Feature list */ |
|
15508
51a669b06193
This should fix up IRC logins for servers which do not provide an
Ethan Blanton <elb@pidgin.im>
parents:
15501
diff
changeset
|
56 | { "251", "n:", irc_msg_luser }, /* Client & Server count */ |
|
51a669b06193
This should fix up IRC logins for servers which do not provide an
Ethan Blanton <elb@pidgin.im>
parents:
15501
diff
changeset
|
57 | { "255", "n:", irc_msg_luser }, /* Client & Server count Mk. II */ |
| 6333 | 58 | { "301", "nn:", irc_msg_away }, /* User is away */ |
| 59 | { "303", "n:", irc_msg_ison }, /* ISON reply */ | |
| 60 | { "311", "nnvvv:", irc_msg_whois }, /* Whois user */ | |
| 61 | { "312", "nnv:", irc_msg_whois }, /* Whois server */ | |
| 62 | { "313", "nn:", irc_msg_whois }, /* Whois ircop */ | |
| 63 | { "317", "nnvv", irc_msg_whois }, /* Whois idle */ | |
| 64 | { "318", "nt:", irc_msg_endwhois }, /* End of WHOIS */ | |
| 65 | { "319", "nn:", irc_msg_whois }, /* Whois channels */ | |
| 66 | { "320", "nn:", irc_msg_whois }, /* Whois (fn ident) */ | |
|
21720
235394d5c7f4
Pull a bunch of bugfix only changes to im.pidgin.pidgin.2.3.1,
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21279
diff
changeset
|
67 | { "314", "nnnvv:", irc_msg_whois }, /* Whowas user */ |
|
31397
b50f1cf05a5e
Moved the conversation attributes API and the IRC periodic WHO updates to i.p.p.next.minor, where they belong.
Evan Schoenberg <evands@pidgin.im>
parents:
31294
diff
changeset
|
68 | { "315", "nt:", irc_msg_who }, /* end of WHO channel */ |
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
69 | { "369", "nt:", irc_msg_endwhois }, /* End of WHOWAS */ |
| 8114 | 70 | { "321", "*", irc_msg_list }, /* Start of list */ |
| 71 | { "322", "ncv:", irc_msg_list }, /* List. */ | |
| 72 | { "323", ":", irc_msg_list }, /* End of list. */ | |
| 6333 | 73 | { "324", "ncv:", irc_msg_chanmode }, /* Channel modes */ |
| 74 | { "331", "nc:", irc_msg_topic }, /* No channel topic */ | |
| 75 | { "332", "nc:", irc_msg_topic }, /* Channel topic */ | |
| 76 | { "333", "*", irc_msg_ignore }, /* Topic setter stuff */ | |
|
31397
b50f1cf05a5e
Moved the conversation attributes API and the IRC periodic WHO updates to i.p.p.next.minor, where they belong.
Evan Schoenberg <evands@pidgin.im>
parents:
31294
diff
changeset
|
77 | { "352", "nvcvnvvv:", irc_msg_who },/* Channel WHO */ |
| 6333 | 78 | { "353", "nvc:", irc_msg_names }, /* Names list */ |
| 79 | { "366", "nc:", irc_msg_names }, /* End of names */ | |
|
22798
a501b4137c64
Handle IRC ban lists in-channel. Channels which are not joined are
Ethan Blanton <elb@pidgin.im>
parents:
22092
diff
changeset
|
80 | { "367", "ncnnv", irc_msg_ban }, /* Ban list */ |
|
a501b4137c64
Handle IRC ban lists in-channel. Channels which are not joined are
Ethan Blanton <elb@pidgin.im>
parents:
22092
diff
changeset
|
81 | { "368", "nc:", irc_msg_ban }, /* End of ban list */ |
| 6333 | 82 | { "372", "n:", irc_msg_motd }, /* MOTD */ |
| 83 | { "375", "n:", irc_msg_motd }, /* Start MOTD */ | |
|
15508
51a669b06193
This should fix up IRC logins for servers which do not provide an
Ethan Blanton <elb@pidgin.im>
parents:
15501
diff
changeset
|
84 | { "376", "n:", irc_msg_motd }, /* End of MOTD */ |
| 10564 | 85 | { "391", "nv:", irc_msg_time }, /* Time reply */ |
| 6333 | 86 | { "401", "nt:", irc_msg_nonick }, /* No such nick/chan */ |
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
87 | { "406", "nt:", irc_msg_nonick }, /* No such nick for WHOWAS */ |
| 7877 | 88 | { "403", "nc:", irc_msg_nochan }, /* No such channel */ |
| 6333 | 89 | { "404", "nt:", irc_msg_nosend }, /* Cannot send to chan */ |
| 90 | { "421", "nv:", irc_msg_unknown }, /* Unknown command */ | |
|
31229
4bef370d8a92
Process 422 (ERR_NOMOTD) as a valid replacement for an actual MOTD
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
28468
diff
changeset
|
91 | { "422", "n:", irc_msg_motd }, /* MOTD file missing */ |
| 10633 | 92 | { "432", "vn:", irc_msg_badnick }, /* Erroneous nickname */ |
| 6333 | 93 | { "433", "vn:", irc_msg_nickused }, /* Nickname already in use */ |
|
10712
2aded9e9abd4
[gaim-migrate @ 12306]
Richard Laager <rlaager@pidgin.im>
parents:
10659
diff
changeset
|
94 | { "437", "nc:", irc_msg_unavailable }, /* Nick/channel is unavailable */ |
| 6718 | 95 | { "438", "nn:", irc_msg_nochangenick }, /* Nick may not change */ |
| 6333 | 96 | { "442", "nc:", irc_msg_notinchan }, /* Not in channel */ |
| 97 | { "473", "nc:", irc_msg_inviteonly }, /* Tried to join invite-only */ | |
| 98 | { "474", "nc:", irc_msg_banned }, /* Banned from channel */ | |
|
16993
536c1485c139
Handle channel joins when registration is required more gracefully.
Ethan Blanton <elb@pidgin.im>
parents:
16474
diff
changeset
|
99 | { "477", "nc:", irc_msg_regonly }, /* Registration Required */ |
|
10659
caf16376fba0
[gaim-migrate @ 12192]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10633
diff
changeset
|
100 | { "478", "nct:", irc_msg_banfull }, /* Banlist is full */ |
| 6333 | 101 | { "482", "nc:", irc_msg_notop }, /* Need to be op to do that */ |
| 102 | { "501", "n:", irc_msg_badmode }, /* Unknown mode flag */ | |
| 8404 | 103 | { "506", "nc:", irc_msg_nosend }, /* Must identify to send */ |
| 6714 | 104 | { "515", "nc:", irc_msg_regonly }, /* Registration required */ |
| 6333 | 105 | { "invite", "n:", irc_msg_invite }, /* Invited */ |
| 106 | { "join", ":", irc_msg_join }, /* Joined a channel */ | |
| 107 | { "kick", "cn:", irc_msg_kick }, /* KICK */ | |
| 108 | { "mode", "tv:", irc_msg_mode }, /* MODE for channel */ | |
| 109 | { "nick", ":", irc_msg_nick }, /* Nick change */ | |
| 110 | { "notice", "t:", irc_msg_notice }, /* NOTICE recv */ | |
| 111 | { "part", "c:", irc_msg_part }, /* Parted a channel */ | |
| 112 | { "ping", ":", irc_msg_ping }, /* Received PING from server */ | |
| 113 | { "pong", "v:", irc_msg_pong }, /* Received PONG from server */ | |
| 114 | { "privmsg", "t:", irc_msg_privmsg }, /* Received private message */ | |
| 115 | { "topic", "c:", irc_msg_topic }, /* TOPIC command */ | |
| 116 | { "quit", ":", irc_msg_quit }, /* QUIT notice */ | |
| 117 | { "wallops", ":", irc_msg_wallops }, /* WALLOPS command */ | |
| 118 | { NULL, NULL, NULL } | |
| 119 | }; | |
| 120 | ||
| 121 | static struct _irc_user_cmd { | |
| 122 | char *name; | |
| 123 | char *format; | |
| 124 | IRCCmdCallback cb; | |
| 9255 | 125 | char *help; |
| 6333 | 126 | } _irc_cmds[] = { |
| 9255 | 127 | { "action", ":", irc_cmd_ctcp_action, N_("action <action to perform>: Perform an action.") }, |
|
31651
24e136c4c399
Add authserv support to IRC. Need a name to credit tomos with. Fixes #13337.
Tomos Lelong <lelongt@gmail.com>
parents:
31565
diff
changeset
|
128 | { "authserv", ":", irc_cmd_service, N_("authserv: Send a command to authserv") }, |
| 9255 | 129 | { "away", ":", irc_cmd_away, N_("away [message]: Set an away message, or use no message to return from being away.") }, |
|
23895
4d883627111f
/ctcp command for IRC
Vladislav Guberinic <neosisani@gmail.com>
parents:
23532
diff
changeset
|
130 | { "ctcp", "t:", irc_cmd_ctcp, N_("ctcp <nick> <msg>: sends ctcp msg to nick.") }, |
| 12013 | 131 | { "chanserv", ":", irc_cmd_service, N_("chanserv: Send a command to chanserv") }, |
| 9258 | 132 | { "deop", ":", irc_cmd_op, N_("deop <nick1> [nick2] ...: Remove channel operator status from someone. You must be a channel operator to do this.") }, |
| 133 | { "devoice", ":", irc_cmd_op, N_("devoice <nick1> [nick2] ...: Remove channel voice status from someone, preventing them from speaking if the channel is moderated (+m). You must be a channel operator to do this.") }, | |
| 134 | { "invite", ":", irc_cmd_invite, N_("invite <nick> [room]: Invite someone to join you in the specified channel, or the current channel.") }, | |
| 9266 | 135 | { "j", "cv", irc_cmd_join, N_("j <room1>[,room2][,...] [key1[,key2][,...]]: Enter one or more channels, optionally providing a channel key for each if needed.") }, |
| 136 | { "join", "cv", irc_cmd_join, N_("join <room1>[,room2][,...] [key1[,key2][,...]]: Enter one or more channels, optionally providing a channel key for each if needed.") }, | |
| 9258 | 137 | { "kick", "n:", irc_cmd_kick, N_("kick <nick> [message]: Remove someone from a channel. You must be a channel operator to do this.") }, |
| 138 | { "list", ":", irc_cmd_list, N_("list: Display a list of chat rooms on the network. <i>Warning, some servers may disconnect you upon doing this.</i>") }, | |
| 9255 | 139 | { "me", ":", irc_cmd_ctcp_action, N_("me <action to perform>: Perform an action.") }, |
| 12013 | 140 | { "memoserv", ":", irc_cmd_service, N_("memoserv: Send a command to memoserv") }, |
|
10609
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
141 | { "mode", ":", irc_cmd_mode, N_("mode <+|-><A-Za-z> <nick|channel>: Set or unset a channel or user mode.") }, |
| 9258 | 142 | { "msg", "t:", irc_cmd_privmsg, N_("msg <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 143 | { "names", "c", irc_cmd_names, N_("names [channel]: List the users currently in a channel.") }, | |
| 9274 | 144 | { "nick", "n", irc_cmd_nick, N_("nick <new nickname>: Change your nickname.") }, |
| 12013 | 145 | { "nickserv", ":", irc_cmd_service, N_("nickserv: Send a command to nickserv") }, |
|
22092
52c00ca73f6f
Added /notice support for IRC. If I didn't do this properly, feel free
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
21720
diff
changeset
|
146 | { "notice", "t:", irc_cmd_privmsg, N_("notice <target<: Send a notice to a user or channel.") }, |
| 9258 | 147 | { "op", ":", irc_cmd_op, N_("op <nick1> [nick2] ...: Grant channel operator status to someone. You must be a channel operator to do this.") }, |
| 9255 | 148 | { "operwall", ":", irc_cmd_wallops, N_("operwall <message>: If you don't know what this is, you probably can't use it.") }, |
| 12013 | 149 | { "operserv", ":", irc_cmd_service, N_("operserv: Send a command to operserv") }, |
| 9258 | 150 | { "part", "c:", irc_cmd_part, N_("part [room] [message]: Leave the current channel, or a specified channel, with an optional message.") }, |
| 9255 | 151 | { "ping", "n", irc_cmd_ping, N_("ping [nick]: Asks how much lag a user (or the server if no user specified) has.") }, |
| 9258 | 152 | { "query", "n:", irc_cmd_query, N_("query <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 9255 | 153 | { "quit", ":", irc_cmd_quit, N_("quit [message]: Disconnect from the server, with an optional message.") }, |
| 154 | { "quote", "*", irc_cmd_quote, N_("quote [...]: Send a raw command to the server.") }, | |
| 155 | { "remove", "n:", irc_cmd_remove, N_("remove <nick> [message]: Remove someone from a room. You must be a channel operator to do this.") }, | |
| 10564 | 156 | { "time", "", irc_cmd_time, N_("time: Displays the current local time at the IRC server.") }, |
| 9255 | 157 | { "topic", ":", irc_cmd_topic, N_("topic [new topic]: View or change the channel topic.") }, |
| 158 | { "umode", ":", irc_cmd_mode, N_("umode <+|-><A-Za-z>: Set or unset a user mode.") }, | |
| 13943 | 159 | { "version", ":", irc_cmd_ctcp_version, N_("version [nick]: send CTCP VERSION request to a user") }, |
| 9258 | 160 | { "voice", ":", irc_cmd_op, N_("voice <nick1> [nick2] ...: Grant channel voice status to someone. You must be a channel operator to do this.") }, |
| 9255 | 161 | { "wallops", ":", irc_cmd_wallops, N_("wallops <message>: If you don't know what this is, you probably can't use it.") }, |
|
10609
170a5af61448
[gaim-migrate @ 12055]
Richard Laager <rlaager@pidgin.im>
parents:
10564
diff
changeset
|
162 | { "whois", "tt", irc_cmd_whois, N_("whois [server] <nick>: Get information on a user.") }, |
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
163 | { "whowas", "t", irc_cmd_whowas, N_("whowas <nick>: Get information on a user that has logged off.") }, |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11136
diff
changeset
|
164 | { NULL, NULL, NULL, NULL } |
| 6333 | 165 | }; |
| 166 | ||
| 15884 | 167 | static PurpleCmdRet irc_parse_purple_cmd(PurpleConversation *conv, const gchar *cmd, |
| 9597 | 168 | gchar **args, gchar **error, void *data) |
| 9130 | 169 | { |
| 15884 | 170 | PurpleConnection *gc; |
| 9130 | 171 | struct irc_conn *irc; |
| 172 | struct _irc_user_cmd *cmdent; | |
| 173 | ||
| 15884 | 174 | gc = purple_conversation_get_gc(conv); |
| 9130 | 175 | if (!gc) |
| 15884 | 176 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 177 | |
| 178 | irc = gc->proto_data; | |
| 179 | ||
| 180 | if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL) | |
| 15884 | 181 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 182 | |
| 15884 | 183 | (cmdent->cb)(irc, cmd, purple_conversation_get_name(conv), (const char **)args); |
| 9130 | 184 | |
| 15884 | 185 | return PURPLE_CMD_RET_OK; |
| 9130 | 186 | } |
| 187 | ||
| 188 | static void irc_register_command(struct _irc_user_cmd *c) | |
| 189 | { | |
| 15884 | 190 | PurpleCmdFlag f; |
| 9130 | 191 | char args[10]; |
| 192 | char *format; | |
|
12316
b4e5d5ea15fd
[gaim-migrate @ 14620]
Richard Laager <rlaager@pidgin.im>
parents:
12282
diff
changeset
|
193 | size_t i; |
| 9130 | 194 | |
| 15884 | 195 | f = PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY |
| 196 | | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS; | |
| 9130 | 197 | |
| 198 | format = c->format; | |
| 199 | ||
| 200 | for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++) | |
| 201 | switch (*format) { | |
| 202 | case 'v': | |
| 203 | case 'n': | |
| 204 | case 'c': | |
| 205 | case 't': | |
| 206 | args[i] = 'w'; | |
| 207 | break; | |
| 208 | case ':': | |
| 209 | case '*': | |
| 210 | args[i] = 's'; | |
| 211 | break; | |
| 212 | } | |
| 213 | ||
| 214 | args[i] = '\0'; | |
| 215 | ||
| 15884 | 216 | purple_cmd_register(c->name, args, PURPLE_CMD_P_PRPL, f, "prpl-irc", |
| 217 | irc_parse_purple_cmd, _(c->help), NULL); | |
| 9130 | 218 | } |
| 219 | ||
| 220 | void irc_register_commands(void) | |
| 221 | { | |
| 222 | struct _irc_user_cmd *c; | |
| 223 | ||
| 224 | for (c = _irc_cmds; c && c->name; c++) | |
| 225 | irc_register_command(c); | |
| 226 | } | |
| 227 | ||
| 6333 | 228 | static char *irc_send_convert(struct irc_conn *irc, const char *string) |
| 229 | { | |
| 230 | char *utf8; | |
| 231 | GError *err = NULL; | |
| 10258 | 232 | gchar **encodings; |
| 233 | const gchar *enclist; | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
234 | |
| 15884 | 235 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 236 | encodings = g_strsplit(enclist, ",", 2); |
| 237 | ||
|
17138
d666ace4a8ac
strcasecmp is post-C89, so use the glib equivalent
Ethan Blanton <elb@pidgin.im>
parents:
16993
diff
changeset
|
238 | if (encodings[0] == NULL || !g_ascii_strcasecmp("UTF-8", encodings[0])) { |
| 10278 | 239 | g_strfreev(encodings); |
|
23392
9268a4fc4786
Remove an unnecessary strdup when sending messages over IRC.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22798
diff
changeset
|
240 | return NULL; |
| 10278 | 241 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
242 | |
| 10258 | 243 | utf8 = g_convert(string, strlen(string), encodings[0], "UTF-8", NULL, NULL, &err); |
| 6333 | 244 | if (err) { |
| 15884 | 245 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message); |
| 246 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", encodings[0]); | |
| 6333 | 247 | utf8 = g_strdup(string); |
| 8954 | 248 | g_error_free(err); |
| 6333 | 249 | } |
| 10258 | 250 | g_strfreev(encodings); |
| 251 | ||
| 6333 | 252 | return utf8; |
| 253 | } | |
| 254 | ||
| 255 | static char *irc_recv_convert(struct irc_conn *irc, const char *string) | |
| 256 | { | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
257 | char *utf8 = NULL; |
| 10258 | 258 | const gchar *charset, *enclist; |
| 259 | gchar **encodings; | |
|
23906
6962e96ddd38
This adds an "auto-detect UTF-8" option to IRC which, when enabled,
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
260 | gboolean autodetect; |
| 10258 | 261 | int i; |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
262 | |
| 15884 | 263 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 264 | encodings = g_strsplit(enclist, ",", -1); |
| 265 | ||
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
266 | if (encodings[0] == NULL) { |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
267 | g_strfreev(encodings); |
| 15884 | 268 | return purple_utf8_salvage(string); |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
269 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
270 | |
|
23906
6962e96ddd38
This adds an "auto-detect UTF-8" option to IRC which, when enabled,
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
271 | autodetect = purple_account_get_bool(irc->account, "autodetect_utf8", IRC_DEFAULT_AUTODETECT); |
|
6962e96ddd38
This adds an "auto-detect UTF-8" option to IRC which, when enabled,
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
272 | |
|
6962e96ddd38
This adds an "auto-detect UTF-8" option to IRC which, when enabled,
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
273 | if (autodetect && g_utf8_validate(string, -1, NULL)) { |
|
6962e96ddd38
This adds an "auto-detect UTF-8" option to IRC which, when enabled,
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
274 | return g_strdup(string); |
|
6962e96ddd38
This adds an "auto-detect UTF-8" option to IRC which, when enabled,
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
275 | } |
|
6962e96ddd38
This adds an "auto-detect UTF-8" option to IRC which, when enabled,
Ethan Blanton <elb@pidgin.im>
parents:
23895
diff
changeset
|
276 | |
| 10258 | 277 | for (i = 0; encodings[i] != NULL; i++) { |
| 278 | charset = encodings[i]; | |
| 279 | while (*charset == ' ') | |
| 280 | charset++; | |
| 281 | ||
|
17156
6d4cc0f310d1
More strcasecmp() replacements.
Richard Laager <rlaager@pidgin.im>
parents:
17138
diff
changeset
|
282 | if (!g_ascii_strcasecmp("UTF-8", charset)) { |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
283 | if (g_utf8_validate(string, -1, NULL)) |
| 10258 | 284 | utf8 = g_strdup(string); |
| 285 | } else { | |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
286 | utf8 = g_convert(string, -1, "UTF-8", charset, NULL, NULL, NULL); |
| 10258 | 287 | } |
| 288 | ||
| 289 | if (utf8) { | |
| 290 | g_strfreev(encodings); | |
| 291 | return utf8; | |
| 292 | } | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
293 | } |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
294 | g_strfreev(encodings); |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
295 | |
| 15884 | 296 | return purple_utf8_salvage(string); |
| 6333 | 297 | } |
| 298 | ||
|
20217
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
299 | /* This function is shamelessly stolen from glib--it is an old version of the |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
300 | * private function append_escaped_text, used by g_markup_escape_text, whose |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
301 | * behavior changed in glib 2.12. */ |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
302 | static void irc_append_escaped_text(GString *str, const char *text, gssize length) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
303 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
304 | const char *p = text; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
305 | const char *end = text + length; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
306 | const char *next = NULL; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
307 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
308 | while(p != end) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
309 | next = g_utf8_next_char(p); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
310 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
311 | switch(*p) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
312 | case '&': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
313 | g_string_append(str, "&"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
314 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
315 | case '<': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
316 | g_string_append(str, "<"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
317 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
318 | case '>': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
319 | g_string_append(str, ">"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
320 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
321 | case '\'': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
322 | g_string_append(str, "'"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
323 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
324 | case '"': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
325 | g_string_append(str, """); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
326 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
327 | default: |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
328 | g_string_append_len(str, p, next - p); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
329 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
330 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
331 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
332 | p = next; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
333 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
334 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
335 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
336 | /* This function is shamelessly stolen from glib--it is an old version of the |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
337 | * function g_markup_escape_text, whose behavior changed in glib 2.12. */ |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
338 | char *irc_escape_privmsg(const char *text, gssize length) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
339 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
340 | GString *str; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
341 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
342 | g_return_val_if_fail(text != NULL, NULL); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
343 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
344 | if(length < 0) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
345 | length = strlen(text); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
346 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
347 | str = g_string_sized_new(length); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
348 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
349 | irc_append_escaped_text(str, text, length); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
350 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
351 | return g_string_free(str, FALSE); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
352 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
353 | |
| 6333 | 354 | /* XXX tag closings are not necessarily correctly nested here! If we |
| 355 | * get a ^O or reach the end of the string and there are open | |
| 356 | * tags, they are closed in a fixed order ... this means, for | |
| 357 | * example, you might see <FONT COLOR="blue">some text <B>with | |
| 358 | * various attributes</FONT></B> (notice that B and FONT overlap | |
| 359 | * and are not cleanly nested). This is imminently fixable but | |
| 360 | * I am not fixing it right now. | |
| 361 | */ | |
| 362 | char *irc_mirc2html(const char *string) | |
| 363 | { | |
| 364 | const char *cur, *end; | |
| 365 | char fg[3] = "\0\0", bg[3] = "\0\0"; | |
| 366 | int fgnum, bgnum; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
367 | int font = 0, bold = 0, underline = 0, italic = 0; |
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
368 | GString *decoded; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
369 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
370 | if (string == NULL) |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
371 | return NULL; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
372 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
373 | decoded = g_string_sized_new(strlen(string)); |
| 6333 | 374 | |
| 375 | cur = string; | |
| 376 | do { | |
| 6754 | 377 | end = strpbrk(cur, "\002\003\007\017\026\037"); |
| 6333 | 378 | |
| 379 | decoded = g_string_append_len(decoded, cur, end ? end - cur : strlen(cur)); | |
| 380 | cur = end ? end : cur + strlen(cur); | |
| 381 | ||
| 382 | switch (*cur) { | |
| 383 | case '\002': | |
| 384 | cur++; | |
| 385 | if (!bold) { | |
| 386 | decoded = g_string_append(decoded, "<B>"); | |
| 387 | bold = TRUE; | |
| 388 | } else { | |
| 389 | decoded = g_string_append(decoded, "</B>"); | |
| 390 | bold = FALSE; | |
| 391 | } | |
| 392 | break; | |
| 393 | case '\003': | |
| 394 | cur++; | |
| 395 | fg[0] = fg[1] = bg[0] = bg[1] = '\0'; | |
| 396 | if (isdigit(*cur)) | |
| 397 | fg[0] = *cur++; | |
| 398 | if (isdigit(*cur)) | |
| 399 | fg[1] = *cur++; | |
| 400 | if (*cur == ',') { | |
| 401 | cur++; | |
| 402 | if (isdigit(*cur)) | |
| 403 | bg[0] = *cur++; | |
| 404 | if (isdigit(*cur)) | |
| 405 | bg[1] = *cur++; | |
| 406 | } | |
| 407 | if (font) { | |
| 408 | decoded = g_string_append(decoded, "</FONT>"); | |
| 409 | font = FALSE; | |
| 410 | } | |
| 411 | ||
| 412 | if (fg[0]) { | |
| 413 | fgnum = atoi(fg); | |
| 414 | if (fgnum < 0 || fgnum > 15) | |
| 415 | continue; | |
| 416 | font = TRUE; | |
| 417 | g_string_append_printf(decoded, "<FONT COLOR=\"%s\"", irc_mirc_colors[fgnum]); | |
| 418 | if (bg[0]) { | |
| 419 | bgnum = atoi(bg); | |
| 420 | if (bgnum >= 0 && bgnum < 16) | |
| 421 | g_string_append_printf(decoded, " BACK=\"%s\"", irc_mirc_colors[bgnum]); | |
| 422 | } | |
| 423 | decoded = g_string_append_c(decoded, '>'); | |
| 424 | } | |
| 425 | break; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
426 | case '\011': |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
427 | cur++; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
428 | if (!italic) { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
429 | decoded = g_string_append(decoded, "<I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
430 | italic = TRUE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
431 | } else { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
432 | decoded = g_string_append(decoded, "</I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
433 | italic = FALSE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
434 | } |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
435 | break; |
| 6754 | 436 | case '\037': |
| 437 | cur++; | |
| 438 | if (!underline) { | |
| 439 | decoded = g_string_append(decoded, "<U>"); | |
| 440 | underline = TRUE; | |
| 441 | } else { | |
| 442 | decoded = g_string_append(decoded, "</U>"); | |
| 12282 | 443 | underline = FALSE; |
| 6754 | 444 | } |
| 445 | break; | |
| 6333 | 446 | case '\007': |
| 447 | case '\026': | |
| 448 | cur++; | |
| 449 | break; | |
| 450 | case '\017': | |
| 451 | cur++; | |
| 452 | /* fallthrough */ | |
| 453 | case '\000': | |
| 454 | if (bold) | |
| 6754 | 455 | decoded = g_string_append(decoded, "</B>"); |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
456 | if (italic) |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
457 | decoded = g_string_append(decoded, "</I>"); |
| 6754 | 458 | if (underline) |
| 459 | decoded = g_string_append(decoded, "</U>"); | |
| 6333 | 460 | if (font) |
| 461 | decoded = g_string_append(decoded, "</FONT>"); | |
| 462 | break; | |
| 463 | default: | |
| 15884 | 464 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unexpected mIRC formatting character %d\n", *cur); |
| 6333 | 465 | } |
| 466 | } while (*cur); | |
| 467 | ||
| 468 | return g_string_free(decoded, FALSE); | |
| 469 | } | |
| 470 | ||
| 8529 | 471 | char *irc_mirc2txt (const char *string) |
| 472 | { | |
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
473 | char *result; |
| 8529 | 474 | int i, j; |
| 475 | ||
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
476 | if (string == NULL) |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
477 | return NULL; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
478 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
479 | result = g_strdup (string); |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
480 | |
| 8529 | 481 | for (i = 0, j = 0; result[i]; i++) { |
| 482 | switch (result[i]) { | |
| 483 | case '\002': | |
| 484 | case '\003': | |
|
17409
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
485 | /* Foreground color */ |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
486 | if (isdigit(result[i + 1])) |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
487 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
488 | if (isdigit(result[i + 1])) |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
489 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
490 | /* Optional comma and background color */ |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
491 | if (result[i + 1] == ',') { |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
492 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
493 | if (isdigit(result[i + 1])) |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
494 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
495 | if (isdigit(result[i + 1])) |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
496 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
497 | } |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
498 | /* Note that i still points to the last character |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
499 | * of the color selection string. */ |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
500 | continue; |
| 8529 | 501 | case '\007': |
| 502 | case '\017': | |
| 503 | case '\026': | |
| 504 | case '\037': | |
| 505 | continue; | |
| 506 | default: | |
| 507 | result[j++] = result[i]; | |
| 508 | } | |
| 509 | } | |
| 11136 | 510 | result[j] = '\0'; |
|
24763
67d9d4c975c0
Replace spaces wth tabs in indentation and tabs with spaces in line continuations.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24574
diff
changeset
|
511 | return result; |
| 8529 | 512 | } |
| 513 | ||
|
24574
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
514 | const char *irc_nick_skip_mode(struct irc_conn *irc, const char *nick) |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
515 | { |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
516 | static const char *default_modes = "@+%&"; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
517 | const char *mode_chars; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
518 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
519 | mode_chars = irc->mode_chars ? irc->mode_chars : default_modes; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
520 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
521 | while (strchr(mode_chars, *nick) != NULL) |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
522 | nick++; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
523 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
524 | return nick; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
525 | } |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
526 | |
| 10208 | 527 | gboolean irc_ischannel(const char *string) |
| 528 | { | |
| 529 | return (string[0] == '#' || string[0] == '&'); | |
| 530 | } | |
| 531 | ||
| 6333 | 532 | char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice) |
| 533 | { | |
| 15884 | 534 | PurpleConnection *gc; |
| 6333 | 535 | const char *cur = msg + 1; |
| 536 | char *buf, *ctcp; | |
| 537 | time_t timestamp; | |
| 538 | ||
| 6754 | 539 | /* Note that this is NOT correct w.r.t. multiple CTCPs in one |
| 540 | * message and low-level quoting ... but if you want that crap, | |
| 541 | * use a real IRC client. */ | |
| 542 | ||
| 6333 | 543 | if (msg[0] != '\001' || msg[strlen(msg) - 1] != '\001') |
| 544 | return g_strdup(msg); | |
| 545 | ||
| 546 | if (!strncmp(cur, "ACTION ", 7)) { | |
| 547 | cur += 7; | |
| 548 | buf = g_strdup_printf("/me %s", cur); | |
| 549 | buf[strlen(buf) - 1] = '\0'; | |
| 550 | return buf; | |
| 551 | } else if (!strncmp(cur, "PING ", 5)) { | |
| 552 | if (notice) { /* reply */ | |
|
11972
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11726
diff
changeset
|
553 | /* TODO: Should this read in the timestamp as a double? */ |
| 6333 | 554 | sscanf(cur, "PING %lu", ×tamp); |
| 15884 | 555 | gc = purple_account_get_connection(irc->account); |
| 6333 | 556 | if (!gc) |
| 557 | return NULL; | |
| 6350 | 558 | buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp); |
| 15884 | 559 | purple_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf); |
| 6333 | 560 | g_free(buf); |
| 561 | return NULL; | |
| 562 | } else { | |
| 563 | buf = irc_format(irc, "vt:", "NOTICE", from, msg); | |
| 564 | irc_send(irc, buf); | |
| 565 | g_free(buf); | |
| 566 | } | |
| 567 | } else if (!strncmp(cur, "VERSION", 7) && !notice) { | |
| 15884 | 568 | buf = irc_format(irc, "vt:", "NOTICE", from, "\001VERSION Purple IRC\001"); |
| 6333 | 569 | irc_send(irc, buf); |
| 570 | g_free(buf); | |
| 8351 | 571 | } else if (!strncmp(cur, "DCC SEND ", 9)) { |
| 572 | irc_dccsend_recv(irc, from, msg + 10); | |
| 573 | return NULL; | |
| 6333 | 574 | } |
| 575 | ||
| 576 | ctcp = g_strdup(msg + 1); | |
| 577 | ctcp[strlen(ctcp) - 1] = '\0'; | |
| 578 | buf = g_strdup_printf("Received CTCP '%s' (to %s) from %s", ctcp, to, from); | |
| 579 | g_free(ctcp); | |
| 580 | return buf; | |
| 581 | } | |
| 582 | ||
| 583 | void irc_msg_table_build(struct irc_conn *irc) | |
| 584 | { | |
| 585 | int i; | |
| 586 | ||
| 587 | if (!irc || !irc->msgs) { | |
| 15884 | 588 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a message table on a bogus structure\n"); |
| 6333 | 589 | return; |
| 590 | } | |
| 591 | ||
| 592 | for (i = 0; _irc_msgs[i].name; i++) { | |
| 593 | g_hash_table_insert(irc->msgs, (gpointer)_irc_msgs[i].name, (gpointer)&_irc_msgs[i]); | |
| 594 | } | |
| 595 | } | |
| 596 | ||
| 597 | void irc_cmd_table_build(struct irc_conn *irc) | |
| 598 | { | |
| 599 | int i; | |
| 600 | ||
| 601 | if (!irc || !irc->cmds) { | |
| 15884 | 602 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a command table on a bogus structure\n"); |
| 6333 | 603 | return; |
| 604 | } | |
| 605 | ||
| 606 | for (i = 0; _irc_cmds[i].name ; i++) { | |
| 607 | g_hash_table_insert(irc->cmds, (gpointer)_irc_cmds[i].name, (gpointer)&_irc_cmds[i]); | |
| 608 | } | |
| 609 | } | |
| 610 | ||
| 611 | char *irc_format(struct irc_conn *irc, const char *format, ...) | |
| 612 | { | |
| 613 | GString *string = g_string_new(""); | |
| 614 | char *tok, *tmp; | |
| 615 | const char *cur; | |
| 616 | va_list ap; | |
| 617 | ||
| 618 | va_start(ap, format); | |
| 619 | for (cur = format; *cur; cur++) { | |
| 620 | if (cur != format) | |
| 621 | g_string_append_c(string, ' '); | |
| 622 | ||
| 623 | tok = va_arg(ap, char *); | |
| 624 | switch (*cur) { | |
| 625 | case 'v': | |
| 626 | g_string_append(string, tok); | |
| 627 | break; | |
| 628 | case ':': | |
| 629 | g_string_append_c(string, ':'); | |
| 630 | /* no break! */ | |
| 631 | case 't': | |
| 632 | case 'n': | |
| 633 | case 'c': | |
| 634 | tmp = irc_send_convert(irc, tok); | |
|
23392
9268a4fc4786
Remove an unnecessary strdup when sending messages over IRC.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22798
diff
changeset
|
635 | g_string_append(string, tmp ? tmp : tok); |
| 6333 | 636 | g_free(tmp); |
| 637 | break; | |
| 638 | default: | |
| 15884 | 639 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Invalid format character '%c'\n", *cur); |
| 6333 | 640 | break; |
| 641 | } | |
| 642 | } | |
| 643 | va_end(ap); | |
| 644 | g_string_append(string, "\r\n"); | |
| 645 | return (g_string_free(string, FALSE)); | |
| 646 | } | |
| 647 | ||
| 648 | void irc_parse_msg(struct irc_conn *irc, char *input) | |
| 649 | { | |
| 650 | struct _irc_msg *msgent; | |
| 651 | char *cur, *end, *tmp, *from, *msgname, *fmt, **args, *msg; | |
| 7631 | 652 | guint i; |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
653 | PurpleConnection *gc = purple_account_get_connection(irc->account); |
| 6333 | 654 | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
655 | irc->recv_time = time(NULL); |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
656 | |
|
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
657 | /* |
|
14996
291304176e0b
[gaim-migrate @ 17706]
Mark Doliner <markdoliner@pidgin.im>
parents:
14995
diff
changeset
|
658 | * The data passed to irc-receiving-text is the raw protocol data. |
|
14995
fc9f51b8f6d5
[gaim-migrate @ 17705]
Mark Doliner <markdoliner@pidgin.im>
parents:
14984
diff
changeset
|
659 | * TODO: It should be passed as an array of bytes and a length |
|
fc9f51b8f6d5
[gaim-migrate @ 17705]
Mark Doliner <markdoliner@pidgin.im>
parents:
14984
diff
changeset
|
660 | * instead of a null terminated string. |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
661 | */ |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
662 | purple_signal_emit(_irc_plugin, "irc-receiving-text", gc, &input); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31229
diff
changeset
|
663 | |
| 6333 | 664 | if (!strncmp(input, "PING ", 5)) { |
| 665 | msg = irc_format(irc, "vv", "PONG", input + 5); | |
| 666 | irc_send(irc, msg); | |
| 667 | g_free(msg); | |
| 668 | return; | |
| 669 | } else if (!strncmp(input, "ERROR ", 6)) { | |
| 10154 | 670 | if (g_utf8_validate(input, -1, NULL)) { |
| 671 | char *tmp = g_strdup_printf("%s\n%s", _("Disconnected."), input); | |
| 21279 | 672 | purple_connection_error_reason (gc, |
| 673 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | |
| 10154 | 674 | g_free(tmp); |
| 675 | } else | |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
676 | purple_connection_error_reason (gc, |
| 21279 | 677 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 678 | _("Disconnected.")); | |
| 6333 | 679 | return; |
| 680 | } | |
| 681 | ||
| 682 | if (input[0] != ':' || (cur = strchr(input, ' ')) == NULL) { | |
| 683 | irc_parse_error_cb(irc, input); | |
| 684 | return; | |
| 685 | } | |
| 686 | ||
| 687 | from = g_strndup(&input[1], cur - &input[1]); | |
| 688 | cur++; | |
| 689 | end = strchr(cur, ' '); | |
| 690 | if (!end) | |
| 691 | end = cur + strlen(cur); | |
| 692 | ||
| 693 | tmp = g_strndup(cur, end - cur); | |
| 694 | msgname = g_ascii_strdown(tmp, -1); | |
| 695 | g_free(tmp); | |
| 696 | ||
| 697 | if ((msgent = g_hash_table_lookup(irc->msgs, msgname)) == NULL) { | |
| 698 | irc_msg_default(irc, "", from, &input); | |
| 699 | g_free(msgname); | |
| 700 | g_free(from); | |
| 701 | return; | |
| 702 | } | |
| 703 | g_free(msgname); | |
| 704 | ||
| 705 | args = g_new0(char *, strlen(msgent->format)); | |
| 706 | for (cur = end, fmt = msgent->format, i = 0; fmt[i] && *cur++; i++) { | |
| 707 | switch (fmt[i]) { | |
| 708 | case 'v': | |
| 709 | if (!(end = strchr(cur, ' '))) end = cur + strlen(cur); | |
| 710 | args[i] = g_strndup(cur, end - cur); | |
| 711 | cur += end - cur; | |
| 712 | break; | |
| 713 | case 't': | |
| 714 | case 'n': | |
| 715 | case 'c': | |
| 716 | if (!(end = strchr(cur, ' '))) end = cur + strlen(cur); | |
| 717 | tmp = g_strndup(cur, end - cur); | |
| 718 | args[i] = irc_recv_convert(irc, tmp); | |
| 719 | g_free(tmp); | |
| 720 | cur += end - cur; | |
| 721 | break; | |
| 722 | case ':': | |
| 723 | if (*cur == ':') cur++; | |
| 724 | args[i] = irc_recv_convert(irc, cur); | |
| 725 | cur = cur + strlen(cur); | |
| 726 | break; | |
| 727 | case '*': | |
| 728 | args[i] = g_strdup(cur); | |
| 729 | cur = cur + strlen(cur); | |
| 730 | break; | |
| 731 | default: | |
| 15884 | 732 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid message format character '%c'\n", fmt[i]); |
| 6333 | 733 | break; |
| 734 | } | |
| 735 | } | |
| 6970 | 736 | tmp = irc_recv_convert(irc, from); |
| 737 | (msgent->cb)(irc, msgent->name, tmp, args); | |
| 738 | g_free(tmp); | |
| 6333 | 739 | for (i = 0; i < strlen(msgent->format); i++) { |
| 740 | g_free(args[i]); | |
| 741 | } | |
| 742 | g_free(args); | |
| 743 | g_free(from); | |
| 744 | } | |
| 745 | ||
| 746 | static void irc_parse_error_cb(struct irc_conn *irc, char *input) | |
| 747 | { | |
|
23433
0094a64519cb
Make the IRC "unknown message" debugging messages UTF-8 safe.
Ethan Blanton <elb@pidgin.im>
parents:
23392
diff
changeset
|
748 | char *clean; |
|
24763
67d9d4c975c0
Replace spaces wth tabs in indentation and tabs with spaces in line continuations.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24574
diff
changeset
|
749 | /* This really should be escaped somehow that you can tell what |
|
67d9d4c975c0
Replace spaces wth tabs in indentation and tabs with spaces in line continuations.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24574
diff
changeset
|
750 | * the junk was -- but as it is, it can crash glib. */ |
|
67d9d4c975c0
Replace spaces wth tabs in indentation and tabs with spaces in line continuations.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24574
diff
changeset
|
751 | clean = purple_utf8_salvage(input); |
|
23433
0094a64519cb
Make the IRC "unknown message" debugging messages UTF-8 safe.
Ethan Blanton <elb@pidgin.im>
parents:
23392
diff
changeset
|
752 | purple_debug(PURPLE_DEBUG_WARNING, "irc", "Unrecognized string: %s\n", clean); |
|
24763
67d9d4c975c0
Replace spaces wth tabs in indentation and tabs with spaces in line continuations.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24574
diff
changeset
|
753 | g_free(clean); |
| 6333 | 754 | } |