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