/soc/2013/ankitkv/gobjectification: c820f900c455: Merged soc.201...

Ankit Vani a at nevitus.org
Fri Aug 2 20:09:18 EDT 2013


Changeset: c820f900c455d306d3cb1ea6375995959664b55b
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-03 05:39 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/c820f900c455

Description:

Merged soc.2013.gobjectification branch

diffstat:

 libpurple/http.c                        |    86 +-
 libpurple/http.h                        |    25 +-
 libpurple/protocols/jabber/bosh.c       |  1332 ++++++++----------------------
 libpurple/protocols/jabber/bosh.h       |    35 +-
 libpurple/protocols/jabber/jabber.c     |    24 +-
 libpurple/protocols/jabber/jabber.h     |     3 +-
 libpurple/protocols/mxit/Makefile.mingw |     1 -
 7 files changed, 513 insertions(+), 993 deletions(-)

diffs (truncated from 1805 to 300 lines):

diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -55,7 +55,7 @@ struct _PurpleHttpSocket
 {
 	gboolean is_ssl;
 	gboolean is_busy;
-	uint use_count;
+	guint use_count;
 	PurpleHttpKeepaliveHost *host;
 
 	PurpleSslConnection *ssl_connection;
@@ -104,6 +104,7 @@ struct _PurpleHttpConnection
 	PurpleHttpResponse *response;
 
 	PurpleHttpKeepaliveRequest *socket_request;
+	PurpleHttpConnectionSet *connection_set;
 	PurpleHttpSocket *socket;
 	GString *request_header;
 	int request_header_written, request_contents_written;
@@ -206,6 +207,13 @@ struct _PurpleHttpKeepalivePool
 	GHashTable *by_hash;
 };
 
