cpw.malu.xmpp.google_ft: aff9b5e6: can now receive files (kinda), it can re...

malu at pidgin.im malu at pidgin.im
Sun Sep 26 15:20:48 EDT 2010


----------------------------------------------------------------------
Revision: aff9b5e6cf8320c28f5149eb468b88b8e68f4764
Parent:   3aff2bb4e95e9df2c2bf81d1764bf3885ab959f5
Author:   malu at pidgin.im
Date:     09/26/10 15:19:12
Branch:   im.pidgin.cpw.malu.xmpp.google_ft
URL: http://d.pidgin.im/viewmtn/revision/info/aff9b5e6cf8320c28f5149eb468b88b8e68f4764

Changelog: 

can now receive files (kinda), it can request the file and prints the received data as raw text...

Changes against parent 3aff2bb4e95e9df2c2bf81d1764bf3885ab959f5

  patched  libpurple/protocols/jabber/google/google_share.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google/google_share.c	f01447547c645e3359167c193e33fb5510e27318
+++ libpurple/protocols/jabber/google/google_share.c	46dabab1055ff0ae2a0ba2e20dacc48ad989f1fb
@@ -19,6 +19,7 @@
  */
 
 #include "internal.h"
+#include "core.h"
 #include "debug.h"
 #include "network.h"
 #include "google_share.h"
@@ -28,6 +29,13 @@
 
 #include <nice/agent.h>
 
+typedef enum {
+	GOOGLE_SHARE_CHANNEL_INITIALIZED = 0,
+	GOOGLE_SHARE_CHANNEL_SENT_HTTP_CONTENT_GET,
+	GOOGLE_SHARE_CHANNEL_PARSED_HTTP_RESPONSE_HEADER
+	/* more states will be added later on... */
+} GoogleShareChannelState;
+
 typedef struct {
 	PurpleXfer *xfer;
 	NiceAgent *agent;
@@ -37,7 +45,8 @@ typedef struct {
 	gboolean got_relay;		/* this indicates if gotten relay credentials */
 	gboolean old_protocol;
 	gboolean candidate_gathering_done;
-	NiceComponentState *state;
+	NiceComponentState state;
+	GoogleShareChannelState channel_state;
 } GoogleShareSessionData;
 
 static void
@@ -58,11 +67,70 @@ google_share_component_state_changed_cb(
 	session_data->state = state;
 }
 
+static gchar *
+google_share_create_http_request(JabberStream *js, const gchar *url)
+{
+	GHashTable *ui_info = purple_core_get_ui_info();
+	const gchar *ui_name = g_hash_table_lookup(ui_info, "name");
+
+	return g_strdup_printf("GET %s HTTP/1.1\r\n"
+		"Connection: Keep-Alive\r\n"
+	    "Content-Length: 0\r\n"
+	    "Host: %s@%s/%s:0\r\n"
+	    "User-Agent: %s\r\n\r\n", url, js->user->node, js->user->domain,
+	    js->user->resource, ui_name ? ui_name : PACKAGE); 
+}
+
 static void
 google_share_writable_cb(NiceAgent *agent, guint stream_id, guint compont_id,
 	gpointer user_data)
 {
+	GoogleSession *session = (GoogleSession *) user_data;
+	GoogleShareSessionData *session_data =
+		(GoogleShareSessionData *) session->session_data;
+	PurpleXfer *xfer = session_data->xfer;
+	
 	purple_debug_info("google-share", "transport writable!\n");
+
+	if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
+		xmlnode *description = session->description;
+		xmlnode *protocol = xmlnode_get_child(description, "protocol");
+		xmlnode *http = xmlnode_get_child(protocol, "http");
+		xmlnode *url;
+		gchar *source_path = NULL;
+		xmlnode *manifest = xmlnode_get_child(description, "manifest");
+		xmlnode *file = xmlnode_get_child(manifest, "file");
+		xmlnode *name = xmlnode_get_child(file, "name");
+		gchar *name_data = xmlnode_get_data(name);
+		gchar *filename = g_uri_escape_string(name_data, NULL, TRUE);
+
+		g_free(name_data);
+		
+		for (url = xmlnode_get_child(http, "url") ;
+		     url ; url = xmlnode_get_next_twin(url)) {
+			if (purple_strequal(xmlnode_get_attrib(url, "name"), "source-path")) {
+				source_path = xmlnode_get_data(url);
+			}
+		}
+
+		if (source_path) {
+			/* send HTTP get request */
+			gchar *uri = g_strdup_printf("%s%s", source_path, filename);
+			gchar *request =
+				google_share_create_http_request(session->js, uri);
+
+			g_free(source_path);
+			g_free(filename);
+			
+			purple_debug_info("google-share", "sending HTTP request: %s\n",
+				request);
+			/* should probably check the respond and bail out or send additional
+			 bytes not sent in the first call if it returned < len */
+			nice_agent_send(session_data->agent, session_data->stream_id, 1,
+				strlen(request), request);
+			g_free(uri);
+		}
+	}
 }
 
 static NiceCandidate *
