Fri, 15 Aug 2008 16:35:32 +0000
* moving BOSH interfacing from jabber_send to jabber_send_raw
* sending BOSH stream restart after successful SASL login
|
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; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
53 | |
|
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 | |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
84 | void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
85 | |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
86 | xmlnode_free(node); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
87 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
88 | |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
89 | 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
|
90 | 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
|
91 | |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
92 | 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
|
93 | child = child->next; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
94 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
95 | |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
96 | 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
|
97 | 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
|
98 | 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
|
99 | 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
|
100 | 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
|
101 | } else { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
102 | 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
|
103 | conn->receive_cb = jabber_bosh_connection_received; |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
104 | 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
|
105 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
106 | } 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
|
107 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
108 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
109 | 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
|
110 | char *version; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
111 | 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
|
112 | 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
|
113 | } else { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
114 | 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
|
115 | } |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
116 | |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
117 | 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
|
118 | version[1] = 0; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
119 | 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
|
120 | else { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
121 | 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
|
122 | 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
|
123 | 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
|
124 | 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
|
125 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
126 | version[1] = '.'; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
127 | } else { |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
128 | 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
|
129 | } |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
130 | } |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
131 | |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
132 | static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
133 | char *tmp; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
134 | xmlnode *init = xmlnode_new("body"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
135 | xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
136 | xmlnode_set_attrib(init, "secure", "true"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
137 | //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
|
138 | //g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
139 | xmlnode_set_attrib(init, "to", conn->js->user->domain); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
140 | xmlnode_set_attrib(init, "xml:lang", "en"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
141 | xmlnode_set_attrib(init, "xmpp:version", "1.0"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
142 | xmlnode_set_attrib(init, "ver", "1.6"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
143 | xmlnode_set_attrib(init, "xmlns:xmpp", "urn:xmpp:xbosh"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
144 | 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
|
145 | g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
146 | 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
|
147 | xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
148 | xmlnode_set_attrib(init, "hold", "1"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
149 | |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
150 | 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
|
151 | jabber_bosh_connection_send_native(conn, init); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
152 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
153 | |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
154 | 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
|
155 | PurpleBOSHConnection *conn = userdata; |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
156 | if (conn->receive_cb) { |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
157 | xmlnode *node = xmlnode_from_str(res->data, res->data_len); |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
158 | char *txt = xmlnode_to_formatted_str(node, NULL); |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
159 | printf("\njabber_bosh_connection_http_received_cb\n%s\n", txt); |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
160 | g_free(txt); |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
161 | conn->receive_cb(conn, node); |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
162 | } 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
|
163 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
164 | |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
165 | 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
|
166 | 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
|
167 | char *tmp; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
168 | conn->rid++; |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
169 | 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
|
170 | 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
|
171 | 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
|
172 | 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
|
173 | g_free(tmp); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
174 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
175 | xmlnode_insert_child(packet, node); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
176 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
177 | 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
|
178 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
179 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
180 | 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
|
181 | 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
|
182 | |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
183 | 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
|
184 | 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
|
185 | g_free(txt); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
186 | |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
187 | 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
|
188 | 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
|
189 | request->data = xmlnode_to_str(node, &(request->data_len)); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
190 | 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
|
191 | 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
|
192 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
193 | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
194 | 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
|
195 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
196 | bosh_conn->receive_cb = jabber_bosh_connection_received; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
197 | if (bosh_conn->ready && bosh_conn->connect_cb) bosh_conn->connect_cb(bosh_conn); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
198 | else jabber_bosh_connection_boot(bosh_conn); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
199 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
200 | |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
201 | 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
|
202 | conn->conn_a->connect_cb = jabber_bosh_connection_connected; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
203 | 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
|
204 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
205 | |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
206 | static void jabber_bosh_http_connection_receive(gpointer data, gint source, PurpleInputCondition condition) { |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
207 | char buffer[1024]; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
208 | int len; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
209 | PurpleHTTPConnection *conn = data; |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
210 | PurpleHTTPResponse *response = conn->current_response; |
|
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
211 | |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
212 | 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
|
213 | if (!response) { |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
214 | // new response |
|
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
215 | response = conn->current_response = g_new0(PurpleHTTPResponse, 1); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
216 | jabber_bosh_http_response_init(response); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
217 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
218 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
219 | len = read(source, buffer, 1024); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
220 | if (len > 0) { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
221 | char *found = NULL; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
222 | if (found = g_strstr_len(buffer, len, "\r\n\r\n")) { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
223 | char *beginning = buffer; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
224 | char *field = NULL; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
225 | char *value = NULL; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
226 | char *cl = NULL; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
227 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
228 | while (*beginning != 'H') ++beginning; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
229 | beginning[12] = 0; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
230 | response->status = atoi(&beginning[9]); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
231 | beginning = &beginning[13]; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
232 | do { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
233 | ++beginning; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
234 | } while (*beginning != '\n'); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
235 | ++beginning; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
236 | /* parse HTTP response header */ |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
237 | for (;beginning != found; ++beginning) { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
238 | if (!field) field = beginning; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
239 | if (*beginning == ':') { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
240 | *beginning = 0; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
241 | value = beginning + 1; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
242 | } else if (*beginning == '\r') { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
243 | *beginning = 0; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
244 | g_hash_table_replace(response->header, g_strdup(field), g_strdup(value)); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
245 | value = field = 0; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
246 | ++beginning; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
247 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
248 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
249 | ++found; ++found; ++found; ++found; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
250 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
251 | cl = g_hash_table_lookup(response->header, "Content-Length"); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
252 | if (cl) { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
253 | PurpleHTTPRequest *request = NULL; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
254 | response->data_len = atoi(cl); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
255 | if (response->data <= len - (found - buffer)) response->data = g_memdup(found, response->data_len); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
256 | else printf("\nDidn't receive complete content"); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
257 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
258 | request = g_queue_pop_head(conn->requests); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
259 | if (request) { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
260 | request->cb(request, response, conn->userdata); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
261 | 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
|
262 | 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
|
263 | conn->current_response = NULL; |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
264 | } else { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
265 | 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
|
266 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
267 | } else { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
268 | printf("\ndidn't receive length.\n"); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
269 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
270 | } else { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
271 | printf("\nDid not receive complete HTTP header!\n"); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
272 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
273 | } else { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
274 | purple_debug_info("jabber", "jabber_bosh_http_connection_receive: problem receiving data\n"); |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
275 | } |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
276 | } |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
277 | |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
278 | 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
|
279 | conn->account = account; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
280 | conn->host = host; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
281 | conn->port = port; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
282 | conn->connect_cb = NULL; |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
283 | conn->current_response = NULL; |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
284 | conn->current_data = NULL; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
285 | conn->requests = g_queue_new(); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
286 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
287 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
288 | void jabber_bosh_http_connection_clean(PurpleHTTPConnection *conn) { |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
289 | g_queue_free(conn->requests); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
290 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
291 | |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
292 | 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
|
293 | PurpleHTTPConnection *conn = data; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
294 | if (source < 0) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
295 | 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
|
296 | return; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
297 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
298 | conn->fd = source; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
299 | conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ, jabber_bosh_http_connection_receive, conn); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
300 | if (conn->connect_cb) conn->connect_cb(conn); |
| 23609 | 301 | } |
| 302 | ||
| 303 | 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
|
304 | 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
|
305 | 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
|
306 | } |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
307 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
308 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
309 | 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
|
310 | char **ppacket = user_data; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
311 | char *tmp = *ppacket; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
312 | char *field = key; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
313 | char *val = value; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
314 | *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
|
315 | g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
316 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
317 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
318 | 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
|
319 | char *packet; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
320 | char *tmp; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
321 | 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
|
322 | 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
|
323 | 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
|
324 | 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
|
325 | tmp = packet; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
326 | 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
|
327 | g_free(tmp); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
328 | 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
|
329 | g_queue_push_tail(conn->requests, req); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
330 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
331 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
332 | 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
|
333 | req->method = g_strdup(method); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
334 | req->path = g_strdup(path); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
335 | req->cb = cb; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
336 | req->userdata = userdata; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
337 | 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
|
338 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
339 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
340 | 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
|
341 | g_hash_table_replace(req->header, field, value); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
342 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
343 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
344 | 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
|
345 | req->data = data; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
346 | req->data_len = len; |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
347 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
348 | |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
349 | 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
|
350 | g_hash_table_destroy(req->header); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
351 | g_free(req->method); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
352 | g_free(req->path); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
353 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
354 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
355 | 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
|
356 | res->status = 0; |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
357 | 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
|
358 | } |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
359 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
360 | |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
361 | void jabber_bosh_http_response_clean(PurpleHTTPResponse *res) { |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
362 | g_hash_table_destroy(res->header); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
363 | g_free(res->data); |
|
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
364 | } |