Mercurial > pidgin
annotate libpurple/protocols/jabber/bosh.c @ 25046:e28f1711f402
* parsing HTTP response and emitting HTTP request callback
author | Tobias Markmann <tfar@soc.pidgin.im> |
---|---|
date | Mon, 11 Aug 2008 21:28:05 +0000 |
parents | 24b97b8359ff |
children | f747c682a0d9 |
rev | line source |
---|---|
25038
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
1 /* |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
2 * purple - Jabber Protocol Plugin |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
3 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
4 * Copyright (C) 2008, Tobias Markmann <tmarkmann@googlemail.com> |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
5 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
9 * (at your option) any later version. |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
10 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
15 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
19 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
20 */ |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
21 #include "internal.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
22 #include "cipher.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
23 #include "debug.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
24 #include "imgstore.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
25 #include "prpl.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
26 #include "notify.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
27 #include "request.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
28 #include "util.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
29 #include "xmlnode.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
30 |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
31 #include "buddy.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
32 #include "chat.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
33 #include "jabber.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
34 #include "iq.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
35 #include "presence.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
36 #include "xdata.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
37 #include "pep.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
38 #include "adhoccommands.h" |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
39 #include "connection.h" |
25038
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
40 |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
41 void jabber_bosh_connection_init(PurpleBOSHConnection *conn, PurpleAccount *account, JabberStream *js, char *url) { |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
42 conn->pipelining = TRUE; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
43 conn->account = account; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
44 if (!purple_url_parse(url, &(conn->host), &(conn->port), &(conn->path), &(conn->user), &(conn->passwd))) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
45 purple_debug_info("jabber", "Unable to parse given URL.\n"); |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
46 return; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
47 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
48 if (conn->user || conn->passwd) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
49 purple_debug_info("jabber", "Sorry, HTTP Authentication isn't supported yet. Username and password in the BOSH URL will be ignored.\n"); |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
50 } |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
51 conn->js = js; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
52 conn->rid = rand() % 100000 + 1728679472; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
53 |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
54 conn->conn_a = g_new0(PurpleHTTPConnection, 1); |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
55 jabber_bosh_http_connection_init(conn->conn_a, conn->account, conn->host, conn->port); |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
56 conn->conn_a->userdata = conn; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
57 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
58 |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
59 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
60 char *tmp; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
61 xmlnode *init = xmlnode_new("body"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
62 xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
63 xmlnode_set_attrib(init, "secure", "true"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
64 //xmlnode_set_attrib(init, "route", tmp = g_strdup_printf("xmpp:%s:5222", conn->js->user->domain)); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
65 //g_free(tmp); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
66 xmlnode_set_attrib(init, "to", conn->js->user->domain); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
67 xmlnode_set_attrib(init, "xml:lang", "en"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
68 xmlnode_set_attrib(init, "xmpp:version", "1.0"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
69 xmlnode_set_attrib(init, "ver", "1.6"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
70 xmlnode_set_attrib(init, "xmlns:xmpp", "urn:xmpp:xbosh"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
71 xmlnode_set_attrib(init, "rid", tmp = g_strdup_printf("%d", conn->rid)); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
72 g_free(tmp); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
73 xmlnode_set_attrib(init, "wait", "60"); /* this should be adjusted automatically according to real time network behavior */ |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
74 xmlnode_set_attrib(init, "ack", "0"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
75 xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
76 xmlnode_set_attrib(init, "hold", "1"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
77 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
78 jabber_bosh_connection_send(conn, init); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
79 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
80 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
81 void jabber_bosh_connection_login_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata) { |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
82 purple_debug_info("jabber", "RECEIVED FIRST HTTP RESPONSE\n"); |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
83 printf("\nDATA\n\n%s\n", res->data); |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
84 } |
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
85 |
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
86 void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) { |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
87 PurpleHTTPRequest *request = g_new0(PurpleHTTPRequest, 1); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
88 jabber_bosh_http_request_init(request, "POST", g_strdup_printf("/%s", conn->path), jabber_bosh_connection_login_cb, conn); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
89 jabber_bosh_http_request_add_to_header(request, "Content-Encoding", "text/xml; charset=utf-8"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
90 request->data = xmlnode_to_str(node, &(request->data_len)); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
91 jabber_bosh_http_request_add_to_header(request, "Content-Length", g_strdup_printf("%d", (int)strlen(request->data))); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
92 jabber_bosh_http_connection_send_request(conn->conn_a, request); |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
93 } |
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
94 |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
95 static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
96 PurpleBOSHConnection *bosh_conn = conn->userdata; |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
97 |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
98 if (bosh_conn->ready && bosh_conn->connect_cb) bosh_conn->connect_cb(bosh_conn); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
99 else jabber_bosh_connection_boot(bosh_conn); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
100 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
101 |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
102 void jabber_bosh_connection_connect(PurpleBOSHConnection *conn) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
103 conn->conn_a->connect_cb = jabber_bosh_connection_connected; |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
104 jabber_bosh_http_connection_connect(conn->conn_a); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
105 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
106 |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
107 static void jabber_bosh_http_connection_receive(gpointer data, gint source, PurpleInputCondition condition) { |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
108 char buffer[1024]; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
109 int len; |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
110 PurpleHTTPConnection *conn = data; |
25045
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25044
diff
changeset
|
111 PurpleHTTPResponse *response = conn->current_response; |
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25044
diff
changeset
|
112 |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
113 purple_debug_info("jabber", "jabber_bosh_http_connection_receive\n"); |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
114 if (!response) { |
25045
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25044
diff
changeset
|
115 // new response |
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25044
diff
changeset
|
116 response = conn->current_response = g_new0(PurpleHTTPResponse, 1); |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
117 jabber_bosh_http_response_init(response); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
118 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
119 |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
120 len = read(source, buffer, 1024); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
121 if (len > 0) { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
122 char *found = NULL; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
123 if (found = g_strstr_len(buffer, len, "\r\n\r\n")) { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
124 char *beginning = buffer; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
125 char *field = NULL; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
126 char *value = NULL; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
127 char *cl = NULL; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
128 |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
129 while (*beginning != 'H') ++beginning; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
130 beginning[12] = 0; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
131 response->status = atoi(&beginning[9]); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
132 beginning = &beginning[13]; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
133 do { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
134 ++beginning; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
135 } while (*beginning != '\n'); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
136 ++beginning; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
137 /* parse HTTP response header */ |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
138 for (;beginning != found; ++beginning) { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
139 if (!field) field = beginning; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
140 if (*beginning == ':') { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
141 *beginning = 0; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
142 value = beginning + 1; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
143 } else if (*beginning == '\r') { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
144 *beginning = 0; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
145 g_hash_table_replace(response->header, g_strdup(field), g_strdup(value)); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
146 value = field = 0; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
147 ++beginning; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
148 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
149 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
150 ++found; ++found; ++found; ++found; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
151 |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
152 cl = g_hash_table_lookup(response->header, "Content-Length"); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
153 if (cl) { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
154 PurpleHTTPRequest *request = NULL; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
155 response->data_len = atoi(cl); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
156 if (response->data <= len - (found - buffer)) response->data = g_memdup(found, response->data_len); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
157 else printf("\nDidn't receive complete content"); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
158 |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
159 request = g_queue_pop_head(conn->requests); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
160 if (request) { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
161 request->cb(request, response, conn->userdata); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
162 jabber_bosh_http_request_clean(request); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
163 jabber_bosh_http_response_clean(response); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
164 } else { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
165 purple_debug_info("jabber", "received HTTP response but haven't requested anything yet.\n"); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
166 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
167 } else { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
168 printf("\ndidn't receive length.\n"); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
169 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
170 } else { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
171 printf("\nDid not receive complete HTTP header!\n"); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
172 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
173 } else { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
174 purple_debug_info("jabber", "jabber_bosh_http_connection_receive: problem receiving data\n"); |
25045
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25044
diff
changeset
|
175 } |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
176 } |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
177 |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
178 void jabber_bosh_http_connection_init(PurpleHTTPConnection *conn, PurpleAccount *account, char *host, int port) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
179 conn->account = account; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
180 conn->host = host; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
181 conn->port = port; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
182 conn->connect_cb = NULL; |
25045
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25044
diff
changeset
|
183 conn->current_response = NULL; |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
184 conn->current_data = NULL; |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
185 conn->requests = g_queue_new(); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
186 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
187 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
188 void jabber_bosh_http_connection_clean(PurpleHTTPConnection *conn) { |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
189 g_queue_free(conn->requests); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
190 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
191 |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
192 static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
193 PurpleHTTPConnection *conn = data; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
194 if (source < 0) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
195 purple_debug_info("jabber", "Couldn't connect becasue of: %s\n", error); |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
196 return; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
197 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
198 conn->fd = source; |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
199 conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ, jabber_bosh_http_connection_receive, conn); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
200 if (conn->connect_cb) conn->connect_cb(conn); |
25040 | 201 } |
202 | |
203 void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn) { | |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
204 if((purple_proxy_connect(&(conn->handle), conn->account, conn->host, conn->port, jabber_bosh_http_connection_callback, conn)) == NULL) { |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
205 purple_debug_info("jabber", "Unable to connect to %s.\n", conn->host); |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
206 } |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
207 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
208 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
209 static void jabber_bosh_http_connection_send_request_add_field_to_string(gpointer key, gpointer value, gpointer user_data) { |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
210 char **ppacket = user_data; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
211 char *tmp = *ppacket; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
212 char *field = key; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
213 char *val = value; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
214 *ppacket = g_strdup_printf("%s%s: %s\r\n", tmp, field, val); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
215 g_free(tmp); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
216 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
217 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
218 void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req) { |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
219 char *packet; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
220 char *tmp; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
221 jabber_bosh_http_request_add_to_header(req, "Host", conn->host); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
222 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
223 packet = tmp = g_strdup_printf("%s %s HTTP/1.1\r\n", req->method, req->path); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
224 g_hash_table_foreach(req->header, jabber_bosh_http_connection_send_request_add_field_to_string, &packet); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
225 tmp = packet; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
226 packet = g_strdup_printf("%s\r\n%s", tmp, req->data); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
227 g_free(tmp); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
228 if (write(conn->fd, packet, strlen(packet)) == -1) purple_debug_info("jabber", "send error\n"); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
229 g_queue_push_tail(conn->requests, req); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
230 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
231 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
232 void jabber_bosh_http_request_init(PurpleHTTPRequest *req, const char *method, const char *path, PurpleHTTPRequestCallback cb, void *userdata) { |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
233 req->method = g_strdup(method); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
234 req->path = g_strdup(path); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
235 req->cb = cb; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
236 req->userdata = userdata; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
237 req->header = g_hash_table_new(g_str_hash, g_str_equal); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
238 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
239 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
240 void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value) { |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
241 g_hash_table_replace(req->header, field, value); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
242 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
243 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
244 void jabber_bosh_http_request_set_data(PurpleHTTPRequest *req, char *data, int len) { |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
245 req->data = data; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
246 req->data_len = len; |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
247 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
248 |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
249 void jabber_bosh_http_request_clean(PurpleHTTPRequest *req) { |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
250 g_hash_table_destroy(req->header); |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
251 g_free(req->method); |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
252 g_free(req->path); |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
253 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
254 |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
255 void jabber_bosh_http_response_init(PurpleHTTPResponse *res) { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
256 res->status = 0; |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
257 res->header = g_hash_table_new(g_str_hash, g_str_equal); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
258 } |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
259 |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
260 |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
261 void jabber_bosh_http_response_clean(PurpleHTTPResponse *res) { |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
262 g_hash_table_destroy(res->header); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
263 g_free(res->data); |
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
264 } |