comparison src/protocols/irc/irc.c @ 3708:da6e3c984985

[gaim-migrate @ 3841] host mask on join thanks to birme (required change to the function) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 15 Oct 2002 22:27:57 +0000
parents c1254110070a
children 34c95669952f
comparison
equal deleted inserted replaced
3707:c1254110070a 3708:da6e3c984985
74 int inpa; 74 int inpa;
75 char nick[80]; 75 char nick[80];
76 }; 76 };
77 77
78 struct irc_file_transfer { 78 struct irc_file_transfer {
79 enum { IFT_SENDFILE_IN, IFT_SENDFILE_OUT } type; 79 enum { IFT_SENDFILE_IN, IFT_SENDFILE_OUT } type;
80 struct file_transfer *xfer; 80 struct file_transfer *xfer;
81 char *sn; 81 char *sn;
82 char *name; 82 char *name;
83 int len; 83 int len;
84 int watcher; 84 int watcher;
85 int awatcher; 85 int awatcher;
86 char ip[12]; 86 char ip[12];
87 int port; 87 int port;
88 int fd; 88 int fd;
89 int cur; 89 int cur;
90 struct gaim_connection *gc; 90 struct gaim_connection *gc;
91 }; 91 };
92 92
93 GSList *dcc_chat_list = NULL; 93 GSList *dcc_chat_list = NULL;
94 94
95 struct irc_data { 95 struct irc_data {
251 } 251 }
252 252
253 static char *int_to_col(int c) 253 static char *int_to_col(int c)
254 { 254 {
255 switch(c) { 255 switch(c) {
256 case 1: 256 case 1:
257 return "#ffffff"; 257 return "#ffffff";
258 case 2: 258 case 2:
259 return "#000066"; 259 return "#000066";
260 case 3: 260 case 3:
261 return "#006600"; 261 return "#006600";
262 case 4: 262 case 4:
263 return "#ff0000"; 263 return "#ff0000";
264 case 5: 264 case 5:
265 return "#660000"; 265 return "#660000";
266 case 6: 266 case 6:
267 return "#660066"; 267 return "#660066";
268 case 7: 268 case 7:
269 return "#666600"; 269 return "#666600";
270 case 8: 270 case 8:
271 return "#cccc00"; 271 return "#cccc00";
272 case 9: 272 case 9:
273 return "#33cc33"; 273 return "#33cc33";
274 case 10: 274 case 10:
275 return "#00acac"; 275 return "#00acac";
276 case 11: 276 case 11:
277 return "#00ccac"; 277 return "#00ccac";
278 case 12: 278 case 12:
279 return "#0000ff"; 279 return "#0000ff";
280 case 13: 280 case 13:
281 return "#cc00cc"; 281 return "#cc00cc";
282 case 14: 282 case 14:
283 return "#666666"; 283 return "#666666";
284 case 15: 284 case 15:
285 return "#00ccac"; 285 return "#00ccac";
286 default: 286 default:
287 return "#000000"; 287 return "#000000";
288 } 288 }
289 } 289 }
290 290
291 static GString *encode_html(char *msg) 291 static GString *encode_html(char *msg)
292 { 292 {
349 char *cur = msg, *end = msg; 349 char *cur = msg, *end = msg;
350 gboolean bold = FALSE, underline = FALSE, fg = FALSE, bg = FALSE; 350 gboolean bold = FALSE, underline = FALSE, fg = FALSE, bg = FALSE;
351 int fore, back; 351 int fore, back;
352 while (*end) { 352 while (*end) {
353 switch (*end) { 353 switch (*end) {
354 case 02: /* ^B */ 354 case 02: /* ^B */
355 *end = 0; 355 *end = 0;
356 str = g_string_append(str, cur); 356 str = g_string_append(str, cur);
357 if (bold) 357 if (bold)
358 str = g_string_append(str, "</B>"); 358 str = g_string_append(str, "</B>");
359 else 359 else
360 str = g_string_append(str, "<B>"); 360 str = g_string_append(str, "<B>");
361 bold = !bold; 361 bold = !bold;
362 cur = end + 1; 362 cur = end + 1;
363 break; 363 break;
364 case 03: /* ^C */ 364 case 03: /* ^C */
365 *end++ = 0; 365 *end++ = 0;
366 str = g_string_append(str, cur); 366 str = g_string_append(str, cur);
367 fore = back = -1; 367 fore = back = -1;
368 if (isdigit(*end)) {
369 fore = *end++ - '0';
368 if (isdigit(*end)) { 370 if (isdigit(*end)) {
369 fore = *end++ - '0'; 371 fore *= 10;
372 fore += *end++ - '0';
373 }
374 if (*end == ',' && isdigit(end[1])) {
375 end++;
376 back = *end++ - '0';
370 if (isdigit(*end)) { 377 if (isdigit(*end)) {
371 fore *= 10; 378 back *= 10;
372 fore += *end++ - '0'; 379 back += *end++ - '0';
373 }
374 if (*end == ',' && isdigit(end[1])) {
375 end++;
376 back = *end++ - '0';
377 if (isdigit(*end)) {
378 back *= 10;
379 back += *end++ - '0';
380 }
381 } 380 }
382 } 381 }
383 if (fore == -1) { 382 }
384 if (fg) 383 if (fore == -1) {
385 str = g_string_append(str, "</FONT>");
386 if (bg)
387 str = g_string_append(str, "</FONT>");
388 fg = bg = FALSE;
389 } else {
390 fore %= 16;
391 if (fg)
392 str = g_string_append(str, "</FONT>");
393 if (back != -1) {
394 if (bg)
395 str = g_string_append(str, "</FONT>");
396 back %= 16;
397 str = g_string_append(str, "<FONT BACK=");
398 str = g_string_append(str, int_to_col(back));
399 str = g_string_append_c(str, '>');
400 bg = TRUE;
401 }
402 str = g_string_append(str, "<FONT COLOR=");
403 str = g_string_append(str, int_to_col(fore));
404 str = g_string_append_c(str, '>');
405 fg = TRUE;
406 }
407 cur = end--;
408 break;
409 case 017: /* ^O */
410 if (!bold && !underline && !fg && !bg)
411 break;
412 *end = 0;
413 str = g_string_append(str, cur);
414 if (bold)
415 str = g_string_append(str, "</B>");
416 if (underline)
417 str = g_string_append(str, "</U>");
418 if (fg) 384 if (fg)
419 str = g_string_append(str, "</FONT>"); 385 str = g_string_append(str, "</FONT>");
420 if (bg) 386 if (bg)
421 str = g_string_append(str, "</FONT>"); 387 str = g_string_append(str, "</FONT>");
422 bold = underline = fg = bg = FALSE; 388 fg = bg = FALSE;
423 cur = end + 1; 389 } else {
390 fore %= 16;
391 if (fg)
392 str = g_string_append(str, "</FONT>");
393 if (back != -1) {
394 if (bg)
395 str = g_string_append(str, "</FONT>");
396 back %= 16;
397 str = g_string_append(str, "<FONT BACK=");
398 str = g_string_append(str, int_to_col(back));
399 str = g_string_append_c(str, '>');
400 bg = TRUE;
401 }
402 str = g_string_append(str, "<FONT COLOR=");
403 str = g_string_append(str, int_to_col(fore));
404 str = g_string_append_c(str, '>');
405 fg = TRUE;
406 }
407 cur = end--;
408 break;
409 case 017: /* ^O */
410 if (!bold && !underline && !fg && !bg)
424 break; 411 break;
425 case 037: /* ^_ */ 412 *end = 0;
426 *end = 0; 413 str = g_string_append(str, cur);
427 str = g_string_append(str, cur); 414 if (bold)
428 if (underline) 415 str = g_string_append(str, "</B>");
429 str = g_string_append(str, "</U>"); 416 if (underline)
430 else 417 str = g_string_append(str, "</U>");
431 str = g_string_append(str, "<U>"); 418 if (fg)
432 underline = !underline; 419 str = g_string_append(str, "</FONT>");
433 cur = end + 1; 420 if (bg)
434 break; 421 str = g_string_append(str, "</FONT>");
422 bold = underline = fg = bg = FALSE;
423 cur = end + 1;
424 break;
425 case 037: /* ^_ */
426 *end = 0;
427 str = g_string_append(str, cur);
428 if (underline)
429 str = g_string_append(str, "</U>");
430 else
431 str = g_string_append(str, "<U>");
432 underline = !underline;
433 cur = end + 1;
434 break;
435 } 435 }
436 end++; 436 end++;
437 } 437 }
438 if (*cur) 438 if (*cur)
439 str = g_string_append(str, cur); 439 str = g_string_append(str, cur);
486 } 486 }
487 487
488 static void irc_file_transfer_do(struct gaim_connection *gc, struct irc_file_transfer *ift) { 488 static void irc_file_transfer_do(struct gaim_connection *gc, struct irc_file_transfer *ift) {
489 /* Ok, we better be receiving some crap here boyeee */ 489 /* Ok, we better be receiving some crap here boyeee */
490 if (transfer_in_do(ift->xfer, ift->fd, ift->name, ift->len)) { 490 if (transfer_in_do(ift->xfer, ift->fd, ift->name, ift->len)) {
491 gaim_input_remove(ift->watcher); 491 gaim_input_remove(ift->watcher);
492 ift->watcher = 0; 492 ift->watcher = 0;
493 } 493 }
494 } 494 }
495 495
496 496
497 void irc_read_dcc_ack (gpointer data, gint source, GaimInputCondition condition) { 497 void irc_read_dcc_ack (gpointer data, gint source, GaimInputCondition condition) {
498 /* Read ACK Here */ 498 /* Read ACK Here */
499 499
500 } 500 }
501 501
502 void dcc_send_callback (gpointer data, gint source, GaimInputCondition condition) { 502 void dcc_send_callback (gpointer data, gint source, GaimInputCondition condition) {
503 struct irc_file_transfer *ift = data; 503 struct irc_file_transfer *ift = data;
504 struct sockaddr_in addr; 504 struct sockaddr_in addr;
505 int len = sizeof(addr); 505 int len = sizeof(addr);
506 506
507 addr.sin_family = AF_INET; 507 addr.sin_family = AF_INET;
508 addr.sin_port = htons(ift->port); 508 addr.sin_port = htons(ift->port);
509 addr.sin_addr.s_addr = INADDR_ANY; 509 addr.sin_addr.s_addr = INADDR_ANY;
510 510
511 ift->fd = accept(ift->fd, (struct sockaddr *)&addr, &len); 511 ift->fd = accept(ift->fd, (struct sockaddr *)&addr, &len);
512 if (!ift->fd) { 512 if (!ift->fd) {
513 /* FIXME: Handle this gracefully XXX */ 513 /* FIXME: Handle this gracefully XXX */
514 printf("Something bad happened here, bubba!\n"); 514 printf("Something bad happened here, bubba!\n");
515 return; 515 return;
516 } 516 }
517 517
518 /* ift->awatcher = gaim_input_add(ift->fd, GAIM_INPUT_READ, irc_read_dcc_ack, ift); */ 518 /* ift->awatcher = gaim_input_add(ift->fd, GAIM_INPUT_READ, irc_read_dcc_ack, ift); */
519 519
520 if (transfer_out_do(ift->xfer, ift->fd, 0)) { 520 if (transfer_out_do(ift->xfer, ift->fd, 0)) {
521 gaim_input_remove(ift->watcher); 521 gaim_input_remove(ift->watcher);
522 ift->watcher = 0; 522 ift->watcher = 0;
523 } 523 }
524 } 524 }
525 525
526 void dcc_recv_callback (gpointer data, gint source, GaimInputCondition condition) { 526 void dcc_recv_callback (gpointer data, gint source, GaimInputCondition condition) {
527 struct irc_file_transfer *ift = data; 527 struct irc_file_transfer *ift = data;
528 528
529 ift->fd = source; 529 ift->fd = source;
530 irc_file_transfer_do(ift->gc, ift); 530 irc_file_transfer_do(ift->gc, ift);
531 } 531 }
532 532
533 void dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) { 533 void dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) {
534 struct dcc_chat *chat = data; 534 struct dcc_chat *chat = data;
535 struct conversation *convo = new_conversation (chat->nick); 535 struct conversation *convo = new_conversation (chat->nick);
629 char **buf, **tmp; 629 char **buf, **tmp;
630 if (!c) return; 630 if (!c) return;
631 if (*names == ':') names++; 631 if (*names == ':') names++;
632 buf = g_strsplit(names, " ", -1); 632 buf = g_strsplit(names, " ", -1);
633 for (tmp = buf; *tmp; tmp++) 633 for (tmp = buf; *tmp; tmp++)
634 add_chat_buddy(c, *tmp); 634 add_chat_buddy(c, *tmp, NULL);
635 g_strfreev(buf); 635 g_strfreev(buf);
636 } 636 }
637 637
638 static void handle_notopic(struct gaim_connection *gc, char *text) 638 static void handle_notopic(struct gaim_connection *gc, char *text)
639 { 639 {
658 658
659 if ((c = irc_find_chat(gc, text))) { 659 if ((c = irc_find_chat(gc, text))) {
660 char buf[IRC_BUF_LEN]; 660 char buf[IRC_BUF_LEN];
661 chat_set_topic(c, NULL, po); 661 chat_set_topic(c, NULL, po);
662 g_snprintf(buf, sizeof(buf), _("<B>%s has changed the topic to: %s</B>"), 662 g_snprintf(buf, sizeof(buf), _("<B>%s has changed the topic to: %s</B>"),
663 text, po); 663 text, po);
664 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); 664 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1);
665 } 665 }
666 } 666 }
667 667
668 static gboolean mode_has_arg(struct gaim_connection *gc, char sign, char mode) 668 static gboolean mode_has_arg(struct gaim_connection *gc, char sign, char mode)
745 else 745 else
746 voice = TRUE; 746 voice = TRUE;
747 } 747 }
748 tmp = g_strdup(r->data); 748 tmp = g_strdup(r->data);
749 g_snprintf(buf, sizeof(buf), "%s%s%s", op ? "@" : "", 749 g_snprintf(buf, sizeof(buf), "%s%s%s", op ? "@" : "",
750 voice ? "+" : "", nick); 750 voice ? "+" : "", nick);
751 rename_chat_buddy(c, tmp, buf); 751 rename_chat_buddy(c, tmp, buf);
752 g_free(tmp); 752 g_free(tmp);
753 return; 753 return;
754 } 754 }
755 r = r->next; 755 r = r->next;
988 break; 988 break;
989 case 351: /* RPL_VERSION */ 989 case 351: /* RPL_VERSION */
990 handle_version(gc, word, word_eol, n); 990 handle_version(gc, word, word_eol, n);
991 break; 991 break;
992 case 352: /* RPL_WHOREPLY */ 992 case 352: /* RPL_WHOREPLY */
993 handle_who(gc, word, word_eol, n); 993 handle_who(gc, word, word_eol, n);
994 break; 994 break;
995 case 353: /* RPL_NAMREPLY */ 995 case 353: /* RPL_NAMREPLY */
996 handle_names(gc, word[5], word_eol[6]); 996 handle_names(gc, word[5], word_eol[6]);
997 break; 997 break;
998 case 376: /* RPL_ENDOFMOTD */ 998 case 376: /* RPL_ENDOFMOTD */
999 irc_request_buddy_update(gc); 999 irc_request_buddy_update(gc);
1150 struct irc_data *id = gc->proto_data; 1150 struct irc_data *id = gc->proto_data;
1151 char buf[IRC_BUF_LEN]; 1151 char buf[IRC_BUF_LEN];
1152 1152
1153 if (!g_strncasecmp(msg, "VERSION", 7)) { 1153 if (!g_strncasecmp(msg, "VERSION", 7)) {
1154 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001VERSION Gaim " VERSION ": The Penguin Pimpin' " 1154 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001VERSION Gaim " VERSION ": The Penguin Pimpin' "
1155 "Multi-protocol Messaging Client: " WEBSITE "\001\r\n", nick); 1155 "Multi-protocol Messaging Client: " WEBSITE "\001\r\n", nick);
1156 irc_write(id->fd, buf, strlen(buf)); 1156 irc_write(id->fd, buf, strlen(buf));
1157 } 1157 }
1158 if (!g_strncasecmp(msg, "CLIENTINFO", 10)) { 1158 if (!g_strncasecmp(msg, "CLIENTINFO", 10)) {
1159 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001CLIENTINFO USERINFO CLIENTINFO VERSION\001\r\n", nick); 1159 g_snprintf(buf, sizeof(buf), "NOTICE %s :\001CLIENTINFO USERINFO CLIENTINFO VERSION\001\r\n", nick);
1160 irc_write(id->fd, buf, strlen(buf)); 1160 irc_write(id->fd, buf, strlen(buf));
1185 do_ask_dialog(ask, dccchat, dcc_chat_init, dcc_chat_cancel); 1185 do_ask_dialog(ask, dccchat, dcc_chat_init, dcc_chat_cancel);
1186 } 1186 }
1187 1187
1188 1188
1189 if (!g_strncasecmp(msg, "DCC SEND", 8)) { 1189 if (!g_strncasecmp(msg, "DCC SEND", 8)) {
1190 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1); 1190 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1);
1191 char **send_args = g_strsplit(msg, " ", 6); 1191 char **send_args = g_strsplit(msg, " ", 6);
1192 send_args[5][strlen(send_args[5])-1] = 0; 1192 send_args[5][strlen(send_args[5])-1] = 0;
1193 1193
1194 ift->type = IFT_SENDFILE_IN; 1194 ift->type = IFT_SENDFILE_IN;
1195 ift->sn = g_strdup(nick); 1195 ift->sn = g_strdup(nick);
1196 ift->gc = gc; 1196 ift->gc = gc;
1197 g_snprintf(ift->ip, sizeof(ift->ip), send_args[3]); 1197 g_snprintf(ift->ip, sizeof(ift->ip), send_args[3]);
1198 ift->port = atoi(send_args[4]); 1198 ift->port = atoi(send_args[4]);
1199 ift->len = atoi(send_args[5]); 1199 ift->len = atoi(send_args[5]);
1200 ift->name = g_strdup(send_args[2]); 1200 ift->name = g_strdup(send_args[2]);
1201 ift->cur = 0; 1201 ift->cur = 0;
1202 1202
1203 id->file_transfers = g_slist_append(id->file_transfers, ift); 1203 id->file_transfers = g_slist_append(id->file_transfers, ift);
1204 1204
1205 ift->xfer = transfer_in_add(gc, nick, ift->name, ift->len, 1, NULL); 1205 ift->xfer = transfer_in_add(gc, nick, ift->name, ift->len, 1, NULL);
1206 } 1206 }
1207 1207
1208 /* XXX should probably write_to_conv or something here */ 1208 /* XXX should probably write_to_conv or something here */
1209 } 1209 }
1210 1210
1284 if (!g_strcasecmp(gc->displayname, nick)) { 1284 if (!g_strcasecmp(gc->displayname, nick)) {
1285 static int id = 1; 1285 static int id = 1;
1286 serv_got_joined_chat(gc, id++, chan); 1286 serv_got_joined_chat(gc, id++, chan);
1287 } else { 1287 } else {
1288 struct conversation *c = irc_find_chat(gc, chan); 1288 struct conversation *c = irc_find_chat(gc, chan);
1289 if (c) 1289 if (c) {
1290 add_chat_buddy(c, nick); 1290 char *hostmask = g_strdup(word[1]);
1291 } 1291 char *p = strchr(hostmask, '!');
1292 if (p) {
1293 char *pend = strchr(p, ' ');
1294 if (pend) {
1295 *pend = 0;
1296 }
1297 add_chat_buddy(c, nick, p+1);
1298 g_free(hostmask);
1299 }
1300 }
1301 }
1302
1292 } else if (!strcmp(cmd, "KICK")) { 1303 } else if (!strcmp(cmd, "KICK")) {
1293 if (!strcmp(gc->displayname, word[4])) { 1304 if (!strcmp(gc->displayname, word[4])) {
1294 struct conversation *c = irc_find_chat(gc, word[3]); 1305 struct conversation *c = irc_find_chat(gc, word[3]);
1295 if (!c) 1306 if (!c)
1296 return FALSE; 1307 return FALSE;
1297 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); 1308 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c);
1298 c->gc = NULL; 1309 c->gc = NULL;
1299 /*
1300 g_snprintf(outbuf, sizeof(outbuf), _("You have been kicked from %s by %s:"),
1301 word[3], nick);
1302 do_error_dialog(outbuf, *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5], GAIM_INFO);
1303 */
1304 g_snprintf(outbuf, sizeof(outbuf), _("You have been kicked from %s: %s"), 1310 g_snprintf(outbuf, sizeof(outbuf), _("You have been kicked from %s: %s"),
1305 word[3], *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]); 1311 word[3], *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]);
1306 do_error_dialog(outbuf, _("IRC Error"), GAIM_ERROR); 1312 do_error_dialog(outbuf, _("IRC Error"), GAIM_ERROR);
1307 } else { 1313 } else {
1308 char *reason = *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]; 1314 char *reason = *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5];
1395 char *topic = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]; 1401 char *topic = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4];
1396 if (c) { 1402 if (c) {
1397 char buf[IRC_BUF_LEN]; 1403 char buf[IRC_BUF_LEN];
1398 chat_set_topic(c, nick, topic); 1404 chat_set_topic(c, nick, topic);
1399 g_snprintf(buf, sizeof(buf), _("<B>%s has changed the topic to: %s</B>"), 1405 g_snprintf(buf, sizeof(buf), _("<B>%s has changed the topic to: %s</B>"),
1400 nick, topic); 1406 nick, topic);
1401 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); 1407 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1);
1402 } 1408 }
1403 } else if (!strcmp(cmd, "WALLOPS")) { /* Don't know if a dialog box is the right way? */ 1409 } else if (!strcmp(cmd, "WALLOPS")) { /* Don't know if a dialog box is the right way? */
1404 char *msg = strrchr(word_eol[0], ':'); 1410 char *msg = strrchr(word_eol[0], ':');
1405 if (msg) 1411 if (msg)
1442 1448
1443 len = e - idata->rxqueue + 1; 1449 len = e - idata->rxqueue + 1;
1444 d = g_strndup(idata->rxqueue, len); 1450 d = g_strndup(idata->rxqueue, len);
1445 g_strchomp(d); 1451 g_strchomp(d);
1446 debug_printf("IRC S: %s\n", d); 1452 debug_printf("IRC S: %s\n", d);
1453
1454 /* REMOVE ME BEFORE SUBMIT! */
1455 /* fprintf(stderr, "IRC S: %s\n", d); */
1447 1456
1448 idata->rxlen -= len; 1457 idata->rxlen -= len;
1449 if (idata->rxlen) { 1458 if (idata->rxlen) {
1450 char *tmp = g_strdup(e + 1); 1459 char *tmp = g_strdup(e + 1);
1451 g_free(idata->rxqueue); 1460 g_free(idata->rxqueue);
1563 idata->rxqueue = NULL; 1572 idata->rxqueue = NULL;
1564 idata->rxlen = 0; 1573 idata->rxlen = 0;
1565 1574
1566 /* Kill any existing transfers */ 1575 /* Kill any existing transfers */
1567 while (idata->file_transfers) { 1576 while (idata->file_transfers) {
1568 struct irc_file_transfer *ift = (struct irc_file_transfer *)idata->file_transfers->data; 1577 struct irc_file_transfer *ift = (struct irc_file_transfer *)idata->file_transfers->data;
1569 1578
1570 g_free(ift->sn); 1579 g_free(ift->sn);
1571 g_free(ift->name); 1580 g_free(ift->name);
1572 gaim_input_remove(ift->watcher); 1581 gaim_input_remove(ift->watcher);
1573 1582
1574 close(ift->fd); 1583 close(ift->fd);
1575 1584
1576 idata->file_transfers = idata->file_transfers->next; 1585 idata->file_transfers = idata->file_transfers->next;
1577 } 1586 }
1578 idata->file_transfers = NULL; 1587 idata->file_transfers = NULL;
1579 1588
1580 1589
1581 g_free(idata->chantypes); 1590 g_free(idata->chantypes);
1599 #endif 1608 #endif
1600 g_free(gc->proto_data); 1609 g_free(gc->proto_data);
1601 } 1610 }
1602 1611
1603 static void set_mode_3(struct gaim_connection *gc, char *who, int sign, int mode, 1612 static void set_mode_3(struct gaim_connection *gc, char *who, int sign, int mode,
1604 int start, int end, char *word[]) 1613 int start, int end, char *word[])
1605 { 1614 {
1606 struct irc_data *id = gc->proto_data; 1615 struct irc_data *id = gc->proto_data;
1607 char buf[IRC_BUF_LEN]; 1616 char buf[IRC_BUF_LEN];
1608 int left; 1617 int left;
1609 int i = start; 1618 int i = start;
1610 1619
1611 while (1) { 1620 while (1) {
1612 left = end - i; 1621 left = end - i;
1613 switch (left) { 1622 switch (left) {
1614 case 0: 1623 case 0:
1615 return; 1624 return;
1616 case 1: 1625 case 1:
1617 g_snprintf(buf, sizeof(buf), "MODE %s %c%c %s\r\n", 1626 g_snprintf(buf, sizeof(buf), "MODE %s %c%c %s\r\n",
1618 who, sign, mode, word[i]); 1627 who, sign, mode, word[i]);
1619 i += 1; 1628 i += 1;
1620 break; 1629 break;
1621 case 2: 1630 case 2:
1622 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c %s %s\r\n", 1631 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c %s %s\r\n",
1623 who, sign, mode, mode, word[i], word[i + 1]); 1632 who, sign, mode, mode, word[i], word[i + 1]);
1624 i += 2; 1633 i += 2;
1625 break; 1634 break;
1626 default: 1635 default:
1627 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c %s %s %s\r\n", 1636 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c %s %s %s\r\n",
1628 who, sign, mode, mode, mode, 1637 who, sign, mode, mode, mode,
1629 word[i], word[i + 1], word[i + 2]); 1638 word[i], word[i + 1], word[i + 2]);
1630 i += 2; 1639 i += 2;
1631 break; 1640 break;
1632 } 1641 }
1633 irc_write(id->fd, buf, strlen(buf)); 1642 irc_write(id->fd, buf, strlen(buf));
1634 if (left < 3) 1643 if (left < 3)
1635 return; 1644 return;
1636 } 1645 }
1637 } 1646 }
1638 1647
1639 static void set_mode_6(struct gaim_connection *gc, char *who, int sign, int mode, 1648 static void set_mode_6(struct gaim_connection *gc, char *who, int sign, int mode,
1640 int start, int end, char *word[]) 1649 int start, int end, char *word[])
1641 { 1650 {
1642 struct irc_data *id = gc->proto_data; 1651 struct irc_data *id = gc->proto_data;
1643 char buf[IRC_BUF_LEN]; 1652 char buf[IRC_BUF_LEN];
1644 int left; 1653 int left;
1645 int i = start; 1654 int i = start;
1646 1655
1647 while (1) { 1656 while (1) {
1648 left = end - i; 1657 left = end - i;
1649 switch (left) { 1658 switch (left) {
1650 case 0: 1659 case 0:
1651 return; 1660 return;
1652 case 1: 1661 case 1:
1653 g_snprintf(buf, sizeof(buf), "MODE %s %c%c %s\r\n", 1662 g_snprintf(buf, sizeof(buf), "MODE %s %c%c %s\r\n",
1654 who, sign, mode, word[i]); 1663 who, sign, mode, word[i]);
1655 i += 1; 1664 i += 1;
1656 break; 1665 break;
1657 case 2: 1666 case 2:
1658 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c %s %s\r\n", 1667 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c %s %s\r\n",
1659 who, sign, mode, mode, word[i], word[i + 1]); 1668 who, sign, mode, mode, word[i], word[i + 1]);
1660 i += 2; 1669 i += 2;
1661 break; 1670 break;
1662 case 3: 1671 case 3:
1663 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c %s %s %s\r\n", 1672 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c %s %s %s\r\n",
1664 who, sign, mode, mode, mode, 1673 who, sign, mode, mode, mode,
1665 word[i], word[i + 1], word[i + 2]); 1674 word[i], word[i + 1], word[i + 2]);
1666 i += 3; 1675 i += 3;
1667 break; 1676 break;
1668 case 4: 1677 case 4:
1669 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c %s %s %s %s\r\n", 1678 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c %s %s %s %s\r\n",
1670 who, sign, mode, mode, mode, mode, 1679 who, sign, mode, mode, mode, mode,
1671 word[i], word[i + 1], word[i + 2], word[i + 3]); 1680 word[i], word[i + 1], word[i + 2], word[i + 3]);
1672 i += 4; 1681 i += 4;
1673 break; 1682 break;
1674 case 5: 1683 case 5:
1675 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c%c %s %s %s %s %s\r\n", 1684 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c%c %s %s %s %s %s\r\n",
1676 who, sign, mode, mode, mode, mode, mode, 1685 who, sign, mode, mode, mode, mode, mode,
1677 word[i], word[i + 1], word[i + 2], 1686 word[i], word[i + 1], word[i + 2],
1678 word[i + 3], word[i + 4]); 1687 word[i + 3], word[i + 4]);
1679 i += 5; 1688 i += 5;
1680 break; 1689 break;
1681 default: 1690 default:
1682 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c%c%c %s %s %s %s %s %s\r\n", 1691 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c%c%c %s %s %s %s %s %s\r\n",
1683 who, sign, mode, mode, mode, mode, mode, mode, 1692 who, sign, mode, mode, mode, mode, mode, mode,
1684 word[i], word[i + 1], word[i + 2], 1693 word[i], word[i + 1], word[i + 2],
1685 word[i + 3], word[i + 4], word[i + 5]); 1694 word[i + 3], word[i + 4], word[i + 5]);
1686 i += 6; 1695 i += 6;
1687 break; 1696 break;
1688 } 1697 }
1689 irc_write(id->fd, buf, strlen(buf)); 1698 irc_write(id->fd, buf, strlen(buf));
1690 if (left < 6) 1699 if (left < 6)
1691 return; 1700 return;
1692 } 1701 }
1861 g_free(what); 1870 g_free(what);
1862 return -EINVAL; 1871 return -EINVAL;
1863 } 1872 }
1864 c = irc_find_chat(gc, chan); 1873 c = irc_find_chat(gc, chan);
1865 g_snprintf(buf, sizeof(buf), "PART %s%s%s\r\n", chan, 1874 g_snprintf(buf, sizeof(buf), "PART %s%s%s\r\n", chan,
1866 *reason ? " :" : "", 1875 *reason ? " :" : "",
1867 *reason ? reason : ""); 1876 *reason ? reason : "");
1868 irc_write(id->fd, buf, strlen(buf)); 1877 irc_write(id->fd, buf, strlen(buf));
1869 if (c) { 1878 if (c) {
1870 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); 1879 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c);
1871 c->gc = NULL; 1880 c->gc = NULL;
1872 g_snprintf(buf, sizeof(buf), _("You have left %s"), chan); 1881 g_snprintf(buf, sizeof(buf), _("You have left %s"), chan);
2152 debug_printf ("Chat with %s established\n", chat->nick); 2161 debug_printf ("Chat with %s established\n", chat->nick);
2153 dcc_chat_list = g_slist_append (dcc_chat_list, chat); 2162 dcc_chat_list = g_slist_append (dcc_chat_list, chat);
2154 } 2163 }
2155 #if 0 2164 #if 0
2156 static void irc_ask_send_file(struct gaim_connection *gc, char *destsn) { 2165 static void irc_ask_send_file(struct gaim_connection *gc, char *destsn) {
2157 struct irc_data *id = (struct irc_data *)gc->proto_data; 2166 struct irc_data *id = (struct irc_data *)gc->proto_data;
2158 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1); 2167 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1);
2159 char *localip = (char *)malloc(12); 2168 char *localip = (char *)malloc(12);
2160 2169
2161 if (getlocalip(localip) == -1) { 2170 if (getlocalip(localip) == -1) {
2162 free(localip); 2171 free(localip);
2163 return; 2172 return;
2164 } 2173 }
2165 2174
2166 ift->type = IFT_SENDFILE_OUT; 2175 ift->type = IFT_SENDFILE_OUT;
2167 ift->sn = g_strdup(destsn); 2176 ift->sn = g_strdup(destsn);
2168 ift->gc = gc; 2177 ift->gc = gc;
2169 snprintf(ift->ip, sizeof(ift->ip), "%s", localip); 2178 snprintf(ift->ip, sizeof(ift->ip), "%s", localip);
2170 id->file_transfers = g_slist_append(id->file_transfers, ift); 2179 id->file_transfers = g_slist_append(id->file_transfers, ift);
2171 2180
2172 ift->xfer = transfer_out_add(gc, ift->sn); 2181 ift->xfer = transfer_out_add(gc, ift->sn);
2173 } 2182 }
2174 #endif 2183 #endif
2175 static struct irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc, 2184 static struct irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc,
2176 struct file_transfer *xfer) { 2185 struct file_transfer *xfer) {
2177 2186
2178 GSList *g = ((struct irc_data *)gc->proto_data)->file_transfers; 2187 GSList *g = ((struct irc_data *)gc->proto_data)->file_transfers;
2179 struct irc_file_transfer *f = NULL; 2188 struct irc_file_transfer *f = NULL;
2180 2189
2181 while (g) { 2190 while (g) {
2182 f = (struct irc_file_transfer *)g->data; 2191 f = (struct irc_file_transfer *)g->data;
2183 if (f->xfer == xfer) 2192 if (f->xfer == xfer)
2184 break; 2193 break;
2185 g = g->next; 2194 g = g->next;
2186 f = NULL; 2195 f = NULL;
2187 } 2196 }
2188 2197
2189 return f; 2198 return f;
2190 } 2199 }
2191 2200
2192 static void irc_file_transfer_data_chunk(struct gaim_connection *gc, struct file_transfer *xfer, const char *data, int len) { 2201 static void irc_file_transfer_data_chunk(struct gaim_connection *gc, struct file_transfer *xfer, const char *data, int len) {
2193 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); 2202 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer);
2194 guint32 pos; 2203 guint32 pos;
2268 printf("Trying: %s\n", buf); 2277 printf("Trying: %s\n", buf);
2269 irc_send_im (gc, ift->sn, buf, -1, 0); 2278 irc_send_im (gc, ift->sn, buf, -1, 0);
2270 } 2279 }
2271 2280
2272 static void irc_file_transfer_in(struct gaim_connection *gc, 2281 static void irc_file_transfer_in(struct gaim_connection *gc,
2273 struct file_transfer *xfer, int offset) { 2282 struct file_transfer *xfer, int offset) {
2274 2283
2275 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); 2284 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer);
2276 2285
2277 ift->xfer = xfer; 2286 ift->xfer = xfer;
2278 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); 2287 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift);
2309 chat = g_new0 (struct dcc_chat, 1); 2318 chat = g_new0 (struct dcc_chat, 1);
2310 chat->fd = socket (AF_INET, SOCK_STREAM, 0); 2319 chat->fd = socket (AF_INET, SOCK_STREAM, 0);
2311 chat->gc = gc; 2320 chat->gc = gc;
2312 g_snprintf (chat->nick, sizeof (chat->nick), "%s", who); 2321 g_snprintf (chat->nick, sizeof (chat->nick), "%s", who);
2313 if (chat->fd < 0) { 2322 if (chat->fd < 0) {
2314 dcc_chat_cancel (NULL,chat); 2323 dcc_chat_cancel (NULL,chat);
2315 return; 2324 return;
2316 } 2325 }
2317 addr.sin_family = AF_INET; 2326 addr.sin_family = AF_INET;
2318 addr.sin_port = 0; 2327 addr.sin_port = 0;
2319 addr.sin_addr.s_addr = INADDR_ANY; 2328 addr.sin_addr.s_addr = INADDR_ANY;
2320 bind (chat->fd, (struct sockaddr *) &addr, sizeof (addr)); 2329 bind (chat->fd, (struct sockaddr *) &addr, sizeof (addr));
2323 getsockname (chat->fd, (struct sockaddr *) &addr, &len); 2332 getsockname (chat->fd, (struct sockaddr *) &addr, &len);
2324 chat->port = ntohs (addr.sin_port); 2333 chat->port = ntohs (addr.sin_port);
2325 getlocalip(chat->ip_address); 2334 getlocalip(chat->ip_address);
2326 chat->inpa = 2335 chat->inpa =
2327 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_connected, 2336 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_connected,
2328 chat); 2337 chat);
2329 g_snprintf (buf, sizeof buf, "\001DCC CHAT chat %s %d\001\n", 2338 g_snprintf (buf, sizeof buf, "\001DCC CHAT chat %s %d\001\n",
2330 chat->ip_address, chat->port); 2339 chat->ip_address, chat->port);
2331 irc_send_im (gc, who, buf, -1, 0); 2340 irc_send_im (gc, who, buf, -1, 0);
2332 } 2341 }
2333 2342
2334 static void irc_get_info(struct gaim_connection *gc, char *who) 2343 static void irc_get_info(struct gaim_connection *gc, char *who)
2335 { 2344 {
2359 pbm = g_new0(struct proto_buddy_menu, 1); 2368 pbm = g_new0(struct proto_buddy_menu, 1);
2360 pbm->label = _("DCC Chat"); 2369 pbm->label = _("DCC Chat");
2361 pbm->callback = irc_start_chat; 2370 pbm->callback = irc_start_chat;
2362 pbm->gc = gc; 2371 pbm->gc = gc;
2363 m = g_list_append(m, pbm); 2372 m = g_list_append(m, pbm);
2364 /* 2373 /*
2365 pbm = g_new0(struct proto_buddy_menu, 1); 2374 pbm = g_new0(struct proto_buddy_menu, 1);
2366 pbm->label = _("DCC Send"); 2375 pbm->label = _("DCC Send");
2367 pbm->callback = irc_ask_send_file; 2376 pbm->callback = irc_ask_send_file;
2368 pbm->gc = gc; 2377 pbm->gc = gc;
2369 m = g_list_append(m, pbm); 2378 m = g_list_append(m, pbm);
2370 */ 2379 */
2371 2380
2372 pbm = g_new0(struct proto_buddy_menu, 1); 2381 pbm = g_new0(struct proto_buddy_menu, 1);
2373 pbm->label = _("CTCP ClientInfo"); 2382 pbm->label = _("CTCP ClientInfo");
2374 pbm->callback = irc_ctcp_clientinfo; 2383 pbm->callback = irc_ctcp_clientinfo;
2375 pbm->gc = gc; 2384 pbm->gc = gc;