/soc/2013/ashmew2/filetransferX: 88d983aeabfa: Own Public IP

Ashish Gupta ashmew2 at gmail.com
Wed Aug 14 15:00:42 EDT 2013


Changeset: 88d983aeabfa59dc98825675ed7dac0f440765d0
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-15 00:30 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/88d983aeabfa

Description:

Own Public IP

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  91 +++++++++++++++------
 libpurple/protocols/jabber/jabber.c                |   3 +-
 libpurple/protocols/jabber/si.c                    |   2 +-
 3 files changed, 67 insertions(+), 29 deletions(-)

diffs (225 lines):

diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c
--- a/libpurple/protocols/jabber/google/google_session.c
+++ b/libpurple/protocols/jabber/google/google_session.c
@@ -201,8 +201,8 @@ google_session_ready(GoogleSession *sess
 	gboolean video =
 		((GoogleAVSessionData *)session->session_data)->video;
 	gboolean share = 
-		((GoogleAVSessionData *)session->session_data)->share;
-		
+		((GoogleAVSessionData *)session->session_data)->share;		
+
 	if (purple_media_codecs_ready(media, NULL) &&
 			purple_media_candidates_prepared(media, NULL, NULL)) {
 		gchar *me = g_strdup_printf("%s@%s/%s",
@@ -219,6 +219,8 @@ google_session_ready(GoogleSession *sess
 			g_free(me);
 			return;
 		}
+		
+		purple_debug_info("google_session", "Inside google_session_ready\n");
 
 		iq = jabber_iq_new(session->js, JABBER_IQ_SET);
 
@@ -389,7 +391,7 @@ jabber_google_relay_response_session_ini
 	JabberStream *js = session->js;
 	GoogleAVSessionData *session_data =
 		(GoogleAVSessionData *) session->session_data;
-
+	
 	session_data->media = purple_media_manager_create_media(
 			purple_media_manager_get(),
 			purple_connection_get_account(js->gc),
@@ -427,7 +429,6 @@ jabber_google_relay_response_session_ini
 	g_free(params);
 }
 
-
 gboolean
 jabber_google_session_initiate(JabberStream *js, const gchar *who, PurpleMediaSessionType type)
 {
@@ -436,6 +437,7 @@ jabber_google_session_initiate(JabberStr
 	JabberBuddyResource *jbr;
 	gchar *jid;
 	GoogleAVSessionData *session_data = NULL;
+	purple_debug_info("google_session", "Inside jabber_google_session_initiate\n");
 
 	/* construct JID to send to */
 	jb = jabber_buddy_find(js, who, FALSE);
@@ -606,6 +608,7 @@ google_session_handle_initiate(JabberStr
 	if (session->state != UNINIT) {
 		purple_debug_error("jabber", "Received initiate for active session.\n");
 		return FALSE;
+		
 	}
 	
 	session->description = xmlnode_copy(xmlnode_get_child(sess, "description"));
@@ -769,6 +772,16 @@ FT XML:
 		  purple_debug_info("google_session", "\nSent set_iq\n");
 		*/
 		/*TODO : Fix name for ResponseIq */
+
+/*		if (js->google_relay_host && js->google_relay_token) {
+			jabber_google_do_relay_request(js, session,
+						       jabber_google_relay_response_session_initiate_cb);
+		} else {
+			jabber_google_relay_response_session_initiate_cb(session, NULL, 0, 0, 0,
+									 NULL, NULL);
+	}
+
+*/
 		  ResponseIq = jabber_iq_new(js,JABBER_IQ_RESULT);
 		  xmlnode_set_attrib(ResponseIq->node, "to", session->remote_jid);
 		  jabber_iq_set_id(ResponseIq, iq_id);
@@ -1032,18 +1045,35 @@ gtalk_port_cb(int listenfd, gpointer dat
 }
 
 void
-cb_candidate_gathering_done(TempStruct *temp)
+cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer user_data)
 {
-  guint  stream_id = temp->stream_id;
+/*  guint  stream_id = temp->stream_id;
   NiceAgent *agent = temp->agent;
-  GList *lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
+*/  
+	GList *lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
 
-  purple_debug_info("google_session", "CANDIDATES GATHERED??\n");
+	purple_debug_info("google_session", "CANDIDATES GATHERED??\n");
+	
+	if(lcands) {
+		GList *iter = lcands;
+		purple_debug_info("google_session", "lcands is nOT null..\n");
+		for(; iter; iter = iter->next) {
+			gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
+			NiceCandidate *candid = (NiceCandidate *)iter->data;
+			NiceAddress *address = &(candid->addr);
+			nice_address_to_string (address, ip);
+			purple_debug_info("google_session", "IP is %s\n",ip);
+		}
+	}
+	else
+		purple_debug_info("google_session", "lcands is NULL\n");	  
+}
 
-  if(lcands)
-	  purple_debug_info("google_session", "lcands is nOT null..\n");
-  else
-	  purple_debug_info("google_session", "lcands is NULL\n");	  
+void
+cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_id,
+    guint len, gchar *buf, gpointer data)
+{
+//dummy function
 }
 
 void
@@ -1054,26 +1084,26 @@ gtalk_xfer_send_candidates(GoogleSession
 	gchar buffer[] = "hello world!";
 	GSList *lcands = NULL, *rcands = NULL;
 	TempStruct *temp_struct = g_new0(TempStruct, 1);
-  
+	GMainLoop *gloop;
 	// Create a nice agent
-	NiceAgent *agent = nice_agent_new (NULL, NICE_COMPATIBILITY_GOOGLE);
+	NiceAgent *agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);
 	JabberStream *js = session->js;
 
-	agent->stun_server = js->stun_ip;
-	agent->stun_server_port = js->stun_port;
 	if(!g_object_get_data(G_OBJECT (agent), "stun->server")) {
 		purple_debug_info("google_session", "Agent's STUN is NULL..");
-		g_object_set_property (G_OBJECT (agent), "stun-server", js->stun_ip);
-		g_object_set_property (G_OBJECT (agent), "stun-server-port", &(js->stun_port));	    
+		g_object_set(G_OBJECT (agent), "stun-server", js->stun_ip, NULL);
+		g_object_set(G_OBJECT (agent), "stun-server-port", js->stun_port, NULL);
+		purple_debug_info("google_session", "Set Stun info");
 	}
 	else
 		purple_debug_info("google_session", "Agent's stun was not NULL.");
 
+	gloop = g_main_loop_new(NULL, FALSE);
+	  
+	
 	purple_debug_info("google_session", "Inside send candids\n");
 	temp_struct->agent = agent;
-	// Connect the signals
-	g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
-			  G_CALLBACK (cb_candidate_gathering_done),  G_OBJECT (temp_struct));
+	// Connect the signals	
 
 	/*  g_signal_connect (G_OBJECT (agent), "component-state-changed",
 	    G_CALLBACK (cb_component_state_changed), NULL);
@@ -1085,17 +1115,25 @@ gtalk_xfer_send_candidates(GoogleSession
 	stream_id = nice_agent_add_stream (agent, 1);
 	temp_struct->stream_id = stream_id;
 
+	  nice_agent_attach_recv(agent, stream_id, 1,
+      g_main_loop_get_context (gloop), cb_nice_recv, NULL);
+
+/*	  nice_agent_attach_recv (agent, stream_id, 1, NULL,
+				cb_nice_recv, NULL);
+*/
+	g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
+			  G_CALLBACK (cb_candidate_gathering_done),  NULL);
+	
 
 	if(!nice_agent_gather_candidates (agent, stream_id))
 		purple_debug_info("google_session", "Gather candidates returned FALSE\n");
 	else
 		purple_debug_info("google_session", "Gather Candidates returned TRUE\n");
-
+	g_main_loop_run (gloop);
+	g_object_unref(agent);
 	return;
 	// Attach to the component to receive the data
-	/*  nice_agent_attach_recv (agent, stream_id, 1, NULL
-	    cb_nice_recv, NULL);
-
+	
 	    /*TODO: need to add $(NICE_LIBS) and look it up with configure.ac*/
   
 	// ... Wait until the signal candidate-gathering-done is fired ...
@@ -1364,6 +1402,7 @@ gtalk_xfer_init(PurpleXfer *xfer)
 	//	purple_xfer_start( xfer, -1, xfer->remote_ip, xfer->remote_port );
 	
 }
+
 void gtalk_xfer_send_info(JabberStream *js, GoogleSession *session, xmlnode *sess)
 {
 
@@ -1590,7 +1629,7 @@ jabber_google_session_parse(JabberStream
 				}
 			}
 		}
-
+	
 		/*if session!=NULL, it's a Share Session*/
 		if(session) {
 			google_session_parse_iq(js, session, session_node, iq_id);
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -3299,8 +3299,7 @@ jabber_initiate_media(PurpleAccount *acc
 				"jabber_initiate_media: NULL stream\n");
 		return FALSE;
 	}
-
-
+	purple_debug_info("jabber", "Inside jabber_initiate_media");
 	if((resource = jabber_get_resource(who)) != NULL) {
 		/* they've specified a resource, no need to ask or
 		 * default or anything, just do it */
diff --git a/libpurple/protocols/jabber/si.c b/libpurple/protocols/jabber/si.c
--- a/libpurple/protocols/jabber/si.c
+++ b/libpurple/protocols/jabber/si.c
@@ -1663,7 +1663,7 @@ void jabber_si_xfer_send(PurpleConnectio
 	PurpleXfer *xfer;
 	JabberStream *js = purple_connection_get_protocol_data(gc);
 
-	if( js-> googletalk) {
+	if(js->googletalk) {
 	  purple_debug_info("jabber", "Found Google Talk. Try to Send File Now..");
 	  gtalk_xfer_send(gc, who, file);
 	  return;



More information about the Commits mailing list