Mercurial > pidgin
annotate libpurple/protocols/jabber/bosh.c @ 25988:f36a94f19db3
Restore BOSH to a more-or-less working state.
Major changes:
* Obey the 'requests' attribute on session creation response. Extra requests
are buffered until we can send something.
* Attempt to gracefully fail from a proxy that doesn't allow pipelining to
multiple TCP connections.
Still to do:
* SSL the Pidgin<>Connection Manager connection
* Pay attention to 'inactivity' and 'polling'
* The HTTP handler won't work if a read() on a pipelined connection returns
data from one response as well as the beginning of a second response.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 15 Mar 2009 04:48:47 +0000 |
parents | c11c14dde641 |
children | 71835e00c0fc |
rev | line source |
---|---|
25038
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
1 /* |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
2 * purple - Jabber Protocol Plugin |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
3 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
4 * Copyright (C) 2008, Tobias Markmann <tmarkmann@googlemail.com> |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
5 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
9 * (at your option) any later version. |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
10 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
15 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
19 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
20 */ |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
21 #include "internal.h" |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
22 #include "core.h" |
25038
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
23 #include "cipher.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
24 #include "debug.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
25 #include "prpl.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
26 #include "util.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
27 #include "xmlnode.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
28 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
29 #include "bosh.h" |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
30 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
31 #define MAX_HTTP_CONNECTIONS 2 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
32 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
33 typedef struct _PurpleHTTPConnection PurpleHTTPConnection; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
34 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
35 typedef void (*PurpleHTTPConnectionConnectFunction)(PurpleHTTPConnection *conn); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
36 typedef void (*PurpleHTTPConnectionDisconnectFunction)(PurpleHTTPConnection *conn); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
37 typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
38 typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
39 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
40 static char *bosh_useragent = NULL; |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
41 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
42 typedef enum { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
43 PACKET_TERMINATE, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
44 PACKET_STREAM_RESTART, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
45 PACKET_NORMAL, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
46 } PurpleBOSHPacketType; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
47 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
48 struct _PurpleBOSHConnection { |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
49 /* decoded URL */ |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
50 char *host; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
51 int port; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
52 char *path; |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
53 |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
54 /* Must be big enough to hold 2^53 - 1 */ |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
55 guint64 rid; |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
56 char *sid; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
57 int wait; |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
58 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
59 JabberStream *js; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
60 gboolean pipelining; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
61 PurpleHTTPConnection *connections[MAX_HTTP_CONNECTIONS]; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
62 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
63 int max_inactivity; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
64 int max_requests; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
65 int requests; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
66 GString *pending; |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
67 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
68 gboolean ready; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
69 PurpleBOSHConnectionConnectFunction connect_cb; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
70 PurpleBOSHConnectionReceiveFunction receive_cb; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
71 }; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
72 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
73 struct _PurpleHTTPConnection { |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
74 int fd; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
75 gboolean ready; |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
76 char *host; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
77 int port; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
78 int ie_handle; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
79 int requests; /* number of outstanding HTTP requests */ |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
80 |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
81 GString *buf; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
82 gboolean headers_done; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
83 gsize handled_len; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
84 gsize body_len; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
85 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
86 int pih; /* what? */ |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
87 PurpleHTTPConnectionConnectFunction connect_cb; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
88 PurpleHTTPConnectionConnectFunction disconnect_cb; |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
89 PurpleBOSHConnection *bosh; |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
90 }; |
25038
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
91 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
92 static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
93 static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
94 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node); |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
95 static void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, PurpleBOSHPacketType, xmlnode *node); |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
96 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
97 static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn); |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
98 static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
99 static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
100 static void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, const GString *req); |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
101 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
102 void jabber_bosh_init(void) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
103 { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
104 GHashTable *ui_info = purple_core_get_ui_info(); |
25668
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
105 const char *ui_name = NULL; |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
106 const char *ui_version = NULL; |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
107 |
25668
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
108 if (ui_info) { |
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
109 ui_name = g_hash_table_lookup(ui_info, "name"); |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
110 ui_version = g_hash_table_lookup(ui_info, "version"); |
25668
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
111 } |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
112 |
25668
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
113 if (ui_name) |
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
114 bosh_useragent = g_strdup_printf("%s%s%s (libpurple " VERSION ")", |
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
115 ui_name, ui_version ? " " : "", |
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25667
diff
changeset
|
116 ui_version ? ui_version : ""); |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
117 else |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
118 bosh_useragent = g_strdup("libpurple " VERSION); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
119 } |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
120 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
121 void jabber_bosh_uninit(void) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
122 { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
123 g_free(bosh_useragent); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
124 bosh_useragent = NULL; |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
125 } |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
126 |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
127 static PurpleHTTPConnection* |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
128 jabber_bosh_http_connection_init(PurpleBOSHConnection *bosh) |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
129 { |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
130 PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1); |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
131 conn->bosh = bosh; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
132 conn->host = g_strdup(bosh->host); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
133 conn->port = bosh->port; |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
134 conn->fd = -1; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
135 conn->ready = FALSE; |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
136 |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
137 return conn; |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
138 } |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
139 |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
140 static void |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
141 jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn) |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
142 { |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
143 g_free(conn->host); |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
144 |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
145 if (conn->buf) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
146 g_string_free(conn->buf, TRUE); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
147 |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
148 if (conn->ie_handle) |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
149 purple_input_remove(conn->ie_handle); |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
150 if (conn->fd >= 0) |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
151 close(conn->fd); |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
152 |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
153 g_free(conn); |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
154 } |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
155 |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
156 PurpleBOSHConnection* |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
157 jabber_bosh_connection_init(JabberStream *js, const char *url) |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
158 { |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
159 PurpleBOSHConnection *conn; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
160 char *host, *path, *user, *passwd; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
161 int port; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
162 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
163 if (!purple_url_parse(url, &host, &port, &path, &user, &passwd)) { |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
164 purple_debug_info("jabber", "Unable to parse given URL.\n"); |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
165 return NULL; |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
166 } |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
167 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
168 conn = g_new0(PurpleBOSHConnection, 1); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
169 conn->host = host; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
170 conn->port = port; |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
171 conn->path = g_strdup_printf("/%s", path); |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
172 g_free(path); |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
173 conn->pipelining = TRUE; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
174 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
175 if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
176 purple_debug_info("jabber", "Ignoring unexpected username and password " |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
177 "in BOSH URL.\n"); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
178 } |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
179 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
180 g_free(user); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
181 g_free(passwd); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
182 |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
183 conn->js = js; |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
184 /* FIXME: This doesn't seem very random */ |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
185 conn->rid = rand() % 100000 + 1728679472; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
186 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
187 conn->pending = g_string_new(""); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
188 |
25052
0a8484372312
* 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:
25051
diff
changeset
|
189 conn->ready = FALSE; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
190 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
191 conn->connections[0] = jabber_bosh_http_connection_init(conn); |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
192 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
193 return conn; |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
194 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
195 |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
196 void |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
197 jabber_bosh_connection_destroy(PurpleBOSHConnection *conn) |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
198 { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
199 int i; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
200 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
201 g_free(conn->host); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
202 g_free(conn->path); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
203 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
204 if (conn->pending) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
205 g_string_free(conn->pending, TRUE); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
206 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
207 for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
208 if (conn->connections[i]) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
209 jabber_bosh_http_connection_destroy(conn->connections[i]); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
210 } |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
211 |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
212 g_free(conn); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
213 } |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
214 |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
215 void jabber_bosh_connection_close(PurpleBOSHConnection *conn) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
216 { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
217 jabber_bosh_connection_send_native(conn, PACKET_TERMINATE, NULL); |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
218 } |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
219 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
220 static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
221 jabber_bosh_connection_send_native(conn, PACKET_STREAM_RESTART, NULL); |
25050
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
222 } |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
223 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
224 static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node) { |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
225 const char *type; |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
226 |
25054
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
227 type = xmlnode_get_attrib(node, "type"); |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
228 |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
229 if (type != NULL && !strcmp(type, "terminate")) { |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
230 conn->ready = FALSE; |
25055
480736bfcf45
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25054
diff
changeset
|
231 purple_connection_error_reason (conn->js->gc, |
480736bfcf45
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25054
diff
changeset
|
232 PURPLE_CONNECTION_ERROR_OTHER_ERROR, |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
233 _("The BOSH connection manager terminated your session.")); |
25054
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
234 return TRUE; |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
235 } |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
236 return FALSE; |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
237 } |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
238 |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
239 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
240 xmlnode *child; |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
241 JabberStream *js = conn->js; |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
242 |
25666
7856dccb02fb
BOSH: Another g_return_if_fail that is backward
Paul Aurich <paul@darkrain42.org>
parents:
25665
diff
changeset
|
243 g_return_if_fail(node != NULL); |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
244 if (jabber_bosh_connection_error_check(conn, node)) |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
245 return; |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
246 |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
247 child = node->child; |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
248 while (child != NULL) { |
25195
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
249 /* jabber_process_packet might free child */ |
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
250 xmlnode *next = child->next; |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
251 if (child->type == XMLNODE_TYPE_TAG) { |
25195
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
252 if (!strcmp(child->name, "iq")) { |
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
253 if (xmlnode_get_child(child, "session")) |
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
254 conn->ready = TRUE; |
25054
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25052
diff
changeset
|
255 } |
25195
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
256 |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
257 jabber_process_packet(js, &child); |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
258 } |
25195
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
259 |
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
260 child = next; |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
261 } |
25050
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
262 } |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
263 |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
264 static void auth_response_cb(PurpleBOSHConnection *conn, xmlnode *node) { |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
265 xmlnode *child; |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
266 |
25195
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25194
diff
changeset
|
267 g_return_if_fail(node != NULL); |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
268 if (jabber_bosh_connection_error_check(conn, node)) |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
269 return; |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
270 |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
271 child = node->child; |
25050
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
272 while(child != NULL && child->type != XMLNODE_TYPE_TAG) { |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
273 child = child->next; |
25050
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
274 } |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
275 |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
276 /* We're only expecting one XML node here, so only process the first one */ |
25050
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
277 if (child != NULL && child->type == XMLNODE_TYPE_TAG) { |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
278 JabberStream *js = conn->js; |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
279 if (!strcmp(child->name, "success")) { |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
280 jabber_bosh_connection_stream_restart(conn); |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
281 jabber_process_packet(js, &child); |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
282 conn->receive_cb = jabber_bosh_connection_received; |
25050
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
283 } else { |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
284 js->state = JABBER_STREAM_AUTHENTICATING; |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
285 jabber_process_packet(js, &child); |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25049
diff
changeset
|
286 } |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
287 } else { |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
288 purple_debug_warning("jabber", "Received unexepcted empty BOSH packet.\n"); |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
289 } |
25049
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
290 } |
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
291 |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
292 static void boot_response_cb(PurpleBOSHConnection *conn, xmlnode *node) { |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
293 const char *sid, *version; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
294 const char *inactivity, *requests; |
25194
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
295 xmlnode *packet; |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
296 |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
297 g_return_if_fail(node != NULL); |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
298 if (jabber_bosh_connection_error_check(conn, node)) |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
299 return; |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
300 |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
301 sid = xmlnode_get_attrib(node, "sid"); |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
302 version = xmlnode_get_attrib(node, "ver"); |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
303 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
304 inactivity = xmlnode_get_attrib(node, "inactivity"); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
305 requests = xmlnode_get_attrib(node, "requests"); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
306 |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
307 if (sid) { |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
308 conn->sid = g_strdup(sid); |
25049
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
309 } else { |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
310 purple_connection_error_reason(conn->js->gc, |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
311 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
312 _("No session ID given")); |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
313 return; |
25049
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
314 } |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
315 |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
316 if (version) { |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
317 const char *dot = strstr(version, "."); |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
318 int major = atoi(version); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
319 int minor = atoi(dot + 1); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
320 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
321 purple_debug_info("jabber", "BOSH connection manager version %s\n", version); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
322 |
25194
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
323 if (major != 1 || minor < 6) { |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
324 purple_connection_error_reason(conn->js->gc, |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
325 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
326 _("Unsupported version of BOSH protocol")); |
25194
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
327 return; |
25049
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
328 } |
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
329 } else { |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
330 purple_debug_info("jabber", "Missing version in BOSH initiation\n"); |
25049
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
331 } |
25194
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
332 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
333 if (inactivity) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
334 conn->max_inactivity = atoi(inactivity); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
335 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
336 if (requests) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
337 conn->max_requests = atoi(requests); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
338 |
25194
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
339 /* FIXME: Depending on receiving features might break with some hosts */ |
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
340 packet = xmlnode_get_child(node, "features"); |
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
341 conn->js->use_bosh = TRUE; |
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
342 conn->receive_cb = auth_response_cb; |
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25193
diff
changeset
|
343 jabber_stream_features_parse(conn->js, packet); |
25047
f747c682a0d9
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25046
diff
changeset
|
344 } |
f747c682a0d9
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25046
diff
changeset
|
345 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
346 static PurpleHTTPConnection * |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
347 find_available_http_connection(PurpleBOSHConnection *conn) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
348 { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
349 int i; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
350 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
351 /* Easy solution: Does everyone involved support pipelining? Hooray! Just use |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
352 * one TCP connection! */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
353 if (conn->pipelining) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
354 return conn->connections[0]; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
355 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
356 /* First loop, look for a connection that's ready */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
357 for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
358 if (conn->connections[i] && conn->connections[i]->ready && |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
359 conn->connections[i]->requests == 0) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
360 return conn->connections[i]; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
361 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
362 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
363 /* Second loop, look for one that's NULL and create a new connection */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
364 for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
365 if (!conn->connections[i]) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
366 conn->connections[i] = jabber_bosh_http_connection_init(conn); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
367 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
368 conn->connections[i]->connect_cb = jabber_bosh_connection_connected; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
369 conn->connections[i]->disconnect_cb = jabber_bosh_http_connection_disconnected; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
370 jabber_bosh_http_connection_connect(conn->connections[i]); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
371 return NULL; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
372 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
373 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
374 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
375 /* None available. */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
376 return NULL; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
377 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
378 |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
379 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
380 GString *buf = g_string_new(""); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
381 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
382 g_string_printf(buf, "<body content='text/xml; charset=utf-8' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
383 "secure='true' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
384 "to='%s' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
385 "xml:lang='en' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
386 "xmpp:version='1.0' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
387 "ver='1.6' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
388 "xmlns:xmpp='urn:xmpp:bosh' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
389 "rid='%" G_GUINT64_FORMAT "' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
390 /* TODO: This should be adjusted/adjustable automatically according to |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
391 * realtime network behavior */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
392 "wait='60' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
393 "hold='1' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
394 "xmlns='http://jabber.org/protocol/httpbind'/>", |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
395 conn->js->user->domain, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
396 ++conn->rid); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
397 |
25184
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25183
diff
changeset
|
398 conn->receive_cb = boot_response_cb; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
399 jabber_bosh_http_connection_send_request(conn->connections[0], buf); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
400 g_string_free(buf, TRUE); |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
401 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
402 |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
403 static void |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
404 http_received_cb(const char *data, int len, PurpleBOSHConnection *conn) |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
405 { |
25047
f747c682a0d9
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25046
diff
changeset
|
406 if (conn->receive_cb) { |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
407 xmlnode *node = xmlnode_from_str(data, len); |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
408 if (node) { |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
409 char *txt = xmlnode_to_formatted_str(node, NULL); |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
410 printf("\nhttp_received_cb\n%s\n", txt); |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
411 g_free(txt); |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
412 conn->receive_cb(conn, node); |
25056
94ccccab4e98
* free xmlnodes after bosh receive callback is called
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25055
diff
changeset
|
413 xmlnode_free(node); |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
414 } else { |
25667
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25666
diff
changeset
|
415 purple_debug_warning("jabber", "BOSH: Received invalid XML\n"); |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
416 } |
25667
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25666
diff
changeset
|
417 } else { |
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25666
diff
changeset
|
418 g_return_if_reached(); |
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25666
diff
changeset
|
419 } |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
420 } |
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
421 |
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
422 void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
423 jabber_bosh_connection_send_native(conn, PACKET_NORMAL, node); |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
424 } |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
425 |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
426 void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
427 const char *data, int len) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
428 { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
429 xmlnode *node = xmlnode_from_str(data, len); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
430 if (node) { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
431 jabber_bosh_connection_send_native(conn, PACKET_NORMAL, node); |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
432 xmlnode_free(node); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
433 } else { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
434 /* |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
435 * This best emulates what a normal XMPP server would do |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
436 * if you send bad XML. |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
437 */ |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
438 purple_connection_error_reason(conn->js->gc, |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
439 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
440 _("Cannot send malformed XML")); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
441 } |
25049
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
442 } |
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
443 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
444 static void |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
445 jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, PurpleBOSHPacketType type, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
446 xmlnode *node) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
447 { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
448 PurpleHTTPConnection *chosen; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
449 GString *packet = NULL; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
450 char *buf = NULL; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
451 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
452 chosen = find_available_http_connection(conn); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
453 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
454 if (type != PACKET_NORMAL && !chosen) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
455 /* |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
456 * For non-ordinary traffic, we don't want to 'buffer' it, so use the first |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
457 * connection. |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
458 */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
459 chosen = conn->connections[0]; |
25049
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25048
diff
changeset
|
460 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
461 if (!chosen->ready) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
462 purple_debug_warning("jabber", "First BOSH connection wasn't ready. Bad " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
463 "things may happen.\n"); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
464 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
465 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
466 if (node) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
467 buf = xmlnode_to_str(node, NULL); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
468 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
469 if (type == PACKET_NORMAL && (!chosen || |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
470 (conn->max_requests > 0 && conn->requests == conn->max_requests))) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
471 /* |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
472 * For normal data, send up to max_requests requests at a time or there is no |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
473 * connection ready (likely, we're currently opening a second connection and |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
474 * will send these packets when connected). |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
475 */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
476 if (buf) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
477 conn->pending = g_string_append(conn->pending, buf); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
478 g_free(buf); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
479 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
480 return; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
481 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
482 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
483 packet = g_string_new(""); |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
484 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
485 g_string_printf(packet, "<body " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
486 "rid='%" G_GUINT64_FORMAT "' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
487 "sid='%s' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
488 "to='%s' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
489 "xml:lang='en' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
490 "xmlns='http://jabber.org/protocol/httpbind' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
491 "xmlns:xmpp='urn:xmpp:xbosh'", |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
492 ++conn->rid, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
493 conn->sid, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
494 conn->js->user->domain); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
495 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
496 if (type == PACKET_STREAM_RESTART) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
497 packet = g_string_append(packet, " xmpp:restart='true'/>"); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
498 else { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
499 if (type == PACKET_TERMINATE) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
500 packet = g_string_append(packet, " type='terminate'"); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
501 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
502 g_string_append_printf(packet, ">%s%s</body>", conn->pending->str, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
503 buf ? buf : ""); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
504 g_string_truncate(conn->pending, 0); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
505 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
506 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
507 g_free(buf); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
508 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
509 jabber_bosh_http_connection_send_request(chosen, packet); |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
510 } |
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
511 |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
512 static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
513 conn->ready = TRUE; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
514 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
515 if (conn->bosh->ready) { |
25052
0a8484372312
* 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:
25051
diff
changeset
|
516 purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n"); |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
517 if (conn->bosh->pending && conn->bosh->pending->len > 0) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
518 /* Send the pending data */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
519 jabber_bosh_connection_send_native(conn->bosh, PACKET_NORMAL, NULL); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
520 } |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
521 #if 0 |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
522 conn->bosh->receive_cb = jabber_bosh_connection_received; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
523 if (conn->bosh->connect_cb) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
524 conn->bosh->connect_cb(conn->bosh); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
525 #endif |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
526 } else |
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
527 jabber_bosh_connection_boot(conn->bosh); |
25052
0a8484372312
* 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:
25051
diff
changeset
|
528 } |
0a8484372312
* 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:
25051
diff
changeset
|
529 |
25183
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
530 void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn) |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
531 { |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25182
diff
changeset
|
532 jabber_bosh_connection_send(conn, NULL); |
25052
0a8484372312
* 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:
25051
diff
changeset
|
533 } |
0a8484372312
* 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:
25051
diff
changeset
|
534 |
0a8484372312
* 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:
25051
diff
changeset
|
535 static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn) { |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
536 /* |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
537 * Well, then. Fine! I never liked you anyway, server! I was cheating on you |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
538 * with AIM! |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
539 */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
540 conn->ready = FALSE; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
541 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
542 if (conn->bosh->pipelining) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
543 /* Hmmmm, fall back to multiple connections */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
544 conn->bosh->pipelining = FALSE; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
545 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
546 /* No! Please! Take me back. It was me, not you! I was weak! */ |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
547 conn->connect_cb = jabber_bosh_connection_connected; |
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
548 jabber_bosh_http_connection_connect(conn); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
549 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
550 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
551 void jabber_bosh_connection_connect(PurpleBOSHConnection *bosh) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
552 PurpleHTTPConnection *conn = bosh->connections[0]; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
553 conn->connect_cb = jabber_bosh_connection_connected; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
554 conn->disconnect_cb = jabber_bosh_http_connection_disconnected; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
555 jabber_bosh_http_connection_connect(conn); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
556 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
557 |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
558 static void |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
559 jabber_bosh_http_connection_process(PurpleHTTPConnection *conn) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
560 { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
561 const char *cursor; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
562 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
563 cursor = conn->buf->str + conn->handled_len; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
564 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
565 if (!conn->headers_done) { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
566 const char *content_length = purple_strcasestr(cursor, "\r\nContent-Length"); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
567 const char *end_of_headers = purple_strcasestr(cursor, "\r\n\r\n"); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
568 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
569 /* Make sure Content-Length is in headers, not body */ |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
570 if (content_length && content_length < end_of_headers) { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
571 char *sep = strstr(content_length, ": "); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
572 int len = atoi(sep + 2); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
573 if (len == 0) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
574 purple_debug_warning("jabber", "Found mangled Content-Length header.\n"); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
575 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
576 conn->body_len = len; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
577 } |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
578 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
579 if (end_of_headers) { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
580 conn->headers_done = TRUE; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
581 conn->handled_len = end_of_headers - conn->buf->str + 4; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
582 cursor = end_of_headers + 4; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
583 } else { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
584 conn->handled_len = conn->buf->len; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
585 return; |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
586 } |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
587 } |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
588 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
589 /* Have we handled everything in the buffer? */ |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
590 if (conn->handled_len >= conn->buf->len) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
591 return; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
592 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
593 /* Have we read all that the Content-Length promised us? */ |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
594 if (conn->buf->len - conn->handled_len < conn->body_len) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
595 return; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
596 |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
597 --conn->requests; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
598 --conn->bosh->requests; |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
599 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
600 #warning For a pure HTTP 1.1 stack, this would need to be handled elsewhere. |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
601 if (conn->bosh->ready && conn->bosh->requests == 0) { |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
602 jabber_bosh_connection_send(conn->bosh, NULL); |
25667
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25666
diff
changeset
|
603 purple_debug_misc("jabber", "BOSH: Sending an empty request\n"); |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
604 } |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
605 |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
606 http_received_cb(conn->buf->str + conn->handled_len, conn->body_len, |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
607 conn->bosh); |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
608 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
609 g_string_free(conn->buf, TRUE); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
610 conn->buf = NULL; |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
611 conn->headers_done = FALSE; |
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
612 conn->handled_len = conn->body_len = 0; |
25051
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
613 } |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25050
diff
changeset
|
614 |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
615 static void |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
616 jabber_bosh_http_connection_read(gpointer data, gint fd, |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
617 PurpleInputCondition condition) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
618 { |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
619 PurpleHTTPConnection *conn = data; |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
620 char buffer[1025]; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
621 int perrno; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
622 int cnt, count = 0; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
623 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
624 purple_debug_info("jabber", "jabber_bosh_http_connection_read\n"); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
625 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
626 if (!conn->buf) |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
627 conn->buf = g_string_new(""); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
628 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
629 while ((cnt = read(fd, buffer, sizeof(buffer))) > 0) { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
630 purple_debug_info("jabber", "bosh read %d bytes\n", cnt); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
631 count += cnt; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
632 g_string_append_len(conn->buf, buffer, cnt); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
633 } |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
634 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
635 perrno = errno; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
636 if (cnt == 0 && count) { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
637 /* TODO: process should know this response ended with a closed socket |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
638 * and throw an error if it's not a complete response. */ |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
639 jabber_bosh_http_connection_process(conn); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
640 } |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
641 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
642 if (cnt == 0 || (cnt < 0 && perrno != EAGAIN)) { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
643 if (cnt < 0) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
644 purple_debug_info("jabber", "bosh read: %d\n", cnt); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
645 else |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
646 purple_debug_info("jabber", "bosh socket closed\n"); |
25046
e28f1711f402
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25045
diff
changeset
|
647 |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
648 purple_input_remove(conn->ie_handle); |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
649 conn->ie_handle = 0; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
650 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
651 if (conn->disconnect_cb) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
652 conn->disconnect_cb(conn); |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
653 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
654 return; |
25045
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25044
diff
changeset
|
655 } |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
656 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
657 jabber_bosh_http_connection_process(conn); |
25043
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25042
diff
changeset
|
658 } |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
659 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
660 static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
661 { |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
662 PurpleHTTPConnection *conn = data; |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
663 PurpleConnection *gc = conn->bosh->js->gc; |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
664 |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
665 if (source < 0) { |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
666 gchar *tmp; |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
667 tmp = g_strdup_printf(_("Could not establish a connection with the server:\n%s"), |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
668 error); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
669 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
670 g_free(tmp); |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
671 return; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
672 } |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
673 |
25042
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25040
diff
changeset
|
674 conn->fd = source; |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
675 |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
676 if (conn->connect_cb) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
677 conn->connect_cb(conn); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
678 |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
679 conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ, |
25193
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25192
diff
changeset
|
680 jabber_bosh_http_connection_read, conn); |
25040 | 681 } |
682 | |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
683 static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
684 { |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
685 PurpleConnection *gc = conn->bosh->js->gc; |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
686 PurpleAccount *account = purple_connection_get_account(gc); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
687 |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
688 if ((purple_proxy_connect(conn, account, conn->host, conn->port, jabber_bosh_http_connection_callback, conn)) == NULL) { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
689 purple_connection_error_reason(gc, |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
690 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
691 _("Unable to create socket")); |
25181
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25056
diff
changeset
|
692 } |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
693 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
694 |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
695 static void |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
696 jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
697 const GString *req) |
25182
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25181
diff
changeset
|
698 { |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
699 GString *packet = g_string_new(""); |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
700 int ret; |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
701 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
702 g_string_printf(packet, "POST %s HTTP/1.1\r\n" |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
703 "Host: %s\r\n" |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
704 "User-Agent: %s\r\n" |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
705 "Content-Encoding: text/xml; charset=utf-8\r\n" |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
706 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n", |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
707 conn->bosh->path, conn->host, bosh_useragent, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
708 req->len); |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
709 |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
710 packet = g_string_append(packet, req->str); |
25664
26259ee81c5b
BOSH: Fix the HTTP Post to include the actual payload.
Paul Aurich <paul@darkrain42.org>
parents:
25195
diff
changeset
|
711 |
25667
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25666
diff
changeset
|
712 purple_debug_misc("jabber", "BOSH out: %s\n", packet->str); |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
713 /* TODO: Better error handling, circbuffer or possible integration with |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
714 * low-level code in jabber.c */ |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
715 ret = write(conn->fd, packet->str, packet->len); |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
716 |
25669
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25668
diff
changeset
|
717 ++conn->requests; |
25988
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25670
diff
changeset
|
718 ++conn->bosh->requests; |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
719 g_string_free(packet, TRUE); |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
720 |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
721 if (ret < 0 && errno == EAGAIN) |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
722 purple_debug_warning("jabber", "BOSH write would have blocked\n"); |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
723 |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
724 if (ret <= 0) { |
25670
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25669
diff
changeset
|
725 purple_connection_error_reason(conn->bosh->js->gc, |
25192
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
726 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
727 _("Write error")); |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
728 return; |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25184
diff
changeset
|
729 } |
25044
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
730 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25043
diff
changeset
|
731 |