Mercurial > pidgin
comparison libpurple/protocols/irc/irc.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | fa666e7f747e |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
66 { | 66 { |
67 PurpleConnection *gc = (PurpleConnection *) action->context; | 67 PurpleConnection *gc = (PurpleConnection *) action->context; |
68 struct irc_conn *irc; | 68 struct irc_conn *irc; |
69 char *title; | 69 char *title; |
70 | 70 |
71 if (gc == NULL || gc->proto_data == NULL) { | 71 if (gc == NULL || purple_connection_get_protocol_data(gc) == NULL) { |
72 purple_debug(PURPLE_DEBUG_ERROR, "irc", "got MOTD request for NULL gc\n"); | 72 purple_debug(PURPLE_DEBUG_ERROR, "irc", "got MOTD request for NULL gc\n"); |
73 return; | 73 return; |
74 } | 74 } |
75 irc = gc->proto_data; | 75 irc = purple_connection_get_protocol_data(gc); |
76 if (irc->motd == NULL) { | 76 if (irc->motd == NULL) { |
77 purple_notify_error(gc, _("Error displaying MOTD"), _("No MOTD available"), | 77 purple_notify_error(gc, _("Error displaying MOTD"), _("No MOTD available"), |
78 _("There is no MOTD associated with this connection.")); | 78 _("There is no MOTD associated with this connection.")); |
79 return; | 79 return; |
80 } | 80 } |
96 return ret; | 96 return ret; |
97 } | 97 } |
98 | 98 |
99 static int irc_send_raw(PurpleConnection *gc, const char *buf, int len) | 99 static int irc_send_raw(PurpleConnection *gc, const char *buf, int len) |
100 { | 100 { |
101 struct irc_conn *irc = (struct irc_conn*)gc->proto_data; | 101 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
102 if (len == -1) { | 102 if (len == -1) { |
103 len = strlen(buf); | 103 len = strlen(buf); |
104 } | 104 } |
105 irc_send_len(irc, buf, len); | 105 irc_send_len(irc, buf, len); |
106 return len; | 106 return len; |
126 return; | 126 return; |
127 else if (ret <= 0) { | 127 else if (ret <= 0) { |
128 PurpleConnection *gc = purple_account_get_connection(irc->account); | 128 PurpleConnection *gc = purple_account_get_connection(irc->account); |
129 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), | 129 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
130 g_strerror(errno)); | 130 g_strerror(errno)); |
131 purple_connection_error_reason (gc, | 131 purple_connection_error (gc, |
132 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | 132 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
133 g_free(tmp); | 133 g_free(tmp); |
134 return; | 134 return; |
135 } | 135 } |
136 | 136 |
170 irc->gsc ? " (ssl)" : "", tosend); */ | 170 irc->gsc ? " (ssl)" : "", tosend); */ |
171 if (ret <= 0 && errno != EAGAIN) { | 171 if (ret <= 0 && errno != EAGAIN) { |
172 PurpleConnection *gc = purple_account_get_connection(irc->account); | 172 PurpleConnection *gc = purple_account_get_connection(irc->account); |
173 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), | 173 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
174 g_strerror(errno)); | 174 g_strerror(errno)); |
175 purple_connection_error_reason (gc, | 175 purple_connection_error (gc, |
176 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | 176 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
177 g_free(tmp); | 177 g_free(tmp); |
178 } else if (ret < buflen) { | 178 } else if (ret < buflen) { |
179 if (ret < 0) | 179 if (ret < 0) |
180 ret = 0; | 180 ret = 0; |
329 struct irc_conn *irc; | 329 struct irc_conn *irc; |
330 char **userparts; | 330 char **userparts; |
331 const char *username = purple_account_get_username(account); | 331 const char *username = purple_account_get_username(account); |
332 | 332 |
333 gc = purple_account_get_connection(account); | 333 gc = purple_account_get_connection(account); |
334 gc->flags |= PURPLE_CONNECTION_NO_NEWLINES; | 334 purple_connection_set_flags(gc, PURPLE_CONNECTION_NO_NEWLINES); |
335 | 335 |
336 if (strpbrk(username, " \t\v\r\n") != NULL) { | 336 if (strpbrk(username, " \t\v\r\n") != NULL) { |
337 purple_connection_error_reason (gc, | 337 purple_connection_error (gc, |
338 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, | 338 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, |
339 _("IRC nick and server may not contain whitespace")); | 339 _("IRC nick and server may not contain whitespace")); |
340 return; | 340 return; |
341 } | 341 } |
342 | 342 |
343 gc->proto_data = irc = g_new0(struct irc_conn, 1); | 343 irc = g_new0(struct irc_conn, 1); |
344 purple_connection_set_protocol_data(gc, irc); | |
344 irc->fd = -1; | 345 irc->fd = -1; |
345 irc->account = account; | 346 irc->account = account; |
346 irc->outbuf = purple_circ_buffer_new(512); | 347 irc->outbuf = purple_circ_buffer_new(512); |
347 | 348 |
348 userparts = g_strsplit(username, "@", 2); | 349 userparts = g_strsplit(username, "@", 2); |
363 if (purple_ssl_is_supported()) { | 364 if (purple_ssl_is_supported()) { |
364 irc->gsc = purple_ssl_connect(account, irc->server, | 365 irc->gsc = purple_ssl_connect(account, irc->server, |
365 purple_account_get_int(account, "port", IRC_DEFAULT_SSL_PORT), | 366 purple_account_get_int(account, "port", IRC_DEFAULT_SSL_PORT), |
366 irc_login_cb_ssl, irc_ssl_connect_failure, gc); | 367 irc_login_cb_ssl, irc_ssl_connect_failure, gc); |
367 } else { | 368 } else { |
368 purple_connection_error_reason (gc, | 369 purple_connection_error (gc, |
369 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, | 370 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
370 _("SSL support unavailable")); | 371 _("SSL support unavailable")); |
371 return; | 372 return; |
372 } | 373 } |
373 } | 374 } |
376 | 377 |
377 if (purple_proxy_connect(gc, account, irc->server, | 378 if (purple_proxy_connect(gc, account, irc->server, |
378 purple_account_get_int(account, "port", IRC_DEFAULT_PORT), | 379 purple_account_get_int(account, "port", IRC_DEFAULT_PORT), |
379 irc_login_cb, gc) == NULL) | 380 irc_login_cb, gc) == NULL) |
380 { | 381 { |
381 purple_connection_error_reason (gc, | 382 purple_connection_error (gc, |
382 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 383 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
383 _("Unable to connect")); | 384 _("Unable to connect")); |
384 return; | 385 return; |
385 } | 386 } |
386 } | 387 } |
388 | 389 |
389 static gboolean do_login(PurpleConnection *gc) { | 390 static gboolean do_login(PurpleConnection *gc) { |
390 char *buf, *tmp = NULL; | 391 char *buf, *tmp = NULL; |
391 char *server; | 392 char *server; |
392 const char *username, *realname; | 393 const char *username, *realname; |
393 struct irc_conn *irc = gc->proto_data; | 394 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
394 const char *pass = purple_connection_get_password(gc); | 395 const char *pass = purple_connection_get_password(gc); |
395 | 396 |
396 if (pass && *pass) { | 397 if (pass && *pass) { |
397 buf = irc_format(irc, "v:", "PASS", pass); | 398 buf = irc_format(irc, "v:", "PASS", pass); |
398 if (irc_send(irc, buf) < 0) { | 399 if (irc_send(irc, buf) < 0) { |
458 } | 459 } |
459 | 460 |
460 static void irc_login_cb(gpointer data, gint source, const gchar *error_message) | 461 static void irc_login_cb(gpointer data, gint source, const gchar *error_message) |
461 { | 462 { |
462 PurpleConnection *gc = data; | 463 PurpleConnection *gc = data; |
463 struct irc_conn *irc = gc->proto_data; | 464 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
464 | 465 |
465 if (source < 0) { | 466 if (source < 0) { |
466 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), | 467 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), |
467 error_message); | 468 error_message); |
468 purple_connection_error_reason (gc, | 469 purple_connection_error (gc, |
469 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | 470 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
470 g_free(tmp); | 471 g_free(tmp); |
471 return; | 472 return; |
472 } | 473 } |
473 | 474 |
474 irc->fd = source; | 475 irc->fd = source; |
475 | 476 |
476 if (do_login(gc)) { | 477 if (do_login(gc)) { |
477 gc->inpa = purple_input_add(irc->fd, PURPLE_INPUT_READ, irc_input_cb, gc); | 478 irc->inpa = purple_input_add(irc->fd, PURPLE_INPUT_READ, irc_input_cb, gc); |
478 } | 479 } |
479 } | 480 } |
480 | 481 |
481 static void | 482 static void |
482 irc_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error, | 483 irc_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error, |
483 gpointer data) | 484 gpointer data) |
484 { | 485 { |
485 PurpleConnection *gc = data; | 486 PurpleConnection *gc = data; |
486 struct irc_conn *irc = gc->proto_data; | 487 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
487 | 488 |
488 irc->gsc = NULL; | 489 irc->gsc = NULL; |
489 | 490 |
490 purple_connection_ssl_error (gc, error); | 491 purple_connection_ssl_error (gc, error); |
491 } | 492 } |
492 | 493 |
493 static void irc_close(PurpleConnection *gc) | 494 static void irc_close(PurpleConnection *gc) |
494 { | 495 { |
495 struct irc_conn *irc = gc->proto_data; | 496 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
496 | 497 |
497 if (irc == NULL) | 498 if (irc == NULL) |
498 return; | 499 return; |
499 | 500 |
500 if (irc->gsc || (irc->fd >= 0)) | 501 if (irc->gsc || (irc->fd >= 0)) |
501 irc_cmd_quit(irc, "quit", NULL, NULL); | 502 irc_cmd_quit(irc, "quit", NULL, NULL); |
502 | 503 |
503 if (gc->inpa) | 504 if (irc->inpa) { |
504 purple_input_remove(gc->inpa); | 505 purple_input_remove(irc->inpa); |
506 irc->inpa = 0; | |
507 } | |
505 | 508 |
506 g_free(irc->inbuf); | 509 g_free(irc->inbuf); |
507 if (irc->gsc) { | 510 if (irc->gsc) { |
508 purple_ssl_close(irc->gsc); | 511 purple_ssl_close(irc->gsc); |
509 } else if (irc->fd >= 0) { | 512 } else if (irc->fd >= 0) { |
529 g_free(irc); | 532 g_free(irc); |
530 } | 533 } |
531 | 534 |
532 static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) | 535 static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) |
533 { | 536 { |
534 struct irc_conn *irc = gc->proto_data; | 537 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
535 char *plain; | 538 char *plain; |
536 const char *args[2]; | 539 const char *args[2]; |
537 | 540 |
538 args[0] = irc_nick_skip_mode(irc, who); | 541 args[0] = irc_nick_skip_mode(irc, who); |
539 | 542 |
545 return 1; | 548 return 1; |
546 } | 549 } |
547 | 550 |
548 static void irc_get_info(PurpleConnection *gc, const char *who) | 551 static void irc_get_info(PurpleConnection *gc, const char *who) |
549 { | 552 { |
550 struct irc_conn *irc = gc->proto_data; | 553 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
551 const char *args[2]; | 554 const char *args[2]; |
552 args[0] = who; | 555 args[0] = who; |
553 args[1] = NULL; | 556 args[1] = NULL; |
554 irc_cmd_whois(irc, "whois", NULL, args); | 557 irc_cmd_whois(irc, "whois", NULL, args); |
555 } | 558 } |
560 struct irc_conn *irc; | 563 struct irc_conn *irc; |
561 const char *args[1]; | 564 const char *args[1]; |
562 const char *status_id = purple_status_get_id(status); | 565 const char *status_id = purple_status_get_id(status); |
563 | 566 |
564 g_return_if_fail(gc != NULL); | 567 g_return_if_fail(gc != NULL); |
565 irc = gc->proto_data; | 568 irc = purple_connection_get_protocol_data(gc); |
566 | 569 |
567 if (!purple_status_is_active(status)) | 570 if (!purple_status_is_active(status)) |
568 return; | 571 return; |
569 | 572 |
570 args[0] = NULL; | 573 args[0] = NULL; |
577 } else if (!strcmp(status_id, "available")) { | 580 } else if (!strcmp(status_id, "available")) { |
578 irc_cmd_away(irc, "back", NULL, args); | 581 irc_cmd_away(irc, "back", NULL, args); |
579 } | 582 } |
580 } | 583 } |
581 | 584 |
582 static void irc_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) | 585 static void irc_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message) |
583 { | 586 { |
584 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; | 587 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
585 struct irc_buddy *ib; | 588 struct irc_buddy *ib; |
586 const char *bname = purple_buddy_get_name(buddy); | 589 const char *bname = purple_buddy_get_name(buddy); |
587 | 590 |
588 ib = g_hash_table_lookup(irc->buddies, bname); | 591 ib = g_hash_table_lookup(irc->buddies, bname); |
589 if (ib != NULL) { | 592 if (ib != NULL) { |
604 irc_ison_one(irc, ib); | 607 irc_ison_one(irc, ib); |
605 } | 608 } |
606 | 609 |
607 static void irc_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) | 610 static void irc_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) |
608 { | 611 { |
609 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; | 612 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
610 struct irc_buddy *ib; | 613 struct irc_buddy *ib; |
611 | 614 |
612 ib = g_hash_table_lookup(irc->buddies, purple_buddy_get_name(buddy)); | 615 ib = g_hash_table_lookup(irc->buddies, purple_buddy_get_name(buddy)); |
613 if (ib && --ib->ref == 0) { | 616 if (ib && --ib->ref == 0) { |
614 g_hash_table_remove(irc->buddies, purple_buddy_get_name(buddy)); | 617 g_hash_table_remove(irc->buddies, purple_buddy_get_name(buddy)); |
615 } | 618 } |
616 } | 619 } |
617 | 620 |
618 static void read_input(struct irc_conn *irc, int len) | 621 static void read_input(struct irc_conn *irc, int len) |
619 { | 622 { |
623 PurpleConnection *connection = purple_account_get_connection(irc->account); | |
620 char *cur, *end; | 624 char *cur, *end; |
621 | 625 |
622 irc->account->gc->last_received = time(NULL); | 626 purple_connection_update_last_received(connection); |
623 irc->inbufused += len; | 627 irc->inbufused += len; |
624 irc->inbuf[irc->inbufused] = '\0'; | 628 irc->inbuf[irc->inbufused] = '\0'; |
625 | 629 |
626 cur = irc->inbuf; | 630 cur = irc->inbuf; |
627 | 631 |
649 static void irc_input_cb_ssl(gpointer data, PurpleSslConnection *gsc, | 653 static void irc_input_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
650 PurpleInputCondition cond) | 654 PurpleInputCondition cond) |
651 { | 655 { |
652 | 656 |
653 PurpleConnection *gc = data; | 657 PurpleConnection *gc = data; |
654 struct irc_conn *irc = gc->proto_data; | 658 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
655 int len; | 659 int len; |
656 | 660 |
657 if(!g_list_find(purple_connections_get_all(), gc)) { | 661 if(!g_list_find(purple_connections_get_all(), gc)) { |
658 purple_ssl_close(gsc); | 662 purple_ssl_close(gsc); |
659 return; | 663 return; |
670 /* Try again later */ | 674 /* Try again later */ |
671 return; | 675 return; |
672 } else if (len < 0) { | 676 } else if (len < 0) { |
673 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), | 677 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
674 g_strerror(errno)); | 678 g_strerror(errno)); |
675 purple_connection_error_reason (gc, | 679 purple_connection_error (gc, |
676 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | 680 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
677 g_free(tmp); | 681 g_free(tmp); |
678 return; | 682 return; |
679 } else if (len == 0) { | 683 } else if (len == 0) { |
680 purple_connection_error_reason (gc, | 684 purple_connection_error (gc, |
681 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 685 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
682 _("Server closed the connection")); | 686 _("Server closed the connection")); |
683 return; | 687 return; |
684 } | 688 } |
685 | 689 |
687 } | 691 } |
688 | 692 |
689 static void irc_input_cb(gpointer data, gint source, PurpleInputCondition cond) | 693 static void irc_input_cb(gpointer data, gint source, PurpleInputCondition cond) |
690 { | 694 { |
691 PurpleConnection *gc = data; | 695 PurpleConnection *gc = data; |
692 struct irc_conn *irc = gc->proto_data; | 696 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
693 int len; | 697 int len; |
694 | 698 |
695 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { | 699 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { |
696 irc->inbuflen += IRC_INITIAL_BUFSIZE; | 700 irc->inbuflen += IRC_INITIAL_BUFSIZE; |
697 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); | 701 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); |
701 if (len < 0 && errno == EAGAIN) { | 705 if (len < 0 && errno == EAGAIN) { |
702 return; | 706 return; |
703 } else if (len < 0) { | 707 } else if (len < 0) { |
704 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), | 708 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
705 g_strerror(errno)); | 709 g_strerror(errno)); |
706 purple_connection_error_reason (gc, | 710 purple_connection_error (gc, |
707 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); | 711 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
708 g_free(tmp); | 712 g_free(tmp); |
709 return; | 713 return; |
710 } else if (len == 0) { | 714 } else if (len == 0) { |
711 purple_connection_error_reason (gc, | 715 purple_connection_error (gc, |
712 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 716 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
713 _("Server closed the connection")); | 717 _("Server closed the connection")); |
714 return; | 718 return; |
715 } | 719 } |
716 | 720 |
717 read_input(irc, len); | 721 read_input(irc, len); |
718 } | 722 } |
719 | 723 |
720 static void irc_chat_join (PurpleConnection *gc, GHashTable *data) | 724 static void irc_chat_join (PurpleConnection *gc, GHashTable *data) |
721 { | 725 { |
722 struct irc_conn *irc = gc->proto_data; | 726 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
723 const char *args[2]; | 727 const char *args[2]; |
724 | 728 |
725 args[0] = g_hash_table_lookup(data, "channel"); | 729 args[0] = g_hash_table_lookup(data, "channel"); |
726 args[1] = g_hash_table_lookup(data, "password"); | 730 args[1] = g_hash_table_lookup(data, "password"); |
727 irc_cmd_join(irc, "join", NULL, args); | 731 irc_cmd_join(irc, "join", NULL, args); |
731 return g_strdup(g_hash_table_lookup(data, "channel")); | 735 return g_strdup(g_hash_table_lookup(data, "channel")); |
732 } | 736 } |
733 | 737 |
734 static void irc_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name) | 738 static void irc_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name) |
735 { | 739 { |
736 struct irc_conn *irc = gc->proto_data; | 740 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
737 PurpleConversation *convo = purple_find_chat(gc, id); | 741 PurpleConversation *convo = purple_find_chat(gc, id); |
738 const char *args[2]; | 742 const char *args[2]; |
739 | 743 |
740 if (!convo) { | 744 if (!convo) { |
741 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); | 745 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); |
747 } | 751 } |
748 | 752 |
749 | 753 |
750 static void irc_chat_leave (PurpleConnection *gc, int id) | 754 static void irc_chat_leave (PurpleConnection *gc, int id) |
751 { | 755 { |
752 struct irc_conn *irc = gc->proto_data; | 756 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
753 PurpleConversation *convo = purple_find_chat(gc, id); | 757 PurpleConversation *convo = purple_find_chat(gc, id); |
754 const char *args[2]; | 758 const char *args[2]; |
755 | 759 |
756 if (!convo) | 760 if (!convo) |
757 return; | 761 return; |
762 serv_got_chat_left(gc, id); | 766 serv_got_chat_left(gc, id); |
763 } | 767 } |
764 | 768 |
765 static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags) | 769 static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags) |
766 { | 770 { |
767 struct irc_conn *irc = gc->proto_data; | 771 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
768 PurpleConversation *convo = purple_find_chat(gc, id); | 772 PurpleConversation *convo = purple_find_chat(gc, id); |
769 const char *args[2]; | 773 const char *args[2]; |
770 char *tmp; | 774 char *tmp; |
771 | 775 |
772 if (!convo) { | 776 if (!convo) { |
777 if (*what == '/') { | 781 if (*what == '/') { |
778 return irc_parse_cmd(irc, convo->name, what + 1); | 782 return irc_parse_cmd(irc, convo->name, what + 1); |
779 } | 783 } |
780 #endif | 784 #endif |
781 purple_markup_html_to_xhtml(what, NULL, &tmp); | 785 purple_markup_html_to_xhtml(what, NULL, &tmp); |
782 args[0] = convo->name; | 786 args[0] = purple_conversation_get_name(convo); |
783 args[1] = tmp; | 787 args[1] = tmp; |
784 | 788 |
785 irc_cmd_privmsg(irc, "msg", NULL, args); | 789 irc_cmd_privmsg(irc, "msg", NULL, args); |
786 | 790 |
787 serv_got_chat_in(gc, id, purple_connection_get_display_name(gc), flags, what, time(NULL)); | 791 serv_got_chat_in(gc, id, purple_connection_get_display_name(gc), flags, what, time(NULL)); |
816 { | 820 { |
817 char *buf; | 821 char *buf; |
818 const char *name = NULL; | 822 const char *name = NULL; |
819 struct irc_conn *irc; | 823 struct irc_conn *irc; |
820 | 824 |
821 irc = gc->proto_data; | 825 irc = purple_connection_get_protocol_data(gc); |
822 name = purple_conversation_get_name(purple_find_chat(gc, id)); | 826 name = purple_conversation_get_name(purple_find_chat(gc, id)); |
823 | 827 |
824 if (name == NULL) | 828 if (name == NULL) |
825 return; | 829 return; |
826 | 830 |
834 struct irc_conn *irc; | 838 struct irc_conn *irc; |
835 GList *fields = NULL; | 839 GList *fields = NULL; |
836 PurpleRoomlistField *f; | 840 PurpleRoomlistField *f; |
837 char *buf; | 841 char *buf; |
838 | 842 |
839 irc = gc->proto_data; | 843 irc = purple_connection_get_protocol_data(gc); |
840 | 844 |
841 if (irc->roomlist) | 845 if (irc->roomlist) |
842 purple_roomlist_unref(irc->roomlist); | 846 purple_roomlist_unref(irc->roomlist); |
843 | 847 |
844 irc->roomlist = purple_roomlist_new(purple_connection_get_account(gc)); | 848 irc->roomlist = purple_roomlist_new(purple_connection_get_account(gc)); |
861 return irc->roomlist; | 865 return irc->roomlist; |
862 } | 866 } |
863 | 867 |
864 static void irc_roomlist_cancel(PurpleRoomlist *list) | 868 static void irc_roomlist_cancel(PurpleRoomlist *list) |
865 { | 869 { |
866 PurpleConnection *gc = purple_account_get_connection(list->account); | 870 PurpleAccount *account = purple_roomlist_get_account(list); |
871 PurpleConnection *gc = purple_account_get_connection(account); | |
867 struct irc_conn *irc; | 872 struct irc_conn *irc; |
868 | 873 |
869 if (gc == NULL) | 874 if (gc == NULL) |
870 return; | 875 return; |
871 | 876 |
872 irc = gc->proto_data; | 877 irc = purple_connection_get_protocol_data(gc); |
873 | 878 |
874 purple_roomlist_set_in_progress(list, FALSE); | 879 purple_roomlist_set_in_progress(list, FALSE); |
875 | 880 |
876 if (irc->roomlist == list) { | 881 if (irc->roomlist == list) { |
877 irc->roomlist = NULL; | 882 irc->roomlist = NULL; |
879 } | 884 } |
880 } | 885 } |
881 | 886 |
882 static void irc_keepalive(PurpleConnection *gc) | 887 static void irc_keepalive(PurpleConnection *gc) |
883 { | 888 { |
884 struct irc_conn *irc = gc->proto_data; | 889 struct irc_conn *irc = purple_connection_get_protocol_data(gc); |
885 if ((time(NULL) - irc->recv_time) > PING_TIMEOUT) | 890 if ((time(NULL) - irc->recv_time) > PING_TIMEOUT) |
886 irc_cmd_ping(irc, NULL, NULL, NULL); | 891 irc_cmd_ping(irc, NULL, NULL, NULL); |
887 } | 892 } |
888 | 893 |
889 static PurplePluginProtocolInfo prpl_info = | 894 static PurplePluginProtocolInfo prpl_info = |
890 { | 895 { |
896 sizeof(PurplePluginProtocolInfo), /* struct_size */ | |
891 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL | | 897 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL | |
892 OPT_PROTO_SLASH_COMMANDS_NATIVE, | 898 OPT_PROTO_SLASH_COMMANDS_NATIVE, |
893 NULL, /* user_splits */ | 899 NULL, /* user_splits */ |
894 NULL, /* protocol_options */ | 900 NULL, /* protocol_options */ |
895 NO_BUDDY_ICONS, /* icon_spec */ | 901 NO_BUDDY_ICONS, /* icon_spec */ |
927 NULL, /* chat_whisper */ | 933 NULL, /* chat_whisper */ |
928 irc_chat_send, /* chat_send */ | 934 irc_chat_send, /* chat_send */ |
929 irc_keepalive, /* keepalive */ | 935 irc_keepalive, /* keepalive */ |
930 NULL, /* register_user */ | 936 NULL, /* register_user */ |
931 NULL, /* get_cb_info */ | 937 NULL, /* get_cb_info */ |
932 NULL, /* get_cb_away */ | |
933 NULL, /* alias_buddy */ | 938 NULL, /* alias_buddy */ |
934 NULL, /* group_buddy */ | 939 NULL, /* group_buddy */ |
935 NULL, /* rename_group */ | 940 NULL, /* rename_group */ |
936 NULL, /* buddy_free */ | 941 NULL, /* buddy_free */ |
937 NULL, /* convo_closed */ | 942 NULL, /* convo_closed */ |
952 irc_send_raw, /* send_raw */ | 957 irc_send_raw, /* send_raw */ |
953 NULL, /* roomlist_room_serialize */ | 958 NULL, /* roomlist_room_serialize */ |
954 NULL, /* unregister_user */ | 959 NULL, /* unregister_user */ |
955 NULL, /* send_attention */ | 960 NULL, /* send_attention */ |
956 NULL, /* get_attention_types */ | 961 NULL, /* get_attention_types */ |
957 sizeof(PurplePluginProtocolInfo), /* struct_size */ | |
958 NULL, /* get_account_text_table */ | 962 NULL, /* get_account_text_table */ |
959 NULL, /* initiate_media */ | 963 NULL, /* initiate_media */ |
960 NULL, /* get_media_caps */ | 964 NULL, /* get_media_caps */ |
961 NULL, /* get_moods */ | 965 NULL, /* get_moods */ |
962 NULL, /* set_public_alias */ | 966 NULL, /* set_public_alias */ |
963 NULL, /* get_public_alias */ | 967 NULL /* get_public_alias */ |
964 NULL, /* add_buddy_with_invite */ | |
965 NULL /* add_buddies_with_invite */ | |
966 }; | 968 }; |
967 | 969 |
968 static gboolean load_plugin (PurplePlugin *plugin) { | 970 static gboolean load_plugin (PurplePlugin *plugin) { |
969 | 971 |
970 purple_signal_register(plugin, "irc-sending-text", | 972 purple_signal_register(plugin, "irc-sending-text", |