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