pidgin: 2b68e6e2: jabber: Automatically find a STUN server...

malu at pidgin.im malu at pidgin.im
Tue Nov 3 13:56:06 EST 2009


-----------------------------------------------------------------
Revision: 2b68e6e2f510e5ed98eb1bbd65775af1113be028
Ancestor: 8c322571bfb4f2d00c9126e59746445f877be296
Author: malu at pidgin.im
Date: 2009-11-03T18:51:32
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/2b68e6e2f510e5ed98eb1bbd65775af1113be028

Modified files:
        ChangeLog libpurple/protocols/jabber/disco.c
        libpurple/protocols/jabber/jingle/jingle.c

ChangeLog: 

jabber: Automatically find a STUN server by SRV lookup on the account's domain
(for vv)

-------------- next part --------------
============================================================
--- ChangeLog	096e2a88dbc05c60df9c9b6e36f54a4074f8b900
+++ ChangeLog	2e23f99e9c3381fbee07b9b12e4504a6bcf7d7f4
@@ -29,6 +29,9 @@ version 2.6.4 (??/??/20??):
 	* Resolve an issue when connecting to iChat Server when no resource
 	  is specified.
 	* Fix a crash when adding a buddy without an '@'.
+	* Try to automatically find a STUN server by using an SRV lookup on the
+	  account's domain, and use that for voice and video if found and the user 
+	  didn't set one manually in prefs.
 
 	Yahoo:
 	* Fix sending /buzz.
============================================================
--- libpurple/protocols/jabber/disco.c	3046e8cc1bc78444f6bebff53fc7318458225dd0
+++ libpurple/protocols/jabber/disco.c	7037e1de250c99f5cbd5e2e99204e3e78bb3fca3
@@ -421,7 +421,77 @@ jabber_disco_finish_server_info_result_c
 
 }
 
+/* should probably share this code with google.c, or maybe from 2.7.0
+ introduce an abstracted hostname -> IP function in dns.c */
 static void
+jabber_disco_stun_lookup_cb(GSList *hosts, gpointer data,
+	const char *error_message)
+{
+	JabberStream *js = (JabberStream *) data;
+
+	if (error_message) {
+		purple_debug_error("jabber", "STUN lookup failed: %s\n",
+			error_message);
+		g_slist_free(hosts);
+		js->stun_query = NULL;
+		return;
+	}
+
+	if (hosts && g_slist_next(hosts)) {
+		struct sockaddr *addr = g_slist_next(hosts)->data;
+		char dst[INET6_ADDRSTRLEN];
+		int port;
+
+		if (addr->sa_family == AF_INET6) {
+			inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
+				dst, sizeof(dst));
+			port = ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
+		} else {
+			inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr,
+				dst, sizeof(dst));
+			port = ntohs(((struct sockaddr_in *) addr)->sin_port);
+		}
+
+		if (js->stun_ip)
+			g_free(js->stun_ip);
+		js->stun_ip = g_strdup(dst);
+		js->stun_port = port;
+
+		purple_debug_info("jabber", "set STUN IP/port address: "
+		                  "%s:%d\n", dst, port);
+
+		/* unmark ongoing query */
+		js->stun_query = NULL;
+	}
+
+	while (hosts != NULL) {
+		hosts = g_slist_delete_link(hosts, hosts);
+		/* Free the address */
+		g_free(hosts->data);
+		hosts = g_slist_delete_link(hosts, hosts);
+	}
+}
+
+
+static void
+jabber_disco_stun_srv_resolve_cb(PurpleSrvResponse *resp, int results, gpointer data)
+{
+	JabberStream *js = (JabberStream *) data;
+	
+	purple_debug_info("jabber", "got %d SRV responses for STUN.\n", results);
+	js->srv_query_data = NULL;
+	
+	if (results > 0) {
+		purple_debug_info("jabber", "looking up IP for %s:%d\n", 
+			resp[0].hostname, resp[0].port);
+		js->stun_query = 
+			purple_dnsquery_a(resp[0].hostname, resp[0].port, 
+				jabber_disco_stun_lookup_cb, js);
+	}
+}
+
+
+static void
 jabber_disco_server_info_result_cb(JabberStream *js, const char *from,
                                    JabberIqType type, const char *id,
                                    xmlnode *packet, gpointer data)
@@ -471,7 +541,10 @@ jabber_disco_server_info_result_cb(Jabbe
 			/* autodiscover stun and relays */
 			jabber_google_send_jingle_info(js);
 		} else {
-			/* TODO: add external service discovery here... */
+			js->srv_query_data = 
+				purple_srv_resolve("stun", "udp", js->user->domain,
+					jabber_disco_stun_srv_resolve_cb, js);
+			/* TODO: add TURN support later... */
 		}
 	}
 
============================================================
--- libpurple/protocols/jabber/jingle/jingle.c	cce76f266446737527e2af2737cec7bf2b494c9a
+++ libpurple/protocols/jabber/jingle/jingle.c	e4ad6f1e4de430479e06e7bcd22371914fe247c7
@@ -442,15 +442,15 @@ jingle_get_params(JabberStream *js, guin
 	if (num_params > 0) {
 		params = g_new0(GParameter, num_params);
 
-		purple_debug_info("jabber", 
-						  "setting param stun-ip for stream using Google auto-config: %s\n",
-						  js->stun_ip);
+		purple_debug_info("jabber",
+			"setting param stun-ip for stream using auto-discovered IP: %s\n",
+			js->stun_ip);
 		params[0].name = "stun-ip";
 		g_value_init(&params[0].value, G_TYPE_STRING);
 		g_value_set_string(&params[0].value, js->stun_ip);
 		purple_debug_info("jabber", 
-						  "setting param stun-port for stream using Google auto-config: %d\n",
-						  js->stun_port);
+			"setting param stun-port for stream using auto-discovered port: %d\n",
+			js->stun_port);
 		params[1].name = "stun-port";
 		g_value_init(&params[1].value, G_TYPE_UINT);
 		g_value_set_uint(&params[1].value, js->stun_port);


More information about the Commits mailing list