Mercurial > pidgin.yaz
annotate libpurple/protocols/jabber/bosh.c @ 31667:076d62344ede
broke des and des3 out to ciphers/des.c
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Mon, 14 Feb 2011 06:51:10 +0000 |
parents | 928335d6461b |
children | f876cb251c7a |
rev | line source |
---|---|
25596
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 * |
28398
c585572e80dd
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <paul@darkrain42.org>
parents:
28141
diff
changeset
|
4 * Purple is the legal property of its developers, whose names are too numerous |
c585572e80dd
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <paul@darkrain42.org>
parents:
28141
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
c585572e80dd
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <paul@darkrain42.org>
parents:
28141
diff
changeset
|
6 * source distribution. |
25596
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
7 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * (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
|
12 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * 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
|
17 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
18 * 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
|
19 * 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
|
20 * 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
|
21 * |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
22 */ |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
23 #include "internal.h" |
25999
c605e5f2fc99
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents:
25998
diff
changeset
|
24 #include "circbuffer.h" |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
25 #include "core.h" |
25596
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
26 #include "cipher.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
27 #include "debug.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
28 #include "prpl.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
29 #include "util.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
30 #include "xmlnode.h" |
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
31 |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
32 #include "bosh.h" |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
33 |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
34 /* The number of HTTP connections to use. This MUST be at least 2. */ |
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
35 #define NUM_HTTP_CONNECTIONS 2 |
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
36 /* How many failed connection attempts before it becomes a fatal error */ |
26355
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
37 #define MAX_FAILED_CONNECTIONS 3 |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
38 /* How long in seconds to queue up outgoing messages */ |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
39 #define BUFFER_SEND_IN_SECS 1 |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
40 |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
41 typedef struct _PurpleHTTPConnection PurpleHTTPConnection; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
42 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
43 typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
44 typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
45 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
46 static char *bosh_useragent = NULL; |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
47 |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
48 typedef enum { |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
49 PACKET_NORMAL, |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
50 PACKET_TERMINATE, |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
51 PACKET_FLUSH, |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
52 } PurpleBOSHPacketType; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
53 |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
54 struct _PurpleBOSHConnection { |
25998
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
55 JabberStream *js; |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
56 PurpleHTTPConnection *connections[NUM_HTTP_CONNECTIONS]; |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
57 |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
58 PurpleCircBuffer *pending; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
59 PurpleBOSHConnectionConnectFunction connect_cb; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
60 PurpleBOSHConnectionReceiveFunction receive_cb; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
61 |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
62 /* Must be big enough to hold 2^53 - 1 */ |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
63 char *sid; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
64 guint64 rid; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
65 |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
66 /* decoded URL */ |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
67 char *host; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
68 char *path; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
69 guint16 port; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
70 |
25998
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
71 gboolean pipelining; |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
72 gboolean ssl; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
73 |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
74 enum { |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
75 BOSH_CONN_OFFLINE, |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
76 BOSH_CONN_BOOTING, |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
77 BOSH_CONN_ONLINE |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
78 } state; |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
79 guint8 failed_connections; |
25998
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
80 |
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
81 int wait; |
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
82 |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
83 int max_requests; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
84 int requests; |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
85 |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
86 guint send_timer; |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
87 }; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
88 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
89 struct _PurpleHTTPConnection { |
25998
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
90 PurpleBOSHConnection *bosh; |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
91 PurpleSslConnection *psc; |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
92 |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
93 PurpleCircBuffer *write_buf; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
94 GString *read_buf; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
95 |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
96 gsize handled_len; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
97 gsize body_len; |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
98 |
25998
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
99 int fd; |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
100 guint readh; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
101 guint writeh; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
102 |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
103 enum { |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
104 HTTP_CONN_OFFLINE, |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
105 HTTP_CONN_CONNECTING, |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
106 HTTP_CONN_CONNECTED |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
107 } state; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
108 int requests; /* number of outstanding HTTP requests */ |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
109 |
25998
349e411da2ce
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents:
25997
diff
changeset
|
110 gboolean headers_done; |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
111 gboolean close; |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
112 }; |
25596
7768cad83127
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
113 |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
114 static void |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
115 debug_dump_http_connections(PurpleBOSHConnection *conn) |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
116 { |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
117 int i; |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
118 |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
119 g_return_if_fail(conn != NULL); |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
120 |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
121 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
122 PurpleHTTPConnection *httpconn = conn->connections[i]; |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
123 if (httpconn == NULL) |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
124 purple_debug_misc("jabber", "BOSH %p->connections[%d] = (nil)\n", |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
125 conn, i); |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
126 else |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
127 purple_debug_misc("jabber", "BOSH %p->connections[%d] = %p, state = %d" |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
128 ", requests = %d\n", conn, i, httpconn, |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
129 httpconn->state, httpconn->requests); |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
130 } |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
131 } |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
132 |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
133 static void http_connection_connect(PurpleHTTPConnection *conn); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
134 static void http_connection_send_request(PurpleHTTPConnection *conn, |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
135 const GString *req); |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
136 static gboolean send_timer_cb(gpointer data); |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
137 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
138 void jabber_bosh_init(void) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
139 { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
140 GHashTable *ui_info = purple_core_get_ui_info(); |
25812
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25811
diff
changeset
|
141 const char *ui_name = NULL; |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
142 const char *ui_version = NULL; |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
143 |
25812
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25811
diff
changeset
|
144 if (ui_info) { |
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25811
diff
changeset
|
145 ui_name = g_hash_table_lookup(ui_info, "name"); |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
146 ui_version = g_hash_table_lookup(ui_info, "version"); |
25812
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25811
diff
changeset
|
147 } |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
148 |
25812
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25811
diff
changeset
|
149 if (ui_name) |
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25811
diff
changeset
|
150 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:
25811
diff
changeset
|
151 ui_name, ui_version ? " " : "", |
8c58f31f41eb
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents:
25811
diff
changeset
|
152 ui_version ? ui_version : ""); |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
153 else |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
154 bosh_useragent = g_strdup("libpurple " VERSION); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
155 } |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
156 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
157 void jabber_bosh_uninit(void) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
158 { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
159 g_free(bosh_useragent); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
160 bosh_useragent = NULL; |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
161 } |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
162 |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
163 static PurpleHTTPConnection* |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
164 jabber_bosh_http_connection_init(PurpleBOSHConnection *bosh) |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
165 { |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
166 PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1); |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
167 conn->bosh = bosh; |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
168 conn->fd = -1; |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
169 conn->state = HTTP_CONN_OFFLINE; |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
170 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
171 conn->write_buf = purple_circ_buffer_new(0 /* default grow size */); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
172 |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
173 return conn; |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
174 } |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
175 |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
176 static void |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
177 jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn) |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
178 { |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
179 if (conn->read_buf) |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
180 g_string_free(conn->read_buf, TRUE); |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
181 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
182 if (conn->write_buf) |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
183 purple_circ_buffer_destroy(conn->write_buf); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
184 if (conn->readh) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
185 purple_input_remove(conn->readh); |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
186 if (conn->writeh) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
187 purple_input_remove(conn->writeh); |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
188 if (conn->psc) |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
189 purple_ssl_close(conn->psc); |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
190 if (conn->fd >= 0) |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
191 close(conn->fd); |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
192 |
25994
c3c2e8b64539
Close a small race with disconnecting while establishing a connection and
Paul Aurich <paul@darkrain42.org>
parents:
25993
diff
changeset
|
193 purple_proxy_connect_cancel_with_handle(conn); |
c3c2e8b64539
Close a small race with disconnecting while establishing a connection and
Paul Aurich <paul@darkrain42.org>
parents:
25993
diff
changeset
|
194 |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
195 g_free(conn); |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
196 } |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
197 |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
198 PurpleBOSHConnection* |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
199 jabber_bosh_connection_init(JabberStream *js, const char *url) |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
200 { |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
201 PurpleBOSHConnection *conn; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
202 char *host, *path, *user, *passwd; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
203 int port; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
204 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
205 if (!purple_url_parse(url, &host, &port, &path, &user, &passwd)) { |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
206 purple_debug_info("jabber", "Unable to parse given URL.\n"); |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
207 return NULL; |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
208 } |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
209 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
210 conn = g_new0(PurpleBOSHConnection, 1); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
211 conn->host = host; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
212 conn->port = port; |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
213 conn->path = g_strdup_printf("/%s", path); |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
214 g_free(path); |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
215 conn->pipelining = TRUE; |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
216 |
30682
22afdd5a9290
jabber: Set js->serverFQDN when connecting via BOSH. Fixes #12289
Paul Aurich <paul@darkrain42.org>
parents:
30184
diff
changeset
|
217 if (purple_ip_address_is_valid(host)) |
22afdd5a9290
jabber: Set js->serverFQDN when connecting via BOSH. Fixes #12289
Paul Aurich <paul@darkrain42.org>
parents:
30184
diff
changeset
|
218 js->serverFQDN = g_strdup(js->user->domain); |
22afdd5a9290
jabber: Set js->serverFQDN when connecting via BOSH. Fixes #12289
Paul Aurich <paul@darkrain42.org>
parents:
30184
diff
changeset
|
219 else |
22afdd5a9290
jabber: Set js->serverFQDN when connecting via BOSH. Fixes #12289
Paul Aurich <paul@darkrain42.org>
parents:
30184
diff
changeset
|
220 js->serverFQDN = g_strdup(host); |
22afdd5a9290
jabber: Set js->serverFQDN when connecting via BOSH. Fixes #12289
Paul Aurich <paul@darkrain42.org>
parents:
30184
diff
changeset
|
221 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
222 if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) { |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
223 purple_debug_info("jabber", "Ignoring unexpected username and password " |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
224 "in BOSH URL.\n"); |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
225 } |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
226 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
227 g_free(user); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
228 g_free(passwd); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
229 |
25602
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25601
diff
changeset
|
230 conn->js = js; |
26543
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
231 |
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
232 /* |
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
233 * Random 64-bit integer masked off by 2^52 - 1. |
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
234 * |
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
235 * This should produce a random integer in the range [0, 2^52). It's |
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
236 * unlikely we'll send enough packets in one session to overflow the rid. |
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
237 */ |
43cfca2eab64
A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents:
26534
diff
changeset
|
238 conn->rid = ((guint64)g_random_int() << 32) | g_random_int(); |
26826
45271de9c65d
Windows compilation complains (probably because it's 32-bit)
Paul Aurich <paul@darkrain42.org>
parents:
26544
diff
changeset
|
239 conn->rid &= 0xFFFFFFFFFFFFFLL; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
240 |
25999
c605e5f2fc99
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents:
25998
diff
changeset
|
241 conn->pending = purple_circ_buffer_new(0 /* default grow size */); |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
242 |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
243 conn->state = BOSH_CONN_OFFLINE; |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
244 if (purple_strcasestr(url, "https://") != NULL) |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
245 conn->ssl = TRUE; |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
246 else |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
247 conn->ssl = FALSE; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
248 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
249 conn->connections[0] = jabber_bosh_http_connection_init(conn); |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
250 |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
251 return conn; |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
252 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
253 |
25778
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
254 void |
62d9bce9ff74
Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents:
25777
diff
changeset
|
255 jabber_bosh_connection_destroy(PurpleBOSHConnection *conn) |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
256 { |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
257 int i; |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
258 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
259 g_free(conn->host); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
260 g_free(conn->path); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
261 |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
262 if (conn->send_timer) |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
263 purple_timeout_remove(conn->send_timer); |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
264 |
25999
c605e5f2fc99
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents:
25998
diff
changeset
|
265 purple_circ_buffer_destroy(conn->pending); |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
266 |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
267 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
268 if (conn->connections[i]) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
269 jabber_bosh_http_connection_destroy(conn->connections[i]); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
270 } |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
271 |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
272 g_free(conn); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
273 } |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
274 |
26354
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
275 gboolean jabber_bosh_connection_is_ssl(PurpleBOSHConnection *conn) |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
276 { |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
277 return conn->ssl; |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
278 } |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
279 |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
280 static PurpleHTTPConnection * |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
281 find_available_http_connection(PurpleBOSHConnection *conn) |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
282 { |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
283 int i; |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
284 |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
285 if (purple_debug_is_verbose()) |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
286 debug_dump_http_connections(conn); |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
287 |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
288 /* Easy solution: Does everyone involved support pipelining? Hooray! Just use |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
289 * one TCP connection! */ |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
290 if (conn->pipelining) |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
291 return conn->connections[0]->state == HTTP_CONN_CONNECTED ? |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
292 conn->connections[0] : NULL; |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
293 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
294 /* First loop, look for a connection that's ready */ |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
295 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
296 if (conn->connections[i] && |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
297 conn->connections[i]->state == HTTP_CONN_CONNECTED && |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
298 conn->connections[i]->requests == 0) |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
299 return conn->connections[i]; |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
300 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
301 |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
302 /* Second loop, is something currently connecting? If so, just queue up. */ |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
303 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
304 if (conn->connections[i] && |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
305 conn->connections[i]->state == HTTP_CONN_CONNECTING) |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
306 return NULL; |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
307 } |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
308 |
31592
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
309 /* Third loop, is something offline that we can connect? */ |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
310 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
311 if (conn->connections[i] && |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
312 conn->connections[i]->state == HTTP_CONN_OFFLINE) { |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
313 purple_debug_info("jabber", "bosh: Reconnecting httpconn " |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
314 "(%i, %p)\n", i, conn->connections[i]); |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
315 http_connection_connect(conn->connections[i]); |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
316 return NULL; |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
317 } |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
318 } |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
319 |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
320 /* Fourth loop, look for one that's NULL and create a new connection */ |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
321 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
322 if (!conn->connections[i]) { |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
323 conn->connections[i] = jabber_bosh_http_connection_init(conn); |
31580
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
324 purple_debug_info("jabber", "bosh: Creating and connecting new httpconn " |
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
325 "(%i, %p)\n", i, conn->connections[i]); |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
326 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
327 http_connection_connect(conn->connections[i]); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
328 return NULL; |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
329 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
330 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
331 |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
332 purple_debug_warning("jabber", "Could not find a HTTP connection!\n"); |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
333 |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
334 /* None available. */ |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
335 return NULL; |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
336 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
337 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
338 static void |
27256
708f92703a13
Don't try to write when the BOSH connection isn't ready.
Paul Aurich <paul@darkrain42.org>
parents:
27014
diff
changeset
|
339 jabber_bosh_connection_send(PurpleBOSHConnection *conn, |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
340 const PurpleBOSHPacketType type, const char *data) |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
341 { |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
342 PurpleHTTPConnection *chosen; |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
343 GString *packet = NULL; |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
344 |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
345 if (type != PACKET_FLUSH && type != PACKET_TERMINATE) { |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
346 /* |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
347 * Unless this is a flush (or session terminate, which needs to be |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
348 * sent immediately), queue up the data and start a timer to flush |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
349 * the buffer. |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
350 */ |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
351 if (data) { |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
352 int len = data ? strlen(data) : 0; |
27014
a8537bbcfb79
Remove trailing whitespace that has snuck in.
Paul Aurich <paul@darkrain42.org>
parents:
27013
diff
changeset
|
353 purple_circ_buffer_append(conn->pending, data, len); |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
354 } |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
355 |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
356 if (purple_debug_is_verbose()) |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
357 purple_debug_misc("jabber", "bosh: %p has %" G_GSIZE_FORMAT " bytes in " |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
358 "the buffer.\n", conn, conn->pending->bufused); |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
359 if (conn->send_timer == 0) |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
360 conn->send_timer = purple_timeout_add_seconds(BUFFER_SEND_IN_SECS, |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
361 send_timer_cb, conn); |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
362 return; |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
363 } |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
364 |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
365 chosen = find_available_http_connection(conn); |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
366 |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
367 if (!chosen) { |
31623
928335d6461b
jabber: bosh: Hopefully a final corrective fix. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
31592
diff
changeset
|
368 if (type == PACKET_FLUSH) |
928335d6461b
jabber: bosh: Hopefully a final corrective fix. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
31592
diff
changeset
|
369 return; |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
370 /* |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
371 * For non-ordinary traffic, we can't 'buffer' it, so use the |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
372 * first connection. |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
373 */ |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
374 chosen = conn->connections[0]; |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
375 |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
376 if (chosen->state != HTTP_CONN_CONNECTED) { |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
377 purple_debug_warning("jabber", "Unable to find a ready BOSH " |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
378 "connection. Ignoring send of type 0x%02x.\n", type); |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
379 return; |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
380 } |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
381 } |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
382 |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
383 /* We're flushing the send buffer, so remove the send timer */ |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
384 if (conn->send_timer != 0) { |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
385 purple_timeout_remove(conn->send_timer); |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
386 conn->send_timer = 0; |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
387 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
388 |
27011
f82f3dc29f9b
Don't try to process BOSH packet if there's no data (avoid a purple_strcasestr assertion).
Paul Aurich <paul@darkrain42.org>
parents:
26826
diff
changeset
|
389 packet = g_string_new(NULL); |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
390 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
391 g_string_printf(packet, "<body " |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
392 "rid='%" G_GUINT64_FORMAT "' " |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
393 "sid='%s' " |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
394 "to='%s' " |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
395 "xml:lang='en' " |
29045
931d6906291b
jabber: Here's a good reason for the namespace defines. Fix a typo 'urn:xmpp:bosh'.
Paul Aurich <paul@darkrain42.org>
parents:
28670
diff
changeset
|
396 "xmlns='" NS_BOSH "' " |
931d6906291b
jabber: Here's a good reason for the namespace defines. Fix a typo 'urn:xmpp:bosh'.
Paul Aurich <paul@darkrain42.org>
parents:
28670
diff
changeset
|
397 "xmlns:xmpp='" NS_XMPP_BOSH "'", |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
398 ++conn->rid, |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
399 conn->sid, |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
400 conn->js->user->domain); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
401 |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
402 if (conn->js->reinit) { |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
403 packet = g_string_append(packet, " xmpp:restart='true'/>"); |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
404 /* TODO: Do we need to wait for a response? */ |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
405 conn->js->reinit = FALSE; |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
406 } else { |
26534
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
407 gsize read_amt; |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
408 if (type == PACKET_TERMINATE) |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
409 packet = g_string_append(packet, " type='terminate'"); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
410 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
411 packet = g_string_append_c(packet, '>'); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
412 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
413 while ((read_amt = purple_circ_buffer_get_max_read(conn->pending)) > 0) { |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
414 packet = g_string_append_len(packet, conn->pending->outptr, read_amt); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
415 purple_circ_buffer_mark_read(conn->pending, read_amt); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
416 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
417 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
418 if (data) |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
419 packet = g_string_append(packet, data); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
420 packet = g_string_append(packet, "</body>"); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
421 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
422 |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
423 http_connection_send_request(chosen, packet); |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
424 } |
5172ebcc8673
Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents:
26531
diff
changeset
|
425 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
426 void jabber_bosh_connection_close(PurpleBOSHConnection *conn) |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
427 { |
28670
9206aabf0251
jabber: Don't crash when disconnecting if there's been no response from the server.
Paul Aurich <paul@darkrain42.org>
parents:
28447
diff
changeset
|
428 if (conn->state == BOSH_CONN_ONLINE) |
9206aabf0251
jabber: Don't crash when disconnecting if there's been no response from the server.
Paul Aurich <paul@darkrain42.org>
parents:
28447
diff
changeset
|
429 jabber_bosh_connection_send(conn, PACKET_TERMINATE, NULL); |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
430 } |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
431 |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
432 static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node) { |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
433 const char *type; |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
434 |
25612
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25610
diff
changeset
|
435 type = xmlnode_get_attrib(node, "type"); |
27014
a8537bbcfb79
Remove trailing whitespace that has snuck in.
Paul Aurich <paul@darkrain42.org>
parents:
27013
diff
changeset
|
436 |
25612
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25610
diff
changeset
|
437 if (type != NULL && !strcmp(type, "terminate")) { |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
438 conn->state = BOSH_CONN_OFFLINE; |
27463
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
439 purple_connection_error_reason(conn->js->gc, |
25613
480736bfcf45
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25612
diff
changeset
|
440 PURPLE_CONNECTION_ERROR_OTHER_ERROR, |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
441 _("The BOSH connection manager terminated your session.")); |
25612
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25610
diff
changeset
|
442 return TRUE; |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25610
diff
changeset
|
443 } |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25610
diff
changeset
|
444 return FALSE; |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25610
diff
changeset
|
445 } |
8badac6cc7c9
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25610
diff
changeset
|
446 |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
447 static gboolean |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
448 send_timer_cb(gpointer data) |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
449 { |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
450 PurpleBOSHConnection *bosh; |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
451 |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
452 bosh = data; |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
453 bosh->send_timer = 0; |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
454 |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
455 jabber_bosh_connection_send(bosh, PACKET_FLUSH, NULL); |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
456 |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
457 return FALSE; |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
458 } |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
459 |
30184
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
460 void |
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
461 jabber_bosh_connection_send_keepalive(PurpleBOSHConnection *bosh) |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
462 { |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
463 if (bosh->send_timer != 0) |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
464 purple_timeout_remove(bosh->send_timer); |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
465 |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
466 /* clears bosh->send_timer */ |
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
467 send_timer_cb(bosh); |
28126
46e80810b095
jabber: Better inactivity timer logic.
Paul Aurich <paul@darkrain42.org>
parents:
28125
diff
changeset
|
468 } |
46e80810b095
jabber: Better inactivity timer logic.
Paul Aurich <paul@darkrain42.org>
parents:
28125
diff
changeset
|
469 |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
470 static void |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
471 jabber_bosh_disable_pipelining(PurpleBOSHConnection *bosh) |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
472 { |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
473 /* Do nothing if it's already disabled */ |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
474 if (!bosh->pipelining) |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
475 return; |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
476 |
31623
928335d6461b
jabber: bosh: Hopefully a final corrective fix. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
31592
diff
changeset
|
477 purple_debug_info("jabber", "BOSH: Disabling pipelining on conn %p\n", |
928335d6461b
jabber: bosh: Hopefully a final corrective fix. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
31592
diff
changeset
|
478 bosh); |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
479 bosh->pipelining = FALSE; |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
480 if (bosh->connections[1] == NULL) { |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
481 bosh->connections[1] = jabber_bosh_http_connection_init(bosh); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
482 http_connection_connect(bosh->connections[1]); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
483 } else { |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
484 /* Shouldn't happen; this should be the only place pipelining |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
485 * is turned off. |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
486 */ |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
487 g_warn_if_reached(); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
488 } |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
489 } |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
490 |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
491 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
492 xmlnode *child; |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
493 JabberStream *js = conn->js; |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
494 |
25810
7856dccb02fb
BOSH: Another g_return_if_fail that is backward
Paul Aurich <paul@darkrain42.org>
parents:
25809
diff
changeset
|
495 g_return_if_fail(node != NULL); |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
496 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:
25778
diff
changeset
|
497 return; |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
498 |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
499 child = node->child; |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
500 while (child != NULL) { |
25790
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25789
diff
changeset
|
501 /* jabber_process_packet might free child */ |
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25789
diff
changeset
|
502 xmlnode *next = child->next; |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
503 if (child->type == XMLNODE_TYPE_TAG) { |
29409
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
504 const char *xmlns = xmlnode_get_namespace(child); |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
505 /* |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
506 * Workaround for non-compliant servers that don't stamp |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
507 * the right xmlns on these packets. See #11315. |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
508 */ |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
509 if ((xmlns == NULL /* shouldn't happen, but is equally wrong */ || |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
510 g_str_equal(xmlns, NS_BOSH)) && |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
511 (g_str_equal(child->name, "iq") || |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
512 g_str_equal(child->name, "message") || |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
513 g_str_equal(child->name, "presence"))) { |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
514 xmlnode_set_namespace(child, NS_XMPP_CLIENT); |
f521dd7c75b5
jabber: Handle non-compliant servers that don't put stanzas in the right namespace.
Paul Aurich <paul@darkrain42.org>
parents:
29045
diff
changeset
|
515 } |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
516 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:
25608
diff
changeset
|
517 } |
25790
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25789
diff
changeset
|
518 |
4e624cc0c4a5
Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents:
25789
diff
changeset
|
519 child = next; |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
520 } |
25608
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25607
diff
changeset
|
521 } |
a03a953ba63d
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25607
diff
changeset
|
522 |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
523 static void boot_response_cb(PurpleBOSHConnection *conn, xmlnode *node) { |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
524 JabberStream *js = conn->js; |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
525 const char *sid, *version; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
526 const char *inactivity, *requests; |
25789
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25788
diff
changeset
|
527 xmlnode *packet; |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
528 |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
529 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:
25778
diff
changeset
|
530 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:
25778
diff
changeset
|
531 return; |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
532 |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
533 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:
25778
diff
changeset
|
534 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:
25778
diff
changeset
|
535 |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
536 inactivity = xmlnode_get_attrib(node, "inactivity"); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
537 requests = xmlnode_get_attrib(node, "requests"); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
538 |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
539 if (sid) { |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
540 conn->sid = g_strdup(sid); |
25607
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25606
diff
changeset
|
541 } else { |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
542 purple_connection_error_reason(js->gc, |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
543 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
544 _("No session ID given")); |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
545 return; |
25607
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25606
diff
changeset
|
546 } |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
547 |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
548 if (version) { |
29961
618c4165d4f8
jabber: Treat the version properly.
Paul Aurich <paul@darkrain42.org>
parents:
29409
diff
changeset
|
549 const char *dot = strchr(version, '.'); |
27013 | 550 int major, minor = 0; |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
551 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
552 purple_debug_info("jabber", "BOSH connection manager version %s\n", version); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
553 |
27013 | 554 major = atoi(version); |
555 if (dot) | |
556 minor = atoi(dot + 1); | |
557 | |
25789
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25788
diff
changeset
|
558 if (major != 1 || minor < 6) { |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
559 purple_connection_error_reason(js->gc, |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
560 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
561 _("Unsupported version of BOSH protocol")); |
25789
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25788
diff
changeset
|
562 return; |
25607
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25606
diff
changeset
|
563 } |
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25606
diff
changeset
|
564 } else { |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
565 purple_debug_info("jabber", "Missing version in BOSH initiation\n"); |
25607
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25606
diff
changeset
|
566 } |
25789
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25788
diff
changeset
|
567 |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
568 if (inactivity) { |
30184
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
569 js->max_inactivity = atoi(inactivity); |
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
570 if (js->max_inactivity <= 5) { |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
571 purple_debug_warning("jabber", "Ignoring bogusly small inactivity: %s\n", |
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
572 inactivity); |
30184
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
573 /* Leave it at the default */ |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
574 } else { |
28126
46e80810b095
jabber: Better inactivity timer logic.
Paul Aurich <paul@darkrain42.org>
parents:
28125
diff
changeset
|
575 /* TODO: Can this check fail? It shouldn't */ |
30184
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
576 js->max_inactivity -= 5; /* rounding */ |
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
577 |
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
578 if (js->inactivity_timer == 0) { |
28126
46e80810b095
jabber: Better inactivity timer logic.
Paul Aurich <paul@darkrain42.org>
parents:
28125
diff
changeset
|
579 purple_debug_misc("jabber", "Starting BOSH inactivity timer " |
46e80810b095
jabber: Better inactivity timer logic.
Paul Aurich <paul@darkrain42.org>
parents:
28125
diff
changeset
|
580 "for %d secs (compensating for rounding)\n", |
30184
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
581 js->max_inactivity); |
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
582 jabber_stream_restart_inactivity_timer(js); |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
583 } |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
584 } |
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
585 } |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
586 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
587 if (requests) |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
588 conn->max_requests = atoi(requests); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
589 |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
590 jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); |
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
591 |
25789
b78c8ab5de2b
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents:
25788
diff
changeset
|
592 /* 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:
25788
diff
changeset
|
593 packet = xmlnode_get_child(node, "features"); |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
594 conn->state = BOSH_CONN_ONLINE; |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
595 conn->receive_cb = jabber_bosh_connection_received; |
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
596 jabber_stream_features_parse(js, packet); |
25605
f747c682a0d9
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25604
diff
changeset
|
597 } |
f747c682a0d9
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25604
diff
changeset
|
598 |
25601
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25600
diff
changeset
|
599 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { |
27011
f82f3dc29f9b
Don't try to process BOSH packet if there's no data (avoid a purple_strcasestr assertion).
Paul Aurich <paul@darkrain42.org>
parents:
26826
diff
changeset
|
600 GString *buf = g_string_new(NULL); |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
601 |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
602 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:
25814
diff
changeset
|
603 "secure='true' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
604 "to='%s' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
605 "xml:lang='en' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
606 "xmpp:version='1.0' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
607 "ver='1.6' " |
29045
931d6906291b
jabber: Here's a good reason for the namespace defines. Fix a typo 'urn:xmpp:bosh'.
Paul Aurich <paul@darkrain42.org>
parents:
28670
diff
changeset
|
608 "xmlns:xmpp='" NS_XMPP_BOSH "' " |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
609 "rid='%" G_GUINT64_FORMAT "' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
610 /* 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:
25814
diff
changeset
|
611 * realtime network behavior */ |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
612 "wait='60' " |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
613 "hold='1' " |
29045
931d6906291b
jabber: Here's a good reason for the namespace defines. Fix a typo 'urn:xmpp:bosh'.
Paul Aurich <paul@darkrain42.org>
parents:
28670
diff
changeset
|
614 "xmlns='" NS_BOSH "'/>", |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
615 conn->js->user->domain, |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
616 ++conn->rid); |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
617 |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
618 purple_debug_misc("jabber", "SendBOSH Boot %s(%" G_GSIZE_FORMAT "): %s\n", |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
619 conn->ssl ? "(ssl)" : "", buf->len, buf->str); |
25779
1ce32c6752fc
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents:
25778
diff
changeset
|
620 conn->receive_cb = boot_response_cb; |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
621 http_connection_send_request(conn->connections[0], buf); |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
622 g_string_free(buf, TRUE); |
25602
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25601
diff
changeset
|
623 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25601
diff
changeset
|
624 |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
625 static void |
25814
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25813
diff
changeset
|
626 http_received_cb(const char *data, int len, PurpleBOSHConnection *conn) |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
627 { |
26355
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
628 if (conn->failed_connections) |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
629 /* We've got some data, so reset the number of failed connections */ |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
630 conn->failed_connections = 0; |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
631 |
25605
f747c682a0d9
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25604
diff
changeset
|
632 if (conn->receive_cb) { |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
633 xmlnode *node = xmlnode_from_str(data, len); |
26531
345165fc51b6
BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents:
26530
diff
changeset
|
634 |
345165fc51b6
BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents:
26530
diff
changeset
|
635 purple_debug_info("jabber", "RecvBOSH %s(%d): %s\n", |
345165fc51b6
BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents:
26530
diff
changeset
|
636 conn->ssl ? "(ssl)" : "", len, data); |
345165fc51b6
BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents:
26530
diff
changeset
|
637 |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
638 if (node) { |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
639 conn->receive_cb(conn, node); |
25614
94ccccab4e98
* free xmlnodes after bosh receive callback is called
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25613
diff
changeset
|
640 xmlnode_free(node); |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
641 } else { |
25811
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25810
diff
changeset
|
642 purple_debug_warning("jabber", "BOSH: Received invalid XML\n"); |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
643 } |
25811
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25810
diff
changeset
|
644 } else { |
bf7338765863
BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents:
25810
diff
changeset
|
645 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:
25810
diff
changeset
|
646 } |
25601
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25600
diff
changeset
|
647 } |
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25600
diff
changeset
|
648 |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
649 void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, |
26530
d4af753e0e33
Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents:
26355
diff
changeset
|
650 const char *data) |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
651 { |
26530
d4af753e0e33
Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents:
26355
diff
changeset
|
652 jabber_bosh_connection_send(conn, PACKET_NORMAL, data); |
25607
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25606
diff
changeset
|
653 } |
f775f6021654
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25606
diff
changeset
|
654 |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
655 static void |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
656 connection_common_established_cb(PurpleHTTPConnection *conn) |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
657 { |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
658 purple_debug_misc("jabber", "bosh: httpconn %p re-connected\n", conn); |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
659 |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
660 /* Indicate we're ready and reset some variables */ |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
661 conn->state = HTTP_CONN_CONNECTED; |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
662 if (conn->requests != 0) |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
663 purple_debug_error("jabber", "bosh: httpconn %p has %d requests, != 0\n", |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
664 conn, conn->requests); |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
665 |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
666 conn->requests = 0; |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
667 if (conn->read_buf) { |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
668 g_string_free(conn->read_buf, TRUE); |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
669 conn->read_buf = NULL; |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
670 } |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
671 conn->close = FALSE; |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
672 conn->headers_done = FALSE; |
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
673 conn->handled_len = conn->body_len = 0; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
674 |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
675 if (purple_debug_is_verbose()) |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
676 debug_dump_http_connections(conn->bosh); |
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
677 |
28447
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
678 if (conn->bosh->js->reinit) |
b357216b7b79
jabber: Fix using BOSH and legacy auth together. Closes #9990.
Paul Aurich <paul@darkrain42.org>
parents:
28398
diff
changeset
|
679 jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL); |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
680 else if (conn->bosh->state == BOSH_CONN_ONLINE) { |
25610
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:
25609
diff
changeset
|
681 purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n"); |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
682 if (conn->bosh->requests == 0 || conn->bosh->pending->bufused > 0) { |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
683 /* Send the pending data */ |
28133
3eef8392a54b
jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <paul@darkrain42.org>
parents:
28127
diff
changeset
|
684 jabber_bosh_connection_send(conn->bosh, PACKET_FLUSH, NULL); |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
685 } |
25814
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25813
diff
changeset
|
686 } else |
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25813
diff
changeset
|
687 jabber_bosh_connection_boot(conn->bosh); |
25610
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:
25609
diff
changeset
|
688 } |
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:
25609
diff
changeset
|
689 |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
690 static void http_connection_disconnected(PurpleHTTPConnection *conn) |
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
691 { |
31592
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
692 gboolean had_requests = FALSE; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
693 /* |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
694 * 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:
25814
diff
changeset
|
695 * with AIM! |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
696 */ |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
697 conn->state = HTTP_CONN_OFFLINE; |
26354
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
698 if (conn->psc) { |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
699 purple_ssl_close(conn->psc); |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
700 conn->psc = NULL; |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
701 } else if (conn->fd >= 0) { |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
702 close(conn->fd); |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
703 conn->fd = -1; |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
704 } |
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
705 |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
706 if (conn->readh) { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
707 purple_input_remove(conn->readh); |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
708 conn->readh = 0; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
709 } |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
710 |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
711 if (conn->writeh) { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
712 purple_input_remove(conn->writeh); |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
713 conn->writeh = 0; |
26354
fcee93c74230
BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents:
26000
diff
changeset
|
714 } |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
715 |
31592
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
716 had_requests = (conn->requests > 0); |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
717 if (had_requests && conn->read_buf->len == 0) { |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
718 purple_debug_error("jabber", "bosh: Adjusting BOSHconn requests (%d) to %d\n", |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
719 conn->bosh->requests, conn->bosh->requests - conn->requests); |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
720 conn->bosh->requests -= conn->requests; |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
721 conn->requests = 0; |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
722 } |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
723 |
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
724 if (conn->bosh->pipelining) { |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
725 /* Hmmmm, fall back to multiple connections */ |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
726 jabber_bosh_disable_pipelining(conn->bosh); |
28141
20f13609ca7a
jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <paul@darkrain42.org>
parents:
28133
diff
changeset
|
727 } |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
728 |
31592
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
729 if (!had_requests) |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
730 /* If the server disconnected us without any requests, let's |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
731 * just wait until we have something to send before we reconnect |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
732 */ |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
733 return; |
7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <paul@darkrain42.org>
parents:
31583
diff
changeset
|
734 |
26355
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
735 if (++conn->bosh->failed_connections == MAX_FAILED_CONNECTIONS) { |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
736 purple_connection_error_reason(conn->bosh->js->gc, |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
737 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
738 _("Unable to establish a connection with the server")); |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
739 } else { |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
740 /* No! Please! Take me back. It was me, not you! I was weak! */ |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
741 http_connection_connect(conn); |
79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents:
26354
diff
changeset
|
742 } |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
743 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
744 |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
745 void jabber_bosh_connection_connect(PurpleBOSHConnection *bosh) { |
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
746 PurpleHTTPConnection *conn = bosh->connections[0]; |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
747 |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
748 g_return_if_fail(bosh->state == BOSH_CONN_OFFLINE); |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
749 bosh->state = BOSH_CONN_BOOTING; |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
750 |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
751 http_connection_connect(conn); |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
752 } |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
753 |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
754 static void |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
755 jabber_bosh_http_connection_process(PurpleHTTPConnection *conn) |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
756 { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
757 const char *cursor; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
758 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
759 cursor = conn->read_buf->str + conn->handled_len; |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
760 |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
761 if (purple_debug_is_verbose()) |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
762 purple_debug_misc("jabber", "BOSH server sent: %s\n", cursor); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
763 |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
764 /* TODO: Chunked encoding and check response version :/ */ |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
765 if (!conn->headers_done) { |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
766 const char *content_length = purple_strcasestr(cursor, "\r\nContent-Length:"); |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
767 const char *connection = purple_strcasestr(cursor, "\r\nConnection:"); |
27013 | 768 const char *end_of_headers = strstr(cursor, "\r\n\r\n"); |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
769 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
770 /* Make sure Content-Length is in headers, not body */ |
27013 | 771 if (content_length && (!end_of_headers || content_length < end_of_headers)) { |
772 int len; | |
773 | |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
774 if (strstr(content_length, "\r\n") == NULL) |
27013 | 775 /* |
776 * The packet ends in the middle of the Content-Length line. | |
777 * We'll try again later when we have more. | |
778 */ | |
779 return; | |
780 | |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
781 len = atoi(content_length + strlen("\r\nContent-Length:")); |
27014
a8537bbcfb79
Remove trailing whitespace that has snuck in.
Paul Aurich <paul@darkrain42.org>
parents:
27013
diff
changeset
|
782 if (len == 0) |
31582
bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <paul@darkrain42.org>
parents:
31581
diff
changeset
|
783 purple_debug_warning("jabber", "Found mangled Content-Length header, or server returned 0-length response.\n"); |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
784 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
785 conn->body_len = len; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
786 } |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
787 |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
788 if (connection && (!end_of_headers || content_length < end_of_headers)) { |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
789 const char *tmp; |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
790 if (strstr(connection, "\r\n") == NULL) |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
791 return; |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
792 |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
793 |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
794 tmp = connection + strlen("\r\nConnection:"); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
795 while (*tmp && (*tmp == ' ' || *tmp == '\t')) |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
796 ++tmp; |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
797 |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
798 if (!g_ascii_strncasecmp(tmp, "close", strlen("close"))) { |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
799 conn->close = TRUE; |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
800 jabber_bosh_disable_pipelining(conn->bosh); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
801 } |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
802 } |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
803 |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
804 if (end_of_headers) { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
805 conn->headers_done = TRUE; |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
806 conn->handled_len = end_of_headers - conn->read_buf->str + 4; |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
807 cursor = end_of_headers + 4; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
808 } else { |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
809 conn->handled_len = conn->read_buf->len; |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
810 return; |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
811 } |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
812 } |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
813 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
814 /* Have we handled everything in the buffer? */ |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
815 if (conn->handled_len >= conn->read_buf->len) |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
816 return; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
817 |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
818 /* Have we read all that the Content-Length promised us? */ |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
819 if (conn->read_buf->len - conn->handled_len < conn->body_len) |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
820 return; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
821 |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
822 --conn->requests; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
823 --conn->bosh->requests; |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
824 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
825 http_received_cb(conn->read_buf->str + conn->handled_len, conn->body_len, |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
826 conn->bosh); |
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
827 |
31583
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
828 /* Connection: Close? */ |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
829 if (conn->close && conn->state == HTTP_CONN_CONNECTED) { |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
830 if (purple_debug_is_verbose()) |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
831 purple_debug_misc("jabber", "bosh (%p), server sent Connection: " |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
832 "close\n", conn); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
833 http_connection_disconnected(conn); |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
834 } |
6826925abd6d
jabber: Handle the connection: close header. Closes #13008
Paul Aurich <paul@darkrain42.org>
parents:
31582
diff
changeset
|
835 |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
836 if (conn->bosh->state == BOSH_CONN_ONLINE && |
25999
c605e5f2fc99
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents:
25998
diff
changeset
|
837 (conn->bosh->requests == 0 || conn->bosh->pending->bufused > 0)) { |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
838 purple_debug_misc("jabber", "BOSH: Sending an empty request\n"); |
26530
d4af753e0e33
Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents:
26355
diff
changeset
|
839 jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL); |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
840 } |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
841 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
842 g_string_free(conn->read_buf, TRUE); |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
843 conn->read_buf = NULL; |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
844 conn->headers_done = FALSE; |
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
845 conn->handled_len = conn->body_len = 0; |
25609
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
846 } |
5f70e13db5cc
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25608
diff
changeset
|
847 |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
848 /* |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
849 * Common code for reading, called from http_connection_read_cb_ssl and |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
850 * http_connection_read_cb. |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
851 */ |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
852 static void |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
853 http_connection_read(PurpleHTTPConnection *conn) |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
854 { |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
855 char buffer[1025]; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
856 int cnt, count = 0; |
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
857 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
858 if (!conn->read_buf) |
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
859 conn->read_buf = g_string_new(NULL); |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
860 |
27013 | 861 do { |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
862 if (conn->psc) |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
863 cnt = purple_ssl_read(conn->psc, buffer, sizeof(buffer)); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
864 else |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
865 cnt = read(conn->fd, buffer, sizeof(buffer)); |
27013 | 866 |
867 if (cnt > 0) { | |
868 count += cnt; | |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
869 g_string_append_len(conn->read_buf, buffer, cnt); |
27013 | 870 } |
871 } while (cnt > 0); | |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
872 |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
873 if (cnt == 0 || (cnt < 0 && errno != EAGAIN)) { |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
874 if (cnt < 0) |
31580
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
875 purple_debug_info("jabber", "BOSH (%p) read=%d, errno=%d, error=%s\n", |
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
876 conn, cnt, errno, g_strerror(errno)); |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
877 else |
31580
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
878 purple_debug_info("jabber", "BOSH server closed the connection (%p)\n", |
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
879 conn); |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
880 |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
881 /* |
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
882 * If the socket is closed, the processing really needs to know about |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
883 * it. Handle that now. |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
884 */ |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
885 http_connection_disconnected(conn); |
25996
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
886 |
a94b28023bf6
Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents:
25994
diff
changeset
|
887 /* Process what we do have */ |
25603
24b97b8359ff
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25602
diff
changeset
|
888 } |
25788
e7f20c859519
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents:
25787
diff
changeset
|
889 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
890 if (conn->read_buf->len > 0) |
27011
f82f3dc29f9b
Don't try to process BOSH packet if there's no data (avoid a purple_strcasestr assertion).
Paul Aurich <paul@darkrain42.org>
parents:
26826
diff
changeset
|
891 jabber_bosh_http_connection_process(conn); |
25601
15d9825a5621
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25600
diff
changeset
|
892 } |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
893 |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
894 static void |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
895 http_connection_read_cb(gpointer data, gint fd, PurpleInputCondition condition) |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
896 { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
897 PurpleHTTPConnection *conn = data; |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
898 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
899 http_connection_read(conn); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
900 } |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
901 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
902 static void |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
903 http_connection_read_cb_ssl(gpointer data, PurpleSslConnection *psc, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
904 PurpleInputCondition cond) |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
905 { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
906 PurpleHTTPConnection *conn = data; |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
907 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
908 http_connection_read(conn); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
909 } |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
910 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
911 static void |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
912 ssl_connection_established_cb(gpointer data, PurpleSslConnection *psc, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
913 PurpleInputCondition cond) |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
914 { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
915 PurpleHTTPConnection *conn = data; |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
916 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
917 purple_ssl_input_add(psc, http_connection_read_cb_ssl, conn); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
918 connection_common_established_cb(conn); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
919 } |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
920 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
921 static void |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
922 ssl_connection_error_cb(PurpleSslConnection *gsc, PurpleSslErrorType error, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
923 gpointer data) |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
924 { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
925 PurpleHTTPConnection *conn = data; |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
926 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
927 /* sslconn frees the connection on error */ |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
928 conn->psc = NULL; |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
929 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
930 purple_connection_ssl_error(conn->bosh->js->gc, error); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
931 } |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
932 |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
933 static void |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
934 connection_established_cb(gpointer data, gint source, const gchar *error) |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
935 { |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
936 PurpleHTTPConnection *conn = data; |
25814
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25813
diff
changeset
|
937 PurpleConnection *gc = conn->bosh->js->gc; |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
938 |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
939 if (source < 0) { |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
940 gchar *tmp; |
27463
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
941 tmp = g_strdup_printf(_("Unable to establish a connection with the server: %s"), |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
942 error); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
943 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
944 g_free(tmp); |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
945 return; |
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
946 } |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
947 |
25600
1cbe5a9f6efb
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25598
diff
changeset
|
948 conn->fd = source; |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
949 conn->readh = purple_input_add(conn->fd, PURPLE_INPUT_READ, |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
950 http_connection_read_cb, conn); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
951 connection_common_established_cb(conn); |
25598 | 952 } |
953 | |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
954 static void http_connection_connect(PurpleHTTPConnection *conn) |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
955 { |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
956 PurpleBOSHConnection *bosh = conn->bosh; |
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
957 PurpleConnection *gc = bosh->js->gc; |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
958 PurpleAccount *account = purple_connection_get_account(gc); |
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
959 |
27622
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
960 conn->state = HTTP_CONN_CONNECTING; |
70dcaa0b6fea
Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
961 |
26000
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
962 if (bosh->ssl) { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
963 if (purple_ssl_is_supported()) { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
964 conn->psc = purple_ssl_connect(account, bosh->host, bosh->port, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
965 ssl_connection_established_cb, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
966 ssl_connection_error_cb, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
967 conn); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
968 if (!conn->psc) { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
969 purple_connection_error_reason(gc, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
970 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
971 _("Unable to establish SSL connection")); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
972 } |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
973 } else { |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
974 purple_connection_error_reason(gc, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
975 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
976 _("SSL support unavailable")); |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
977 } |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
978 } else if (purple_proxy_connect(conn, account, bosh->host, bosh->port, |
31bb0d6e7f7e
BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents:
25999
diff
changeset
|
979 connection_established_cb, conn) == NULL) { |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
980 purple_connection_error_reason(gc, |
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
981 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
27463
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
982 _("Unable to connect")); |
25776
7de1f124f95a
Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents:
25614
diff
changeset
|
983 } |
25602
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25601
diff
changeset
|
984 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25601
diff
changeset
|
985 |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
986 static int |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
987 http_connection_do_send(PurpleHTTPConnection *conn, const char *data, int len) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
988 { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
989 int ret; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
990 |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
991 if (conn->psc) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
992 ret = purple_ssl_write(conn->psc, data, len); |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
993 else |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
994 ret = write(conn->fd, data, len); |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
995 |
31580
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
996 if (purple_debug_is_verbose()) |
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
997 purple_debug_misc("jabber", "BOSH (%p): wrote %d bytes\n", conn, ret); |
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
998 |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
999 return ret; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1000 } |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1001 |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1002 static void |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1003 http_connection_send_cb(gpointer data, gint source, PurpleInputCondition cond) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1004 { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1005 PurpleHTTPConnection *conn = data; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1006 int ret; |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
1007 int writelen = purple_circ_buffer_get_max_read(conn->write_buf); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1008 |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1009 if (writelen == 0) { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1010 purple_input_remove(conn->writeh); |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1011 conn->writeh = 0; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1012 return; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1013 } |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1014 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
1015 ret = http_connection_do_send(conn, conn->write_buf->outptr, writelen); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1016 |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1017 if (ret < 0 && errno == EAGAIN) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1018 return; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1019 else if (ret <= 0) { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1020 /* |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1021 * TODO: Handle this better. Probably requires a PurpleBOSHConnection |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1022 * buffer that stores what is "being sent" until the |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1023 * PurpleHTTPConnection reports it is fully sent. |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1024 */ |
27463
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1025 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1026 g_strerror(errno)); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1027 purple_connection_error_reason(conn->bosh->js->gc, |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1028 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
27463
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1029 tmp); |
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1030 g_free(tmp); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1031 return; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1032 } |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1033 |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
1034 purple_circ_buffer_mark_read(conn->write_buf, ret); |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1035 } |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1036 |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1037 static void |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
1038 http_connection_send_request(PurpleHTTPConnection *conn, const GString *req) |
25777
17b60b844803
Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents:
25776
diff
changeset
|
1039 { |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1040 char *data; |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1041 int ret; |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1042 size_t len; |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1043 |
28126
46e80810b095
jabber: Better inactivity timer logic.
Paul Aurich <paul@darkrain42.org>
parents:
28125
diff
changeset
|
1044 /* Sending something to the server, restart the inactivity timer */ |
30184
3ac7f10d13d4
jabber: Send whitespace keepalives every two minutes of (outgoing) silence.
Paul Aurich <paul@darkrain42.org>
parents:
29961
diff
changeset
|
1045 jabber_stream_restart_inactivity_timer(conn->bosh->js); |
28126
46e80810b095
jabber: Better inactivity timer logic.
Paul Aurich <paul@darkrain42.org>
parents:
28125
diff
changeset
|
1046 |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1047 data = g_strdup_printf("POST %s HTTP/1.1\r\n" |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1048 "Host: %s\r\n" |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1049 "User-Agent: %s\r\n" |
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1050 "Content-Encoding: text/xml; charset=utf-8\r\n" |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
1051 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n" |
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
1052 "%s", |
25993
71835e00c0fc
Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents:
25990
diff
changeset
|
1053 conn->bosh->path, conn->bosh->host, bosh_useragent, |
25997
e995540378f0
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents:
25996
diff
changeset
|
1054 req->len, req->str); |
25808
26259ee81c5b
BOSH: Fix the HTTP Post to include the actual payload.
Paul Aurich <paul@darkrain42.org>
parents:
25790
diff
changeset
|
1055 |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1056 len = strlen(data); |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1057 |
25813
828640306e31
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents:
25812
diff
changeset
|
1058 ++conn->requests; |
25990
f36a94f19db3
Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents:
25814
diff
changeset
|
1059 ++conn->bosh->requests; |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1060 |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
1061 if (purple_debug_is_unsafe() && purple_debug_is_verbose()) |
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
1062 /* Will contain passwords for SASL PLAIN and is verbose */ |
31580
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
1063 purple_debug_misc("jabber", "BOSH (%p): Sending %s\n", conn, data); |
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
1064 else if (purple_debug_is_verbose()) |
b7e2cddaac7a
jabber: Improved BOSH logging some. Refs #13008
Paul Aurich <paul@darkrain42.org>
parents:
30846
diff
changeset
|
1065 purple_debug_misc("jabber", "BOSH (%p): Sending request of " |
31581
dbd0012e72cb
jabber: \n-ize a debug message
Paul Aurich <paul@darkrain42.org>
parents:
31580
diff
changeset
|
1066 "%" G_GSIZE_FORMAT " bytes.\n", conn, len); |
28127
1ff7de15d856
jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <paul@darkrain42.org>
parents:
28126
diff
changeset
|
1067 |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1068 if (conn->writeh == 0) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1069 ret = http_connection_do_send(conn, data, len); |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1070 else { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1071 ret = -1; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1072 errno = EAGAIN; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1073 } |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1074 |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1075 if (ret < 0 && errno != EAGAIN) { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1076 /* |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1077 * TODO: Handle this better. Probably requires a PurpleBOSHConnection |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1078 * buffer that stores what is "being sent" until the |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1079 * PurpleHTTPConnection reports it is fully sent. |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1080 */ |
27463
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1081 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), |
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1082 g_strerror(errno)); |
25814
c11c14dde641
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents:
25813
diff
changeset
|
1083 purple_connection_error_reason(conn->bosh->js->gc, |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1084 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
27463
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1085 tmp); |
f541583e31bd
More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents:
27256
diff
changeset
|
1086 g_free(tmp); |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1087 return; |
26544
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1088 } else if (ret < len) { |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1089 if (ret < 0) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1090 ret = 0; |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1091 if (conn->writeh == 0) |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1092 conn->writeh = purple_input_add(conn->psc ? conn->psc->fd : conn->fd, |
e0218e4ec785
BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents:
26543
diff
changeset
|
1093 PURPLE_INPUT_WRITE, http_connection_send_cb, conn); |
28123
14e5eadff540
jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <paul@darkrain42.org>
parents:
27622
diff
changeset
|
1094 purple_circ_buffer_append(conn->write_buf, data + ret, len - ret); |
25787
592c2cf00fea
Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents:
25779
diff
changeset
|
1095 } |
25602
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25601
diff
changeset
|
1096 } |
f9322be084c4
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
25601
diff
changeset
|
1097 |