cpw.malu.xmpp.google_ft: 6bcdd553: parse response HTTP headers (don't yet a...

malu at pidgin.im malu at pidgin.im
Mon Sep 27 17:10:57 EDT 2010


----------------------------------------------------------------------
Revision: 6bcdd5538deecf01186a2878484f5613f2438e97
Parent:   aff9b5e6cf8320c28f5149eb468b88b8e68f4764
Author:   malu at pidgin.im
Date:     09/27/10 17:09:26
Branch:   im.pidgin.cpw.malu.xmpp.google_ft
URL: http://d.pidgin.im/viewmtn/revision/info/6bcdd5538deecf01186a2878484f5613f2438e97

Changelog: 

parse response HTTP headers (don't yet act on them, like repsonse 404...)

Changes against parent aff9b5e6cf8320c28f5149eb468b88b8e68f4764

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

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google/google_share.c	46dabab1055ff0ae2a0ba2e20dacc48ad989f1fb
+++ libpurple/protocols/jabber/google/google_share.c	cb4b0cf1dc129ddf51e220fb26761d7c9d73f117
@@ -129,6 +129,7 @@ google_share_writable_cb(NiceAgent *agen
 			nice_agent_send(session_data->agent, session_data->stream_id, 1,
 				strlen(request), request);
 			g_free(uri);
+			session_data->channel_state = GOOGLE_SHARE_CHANNEL_SENT_HTTP_CONTENT_GET;
 		}
 	}
 }
@@ -319,14 +320,81 @@ google_share_candidate_gathering_done_cb
 	}
 }
 
+/* If buffer contains a line ending, 0-terminate the first line and
+ * return a pointer to the beginning of the next line. Otherwise
+ * return NULL. */
+static gchar *
+http_read_line(gchar *buffer, guint len)
+{
+  gchar *p = memchr(buffer, '\n', len);
+
+  if (p != NULL) {
+      *p = 0;
+      if (p > buffer && *(p-1) == '\r')
+        *(p-1) = '\0';
+      p++;
+  }
+
+  return p;
+}
+
+
 static void
 google_share_data_received_cb(NiceAgent *agent, guint stream_id,
 	guint component_id, guint len, gchar *buf, gpointer user_data)
 {
 	GoogleSession *session = (GoogleSession *) user_data;
+	GoogleShareSessionData *session_data =
+		(GoogleShareSessionData *) session->session_data;
+	PurpleXfer *xfer = session_data->xfer;
+	gchar *curr = buf;
+	
+	purple_debug_info("google-share", "received data len: %d\n", len);
 
-	purple_debug_info("google-share", "received data len: %d\n", len);
-	purple_debug_info("google-share", "data: %s\n", buf);
+	if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
+		if (session_data->channel_state ==
+		    GOOGLE_SHARE_CHANNEL_SENT_HTTP_CONTENT_GET) {
+			gchar *tmp;
+				
+			do {
+				tmp = http_read_line(curr, len); 
+				gsize read_len = tmp - curr;
+				
+				purple_debug_info("google-share",
+					"found HTTP response header: %s\n", curr);
+
+				len -= read_len;
+				curr += read_len;
+
+				if (g_ascii_strncasecmp(curr, "HTTP/1.1", 8)) {
+					if (purple_strequal(curr + 9, "404")) {
+						/* got a 404 (file not found) stop... */
+						/* TODO: terminate the session */
+					}
+				}
+				/* check Content-Length and other headers too? */
+				
+			} while (curr[0] != '\0' && len > 0);
+
+			if (curr[0] == '\0') {
+				/* we found the end of the headers */
+				purple_debug_info("google-share", "found empty line in headers\n");
+
+				session_data->channel_state =
+					GOOGLE_SHARE_CHANNEL_PARSED_HTTP_RESPONSE_HEADER;
+			}
+			/* otherwise the remaining headers would come in the next package
+				 not sure if this will ever happen */
+				
+		} else if (session_data->channel_state ==
+			GOOGLE_SHARE_CHANNEL_PARSED_HTTP_RESPONSE_HEADER) {
+			/* write data to transfer */
+			purple_debug_info("google-share",
+				"got %d bytes to write to transfer\n", len);
+		}
+	} else {
+
+	}
 }
 
 static void


More information about the Commits mailing list