/soc/2013/ashmew2/filetransferX: 72f35879957d: Modified gtalk_xf...

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


Changeset: 72f35879957dd8d683b08673f67c3b74c90f7a7d
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-20 04:55 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/72f35879957d

Description:

Modified gtalk_xfer_handle_candidates

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  112 ++++++++++++++------
 1 files changed, 76 insertions(+), 36 deletions(-)

diffs (139 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
@@ -1180,13 +1180,53 @@ google_session_handle_transport_accept(J
 	jabber_iq_send(result_iq);
 }
 
+NiceCandidate *
+nice_candidate_from_xml(const xmlnode *candidate,
+			guint stream_id)
+{
+	NiceCandidate *cand = NULL;
+	const gchar *name = xmlnode_get_attrib(candidate, "name");
+	const gchar *type = xmlnode_get_attrib(candidate, "type");
+	const gchar *address = xmlnode_get_attrib(candidate, "address");
+	guint port = atoi(xmlnode_get_attrib(candidate, "port"));
+	const gchar *protocol = xmlnode_get_attrib(candidate, "protocol");
+	const gchar *preference = xmlnode_get_attrib(candidate, "preference");
+	
+	if (name && type && address && port != 0) {
+		guint prio = preference ? g_ascii_strtod(preference, NULL) * 1000 : 0;
+		cand = nice_candidate_new(purple_strequal(type, "host") ?
+			NICE_CANDIDATE_TYPE_HOST :
+			purple_strequal(type, "stun") ? NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE :
+			purple_strequal(type, "relay") ? NICE_CANDIDATE_TYPE_RELAYED :
+			NICE_CANDIDATE_TYPE_HOST);
+
+		nice_address_init(&cand->addr);
+
+		if (!nice_address_set_from_string(&cand->addr, address)) {
+			purple_debug_error("google-share",
+				"got invalid address in remote candidate\n");
+			nice_candidate_free(cand);
+			return NULL;
+		}
+
+		nice_address_set_port(&cand->addr, port);
+		cand->priority = prio;
+		cand->stream_id = stream_id;
+		cand->username = g_strdup(xmlnode_get_attrib(candidate, "username"));
+		cand->password = g_strdup(xmlnode_get_attrib(candidate, "password"));
+	} else {
+		purple_debug_error("google-share", "received invalid candidate!\n");
+	}
+
+	return cand;
+}
+
 static void
 gtalk_xfer_handle_candidates(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
 {/*<iq to="doondoon1234 at gmail.com/F0529E73" type="set" id="249" from="ashmew2 at gmail.com/Talk.v1040217A105"><session type="transport-info" id="1195983148" initiator="ashmew2 at gmail.com/Talk.v1040217A105" xmlns="http://www.google.com/session"><transport xmlns="http://www.google.com/transport/p2p"><candidate name="private-1" address="10.0.2.15" port="58919" preference="1" username="j8xIQAN/LvaC/dxb" protocol="udp" generation="0" password="eEy12J+BFBmZO0jj" type="local" network="0"/></transport></session></iq>*/
 
-	NiceCandidate *candid = nice_candidate_new(NICE_CANDIDATE_TYPE_HOST);
 	GSList *candidate_list = NULL;
-	xmlnode *candidate_node;
+	xmlnode *candidate_node, *transport_node;
 	GoogleAVSessionData *session_data = (GoogleAVSessionData*)session->session_data;
 	GoogleXferSessionData *share_session = session_data->share_session;
 	JabberIq *result;
@@ -1194,45 +1234,45 @@ gtalk_xfer_handle_candidates(JabberStrea
 	purple_debug_info("google_session", "Inside gtalk_xfer_handle_candidates..\n");
 
 	/*Sending IQ_RESULT first and then processing the candidate*/
+/*Modifying this to handle multiple candidates inside a single transport message*/
+	
+	if(sess)
+		transport_node = xmlnode_get_child(sess, "transport");
+
+	if(transport_node) {
+		
+		for (candidate_node = xmlnode_get_child(transport_node, "candidate");
+		     candidate_node; candidate_node = xmlnode_get_next_twin(candidate_node)) {
+			NiceCandidate *cand =
+				nice_candidate_from_xml(candidate_node,
+							share_session->stream_id);
+			
+			if (cand) {
+				candidate_list = g_slist_append(candidate_list, cand);
+			}
+		}
+		
+		if (share_session->candidates_gathered) {
+			nice_agent_set_remote_candidates(share_session->share_agent, share_session->stream_id,
+							 1, candidate_list);
+			while(candidate_list) {
+				NiceCandidate *c = (NiceCandidate *) candidate_list->data;
+				nice_candidate_free(c);
+				candidate_list = g_slist_delete_link(candidate_list, candidate_list);
+			}
+
+		} else {
+			share_session->remote_share_candidates =
+				g_slist_concat(share_session->remote_share_candidates, candidate_list);
+		}		
+	}
+	purple_debug_info("google_session", "Added remote candidate to Nice Agent!.\n");	
+	
 	result = jabber_iq_new(js, JABBER_IQ_RESULT);
 	jabber_iq_set_id(result, iq_id);
 	xmlnode_set_attrib(result->node, "to", session->remote_jid);
 	jabber_iq_send(result);
-	
-	if(sess)
-		candidate_node = xmlnode_get_child(xmlnode_get_child(sess, "transport"), "candidate");
 
-	if(candidate_node) {
-		gchar *type = xmlnode_get_attrib(candidate_node, "type");
-		candid->type = (!strcmp(type, "local") ? NICE_CANDIDATE_TYPE_HOST : 
-				!strcmp(type, "stun") ? NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE :
-				!strcmp(type, "relay") ? NICE_CANDIDATE_TYPE_RELAYED :
-				NICE_CANDIDATE_TYPE_HOST);
-
-		if(!strcmp(xmlnode_get_attrib(candidate_node, "protocol"), "udp"))
-			candid->transport = NICE_CANDIDATE_TRANSPORT_UDP;
-		else {
-			purple_debug_info("google_session", "Remote Candidate is not UDP...Returning..\n");
-			return;
-		}
-		nice_address_init(&candid->addr);
-		nice_address_set_from_string(&candid->addr, xmlnode_get_attrib(candidate_node, "address"));
-		nice_address_set_port(&candid->addr, atoi(xmlnode_get_attrib(candidate_node, "port")));
-		candid->stream_id = share_session->stream_id;
-		candid->username = g_strdup(xmlnode_get_attrib(candidate_node, "username"));
-		if(!candid->username)
-			candid->username = g_strdup("");
-		candid->password = g_strdup(xmlnode_get_attrib(candidate_node, "password"));
-		if(!candid->password)
-			candid->password = g_strdup("");
-		candidate_list = g_slist_append(candidate_list, candid);
-		nice_agent_set_remote_candidates(share_session->share_agent, 
-						 share_session->stream_id, share_session->share_channel->component_id, 
-						 candidate_list);
-		g_slist_free(candidate_list);
-	}
-	
-	purple_debug_info("google_session", "Added remote candidate to Nice Agent.\n");	
 }
 
 static void



More information about the Commits mailing list