libpurple/protocols/jabber/bosh.c

Mon, 04 Nov 2019 01:18:24 +0000

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 04 Nov 2019 01:18:24 +0000
changeset 40112
52c9656e40ed
parent 40101
ac21110b72db
parent 40103
0d8e52078bc7
child 40312
956745ff3ee8
permissions
-rw-r--r--

Merged in default (pull request #617)

Convert XMPP stuff to GIO

Approved-by: Gary Kramlich

23607
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
1 /*
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
3 *
28322
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28079
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28079
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28079
diff changeset
6 * source distribution.
23607
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
7 *
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
12 *
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
17 *
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23607
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
21 *
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
22 */
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
23 #include "internal.h"
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
24 #include "core.h"
23607
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
25 #include "debug.h"
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
26
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
27 #include <libsoup/soup.h>
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
28
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
29 #include "bosh.h"
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
30
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
31 /*
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
32 TODO: test, what happens, if the http server (BOSH server) doesn't support
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
33 keep-alive (sends connection: close).
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
34 */
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
35
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
36 #define JABBER_BOSH_SEND_DELAY 250
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
37
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
38 #define JABBER_BOSH_TIMEOUT 10
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
39
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
40 static gchar *jabber_bosh_useragent = NULL;
28062
f743d255c355 jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <darkrain42@pidgin.im>
parents: 27811
diff changeset
41
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
42 struct _PurpleJabberBOSHConnection {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
43 JabberStream *js;
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
44 SoupSession *payload_reqs;
28062
f743d255c355 jabber: Re-order the BOSH structs and normalize the buffer names.
Paul Aurich <darkrain42@pidgin.im>
parents: 27811
diff changeset
45
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
46 gchar *url;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
47 gboolean is_ssl;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
48 gboolean is_terminating;
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
49
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
50 gchar *sid;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
51 guint64 rid; /* Must be big enough to hold 2^53 - 1 */
26083
e716012de66e Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents: 26082
diff changeset
52
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
53 GString *send_buff;
28072
208dfa375b79 jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <darkrain42@pidgin.im>
parents: 28066
diff changeset
54 guint send_timer;
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
55 };
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
56
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
57 static SoupMessage *jabber_bosh_connection_http_request_new(
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
58 PurpleJabberBOSHConnection *conn, const GString *data);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
59 static void
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
60 jabber_bosh_connection_session_create(PurpleJabberBOSHConnection *conn);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
61 static void
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
62 jabber_bosh_connection_send_now(PurpleJabberBOSHConnection *conn);
23607
bc82598d3798 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
63
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
64 void
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
65 jabber_bosh_init(void)
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
66 {
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
67 GHashTable *ui_info = purple_core_get_ui_info();
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
68 const gchar *ui_name = NULL;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
69 const gchar *ui_version = NULL;
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
70
25487
00e94f044205 The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <darkrain42@pidgin.im>
parents: 25486
diff changeset
71 if (ui_info) {
00e94f044205 The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <darkrain42@pidgin.im>
parents: 25486
diff changeset
72 ui_name = g_hash_table_lookup(ui_info, "name");
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
73 ui_version = g_hash_table_lookup(ui_info, "version");
25487
00e94f044205 The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <darkrain42@pidgin.im>
parents: 25486
diff changeset
74 }
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
75
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
76 if (ui_name) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
77 jabber_bosh_useragent = g_strdup_printf(
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
78 "%s%s%s (libpurple " VERSION ")", ui_name,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
79 ui_version ? " " : "", ui_version ? ui_version : "");
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
80 } else
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
81 jabber_bosh_useragent = g_strdup("libpurple " VERSION);
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
82 }
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
83
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
84 void jabber_bosh_uninit(void)
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
85 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
86 g_free(jabber_bosh_useragent);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
87 jabber_bosh_useragent = NULL;
24874
33902e1daba1 Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents: 24873
diff changeset
88 }
33902e1daba1 Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents: 24873
diff changeset
89
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
90 PurpleJabberBOSHConnection*
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
91 jabber_bosh_connection_new(JabberStream *js, const gchar *url)
24874
33902e1daba1 Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents: 24873
diff changeset
92 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
93 PurpleJabberBOSHConnection *conn;
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
94 PurpleAccount *account;
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
95 GProxyResolver *resolver;
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
96 GError *error = NULL;
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
97 SoupURI *url_p;
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
98
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
99 account = purple_connection_get_account(js->gc);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
100 resolver = purple_proxy_get_proxy_resolver(account, &error);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
101 if (resolver == NULL) {
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
102 purple_debug_error("jabber-bosh",
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
103 "Unable to get account proxy resolver: %s",
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
104 error->message);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
105 g_error_free(error);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
106 return NULL;
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
107 }
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
108
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
109 url_p = soup_uri_new(url);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
110 if (!SOUP_URI_VALID_FOR_HTTP(url_p)) {
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
111 purple_debug_error("jabber-bosh", "Unable to parse given BOSH URL: %s",
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
112 url);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
113 g_object_unref(resolver);
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
114 return NULL;
23611
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
115 }
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
116
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
117 conn = g_new0(PurpleJabberBOSHConnection, 1);
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
118 conn->payload_reqs = soup_session_new_with_options(
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
119 SOUP_SESSION_PROXY_RESOLVER, resolver, SOUP_SESSION_TIMEOUT,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
120 JABBER_BOSH_TIMEOUT + 2, SOUP_SESSION_USER_AGENT,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
121 jabber_bosh_useragent, NULL);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
122 conn->url = g_strdup(url);
23613
1da7c5cbcc54 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23612
diff changeset
123 conn->js = js;
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
124 conn->is_ssl = (url_p->scheme == SOUP_URI_SCHEME_HTTPS);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
125 conn->send_buff = g_string_new(NULL);
26672
d424e92111b5 A better random number for the rid in the range [0, 2**52).
Paul Aurich <darkrain42@pidgin.im>
parents: 26664
diff changeset
126
d424e92111b5 A better random number for the rid in the range [0, 2**52).
Paul Aurich <darkrain42@pidgin.im>
parents: 26664
diff changeset
127 /*
d424e92111b5 A better random number for the rid in the range [0, 2**52).
Paul Aurich <darkrain42@pidgin.im>
parents: 26664
diff changeset
128 * Random 64-bit integer masked off by 2^52 - 1.
d424e92111b5 A better random number for the rid in the range [0, 2**52).
Paul Aurich <darkrain42@pidgin.im>
parents: 26664
diff changeset
129 *
d424e92111b5 A better random number for the rid in the range [0, 2**52).
Paul Aurich <darkrain42@pidgin.im>
parents: 26664
diff changeset
130 * This should produce a random integer in the range [0, 2^52). It's
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
131 * unlikely we'll send enough packets in one session to overflow the
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
132 * rid.
26672
d424e92111b5 A better random number for the rid in the range [0, 2**52).
Paul Aurich <darkrain42@pidgin.im>
parents: 26664
diff changeset
133 */
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
134 conn->rid = (((guint64)g_random_int() << 32) | g_random_int());
26967
b52a6393cc13 Windows compilation complains (probably because it's 32-bit)
Paul Aurich <darkrain42@pidgin.im>
parents: 26673
diff changeset
135 conn->rid &= 0xFFFFFFFFFFFFFLL;
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
136
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
137 soup_uri_free(url_p);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
138 g_object_unref(resolver);
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
139
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
140 jabber_bosh_connection_session_create(conn);
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
141
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
142 return conn;
23611
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
143 }
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
144
24874
33902e1daba1 Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents: 24873
diff changeset
145 void
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
146 jabber_bosh_connection_destroy(PurpleJabberBOSHConnection *conn)
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
147 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
148 if (conn == NULL || conn->is_terminating)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
149 return;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
150 conn->is_terminating = TRUE;
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
151
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
152 if (conn->sid != NULL) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
153 purple_debug_info("jabber-bosh",
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
154 "Terminating a session for %p\n", conn);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
155 jabber_bosh_connection_send_now(conn);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
156 }
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
157
28072
208dfa375b79 jabber: Add a BOSH send timer (queue up stanzas), fixes connecting to Prosody
Paul Aurich <darkrain42@pidgin.im>
parents: 28066
diff changeset
158 if (conn->send_timer)
38433
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
159 g_source_remove(conn->send_timer);
26082
7e3952f2713d Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents: 26081
diff changeset
160
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
161 soup_session_abort(conn->payload_reqs);
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
162
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
163 g_clear_object(&conn->payload_reqs);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
164 g_string_free(conn->send_buff, TRUE);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
165 conn->send_buff = NULL;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
166
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
167 g_free(conn->sid);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
168 conn->sid = NULL;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
169 g_free(conn->url);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
170 conn->url = NULL;
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
171
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
172 g_free(conn);
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
173 }
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
174
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
175 gboolean
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
176 jabber_bosh_connection_is_ssl(const PurpleJabberBOSHConnection *conn)
26533
5c74696c34d1 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <darkrain42@pidgin.im>
parents: 26085
diff changeset
177 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
178 return conn->is_ssl;
26533
5c74696c34d1 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <darkrain42@pidgin.im>
parents: 26085
diff changeset
179 }
5c74696c34d1 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <darkrain42@pidgin.im>
parents: 26085
diff changeset
180
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
181 static PurpleXmlNode *
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
182 jabber_bosh_connection_parse(PurpleJabberBOSHConnection *conn,
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
183 SoupMessage *response)
26664
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
184 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
185 PurpleXmlNode *root;
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
186 const gchar *type;
28066
6e27a78baf3d jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <darkrain42@pidgin.im>
parents: 28065
diff changeset
187
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
188 g_return_val_if_fail(conn != NULL, NULL);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
189 g_return_val_if_fail(response != NULL, NULL);
26664
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
190
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
191 if (conn->is_terminating || purple_account_is_disconnecting(
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
192 purple_connection_get_account(conn->js->gc)))
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
193 {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
194 return NULL;
27811
9db18cacd8fc Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <darkrain42@pidgin.im>
parents: 27635
diff changeset
195 }
9db18cacd8fc Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <darkrain42@pidgin.im>
parents: 27635
diff changeset
196
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
197 if (!SOUP_STATUS_IS_SUCCESSFUL(response->status_code)) {
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
198 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
199 response->reason_phrase);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
200 purple_connection_error(conn->js->gc,
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
201 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
202 g_free(tmp);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
203 return NULL;
31360
4ddd59618002 jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <darkrain42@pidgin.im>
parents: 31350
diff changeset
204 }
4ddd59618002 jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <darkrain42@pidgin.im>
parents: 31350
diff changeset
205
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
206 root = purple_xmlnode_from_str(response->response_body->data,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
207 response->response_body->length);
26664
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
208
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
209 type = purple_xmlnode_get_attrib(root, "type");
38358
30ba44276e74 Merge release-2.x.y into default
dx <dx@dxzone.com.ar>
parents: 36257 38260
diff changeset
210 if (purple_strequal(type, "terminate")) {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
211 purple_connection_error(conn->js->gc,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
212 PURPLE_CONNECTION_ERROR_OTHER_ERROR, _("The BOSH "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
213 "connection manager terminated your session."));
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
214 purple_xmlnode_free(root);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
215 return NULL;
26664
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
216 }
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
217
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
218 return root;
26664
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
219 }
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
220
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
221 static void
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
222 jabber_bosh_connection_recv(SoupSession *session, SoupMessage *msg,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
223 gpointer user_data)
26664
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
224 {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
225 PurpleJabberBOSHConnection *bosh_conn = user_data;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
226 PurpleXmlNode *node, *child;
27811
9db18cacd8fc Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <darkrain42@pidgin.im>
parents: 27635
diff changeset
227
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
228 if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
229 purple_debug_misc("jabber-bosh", "received: %s\n",
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
230 msg->response_body->data);
26664
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
231 }
a42da6facb80 Reorder functions to remove prototypes
Paul Aurich <darkrain42@pidgin.im>
parents: 26661
diff changeset
232
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
233 node = jabber_bosh_connection_parse(bosh_conn, msg);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
234 if (node == NULL)
24875
0fa0cf6ea28e Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents: 24874
diff changeset
235 return;
0fa0cf6ea28e Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents: 24874
diff changeset
236
23620
e306af5178d7 * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23619
diff changeset
237 child = node->child;
24875
0fa0cf6ea28e Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents: 24874
diff changeset
238 while (child != NULL) {
24886
de0388948ac8 Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 24885
diff changeset
239 /* jabber_process_packet might free child */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
240 PurpleXmlNode *next = child->next;
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
241 const gchar *xmlns;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
242
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
243 if (child->type != PURPLE_XMLNODE_TYPE_TAG) {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
244 child = next;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
245 continue;
23620
e306af5178d7 * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23619
diff changeset
246 }
24886
de0388948ac8 Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 24885
diff changeset
247
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
248 /* Workaround for non-compliant servers that don't stamp
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
249 * the right xmlns on these packets. See #11315.
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
250 */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
251 xmlns = purple_xmlnode_get_namespace(child);
38358
30ba44276e74 Merge release-2.x.y into default
dx <dx@dxzone.com.ar>
parents: 36257 38260
diff changeset
252 if ((xmlns == NULL || purple_strequal(xmlns, NS_BOSH)) &&
30ba44276e74 Merge release-2.x.y into default
dx <dx@dxzone.com.ar>
parents: 36257 38260
diff changeset
253 (purple_strequal(child->name, "iq") ||
30ba44276e74 Merge release-2.x.y into default
dx <dx@dxzone.com.ar>
parents: 36257 38260
diff changeset
254 purple_strequal(child->name, "message") ||
30ba44276e74 Merge release-2.x.y into default
dx <dx@dxzone.com.ar>
parents: 36257 38260
diff changeset
255 purple_strequal(child->name, "presence")))
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
256 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
257 purple_xmlnode_set_namespace(child, NS_XMPP_CLIENT);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
258 }
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
259
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
260 jabber_process_packet(bosh_conn->js, &child);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
261
24886
de0388948ac8 Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 24885
diff changeset
262 child = next;
23620
e306af5178d7 * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23619
diff changeset
263 }
23619
5c215ab46f1e * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23618
diff changeset
264
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
265 jabber_bosh_connection_send(bosh_conn, NULL);
23618
8497c2f5e62d * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23617
diff changeset
266 }
8497c2f5e62d * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23617
diff changeset
267
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
268 static void
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
269 jabber_bosh_connection_send_now(PurpleJabberBOSHConnection *conn)
26078
3526ac955ce3 Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents: 26076
diff changeset
270 {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
271 SoupMessage *req;
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
272 GString *data;
31349
dd0d5d14b148 jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
Paul Aurich <darkrain42@pidgin.im>
parents: 31348
diff changeset
273
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
274 g_return_if_fail(conn != NULL);
23621
d7a6cc7ca517 * sending empty <body> requests if there are not othere requests to be answered to keep a CM -> client channel open
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23620
diff changeset
275
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
276 if (conn->send_timer != 0) {
38433
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
277 g_source_remove(conn->send_timer);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
278 conn->send_timer = 0;
26533
5c74696c34d1 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <darkrain42@pidgin.im>
parents: 26085
diff changeset
279 }
5c74696c34d1 BOSH: For authentication purposes, HTTPS is equivalent to a secured JabberStream.
Paul Aurich <darkrain42@pidgin.im>
parents: 26085
diff changeset
280
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
281 if (conn->sid == NULL)
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
282 return;
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
283
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
284 data = g_string_new(NULL);
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
285
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
286 /* missing parameters: route, from, ack */
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
287 g_string_printf(data, "<body "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
288 "rid='%" G_GUINT64_FORMAT "' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
289 "sid='%s' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
290 "xmlns='" NS_BOSH "' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
291 "xmlns:xmpp='" NS_XMPP_BOSH "' ",
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
292 ++conn->rid, conn->sid);
26076
1755f871f1d1 Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents: 25489
diff changeset
293
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
294 if (conn->js->reinit && !conn->is_terminating) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
295 g_string_append(data, "xmpp:restart='true'/>");
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
296 conn->js->reinit = FALSE;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
297 } else {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
298 if (conn->is_terminating)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
299 g_string_append(data, "type='terminate' ");
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
300 g_string_append_c(data, '>');
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
301 g_string_append_len(data, conn->send_buff->str,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
302 conn->send_buff->len);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
303 g_string_append(data, "</body>");
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
304 g_string_set_size(conn->send_buff, 0);
28066
6e27a78baf3d jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <darkrain42@pidgin.im>
parents: 28065
diff changeset
305 }
28079
69fc36a9cbe3 jabber: Keep a second connection open over which to send the terminate.
Paul Aurich <darkrain42@pidgin.im>
parents: 28072
diff changeset
306
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
307 if (purple_debug_is_verbose() && purple_debug_is_unsafe())
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
308 purple_debug_misc("jabber-bosh", "sending: %s\n", data->str);
31360
4ddd59618002 jabber: Be friendlier to servers when we have nothing to say.
Paul Aurich <darkrain42@pidgin.im>
parents: 31350
diff changeset
309
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
310 req = jabber_bosh_connection_http_request_new(conn, data);
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
311 g_string_free(data, FALSE);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
312
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
313 if (conn->is_terminating) {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
314 soup_session_send_async(conn->payload_reqs, req, NULL, NULL, NULL);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
315 g_free(conn->sid);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
316 conn->sid = NULL;
26534
20a970cad8e2 Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <darkrain42@pidgin.im>
parents: 26533
diff changeset
317 } else {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
318 soup_session_queue_message(conn->payload_reqs, req,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
319 jabber_bosh_connection_recv, conn);
26534
20a970cad8e2 Because BOSH works over connections that may die non-fatally, we need to
Paul Aurich <darkrain42@pidgin.im>
parents: 26533
diff changeset
320 }
23611
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
321 }
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
322
35264
5b9619d1dec4 Fix dropping incoming stanzas on BOSH connections when we receive
Mark Doliner <mark@kingant.net>
parents: 35263
diff changeset
323 static gboolean
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
324 jabber_bosh_connection_send_delayed(gpointer _conn)
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
325 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
326 PurpleJabberBOSHConnection *conn = _conn;
31350
c4038b151558 jabber: Handle the connection: close header. Closes #13008
Paul Aurich <darkrain42@pidgin.im>
parents: 31349
diff changeset
327
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
328 conn->send_timer = 0;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
329 jabber_bosh_connection_send_now(conn);
35264
5b9619d1dec4 Fix dropping incoming stanzas on BOSH connections when we receive
Mark Doliner <mark@kingant.net>
parents: 35263
diff changeset
330
5b9619d1dec4 Fix dropping incoming stanzas on BOSH connections when we receive
Mark Doliner <mark@kingant.net>
parents: 35263
diff changeset
331 return FALSE;
23620
e306af5178d7 * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23619
diff changeset
332 }
e306af5178d7 * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23619
diff changeset
333
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
334 void
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
335 jabber_bosh_connection_send(PurpleJabberBOSHConnection *conn,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
336 const gchar *data)
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
337 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
338 g_return_if_fail(conn != NULL);
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
339
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
340 if (data)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
341 g_string_append(conn->send_buff, data);
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
342
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
343 if (conn->send_timer == 0) {
38433
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
344 conn->send_timer = g_timeout_add(
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
345 JABBER_BOSH_SEND_DELAY,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
346 jabber_bosh_connection_send_delayed, conn);
23614
cb637468e183 * preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23613
diff changeset
347 }
23612
0d8cc9f7f223 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23611
diff changeset
348 }
23611
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
349
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
350 void
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
351 jabber_bosh_connection_send_keepalive(PurpleJabberBOSHConnection *conn)
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
352 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
353 g_return_if_fail(conn != NULL);
27154
2ef476bfe073 Various BOSH fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 27152
diff changeset
354
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
355 jabber_bosh_connection_send_now(conn);
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
356 }
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
357
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
358 static gboolean
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
359 jabber_bosh_version_check(const gchar *version, int major_req, int minor_min)
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
360 {
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
361 const gchar *dot;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
362 int major, minor = 0;
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
363
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
364 if (version == NULL)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
365 return FALSE;
26081
ef41d4bd0dfa Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents: 26079
diff changeset
366
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
367 major = atoi(version);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
368 dot = strchr(version, '.');
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
369 if (dot)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
370 minor = atoi(dot + 1);
24884
896733ece217 Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents: 24883
diff changeset
371
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
372 if (major != major_req)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
373 return FALSE;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
374 if (minor < minor_min)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
375 return FALSE;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
376 return TRUE;
23612
0d8cc9f7f223 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23611
diff changeset
377 }
23611
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
378
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
379 static void
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
380 jabber_bosh_connection_session_created(SoupSession *session, SoupMessage *msg,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
381 gpointer user_data)
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
382 {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
383 PurpleJabberBOSHConnection *bosh_conn = user_data;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
384 PurpleXmlNode *node, *features;
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
385 const gchar *sid, *ver, *inactivity_str;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
386 int inactivity = 0;
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
387
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
388 if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
389 purple_debug_misc("jabber-bosh", "received (session creation): %s\n",
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
390 msg->response_body->data);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
391 }
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
392
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
393 node = jabber_bosh_connection_parse(bosh_conn, msg);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
394 if (node == NULL)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
395 return;
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
396
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
397 sid = purple_xmlnode_get_attrib(node, "sid");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
398 ver = purple_xmlnode_get_attrib(node, "ver");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
399 inactivity_str = purple_xmlnode_get_attrib(node, "inactivity");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
400 /* requests = purple_xmlnode_get_attrib(node, "requests"); */
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
401
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
402 if (!sid) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
403 purple_connection_error(bosh_conn->js->gc,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
404 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
405 _("No BOSH session ID given"));
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
406 purple_xmlnode_free(node);
23611
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
407 return;
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
408 }
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
409
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
410 if (ver == NULL) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
411 purple_debug_info("jabber-bosh", "Missing version in BOSH initiation\n");
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
412 } else if (!jabber_bosh_version_check(ver, 1, 6)) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
413 purple_debug_error("jabber-bosh",
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
414 "Unsupported BOSH version: %s\n", ver);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
415 purple_connection_error(bosh_conn->js->gc,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
416 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
417 _("Unsupported version of BOSH protocol"));
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
418 purple_xmlnode_free(node);
23611
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
419 return;
d811757e19b5 * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23609
diff changeset
420 }
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
421
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
422 purple_debug_misc("jabber-bosh", "Session created for %p\n", bosh_conn);
23609
94f1737e3853 * some refactoring
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23607
diff changeset
423
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
424 bosh_conn->sid = g_strdup(sid);
27811
9db18cacd8fc Various fixes to get BOSH working with Prosody 0.5.
Paul Aurich <darkrain42@pidgin.im>
parents: 27635
diff changeset
425
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
426 if (inactivity_str)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
427 inactivity = atoi(inactivity_str);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
428 if (inactivity < 0 || inactivity > 3600) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
429 purple_debug_warning("jabber-bosh", "Ignoring invalid "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
430 "inactivity value: %s\n", inactivity_str);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
431 inactivity = 0;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
432 }
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
433 if (inactivity > 0) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
434 inactivity -= 5; /* rounding */
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
435 if (inactivity <= 0)
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
436 inactivity = 1;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
437 bosh_conn->js->max_inactivity = inactivity;
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
438 if (bosh_conn->js->inactivity_timer == 0) {
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
439 purple_debug_misc("jabber-bosh", "Starting inactivity "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
440 "timer for %d secs (compensating for "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
441 "rounding)\n", inactivity);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
442 jabber_stream_restart_inactivity_timer(bosh_conn->js);
26085
6b5686df629c BOSH: Support HTTPS connections to the connection manager
Paul Aurich <darkrain42@pidgin.im>
parents: 26084
diff changeset
443 }
24872
68de61b562f6 Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents: 23625
diff changeset
444 }
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
445
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
446 jabber_stream_set_state(bosh_conn->js, JABBER_STREAM_AUTHENTICATING);
23613
1da7c5cbcc54 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23612
diff changeset
447
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
448 /* FIXME: Depending on receiving features might break with some hosts */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
449 features = purple_xmlnode_get_child(node, "features");
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
450 jabber_stream_features_parse(bosh_conn->js, features);
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
451
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
452 purple_xmlnode_free(node);
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
453
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
454 jabber_bosh_connection_send(bosh_conn, NULL);
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
455 }
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
456
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
457 static void
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
458 jabber_bosh_connection_session_create(PurpleJabberBOSHConnection *conn)
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
459 {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
460 SoupMessage *req;
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
461 GString *data;
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
462
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
463 purple_debug_misc("jabber-bosh", "Requesting Session Create for %p\n",
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
464 conn);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
465
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
466 data = g_string_new(NULL);
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
467
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
468 /* missing optional parameters: route, from, ack */
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
469 g_string_printf(data, "<body content='text/xml; charset=utf-8' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
470 "rid='%" G_GUINT64_FORMAT "' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
471 "to='%s' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
472 "xml:lang='en' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
473 "ver='1.10' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
474 "wait='%d' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
475 "hold='1' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
476 "xmlns='" NS_BOSH "' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
477 "xmpp:version='1.0' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
478 "xmlns:xmpp='urn:xmpp:xbosh' "
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
479 "/>",
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
480 ++conn->rid, conn->js->user->domain, JABBER_BOSH_TIMEOUT);
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
481
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
482 req = jabber_bosh_connection_http_request_new(conn, data);
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
483 g_string_free(data, FALSE);
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
484
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
485 soup_session_queue_message(conn->payload_reqs, req,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
486 jabber_bosh_connection_session_created, conn);
26673
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
487 }
f632d4de4bce BOSH: Use a write buffer (read: basically cut-n-paste from jabber.c)
Paul Aurich <darkrain42@pidgin.im>
parents: 26672
diff changeset
488
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
489 static SoupMessage *
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
490 jabber_bosh_connection_http_request_new(PurpleJabberBOSHConnection *conn,
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
491 const GString *data)
24873
7d1e91d5ec46 Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents: 24872
diff changeset
492 {
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
493 SoupMessage *req;
28065
f9b9e38c98f4 jabber: Better inactivity timer logic.
Paul Aurich <darkrain42@pidgin.im>
parents: 28064
diff changeset
494
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
495 jabber_stream_restart_inactivity_timer(conn->js);
28066
6e27a78baf3d jabber: Ridiculously verbose logging for BOSH.
Paul Aurich <darkrain42@pidgin.im>
parents: 28065
diff changeset
496
40002
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
497 req = soup_message_new("POST", conn->url);
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
498 soup_message_set_request(req, "text/xml; charset=utf-8", SOUP_MEMORY_TAKE,
f08d87a438c2 Convert Jabber BOSH to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39987
diff changeset
499 data->str, data->len);
24883
c283f8737645 Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents: 24875
diff changeset
500
34268
cf61366236ee HTTP: connections set support added; BOSH for xmpp reimplemented, to use http API instead of its own HTTP implementation
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
501 return req;
23613
1da7c5cbcc54 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23612
diff changeset
502 }

mercurial