Mercurial > pidgin
diff libpurple/protocols/jabber/bosh.c @ 25042:1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
* establishing HTTP connection for BOSH
author | Tobias Markmann <tfar@soc.pidgin.im> |
---|---|
date | Tue, 05 Aug 2008 18:44:42 +0000 |
parents | b238da95f39a |
children | 15d9825a5621 |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c Sun Aug 03 22:58:10 2008 +0000 +++ b/libpurple/protocols/jabber/bosh.c Tue Aug 05 18:44:42 2008 +0000 @@ -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); + } } \ No newline at end of file