soc.2008.xmpp: 848dfd93: * adding bosh files to Makefile.am Subject: im.pidgin.soc.2008.xmpp: 848dfd939dfe271c06ad52dc6e66036ecfda48a0 .mi...
tfar at soc.pidgin.im
tfar at soc.pidgin.im
Fri Aug 15 10:11:11 EDT 2008
-----------------------------------------------------------------
Revision: 848dfd939dfe271c06ad52dc6e66036ecfda48a0
Ancestor: 72d6870ed2c62423a05ed89822db25d9916ecf2b
Author: tfar at soc.pidgin.im
Date: 2008-08-05T18:44:42
Branch: im.pidgin.soc.2008.xmpp
URL: http://d.pidgin.im/viewmtn/revision/info/848dfd939dfe271c06ad52dc6e66036ecfda48a0
Modified files:
libpurple/protocols/jabber/Makefile.am
libpurple/protocols/jabber/Makefile.mingw
libpurple/protocols/jabber/bosh.c
libpurple/protocols/jabber/bosh.h
libpurple/protocols/jabber/jabber.c
ChangeLog:
* adding bosh files to Makefile.am & .mingw
* establishing HTTP connection for BOSH
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/Makefile.am c3548815c48a2264e4ed44e9023d8a124c3fc7f7
+++ libpurple/protocols/jabber/Makefile.am 2b2d17248604993bc39e65785f1f124f98947062
@@ -9,6 +9,8 @@ JABBERSOURCES = auth.c \
auth.h \
buddy.c \
buddy.h \
+ bosh.c \
+ bosh.h \
chat.c \
chat.h \
disco.c \
============================================================
--- libpurple/protocols/jabber/Makefile.mingw f0ba792560dee01a48fc6252c5fb4b1fd8e71689
+++ libpurple/protocols/jabber/Makefile.mingw 3781c1aa91e0cd25aa285e5ac8884062c66b4101
@@ -46,6 +46,7 @@ C_SRC = \
adhoccommands.c \
auth.c \
buddy.c \
+ bosh.c
caps.c \
chat.c \
disco.c \
============================================================
--- libpurple/protocols/jabber/bosh.c b848bb9c2bc73b09db310bae9222629bad980ae7
+++ libpurple/protocols/jabber/bosh.c 1464502d62858b38127a53f672676bfec0ee1fb7
@@ -37,13 +37,51 @@
#include "pep.h"
#include "adhoccommands.h"
-PurpleHTTPHeaderField* jabber_bosh_http_header_field(const char *name, *const char *value) {
- PurpleHTTPHeaderField *tmp = g_new0(PurpleHTTPHeaderField, 0);
- tmp->name = g_strdup(name);
- tmp->value = g_strdup(value);
- return tmp;
+void jabber_bosh_connection_init(PurpleBOSHConnection *conn, PurpleAccount *account, char *url) {
+ conn->pipelining = TRUE;
+ conn->account = account;
+ if (!purple_url_parse(url, &(conn->host), &(conn->port), &(conn->path), &(conn->user), &(conn->passwd))) {
+ purple_debug_info("jabber", "Unable to parse given URL.\n");
+ return;
+ }
+ if (conn->user || conn->passwd) {
+ purple_debug_info("jabber", "Sorry, HTTP Authentication isn't supported yet. Username and password in the BOSH URL will be ignored.\n");
+ }
+ conn->conn_a = g_new0(PurpleHTTPConnection, 1);
+ jabber_bosh_http_connection_init(conn->conn_a, conn->account, conn->host, conn->port);
+ conn->conn_a->userdata = conn;
}
+static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) {
+ PurpleBOSHConnection *bosh_conn = conn->userdata;
+ if (bosh_conn->connect_cb) bosh_conn->connect_cb(bosh_conn);
+}
+
+void jabber_bosh_connection_connect(PurpleBOSHConnection *conn) {
+ conn->conn_a->connect_cb = jabber_bosh_connection_connected;
+ jabber_bosh_http_connection_connect(conn->conn_a);
+}
+
+
+void jabber_bosh_http_connection_init(PurpleHTTPConnection *conn, PurpleAccount *account, char *host, int port) {
+ conn->account = account;
+ conn->host = host;
+ conn->port = port;
+ conn->connect_cb = NULL;
+}
+
+static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) {
+ PurpleHTTPConnection *conn = data;
+ if (source < 0) {
+ purple_debug_info("jabber", "Couldn't connect becasue of: %s\n", error);
+ return;
+ }
+ conn->fd = source;
+ if (conn->connect_cb) conn->connect_cb(conn);
+}
+
void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn) {
-
+ if((purple_proxy_connect(&(conn->handle), conn->account, conn->host, conn->port, jabber_bosh_http_connection_callback, conn)) == NULL) {
+ purple_debug_info("jabber", "Unable to connect to %s.\n", conn->host);
+ }
}
============================================================
--- libpurple/protocols/jabber/bosh.h 47b44b75394e8ac8e4636be5956a3d970bec4d36
+++ libpurple/protocols/jabber/bosh.h 30dfe2e7aaeba8942284fda762d3e0db4bd22426
@@ -26,24 +26,45 @@ typedef struct _PurpleHTTPResponse Purpl
typedef struct _PurpleHTTPRequest PurpleHTTPRequest;
typedef struct _PurpleHTTPResponse PurpleHTTPResponse;
-typedef struct _PurpleHTTPHeaderField PurpleHTTPHeaderField;
+typedef struct _PurpleHTTPConnection PurpleHTTPConnection;
+typedef struct _PurpleBOSHConnection PurpleBOSHConnection;
+typedef void (*PurpleHTTPConnectionConnectFunction)(PurpleHTTPConnection *conn);
typedef void (*PurpleHTTPRequestCallback)(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata);
+typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn);
+typedef void (*PurpleBOSHConnectionReciveFunction)(PurpleBOSHConnection *conn, xmlnode *node);
-typedef struct {
- int fd;
- PurpleConnection *conn;
- GQueue *requests;
+struct _PurpleBOSHConnection {
+ /* decoded URL */
+ char *host;
+ int port;
+ char *path;
+ char *user;
+ char *passwd;
+
void *userdata;
-} PurpleHTTPConnection;
-
-typedef struct {
- char *url;
+ PurpleAccount *account;
gboolean pipelining;
PurpleHTTPConnection *conn_a;
PurpleHTTPConnection *conn_b;
-} PurpleBOSHConnection;
+
+ PurpleBOSHConnectionConnectFunction connect_cb;
+ PurpleBOSHConnectionReciveFunction receive_cb;
+};
+struct _PurpleHTTPConnection {
+ int fd;
+ char *host;
+ int port;
+ int handle;
+ PurpleConnection *conn;
+ PurpleAccount *account;
+ GQueue *requests;
+
+ PurpleHTTPConnectionConnectFunction connect_cb;
+ void *userdata;
+};
+
struct _PurpleHTTPRequest {
PurpleHTTPRequestCallback cb;
char *method;
@@ -55,21 +76,18 @@ struct _PurpleHTTPResponse {
struct _PurpleHTTPResponse {
int status;
- GList *header;
+ GHashTable *header;
char *data;
};
-struct _PurpleHTTPHeaderField {
- char *name;
- char *value;
-};
+void jabber_bosh_connection_init(PurpleBOSHConnection *conn, PurpleAccount *account, char *url);
+void jabber_bosh_connection_connect(PurpleBOSHConnection *conn);
-PurpleHTTPHeaderField *jabber_bosh_http_header_field(const char *name, const char *value);
-
+void jabber_bosh_http_connection_init(PurpleHTTPConnection *conn, PurpleAccount *account, char *host, int port);
void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn);
void jabber_bosh_http_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req);
void jabber_bosh_http_connection_clean(PurpleHTTPConnection *conn);
-void jabber_bosh_http_request_init(PurpleHTTPRequest *req, const char *method, const char *url, PurpleHTTPRequestCallback cb, void *userdata);
+void jabber_bosh_http_request_init(PurpleHTTPRequest *req, const char *method, const char *path, PurpleHTTPRequestCallback cb, void *userdata);
void jabber_bosh_http_request_clean(PurpleHTTPRequest *req);
#endif /* _PURPLE_JABBER_BOSH_H_ */
============================================================
--- libpurple/protocols/jabber/jabber.c 9d6c90aeb4dcf6074b7787993a1af4440d189253
+++ libpurple/protocols/jabber/jabber.c ab1cf692d3d867232a6c5b1660cc108bc6fb813b
@@ -521,6 +521,12 @@ jabber_login_callback_ssl(gpointer data,
jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING_ENCRYPTION);
}
+static void
+jabber_bosh_login_callback(PurpleBOSHConnection *conn)
+{
+ purple_debug_info("jabber","YAY...BOSH connection established.\n");
+}
+
static void
txt_resolved_cb(PurpleTxtResponse *resp, int results, gpointer data)
{
@@ -533,7 +539,8 @@ txt_resolved_cb(PurpleTxtResponse *resp,
tmp = g_strdup_printf(_("Could not find alternative XMPP connection methods after failing to connect directly.\n"));
purple_connection_error_reason (gc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
- g_free(tmp);
+ g_free(tmp);
+ return;
}
for (n = 0; n < results; n++) {
@@ -541,12 +548,19 @@ txt_resolved_cb(PurpleTxtResponse *resp,
token = g_strsplit(resp[n].content, "=", 2);
if (!strcmp(token[0], "_xmpp-client-xbosh")) {
purple_debug_info("jabber","Found alternative connection method using %s at %s.\n", token[0], token[1]);
- js->bosh.url = g_strdup(token[1]);
+ jabber_bosh_connection_init(&(js->bosh), gc->account, token[1]);
g_strfreev(token);
break;
}
g_strfreev(token);
}
+ if (js->bosh.host) {
+ js->bosh.userdata = gc;
+ js->bosh.connect_cb = jabber_bosh_login_callback;
+ jabber_bosh_connection_connect(&(js->bosh));
+ } else {
+ purple_debug_info("jabber","Didn't find an alternative connection method.\n");
+ }
}
static void
More information about the Commits
mailing list