/soc/2013/ashmew2/filetransferX: ebf06164eefa: XML Parsed

Ashish Gupta ashmew2 at gmail.com
Thu Jul 25 08:15:19 EDT 2013


Changeset: ebf06164eefadf85de55f09a7505a46c8f9d9bb8
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-07-25 17:44 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/ebf06164eefa

Description:

XML Parsed

diffstat:

 libpurple/protocols/jabber/caps.c                  |   10 +-
 libpurple/protocols/jabber/disco.c                 |    2 +-
 libpurple/protocols/jabber/google/google_session.c |  116 ++++++++++++++++----
 libpurple/protocols/jabber/jabber.c                |    8 +-
 libpurple/protocols/jabber/namespaces.h            |    3 +
 libpurple/protocols/jabber/parser.c                |    2 +
 libpurple/xmlnode.c                                |    1 +
 7 files changed, 111 insertions(+), 31 deletions(-)

diffs (truncated from 303 to 300 lines):

diff --git a/libpurple/protocols/jabber/caps.c b/libpurple/protocols/jabber/caps.c
--- a/libpurple/protocols/jabber/caps.c
+++ b/libpurple/protocols/jabber/caps.c
@@ -358,7 +358,15 @@ gboolean jabber_caps_exts_known(const Ja
 		/* Hack since we advertise the ext along with v1.5 caps but don't
 		 * store any exts */
 		if (g_str_equal(exts[i], "voice-v1") && !info->exts)
-			continue;
+			{
+				purple_debug_info("caps","voice-v1 detected.");
+				continue;
+			}
+		if (g_str_equal(exts[i], "share-v1") && !info->exts)
+			{
+				purple_debug_info("caps","share-v1 detected.");
+				continue;
+			}
 		if (!info->exts ||
 				!g_hash_table_lookup(info->exts->exts, exts[i]))
 			return FALSE;
diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -145,7 +145,7 @@ void jabber_disco_info_parse(JabberStrea
 		} else if (g_str_equal(node, CAPS0115_NODE "#" "share-v1")) {
 		  
 			xmlnode *feature = xmlnode_new_child(query, "feature");
-			xmlnode_set_attrib(feature, "var", "http://google.com/xmpp/protocol/share/v1");
+			xmlnode_set_attrib(feature, "var", NS_GOOGLE_SHARE);
 #ifdef USE_VV
 		} else if (g_str_equal(node, CAPS0115_NODE "#" "voice-v1")) {
 			/*
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
@@ -30,6 +30,7 @@
 typedef struct {
 	PurpleMedia *media;
 	gboolean video;
+	gboolean share;
 	GList *remote_audio_candidates; /* list of PurpleMediaCandidate */
 	GList *remote_video_candidates; /* list of PurpleMediaCandidate */
 	gboolean added_streams;		/* this indicates if the streams have been
@@ -170,6 +171,9 @@ google_session_ready(GoogleSession *sess
 		((GoogleAVSessionData *)session->session_data)->media;
 	gboolean video =
 		((GoogleAVSessionData *)session->session_data)->video;
+	gboolean 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",
@@ -206,11 +210,16 @@ google_session_ready(GoogleSession *sess
 		}
 		xmlnode_insert_child(iq->node, sess);
 		desc = xmlnode_new_child(sess, "description");
-		if (video)
+
+		if (share) {
+			xmlnode_set_namespace(desc, NS_GOOGLE_SESSION_SHARE);
+			purple_debug_info("google_session", "Set namespace to NS_GOOGLE_SESSION_SHARE");
+		}
+		else if (video)
 			xmlnode_set_namespace(desc, NS_GOOGLE_SESSION_VIDEO);
 		else
 			xmlnode_set_namespace(desc, NS_GOOGLE_SESSION_PHONE);
-
+		
 		codecs = purple_media_get_codecs(media, "google-video");
 
 		for (iter = codecs; iter; iter = g_list_next(iter)) {
@@ -561,56 +570,114 @@ google_session_handle_initiate(JabberStr
 	const gchar *xmlns;
 	GoogleAVSessionData *session_data =
 		(GoogleAVSessionData *) session->session_data;
+	
+	purple_debug_info("google_session", "Inside google_session_handle_initiate");
 
 	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"));
 	xmlns = xmlnode_get_namespace(session->description);
+	session_data->share = FALSE;
 
 	if (purple_strequal(xmlns, NS_GOOGLE_SESSION_PHONE))
 		session_data->video = FALSE;
 	else if (purple_strequal(xmlns, NS_GOOGLE_SESSION_VIDEO))
 		session_data->video = TRUE;
+	else if (purple_strequal(xmlns, NS_GOOGLE_SESSION_SHARE))
+		session_data->share = TRUE;
 	else {
 		purple_debug_error("jabber", "Received initiate with "
 				"invalid namespace %s.\n", xmlns);
 		return FALSE;
 	}
 
-	session_data->media = purple_media_manager_create_media(
+	if (!session_data->share) {
+		session_data->media = purple_media_manager_create_media(
 			purple_media_manager_get(),
 			purple_connection_get_account(js->gc),
 			"fsrtpconference", session->remote_jid, FALSE);
 
-	purple_media_set_prpl_data(session_data->media, session);
+		purple_media_set_prpl_data(session_data->media, session);
 
-	g_signal_connect_swapped(G_OBJECT(session_data->media),
-			"candidates-prepared",
-			G_CALLBACK(google_session_ready), session);
-	g_signal_connect_swapped(G_OBJECT(session_data->media), "codecs-changed",
-			G_CALLBACK(google_session_ready), session);
-	g_signal_connect(G_OBJECT(session_data->media), "state-changed",
-			G_CALLBACK(google_session_state_changed_cb), session);
-	g_signal_connect(G_OBJECT(session_data->media), "stream-info",
-			G_CALLBACK(google_session_stream_info_cb), session);
+		g_signal_connect_swapped(G_OBJECT(session_data->media),
+					 "candidates-prepared",
+					 G_CALLBACK(google_session_ready), session);
+		g_signal_connect_swapped(G_OBJECT(session_data->media), "codecs-changed",
+					 G_CALLBACK(google_session_ready), session);
+		g_signal_connect(G_OBJECT(session_data->media), "state-changed",
+				 G_CALLBACK(google_session_state_changed_cb), session);
+		g_signal_connect(G_OBJECT(session_data->media), "stream-info",
+				 G_CALLBACK(google_session_stream_info_cb), session);
 
-	session->iq_id = g_strdup(iq_id);
+		session->iq_id = g_strdup(iq_id);
 
-	if (js->google_relay_host && js->google_relay_token) {
-		jabber_google_do_relay_request(js, session,
-			jabber_google_relay_response_session_handle_initiate_cb);
-	} else {
-		jabber_google_relay_response_session_handle_initiate_cb(session, NULL,
-			0, 0, 0, NULL, NULL);
+		if (js->google_relay_host && js->google_relay_token) {
+			jabber_google_do_relay_request(js, session,
+						       jabber_google_relay_response_session_handle_initiate_cb);
+		} else {
+			jabber_google_relay_response_session_handle_initiate_cb(session, NULL,
+										0, 0, 0, NULL, NULL);
+		}
 	}
+	else {
+		purple_debug_info("google_session", "\nTrying to grab protocol\n");
+		xmlnode *description = xmlnode_get_child(sess, "description");
+		xmlnode *manifest,*file,*filename,*protocol,*http,*url_source_path,*url_preview_path,*transport;
+		char *filesize;
 
+		if( description ) {
+		  purple_debug_info("google_session", "\ndescription is not NULL");
+		  manifest = xmlnode_get_child(description, "manifest");
+		  if( manifest ) {
+		    purple_debug_info("google_session", "\nmanifest not NULL");
+		    file = xmlnode_get_child(manifest, "file");
+		    if( file ) {
+		      purple_debug_info("google_session", "\nfile is not NULL");
+		      filename = xmlnode_get_child(file, "name");
+		      filesize = xmlnode_get_attrib(file, "size");
+		      purple_debug_info("google_session", "File size : %s",filesize);
+
+		      if( filename ) {
+			      purple_debug_info("google_session", "Filename : %s",xmlnode_get_data(filename));
+		      }
+		      else
+			      purple_debug_info("google_session", "Filename is NULL");
+		    }
+		  }
+		  protocol = xmlnode_get_child(description, "protocol");
+		  if( protocol ) { 
+			  purple_debug_info("google_session", "\nprotocol is not NULL");
+			  http = xmlnode_get_child(protocol, "http");
+			  if( http ) { 
+				  purple_debug_info("google_session", "\nhttp 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));
+				  }
+				  url_preview_path = xmlnode_get_next_twin(url_source_path);
+				  if(url_preview_path) {
+					  purple_debug_info("google_session", "url_source_preview is not NULL. Data : %s",xmlnode_get_data(url_preview_path));
+				  }
+			  }
+		  }
+		
+	transport = xmlnode_get_child(sess, "transport");
+	if(transport) 
+			purple_debug_info("google_session", "\nTransport is not null : %s",xmlnode_get_attrib(transport, "xmlns"));
+		else
+			purple_debug_info("google_session", "\nTransport is NULL");
+		}
+		
+		purple_debug_info("Jabber", "We have received a file request.");
+		return TRUE;
+		}
 	return TRUE;
+	
 }
 
-
 static void
 google_session_handle_candidates(JabberStream  *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
 {
@@ -813,7 +880,7 @@ jabber_google_session_parse(JabberStream
 	xmlnode *desc_node;
 
 	GList *iter = NULL;
-
+	
 	if (type != JABBER_IQ_SET)
 		return;
 
@@ -858,9 +925,6 @@ jabber_google_session_parse(JabberStream
 	session->js = js;
 	session->remote_jid = g_strdup(session->id.initiator);
 	session->session_data = g_new0(GoogleAVSessionData, 1);
-
 	google_session_handle_initiate(js, session, session_node, iq_id);
 }
 #endif /* USE_VV */
-
-
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
@@ -1951,7 +1951,6 @@ void jabber_rem_deny(PurpleConnection *g
 	js = purple_connection_get_protocol_data(gc);
 	if (js == NULL)
 		return;
-
 	if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
 	{
 		jabber_google_roster_rem_deny(js, who);
@@ -1975,7 +1974,7 @@ void jabber_rem_deny(PurpleConnection *g
 void jabber_add_feature(const char *namespace, JabberFeatureEnabled cb) {
 	JabberFeature *feat;
 
-	purple_debug_info("jabber", "Inside jabber-add-feature");
+	purple_debug_info("jabber", "Inside jabber-add-feature for %s",namespace);
 
 	g_return_if_fail(namespace != NULL);
 
@@ -3872,7 +3871,10 @@ jabber_do_init(void)
 	jabber_add_feature(JINGLE_APP_FT, 0);
 	jabber_add_feature(JINGLE_TRANSPORT_S5B, 0);
 	jabber_add_feature(JINGLE_TRANSPORT_IBB, 0);
-	jabber_add_feature("http://google.com/xmpp/protocol/share/v1",0);
+
+	/* Google Talk File Transfer*/
+	jabber_add_feature(NS_GOOGLE_SHARE,0);
+	
 #ifdef USE_VV
 	jabber_add_feature(NS_GOOGLE_PROTOCOL_SESSION, jabber_audio_enabled);
 	jabber_add_feature(NS_GOOGLE_VOICE, jabber_audio_enabled);
diff --git a/libpurple/protocols/jabber/namespaces.h b/libpurple/protocols/jabber/namespaces.h
--- a/libpurple/protocols/jabber/namespaces.h
+++ b/libpurple/protocols/jabber/namespaces.h
@@ -99,6 +99,7 @@
 #define NS_GOOGLE_CAMERA "http://www.google.com/xmpp/protocol/camera/v1"
 #define NS_GOOGLE_VIDEO "http://www.google.com/xmpp/protocol/video/v1"
 #define NS_GOOGLE_VOICE "http://www.google.com/xmpp/protocol/voice/v1"
+#define NS_GOOGLE_SHARE "http://www.google.com/xmpp/protocol/share/v1"
 #define NS_GOOGLE_JINGLE_INFO "google:jingleinfo"
 
 #define NS_GOOGLE_MAIL_NOTIFY "google:mail:notify"
@@ -108,5 +109,7 @@
 #define NS_GOOGLE_SESSION "http://www.google.com/session"
 #define NS_GOOGLE_SESSION_PHONE "http://www.google.com/session/phone"
 #define NS_GOOGLE_SESSION_VIDEO "http://www.google.com/session/video"
+#define NS_GOOGLE_SESSION_SHARE "http://www.google.com/session/share"
+#define NS_GOOGLE_TRANSPORT_P2P "http://www.google.com/transport/p2p"
 
 #endif /* PURPLE_JABBER_NAMESPACES_H_ */
diff --git a/libpurple/protocols/jabber/parser.c b/libpurple/protocols/jabber/parser.c
--- a/libpurple/protocols/jabber/parser.c
+++ b/libpurple/protocols/jabber/parser.c
@@ -272,9 +272,11 @@ void jabber_parser_process(JabberStream 
 	int ret;
 
 	if (js->context == NULL) {
+	  
 		/* libxml inconsistently starts parsing on creating the
 		 * parser, so do a ParseChunk right afterwards to force it. */
 		js->context = xmlCreatePushParserCtxt(&jabber_parser_libxml, js, buf, len, NULL);
+
 		xmlParseChunk(js->context, "", 0, 0);
 	} else if ((ret = xmlParseChunk(js->context, buf, len, 0)) != XML_ERR_OK) {
 		xmlError *err = xmlCtxtGetLastError(js->context);
diff --git a/libpurple/xmlnode.c b/libpurple/xmlnode.c
--- a/libpurple/xmlnode.c
+++ b/libpurple/xmlnode.c
@@ -53,6 +53,7 @@ new_node(const char *name, XMLNodeType t
 
 	node->name = g_strdup(name);
 	node->type = type;
+	node->parent = NULL;



More information about the Commits mailing list