cpw.malu.xmpp.google_relay: 3dd0f075: Keep track of more than one relay reques...

malu at pidgin.im malu at pidgin.im
Wed Sep 30 17:36:16 EDT 2009


-----------------------------------------------------------------
Revision: 3dd0f0753787ede0cf7fd3266d03b324cf869053
Ancestor: e3ad44780fc3f688ae5b5f2c4f41d908c2f83a1d
Author: malu at pidgin.im
Date: 2009-09-30T21:31:04
Branch: im.pidgin.cpw.malu.xmpp.google_relay
URL: http://d.pidgin.im/viewmtn/revision/info/3dd0f0753787ede0cf7fd3266d03b324cf869053

Modified files:
        libpurple/protocols/jabber/google.c
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h

ChangeLog: 

Keep track of more than one relay request at a time (this is probably not
likely to happen, but you never know...)

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google.c	4f1b86f0bb1e0c150c51647044f508d22f348e60
+++ libpurple/protocols/jabber/google.c	4c5812af0abfcc0cabd41d8ea3bc172e688cc051
@@ -379,6 +379,21 @@ static void
 }
 
 static void
+jabber_google_relay_remove_url_data(JabberStream *js, 
+	PurpleUtilFetchUrlData *url_data)
+{
+	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)
@@ -394,7 +409,9 @@ jabber_google_relay_response_session_ini
 	gchar *relay_username = NULL;
 	gchar *relay_password = NULL;
 
-	js->google_relay_request = NULL;
+	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");
 
@@ -449,6 +466,7 @@ jabber_google_do_relay_request(JabberStr
 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"
@@ -458,9 +476,16 @@ jabber_google_do_relay_request(JabberStr
 			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); 
-	js->google_relay_request =
+	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);
 }
@@ -542,7 +567,9 @@ jabber_google_relay_response_session_han
 	GList *codecs = NULL;
 	JabberIq *result;
 
-	js->google_relay_request = NULL;
+	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",
============================================================
--- libpurple/protocols/jabber/jabber.c	4d74d1df3b55b3bd09b765f242e69374f4d329e7
+++ libpurple/protocols/jabber/jabber.c	f638a3ff365ff67e1784debc1e53600e01b37354
@@ -844,7 +844,7 @@ jabber_stream_new(PurpleAccount *account
 	js->stun_query = NULL;
 	js->google_relay_token = NULL;
 	js->google_relay_host = NULL;
-	js->google_relay_request = NULL;
+	js->google_relay_requests = NULL;
 
 	/* if we are idle, set idle-ness on the stream (this could happen if we get
 		disconnected and the reconnects while being idle. I don't think it makes
@@ -1569,16 +1569,18 @@ void jabber_close(PurpleConnection *gc)
 	/* remove Google relay-related stuff */
 	g_free(js->google_relay_token);
 	g_free(js->google_relay_host);
-	if (js->google_relay_request) {
-		purple_util_fetch_url_cancel(js->google_relay_request);
-		js->google_relay_request = NULL;
+	if (js->google_relay_requests) {
+		while (js->google_relay_requests) {
+			PurpleUtilFetchUrlData *url_data =
+				(PurpleUtilFetchUrlData *) js->google_relay_requests->data;
+			purple_util_fetch_url_cancel(url_data);
+			g_free(url_data);
+			js->google_relay_requests = 
+				g_list_delete_link(js->google_relay_requests, 
+					js->google_relay_requests);
+		}
 	}
 
-	if (js->google_relay_request != NULL) {
-		purple_util_fetch_url_cancel(js->google_relay_request);
-		js->google_relay_request = NULL;
-	}
-
 	g_free(js);
 
 	gc->proto_data = NULL;
============================================================
--- libpurple/protocols/jabber/jabber.h	d63970faa17769504013dc1e2817cd5c7a2a15b3
+++ libpurple/protocols/jabber/jabber.h	d30622fbfbb3785ad9e0d60d2af645ba16daed62
@@ -276,7 +276,7 @@ struct _JabberStream
 	/* stuff for Google's relay handling */
 	gchar *google_relay_token;
 	gchar *google_relay_host;
-	PurpleUtilFetchUrlData *google_relay_request; /* the HTTP request to get */
+	GList *google_relay_requests; /* the HTTP requests to get */
 												/* relay info */
 };
 


More information about the Commits mailing list