Wed, 27 Apr 2022 23:44:53 -0500
Make all irc login time commands skip the rate limiter.
Most networks don't rate limit during the login process but will time you out
if you take too long. Running through the SASL mechansism on Freenode with the
rate limiter was causing us to time out. The ideal solution is to handle the
908 reply and use those mechanisms directly, but I ran into some issues and
this is useful on its own.
Testing Done:
Connected to Freenode and verified we didn't time out during SASL login.
Reviewed at https://reviews.imfreedom.org/r/1391/
| 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; | |
|
35253
4d9be297d399
Fill in req_cnt for irc_msg_kick and irc_msg_nick.
Mark Doliner <mark@kingant.net>
parents:
35250
diff
changeset
|
53 | |
|
4d9be297d399
Fill in req_cnt for irc_msg_kick and irc_msg_nick.
Mark Doliner <mark@kingant.net>
parents:
35250
diff
changeset
|
54 | /** The required parameter count, based on values we use, not protocol |
|
4d9be297d399
Fill in req_cnt for irc_msg_kick and irc_msg_nick.
Mark Doliner <mark@kingant.net>
parents:
35250
diff
changeset
|
55 | * specification. */ |
|
4d9be297d399
Fill in req_cnt for irc_msg_kick and irc_msg_nick.
Mark Doliner <mark@kingant.net>
parents:
35250
diff
changeset
|
56 | int req_cnt; |
|
4d9be297d399
Fill in req_cnt for irc_msg_kick and irc_msg_nick.
Mark Doliner <mark@kingant.net>
parents:
35250
diff
changeset
|
57 | |
| 6333 | 58 | void (*cb)(struct irc_conn *irc, const char *name, const char *from, char **args); |
| 59 | } _irc_msgs[] = { | |
|
35250
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
60 | { "005", "n*", 2, irc_msg_features }, /* Feature list */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
61 | { "251", "n:", 1, irc_msg_luser }, /* Client & Server count */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
62 | { "255", "n:", 1, irc_msg_luser }, /* Client & Server count Mk. II */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
63 | { "301", "nn:", 3, irc_msg_away }, /* User is away */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
64 | { "303", "n:", 2, irc_msg_ison }, /* ISON reply */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
65 | { "311", "nnvvv:", 6, irc_msg_whois }, /* Whois user */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
66 | { "312", "nnv:", 4, irc_msg_whois }, /* Whois server */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
67 | { "313", "nn:", 2, irc_msg_whois }, /* Whois ircop */ |
|
35272
d33c29cda7bb
I think 317 actually only requires 3 args. I think the fourth is optional.
Mark Doliner <mark@kingant.net>
parents:
35253
diff
changeset
|
68 | { "317", "nnvv", 3, irc_msg_whois }, /* Whois idle */ |
|
35250
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
69 | { "318", "nt:", 2, irc_msg_endwhois }, /* End of WHOIS */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
70 | { "319", "nn:", 3, irc_msg_whois }, /* Whois channels */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
71 | { "320", "nn:", 2, irc_msg_whois }, /* Whois (fn ident) */ |
|
35282
9a21b3ce6ed7
Followup on 639ec03ba1ba related to the IRC security fixes - also fix debugging
Daniel Atallah <datallah@pidgin.im>
parents:
35280
diff
changeset
|
72 | { "330", "nnv:", 4, irc_msg_whois }, /* Whois (fn login) */ |
|
35250
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
73 | { "314", "nnnvv:", 6, irc_msg_whois }, /* Whowas user */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
74 | { "315", "nt:", 0, irc_msg_who }, /* end of WHO channel */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
75 | { "369", "nt:", 2, irc_msg_endwhois }, /* End of WHOWAS */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
76 | { "321", "*", 0, irc_msg_list }, /* Start of list */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
77 | { "322", "ncv:", 4, irc_msg_list }, /* List. */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
78 | { "323", ":", 0, irc_msg_list }, /* End of list. */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
79 | { "324", "ncv:", 3, irc_msg_chanmode }, /* Channel modes */ |
|
35248
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
80 | { "331", "nc:", 3, irc_msg_topic }, /* No channel topic */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
81 | { "332", "nc:", 3, irc_msg_topic }, /* Channel topic */ |
|
35250
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
82 | { "333", "ncvv", 4, irc_msg_topicinfo }, /* Topic setter stuff */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
83 | { "352", "ncvvvnv:", 8, irc_msg_who }, /* Channel WHO */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
84 | { "353", "nvc:", 4, irc_msg_names }, /* Names list */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
85 | { "366", "nc:", 2, irc_msg_names }, /* End of names */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
86 | { "367", "ncnnv", 3, irc_msg_ban }, /* Ban list */ |
|
6b0e0566af20
IRC: fill required command parameter counts (part 3)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35249
diff
changeset
|
87 | { "368", "nc:", 2, irc_msg_ban }, /* End of ban list */ |
|
35249
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
88 | { "372", "n:", 1, irc_msg_motd }, /* MOTD */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
89 | { "375", "n:", 1, irc_msg_motd }, /* Start MOTD */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
90 | { "376", "n:", 1, irc_msg_motd }, /* End of MOTD */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
91 | { "391", "nv:", 3, irc_msg_time }, /* Time reply */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
92 | { "401", "nt:", 2, irc_msg_nonick }, /* No such nick/chan */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
93 | { "406", "nt:", 2, irc_msg_nonick }, /* No such nick for WHOWAS */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
94 | { "403", "nc:", 2, irc_msg_nochan }, /* No such channel */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
95 | { "404", "nt:", 3, irc_msg_nosend }, /* Cannot send to chan */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
96 | { "421", "nv:", 2, irc_msg_unknown }, /* Unknown command */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
97 | { "422", "n:", 1, irc_msg_motd }, /* MOTD file missing */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
98 | { "432", "vn:", 0, irc_msg_badnick }, /* Erroneous nickname */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
99 | { "433", "vn:", 2, irc_msg_nickused }, /* Nickname already in use */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
100 | { "437", "nc:", 2, irc_msg_unavailable }, /* Nick/channel is unavailable */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
101 | { "438", "nn:", 3, irc_msg_nochangenick }, /* Nick may not change */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
102 | { "442", "nc:", 3, irc_msg_notinchan }, /* Not in channel */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
103 | { "473", "nc:", 2, irc_msg_inviteonly }, /* Tried to join invite-only */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
104 | { "474", "nc:", 2, irc_msg_banned }, /* Banned from channel */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
105 | { "477", "nc:", 3, irc_msg_regonly }, /* Registration Required */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
106 | { "478", "nct:", 3, irc_msg_banfull }, /* Banlist is full */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
107 | { "482", "nc:", 3, irc_msg_notop }, /* Need to be op to do that */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
108 | { "501", "n:", 2, irc_msg_badmode }, /* Unknown mode flag */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
109 | { "506", "nc:", 3, irc_msg_nosend }, /* Must identify to send */ |
|
5845d9fa7084
IRC: fill required command parameter counts (part 2)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35248
diff
changeset
|
110 | { "515", "nc:", 3, irc_msg_regonly }, /* Registration required */ |
|
33404
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
111 | #ifdef HAVE_CYRUS_SASL |
|
35248
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
112 | { "903", "*", 0, irc_msg_authok}, /* SASL auth successful */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
113 | { "904", "*", 0, irc_msg_authtryagain }, /* SASL auth failed, can recover*/ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
114 | { "905", "*", 0, irc_msg_authfail }, /* SASL auth failed */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
115 | { "906", "*", 0, irc_msg_authfail }, /* SASL auth failed */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
116 | { "907", "*", 0, irc_msg_authfail }, /* SASL auth failed */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
117 | { "cap", "vv:", 3, irc_msg_cap }, /* SASL capable */ |
|
38908
86e7c9ca0bcd
irc: handle AUTHENTICATE as a normal command with server prefix
dx <dx@dxzone.com.ar>
parents:
38907
diff
changeset
|
118 | { "authenticate", ":", 1, irc_msg_authenticate }, /* SASL authenticate */ |
|
33404
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
119 | #endif |
|
35248
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
120 | { "invite", "n:", 2, irc_msg_invite }, /* Invited */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
121 | { "join", ":", 1, irc_msg_join }, /* Joined a channel */ |
|
35253
4d9be297d399
Fill in req_cnt for irc_msg_kick and irc_msg_nick.
Mark Doliner <mark@kingant.net>
parents:
35250
diff
changeset
|
122 | { "kick", "cn:", 3, irc_msg_kick }, /* KICK */ |
|
35248
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
123 | { "mode", "tv:", 2, irc_msg_mode }, /* MODE for channel */ |
|
35253
4d9be297d399
Fill in req_cnt for irc_msg_kick and irc_msg_nick.
Mark Doliner <mark@kingant.net>
parents:
35250
diff
changeset
|
124 | { "nick", ":", 1, irc_msg_nick }, /* Nick change */ |
|
35248
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
125 | { "notice", "t:", 2, irc_msg_notice }, /* NOTICE recv */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
126 | { "part", "c:", 1, irc_msg_part }, /* Parted a channel */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
127 | { "ping", ":", 1, irc_msg_ping }, /* Received PING from server */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
128 | { "pong", "v:", 2, irc_msg_pong }, /* Received PONG from server */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
129 | { "privmsg", "t:", 2, irc_msg_privmsg }, /* Received private message */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
130 | { "topic", "c:", 2, irc_msg_topic }, /* TOPIC command */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
131 | { "quit", ":", 1, irc_msg_quit }, /* QUIT notice */ |
|
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
132 | { "wallops", ":", 1, irc_msg_wallops }, /* WALLOPS command */ |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
133 | { NULL, NULL, 0, NULL } |
| 6333 | 134 | }; |
| 135 | ||
| 136 | static struct _irc_user_cmd { | |
| 137 | char *name; | |
| 138 | char *format; | |
| 139 | IRCCmdCallback cb; | |
| 9255 | 140 | char *help; |
| 6333 | 141 | } _irc_cmds[] = { |
| 9255 | 142 | { "action", ":", irc_cmd_ctcp_action, N_("action <action to perform>: Perform an action.") }, |
|
31651
24e136c4c399
Add authserv support to IRC. Need a name to credit tomos with. Fixes #13337.
Tomos Lelong <lelongt@gmail.com>
parents:
31565
diff
changeset
|
143 | { "authserv", ":", irc_cmd_service, N_("authserv: Send a command to authserv") }, |
| 9255 | 144 | { "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
|
145 | { "ctcp", "t:", irc_cmd_ctcp, N_("ctcp <nick> <msg>: sends ctcp msg to nick.") }, |
| 12013 | 146 | { "chanserv", ":", irc_cmd_service, N_("chanserv: Send a command to chanserv") }, |
| 9258 | 147 | { "deop", ":", irc_cmd_op, N_("deop <nick1> [nick2] ...: Remove channel operator status from someone. You must be a channel operator to do this.") }, |
| 148 | { "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.") }, | |
| 149 | { "invite", ":", irc_cmd_invite, N_("invite <nick> [room]: Invite someone to join you in the specified channel, or the current channel.") }, | |
| 9266 | 150 | { "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.") }, |
| 151 | { "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 | 152 | { "kick", "n:", irc_cmd_kick, N_("kick <nick> [message]: Remove someone from a channel. You must be a channel operator to do this.") }, |
| 153 | { "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 | 154 | { "me", ":", irc_cmd_ctcp_action, N_("me <action to perform>: Perform an action.") }, |
| 12013 | 155 | { "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
|
156 | { "mode", ":", irc_cmd_mode, N_("mode <+|-><A-Za-z> <nick|channel>: Set or unset a channel or user mode.") }, |
| 9258 | 157 | { "msg", "t:", irc_cmd_privmsg, N_("msg <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 158 | { "names", "c", irc_cmd_names, N_("names [channel]: List the users currently in a channel.") }, | |
| 9274 | 159 | { "nick", "n", irc_cmd_nick, N_("nick <new nickname>: Change your nickname.") }, |
| 12013 | 160 | { "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
|
161 | { "notice", "t:", irc_cmd_privmsg, N_("notice <target<: Send a notice to a user or channel.") }, |
| 9258 | 162 | { "op", ":", irc_cmd_op, N_("op <nick1> [nick2] ...: Grant channel operator status to someone. You must be a channel operator to do this.") }, |
| 9255 | 163 | { "operwall", ":", irc_cmd_wallops, N_("operwall <message>: If you don't know what this is, you probably can't use it.") }, |
| 12013 | 164 | { "operserv", ":", irc_cmd_service, N_("operserv: Send a command to operserv") }, |
| 9258 | 165 | { "part", "c:", irc_cmd_part, N_("part [room] [message]: Leave the current channel, or a specified channel, with an optional message.") }, |
| 9255 | 166 | { "ping", "n", irc_cmd_ping, N_("ping [nick]: Asks how much lag a user (or the server if no user specified) has.") }, |
| 9258 | 167 | { "query", "n:", irc_cmd_query, N_("query <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 9255 | 168 | { "quit", ":", irc_cmd_quit, N_("quit [message]: Disconnect from the server, with an optional message.") }, |
| 169 | { "quote", "*", irc_cmd_quote, N_("quote [...]: Send a raw command to the server.") }, | |
| 170 | { "remove", "n:", irc_cmd_remove, N_("remove <nick> [message]: Remove someone from a room. You must be a channel operator to do this.") }, | |
| 10564 | 171 | { "time", "", irc_cmd_time, N_("time: Displays the current local time at the IRC server.") }, |
| 9255 | 172 | { "topic", ":", irc_cmd_topic, N_("topic [new topic]: View or change the channel topic.") }, |
| 173 | { "umode", ":", irc_cmd_mode, N_("umode <+|-><A-Za-z>: Set or unset a user mode.") }, | |
| 13943 | 174 | { "version", ":", irc_cmd_ctcp_version, N_("version [nick]: send CTCP VERSION request to a user") }, |
| 9258 | 175 | { "voice", ":", irc_cmd_op, N_("voice <nick1> [nick2] ...: Grant channel voice status to someone. You must be a channel operator to do this.") }, |
| 9255 | 176 | { "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
|
177 | { "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
|
178 | { "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
|
179 | { NULL, NULL, NULL, NULL } |
| 6333 | 180 | }; |
| 181 | ||
| 15884 | 182 | static PurpleCmdRet irc_parse_purple_cmd(PurpleConversation *conv, const gchar *cmd, |
| 9597 | 183 | gchar **args, gchar **error, void *data) |
| 9130 | 184 | { |
| 15884 | 185 | PurpleConnection *gc; |
| 9130 | 186 | struct irc_conn *irc; |
| 187 | struct _irc_user_cmd *cmdent; | |
| 188 | ||
| 15884 | 189 | gc = purple_conversation_get_gc(conv); |
| 9130 | 190 | if (!gc) |
| 15884 | 191 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 192 | |
| 193 | irc = gc->proto_data; | |
| 194 | ||
| 195 | if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL) | |
| 15884 | 196 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 197 | |
| 15884 | 198 | (cmdent->cb)(irc, cmd, purple_conversation_get_name(conv), (const char **)args); |
| 9130 | 199 | |
| 15884 | 200 | return PURPLE_CMD_RET_OK; |
| 9130 | 201 | } |
| 202 | ||
| 203 | static void irc_register_command(struct _irc_user_cmd *c) | |
| 204 | { | |
| 15884 | 205 | PurpleCmdFlag f; |
| 9130 | 206 | char args[10]; |
| 207 | char *format; | |
|
12316
b4e5d5ea15fd
[gaim-migrate @ 14620]
Richard Laager <rlaager@pidgin.im>
parents:
12282
diff
changeset
|
208 | size_t i; |
| 9130 | 209 | |
| 15884 | 210 | f = PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY |
| 211 | | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS; | |
| 9130 | 212 | |
| 213 | format = c->format; | |
| 214 | ||
| 215 | for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++) | |
| 216 | switch (*format) { | |
| 217 | case 'v': | |
| 218 | case 'n': | |
| 219 | case 'c': | |
| 220 | case 't': | |
| 221 | args[i] = 'w'; | |
| 222 | break; | |
| 223 | case ':': | |
| 224 | case '*': | |
| 225 | args[i] = 's'; | |
| 226 | break; | |
| 227 | } | |
| 228 | ||
| 229 | args[i] = '\0'; | |
| 230 | ||
| 15884 | 231 | purple_cmd_register(c->name, args, PURPLE_CMD_P_PRPL, f, "prpl-irc", |
| 232 | irc_parse_purple_cmd, _(c->help), NULL); | |
| 9130 | 233 | } |
| 234 | ||
| 235 | void irc_register_commands(void) | |
| 236 | { | |
| 237 | struct _irc_user_cmd *c; | |
| 238 | ||
| 239 | for (c = _irc_cmds; c && c->name; c++) | |
| 240 | irc_register_command(c); | |
| 241 | } | |
| 242 | ||
| 6333 | 243 | static char *irc_send_convert(struct irc_conn *irc, const char *string) |
| 244 | { | |
| 245 | char *utf8; | |
| 246 | GError *err = NULL; | |
| 10258 | 247 | gchar **encodings; |
| 248 | const gchar *enclist; | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
249 | |
| 15884 | 250 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 251 | encodings = g_strsplit(enclist, ",", 2); |
| 252 | ||
|
17138
d666ace4a8ac
strcasecmp is post-C89, so use the glib equivalent
Ethan Blanton <elb@pidgin.im>
parents:
16993
diff
changeset
|
253 | if (encodings[0] == NULL || !g_ascii_strcasecmp("UTF-8", encodings[0])) { |
| 10278 | 254 | g_strfreev(encodings); |
|
23392
9268a4fc4786
Remove an unnecessary strdup when sending messages over IRC.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22798
diff
changeset
|
255 | return NULL; |
| 10278 | 256 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
257 | |
| 10258 | 258 | utf8 = g_convert(string, strlen(string), encodings[0], "UTF-8", NULL, NULL, &err); |
| 6333 | 259 | if (err) { |
| 15884 | 260 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message); |
| 261 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", encodings[0]); | |
| 6333 | 262 | utf8 = g_strdup(string); |
| 8954 | 263 | g_error_free(err); |
| 6333 | 264 | } |
| 10258 | 265 | g_strfreev(encodings); |
| 266 | ||
| 6333 | 267 | return utf8; |
| 268 | } | |
| 269 | ||
| 270 | static char *irc_recv_convert(struct irc_conn *irc, const char *string) | |
| 271 | { | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
272 | char *utf8 = NULL; |
| 10258 | 273 | const gchar *charset, *enclist; |
| 274 | 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
|
275 | gboolean autodetect; |
| 10258 | 276 | int i; |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
277 | |
|
32057
e0abdcaf6fd9
Fix a leak in IRC when accepting a UTF-8 message with a non-UTF-8 encoding.
Ethan Blanton <elb@pidgin.im>
parents:
32047
diff
changeset
|
278 | autodetect = purple_account_get_bool(irc->account, "autodetect_utf8", IRC_DEFAULT_AUTODETECT); |
|
e0abdcaf6fd9
Fix a leak in IRC when accepting a UTF-8 message with a non-UTF-8 encoding.
Ethan Blanton <elb@pidgin.im>
parents:
32047
diff
changeset
|
279 | |
|
e0abdcaf6fd9
Fix a leak in IRC when accepting a UTF-8 message with a non-UTF-8 encoding.
Ethan Blanton <elb@pidgin.im>
parents:
32047
diff
changeset
|
280 | if (autodetect && g_utf8_validate(string, -1, NULL)) { |
|
e0abdcaf6fd9
Fix a leak in IRC when accepting a UTF-8 message with a non-UTF-8 encoding.
Ethan Blanton <elb@pidgin.im>
parents:
32047
diff
changeset
|
281 | return g_strdup(string); |
|
e0abdcaf6fd9
Fix a leak in IRC when accepting a UTF-8 message with a non-UTF-8 encoding.
Ethan Blanton <elb@pidgin.im>
parents:
32047
diff
changeset
|
282 | } |
|
e0abdcaf6fd9
Fix a leak in IRC when accepting a UTF-8 message with a non-UTF-8 encoding.
Ethan Blanton <elb@pidgin.im>
parents:
32047
diff
changeset
|
283 | |
| 15884 | 284 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 285 | encodings = g_strsplit(enclist, ",", -1); |
| 286 | ||
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
287 | if (encodings[0] == NULL) { |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
288 | g_strfreev(encodings); |
| 15884 | 289 | return purple_utf8_salvage(string); |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
290 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
291 | |
| 10258 | 292 | for (i = 0; encodings[i] != NULL; i++) { |
| 293 | charset = encodings[i]; | |
| 294 | while (*charset == ' ') | |
| 295 | charset++; | |
| 296 | ||
|
17156
6d4cc0f310d1
More strcasecmp() replacements.
Richard Laager <rlaager@pidgin.im>
parents:
17138
diff
changeset
|
297 | if (!g_ascii_strcasecmp("UTF-8", charset)) { |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
298 | if (g_utf8_validate(string, -1, NULL)) |
| 10258 | 299 | utf8 = g_strdup(string); |
| 300 | } else { | |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
301 | utf8 = g_convert(string, -1, "UTF-8", charset, NULL, NULL, NULL); |
| 10258 | 302 | } |
| 303 | ||
| 304 | if (utf8) { | |
| 305 | g_strfreev(encodings); | |
| 306 | return utf8; | |
| 307 | } | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
308 | } |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
309 | g_strfreev(encodings); |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
310 | |
| 15884 | 311 | return purple_utf8_salvage(string); |
| 6333 | 312 | } |
| 313 | ||
|
20217
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
314 | /* 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
|
315 | * 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
|
316 | * behavior changed in glib 2.12. */ |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
317 | 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
|
318 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
319 | const char *p = text; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
320 | const char *end = text + length; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
321 | const char *next = NULL; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
322 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
323 | while(p != end) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
324 | next = g_utf8_next_char(p); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
325 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
326 | switch(*p) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
327 | case '&': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
328 | g_string_append(str, "&"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
329 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
330 | case '<': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
331 | g_string_append(str, "<"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
332 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
333 | case '>': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
334 | g_string_append(str, ">"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
335 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
336 | case '\'': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
337 | g_string_append(str, "'"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
338 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
339 | case '"': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
340 | g_string_append(str, """); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
341 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
342 | default: |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
343 | g_string_append_len(str, p, next - p); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
344 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
345 | } |
|
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 | p = next; |
|
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 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
350 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
351 | /* 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
|
352 | * 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
|
353 | char *irc_escape_privmsg(const char *text, gssize length) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
354 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
355 | GString *str; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
356 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
357 | g_return_val_if_fail(text != NULL, NULL); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
358 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
359 | if(length < 0) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
360 | length = strlen(text); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
361 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
362 | str = g_string_sized_new(length); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
363 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
364 | irc_append_escaped_text(str, text, length); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
365 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
366 | return g_string_free(str, FALSE); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
367 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
368 | |
| 6333 | 369 | /* XXX tag closings are not necessarily correctly nested here! If we |
| 370 | * get a ^O or reach the end of the string and there are open | |
| 371 | * tags, they are closed in a fixed order ... this means, for | |
| 372 | * example, you might see <FONT COLOR="blue">some text <B>with | |
| 373 | * various attributes</FONT></B> (notice that B and FONT overlap | |
| 374 | * and are not cleanly nested). This is imminently fixable but | |
| 375 | * I am not fixing it right now. | |
| 376 | */ | |
| 377 | char *irc_mirc2html(const char *string) | |
| 378 | { | |
| 379 | const char *cur, *end; | |
| 380 | char fg[3] = "\0\0", bg[3] = "\0\0"; | |
| 381 | int fgnum, bgnum; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
382 | int font = 0, bold = 0, underline = 0, italic = 0; |
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
383 | GString *decoded; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
384 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
385 | if (string == NULL) |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
386 | return NULL; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
387 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
388 | decoded = g_string_sized_new(strlen(string)); |
| 6333 | 389 | |
| 390 | cur = string; | |
| 391 | do { | |
| 6754 | 392 | end = strpbrk(cur, "\002\003\007\017\026\037"); |
| 6333 | 393 | |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35282
diff
changeset
|
394 | decoded = g_string_append_len(decoded, cur, (end ? (gssize)(end - cur) : (gssize)strlen(cur))); |
| 6333 | 395 | cur = end ? end : cur + strlen(cur); |
| 396 | ||
| 397 | switch (*cur) { | |
| 398 | case '\002': | |
| 399 | cur++; | |
| 400 | if (!bold) { | |
| 401 | decoded = g_string_append(decoded, "<B>"); | |
| 402 | bold = TRUE; | |
| 403 | } else { | |
| 404 | decoded = g_string_append(decoded, "</B>"); | |
| 405 | bold = FALSE; | |
| 406 | } | |
| 407 | break; | |
| 408 | case '\003': | |
| 409 | cur++; | |
| 410 | fg[0] = fg[1] = bg[0] = bg[1] = '\0'; | |
| 411 | if (isdigit(*cur)) | |
| 412 | fg[0] = *cur++; | |
| 413 | if (isdigit(*cur)) | |
| 414 | fg[1] = *cur++; | |
| 415 | if (*cur == ',') { | |
| 416 | cur++; | |
| 417 | if (isdigit(*cur)) | |
| 418 | bg[0] = *cur++; | |
| 419 | if (isdigit(*cur)) | |
| 420 | bg[1] = *cur++; | |
| 421 | } | |
| 422 | if (font) { | |
| 423 | decoded = g_string_append(decoded, "</FONT>"); | |
| 424 | font = FALSE; | |
| 425 | } | |
| 426 | ||
| 427 | if (fg[0]) { | |
| 428 | fgnum = atoi(fg); | |
| 429 | if (fgnum < 0 || fgnum > 15) | |
| 430 | continue; | |
| 431 | font = TRUE; | |
| 432 | g_string_append_printf(decoded, "<FONT COLOR=\"%s\"", irc_mirc_colors[fgnum]); | |
| 433 | if (bg[0]) { | |
| 434 | bgnum = atoi(bg); | |
| 435 | if (bgnum >= 0 && bgnum < 16) | |
| 436 | g_string_append_printf(decoded, " BACK=\"%s\"", irc_mirc_colors[bgnum]); | |
| 437 | } | |
| 438 | decoded = g_string_append_c(decoded, '>'); | |
| 439 | } | |
| 440 | break; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
441 | case '\011': |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
442 | cur++; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
443 | if (!italic) { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
444 | decoded = g_string_append(decoded, "<I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
445 | italic = TRUE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
446 | } else { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
447 | decoded = g_string_append(decoded, "</I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
448 | italic = FALSE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
449 | } |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
450 | break; |
| 6754 | 451 | case '\037': |
| 452 | cur++; | |
| 453 | if (!underline) { | |
| 454 | decoded = g_string_append(decoded, "<U>"); | |
| 455 | underline = TRUE; | |
| 456 | } else { | |
| 457 | decoded = g_string_append(decoded, "</U>"); | |
| 12282 | 458 | underline = FALSE; |
| 6754 | 459 | } |
| 460 | break; | |
| 6333 | 461 | case '\007': |
| 462 | case '\026': | |
| 463 | cur++; | |
| 464 | break; | |
| 465 | case '\017': | |
| 466 | cur++; | |
| 467 | /* fallthrough */ | |
| 468 | case '\000': | |
| 469 | if (bold) | |
| 6754 | 470 | decoded = g_string_append(decoded, "</B>"); |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
471 | if (italic) |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
472 | decoded = g_string_append(decoded, "</I>"); |
| 6754 | 473 | if (underline) |
| 474 | decoded = g_string_append(decoded, "</U>"); | |
| 6333 | 475 | if (font) |
| 476 | decoded = g_string_append(decoded, "</FONT>"); | |
|
31974
28ac37064cd4
Fix the handling of IRC formatting following mIRC ^O.
Ethan Blanton <elb@pidgin.im>
parents:
31651
diff
changeset
|
477 | bold = italic = underline = font = FALSE; |
| 6333 | 478 | break; |
| 479 | default: | |
| 15884 | 480 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unexpected mIRC formatting character %d\n", *cur); |
| 6333 | 481 | } |
| 482 | } while (*cur); | |
| 483 | ||
| 484 | return g_string_free(decoded, FALSE); | |
| 485 | } | |
| 486 | ||
| 8529 | 487 | char *irc_mirc2txt (const char *string) |
| 488 | { | |
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
489 | char *result; |
| 8529 | 490 | int i, j; |
| 491 | ||
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
492 | if (string == NULL) |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
493 | return NULL; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
494 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
495 | result = g_strdup (string); |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
496 | |
| 8529 | 497 | for (i = 0, j = 0; result[i]; i++) { |
| 498 | switch (result[i]) { | |
| 499 | case '\002': | |
| 500 | case '\003': | |
|
17409
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
501 | /* Foreground color */ |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
502 | 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
|
503 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
504 | 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
|
505 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
506 | /* 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
|
507 | 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
|
508 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
509 | 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
|
510 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
511 | 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
|
512 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
513 | } |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
514 | /* 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
|
515 | * 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
|
516 | continue; |
| 8529 | 517 | case '\007': |
| 518 | case '\017': | |
| 519 | case '\026': | |
| 520 | case '\037': | |
| 521 | continue; | |
| 522 | default: | |
| 523 | result[j++] = result[i]; | |
| 524 | } | |
| 525 | } | |
| 11136 | 526 | 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
|
527 | return result; |
| 8529 | 528 | } |
| 529 | ||
|
24574
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
530 | 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
|
531 | { |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
532 | 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
|
533 | const char *mode_chars; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
534 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
535 | 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
|
536 | |
|
38918
bb3906c14782
irc: fix read out of bounds in irc_nick_skip_mode
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
537 | while (*nick && strchr(mode_chars, *nick) != NULL) |
|
24574
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
538 | nick++; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
539 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
540 | return nick; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
541 | } |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
542 | |
| 10208 | 543 | gboolean irc_ischannel(const char *string) |
| 544 | { | |
| 545 | return (string[0] == '#' || string[0] == '&'); | |
| 546 | } | |
| 547 | ||
| 6333 | 548 | char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice) |
| 549 | { | |
| 15884 | 550 | PurpleConnection *gc; |
| 6333 | 551 | const char *cur = msg + 1; |
| 552 | char *buf, *ctcp; | |
| 553 | time_t timestamp; | |
| 554 | ||
| 6754 | 555 | /* Note that this is NOT correct w.r.t. multiple CTCPs in one |
| 556 | * message and low-level quoting ... but if you want that crap, | |
| 557 | * use a real IRC client. */ | |
| 558 | ||
|
38920
306b7ae2c8a4
irc: Fix write of a single \0 before the start of a buffer in irc_parse_ctcp
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
559 | if (msg[0] != '\001' || msg[1] == '\0' || msg[strlen(msg) - 1] != '\001') |
| 6333 | 560 | return g_strdup(msg); |
| 561 | ||
| 562 | if (!strncmp(cur, "ACTION ", 7)) { | |
| 563 | cur += 7; | |
| 564 | buf = g_strdup_printf("/me %s", cur); | |
| 565 | buf[strlen(buf) - 1] = '\0'; | |
| 566 | return buf; | |
| 567 | } else if (!strncmp(cur, "PING ", 5)) { | |
| 568 | if (notice) { /* reply */ | |
| 15884 | 569 | gc = purple_account_get_connection(irc->account); |
| 6333 | 570 | if (!gc) |
| 571 | return NULL; | |
|
33809
d5e9c888ccd7
Add some error checking for sscanf usage (there are more places that could use this)
Daniel Atallah <datallah@pidgin.im>
parents:
33544
diff
changeset
|
572 | /* TODO: Should this read in the timestamp as a double? */ |
|
d5e9c888ccd7
Add some error checking for sscanf usage (there are more places that could use this)
Daniel Atallah <datallah@pidgin.im>
parents:
33544
diff
changeset
|
573 | if (sscanf(cur, "PING %lu", ×tamp) == 1) { |
|
d5e9c888ccd7
Add some error checking for sscanf usage (there are more places that could use this)
Daniel Atallah <datallah@pidgin.im>
parents:
33544
diff
changeset
|
574 | buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp); |
|
d5e9c888ccd7
Add some error checking for sscanf usage (there are more places that could use this)
Daniel Atallah <datallah@pidgin.im>
parents:
33544
diff
changeset
|
575 | purple_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf); |
|
d5e9c888ccd7
Add some error checking for sscanf usage (there are more places that could use this)
Daniel Atallah <datallah@pidgin.im>
parents:
33544
diff
changeset
|
576 | g_free(buf); |
|
d5e9c888ccd7
Add some error checking for sscanf usage (there are more places that could use this)
Daniel Atallah <datallah@pidgin.im>
parents:
33544
diff
changeset
|
577 | } else |
|
d5e9c888ccd7
Add some error checking for sscanf usage (there are more places that could use this)
Daniel Atallah <datallah@pidgin.im>
parents:
33544
diff
changeset
|
578 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unable to parse PING timestamp"); |
| 6333 | 579 | return NULL; |
| 580 | } else { | |
| 581 | buf = irc_format(irc, "vt:", "NOTICE", from, msg); | |
| 582 | irc_send(irc, buf); | |
| 583 | g_free(buf); | |
| 584 | } | |
| 585 | } else if (!strncmp(cur, "VERSION", 7) && !notice) { | |
| 15884 | 586 | buf = irc_format(irc, "vt:", "NOTICE", from, "\001VERSION Purple IRC\001"); |
| 6333 | 587 | irc_send(irc, buf); |
| 588 | g_free(buf); | |
| 8351 | 589 | } else if (!strncmp(cur, "DCC SEND ", 9)) { |
| 590 | irc_dccsend_recv(irc, from, msg + 10); | |
| 591 | return NULL; | |
| 6333 | 592 | } |
| 593 | ||
| 594 | ctcp = g_strdup(msg + 1); | |
| 595 | ctcp[strlen(ctcp) - 1] = '\0'; | |
| 596 | buf = g_strdup_printf("Received CTCP '%s' (to %s) from %s", ctcp, to, from); | |
| 597 | g_free(ctcp); | |
| 598 | return buf; | |
| 599 | } | |
| 600 | ||
| 601 | void irc_msg_table_build(struct irc_conn *irc) | |
| 602 | { | |
| 603 | int i; | |
| 604 | ||
| 605 | if (!irc || !irc->msgs) { | |
| 15884 | 606 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a message table on a bogus structure\n"); |
| 6333 | 607 | return; |
| 608 | } | |
| 609 | ||
| 610 | for (i = 0; _irc_msgs[i].name; i++) { | |
| 611 | g_hash_table_insert(irc->msgs, (gpointer)_irc_msgs[i].name, (gpointer)&_irc_msgs[i]); | |
| 612 | } | |
| 613 | } | |
| 614 | ||
| 615 | void irc_cmd_table_build(struct irc_conn *irc) | |
| 616 | { | |
| 617 | int i; | |
| 618 | ||
| 619 | if (!irc || !irc->cmds) { | |
| 15884 | 620 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a command table on a bogus structure\n"); |
| 6333 | 621 | return; |
| 622 | } | |
| 623 | ||
| 624 | for (i = 0; _irc_cmds[i].name ; i++) { | |
| 625 | g_hash_table_insert(irc->cmds, (gpointer)_irc_cmds[i].name, (gpointer)&_irc_cmds[i]); | |
| 626 | } | |
| 627 | } | |
| 628 | ||
| 629 | char *irc_format(struct irc_conn *irc, const char *format, ...) | |
| 630 | { | |
| 631 | GString *string = g_string_new(""); | |
| 632 | char *tok, *tmp; | |
| 633 | const char *cur; | |
| 634 | va_list ap; | |
| 635 | ||
| 636 | va_start(ap, format); | |
| 637 | for (cur = format; *cur; cur++) { | |
| 638 | if (cur != format) | |
| 639 | g_string_append_c(string, ' '); | |
| 640 | ||
| 641 | tok = va_arg(ap, char *); | |
| 642 | switch (*cur) { | |
| 643 | case 'v': | |
| 644 | g_string_append(string, tok); | |
| 645 | break; | |
| 646 | case ':': | |
| 647 | g_string_append_c(string, ':'); | |
|
41339
3230f4408394
Make all irc login time commands skip the rate limiter.
Gary Kramlich <grim@reaperworld.com>
parents:
38924
diff
changeset
|
648 | /* fallthrough */ |
| 6333 | 649 | case 't': |
| 650 | case 'n': | |
| 651 | case 'c': | |
| 652 | 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
|
653 | g_string_append(string, tmp ? tmp : tok); |
| 6333 | 654 | g_free(tmp); |
| 655 | break; | |
| 656 | default: | |
| 15884 | 657 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Invalid format character '%c'\n", *cur); |
| 6333 | 658 | break; |
| 659 | } | |
| 660 | } | |
| 661 | va_end(ap); | |
| 662 | g_string_append(string, "\r\n"); | |
| 663 | return (g_string_free(string, FALSE)); | |
| 664 | } | |
| 665 | ||
| 666 | void irc_parse_msg(struct irc_conn *irc, char *input) | |
| 667 | { | |
| 668 | struct _irc_msg *msgent; | |
| 669 | char *cur, *end, *tmp, *from, *msgname, *fmt, **args, *msg; | |
| 7631 | 670 | guint i; |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
671 | PurpleConnection *gc = purple_account_get_connection(irc->account); |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
672 | gboolean fmt_valid; |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
673 | int args_cnt; |
| 6333 | 674 | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
675 | irc->recv_time = time(NULL); |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
676 | |
|
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
677 | /* |
|
14996
291304176e0b
[gaim-migrate @ 17706]
Mark Doliner <markdoliner@pidgin.im>
parents:
14995
diff
changeset
|
678 | * 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
|
679 | * 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
|
680 | * instead of a null terminated string. |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
681 | */ |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
682 | purple_signal_emit(_irc_plugin, "irc-receiving-text", gc, &input); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31229
diff
changeset
|
683 | |
|
38907
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
684 | if (purple_debug_is_verbose()) { |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
685 | char *clean = purple_utf8_salvage(input); |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
686 | clean = g_strstrip(clean); |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
687 | purple_debug_misc("irc", ">> %s\n", clean); |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
688 | g_free(clean); |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
689 | } |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
690 | |
| 6333 | 691 | if (!strncmp(input, "PING ", 5)) { |
| 692 | msg = irc_format(irc, "vv", "PONG", input + 5); | |
| 693 | irc_send(irc, msg); | |
| 694 | g_free(msg); | |
| 695 | return; | |
| 696 | } else if (!strncmp(input, "ERROR ", 6)) { | |
| 10154 | 697 | if (g_utf8_validate(input, -1, NULL)) { |
| 698 | char *tmp = g_strdup_printf("%s\n%s", _("Disconnected."), input); | |
| 21279 | 699 | purple_connection_error_reason (gc, |
| 700 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | |
| 10154 | 701 | g_free(tmp); |
| 702 | } else | |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
703 | purple_connection_error_reason (gc, |
| 21279 | 704 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 705 | _("Disconnected.")); | |
| 6333 | 706 | return; |
|
33404
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
707 | #ifdef HAVE_CYRUS_SASL |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
708 | } else if (!strncmp(input, "AUTHENTICATE ", 13)) { |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
709 | irc_msg_auth(irc, input + 13); |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
710 | return; |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
711 | #endif |
| 6333 | 712 | } |
| 713 | ||
| 714 | if (input[0] != ':' || (cur = strchr(input, ' ')) == NULL) { | |
| 715 | irc_parse_error_cb(irc, input); | |
| 716 | return; | |
| 717 | } | |
| 718 | ||
| 719 | from = g_strndup(&input[1], cur - &input[1]); | |
| 720 | cur++; | |
| 721 | end = strchr(cur, ' '); | |
| 722 | if (!end) | |
| 723 | end = cur + strlen(cur); | |
| 724 | ||
| 725 | tmp = g_strndup(cur, end - cur); | |
| 726 | msgname = g_ascii_strdown(tmp, -1); | |
| 727 | g_free(tmp); | |
| 728 | ||
| 729 | if ((msgent = g_hash_table_lookup(irc->msgs, msgname)) == NULL) { | |
| 730 | irc_msg_default(irc, "", from, &input); | |
| 731 | g_free(msgname); | |
| 732 | g_free(from); | |
| 733 | return; | |
| 734 | } | |
| 735 | g_free(msgname); | |
| 736 | ||
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
737 | fmt_valid = TRUE; |
| 6333 | 738 | args = g_new0(char *, strlen(msgent->format)); |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
739 | args_cnt = 0; |
| 6333 | 740 | for (cur = end, fmt = msgent->format, i = 0; fmt[i] && *cur++; i++) { |
| 741 | switch (fmt[i]) { | |
| 742 | case 'v': | |
| 743 | if (!(end = strchr(cur, ' '))) end = cur + strlen(cur); | |
|
32047
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
744 | /* This is a string of unknown encoding which we do not |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
745 | * want to transcode, but it may or may not be valid |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
746 | * UTF-8, so we'll salvage it. If a nick/channel/target |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
747 | * field has inadvertently been marked verbatim, this |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
748 | * could cause weirdness. */ |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
749 | tmp = g_strndup(cur, end - cur); |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
750 | args[i] = purple_utf8_salvage(tmp); |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
751 | g_free(tmp); |
| 6333 | 752 | cur += end - cur; |
| 753 | break; | |
| 754 | case 't': | |
| 755 | case 'n': | |
| 756 | case 'c': | |
| 757 | if (!(end = strchr(cur, ' '))) end = cur + strlen(cur); | |
| 758 | tmp = g_strndup(cur, end - cur); | |
| 759 | args[i] = irc_recv_convert(irc, tmp); | |
| 760 | g_free(tmp); | |
| 761 | cur += end - cur; | |
| 762 | break; | |
| 763 | case ':': | |
| 764 | if (*cur == ':') cur++; | |
| 765 | args[i] = irc_recv_convert(irc, cur); | |
| 766 | cur = cur + strlen(cur); | |
| 767 | break; | |
| 768 | case '*': | |
|
32047
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
769 | /* Ditto 'v' above; we're going to salvage this in case |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
770 | * it leaks past the IRC prpl */ |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
771 | args[i] = purple_utf8_salvage(cur); |
| 6333 | 772 | cur = cur + strlen(cur); |
| 773 | break; | |
| 774 | default: | |
| 15884 | 775 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "invalid message format character '%c'\n", fmt[i]); |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
776 | fmt_valid = FALSE; |
| 6333 | 777 | break; |
| 778 | } | |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
779 | if (fmt_valid) |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
780 | args_cnt = i + 1; |
| 6333 | 781 | } |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
782 | if (G_UNLIKELY(!fmt_valid)) { |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
783 | purple_debug_error("irc", "message format was invalid"); |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
784 | } else if (G_LIKELY(args_cnt >= msgent->req_cnt)) { |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
785 | tmp = irc_recv_convert(irc, from); |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
786 | (msgent->cb)(irc, msgent->name, tmp, args); |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
787 | g_free(tmp); |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
788 | } else { |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
789 | purple_debug_error("irc", "args count (%d) doesn't reach " |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
790 | "expected value of %d for the '%s' command", |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
791 | args_cnt, msgent->req_cnt, msgent->name); |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
792 | } |
| 6333 | 793 | for (i = 0; i < strlen(msgent->format); i++) { |
| 794 | g_free(args[i]); | |
| 795 | } | |
| 796 | g_free(args); | |
| 797 | g_free(from); | |
| 798 | } | |
| 799 | ||
| 800 | static void irc_parse_error_cb(struct irc_conn *irc, char *input) | |
| 801 | { | |
|
23433
0094a64519cb
Make the IRC "unknown message" debugging messages UTF-8 safe.
Ethan Blanton <elb@pidgin.im>
parents:
23392
diff
changeset
|
802 | 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
|
803 | /* 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
|
804 | * 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
|
805 | 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
|
806 | 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
|
807 | g_free(clean); |
| 6333 | 808 | } |