6 * Copyright (C) 2003, 2012 Ethan Blanton <elb@pidgin.im>
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.
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.
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
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #ifndef PURPLE_IRC_IRC_H
24 #define PURPLE_IRC_IRC_H
29 #ifdef HAVE_CYRUS_SASL
30 #include <sasl/sasl.h>
33 #include "circularbuffer.h"
35 #include "queuedoutputstream.h"
38 #define IRC_TYPE_PROTOCOL (irc_protocol_get_type())
39 #define IRC_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), IRC_TYPE_PROTOCOL, IRCProtocol))
40 #define IRC_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), IRC_TYPE_PROTOCOL, IRCProtocolClass))
41 #define IRC_IS_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), IRC_TYPE_PROTOCOL))
42 #define IRC_IS_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), IRC_TYPE_PROTOCOL))
43 #define IRC_PROTOCOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), IRC_TYPE_PROTOCOL, IRCProtocolClass))
45 #define IRC_DEFAULT_SERVER "irc.freenode.net"
46 #define IRC_DEFAULT_PORT 6667
47 #define IRC_DEFAULT_SSL_PORT 994
49 #define IRC_DEFAULT_CHARSET "UTF-8"
50 #define IRC_DEFAULT_AUTODETECT FALSE
51 #define IRC_DEFAULT_ALIAS "purple"
53 #define IRC_DEFAULT_QUIT "Leaving."
55 #define IRC_BUFSIZE_INCREMENT 1024
56 #define IRC_MAX_BUFSIZE 16384
58 #define IRC_MAX_MSG_SIZE 512
60 #define IRC_NAMES_FLAG "irc-namelist"
62 enum { IRC_USEROPT_SERVER
, IRC_USEROPT_PORT
, IRC_USEROPT_CHARSET
};
63 enum irc_state
{ IRC_STATE_NEW
, IRC_STATE_ESTABLISHED
};
67 PurpleProtocol parent
;
72 PurpleProtocolClass parent_class
;
76 PurpleAccount
*account
;
80 GSocketConnection
*conn
;
81 GCancellable
*cancellable
;
85 gboolean ison_outstanding
;
86 GList
*buddies_outstanding
;
88 GDataInputStream
*input
;
89 PurpleQueuedOutputStream
*output
;
108 PurpleRoomlist
*roomlist
;
117 #ifdef HAVE_CYRUS_SASL
118 sasl_conn_t
*sasl_conn
;
119 const char *current_mech
;
122 sasl_callback_t
*sasl_cb
;
130 gboolean new_online_status
;
134 typedef int (*IRCCmdCallback
) (struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
136 G_MODULE_EXPORT GType
irc_protocol_get_type(void);
138 int irc_send(struct irc_conn
*irc
, const char *buf
);
139 int irc_send_len(struct irc_conn
*irc
, const char *buf
, int len
);
140 gboolean
irc_blist_timeout(struct irc_conn
*irc
);
141 gboolean
irc_who_channel_timeout(struct irc_conn
*irc
);
142 void irc_buddy_query(struct irc_conn
*irc
);
144 char *irc_escape_privmsg(const char *text
, gssize length
);
146 char *irc_mirc2html(const char *string
);
147 char *irc_mirc2txt(const char *string
);
149 const char *irc_nick_skip_mode(struct irc_conn
*irc
, const char *string
);
151 gboolean
irc_ischannel(const char *string
);
153 void irc_register_commands(void);
154 void irc_unregister_commands(void);
155 void irc_msg_table_build(struct irc_conn
*irc
);
156 void irc_parse_msg(struct irc_conn
*irc
, char *input
);
157 char *irc_parse_ctcp(struct irc_conn
*irc
, const char *from
, const char *to
, const char *msg
, int notice
);
158 char *irc_format(struct irc_conn
*irc
, const char *format
, ...);
160 void irc_msg_default(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
161 void irc_msg_away(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
162 void irc_msg_badmode(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
163 void irc_msg_badnick(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
164 void irc_msg_ban(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
165 void irc_msg_banfull(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
166 void irc_msg_banned(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
167 void irc_msg_chanmode(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
168 void irc_msg_endwhois(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
169 void irc_msg_features(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
170 void irc_msg_invite(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
171 void irc_msg_inviteonly(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
172 void irc_msg_ison(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
173 void irc_msg_join(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
174 void irc_msg_kick(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
175 void irc_msg_list(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
176 void irc_msg_luser(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
177 void irc_msg_mode(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
178 void irc_msg_motd(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
179 void irc_msg_names(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
180 void irc_msg_nick(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
181 void irc_msg_nickused(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
182 void irc_msg_nochan(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
183 void irc_msg_nonick(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
184 void irc_msg_nochangenick(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
185 void irc_msg_nosend(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
186 void irc_msg_notice(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
187 void irc_msg_notinchan(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
188 void irc_msg_notop(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
189 void irc_msg_part(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
190 void irc_msg_ping(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
191 void irc_msg_pong(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
192 void irc_msg_privmsg(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
193 void irc_msg_quit(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
194 void irc_msg_regonly(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
195 void irc_msg_time(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
196 void irc_msg_topic(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
197 void irc_msg_topicinfo(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
198 void irc_msg_unavailable(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
199 void irc_msg_unknown(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
200 void irc_msg_wallops(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
201 void irc_msg_whois(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
202 void irc_msg_who(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
203 #ifdef HAVE_CYRUS_SASL
204 void irc_msg_cap(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
205 void irc_msg_auth(struct irc_conn
*irc
, char *arg
);
206 void irc_msg_authenticate(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
207 void irc_msg_authok(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
208 void irc_msg_authtryagain(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
209 void irc_msg_authfail(struct irc_conn
*irc
, const char *name
, const char *from
, char **args
);
212 void irc_cmd_table_build(struct irc_conn
*irc
);
214 int irc_cmd_default(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
215 int irc_cmd_away(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
216 int irc_cmd_ctcp(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
217 int irc_cmd_ctcp_action(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
218 int irc_cmd_ctcp_version(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
219 int irc_cmd_invite(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
220 int irc_cmd_join(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
221 int irc_cmd_kick(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
222 int irc_cmd_list(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
223 int irc_cmd_mode(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
224 int irc_cmd_names(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
225 int irc_cmd_nick(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
226 int irc_cmd_op(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
227 int irc_cmd_privmsg(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
228 int irc_cmd_part(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
229 int irc_cmd_ping(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
230 int irc_cmd_quit(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
231 int irc_cmd_quote(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
232 int irc_cmd_query(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
233 int irc_cmd_remove(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
234 int irc_cmd_service(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
235 int irc_cmd_time(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
236 int irc_cmd_topic(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
237 int irc_cmd_wallops(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
238 int irc_cmd_whois(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
239 int irc_cmd_whowas(struct irc_conn
*irc
, const char *cmd
, const char *target
, const char **args
);
241 #define IRC_TYPE_XFER (irc_xfer_get_type())
242 G_DECLARE_FINAL_TYPE(IrcXfer
, irc_xfer
, IRC
, XFER
, PurpleXfer
);
244 void irc_xfer_register(GTypeModule
*module
);
246 PurpleXfer
*irc_dccsend_new_xfer(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
);
247 void irc_dccsend_send_file(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
, const char *file
);
248 void irc_dccsend_recv(struct irc_conn
*irc
, const char *from
, const char *msg
);
250 #endif /* PURPLE_IRC_IRC_H */