/soc/2013/ashmew2/filetransferX: 68100e8776c6: Modified candidat...

Ashish Gupta ashmew2 at gmail.com
Mon Aug 19 19:25:51 EDT 2013


Changeset: 68100e8776c6824b6d701b5659db7d6d0244708f
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-20 04:28 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/68100e8776c6

Description:

Modified candidates_gathered_cb

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  89 ++++++++++++++++++++-
 1 files changed, 83 insertions(+), 6 deletions(-)

diffs (140 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
@@ -63,9 +63,10 @@ typedef struct {
 	NiceComponentState agent_state;
 	PurpleCircBuffer *buffer; /*Need to add something for HTTP_STATUS too */
 	guint stream_id;
+	gboolean candidates_gathered;
 	GList *remote_share_candidates; /* lists of PurpleMediaCandidate OR NiceCandidates(maybe?)*/
 	GList *local_share_candidates;
-
+	
 } GoogleXferSessionData; 
 /*Thanks malu!*/
 
@@ -447,7 +448,7 @@ jabber_google_relay_response_session_ini
 		if(!share_session->share_agent) {/*TODO: Should probably have an agent_init function for this..Later..*/
 			purple_xfer_request(share_session->xfer);
 			
-			agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);			
+			agent = nice_agent_new_reliable (g_main_context_default(), NICE_COMPATIBILITY_RFC5245);			
 			share_session->share_agent = agent;
 			share_session->stream_id = nice_agent_add_stream(agent, 1);
 			stream_id = share_session->stream_id;
@@ -1505,6 +1506,37 @@ gtalk_xfer_send_candidates(GoogleSession
 	}
 }
 
+/*Thanks for this, malu :D*/
+static xmlnode *
+nice_candidate_to_xml(const NiceCandidate *cand,
+	const gchar *channel_name)
+{
+	xmlnode *candidate = xmlnode_new("candidate");
+	gchar address[NICE_ADDRESS_STRING_LEN];
+	gchar pref[16];
+
+	nice_address_to_string(&cand->addr, address);
+	xmlnode_set_attrib(candidate, "address", address);
+	xmlnode_set_attrib(candidate, "port",
+		g_strdup_printf("%d", nice_address_get_port(&cand->addr)));
+	xmlnode_set_attrib(candidate, "name", channel_name);
+	xmlnode_set_attrib(candidate, "username", cand->username);
+	xmlnode_set_attrib(candidate, "password",
+		cand->password != NULL ? cand->password : "");
+	g_ascii_dtostr(pref, 16, cand->priority / 1000.0);
+	xmlnode_set_attrib(candidate, "preference", pref);
+	xmlnode_set_attrib(candidate, "protocol",
+		cand->transport == NICE_CANDIDATE_TRANSPORT_UDP ? "udp" : "tcp");
+	xmlnode_set_attrib(candidate, "type",
+	    cand->type == NICE_CANDIDATE_TYPE_HOST ? "host" :
+		cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE ? "stun" :
+		cand->type == NICE_CANDIDATE_TYPE_RELAYED ? "relay" : "host");
+	xmlnode_set_attrib(candidate, "generation", "0");
+	xmlnode_set_attrib(candidate, "network", "0");
+
+	return candidate;
+}
+
 void
 cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer user_data)
 {
@@ -1512,9 +1544,54 @@ cb_candidate_gathering_done(NiceAgent *a
   guint  stream_id = temp->stream_id;
   NiceAgent *agent = temp->agent;
 */
-	GList *lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
 	char *local_ufrag, *local_password;
 	GoogleSession *session = (GoogleSession *)user_data;
+	GoogleAVSessionData *session_data = session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
+	GList *local_candidates = nice_agent_get_local_candidates(agent, stream_id, 1);
+
+	purple_debug_info("google-share", "candidate gathering done!\n");
+	share_session->candidates_gathered = TRUE;
+
+	/* add remote candidates received while gathering local candidates */
+	nice_agent_set_remote_candidates(agent, share_session->stream_id, 1,
+					 share_session->remote_share_candidates);
+/*TODO: Free the remote_candidates list of the share_session : DONE?*/
+
+	while (share_session->remote_share_candidates) {
+		NiceCandidate *c = (NiceCandidate *) share_session->remote_share_candidates->data;
+		nice_candidate_free(c);
+		share_session->remote_share_candidates = g_slist_delete_link(share_session->remote_share_candidates,
+									     share_session->remote_share_candidates);
+	}
+		
+	/* Time to send local candidates. */
+	while (local_candidates) {
+		NiceCandidate *candidate = (NiceCandidate *) local_candidates->data;
+		JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+		gchar address[NICE_ADDRESS_STRING_LEN];
+		gchar pref[16];
+		gchar *me = g_strdup_printf("%s@%s/%s",
+				session->js->user->node,
+				session->js->user->domain,
+				session->js->user->resource);
+		/*Preparing the xmlnode for sending out candidates to gtalk*/
+		xmlnode *sess = google_session_create_xmlnode(session, "transport-info");
+		xmlnode *transport = xmlnode_new_child(sess, "transport");
+
+		xmlnode_insert_child(transport, nice_candidate_to_xml(candidate, share_session->channel_name));
+		xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
+
+		xmlnode_insert_child(iq->node, sess);
+		xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+		xmlnode_set_attrib(iq->node, "from", me);
+		jabber_iq_send(iq);
+
+		nice_candidate_free(candidate);
+		local_candidates = g_slist_delete_link(local_candidates, local_candidates);
+	}
+
+/*
 	JabberStream *js = session->js;
 	char *buf1,*buf2,*buf3;
 	gchar *me = g_strdup_printf("%s@%s/%s",
@@ -1543,10 +1620,10 @@ cb_candidate_gathering_done(NiceAgent *a
 				candid->password = g_strdup(local_password);
 
                         /*Insert it into our GoogleXferSession's local_share_candidates*/
-			share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, candid);
+/*			share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, candid);
 			/*TODO: local_share_candidates are being added to the list here itself. What about the part that follows?
 			  Shouldn't relay candidates and these candidates be togeter?*/
-		}
+
 
 /*Send relay candidates. TODO: Relocate and Fix Initiator*/
 /*	buf1=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"19305\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
@@ -1558,7 +1635,7 @@ cb_candidate_gathering_done(NiceAgent *a
 	jabber_send_raw(js,buf3,strlen(buf3));
 	purple_debug_info("google_session", "Sent ALL CANDIDATES \n");
 */
-	}
+
 
 /*TODO: Once the candidates have beeng gthered, we must send out our GList of NiceCandidates.
 Call gtalk_xfer_send_candidates() Here .



More information about the Commits mailing list