Mon, 18 Aug 2008 15:44:43 +0000
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
* removing some debugging output
|
23607
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
1 | /* |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
2 | * purple - Jabber Protocol Plugin |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
3 | * |
|
bc82598d3798
* 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> |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
5 | * |
|
bc82598d3798
* 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 |
|
bc82598d3798
* 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 |
|
bc82598d3798
* 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 |
|
bc82598d3798
* 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. |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
10 | * |
|
bc82598d3798
* 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, |
|
bc82598d3798
* 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 |
|
bc82598d3798
* 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 |
|
bc82598d3798
* 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. |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
15 | * |
|
bc82598d3798
* 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 |
|
bc82598d3798
* 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 |
|
bc82598d3798
* 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 |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
19 | * |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
20 | */ |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
21 | #include "internal.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
22 | #include "cipher.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
23 | #include "debug.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
24 | #include "imgstore.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
25 | #include "prpl.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
26 | #include "notify.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
27 | #include "request.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
28 | #include "util.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
29 | #include "xmlnode.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
30 | |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
31 | #include "buddy.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
32 | #include "chat.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
33 | #include "jabber.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
34 | #include "iq.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
35 | #include "presence.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
36 | #include "xdata.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
37 | #include "pep.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
38 | #include "adhoccommands.h" |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
39 | #include "connection.h" |
|
23607
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
40 | |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
41 | void jabber_bosh_connection_init(PurpleBOSHConnection *conn, PurpleAccount *account, JabberStream *js, char *url) { |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
42 | conn->pipelining = TRUE; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
43 | conn->account = account; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
44 | if (!purple_url_parse(url, &(conn->host), &(conn->port), &(conn->path), &(conn->user), &(conn->passwd))) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
45 | purple_debug_info("jabber", "Unable to parse given URL.\n"); |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
46 | return; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
47 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
48 | if (conn->user || conn->passwd) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
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"); |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
50 | } |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
51 | conn->js = js; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
52 | conn->rid = rand() % 100000 + 1728679472; |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
53 | conn->ready = FALSE; |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
54 | conn->conn_a = g_new0(PurpleHTTPConnection, 1); |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
55 | jabber_bosh_http_connection_init(conn->conn_a, conn->account, conn->host, conn->port); |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
56 | conn->conn_a->userdata = conn; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
57 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
58 | |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
59 | void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
60 | /* |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
61 | <body rid='1573741824' |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
62 | sid='SomeSID' |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
63 | to='jabber.org' |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
64 | xml:lang='en' |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
65 | xmpp:restart='true' |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
66 | xmlns='http://jabber.org/protocol/httpbind' |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
67 | xmlns:xmpp='urn:xmpp:xbosh'/> |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
68 | */ |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
69 | xmlnode *restart = xmlnode_new("body"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
70 | char *tmp = NULL; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
71 | conn->rid++; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
72 | xmlnode_set_attrib(restart, "rid", tmp = g_strdup_printf("%d", conn->rid)); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
73 | g_free(tmp); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
74 | xmlnode_set_attrib(restart, "sid", conn->sid); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
75 | xmlnode_set_attrib(restart, "to", conn->js->user->domain); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
76 | xmlnode_set_attrib(restart, "xml:lang", "en"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
77 | xmlnode_set_attrib(restart, "xmpp:restart", "true"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
78 | xmlnode_set_attrib(restart, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
79 | xmlnode_set_attrib(restart, "xmlns:xmpp", "urn:xmpp:xbosh"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
80 | |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
81 | jabber_bosh_connection_send_native(conn, restart); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
82 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
83 | |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
84 | gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node) { |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
85 | char *type; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
86 | |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
87 | if (!node) return; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
88 | type = xmlnode_get_attrib(node, "type"); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
89 | |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
90 | if (type != NULL && !strcmp(type, "terminate")) { |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
91 | conn->ready = FALSE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
92 | return TRUE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
93 | } |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
94 | return FALSE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
95 | } |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
96 | |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
97 | void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
98 | xmlnode *child; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
99 | JabberStream *js = conn->js; |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
100 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
101 | if (node == NULL) return; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
102 | |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
103 | if (jabber_bosh_connection_error_check(conn, node) == TRUE) return; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
104 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
105 | child = node->child; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
106 | while (child != 0) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
107 | if (child->type == XMLNODE_TYPE_TAG) { |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
108 | xmlnode *session = NULL; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
109 | if (!strcmp(child->name, "iq")) session = xmlnode_get_child(child, "session"); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
110 | if (session) { |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
111 | conn->ready = TRUE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
112 | } |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
113 | jabber_process_packet(js, &child); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
114 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
115 | child = child->next; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
116 | } |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
117 | xmlnode_free(node); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
118 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
119 | |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
120 | void jabber_bosh_connection_auth_response(PurpleBOSHConnection *conn, xmlnode *node) { |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
121 | xmlnode *child = node->child; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
122 | |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
123 | if (jabber_bosh_connection_error_check(conn, node) == TRUE) return; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
124 | |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
125 | while(child != NULL && child->type != XMLNODE_TYPE_TAG) { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
126 | child = child->next; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
127 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
128 | |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
129 | if (child != NULL && child->type == XMLNODE_TYPE_TAG) { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
130 | JabberStream *js = conn->js; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
131 | if (!strcmp(child->name, "success")) { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
132 | jabber_bosh_connection_stream_restart(conn); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
133 | jabber_process_packet(js, &child); |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
134 | conn->receive_cb = jabber_bosh_connection_received; |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
135 | } else { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
136 | js->state = JABBER_STREAM_AUTHENTICATING; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
137 | jabber_process_packet(js, &child); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
138 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
139 | } else printf("\n!! no child!!\n"); |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
140 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
141 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
142 | void jabber_bosh_connection_boot_response(PurpleBOSHConnection *conn, xmlnode *node) { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
143 | char *version; |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
144 | |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
145 | if (jabber_bosh_connection_error_check(conn, node) == TRUE) return; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
146 | |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
147 | if (xmlnode_get_attrib(node, "sid")) { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
148 | conn->sid = g_strdup(xmlnode_get_attrib(node, "sid")); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
149 | } else { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
150 | purple_debug_info("jabber", "Connection manager doesn't behave BOSH-like!\n"); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
151 | } |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
152 | |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
153 | if (version = xmlnode_get_attrib(node, "ver")) { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
154 | version[1] = 0; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
155 | if (!(atoi(version) >= 1 && atoi(&version[2]) >= 6)) purple_debug_info("jabber", "Unsupported version of BOSH protocol. The connection manager must at least support version 1.6!\n"); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
156 | else { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
157 | xmlnode *packet = xmlnode_get_child(node, "features"); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
158 | conn->js->use_bosh = TRUE; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
159 | conn->receive_cb = jabber_bosh_connection_auth_response; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
160 | jabber_stream_features_parse(conn->js, packet); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
161 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
162 | version[1] = '.'; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
163 | } else { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
164 | purple_debug_info("jabber", "Missing version in session creation response!\n"); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
165 | } |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
166 | } |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
167 | |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
168 | static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
169 | char *tmp; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
170 | xmlnode *init = xmlnode_new("body"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
171 | xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
172 | xmlnode_set_attrib(init, "secure", "true"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
173 | //xmlnode_set_attrib(init, "route", tmp = g_strdup_printf("xmpp:%s:5222", conn->js->user->domain)); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
174 | //g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
175 | xmlnode_set_attrib(init, "to", conn->js->user->domain); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
176 | xmlnode_set_attrib(init, "xml:lang", "en"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
177 | xmlnode_set_attrib(init, "xmpp:version", "1.0"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
178 | xmlnode_set_attrib(init, "ver", "1.6"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
179 | xmlnode_set_attrib(init, "xmlns:xmpp", "urn:xmpp:xbosh"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
180 | xmlnode_set_attrib(init, "rid", tmp = g_strdup_printf("%d", conn->rid)); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
181 | g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
182 | xmlnode_set_attrib(init, "wait", "60"); /* this should be adjusted automatically according to real time network behavior */ |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
183 | xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
184 | xmlnode_set_attrib(init, "hold", "1"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
185 | |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
186 | conn->receive_cb = jabber_bosh_connection_boot_response; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
187 | jabber_bosh_connection_send_native(conn, init); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
188 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
189 | |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
190 | void jabber_bosh_connection_http_received_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata) { |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
191 | PurpleBOSHConnection *conn = userdata; |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
192 | if (conn->receive_cb) { |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
193 | xmlnode *node = xmlnode_from_str(res->data, res->data_len); |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
194 | if (node) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
195 | char *txt = xmlnode_to_formatted_str(node, NULL); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
196 | printf("\njabber_bosh_connection_http_received_cb\n%s\n", txt); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
197 | g_free(txt); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
198 | conn->receive_cb(conn, node); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
199 | } else { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
200 | printf("\njabber_bosh_connection_http_received_cb: XML ERROR: %s\n", res->data); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
201 | } |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
202 | } else purple_debug_info("jabber", "missing receive_cb of PurpleBOSHConnection.\n"); |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
203 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
204 | |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
205 | void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) { |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
206 | xmlnode *packet = xmlnode_new("body"); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
207 | char *tmp; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
208 | conn->rid++; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
209 | xmlnode_set_attrib(packet, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
210 | xmlnode_set_attrib(packet, "sid", conn->sid); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
211 | tmp = g_strdup_printf("%d", conn->rid); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
212 | xmlnode_set_attrib(packet, "rid", tmp); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
213 | g_free(tmp); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
214 | |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
215 | if (node) { |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
216 | xmlnode_insert_child(packet, node); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
217 | if (conn->ready == TRUE) xmlnode_set_attrib(node, "xmlns", "jabber:client"); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
218 | } |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
219 | jabber_bosh_connection_send_native(conn, packet); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
220 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
221 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
222 | void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, xmlnode *node) { |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
223 | PurpleHTTPRequest *request = g_new0(PurpleHTTPRequest, 1); |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
224 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
225 | char *txt = xmlnode_to_formatted_str(node, NULL); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
226 | printf("\njabber_bosh_connection_send\n%s\n", txt); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
227 | g_free(txt); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
228 | |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
229 | jabber_bosh_http_request_init(request, "POST", g_strdup_printf("/%s", conn->path), jabber_bosh_connection_http_received_cb, conn); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
230 | jabber_bosh_http_request_add_to_header(request, "Content-Encoding", "text/xml; charset=utf-8"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
231 | request->data = xmlnode_to_str(node, &(request->data_len)); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
232 | jabber_bosh_http_request_add_to_header(request, "Content-Length", g_strdup_printf("%d", (int)strlen(request->data))); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
233 | jabber_bosh_http_connection_send_request(conn->conn_a, request); |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
234 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
235 | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
236 | static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
237 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
238 | if (bosh_conn->ready == TRUE && bosh_conn->connect_cb) { |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
239 | purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n"); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
240 | bosh_conn->receive_cb = jabber_bosh_connection_received; |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
241 | bosh_conn->connect_cb(bosh_conn); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
242 | } else jabber_bosh_connection_boot(bosh_conn); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
243 | } |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
244 | |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
245 | static void jabber_bosh_connection_refresh(PurpleHTTPConnection *conn) { |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
246 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
247 | jabber_bosh_connection_send(bosh_conn, NULL); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
248 | } |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
249 | |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
250 | static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn) { |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
251 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
252 | bosh_conn->conn_a->connect_cb = jabber_bosh_connection_connected; |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
253 | jabber_bosh_http_connection_connect(bosh_conn->conn_a); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
254 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
255 | |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
256 | void jabber_bosh_connection_connect(PurpleBOSHConnection *conn) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
257 | conn->conn_a->connect_cb = jabber_bosh_connection_connected; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
258 | jabber_bosh_http_connection_connect(conn->conn_a); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
259 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
260 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
261 | void jabber_bosh_http_connection_receive_parse_header(PurpleHTTPResponse *response, char **data, int *len) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
262 | GHashTable *header = response->header; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
263 | char *beginning = *data; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
264 | char *found = g_strstr_len(*data, len, "\r\n\r\n"); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
265 | char *field = NULL; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
266 | char *value = NULL; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
267 | char *old_data = *data; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
268 | |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
269 | while (*beginning != 'H') ++beginning; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
270 | beginning[12] = 0; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
271 | response->status = atoi(&beginning[9]); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
272 | beginning = &beginning[13]; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
273 | do { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
274 | ++beginning; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
275 | } while (*beginning != '\n'); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
276 | ++beginning; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
277 | /* parse HTTP response header */ |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
278 | for (;beginning != found; ++beginning) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
279 | if (!field) field = beginning; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
280 | if (*beginning == ':') { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
281 | *beginning = 0; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
282 | value = beginning + 1; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
283 | } else if (*beginning == '\r') { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
284 | *beginning = 0; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
285 | g_hash_table_replace(header, g_strdup(field), g_strdup(value)); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
286 | value = field = 0; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
287 | ++beginning; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
288 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
289 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
290 | ++beginning; ++beginning; ++beginning; ++beginning; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
291 | /* remove the header from data buffer */ |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
292 | *data = g_strdup(beginning); |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
293 | *len = *len - (beginning - old_data); |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
294 | g_free(old_data); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
295 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
296 | |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
297 | static void jabber_bosh_http_connection_receive(gpointer data, gint source, PurpleInputCondition condition) { |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
298 | char buffer[1025]; |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
299 | int len; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
300 | PurpleHTTPConnection *conn = data; |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
301 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
302 | PurpleHTTPResponse *response = conn->current_response; |
|
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
303 | |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
304 | purple_debug_info("jabber", "jabber_bosh_http_connection_receive\n"); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
305 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
306 | len = read(source, buffer, 1024); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
307 | if (len > 0) { |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
308 | buffer[len] = 0; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
309 | if (conn->current_data == NULL) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
310 | conn->current_len = len; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
311 | conn->current_data = g_strdup_printf("%s", buffer); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
312 | } else { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
313 | char *old_data = conn->current_data; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
314 | conn->current_len += len; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
315 | conn->current_data = g_strdup_printf("%s%s", conn->current_data, buffer); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
316 | g_free(old_data); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
317 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
318 | |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
319 | if (!response) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
320 | /* check for header footer */ |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
321 | char *found = NULL; |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
322 | if (found = g_strstr_len(conn->current_data, conn->current_len, "\r\n\r\n")) { |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
323 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
324 | // new response |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
325 | response = conn->current_response = g_new0(PurpleHTTPResponse, 1); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
326 | jabber_bosh_http_response_init(response); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
327 | jabber_bosh_http_connection_receive_parse_header(response, &(conn->current_data), &(conn->current_len)); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
328 | response->data_len = atoi(g_hash_table_lookup(response->header, "Content-Length")); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
329 | } else { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
330 | printf("\nDid not receive HTTP header\n"); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
331 | } |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
332 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
333 | |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
334 | if (response) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
335 | if (conn->current_len >= response->data_len) { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
336 | PurpleHTTPRequest *request = g_queue_pop_head(conn->requests); |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
337 | |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
338 | #warning for a pure HTTP 1.1 stack this would be needed to be handled elsewhereå |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
339 | if (bosh_conn->ready == TRUE && g_queue_is_empty(conn->requests) == TRUE) { |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
340 | jabber_bosh_connection_send(bosh_conn, NULL); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
341 | printf("\n SEND AN EMPTY REQUEST \n"); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
342 | } |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
343 | |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
344 | if (request) { |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
345 | char *old_data = conn->current_data; |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
346 | response->data = g_memdup(conn->current_data, response->data_len); |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
347 | conn->current_data = g_strdup(&conn->current_data[response->data_len]); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
348 | conn->current_len -= response->data_len; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
349 | g_free(old_data); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
350 | |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
351 | if (request->cb) request->cb(request, response, conn->userdata); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
352 | else purple_debug_info("jabber", "missing request callback!\n"); |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
353 | |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
354 | jabber_bosh_http_request_clean(request); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
355 | jabber_bosh_http_response_clean(response); |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
356 | conn->current_response = NULL; |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
357 | g_free(request); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
358 | g_free(response); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
359 | } else { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
360 | purple_debug_info("jabber", "received HTTP response but haven't requested anything yet.\n"); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
361 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
362 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
363 | } |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
364 | } else if (len == 0) { |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
365 | purple_input_remove(conn->ie_handle); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
366 | if (conn->disconnect_cb) conn->disconnect_cb(conn); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
367 | } else { |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
368 | purple_debug_info("jabber", "jabber_bosh_http_connection_receive: problem receiving data (%d)\n", len); |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
369 | } |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
370 | } |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
371 | |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
372 | void jabber_bosh_http_connection_init(PurpleHTTPConnection *conn, PurpleAccount *account, char *host, int port) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
373 | conn->account = account; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
374 | conn->host = host; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
375 | conn->port = port; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
376 | conn->connect_cb = NULL; |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
377 | conn->current_response = NULL; |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
378 | conn->current_data = NULL; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
379 | conn->requests = g_queue_new(); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
380 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
381 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
382 | void jabber_bosh_http_connection_clean(PurpleHTTPConnection *conn) { |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
383 | g_queue_free(conn->requests); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
384 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
385 | |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
386 | static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
387 | PurpleHTTPConnection *conn = data; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
388 | if (source < 0) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
389 | purple_debug_info("jabber", "Couldn't connect becasue of: %s\n", error); |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
390 | return; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
391 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
392 | conn->fd = source; |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
393 | if (conn->connect_cb) conn->connect_cb(conn); |
|
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
394 | else purple_debug_info("jabber", "No connect callback for HTTP connection.\n"); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
395 | conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ, jabber_bosh_http_connection_receive, conn); |
| 23609 | 396 | } |
| 397 | ||
| 398 | void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn) { | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
399 | if((purple_proxy_connect(&(conn->handle), conn->account, conn->host, conn->port, jabber_bosh_http_connection_callback, conn)) == NULL) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
400 | purple_debug_info("jabber", "Unable to connect to %s.\n", conn->host); |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
401 | } |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
402 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
403 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
404 | static void jabber_bosh_http_connection_send_request_add_field_to_string(gpointer key, gpointer value, gpointer user_data) { |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
405 | char **ppacket = user_data; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
406 | char *tmp = *ppacket; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
407 | char *field = key; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
408 | char *val = value; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
409 | *ppacket = g_strdup_printf("%s%s: %s\r\n", tmp, field, val); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
410 | g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
411 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
412 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
413 | void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req) { |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
414 | char *packet; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
415 | char *tmp; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
416 | jabber_bosh_http_request_add_to_header(req, "Host", conn->host); |
|
23617
0535645c461a
* sending some User-Agent
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23616
diff
changeset
|
417 | jabber_bosh_http_request_add_to_header(req, "User-Agent", "libpurple"); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
418 | packet = tmp = g_strdup_printf("%s %s HTTP/1.1\r\n", req->method, req->path); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
419 | g_hash_table_foreach(req->header, jabber_bosh_http_connection_send_request_add_field_to_string, &packet); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
420 | tmp = packet; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
421 | packet = g_strdup_printf("%s\r\n%s", tmp, req->data); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
422 | g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
423 | if (write(conn->fd, packet, strlen(packet)) == -1) purple_debug_info("jabber", "send error\n"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
424 | g_queue_push_tail(conn->requests, req); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
425 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
426 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
427 | void jabber_bosh_http_request_init(PurpleHTTPRequest *req, const char *method, const char *path, PurpleHTTPRequestCallback cb, void *userdata) { |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
428 | req->method = g_strdup(method); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
429 | req->path = g_strdup(path); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
430 | req->cb = cb; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
431 | req->userdata = userdata; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
432 | req->header = g_hash_table_new(g_str_hash, g_str_equal); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
433 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
434 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
435 | void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value) { |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
436 | g_hash_table_replace(req->header, field, value); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
437 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
438 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
439 | void jabber_bosh_http_request_set_data(PurpleHTTPRequest *req, char *data, int len) { |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
440 | req->data = data; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
441 | req->data_len = len; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
442 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
443 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
444 | void jabber_bosh_http_request_clean(PurpleHTTPRequest *req) { |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
445 | g_hash_table_destroy(req->header); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
446 | g_free(req->method); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
447 | g_free(req->path); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
448 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
449 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
450 | void jabber_bosh_http_response_init(PurpleHTTPResponse *res) { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
451 | res->status = 0; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
452 | res->header = g_hash_table_new(g_str_hash, g_str_equal); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
453 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
454 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
455 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
456 | void jabber_bosh_http_response_clean(PurpleHTTPResponse *res) { |
|
23621
d7a6cc7ca517
* sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23620
diff
changeset
|
457 | //g_hash_table_destroy(res->header); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
458 | g_free(res->data); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
459 | } |