cpw.malu.xmpp.google_relay: 0c2a5c9d: refactor out the relay credential fetchi...

malu at pidgin.im malu at pidgin.im
Sun Sep 5 04:43:51 EDT 2010


----------------------------------------------------------------------
Revision: 0c2a5c9df741c77ee5f85904b5858faa853836d8
Parent:   cfbc0a615404a2b18838a5754cb42d9b010ad1a1
Author:   malu at pidgin.im
Date:     09/05/10 04:35:37
Branch:   im.pidgin.cpw.malu.xmpp.google_relay
URL: http://d.pidgin.im/viewmtn/revision/info/0c2a5c9df741c77ee5f85904b5858faa853836d8

Changelog: 

refactor out the relay credential fetching code to its own module

Changes against parent cfbc0a615404a2b18838a5754cb42d9b010ad1a1

  patched  libpurple/protocols/jabber/Makefile.am
  patched  libpurple/protocols/jabber/Makefile.mingw
  patched  libpurple/protocols/jabber/google/google_session.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/Makefile.am	9288c280e34cb713069b1f7e8986c18babe47068
+++ libpurple/protocols/jabber/Makefile.am	9c9c664e7262b61ad796bba3066f6813dcf5c613
@@ -38,6 +38,8 @@ JABBERSOURCES = \
 			  google/google_session.h \
 			  google/jingleinfo.c \
 			  google/jingleinfo.h \
+			  google/relay.c \
+			  google/relay.h \
 			  ibb.c \
 			  ibb.h \
 			  iq.c \
============================================================
--- libpurple/protocols/jabber/Makefile.mingw	21684906e355ce47b0955947844e33f20a391a8e
+++ libpurple/protocols/jabber/Makefile.mingw	6653f6e550c184f6b90df95150ab7b44694c4e25
@@ -61,6 +61,7 @@ C_SRC =	\
 			google/google_roster.c \
 			google/google_session.c \
 			google/jingleinfo.c \
+			google/relay.c \
 			ibb.c \
 			iq.c \
 			jabber.c \
============================================================
--- libpurple/protocols/jabber/google/google_session.c	7369ff7dc2b9c273641060873fe39252d604223b
+++ libpurple/protocols/jabber/google/google_session.c	8fd722f9810b000103287edad6815f0442354e1b
@@ -21,6 +21,7 @@
 #include "internal.h"
 #include "debug.h"
 #include "google_session.h"
+#include "relay.h"
 
 #include "jingle/jingle.h"
 
@@ -336,84 +337,18 @@ jabber_google_session_get_params(JabberS
 	return new_params;
 }
 
-static void
-jabber_google_relay_parse_response(const gchar *response, gchar **ip,
-	guint *udp, guint *tcp, guint *ssltcp, gchar **username, gchar **password)
-{
-	gchar **lines = g_strsplit(response, "\n", -1);
-	int i = 0;
 
-	for (; lines[i] ; i++) {
-		gchar *line = lines[i];
-		gchar **parts = g_strsplit(line, "=", 2);
-		
-		if (parts[0] && parts[1]) {
-			if (purple_strequal(parts[0], "relay.ip")) {
-				*ip = g_strdup(parts[1]);
-			} else if (purple_strequal(parts[0], "relay.udp_port")) {
-				*udp = atoi(parts[1]);
-			} else if (purple_strequal(parts[0], "relay.tcp_port")) {
-				*tcp = atoi(parts[1]);
-			} else if (purple_strequal(parts[0], "relay.ssltcp_port")) {
-				*ssltcp = atoi(parts[1]);
-			} else if (purple_strequal(parts[0], "username")) {
-				*username = g_strdup(parts[1]);
-			} else if (purple_strequal(parts[0], "password")) {
-				*password = g_strdup(parts[1]);
-			}
-		}
-		g_strfreev(parts);
-	}
-
-	g_strfreev(lines);
-}
-
 static void
