comparison libpurple/protocols/jabber/jabber.c @ 26168:af42303654a5

propagate from branch 'im.pidgin.pidgin' (head 0bb02399ead9501a3e7951cfba2e8e8350fe917c) to branch 'im.pidgin.pidgin.vv' (head a940363ef1efa4bf53c71cbb8201f36ed5795583)
author Mike Ruprecht <maiku@soc.pidgin.im>
date Thu, 05 Feb 2009 00:31:35 +0000
parents b5c82724598c 88f183f7dfc7
children d6e23439b77c
comparison
equal deleted inserted replaced
25056:b0c75121cf66 26168:af42303654a5
57 #include "si.h" 57 #include "si.h"
58 #include "xdata.h" 58 #include "xdata.h"
59 #include "pep.h" 59 #include "pep.h"
60 #include "adhoccommands.h" 60 #include "adhoccommands.h"
61 61
62 #include "jingle/jingle.h"
63 #include "jingle/rtp.h"
64
65 #ifdef USE_VV
66 #include <gst/farsight/fs-conference-iface.h>
67
68 #define GTALK_CAP "http://www.google.com/xmpp/protocol/voice/v1"
69
70 #endif
62 71
63 #define JABBER_CONNECT_STEPS (js->gsc ? 9 : 5) 72 #define JABBER_CONNECT_STEPS (js->gsc ? 9 : 5)
64 73
65 static PurplePlugin *my_protocol = NULL; 74 static PurplePlugin *my_protocol = NULL;
66 GList *jabber_features = NULL; 75 GList *jabber_features = NULL;
720 js->next_id = g_random_int(); 729 js->next_id = g_random_int();
721 js->write_buffer = purple_circ_buffer_new(512); 730 js->write_buffer = purple_circ_buffer_new(512);
722 js->old_length = 0; 731 js->old_length = 0;
723 js->keepalive_timeout = -1; 732 js->keepalive_timeout = -1;
724 js->certificate_CN = g_strdup(connect_server[0] ? connect_server : js->user ? js->user->domain : NULL); 733 js->certificate_CN = g_strdup(connect_server[0] ? connect_server : js->user ? js->user->domain : NULL);
734 #ifdef USE_VV
735 js->sessions = NULL;
736 #endif
737
738 js->stun_ip = NULL;
739 js->stun_port = 0;
740 js->stun_query = NULL;
725 741
726 if(!js->user) { 742 if(!js->user) {
727 purple_connection_error_reason (gc, 743 purple_connection_error_reason (gc,
728 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 744 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
729 _("Invalid XMPP ID")); 745 _("Invalid XMPP ID"));
730 return; 746 return;
731 } 747 }
732 748
733 if (!js->user->domain || *(js->user->domain) == '\0') { 749 if (!js->user->domain || *(js->user->domain) == '\0') {
734 purple_connection_error_reason (gc, 750 purple_connection_error_reason (gc,
735 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 751 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
736 _("Invalid XMPP ID. Domain must be set.")); 752 _("Invalid XMPP ID. Domain must be set."));
737 return; 753 return;
738 } 754 }
739 755
740 if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE))) 756 if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE)))
741 my_jb->subscription |= JABBER_SUB_BOTH; 757 my_jb->subscription |= JABBER_SUB_BOTH;
742 758
743 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); 759 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING);
744 760
1208 my_jb->subscription |= JABBER_SUB_BOTH; 1224 my_jb->subscription |= JABBER_SUB_BOTH;
1209 1225
1210 server = connect_server[0] ? connect_server : js->user->domain; 1226 server = connect_server[0] ? connect_server : js->user->domain;
1211 js->certificate_CN = g_strdup(server); 1227 js->certificate_CN = g_strdup(server);
1212 1228
1229 js->stun_ip = NULL;
1230 js->stun_port = 0;
1231 js->stun_query = NULL;
1232
1213 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); 1233 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING);
1214 1234
1215 if(purple_account_get_bool(account, "old_ssl", FALSE)) { 1235 if(purple_account_get_bool(account, "old_ssl", FALSE)) {
1216 if(purple_ssl_is_supported()) { 1236 if(purple_ssl_is_supported()) {
1217 js->gsc = purple_ssl_connect(account, server, 1237 js->gsc = purple_ssl_connect(account, server,
1304 } 1324 }
1305 1325
1306 void jabber_close(PurpleConnection *gc) 1326 void jabber_close(PurpleConnection *gc)
1307 { 1327 {
1308 JabberStream *js = gc->proto_data; 1328 JabberStream *js = gc->proto_data;
1329
1330 #ifdef USE_VV
1331 /* Close all of the open Jingle sessions on this stream */
1332 jingle_terminate_sessions(js);
1333 #endif
1309 1334
1310 /* Don't perform any actions on the ssl connection 1335 /* Don't perform any actions on the ssl connection
1311 * if we were forcibly disconnected because it will crash 1336 * if we were forcibly disconnected because it will crash
1312 * on some SSL backends. 1337 * on some SSL backends.
1313 */ 1338 */
1406 purple_timeout_remove(js->keepalive_timeout); 1431 purple_timeout_remove(js->keepalive_timeout);
1407 1432
1408 g_free(js->srv_rec); 1433 g_free(js->srv_rec);
1409 js->srv_rec = NULL; 1434 js->srv_rec = NULL;
1410 1435
1436 g_free(js->stun_ip);
1437 js->stun_ip = NULL;
1438
1439 /* cancel DNS query for STUN, if one is ongoing */
1440 if (js->stun_query) {
1441 purple_dnsquery_destroy(js->stun_query);
1442 js->stun_query = NULL;
1443 }
1444
1411 g_free(js); 1445 g_free(js);
1412 1446
1413 gc->proto_data = NULL; 1447 gc->proto_data = NULL;
1414 } 1448 }
1415 1449
2044 { 2078 {
2045 JabberStream *js = gc->proto_data; 2079 JabberStream *js = gc->proto_data;
2046 JabberID *jid; 2080 JabberID *jid;
2047 JabberBuddy *jb; 2081 JabberBuddy *jb;
2048 JabberBuddyResource *jbr; 2082 JabberBuddyResource *jbr;
2049 2083
2050 if(!(jid = jabber_id_new(who))) 2084 if(!(jid = jabber_id_new(who)))
2051 return; 2085 return;
2052 2086
2053 if((jb = jabber_buddy_find(js, who, TRUE)) && 2087 if((jb = jabber_buddy_find(js, who, TRUE)) &&
2054 (jbr = jabber_buddy_find_resource(jb, jid->resource))) { 2088 (jbr = jabber_buddy_find_resource(jb, jid->resource))) {
2524 2558
2525 gboolean jabber_offline_message(const PurpleBuddy *buddy) 2559 gboolean jabber_offline_message(const PurpleBuddy *buddy)
2526 { 2560 {
2527 return TRUE; 2561 return TRUE;
2528 } 2562 }
2563 #ifdef USE_VV
2564
2565 PurpleMedia *
2566 jabber_initiate_media(PurpleConnection *gc, const char *who,
2567 PurpleMediaSessionType type)
2568 {
2569 JabberStream *js = (JabberStream *) gc->proto_data;
2570 JabberBuddy *jb;
2571
2572 if (!js) {
2573 purple_debug_error("jabber",
2574 "jabber_initiate_media: NULL stream\n");
2575 return NULL;
2576 }
2577
2578 jb = jabber_buddy_find(js, who, FALSE);
2579
2580 if (!jb) {
2581 purple_debug_error("jabber", "Could not find buddy\n");
2582 return NULL;
2583 }
2584
2585 if (type & PURPLE_MEDIA_AUDIO &&
2586 !jabber_buddy_has_capability(jb,
2587 JINGLE_APP_RTP_SUPPORT_AUDIO) &&
2588 jabber_buddy_has_capability(jb, GTALK_CAP))
2589 return jabber_google_session_initiate(gc->proto_data, who, type);
2590 else
2591 return jingle_rtp_initiate_media(gc->proto_data, who, type);
2592 }
2593
2594 gboolean jabber_can_do_media(PurpleConnection *gc, const char *who,
2595 PurpleMediaSessionType type)
2596 {
2597 JabberStream *js = (JabberStream *) gc->proto_data;
2598 JabberBuddy *jb;
2599
2600 if (!js) {
2601 purple_debug_error("jabber", "jabber_can_do_media: NULL stream\n");
2602 return FALSE;
2603 }
2604
2605 jb = jabber_buddy_find(js, who, FALSE);
2606
2607 if (!jb) {
2608 purple_debug_error("jabber", "Could not find buddy\n");
2609 return FALSE;
2610 }
2611
2612 if (!jabber_buddy_has_capability(jb, JINGLE_TRANSPORT_ICEUDP) &&
2613 !jabber_buddy_has_capability(jb,
2614 JINGLE_TRANSPORT_RAWUDP) &&
2615 !jabber_buddy_has_capability(jb, GTALK_CAP)) {
2616 purple_debug_info("jingle-rtp", "Buddy doesn't support "
2617 "the same transport types\n");
2618 return FALSE;
2619 }
2620
2621 /* XMPP will only support two-way media, AFAIK... */
2622 if (type == (PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO)) {
2623 purple_debug_info("jabber",
2624 "Checking audio/video XEP support for %s\n", who);
2625 return (jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_AUDIO) ||
2626 jabber_buddy_has_capability(jb, GTALK_CAP)) &&
2627 jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_VIDEO);
2628 } else if (type == (PURPLE_MEDIA_AUDIO)) {
2629 purple_debug_info("jabber",
2630 "Checking audio XEP support for %s\n", who);
2631 return jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_AUDIO) ||
2632 jabber_buddy_has_capability(jb, GTALK_CAP);
2633 } else if (type == (PURPLE_MEDIA_VIDEO)) {
2634 purple_debug_info("jabber",
2635 "Checking video XEP support for %s\n", who);
2636 return jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_VIDEO);
2637 }
2638
2639 return FALSE;
2640 }
2641
2642 #endif
2529 2643
2530 void jabber_register_commands(void) 2644 void jabber_register_commands(void)
2531 { 2645 {
2532 purple_cmd_register("config", "", PURPLE_CMD_P_PRPL, 2646 purple_cmd_register("config", "", PURPLE_CMD_P_PRPL,
2533 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY, 2647 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,