/soc/2013/ashmew2/filetransferX: d611d96a8b33: Added functions

Ashish Gupta ashmew2 at gmail.com
Mon Aug 5 09:17:11 EDT 2013


Changeset: d611d96a8b335edecd6714bd7ece12c737d75b04
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-05 18:46 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/d611d96a8b33

Description:

Added functions

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  193 +++++++++++++++++---
 libpurple/protocols/jabber/jabber.h                |    1 +
 2 files changed, 159 insertions(+), 35 deletions(-)

diffs (truncated from 376 to 300 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
@@ -22,9 +22,8 @@
 #include "debug.h"
 #include "google_session.h"
 #include "relay.h"
-
 #include "jingle/jingle.h"
-
+#include "network.h"
 #ifdef USE_VV
 
 typedef struct {
@@ -40,7 +39,7 @@ typedef struct {
 	PurpleMedia *media;
 	gboolean video;
 	gboolean share;
-	GoogleXferSessionData share_session;
+	GoogleXferSessionData* share_session;
 	GList *remote_audio_candidates; /* list of PurpleMediaCandidate */
 	GList *remote_video_candidates; /* list of PurpleMediaCandidate */
 	gboolean added_streams;		/* this indicates if the streams have been
@@ -79,7 +78,7 @@ google_session_destroy(GoogleSession *se
 
 	if (session->description)
 		xmlnode_free(session->description);
-
+/*TODO : Since we have made a new GList in _JabberStream, we should probably delete the GoogleSession from it now*/
 	g_free(session->session_data);
 	g_free(session);
 }
@@ -105,6 +104,7 @@ google_session_send_candidates(PurpleMed
 		purple_media_get_local_candidates(session_media, session_id,
 		    session->remote_jid);
 	GList *iter;
+
 	PurpleMediaCandidate *transport;
 	gboolean video = FALSE;
 
@@ -451,6 +451,7 @@ jabber_google_session_initiate(JabberStr
 	session->js = js;
 	session->remote_jid = jid;
 	session_data = g_new0(GoogleAVSessionData, 1);
+	((GoogleAVSessionData *)session_data)->share_session = g_new0(GoogleXferSessionData, 1);
 	session->session_data = session_data;
 
 	if (type & PURPLE_MEDIA_VIDEO)
@@ -653,6 +654,7 @@ 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", "description is not NULL");
 			manifest = xmlnode_get_child(description, "manifest");
@@ -666,8 +668,8 @@ google_session_handle_initiate(JabberStr
 					purple_debug_info("google_session", "File size : %s",filesize);
 					session_data->share_session->filesize = g_ascii_strtoull((gchar *)xmlnode_get_attrib(file, "size"),NULL,10);
 					if( filename ) {
-						purple_debug_info("google_session", "Filename : %s",xmlnode_get_data(filename));
-						session_data->share_session->filename = xmlnode_get_data(filename);
+						purple_debug_info("google_session", "Filename : %s",xmlnode_get_data_unescaped(filename));
+						session_data->share_session->filename = xmlnode_get_data_unescaped(filename);
 					}
 					else
 						purple_debug_info("google_session", "Filename is NULL");
@@ -681,13 +683,13 @@ google_session_handle_initiate(JabberStr
 					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));
-						session_data->share_session->source_url = xmlnode_get_data(url_source_path);
+						purple_debug_info("google_session", "url_source_path is not NULL. Name : %s",xmlnode_get_data_unescaped(url_source_path));
+						session_data->share_session->source_url = xmlnode_get_data_unescaped(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));
-						session_data->share_session->preview_url = xmlnode_get_data(url_preview_path);
+						purple_debug_info("google_session", "url_source_preview is not NULL. Data : %s",xmlnode_get_data_unescaped(url_preview_path));
+						session_data->share_session->preview_url = xmlnode_get_data_unescaped(url_preview_path);
 					}
 				}
 			}
@@ -718,11 +720,21 @@ 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>
 		************************************/
