/soc/2013/ashmew2/filetransferX: f21485742825: Added gtalk_xfer_...

Ashish Gupta ashmew2 at gmail.com
Tue Aug 20 19:07:21 EDT 2013


Changeset: f214857428257e5d024d82b75ac65ffbb7aeb687
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-21 04:27 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/f21485742825

Description:

Added gtalk_xfer_send_session_initiate

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  223 ++++++++------------
 libpurple/protocols/jabber/google/google_session.h |    1 +
 2 files changed, 86 insertions(+), 138 deletions(-)

diffs (truncated from 315 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
@@ -431,11 +431,12 @@ gint gtalk_xfer_init_agent(GoogleXferSes
 	gint stream_id;
 	if(!share_session)
 		return -1;
+
 	if(share_session->share_agent)
 		return share_session->stream_id;
 
-	share_session->agent = nice_agent_new_reliable (g_main_context_default(), NICE_COMPATIBILITY_GOOGLE);
-	stream_id = nice_agent_add_stream(agent, 1);
+	share_session->share_agent = nice_agent_new_reliable (g_main_context_default(), NICE_COMPATIBILITY_GOOGLE);
+	stream_id = nice_agent_add_stream(share_session->share_agent, 1);
 	share_session->stream_id = stream_id;
 	return stream_id;
 }
@@ -455,24 +456,17 @@ jabber_google_relay_response_session_ini
 	NiceCandidate *relay_candidate_udp, *relay_candidate_tcp;
 	NiceCandidate *relay_candidate_ssltcp;
 	guint stream_id = share_session->stream_id;
-	NiceAgent *agent;
+	NiceAgent *agent = share_session->share_agent;
 
 	if(session_data->share) {
-		/*TODO: Relocate? Define a new function? Only time will tell :P
-		  gtalk_relay_response_session_initiate_cb(session, relay_ip, relay_udp,
-				 relay_tcp, relay_ssltcp, relay_username, relay_password);
-		return;
-		*/
-		GoogleXferSessionData *share_session = session_data->share_session;
-		agent = share_session->share_agent;
-
-		if(!share_session->share_agent) {/*TODO: Should probably have an agent_init function for this..Later..*/
-			purple_xfer_request(share_session->xfer);
+		if(!agent) {
+			if(purple_xfer_get_type(share_session->xfer) == PURPLE_XFER_RECEIVE)
+				purple_xfer_request(share_session->xfer);
+			/*if xfer is of type PURPLE_XFER_SEND, We've already requested it*/
 
 			stream_id = gtalk_xfer_init_agent(share_session);
 
-			purple_debug_info("google_session", "share_agent is NULL in relab_cb!\n");
-			purple_debug_info("google_session", "Value of stream_id : %d\n",share_session->stream_id);
+			purple_debug_info("google_session", "share_agent is NULL in relay_cb!\n");
 			
 			if(js->stun_ip) {
 				purple_debug_info("google_session", "Setting Agent's STUN..");
@@ -2157,57 +2151,80 @@ stun_discovery_cb(PurpleStunNatDiscovery
 	purple_debug_info("google_session", "Inside stun_discovery_cb with publicip as %s\n",stun_discovery->publicip);
 }
 
+GoogleSession *
+gtalk_xfer_new_session(JabberStream *js, char *who)
+{
+	GoogleSession *session = g_new0(GoogleSession, 1);
+	GoogleAVSessionData *session_data = g_new0(GoogleAVSessionData, 1);
+	GoogleXferSessionData *share_session = g_new0(GoogleXferSessionData, 1);
+	gchar *me = g_strdup_printf("%s@%s/%s",
+				    js->user->node,
+				    js->user->domain,
+				    js->user->resource);
+	
+
+	JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
+	JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, NULL);
+	gchar *jid;
+	
+	purple_debug_info("google_session", "Inside gtalk_xfer_new_session\n");
+	
+	if (!jbr) {
+		purple_debug_error("google_session",
+				"Could not find buddy's resource\n");
+	}
+
+	if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
+		jid = g_strdup_printf("%s/%s", who, jbr->name);
+	} else {
+		jid = g_strdup(who);
+	}
+
+	share_session->buffer = purple_circ_buffer_new(65536);
+	session->id.id = jabber_get_next_id(js);
+	session->id.initiator = me;
+	session_data->share = 1;
+	session_data->share_session = share_session;
+	session->session_data = session_data;
+/*  TODO : Append this GoogleSession to js->google_share_sessions */
+	session->state = UNINIT;
+	session->js = js;
+	session->remote_jid = g_strdup(jid);
+	purple_debug_info("google_session", "Peer's JID : %s\n",jid);
+	return session;
+}
+
 void
 gtalk_xfer_send(PurpleConnection *gc, const char *who, const char *file)
 {
-  PurpleXfer *xfer;
-  PurpleStunNatDiscovery *stun_discovery;
+  PurpleXfer *xfer = NULL;
+  JabberStream *js = purple_connection_get_protocol_data(gc);
 
-  xfer = gtalk_xfer_new(gc, who);
-  purple_debug_info("google_session", "Just Created an Xfer.");
+  purple_debug_info("google_session", "INSIDE GTALK_XFER_SEND\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", "\n <ALL> IP : %s\n",iter->data);
-	  }
-			g_list_free(iplist);
-			purple_debug_info("google_session", "get_pub_ip : %s",purple_network_get_public_ip());
-			
-  }
-*/
-  if(!xfer) {
-	  purple_debug_info("google_session", "Failed to Create an Xfer for Sending a File..");
-	  return;
-  }
-  /*TODO: Start a STUN discovery here to get our external IP for sending out as a candidate to GTalk*/
-/*  stun_discovery = purple_stun_discover(stun_discovery_cb);*/
-  /*TODO: if stun_discovery is NULL, that means stun_discovery_cb will be called when discovery is done.*/
-
-/*  if(stun_discovery)
-	  purple_debug_info("google_session", "stun_discovery is NOT NULL. Public IP : %s\n",stun_discovery->publicip);
-  else
-	  purple_debug_info("google_session", "stun_discovery is NULL for now..\n");
-*/
   if (file) {
-/*TODO: This should probably be something else*/
+	  purple_debug_info("google_session", "file is non NULL.File : %s\n");
 	  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);
+	  purple_debug_info("google_session", "File is NULL!\n");
+	  GoogleSession *session = gtalk_xfer_new_session(js, who);
+	  GoogleAVSessionData *session_data = session->session_data;
+	  GoogleXferSessionData *share_session = session_data->share_session;
+	  
+	  xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_SEND, 
+				 session->remote_jid);
 
-	  session->state = UNINIT;
-	  session->js = purple_connection_get_protocol_data(gc);
-	  session_data->share = TRUE;
-	  session->session_data = session_data;
+	  purple_xfer_set_init_fnc(xfer, gtalk_xfer_init);
+	  purple_xfer_set_request_denied_fnc(xfer,
+					     gtalk_xfer_request_denied);
 
 	  xfer->data = session;
+	  share_session->xfer = xfer;
 	  purple_xfer_request(xfer);
-	  purple_debug_info("google_session", "file is NULL. File : %s\n",file);
+	  js->google_share_sessions = g_list_prepend(js->google_share_sessions, session);
+	  gtalk_xfer_send_session_initiate(xfer);
+	  /*TODO: Frame an XML Session initiate node, send it. Wait for the response*/
   }
 
 }
