987
|
1 /*
|
|
2 * gaim - IRC Protocol Plugin
|
|
3 *
|
|
4 * Copyright (C) 2000, 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 #ifdef HAVE_CONFIG_H
|
|
24 #include "../config.h"
|
|
25 #endif
|
|
26
|
|
27
|
|
28 #include <netdb.h>
|
|
29 #include <gtk/gtk.h>
|
|
30 #include <unistd.h>
|
|
31 #include <errno.h>
|
|
32 #include <netinet/in.h>
|
|
33 #include <arpa/inet.h>
|
|
34 #include <string.h>
|
|
35 #include <stdlib.h>
|
|
36 #include <stdio.h>
|
|
37 #include <time.h>
|
|
38 #include <sys/socket.h>
|
|
39 #include <sys/stat.h>
|
|
40 #include "multi.h"
|
|
41 #include "prpl.h"
|
|
42 #include "gaim.h"
|
|
43 #include "aim.h"
|
|
44 #include "gnome_applet_mgr.h"
|
|
45
|
|
46 #include "pixmaps/cancel.xpm"
|
|
47 #include "pixmaps/ok.xpm"
|
|
48
|
1011
|
49 /* FIXME: We shouldn't have hard coded servers and ports :-) */
|
1019
|
50 #define IRC_SERVER "irc.undernet.org"
|
1011
|
51 #define IRC_PORT 6667
|
|
52
|
|
53 #define IRC_BUF_LEN 4096
|
|
54
|
|
55 static int chat_id = 0;
|
|
56
|
|
57 struct irc_channel {
|
|
58 int id;
|
|
59 gchar *name;
|
|
60 };
|
|
61
|
|
62 struct irc_data {
|
|
63 int fd;
|
|
64
|
|
65 GList *channels;
|
|
66 };
|
|
67
|
1008
|
68 static char *irc_name() {
|
|
69 return "IRC";
|
|
70 }
|
|
71
|
|
72 char *name() {
|
|
73 return "IRC";
|
|
74 }
|
|
75
|
|
76 char *description() {
|
|
77 return "Allows gaim to use the IRC protocol";
|
|
78 }
|
|
79
|
1011
|
80 void irc_join_chat( struct gaim_connection *gc, int id, char *name) {
|
|
81 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
82 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN+1);
|
|
83
|
|
84 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name);
|
|
85 write(idata->fd, buf, strlen(buf));
|
1008
|
86
|
1011
|
87 g_free(buf);
|
|
88 }
|
|
89
|
|
90 void irc_send_im( struct gaim_connection *gc, char *who, char *message, int away) {
|
|
91
|
|
92 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
93 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN + 1);
|
|
94
|
|
95 /* Before we actually send this, we should check to see if they're trying
|
|
96 * To issue a /me command and handle it properly. */
|
|
97
|
|
98 if ( (g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message)>4)) {
|
|
99 /* We have /me!! We have /me!! :-) */
|
|
100
|
|
101 gchar *temp = (gchar *)g_malloc(IRC_BUF_LEN+1);
|
|
102 strcpy(temp, message+4);
|
|
103 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%cACTION %s%c\n", who, '\001', temp, '\001');
|
|
104 g_free(temp);
|
|
105 }
|
|
106 else
|
|
107 {
|
|
108 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%s\n", who, message);
|
|
109 }
|
|
110
|
|
111 write(idata->fd, buf, strlen(buf));
|
|
112
|
|
113 g_free(buf);
|
|
114 }
|
|
115
|
|
116 int find_id_by_name(struct gaim_connection *gc, char *name) {
|
|
117 gchar *temp = (gchar *)g_malloc(IRC_BUF_LEN + 1);
|
|
118 GList *templist;
|
|
119 struct irc_channel *channel;
|
|
120
|
|
121 templist = ((struct irc_data *)gc->proto_data)->channels;
|
|
122
|
|
123 while (templist) {
|
|
124 channel = (struct irc_channel *)templist->data;
|
|
125
|
|
126 g_snprintf(temp, IRC_BUF_LEN, "#%s", channel->name);
|
|
127
|
|
128 if (g_strcasecmp(temp, name) == 0) {
|
|
129 g_free(temp);
|
|
130 return channel->id;
|
|
131 }
|
|
132
|
|
133 templist = templist -> next;
|
|
134 }
|
|
135
|
|
136 g_free(temp);
|
|
137
|
|
138 /* Return -1 if we have no ID */
|
|
139 return -1;
|
|
140 }
|
|
141
|
|
142 struct irc_channel * find_channel_by_name(struct gaim_connection *gc, char *name) {
|
|
143 gchar *temp = (gchar *)g_malloc(IRC_BUF_LEN + 1);
|
|
144 GList *templist;
|
|
145 struct irc_channel *channel;
|
|
146
|
|
147 templist = ((struct irc_data *)gc->proto_data)->channels;
|
|
148
|
|
149 while (templist) {
|
|
150 channel = (struct irc_channel *)templist->data;
|
|
151
|
|
152 g_snprintf(temp, IRC_BUF_LEN, "%s", channel->name);
|
|
153
|
|
154 if (g_strcasecmp(temp, name) == 0) {
|
|
155 g_free(temp);
|
|
156 return channel;
|
|
157 }
|
|
158
|
|
159 templist = templist -> next;
|
|
160 }
|
|
161
|
|
162 g_free(temp);
|
|
163
|
|
164 /* If we found nothing, return nothing :-) */
|
|
165 return NULL;
|
|
166 }
|
|
167
|
|
168 struct irc_channel * find_channel_by_id (struct gaim_connection *gc, int id) {
|
|
169 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
170 struct irc_channel *channel;
|
|
171
|
|
172 GList *temp;
|
|
173
|
|
174 temp = idata->channels;
|
|
175
|
|
176 while (temp) {
|
|
177 channel = (struct irc_channel *)temp->data;
|
|
178
|
|
179 if (channel->id == id) {
|
|
180 /* We've found our man */
|
|
181 return channel;
|
|
182 }
|
|
183
|
|
184 temp = temp->next;
|
|
185 }
|
|
186
|
|
187
|
|
188 /* If we didnt find one, return NULL */
|
|
189 return NULL;
|
|
190 }
|
|
191
|
|
192 void irc_chat_send( struct gaim_connection *gc, int id, char *message) {
|
|
193
|
|
194 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
195 struct irc_channel *channel = g_new0(struct irc_channel, 1);
|
|
196 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN + 1);
|
|
197
|
|
198 /* First lets get our current channel */
|
|
199 channel = find_channel_by_id(gc, id);
|
|
200
|
|
201
|
|
202 if (!channel) {
|
|
203 /* If for some reason we've lost our channel, let's bolt */
|
|
204 return;
|
|
205 }
|
|
206
|
|
207
|
|
208 /* Before we actually send this, we should check to see if they're trying
|
|
209 * To issue a /me command and handle it properly. */
|
|
210
|
|
211 if ( (g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message)>4)) {
|
|
212 /* We have /me!! We have /me!! :-) */
|
|
213
|
|
214 gchar *temp = (gchar *)g_malloc(IRC_BUF_LEN+1);
|
|
215 strcpy(temp, message+4);
|
|
216 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%cACTION %s%c\n", channel->name, '\001', temp, '\001');
|
|
217 g_free(temp);
|
|
218 }
|
|
219 else
|
|
220 {
|
|
221 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%s\n", channel->name, message);
|
|
222 }
|
|
223
|
|
224 write(idata->fd, buf, strlen(buf));
|
|
225
|
|
226 /* Since AIM expects us to receive the message we send, we gotta fake it */
|
|
227 serv_got_chat_in(gc, id, gc->username, 0, message);
|
|
228
|
|
229 g_free(buf);
|
1008
|
230 }
|
|
231
|
1014
|
232 struct conversation * find_conversation_by_id( struct gaim_connection * gc, int id) {
|
|
233 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
234 GSList *bc = gc->buddy_chats;
|
|
235 struct conversation *b = NULL;
|
|
236
|
|
237 while (bc) {
|
|
238 b = (struct conversation *)bc->data;
|
|
239 if (id == b->id) {
|
|
240 break;
|
|
241 }
|
|
242 bc = bc->next;
|
|
243 b = NULL;
|
|
244 }
|
|
245
|
|
246 if (!b) {
|
|
247 return NULL;
|
|
248 }
|
|
249
|
|
250 return b;
|
|
251 }
|
|
252
|
|
253 struct conversation * find_conversation_by_name( struct gaim_connection * gc, char *name) {
|
|
254 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
255 GSList *bc = gc->buddy_chats;
|
|
256 struct conversation *b = NULL;
|
|
257
|
|
258 while (bc) {
|
|
259 b = (struct conversation *)bc->data;
|
|
260
|
|
261 if (g_strcasecmp(name, b->name) == 0) {
|
|
262 break;
|
|
263 }
|
|
264 bc = bc->next;
|
|
265 b = NULL;
|
|
266 }
|
|
267
|
|
268 if (!b) {
|
|
269 return NULL;
|
|
270 }
|
|
271
|
|
272 return b;
|
|
273 }
|
|
274
|
|
275
|
|
276
|
1011
|
277 void irc_callback ( struct gaim_connection * gc ) {
|
|
278
|
|
279 int i = 0;
|
|
280 char c;
|
|
281 gchar buf[4096];
|
|
282 gchar **buf2;
|
|
283 int status;
|
|
284 struct irc_data *idata;
|
|
285
|
|
286 idata = (struct irc_data *)gc->proto_data;
|
|
287
|
|
288 do {
|
|
289 status = recv(idata->fd, &c, 1, 0);
|
|
290
|
|
291 if (!status)
|
|
292 {
|
|
293 exit(1);
|
|
294 }
|
|
295 buf[i] = c;
|
|
296 i++;
|
|
297 } while (c != '\n');
|
|
298
|
|
299 buf[i] = '\0';
|
|
300
|
|
301 /* And remove that damned trailing \n */
|
|
302 g_strchomp(buf);
|
|
303
|
1014
|
304 /* For now, lets display everything to the console too. Im such
|
|
305 * a bitch */
|
1011
|
306 printf("IRC:'%'s\n", buf);
|
|
307
|
1014
|
308
|
|
309 /* Parse the list of names that we receive when we first sign on to
|
|
310 * a channel */
|
|
311
|
|
312 if (((strstr(buf, " 353 ")) && (!strstr(buf, "PRIVMSG")) &&
|
|
313 (!strstr(buf, "NOTICE")))) {
|
|
314 gchar u_host[255];
|
|
315 gchar u_command[32];
|
|
316 gchar u_channel[128];
|
|
317 gchar u_names[IRC_BUF_LEN + 1];
|
|
318 struct conversation *convo = NULL;
|
|
319 int j;
|
|
320
|
|
321 for (j = 0, i = 0; buf[i] != ' '; j++, i++) {
|
|
322 u_host[j] = buf[i];
|
|
323 }
|
|
324
|
|
325 u_host[j] = '\0'; i++;
|
|
326
|
|
327 for (j = 0; buf[i] != ' '; j++, i++) {
|
|
328 u_command[j] = buf[i];
|
|
329 }
|
|
330
|
|
331 u_command[j] = '\0'; i++;
|
|
332
|
|
333 for (j = 0; buf[i] != '#'; j++, i++) {
|
|
334 }
|
|
335 i++;
|
|
336
|
|
337 for (j = 0; buf[i] != ':'; j++, i++) {
|
|
338 u_channel[j] = buf[i];
|
|
339 }
|
|
340
|
|
341 u_channel[j-1] = '\0'; i++;
|
|
342
|
|
343 while ((buf[i] == ' ') || (buf[i] == ':')) {
|
|
344 i++;
|
|
345 }
|
|
346
|
|
347 strcpy(u_names, buf + i);
|
|
348
|
|
349 buf2 = g_strsplit(u_names, " ", 0);
|
|
350
|
|
351 /* Let's get our conversation window */
|
|
352 convo = find_conversation_by_name(gc, u_channel);
|
|
353
|
|
354 if (!convo) {
|
|
355 return;
|
|
356 }
|
|
357
|
|
358 /* Now that we've parsed the hell out of this big
|
|
359 * mess, let's try to split up the names properly */
|
|
360
|
|
361 for (i = 0; buf2[i] != NULL; i++) {
|
|
362 /* We shouldnt play with ourselves */
|
|
363 if (g_strcasecmp(buf2[i], gc->username) != 0) {
|
|
364 /* Add the person to the list */
|
|
365 add_chat_buddy(convo, buf2[i]);
|
|
366 }
|
|
367 }
|
|
368
|
|
369 return;
|
|
370
|
|
371 }
|
|
372
|
|
373
|
1011
|
374 if ( (strstr(buf, " JOIN ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
|
|
375
|
|
376 gchar u_channel[128];
|
1012
|
377 gchar u_nick[128];
|
|
378
|
1011
|
379 struct irc_channel *channel;
|
|
380 int id;
|
|
381 int j;
|
|
382
|
1012
|
383 for (j = 0, i = 1; buf[i] != '!'; j++, i++) {
|
|
384 u_nick[j] = buf[i];
|
|
385 }
|
|
386
|
|
387 u_nick[j] = '\0'; i++;
|
|
388
|
|
389 for (j = 0; buf[i] != '#'; j++, i++) {
|
1011
|
390 }
|
|
391
|
|
392 i++;
|
|
393
|
|
394 strcpy(u_channel, buf+i);
|
|
395
|
1014
|
396 /* Looks like we're going to join the channel for real
|
|
397 * now. Let's create a valid channel structure and add
|
|
398 * it to our list. Let's make sure that
|
1011
|
399 * we are not already in a channel first */
|
|
400
|
|
401 channel = find_channel_by_name(gc, u_channel);
|
|
402
|
|
403 if (!channel) {
|
|
404 chat_id++;
|
|
405
|
|
406 channel = g_new0(struct irc_channel, 1);
|
|
407
|
|
408 channel->id = chat_id;
|
|
409 channel->name = strdup(u_channel);
|
|
410
|
|
411 idata->channels = g_list_append(idata->channels, channel);
|
|
412
|
1014
|
413 printf("Started channel with ID %d\n", chat_id);
|
1011
|
414 serv_got_joined_chat(gc, chat_id, u_channel);
|
|
415 } else {
|
1014
|
416 struct conversation *convo = NULL;
|
|
417
|
|
418 /* Someone else joined. Find their conversation
|
|
419 * window */
|
|
420 convo = find_conversation_by_id(gc, channel->id);
|
|
421
|
|
422 /* And add their name to it */
|
|
423 add_chat_buddy(convo, u_nick);
|
|
424
|
1011
|
425 }
|
|
426
|
|
427 return;
|
|
428 }
|
|
429
|
|
430 if ( (strstr(buf, " PART ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) {
|
|
431
|
|
432 gchar u_channel[128];
|
|
433 gchar u_nick[128];
|
|
434
|
|
435 struct irc_channel *channel = g_new0(struct irc_channel, 1);
|
|
436 int id;
|
|
437 int j;
|
|
438 GList *test = NULL;
|
|
439
|
|
440 for (j = 0, i = 1; buf[i] != '!'; j++, i++) {
|
|
441 u_nick[j] = buf[i];
|
|
442 }
|
|
443 u_nick[j] = '\0';
|
|
444
|
|
445 i++;
|
|
446
|
|
447 for (j = 0; buf[i] != '#'; j++, i++) {
|
|
448 }
|
|
449
|
|
450 i++;
|
|
451
|
|
452 strcpy(u_channel, buf+i);
|
|
453
|
|
454
|
1014
|
455 /* Now, lets check to see if it was US that was leaving.
|
|
456 * If so, do the correct thing by closing up all of our
|
|
457 * old channel stuff. Otherwise,
|
1011
|
458 * we should just print that someone left */
|
|
459
|
1014
|
460 channel = find_channel_by_name(gc, u_channel);
|
|
461
|
|
462 if (!channel) {
|
|
463 return;
|
|
464 }
|
|
465
|
1011
|
466 if (g_strcasecmp(u_nick, gc->username) == 0) {
|
|
467
|
1014
|
468 /* Looks like we're going to leave the channel for
|
|
469 * real now. Let's create a valid channel structure
|
|
470 * and add it to our list */
|
1011
|
471
|
|
472 serv_got_chat_left(gc, channel->id);
|
|
473
|
|
474 idata->channels = g_list_remove(idata->channels, channel);
|
|
475 g_free(channel);
|
1014
|
476 } else {
|
|
477 struct conversation *convo = NULL;
|
|
478
|
|
479 /* Find their conversation window */
|
|
480 convo = find_conversation_by_id(gc, channel->id);
|
|
481
|
|
482 if (!convo) {
|
|
483 /* Some how the window doesn't exist.
|
|
484 * Let's get out of here */
|
|
485 return ;
|
|
486 }
|
|
487
|
|
488 /* And remove their name */
|
|
489 remove_chat_buddy(convo, u_nick);
|
|
490
|
1011
|
491 }
|
|
492
|
1014
|
493 /* Go Home! */
|
1011
|
494 return;
|
|
495 }
|
|
496
|
1012
|
497 if ( (strstr(buf, " PRIVMSG ")) && (buf[0] == ':')) {
|
1011
|
498 gchar u_nick[128];
|
|
499 gchar u_host[255];
|
|
500 gchar u_command[32];
|
|
501 gchar u_channel[128];
|
|
502 gchar u_message[IRC_BUF_LEN];
|
|
503 int j;
|
|
504 int msgcode = 0;
|
|
505
|
|
506 for (j = 0, i = 1; buf[i] != '!'; j++, i++) {
|
|
507 u_nick[j] = buf[i];
|
|
508 }
|
|
509
|
|
510 u_nick[j] = '\0'; i++;
|
|
511
|
|
512 for (j = 0; buf[i] != ' '; j++, i++) {
|
|
513 u_host[j] = buf[i];
|
|
514 }
|
|
515
|
|
516 u_host[j] = '\0'; i++;
|
|
517
|
|
518 for (j = 0; buf[i] != ' '; j++, i++) {
|
|
519 u_command[j] = buf[i];
|
|
520 }
|
|
521
|
|
522 u_command[j] = '\0'; i++;
|
|
523
|
|
524 for (j = 0; buf[i] != ':'; j++, i++) {
|
|
525 u_channel[j] = buf[i];
|
|
526 }
|
|
527
|
|
528 u_channel[j-1] = '\0'; i++;
|
|
529
|
|
530
|
|
531 /* Now that everything is parsed, the rest of this baby must be our message */
|
|
532 strncpy(u_message, buf + i, IRC_BUF_LEN);
|
|
533
|
|
534 /* Now, lets check the message to see if there's anything special in it */
|
|
535 if (u_message[0] == '\001') {
|
1017
|
536 if (g_strncasecmp(u_message, "\001VERSION", 8) == 0) {
|
|
537 /* Looks like we have a version request. Let
|
|
538 * us handle it thusly */
|
|
539
|
|
540 g_snprintf(buf, IRC_BUF_LEN, "NOTICE %s :%cVERSION GAIM %s:The Pimpin Penguin AIM Clone:www.marko.net/gaim%c\n", u_nick, '\001', VERSION, '\001');
|
|
541
|
|
542 write(idata->fd, buf, strlen(buf));
|
|
543
|
|
544 /* And get the heck out of dodge */
|
|
545 return;
|
|
546 }
|
|
547
|
|
548 if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) {
|
|
549 /* Someone's triyng to ping us. Let's respond */
|
|
550 gchar u_arg[24];
|
|
551
|
|
552 strcpy(u_arg, u_message + 6);
|
|
553 u_arg[strlen(u_arg)-1] = '\0';
|
|
554
|
|
555 g_snprintf(buf, IRC_BUF_LEN, "NOTICE %s :%cPING %s%c\n", u_nick, '\001', u_arg, '\001');
|
|
556
|
|
557 write(idata->fd, buf, strlen(buf));
|
|
558
|
|
559 /* And get the heck out of dodge */
|
|
560 return;
|
|
561 }
|
|
562
|
1011
|
563 if (g_strncasecmp(u_message, "\001ACTION ", 8) == 0) {
|
|
564 /* Looks like we have an action. Let's parse it a little */
|
|
565 strcpy(buf, u_message);
|
|
566
|
|
567 strcpy(u_message, "/me ");
|
|
568 for (j = 4, i = 8; buf[i] != '\001'; i++, j++) {
|
|
569 u_message[j] = buf[i];
|
|
570 }
|
|
571 u_message[j] = '\0';
|
|
572 }
|
|
573 }
|
|
574
|
|
575
|
|
576 /* Let's check to see if we have a channel on our hands */
|
|
577 if (u_channel[0] == '#') {
|
|
578 /* Yup. We have a channel */
|
|
579 int id;
|
|
580
|
|
581 id = find_id_by_name(gc, u_channel);
|
|
582 if (id != -1) {
|
|
583 serv_got_chat_in(gc, id, u_nick, 0, u_message);
|
|
584 }
|
|
585 }
|
|
586 else {
|
|
587 /* Nope. Let's treat it as a private message */
|
|
588 serv_got_im(gc, u_nick, u_message, 0);
|
|
589 }
|
|
590
|
|
591 return;
|
|
592 }
|
|
593
|
|
594 /* Let's parse PING requests so that we wont get booted for inactivity */
|
|
595
|
|
596 if (strncmp(buf, "PING :", 6) == 0) {
|
|
597 buf2 = g_strsplit(buf, ":", 1);
|
|
598
|
|
599 /* Let's build a new response */
|
|
600 g_snprintf(buf, IRC_BUF_LEN, "PONG :%s\n", buf2[1]);
|
|
601 write(idata->fd, buf, strlen(buf));
|
|
602
|
|
603 /* And clean up after ourselves */
|
|
604 g_strfreev(buf2);
|
|
605
|
|
606 return;
|
|
607 }
|
|
608
|
|
609 }
|
|
610
|
|
611 void irc_handler(gpointer data, gint source, GdkInputCondition condition) {
|
|
612 irc_callback(data);
|
|
613 }
|
|
614
|
|
615 void irc_close(struct gaim_connection *gc) {
|
|
616 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
617 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN);
|
|
618
|
|
619 g_snprintf(buf, IRC_BUF_LEN, "QUIT :GAIM [www.marko.net/gaim]\n");
|
|
620 write(idata->fd, buf, strlen(buf));
|
|
621
|
|
622 g_free(buf);
|
|
623 close(idata->fd);
|
|
624 g_free(gc->proto_data);
|
|
625 }
|
|
626
|
|
627 void irc_chat_leave(struct gaim_connection *gc, int id) {
|
|
628 struct irc_data *idata = (struct irc_data *)gc->proto_data;
|
|
629 struct irc_channel *channel;
|
|
630 gchar *buf = (gchar *)g_malloc(IRC_BUF_LEN+1);
|
|
631
|
|
632 channel = find_channel_by_id(gc, id);
|
|
633
|
|
634 if (!channel) {
|
|
635 return;
|
|
636 }
|
|
637
|
|
638 g_snprintf(buf, IRC_BUF_LEN, "PART #%s\n", channel->name);
|
|
639 write(idata->fd, buf, strlen(buf));
|
|
640
|
|
641 g_free(buf);
|
|
642 }
|
|
643
|
|
644 void irc_login(struct aim_user *user) {
|
|
645 int fd;
|
|
646 struct hostent *host;
|
|
647 struct sockaddr_in site;
|
|
648 char buf[4096];
|
|
649
|
|
650 struct gaim_connection *gc = new_gaim_conn(PROTO_IRC, user->username, user->password);
|
|
651 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1);
|
|
652 char c;
|
|
653 int i;
|
|
654 int status;
|
|
655
|
|
656 set_login_progress(gc, 1, buf);
|
|
657
|
|
658 while (gtk_events_pending())
|
|
659 gtk_main_iteration();
|
|
660
|
|
661 host = gethostbyname(IRC_SERVER);
|
|
662 if (!host) {
|
|
663 hide_login_progress(gc, "Unable to resolve hostname");
|
|
664 destroy_gaim_conn(gc);
|
|
665 return;
|
|
666 }
|
|
667
|
|
668 site.sin_family = AF_INET;
|
|
669 site.sin_addr.s_addr = *(long *)(host->h_addr);
|
|
670 site.sin_port = htons(IRC_PORT);
|
|
671
|
|
672 fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
673 if (fd < 0) {
|
|
674 hide_login_progress(gc, "Unable to create socket");
|
|
675 destroy_gaim_conn(gc);
|
|
676 return;
|
|
677 }
|
|
678
|
|
679 if (connect(fd, (struct sockaddr *)&site, sizeof(site)) < 0) {
|
|
680 hide_login_progress(gc, "Unable to connect.");
|
|
681 destroy_gaim_conn(gc);
|
|
682 return;
|
|
683 }
|
|
684
|
|
685 idata->fd = fd;
|
|
686
|
|
687 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username);
|
|
688 set_login_progress(gc, 2, buf);
|
|
689
|
|
690 /* This is where we will attempt to sign on */
|
|
691
|
|
692 /* FIXME: This should be their servername, not their username. im just lazy right now */
|
|
693
|
|
694 g_snprintf(buf, 4096, "NICK %s\nUSER %s localhost %s :GAIM (www.marko.net/gaim)\n", gc->username, gc->username, gc->username);
|
|
695 write(idata->fd, buf, strlen(buf));
|
|
696
|
|
697
|
|
698 /* Now lets sign ourselves on */
|
|
699 account_online(gc);
|
|
700
|
|
701 if (mainwindow)
|
|
702 gtk_widget_hide(mainwindow);
|
|
703
|
|
704 show_buddy_list();
|
|
705 refresh_buddy_window();
|
|
706
|
|
707 serv_finish_login(gc);
|
|
708 gaim_setup(gc);
|
|
709
|
|
710 gc->inpa = gdk_input_add(idata->fd, GDK_INPUT_READ, irc_handler, gc);
|
|
711 }
|
1008
|
712
|
987
|
713 struct prpl *irc_init() {
|
|
714 struct prpl *ret = g_new0(struct prpl, 1);
|
|
715
|
1008
|
716 ret->protocol = PROTO_IRC;
|
|
717 ret->name = irc_name;
|
|
718 ret->login = irc_login;
|
1011
|
719 ret->close = irc_close;
|
|
720 ret->send_im = irc_send_im;
|
987
|
721 ret->set_info = NULL;
|
|
722 ret->get_info = NULL;
|
|
723 ret->set_away = NULL;
|
|
724 ret->get_away_msg = NULL;
|
|
725 ret->set_dir = NULL;
|
|
726 ret->get_dir = NULL;
|
|
727 ret->dir_search = NULL;
|
|
728 ret->set_idle = NULL;
|
|
729 ret->change_passwd = NULL;
|
|
730 ret->add_buddy = NULL;
|
|
731 ret->add_buddies = NULL;
|
|
732 ret->remove_buddy = NULL;
|
|
733 ret->add_permit = NULL;
|
|
734 ret->add_deny = NULL;
|
|
735 ret->warn = NULL;
|
|
736 ret->accept_chat = NULL;
|
1011
|
737 ret->join_chat = irc_join_chat;
|
987
|
738 ret->chat_invite = NULL;
|
1011
|
739 ret->chat_leave = irc_chat_leave;
|
987
|
740 ret->chat_whisper = NULL;
|
1011
|
741 ret->chat_send = irc_chat_send;
|
987
|
742 ret->keepalive = NULL;
|
|
743
|
|
744 return ret;
|
|
745 }
|
|
746
|
|
747 int gaim_plugin_init(void *handle) {
|
|
748 protocols = g_slist_append(protocols, irc_init());
|
|
749 return 0;
|
|
750 }
|