+		/*Add the GoogleSession *session to the GList*/
+		js->google_share_sessions = g_list_prepend(js->google_share_sessions, session);
 		purple_debug_info("google_session", "We have received a file request.\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");
+		if(1) {
+/*			GList *iplist = purple_network_get_all_local_system_ips();
+			GList *iter;
+			for(iter = iplist; iter; iter=iter->next) {
+				purple_debug_info("google_session", "\nIP : %s\n",iter->data);
+			}
+			g_list_free(iplist);
+*/		
+		}
 		/*
 		result_iq = jabber_iq_new(js,JABBER_IQ_RESULT);
 		xmlnode_set_attrib(result_iq->node, "to", session->remote_jid);
@@ -797,7 +809,7 @@ google_session_handle_candidates(JabberS
 		const gchar *port = xmlnode_get_attrib(cand, "port");
 		const gchar *preference = xmlnode_get_attrib(cand, "preference");
 		guint component_id;
-
+		
 		if (cname && type && address && port) {
 			PurpleMediaCandidateType candidate_type;
 			guint prio = preference ? g_ascii_strtod(preference, NULL) * 1000 : 0;
@@ -829,25 +841,33 @@ google_session_handle_candidates(JabberS
 			g_object_set(info, "username", xmlnode_get_attrib(cand, "username"),
 					"password", xmlnode_get_attrib(cand, "password"),
 			        "priority", prio, NULL);
-			if (!strncmp(cname, "video_", 6)) {
-				if (session_data->added_streams) {
-					video_list = g_list_append(video_list, info);
+
+			if(!session_data->share) {
+				if (!strncmp(cname, "video_", 6)) {
+					if (session_data->added_streams) {
+						video_list = g_list_append(video_list, info);
+					} else {
+						session_data->remote_video_candidates =
+							g_list_append(session_data->remote_video_candidates,
+								      info);
+					}
 				} else {
-					session_data->remote_video_candidates =
-						g_list_append(session_data->remote_video_candidates,
-							info);
-				}
-			} else {
-				if (session_data->added_streams) {
-					list = g_list_append(list, info);
-				} else {
-					session_data->remote_audio_candidates =
-						g_list_append(session_data->remote_audio_candidates,
-							info);
+					if (session_data->added_streams) {
+						list = g_list_append(list, info);
+					} else {
+						session_data->remote_audio_candidates =
+							g_list_append(session_data->remote_audio_candidates,
+								      info);
+					}
 				}
 			}
+			else /*If it's a share session*/
+				session_data->share_session->remote_share_candidates = 
+					g_list_append(session_data->share_session->remote_share_candidates,
+						      info);
 		}
 	}
+	/*if session was share, list and video_list are NULL*/
 
 	if (list) {
 		purple_media_add_remote_candidates(session_data->media, "google-voice",
@@ -859,11 +879,12 @@ google_session_handle_candidates(JabberS
 			session->remote_jid, video_list);
 		purple_media_candidate_list_free(video_list);
 	}
-
+	
 	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);
+	purple_debug_info("google_session", "End of handle_candidates().\n");
 }
 
 static void
@@ -880,7 +901,7 @@ 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");
+	google_session_handle_candidates(js, session, sess, iq_id);
 }
 
 static void
@@ -967,10 +988,83 @@ google_session_handle_terminate(JabberSt
 }
 
 static void
