Mercurial > pidgin
annotate src/protocols/irc/irc.c @ 8944:f041cc8d86cf
[gaim-migrate @ 9716]
Fully replace Ignore colors, Ignore font faces and Ignore font sizes with
Ignore formatting on incoming messages.
nosnilmot: I chose not to apply your change to set_away_option because
people should not attempt to set a preference with a NULL value, and
if they do we might as well just have Gaim crash so they know about it.
My reasoning might be flawed. Eh.
Also, Chip and Etan were both against consolidating these options,
so someone might want to keep a patch of this commit handy so we can
revert it, if necessary.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 16 May 2004 05:25:37 +0000 |
parents | 8bf735cf9d1c |
children | 80b4c956d7ae |
rev | line source |
---|---|
6333 | 1 /** |
2 * @file irc.c | |
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
3 * |
6333 | 4 * gaim |
2086 | 5 * |
8351 | 6 * Copyright (C) 2003, Robbert Haarman <gaim@inglorion.net> |
6333 | 7 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> |
8 * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com> | |
2086 | 9 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> |
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
10 * |
2086 | 11 * This program is free software; you can redistribute it and/or modify |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
6333 | 25 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
26 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
27 |
6333 | 28 #include "plugin.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
29 #include "accountopt.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
30 #include "multi.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
31 #include "prpl.h" |
6333 | 32 #include "conversation.h" |
7148 | 33 #include "notify.h" |
6333 | 34 #include "debug.h" |
35 #include "blist.h" | |
6350 | 36 #include "util.h" |
6333 | 37 #include "irc.h" |
4422 | 38 |
6333 | 39 static void irc_buddy_append(char *name, struct irc_buddy *ib, GString *string); |
2086 | 40 |
6695 | 41 static const char *irc_blist_icon(GaimAccount *a, GaimBuddy *b); |
42 static void irc_blist_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne); | |
6333 | 43 static GList *irc_away_states(GaimConnection *gc); |
7148 | 44 static GList *irc_actions(GaimConnection *gc); |
6333 | 45 /* static GList *irc_chat_info(GaimConnection *gc); */ |
46 static void irc_login(GaimAccount *account); | |
47 static void irc_login_cb(gpointer data, gint source, GaimInputCondition cond); | |
48 static void irc_close(GaimConnection *gc); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
49 static int irc_im_send(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags); |
6333 | 50 static int irc_chat_send(GaimConnection *gc, int id, const char *what); |
51 static void irc_chat_join (GaimConnection *gc, GHashTable *data); | |
52 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond); | |
3751 | 53 |
7711 | 54 static guint irc_nick_hash(const char *nick); |
55 static gboolean irc_nick_equal(const char *nick1, const char *nick2); | |
56 static void irc_buddy_free(struct irc_buddy *ib); | |
57 | |
58 static GaimPlugin *_irc_plugin = NULL; | |
59 | |
60 static const char *status_chars = "@+%&"; | |
61 | |
7148 | 62 static void irc_view_motd(GaimConnection *gc) |
63 { | |
64 struct irc_conn *irc; | |
65 char *title; | |
66 | |
67 if (gc == NULL || gc->proto_data == NULL) { | |
68 gaim_debug(GAIM_DEBUG_ERROR, "irc", "got MOTD request for NULL gc\n"); | |
69 return; | |
70 } | |
71 irc = gc->proto_data; | |
72 if (irc->motd == NULL) { | |
73 gaim_notify_error(gc, _("Error displaying MOTD"), _("No MOTD available"), | |
74 _("There is no MOTD associated with this connection.")); | |
75 return; | |
76 } | |
77 title = g_strdup_printf(_("MOTD for %s"), irc->server); | |
78 gaim_notify_formatted(gc, title, title, NULL, irc->motd->str, NULL, NULL); | |
79 } | |
80 | |
6333 | 81 int irc_send(struct irc_conn *irc, const char *buf) |
3751 | 82 { |
6333 | 83 if (irc->fd < 0) |
84 return -1; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
85 |
6333 | 86 /* gaim_debug(GAIM_DEBUG_MISC, "irc", "sent: %s", buf); */ |
87 return write(irc->fd, buf, strlen(buf)); | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
88 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
89 |
6333 | 90 /* XXX I don't like messing directly with these buddies */ |
91 gboolean irc_blist_timeout(struct irc_conn *irc) | |
2086 | 92 { |
6333 | 93 GString *string = g_string_sized_new(512); |
94 char *list, *buf; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
95 |
6333 | 96 g_hash_table_foreach(irc->buddies, (GHFunc)irc_buddy_append, (gpointer)string); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
97 |
6333 | 98 list = g_string_free(string, FALSE); |
99 if (!list || !strlen(list)) { | |
100 g_free(list); | |
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2131
diff
changeset
|
101 return TRUE; |
2086 | 102 } |
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
103 |
8038 | 104 buf = irc_format(irc, "vn", "ISON", list); |
6333 | 105 g_free(list); |
106 irc_send(irc, buf); | |
107 g_free(buf); | |
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
108 |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
109 return TRUE; |
2086 | 110 } |
111 | |
6333 | 112 static void irc_buddy_append(char *name, struct irc_buddy *ib, GString *string) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
113 { |
6333 | 114 ib->flag = FALSE; |
115 g_string_append_printf(string, "%s ", name); | |
3511 | 116 } |
117 | |
6695 | 118 static const char *irc_blist_icon(GaimAccount *a, GaimBuddy *b) |
3029 | 119 { |
6333 | 120 return "irc"; |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
121 } |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
122 |
6695 | 123 static void irc_blist_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) |
3751 | 124 { |
6333 | 125 if (b->present == GAIM_BUDDY_OFFLINE) |
126 *se = "offline"; | |
2086 | 127 } |
128 | |
6333 | 129 static GList *irc_away_states(GaimConnection *gc) |
2086 | 130 { |
6333 | 131 return g_list_append(NULL, (gpointer)GAIM_AWAY_CUSTOM); |
3452 | 132 } |
133 | |
7148 | 134 static GList *irc_actions(GaimConnection *gc) |
135 { | |
136 struct proto_actions_menu *pam; | |
137 GList *list = NULL; | |
138 | |
139 pam = g_new0(struct proto_actions_menu, 1); | |
140 pam->label = _("View MOTD"); | |
141 pam->callback = irc_view_motd; | |
142 pam->gc = gc; | |
143 list = g_list_append(list, pam); | |
144 | |
145 return list; | |
146 } | |
147 | |
6333 | 148 static GList *irc_buddy_menu(GaimConnection *gc, const char *who) |
2086 | 149 { |
8351 | 150 GList *m = NULL; |
151 struct proto_buddy_menu *pbm; | |
152 | |
153 pbm = g_new0(struct proto_buddy_menu, 1); | |
154 pbm->label = _("Send File"); | |
155 pbm->callback = irc_dccsend_send_ask; | |
156 pbm->gc = gc; | |
157 m = g_list_append(m, pbm); | |
158 | |
159 return m; | |
2086 | 160 } |
161 | |
6333 | 162 static GList *irc_chat_join_info(GaimConnection *gc) |
2086 | 163 { |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
164 GList *m = NULL; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
165 struct proto_chat_entry *pce; |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
166 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
167 pce = g_new0(struct proto_chat_entry, 1); |
7841 | 168 pce->label = _("_Channel:"); |
5234 | 169 pce->identifier = "channel"; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
170 m = g_list_append(m, pce); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
171 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
172 pce = g_new0(struct proto_chat_entry, 1); |
7841 | 173 pce->label = _("_Password:"); |
5234 | 174 pce->identifier = "password"; |
6499 | 175 pce->secret = TRUE; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
176 m = g_list_append(m, pce); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
177 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
178 return m; |
2086 | 179 } |
180 | |
6333 | 181 static void irc_login(GaimAccount *account) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
182 { |
6333 | 183 GaimConnection *gc; |
184 struct irc_conn *irc; | |
185 char *buf, **userparts; | |
186 const char *username = gaim_account_get_username(account); | |
187 int err; | |
188 | |
189 gc = gaim_account_get_connection(account); | |
8677 | 190 gc->flags |= GAIM_CONNECTION_NO_NEWLINES; |
6333 | 191 |
6752 | 192 if (strpbrk(username, " \t\v\r\n") != NULL) { |
193 gaim_connection_error(gc, _("IRC nicks may not contain whitespace")); | |
194 return; | |
195 } | |
196 | |
6333 | 197 gc->proto_data = irc = g_new0(struct irc_conn, 1); |
198 irc->account = account; | |
199 | |
200 userparts = g_strsplit(username, "@", 2); | |
201 gaim_connection_set_display_name(gc, userparts[0]); | |
202 irc->server = g_strdup(userparts[1]); | |
203 g_strfreev(userparts); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
204 |
6333 | 205 irc->buddies = g_hash_table_new_full((GHashFunc)irc_nick_hash, (GEqualFunc)irc_nick_equal, |
206 NULL, (GDestroyNotify)irc_buddy_free); | |
207 irc->cmds = g_hash_table_new(g_str_hash, g_str_equal); | |
208 irc_cmd_table_build(irc); | |
209 irc->msgs = g_hash_table_new(g_str_hash, g_str_equal); | |
210 irc_msg_table_build(irc); | |
211 | |
212 buf = g_strdup_printf(_("Signon: %s"), username); | |
213 gaim_connection_update_progress(gc, buf, 1, 2); | |
214 g_free(buf); | |
215 | |
216 err = gaim_proxy_connect(account, irc->server, | |
217 gaim_account_get_int(account, "port", IRC_DEFAULT_PORT), | |
218 irc_login_cb, gc); | |
219 | |
220 if (err || !account->gc) { | |
221 gaim_connection_error(gc, _("Couldn't create socket")); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
222 return; |
6333 | 223 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
224 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
225 |
6333 | 226 static void irc_login_cb(gpointer data, gint source, GaimInputCondition cond) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
227 { |
6333 | 228 GaimConnection *gc = data; |
229 struct irc_conn *irc = gc->proto_data; | |
230 char hostname[256]; | |
231 char *buf; | |
7323 | 232 const char *username; |
6333 | 233 GList *connections = gaim_connections_get_all(); |
234 | |
8778 | 235 if (source < 0) { |
236 gaim_connection_error(gc, _("Couldn't connect to host")); | |
6333 | 237 return; |
8778 | 238 } |
6333 | 239 |
240 if (!g_list_find(connections, gc)) { | |
241 close(source); | |
242 return; | |
243 } | |
244 | |
245 irc->fd = source; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
246 |
6333 | 247 if (gc->account->password && *gc->account->password) { |
248 buf = irc_format(irc, "vv", "PASS", gc->account->password); | |
249 if (irc_send(irc, buf) < 0) { | |
250 gaim_connection_error(gc, "Error sending password"); | |
251 return; | |
252 } | |
253 g_free(buf); | |
254 } | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
255 |
6333 | 256 gethostname(hostname, sizeof(hostname)); |
257 hostname[sizeof(hostname) - 1] = '\0'; | |
7323 | 258 username = gaim_account_get_string(irc->account, "username", ""); |
259 buf = irc_format(irc, "vvvv:", "USER", strlen(username) ? username : g_get_user_name(), hostname, irc->server, | |
6333 | 260 gc->account->alias && *gc->account->alias ? gc->account->alias : IRC_DEFAULT_ALIAS); |
261 if (irc_send(irc, buf) < 0) { | |
262 gaim_connection_error(gc, "Error registering with server"); | |
263 return; | |
264 } | |
265 g_free(buf); | |
266 buf = irc_format(irc, "vn", "NICK", gaim_connection_get_display_name(gc)); | |
267 if (irc_send(irc, buf) < 0) { | |
268 gaim_connection_error(gc, "Error sending nickname"); | |
269 return; | |
270 } | |
271 g_free(buf); | |
272 | |
273 gc->inpa = gaim_input_add(irc->fd, GAIM_INPUT_READ, irc_input_cb, gc); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
274 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
275 |
6333 | 276 static void irc_close(GaimConnection *gc) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
277 { |
6333 | 278 struct irc_conn *irc = gc->proto_data; |
279 | |
6752 | 280 if (irc == NULL) |
281 return; | |
282 | |
6333 | 283 irc_cmd_quit(irc, "quit", NULL, NULL); |
284 | |
285 if (gc->inpa) | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8170
diff
changeset
|
286 gaim_timeout_remove(gc->inpa); |
6333 | 287 |
288 g_free(irc->inbuf); | |
289 close(irc->fd); | |
290 if (irc->timer) | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8170
diff
changeset
|
291 gaim_timeout_remove(irc->timer); |
6333 | 292 g_hash_table_destroy(irc->cmds); |
293 g_hash_table_destroy(irc->msgs); | |
294 if (irc->motd) | |
295 g_string_free(irc->motd, TRUE); | |
296 g_free(irc->server); | |
297 g_free(irc); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
298 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
299 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
300 static int irc_im_send(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
301 { |
6333 | 302 struct irc_conn *irc = gc->proto_data; |
303 const char *args[2]; | |
304 | |
7711 | 305 if (strchr(status_chars, *who) != NULL) |
6333 | 306 args[0] = who + 1; |
307 else | |
308 args[0] = who; | |
309 args[1] = what; | |
310 | |
311 if (*what == '/') { | |
312 return irc_parse_cmd(irc, who, what + 1); | |
313 } | |
314 | |
315 irc_cmd_privmsg(irc, "msg", NULL, args); | |
316 return 1; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
317 } |
2086 | 318 |
6333 | 319 static void irc_get_info(GaimConnection *gc, const char *who) |
2086 | 320 { |
6333 | 321 struct irc_conn *irc = gc->proto_data; |
322 const char *args[1]; | |
323 args[0] = who; | |
324 irc_cmd_whois(irc, "whois", NULL, args); | |
325 } | |
326 | |
327 static void irc_set_away(GaimConnection *gc, const char *state, const char *msg) | |
328 { | |
329 struct irc_conn *irc = gc->proto_data; | |
330 const char *args[1]; | |
2086 | 331 |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
332 if (gc->away) { |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
333 g_free(gc->away); |
2394
579f8d4347ad
[gaim-migrate @ 2407]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
334 gc->away = NULL; |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
335 } |
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
336 |
6333 | 337 if (msg) |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
338 gc->away = g_strdup(msg); |
2086 | 339 |
6333 | 340 args[0] = msg; |
341 irc_cmd_away(irc, "away", NULL, args); | |
4916 | 342 } |
343 | |
6787
faa491042c66
[gaim-migrate @ 7326]
Christian Hammond <chipx86@chipx86.com>
parents:
6752
diff
changeset
|
344 static void irc_add_buddy(GaimConnection *gc, const char *who, GaimGroup *group) |
3029 | 345 { |
6333 | 346 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; |
347 struct irc_buddy *ib = g_new0(struct irc_buddy, 1); | |
348 ib->name = g_strdup(who); | |
349 g_hash_table_insert(irc->buddies, ib->name, ib); | |
3029 | 350 } |
3622 | 351 |
6333 | 352 static void irc_remove_buddy(GaimConnection *gc, const char *who, const char *group) |
353 { | |
354 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; | |
355 g_hash_table_remove(irc->buddies, who); | |
3616 | 356 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4509
diff
changeset
|
357 |
3616 | 358 |
6333 | 359 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond) |
360 { | |
361 GaimConnection *gc = data; | |
362 struct irc_conn *irc = gc->proto_data; | |
363 char *cur, *end; | |
364 int len; | |
365 | |
366 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { | |
367 irc->inbuflen += IRC_INITIAL_BUFSIZE; | |
368 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); | |
3708 | 369 } |
3616 | 370 |
6333 | 371 if ((len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1)) < 0) { |
7653 | 372 gaim_connection_error(gc, _("Read error")); |
6333 | 373 return; |
6369 | 374 } else if (len == 0) { |
375 /* Remote closed the connection, probably */ | |
376 return; | |
6333 | 377 } |
6369 | 378 |
6333 | 379 irc->inbufused += len; |
380 irc->inbuf[irc->inbufused] = '\0'; | |
3616 | 381 |
8156 | 382 cur = irc->inbuf; |
383 while (cur < irc->inbuf + irc->inbufused && | |
384 ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) { | |
385 int step = (*end == '\r' ? 2 : 1); | |
6333 | 386 *end = '\0'; |
387 irc_parse_msg(irc, cur); | |
8156 | 388 cur = end + step; |
6333 | 389 } |
390 if (cur != irc->inbuf + irc->inbufused) { /* leftover */ | |
391 irc->inbufused -= (cur - irc->inbuf); | |
392 memmove(irc->inbuf, cur, irc->inbufused); | |
393 } else { | |
394 irc->inbufused = 0; | |
395 } | |
3616 | 396 } |
397 | |
6333 | 398 static void irc_chat_join (GaimConnection *gc, GHashTable *data) |
399 { | |
400 struct irc_conn *irc = gc->proto_data; | |
401 const char *args[2]; | |
3616 | 402 |
6333 | 403 args[0] = g_hash_table_lookup(data, "channel"); |
404 args[1] = g_hash_table_lookup(data, "password"); | |
405 irc_cmd_join(irc, "join", NULL, args); | |
3622 | 406 } |
407 | |
6333 | 408 static void irc_chat_invite(GaimConnection *gc, int id, const char *message, const char *name) |
3751 | 409 { |
6333 | 410 struct irc_conn *irc = gc->proto_data; |
411 GaimConversation *convo = gaim_find_chat(gc, id); | |
412 const char *args[2]; | |
3751 | 413 |
6333 | 414 if (!convo) { |
415 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); | |
416 return; | |
417 } | |
418 args[0] = name; | |
419 args[1] = gaim_conversation_get_name(convo); | |
420 irc_cmd_invite(irc, "invite", gaim_conversation_get_name(convo), args); | |
3707 | 421 } |
422 | |
6333 | 423 |
424 static void irc_chat_leave (GaimConnection *gc, int id) | |
3707 | 425 { |
6333 | 426 struct irc_conn *irc = gc->proto_data; |
427 GaimConversation *convo = gaim_find_chat(gc, id); | |
428 const char *args[2]; | |
5298 | 429 |
6333 | 430 if (!convo) |
431 return; | |
3735 | 432 |
6333 | 433 args[0] = gaim_conversation_get_name(convo); |
434 args[1] = NULL; | |
435 irc_cmd_part(irc, "part", gaim_conversation_get_name(convo), args); | |
436 serv_got_chat_left(gc, id); | |
3735 | 437 } |
438 | |
6333 | 439 static int irc_chat_send(GaimConnection *gc, int id, const char *what) |
3735 | 440 { |
6333 | 441 struct irc_conn *irc = gc->proto_data; |
442 GaimConversation *convo = gaim_find_chat(gc, id); | |
443 const char *args[2]; | |
8163 | 444 char *tmp; |
6333 | 445 |
446 if (!convo) { | |
447 gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); | |
448 return -EINVAL; | |
449 } | |
450 | |
451 if (*what == '/') { | |
452 return irc_parse_cmd(irc, convo->name, what + 1); | |
453 } | |
454 | |
455 args[0] = convo->name; | |
456 args[1] = what; | |
457 | |
458 irc_cmd_privmsg(irc, "msg", NULL, args); | |
8163 | 459 |
460 tmp = gaim_escape_html(what); | |
461 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, tmp, time(NULL)); | |
462 g_free(tmp); | |
6333 | 463 return 0; |
3707 | 464 } |
465 | |
6333 | 466 static guint irc_nick_hash(const char *nick) |
467 { | |
468 char *lc; | |
469 guint bucket; | |
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
470 |
6333 | 471 lc = g_utf8_strdown(nick, -1); |
472 bucket = g_str_hash(lc); | |
473 g_free(lc); | |
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
474 |
6333 | 475 return bucket; |
3029 | 476 } |
477 | |
6333 | 478 static gboolean irc_nick_equal(const char *nick1, const char *nick2) |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
479 { |
6333 | 480 return (gaim_utf8_strcasecmp(nick1, nick2) == 0); |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
481 } |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
482 |
6333 | 483 static void irc_buddy_free(struct irc_buddy *ib) |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
484 { |
6333 | 485 g_free(ib->name); |
486 g_free(ib); | |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
487 } |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
488 |
8114 | 489 static GaimRoomlist *irc_roomlist_get_list(GaimConnection *gc) |
490 { | |
491 struct irc_conn *irc; | |
492 GList *fields = NULL; | |
493 GaimRoomlistField *f; | |
8352 | 494 char *buf; |
8114 | 495 |
496 irc = gc->proto_data; | |
497 | |
498 if (irc->roomlist) | |
499 gaim_roomlist_unref(irc->roomlist); | |
500 | |
501 irc->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
502 | |
503 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "channel", TRUE); | |
504 fields = g_list_append(fields, f); | |
505 | |
506 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Users"), "users", FALSE); | |
507 fields = g_list_append(fields, f); | |
508 | |
509 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Topic"), "topic", FALSE); | |
510 fields = g_list_append(fields, f); | |
511 | |
512 gaim_roomlist_set_fields(irc->roomlist, fields); | |
513 | |
8352 | 514 buf = irc_format(irc, "v", "LIST"); |
515 irc_send(irc, buf); | |
516 g_free(buf); | |
8114 | 517 |
518 return irc->roomlist; | |
519 } | |
520 | |
521 static void irc_roomlist_cancel(GaimRoomlist *list) | |
522 { | |
523 GaimConnection *gc = gaim_account_get_connection(list->account); | |
524 struct irc_conn *irc; | |
525 | |
526 if (gc == NULL) | |
527 return; | |
528 | |
529 irc = gc->proto_data; | |
530 | |
531 gaim_roomlist_set_in_progress(list, FALSE); | |
532 | |
533 if (irc->roomlist == list) { | |
534 irc->roomlist = NULL; | |
535 gaim_roomlist_unref(list); | |
536 } | |
537 } | |
538 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
539 static GaimPluginProtocolInfo prpl_info = |
2086 | 540 { |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
541 GAIM_PRPL_API_VERSION, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
542 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
543 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
544 NULL, |
6333 | 545 irc_blist_icon, |
546 irc_blist_emblems, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
547 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
548 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
549 irc_away_states, |
7148 | 550 irc_actions, |
6350 | 551 irc_buddy_menu, |
6333 | 552 irc_chat_join_info, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
553 irc_login, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
554 irc_close, |
6333 | 555 irc_im_send, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
556 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
557 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
558 irc_get_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
559 irc_set_away, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
560 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
561 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
562 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
563 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
564 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
565 irc_add_buddy, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
566 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
567 irc_remove_buddy, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
568 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
569 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
570 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
571 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
572 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
573 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
574 NULL, |
6333 | 575 irc_chat_join, |
8562 | 576 NULL, /* reject chat invite */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
577 irc_chat_invite, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
578 irc_chat_leave, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
579 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
580 irc_chat_send, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
581 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
582 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
583 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
584 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
585 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
586 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
587 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
588 NULL, |
6333 | 589 NULL, /*irc_convo_closed,*/ |
8114 | 590 NULL, /* normalize */ |
591 NULL, /* set buddy icon */ | |
592 NULL, /* remove group */ | |
593 NULL, /* get_cb_real_name */ | |
594 NULL, | |
595 NULL, | |
596 irc_roomlist_get_list, | |
597 irc_roomlist_cancel, | |
8586 | 598 NULL, |
8589 | 599 NULL |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
600 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
601 |
8114 | 602 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
603 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
604 { |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
605 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
606 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
607 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
608 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
609 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
610 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
611 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
612 "prpl-irc", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
613 "IRC", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
614 VERSION, /**< version */ |
6333 | 615 N_("IRC Protocol Plugin"), /** summary */ |
616 N_("The IRC Protocol Plugin that Sucks Less"), /** description */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
617 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6369
diff
changeset
|
618 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
619 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
620 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
621 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
622 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
623 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
624 NULL, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
625 &prpl_info /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
626 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
627 |
6333 | 628 static void _init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
629 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
630 GaimAccountUserSplit *split; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
631 GaimAccountOption *option; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
632 |
6333 | 633 split = gaim_account_user_split_new(_("Server"), IRC_DEFAULT_SERVER, '@'); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
634 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
635 |
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
636 option = gaim_account_option_int_new(_("Port"), "port", IRC_DEFAULT_PORT); |
6333 | 637 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
638 |
6333 | 639 option = gaim_account_option_string_new(_("Encoding"), "encoding", IRC_DEFAULT_CHARSET); |
640 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
641 |
7323 | 642 option = gaim_account_option_string_new(_("Username"), "username", ""); |
643 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
644 | |
6333 | 645 _irc_plugin = plugin; |
2086 | 646 } |
647 | |
6333 | 648 GAIM_INIT_PLUGIN(irc, _init_plugin, info); |