cpw.malu.xmpp.google_ft: f44227c4: Add NiceAgent, gathering local candidate...

malu at pidgin.im malu at pidgin.im
Wed Sep 8 17:16:32 EDT 2010


----------------------------------------------------------------------
Revision: f44227c4eeb9eb070339d379cdd47d6df77c5fd6
Parent:   02a1680a14e01e88dfd14ac2d344869f08d5458f
Author:   malu at pidgin.im
Date:     09/08/10 17:10:30
Branch:   im.pidgin.cpw.malu.xmpp.google_ft
URL: http://d.pidgin.im/viewmtn/revision/info/f44227c4eeb9eb070339d379cdd47d6df77c5fd6

Changelog: 

Add NiceAgent, gathering local candidates doesn't quite seem to work yet (only gets a local IP candidate)

Changes against parent 02a1680a14e01e88dfd14ac2d344869f08d5458f

  patched  libpurple/protocols/jabber/Makefile.am
  patched  libpurple/protocols/jabber/google/google_share.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/Makefile.am	6271ccec937ef472f6bf717e2aff68a90325d527
+++ libpurple/protocols/jabber/Makefile.am	9e85dbe7b07ebb979cbc11a773e25686f436dac0
@@ -117,7 +117,8 @@ libjabber_la_LIBADD  = $(GLIB_LIBS) $(SA
 libjabber_la_LIBADD  = $(GLIB_LIBS) $(SASL_LIBS) $(LIBXML_LIBS) $(IDN_LIBS)\
 	$(FARSIGHT_LIBS) \
 	$(GSTREAMER_LIBS) \
-	$(GSTINTERFACES_LIBS)
+	$(GSTINTERFACES_LIBS) \
+	$(LIBNICE_LIBS)
 
 libxmpp_la_SOURCES = libxmpp.c
 libxmpp_la_LIBADD = libjabber.la
============================================================
--- libpurple/protocols/jabber/google/google_share.c	6f1676f0e50518b31f3a4a1149e4d32b8a04c81a
+++ libpurple/protocols/jabber/google/google_share.c	6702481560bb2e336d5e34cb472ac30ec639ea84
@@ -20,6 +20,7 @@
 
 #include "internal.h"
 #include "debug.h"
+#include "network.h"
 #include "google_share.h"
 #include "relay.h"
 
@@ -29,17 +30,70 @@ typedef struct {
 
 typedef struct {
 	PurpleXfer *xfer;
+	NiceAgent *agent;
+	guint stream_id;
 	GList *remote_candidates; /* list of PurpleMediaCandidate */
 	gboolean got_relay;		/* this indicates if gotten relay credentials */
 } GoogleShareSessionData;
 
 static void
+google_share_request_denied(PurpleXfer *xfer)
+{
+	/* TODO: implement request denied */
+}
+
+static void
 google_share_init(PurpleXfer *xfer)
 {
 	/* TODO: implement init here... */
+	GoogleShareSessionData *session_data =
+		(GoogleShareSessionData *) ((GoogleSession *) xfer->data)->session_data;
+
+	/* start agent */
+	nice_agent_gather_candidates(session_data->agent, session_data->stream_id);
+	/* set up signal */
 }
 
 static void
+google_share_init_agent(GoogleSession *session,
+    const gchar *relay_ip, guint relay_udp, guint relay_tcp, guint relay_ssltcp,
+    const gchar *relay_username, const gchar *relay_password)
+{
+	GoogleShareSessionData *session_data =
+		(GoogleShareSessionData *) session->session_data;
+	NiceAgent *agent = nice_agent_new_reliable(g_main_context_default(),
+		NICE_COMPATIBILITY_GOOGLE);
+	guint stream_id = nice_agent_add_stream(agent, 1);
+	const gchar *stun_ip = purple_network_get_stun_ip() ?
+		purple_network_get_stun_ip() : session->js->stun_ip;
+	guint stun_port = purple_network_get_stun_ip() ? 3478 : session->js->stun_port;
+	
+	if (stream_id > 0) {
+		session_data->agent = agent;
+		session_data->stream_id = stream_id;
+
+		/* set STUN server */
+		if (stun_ip) {
+			g_object_set(G_OBJECT(agent), "stun-server", stun_ip,
+				"stun-server-port", stun_port, NULL);
+		}
+		
+		/* set relays */
+		if (relay_ip) {
+			if (relay_udp)
+				nice_agent_set_relay_info(agent, stream_id, 0, relay_ip, relay_udp,
+					relay_username, relay_password, NICE_RELAY_TYPE_TURN_UDP);
+			if (relay_tcp)
+				nice_agent_set_relay_info(agent, stream_id, 0, relay_ip, relay_tcp,
+			    	relay_username, relay_password, NICE_RELAY_TYPE_TURN_TCP);
+			if (relay_ssltcp)
+				nice_agent_set_relay_info(agent, stream_id, 0, relay_ip, relay_ssltcp,
+			    	relay_username, relay_password, NICE_RELAY_TYPE_TURN_TLS);
+		}
+	}
+}
+
+static void
 google_relay_response_share_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)
@@ -48,6 +102,8 @@ google_relay_response_share_handle_initi
 		(GoogleShareSessionData *) session->session_data;
 	
 	purple_xfer_request(session_data->xfer);
+	google_share_init_agent(session, relay_ip, relay_udp, relay_tcp, relay_ssltcp,
+		relay_username, relay_password);
 }
 
 void google_share_handle_initiate(JabberStream *js, GoogleSession *session,
@@ -72,6 +128,8 @@ void google_share_handle_initiate(Jabber
 	purple_xfer_set_filename(session_data->xfer, name);
 	purple_xfer_set_size(session_data->xfer, size);
 	purple_xfer_set_init_fnc(session_data->xfer, google_share_init);
+	purple_xfer_set_request_denied_fnc(session_data->xfer,
+		google_share_request_denied);
 	session_data->xfer->data = session;
 	session->session_data = session_data;
 	


More information about the Commits mailing list