annotate src/protocols/irc/parse.c @ 9255:36938636ca8a

[gaim-migrate @ 10054] this adds some per command help strings to IRC. Someone might want to proof read this for typos or errors. I actually know what IRC commands are supposed to do. But I still may have gotten some arguments wrong, since we don't take the exact same arguments we send the server. Also some of these help strings suck. Patches welcomed. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Thu, 10 Jun 2004 06:00:19 +0000
parents 6430b09ccc71
children 43323228a3da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1 /**
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
2 * @file parse.c
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents: 8114
diff changeset
3 *
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
4 * gaim
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
5 *
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu>
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents: 8114
diff changeset
7 *
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
12 *
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
17 *
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
21 */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
22
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
23 #include "internal.h"
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
24
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
25 #include "accountopt.h"
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
26 #include "conversation.h"
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
27 #include "notify.h"
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
28 #include "debug.h"
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
29 #include "cmds.h"
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
30 #include "irc.h"
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
31
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
32 #include <stdio.h>
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
33 #include <stdlib.h>
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
34 #include <ctype.h>
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
35
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
36 static char *irc_send_convert(struct irc_conn *irc, const char *string);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
37 static char *irc_recv_convert(struct irc_conn *irc, const char *string);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
38
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
39 static void irc_parse_error_cb(struct irc_conn *irc, char *input);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
40
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
41 static char *irc_mirc_colors[16] = {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
42 "white", "black", "blue", "dark green", "red", "brown", "purple",
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
43 "orange", "yellow", "green", "teal", "cyan", "light blue",
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
44 "pink", "grey", "light grey" };
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
45
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
46 /*typedef void (*IRCMsgCallback)(struct irc_conn *irc, char *from, char *name, char **args);*/
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
47 static struct _irc_msg {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
48 char *name;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
49 char *format;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
50 void (*cb)(struct irc_conn *irc, const char *name, const char *from, char **args);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
51 } _irc_msgs[] = {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
52 { "301", "nn:", irc_msg_away }, /* User is away */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
53 { "303", "n:", irc_msg_ison }, /* ISON reply */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
54 { "311", "nnvvv:", irc_msg_whois }, /* Whois user */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
55 { "312", "nnv:", irc_msg_whois }, /* Whois server */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
56 { "313", "nn:", irc_msg_whois }, /* Whois ircop */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
57 { "317", "nnvv", irc_msg_whois }, /* Whois idle */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
58 { "318", "nt:", irc_msg_endwhois }, /* End of WHOIS */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
59 { "319", "nn:", irc_msg_whois }, /* Whois channels */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
60 { "320", "nn:", irc_msg_whois }, /* Whois (fn ident) */
8114
7a6e30eb7aad [gaim-migrate @ 8818]
Ethan Blanton <elb@pidgin.im>
parents: 7981
diff changeset
61 { "321", "*", irc_msg_list }, /* Start of list */
7a6e30eb7aad [gaim-migrate @ 8818]
Ethan Blanton <elb@pidgin.im>
parents: 7981
diff changeset
62 { "322", "ncv:", irc_msg_list }, /* List. */
7a6e30eb7aad [gaim-migrate @ 8818]
Ethan Blanton <elb@pidgin.im>
parents: 7981
diff changeset
63 { "323", ":", irc_msg_list }, /* End of list. */
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
64 { "324", "ncv:", irc_msg_chanmode }, /* Channel modes */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
65 { "331", "nc:", irc_msg_topic }, /* No channel topic */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
66 { "332", "nc:", irc_msg_topic }, /* Channel topic */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
67 { "333", "*", irc_msg_ignore }, /* Topic setter stuff */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
68 { "353", "nvc:", irc_msg_names }, /* Names list */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
69 { "366", "nc:", irc_msg_names }, /* End of names */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
70 { "372", "n:", irc_msg_motd }, /* MOTD */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
71 { "375", "n:", irc_msg_motd }, /* Start MOTD */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
72 { "376", "n:", irc_msg_endmotd }, /* End of MOTD */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
73 { "401", "nt:", irc_msg_nonick }, /* No such nick/chan */
7877
828856b7fe30 [gaim-migrate @ 8531]
Ethan Blanton <elb@pidgin.im>
parents: 7631
diff changeset
74 { "403", "nc:", irc_msg_nochan }, /* No such channel */
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
75 { "404", "nt:", irc_msg_nosend }, /* Cannot send to chan */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
76 { "421", "nv:", irc_msg_unknown }, /* Unknown command */
6350
34c07f5f34a0 [gaim-migrate @ 6849]
Mark Doliner <mark@kingant.net>
parents: 6333
diff changeset
77 { "422", "nv:", irc_msg_endmotd }, /* No MOTD available */
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
78 { "433", "vn:", irc_msg_nickused }, /* Nickname already in use */
6718
37af5dea14d1 [gaim-migrate @ 7245]
Ethan Blanton <elb@pidgin.im>
parents: 6714
diff changeset
79 { "438", "nn:", irc_msg_nochangenick }, /* Nick may not change */
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
80 { "442", "nc:", irc_msg_notinchan }, /* Not in channel */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
81 { "473", "nc:", irc_msg_inviteonly }, /* Tried to join invite-only */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
82 { "474", "nc:", irc_msg_banned }, /* Banned from channel */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
83 { "482", "nc:", irc_msg_notop }, /* Need to be op to do that */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
84 { "501", "n:", irc_msg_badmode }, /* Unknown mode flag */
8404
3f384e95c5c0 [gaim-migrate @ 9134]
Ethan Blanton <elb@pidgin.im>
parents: 8351
diff changeset
85 { "506", "nc:", irc_msg_nosend }, /* Must identify to send */
6714
0c260c4e753e [gaim-migrate @ 7240]
Ethan Blanton <elb@pidgin.im>
parents: 6415
diff changeset
86 { "515", "nc:", irc_msg_regonly }, /* Registration required */
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
87 { "invite", "n:", irc_msg_invite }, /* Invited */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
88 { "join", ":", irc_msg_join }, /* Joined a channel */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
89 { "kick", "cn:", irc_msg_kick }, /* KICK */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
90 { "mode", "tv:", irc_msg_mode }, /* MODE for channel */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
91 { "nick", ":", irc_msg_nick }, /* Nick change */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
92 { "notice", "t:", irc_msg_notice }, /* NOTICE recv */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
93 { "part", "c:", irc_msg_part }, /* Parted a channel */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
94 { "ping", ":", irc_msg_ping }, /* Received PING from server */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
95 { "pong", "v:", irc_msg_pong }, /* Received PONG from server */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
96 { "privmsg", "t:", irc_msg_privmsg }, /* Received private message */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
97 { "topic", "c:", irc_msg_topic }, /* TOPIC command */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
98 { "quit", ":", irc_msg_quit }, /* QUIT notice */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
99 { "wallops", ":", irc_msg_wallops }, /* WALLOPS command */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
100 { NULL, NULL, NULL }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
101 };
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
102
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
103 static struct _irc_user_cmd {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
104 char *name;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
105 char *format;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
106 IRCCmdCallback cb;
9255
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
107 char *help;
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
108 } _irc_cmds[] = {
9255
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
109 { "action", ":", irc_cmd_ctcp_action, N_("action &lt;action to perform&gt;: Perform an action.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
110 { "away", ":", irc_cmd_away, N_("away [message]: Set an away message, or use no message to return from being away.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
111 { "deop", ":", irc_cmd_op, N_("deop &lt;nick1&gt; [nick2] ...: Remove channel operator status from someone. You must have ops yourself to do this.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
112 { "devoice", ":", irc_cmd_op, N_("devoice &lt;nick1&gt; [nick2] ...: Remove channel voice status from someone, preventing them from speaking if the room is +m. You must have ops to do this.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
113 { "invite", ":", irc_cmd_invite, N_("invite &lt;nick&gt; [room]: Invite someone to join you in the specified chat room, or the current room.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
114 { "j", "cv", irc_cmd_join, N_("j &lt;room1&gt[,room2][,...] [key1[,key2][,...]]: Enter one or more chat rooms, optionally providing a channel key if needed.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
115 { "join", "cv", irc_cmd_join, N_("join &lt;room1&gt[,room2][,...] [key1[,key2][,...]]: Enter one or more chat rooms, optionally providing a channel key if needed.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
116 { "kick", "n:", irc_cmd_kick, N_("kick &lt;nick&gt; [message]: Remove someone from a room. You must be a channel operator to do this.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
117 { "list", ":", irc_cmd_list, N_("list: Bring up the list of chat rooms. <i>Warning, some servers may disconnect you upon doing this.</i>") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
118 { "me", ":", irc_cmd_ctcp_action, N_("me &lt;action to perform&gt;: Perform an action.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
119 { "mode", ":", irc_cmd_mode, N_("mode &lt;nick|channel&gt; &lt;+|-&gt;&lt;A-Za-z&gt;: Set or unset a channel or user mode.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
120 { "msg", "t:", irc_cmd_privmsg, N_("msg &lt;nick&gt; &lt;message&gt;: Sent a message to a user (as opposed to a channel).") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
121 { "names", "c", irc_cmd_names, N_("names [channel]: See who is in a channel.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
122 { "nick", "n", irc_cmd_nick, N_("nick &lt;new nick name&gt;: Change your nick name.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
123 { "op", ":", irc_cmd_op, N_("op &lt;nick1&gt; [nick2] ...: Grant channel operator status to someone. You must have ops yourself to do this.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
124 { "operwall", ":", irc_cmd_wallops, N_("operwall &lt;message&gt;: If you don't know what this is, you probably can't use it.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
125 { "part", "c:", irc_cmd_part, N_("part [room] [message]: Leave the current room, or a specified room, with an optional message.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
126 { "ping", "n", irc_cmd_ping, N_("ping [nick]: Asks how much lag a user (or the server if no user specified) has.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
127 { "query", "n:", irc_cmd_query, N_("query &lt;nick&gt; &lt;message&gt;: Sent a message to a user (as opposed to a channel).") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
128 { "quit", ":", irc_cmd_quit, N_("quit [message]: Disconnect from the server, with an optional message.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
129 { "quote", "*", irc_cmd_quote, N_("quote [...]: Send a raw command to the server.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
130 { "remove", "n:", irc_cmd_remove, N_("remove &lt;nick&gt; [message]: Remove someone from a room. You must be a channel operator to do this.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
131 { "topic", ":", irc_cmd_topic, N_("topic [new topic]: View or change the channel topic.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
132 { "umode", ":", irc_cmd_mode, N_("umode &lt;+|-&gt;&lt;A-Za-z&gt;: Set or unset a user mode.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
133 { "voice", ":", irc_cmd_op, N_("voice &lt;nick1&gt; [nick2] ...: Grant channel voice status to someone. You must have ops to do this.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
134 { "wallops", ":", irc_cmd_wallops, N_("wallops &lt;message&gt;: If you don't know what this is, you probably can't use it.") },
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
135 { "whois", "n", irc_cmd_whois, N_("whois &lt;nick&gt;: Get information on a user.") },
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 6970
diff changeset
136 { NULL, NULL, NULL }
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
137 };
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
138
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
139 static GaimCmdRet irc_parse_gaim_cmd(GaimConversation *conv, const gchar *cmd,
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
140 gchar **args, gchar **error)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
141 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
142 GaimConnection *gc;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
143 struct irc_conn *irc;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
144 struct _irc_user_cmd *cmdent;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
145
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
146 gc = gaim_conversation_get_gc(conv);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
147 if (!gc)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
148 return GAIM_CMD_RET_FAILED;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
149
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
150 irc = gc->proto_data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
151
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
152 if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
153 return GAIM_CMD_RET_FAILED;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
154
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
155 (cmdent->cb)(irc, cmd, gaim_conversation_get_name(conv), (const char **)args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
156
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
157 return GAIM_CMD_RET_OK;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
158 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
159
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
160 static void irc_register_command(struct _irc_user_cmd *c)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
161 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
162 GaimCmdFlag f;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
163 char args[10];
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
164 char *format;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
165 int i;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
166
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
167 f = GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
168 | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
169
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
170 format = c->format;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
171
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
172 for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
173 switch (*format) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
174 case 'v':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
175 case 'n':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
176 case 'c':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
177 case 't':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
178 args[i] = 'w';
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
179 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
180 case ':':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
181 case '*':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
182 args[i] = 's';
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
183 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
184 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
185
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
186 args[i] = '\0';
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
187
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
188 gaim_cmd_register(c->name, args, GAIM_CMD_P_PRPL, f, "prpl-irc", irc_parse_gaim_cmd,
9255
36938636ca8a [gaim-migrate @ 10054]
Tim Ringenbach <marv@pidgin.im>
parents: 9248
diff changeset
189 _(c->help));
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
190 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
191
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
192 void irc_register_commands(void)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
193 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
194 struct _irc_user_cmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
195
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
196 for (c = _irc_cmds; c && c->name; c++)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
197 irc_register_command(c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
198 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8954
diff changeset
199
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
200 static char *irc_send_convert(struct irc_conn *irc, const char *string)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
201 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
202 char *utf8;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
203 GError *err = NULL;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
204
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
205 utf8 = g_convert(string, strlen(string),
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
206 gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET),
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
207 "UTF-8", NULL, NULL, &err);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
208 if (err) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
209 gaim_debug(GAIM_DEBUG_ERROR, "irc", "send conversion error: %s\n", err->message);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
210 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Sending raw, which probably isn't right\n");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
211 utf8 = g_strdup(string);
8954
c60f82d78dea [gaim-migrate @ 9727]
Luke Schierer <lschiere@pidgin.im>
parents: 8627
diff changeset
212 g_error_free(err);
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
213 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
214
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
215 return utf8;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
216 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
217
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
218 static char *irc_recv_convert(struct irc_conn *irc, const char *string)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
219 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
220 char *utf8;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
221 GError *err = NULL;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
222
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
223 utf8 = g_convert(string, strlen(string), "UTF-8",
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
224 gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET),
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
225 NULL, NULL, &err);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
226 if (err) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
227 gaim_debug(GAIM_DEBUG_ERROR, "irc", "recv conversion error: %s\n", err->message);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
228 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)"));
8954
c60f82d78dea [gaim-migrate @ 9727]
Luke Schierer <lschiere@pidgin.im>
parents: 8627
diff changeset
229 g_error_free(err);
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
230 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
231
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
232 return utf8;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
233 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
234
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
235 /* XXX tag closings are not necessarily correctly nested here! If we
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
236 * get a ^O or reach the end of the string and there are open
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
237 * tags, they are closed in a fixed order ... this means, for
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
238 * example, you might see <FONT COLOR="blue">some text <B>with
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
239 * various attributes</FONT></B> (notice that B and FONT overlap
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
240 * and are not cleanly nested). This is imminently fixable but
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
241 * I am not fixing it right now.
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
242 */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
243 char *irc_mirc2html(const char *string)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
244 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
245 const char *cur, *end;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
246 char fg[3] = "\0\0", bg[3] = "\0\0";
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
247 int fgnum, bgnum;
6754
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
248 int font = 0, bold = 0, underline = 0;
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
249 GString *decoded = g_string_sized_new(strlen(string));
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
250
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
251 cur = string;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
252 do {
6754
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
253 end = strpbrk(cur, "\002\003\007\017\026\037");
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
254
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
255 decoded = g_string_append_len(decoded, cur, end ? end - cur : strlen(cur));
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
256 cur = end ? end : cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
257
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
258 switch (*cur) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
259 case '\002':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
260 cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
261 if (!bold) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
262 decoded = g_string_append(decoded, "<B>");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
263 bold = TRUE;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
264 } else {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
265 decoded = g_string_append(decoded, "</B>");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
266 bold = FALSE;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
267 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
268 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
269 case '\003':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
270 cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
271 fg[0] = fg[1] = bg[0] = bg[1] = '\0';
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
272 if (isdigit(*cur))
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
273 fg[0] = *cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
274 if (isdigit(*cur))
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
275 fg[1] = *cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
276 if (*cur == ',') {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
277 cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
278 if (isdigit(*cur))
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
279 bg[0] = *cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
280 if (isdigit(*cur))
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
281 bg[1] = *cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
282 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
283 if (font) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
284 decoded = g_string_append(decoded, "</FONT>");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
285 font = FALSE;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
286 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
287
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
288 if (fg[0]) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
289 fgnum = atoi(fg);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
290 if (fgnum < 0 || fgnum > 15)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
291 continue;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
292 font = TRUE;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
293 g_string_append_printf(decoded, "<FONT COLOR=\"%s\"", irc_mirc_colors[fgnum]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
294 if (bg[0]) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
295 bgnum = atoi(bg);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
296 if (bgnum >= 0 && bgnum < 16)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
297 g_string_append_printf(decoded, " BACK=\"%s\"", irc_mirc_colors[bgnum]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
298 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
299 decoded = g_string_append_c(decoded, '>');
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
300 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
301 break;
6754
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
302 case '\037':
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
303 cur++;
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
304 if (!underline) {
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
305 decoded = g_string_append(decoded, "<U>");
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
306 underline = TRUE;
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
307 } else {
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
308 decoded = g_string_append(decoded, "</U>");
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
309 underline = TRUE;
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
310 }
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
311 break;
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
312 case '\007':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
313 case '\026':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
314 cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
315 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
316 case '\017':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
317 cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
318 /* fallthrough */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
319 case '\000':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
320 if (bold)
6754
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
321 decoded = g_string_append(decoded, "</B>");
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
322 if (underline)
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
323 decoded = g_string_append(decoded, "</U>");
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
324 if (font)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
325 decoded = g_string_append(decoded, "</FONT>");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
326 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
327 default:
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
328 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Unexpected mIRC formatting character %d\n", *cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
329 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
330 } while (*cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
331
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
332 return g_string_free(decoded, FALSE);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
333 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
334
8529
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
335 char *irc_mirc2txt (const char *string)
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
336 {
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
337 char *result = g_strdup (string);
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
338 int i, j;
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
339
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
340 for (i = 0, j = 0; result[i]; i++) {
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
341 switch (result[i]) {
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
342 case '\002':
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
343 case '\003':
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
344 case '\007':
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
345 case '\017':
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
346 case '\026':
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
347 case '\037':
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
348 continue;
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
349 default:
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
350 result[j++] = result[i];
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
351 }
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
352 }
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
353 result[i] = '\0';
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
354 return result;
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
355 }
2f505651ac03 [gaim-migrate @ 9268]
Ethan Blanton <elb@pidgin.im>
parents: 8404
diff changeset
356
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
357 char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
358 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
359 GaimConnection *gc;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
360 const char *cur = msg + 1;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
361 char *buf, *ctcp;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
362 time_t timestamp;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
363
6754
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
364 /* Note that this is NOT correct w.r.t. multiple CTCPs in one
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
365 * message and low-level quoting ... but if you want that crap,
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
366 * use a real IRC client. */
47e49e3c00f4 [gaim-migrate @ 7286]
Ethan Blanton <elb@pidgin.im>
parents: 6718
diff changeset
367
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
368 if (msg[0] != '\001' || msg[strlen(msg) - 1] != '\001')
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
369 return g_strdup(msg);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
370
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
371 if (!strncmp(cur, "ACTION ", 7)) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
372 cur += 7;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
373 buf = g_strdup_printf("/me %s", cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
374 buf[strlen(buf) - 1] = '\0';
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
375 return buf;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
376 } else if (!strncmp(cur, "PING ", 5)) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
377 if (notice) { /* reply */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
378 sscanf(cur, "PING %lu", &timestamp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
379 gc = gaim_account_get_connection(irc->account);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
380 if (!gc)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
381 return NULL;
6350
34c07f5f34a0 [gaim-migrate @ 6849]
Mark Doliner <mark@kingant.net>
parents: 6333
diff changeset
382 buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp);
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
383 gaim_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
384 g_free(buf);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
385 return NULL;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
386 } else {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
387 buf = irc_format(irc, "vt:", "NOTICE", from, msg);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
388 irc_send(irc, buf);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
389 g_free(buf);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
390 gc = gaim_account_get_connection(irc->account);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
391 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
392 } else if (!strncmp(cur, "VERSION", 7) && !notice) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
393 buf = irc_format(irc, "vt:", "NOTICE", from, "\001VERSION Gaim IRC\001");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
394 irc_send(irc, buf);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
395 g_free(buf);
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents: 8114
diff changeset
396 } else if (!strncmp(cur, "DCC SEND ", 9)) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents: 8114
diff changeset
397 irc_dccsend_recv(irc, from, msg + 10);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents: 8114
diff changeset
398 return NULL;
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
399 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
400
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
401 ctcp = g_strdup(msg + 1);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
402 ctcp[strlen(ctcp) - 1] = '\0';
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
403 buf = g_strdup_printf("Received CTCP '%s' (to %s) from %s", ctcp, to, from);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
404 g_free(ctcp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
405 return buf;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
406 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
407
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
408 void irc_msg_table_build(struct irc_conn *irc)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
409 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
410 int i;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
411
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
412 if (!irc || !irc->msgs) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
413 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Attempt to build a message table on a bogus structure\n");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
414 return;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
415 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
416
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
417 for (i = 0; _irc_msgs[i].name; i++) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
418 g_hash_table_insert(irc->msgs, (gpointer)_irc_msgs[i].name, (gpointer)&_irc_msgs[i]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
419 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
420 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
421
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
422 void irc_cmd_table_build(struct irc_conn *irc)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
423 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
424 int i;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
425
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
426 if (!irc || !irc->cmds) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
427 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Attempt to build a command table on a bogus structure\n");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
428 return;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
429 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
430
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
431 for (i = 0; _irc_cmds[i].name ; i++) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
432 g_hash_table_insert(irc->cmds, (gpointer)_irc_cmds[i].name, (gpointer)&_irc_cmds[i]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
433 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
434 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
435
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
436 char *irc_format(struct irc_conn *irc, const char *format, ...)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
437 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
438 GString *string = g_string_new("");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
439 char *tok, *tmp;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
440 const char *cur;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
441 va_list ap;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
442
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
443 va_start(ap, format);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
444 for (cur = format; *cur; cur++) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
445 if (cur != format)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
446 g_string_append_c(string, ' ');
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
447
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
448 tok = va_arg(ap, char *);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
449 switch (*cur) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
450 case 'v':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
451 g_string_append(string, tok);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
452 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
453 case ':':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
454 g_string_append_c(string, ':');
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
455 /* no break! */
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
456 case 't':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
457 case 'n':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
458 case 'c':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
459 tmp = irc_send_convert(irc, tok);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
460 g_string_append(string, tmp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
461 g_free(tmp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
462 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
463 default:
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
464 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Invalid format character '%c'\n", *cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
465 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
466 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
467 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
468 va_end(ap);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
469 g_string_append(string, "\r\n");
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
470 return (g_string_free(string, FALSE));
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
471 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
472
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
473 void irc_parse_msg(struct irc_conn *irc, char *input)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
474 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
475 struct _irc_msg *msgent;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
476 char *cur, *end, *tmp, *from, *msgname, *fmt, **args, *msg;
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 6970
diff changeset
477 guint i;
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
478
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
479 if (!strncmp(input, "PING ", 5)) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
480 msg = irc_format(irc, "vv", "PONG", input + 5);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
481 irc_send(irc, msg);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
482 g_free(msg);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
483 return;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
484 } else if (!strncmp(input, "ERROR ", 6)) {
7981
ad5c8f01882b [gaim-migrate @ 8658]
Luke Schierer <lschiere@pidgin.im>
parents: 7877
diff changeset
485 gaim_connection_error(gaim_account_get_connection(irc->account), _("Disconnected."));
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
486 return;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
487 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
488
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
489 if (input[0] != ':' || (cur = strchr(input, ' ')) == NULL) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
490 irc_parse_error_cb(irc, input);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
491 return;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
492 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
493
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
494 from = g_strndup(&input[1], cur - &input[1]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
495 cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
496 end = strchr(cur, ' ');
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
497 if (!end)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
498 end = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
499
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
500 tmp = g_strndup(cur, end - cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
501 msgname = g_ascii_strdown(tmp, -1);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
502 g_free(tmp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
503
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
504 if ((msgent = g_hash_table_lookup(irc->msgs, msgname)) == NULL) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
505 irc_msg_default(irc, "", from, &input);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
506 g_free(msgname);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
507 g_free(from);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
508 return;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
509 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
510 g_free(msgname);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
511
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
512 args = g_new0(char *, strlen(msgent->format));
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
513 for (cur = end, fmt = msgent->format, i = 0; fmt[i] && *cur++; i++) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
514 switch (fmt[i]) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
515 case 'v':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
516 if (!(end = strchr(cur, ' '))) end = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
517 args[i] = g_strndup(cur, end - cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
518 cur += end - cur;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
519 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
520 case 't':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
521 case 'n':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
522 case 'c':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
523 if (!(end = strchr(cur, ' '))) end = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
524 tmp = g_strndup(cur, end - cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
525 args[i] = irc_recv_convert(irc, tmp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
526 g_free(tmp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
527 cur += end - cur;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
528 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
529 case ':':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
530 if (*cur == ':') cur++;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
531 args[i] = irc_recv_convert(irc, cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
532 cur = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
533 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
534 case '*':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
535 args[i] = g_strdup(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
536 cur = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
537 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
538 default:
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
539 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid message format character '%c'\n", fmt[i]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
540 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
541 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
542 }
6970
91df6a6e6567 [gaim-migrate @ 7517]
Ethan Blanton <elb@pidgin.im>
parents: 6754
diff changeset
543 tmp = irc_recv_convert(irc, from);
91df6a6e6567 [gaim-migrate @ 7517]
Ethan Blanton <elb@pidgin.im>
parents: 6754
diff changeset
544 (msgent->cb)(irc, msgent->name, tmp, args);
91df6a6e6567 [gaim-migrate @ 7517]
Ethan Blanton <elb@pidgin.im>
parents: 6754
diff changeset
545 g_free(tmp);
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
546 for (i = 0; i < strlen(msgent->format); i++) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
547 g_free(args[i]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
548 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
549 g_free(args);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
550 g_free(from);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
551 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
552
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
553 int irc_parse_cmd(struct irc_conn *irc, const char *target, const char *cmdstr)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
554 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
555 const char *cur, *end, *fmt;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
556 char *tmp, *cmd, **args;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
557 struct _irc_user_cmd *cmdent;
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 6970
diff changeset
558 guint i;
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 6970
diff changeset
559 int ret;
6333
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
560
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
561 cur = cmdstr;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
562 end = strchr(cmdstr, ' ');
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
563 if (!end)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
564 end = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
565
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
566 tmp = g_strndup(cur, end - cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
567 cmd = g_utf8_strdown(tmp, -1);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
568 g_free(tmp);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
569
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
570 if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
571 ret = irc_cmd_default(irc, cmd, target, &cmdstr);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
572 g_free(cmd);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
573 return ret;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
574 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
575
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
576 args = g_new0(char *, strlen(cmdent->format));
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
577 for (cur = end, fmt = cmdent->format, i = 0; fmt[i] && *cur++; i++) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
578 switch (fmt[i]) {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
579 case 'v':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
580 if (!(end = strchr(cur, ' '))) end = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
581 args[i] = g_strndup(cur, end - cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
582 cur += end - cur;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
583 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
584 case 't':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
585 case 'n':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
586 case 'c':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
587 if (!(end = strchr(cur, ' '))) end = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
588 args[i] = g_strndup(cur, end - cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
589 cur += end - cur;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
590 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
591 case ':':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
592 case '*':
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
593 args[i] = g_strdup(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
594 cur = cur + strlen(cur);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
595 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
596 default:
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
597 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid command format character '%c'\n", fmt[i]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
598 break;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
599 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
600 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
601 ret = (cmdent->cb)(irc, cmd, target, (const char **)args);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
602 for (i = 0; i < strlen(cmdent->format); i++)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
603 g_free(args[i]);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
604 g_free(args);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
605
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
606 g_free(cmd);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
607 return ret;
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
608 }
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
609
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
610 static void irc_parse_error_cb(struct irc_conn *irc, char *input)
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
611 {
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
612 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Unrecognized string: %s\n", input);
e06e04e44914 [gaim-migrate @ 6832]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
613 }