changeset 14113:8ca0e500da4c

[gaim-migrate @ 16747] Jabber is done. Also, I have a feeling JabberSIXfer->streamhosts is leaking, if anyone wants to fix it. Wink wink. Nudge Nudge. Karate chop. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 14 Aug 2006 07:18:58 +0000
parents e149556f7569
children 7795753a7af6
files src/protocols/jabber/jabber.c src/protocols/jabber/jabber.h src/protocols/jabber/si.c
diffstat 3 files changed, 32 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/jabber/jabber.c	Mon Aug 14 07:00:26 2006 +0000
+++ b/src/protocols/jabber/jabber.c	Mon Aug 14 07:18:58 2006 +0000
@@ -30,6 +30,7 @@
 #include "message.h"
 #include "notify.h"
 #include "pluginpref.h"
+#include "proxy.h"
 #include "prpl.h"
 #include "request.h"
 #include "server.h"
@@ -421,21 +422,18 @@
 
 
 static void
-jabber_login_callback(gpointer data, gint source)
+jabber_login_callback(gpointer data, gint source, const gchar *error)
 {
 	GaimConnection *gc = data;
 	JabberStream *js = gc->proto_data;
 
+	js->connect_info = NULL;
+
 	if (source < 0) {
 		gaim_connection_error(gc, _("Couldn't connect to host"));
 		return;
 	}
 
-	if(!g_list_find(gaim_connections_get_all(), gc)) {
-		close(source);
-		return;
-	}
-
 	js->fd = source;
 
 	if(js->state == JABBER_STREAM_CONNECTING)
@@ -474,12 +472,10 @@
 
 static void jabber_login_connect(JabberStream *js, const char *server, int port)
 {
-	GaimProxyConnectInfo *connect_info;
-
-	connect_info = gaim_proxy_connect(js->gc->account, server,
+	js->connect_info = gaim_proxy_connect(js->gc->account, server,
 			port, jabber_login_callback, js->gc);
 
-	if (connect_info == NULL)
+	if (js->connect_info == NULL)
 		gaim_connection_error(js->gc, _("Unable to create socket"));
 }
 
@@ -862,7 +858,6 @@
 	const char *connect_server = gaim_account_get_string(account,
 			"connect_server", "");
 	const char *server;
-	GaimProxyConnectInfo *connect_info;
 
 	js = gc->proto_data = g_new0(JabberStream, 1);
 	js->gc = gc;
@@ -912,11 +907,11 @@
 	}
 
 	if(!js->gsc) {
-		connect_info = gaim_proxy_connect(account, server,
+		js->connect_info = gaim_proxy_connect(account, server,
 				gaim_account_get_int(account, "port", 5222),
 				jabber_login_callback, gc);
 
-		if (connect_info == NULL)
+		if (js->connect_info == NULL)
 			gaim_connection_error(gc, _("Unable to create socket"));
 	}
 }
@@ -932,6 +927,9 @@
 	if (!gc->disconnect_timeout)
 		jabber_send_raw(js, "</stream:stream>", -1);
 
+	if (js->connect_info)
+		gaim_proxy_connect_cancel(js->connect_info);
+
 	if(js->gsc) {
 #ifdef HAVE_OPENSSL
 		if (!gc->disconnect_timeout)
--- a/src/protocols/jabber/jabber.h	Mon Aug 14 07:00:26 2006 +0000
+++ b/src/protocols/jabber/jabber.h	Mon Aug 14 07:18:58 2006 +0000
@@ -67,6 +67,8 @@
 {
 	int fd;
 
+	GaimProxyConnectInfo *connect_info;
+
 #ifdef HAVE_LIBXML
 	xmlParserCtxt *context;
 #else
--- a/src/protocols/jabber/si.c	Mon Aug 14 07:00:26 2006 +0000
+++ b/src/protocols/jabber/si.c	Mon Aug 14 07:18:58 2006 +0000
@@ -46,6 +46,8 @@
 typedef struct _JabberSIXfer {
 	JabberStream *js;
 
+	GaimProxyConnectInfo *connect_info;
+
 	gboolean accepted;
 
 	char *stream_id;
@@ -88,7 +90,8 @@
 
 static void jabber_si_bytestreams_attempt_connect(GaimXfer *xfer);
 
-static void jabber_si_bytestreams_connect_cb(gpointer data, gint source)
+static void
+jabber_si_bytestreams_connect_cb(gpointer data, gint source, const gchar *error_message)
 {
 	GaimXfer *xfer = data;
 	JabberSIXfer *jsx = xfer->data;
@@ -97,6 +100,7 @@
 	struct bytestreams_streamhost *streamhost = jsx->streamhosts->data;
 
 	gaim_proxy_info_destroy(jsx->gpi);
+	jsx->connect_info = NULL;
 
 	if(source < 0) {
 		jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost);
@@ -167,8 +171,18 @@
 	for(i=0; i<20; i++, p+=2)
 		snprintf(p, 3, "%02x", hashval[i]);
 
-	gaim_proxy_connect_socks5(jsx->gpi, dstaddr, 0, jabber_si_bytestreams_connect_cb, xfer);
+	jsx->connect_info = gaim_proxy_connect_socks5(jsx->gpi, dstaddr, 0,
+			jabber_si_bytestreams_connect_cb, xfer);
 	g_free(dstaddr);
+
+	if (jsx->connect_info == NULL)
+	{
+		jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost);
+		g_free(streamhost->jid);
+		g_free(streamhost->host);
+		g_free(streamhost);
+		jabber_si_bytestreams_attempt_connect(xfer);
+	}
 }
 
 void jabber_bytestreams_parse(JabberStream *js, xmlnode *packet)
@@ -682,6 +696,9 @@
 
 	js->file_transfers = g_list_remove(js->file_transfers, xfer);
 
+	if (jsx->connect_info != NULL)
+		gaim_proxy_connect_cancel(jsx->connect_info);
+
 	g_free(jsx->stream_id);
 	g_free(jsx->iq_id);
 	/* XXX: free other stuff */