Mercurial > pidgin
comparison libpurple/protocols/jabber/jabber.c @ 32672:3828a61c44da
A boring and large patch so I can merge heads.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 23 Dec 2011 08:21:58 +0000 |
parents | 99ca503ea087 |
children |
comparison
equal
deleted
inserted
replaced
32671:0e69949b3e61 | 32672:3828a61c44da |
---|---|
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(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); |
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(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 } |
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); |
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; |
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); |
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 |
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 */ |
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); |
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; |
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 /* if no argument was given, unset mood */ |
3578 if (!args || !args[0]) { | 3579 if (!args || !args[0]) { |
3579 jabber_mood_set(js, NULL, NULL); | 3580 jabber_mood_set(js, NULL, NULL); |
3753 JabberBuddyResource *jbr; | 3754 JabberBuddyResource *jbr; |
3754 gchar *resource; | 3755 gchar *resource; |
3755 | 3756 |
3756 if (!purple_account_is_connected(account)) | 3757 if (!purple_account_is_connected(account)) |
3757 return FALSE; | 3758 return FALSE; |
3758 js = gc->proto_data; | 3759 js = purple_connection_get_protocol_data(gc); |
3759 | 3760 |
3760 if (!(resource = jabber_get_resource(jid)) || | 3761 if (!(resource = jabber_get_resource(jid)) || |
3761 !(jb = jabber_buddy_find(js, jid, FALSE)) || | 3762 !(jb = jabber_buddy_find(js, jid, FALSE)) || |
3762 !(jbr = jabber_buddy_find_resource(jb, resource))) { | 3763 !(jbr = jabber_buddy_find_resource(jb, resource))) { |
3763 g_free(resource); | 3764 g_free(resource); |