Mercurial > pidgin.yaz
annotate src/protocols/irc/irc.c @ 2131:acc11216ec5d
[gaim-migrate @ 2141]
changing some gtk_timeout stuff to g_timeout (since it's likely that these will be used in core rather than gtk-ui). also fixed a small buddy pounce bug.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 06 Aug 2001 23:38:48 +0000 |
parents | 56c4382f2909 |
children | 18722ae5b882 |
rev | line source |
---|---|
2086 | 1 /* |
2 * gaim - IRC Protocol Plugin | |
3 * | |
4 * Copyright (C) 2000-2001, Rob Flynn <rob@tgflinux.com> | |
5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
23 #include <config.h> |
2086 | 24 |
25 | |
26 #include <netdb.h> | |
27 #include <gtk/gtk.h> | |
28 #include <unistd.h> | |
29 #include <errno.h> | |
30 #include <netinet/in.h> | |
31 #include <arpa/inet.h> | |
32 #include <fcntl.h> | |
33 #include <string.h> | |
34 #include <stdlib.h> | |
35 #include <stdio.h> | |
36 #include <time.h> | |
37 #include <sys/socket.h> | |
38 #include <sys/stat.h> | |
39 #include <ctype.h> | |
40 #include "multi.h" | |
41 #include "prpl.h" | |
42 #include "gaim.h" | |
43 #include "proxy.h" | |
44 | |
45 #include "pixmaps/free_icon.xpm" | |
46 | |
47 #define IRC_BUF_LEN 4096 | |
48 | |
49 | |
50 #define USEROPT_SERV 0 | |
51 #define USEROPT_PORT 1 | |
52 | |
53 static int chat_id = 0; | |
54 | |
55 struct irc_channel { | |
56 int id; | |
57 gchar *name; | |
58 }; | |
59 | |
60 struct irc_data { | |
61 int fd; | |
62 int inpa; /* used for non-block logins */ | |
63 | |
64 int timer; | |
65 | |
66 int totalblocks; | |
67 int recblocks; | |
68 | |
69 GSList *templist; | |
70 GList *channels; | |
71 }; | |
72 | |
73 static char *irc_name() | |
74 { | |
75 return "IRC"; | |
76 } | |
77 | |
78 static void irc_get_info(struct gaim_connection *gc, char *who); | |
79 | |
80 static void irc_join_chat(struct gaim_connection *gc, int id, char *name) | |
81 { | |
82 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
83 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
84 | |
85 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); | |
86 write(idata->fd, buf, strlen(buf)); | |
87 write(idata->fd, buf, strlen(buf)); | |
88 | |
89 g_free(buf); | |
90 } | |
91 | |
92 static void irc_update_user(struct gaim_connection *gc, char *name, int status) | |
93 { | |
94 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
95 struct irc_channel *u; | |
96 GSList *temp = idata->templist; | |
97 | |
98 /* Loop through our list */ | |
99 | |
100 while (temp) { | |
101 u = (struct irc_channel *)temp->data; | |
102 if (g_strcasecmp(u->name, name) == 0) { | |
103 u->id = status; | |
104 return; | |
105 } | |
106 | |
107 temp = g_slist_next(temp); | |
108 } | |
109 return; | |
110 } | |
111 | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
112 static gboolean irc_request_buddy_update(struct gaim_connection *gc) |
2086 | 113 { |
114 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
115 GSList *grp = gc->groups; | |
116 GSList *person; | |
117 struct group *g; | |
118 struct buddy *b; | |
119 struct irc_channel *u; | |
120 | |
121 if (idata->templist != NULL) | |
122 return; | |
123 | |
124 idata->recblocks = 0; | |
125 idata->totalblocks = 1; | |
126 | |
127 /* First, let's check to see if we have anyone on our buddylist */ | |
128 if (!grp) { | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
129 return TRUE; |
2086 | 130 } |
131 | |
132 /* Send the first part of our request */ | |
133 write(idata->fd, "ISON", 4); | |
134 | |
135 /* Step through our list of groups */ | |
136 while (grp) { | |
137 | |
138 g = (struct group *)grp->data; | |
139 person = g->members; | |
140 | |
141 while (person) { | |
142 b = (struct buddy *)person->data; | |
143 | |
144 /* We will store our buddy info here. I know, this is cheap | |
145 * but hey, its the exact same data structure. Why should we | |
146 * bother with making another one */ | |
147 | |
148 u = g_new0(struct irc_channel, 1); | |
149 u->id = 0; /* Assume by default that they're offline */ | |
150 u->name = strdup(b->name); | |
151 | |
152 write(idata->fd, " ", 1); | |
153 write(idata->fd, u->name, strlen(u->name)); | |
154 idata->templist = g_slist_append(idata->templist, u); | |
155 | |
156 person = person->next; | |
157 } | |
158 | |
159 grp = g_slist_next(grp); | |
160 } | |
161 write(idata->fd, "\n", 1); | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
162 return TRUE; |
2086 | 163 } |
164 | |
165 | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2100
diff
changeset
|
166 static int irc_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
2086 | 167 { |
168 | |
169 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
170 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
171 | |
172 if (who[0] == '@' || who[0] == '+') { | |
173 | |
174 /* If the user trys to msg an op or a voice from the channel, the convo will try | |
175 * to send it to @nick or +nick... needless to say, this is undesirable. | |
176 */ | |
177 who++; | |
178 } | |
179 | |
180 /* Before we actually send this, we should check to see if they're trying | |
181 * To issue a command and handle it properly. */ | |
182 | |
183 if (message[0] == '/') { | |
184 /* I'll change the implementation of this a little later :-) */ | |
185 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { | |
186 /* We have /me!! We have /me!! :-) */ | |
187 | |
188 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
189 strcpy(temp, message + 4); | |
190 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%cACTION %s%c\n", who, '\001', temp, | |
191 '\001'); | |
192 g_free(temp); | |
193 } else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { | |
194 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
195 strcpy(temp, message + 7); | |
196 irc_get_info(gc, temp); | |
197 g_free(temp); | |
198 | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2100
diff
changeset
|
199 return 0; |
2086 | 200 } |
201 | |
202 } else { | |
203 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%s\n", who, message); | |
204 } | |
205 | |
206 write(idata->fd, buf, strlen(buf)); | |
207 | |
208 g_free(buf); | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2100
diff
changeset
|
209 return 0; |
2086 | 210 } |
211 | |
212 static int find_id_by_name(struct gaim_connection *gc, char *name) | |
213 { | |
214 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
215 GList *templist; | |
216 struct irc_channel *channel; | |
217 | |
218 templist = ((struct irc_data *)gc->proto_data)->channels; | |
219 | |
220 while (templist) { | |
221 channel = (struct irc_channel *)templist->data; | |
222 | |
223 g_snprintf(temp, IRC_BUF_LEN, "#%s", channel->name); | |
224 | |
225 if (g_strcasecmp(temp, name) == 0) { | |
226 g_free(temp); | |
227 return channel->id; | |
228 } | |
229 | |
230 templist = templist->next; | |
231 } | |
232 | |
233 g_free(temp); | |
234 | |
235 /* Return -1 if we have no ID */ | |
236 return -1; | |
237 } | |
238 | |
239 static struct irc_channel *find_channel_by_name(struct gaim_connection *gc, char *name) | |
240 { | |
241 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
242 GList *templist; | |
243 struct irc_channel *channel; | |
244 | |
245 templist = ((struct irc_data *)gc->proto_data)->channels; | |
246 | |
247 while (templist) { | |
248 channel = (struct irc_channel *)templist->data; | |
249 | |
250 g_snprintf(temp, IRC_BUF_LEN, "%s", channel->name); | |
251 | |
252 if (g_strcasecmp(temp, name) == 0) { | |
253 g_free(temp); | |
254 return channel; | |
255 } | |
256 | |
257 templist = templist->next; | |
258 } | |
259 | |
260 g_free(temp); | |
261 | |
262 /* If we found nothing, return nothing :-) */ | |
263 return NULL; | |
264 } | |
265 | |
266 static struct irc_channel *find_channel_by_id(struct gaim_connection *gc, int id) | |
267 { | |
268 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
269 struct irc_channel *channel; | |
270 | |
271 GList *temp; | |
272 | |
273 temp = idata->channels; | |
274 | |
275 while (temp) { | |
276 channel = (struct irc_channel *)temp->data; | |
277 | |
278 if (channel->id == id) { | |
279 /* We've found our man */ | |
280 return channel; | |
281 } | |
282 | |
283 temp = temp->next; | |
284 } | |
285 | |
286 | |
287 /* If we didnt find one, return NULL */ | |
288 return NULL; | |
289 } | |
290 | |
291 static struct conversation *find_chat(struct gaim_connection *gc, char *name) | |
292 { | |
293 GSList *bcs = gc->buddy_chats; | |
294 struct conversation *b = NULL; | |
295 char *chat = g_strdup(normalize(name)); | |
296 | |
297 while (bcs) { | |
298 b = bcs->data; | |
299 if (!strcasecmp(normalize(b->name), chat)) | |
300 break; | |
301 b = NULL; | |
302 bcs = bcs->next; | |
303 } | |
304 | |
305 g_free(chat); | |
306 return b; | |
307 } | |
308 | |
309 static void irc_chat_leave(struct gaim_connection *gc, int id); | |
310 static void irc_chat_send(struct gaim_connection *gc, int id, char *message) | |
311 { | |
312 | |
313 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
314 struct irc_channel *channel = NULL; | |
315 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
316 char **kick; | |
317 gboolean is_command = FALSE; | |
318 /* First lets get our current channel */ | |
319 channel = find_channel_by_id(gc, id); | |
320 | |
321 | |
322 if (!channel) { | |
323 /* If for some reason we've lost our channel, let's bolt */ | |
324 g_free(buf); | |
325 return; | |
326 } | |
327 | |
328 | |
329 /* Before we actually send this, we should check to see if they're trying | |
330 * To issue a command and handle it properly. */ | |
331 | |
332 if (message[0] == '/') { | |
333 | |
334 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { | |
335 /* We have /me!! We have /me!! :-) */ | |
336 | |
337 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
338 strcpy(temp, message + 4); | |
339 | |
340 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%cACTION %s%c\n", channel->name, | |
341 '\001', temp, '\001'); | |
342 g_free(temp); | |
343 } else if ((g_strncasecmp(message, "/op ", 4) == 0) && (strlen(message) > 4)) { | |
344 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
345 strcpy(temp, message + 4); | |
346 | |
347 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +o %s\n", channel->name, temp); | |
348 | |
349 g_free(temp); | |
350 is_command = TRUE; | |
351 | |
352 } else if ((g_strncasecmp(message, "/deop ", 6) == 0) && (strlen(message) > 6)) { | |
353 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
354 strcpy(temp, message + 6); | |
355 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -o %s\n", channel->name, temp); | |
356 | |
357 g_free(temp); | |
358 is_command = TRUE; | |
359 } | |
360 | |
361 else if ((g_strncasecmp(message, "/voice ", 7) == 0) && (strlen(message) > 7)) { | |
362 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
363 strcpy(temp, message + 7); | |
364 | |
365 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +v %s\n", channel->name, temp); | |
366 | |
367 g_free(temp); | |
368 is_command = TRUE; | |
369 | |
370 } else if ((g_strncasecmp(message, "/devoice ", 9) == 0) && (strlen(message) > 9)) { | |
371 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
372 strcpy(temp, message + 6); | |
373 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -v %s\n", channel->name, temp); | |
374 | |
375 g_free(temp); | |
376 is_command = TRUE; | |
377 } else if ((g_strncasecmp(message, "/mode ", 6) == 0) && (strlen(message) > 6)) { | |
378 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
379 strcpy(temp, message + 6); | |
380 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s %s\n", channel->name, temp); | |
381 g_free(temp); | |
382 is_command = TRUE; | |
383 } | |
384 | |
385 else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { | |
386 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
387 | |
388 strcpy(temp, message + 7); | |
389 irc_get_info(gc, temp); | |
390 g_free(temp); | |
391 is_command = TRUE; | |
392 | |
393 } | |
394 | |
395 else if (!g_strncasecmp(message, "/topic ", 7) && (strlen(message) > 7)) { | |
396 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
397 strcpy(temp, message + 7); | |
398 | |
399 /* Send the chat topic change request */ | |
400 serv_chat_set_topic(gc, id, temp); | |
401 | |
402 g_free(temp); | |
403 is_command = TRUE; | |
404 } | |
405 | |
406 else if (!g_strncasecmp(message, "/part", 5) && (strlen(message) == 5)) { | |
407 | |
408 /* If I'm not mistaken, the chat_leave command was coded under the | |
409 * pretense that it would only occur when someone closed the window. | |
410 * For this reason, the /part command will not close the window. Nor | |
411 * will the window close when the user is /kicked. I'll let you decide | |
412 * the best way to fix it--I'd imagine it'd just be a little line like | |
413 * if (convo) close (convo), but I'll let you decide where to put it. | |
414 */ | |
415 | |
416 irc_chat_leave(gc, id); | |
417 is_command = TRUE; | |
418 return; | |
419 | |
420 | |
421 } | |
422 | |
423 else if (!g_strncasecmp(message, "/join ", 6) && (strlen(message) > 6)) { | |
424 | |
425 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
426 | |
427 strcpy(temp, message + 6); | |
428 | |
429 | |
430 irc_join_chat(gc, 0, temp); | |
431 g_free(temp); | |
432 is_command = TRUE; | |
433 return; | |
434 } | |
435 | |
436 else if (!g_strncasecmp(message, "/raw ", 5) && (strlen(message) > 5)) { | |
437 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
438 strcpy(temp, message + 5); | |
439 g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
440 g_free(temp); | |
441 is_command = TRUE; | |
442 } | |
443 | |
444 else if (!g_strncasecmp(message, "/quote ", 7) && (strlen(message) > 7)) { | |
445 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
446 strcpy(temp, message + 7); | |
447 g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
448 g_free(temp); | |
449 is_command = TRUE; | |
450 } | |
451 | |
452 else if (!g_strncasecmp(message, "/kick ", 6) && (strlen(message) > 6)) { | |
453 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
454 strcpy(temp, message + 6); | |
455 kick = g_strsplit(temp, " ", 2); | |
456 g_snprintf(buf, IRC_BUF_LEN, "KICK #%s %s :%s\r\n", channel->name, kick[0], | |
457 kick[1]); | |
458 g_free(temp); | |
459 is_command = TRUE; | |
460 } | |
461 | |
462 /* FIXME: I'll go back in and grab this later. -- Rob */ | |
463 /* | |
464 I THOUGHT THIS WOULD WORK, BUT I WAS WRONG. WOULD SOMEONE KINDLY FIX IT? | |
465 | |
466 | |
467 else if (!g_strncasecmp(message, "/help", 5)) { | |
468 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
469 strcpy(temp, message + 5); | |
470 if (temp == "") { | |
471 | |
472 serv_got_chat_in(gc, id, "gAIM", 0, "Available Commands:"); | |
473 serv_got_chat_in(gc, id, "gAIM", 0, " "); | |
474 serv_got_chat_in(gc, id, "gAIM", 0, "<b>op voice kick </b>"); | |
475 serv_got_chat_in(gc, id, "gAIM", 0, "<b>deop devoice whois</b>"); | |
476 serv_got_chat_in(gc, id, "gAIM", 0, "<b>me raw quote</b>"); | |
477 serv_got_chat_in(gc, id, "gAIM", 0, "<b>mode</b>"); | |
478 } | |
479 else { | |
480 serv_got_chat_in(gc, id, "gAIM", 0, "Usage: "); | |
481 if (temp == "op") | |
482 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/op <nick></b> - Gives operator status to user."); | |
483 else if (temp == "deop") | |
484 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/deop <nick></b> - Removes operator status from user."); | |
485 else if (temp == "me") | |
486 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/me <action></b> - Sends an action to the channel."); | |
487 else if (temp == "mode") | |
488 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/mode {[+|-}|o|p|s|i|t|n|b|v} [<limit][<nick>][<ban mask]</b> - Changes channel and user modes."); | |
489 else if (temp == "voice") | |
490 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/voice <nick></b> - Gives voice status to user."); | |
491 else if (temp == "devoice") | |
492 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/devoice <nick></b> - Removes voice status from user."); | |
493 else if (temp == "raw") | |
494 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
495 else if (temp == "kick") | |
496 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/kick [<comment>]</b> - Kicks a user out of the channel."); | |
497 else if (temp == "whois") | |
498 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/whois <nick></b> - Gets information about user."); | |
499 else if (temp == "quote") | |
500 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
501 else | |
502 serv_got_chat_in(gc, id, "gAIM", 0, "No such command."); | |
503 } | |
504 | |
505 g_free(temp); | |
506 is_command = TRUE; | |
507 } | |
508 */ | |
509 | |
510 } | |
511 | |
512 else { | |
513 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%s\n", channel->name, message); | |
514 | |
515 } | |
516 | |
517 | |
518 write(idata->fd, buf, strlen(buf)); | |
519 | |
520 /* Since AIM expects us to receive the message we send, we gotta fake it */ | |
521 if (is_command == FALSE) | |
522 serv_got_chat_in(gc, id, gc->username, 0, message, time((time_t) NULL)); | |
523 | |
524 g_free(buf); | |
525 | |
526 | |
527 } | |
528 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) | |
529 { | |
530 GSList *bc = gc->buddy_chats; | |
531 struct conversation *b = NULL; | |
532 | |
533 while (bc) { | |
534 b = (struct conversation *)bc->data; | |
535 if (id == b->id) { | |
536 break; | |
537 } | |
538 bc = bc->next; | |
539 b = NULL; | |
540 } | |
541 | |
542 if (!b) { | |
543 return NULL; | |
544 } | |
545 | |
546 return b; | |
547 } | |
548 | |
549 static struct conversation *find_conversation_by_name(struct gaim_connection *gc, char *name) | |
550 { | |
551 GSList *bc = gc->buddy_chats; | |
552 struct conversation *b = NULL; | |
553 | |
554 while (bc) { | |
555 b = (struct conversation *)bc->data; | |
556 | |
557 if (g_strcasecmp(name, b->name) == 0) { | |
558 break; | |
559 } | |
560 bc = bc->next; | |
561 b = NULL; | |
562 } | |
563 | |
564 if (!b) { | |
565 return NULL; | |
566 } | |
567 | |
568 return b; | |
569 } | |
570 | |
571 | |
572 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
573 static void irc_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 574 { |
575 struct gaim_connection *gc = data; | |
576 int i = 0; | |
577 gchar buf[4096]; | |
578 gchar **buf2; | |
579 struct irc_data *idata; | |
580 | |
581 idata = (struct irc_data *)gc->proto_data; | |
582 | |
583 | |
584 do { | |
585 if (read(idata->fd, buf + i, 1) < 0) { | |
586 hide_login_progress(gc, "Read error"); | |
587 signoff(gc); | |
588 return; | |
589 } | |
590 } while (buf[i++] != '\n'); | |
591 | |
592 buf[--i] = '\0'; | |
593 g_strchomp(buf); | |
594 g_print("%s\n", buf); | |
595 | |
596 /* Check for errors */ | |
597 | |
598 if (((strstr(buf, "ERROR :") && (!strstr(buf, "PRIVMSG ")) && | |
599 (!strstr(buf, "NOTICE ")) && (strlen(buf) > 7)))) { | |
600 | |
601 gchar *u_errormsg; | |
602 | |
603 /* Let's get our error message */ | |
604 u_errormsg = g_strdup(buf + 7); | |
605 | |
606 /* We got our error message. Now, let's reaise an | |
607 * error dialog */ | |
608 | |
609 do_error_dialog(u_errormsg, "Gaim: IRC Error"); | |
610 | |
611 /* And our necessary garbage collection */ | |
612 g_free(u_errormsg); | |
613 return; | |
614 } | |
615 | |
616 /* This should be a whois response. I only care about the first (311) one. I might do | |
617 * the other's later. They're boring. */ | |
618 | |
619 if (((strstr(buf, " 311 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
620 char **res; | |
621 | |
622 res = g_strsplit(buf, " ", 7); | |
623 | |
624 if (!strcmp(res[1], "311")) { | |
625 char buf[8192]; | |
626 | |
627 g_snprintf(buf, 4096, "<b>Nick:</b> %s<br>" | |
628 "<b>Host:</b> %s@%s<br>" | |
629 "<b>Name:</b> %s<br>", res[3], res[4], res[5], res[7] + 1); | |
630 | |
631 g_show_info_text(buf); | |
632 } | |
633 | |
634 g_strfreev(res); | |
635 return; | |
636 } | |
637 | |
638 /* Autoresponse to an away message */ | |
639 if (((strstr(buf, " 301 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
640 char **res; | |
641 | |
642 res = g_strsplit(buf, " ", 5); | |
643 | |
644 if (!strcmp(res[1], "301")) | |
645 serv_got_im(gc, res[3], res[4] + 1, 1, time((time_t) NULL)); | |
646 | |
647 g_strfreev(res); | |
648 return; | |
649 } | |
650 | |
651 /* Parse the list of names that we receive when we first sign on to | |
652 * a channel */ | |
653 | |
654 if (((strstr(buf, " 353 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
655 gchar u_host[255]; | |
656 gchar u_command[32]; | |
657 gchar u_channel[128]; | |
658 gchar u_names[IRC_BUF_LEN + 1]; | |
659 struct conversation *convo = NULL; | |
660 int j; | |
661 | |
662 for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
663 u_host[j] = buf[i]; | |
664 } | |
665 | |
666 u_host[j] = '\0'; | |
667 i++; | |
668 | |
669 for (j = 0; buf[i] != ' '; j++, i++) { | |
670 u_command[j] = buf[i]; | |
671 } | |
672 | |
673 u_command[j] = '\0'; | |
674 i++; | |
675 | |
676 for (j = 0; buf[i] != '#'; j++, i++) { | |
677 } | |
678 i++; | |
679 | |
680 for (j = 0; buf[i] != ':'; j++, i++) { | |
681 u_channel[j] = buf[i]; | |
682 } | |
683 | |
684 u_channel[j - 1] = '\0'; | |
685 i++; | |
686 | |
687 while ((buf[i] == ' ') || (buf[i] == ':')) { | |
688 i++; | |
689 } | |
690 | |
691 strcpy(u_names, buf + i); | |
692 | |
693 buf2 = g_strsplit(u_names, " ", 0); | |
694 | |
695 /* Let's get our conversation window */ | |
696 convo = find_conversation_by_name(gc, u_channel); | |
697 | |
698 if (!convo) { | |
699 return; | |
700 } | |
701 | |
702 /* Now that we've parsed the hell out of this big | |
703 * mess, let's try to split up the names properly */ | |
704 | |
705 for (i = 0; buf2[i] != NULL; i++) | |
706 add_chat_buddy(convo, buf2[i]); | |
707 | |
708 /* And free our pointers */ | |
709 g_strfreev(buf2); | |
710 | |
711 return; | |
712 | |
713 } | |
714 | |
715 /* Receive a list of users that are currently online */ | |
716 | |
717 if (((strstr(buf, " 303 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
718 gchar u_host[255]; | |
719 gchar u_command[32]; | |
720 gchar u_names[IRC_BUF_LEN + 1]; | |
721 int j; | |
722 | |
723 for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
724 u_host[j] = buf[i]; | |
725 } | |
726 | |
727 u_host[j] = '\0'; | |
728 i++; | |
729 | |
730 for (j = 0; buf[i] != ' '; j++, i++) { | |
731 u_command[j] = buf[i]; | |
732 } | |
733 | |
734 u_command[j] = '\0'; | |
735 i++; | |
736 | |
737 for (j = 0; buf[i] != ':'; j++, i++) { | |
738 /* My Nick */ | |
739 } | |
740 i++; | |
741 | |
742 strcpy(u_names, buf + i); | |
743 | |
744 buf2 = g_strsplit(u_names, " ", 0); | |
745 | |
746 /* Now that we've parsed the hell out of this big | |
747 * mess, let's try to split up the names properly */ | |
748 | |
749 for (i = 0; buf2[i] != NULL; i++) { | |
750 /* If we have a name here then our buddy is online. We should | |
751 * update our temporary gslist accordingly. When we achieve our maximum | |
752 * list of names then we should force an update */ | |
753 | |
754 irc_update_user(gc, buf2[i], 1); | |
755 } | |
756 | |
757 /* Increase our received blocks counter */ | |
758 idata->recblocks++; | |
759 | |
760 /* If we have our total number of blocks */ | |
761 if (idata->recblocks == idata->totalblocks) { | |
762 GSList *temp; | |
763 struct irc_channel *u; | |
764 | |
765 /* Let's grab our list of people and bring them all on or off line */ | |
766 temp = idata->templist; | |
767 | |
768 /* Loop */ | |
769 while (temp) { | |
770 | |
771 u = temp->data; | |
772 | |
773 /* Tell Gaim to bring the person on or off line */ | |
774 serv_got_update(gc, u->name, u->id, 0, 0, 0, 0, 0); | |
775 | |
776 /* Grab the next entry */ | |
777 temp = g_slist_next(temp); | |
778 } | |
779 | |
780 /* And now, let's delete all of our entries */ | |
781 temp = idata->templist; | |
782 while (temp) { | |
783 u = temp->data; | |
784 g_free(u->name); | |
785 temp = g_slist_remove(temp, u); | |
786 } | |
787 | |
788 /* Reset our list */ | |
789 idata->totalblocks = 0; | |
790 idata->recblocks = 0; | |
791 | |
792 idata->templist = NULL; | |
793 | |
794 return; | |
795 } | |
796 | |
797 /* And free our pointers */ | |
798 g_strfreev(buf2); | |
799 | |
800 return; | |
801 | |
802 } | |
803 | |
804 | |
805 if ((strstr(buf, " MODE ")) && (strstr(buf, "!")) | |
806 && (strstr(buf, "+v") || strstr(buf, "-v") || strstr(buf, "-o") || strstr(buf, "+o")) | |
807 && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { | |
808 | |
809 gchar u_channel[128]; | |
810 gchar u_nick[128]; | |
811 | |
812 gchar u_mode[5]; | |
813 char **people; | |
814 gchar *temp, *temp_new; | |
815 | |
816 | |
817 struct irc_channel *channel; | |
818 int j; | |
819 temp = NULL; | |
820 temp_new = NULL; | |
821 | |
822 | |
823 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
824 u_nick[j] = buf[i]; | |
825 } | |
826 u_nick[j] = '\0'; | |
827 i++; | |
828 | |
829 for (j = 0; buf[i] != '#'; j++, i++) { | |
830 } | |
831 i++; | |
832 | |
833 for (j = 0; buf[i] != ' '; j++, i++) { | |
834 u_channel[j] = buf[i]; | |
835 } | |
836 | |
837 u_channel[j] = '\0'; | |
838 i++; | |
839 | |
840 for (j = 0; buf[i] != ' '; j++, i++) { | |
841 u_mode[j] = buf[i]; | |
842 } | |
843 u_mode[j] = '\0'; | |
844 i++; | |
845 | |
846 | |
847 | |
848 | |
849 people = g_strsplit(buf + i, " ", 3); | |
850 | |
851 | |
852 | |
853 channel = find_channel_by_name(gc, u_channel); | |
854 | |
855 if (!channel) { | |
856 return; | |
857 } | |
858 | |
859 for (j = 0; j < strlen(u_mode) - 1; j++) { | |
860 | |
861 | |
862 struct conversation *convo = NULL; | |
863 convo = find_conversation_by_id(gc, channel->id); | |
864 | |
865 | |
866 | |
867 temp = (gchar *) g_malloc(strlen(people[j]) + 3); | |
868 temp_new = (gchar *) g_malloc(strlen(people[j]) + 3); | |
869 g_snprintf(temp, strlen(people[j]) + 2, "@%s", people[j]); | |
870 | |
871 if (u_mode[1] == 'v' && u_mode[0] == '+') { | |
872 g_snprintf(temp_new, strlen(people[j]) + 2, "+%s", people[j]); | |
873 } else if (u_mode[1] == 'o' && u_mode[0] == '+') { | |
874 g_snprintf(temp_new, strlen(people[j]) + 2, "@%s", people[j]); | |
875 } | |
876 | |
877 else if (u_mode[0] == '-') { | |
878 g_snprintf(temp_new, strlen(people[j]) + 1, "%s", people[j]); | |
879 } | |
880 | |
881 | |
882 | |
883 rename_chat_buddy(convo, temp, temp_new); | |
884 g_snprintf(temp, strlen(people[j]) + 2, "+%s", people[j]); | |
885 rename_chat_buddy(convo, temp, temp_new); | |
886 | |
887 rename_chat_buddy(convo, people[j], temp_new); | |
888 | |
889 | |
890 | |
891 | |
892 | |
893 } | |
894 if (temp) | |
895 g_free(temp); | |
896 if (temp_new) | |
897 g_free(temp_new); | |
898 | |
899 return; | |
900 } | |
901 | |
902 | |
903 if ((strstr(buf, " KICK ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
904 && (!strstr(buf, " NOTICE "))) { | |
905 gchar u_channel[128]; | |
906 gchar u_nick[128]; | |
907 gchar u_comment[128]; | |
908 gchar u_who[128]; | |
909 | |
910 int id; | |
911 | |
912 gchar *temp; | |
913 | |
914 | |
915 | |
916 struct irc_channel *channel; | |
917 int j; | |
918 | |
919 temp = NULL; | |
920 | |
921 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
922 u_nick[j] = buf[i]; | |
923 } | |
924 u_nick[j] = '\0'; | |
925 i++; | |
926 | |
927 for (j = 0; buf[i] != '#'; j++, i++) { | |
928 } | |
929 i++; | |
930 | |
931 for (j = 0; buf[i] != ' '; j++, i++) { | |
932 u_channel[j] = buf[i]; | |
933 } | |
934 | |
935 u_channel[j] = '\0'; | |
936 i++; | |
937 | |
938 for (j = 0; buf[i] != ' '; j++, i++) { | |
939 u_who[j] = buf[i]; | |
940 } | |
941 u_who[j] = '\0'; | |
942 i++; | |
943 i++; | |
944 strcpy(u_comment, buf + i); | |
945 g_strchomp(u_comment); | |
946 | |
947 channel = find_channel_by_name(gc, u_channel); | |
948 | |
949 if (!channel) { | |
950 return; | |
951 } | |
952 | |
953 | |
954 id = find_id_by_name(gc, u_channel); | |
955 | |
956 | |
957 if (g_strcasecmp(u_nick, gc->username) == 0) { | |
958 | |
959 /* It looks like you've been naughty! */ | |
960 | |
961 serv_got_chat_left(gc, channel->id); | |
962 | |
963 idata->channels = g_list_remove(idata->channels, channel); | |
964 } else { | |
965 struct conversation *convo = NULL; | |
966 | |
967 /* Find their conversation window */ | |
968 convo = find_conversation_by_id(gc, channel->id); | |
969 | |
970 if (!convo) { | |
971 /* Some how the window doesn't exist. | |
972 * Let's get out of here */ | |
973 return; | |
974 } | |
975 | |
976 /* And remove their name */ | |
977 /* If the person is an op or voice, this won't work. | |
978 * so we'll just do a nice hack and remove nick and | |
979 * @nick and +nick. Truly wasteful. | |
980 */ | |
981 | |
982 temp = (gchar *) g_malloc(strlen(u_who) + 3); | |
983 g_snprintf(temp, strlen(u_who) + 2, "@%s", u_who); | |
984 remove_chat_buddy(convo, temp); | |
985 g_free(temp); | |
986 temp = (gchar *) g_malloc(strlen(u_who) + 3); | |
987 g_snprintf(temp, strlen(u_who) + 2, "+%s", u_who); | |
988 remove_chat_buddy(convo, temp); | |
989 remove_chat_buddy(convo, u_who); | |
990 | |
991 g_free(temp); | |
992 | |
993 } | |
994 | |
995 /* Go Home! */ | |
996 return; | |
997 } | |
998 | |
999 if ((strstr(buf, " TOPIC ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { | |
1000 | |
1001 gchar u_channel[128]; | |
1002 gchar u_nick[128]; | |
1003 gchar u_topic[128]; | |
1004 int j; | |
1005 struct conversation *chatroom = NULL; | |
1006 | |
1007 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1008 u_nick[j] = buf[i]; | |
1009 } | |
1010 u_nick[j] = 0; | |
1011 i++; | |
1012 | |
1013 for (j = 0; buf[i] != '#'; j++, i++) { | |
1014 } | |
1015 i++; | |
1016 | |
1017 for (j = 0; buf[i] != ' '; j++, i++) { | |
1018 if (buf[i] == '\0') | |
1019 break; | |
1020 | |
1021 u_channel[j] = buf[i]; | |
1022 } | |
1023 | |
1024 for (j = 0; buf[i] != ':'; j++, i++) { | |
1025 } | |
1026 i++; | |
1027 | |
1028 strcpy(u_topic, buf + i); | |
1029 g_strchomp(u_topic); | |
1030 | |
1031 chatroom = find_chat(gc, u_channel); | |
1032 | |
1033 if (!chatroom) | |
1034 return; | |
1035 | |
1036 chat_set_topic(chatroom, u_nick, u_topic); | |
1037 | |
1038 return; | |
1039 } | |
1040 | |
1041 | |
1042 if ((strstr(buf, " JOIN ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
1043 && (!strstr(buf, " NOTICE "))) { | |
1044 | |
1045 gchar u_channel[128]; | |
1046 gchar u_nick[128]; | |
1047 | |
1048 struct irc_channel *channel; | |
1049 int j; | |
1050 | |
1051 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1052 u_nick[j] = buf[i]; | |
1053 } | |
1054 | |
1055 u_nick[j] = '\0'; | |
1056 i++; | |
1057 | |
1058 for (j = 0; buf[i] != '#'; j++, i++) { | |
1059 } | |
1060 | |
1061 i++; | |
1062 | |
1063 strcpy(u_channel, buf + i); | |
1064 | |
1065 g_strchomp(u_channel); | |
1066 | |
1067 /* Looks like we're going to join the channel for real | |
1068 * now. Let's create a valid channel structure and add | |
1069 * it to our list. Let's make sure that | |
1070 * we are not already in a channel first */ | |
1071 | |
1072 channel = find_channel_by_name(gc, u_channel); | |
1073 | |
1074 if (!channel) { | |
1075 | |
1076 chat_id++; | |
1077 | |
1078 channel = g_new0(struct irc_channel, 1); | |
1079 | |
1080 channel->id = chat_id; | |
1081 channel->name = strdup(u_channel); | |
1082 | |
1083 idata->channels = g_list_append(idata->channels, channel); | |
1084 | |
1085 serv_got_joined_chat(gc, chat_id, u_channel); | |
1086 } else { | |
1087 struct conversation *convo = NULL; | |
1088 | |
1089 /* Someone else joined. Find their conversation | |
1090 * window */ | |
1091 convo = find_conversation_by_id(gc, channel->id); | |
1092 | |
1093 /* And add their name to it */ | |
1094 add_chat_buddy(convo, u_nick); | |
1095 | |
1096 } | |
1097 | |
1098 return; | |
1099 } | |
1100 | |
1101 if ((strstr(buf, " NICK ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
1102 && (!strstr(buf, " NOTICE "))) { | |
1103 | |
1104 gchar old[128]; | |
1105 gchar new[128]; | |
1106 | |
1107 GList *templist; | |
1108 gchar *temp, *temp_new; | |
1109 struct irc_channel *channel; | |
1110 int j; | |
1111 temp = temp_new = NULL; | |
1112 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1113 old[j] = buf[i]; | |
1114 } | |
1115 | |
1116 old[j] = '\0'; | |
1117 i++; | |
1118 | |
1119 for (j = 0; buf[i] != ':'; j++, i++) { | |
1120 } | |
1121 | |
1122 i++; | |
1123 strcpy(new, buf + i); | |
1124 | |
1125 g_strchomp(new); | |
1126 | |
1127 templist = ((struct irc_data *)gc->proto_data)->channels; | |
1128 | |
1129 while (templist) { | |
1130 struct conversation *convo = NULL; | |
1131 channel = templist->data; | |
1132 | |
1133 convo = find_conversation_by_id(gc, channel->id); | |
1134 | |
1135 /* If the person is an op or voice, this won't work. | |
1136 * so we'll just do a nice hack and rename nick and | |
1137 * @nick and +nick. Truly wasteful. | |
1138 */ | |
1139 | |
1140 temp = (gchar *) g_malloc(strlen(old) + 5); | |
1141 temp_new = (gchar *) g_malloc(strlen(new) + 5); | |
1142 g_snprintf(temp_new, strlen(new) + 2, "@%s", new); | |
1143 g_snprintf(temp, strlen(old) + 2, "@%s", old); | |
1144 rename_chat_buddy(convo, temp, temp_new); | |
1145 g_snprintf(temp, strlen(old) + 2, "+%s", old); | |
1146 g_snprintf(temp_new, strlen(new) + 2, "+%s", new); | |
1147 rename_chat_buddy(convo, temp, temp_new); | |
1148 rename_chat_buddy(convo, old, new); | |
1149 if (temp) | |
1150 g_free(temp); | |
1151 if (temp_new) | |
1152 g_free(temp_new); | |
1153 | |
1154 templist = templist->next; | |
1155 } | |
1156 return; | |
1157 } | |
1158 | |
1159 | |
1160 if ((strstr(buf, "QUIT ")) && (buf[0] == ':') && (strstr(buf, "!")) | |
1161 && (!strstr(buf, " NOTICE "))) { | |
1162 | |
1163 gchar u_nick[128]; | |
1164 gchar *temp; | |
1165 GList *templist; | |
1166 | |
1167 struct irc_channel *channel; | |
1168 int j; | |
1169 | |
1170 | |
1171 temp = NULL; | |
1172 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1173 u_nick[j] = buf[i]; | |
1174 } | |
1175 | |
1176 u_nick[j] = '\0'; | |
1177 | |
1178 templist = ((struct irc_data *)gc->proto_data)->channels; | |
1179 | |
1180 while (templist) { | |
1181 struct conversation *convo = NULL; | |
1182 channel = templist->data; | |
1183 | |
1184 convo = find_conversation_by_id(gc, channel->id); | |
1185 | |
1186 /* If the person is an op or voice, this won't work. | |
1187 * so we'll just do a nice hack and remove nick and | |
1188 * @nick and +nick. Truly wasteful. | |
1189 */ | |
1190 | |
1191 temp = (gchar *) g_malloc(strlen(u_nick) + 2); | |
1192 g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); | |
1193 remove_chat_buddy(convo, temp); | |
1194 g_free(temp); | |
1195 temp = (gchar *) g_malloc(strlen(u_nick) + 2); | |
1196 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); | |
1197 remove_chat_buddy(convo, temp); | |
1198 remove_chat_buddy(convo, u_nick); | |
1199 | |
1200 | |
1201 | |
1202 templist = templist->next; | |
1203 } | |
1204 | |
1205 g_free(temp); | |
1206 | |
1207 return; | |
1208 } | |
1209 | |
1210 | |
1211 | |
1212 if ((strstr(buf, " PART ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
1213 && (!strstr(buf, " NOTICE "))) { | |
1214 | |
1215 gchar u_channel[128]; | |
1216 gchar u_nick[128]; | |
1217 gchar *temp; | |
1218 struct irc_channel *channel; | |
1219 int j; | |
1220 temp = NULL; | |
1221 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1222 u_nick[j] = buf[i]; | |
1223 } | |
1224 u_nick[j] = '\0'; | |
1225 | |
1226 i++; | |
1227 | |
1228 for (j = 0; buf[i] != '#'; j++, i++) { | |
1229 } | |
1230 | |
1231 i++; | |
1232 | |
1233 for (j = 0; buf[i] != ' '; j++, i++) { | |
1234 if (buf[i] == '\0') { | |
1235 break; | |
1236 } | |
1237 u_channel[j] = buf[i]; | |
1238 } | |
1239 u_channel[j] = '\0'; | |
1240 | |
1241 /* Now, lets check to see if it was US that was leaving. | |
1242 * If so, do the correct thing by closing up all of our | |
1243 * old channel stuff. Otherwise, | |
1244 * we should just print that someone left */ | |
1245 | |
1246 channel = find_channel_by_name(gc, u_channel); | |
1247 | |
1248 if (!channel) { | |
1249 return; | |
1250 } | |
1251 | |
1252 if (g_strcasecmp(u_nick, gc->username) == 0) { | |
1253 | |
1254 /* Looks like we're going to leave the channel for | |
1255 * real now. Let's create a valid channel structure | |
1256 * and add it to our list */ | |
1257 | |
1258 serv_got_chat_left(gc, channel->id); | |
1259 | |
1260 idata->channels = g_list_remove(idata->channels, channel); | |
1261 } else { | |
1262 struct conversation *convo = NULL; | |
1263 | |
1264 /* Find their conversation window */ | |
1265 convo = find_conversation_by_id(gc, channel->id); | |
1266 | |
1267 if (!convo) { | |
1268 /* Some how the window doesn't exist. | |
1269 * Let's get out of here */ | |
1270 return; | |
1271 } | |
1272 | |
1273 /* And remove their name */ | |
1274 /* If the person is an op or voice, this won't work. | |
1275 * so we'll just do a nice hack and remove nick and | |
1276 * @nick and +nick. Truly wasteful. | |
1277 */ | |
1278 | |
1279 temp = (gchar *) g_malloc(strlen(u_nick) + 3); | |
1280 g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); | |
1281 remove_chat_buddy(convo, temp); | |
1282 g_free(temp); | |
1283 temp = (gchar *) g_malloc(strlen(u_nick) + 3); | |
1284 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); | |
1285 remove_chat_buddy(convo, temp); | |
1286 g_free(temp); | |
1287 remove_chat_buddy(convo, u_nick); | |
1288 | |
1289 | |
1290 } | |
1291 | |
1292 /* Go Home! */ | |
1293 return; | |
1294 } | |
1295 | |
1296 if ((strstr(buf, " NOTICE ")) && (buf[0] == ':')) { | |
1297 gchar u_nick[128]; | |
1298 gchar u_host[255]; | |
1299 gchar u_command[32]; | |
1300 gchar u_channel[128]; | |
1301 gchar u_message[IRC_BUF_LEN]; | |
1302 int j; | |
1303 | |
1304 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1305 u_nick[j] = buf[i]; | |
1306 } | |
1307 | |
1308 u_nick[j] = '\0'; | |
1309 i++; | |
1310 | |
1311 for (j = 0; buf[i] != ' '; j++, i++) { | |
1312 u_host[j] = buf[i]; | |
1313 } | |
1314 | |
1315 u_host[j] = '\0'; | |
1316 i++; | |
1317 | |
1318 for (j = 0; buf[i] != ' '; j++, i++) { | |
1319 u_command[j] = buf[i]; | |
1320 } | |
1321 | |
1322 u_command[j] = '\0'; | |
1323 i++; | |
1324 | |
1325 for (j = 0; buf[i] != ':'; j++, i++) { | |
1326 u_channel[j] = buf[i]; | |
1327 } | |
1328 | |
1329 u_channel[j - 1] = '\0'; | |
1330 i++; | |
1331 | |
1332 | |
1333 /* Now that everything is parsed, the rest of this baby must be our message */ | |
1334 strncpy(u_message, buf + i, IRC_BUF_LEN); | |
1335 | |
1336 /* Now, lets check the message to see if there's anything special in it */ | |
1337 if (u_message[0] == '\001') { | |
1338 if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { | |
1339 /* Someone's triyng to ping us. Let's respond */ | |
1340 gchar u_arg[24]; | |
1341 gchar u_buf[200]; | |
1342 unsigned long tend = time((time_t *) NULL); | |
1343 unsigned long tstart; | |
1344 | |
1345 printf("LA: %s\n", buf); | |
1346 | |
1347 strcpy(u_arg, u_message + 6); | |
1348 u_arg[strlen(u_arg) - 1] = '\0'; | |
1349 | |
1350 tstart = atol(u_arg); | |
1351 | |
1352 g_snprintf(u_buf, sizeof(u_buf), "Ping Reply From %s: [%ld seconds]", | |
1353 u_nick, tend - tstart); | |
1354 | |
1355 do_error_dialog(u_buf, "Gaim IRC - Ping Reply"); | |
1356 | |
1357 return; | |
1358 } | |
1359 } | |
1360 | |
1361 } | |
1362 | |
1363 | |
1364 if ((strstr(buf, " PRIVMSG ")) && (buf[0] == ':')) { | |
1365 gchar u_nick[128]; | |
1366 gchar u_host[255]; | |
1367 gchar u_command[32]; | |
1368 gchar u_channel[128]; | |
1369 gchar u_message[IRC_BUF_LEN]; | |
1370 gboolean is_closing; | |
1371 | |
1372 int j; | |
1373 | |
1374 | |
1375 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1376 u_nick[j] = buf[i]; | |
1377 } | |
1378 | |
1379 u_nick[j] = '\0'; | |
1380 i++; | |
1381 | |
1382 for (j = 0; buf[i] != ' '; j++, i++) { | |
1383 u_host[j] = buf[i]; | |
1384 } | |
1385 | |
1386 u_host[j] = '\0'; | |
1387 i++; | |
1388 | |
1389 for (j = 0; buf[i] != ' '; j++, i++) { | |
1390 u_command[j] = buf[i]; | |
1391 } | |
1392 | |
1393 u_command[j] = '\0'; | |
1394 i++; | |
1395 | |
1396 for (j = 0; buf[i] != ':'; j++, i++) { | |
1397 u_channel[j] = buf[i]; | |
1398 } | |
1399 | |
1400 u_channel[j - 1] = '\0'; | |
1401 i++; | |
1402 | |
1403 | |
1404 /* Now that everything is parsed, the rest of this baby must be our message */ | |
1405 strncpy(u_message, buf + i, IRC_BUF_LEN); | |
1406 | |
1407 /* Now, lets check the message to see if there's anything special in it */ | |
1408 if (u_message[0] == '\001') { | |
1409 if (g_strncasecmp(u_message, "\001VERSION", 8) == 0) { | |
1410 /* Looks like we have a version request. Let | |
1411 * us handle it thusly */ | |
1412 | |
1413 g_snprintf(buf, IRC_BUF_LEN, | |
1414 "NOTICE %s :%cVERSION GAIM %s:The Pimpin Penguin AIM Clone:%s%c\n", | |
1415 u_nick, '\001', VERSION, WEBSITE, '\001'); | |
1416 | |
1417 write(idata->fd, buf, strlen(buf)); | |
1418 | |
1419 /* And get the heck out of dodge */ | |
1420 return; | |
1421 } | |
1422 | |
1423 if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { | |
1424 /* Someone's triyng to ping us. Let's respond */ | |
1425 gchar u_arg[24]; | |
1426 | |
1427 strcpy(u_arg, u_message + 6); | |
1428 u_arg[strlen(u_arg) - 1] = '\0'; | |
1429 | |
1430 g_snprintf(buf, IRC_BUF_LEN, "NOTICE %s :%cPING %s%c\n", u_nick, '\001', | |
1431 u_arg, '\001'); | |
1432 | |
1433 write(idata->fd, buf, strlen(buf)); | |
1434 | |
1435 /* And get the heck out of dodge */ | |
1436 return; | |
1437 } | |
1438 | |
1439 if (g_strncasecmp(u_message, "\001ACTION ", 8) == 0) { | |
1440 /* Looks like we have an action. Let's parse it a little */ | |
1441 strcpy(buf, u_message); | |
1442 | |
1443 strcpy(u_message, "/me "); | |
1444 for (j = 4, i = 8; buf[i] != '\001'; i++, j++) { | |
1445 u_message[j] = buf[i]; | |
1446 } | |
1447 u_message[j] = '\0'; | |
1448 } | |
1449 } | |
1450 | |
1451 | |
1452 /* OK, It is a chat or IM message. Here, let's translate the IRC formatting into | |
1453 * good ol' fashioned gtkimhtml style hypertext markup. */ | |
1454 | |
1455 | |
1456 is_closing = FALSE; | |
1457 | |
1458 while (strchr(u_message, '\002')) { /* \002 = ^B */ | |
1459 gchar *current; | |
1460 gchar *temp, *free_here; | |
1461 | |
1462 | |
1463 temp = g_strdup(strchr(u_message, '\002')); | |
1464 free_here = temp; | |
1465 temp++; | |
1466 | |
1467 current = strchr(u_message, '\002'); | |
1468 *current = '<'; | |
1469 current++; | |
1470 if (is_closing) { | |
1471 *current = '/'; | |
1472 current++; | |
1473 } | |
1474 *current = 'b'; | |
1475 current++; | |
1476 *current = '>'; | |
1477 current++; | |
1478 | |
1479 | |
1480 while (*temp != '\0') { | |
1481 *current = *temp; | |
1482 current++; | |
1483 temp++; | |
1484 } | |
1485 *current = '\0'; | |
1486 g_free(free_here); | |
1487 | |
1488 is_closing = !is_closing; | |
1489 } | |
1490 | |
1491 is_closing = FALSE; | |
1492 while (strchr(u_message, '\037')) { /* \037 = ^_ */ | |
1493 gchar *current; | |
1494 gchar *temp, *free_here; | |
1495 | |
1496 | |
1497 temp = g_strdup(strchr(u_message, '\037')); | |
1498 free_here = temp; | |
1499 temp++; | |
1500 | |
1501 current = strchr(u_message, '\037'); | |
1502 *current = '<'; | |
1503 current++; | |
1504 if (is_closing) { | |
1505 *current = '/'; | |
1506 current++; | |
1507 } | |
1508 *current = 'u'; | |
1509 current++; | |
1510 *current = '>'; | |
1511 current++; | |
1512 | |
1513 | |
1514 while (*temp != '\0') { | |
1515 *current = *temp; | |
1516 current++; | |
1517 temp++; | |
1518 } | |
1519 *current = '\0'; | |
1520 g_free(free_here); | |
1521 is_closing = !is_closing; | |
1522 | |
1523 } | |
1524 | |
1525 while (strchr(u_message, '\003')) { /* \003 = ^C */ | |
1526 | |
1527 /* This is color formatting. IRC uses its own weird little system | |
1528 * that we must translate to HTML. */ | |
1529 | |
1530 | |
1531 /* The format is something like this: | |
1532 * ^C5 or ^C5,3 | |
1533 * The number before the comma is the foreground color, after is the | |
1534 * background color. Either number can be 1 or two digits. | |
1535 */ | |
1536 | |
1537 gchar *current; | |
1538 gchar *temp, *free_here; | |
1539 gchar *font_tag, *body_tag; | |
1540 int fg_color, bg_color; | |
1541 | |
1542 temp = g_strdup(strchr(u_message, '\003')); | |
1543 free_here = temp; | |
1544 temp++; | |
1545 | |
1546 fg_color = bg_color = -1; | |
1547 body_tag = font_tag = ""; | |
1548 | |
1549 /* Parsing the color information: */ | |
1550 do { | |
1551 if (!isdigit(*temp)) | |
1552 break; /* This translates to </font> */ | |
1553 fg_color = (int)(*temp - 48); | |
1554 temp++; | |
1555 if (isdigit(*temp)) { | |
1556 fg_color = (fg_color * 10) + (int)(*temp - 48); | |
1557 temp++; | |
1558 } | |
1559 if (*temp != ',') | |
1560 break; | |
1561 temp++; | |
1562 if (!isdigit(*temp)) | |
1563 break; /* This translates to </font> */ | |
1564 bg_color = (int)(*temp - 48); | |
1565 temp++; | |
1566 if (isdigit(*temp)) { | |
1567 bg_color = (bg_color * 10) + (int)(*temp - 48); | |
1568 temp++; | |
1569 } | |
1570 } while (FALSE); | |
1571 | |
1572 if (fg_color > 15) | |
1573 fg_color = fg_color % 16; | |
1574 if (bg_color > 15) | |
1575 bg_color = bg_color % 16; | |
1576 | |
1577 switch (fg_color) { | |
1578 case -1: | |
1579 font_tag = "</font></body>"; | |
1580 break; | |
1581 case 0: /* WHITE */ | |
1582 font_tag = "<font color=\"#ffffff\">"; | |
1583 /* If no background color is specified, we're going to make it black anyway. | |
1584 * That's probably what the sender anticipated the background color to be. | |
1585 * White on white would be illegible. | |
1586 */ | |
1587 if (bg_color == -1) { | |
1588 body_tag = "<body bgcolor=\"#000000\">"; | |
1589 } | |
1590 break; | |
1591 case 1: /* BLACK */ | |
1592 font_tag = "<font color=\"#000000\">"; | |
1593 break; | |
1594 case 2: /* NAVY BLUE */ | |
1595 font_tag = "<font color=\"#000066\">"; | |
1596 break; | |
1597 case 3: /* GREEN */ | |
1598 font_tag = "<font color=\"#006600\">"; | |
1599 break; | |
1600 case 4: /* RED */ | |
1601 font_tag = "<font color=\"#ff0000\">"; | |
1602 break; | |
1603 case 5: /* MAROON */ | |
1604 font_tag = "<font color=\"#660000\">"; | |
1605 break; | |
1606 case 6: /* PURPLE */ | |
1607 font_tag = "<font color=\"#660066\">"; | |
1608 break; | |
1609 case 7: /* DISGUSTING PUKE COLOR */ | |
1610 font_tag = "<font color=\"#666600\">"; | |
1611 break; | |
1612 case 8: /* YELLOW */ | |
1613 font_tag = "<font color=\"#cccc00\">"; | |
1614 break; | |
1615 case 9: /* LIGHT GREEN */ | |
1616 font_tag = "<font color=\"#33cc33\">"; | |
1617 break; | |
1618 case 10: /* TEAL */ | |
1619 font_tag = "<font color=\"#00acac\">"; | |
1620 break; | |
1621 case 11: /* CYAN */ | |
1622 font_tag = "<font color=\"#00ccac\">"; | |
1623 break; | |
1624 case 12: /* BLUE */ | |
1625 font_tag = "<font color=\"#0000ff\">"; | |
1626 break; | |
1627 case 13: /* PINK */ | |
1628 font_tag = "<font color=\"#cc00cc\">"; | |
1629 break; | |
1630 case 14: /* GREY */ | |
1631 font_tag = "<font color=\"#666666\">"; | |
1632 break; | |
1633 case 15: /* SILVER */ | |
1634 font_tag = "<font color=\"#00ccac\">"; | |
1635 break; | |
1636 } | |
1637 | |
1638 switch (bg_color) { | |
1639 case 0: /* WHITE */ | |
1640 body_tag = "<body bgcolor=\"#ffffff\">"; | |
1641 break; | |
1642 case 1: /* BLACK */ | |
1643 body_tag = "<body bgcolor=\"#000000\">"; | |
1644 break; | |
1645 case 2: /* NAVY BLUE */ | |
1646 body_tag = "<body bgcolor=\"#000066\">"; | |
1647 break; | |
1648 case 3: /* GREEN */ | |
1649 body_tag = "<body bgcolor=\"#006600\">"; | |
1650 break; | |
1651 case 4: /* RED */ | |
1652 body_tag = "<body bgcolor=\"#ff0000\">"; | |
1653 break; | |
1654 case 5: /* MAROON */ | |
1655 body_tag = "<body bgcolor=\"#660000\">"; | |
1656 break; | |
1657 case 6: /* PURPLE */ | |
1658 body_tag = "<body bgcolor=\"#660066\">"; | |
1659 break; | |
1660 case 7: /* DISGUSTING PUKE COLOR */ | |
1661 body_tag = "<body bgcolor=\"#666600\">"; | |
1662 break; | |
1663 case 8: /* YELLOW */ | |
1664 body_tag = "<body bgcolor=\"#cccc00\">"; | |
1665 break; | |
1666 case 9: /* LIGHT GREEN */ | |
1667 body_tag = "<body bgcolor=\"#33cc33\">"; | |
1668 break; | |
1669 case 10: /* TEAL */ | |
1670 body_tag = "<body bgcolor=\"#00acac\">"; | |
1671 break; | |
1672 case 11: /* CYAN */ | |
1673 body_tag = "<body bgcolor=\"#00ccac\">"; | |
1674 break; | |
1675 case 12: /* BLUE */ | |
1676 body_tag = "<body bgcolor=\"#0000ff\">"; | |
1677 break; | |
1678 case 13: /* PINK */ | |
1679 body_tag = "<body bgcolor=\"#cc00cc\">"; | |
1680 break; | |
1681 case 14: /* GREY */ | |
1682 body_tag = "<body bgcolor=\"#666666\">"; | |
1683 break; | |
1684 case 15: /* SILVER */ | |
1685 body_tag = "<body bgcolor=\"#00ccac\">"; | |
1686 break; | |
1687 } | |
1688 | |
1689 current = strchr(u_message, '\003'); | |
1690 | |
1691 while (*body_tag != '\0') { | |
1692 *current = *body_tag; | |
1693 current++; | |
1694 body_tag++; | |
1695 } | |
1696 | |
1697 while (*font_tag != '\0') { | |
1698 *current = *font_tag; | |
1699 current++; | |
1700 font_tag++; | |
1701 } | |
1702 | |
1703 while (*temp != '\0') { | |
1704 *current = *temp; | |
1705 current++; | |
1706 temp++; | |
1707 } | |
1708 *current = '\0'; | |
1709 g_free(free_here); | |
1710 is_closing = !is_closing; | |
1711 | |
1712 } | |
1713 | |
1714 while (strchr(u_message, '\017')) { /* \017 = ^O */ | |
1715 gchar *current; | |
1716 gchar *temp, *free_here; | |
1717 | |
1718 | |
1719 temp = g_strdup(strchr(u_message, '\017')); | |
1720 free_here = temp; | |
1721 temp++; | |
1722 | |
1723 current = strchr(u_message, '\017'); | |
1724 *current = '<'; | |
1725 current++; | |
1726 *current = '/'; | |
1727 current++; | |
1728 *current = 'b'; | |
1729 current++; | |
1730 *current = '>'; | |
1731 current++; | |
1732 *current = '<'; | |
1733 current++; | |
1734 *current = '/'; | |
1735 current++; | |
1736 *current = 'u'; | |
1737 current++; | |
1738 *current = '>'; | |
1739 current++; | |
1740 | |
1741 while (*temp != '\0') { | |
1742 *current = *temp; | |
1743 current++; | |
1744 temp++; | |
1745 } | |
1746 *current = '\0'; | |
1747 g_free(free_here); | |
1748 } | |
1749 | |
1750 /* Let's check to see if we have a channel on our hands */ | |
1751 if (u_channel[0] == '#') { | |
1752 /* Yup. We have a channel */ | |
1753 int id; | |
1754 | |
1755 id = find_id_by_name(gc, u_channel); | |
1756 if (id != -1) { | |
1757 serv_got_chat_in(gc, id, u_nick, 0, u_message, time((time_t) NULL)); | |
1758 | |
1759 } | |
1760 | |
1761 } else { | |
1762 /* Nope. Let's treat it as a private message */ | |
1763 | |
1764 gchar *temp; | |
1765 temp = NULL; | |
1766 | |
1767 temp = (gchar *) g_malloc(strlen(u_nick) + 5); | |
1768 g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); | |
1769 | |
1770 | |
1771 /* If I get a message from SeanEgn, and I already have a window | |
1772 * open for him as @SeanEgn or +SeanEgn, this will keep it in the | |
1773 * same window. Unfortunately, if SeanEgn loses his op status | |
1774 * (a sad thing indeed), the messages will still appear to come from | |
1775 * @SeanEgn, until that convo is closed. | |
1776 */ | |
1777 | |
1778 if (find_conversation(temp)) { | |
1779 serv_got_im(gc, temp, u_message, 0, time((time_t) NULL)); | |
1780 g_free(temp); | |
1781 return; | |
1782 } else { | |
1783 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); | |
1784 if (find_conversation(temp)) { | |
1785 serv_got_im(gc, temp, u_message, 0, time((time_t) NULL)); | |
1786 g_free(temp); | |
1787 return; | |
1788 } else { | |
1789 g_free(temp); | |
1790 serv_got_im(gc, u_nick, u_message, 0, time((time_t) NULL)); | |
1791 return; | |
1792 } | |
1793 } | |
1794 } | |
1795 | |
1796 return; | |
1797 } | |
1798 | |
1799 /* Let's parse PING requests so that we wont get booted for inactivity */ | |
1800 | |
1801 if (strncmp(buf, "PING :", 6) == 0) { | |
1802 buf2 = g_strsplit(buf, ":", 1); | |
1803 | |
1804 /* Let's build a new response */ | |
1805 g_snprintf(buf, IRC_BUF_LEN, "PONG :%s\n", buf2[1]); | |
1806 write(idata->fd, buf, strlen(buf)); | |
1807 | |
1808 /* And clean up after ourselves */ | |
1809 g_strfreev(buf2); | |
1810 | |
1811 return; | |
1812 } | |
1813 | |
1814 } | |
1815 | |
1816 static void irc_close(struct gaim_connection *gc) | |
1817 { | |
1818 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1819 GList *chats = idata->channels; | |
1820 struct irc_channel *cc; | |
1821 | |
1822 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN); | |
1823 | |
1824 g_snprintf(buf, IRC_BUF_LEN, "QUIT :Download GAIM [%s]\n", WEBSITE); | |
1825 write(idata->fd, buf, strlen(buf)); | |
1826 | |
1827 g_free(buf); | |
1828 | |
1829 if (idata->timer) | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
1830 g_source_remove(idata->timer); |
2086 | 1831 |
1832 while (chats) { | |
1833 cc = (struct irc_channel *)chats->data; | |
1834 g_free(cc->name); | |
1835 chats = g_list_remove(chats, cc); | |
1836 g_free(cc); | |
1837 } | |
1838 | |
1839 if (gc->inpa) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1840 gaim_input_remove(gc->inpa); |
2086 | 1841 |
1842 if (idata->inpa) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1843 gaim_input_remove(idata->inpa); |
2086 | 1844 |
1845 close(idata->fd); | |
1846 g_free(gc->proto_data); | |
1847 } | |
1848 | |
1849 static void irc_chat_leave(struct gaim_connection *gc, int id) | |
1850 { | |
1851 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1852 struct irc_channel *channel; | |
1853 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
1854 | |
1855 channel = find_channel_by_id(gc, id); | |
1856 | |
1857 if (!channel) { | |
1858 return; | |
1859 } | |
1860 | |
1861 g_snprintf(buf, IRC_BUF_LEN, "PART #%s\n", channel->name); | |
1862 write(idata->fd, buf, strlen(buf)); | |
1863 | |
1864 g_free(buf); | |
1865 } | |
1866 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1867 static void irc_login_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 1868 { |
1869 struct gaim_connection *gc = data; | |
1870 struct irc_data *idata; | |
1871 char buf[4096]; | |
1872 | |
1873 if (!g_slist_find(connections, gc)) { | |
1874 close(source); | |
1875 return; | |
1876 } | |
1877 | |
1878 idata = gc->proto_data; | |
1879 | |
1880 if (source == -1) { | |
1881 hide_login_progress(gc, "Write error"); | |
1882 signoff(gc); | |
1883 return; | |
1884 } | |
1885 | |
1886 if (idata->fd != source) | |
1887 idata->fd = source; | |
1888 | |
1889 g_snprintf(buf, 4096, "NICK %s\n USER %s localhost %s :GAIM (%s)\n", | |
1890 gc->username, g_get_user_name(), gc->user->proto_opt[USEROPT_SERV], WEBSITE); | |
1891 | |
1892 if (write(idata->fd, buf, strlen(buf)) < 0) { | |
1893 hide_login_progress(gc, "Write error"); | |
1894 signoff(gc); | |
1895 return; | |
1896 } | |
1897 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1898 idata->inpa = gaim_input_add(idata->fd, GAIM_INPUT_READ, irc_callback, gc); |
2086 | 1899 idata->inpa = 0; |
1900 | |
1901 /* Now lets sign ourselves on */ | |
1902 account_online(gc); | |
1903 serv_finish_login(gc); | |
1904 | |
1905 if (bud_list_cache_exists(gc)) | |
1906 do_import(NULL, gc); | |
1907 | |
1908 /* we don't call this now because otherwise some IRC servers might not like us */ | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
1909 idata->timer = g_timeout_add(20000, irc_request_buddy_update, gc); |
2086 | 1910 } |
1911 | |
1912 static void irc_login(struct aim_user *user) | |
1913 { | |
1914 char buf[4096]; | |
1915 | |
1916 struct gaim_connection *gc = new_gaim_conn(user); | |
1917 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); | |
1918 | |
1919 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); | |
1920 set_login_progress(gc, 2, buf); | |
1921 | |
1922 idata->fd = proxy_connect(user->proto_opt[USEROPT_SERV], | |
1923 user->proto_opt[USEROPT_PORT][0] ? atoi(user-> | |
1924 proto_opt[USEROPT_PORT]) : | |
1925 6667, irc_login_callback, gc); | |
1926 if (!user->gc || (idata->fd < 0)) { | |
1927 hide_login_progress(gc, "Unable to create socket"); | |
1928 signoff(gc); | |
1929 return; | |
1930 } | |
1931 } | |
1932 | |
1933 static void irc_print_option(GtkEntry *entry, struct aim_user *user) | |
1934 { | |
1935 int entrynum; | |
1936 | |
1937 entrynum = (int)gtk_object_get_user_data(GTK_OBJECT(entry)); | |
1938 | |
1939 if (entrynum == USEROPT_SERV) { | |
1940 g_snprintf(user->proto_opt[USEROPT_SERV], | |
1941 sizeof(user->proto_opt[USEROPT_SERV]), "%s", gtk_entry_get_text(entry)); | |
1942 } else if (entrynum == USEROPT_PORT) { | |
1943 g_snprintf(user->proto_opt[USEROPT_PORT], | |
1944 sizeof(user->proto_opt[USEROPT_PORT]), "%s", gtk_entry_get_text(entry)); | |
1945 } | |
1946 } | |
1947 | |
1948 static void irc_user_opts(GtkWidget *book, struct aim_user *user) | |
1949 { | |
1950 /* so here, we create the new notebook page */ | |
1951 GtkWidget *vbox; | |
1952 GtkWidget *hbox; | |
1953 GtkWidget *label; | |
1954 GtkWidget *entry; | |
1955 | |
1956 vbox = gtk_vbox_new(FALSE, 5); | |
1957 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
1958 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("IRC Options")); | |
1959 gtk_widget_show(vbox); | |
1960 | |
1961 hbox = gtk_hbox_new(FALSE, 5); | |
1962 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1963 gtk_widget_show(hbox); | |
1964 | |
1965 label = gtk_label_new("Server:"); | |
1966 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1967 gtk_widget_show(label); | |
1968 | |
1969 entry = gtk_entry_new(); | |
1970 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
1971 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_SERV); | |
1972 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(irc_print_option), user); | |
1973 if (user->proto_opt[USEROPT_SERV][0]) { | |
1974 debug_printf("setting text %s\n", user->proto_opt[USEROPT_SERV]); | |
1975 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_SERV]); | |
1976 } | |
1977 gtk_widget_show(entry); | |
1978 | |
1979 hbox = gtk_hbox_new(FALSE, 0); | |
1980 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1981 gtk_widget_show(hbox); | |
1982 | |
1983 label = gtk_label_new("Port:"); | |
1984 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1985 gtk_widget_show(label); | |
1986 | |
1987 entry = gtk_entry_new(); | |
1988 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
1989 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PORT); | |
1990 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(irc_print_option), user); | |
1991 if (user->proto_opt[USEROPT_PORT][0]) { | |
1992 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PORT]); | |
1993 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PORT]); | |
1994 } else | |
1995 gtk_entry_set_text(GTK_ENTRY(entry), "6667"); | |
1996 | |
1997 gtk_widget_show(entry); | |
1998 } | |
1999 | |
2000 static char **irc_list_icon(int uc) | |
2001 { | |
2002 return free_icon_xpm; | |
2003 } | |
2004 | |
2005 /* Send out a ping request to the specified user */ | |
2006 static void irc_send_ping(GtkObject *w, char *who) | |
2007 { | |
2008 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
2009 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
2010 char buf[BUF_LEN]; | |
2011 | |
2012 g_snprintf(buf, BUF_LEN, "PRIVMSG %s :%cPING %ld%c\n", who, '\001', time((time_t *) NULL), | |
2013 '\001'); | |
2014 | |
2015 write(idata->fd, buf, strlen(buf)); | |
2016 } | |
2017 | |
2018 /* Do a whois check on someone :-) */ | |
2019 static void irc_get_info(struct gaim_connection *gc, char *who) | |
2020 { | |
2021 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
2022 char buf[BUF_LEN]; | |
2023 | |
2024 if (((who[0] == '@') || (who[0] == '+')) && (strlen(who) > 1)) | |
2025 g_snprintf(buf, BUF_LEN, "WHOIS %s\n", who + 1); | |
2026 else | |
2027 g_snprintf(buf, BUF_LEN, "WHOIS %s\n", who); | |
2028 write(idata->fd, buf, strlen(buf)); | |
2029 } | |
2030 | |
2031 static void irc_send_whois(GtkObject *w, char *who) | |
2032 { | |
2033 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
2034 irc_get_info(gc, who); | |
2035 } | |
2036 | |
2037 static void irc_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) | |
2038 { | |
2039 GtkWidget *button; | |
2040 | |
2041 button = gtk_menu_item_new_with_label("Ping"); | |
2042 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(irc_send_ping), who); | |
2043 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
2044 gtk_menu_append(GTK_MENU(menu), button); | |
2045 gtk_widget_show(button); | |
2046 | |
2047 button = gtk_menu_item_new_with_label("Whois"); | |
2048 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(irc_send_whois), who); | |
2049 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
2050 gtk_menu_append(GTK_MENU(menu), button); | |
2051 gtk_widget_show(button); | |
2052 } | |
2053 | |
2054 | |
2055 static void irc_set_away(struct gaim_connection *gc, char *state, char *msg) | |
2056 { | |
2057 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
2058 char buf[BUF_LEN]; | |
2059 | |
2060 if (msg) | |
2061 g_snprintf(buf, BUF_LEN, "AWAY :%s\n", msg); | |
2062 else | |
2063 g_snprintf(buf, BUF_LEN, "AWAY\n"); | |
2064 | |
2065 write(idata->fd, buf, strlen(buf)); | |
2066 } | |
2067 | |
2068 static void irc_fake_buddy(struct gaim_connection *gc, char *who) | |
2069 { | |
2070 /* Heh, there is no buddy list. We fake it. | |
2071 * I just need this here so the add and remove buttons will | |
2072 * show up */ | |
2073 } | |
2074 | |
2075 static void irc_chat_set_topic(struct gaim_connection *gc, int id, char *topic) | |
2076 { | |
2077 struct irc_channel *ic = NULL; | |
2078 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
2079 char buf[BUF_LEN]; | |
2080 | |
2081 ic = find_channel_by_id(gc, id); | |
2082 | |
2083 /* If we ain't in no channel, foo, gets outta da kitchen beeyotch */ | |
2084 if (!ic) | |
2085 return; | |
2086 | |
2087 /* Prepare our command */ | |
2088 g_snprintf(buf, BUF_LEN, "TOPIC #%s :%s\n", ic->name, topic); | |
2089 | |
2090 /* And send it */ | |
2091 write(idata->fd, buf, strlen(buf)); | |
2092 } | |
2093 | |
2094 static struct prpl *my_protocol = NULL; | |
2095 | |
2096 void irc_init(struct prpl *ret) | |
2097 { | |
2098 ret->protocol = PROTO_IRC; | |
2100
a93aeb6f813d
[gaim-migrate @ 2110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
2099 ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD; |
2086 | 2100 ret->name = irc_name; |
2101 ret->list_icon = irc_list_icon; | |
2102 ret->buddy_menu = irc_buddy_menu; | |
2103 ret->user_opts = irc_user_opts; | |
2104 ret->login = irc_login; | |
2105 ret->close = irc_close; | |
2106 ret->send_im = irc_send_im; | |
2107 ret->join_chat = irc_join_chat; | |
2108 ret->chat_leave = irc_chat_leave; | |
2109 ret->chat_send = irc_chat_send; | |
2110 ret->get_info = irc_get_info; | |
2111 ret->set_away = irc_set_away; | |
2112 ret->add_buddy = irc_fake_buddy; | |
2113 ret->remove_buddy = irc_fake_buddy; | |
2114 ret->chat_set_topic = irc_chat_set_topic; | |
2115 my_protocol = ret; | |
2116 } | |
2117 | |
2118 #ifndef STATIC | |
2119 | |
2120 char *gaim_plugin_init(GModule *handle) | |
2121 { | |
2122 load_protocol(irc_init, sizeof(struct prpl)); | |
2123 return NULL; | |
2124 } | |
2125 | |
2126 void gaim_plugin_remove() | |
2127 { | |
2128 struct prpl *p = find_prpl(PROTO_IRC); | |
2129 if (p == my_protocol) | |
2130 unload_protocol(p); | |
2131 } | |
2132 | |
2133 char *name() | |
2134 { | |
2135 return "IRC"; | |
2136 } | |
2137 | |
2138 char *description() | |
2139 { | |
2140 return "Allows gaim to use the IRC protocol"; | |
2141 } | |
2142 | |
2143 #endif |