annotate libpurple/protocols/jabber/bosh.c @ 26874:76de9455154c

Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node. It causes problems (see note about ejabberd 2.0.0) and backward-compatibility should be achievable in most cases via vcard-temp:x:update.
author Paul Aurich <paul@darkrain42.org>
date Sun, 03 May 2009 06:45:38 +0000
parents 45271de9c65d
children f82f3dc29f9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25596
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
1 /*
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
3 *
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2008, Tobias Markmann <tmarkmann@googlemail.com>
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
5 *
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
10 *
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
15 *
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
19 *
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
20 */
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
21 #include "internal.h"
25999
c605e5f2fc99 Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents: 25998
diff changeset
22 #include "circbuffer.h"
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
23 #include "core.h"
25596
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
24 #include "cipher.h"
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
25 #include "debug.h"
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
26 #include "prpl.h"
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
27 #include "util.h"
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
28 #include "xmlnode.h"
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
29
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
30 #include "bosh.h"
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
31
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
32 #define MAX_HTTP_CONNECTIONS 2
26355
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
33 #define MAX_FAILED_CONNECTIONS 3
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
34
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
35 typedef struct _PurpleHTTPConnection PurpleHTTPConnection;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
36
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
37 typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
38 typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
39
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
40 static char *bosh_useragent = NULL;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
41
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
42 typedef enum {
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
43 PACKET_TERMINATE,
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
44 PACKET_STREAM_RESTART,
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
45 PACKET_NORMAL,
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
46 } PurpleBOSHPacketType;
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
47
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
48 struct _PurpleBOSHConnection {
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
49 JabberStream *js;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
50 gboolean pipelining;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
51 PurpleHTTPConnection *connections[MAX_HTTP_CONNECTIONS];
26355
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
52 unsigned short failed_connections;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
53
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
54 gboolean ready;
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
55 gboolean ssl;
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
56
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
57 /* decoded URL */
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
58 char *host;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
59 int port;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
60 char *path;
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
61
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
62 /* Must be big enough to hold 2^53 - 1 */
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
63 guint64 rid;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
64 char *sid;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
65
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
66 unsigned int inactivity_timer;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
67 int max_inactivity;
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
68 int wait;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
69
25999
c605e5f2fc99 Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents: 25998
diff changeset
70 PurpleCircBuffer *pending;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
71 int max_requests;
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
72 int requests;
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
73
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
74 PurpleBOSHConnectionConnectFunction connect_cb;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
75 PurpleBOSHConnectionReceiveFunction receive_cb;
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
76 };
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
77
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
78 struct _PurpleHTTPConnection {
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
79 PurpleBOSHConnection *bosh;
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
80 PurpleSslConnection *psc;
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
81 int fd;
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
82 guint readh;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
83 guint writeh;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
84
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
85 PurpleCircBuffer *write_buffer;
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
86
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
87 gboolean ready;
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
88 int requests; /* number of outstanding HTTP requests */
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
89
25998
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
90 GString *buf;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
91 gboolean headers_done;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
92 gsize handled_len;
349e411da2ce Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <paul@darkrain42.org>
parents: 25997
diff changeset
93 gsize body_len;
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
94
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
95 };
25596
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
96
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
97 static void http_connection_connect(PurpleHTTPConnection *conn);
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
98 static void http_connection_send_request(PurpleHTTPConnection *conn,
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
99 const GString *req);
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
100
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
101 void jabber_bosh_init(void)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
102 {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
103 GHashTable *ui_info = purple_core_get_ui_info();
25812
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
104 const char *ui_name = NULL;
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
105 const char *ui_version = NULL;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
106
25812
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
107 if (ui_info) {
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
108 ui_name = g_hash_table_lookup(ui_info, "name");
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
109 ui_version = g_hash_table_lookup(ui_info, "version");
25812
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
110 }
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
111
25812
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
112 if (ui_name)
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
113 bosh_useragent = g_strdup_printf("%s%s%s (libpurple " VERSION ")",
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
114 ui_name, ui_version ? " " : "",
8c58f31f41eb The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <paul@darkrain42.org>
parents: 25811
diff changeset
115 ui_version ? ui_version : "");
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
116 else
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
117 bosh_useragent = g_strdup("libpurple " VERSION);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
118 }
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
119
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
120 void jabber_bosh_uninit(void)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
121 {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
122 g_free(bosh_useragent);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
123 bosh_useragent = NULL;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
124 }
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
125
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
126 static PurpleHTTPConnection*
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
127 jabber_bosh_http_connection_init(PurpleBOSHConnection *bosh)
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
128 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
129 PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1);
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
130 conn->bosh = bosh;
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
131 conn->fd = -1;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
132 conn->ready = FALSE;
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
133
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
134 conn->write_buffer = purple_circ_buffer_new(0 /* default grow size */);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
135
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
136 return conn;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
137 }
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
138
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
139 static void
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
140 jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
141 {
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
142 if (conn->buf)
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
143 g_string_free(conn->buf, TRUE);
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
144
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
145 if (conn->write_buffer)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
146 purple_circ_buffer_destroy(conn->write_buffer);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
147 if (conn->readh)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
148 purple_input_remove(conn->readh);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
149 if (conn->writeh)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
150 purple_input_remove(conn->writeh);
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
151 if (conn->psc)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
152 purple_ssl_close(conn->psc);
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
153 if (conn->fd >= 0)
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
154 close(conn->fd);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
155
25994
c3c2e8b64539 Close a small race with disconnecting while establishing a connection and
Paul Aurich <paul@darkrain42.org>
parents: 25993
diff changeset
156 purple_proxy_connect_cancel_with_handle(conn);
c3c2e8b64539 Close a small race with disconnecting while establishing a connection and
Paul Aurich <paul@darkrain42.org>
parents: 25993
diff changeset
157
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
158 g_free(conn);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
159 }
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
160
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
161 PurpleBOSHConnection*
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
162 jabber_bosh_connection_init(JabberStream *js, const char *url)
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
163 {
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
164 PurpleBOSHConnection *conn;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
165 char *host, *path, *user, *passwd;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
166 int port;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
167
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
168 if (!purple_url_parse(url, &host, &port, &path, &user, &passwd)) {
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
169 purple_debug_info("jabber", "Unable to parse given URL.\n");
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
170 return NULL;
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
171 }
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
172
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
173 conn = g_new0(PurpleBOSHConnection, 1);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
174 conn->host = host;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
175 conn->port = port;
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
176 conn->path = g_strdup_printf("/%s", path);
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
177 g_free(path);
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
178 conn->pipelining = TRUE;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
179
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
180 if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
181 purple_debug_info("jabber", "Ignoring unexpected username and password "
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
182 "in BOSH URL.\n");
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
183 }
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
184
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
185 g_free(user);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
186 g_free(passwd);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
187
25602
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25601
diff changeset
188 conn->js = js;
26543
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
189
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
190 /*
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
191 * Random 64-bit integer masked off by 2^52 - 1.
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
192 *
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
193 * This should produce a random integer in the range [0, 2^52). It's
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
194 * unlikely we'll send enough packets in one session to overflow the rid.
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
195 */
43cfca2eab64 A better random number for the rid in the range [0, 2**52).
Paul Aurich <paul@darkrain42.org>
parents: 26534
diff changeset
196 conn->rid = ((guint64)g_random_int() << 32) | g_random_int();
26826
45271de9c65d Windows compilation complains (probably because it's 32-bit)
Paul Aurich <paul@darkrain42.org>
parents: 26544
diff changeset
197 conn->rid &= 0xFFFFFFFFFFFFFLL;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
198
25999
c605e5f2fc99 Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents: 25998
diff changeset
199 conn->pending = purple_circ_buffer_new(0 /* default grow size */);
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
200
25610
0a8484372312 * sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25609
diff changeset
201 conn->ready = FALSE;
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
202 if (purple_strcasestr(url, "https://") != NULL)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
203 conn->ssl = TRUE;
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
204 else
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
205 conn->ssl = FALSE;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
206
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
207 conn->connections[0] = jabber_bosh_http_connection_init(conn);
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
208
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
209 return conn;
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
210 }
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
211
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
212 void
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
213 jabber_bosh_connection_destroy(PurpleBOSHConnection *conn)
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
214 {
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
215 int i;
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
216
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
217 g_free(conn->host);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
218 g_free(conn->path);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
219
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
220 if (conn->inactivity_timer)
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
221 purple_timeout_remove(conn->inactivity_timer);
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
222
25999
c605e5f2fc99 Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents: 25998
diff changeset
223 purple_circ_buffer_destroy(conn->pending);
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
224
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
225 for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) {
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
226 if (conn->connections[i])
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
227 jabber_bosh_http_connection_destroy(conn->connections[i]);
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
228 }
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
229
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
230 g_free(conn);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
231 }
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
232
26354
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
233 gboolean jabber_bosh_connection_is_ssl(PurpleBOSHConnection *conn)
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
234 {
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
235 return conn->ssl;
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
236 }
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
237
26534
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
238 static PurpleHTTPConnection *
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
239 find_available_http_connection(PurpleBOSHConnection *conn)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
240 {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
241 int i;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
242
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
243 /* Easy solution: Does everyone involved support pipelining? Hooray! Just use
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
244 * one TCP connection! */
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
245 if (conn->pipelining)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
246 return conn->connections[0];
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
247
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
248 /* First loop, look for a connection that's ready */
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
249 for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
250 if (conn->connections[i] && conn->connections[i]->ready &&
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
251 conn->connections[i]->requests == 0)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
252 return conn->connections[i];
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
253 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
254
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
255 /* Second loop, look for one that's NULL and create a new connection */
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
256 for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
257 if (!conn->connections[i]) {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
258 conn->connections[i] = jabber_bosh_http_connection_init(conn);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
259
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
260 http_connection_connect(conn->connections[i]);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
261 return NULL;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
262 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
263 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
264
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
265 /* None available. */
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
266 return NULL;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
267 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
268
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
269 static void
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
270 jabber_bosh_connection_send(PurpleBOSHConnection *conn, PurpleBOSHPacketType type,
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
271 const char *data)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
272 {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
273 PurpleHTTPConnection *chosen;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
274 GString *packet = NULL;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
275
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
276 chosen = find_available_http_connection(conn);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
277
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
278 if (type != PACKET_NORMAL && !chosen) {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
279 /*
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
280 * For non-ordinary traffic, we don't want to 'buffer' it, so use the first
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
281 * connection.
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
282 */
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
283 chosen = conn->connections[0];
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
284
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
285 if (!chosen->ready)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
286 purple_debug_warning("jabber", "First BOSH connection wasn't ready. Bad "
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
287 "things may happen.\n");
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
288 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
289
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
290 if (type == PACKET_NORMAL && (!chosen ||
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
291 (conn->max_requests > 0 && conn->requests == conn->max_requests))) {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
292 /*
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
293 * For normal data, send up to max_requests requests at a time or there is no
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
294 * connection ready (likely, we're currently opening a second connection and
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
295 * will send these packets when connected).
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
296 */
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
297 if (data) {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
298 int len = data ? strlen(data) : 0;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
299 purple_circ_buffer_append(conn->pending, data, len);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
300 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
301 return;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
302 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
303
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
304 packet = g_string_new("");
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
305
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
306 g_string_printf(packet, "<body "
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
307 "rid='%" G_GUINT64_FORMAT "' "
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
308 "sid='%s' "
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
309 "to='%s' "
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
310 "xml:lang='en' "
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
311 "xmlns='http://jabber.org/protocol/httpbind' "
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
312 "xmlns:xmpp='urn:xmpp:xbosh'",
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
313 ++conn->rid,
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
314 conn->sid,
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
315 conn->js->user->domain);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
316
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
317 if (type == PACKET_STREAM_RESTART)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
318 packet = g_string_append(packet, " xmpp:restart='true'/>");
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
319 else {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
320 gsize read_amt;
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
321 if (type == PACKET_TERMINATE)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
322 packet = g_string_append(packet, " type='terminate'");
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
323
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
324 packet = g_string_append_c(packet, '>');
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
325
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
326 while ((read_amt = purple_circ_buffer_get_max_read(conn->pending)) > 0) {
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
327 packet = g_string_append_len(packet, conn->pending->outptr, read_amt);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
328 purple_circ_buffer_mark_read(conn->pending, read_amt);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
329 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
330
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
331 if (data)
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
332 packet = g_string_append(packet, data);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
333 packet = g_string_append(packet, "</body>");
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
334 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
335
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
336 http_connection_send_request(chosen, packet);
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
337 }
5172ebcc8673 Reorder functions to remove prototypes
Paul Aurich <paul@darkrain42.org>
parents: 26531
diff changeset
338
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
339 void jabber_bosh_connection_close(PurpleBOSHConnection *conn)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
340 {
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
341 jabber_bosh_connection_send(conn, PACKET_TERMINATE, NULL);
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
342 }
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
343
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
344 static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) {
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
345 jabber_bosh_connection_send(conn, PACKET_STREAM_RESTART, NULL);
25608
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
346 }
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
347
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
348 static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node) {
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
349 const char *type;
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
350
25612
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
351 type = xmlnode_get_attrib(node, "type");
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
352
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
353 if (type != NULL && !strcmp(type, "terminate")) {
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
354 conn->ready = FALSE;
25613
480736bfcf45 * removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25612
diff changeset
355 purple_connection_error_reason (conn->js->gc,
480736bfcf45 * removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25612
diff changeset
356 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
357 _("The BOSH connection manager terminated your session."));
25612
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
358 return TRUE;
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
359 }
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
360 return FALSE;
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
361 }
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
362
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
363 static gboolean
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
364 bosh_inactivity_cb(gpointer data)
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
365 {
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
366 PurpleBOSHConnection *bosh = data;
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
367
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
368 jabber_bosh_connection_send(bosh, PACKET_NORMAL, NULL);
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
369 return TRUE;
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
370 }
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
371
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
372 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) {
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
373 xmlnode *child;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
374 JabberStream *js = conn->js;
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
375
25810
7856dccb02fb BOSH: Another g_return_if_fail that is backward
Paul Aurich <paul@darkrain42.org>
parents: 25809
diff changeset
376 g_return_if_fail(node != NULL);
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
377 if (jabber_bosh_connection_error_check(conn, node))
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
378 return;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
379
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
380 child = node->child;
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
381 while (child != NULL) {
25790
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
382 /* jabber_process_packet might free child */
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
383 xmlnode *next = child->next;
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
384 if (child->type == XMLNODE_TYPE_TAG) {
25790
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
385 if (!strcmp(child->name, "iq")) {
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
386 if (xmlnode_get_child(child, "session"))
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
387 conn->ready = TRUE;
25612
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25610
diff changeset
388 }
25790
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
389
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
390 jabber_process_packet(js, &child);
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
391 }
25790
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
392
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
393 child = next;
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
394 }
25608
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
395 }
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
396
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
397 static void auth_response_cb(PurpleBOSHConnection *conn, xmlnode *node) {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
398 xmlnode *child;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
399
25790
4e624cc0c4a5 Jabber BOSH: memory management fixes
Paul Aurich <paul@darkrain42.org>
parents: 25789
diff changeset
400 g_return_if_fail(node != NULL);
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
401 if (jabber_bosh_connection_error_check(conn, node))
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
402 return;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
403
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
404 child = node->child;
25608
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
405 while(child != NULL && child->type != XMLNODE_TYPE_TAG) {
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
406 child = child->next;
25608
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
407 }
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
408
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
409 /* We're only expecting one XML node here, so only process the first one */
25608
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
410 if (child != NULL && child->type == XMLNODE_TYPE_TAG) {
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
411 JabberStream *js = conn->js;
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
412 if (!strcmp(child->name, "success")) {
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
413 jabber_bosh_connection_stream_restart(conn);
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
414 jabber_process_packet(js, &child);
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
415 conn->receive_cb = jabber_bosh_connection_received;
25608
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
416 } else {
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
417 js->state = JABBER_STREAM_AUTHENTICATING;
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
418 jabber_process_packet(js, &child);
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25607
diff changeset
419 }
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
420 } else {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
421 purple_debug_warning("jabber", "Received unexepcted empty BOSH packet.\n");
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
422 }
25607
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
423 }
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
424
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
425 static void boot_response_cb(PurpleBOSHConnection *conn, xmlnode *node) {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
426 const char *sid, *version;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
427 const char *inactivity, *requests;
25789
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
428 xmlnode *packet;
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
429
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
430 g_return_if_fail(node != NULL);
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
431 if (jabber_bosh_connection_error_check(conn, node))
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
432 return;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
433
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
434 sid = xmlnode_get_attrib(node, "sid");
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
435 version = xmlnode_get_attrib(node, "ver");
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
436
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
437 inactivity = xmlnode_get_attrib(node, "inactivity");
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
438 requests = xmlnode_get_attrib(node, "requests");
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
439
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
440 if (sid) {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
441 conn->sid = g_strdup(sid);
25607
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
442 } else {
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
443 purple_connection_error_reason(conn->js->gc,
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
444 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
445 _("No session ID given"));
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
446 return;
25607
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
447 }
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
448
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
449 if (version) {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
450 const char *dot = strstr(version, ".");
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
451 int major = atoi(version);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
452 int minor = atoi(dot + 1);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
453
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
454 purple_debug_info("jabber", "BOSH connection manager version %s\n", version);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
455
25789
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
456 if (major != 1 || minor < 6) {
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
457 purple_connection_error_reason(conn->js->gc,
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
458 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
459 _("Unsupported version of BOSH protocol"));
25789
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
460 return;
25607
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
461 }
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
462 } else {
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
463 purple_debug_info("jabber", "Missing version in BOSH initiation\n");
25607
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
464 }
25789
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
465
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
466 if (inactivity) {
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
467 conn->max_inactivity = atoi(inactivity);
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
468 if (conn->max_inactivity <= 2) {
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
469 purple_debug_warning("jabber", "Ignoring bogusly small inactivity: %s\n",
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
470 inactivity);
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
471 conn->max_inactivity = 0;
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
472 } else {
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
473 /* TODO: Integrate this with jabber.c keepalive checks... */
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
474 conn->inactivity_timer = purple_timeout_add_seconds(
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
475 conn->max_inactivity - 2 /* rounding */, bosh_inactivity_cb,
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
476 conn);
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
477 }
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
478 }
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
479
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
480 if (requests)
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
481 conn->max_requests = atoi(requests);
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
482
25789
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
483 /* FIXME: Depending on receiving features might break with some hosts */
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
484 packet = xmlnode_get_child(node, "features");
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
485 conn->js->use_bosh = TRUE;
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
486 conn->receive_cb = auth_response_cb;
b78c8ab5de2b Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <paul@darkrain42.org>
parents: 25788
diff changeset
487 jabber_stream_features_parse(conn->js, packet);
25605
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25604
diff changeset
488 }
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25604
diff changeset
489
25601
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25600
diff changeset
490 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) {
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
491 GString *buf = g_string_new("");
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
492
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
493 g_string_printf(buf, "<body content='text/xml; charset=utf-8' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
494 "secure='true' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
495 "to='%s' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
496 "xml:lang='en' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
497 "xmpp:version='1.0' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
498 "ver='1.6' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
499 "xmlns:xmpp='urn:xmpp:bosh' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
500 "rid='%" G_GUINT64_FORMAT "' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
501 /* TODO: This should be adjusted/adjustable automatically according to
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
502 * realtime network behavior */
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
503 "wait='60' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
504 "hold='1' "
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
505 "xmlns='http://jabber.org/protocol/httpbind'/>",
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
506 conn->js->user->domain,
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
507 ++conn->rid);
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
508
25779
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25778
diff changeset
509 conn->receive_cb = boot_response_cb;
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
510 http_connection_send_request(conn->connections[0], buf);
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
511 g_string_free(buf, TRUE);
25602
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25601
diff changeset
512 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25601
diff changeset
513
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
514 static void
25814
c11c14dde641 Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents: 25813
diff changeset
515 http_received_cb(const char *data, int len, PurpleBOSHConnection *conn)
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
516 {
26355
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
517 if (conn->failed_connections)
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
518 /* We've got some data, so reset the number of failed connections */
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
519 conn->failed_connections = 0;
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
520
25605
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25604
diff changeset
521 if (conn->receive_cb) {
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
522 xmlnode *node = xmlnode_from_str(data, len);
26531
345165fc51b6 BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents: 26530
diff changeset
523
345165fc51b6 BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents: 26530
diff changeset
524 purple_debug_info("jabber", "RecvBOSH %s(%d): %s\n",
345165fc51b6 BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents: 26530
diff changeset
525 conn->ssl ? "(ssl)" : "", len, data);
345165fc51b6 BOSH: Print out the received data (similar to the standard XMPP method,
Paul Aurich <paul@darkrain42.org>
parents: 26530
diff changeset
526
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
527 if (node) {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
528 conn->receive_cb(conn, node);
25614
94ccccab4e98 * free xmlnodes after bosh receive callback is called
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25613
diff changeset
529 xmlnode_free(node);
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
530 } else {
25811
bf7338765863 BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents: 25810
diff changeset
531 purple_debug_warning("jabber", "BOSH: Received invalid XML\n");
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
532 }
25811
bf7338765863 BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents: 25810
diff changeset
533 } else {
bf7338765863 BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents: 25810
diff changeset
534 g_return_if_reached();
bf7338765863 BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents: 25810
diff changeset
535 }
25601
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25600
diff changeset
536 }
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25600
diff changeset
537
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
538 void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn,
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
539 const char *data)
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
540 {
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
541 jabber_bosh_connection_send(conn, PACKET_NORMAL, data);
25607
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
542 }
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25606
diff changeset
543
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
544 static void
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
545 connection_common_established_cb(PurpleHTTPConnection *conn)
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
546 {
25996
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
547 /* Indicate we're ready and reset some variables */
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
548 conn->ready = TRUE;
25996
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
549 conn->requests = 0;
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
550 if (conn->buf) {
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
551 g_string_free(conn->buf, TRUE);
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
552 conn->buf = NULL;
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
553 }
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
554 conn->headers_done = FALSE;
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
555 conn->handled_len = conn->body_len = 0;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
556
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
557 if (conn->bosh->ready) {
25610
0a8484372312 * sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25609
diff changeset
558 purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n");
25999
c605e5f2fc99 Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents: 25998
diff changeset
559 if (conn->bosh->pending->bufused > 0) {
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
560 /* Send the pending data */
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
561 jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL);
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
562 }
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
563 #if 0
25814
c11c14dde641 Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents: 25813
diff changeset
564 conn->bosh->receive_cb = jabber_bosh_connection_received;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
565 if (conn->bosh->connect_cb)
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
566 conn->bosh->connect_cb(conn->bosh);
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
567 #endif
25814
c11c14dde641 Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents: 25813
diff changeset
568 } else
c11c14dde641 Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents: 25813
diff changeset
569 jabber_bosh_connection_boot(conn->bosh);
25610
0a8484372312 * sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25609
diff changeset
570 }
0a8484372312 * sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25609
diff changeset
571
25778
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
572 void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25777
diff changeset
573 {
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
574 jabber_bosh_connection_send(conn, PACKET_NORMAL, NULL);
25610
0a8484372312 * sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25609
diff changeset
575 }
0a8484372312 * sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25609
diff changeset
576
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
577 static void http_connection_disconnected(PurpleHTTPConnection *conn)
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
578 {
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
579 /*
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
580 * Well, then. Fine! I never liked you anyway, server! I was cheating on you
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
581 * with AIM!
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
582 */
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
583 conn->ready = FALSE;
26354
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
584 if (conn->psc) {
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
585 purple_ssl_close(conn->psc);
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
586 conn->psc = NULL;
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
587 } else if (conn->fd >= 0) {
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
588 close(conn->fd);
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
589 conn->fd = -1;
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
590 }
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
591
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
592 if (conn->readh) {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
593 purple_input_remove(conn->readh);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
594 conn->readh = 0;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
595 }
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
596
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
597 if (conn->writeh) {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
598 purple_input_remove(conn->writeh);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
599 conn->writeh = 0;
26354
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
600 }
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
601
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
602 if (conn->bosh->pipelining)
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
603 /* Hmmmm, fall back to multiple connections */
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
604 conn->bosh->pipelining = FALSE;
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
605
26355
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
606 if (++conn->bosh->failed_connections == MAX_FAILED_CONNECTIONS) {
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
607 purple_connection_error_reason(conn->bosh->js->gc,
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
608 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
609 _("Unable to establish a connection with the server"));
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
610 } else {
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
611 /* No! Please! Take me back. It was me, not you! I was weak! */
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
612 http_connection_connect(conn);
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
613 }
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
614 }
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
615
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
616 void jabber_bosh_connection_connect(PurpleBOSHConnection *bosh) {
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
617 PurpleHTTPConnection *conn = bosh->connections[0];
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
618 http_connection_connect(conn);
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
619 }
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
620
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
621 static void
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
622 jabber_bosh_http_connection_process(PurpleHTTPConnection *conn)
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
623 {
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
624 const char *cursor;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
625
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
626 cursor = conn->buf->str + conn->handled_len;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
627
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
628 if (!conn->headers_done) {
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
629 const char *content_length = purple_strcasestr(cursor, "\r\nContent-Length");
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
630 const char *end_of_headers = purple_strcasestr(cursor, "\r\n\r\n");
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
631
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
632 /* Make sure Content-Length is in headers, not body */
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
633 if (content_length && content_length < end_of_headers) {
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
634 char *sep = strstr(content_length, ": ");
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
635 int len = atoi(sep + 2);
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
636 if (len == 0)
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
637 purple_debug_warning("jabber", "Found mangled Content-Length header.\n");
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
638
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
639 conn->body_len = len;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
640 }
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
641
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
642 if (end_of_headers) {
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
643 conn->headers_done = TRUE;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
644 conn->handled_len = end_of_headers - conn->buf->str + 4;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
645 cursor = end_of_headers + 4;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
646 } else {
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
647 conn->handled_len = conn->buf->len;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
648 return;
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
649 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
650 }
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
651
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
652 /* Have we handled everything in the buffer? */
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
653 if (conn->handled_len >= conn->buf->len)
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
654 return;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
655
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
656 /* Have we read all that the Content-Length promised us? */
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
657 if (conn->buf->len - conn->handled_len < conn->body_len)
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
658 return;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
659
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
660 --conn->requests;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
661 --conn->bosh->requests;
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
662
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
663 http_received_cb(conn->buf->str + conn->handled_len, conn->body_len,
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
664 conn->bosh);
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
665
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
666 if (conn->bosh->ready &&
25999
c605e5f2fc99 Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <paul@darkrain42.org>
parents: 25998
diff changeset
667 (conn->bosh->requests == 0 || conn->bosh->pending->bufused > 0)) {
26530
d4af753e0e33 Pass all messages to BOSH as text, so they pass through the sending-text
Paul Aurich <paul@darkrain42.org>
parents: 26355
diff changeset
668 jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL);
25811
bf7338765863 BOSH: Fix an off-by-one g_memdup that was missing the null terminator.
Paul Aurich <paul@darkrain42.org>
parents: 25810
diff changeset
669 purple_debug_misc("jabber", "BOSH: Sending an empty request\n");
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
670 }
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
671
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
672 g_string_free(conn->buf, TRUE);
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
673 conn->buf = NULL;
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
674 conn->headers_done = FALSE;
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
675 conn->handled_len = conn->body_len = 0;
25609
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
676 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25608
diff changeset
677
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
678 /*
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
679 * Common code for reading, called from http_connection_read_cb_ssl and
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
680 * http_connection_read_cb.
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
681 */
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
682 static void
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
683 http_connection_read(PurpleHTTPConnection *conn)
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
684 {
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
685 char buffer[1025];
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
686 int cnt, count = 0;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
687
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
688 if (!conn->buf)
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
689 conn->buf = g_string_new("");
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
690
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
691 /* Read once to prime cnt before the loop */
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
692 if (conn->psc)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
693 cnt = purple_ssl_read(conn->psc, buffer, sizeof(buffer));
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
694 else
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
695 cnt = read(conn->fd, buffer, sizeof(buffer));
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
696 while (cnt > 0) {
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
697 count += cnt;
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
698 g_string_append_len(conn->buf, buffer, cnt);
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
699
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
700 if (conn->psc)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
701 cnt = purple_ssl_read(conn->psc, buffer, sizeof(buffer));
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
702 else
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
703 cnt = read(conn->fd, buffer, sizeof(buffer));
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
704 }
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
705
25996
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
706 if (cnt == 0 || (cnt < 0 && errno != EAGAIN)) {
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
707 if (cnt < 0)
25996
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
708 purple_debug_info("jabber", "bosh read=%d, errno=%d\n", cnt, errno);
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
709 else
26354
fcee93c74230 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <paul@darkrain42.org>
parents: 26000
diff changeset
710 purple_debug_info("jabber", "bosh server closed the connection\n");
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
711
25996
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
712 /*
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
713 * If the socket is closed, the processing really needs to know about
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
714 * it. Handle that now.
25996
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
715 */
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
716 http_connection_disconnected(conn);
25996
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
717
a94b28023bf6 Clean up BOSH reading and disconnection handling.
Paul Aurich <paul@darkrain42.org>
parents: 25994
diff changeset
718 /* Process what we do have */
25603
24b97b8359ff * preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25602
diff changeset
719 }
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
720
26355
79ca1cf55d9d Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <paul@darkrain42.org>
parents: 26354
diff changeset
721
25788
e7f20c859519 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <paul@darkrain42.org>
parents: 25787
diff changeset
722 jabber_bosh_http_connection_process(conn);
25601
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25600
diff changeset
723 }
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
724
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
725 static void
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
726 http_connection_read_cb(gpointer data, gint fd, PurpleInputCondition condition)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
727 {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
728 PurpleHTTPConnection *conn = data;
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
729
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
730 http_connection_read(conn);
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
731 }
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
732
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
733 static void
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
734 http_connection_read_cb_ssl(gpointer data, PurpleSslConnection *psc,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
735 PurpleInputCondition cond)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
736 {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
737 PurpleHTTPConnection *conn = data;
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
738
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
739 http_connection_read(conn);
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
740 }
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
741
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
742 static void
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
743 ssl_connection_established_cb(gpointer data, PurpleSslConnection *psc,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
744 PurpleInputCondition cond)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
745 {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
746 PurpleHTTPConnection *conn = data;
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
747
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
748 purple_ssl_input_add(psc, http_connection_read_cb_ssl, conn);
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
749 connection_common_established_cb(conn);
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
750 }
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
751
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
752 static void
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
753 ssl_connection_error_cb(PurpleSslConnection *gsc, PurpleSslErrorType error,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
754 gpointer data)
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
755 {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
756 PurpleHTTPConnection *conn = data;
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
757
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
758 /* sslconn frees the connection on error */
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
759 conn->psc = NULL;
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
760
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
761 purple_connection_ssl_error(conn->bosh->js->gc, error);
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
762 }
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
763
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
764 static void
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
765 connection_established_cb(gpointer data, gint source, const gchar *error)
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
766 {
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
767 PurpleHTTPConnection *conn = data;
25814
c11c14dde641 Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents: 25813
diff changeset
768 PurpleConnection *gc = conn->bosh->js->gc;
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
769
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
770 if (source < 0) {
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
771 gchar *tmp;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
772 tmp = g_strdup_printf(_("Could not establish a connection with the server:\n%s"),
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
773 error);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
774 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
775 g_free(tmp);
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
776 return;
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
777 }
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
778
25600
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25598
diff changeset
779 conn->fd = source;
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
780 conn->readh = purple_input_add(conn->fd, PURPLE_INPUT_READ,
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
781 http_connection_read_cb, conn);
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
782 connection_common_established_cb(conn);
25598
b238da95f39a * some refactoring
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25596
diff changeset
783 }
b238da95f39a * some refactoring
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25596
diff changeset
784
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
785 static void http_connection_connect(PurpleHTTPConnection *conn)
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
786 {
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
787 PurpleBOSHConnection *bosh = conn->bosh;
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
788 PurpleConnection *gc = bosh->js->gc;
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
789 PurpleAccount *account = purple_connection_get_account(gc);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
790
26000
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
791 if (bosh->ssl) {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
792 if (purple_ssl_is_supported()) {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
793 conn->psc = purple_ssl_connect(account, bosh->host, bosh->port,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
794 ssl_connection_established_cb,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
795 ssl_connection_error_cb,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
796 conn);
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
797 if (!conn->psc) {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
798 purple_connection_error_reason(gc,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
799 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
800 _("Unable to establish SSL connection"));
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
801 }
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
802 } else {
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
803 purple_connection_error_reason(gc,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
804 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
805 _("SSL support unavailable"));
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
806 }
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
807 } else if (purple_proxy_connect(conn, account, bosh->host, bosh->port,
31bb0d6e7f7e BOSH: Support HTTPS connections to the connection manager
Paul Aurich <paul@darkrain42.org>
parents: 25999
diff changeset
808 connection_established_cb, conn) == NULL) {
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
809 purple_connection_error_reason(gc,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
810 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
811 _("Unable to create socket"));
25776
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25614
diff changeset
812 }
25602
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25601
diff changeset
813 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25601
diff changeset
814
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
815 static int
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
816 http_connection_do_send(PurpleHTTPConnection *conn, const char *data, int len)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
817 {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
818 int ret;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
819
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
820 if (conn->psc)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
821 ret = purple_ssl_write(conn->psc, data, len);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
822 else
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
823 ret = write(conn->fd, data, len);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
824
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
825 return ret;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
826 }
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
827
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
828 static void
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
829 http_connection_send_cb(gpointer data, gint source, PurpleInputCondition cond)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
830 {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
831 PurpleHTTPConnection *conn = data;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
832 int ret;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
833 int writelen = purple_circ_buffer_get_max_read(conn->write_buffer);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
834
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
835 if (writelen == 0) {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
836 purple_input_remove(conn->writeh);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
837 conn->writeh = 0;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
838 return;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
839 }
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
840
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
841 ret = http_connection_do_send(conn, conn->write_buffer->outptr, writelen);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
842
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
843 if (ret < 0 && errno == EAGAIN)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
844 return;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
845 else if (ret <= 0) {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
846 /*
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
847 * TODO: Handle this better. Probably requires a PurpleBOSHConnection
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
848 * buffer that stores what is "being sent" until the
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
849 * PurpleHTTPConnection reports it is fully sent.
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
850 */
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
851 purple_connection_error_reason(conn->bosh->js->gc,
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
852 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
853 _("Write error"));
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
854 return;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
855 }
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
856
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
857 purple_circ_buffer_mark_read(conn->write_buffer, ret);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
858 }
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
859
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
860 static void
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
861 http_connection_send_request(PurpleHTTPConnection *conn, const GString *req)
25777
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25776
diff changeset
862 {
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
863 char *data;
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
864 int ret;
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
865 size_t len;
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
866
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
867 data = g_strdup_printf("POST %s HTTP/1.1\r\n"
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
868 "Host: %s\r\n"
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
869 "User-Agent: %s\r\n"
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
870 "Content-Encoding: text/xml; charset=utf-8\r\n"
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
871 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n"
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
872 "%s",
25993
71835e00c0fc Rename a few functions and drop some data members.
Paul Aurich <paul@darkrain42.org>
parents: 25990
diff changeset
873 conn->bosh->path, conn->bosh->host, bosh_useragent,
25997
e995540378f0 Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <paul@darkrain42.org>
parents: 25996
diff changeset
874 req->len, req->str);
25808
26259ee81c5b BOSH: Fix the HTTP Post to include the actual payload.
Paul Aurich <paul@darkrain42.org>
parents: 25790
diff changeset
875
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
876 len = strlen(data);
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
877
25813
828640306e31 Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <paul@darkrain42.org>
parents: 25812
diff changeset
878 ++conn->requests;
25990
f36a94f19db3 Restore BOSH to a more-or-less working state.
Paul Aurich <paul@darkrain42.org>
parents: 25814
diff changeset
879 ++conn->bosh->requests;
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
880
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
881 if (conn->writeh == 0)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
882 ret = http_connection_do_send(conn, data, len);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
883 else {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
884 ret = -1;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
885 errno = EAGAIN;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
886 }
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
887
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
888 if (ret < 0 && errno != EAGAIN) {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
889 /*
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
890 * TODO: Handle this better. Probably requires a PurpleBOSHConnection
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
891 * buffer that stores what is "being sent" until the
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
892 * PurpleHTTPConnection reports it is fully sent.
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
893 */
25814
c11c14dde641 Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <paul@darkrain42.org>
parents: 25813
diff changeset
894 purple_connection_error_reason(conn->bosh->js->gc,
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
895 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
896 _("Write error"));
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
897 return;
26544
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
898 } else if (ret < len) {
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
899 if (ret < 0)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
900 ret = 0;
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
901 if (conn->writeh == 0)
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
902 conn->writeh = purple_input_add(conn->psc ? conn->psc->fd : conn->fd,
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
903 PURPLE_INPUT_WRITE, http_connection_send_cb, conn);
e0218e4ec785 BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <paul@darkrain42.org>
parents: 26543
diff changeset
904 purple_circ_buffer_append(conn->write_buffer, data + ret, len - ret);
25787
592c2cf00fea Jabber BOSH: Store less for each Request/Response
Paul Aurich <paul@darkrain42.org>
parents: 25779
diff changeset
905 }
25602
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25601
diff changeset
906 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25601
diff changeset
907