+gtalk_port_cb(int listenfd, gpointer data)
+{
+	PurpleXfer *xfer = data;
+	if(listenfd == -1)
+		purple_debug_info("google_session", "FATAL ERROR : listenfd is -1 !\n");
+	else
+		xfer->remote_port = purple_network_get_port_from_fd(listenfd);
+
+	purple_debug_info("google_session", "Inside gtalk_port_cb()\n, Reached ENDofFunc.\n");
+	
+}
+
+static void
+gtalk_xfer_init(PurpleXfer *xfer)
+{
+	GoogleSession *session = (GoogleSession *)(xfer->data);
+	GoogleAVSessionData *session_data = session->session_data;
+	GList *iter;
+	PurpleNetworkListenData *portdata = purple_network_listen_range_family
+		(27015, 64000, AF_INET, SOCK_STREAM, gtalk_port_cb, NULL);
+	purple_debug_info("google_session", "Inside gtalk_xfer_init() \n");
+
+/**IP.PORT etc should all be in the GoogleSession thing? I guess so.*/
+	xfer->filename = g_strdup_printf("%s",session_data->share_session->filename);
+	xfer->local_filename = g_strdup_printf("%s",session_data->share_session->filename);
+	xfer->size = session_data->share_session->filesize;
+/* xfer->remote_port set in the gtalk_port_cb() */
+
+	xfer->dest_fp = g_strdup_printf("%s","/home/ashish/XPLUS5.rar");
+
+	for(iter=session_data->share_session->remote_share_candidates;
+	    iter; iter = iter->next) {
+		PurpleMediaCandidate *candid = (PurpleMediaCandidate *)(iter->data);
+		if(purple_media_candidate_get_candidate_type(candid)==PURPLE_MEDIA_CANDIDATE_TYPE_PRFLX) {
+			xfer->remote_ip = g_strdup_printf("%s",purple_media_candidate_get_ip(candid));
+			xfer->remote_port = purple_media_candidate_get_port(candid);
+			break;
+		}
+	}
+	purple_xfer_start( xfer, -1, xfer->remote_ip, xfer->remote_port );
+	
+}
+
+static void
+gtalk_xfer_start(PurpleXfer *xfer)
+{
+	purple_debug_info("google_session", "Inside gtalk_xfer_start()\n");
+	if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) {
+		guchar *buffer = g_malloc( xfer->bytes_remaining );
+		int size = fread( buffer, xfer->bytes_remaining, 1, xfer->dest_fp );
+		int wrote = purple_xfer_write( xfer, buffer, xfer->bytes_remaining );
+
+		if ( wrote > 0 )
+			purple_xfer_set_bytes_sent( xfer, wrote );
+
+		/* free the buffer */
+		g_free( buffer );
+		buffer = NULL;
+	}
+}
+
+static void 
+google_session_initiate_file_transfer(JabberStream *js, GoogleSession *session)
+{
+	PurpleXfer *xfer = purple_xfer_new(purple_connection_get_account(js->gc), PURPLE_XFER_SEND, session->remote_jid);
+	xfer->data = session;
+	purple_debug_info("google_session", "inside google_session_initiate_file_transfer\n");
+	purple_xfer_set_init_fnc( xfer, gtalk_xfer_init );
+	purple_xfer_set_start_fnc(xfer, gtalk_xfer_start);
+}
+
+static void
 google_session_parse_iq(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
 {
 	const char *type = xmlnode_get_attrib(sess, "type");
 	purple_debug_info("google_session", "\nType of IQ being parsed : %s\n",type);
+	GoogleAVSessionData *session_data = (GoogleAVSessionData *)(session->session_data);
 
 	if (!strcmp(type, "initiate")) {
 		google_session_handle_initiate(js, session, sess, iq_id);
@@ -985,7 +1079,8 @@ google_session_parse_iq(JabberStream *js
 	} else if (!strcmp(type, "transport-accept")) {
 		google_session_handle_transport_accept(js, session, sess, iq_id);
 	} else if (!strcmp(type, "transport-info")) {
-		google_session_handle_candidates(js, session, sess, iq_id);
+		google_session_handle_transport_info(js, session, sess, iq_id);
+		google_session_initiate_file_transfer(js,session);
 	}
 
 }
@@ -997,7 +1092,7 @@ jabber_google_session_parse(JabberStream
 {
 	GoogleSession *session = NULL;
 	GoogleSessionId id;
-
+	GoogleAVSessionData *session_data;
 	xmlnode *desc_node;
 
 	GList *iter = NULL;
@@ -1029,7 +1124,7 @@ jabber_google_session_parse(JabberStream
 		g_list_free(iter);
 	}
 	
-	if (session) {
+	if (session) { /*It's a media 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;



More information about the Commits mailing list