/soc/2013/ashmew2/filetransferY: 2b5b486982d6: Segregated functi...

Ashish Gupta ashmew2 at gmail.com
Sat Feb 1 07:55:20 EST 2014


Changeset: 2b5b486982d6f1277b0fe649d2500539f8319a3d
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2014-02-01 15:01 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferY/rev/2b5b486982d6

Description:

Segregated functions for FT and other Sessions

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  1320 +-------------------
 libpurple/protocols/jabber/google/google_share.c   |  1293 +++++++++++++++++++-
 2 files changed, 1292 insertions(+), 1321 deletions(-)

diffs (truncated from 2728 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
@@ -16,7 +16,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
- */
+ **/
 
 #include <stdlib.h>
 #include "internal.h"
@@ -33,47 +33,6 @@
 
 #ifdef USE_VV
 
-typedef enum {
-	GTALK_XFER_CHANNEL_INITIALIZED = 0,
-	GTALK_XFER_CHANNEL_HTTP_GET_NOT_SENT,
-	GTALK_XFER_CHANNEL_SENT_HTTP_GET,
-	GTALK_XFER_CHANNEL_HTTP_GET_RECEIVED,
-	GTALK_XFER_CHANNEL_HTTP_OK_SENT,
-	GTALK_XFER_CHANNEL_HTTP_SENDING,
-	GTALK_XFER_CHANNEL_HTTP_RECEIVING,
-	GTALK_XFER_CHANNEL_HTTP_TRANSFERRING,
-	GTALK_XFER_CHANNEL_HTTP_SENDING_COMPLETE,
-	GTALK_XFER_CHANNEL_HTTP_RECEIVING_COMPLETE,
-	GTALK_XFER_CHANNEL_PARSED_HTTP_RESPONSE_HEADER
-} GoogleXferChannelState;
-
-typedef struct {
-	gchar *filename;        /*File Details*/
-	guint64 filesize;
-	gchar *preview_url;
-	gchar *source_url;
-	PurpleXfer *xfer;
-	NiceAgent *share_agent; /*Needs to have a manifest
-				  Entry for Folder Sharing: TODO*/
-	gchar *channel_name;
-	NiceComponentState agent_state;
-	PurpleCircBuffer *buffer; 
-	GoogleXferChannelState channel_state;
-	gint stream_id;
-	gboolean candidates_gathered;	
-	gboolean file_opened;   /* Stuff for using file buffer 
-				   for sending Gtalk Files.. */ 
-	FILE *file_to_send;
-	char *file_buf;
-	int file_buf_current_size;
-	int file_buf_sent;
-
-	GSList *remote_share_candidates; /* lists of 
-					    NiceCandidates */	
-	GSList *local_share_candidates;	
-
-} GoogleXferSessionData; 
-
 typedef struct {
 	PurpleMedia *media;
 	gboolean video;
@@ -83,32 +42,6 @@ typedef struct {
 					   to media (ie. after getting relay credentials */
 } GoogleAVSessionData;
 
-void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer user_data);
-void cb_nice_component_state_changed(NiceAgent *agent,guint stream_id, guint component_id,
-				     guint state, gpointer user_data);
-void cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_id,
-	     guint len, gchar *buf, gpointer data);
-void cb_nice_component_writable(NiceAgent *agent, guint stream_id, guint component_id,
-				gpointer user_data);
-void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id,
-			  gchar *lfoundation, gchar *rfoundation, gpointer user_data);
-gint gtalk_xfer_init_agent(GoogleSession *session);
-void
-gtalk_xfer_handle_info(JabberStream  *js, GoogleSession *session, xmlnode *sess, const char *iq_id);
-NiceCandidate * nice_candidate_from_xml(const xmlnode *candidate, guint stream_id);
-gchar * http_read_line(gchar *buffer, guint len);
-char* gtalk_get_temporary_url(void);
-GoogleSession *gtalk_xfer_new_session(JabberStream *js, const char *who);
-char *nice_component_state_to_str(guint state);
-void gtalk_xfer_get_next_block(GoogleXferSessionData *share_session);
-void gtalk_xfer_send_info(JabberStream *js, GoogleSession *session, xmlnode *sess);
-void gtalk_xfer_accept_cb(JabberStream *js, const gchar *from, JabberIqType type, 
-		     const gchar *id, xmlnode *sess, gpointer data);
-void gtalk_xfer_channel_cb(JabberStream *js, const gchar *from, JabberIqType type, 
-		      const gchar *id, xmlnode *sess, gpointer data);
-void gtalk_xfer_transport_accept_cb(JabberStream *js, const gchar *from, JabberIqType type, 
-				    const gchar *id, xmlnode *packet, gpointer data);
-
 static gboolean
 google_session_id_equal(gconstpointer a, gconstpointer b)
 {
@@ -119,12 +52,13 @@ google_session_id_equal(gconstpointer a,
 }
 
 void
-google_session_destroy(GoogleSession *session)
+google_session_destroy(GoogleSession *session) /*TODO: Used for both share and VV*/
 {
 	JabberStream *js = session->js;	
 	session->state = TERMINATED;			
 	
 	if(session->share) {
+	  
 		GoogleXferSessionData *share_session = session->session_data;
 		GSList *temp = NULL;
 		
@@ -230,7 +164,6 @@ static void
 google_session_send_candidates(PurpleMedia *media, gchar *session_id,
 		gchar *participant, GoogleSession *session)
 {
-
 	PurpleMedia *session_media =
 		((GoogleAVSessionData *) session->session_data)->media;
 	GList *candidates =
@@ -500,93 +433,6 @@ jabber_google_session_get_params(JabberS
 	return new_params;
 }
 
-void
-gtalk_xfer_send_terminate(PurpleXfer *xfer)
-{
-	GoogleSession *session = (GoogleSession *) xfer->data;
-	JabberStream *js = session->js;
-	JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
-	xmlnode *session_node;
-
-	purple_debug_info("google_session", "Inside gtalk_xfer_send_terminate, xfer_status : %d\n",
-			  purple_xfer_get_status(xfer));
-
-	if(session->state < IN_PROGRESS) {
-		purple_debug_info("google_session", "Directly calling destroy().. as state<IN_PROGRESS..\n");
-		google_session_destroy(session);
-	}
-	else {
-		xmlnode_set_attrib(iq->node, "to", session->remote_jid);	
-		session_node = xmlnode_new_child(iq->node, "session");
-		xmlnode_set_attrib(session_node, "type", "terminate");
-		xmlnode_set_attrib(session_node, "id", session->id.id);
-		xmlnode_set_attrib(session_node, "initiator", session->id.initiator);
-		xmlnode_set_namespace(session_node, NS_GOOGLE_SESSION);        
-		purple_debug_info("google_session", "Sending google_s_dest as callback..Sending IQ\n");
-		jabber_iq_send(iq);       	
-		google_session_destroy(session);
-	}
-}
-
-void
-gtalk_xfer_cancel_xfer(PurpleXfer *xfer)
-{
-	GoogleSession *session = (GoogleSession *)xfer->data;
-
-	purple_debug_info("gs", "Inside gtalk_xfer_cancel_xfer...\n");
-	
-	if(session->state == TERMINATED)
-		return;
-//TODO: Possible shift the = TERMINATED to google_session_destroy exclusively and remove from everywhere else.
-//High cohesion is good.
-
-//	session->state = TERMINATED;
-
-	gtalk_xfer_send_terminate(xfer);
-
-//	purple_debug_info("google_session", "Calling the google_session_destroy from gtalk_xfer_cancel_xfer() \n");
-//	google_session_destroy(session);
-}
-
-gint gtalk_xfer_init_agent(GoogleSession *session)
-{
-	gint stream_id;
-	NiceAgent *agent;
-	GoogleXferSessionData *share_session = (GoogleXferSessionData *)session->session_data;
-	
-	purple_debug_info("google_session", "Inside gtalk_xfer_init_agent\n");
-	if(!share_session)
-	  return -1;
-	
-	if(share_session->share_agent)
-	  return share_session->stream_id;
-
-	agent = share_session->share_agent;
-	
-	agent = nice_agent_new_reliable (g_main_context_default(), NICE_COMPATIBILITY_GOOGLE);
-	stream_id = nice_agent_add_stream(agent, 1);
-	share_session->share_agent = agent;
-
-	nice_agent_attach_recv (share_session->share_agent, stream_id, 1, g_main_context_default(),
-				cb_nice_recv, share_session);
-	
-	g_signal_connect (G_OBJECT (share_session->share_agent), "candidate-gathering-done",
-			  G_CALLBACK (cb_candidate_gathering_done),  session);
-	
-	g_signal_connect (G_OBJECT (share_session->share_agent), "new-selected-pair",
-			  G_CALLBACK (cb_new_selected_pair), NULL);
-	
-	g_signal_connect  (G_OBJECT (share_session->share_agent), "component-state-changed",
-			   G_CALLBACK (cb_nice_component_state_changed), session);
-
-	g_signal_connect (G_OBJECT (share_session->share_agent), "reliable-transport-writable",
-			  G_CALLBACK (cb_nice_component_writable), share_session);
-
-	share_session->share_agent = agent;
-	share_session->stream_id = stream_id;
-	return stream_id;
-}
-
 static void
 jabber_google_relay_response_session_initiate_cb(GoogleSession *session,
     const gchar *relay_ip, guint relay_udp, guint relay_tcp, guint relay_ssltcp,
@@ -1027,42 +873,6 @@ google_session_handle_initiate(JabberStr
 	return TRUE;	
 }
 
-void
-gtalk_xfer_handle_info(JabberStream  *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
-{
-	JabberIq *iq;
-	xmlnode *channel = xmlnode_get_child(sess, "channel");
-	xmlnode *complete = xmlnode_get_child(sess, "complete");	
-	GoogleXferSessionData *share_session = (GoogleXferSessionData *)session->session_data;	
-
-	purple_debug_info("google_session", "Inside gtalk_xfer_handle_info\n");
-	
-	if(complete) {
-		iq = jabber_iq_new(js, JABBER_IQ_RESULT);
-		jabber_iq_set_id(iq, iq_id);
-		xmlnode_set_attrib(iq->node, "to", session->remote_jid);
-		jabber_iq_send(iq);
-		/*Maybe this call to session_destroy shouldn't occur and we should trigger the destroy when
-		  GTalk sends us the terminate message,(which ideally should be immediately following
-		  the "complete" message), but that would be depending on Google Talk for killing
-		  this session. Need to resolve this and this comment should go away ASAP. TODO*/
-		google_session_destroy(session);
-		return;
-	}
-
-	if(channel)
-		share_session->channel_name = g_strdup(xmlnode_get_attrib(channel, "name"));
-	
-	iq = jabber_iq_new(js, JABBER_IQ_RESULT);
-	jabber_iq_set_id(iq, iq_id);
-	xmlnode_set_attrib(iq->node, "to", session->remote_jid);
-	jabber_iq_send(iq);
-
-	purple_debug_info("google_session", "Starting candidate cathering with nice agent..\n");
-
-	nice_agent_gather_candidates(share_session->share_agent, share_session->stream_id);
-}
-
 static void
 google_session_handle_candidates(JabberStream  *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
 {
@@ -1249,98 +1059,6 @@ google_session_handle_transport_accept(J
 	session->state = IN_PROGRESS;
 }
 
-NiceCandidate *
-nice_candidate_from_xml(const xmlnode *candidate,
-			guint stream_id)
-{
-	NiceCandidate *cand = NULL;
-	const gchar *name = xmlnode_get_attrib(candidate, "name");
-	const gchar *type = xmlnode_get_attrib(candidate, "type");
-	const gchar *address = xmlnode_get_attrib(candidate, "address");
-	guint port = atoi(xmlnode_get_attrib(candidate, "port"));
-	const gchar *preference = xmlnode_get_attrib(candidate, "preference");
-	
-	if (name && type && address && port != 0) {
-		guint prio = preference ? g_ascii_strtod(preference, NULL) * 1000 : 0;
-		cand = nice_candidate_new(purple_strequal(type, "host") ?
-			NICE_CANDIDATE_TYPE_HOST :
-			purple_strequal(type, "stun") ? NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE :
-			purple_strequal(type, "relay") ? NICE_CANDIDATE_TYPE_RELAYED :
-			NICE_CANDIDATE_TYPE_HOST);
-
-		nice_address_init(&cand->addr);
-
-		if (!nice_address_set_from_string(&cand->addr, address)) {
-			purple_debug_error("google_session",
-				"Invalid NiceAddress in NiceCandidate.\n");
-			nice_candidate_free(cand);
-			return NULL;
-		}
-
-		nice_address_set_port(&cand->addr, port);
-		cand->priority = prio;
-		cand->stream_id = stream_id;
-		cand->username = g_strdup(xmlnode_get_attrib(candidate, "username"));
-		cand->password = g_strdup(xmlnode_get_attrib(candidate, "password"));
-	} else {
-		purple_debug_error("google_session", "received invalid candidate!\n");
-	}
-
-	return cand;
-}
-
-static void
-gtalk_xfer_handle_candidates(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
-{



More information about the Commits mailing list