pidgin.vv.yahoo.voice: 1815471c: Actually resolve voipa.sip.yahoo.com ins...

maiku at pidgin.im maiku at pidgin.im
Sat Aug 29 07:55:43 EDT 2009


-----------------------------------------------------------------
Revision: 1815471c7f16efce664b130a8ee2212e63dfa2d9
Ancestor: c50b2269a9ca465d32a3642c07cef152a97c5e23
Author: maiku at pidgin.im
Date: 2009-08-29T11:51:46
Branch: im.pidgin.pidgin.vv.yahoo.voice
URL: http://d.pidgin.im/viewmtn/revision/info/1815471c7f16efce664b130a8ee2212e63dfa2d9

Modified files:
        libpurple/protocols/yahoo/yahoo_sip.c

ChangeLog: 

Actually resolve voipa.sip.yahoo.com instead of hardcoding the address.

-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/yahoo_sip.c	35b606c2073dc039791dce1860fe40f3e9329273
+++ libpurple/protocols/yahoo/yahoo_sip.c	b7c489365b0e3f759114de691ec57fa338487a04
@@ -26,6 +26,7 @@
 
 #include "cipher.h"
 #include "debug.h"
+#include "dnsquery.h"
 #include "mediamanager.h"
 
 #include "yahoo_sip.h"
@@ -44,6 +45,7 @@ struct _YahooSip {
 	nua_handle_t *nh;
 	nua_handle_t *yahooref_nh;
 	guint yahooref_timeout_handle;
+	gchar *to_str;
 	gboolean shutdown;
 };
 
@@ -293,16 +295,12 @@ event_callback(nua_event_t event, int st
 		PurpleConnection *pc = purple_account_get_connection(account);
 		YahooData *yd = pc->proto_data;
 		YahooSip *ysip = yd->ysip;
-		gchar *sip_str;
 		nua_subscribe(nh, 
 				SIPTAG_EVENT_STR("billing"),
 				TAG_END());
-		sip_str = g_strdup_printf("sip:%s at 68.142.233.179:443;transport=tcp",
-				purple_url_encode(purple_account_get_username(account)));
 		ysip->yahooref_nh = nua_handle(ysip->nua, NULL,
-				SIPTAG_TO_STR(sip_str),
+				SIPTAG_TO_STR(ysip->to_str),
 				TAG_END());
-		g_free(sip_str);
 		ysip->yahooref_timeout_handle =
 				purple_timeout_add_seconds(60,
 				send_yahooref, ysip->yahooref_nh);
@@ -440,17 +438,45 @@ event_callback(nua_event_t event, int st
 	}
 }
 
-void
-yahoo_sip_init(PurpleAccount *account)
+static void
+yahoo_start_sip(GSList *hosts, gpointer data, const char *error_message)
 {
-	PurpleConnection *pc = purple_account_get_connection(account);
-	YahooData *yd = purple_connection_get_protocol_data(pc);
-	YahooSip *ysip = yd->ysip = g_new0(YahooSip, 1);
+	PurpleAccount *account;
+	PurpleConnection *pc;
+	YahooData *yd;
+	YahooSip *ysip;
 	GSource *gsource;
-	gchar *sip_str;
+	gchar sip_host[INET6_ADDRSTRLEN];
+	struct sockaddr *addr;
 
+	if (error_message) {
+		purple_debug_warning("yahoo", "Error resolving SIP server "
+				"address: %s\n", error_message);
+		g_slist_free(hosts);
+		return;
+	} else if (hosts == NULL || g_slist_next(hosts) == NULL) {
+		purple_debug_warning("yahoo", "No hosts retrieved from "
+				"SIP dns query\n");
+		return;
+	}
+
+	addr = g_slist_next(hosts)->data;
+	if (addr->sa_family == AF_INET6) {
+		inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
+			sip_host, sizeof(sip_host));
+	} else {
+		inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr,
+			sip_host, sizeof(sip_host));
+	}
+	g_slist_free(hosts);
+
 	purple_debug_info("yahoo", "Starting Sofia-SIP\n");
 
+	account = data;
+	pc = purple_account_get_connection(account);
+	yd = purple_connection_get_protocol_data(pc);
+	ysip = yd->ysip = g_new0(YahooSip, 1);
+
 	ysip->root = su_glib_root_create(NULL);
 
 	gsource = su_glib_root_gsource(ysip->root);
@@ -473,13 +499,12 @@ yahoo_sip_init(PurpleAccount *account)
 #endif
 			TAG_END());
 
-	/* XXX: Use the real address here or resolve it */
-	sip_str = g_strdup_printf("sip:%s at 68.142.233.179:443;transport=tcp",
-			purple_url_encode(purple_account_get_username(account)));
+	ysip->to_str = g_strdup_printf("sip:%s@%s:443;transport=tcp",
+			purple_url_encode(purple_account_get_username(
+			account)), sip_host);
 	ysip->nh = nua_handle(ysip->nua, NULL,
-			SIPTAG_TO_STR(sip_str),
+			SIPTAG_TO_STR(ysip->to_str),
 			TAG_END());
-	g_free(sip_str);
 
 	nua_register(ysip->nh,
 #if 0
@@ -494,6 +519,15 @@ void
 }
 
 void
+yahoo_sip_init(PurpleAccount *account)
+{
+	if (purple_dnsquery_a(YAHOO_SIP_HOST, 443,
+			yahoo_start_sip, account) == NULL)
+		purple_debug_warning("yahoo", "Error starting SIP "
+				"server dns query\n");
+}
+
+void
 yahoo_sip_uninit(PurpleAccount *account)
 {
 	PurpleConnection *pc = purple_account_get_connection(account);
@@ -521,5 +555,6 @@ yahoo_sip_uninit(PurpleAccount *account)
 		su_root_sleep(ysip->root, 10L);
 
 	nua_destroy(ysip->nua);
+	g_free(ysip->to_str);
 	g_free(ysip);
 }


More information about the Commits mailing list