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