/soc/2013/ashmew2/filetransferX: 5001010cb75a: Hack For Share Se...

Ashish Gupta ashmew2 at gmail.com
Sun Aug 4 07:54:14 EDT 2013


Changeset: 5001010cb75a3460f5bb92a008dd7d2c4958c527
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-04 17:24 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/5001010cb75a

Description:

Hack For Share Session

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  72 ++++++++++++++++-----
 libpurple/protocols/jabber/jabber.c                |   6 +-
 2 files changed, 60 insertions(+), 18 deletions(-)

diffs (173 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
@@ -651,13 +651,13 @@ google_session_handle_initiate(JabberStr
 		char *temp=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"initiate\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><description xmlns=\"http://www.google.com/session/share\"><manifest><file size=\"1611\"><name>XPLUS5.rar</name></file></manifest><protocol><http><url name=\"source-path\">/temporary/667e854066cbd01f8cd111c35752275e/</url><url name=\"preview-path\">/temporary/bca878ad01c248741978a105ed28d9a4/</url></http></protocol></description><transport xmlns=\"http://www.google.com/transport/p2p\"/></session></iq>",session->remote_jid, iq_id, me, xmlnode_get_attrib(sess, "id"), me);
 
 		if( description ) {
-			purple_debug_info("google_session", "\ndescription is not NULL");
+			purple_debug_info("google_session", "description is not NULL");
 			manifest = xmlnode_get_child(description, "manifest");
 			if( manifest ) {
-				purple_debug_info("google_session", "\nmanifest not NULL");
+				purple_debug_info("google_session", "manifest not NULL");
 				file = xmlnode_get_child(manifest, "file");
 				if( file ) {
-					purple_debug_info("google_session", "\nfile is not NULL");
+					purple_debug_info("google_session", "file is not NULL");
 					filename = xmlnode_get_child(file, "name");
 					filesize = xmlnode_get_attrib(file, "size");
 					purple_debug_info("google_session", "File size : %s",filesize);
@@ -673,10 +673,10 @@ google_session_handle_initiate(JabberStr
 			}
 			protocol = xmlnode_get_child(description, "protocol");
 			if( protocol ) { 
-				purple_debug_info("google_session", "\nprotocol is not NULL");
+				purple_debug_info("google_session", "protocol is not NULL");
 				http = xmlnode_get_child(protocol, "http");
 				if( http ) { 
-					purple_debug_info("google_session", "\nhttp is not NULL");
+					purple_debug_info("google_session", "http is not NULL");
 					url_source_path = xmlnode_get_child(http, "url");
 					if( url_source_path ) {
 						purple_debug_info("google_session", "url_source_path is not NULL. Name : %s",xmlnode_get_data(url_source_path));
@@ -692,9 +692,9 @@ google_session_handle_initiate(JabberStr
 			
 			transport = xmlnode_get_child(sess, "transport");
 			if( transport ) 
-				purple_debug_info("google_session", "\nTransport is not null : %s",xmlnode_get_attrib(transport, "xmlns"));
+				purple_debug_info("google_session", "Transport is not null : %s",xmlnode_get_attrib(transport, "xmlns"));
 			else
-				purple_debug_info("google_session", "\nTransport is NULL");
+				purple_debug_info("google_session", "Transport is NULL");
 		}
 		/**************************
 FT XML: 
@@ -717,10 +717,10 @@ FT XML:
 (23:33:01) jabber: Recv (ssl)(238): <iq to="doondoon1234 at gmail.com/B1D48535" type="set" id="152" from="ashmew2 at gmail.com/Talk.v104536A73D2"><session type="terminate" id="1800989809" initiator="ashmew2 at gmail.com/Talk.v104536A73D2" xmlns="http://www.google.com/session"/></iq>
 		************************************/
 		purple_debug_info("google_session", "We have received a file request.\n");
-		purple_debug_info("google_session", "\nme = %s. Length : %d\n",me, strlen(temp));
-		purple_debug_info("google_session", "\nParameter : iq_id = %s.\n", iq_id);
+		purple_debug_info("google_session", "me = %s. Length : %d\n",me, strlen(temp));
+		purple_debug_info("google_session", "Parameter : iq_id = %s.\n", iq_id);
 
-		purple_debug_info("google_session", "\nSending a file request in return\n");
+		purple_debug_info("google_session", "Sending a file request in return\n");
 		jabber_send_raw(js,temp,strlen(temp));
 		purple_debug_info("google_session","Sent to GTALK\n");
 		/*
@@ -786,7 +786,7 @@ google_session_handle_candidates(JabberS
 	char n[4];
 	GoogleAVSessionData *session_data =
 		(GoogleAVSessionData *) session->session_data;
-
+	purple_debug_info("google_session", "Inside google_session_handle_candidiates()\n");
 	for (cand = xmlnode_get_child(sess, "candidate"); cand;
 			cand = xmlnode_get_next_twin(cand)) {
 		PurpleMediaCandidate *info;
@@ -873,7 +873,14 @@ google_session_handle_transport_accept(J
 	xmlnode_set_attrib(result_iq->node, "to", session->remote_jid);
 	jabber_iq_set_id(result_iq, iq_id);
 	jabber_iq_send(result_iq);
-	purple_debug_info("google_session", "\nSent RESULT_IQ for google_session_handle_transport_accept\n");
+
+}
+
+static void
+google_session_handle_transport_info(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
+{
+
+	purple_debug_info("google_session", "TODO : Sent RESULT_IQ for google_session_handle_transport_info\n");
 }
 
 static void
@@ -977,10 +984,10 @@ google_session_parse_iq(JabberStream *js
 		google_session_handle_candidates(js, session, sess, iq_id);
 	} else if (!strcmp(type, "transport-accept")) {
 		google_session_handle_transport_accept(js, session, sess, iq_id);
-	} else {
-		purple_debug_info("google_session", "In google_session_parse_iq, Unhandled IQ type");
+	} else if (!strcmp(type, "transport-info")) {
+		google_session_handle_candidates(js, session, sess, iq_id);
 	}
-	
+
 }
 
 void
@@ -995,6 +1002,7 @@ jabber_google_session_parse(JabberStream
 
 	GList *iter = NULL;
 	
+	purple_debug_info("google_session", "inside jabber_google_session_parse\n");
 	if (type != JABBER_IQ_SET)
 		return;
 
@@ -1020,18 +1028,48 @@ jabber_google_session_parse(JabberStream
 	if (iter != NULL) {
 		g_list_free(iter);
 	}
-
+	
 	if (session) {
+		purple_debug_info("google_session", "Calling google_session_parse_iq from jabber_google_session_parse.MEDIA HACK WORKS.\n");
 		google_session_parse_iq(js, session, session_node, iq_id);
 		return;
 	}
+	else {
+		/*The session was NULL either because it was NULL, OR because it was a share-session and never added to the HashTable
+	    So we will try to deduce from the session_node if it's a share session which is already initiated and googletalk 
+	    on the other side. This is a temporary workaround and should be fixed by having a specific GList for File Transfers, making
+	    sessions of both AVtype as well as Share (FT).
+		*/
+
+		if(js->googletalk && strcmp(xmlnode_get_attrib(session_node, "type"), "initiate"))
+			{
+				session = g_new0(GoogleSession, 1);
+				session->id.id = g_strdup(id.id);
+				session->id.initiator = g_strdup(id.initiator);
+				session->state = UNINIT;
+				session->js = js;
+				session->remote_jid = g_strdup(session->id.initiator);
+				session->session_data = g_new0(GoogleAVSessionData, 1);
+
+				google_session_parse_iq(js, session, session_node, iq_id);
+				return;
+			}
+		else
+			purple_debug_info("google_session", "Check for session!=initiate and peer==gtalk FAILED.\n");	  
+	}
+	  
 
 	/* If the session doesn't exist, this has to be an initiate message */
-	if (strcmp(xmlnode_get_attrib(session_node, "type"), "initiate"))
+
+	if (strcmp(xmlnode_get_attrib(session_node, "type"), "initiate")) {
+		purple_debug_info("google_session", "It is NOT an initiate message, returning\n");
 		return;
+	}
+
 	desc_node = xmlnode_get_child(session_node, "description");
 	if (!desc_node)
 		return;
+
 	session = g_new0(GoogleSession, 1);
 	session->id.id = g_strdup(id.id);
 	session->id.initiator = g_strdup(id.initiator);
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
@@ -3532,7 +3532,11 @@ gboolean jabber_can_receive_file(PurpleC
 		 when actually trying */
 		if (jb == NULL)
 			return TRUE;
-
+		/* If the client on the other side is GoogleTalk, js->googletalk will be TRUE
+		   We know for a fact it can receive file, so return TRUE
+		*/
+		if (js->googletalk)
+			return TRUE;
 		/* find out if there is any resources without caps */
 		for (iter = jb->resources; iter ; iter = g_list_next(iter)) {
 			JabberBuddyResource *jbr = (JabberBuddyResource *) iter->data;



More information about the Commits mailing list