/soc/2013/ashmew2/filetransferX: 60bcb37fa8ef: (Crash) gtalk_xfe...

Ashish Gupta ashmew2 at gmail.com
Mon Aug 5 20:13:45 EDT 2013


Changeset: 60bcb37fa8eff2efe53b62be6aa91cd77c1402e7
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-06 05:43 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/60bcb37fa8ef

Description:

(Crash) gtalk_xfer_session_initiate better

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  126 +++++++++++++++-----
 1 files changed, 92 insertions(+), 34 deletions(-)

diffs (181 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
@@ -991,6 +991,8 @@ static void
 gtalk_port_cb(int listenfd, gpointer data)
 {
 	PurpleXfer *xfer = data;
+	if(!xfer)
+		purple_debug_info("google_session", "gtalk_port_cb XFER IS NULL\n");
 	if(listenfd == -1)
 		purple_debug_info("google_session", "FATAL ERROR : listenfd is -1 !\n");
 	else
@@ -1029,7 +1031,7 @@ PurpleXfer *gtalk_xfer_new(PurpleConnect
 
 	if (xfer) {
 		xfer->data = g_new0(GoogleSession, 1);
-/*TODO: GoogleXferSessionData should probably have JabberStream in it*/
+
 		purple_xfer_set_init_fnc(xfer, gtalk_xfer_init);
 		purple_xfer_set_start_fnc(xfer, gtalk_xfer_start);
 	}
@@ -1042,46 +1044,103 @@ gtalk_xfer_send(PurpleConnection *gc, co
 {
   PurpleXfer *xfer;
   xfer = gtalk_xfer_new(gc, who);
-
+  
   if(!xfer) {
 	  purple_debug_info("google_session", "Failed to Create an Xfer for Sending a File..");
 	  return;
   }
-
+  
   if (file) {
+/*TODO: This should probably be something else*/
 	  purple_xfer_request_accepted(xfer, file);
 	  purple_debug_info("google_session", "file is non NULL.File : %s\n");
   }
   else {
+	  GoogleSession *session = g_new0(GoogleSession, 1);
+	  GoogleAVSessionData *session_data = g_new0(GoogleAVSessionData, 1);
+	  session_data->share_session = g_new0(GoogleXferSessionData, 1);
+
+	  session->state = UNINIT;
+	  session->js = purple_connection_get_protocol_data(gc);
+	  session_data->share = TRUE;
+	  session->session_data = session_data;
+
+	  xfer->data = session;
 	  purple_xfer_request(xfer);
 	  purple_debug_info("google_session", "file is NULL. File : %s\n",file);
   }
-  purple_debug_info("google_session", "We have a file now. Details of Xfer :\nwho : %s\nfilename:%s\nlocal_filename:%s\nsize:%d\n",xfer->who,xfer->filename,xfer->local_filename,xfer->size);
 
-  /*
+}
 
-  JabberStream *js = purple_connection_get_protocol_data(gc);
-  JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
-  xmlnode *session_node, *description_node;
-  gchar *me = g_strdup_printf("%s@%s/%s",
-			      session->js->user->node,
-			      session->js->user->domain,
-			      session->js->user->resource);
-		
-  xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+void gtalk_xfer_session_initiate(PurpleXfer *xfer)
+{
+	GoogleSession *session = xfer->data;
+	JabberStream *js = session->js;
+	JabberBuddy *jb;
+	JabberBuddyResource *jbr;
+	gchar *jid;	
+	JabberIq *iq;
+	xmlnode *session_node, *description_node, *file_node, *manifest_node;
+	xmlnode *name_node, *protocol_node, *http_node, *url_source_node, *url_preview_node;
 
-  session_node = xmlnode_new_child(iq->node, "session");
-  xmlnode_set_attrib(session_node, "type", "initiate");
-  xmlnode_set_attrib(session_node, "id", jabber_get_next_id(js));
-  xmlnode_set_attrib(session_node, "initiator", me);
-  xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);
+	gchar *me = g_strdup_printf("%s@%s/%s",
+				    js->user->node,
+				    js->user->domain,
+				    js->user->resource);
 
-  description_node = xmlnode_new_child(session_node, "description");
-  xmlnode_set_namespace(description_node, NS_GOOGLE_SESSION_SHARE);
-  
-  manifest_node = xmlnode_new_child(description_node, "manifest");
-  file_node = xmlnode_new_child(manifest_node, "file");
-  /*  xmlnode_set_attrib(file_node, "size", FILE_SIZE); */
+/*TODO : Probably make a get_remote_jid() function*/
+	jb = jabber_buddy_find(js, xfer->who, FALSE);
+	if (!jb) {
+		purple_debug_error("google_session",
+				"Could not find Jabber buddy\n");
+		return FALSE;
+	}
+	jbr = jabber_buddy_find_resource(jb, NULL);
+	if (!jbr) {
+		purple_debug_error("google_session",
+				"Could not find buddy's resource\n");
+	}
+
+	if ((strchr(xfer->who, '/') == NULL) && jbr && (jbr->name != NULL)) {
+		jid = g_strdup_printf("%s/%s", xfer->who, jbr->name);
+	} else {
+		jid = g_strdup(xfer->who);
+	}
+	session->remote_jid = g_strdup(jid);
+
+	purple_debug_info("google_session", "remote_jid = %s",jid);
+
+	session->id.id = jabber_get_next_id(js);
+	session->id.initiator = me;
+
+	iq = jabber_iq_new(js, JABBER_IQ_SET);
+
+	xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+	/*TODO: what about the iq's id? Is it auto generated?*/
+	session_node = xmlnode_new_child(iq->node, "session");
+
+	xmlnode_set_attrib(session_node, "type", "initiate");
+	xmlnode_set_attrib(session_node, "id", session->id.id);
+/*TODO: Check if initiator attrib is optional*/
+/*	xmlnode_set_attrib(session_node, "initiator", me);*/
+	xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);
+
+	description_node = xmlnode_new_child(session_node, "description");
+	xmlnode_set_namespace(description_node, NS_GOOGLE_SESSION_SHARE);
+
+	manifest_node = xmlnode_new_child(description_node, "manifest");
+	file_node = xmlnode_new_child(manifest_node, "file");
+	xmlnode_set_attrib(file_node, "size", g_strdup_printf("%llu",xfer->size));
+
+	name_node = xmlnode_new_child(file_node, "name");
+	xmlnode_insert_data(name_node,xfer->filename,strlen(xfer->filename));
+
+	protocol_node = xmlnode_new_child(description_node, "protocol");
+	http_node = xmlnode_new_child(protocol_node, "http");
+	url_source_node = xmlnode_new_child(http_node, "url");
+	url_preview_node = xmlnode_new_child(http_node, "url");
+	
+	/*  xmlnode_set_attrib(file_node, "size", FILE_SIZE); */
 }
 
 void
@@ -1092,16 +1151,14 @@ gtalk_xfer_init(PurpleXfer *xfer)
 	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");
-
+	purple_debug_info("google_session", "We have a file now. Details of Xfer :\nwho : %s\nfilename:%s\nlocal_filename:%s\nsize:%d\nlocal_port : %d\nremote_port:%d\nremote_ip:%s\nBytes Sent:%d\nBytes Remaining:%d\n",xfer->who,xfer->filename,xfer->local_filename,xfer->size,xfer->local_port,xfer->remote_port,xfer->remote_ip,xfer->bytes_sent,xfer->bytes_remaining);
+/**TODO: Should probably send out the XML for initiating session now**/
+	gtalk_xfer_session_initiate(xfer);
+/**TODO: IP.PORT etc should all be in the GoogleSession thing? I guess so.*/
+/*TODO: xfer->remote_port set in the gtalk_port_cb() */
+/*TODO: xfer->remote_ip and xfer->local_port need to be set somewhere*/
 	for(iter=session_data->share_session->remote_share_candidates;
 	    iter; iter = iter->next) {
 		PurpleMediaCandidate *candid = (PurpleMediaCandidate *)(iter->data);
@@ -1268,6 +1325,7 @@ jabber_google_session_parse(JabberStream
 	session->remote_jid = g_strdup(session->id.initiator);
 	session->session_data = g_new0(GoogleAVSessionData, 1);
 	session_data = session->session_data;
+	/*TODO: Do we really need a g_new0 here?*/
 	session_data->share_session = g_new0(GoogleXferSessionData, 1);
 	google_session_handle_initiate(js, session, session_node, iq_id);
 }



More information about the Commits mailing list