@@ -2241,51 +2258,24 @@ gtalk_get_temporary_url(void)
 	return temporary_url;
 }
 
-void gtalk_xfer_send_initiate(PurpleXfer *xfer)
+void gtalk_xfer_send_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, *transport_node;
 	xmlnode *name_node, *protocol_node, *http_node, *url_source_node, *url_preview_node;
-	int size;
+	guint64 size;
 	gchar *me = g_strdup_printf("%s@%s/%s",
 				    js->user->node,
 				    js->user->domain,
 				    js->user->resource);
 
-/*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;
+	purple_debug_info("google_session", "Inside gtalk_xfer_send_session_initiate()\n");
 
 	iq = jabber_iq_new(js, JABBER_IQ_SET);
+	xmlnode_set_attrib(iq->node, "to", session->remote_jid);
 
-	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");
@@ -2316,11 +2306,18 @@ void gtalk_xfer_send_initiate(PurpleXfer
 
 	transport_node = xmlnode_new_child(session_node, "transport");
 	xmlnode_set_namespace(transport_node, NS_GOOGLE_TRANSPORT_P2P);
+	jabber_iq_send(iq);
+	purple_debug_info("google_session", "Initiate SENT!");
 
-	js->google_share_sessions = g_list_prepend(js->google_share_sessions, session);
-	jabber_iq_send(iq);
-	
+	if (js->google_relay_host && js->google_relay_token) {
+		jabber_google_do_relay_request(js, session,
+					       jabber_google_relay_response_session_initiate_cb);
+	} else {
+		jabber_google_relay_response_session_initiate_cb(session, NULL, 0, 0, 0,
+								 NULL, NULL);
+	}
 }
+
 void
 gtalk_xfer_request_denied(PurpleXfer *xfer)
 {
@@ -2335,57 +2332,7 @@ gtalk_xfer_init(PurpleXfer *xfer)
 	GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
 	GoogleXferSessionData *share_session = session_data->share_session;
 	JabberStream *js = session->js;  
-
-/*	GList *iter;
-	PurpleNetworkListenData *portdata = purple_network_listen_range_family
-	  (27015, 64000, AF_INET, SOCK_STREAM, gtalk_port_cb, xfer);
-
-
-	purple_debug_info("google_session", "Inside gtalk_xfer_init() \n");
-	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);
-
-	if(share_session) {
-		NiceAgent *agent = nice_agent_new_reliable (g_main_context_default (), NICE_COMPATIBILITY_RFC5245);
-		guint stream_id;
-		stream_id = nice_agent_add_stream (agent, 1);
-		share_session->stream_id = stream_id;
-		share_session->share_agent = agent;
-		purple_debug_info("google_session", "share_session wasn't NULL\n");
-	}
-	else {
-		share_session = g_new0(GoogleXferSessionData, 1);
-		purple_debug_info("google_session", "share_session WAS NULL\n");
-	}
-
-/*  if (js->google_relay_host && js->google_relay_token) {
-	  jabber_google_do_relay_request(js, session,
-					 jabber_google_relay_response_session_initiate_cb);
-  } else {
-	  jabber_google_relay_response_session_initiate_cb(session, NULL, 0, 0, 0,
-							   NULL, NULL);
-  }
-*/
-/*  TODO:Uncomment above and below?*/
-/*	gtalk_xfer_send_initiate(xfer);*/
-  
-/**TODO: IP.PORT etc should all be in the GoogleSession thing? I guess so.*/
-/*TODO: xfer->local_port set in the gtalk_port_cb() */
-/*TODO: xfer->remote_ip and xfer->remote_port will be set when we get a list of candidates*/
-
-/*	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;
-		}
-	}
-
-	gtalk_xfer_start(xfer);
-*/
-	//	purple_xfer_start( xfer, -1, xfer->remote_ip, xfer->remote_port );



More information about the Commits mailing list