-jabber_google_relay_remove_url_data(JabberStream *js, 
-	PurpleUtilFetchUrlData *url_data)
+jabber_google_relay_response_session_initiate_cb(GoogleSession *session,
+    const gchar *relay_ip, guint relay_udp, guint relay_tcp, guint relay_ssltcp,
+    const gchar *relay_username, const gchar *relay_password)
 {
-	GList *iter = js->google_relay_requests;
-
-	while (iter) {
-		if (iter->data == url_data) {
-			js->google_relay_requests =
-				g_list_delete_link(js->google_relay_requests, iter);
-			break;
-		}
-	}
-}
-
-static void
-jabber_google_relay_response_session_initiate_cb(PurpleUtilFetchUrlData *url_data, 
-	gpointer user_data, const gchar *url_text, gsize len, 
-	const gchar *error_message)
-{
-	GoogleSession *session = (GoogleSession *) user_data;
 	GParameter *params;
 	guint num_params;
 	JabberStream *js = session->js;
-	gchar *relay_ip = NULL;
-	guint relay_udp = 0;
-	guint relay_tcp = 0;
-	guint relay_ssltcp = 0;
-	gchar *relay_username = NULL;
-	gchar *relay_password = NULL;
 	GoogleAVSessionData *session_data =
 		(GoogleAVSessionData *) session->session_data;
-	
-	if (url_data) {
-		jabber_google_relay_remove_url_data(js, url_data);
-	}
 
-	purple_debug_info("jabber", "got response on HTTP request to relay server\n");
-
-	if (url_text && len > 0) {
-		purple_debug_info("jabber", "got Google relay request response:\n%s\n",
-			url_text);
-		jabber_google_relay_parse_response(url_text, &relay_ip, &relay_udp,
-			&relay_tcp, &relay_ssltcp, &relay_username, &relay_password);
-	}
-
 	session_data->media = purple_media_manager_create_media(
 			purple_media_manager_get(),
 			purple_connection_get_account(js->gc),
@@ -434,10 +369,6 @@ jabber_google_relay_response_session_ini
 	params =
 		jabber_google_session_get_params(js, relay_ip, relay_udp, relay_tcp,
 			relay_ssltcp, relay_username, relay_password, &num_params);
-
-	g_free(relay_ip);
-	g_free(relay_username);
-	g_free(relay_password);
 	
 	if (purple_media_add_stream(session_data->media, "google-voice",
 			session->remote_jid, PURPLE_MEDIA_AUDIO,
@@ -456,33 +387,6 @@ jabber_google_relay_response_session_ini
 	g_free(params);	
 }
 
-static void
-jabber_google_do_relay_request(JabberStream *js, GoogleSession *session,
-	PurpleUtilFetchUrlCallback cb)
-{
-	PurpleUtilFetchUrlData *url_data = NULL;
-	gchar *url = g_strdup_printf("http://%s", js->google_relay_host);
-	gchar *request =
-		g_strdup_printf("GET /create_session HTTP/1.0\r\n"
-			            "Host: %s\r\n"
-						"X-Talk-Google-Relay-Auth: %s\r\n"
-						"X-Google-Relay-Auth: %s\r\n\r\n", 
-			js->google_relay_host, js->google_relay_token, js->google_relay_token);
-	purple_debug_info("jabber", 
-		"sending Google relay request %s to %s\n", request, url); 
-	url_data = 
-		purple_util_fetch_url_request(url, FALSE, NULL, FALSE, request, FALSE,
-			cb, session);
-	if (url_data) {
-		js->google_relay_requests =
-			g_list_prepend(js->google_relay_requests, url_data);
-	} else {
-		purple_debug_error("jabber", "unable to create Google relay request\n");
-		cb(NULL, session, NULL, 0, NULL);
-	}
-	g_free(url);
-	g_free(request);
-}
 
 gboolean
 jabber_google_session_initiate(JabberStream *js, const gchar *who, PurpleMediaSessionType type)
@@ -531,8 +435,8 @@ jabber_google_session_initiate(JabberStr
 		jabber_google_do_relay_request(js, session,
 			jabber_google_relay_response_session_initiate_cb);
 	} else {
-		jabber_google_relay_response_session_initiate_cb(NULL, session, NULL, 0,
-			NULL);
+		jabber_google_relay_response_session_initiate_cb(session, NULL, 0, 0, 0,
+			NULL, NULL);
 	}
 	
 	/* we don't actually know yet wether it succeeded... maybe this is very
@@ -541,21 +445,13 @@ static void
 }
 
 static void
-jabber_google_relay_response_session_handle_initiate_cb(
-    PurpleUtilFetchUrlData *url_data, 
-	gpointer user_data, const gchar *url_text, gsize len, 
-	const gchar *error_message)
+jabber_google_relay_response_session_handle_initiate_cb(GoogleSession *session,
+    const gchar *relay_ip, guint relay_udp, guint relay_tcp, guint relay_ssltcp,
+    const gchar *relay_username, const gchar *relay_password)
 {
-	GoogleSession *session = (GoogleSession *) user_data;
 	GParameter *params;
 	guint num_params;
 	JabberStream *js = session->js;
-	gchar *relay_ip = NULL;
-	guint relay_udp = 0;
-	guint relay_tcp = 0;
-	guint relay_ssltcp = 0;
-	gchar *relay_username = NULL;
-	gchar *relay_password = NULL;
 	xmlnode *codec_element;
 	xmlnode *desc_element;
 	const gchar *xmlns;
@@ -566,18 +462,7 @@ jabber_google_relay_response_session_han
 	GoogleAVSessionData *session_data =
 		(GoogleAVSessionData *) session->session_data;
 
-	if (url_data) {
-		jabber_google_relay_remove_url_data(js, url_data);
-	}
-
-	if (url_text && len > 0) {
-		purple_debug_info("jabber", "got Google relay request response:\n%s\n",
-			url_text);
-		jabber_google_relay_parse_response(url_text, &relay_ip, &relay_udp,
-			&relay_tcp, &relay_ssltcp, &relay_username, &relay_password);
-	}
-
-	params = 
+	params =
 		jabber_google_session_get_params(js, relay_ip, relay_udp, relay_tcp, 
 	    	relay_ssltcp, relay_username, relay_password, &num_params);
 
@@ -718,8 +603,8 @@ google_session_handle_initiate(JabberStr
 		jabber_google_do_relay_request(js, session, 
 			jabber_google_relay_response_session_handle_initiate_cb);
 	} else {
-		jabber_google_relay_response_session_handle_initiate_cb(NULL, session,
-			NULL, 0, NULL);
+		jabber_google_relay_response_session_handle_initiate_cb(session, NULL,
+			0, 0, 0, NULL, NULL);
 	}
 
 	return TRUE;


More information about the Commits mailing list