comparison libpurple/protocols/jabber/jabber.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 3b1070cb4f29
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
117 if (type == JABBER_IQ_RESULT) { 117 if (type == JABBER_IQ_RESULT) {
118 jabber_disco_items_server(js); 118 jabber_disco_items_server(js);
119 if(js->unregistration) 119 if(js->unregistration)
120 jabber_unregister_account_cb(js); 120 jabber_unregister_account_cb(js);
121 } else { 121 } else {
122 purple_connection_error_reason(js->gc, 122 purple_connection_error(js->gc,
123 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 123 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
124 ("Error initializing session")); 124 ("Error initializing session"));
125 } 125 }
126 } 126 }
127 127
151 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { 151 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) {
152 jabber_id_free(js->user); 152 jabber_id_free(js->user);
153 153
154 js->user = jabber_id_new(full_jid); 154 js->user = jabber_id_new(full_jid);
155 if (js->user == NULL) { 155 if (js->user == NULL) {
156 purple_connection_error_reason(js->gc, 156 purple_connection_error(js->gc,
157 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 157 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
158 _("Invalid response from server")); 158 _("Invalid response from server"));
159 g_free(full_jid); 159 g_free(full_jid);
160 return; 160 return;
161 } 161 }
168 g_free(full_jid); 168 g_free(full_jid);
169 } 169 }
170 } else { 170 } else {
171 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; 171 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
172 char *msg = jabber_parse_error(js, packet, &reason); 172 char *msg = jabber_parse_error(js, packet, &reason);
173 purple_connection_error_reason(js->gc, reason, msg); 173 purple_connection_error(js->gc, reason, msg);
174 g_free(msg); 174 g_free(msg);
175 175
176 return; 176 return;
177 } 177 }
178 178
245 } 245 }
246 #endif 246 #endif
247 247
248 starttls = xmlnode_get_child(packet, "starttls"); 248 starttls = xmlnode_get_child(packet, "starttls");
249 if(xmlnode_get_child(starttls, "required")) { 249 if(xmlnode_get_child(starttls, "required")) {
250 purple_connection_error_reason(js->gc, 250 purple_connection_error(js->gc,
251 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, 251 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
252 _("Server requires TLS/SSL, but no TLS/SSL support was found.")); 252 _("Server requires TLS/SSL, but no TLS/SSL support was found."));
253 return TRUE; 253 return TRUE;
254 } 254 }
255 255
256 if (g_str_equal("require_tls", purple_account_get_string(account, "connection_security", JABBER_DEFAULT_REQUIRE_TLS))) { 256 if (g_str_equal("require_tls", purple_account_get_string(account, "connection_security", JABBER_DEFAULT_REQUIRE_TLS))) {
257 purple_connection_error_reason(js->gc, 257 purple_connection_error(js->gc,
258 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, 258 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
259 _("You require encryption, but no TLS/SSL support was found.")); 259 _("You require encryption, but no TLS/SSL support was found."));
260 return TRUE; 260 return TRUE;
261 } 261 }
262 262
273 if (jabber_process_starttls(js, packet)) { 273 if (jabber_process_starttls(js, packet)) {
274 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING_ENCRYPTION); 274 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING_ENCRYPTION);
275 return; 275 return;
276 } 276 }
277 } else if (g_str_equal(connection_security, "require_tls") && !jabber_stream_is_ssl(js)) { 277 } else if (g_str_equal(connection_security, "require_tls") && !jabber_stream_is_ssl(js)) {
278 purple_connection_error_reason(js->gc, 278 purple_connection_error(js->gc,
279 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, 279 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR,
280 _("You require encryption, but it is not available on this server.")); 280 _("You require encryption, but it is not available on this server."));
281 return; 281 return;
282 } 282 }
283 283
318 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) 318 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet)
319 { 319 {
320 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; 320 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
321 char *msg = jabber_parse_error(js, packet, &reason); 321 char *msg = jabber_parse_error(js, packet, &reason);
322 322
323 purple_connection_error_reason(js->gc, reason, msg); 323 purple_connection_error(js->gc, reason, msg);
324 324
325 g_free(msg); 325 g_free(msg);
326 } 326 }
327 327
328 static void tls_init(JabberStream *js); 328 static void tls_init(JabberStream *js);
405 if (ret < 0 && errno == EAGAIN) 405 if (ret < 0 && errno == EAGAIN)
406 return; 406 return;
407 else if (ret <= 0) { 407 else if (ret <= 0) {
408 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), 408 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"),
409 g_strerror(errno)); 409 g_strerror(errno));
410 purple_connection_error_reason(js->gc, 410 purple_connection_error(js->gc,
411 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 411 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
412 g_free(tmp); 412 g_free(tmp);
413 return; 413 return;
414 } 414 }
415 415
438 /* 438 /*
439 * The server may have closed the socket (on a stream error), so if 439 * The server may have closed the socket (on a stream error), so if
440 * we're disconnecting, don't generate (possibly another) error that 440 * we're disconnecting, don't generate (possibly another) error that
441 * (for some UIs) would mask the first. 441 * (for some UIs) would mask the first.
442 */ 442 */
443 if (!account->disconnecting) { 443 if (!purple_account_is_disconnecting(account)) {
444 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), 444 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"),
445 g_strerror(errno)); 445 g_strerror(errno));
446 purple_connection_error_reason(js->gc, 446 purple_connection_error(js->gc,
447 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 447 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
448 g_free(tmp); 448 g_free(tmp);
449 } 449 }
450 450
451 success = FALSE; 451 success = FALSE;
542 g_strdup_printf(_("SASL error: %s"), 542 g_strdup_printf(_("SASL error: %s"),
543 sasl_errdetail(js->sasl)); 543 sasl_errdetail(js->sasl));
544 purple_debug_error("jabber", 544 purple_debug_error("jabber",
545 "sasl_encode error %d: %s\n", rc, 545 "sasl_encode error %d: %s\n", rc,
546 sasl_errdetail(js->sasl)); 546 sasl_errdetail(js->sasl));
547 purple_connection_error_reason(gc, 547 purple_connection_error(gc,
548 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 548 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
549 error); 549 error);
550 g_free(error); 550 g_free(error);
551 return; 551 return;
552 } 552 }
614 purple_signal_emit(purple_connection_get_prpl(js->gc), "jabber-sending-xmlnode", js->gc, &packet); 614 purple_signal_emit(purple_connection_get_prpl(js->gc), "jabber-sending-xmlnode", js->gc, &packet);
615 } 615 }
616 616
617 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) 617 static gboolean jabber_keepalive_timeout(PurpleConnection *gc)
618 { 618 {
619 JabberStream *js = gc->proto_data; 619 JabberStream *js = purple_connection_get_protocol_data(gc);
620 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 620 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
621 _("Ping timed out")); 621 _("Ping timed out"));
622 js->keepalive_timeout = 0; 622 js->keepalive_timeout = 0;
623 return FALSE; 623 return FALSE;
624 } 624 }
625 625
640 static void 640 static void
641 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, 641 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc,
642 PurpleInputCondition cond) 642 PurpleInputCondition cond)
643 { 643 {
644 PurpleConnection *gc = data; 644 PurpleConnection *gc = data;
645 JabberStream *js = gc->proto_data; 645 JabberStream *js = purple_connection_get_protocol_data(gc);
646 int len; 646 int len;
647 static char buf[4096]; 647 static char buf[4096];
648 648
649 /* TODO: It should be possible to make this check unnecessary */ 649 /* TODO: It should be possible to make this check unnecessary */
650 if(!PURPLE_CONNECTION_IS_VALID(gc)) { 650 if(!PURPLE_CONNECTION_IS_VALID(gc)) {
651 purple_ssl_close(gsc); 651 purple_ssl_close(gsc);
652 g_return_if_reached(); 652 g_return_if_reached();
653 } 653 }
654 654
655 while((len = purple_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) { 655 while((len = purple_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) {
656 gc->last_received = time(NULL); 656 purple_connection_update_last_received(gc);
657 buf[len] = '\0'; 657 buf[len] = '\0';
658 purple_debug_info("jabber", "Recv (ssl)(%d): %s\n", len, buf); 658 purple_debug_info("jabber", "Recv (ssl)(%d): %s\n", len, buf);
659 jabber_parser_process(js, buf, len); 659 jabber_parser_process(js, buf, len);
660 if(js->reinit) 660 if(js->reinit)
661 jabber_stream_init(js); 661 jabber_stream_init(js);
668 if (len == 0) 668 if (len == 0)
669 tmp = g_strdup_printf(_("Server closed the connection")); 669 tmp = g_strdup_printf(_("Server closed the connection"));
670 else 670 else
671 tmp = g_strdup_printf(_("Lost connection with server: %s"), 671 tmp = g_strdup_printf(_("Lost connection with server: %s"),
672 g_strerror(errno)); 672 g_strerror(errno));
673 purple_connection_error_reason(js->gc, 673 purple_connection_error(js->gc,
674 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 674 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
675 g_free(tmp); 675 g_free(tmp);
676 } 676 }
677 } 677 }
678 678
685 static char buf[4096]; 685 static char buf[4096];
686 686
687 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc)); 687 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
688 688
689 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) { 689 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) {
690 gc->last_received = time(NULL); 690 purple_connection_update_last_received(gc);
691 #ifdef HAVE_CYRUS_SASL 691 #ifdef HAVE_CYRUS_SASL
692 if (js->sasl_maxbuf > 0) { 692 if (js->sasl_maxbuf > 0) {
693 const char *out; 693 const char *out;
694 unsigned int olen; 694 unsigned int olen;
695 int rc; 695 int rc;
700 g_strdup_printf(_("SASL error: %s"), 700 g_strdup_printf(_("SASL error: %s"),
701 sasl_errdetail(js->sasl)); 701 sasl_errdetail(js->sasl));
702 purple_debug_error("jabber", 702 purple_debug_error("jabber",
703 "sasl_decode_error %d: %s\n", rc, 703 "sasl_decode_error %d: %s\n", rc,
704 sasl_errdetail(js->sasl)); 704 sasl_errdetail(js->sasl));
705 purple_connection_error_reason(gc, 705 purple_connection_error(gc,
706 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 706 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
707 error); 707 error);
708 } else if (olen > 0) { 708 } else if (olen > 0) {
709 purple_debug_info("jabber", "RecvSASL (%u): %s\n", olen, out); 709 purple_debug_info("jabber", "RecvSASL (%u): %s\n", olen, out);
710 jabber_parser_process(js, out, olen); 710 jabber_parser_process(js, out, olen);
726 if (len == 0) 726 if (len == 0)
727 tmp = g_strdup_printf(_("Server closed the connection")); 727 tmp = g_strdup_printf(_("Server closed the connection"));
728 else 728 else
729 tmp = g_strdup_printf(_("Lost connection with server: %s"), 729 tmp = g_strdup_printf(_("Lost connection with server: %s"),
730 g_strerror(errno)); 730 g_strerror(errno));
731 purple_connection_error_reason(js->gc, 731 purple_connection_error(js->gc,
732 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 732 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
733 g_free(tmp); 733 g_free(tmp);
734 } 734 }
735 } 735 }
736 736
745 if(!PURPLE_CONNECTION_IS_VALID(gc)) { 745 if(!PURPLE_CONNECTION_IS_VALID(gc)) {
746 purple_ssl_close(gsc); 746 purple_ssl_close(gsc);
747 g_return_if_reached(); 747 g_return_if_reached();
748 } 748 }
749 749
750 js = gc->proto_data; 750 js = purple_connection_get_protocol_data(gc);
751 751
752 if(js->state == JABBER_STREAM_CONNECTING) 752 if(js->state == JABBER_STREAM_CONNECTING)
753 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); 753 jabber_send_raw(js, "<?xml version='1.0' ?>", -1);
754 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); 754 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING);
755 purple_ssl_input_add(gsc, jabber_recv_cb_ssl, gc); 755 purple_ssl_input_add(gsc, jabber_recv_cb_ssl, gc);
787 } 787 }
788 788
789 if (!found) { 789 if (!found) {
790 purple_debug_warning("jabber", "Unable to find alternative XMPP connection " 790 purple_debug_warning("jabber", "Unable to find alternative XMPP connection "
791 "methods after failing to connect directly.\n"); 791 "methods after failing to connect directly.\n");
792 purple_connection_error_reason(js->gc, 792 purple_connection_error(js->gc,
793 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 793 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
794 _("Unable to connect")); 794 _("Unable to connect"));
795 return; 795 return;
796 } 796 }
797 797
811 if (js->srv_rec != NULL) { 811 if (js->srv_rec != NULL) {
812 purple_debug_error("jabber", "Unable to connect to server: %s. Trying next SRV record or connecting directly.\n", error); 812 purple_debug_error("jabber", "Unable to connect to server: %s. Trying next SRV record or connecting directly.\n", error);
813 try_srv_connect(js); 813 try_srv_connect(js);
814 } else { 814 } else {
815 purple_debug_info("jabber","Couldn't connect directly to %s. Trying to find alternative connection methods, like BOSH.\n", js->user->domain); 815 purple_debug_info("jabber","Couldn't connect directly to %s. Trying to find alternative connection methods, like BOSH.\n", js->user->domain);
816 js->srv_query_data = purple_txt_resolve_account( 816 js->srv_query_data = purple_txt_resolve(
817 purple_connection_get_account(gc), "_xmppconnect", 817 purple_connection_get_account(gc), "_xmppconnect",
818 js->user->domain, txt_resolved_cb, js); 818 js->user->domain, txt_resolved_cb, js);
819 } 819 }
820 return; 820 return;
821 } 821 }
827 827
828 if(js->state == JABBER_STREAM_CONNECTING) 828 if(js->state == JABBER_STREAM_CONNECTING)
829 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); 829 jabber_send_raw(js, "<?xml version='1.0' ?>", -1);
830 830
831 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); 831 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING);
832 gc->inpa = purple_input_add(js->fd, PURPLE_INPUT_READ, jabber_recv_cb, gc); 832 js->inpa = purple_input_add(js->fd, PURPLE_INPUT_READ, jabber_recv_cb, gc);
833 } 833 }
834 834
835 static void 835 static void
836 jabber_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error, 836 jabber_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error,
837 gpointer data) 837 gpointer data)
840 JabberStream *js; 840 JabberStream *js;
841 841
842 /* If the connection is already disconnected, we don't need to do anything else */ 842 /* If the connection is already disconnected, we don't need to do anything else */
843 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc)); 843 g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
844 844
845 js = gc->proto_data; 845 js = purple_connection_get_protocol_data(gc);
846 js->gsc = NULL; 846 js->gsc = NULL;
847 847
848 purple_connection_ssl_error (gc, error); 848 purple_connection_ssl_error (gc, error);
849 } 849 }
850 850
851 static void tls_init(JabberStream *js) 851 static void tls_init(JabberStream *js)
852 { 852 {
853 purple_input_remove(js->gc->inpa); 853 purple_input_remove(js->inpa);
854 js->gc->inpa = 0; 854 js->inpa = 0;
855 js->gsc = purple_ssl_connect_with_host_fd(js->gc->account, js->fd, 855 js->gsc = purple_ssl_connect_with_host_fd(purple_connection_get_account(js->gc), js->fd,
856 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->certificate_CN, js->gc); 856 jabber_login_callback_ssl, jabber_ssl_connect_failure, js->certificate_CN, js->gc);
857 /* The fd is no longer our concern */ 857 /* The fd is no longer our concern */
858 js->fd = -1; 858 js->fd = -1;
859 } 859 }
860 860
872 js->serverFQDN = g_strdup(host); 872 js->serverFQDN = g_strdup(host);
873 873
874 if (purple_proxy_connect(js->gc, purple_connection_get_account(js->gc), 874 if (purple_proxy_connect(js->gc, purple_connection_get_account(js->gc),
875 host, port, jabber_login_callback, js->gc) == NULL) { 875 host, port, jabber_login_callback, js->gc) == NULL) {
876 if (fatal_failure) { 876 if (fatal_failure) {
877 purple_connection_error_reason(js->gc, 877 purple_connection_error(js->gc,
878 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 878 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
879 _("Unable to connect")); 879 _("Unable to connect"));
880 } 880 }
881 881
882 return FALSE; 882 return FALSE;
926 JabberStream *js; 926 JabberStream *js;
927 PurplePresence *presence; 927 PurplePresence *presence;
928 gchar *user; 928 gchar *user;
929 gchar *slash; 929 gchar *slash;
930 930
931 js = gc->proto_data = g_new0(JabberStream, 1); 931 js = g_new0(JabberStream, 1);
932 purple_connection_set_protocol_data(gc, js);
932 js->gc = gc; 933 js->gc = gc;
933 js->fd = -1; 934 js->fd = -1;
934 935
935 user = g_strdup(purple_account_get_username(account)); 936 user = g_strdup(purple_account_get_username(account));
936 /* jabber_id_new doesn't accept "user@domain/" as valid */ 937 /* jabber_id_new doesn't accept "user@domain/" as valid */
938 if (slash && *(slash + 1) == '\0') 939 if (slash && *(slash + 1) == '\0')
939 *slash = '\0'; 940 *slash = '\0';
940 js->user = jabber_id_new(user); 941 js->user = jabber_id_new(user);
941 942
942 if (!js->user) { 943 if (!js->user) {
943 purple_connection_error_reason(gc, 944 purple_connection_error(gc,
944 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 945 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
945 _("Invalid XMPP ID")); 946 _("Invalid XMPP ID"));
946 g_free(user); 947 g_free(user);
947 /* Destroying the connection will free the JabberStream */ 948 /* Destroying the connection will free the JabberStream */
948 return NULL; 949 return NULL;
949 } 950 }
950 951
951 if (!js->user->node || *(js->user->node) == '\0') { 952 if (!js->user->node || *(js->user->node) == '\0') {
952 purple_connection_error_reason(gc, 953 purple_connection_error(gc,
953 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 954 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
954 _("Invalid XMPP ID. Username portion must be set.")); 955 _("Invalid XMPP ID. Username portion must be set."));
955 g_free(user); 956 g_free(user);
956 /* Destroying the connection will free the JabberStream */ 957 /* Destroying the connection will free the JabberStream */
957 return NULL; 958 return NULL;
958 } 959 }
959 960
960 if (!js->user->domain || *(js->user->domain) == '\0') { 961 if (!js->user->domain || *(js->user->domain) == '\0') {
961 purple_connection_error_reason(gc, 962 purple_connection_error(gc,
962 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 963 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
963 _("Invalid XMPP ID. Domain must be set.")); 964 _("Invalid XMPP ID. Domain must be set."));
964 g_free(user); 965 g_free(user);
965 /* Destroying the connection will free the JabberStream */ 966 /* Destroying the connection will free the JabberStream */
966 return NULL; 967 return NULL;
976 977
977 js->user_jb = jabber_buddy_find(js, user, TRUE); 978 js->user_jb = jabber_buddy_find(js, user, TRUE);
978 g_free(user); 979 g_free(user);
979 if (!js->user_jb) { 980 if (!js->user_jb) {
980 /* This basically *can't* fail, but for good measure... */ 981 /* This basically *can't* fail, but for good measure... */
981 purple_connection_error_reason(gc, 982 purple_connection_error(gc,
982 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 983 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
983 _("Invalid XMPP ID")); 984 _("Invalid XMPP ID"));
984 /* Destroying the connection will free the JabberStream */ 985 /* Destroying the connection will free the JabberStream */
985 g_return_val_if_reached(NULL); 986 g_return_val_if_reached(NULL);
986 } 987 }
1035 if (*bosh_url) { 1036 if (*bosh_url) {
1036 js->bosh = jabber_bosh_connection_init(js, bosh_url); 1037 js->bosh = jabber_bosh_connection_init(js, bosh_url);
1037 if (js->bosh) 1038 if (js->bosh)
1038 jabber_bosh_connection_connect(js->bosh); 1039 jabber_bosh_connection_connect(js->bosh);
1039 else { 1040 else {
1040 purple_connection_error_reason(gc, 1041 purple_connection_error(gc,
1041 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 1042 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
1042 _("Malformed BOSH URL")); 1043 _("Malformed BOSH URL"));
1043 } 1044 }
1044 1045
1045 return; 1046 return;
1052 if(purple_ssl_is_supported()) { 1053 if(purple_ssl_is_supported()) {
1053 js->gsc = purple_ssl_connect(account, js->certificate_CN, 1054 js->gsc = purple_ssl_connect(account, js->certificate_CN,
1054 purple_account_get_int(account, "port", 5223), 1055 purple_account_get_int(account, "port", 5223),
1055 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc); 1056 jabber_login_callback_ssl, jabber_ssl_connect_failure, gc);
1056 if (!js->gsc) { 1057 if (!js->gsc) {
1057 purple_connection_error_reason(gc, 1058 purple_connection_error(gc,
1058 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, 1059 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
1059 _("Unable to establish SSL connection")); 1060 _("Unable to establish SSL connection"));
1060 } 1061 }
1061 } else { 1062 } else {
1062 purple_connection_error_reason(gc, 1063 purple_connection_error(gc,
1063 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, 1064 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
1064 _("SSL support unavailable")); 1065 _("SSL support unavailable"));
1065 } 1066 }
1066 1067
1067 return; 1068 return;
1071 * invoke the magic of SRV lookups, to figure out host and port */ 1072 * invoke the magic of SRV lookups, to figure out host and port */
1072 if(connect_server[0]) { 1073 if(connect_server[0]) {
1073 jabber_login_connect(js, js->user->domain, connect_server, 1074 jabber_login_connect(js, js->user->domain, connect_server,
1074 purple_account_get_int(account, "port", 5222), TRUE); 1075 purple_account_get_int(account, "port", 5222), TRUE);
1075 } else { 1076 } else {
1076 js->srv_query_data = purple_srv_resolve_account(account, "xmpp-client", 1077 js->srv_query_data = purple_srv_resolve(account, "xmpp-client",
1077 "tcp", js->user->domain, srv_resolved_cb, js); 1078 "tcp", js->user->domain, srv_resolved_cb, js);
1078 } 1079 }
1079 } 1080 }
1080 1081
1081 void 1082 void
1083 { 1084 {
1084 PurpleConnection *gc = purple_account_get_connection(account); 1085 PurpleConnection *gc = purple_account_get_connection(account);
1085 JabberStream *js; 1086 JabberStream *js;
1086 PurpleStoredImage *image; 1087 PurpleStoredImage *image;
1087 1088
1088 gc->flags |= PURPLE_CONNECTION_HTML | 1089 purple_connection_set_flags(gc, PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY);
1089 PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
1090 js = jabber_stream_new(account); 1090 js = jabber_stream_new(account);
1091 if (js == NULL) 1091 if (js == NULL)
1092 return; 1092 return;
1093 1093
1094 /* TODO: Remove this at some point. Added 2010-02-14 (v2.6.6) */ 1094 /* TODO: Remove this at some point. Added 2010-02-14 (v2.6.6) */
1142 1142
1143 if (type == JABBER_IQ_RESULT) { 1143 if (type == JABBER_IQ_RESULT) {
1144 if(js->registration) { 1144 if(js->registration) {
1145 buf = g_strdup_printf(_("Registration of %s@%s successful"), 1145 buf = g_strdup_printf(_("Registration of %s@%s successful"),
1146 js->user->node, js->user->domain); 1146 js->user->node, js->user->domain);
1147 if(account->registration_cb) 1147 purple_account_register_completed(account, TRUE);
1148 (account->registration_cb)(account, TRUE, account->registration_cb_user_data);
1149 } else { 1148 } else {
1150 g_return_if_fail(to != NULL); 1149 g_return_if_fail(to != NULL);
1151 buf = g_strdup_printf(_("Registration to %s successful"), 1150 buf = g_strdup_printf(_("Registration to %s successful"),
1152 to); 1151 to);
1153 } 1152 }
1161 msg = g_strdup(_("Unknown Error")); 1160 msg = g_strdup(_("Unknown Error"));
1162 1161
1163 purple_notify_error(NULL, _("Registration Failed"), 1162 purple_notify_error(NULL, _("Registration Failed"),
1164 _("Registration Failed"), msg); 1163 _("Registration Failed"), msg);
1165 g_free(msg); 1164 g_free(msg);
1166 if(account->registration_cb) 1165 purple_account_register_completed(account, FALSE);
1167 (account->registration_cb)(account, FALSE, account->registration_cb_user_data);
1168 } 1166 }
1169 g_free(to); 1167 g_free(to);
1170 if(js->registration) 1168 if(js->registration)
1171 jabber_connection_schedule_close(js); 1169 jabber_connection_schedule_close(js);
1172 } 1170 }
1262 if(cbdata->js->registration && !strcmp(id, "username")) { 1260 if(cbdata->js->registration && !strcmp(id, "username")) {
1263 g_free(cbdata->js->user->node); 1261 g_free(cbdata->js->user->node);
1264 cbdata->js->user->node = g_strdup(value); 1262 cbdata->js->user->node = g_strdup(value);
1265 } 1263 }
1266 if(cbdata->js->registration && !strcmp(id, "password")) 1264 if(cbdata->js->registration && !strcmp(id, "password"))
1267 purple_account_set_password(cbdata->js->gc->account, value); 1265 purple_account_set_password(purple_connection_get_account(cbdata->js->gc), value);
1268 } 1266 }
1269 } 1267 }
1270 } 1268 }
1271 1269
1272 if(cbdata->js->registration) { 1270 if(cbdata->js->registration) {
1273 username = g_strdup_printf("%s@%s%s%s", cbdata->js->user->node, cbdata->js->user->domain, 1271 username = g_strdup_printf("%s@%s%s%s", cbdata->js->user->node, cbdata->js->user->domain,
1274 cbdata->js->user->resource ? "/" : "", 1272 cbdata->js->user->resource ? "/" : "",
1275 cbdata->js->user->resource ? cbdata->js->user->resource : ""); 1273 cbdata->js->user->resource ? cbdata->js->user->resource : "");
1276 purple_account_set_username(cbdata->js->gc->account, username); 1274 purple_account_set_username(purple_connection_get_account(cbdata->js->gc), username);
1277 g_free(username); 1275 g_free(username);
1278 } 1276 }
1279 1277
1280 jabber_iq_set_callback(iq, jabber_registration_result_cb, cbdata->who); 1278 jabber_iq_set_callback(iq, jabber_registration_result_cb, cbdata->who);
1281 1279
1286 static void 1284 static void
1287 jabber_register_cancel_cb(JabberRegisterCBData *cbdata, PurpleRequestFields *fields) 1285 jabber_register_cancel_cb(JabberRegisterCBData *cbdata, PurpleRequestFields *fields)
1288 { 1286 {
1289 PurpleAccount *account = purple_connection_get_account(cbdata->js->gc); 1287 PurpleAccount *account = purple_connection_get_account(cbdata->js->gc);
1290 if(account && cbdata->js->registration) { 1288 if(account && cbdata->js->registration) {
1291 if(account->registration_cb) 1289 purple_account_register_completed(account, FALSE);
1292 (account->registration_cb)(account, FALSE, account->registration_cb_user_data);
1293 jabber_connection_schedule_close(cbdata->js); 1290 jabber_connection_schedule_close(cbdata->js);
1294 } 1291 }
1295 g_free(cbdata->who); 1292 g_free(cbdata->who);
1296 g_free(cbdata); 1293 g_free(cbdata);
1297 } 1294 }
1356 registered = TRUE; 1353 registered = TRUE;
1357 1354
1358 if(js->registration) { 1355 if(js->registration) {
1359 purple_notify_error(NULL, _("Already Registered"), 1356 purple_notify_error(NULL, _("Already Registered"),
1360 _("Already Registered"), NULL); 1357 _("Already Registered"), NULL);
1361 if(account->registration_cb) 1358 purple_account_register_completed(account, FALSE);
1362 (account->registration_cb)(account, FALSE, account->registration_cb_user_data);
1363 jabber_connection_schedule_close(js); 1359 jabber_connection_schedule_close(js);
1364 return; 1360 return;
1365 } 1361 }
1366 } 1362 }
1367 1363
1378 purple_notify_uri(NULL, href); 1374 purple_notify_uri(NULL, href);
1379 g_free(href); 1375 g_free(href);
1380 1376
1381 if(js->registration) { 1377 if(js->registration) {
1382 js->gc->wants_to_die = TRUE; 1378 js->gc->wants_to_die = TRUE;
1383 if(account->registration_cb) /* succeeded, but we have no login info */ 1379 /* succeeded, but we have no login info */
1384 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); 1380 purple_account_register_completed(account, TRUE);
1385 jabber_connection_schedule_close(js); 1381 jabber_connection_schedule_close(js);
1386 } 1382 }
1387 return; 1383 return;
1388 } 1384 }
1389 } 1385 }
1420 } 1416 }
1421 1417
1422 if((node = xmlnode_get_child(query, "name"))) { 1418 if((node = xmlnode_get_child(query, "name"))) {
1423 if(js->registration) 1419 if(js->registration)
1424 field = purple_request_field_string_new("name", _("Name"), 1420 field = purple_request_field_string_new("name", _("Name"),
1425 purple_account_get_alias(js->gc->account), FALSE); 1421 purple_account_get_alias(purple_connection_get_account(js->gc)), FALSE);
1426 else { 1422 else {
1427 char *data = xmlnode_get_data(node); 1423 char *data = xmlnode_get_data(node);
1428 field = purple_request_field_string_new("name", _("Name"), data, FALSE); 1424 field = purple_request_field_string_new("name", _("Name"), data, FALSE);
1429 g_free(data); 1425 g_free(data);
1430 } 1426 }
1554 1550
1555 void jabber_unregister_account(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data) { 1551 void jabber_unregister_account(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data) {
1556 PurpleConnection *gc = purple_account_get_connection(account); 1552 PurpleConnection *gc = purple_account_get_connection(account);
1557 JabberStream *js; 1553 JabberStream *js;
1558 1554
1559 if(gc->state != PURPLE_CONNECTED) { 1555 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) {
1560 if(gc->state != PURPLE_CONNECTING) 1556 if (purple_connection_get_state(gc) != PURPLE_CONNECTING)
1561 jabber_login(account); 1557 jabber_login(account);
1562 js = gc->proto_data; 1558 js = purple_connection_get_protocol_data(gc);
1563 js->unregistration = TRUE; 1559 js->unregistration = TRUE;
1564 js->unregistration_cb = cb; 1560 js->unregistration_cb = cb;
1565 js->unregistration_user_data = user_data; 1561 js->unregistration_user_data = user_data;
1566 return; 1562 return;
1567 } 1563 }
1568 1564
1569 js = gc->proto_data; 1565 js = purple_connection_get_protocol_data(gc);
1570 1566
1571 if (js->unregistration) { 1567 if (js->unregistration) {
1572 purple_debug_error("jabber", "Unregistration in process; ignoring duplicate request.\n"); 1568 purple_debug_error("jabber", "Unregistration in process; ignoring duplicate request.\n");
1573 return; 1569 return;
1574 } 1570 }
1596 jabber_bosh_connection_close(js->bosh); 1592 jabber_bosh_connection_close(js->bosh);
1597 else if ((js->gsc && js->gsc->fd > 0) || js->fd > 0) 1593 else if ((js->gsc && js->gsc->fd > 0) || js->fd > 0)
1598 jabber_send_raw(js, "</stream:stream>", -1); 1594 jabber_send_raw(js, "</stream:stream>", -1);
1599 1595
1600 if (js->srv_query_data) 1596 if (js->srv_query_data)
1601 purple_srv_cancel(js->srv_query_data); 1597 purple_srv_txt_query_destroy(js->srv_query_data);
1602 1598
1603 if(js->gsc) { 1599 if(js->gsc) {
1604 purple_ssl_close(js->gsc); 1600 purple_ssl_close(js->gsc);
1605 } else if (js->fd > 0) { 1601 } else if (js->fd > 0) {
1606 if(js->gc->inpa) 1602 if(js->inpa) {
1607 purple_input_remove(js->gc->inpa); 1603 purple_input_remove(js->inpa);
1604 js->inpa = 0;
1605 }
1608 close(js->fd); 1606 close(js->fd);
1609 } 1607 }
1610 1608
1611 if (js->bosh) 1609 if (js->bosh)
1612 jabber_bosh_connection_destroy(js->bosh); 1610 jabber_bosh_connection_destroy(js->bosh);
1724 } 1722 }
1725 } 1723 }
1726 1724
1727 g_free(js); 1725 g_free(js);
1728 1726
1729 gc->proto_data = NULL; 1727 purple_connection_set_protocol_data(gc, NULL);
1730 } 1728 }
1731 1729
1732 void jabber_stream_set_state(JabberStream *js, JabberStreamState state) 1730 void jabber_stream_set_state(JabberStream *js, JabberStreamState state)
1733 { 1731 {
1734 #define JABBER_CONNECT_STEPS ((js->gsc || js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION) ? 9 : 5) 1732 #define JABBER_CONNECT_STEPS ((js->gsc || js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION) ? 9 : 5)
1778 } 1776 }
1779 1777
1780 1778
1781 void jabber_idle_set(PurpleConnection *gc, int idle) 1779 void jabber_idle_set(PurpleConnection *gc, int idle)
1782 { 1780 {
1783 JabberStream *js = gc->proto_data; 1781 JabberStream *js = purple_connection_get_protocol_data(gc);
1784 1782
1785 js->idle = idle ? time(NULL) - idle : idle; 1783 js->idle = idle ? time(NULL) - idle : idle;
1786 1784
1787 /* send out an updated prescence */ 1785 /* send out an updated prescence */
1788 purple_debug_info("jabber", "sending updated presence for idle\n"); 1786 purple_debug_info("jabber", "sending updated presence for idle\n");
1869 1867
1870 if (type == JABBER_IQ_ERROR || blocklist == NULL) 1868 if (type == JABBER_IQ_ERROR || blocklist == NULL)
1871 return; 1869 return;
1872 1870
1873 /* This is the only privacy method supported by XEP-0191 */ 1871 /* This is the only privacy method supported by XEP-0191 */
1874 if (account->perm_deny != PURPLE_PRIVACY_DENY_USERS) 1872 purple_account_set_privacy_type(account, PURPLE_PRIVACY_DENY_USERS);
1875 account->perm_deny = PURPLE_PRIVACY_DENY_USERS;
1876 1873
1877 /* 1874 /*
1878 * TODO: When account->deny is something more than a hash table, this can 1875 * TODO: When account->deny is something more than a hash table, this can
1879 * be re-written to find the set intersection and difference. 1876 * be re-written to find the set intersection and difference.
1880 */ 1877 */
2131 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(b)); 2128 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(b));
2132 2129
2133 if(!gc) 2130 if(!gc)
2134 return NULL; 2131 return NULL;
2135 2132
2136 js = gc->proto_data; 2133 js = purple_connection_get_protocol_data(gc);
2137 if(js) 2134 if(js)
2138 jb = jabber_buddy_find(js, purple_buddy_get_name(b), FALSE); 2135 jb = jabber_buddy_find(js, purple_buddy_get_name(b), FALSE);
2139 2136
2140 if(!PURPLE_BUDDY_IS_ONLINE(b)) { 2137 if(!PURPLE_BUDDY_IS_ONLINE(b)) {
2141 if(jb && (jb->subscription & JABBER_SUB_PENDING || 2138 if(jb && (jb->subscription & JABBER_SUB_PENDING ||
2172 char *ret = NULL; 2169 char *ret = NULL;
2173 JabberBuddy *jb = NULL; 2170 JabberBuddy *jb = NULL;
2174 PurpleAccount *account = purple_buddy_get_account(b); 2171 PurpleAccount *account = purple_buddy_get_account(b);
2175 PurpleConnection *gc = purple_account_get_connection(account); 2172 PurpleConnection *gc = purple_account_get_connection(account);
2176 2173
2177 if (gc && gc->proto_data) 2174 if (gc && purple_connection_get_protocol_data(gc))
2178 jb = jabber_buddy_find(gc->proto_data, purple_buddy_get_name(b), FALSE); 2175 jb = jabber_buddy_find(purple_connection_get_protocol_data(gc), purple_buddy_get_name(b), FALSE);
2179 2176
2180 if(jb && !PURPLE_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) { 2177 if(jb && !PURPLE_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) {
2181 ret = g_strdup(_("Not Authorized")); 2178 ret = g_strdup(_("Not Authorized"));
2182 } else if(jb && !PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) { 2179 } else if(jb && !PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) {
2183 ret = g_strdup(jb->error_msg); 2180 ret = g_strdup(jb->error_msg);
2223 } 2220 }
2224 2221
2225 label = g_strdup_printf("%s%s", _("Status"), (res ? res : "")); 2222 label = g_strdup_printf("%s%s", _("Status"), (res ? res : ""));
2226 value = g_strdup_printf("%s%s%s", state, (text ? ": " : ""), (text ? text : "")); 2223 value = g_strdup_printf("%s%s%s", state, (text ? ": " : ""), (text ? text : ""));
2227 2224
2228 purple_notify_user_info_add_pair(user_info, label, value); 2225 purple_notify_user_info_add_pair_html(user_info, label, value);
2229 g_free(label); 2226 g_free(label);
2230 g_free(value); 2227 g_free(value);
2231 g_free(text); 2228 g_free(text);
2232 2229
2233 /* if the resource is idle, show that */ 2230 /* if the resource is idle, show that */
2236 this way we can see see the idleness of lower-priority resources */ 2233 this way we can see see the idleness of lower-priority resources */
2237 if (jbr->idle && multiple_resources) { 2234 if (jbr->idle && multiple_resources) {
2238 gchar *idle_str = 2235 gchar *idle_str =
2239 purple_str_seconds_to_string(time(NULL) - jbr->idle); 2236 purple_str_seconds_to_string(time(NULL) - jbr->idle);
2240 label = g_strdup_printf("%s%s", _("Idle"), (res ? res : "")); 2237 label = g_strdup_printf("%s%s", _("Idle"), (res ? res : ""));
2241 purple_notify_user_info_add_pair(user_info, label, idle_str); 2238 purple_notify_user_info_add_pair_plaintext(user_info, label, idle_str);
2242 g_free(idle_str); 2239 g_free(idle_str);
2243 g_free(label); 2240 g_free(label);
2244 } 2241 }
2245 g_free(res); 2242 g_free(res);
2246 } 2243 }
2248 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full) 2245 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full)
2249 { 2246 {
2250 JabberBuddy *jb; 2247 JabberBuddy *jb;
2251 PurpleAccount *account; 2248 PurpleAccount *account;
2252 PurpleConnection *gc; 2249 PurpleConnection *gc;
2250 JabberStream *js;
2253 2251
2254 g_return_if_fail(b != NULL); 2252 g_return_if_fail(b != NULL);
2255 2253
2256 account = purple_buddy_get_account(b); 2254 account = purple_buddy_get_account(b);
2257 g_return_if_fail(account != NULL); 2255 g_return_if_fail(account != NULL);
2258 2256
2259 gc = purple_account_get_connection(account); 2257 gc = purple_account_get_connection(account);
2260 g_return_if_fail(gc != NULL); 2258 g_return_if_fail(gc != NULL);
2261 g_return_if_fail(gc->proto_data != NULL); 2259
2262 2260 js = purple_connection_get_protocol_data(gc);
2263 jb = jabber_buddy_find(gc->proto_data, purple_buddy_get_name(b), FALSE); 2261 g_return_if_fail(js != NULL);
2262
2263 jb = jabber_buddy_find(js, purple_buddy_get_name(b), FALSE);
2264 2264
2265 if(jb) { 2265 if(jb) {
2266 JabberBuddyResource *jbr = NULL; 2266 JabberBuddyResource *jbr = NULL;
2267 PurplePresence *presence = purple_buddy_get_presence(b); 2267 PurplePresence *presence = purple_buddy_get_presence(b);
2268 const char *sub; 2268 const char *sub;
2308 moodtext = purple_status_get_attr_string(status, PURPLE_MOOD_COMMENT); 2308 moodtext = purple_status_get_attr_string(status, PURPLE_MOOD_COMMENT);
2309 if(moodtext && *moodtext) { 2309 if(moodtext && *moodtext) {
2310 char *moodplustext = 2310 char *moodplustext =
2311 g_strdup_printf("%s (%s)", description ? _(description) : mood, moodtext); 2311 g_strdup_printf("%s (%s)", description ? _(description) : mood, moodtext);
2312 2312
2313 purple_notify_user_info_add_pair(user_info, _("Mood"), moodplustext); 2313 purple_notify_user_info_add_pair_html(user_info, _("Mood"), moodplustext);
2314 g_free(moodplustext); 2314 g_free(moodplustext);
2315 } else 2315 } else
2316 purple_notify_user_info_add_pair(user_info, _("Mood"), 2316 purple_notify_user_info_add_pair_html(user_info, _("Mood"),
2317 description ? _(description) : mood); 2317 description ? _(description) : mood);
2318 } 2318 }
2319 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) { 2319 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
2320 PurpleStatus *tune = purple_presence_get_status(presence, "tune"); 2320 PurpleStatus *tune = purple_presence_get_status(presence, "tune");
2321 const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE); 2321 const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
2322 const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST); 2322 const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST);
2323 const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM); 2323 const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM);
2324 char *playing = purple_util_format_song_info(title, artist, album, NULL); 2324 char *playing = purple_util_format_song_info(title, artist, album, NULL);
2325 if (playing) { 2325 if (playing) {
2326 purple_notify_user_info_add_pair(user_info, _("Now Listening"), playing); 2326 purple_notify_user_info_add_pair_html(user_info, _("Now Listening"), playing);
2327 g_free(playing); 2327 g_free(playing);
2328 } 2328 }
2329 } 2329 }
2330 2330
2331 if(jb->subscription & JABBER_SUB_FROM) { 2331 if(jb->subscription & JABBER_SUB_FROM) {
2342 sub = _("None (To pending)"); 2342 sub = _("None (To pending)");
2343 else 2343 else
2344 sub = _("None"); 2344 sub = _("None");
2345 } 2345 }
2346 2346
2347 purple_notify_user_info_add_pair(user_info, _("Subscription"), sub); 2347 purple_notify_user_info_add_pair_html(user_info, _("Subscription"), sub);
2348 2348
2349 } 2349 }
2350 2350
2351 if(!PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) { 2351 if(!PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) {
2352 purple_notify_user_info_add_pair(user_info, _("Error"), jb->error_msg); 2352 purple_notify_user_info_add_pair_html(user_info, _("Error"), jb->error_msg);
2353 } 2353 }
2354 } 2354 }
2355 } 2355 }
2356 2356
2357 GList *jabber_status_types(PurpleAccount *account) 2357 GList *jabber_status_types(PurpleAccount *account)
2482 { 2482 {
2483 if (type == JABBER_IQ_RESULT) { 2483 if (type == JABBER_IQ_RESULT) {
2484 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"), 2484 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"),
2485 _("Your password has been changed.")); 2485 _("Your password has been changed."));
2486 2486
2487 purple_account_set_password(js->gc->account, (char *)data); 2487 purple_account_set_password(purple_connection_get_account(js->gc), (char *)data);
2488 } else { 2488 } else {
2489 char *msg = jabber_parse_error(js, packet, NULL); 2489 char *msg = jabber_parse_error(js, packet, NULL);
2490 2490
2491 purple_notify_error(js->gc, _("Error changing password"), 2491 purple_notify_error(js->gc, _("Error changing password"),
2492 _("Error changing password"), msg); 2492 _("Error changing password"), msg);
2529 2529
2530 static void jabber_password_change(PurplePluginAction *action) 2530 static void jabber_password_change(PurplePluginAction *action)
2531 { 2531 {
2532 2532
2533 PurpleConnection *gc = (PurpleConnection *) action->context; 2533 PurpleConnection *gc = (PurpleConnection *) action->context;
2534 JabberStream *js = gc->proto_data; 2534 JabberStream *js = purple_connection_get_protocol_data(gc);
2535 PurpleRequestFields *fields; 2535 PurpleRequestFields *fields;
2536 PurpleRequestFieldGroup *group; 2536 PurpleRequestFieldGroup *group;
2537 PurpleRequestField *field; 2537 PurpleRequestField *field;
2538 2538
2539 fields = purple_request_fields_new(); 2539 fields = purple_request_fields_new();
2561 } 2561 }
2562 2562
2563 GList *jabber_actions(PurplePlugin *plugin, gpointer context) 2563 GList *jabber_actions(PurplePlugin *plugin, gpointer context)
2564 { 2564 {
2565 PurpleConnection *gc = (PurpleConnection *) context; 2565 PurpleConnection *gc = (PurpleConnection *) context;
2566 JabberStream *js = gc->proto_data; 2566 JabberStream *js = purple_connection_get_protocol_data(gc);
2567 GList *m = NULL; 2567 GList *m = NULL;
2568 PurplePluginAction *act; 2568 PurplePluginAction *act;
2569 2569
2570 act = purple_plugin_action_new(_("Set User Info..."), 2570 act = purple_plugin_action_new(_("Set User Info..."),
2571 jabber_setup_set_info); 2571 jabber_setup_set_info);
2632 return NULL; 2632 return NULL;
2633 } 2633 }
2634 2634
2635 void jabber_convo_closed(PurpleConnection *gc, const char *who) 2635 void jabber_convo_closed(PurpleConnection *gc, const char *who)
2636 { 2636 {
2637 JabberStream *js = gc->proto_data; 2637 JabberStream *js = purple_connection_get_protocol_data(gc);
2638 JabberID *jid; 2638 JabberID *jid;
2639 JabberBuddy *jb; 2639 JabberBuddy *jb;
2640 JabberBuddyResource *jbr; 2640 JabberBuddyResource *jbr;
2641 2641
2642 if(!(jid = jabber_id_new(who))) 2642 if(!(jid = jabber_id_new(who)))
2737 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE); 2737 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE);
2738 text = _("Authorization mechanism too weak"); 2738 text = _("Authorization mechanism too weak");
2739 } else if(xmlnode_get_child(packet, "not-authorized")) { 2739 } else if(xmlnode_get_child(packet, "not-authorized")) {
2740 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED); 2740 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED);
2741 /* Clear the pasword if it isn't being saved */ 2741 /* Clear the pasword if it isn't being saved */
2742 if (!purple_account_get_remember_password(js->gc->account)) 2742 if (!purple_account_get_remember_password(purple_connection_get_account(js->gc)))
2743 purple_account_set_password(js->gc->account, NULL); 2743 purple_account_set_password(purple_connection_get_account(js->gc), NULL);
2744 text = _("Not Authorized"); 2744 text = _("Not Authorized");
2745 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) { 2745 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) {
2746 text = _("Temporary Authentication Failure"); 2746 text = _("Temporary Authentication Failure");
2747 } else { 2747 } else {
2748 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED); 2748 SET_REASON(PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED);
2995 const char *cmd, char **args, char **error, void *data) 2995 const char *cmd, char **args, char **error, void *data)
2996 { 2996 {
2997 if(!args || !args[0]) 2997 if(!args || !args[0])
2998 return PURPLE_CMD_RET_FAILED; 2998 return PURPLE_CMD_RET_FAILED;
2999 2999
3000 jabber_chat_invite(purple_conversation_get_gc(conv), 3000 jabber_chat_invite(purple_conversation_get_connection(conv),
3001 purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), args[1] ? args[1] : "", 3001 purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), args[1] ? args[1] : "",
3002 args[0]); 3002 args[0]);
3003 3003
3004 return PURPLE_CMD_RET_OK; 3004 return PURPLE_CMD_RET_OK;
3005 } 3005 }
3042 g_hash_table_insert(components, "handle", (gpointer)handle); 3042 g_hash_table_insert(components, "handle", (gpointer)handle);
3043 3043
3044 if (args[1]) 3044 if (args[1])
3045 g_hash_table_insert(components, "password", args[1]); 3045 g_hash_table_insert(components, "password", args[1]);
3046 3046
3047 jabber_chat_join(purple_conversation_get_gc(conv), components); 3047 jabber_chat_join(purple_conversation_get_connection(conv), components);
3048 3048
3049 g_hash_table_destroy(components); 3049 g_hash_table_destroy(components);
3050 jabber_id_free(jid); 3050 jabber_id_free(jid);
3051 return PURPLE_CMD_RET_OK; 3051 return PURPLE_CMD_RET_OK;
3052 } 3052 }
3076 if (!chat) 3076 if (!chat)
3077 return PURPLE_CMD_RET_FAILED; 3077 return PURPLE_CMD_RET_FAILED;
3078 3078
3079 who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]); 3079 who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]);
3080 3080
3081 jabber_message_send_im(purple_conversation_get_gc(conv), who, args[1], 0); 3081 jabber_message_send_im(purple_conversation_get_connection(conv), who, args[1], 0);
3082 3082
3083 g_free(who); 3083 g_free(who);
3084 return PURPLE_CMD_RET_OK; 3084 return PURPLE_CMD_RET_OK;
3085 } 3085 }
3086 3086
3157 } 3157 }
3158 3158
3159 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv, 3159 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv,
3160 const char *cmd, char **args, char **error, void *data) 3160 const char *cmd, char **args, char **error, void *data)
3161 { 3161 {
3162 JabberStream *js = conv->account->gc->proto_data; 3162 PurpleAccount *account = purple_conversation_get_account(conv);
3163 JabberStream *js = purple_connection_get_protocol_data(purple_account_get_connection(account));
3163 const gchar *who; 3164 const gchar *who;
3164 gchar *description; 3165 gchar *description;
3165 PurpleBuddy *buddy; 3166 PurpleBuddy *buddy;
3166 const char *alias; 3167 const char *alias;
3167 PurpleAttentionType *attn = 3168 PurpleAttentionType *attn =
3168 purple_get_attention_type_from_code(conv->account, 0); 3169 purple_get_attention_type_from_code(account, 0);
3169 3170
3170 if (!args || !args[0]) { 3171 if (!args || !args[0]) {
3171 /* use the buddy from conversation, if it's a one-to-one conversation */ 3172 /* use the buddy from conversation, if it's a one-to-one conversation */
3172 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) { 3173 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
3173 who = purple_conversation_get_name(conv); 3174 who = purple_conversation_get_name(conv);
3176 } 3177 }
3177 } else { 3178 } else {
3178 who = args[0]; 3179 who = args[0];
3179 } 3180 }
3180 3181
3181 buddy = purple_find_buddy(conv->account, who); 3182 buddy = purple_find_buddy(account, who);
3182 if (buddy != NULL) 3183 if (buddy != NULL)
3183 alias = purple_buddy_get_contact_alias(buddy); 3184 alias = purple_buddy_get_contact_alias(buddy);
3184 else 3185 else
3185 alias = who; 3186 alias = who;
3186 3187
3204 return types; 3205 return types;
3205 } 3206 }
3206 3207
3207 gboolean jabber_send_attention(PurpleConnection *gc, const char *username, guint code) 3208 gboolean jabber_send_attention(PurpleConnection *gc, const char *username, guint code)
3208 { 3209 {
3209 JabberStream *js = gc->proto_data; 3210 JabberStream *js = purple_connection_get_protocol_data(gc);
3210 gchar *error = NULL; 3211 gchar *error = NULL;
3211 3212
3212 if (!_jabber_send_buzz(js, username, &error)) { 3213 if (!_jabber_send_buzz(js, username, &error)) {
3213 PurpleAccount *account = purple_connection_get_account(gc); 3214 PurpleAccount *account = purple_connection_get_account(gc);
3214 PurpleConversation *conv = 3215 PurpleConversation *conv =
3287 gboolean 3288 gboolean
3288 jabber_initiate_media(PurpleAccount *account, const char *who, 3289 jabber_initiate_media(PurpleAccount *account, const char *who,
3289 PurpleMediaSessionType type) 3290 PurpleMediaSessionType type)
3290 { 3291 {
3291 #ifdef USE_VV 3292 #ifdef USE_VV
3292 JabberStream *js = (JabberStream *) 3293 PurpleConnection *gc = purple_account_get_connection(account);
3293 purple_account_get_connection(account)->proto_data; 3294 JabberStream *js = purple_connection_get_protocol_data(gc);
3294 JabberBuddy *jb; 3295 JabberBuddy *jb;
3295 JabberBuddyResource *jbr = NULL; 3296 JabberBuddyResource *jbr = NULL;
3296 char *resource; 3297 char *resource;
3297 3298
3298 if (!js) { 3299 if (!js) {
3299 purple_debug_error("jabber", 3300 purple_debug_error("jabber",
3300 "jabber_initiate_media: NULL stream\n"); 3301 "jabber_initiate_media: NULL stream\n");
3301 return FALSE; 3302 return FALSE;
3302 } 3303 }
3303
3304 3304
3305 if((resource = jabber_get_resource(who)) != NULL) { 3305 if((resource = jabber_get_resource(who)) != NULL) {
3306 /* they've specified a resource, no need to ask or 3306 /* they've specified a resource, no need to ask or
3307 * default or anything, just do it */ 3307 * default or anything, just do it */
3308 3308
3430 } 3430 }
3431 3431
3432 PurpleMediaCaps jabber_get_media_caps(PurpleAccount *account, const char *who) 3432 PurpleMediaCaps jabber_get_media_caps(PurpleAccount *account, const char *who)
3433 { 3433 {
3434 #ifdef USE_VV 3434 #ifdef USE_VV
3435 JabberStream *js = (JabberStream *) 3435 PurpleConnection *gc = purple_account_get_connection(account);
3436 purple_account_get_connection(account)->proto_data; 3436 JabberStream *js = purple_connection_get_protocol_data(gc);
3437 JabberBuddy *jb; 3437 JabberBuddy *jb;
3438 JabberBuddyResource *jbr; 3438 JabberBuddyResource *jbr;
3439 PurpleMediaCaps total = PURPLE_MEDIA_CAPS_NONE; 3439 PurpleMediaCaps total = PURPLE_MEDIA_CAPS_NONE;
3440 gchar *resource; 3440 gchar *resource;
3441 GList *specific = NULL, *l; 3441 GList *specific = NULL, *l;
3519 #endif 3519 #endif
3520 } 3520 }
3521 3521
3522 gboolean jabber_can_receive_file(PurpleConnection *gc, const char *who) 3522 gboolean jabber_can_receive_file(PurpleConnection *gc, const char *who)
3523 { 3523 {
3524 JabberStream *js = gc->proto_data; 3524 JabberStream *js = purple_connection_get_protocol_data(gc);
3525 3525
3526 if (js) { 3526 if (js) {
3527 JabberBuddy *jb = jabber_buddy_find(js, who, FALSE); 3527 JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
3528 GList *iter; 3528 GList *iter;
3529 gboolean has_resources_without_caps = FALSE; 3529 gboolean has_resources_without_caps = FALSE;
3569 3569
3570 static PurpleCmdRet 3570 static PurpleCmdRet
3571 jabber_cmd_mood(PurpleConversation *conv, 3571 jabber_cmd_mood(PurpleConversation *conv,
3572 const char *cmd, char **args, char **error, void *data) 3572 const char *cmd, char **args, char **error, void *data)
3573 { 3573 {
3574 JabberStream *js = conv->account->gc->proto_data; 3574 PurpleAccount *account = purple_conversation_get_account(conv);
3575 JabberStream *js = purple_connection_get_protocol_data(purple_account_get_connection(account));
3575 3576
3576 if (js->pep) { 3577 if (js->pep) {
3577 /* if no argument was given, unset mood */ 3578 gboolean ret;
3579
3578 if (!args || !args[0]) { 3580 if (!args || !args[0]) {
3579 jabber_mood_set(js, NULL, NULL); 3581 /* No arguments; unset mood */
3580 } else if (!args[1]) { 3582 ret = jabber_mood_set(js, NULL, NULL);
3581 jabber_mood_set(js, args[0], NULL);
3582 } else { 3583 } else {
3583 jabber_mood_set(js, args[0], args[1]); 3584 /* At least one argument. Relying on the list of arguments
3584 } 3585 * being NULL-terminated.
3585 3586 */
3586 return PURPLE_CMD_RET_OK; 3587 ret = jabber_mood_set(js, args[0], args[1]);
3588 if (!ret) {
3589 /* Let's try again */
3590 char *tmp = g_strjoin(" ", args[0], args[1], NULL);
3591 ret = jabber_mood_set(js, "undefined", tmp);
3592 g_free(tmp);
3593 }
3594 }
3595
3596 if (ret) {
3597 return PURPLE_CMD_RET_OK;
3598 } else {
3599 purple_conversation_write(conv, NULL,
3600 _("Failed to specify mood"),
3601 PURPLE_MESSAGE_ERROR, time(NULL));
3602 return PURPLE_CMD_RET_FAILED;
3603 }
3587 } else { 3604 } else {
3588 /* account does not support PEP, can't set a mood */ 3605 /* account does not support PEP, can't set a mood */
3589 purple_conversation_write(conv, NULL, 3606 purple_conversation_write(conv, NULL,
3590 _("Account does not support PEP, can't set mood"), 3607 _("Account does not support PEP, can't set mood"),
3591 PURPLE_MESSAGE_ERROR, time(NULL)); 3608 PURPLE_MESSAGE_ERROR, time(NULL));
3710 3727
3711 id = purple_cmd_register("mood", "ws", PURPLE_CMD_P_PRPL, 3728 id = purple_cmd_register("mood", "ws", PURPLE_CMD_P_PRPL,
3712 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | 3729 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM |
3713 PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, 3730 PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS,
3714 "prpl-jabber", jabber_cmd_mood, 3731 "prpl-jabber", jabber_cmd_mood,
3715 _("mood: Set current user mood"), NULL); 3732 _("mood &lt;mood&gt; [text]: Set current user mood"), NULL);
3716 commands = g_slist_prepend(commands, GUINT_TO_POINTER(id)); 3733 commands = g_slist_prepend(commands, GUINT_TO_POINTER(id));
3717 3734
3718 g_hash_table_insert(jabber_cmds, plugin, commands); 3735 g_hash_table_insert(jabber_cmds, plugin, commands);
3719 } 3736 }
3720 3737
3753 JabberBuddyResource *jbr; 3770 JabberBuddyResource *jbr;
3754 gchar *resource; 3771 gchar *resource;
3755 3772
3756 if (!purple_account_is_connected(account)) 3773 if (!purple_account_is_connected(account))
3757 return FALSE; 3774 return FALSE;
3758 js = gc->proto_data; 3775 js = purple_connection_get_protocol_data(gc);
3759 3776
3760 if (!(resource = jabber_get_resource(jid)) || 3777 if (!(resource = jabber_get_resource(jid)) ||
3761 !(jb = jabber_buddy_find(js, jid, FALSE)) || 3778 !(jb = jabber_buddy_find(js, jid, FALSE)) ||
3762 !(jbr = jabber_buddy_find_resource(jb, resource))) { 3779 !(jbr = jabber_buddy_find_resource(jb, resource))) {
3763 g_free(resource); 3780 g_free(resource);