Mon, 05 Mar 2018 02:41:47 -0300
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
| 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 */ |
|
33404
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
118 | #endif |
|
35248
9f132a6855cd
IRC: fill required command parameter counts (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35245
diff
changeset
|
119 | { "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
|
120 | { "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
|
121 | { "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
|
122 | { "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
|
123 | { "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
|
124 | { "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
|
125 | { "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
|
126 | { "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
|
127 | { "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
|
128 | { "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
|
129 | { "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
|
130 | { "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
|
131 | { "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
|
132 | { NULL, NULL, 0, NULL } |
| 6333 | 133 | }; |
| 134 | ||
| 135 | static struct _irc_user_cmd { | |
| 136 | char *name; | |
| 137 | char *format; | |
| 138 | IRCCmdCallback cb; | |
| 9255 | 139 | char *help; |
| 6333 | 140 | } _irc_cmds[] = { |
| 9255 | 141 | { "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
|
142 | { "authserv", ":", irc_cmd_service, N_("authserv: Send a command to authserv") }, |
| 9255 | 143 | { "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
|
144 | { "ctcp", "t:", irc_cmd_ctcp, N_("ctcp <nick> <msg>: sends ctcp msg to nick.") }, |
| 12013 | 145 | { "chanserv", ":", irc_cmd_service, N_("chanserv: Send a command to chanserv") }, |
| 9258 | 146 | { "deop", ":", irc_cmd_op, N_("deop <nick1> [nick2] ...: Remove channel operator status from someone. You must be a channel operator to do this.") }, |
| 147 | { "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.") }, | |
| 148 | { "invite", ":", irc_cmd_invite, N_("invite <nick> [room]: Invite someone to join you in the specified channel, or the current channel.") }, | |
| 9266 | 149 | { "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.") }, |
| 150 | { "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 | 151 | { "kick", "n:", irc_cmd_kick, N_("kick <nick> [message]: Remove someone from a channel. You must be a channel operator to do this.") }, |
| 152 | { "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 | 153 | { "me", ":", irc_cmd_ctcp_action, N_("me <action to perform>: Perform an action.") }, |
| 12013 | 154 | { "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
|
155 | { "mode", ":", irc_cmd_mode, N_("mode <+|-><A-Za-z> <nick|channel>: Set or unset a channel or user mode.") }, |
| 9258 | 156 | { "msg", "t:", irc_cmd_privmsg, N_("msg <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 157 | { "names", "c", irc_cmd_names, N_("names [channel]: List the users currently in a channel.") }, | |
| 9274 | 158 | { "nick", "n", irc_cmd_nick, N_("nick <new nickname>: Change your nickname.") }, |
| 12013 | 159 | { "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
|
160 | { "notice", "t:", irc_cmd_privmsg, N_("notice <target<: Send a notice to a user or channel.") }, |
| 9258 | 161 | { "op", ":", irc_cmd_op, N_("op <nick1> [nick2] ...: Grant channel operator status to someone. You must be a channel operator to do this.") }, |
| 9255 | 162 | { "operwall", ":", irc_cmd_wallops, N_("operwall <message>: If you don't know what this is, you probably can't use it.") }, |
| 12013 | 163 | { "operserv", ":", irc_cmd_service, N_("operserv: Send a command to operserv") }, |
| 9258 | 164 | { "part", "c:", irc_cmd_part, N_("part [room] [message]: Leave the current channel, or a specified channel, with an optional message.") }, |
| 9255 | 165 | { "ping", "n", irc_cmd_ping, N_("ping [nick]: Asks how much lag a user (or the server if no user specified) has.") }, |
| 9258 | 166 | { "query", "n:", irc_cmd_query, N_("query <nick> <message>: Send a private message to a user (as opposed to a channel).") }, |
| 9255 | 167 | { "quit", ":", irc_cmd_quit, N_("quit [message]: Disconnect from the server, with an optional message.") }, |
| 168 | { "quote", "*", irc_cmd_quote, N_("quote [...]: Send a raw command to the server.") }, | |
| 169 | { "remove", "n:", irc_cmd_remove, N_("remove <nick> [message]: Remove someone from a room. You must be a channel operator to do this.") }, | |
| 10564 | 170 | { "time", "", irc_cmd_time, N_("time: Displays the current local time at the IRC server.") }, |
| 9255 | 171 | { "topic", ":", irc_cmd_topic, N_("topic [new topic]: View or change the channel topic.") }, |
| 172 | { "umode", ":", irc_cmd_mode, N_("umode <+|-><A-Za-z>: Set or unset a user mode.") }, | |
| 13943 | 173 | { "version", ":", irc_cmd_ctcp_version, N_("version [nick]: send CTCP VERSION request to a user") }, |
| 9258 | 174 | { "voice", ":", irc_cmd_op, N_("voice <nick1> [nick2] ...: Grant channel voice status to someone. You must be a channel operator to do this.") }, |
| 9255 | 175 | { "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
|
176 | { "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
|
177 | { "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
|
178 | { NULL, NULL, NULL, NULL } |
| 6333 | 179 | }; |
| 180 | ||
| 15884 | 181 | static PurpleCmdRet irc_parse_purple_cmd(PurpleConversation *conv, const gchar *cmd, |
| 9597 | 182 | gchar **args, gchar **error, void *data) |
| 9130 | 183 | { |
| 15884 | 184 | PurpleConnection *gc; |
| 9130 | 185 | struct irc_conn *irc; |
| 186 | struct _irc_user_cmd *cmdent; | |
| 187 | ||
| 15884 | 188 | gc = purple_conversation_get_gc(conv); |
| 9130 | 189 | if (!gc) |
| 15884 | 190 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 191 | |
| 192 | irc = gc->proto_data; | |
| 193 | ||
| 194 | if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL) | |
| 15884 | 195 | return PURPLE_CMD_RET_FAILED; |
| 9130 | 196 | |
| 15884 | 197 | (cmdent->cb)(irc, cmd, purple_conversation_get_name(conv), (const char **)args); |
| 9130 | 198 | |
| 15884 | 199 | return PURPLE_CMD_RET_OK; |
| 9130 | 200 | } |
| 201 | ||
| 202 | static void irc_register_command(struct _irc_user_cmd *c) | |
| 203 | { | |
| 15884 | 204 | PurpleCmdFlag f; |
| 9130 | 205 | char args[10]; |
| 206 | char *format; | |
|
12316
b4e5d5ea15fd
[gaim-migrate @ 14620]
Richard Laager <rlaager@pidgin.im>
parents:
12282
diff
changeset
|
207 | size_t i; |
| 9130 | 208 | |
| 15884 | 209 | f = PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY |
| 210 | | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS; | |
| 9130 | 211 | |
| 212 | format = c->format; | |
| 213 | ||
| 214 | for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++) | |
| 215 | switch (*format) { | |
| 216 | case 'v': | |
| 217 | case 'n': | |
| 218 | case 'c': | |
| 219 | case 't': | |
| 220 | args[i] = 'w'; | |
| 221 | break; | |
| 222 | case ':': | |
| 223 | case '*': | |
| 224 | args[i] = 's'; | |
| 225 | break; | |
| 226 | } | |
| 227 | ||
| 228 | args[i] = '\0'; | |
| 229 | ||
| 15884 | 230 | purple_cmd_register(c->name, args, PURPLE_CMD_P_PRPL, f, "prpl-irc", |
| 231 | irc_parse_purple_cmd, _(c->help), NULL); | |
| 9130 | 232 | } |
| 233 | ||
| 234 | void irc_register_commands(void) | |
| 235 | { | |
| 236 | struct _irc_user_cmd *c; | |
| 237 | ||
| 238 | for (c = _irc_cmds; c && c->name; c++) | |
| 239 | irc_register_command(c); | |
| 240 | } | |
| 241 | ||
| 6333 | 242 | static char *irc_send_convert(struct irc_conn *irc, const char *string) |
| 243 | { | |
| 244 | char *utf8; | |
| 245 | GError *err = NULL; | |
| 10258 | 246 | gchar **encodings; |
| 247 | const gchar *enclist; | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
248 | |
| 15884 | 249 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 250 | encodings = g_strsplit(enclist, ",", 2); |
| 251 | ||
|
17138
d666ace4a8ac
strcasecmp is post-C89, so use the glib equivalent
Ethan Blanton <elb@pidgin.im>
parents:
16993
diff
changeset
|
252 | if (encodings[0] == NULL || !g_ascii_strcasecmp("UTF-8", encodings[0])) { |
| 10278 | 253 | g_strfreev(encodings); |
|
23392
9268a4fc4786
Remove an unnecessary strdup when sending messages over IRC.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22798
diff
changeset
|
254 | return NULL; |
| 10278 | 255 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
256 | |
| 10258 | 257 | utf8 = g_convert(string, strlen(string), encodings[0], "UTF-8", NULL, NULL, &err); |
| 6333 | 258 | if (err) { |
| 15884 | 259 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message); |
| 260 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", encodings[0]); | |
| 6333 | 261 | utf8 = g_strdup(string); |
| 8954 | 262 | g_error_free(err); |
| 6333 | 263 | } |
| 10258 | 264 | g_strfreev(encodings); |
| 265 | ||
| 6333 | 266 | return utf8; |
| 267 | } | |
| 268 | ||
| 269 | static char *irc_recv_convert(struct irc_conn *irc, const char *string) | |
| 270 | { | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
271 | char *utf8 = NULL; |
| 10258 | 272 | const gchar *charset, *enclist; |
| 273 | 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
|
274 | gboolean autodetect; |
| 10258 | 275 | int i; |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
276 | |
|
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
|
277 | 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
|
278 | |
|
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 | 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
|
280 | 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
|
281 | } |
|
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 | |
| 15884 | 283 | enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); |
| 10258 | 284 | encodings = g_strsplit(enclist, ",", -1); |
| 285 | ||
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
286 | if (encodings[0] == NULL) { |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
287 | g_strfreev(encodings); |
| 15884 | 288 | return purple_utf8_salvage(string); |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
289 | } |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
290 | |
| 10258 | 291 | for (i = 0; encodings[i] != NULL; i++) { |
| 292 | charset = encodings[i]; | |
| 293 | while (*charset == ' ') | |
| 294 | charset++; | |
| 295 | ||
|
17156
6d4cc0f310d1
More strcasecmp() replacements.
Richard Laager <rlaager@pidgin.im>
parents:
17138
diff
changeset
|
296 | if (!g_ascii_strcasecmp("UTF-8", charset)) { |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
297 | if (g_utf8_validate(string, -1, NULL)) |
| 10258 | 298 | utf8 = g_strdup(string); |
| 299 | } else { | |
|
11726
6f319ff4cea5
[gaim-migrate @ 14017]
Richard Laager <rlaager@pidgin.im>
parents:
11318
diff
changeset
|
300 | utf8 = g_convert(string, -1, "UTF-8", charset, NULL, NULL, NULL); |
| 10258 | 301 | } |
| 302 | ||
| 303 | if (utf8) { | |
| 304 | g_strfreev(encodings); | |
| 305 | return utf8; | |
| 306 | } | |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
307 | } |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10278
diff
changeset
|
308 | g_strfreev(encodings); |
|
9644
a9a0dedb52c7
[gaim-migrate @ 10492]
Mark Doliner <markdoliner@pidgin.im>
parents:
9597
diff
changeset
|
309 | |
| 15884 | 310 | return purple_utf8_salvage(string); |
| 6333 | 311 | } |
| 312 | ||
|
20217
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
313 | /* 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
|
314 | * 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
|
315 | * behavior changed in glib 2.12. */ |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
316 | 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
|
317 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
318 | const char *p = text; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
319 | const char *end = text + length; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
320 | const char *next = NULL; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
321 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
322 | while(p != end) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
323 | next = g_utf8_next_char(p); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
324 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
325 | switch(*p) { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
326 | case '&': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
327 | g_string_append(str, "&"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
328 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
329 | case '<': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
330 | g_string_append(str, "<"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
331 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
332 | case '>': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
333 | g_string_append(str, ">"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
334 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
335 | case '\'': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
336 | g_string_append(str, "'"); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
337 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
338 | case '"': |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
339 | g_string_append(str, """); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
340 | break; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
341 | default: |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
342 | g_string_append_len(str, p, next - p); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
343 | break; |
|
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 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
346 | p = next; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
347 | } |
|
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 | /* 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
|
351 | * 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
|
352 | char *irc_escape_privmsg(const char *text, gssize length) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
353 | { |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
354 | GString *str; |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
355 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
356 | g_return_val_if_fail(text != NULL, NULL); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
357 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
358 | if(length < 0) |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
359 | length = strlen(text); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
360 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
361 | str = g_string_sized_new(length); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
362 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
363 | irc_append_escaped_text(str, text, length); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
364 | |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
365 | return g_string_free(str, FALSE); |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
366 | } |
|
9249f67ef61e
applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
367 | |
| 6333 | 368 | /* XXX tag closings are not necessarily correctly nested here! If we |
| 369 | * get a ^O or reach the end of the string and there are open | |
| 370 | * tags, they are closed in a fixed order ... this means, for | |
| 371 | * example, you might see <FONT COLOR="blue">some text <B>with | |
| 372 | * various attributes</FONT></B> (notice that B and FONT overlap | |
| 373 | * and are not cleanly nested). This is imminently fixable but | |
| 374 | * I am not fixing it right now. | |
| 375 | */ | |
| 376 | char *irc_mirc2html(const char *string) | |
| 377 | { | |
| 378 | const char *cur, *end; | |
| 379 | char fg[3] = "\0\0", bg[3] = "\0\0"; | |
| 380 | int fgnum, bgnum; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
381 | 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
|
382 | GString *decoded; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
383 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
384 | 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
|
385 | return NULL; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
386 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
387 | decoded = g_string_sized_new(strlen(string)); |
| 6333 | 388 | |
| 389 | cur = string; | |
| 390 | do { | |
| 6754 | 391 | end = strpbrk(cur, "\002\003\007\017\026\037"); |
| 6333 | 392 | |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35282
diff
changeset
|
393 | decoded = g_string_append_len(decoded, cur, (end ? (gssize)(end - cur) : (gssize)strlen(cur))); |
| 6333 | 394 | cur = end ? end : cur + strlen(cur); |
| 395 | ||
| 396 | switch (*cur) { | |
| 397 | case '\002': | |
| 398 | cur++; | |
| 399 | if (!bold) { | |
| 400 | decoded = g_string_append(decoded, "<B>"); | |
| 401 | bold = TRUE; | |
| 402 | } else { | |
| 403 | decoded = g_string_append(decoded, "</B>"); | |
| 404 | bold = FALSE; | |
| 405 | } | |
| 406 | break; | |
| 407 | case '\003': | |
| 408 | cur++; | |
| 409 | fg[0] = fg[1] = bg[0] = bg[1] = '\0'; | |
| 410 | if (isdigit(*cur)) | |
| 411 | fg[0] = *cur++; | |
| 412 | if (isdigit(*cur)) | |
| 413 | fg[1] = *cur++; | |
| 414 | if (*cur == ',') { | |
| 415 | cur++; | |
| 416 | if (isdigit(*cur)) | |
| 417 | bg[0] = *cur++; | |
| 418 | if (isdigit(*cur)) | |
| 419 | bg[1] = *cur++; | |
| 420 | } | |
| 421 | if (font) { | |
| 422 | decoded = g_string_append(decoded, "</FONT>"); | |
| 423 | font = FALSE; | |
| 424 | } | |
| 425 | ||
| 426 | if (fg[0]) { | |
| 427 | fgnum = atoi(fg); | |
| 428 | if (fgnum < 0 || fgnum > 15) | |
| 429 | continue; | |
| 430 | font = TRUE; | |
| 431 | g_string_append_printf(decoded, "<FONT COLOR=\"%s\"", irc_mirc_colors[fgnum]); | |
| 432 | if (bg[0]) { | |
| 433 | bgnum = atoi(bg); | |
| 434 | if (bgnum >= 0 && bgnum < 16) | |
| 435 | g_string_append_printf(decoded, " BACK=\"%s\"", irc_mirc_colors[bgnum]); | |
| 436 | } | |
| 437 | decoded = g_string_append_c(decoded, '>'); | |
| 438 | } | |
| 439 | break; | |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
440 | case '\011': |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
441 | cur++; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
442 | if (!italic) { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
443 | decoded = g_string_append(decoded, "<I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
444 | italic = TRUE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
445 | } else { |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
446 | decoded = g_string_append(decoded, "</I>"); |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
447 | italic = FALSE; |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
448 | } |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
449 | break; |
| 6754 | 450 | case '\037': |
| 451 | cur++; | |
| 452 | if (!underline) { | |
| 453 | decoded = g_string_append(decoded, "<U>"); | |
| 454 | underline = TRUE; | |
| 455 | } else { | |
| 456 | decoded = g_string_append(decoded, "</U>"); | |
| 12282 | 457 | underline = FALSE; |
| 6754 | 458 | } |
| 459 | break; | |
| 6333 | 460 | case '\007': |
| 461 | case '\026': | |
| 462 | cur++; | |
| 463 | break; | |
| 464 | case '\017': | |
| 465 | cur++; | |
| 466 | /* fallthrough */ | |
| 467 | case '\000': | |
| 468 | if (bold) | |
| 6754 | 469 | decoded = g_string_append(decoded, "</B>"); |
|
12158
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
470 | if (italic) |
|
02fcec741f07
[gaim-migrate @ 14459]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12013
diff
changeset
|
471 | decoded = g_string_append(decoded, "</I>"); |
| 6754 | 472 | if (underline) |
| 473 | decoded = g_string_append(decoded, "</U>"); | |
| 6333 | 474 | if (font) |
| 475 | 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
|
476 | bold = italic = underline = font = FALSE; |
| 6333 | 477 | break; |
| 478 | default: | |
| 15884 | 479 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unexpected mIRC formatting character %d\n", *cur); |
| 6333 | 480 | } |
| 481 | } while (*cur); | |
| 482 | ||
| 483 | return g_string_free(decoded, FALSE); | |
| 484 | } | |
| 485 | ||
| 8529 | 486 | char *irc_mirc2txt (const char *string) |
| 487 | { | |
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
488 | char *result; |
| 8529 | 489 | int i, j; |
| 490 | ||
|
28468
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
491 | 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
|
492 | return NULL; |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
493 | |
|
aa8975185a48
Head irc_mirc2* bugs off at the pass with a NULL check
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
494 | 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
|
495 | |
| 8529 | 496 | for (i = 0, j = 0; result[i]; i++) { |
| 497 | switch (result[i]) { | |
| 498 | case '\002': | |
| 499 | case '\003': | |
|
17409
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
500 | /* Foreground color */ |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
501 | 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
|
502 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
503 | 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
|
504 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
505 | /* 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
|
506 | 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
|
507 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
508 | 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
|
509 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
510 | 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
|
511 | i++; |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
512 | } |
|
1205b4f7bb82
This performs mIRC formatting code stripping for the room list, as
Ethan Blanton <elb@pidgin.im>
parents:
17156
diff
changeset
|
513 | /* 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
|
514 | * 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
|
515 | continue; |
| 8529 | 516 | case '\007': |
| 517 | case '\017': | |
| 518 | case '\026': | |
| 519 | case '\037': | |
| 520 | continue; | |
| 521 | default: | |
| 522 | result[j++] = result[i]; | |
| 523 | } | |
| 524 | } | |
| 11136 | 525 | 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
|
526 | return result; |
| 8529 | 527 | } |
| 528 | ||
|
24574
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
529 | 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
|
530 | { |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
531 | 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
|
532 | const char *mode_chars; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
533 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
534 | 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
|
535 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
536 | 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
|
537 | nick++; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
538 | |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
539 | return nick; |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
540 | } |
|
4ee71b4f335f
Strip multiple leading mode characters from incoming nicknames.
Marcos García Ochoa <magao@bigfoot.com>
parents:
23906
diff
changeset
|
541 | |
| 10208 | 542 | gboolean irc_ischannel(const char *string) |
| 543 | { | |
| 544 | return (string[0] == '#' || string[0] == '&'); | |
| 545 | } | |
| 546 | ||
| 6333 | 547 | char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice) |
| 548 | { | |
| 15884 | 549 | PurpleConnection *gc; |
| 6333 | 550 | const char *cur = msg + 1; |
| 551 | char *buf, *ctcp; | |
| 552 | time_t timestamp; | |
| 553 | ||
| 6754 | 554 | /* Note that this is NOT correct w.r.t. multiple CTCPs in one |
| 555 | * message and low-level quoting ... but if you want that crap, | |
| 556 | * use a real IRC client. */ | |
| 557 | ||
| 6333 | 558 | if (msg[0] != '\001' || msg[strlen(msg) - 1] != '\001') |
| 559 | return g_strdup(msg); | |
| 560 | ||
| 561 | if (!strncmp(cur, "ACTION ", 7)) { | |
| 562 | cur += 7; | |
| 563 | buf = g_strdup_printf("/me %s", cur); | |
| 564 | buf[strlen(buf) - 1] = '\0'; | |
| 565 | return buf; | |
| 566 | } else if (!strncmp(cur, "PING ", 5)) { | |
| 567 | if (notice) { /* reply */ | |
| 15884 | 568 | gc = purple_account_get_connection(irc->account); |
| 6333 | 569 | if (!gc) |
| 570 | 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
|
571 | /* 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
|
572 | 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
|
573 | 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
|
574 | 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
|
575 | 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
|
576 | } 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
|
577 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unable to parse PING timestamp"); |
| 6333 | 578 | return NULL; |
| 579 | } else { | |
| 580 | buf = irc_format(irc, "vt:", "NOTICE", from, msg); | |
| 581 | irc_send(irc, buf); | |
| 582 | g_free(buf); | |
| 583 | } | |
| 584 | } else if (!strncmp(cur, "VERSION", 7) && !notice) { | |
| 15884 | 585 | buf = irc_format(irc, "vt:", "NOTICE", from, "\001VERSION Purple IRC\001"); |
| 6333 | 586 | irc_send(irc, buf); |
| 587 | g_free(buf); | |
| 8351 | 588 | } else if (!strncmp(cur, "DCC SEND ", 9)) { |
| 589 | irc_dccsend_recv(irc, from, msg + 10); | |
| 590 | return NULL; | |
| 6333 | 591 | } |
| 592 | ||
| 593 | ctcp = g_strdup(msg + 1); | |
| 594 | ctcp[strlen(ctcp) - 1] = '\0'; | |
| 595 | buf = g_strdup_printf("Received CTCP '%s' (to %s) from %s", ctcp, to, from); | |
| 596 | g_free(ctcp); | |
| 597 | return buf; | |
| 598 | } | |
| 599 | ||
| 600 | void irc_msg_table_build(struct irc_conn *irc) | |
| 601 | { | |
| 602 | int i; | |
| 603 | ||
| 604 | if (!irc || !irc->msgs) { | |
| 15884 | 605 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a message table on a bogus structure\n"); |
| 6333 | 606 | return; |
| 607 | } | |
| 608 | ||
| 609 | for (i = 0; _irc_msgs[i].name; i++) { | |
| 610 | g_hash_table_insert(irc->msgs, (gpointer)_irc_msgs[i].name, (gpointer)&_irc_msgs[i]); | |
| 611 | } | |
| 612 | } | |
| 613 | ||
| 614 | void irc_cmd_table_build(struct irc_conn *irc) | |
| 615 | { | |
| 616 | int i; | |
| 617 | ||
| 618 | if (!irc || !irc->cmds) { | |
| 15884 | 619 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Attempt to build a command table on a bogus structure\n"); |
| 6333 | 620 | return; |
| 621 | } | |
| 622 | ||
| 623 | for (i = 0; _irc_cmds[i].name ; i++) { | |
| 624 | g_hash_table_insert(irc->cmds, (gpointer)_irc_cmds[i].name, (gpointer)&_irc_cmds[i]); | |
| 625 | } | |
| 626 | } | |
| 627 | ||
| 628 | char *irc_format(struct irc_conn *irc, const char *format, ...) | |
| 629 | { | |
| 630 | GString *string = g_string_new(""); | |
| 631 | char *tok, *tmp; | |
| 632 | const char *cur; | |
| 633 | va_list ap; | |
| 634 | ||
| 635 | va_start(ap, format); | |
| 636 | for (cur = format; *cur; cur++) { | |
| 637 | if (cur != format) | |
| 638 | g_string_append_c(string, ' '); | |
| 639 | ||
| 640 | tok = va_arg(ap, char *); | |
| 641 | switch (*cur) { | |
| 642 | case 'v': | |
| 643 | g_string_append(string, tok); | |
| 644 | break; | |
| 645 | case ':': | |
| 646 | g_string_append_c(string, ':'); | |
| 647 | /* no break! */ | |
| 648 | case 't': | |
| 649 | case 'n': | |
| 650 | case 'c': | |
| 651 | 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
|
652 | g_string_append(string, tmp ? tmp : tok); |
| 6333 | 653 | g_free(tmp); |
| 654 | break; | |
| 655 | default: | |
| 15884 | 656 | purple_debug(PURPLE_DEBUG_ERROR, "irc", "Invalid format character '%c'\n", *cur); |
| 6333 | 657 | break; |
| 658 | } | |
| 659 | } | |
| 660 | va_end(ap); | |
| 661 | g_string_append(string, "\r\n"); | |
| 662 | return (g_string_free(string, FALSE)); | |
| 663 | } | |
| 664 | ||
| 665 | void irc_parse_msg(struct irc_conn *irc, char *input) | |
| 666 | { | |
| 667 | struct _irc_msg *msgent; | |
| 668 | char *cur, *end, *tmp, *from, *msgname, *fmt, **args, *msg; | |
| 7631 | 669 | guint i; |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
670 | 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
|
671 | gboolean fmt_valid; |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
672 | int args_cnt; |
| 6333 | 673 | |
|
14544
847944da3ca0
[gaim-migrate @ 17201]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
674 | irc->recv_time = time(NULL); |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
675 | |
|
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
676 | /* |
|
14996
291304176e0b
[gaim-migrate @ 17706]
Mark Doliner <markdoliner@pidgin.im>
parents:
14995
diff
changeset
|
677 | * 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
|
678 | * 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
|
679 | * instead of a null terminated string. |
|
14984
aa56a88dc792
[gaim-migrate @ 17694]
Mark Doliner <markdoliner@pidgin.im>
parents:
14683
diff
changeset
|
680 | */ |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
681 | purple_signal_emit(_irc_plugin, "irc-receiving-text", gc, &input); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31229
diff
changeset
|
682 | |
|
38907
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
683 | if (purple_debug_is_verbose()) { |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
684 | 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
|
685 | clean = g_strstrip(clean); |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
686 | 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
|
687 | g_free(clean); |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
688 | } |
|
d184ca7f413e
irc: show protocol debug if PURPLE_VERBOSE_DEBUG=1
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
689 | |
| 6333 | 690 | if (!strncmp(input, "PING ", 5)) { |
| 691 | msg = irc_format(irc, "vv", "PONG", input + 5); | |
| 692 | irc_send(irc, msg); | |
| 693 | g_free(msg); | |
| 694 | return; | |
| 695 | } else if (!strncmp(input, "ERROR ", 6)) { | |
| 10154 | 696 | if (g_utf8_validate(input, -1, NULL)) { |
| 697 | char *tmp = g_strdup_printf("%s\n%s", _("Disconnected."), input); | |
| 21279 | 698 | purple_connection_error_reason (gc, |
| 699 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | |
| 10154 | 700 | g_free(tmp); |
| 701 | } else | |
|
20440
42e5e5445a2f
Move prpl-irc to purple_connection_error_reason.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
702 | purple_connection_error_reason (gc, |
| 21279 | 703 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 704 | _("Disconnected.")); | |
| 6333 | 705 | return; |
|
33404
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
706 | #ifdef HAVE_CYRUS_SASL |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
707 | } else if (!strncmp(input, "AUTHENTICATE ", 13)) { |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
708 | irc_msg_auth(irc, input + 13); |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
709 | return; |
|
bbd52f93184e
Implement SASL support for IRC, using Cyrus.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
32057
diff
changeset
|
710 | #endif |
| 6333 | 711 | } |
| 712 | ||
| 713 | if (input[0] != ':' || (cur = strchr(input, ' ')) == NULL) { | |
| 714 | irc_parse_error_cb(irc, input); | |
| 715 | return; | |
| 716 | } | |
| 717 | ||
| 718 | from = g_strndup(&input[1], cur - &input[1]); | |
| 719 | cur++; | |
| 720 | end = strchr(cur, ' '); | |
| 721 | if (!end) | |
| 722 | end = cur + strlen(cur); | |
| 723 | ||
| 724 | tmp = g_strndup(cur, end - cur); | |
| 725 | msgname = g_ascii_strdown(tmp, -1); | |
| 726 | g_free(tmp); | |
| 727 | ||
| 728 | if ((msgent = g_hash_table_lookup(irc->msgs, msgname)) == NULL) { | |
| 729 | irc_msg_default(irc, "", from, &input); | |
| 730 | g_free(msgname); | |
| 731 | g_free(from); | |
| 732 | return; | |
| 733 | } | |
| 734 | g_free(msgname); | |
| 735 | ||
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
736 | fmt_valid = TRUE; |
| 6333 | 737 | 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
|
738 | args_cnt = 0; |
| 6333 | 739 | for (cur = end, fmt = msgent->format, i = 0; fmt[i] && *cur++; i++) { |
| 740 | switch (fmt[i]) { | |
| 741 | case 'v': | |
| 742 | 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
|
743 | /* 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
|
744 | * 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
|
745 | * 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
|
746 | * field has inadvertently been marked verbatim, this |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
747 | * could cause weirdness. */ |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
748 | tmp = g_strndup(cur, end - cur); |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
749 | args[i] = purple_utf8_salvage(tmp); |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
750 | g_free(tmp); |
| 6333 | 751 | cur += end - cur; |
| 752 | break; | |
| 753 | case 't': | |
| 754 | case 'n': | |
| 755 | case 'c': | |
| 756 | if (!(end = strchr(cur, ' '))) end = cur + strlen(cur); | |
| 757 | tmp = g_strndup(cur, end - cur); | |
| 758 | args[i] = irc_recv_convert(irc, tmp); | |
| 759 | g_free(tmp); | |
| 760 | cur += end - cur; | |
| 761 | break; | |
| 762 | case ':': | |
| 763 | if (*cur == ':') cur++; | |
| 764 | args[i] = irc_recv_convert(irc, cur); | |
| 765 | cur = cur + strlen(cur); | |
| 766 | break; | |
| 767 | case '*': | |
|
32047
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
768 | /* 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
|
769 | * it leaks past the IRC prpl */ |
|
42d2acf32425
UTF-8 salvage unknown strings in IRC
Ethan Blanton <elb@pidgin.im>
parents:
32037
diff
changeset
|
770 | args[i] = purple_utf8_salvage(cur); |
| 6333 | 771 | cur = cur + strlen(cur); |
| 772 | break; | |
| 773 | default: | |
| 15884 | 774 | 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
|
775 | fmt_valid = FALSE; |
| 6333 | 776 | break; |
| 777 | } | |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
778 | if (fmt_valid) |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
779 | args_cnt = i + 1; |
| 6333 | 780 | } |
|
35245
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
781 | 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
|
782 | 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
|
783 | } 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
|
784 | 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
|
785 | (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
|
786 | g_free(tmp); |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
787 | } else { |
|
a167504359e5
IRC: implement support for required args checking in message parser
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33809
diff
changeset
|
788 | 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
|
789 | "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
|
790 | 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
|
791 | } |
| 6333 | 792 | for (i = 0; i < strlen(msgent->format); i++) { |
| 793 | g_free(args[i]); | |
| 794 | } | |
| 795 | g_free(args); | |
| 796 | g_free(from); | |
| 797 | } | |
| 798 | ||
| 799 | static void irc_parse_error_cb(struct irc_conn *irc, char *input) | |
| 800 | { | |
|
23433
0094a64519cb
Make the IRC "unknown message" debugging messages UTF-8 safe.
Ethan Blanton <elb@pidgin.im>
parents:
23392
diff
changeset
|
801 | 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
|
802 | /* 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
|
803 | * 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
|
804 | 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
|
805 | 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
|
806 | g_free(clean); |
| 6333 | 807 | } |