cpw.malu.xmpp.jingle_ft: 96f312f8: Added a skeleton S5B (socks5) transport.

malu at pidgin.im malu at pidgin.im
Mon Mar 23 19:45:39 EDT 2009


-----------------------------------------------------------------
Revision: 96f312f8e18cd6a117216f707f51c726b0fdc8be
Ancestor: a1415f651d2be1535d13d2882c7ace37c4ed1294
Author: malu at pidgin.im
Date: 2009-03-23T23:42:45
Branch: im.pidgin.cpw.malu.xmpp.jingle_ft
URL: http://d.pidgin.im/viewmtn/revision/info/96f312f8e18cd6a117216f707f51c726b0fdc8be

Added files:
        libpurple/protocols/jabber/jingle/s5b.c
        libpurple/protocols/jabber/jingle/s5b.h
Modified files:
        libpurple/protocols/jabber/Makefile.am
        libpurple/protocols/jabber/Makefile.mingw
        libpurple/protocols/jabber/disco.c
        libpurple/protocols/jabber/jingle/file-transfer.c
        libpurple/protocols/jabber/jingle/ibbs.h
        libpurple/protocols/jabber/jingle/jingle.c

ChangeLog: 

Added a skeleton S5B (socks5) transport.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jingle/s5b.c	2e2688af85818c61cd76746a8dd8963dc415e8cd
+++ libpurple/protocols/jabber/jingle/s5b.c	2e2688af85818c61cd76746a8dd8963dc415e8cd
@@ -0,0 +1,153 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+ 
+#include "internal.h"
+
+#include "jingle.h"
+#include "session.h"
+#include "content.h"
+#include "s5b.h"
+#include "debug.h"
+#include "xmlnode.h"
+
+struct _JingleS5BPrivate {
+	/* S5B stuff here... */
+	guint fd;
+};
+
+#define JINGLE_S5B_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), JINGLE_TYPE_S5B, JingleS5BPrivate))
+
+static void jingle_s5b_class_init (JingleS5BClass *klass);
+static void jingle_s5b_init (JingleS5B *s5b);
+static void jingle_s5b_finalize (GObject *object);
+static void jingle_s5b_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static void jingle_s5b_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static JingleTransport *jingle_s5b_parse_internal(xmlnode *s5b);
+static xmlnode *jingle_s5b_to_xml_internal(JingleTransport *transport, xmlnode *content, JingleActionType action);
+
+static JingleTransportClass *parent_class = NULL;
+
+enum {
+	PROP_0
+};
+
+GType
+jingle_s5b_get_type()
+{
+	static GType type = 0;
+
+	if (type == 0) {
+		static const GTypeInfo info = {
+			sizeof(JingleS5BClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) jingle_s5b_class_init,
+			NULL,
+			NULL,
+			sizeof(JingleS5B),
+			0,
+			(GInstanceInitFunc) jingle_s5b_init,
+			NULL
+		};
+		type = g_type_register_static(JINGLE_TYPE_TRANSPORT, "JingleS5B", &info, 0);
+	}
+	return type;
+}
+
+static void
+jingle_s5b_class_init (JingleS5BClass *klass)
+{
+	GObjectClass *gobject_class = (GObjectClass*)klass;
+	parent_class = g_type_class_peek_parent(klass);
+
+	gobject_class->finalize = jingle_s5b_finalize;
+	gobject_class->set_property = jingle_s5b_set_property;
+	gobject_class->get_property = jingle_s5b_get_property;
+	klass->parent_class.to_xml = jingle_s5b_to_xml_internal;
+	klass->parent_class.parse = jingle_s5b_parse_internal;
+	klass->parent_class.transport_type = JINGLE_TRANSPORT_S5B;
+
+	g_type_class_add_private(klass, sizeof(JingleS5BPrivate));
+}
+
+static void
+jingle_s5b_init (JingleS5B *s5b)
+{	
+	s5b->priv = JINGLE_S5B_GET_PRIVATE(s5b);
+	memset(s5b->priv, 0, sizeof(s5b->priv));
+}
+
+static void
+jingle_s5b_finalize (GObject *s5b)
+{
+	JingleS5BPrivate *priv = JINGLE_S5B_GET_PRIVATE(s5b);
+	purple_debug_info("jingle-s5b","jingle_s5b_finalize\n");
+	
+	G_OBJECT_CLASS(parent_class)->finalize(s5b);
+}
+
+static void
+jingle_s5b_set_property (GObject *object, guint prop_id, const GValue *value, 
+	GParamSpec *pspec)
+{
+	JingleS5B *s5b;
+	g_return_if_fail(JINGLE_IS_S5B(object));
+
+	s5b = JINGLE_S5B(object);
+
+	switch (prop_id) {
+		default:	
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+jingle_s5b_get_property (GObject *object, guint prop_id, GValue *value, 
+	GParamSpec *pspec)
+{
+	JingleS5B *s5b;
+	g_return_if_fail(JINGLE_IS_S5B(object));
+	
+	s5b = JINGLE_S5B(object);
+
+	switch (prop_id) {
+		default:	
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);	
+			break;
+	}
+}
+
+static JingleTransport *
+jingle_s5b_parse_internal(xmlnode *s5b)
+{
+	JingleTransport *transport = parent_class->parse(s5b);
+	JingleS5BPrivate *priv = JINGLE_S5B_GET_PRIVATE(transport);
+	
+	return transport;
+}
+
+static xmlnode *
+jingle_s5b_to_xml_internal(JingleTransport *transport, xmlnode *content, 
+	JingleActionType action)
+{
+	xmlnode *node = parent_class->to_xml(transport, content, action);
+
+	purple_debug_info("jingle", "jingle_ibb_to_xml_internal\n");
+
+	return node;
+}
+
============================================================
--- libpurple/protocols/jabber/jingle/s5b.h	b10ecd3a14448792df79e4356fdac0de79a28941
+++ libpurple/protocols/jabber/jingle/s5b.h	b10ecd3a14448792df79e4356fdac0de79a28941
@@ -0,0 +1,74 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+ 
+#ifndef JINGLE_S5B_H
+#define JINGLE_S5B_H
+ 
+#include <glib.h>
+#include <glib-object.h>
+
+#include "transport.h"
+
+G_BEGIN_DECLS
+
+#define JINGLE_TYPE_S5B            (jingle_s5b_get_type())
+#define JINGLE_S5B(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), JINGLE_TYPE_S5B, JingleS5B))
+#define JINGLE_S5B_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), JINGLE_TYPE_S5B, JingleS5BClass))
+#define JINGLE_IS_S5B(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), JINGLE_TYPE_S5B))
+#define JINGLE_IS_S5B_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), JINGLE_TYPE_S5B))
+#define JINGLE_S5B_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), JINGLE_TYPE_S5B, JingleS5BClass))
+
+/** @copydoc _JingleS5B */
+typedef struct _JingleS5B JingleS5B;
+/** @copydoc _JingleS5BClass */
+typedef struct _JingleS5BClass JingleS5BClass;
+/** @copydoc _JingleS5BPrivate */
+typedef struct _JingleS5BPrivate JingleS5BPrivate;
+ 
+ /** The S5B class */
+struct _JingleS5BClass
+{
+	JingleTransportClass parent_class;     /**< The parent class. */
+
+	xmlnode *(*to_xml) (JingleTransport *transport, xmlnode *content, JingleActionType action);
+	JingleTransport *(*parse) (xmlnode *transport);
+};
+
+/** The IBB class's private data */
+struct _JingleS5B
+{
+	JingleTransport parent;                /**< The parent of this object. */
+	JingleS5BPrivate *priv;      /**< The private data of this object. */
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Gets the S5B class's GType
+ *
+ * @return The S5B class's GType.
+ */
+GType jingle_s5b_get_type(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+G_END_DECLS
+ 
+#endif /* JINGLE_S5B_H */
\ No newline at end of file
============================================================
--- libpurple/protocols/jabber/Makefile.am	0d2f16fe14690024b8619ee7ec3f023afb2ac1ed
+++ libpurple/protocols/jabber/Makefile.am	a24cbc9d2d7168443eb0a9a82963001f5d03ced4
@@ -37,6 +37,8 @@ JABBERSOURCES = auth.c \
 			  jingle/rawudp.h \
 			  jingle/rtp.c \
 			  jingle/rtp.h \
+			  jingle/s5b.c \
+			  jingle/s5b.h \
 			  jingle/session.c \
 			  jingle/session.h \
 			  jingle/transport.c \
============================================================
--- libpurple/protocols/jabber/Makefile.mingw	13dde37ebec9e8c76db86b6f0fa7f500b6954e83
+++ libpurple/protocols/jabber/Makefile.mingw	b23c63dd597c515f3bf1ace874f67881b6afe06c
@@ -61,6 +61,7 @@ C_SRC =	\
 			jingle/iceudp.c \
 			jingle/rawudp.c \
 			jingle/rtp.c \
+			jingle/s5b.c \
 			jingle/session.c \
 			jingle/transport.c \
 			jutil.c \
============================================================
--- libpurple/protocols/jabber/disco.c	b73258ecd67112416a054920848bbc5d5bfcb9f4
+++ libpurple/protocols/jabber/disco.c	31a61f89b485139e1fdf474dedd823b6a2f8fb06
@@ -142,6 +142,8 @@ void jabber_disco_info_parse(JabberStrea
 			SUPPORT_FEATURE("urn:xmpp:ping")
 			SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0199.html#ns")
 			SUPPORT_FEATURE(JINGLE_APP_FT)
+			SUPPORT_FEATURE(JINGLE_TRANSPORT_IBB)
+			SUPPORT_FEATURE(JINGLE_TRANSPORT_S5B)
 							
 			if(!node) { /* non-caps disco#info, add all enabled extensions */
 				GList *features;
============================================================
--- libpurple/protocols/jabber/jingle/file-transfer.c	3a5357b54e9869852e79e639e3f223be1df4dd19
+++ libpurple/protocols/jabber/jingle/file-transfer.c	5fdd8140c1ebc624c07a554709ba770ec8d45c09
@@ -19,6 +19,7 @@
 #include "jingle.h"
 #include "file-transfer.h"
 #include "ibbs.h"
+#include "s5b.h"
 #include "debug.h"
 #include "xmlnode.h"
 #include "xfer.h"
@@ -573,7 +574,26 @@ jingle_file_transfer_handle_action_inter
 	}
 }
 
+static void
+jingle_file_transfer_add_ibb_session_to_transport(JabberStream *js,
+	JingleTransport *transport, JingleContent *content, const gchar *jid)
+{
+	gchar *sid = jabber_get_next_id(js);
 
+	if (JINGLE_IS_IBB(transport)) {
+		jingle_ibb_create_session(JINGLE_IBB(transport), content, sid, jid);
+		jingle_ibb_set_data_sent_callback(JINGLE_IBB(transport),
+			jingle_file_transfer_ibb_data_sent_callback);
+		jingle_ibb_set_error_callback(JINGLE_IBB(transport),
+			jingle_file_transfer_ibb_error_callback);
+	} else {
+		purple_debug_error("jingle-ft",
+			"trying to setup an IBB session of a non-IBB transport\n");
+	}
+		
+	g_free(sid);
+}
+
 PurpleXfer *
 jingle_file_transfer_new_xfer(PurpleConnection *gc, const gchar *who)
 {
@@ -588,7 +608,8 @@ jingle_file_transfer_new_xfer(PurpleConn
 		JingleContent *content;
 		JingleTransport *transport;
 		gchar *jid = NULL, *me = NULL, *sid = NULL;
-
+		const gchar *transport_type = NULL;
+			
 		/* construct JID to send to */
 		JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
 		JabberBuddyResource *jbr;
@@ -602,6 +623,21 @@ jingle_file_transfer_new_xfer(PurpleConn
 			purple_debug_error("jingle-rtp", "Could not find buddy's resource\n");
 		}
 		
+		if (jabber_resource_has_capability(jbr, JINGLE_TRANSPORT_S5B)) {
+			purple_debug_info("jingle-ft", 
+				"receiver supports S5B, let's try that first\n");
+			transport_type = JINGLE_TRANSPORT_S5B;
+		} else if (jabber_resource_has_capability(jbr, JINGLE_TRANSPORT_IBB)) {
+			purple_debug_info("jingle-ft",
+				"receiver didn't support S5B but IBB, so let's try that\n");
+			transport_type = JINGLE_TRANSPORT_IBB;
+		} else {
+			purple_debug_error("jingle-ft",
+				"receiver doesn't support S5B or IBB, bailing out "
+				"(this shouldn't happen).");
+			return NULL;
+		}
+		
 		if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
 			jid = g_strdup_printf("%s/%s", who, jbr->name);
 		} else {
@@ -616,20 +652,17 @@ jingle_file_transfer_new_xfer(PurpleConn
 		g_free(sid);
 		
 		/* add the content */
-		/* for now just do IBB... */
-		transport = jingle_transport_create(JINGLE_TRANSPORT_IBB);
+		transport = jingle_transport_create(transport_type);
 		content = jingle_content_create(JINGLE_APP_FT, "initiator", "session",
 			"ft-session", "sender", transport);
 		jingle_session_add_content(session, content);
 		JINGLE_FT_GET_PRIVATE(JINGLE_FT(content))->xfer = xfer;
 
-		sid = jabber_get_next_id(js);
-		jingle_ibb_create_session(JINGLE_IBB(transport), content, sid, jid);
-		jingle_ibb_set_data_sent_callback(JINGLE_IBB(transport),
-			jingle_file_transfer_ibb_data_sent_callback);
-		jingle_ibb_set_error_callback(JINGLE_IBB(transport),
-			jingle_file_transfer_ibb_error_callback);
-		
+		if (JINGLE_IS_IBB(transport)) {
+			jingle_file_transfer_add_ibb_session_to_transport(js, transport, 
+				content, jid);
+		}
+
 		xfer->data = content;
 		purple_xfer_set_init_fnc(xfer, jingle_file_transfer_xfer_init);
 		purple_xfer_set_cancel_send_fnc(xfer, jingle_file_transfer_cancel_send);
============================================================
--- libpurple/protocols/jabber/jingle/ibbs.h	c8e75845fbc502bd96af3dddd711243aa7d38c5f
+++ libpurple/protocols/jabber/jingle/ibbs.h	4cc87c1ff8904b72e6240f8cef9dfa2d6fecd770
@@ -14,10 +14,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
  */
  
- #ifndef JINGLE_IBB_H
- #define JINGLE_IBB_H
+#ifndef JINGLE_IBB_H
+#define JINGLE_IBB_H
  
- #include <glib.h>
+#include <glib.h>
 #include <glib-object.h>
 
 #include "transport.h"
@@ -92,4 +92,4 @@ G_END_DECLS
 
 G_END_DECLS
  
- #endif /* JINGLE_IBB_H */
\ No newline at end of file
+#endif /* JINGLE_IBB_H */
\ No newline at end of file
============================================================
--- libpurple/protocols/jabber/jingle/jingle.c	085a573101f35e76aa7296d5b4dbbcc7afca73cf
+++ libpurple/protocols/jabber/jingle/jingle.c	633faaf302f3579ccedacbb70a1cbaa323ed48e0
@@ -32,6 +32,7 @@
 #include "iceudp.h"
 #include "rawudp.h"
 #include "rtp.h"
+#include "s5b.h"
 
 GType
 jingle_get_type(const gchar *type)
@@ -40,10 +41,8 @@ jingle_get_type(const gchar *type)
 		return JINGLE_TYPE_RAWUDP;
 	else if (!strcmp(type, JINGLE_TRANSPORT_ICEUDP))
 		return JINGLE_TYPE_ICEUDP;
-#if 0
-	else if (!strcmp(type, JINGLE_TRANSPORT_SOCKS))
-		return JINGLE_TYPE_SOCKS;
-#endif
+	else if (!strcmp(type, JINGLE_TRANSPORT_S5B))
+		return JINGLE_TYPE_S5B;
 	else if (!strcmp(type, JINGLE_TRANSPORT_IBB))
 		return JINGLE_TYPE_IBB;
 #ifdef USE_VV


More information about the Commits mailing list