libpurple/protocols/jabber/bosh.c

Wed, 11 May 2011 05:04:43 +0000

author
Paul Aurich <darkrain42@pidgin.im>
date
Wed, 11 May 2011 05:04:43 +0000
changeset 31804
847a13d5d3bb
parent 31796
76b8a4f47cba
child 32157
39ba2e2492ee
child 33770
6625cbf09e08
permissions
-rw-r--r--

Get rid of a few other dead variables.

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

mercurial