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