Sat, 01 Dec 2007 14:08:02 +0000
Pull a bunch of bugfix only changes to im.pidgin.pidgin.2.3.1,
hopefully I didn't get any string changes in here so we can
release off this branch without requiring a new freeze.
applied changes from 8e8cba27fc7816cd4f4c7cf3b88766fa17044415
through 39e5d9f03e532b8584c78ddc91caff2e849faf4c
applied changes from 2702e711166c502d17af8586d58eac0247a01886
through 9a0ae9156ebcba6ee62646fb7e310af4f1b5b33a
applied changes from 9a0ae9156ebcba6ee62646fb7e310af4f1b5b33a
through 5956ea2cb4af794d14fab6bab838fd44782f00e7
applied changes from dc4128cfe2d3f8a85eec29eb92526e18aec6e227
through b4d7c3fe216cda1272c646960d568aaf68155d4d
applied changes from c77aee16184e888f78cd2e43d89ecb6202938d9b
through 30553187b82f795a4c65a0bf7f1e7e6c3fc4ff57
applied changes from 30553187b82f795a4c65a0bf7f1e7e6c3fc4ff57
through b1278944ccaa36c30b7f00edf5b79dc38347c931
applied changes from 41c1eba01a2c9fe574f5c3b0c4a2a6ee0c9955b0
through 83367f8f60af4ebb6636d5aa3e3eed63fc7e49b8
applied changes from 83367f8f60af4ebb6636d5aa3e3eed63fc7e49b8
through cf65b89d71f0a142ac21a919ced9f163b4bc7251
applied changes from cf65b89d71f0a142ac21a919ced9f163b4bc7251
through 55decf7b3893d1f4798d2a966b93eb9f08858f67
applied changes from 88390766d9b581d7a7e2e3b6156437c5bef76e93
through a00ff8e1a342a8326627d51728ad97699740c945
applied changes from a00ff8e1a342a8326627d51728ad97699740c945
through c55dabf731ea4d3fcb287e43b157062eb2d425fa
applied changes from c55dabf731ea4d3fcb287e43b157062eb2d425fa
through b576470ab9bee5e0b1c48de1e78e3e6234254cdb
applied changes from b576470ab9bee5e0b1c48de1e78e3e6234254cdb
through 5865eb4a45b2c059f8cd82ebd88bcca28ec72bd7
applied changes from 472e5899208300c15ff10fe526443261c740d2e2
through b5f18a0ed9a1cdf744b5d3344e415afd5fb05cf1
applied changes from cfebb2730668c41870ff696f157ddd68175aa0f3
through e7f1ca64fe26b46544c0f64f082c81a0a9e96f5f
applied changes from 87a81ecce720018f2f6c6d2983c0259ae3c88814
through 72fffff81de35e7d400bf8b8fb18ba7ed84a6b8c
applied changes from f5e03381162836652532f1495162df4868b7b8cb
through 48faf08abe024b6ad491a1145e309b36fceda249
applied changes from cd4038a435bd39cc62244d5614b8d94ad689d8bf
through d03ce5e2bc3aaa6ee963e1ebced007175aaa099f
applied changes from d03ce5e2bc3aaa6ee963e1ebced007175aaa099f
through f5e03381162836652532f1495162df4868b7b8cb
applied changes from 9e52f5f3fa15ac341c185f72558447f3ff263337
through 727439d778b7d7f40aa0230cb9be26765e8d50a9
applied changes from cd4038a435bd39cc62244d5614b8d94ad689d8bf
through 37d10660345bc1f2092492296caa8deaf84744b4
applied changes from d5c8358a1cdfe381e834ab7f86a9e1fb6835e65f
through 41b4d75b70555daf78b3c5701a59453027ca57e7
applied changes from 41b4d75b70555daf78b3c5701a59453027ca57e7
through fb945a0cab270a5eaf15d294b8706714e22742c1
applied changes from fb945a0cab270a5eaf15d294b8706714e22742c1
through 680ead8ac23fbdc99bd7178248a4cdf0bec54307
applied changes from 41b4d75b70555daf78b3c5701a59453027ca57e7
through 29f8aed19e209a53a63c57cf872bc9f446d84aeb
applied changes from 2996670bdeb36ac63658ea4760a8a1f2e362e703
through 7595eff42168a97a13aec5a68f05916a862b22df
applied changes from 1273d64fc47b82be9ff2bca00d14e37199bcc026
through bd625d93706896fbd570aee9b3d53ceb38241a12
applied changes from c27700a33779f1f8f380b0ed0a62756be4b6f17c
through a66a55b8836e3241bcc5772e499aa7c85d7bef88
applied changes from ed49703095cc1bf4f1938ef4cebcc2d906f5d911
through ae553a7b1f48faebd22d107832f5827460d5d656
| 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 */ |
|
16474
bc8580a69dba
/whowas for IRC. Thanks, achris.
Ethan Blanton <elb@pidgin.im>
parents:
15884
diff
changeset
|
68 | { "369", "nt:", irc_msg_endwhois }, /* End of WHOWAS */ |
| 8114 | 69 | { "321", "*", irc_msg_list }, /* Start of list */ |
| 70 | { "322", "ncv:", irc_msg_list }, /* List. */ | |
| 71 | { "323", ":", irc_msg_list }, /* End of list. */ | |
| 6333 | 72 | { "324", "ncv:", irc_msg_chanmode }, /* Channel modes */ |
| 73 | { "331", "nc:", irc_msg_topic }, /* No channel topic */ | |
| 74 | { "332", "nc:", irc_msg_topic }, /* Channel topic */ | |
| 75 | { "333", "*", irc_msg_ignore }, /* Topic setter stuff */ | |
| 76 | { "353", "nvc:", irc_msg_names }, /* Names list */ | |
| 77 | { "366", "nc:", irc_msg_names }, /* End of names */ | |
| 78 | { "372", "n:", irc_msg_motd }, /* MOTD */ | |
| 79 | { "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
|
80 | { "376", "n:", irc_msg_motd }, /* End of MOTD */ |
| 10564 | 81 | { "391", "nv:", irc_msg_time }, /* Time reply */ |
| 6333 | 82 | { "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
|
83 | { "406", "nt:", irc_msg_nonick }, /* No such nick for WHOWAS */ |
| 7877 | 84 | { "403", "nc:", irc_msg_nochan }, /* No such channel */ |
| 6333 | 85 | { "404", "nt:", irc_msg_nosend }, /* Cannot send to chan */ |
| 86 | { "421", "nv:", irc_msg_unknown }, /* Unknown command */ | |
| 10633 | 87 | { "432", "vn:", irc_msg_badnick }, /* Erroneous nickname */ |
| 6333 | 88 | { "433", "vn:", irc_msg_nickused }, /* Nickname already in use */ |
|
10712
2aded9e9abd4
[gaim-migrate @ 12306]
Richard Laager <rlaager@pidgin.im>
parents:
10659
diff
changeset
|
89 | { "437", "nc:", irc_msg_unavailable }, /* Nick/channel is unavailable */ |
| 6718 | 90 | { "438", "nn:", irc_msg_nochangenick }, /* Nick may not change */ |
| 6333 | 91 | { "442", "nc:", irc_msg_notinchan }, /* Not in channel */ |
| 92 | { "473", "nc:", irc_msg_inviteonly }, /* Tried to join invite-only */ | |
| 93 | { "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
|
94 | { "477", "nc:", irc_msg_regonly }, /* Registration Required */ |
|
10659
caf16376fba0
[gaim-migrate @ 12192]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10633
diff
changeset
|
95 | { "478", "nct:", irc_msg_banfull }, /* Banlist is full */ |
| 6333 | 96 | { "482", "nc:", irc_msg_notop }, /* Need to be op to do that */ |
| 97 | { "501", "n:", irc_msg_badmode }, /* Unknown mode flag */ | |
| 8404 | 98 | { "506", "nc:", irc_msg_nosend }, /* Must identify to send */ |
| 6714 | 99 | { "515", "nc:", irc_msg_regonly }, /* Registration required */ |
| 6333 | 100 | { "invite", "n:", irc_msg_invite }, /* Invited */ |
| 101 | { "join", ":", irc_msg_join }, /* Joined a channel */ | |
| 102 | { "kick", "cn:", irc_msg_kick }, /* KICK */ | |
| 103 | { "mode", "tv:", irc_msg_mode }, /* MODE for channel */ | |
| 104 | { "nick", ":", irc_msg_nick }, /* Nick change */ | |
| 105 | { "notice", "t:", irc_msg_notice }, /* NOTICE recv */ | |
| 106 | { "part", "c:", irc_msg_part }, /* Parted a channel */ | |
| 107 | { "ping", ":", irc_msg_ping }, /* Received PING from server */ | |
| 108 | { "pong", "v:", irc_msg_pong }, /* Received PONG from server */ | |
| 109 | { "privmsg", "t:", irc_msg_privmsg }, /* Received private message */ | |
| 110 | { "topic", "c:", irc_msg_topic }, /* TOPIC command */ | |
| 111 | { "quit", ":", irc_msg_quit }, /* QUIT notice */ | |
| 112 | { "wallops", ":", irc_msg_wallops }, /* WALLOPS command */ | |
| 113 | { NULL, NULL, NULL } | |
| 114 | }; | |
| 115 | ||
| 116 | static struct _irc_user_cmd { | |
| 117 | char *name; | |
| 118 | char *format; | |
| 119 | IRCCmdCallback cb; | |
| 9255 | 120 | char *help; |
| 6333 | 121 | } _irc_cmds[] = { |
| 9255 | 122 | { "action", ":", irc_cmd_ctcp_action, N_("action <action to perform>: Perform an action.") }, |
| 123 | { "away", ":", irc_cmd_away, N_("away [message]: Set an away message, or use no message to return from being away.") }, | |
| 12013 | 124 | { "chanserv", ":", irc_cmd_service, N_("chanserv: Send a command to chanserv") }, |
| 9258 | 125 | { "deop", ":", irc_cmd_op, N_("deop <nick1> [nick2] ...: Remove channel operator status from someone. You must be a channel operator to do this.") }, |
| 126 | { "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.") }, | |
| 127 | { "invite", ":", irc_cmd_invite, N_("invite <nick> [room]: Invite someone to join you in the specified channel, or the current channel.") }, | |
| 9266 | 128 | { "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.") }, |
| 129 | { "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 | 130 | { "kick", "n:", irc_cmd_kick, N_("kick <nick> [message]: Remove someone from a channel. You must be a channel operator to do this.") }, |
| 131 | { "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 | 132 | { "me", ":", irc_cmd_ctcp_action, N_("me <action to perform>: Perform an action.") }, |
| 12013 | 133 | { "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
|
134 | { "mode", ":", irc_cmd_mode, N_("mode <+|-><A-Za-z> <nick|channel>: Set or unset a channel or user mode.") }, |
| 9258 | 135 | { "msg", "t:", irc_cmd_privmsg, N_("msg <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 136 | { "names", "c", irc_cmd_names, N_("names [channel]: List the users currently in a channel.") }, | |
| 9274 | 137 | { "nick", "n", irc_cmd_nick, N_("nick <new nickname>: Change your nickname.") }, |
| 12013 | 138 | { "nickserv", ":", irc_cmd_service, N_("nickserv: Send a command to nickserv") }, |
| 9258 | 139 | { "op", ":", irc_cmd_op, N_("op <nick1> [nick2] ...: Grant channel operator status to someone. You must be a channel operator to do this.") }, |
| 9255 | 140 | { "operwall", ":", irc_cmd_wallops, N_("operwall <message>: If you don't know what this is, you probably can't use it.") }, |
| 12013 | 141 | { "operserv", ":", irc_cmd_service, N_("operserv: Send a command to operserv") }, |
| 9258 | 142 | { "part", "c:", irc_cmd_part, N_("part [room] [message]: Leave the current channel, or a specified channel, with an optional message.") }, |
| 9255 | 143 | { "ping", "n", irc_cmd_ping, N_("ping [nick]: Asks how much lag a user (or the server if no user specified) has.") }, |
| 9258 | 144 | { "query", "n:", irc_cmd_query, N_("query <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 9255 | 145 | { "quit", ":", irc_cmd_quit, N_("quit [message]: Disconnect from the server, with an optional message.") }, |
| 146 | { "quote", "*", irc_cmd_quote, N_("quote [...]: Send a raw command to the server.") }, | |
| 147 | { "remove", "n:", irc_cmd_remove, N_("remove <nick> [message]: Remove someone from a room. You must be a channel operator to do this.") }, | |
| 10564 | 148 | { "time", "", irc_cmd_time, N_("time: Displays the current local time at the IRC server.") }, |
| 9255 | 149 | { "topic", ":", irc_cmd_topic, N_("topic [new topic]: View or change the channel topic.") }, |
| 150 | { "umode", ":", irc_cmd_mode, N_("umode <+|-><A-Za-z>: Set or unset a user mode.") }, | |
| 13943 | 151 | { "version", ":", irc_cmd_ctcp_version, N_("version [nick]: send CTCP VERSION request to a user") }, |
| 9258 | 152 | { "voice", ":", irc_cmd_op, N_("voice <nick1> [nick2] ...: Grant channel voice status to someone. You must be a channel operator to do this.") }, |
| 9255 | 153 | { "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
|
154 | { "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
|
155 | { "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
|
156 | { NULL, NULL, NULL, NULL } |
| 6333 | 157 | }; |
| 158 | ||
| 15884 | 159 | static PurpleCmdRet irc_parse_purple_cmd(PurpleConversation *conv, const gchar *cmd, |
| 9597 | 160 | gchar **args, gchar **error, void *data) |
| 9130 | 161 | { |
| 15884 | 162 | PurpleConnection *gc; |
| 9130 | 163 | struct irc_conn *irc; |
| 164 | struct _irc_user_cmd *cmdent; | |
| 165 | ||
| 15884 | 166 | gc = purple_conversation_get_gc(conv); |
| 9130 | 167 | if (!gc) |
| 15884 | 168 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 169 | |
| 170 | irc = gc->proto_data; | |
| 171 | ||
| 172 | if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL) | |
| 15884 | 173 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 174 | |
| 15884 | 175 | (cmdent->cb)(irc, cmd, purple_conversation_get_name(conv), (const char **)args); |
| 9130 | 176 | |
| 15884 | 177 | return PURPLE_CMD_RET_OK; |
| 9130 | 178 | } |
| 179 | ||
| 180 | static void irc_register_command(struct _irc_user_cmd *c) | |
| 181 | { | |
| 15884 | 182 | PurpleCmdFlag f; |
| 9130 | 183 | char args[10]; |
| 184 | char *format; | |
|
12316
b4e5d5ea15fd
[gaim-migrate @ 14620]
Richard Laager <rlaager@pidgin.im>
parents:
12282
diff
changeset
|
185 | size_t i; |
| 9130 | 186 | |
| 15884 | 187 | f = PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY |
| 188 | | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS; | |
| 9130 | 189 | |
| 190 | format = c->format; | |
| 191 | ||
| 192 | for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++) | |
| 193 | switch (*format) { | |
| 194 | case 'v': | |
| 195 | case 'n': | |
| 196 | case 'c': | |
| 197 | case 't': | |
| 198 | args[i] = 'w'; | |
| 199 | break; | |
| 200 | case ':': | |
| 201 | case '*': | |
| 202 | args[i] = 's'; | |
| 203 | break; | |
| 204 | } | |
| 205 | ||
| 206 | args[i] = '\0'; | |
| 207 | ||
| 15884 | 208 | purple_cmd_register(c->name, args, PURPLE_CMD_P_PRPL, f, "prpl-irc", |
| 209 | irc_parse_purple_cmd, _(c->help), NULL); | |
| 9130 | 210 | } |
| 211 | ||
| 212 | void irc_register_commands(void) | |
| 213 | { | |
| 214 | struct _irc_user_cmd *c; | |
| 215 | ||
| 216 | for (c = _irc_cmds; c && c->name; c++) | |
| 217 | irc_register_command(c); | |
| 218 | } | |
| 219 | ||
| 6333 | 220 | static char *irc_send_convert(struct irc_conn *irc, const char *string) |
| 221 | { | |
| 222 | char *utf8; | |
| 223 | GError *err = NULL; | |
| 10258 | 224 | gchar **encodings; |
| 225 | const gchar *enclist; | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
226 | |
| 15884 | 227 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 228 | encodings = g_strsplit(enclist, ",", 2); |
| 229 | ||
|
17138
d666ace4a8ac
strcasecmp is post-C89, so use the glib equivalent
Ethan Blanton <elb@pidgin.im>
parents:
16993
diff
changeset
|
230 | if (encodings[0] == NULL || !g_ascii_strcasecmp("UTF-8", encodings[0])) { |
| 10278 | 231 | g_strfreev(encodings); |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
232 | return g_strdup(string); |
| 10278 | 233 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
234 | |
| 10258 | 235 | utf8 = g_convert(string, strlen(string), encodings[0], "UTF-8", NULL, NULL, &err); |
| 6333 | 236 | if (err) { |
| 15884 | 237 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message); |
| 238 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", encodings[0]); | |
| 6333 | 239 | utf8 = g_strdup(string); |
| 8954 | 240 | g_error_free(err); |
| 6333 | 241 | } |
| 10258 | 242 | g_strfreev(encodings); |
| 243 | ||
| 6333 | 244 | return utf8; |
| 245 | } | |
| 246 | ||
| 247 | static char *irc_recv_convert(struct irc_conn *irc, const char *string) | |
| 248 | { | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
249 | char *utf8 = NULL; |
| 10258 | 250 | const gchar *charset, *enclist; |
| 251 | gchar **encodings; | |
| 252 | int i; | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
253 | |
| 15884 | 254 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 255 | encodings = g_strsplit(enclist, ",", -1); |
| 256 | ||
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
257 | if (encodings[0] == NULL) { |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
258 | g_strfreev(encodings); |
| 15884 | 259 | return purple_utf8_salvage(string); |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
260 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
261 | |
| 10258 | 262 | for (i = 0; encodings[i] != NULL; i++) { |
| 263 | charset = encodings[i]; | |
| 264 | while (*charset == ' ') | |
| 265 | charset++; | |
| 266 | ||
|
17156
6d4cc0f310d1
More strcasecmp() replacements.
Richard Laager <rlaager@pidgin.im>
parents:
17138
diff
changeset
|
267 | if (!g_ascii_strcasecmp("UTF-8", charset)) { |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
268 | if (g_utf8_validate(string, -1, NULL)) |
| 10258 | 269 | utf8 = g_strdup(string); |
| 270 | } else { | |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
271 | utf8 = g_convert(string, -1, "UTF-8", charset, NULL, NULL, NULL); |
| 10258 | 272 | } |
| 273 | ||
| 274 | if (utf8) { | |
| 275 | g_strfreev(encodings); | |
| 276 | return utf8; | |
| 277 | } | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
278 | } |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
279 | g_strfreev(encodings); |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
280 | |
| 15884 | 281 | return purple_utf8_salvage(string); |
| 6333 | 282 | } |
| 283 | ||
|
20217
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
284 | /* 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
|
285 | * 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
|
286 | * behavior changed in glib 2.12. */ |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
287 | 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
|
288 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
289 | const char *p = text; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
290 | const char *end = text + length; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
291 | const char *next = NULL; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
292 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
293 | while(p != end) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
294 | next = g_utf8_next_char(p); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
295 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
296 | switch(*p) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
297 | case '&': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
298 | g_string_append(str, "&"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
299 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
300 | case '<': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
301 | g_string_append(str, "<"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
302 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
303 | case '>': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
304 | g_string_append(str, ">"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
305 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
306 | case '\'': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
307 | g_string_append(str, "'"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
308 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
309 | case '"': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
310 | g_string_append(str, """); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
311 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
312 | default: |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
313 | g_string_append_len(str, p, next - p); |
|
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 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
316 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
317 | p = next; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
318 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
319 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
320 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
321 | /* 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
|
322 | * 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
|
323 | char *irc_escape_privmsg(const char *text, gssize length) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
324 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
325 | GString *str; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
326 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
327 | g_return_val_if_fail(text != NULL, NULL); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
328 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
329 | if(length < 0) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
330 | length = strlen(text); |
|
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 | str = g_string_sized_new(length); |
|
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 | irc_append_escaped_text(str, text, length); |
|
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 | return g_string_free(str, FALSE); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
337 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
338 | |
| 6333 | 339 | /* XXX tag closings are not necessarily correctly nested here! If we |
| 340 | * get a ^O or reach the end of the string and there are open | |
| 341 | * tags, they are closed in a fixed order ... this means, for | |
| 342 | * example, you might see <FONT COLOR="blue">some text <B>with | |
| 343 | * various attributes</FONT></B> (notice that B and FONT overlap | |
| 344 | * and are not cleanly nested). This is imminently fixable but | |
| 345 | * I am not fixing it right now. | |
| 346 | */ | |
| 347 | char *irc_mirc2html(const char *string) | |
| 348 | { | |
| 349 | const char *cur, *end; | |
| 350 | char fg[3] = "\0\0", bg[3] = "\0\0"; | |
| 351 | int fgnum, bgnum; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
352 | int font = 0, bold = 0, underline = 0, italic = 0; |
| 6333 | 353 | GString *decoded = g_string_sized_new(strlen(string)); |
| 354 | ||
| 355 | cur = string; | |
| 356 | do { | |
| 6754 | 357 | end = strpbrk(cur, "\002\003\007\017\026\037"); |
| 6333 | 358 | |
| 359 | decoded = g_string_append_len(decoded, cur, end ? end - cur : strlen(cur)); | |
| 360 | cur = end ? end : cur + strlen(cur); | |
| 361 | ||
| 362 | switch (*cur) { | |
| 363 | case '\002': | |
| 364 | cur++; | |
| 365 | if (!bold) { | |
| 366 | decoded = g_string_append(decoded, "<B>"); | |
| 367 | bold = TRUE; | |
| 368 | } else { | |
| 369 | decoded = g_string_append(decoded, "</B>"); | |
| 370 | bold = FALSE; | |
| 371 | } | |
| 372 | break; | |
| 373 | case '\003': | |
| 374 | cur++; | |
| 375 | fg[0] = fg[1] = bg[0] = bg[1] = '\0'; | |
| 376 | if (isdigit(*cur)) | |
| 377 | fg[0] = *cur++; | |
| 378 | if (isdigit(*cur)) | |
| 379 | fg[1] = *cur++; | |
| 380 | if (*cur == ',') { | |
| 381 | cur++; | |
| 382 | if (isdigit(*cur)) | |
| 383 | bg[0] = *cur++; | |
| 384 | if (isdigit(*cur)) | |
| 385 | bg[1] = *cur++; | |
| 386 | } | |
| 387 | if (font) { | |
| 388 | decoded = g_string_append(decoded, "</FONT>"); | |
| 389 | font = FALSE; | |
| 390 | } | |
| 391 | ||
| 392 | if (fg[0]) { | |
| 393 | fgnum = atoi(fg); | |
| 394 | if (fgnum < 0 || fgnum > 15) | |
| 395 | continue; | |
| 396 | font = TRUE; | |
| 397 | g_string_append_printf(decoded, "<FONT COLOR=\"%s\"", irc_mirc_colors[fgnum]); | |
| 398 | if (bg[0]) { | |
| 399 | bgnum = atoi(bg); | |
| 400 | if (bgnum >= 0 && bgnum < 16) | |
| 401 | g_string_append_printf(decoded, " BACK=\"%s\"", irc_mirc_colors[bgnum]); | |
| 402 | } | |
| 403 | decoded = g_string_append_c(decoded, '>'); | |
| 404 | } | |
| 405 | break; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
406 | case '\011': |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
407 | cur++; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
408 | if (!italic) { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
409 | decoded = g_string_append(decoded, "<I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
410 | italic = TRUE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
411 | } else { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
412 | decoded = g_string_append(decoded, "</I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
413 | italic = FALSE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
414 | } |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
415 | break; |
| 6754 | 416 | case '\037': |
| 417 | cur++; | |
| 418 | if (!underline) { | |
| 419 | decoded = g_string_append(decoded, "<U>"); | |
| 420 | underline = TRUE; | |
| 421 | } else { | |
| 422 | decoded = g_string_append(decoded, "</U>"); | |
| 12282 | 423 | underline = FALSE; |
| 6754 | 424 | } |
| 425 | break; | |
| 6333 | 426 | case '\007': |
| 427 | case '\026': | |
| 428 | cur++; | |
| 429 | break; | |
| 430 | case '\017': | |
| 431 | cur++; | |
| 432 | /* fallthrough */ | |
| 433 | case '\000': | |
| 434 | if (bold) | |
| 6754 | 435 | decoded = g_string_append(decoded, "</B>"); |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
436 | if (italic) |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
437 | decoded = g_string_append(decoded, "</I>"); |
| 6754 | 438 | if (underline) |
| 439 | decoded = g_string_append(decoded, "</U>"); | |
| 6333 | 440 | if (font) |
| 441 | decoded = g_string_append(decoded, "</FONT>"); | |
| 442 | break; | |
| 443 | default: | |
| 15884 | 444 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unexpected mIRC formatting character %d\n", *cur); |
| 6333 | 445 | } |
| 446 | } while (*cur); | |
| 447 | ||
| 448 | return g_string_free(decoded, FALSE); | |
| 449 | } | |
| 450 | ||
| 8529 | 451 | char *irc_mirc2txt (const char *string) |
| 452 | { | |
| 453 | char *result = g_strdup (string); | |
| 454 | int i, j; | |
| 455 | ||
| 456 | for (i = 0, j = 0; result[i]; i++) { | |
| 457 | switch (result[i]) { | |
| 458 | case '\002': | |
| 459 | case '\003': | |
|
17409
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
460 | /* Foreground color */ |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
461 | 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
|
462 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
463 | 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
|
464 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
465 | /* 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
|
466 | 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
|
467 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
468 | 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
|
469 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
470 | 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
|
471 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
472 | } |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
473 | /* 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
|
474 | * 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
|
475 | continue; |
| 8529 | 476 | case '\007': |
| 477 | case '\017': | |
| 478 | case '\026': | |
| 479 | case '\037': | |
| 480 | continue; | |
| 481 | default: | |
| 482 | result[j++] = result[i]; | |
| 483 | } | |
| 484 | } | |
| 11136 | 485 | result[j] = '\0'; |
| 8529 | 486 | return result; |
| 487 | } | |
| 488 | ||
| 10208 | 489 | gboolean irc_ischannel(const char *string) |
| 490 | { | |
| 491 | return (string[0] == '#' || string[0] == '&'); | |
| 492 | } | |
| 493 | ||
| 6333 | 494 | char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice) |
| 495 | { | |
| 15884 | 496 | PurpleConnection *gc; |
| 6333 | 497 | const char *cur = msg + 1; |
| 498 | char *buf, *ctcp; | |
| 499 | time_t timestamp; | |
| 500 | ||
| 6754 | 501 | /* Note that this is NOT correct w.r.t. multiple CTCPs in one |
| 502 | * message and low-level quoting ... but if you want that crap, | |
| 503 | * use a real IRC client. */ | |
| 504 | ||
| 6333 | 505 | if (msg[0] != '\001' || msg[strlen(msg) - 1] != '\001') |
| 506 | return g_strdup(msg); | |
| 507 | ||
| 508 | if (!strncmp(cur, "ACTION ", 7)) { | |
| 509 | cur += 7; | |
| 510 | buf = g_strdup_printf("/me %s", cur); | |
| 511 | buf[strlen(buf) - 1] = '\0'; | |
| 512 | return buf; | |
| 513 | } else if (!strncmp(cur, "PING ", 5)) { | |
| 514 | if (notice) { /* reply */ | |
|
11972
23ac6d9de1fa
[gaim-migrate @ 14265]
Mark Doliner <markdoliner@pidgin.im>
parents:
11726
diff
changeset
|
515 | /* TODO: Should this read in the timestamp as a double? */ |
| 6333 | 516 | sscanf(cur, "PING %lu", ×tamp); |
| 15884 | 517 | gc = purple_account_get_connection(irc->account); |
| 6333 | 518 | if (!gc) |
| 519 | return NULL; | |
| 6350 | 520 | buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp); |
| 15884 | 521 | purple_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf); |
| 6333 | 522 | g_free(buf); |
| 523 | return NULL; | |
| 524 | } else { | |
| 525 | buf = irc_format(irc, "vt:", "NOTICE", from, msg); | |
| 526 | irc_send(irc, buf); | |
| 527 | g_free(buf); | |
| 528 | } | |
| 529 | } else if (!strncmp(cur, "VERSION", 7) && !notice) { | |
| 15884 | 530 | buf = irc_format(irc, "vt:", "NOTICE", from, "\001VERSION Purple IRC\001"); |
| 6333 | 531 | irc_send(irc, buf); |
| 532 | g_free(buf); | |
| 8351 | 533 | } else if (!strncmp(cur, "DCC SEND ", 9)) { |
| 534 | irc_dccsend_recv(irc, from, msg + 10); | |
| 535 | return NULL; | |
| 6333 | 536 | } |
| 537 | ||
| 538 | ctcp = g_strdup(msg + 1); | |
| 539 | ctcp[strlen(ctcp) - 1] = '\0'; | |
| 540 | buf = g_strdup_printf("Received CTCP '%s' (to %s) from %s", ctcp, to, from); | |
| 541 | g_free(ctcp); | |
| 542 | return buf; | |
| 543 | } | |
| 544 | ||
| 545 | void irc_msg_table_build(struct irc_conn *irc) | |
| 546 | { | |
| 547 | int i; | |
| 548 | ||
| 549 | if (!irc || !irc->msgs) { | |
| 15884 | 550 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a message table on a bogus structure\n"); |
| 6333 | 551 | return; |
| 552 | } | |
| 553 | ||
| 554 | for (i = 0; _irc_msgs[i].name; i++) { | |
| 555 | g_hash_table_insert(irc->msgs, (gpointer)_irc_msgs[i].name, (gpointer)&_irc_msgs[i]); | |
| 556 | } | |
| 557 | } | |
| 558 | ||
| 559 | void irc_cmd_table_build(struct irc_conn *irc) | |
| 560 | { | |
| 561 | int i; | |
| 562 | ||
| 563 | if (!irc || !irc->cmds) { | |
| 15884 | 564 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a command table on a bogus structure\n"); |
| 6333 | 565 | return; |
| 566 | } | |
| 567 | ||
| 568 | for (i = 0; _irc_cmds[i].name ; i++) { | |
| 569 | g_hash_table_insert(irc->cmds, (gpointer)_irc_cmds[i].name, (gpointer)&_irc_cmds[i]); | |
| 570 | } | |
| 571 | } | |
| 572 | ||
| 573 | char *irc_format(struct irc_conn *irc, const char *format, ...) | |
| 574 | { | |
| 575 | GString *string = g_string_new(""); | |
| 576 | char *tok, *tmp; | |
| 577 | const char *cur; | |
| 578 | va_list ap; | |
| 579 | ||
| 580 | va_start(ap, format); | |
| 581 | for (cur = format; *cur; cur++) { | |
| 582 | if (cur != format) | |
| 583 | g_string_append_c(string, ' '); | |
| 584 | ||
| 585 | tok = va_arg(ap, char *); | |
| 586 | switch (*cur) { | |
| 587 | case 'v': | |
| 588 | g_string_append(string, tok); | |
| 589 | break; | |
| 590 | case ':': | |
| 591 | g_string_append_c(string, ':'); | |
| 592 | /* no break! */ | |
| 593 | case 't': | |
| 594 | case 'n': | |
| 595 | case 'c': | |
| 596 | tmp = irc_send_convert(irc, tok); | |
| 597 | g_string_append(string, tmp); | |
| 598 | g_free(tmp); | |
| 599 | break; | |
| 600 | default: | |
| 15884 | 601 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Invalid format character '%c'\n", *cur); |
| 6333 | 602 | break; |
| 603 | } | |
| 604 | } | |
| 605 | va_end(ap); | |
| 606 | g_string_append(string, "\r\n"); | |
| 607 | return (g_string_free(string, FALSE)); | |
| 608 | } | |
| 609 | ||
| 610 | void irc_parse_msg(struct irc_conn *irc, char *input) | |
| 611 | { | |
| 612 | struct _irc_msg *msgent; | |
| 613 | char *cur, *end, *tmp, *from, *msgname, *fmt, **args, *msg; | |
| 7631 | 614 | guint i; |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
615 | PurpleConnection *gc = purple_account_get_connection(irc->account); |
| 6333 | 616 | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
617 | irc->recv_time = time(NULL); |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
618 | |
|
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
619 | /* |
|
14996
291304176e0b
[gaim-migrate @ 17706]
Mark Doliner <markdoliner@pidgin.im>
parents:
14995
diff
changeset
|
620 | * 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
|
621 | * 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
|
622 | * instead of a null terminated string. |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
623 | */ |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
624 | purple_signal_emit(_irc_plugin, "irc-receiving-text", gc, &input); |
| 14683 | 625 | |
| 6333 | 626 | if (!strncmp(input, "PING ", 5)) { |
| 627 | msg = irc_format(irc, "vv", "PONG", input + 5); | |
| 628 | irc_send(irc, msg); | |
| 629 | g_free(msg); | |
| 630 | return; | |
| 631 | } else if (!strncmp(input, "ERROR ", 6)) { | |
| 10154 | 632 | if (g_utf8_validate(input, -1, NULL)) { |
| 633 | char *tmp = g_strdup_printf("%s\n%s", _("Disconnected."), input); | |
| 21279 | 634 | purple_connection_error_reason (gc, |
| 635 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | |
| 10154 | 636 | g_free(tmp); |
| 637 | } else | |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
638 | purple_connection_error_reason (gc, |
| 21279 | 639 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 640 | _("Disconnected.")); | |
| 6333 | 641 | return; |
| 642 | } | |
| 643 | ||
| 644 | if (input[0] != ':' || (cur = strchr(input, ' ')) == NULL) { | |
| 645 | irc_parse_error_cb(irc, input); | |
| 646 | return; | |
| 647 | } | |
| 648 | ||
| 649 | from = g_strndup(&input[1], cur - &input[1]); | |
| 650 | cur++; | |
| 651 | end = strchr(cur, ' '); | |
| 652 | if (!end) | |
| 653 | end = cur + strlen(cur); | |
| 654 | ||
| 655 | tmp = g_strndup(cur, end - cur); | |
| 656 | msgname = g_ascii_strdown(tmp, -1); | |
| 657 | g_free(tmp); | |
| 658 | ||
| 659 | if ((msgent = g_hash_table_lookup(irc->msgs, msgname)) == NULL) { | |
| 660 | irc_msg_default(irc, "", from, &input); | |
| 661 | g_free(msgname); | |
| 662 | g_free(from); | |
| 663 | return; | |
| 664 | } | |
| 665 | g_free(msgname); | |
| 666 | ||
| 667 | args = g_new0(char *, strlen(msgent->format)); | |
| 668 | for (cur = end, fmt = msgent->format, i = 0; fmt[i] && *cur++; i++) { | |
| 669 | switch (fmt[i]) { | |
| 670 | case 'v': | |
| 671 | if (!(end = strchr(cur, ' '))) end = cur + strlen(cur); | |
| 672 | args[i] = g_strndup(cur, end - cur); | |
| 673 | cur += end - cur; | |
| 674 | break; | |
| 675 | case 't': | |
| 676 | case 'n': | |
| 677 | case 'c': | |
| 678 | if (!(end = strchr(cur, ' '))) end = cur + strlen(cur); | |
| 679 | tmp = g_strndup(cur, end - cur); | |
| 680 | args[i] = irc_recv_convert(irc, tmp); | |
| 681 | g_free(tmp); | |
| 682 | cur += end - cur; | |
| 683 | break; | |
| 684 | case ':': | |
| 685 | if (*cur == ':') cur++; | |
| 686 | args[i] = irc_recv_convert(irc, cur); | |
| 687 | cur = cur + strlen(cur); | |
| 688 | break; | |
| 689 | case '*': | |
| 690 | args[i] = g_strdup(cur); | |
| 691 | cur = cur + strlen(cur); | |
| 692 | break; | |
| 693 | default: | |
| 15884 | 694 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid message format character '%c'\n", fmt[i]); |
| 6333 | 695 | break; |
| 696 | } | |
| 697 | } | |
| 6970 | 698 | tmp = irc_recv_convert(irc, from); |
| 699 | (msgent->cb)(irc, msgent->name, tmp, args); | |
| 700 | g_free(tmp); | |
| 6333 | 701 | for (i = 0; i < strlen(msgent->format); i++) { |
| 702 | g_free(args[i]); | |
| 703 | } | |
| 704 | g_free(args); | |
| 705 | g_free(from); | |
| 706 | } | |
| 707 | ||
| 708 | static void irc_parse_error_cb(struct irc_conn *irc, char *input) | |
| 709 | { | |
| 15884 | 710 | purple_debug(PURPLE_DEBUG_WARNING, "irc", "Unrecognized string: %s\n", input); |
| 6333 | 711 | } |