@@ -147,7 +215,7 @@ google_share_handle_transport_info(Jabbe
 
 		if (session_data->candidate_gathering_done) {
 			nice_agent_set_remote_candidates(agent, session_data->stream_id,
-				NICE_COMPONENT_TYPE_RTP, candidates);
+				1, candidates);
 			google_share_candidate_list_free(candidates);
 		} else {
 			session_data->remote_candidates =
@@ -226,14 +294,14 @@ google_share_candidate_gathering_done_cb
 	GoogleShareSessionData *session_data =
 		(GoogleShareSessionData *) session->session_data;
 	GSList *candidates = nice_agent_get_local_candidates(agent,
-		session_data->stream_id, NICE_COMPONENT_TYPE_RTP);
+		session_data->stream_id, 1);
 
 	purple_debug_info("google-share", "candidate gathering done!\n");
 	session_data->candidate_gathering_done = TRUE;
 
 	/* add remote candidates received while gathering local candidates */
 	nice_agent_set_remote_candidates(agent, session_data->stream_id,
-		NICE_COMPONENT_TYPE_RTP, session_data->remote_candidates);
+		1, session_data->remote_candidates);
 	google_share_candidate_list_free(session_data->remote_candidates);
 
 	/* send local candidates */
@@ -257,6 +325,8 @@ google_share_data_received_cb(NiceAgent 
 {
 	GoogleSession *session = (GoogleSession *) user_data;
 
+	purple_debug_info("google-share", "received data len: %d\n", len);
+	purple_debug_info("google-share", "data: %s\n", buf);
 }
 
 static void
@@ -394,22 +464,19 @@ google_share_init_agent(GoogleSession *s
 		/* set relays */
 		if (relay_ip) {
 			if (relay_udp)
-				nice_agent_set_relay_info(agent, stream_id,
-				    NICE_COMPONENT_TYPE_RTP, relay_ip, relay_udp,
+				nice_agent_set_relay_info(agent, stream_id, 1, relay_ip, relay_udp,
 					relay_username, relay_password, NICE_RELAY_TYPE_TURN_UDP);
 			if (relay_tcp)
-				nice_agent_set_relay_info(agent, stream_id,
-				    NICE_COMPONENT_TYPE_RTP, relay_ip, relay_tcp,
+				nice_agent_set_relay_info(agent, stream_id, 1, relay_ip, relay_tcp,
 			    	relay_username, relay_password, NICE_RELAY_TYPE_TURN_TCP);
 			if (relay_ssltcp)
-				nice_agent_set_relay_info(agent, stream_id,
-				    NICE_COMPONENT_TYPE_RTP, relay_ip, relay_ssltcp,
+				nice_agent_set_relay_info(agent, stream_id, 1, relay_ip, relay_ssltcp,
 			    	relay_username, relay_password, NICE_RELAY_TYPE_TURN_TLS);
 		}
 
 		/* set up signal */
-		nice_agent_attach_recv(agent, stream_id, NICE_COMPONENT_TYPE_RTP,
-		    g_main_context_default(), google_share_data_received_cb, session);
+		nice_agent_attach_recv(agent, stream_id, 1, g_main_context_default(),
+			google_share_data_received_cb, session);
 		g_signal_connect(G_OBJECT(agent), "candidate-gathering-done",
 	    	G_CALLBACK(google_share_candidate_gathering_done_cb), session);
 		g_signal_connect(G_OBJECT(agent), "reliable-transport-writable",


More information about the Commits mailing list