+struct _PurpleHttpConnectionSet
+{
+	gboolean is_destroying;
+
+	GHashTable *connections;
+};
+
 static time_t purple_http_rfc1123_to_time(const gchar *str);
 
 static gboolean purple_http_request_is_method(PurpleHttpRequest *request,
@@ -235,6 +243,10 @@ purple_http_keepalive_pool_request_cance
 static void
 purple_http_keepalive_pool_release(PurpleHttpSocket *hs, gboolean invalidate);
 
+static void
+purple_http_connection_set_remove(PurpleHttpConnectionSet *set,
+	PurpleHttpConnection *http_conn);
+
 static GRegex *purple_http_re_url, *purple_http_re_url_host,
 	*purple_http_re_rfc1123;
 
@@ -1514,13 +1526,15 @@ PurpleHttpConnection * purple_http_reque
 	hc->callback = callback;
 	hc->user_data = user_data;
 
+	hc->url = purple_http_url_parse(request->url);
+
 	if (purple_debug_is_unsafe())
 		purple_debug_misc("http", "Performing new request %p for %s.\n",
 			hc, request->url);
 	else
-		purple_debug_misc("http", "Performing new request %p.\n", hc);
-
-	hc->url = purple_http_url_parse(request->url);
+		purple_debug_misc("http", "Performing new request %p to %s.\n",
+			hc, hc->url ? hc->url->host : NULL);
+
 	if (!hc->url || hc->url->host == NULL || hc->url->host[0] == '\0') {
 		purple_debug_error("http", "Invalid URL requested.\n");
 		purple_http_connection_terminate(hc);
@@ -1571,6 +1585,9 @@ static void purple_http_connection_free(
 	if (hc->watcher_delayed_handle)
 		purple_timeout_remove(hc->watcher_delayed_handle);
 
+	if (hc->connection_set != NULL)
+		purple_http_connection_set_remove(hc->connection_set, hc);
+
 	purple_http_url_free(hc->url);
 	purple_http_request_unref(hc->request);
 	purple_http_response_free(hc->response);
@@ -2254,6 +2271,67 @@ purple_http_keepalive_pool_get_limit_per
 	return pool->limit_per_host;
 }
 
+/*** HTTP connection set API **************************************************/
+
+PurpleHttpConnectionSet *
+purple_http_connection_set_new(void)
+{
+	PurpleHttpConnectionSet *set;
+
+	set = g_new0(PurpleHttpConnectionSet, 1);
+	set->connections = g_hash_table_new(g_direct_hash, g_direct_equal);
+
+	return set;
+}
+
+void
+purple_http_connection_set_destroy(PurpleHttpConnectionSet *set)
+{
+	if (set == NULL)
+		return;
+
+	set->is_destroying = TRUE;
+
+	while (TRUE) {
+		GHashTableIter iter;
+		PurpleHttpConnection *http_conn;
+
+		g_hash_table_iter_init(&iter, set->connections);
+		if (!g_hash_table_iter_next(&iter, (gpointer*)&http_conn, NULL))
+			break;
+
+		purple_http_conn_cancel(http_conn);
+	}
+
+	g_hash_table_destroy(set->connections);
+	g_free(set);
+}
+
+void
+purple_http_connection_set_add(PurpleHttpConnectionSet *set,
+	PurpleHttpConnection *http_conn)
+{
+	if (set->is_destroying)
+		return;
+	if (http_conn->connection_set == set)
+		return;
+	if (http_conn->connection_set != NULL) {
+		purple_http_connection_set_remove(http_conn->connection_set,
+			http_conn);
+	}
+	g_hash_table_insert(set->connections, http_conn, (gpointer)TRUE);
+	http_conn->connection_set = set;
+}
+
+static void
+purple_http_connection_set_remove(PurpleHttpConnectionSet *set,
+	PurpleHttpConnection *http_conn)
+{
+	g_hash_table_remove(set->connections, http_conn);
+	if (http_conn->connection_set == set)
+		http_conn->connection_set = NULL;
+}
+
 /*** Request API **************************************************************/
 
 static void purple_http_request_free(PurpleHttpRequest *request);
diff --git a/libpurple/http.h b/libpurple/http.h
--- a/libpurple/http.h
+++ b/libpurple/http.h
@@ -59,11 +59,16 @@ typedef struct _PurpleHttpURL PurpleHttp
 typedef struct _PurpleHttpCookieJar PurpleHttpCookieJar;
 
 /**
- * An pool of TCP connections for HTTP Keep-Alive session.
+ * A pool of TCP connections for HTTP Keep-Alive session.
  */
 typedef struct _PurpleHttpKeepalivePool PurpleHttpKeepalivePool;
 
 /**
+ * A set of running HTTP requests. Can be used to cancel all of them at once.
+ */
+typedef struct _PurpleHttpConnectionSet PurpleHttpConnectionSet;
+
+/**
  * An callback called after performing (successfully or not) HTTP request.
  */
 typedef void (*PurpleHttpCallback)(PurpleHttpConnection *http_conn,
@@ -721,6 +726,24 @@ purple_http_keepalive_pool_get_limit_per
 
 
 /**************************************************************************/
+/** @name HTTP connection set API                                         */
+/**************************************************************************/
+/*@{*/
+
+PurpleHttpConnectionSet *
+purple_http_connection_set_new(void);
+
+void
+purple_http_connection_set_destroy(PurpleHttpConnectionSet *set);
+
+void
+purple_http_connection_set_add(PurpleHttpConnectionSet *set,
+	PurpleHttpConnection *http_conn);
+
+/*@}*/
+
+
+/**************************************************************************/
 /** @name HTTP response API                                               */
 /**************************************************************************/
 /*@{*/
diff --git a/libpurple/protocols/jabber/bosh.c b/libpurple/protocols/jabber/bosh.c
--- a/libpurple/protocols/jabber/bosh.c
+++ b/libpurple/protocols/jabber/bosh.c
@@ -17,1087 +17,503 @@
  *
  * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
  *
  */
 #include "internal.h"
-#include "circularbuffer.h"
 #include "core.h"
-#include "cipher.h"
 #include "debug.h"
 #include "http.h"
-#include "prpl.h"
-#include "util.h"
-#include "xmlnode.h"
 
 #include "bosh.h"
 
-/* The number of HTTP connections to use. This MUST be at least 2. */
-#define NUM_HTTP_CONNECTIONS      2
-/* How many failed connection attempts before it becomes a fatal error */
-#define MAX_FAILED_CONNECTIONS    3
-/* How long in seconds to queue up outgoing messages */
-#define BUFFER_SEND_IN_SECS       1
+/*
+TODO: test, what happens, if the http server (BOSH server) doesn't support
+keep-alive (sends connection: close).
+*/
 
-typedef struct _PurpleHTTPConnection PurpleHTTPConnection;
+#define JABBER_BOSH_SEND_DELAY 250
 
-typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn);
-typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node);
+#define JABBER_BOSH_TIMEOUT 10
 
-static char *bosh_useragent = NULL;
+static gchar *jabber_bosh_useragent = NULL;
 
-typedef enum {
-	PACKET_NORMAL,
-	PACKET_TERMINATE,
-	PACKET_FLUSH,
-} PurpleBOSHPacketType;
+struct _PurpleJabberBOSHConnection {
+	JabberStream *js;
+	PurpleHttpKeepalivePool *kapool;
+	PurpleHttpConnection *sc_req; /* Session Creation Request */
+	PurpleHttpConnectionSet *payload_reqs;
 
-struct _PurpleBOSHConnection {
-	JabberStream *js;
-	PurpleHTTPConnection *connections[NUM_HTTP_CONNECTIONS];
+	gchar *url;
+	gboolean is_ssl;
+	gboolean is_terminating;
 
-	PurpleCircularBuffer *pending;
-	PurpleBOSHConnectionConnectFunction connect_cb;
-	PurpleBOSHConnectionReceiveFunction receive_cb;
+	gchar *sid;
+	guint64 rid; /* Must be big enough to hold 2^53 - 1 */
 
-	/* Must be big enough to hold 2^53 - 1 */
-	char *sid;
-	guint64 rid;
-
-	/* decoded URL */
-	char *host;
-	char *path;
-	guint16 port;
-
-	gboolean pipelining;
-	gboolean ssl;
-
-	enum {
-		BOSH_CONN_OFFLINE,
-		BOSH_CONN_BOOTING,
-		BOSH_CONN_ONLINE
-	} state;
-	guint8 failed_connections;
-
-	int wait;
-
-	int max_requests;
-	int requests;
-
+	GString *send_buff;
 	guint send_timer;
 };
 
-struct _PurpleHTTPConnection {
-	PurpleBOSHConnection *bosh;
-	PurpleSslConnection *psc;
+static PurpleHttpRequest *
+jabber_bosh_connection_http_request_new(PurpleJabberBOSHConnection *conn,
+	const GString *data);
+static void
+jabber_bosh_connection_session_create(PurpleJabberBOSHConnection *conn);
+static void
+jabber_bosh_connection_send_now(PurpleJabberBOSHConnection *conn);
 
-	PurpleCircularBuffer *write_buf;
-	GString *read_buf;
-
-	gsize handled_len;
-	gsize body_len;



More information about the Commits mailing list