Sat, 21 Mar 2009 03:03:18 +0000
Use a PurpleCircBuffer for the queued stanzas
|
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 |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
33 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
34 | typedef struct _PurpleHTTPConnection PurpleHTTPConnection; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
35 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
36 | typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
37 | typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
38 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
39 | static char *bosh_useragent = NULL; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
40 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
41 | typedef enum { |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
42 | PACKET_TERMINATE, |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
43 | PACKET_STREAM_RESTART, |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
44 | PACKET_NORMAL, |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
45 | } PurpleBOSHPacketType; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
46 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
47 | struct _PurpleBOSHConnection { |
|
26083
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
48 | JabberStream *js; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
49 | gboolean pipelining; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
50 | PurpleHTTPConnection *connections[MAX_HTTP_CONNECTIONS]; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
51 | |
|
26083
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
52 | gboolean ready; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
53 | |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
54 | /* decoded URL */ |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
55 | char *host; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
56 | int port; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
57 | char *path; |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
58 | |
|
26083
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
59 | /* 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
|
60 | guint64 rid; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
61 | char *sid; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
62 | |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
63 | unsigned int inactivity_timer; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
64 | int max_inactivity; |
|
26083
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
65 | int wait; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
66 | |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
67 | PurpleCircBuffer *pending; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
68 | int max_requests; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
69 | 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
|
70 | |
|
26083
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
71 | PurpleBOSHConnectionConnectFunction connect_cb; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
72 | PurpleBOSHConnectionReceiveFunction receive_cb; |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
73 | }; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
74 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
75 | struct _PurpleHTTPConnection { |
|
26083
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
76 | PurpleBOSHConnection *bosh; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
77 | int fd; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
78 | int ie_handle; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
79 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
80 | gboolean ready; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
81 | 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
|
82 | |
|
26083
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
83 | GString *buf; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
84 | gboolean headers_done; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
85 | gsize handled_len; |
|
e716012de66e
Rearrange the structs and fix the indentation. No functional changes.
Paul Aurich <darkrain42@pidgin.im>
parents:
26082
diff
changeset
|
86 | gsize body_len; |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
87 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
88 | }; |
|
23607
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
89 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
90 | static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
91 | 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
|
92 | 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
|
93 | 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
|
94 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
95 | 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
|
96 | 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
|
97 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
98 | void jabber_bosh_init(void) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
99 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
100 | 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
|
101 | const char *ui_name = NULL; |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
102 | const char *ui_version = NULL; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
103 | |
|
25487
00e94f044205
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <darkrain42@pidgin.im>
parents:
25486
diff
changeset
|
104 | 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
|
105 | ui_name = g_hash_table_lookup(ui_info, "name"); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
106 | 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
|
107 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
108 | |
|
25487
00e94f044205
The BOSH User Agent should include the client name (and optionally version),
Paul Aurich <darkrain42@pidgin.im>
parents:
25486
diff
changeset
|
109 | 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
|
110 | 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
|
111 | 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
|
112 | ui_version ? ui_version : ""); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
113 | else |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
114 | bosh_useragent = g_strdup("libpurple " VERSION); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
115 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
116 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
117 | void jabber_bosh_uninit(void) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
118 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
119 | g_free(bosh_useragent); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
120 | bosh_useragent = NULL; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
121 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
122 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
123 | static PurpleHTTPConnection* |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
124 | 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
|
125 | { |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
126 | 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
|
127 | conn->bosh = bosh; |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
128 | conn->fd = -1; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
129 | conn->ready = FALSE; |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
130 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
131 | return conn; |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
132 | } |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
133 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
134 | static void |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
135 | jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
136 | { |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
137 | if (conn->buf) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
138 | 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
|
139 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
140 | if (conn->ie_handle) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
141 | purple_input_remove(conn->ie_handle); |
|
25488
acdb4dbab299
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <darkrain42@pidgin.im>
parents:
25487
diff
changeset
|
142 | if (conn->fd >= 0) |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
143 | close(conn->fd); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
144 | |
|
26079
4d75323e1e6b
Close a small race with disconnecting while establishing a connection and
Paul Aurich <darkrain42@pidgin.im>
parents:
26078
diff
changeset
|
145 | 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
|
146 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
147 | g_free(conn); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
148 | } |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
149 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
150 | PurpleBOSHConnection* |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
151 | jabber_bosh_connection_init(JabberStream *js, const char *url) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
152 | { |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
153 | PurpleBOSHConnection *conn; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
154 | char *host, *path, *user, *passwd; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
155 | int port; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
156 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
157 | 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
|
158 | 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
|
159 | return NULL; |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
160 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
161 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
162 | conn = g_new0(PurpleBOSHConnection, 1); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
163 | conn->host = host; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
164 | conn->port = port; |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
165 | 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
|
166 | g_free(path); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
167 | conn->pipelining = TRUE; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
168 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
169 | if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
170 | purple_debug_info("jabber", "Ignoring unexpected username and password " |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
171 | "in BOSH URL.\n"); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
172 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
173 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
174 | g_free(user); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
175 | g_free(passwd); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
176 | |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
177 | conn->js = js; |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
178 | /* FIXME: This doesn't seem very random */ |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
179 | 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
|
180 | |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
181 | 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
|
182 | |
|
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
|
183 | conn->ready = FALSE; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
184 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
185 | conn->connections[0] = jabber_bosh_http_connection_init(conn); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
186 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
187 | return conn; |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
188 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
189 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
190 | void |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
191 | jabber_bosh_connection_destroy(PurpleBOSHConnection *conn) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
192 | { |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
193 | int i; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
194 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
195 | g_free(conn->host); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
196 | g_free(conn->path); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
197 | |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
198 | 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
|
199 | 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
|
200 | |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
201 | 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
|
202 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
203 | 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
|
204 | if (conn->connections[i]) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
205 | 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
|
206 | } |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
207 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
208 | g_free(conn); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
209 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
210 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
211 | void jabber_bosh_connection_close(PurpleBOSHConnection *conn) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
212 | { |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
213 | jabber_bosh_connection_send_native(conn, PACKET_TERMINATE, NULL); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
214 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
215 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
216 | 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
|
217 | 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
|
218 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
219 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
220 | 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
|
221 | 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
|
222 | |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
223 | 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
|
224 | |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
225 | 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
|
226 | conn->ready = FALSE; |
|
23624
84b42375e411
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23623
diff
changeset
|
227 | purple_connection_error_reason (conn->js->gc, |
|
84b42375e411
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23623
diff
changeset
|
228 | 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
|
229 | _("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
|
230 | return TRUE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
231 | } |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
232 | return FALSE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
233 | } |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
234 | |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
235 | static gboolean |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
236 | 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
|
237 | { |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
238 | PurpleBOSHConnection *bosh = data; |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
239 | |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
240 | 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
|
241 | return TRUE; |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
242 | } |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
243 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
244 | 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
|
245 | 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
|
246 | 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
|
247 | |
|
25485
cb56bf5684c1
BOSH: Another g_return_if_fail that is backward
Paul Aurich <darkrain42@pidgin.im>
parents:
25484
diff
changeset
|
248 | 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
|
249 | 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
|
250 | return; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
251 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
252 | 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
|
253 | while (child != NULL) { |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
254 | /* jabber_process_packet might free child */ |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
255 | 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
|
256 | if (child->type == XMLNODE_TYPE_TAG) { |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
257 | if (!strcmp(child->name, "iq")) { |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
258 | if (xmlnode_get_child(child, "session")) |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
259 | 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
|
260 | } |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
261 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
262 | 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
|
263 | } |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
264 | |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
265 | 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
|
266 | } |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
267 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
268 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
269 | 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
|
270 | xmlnode *child; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
271 | |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
272 | 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
|
273 | 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
|
274 | return; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
275 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
276 | 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
|
277 | 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
|
278 | 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
|
279 | } |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
280 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
281 | /* 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
|
282 | 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
|
283 | 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
|
284 | 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
|
285 | 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
|
286 | 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
|
287 | 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
|
288 | } else { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
289 | 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
|
290 | 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
|
291 | } |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
292 | } else { |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
293 | 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
|
294 | } |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
295 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
296 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
297 | 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
|
298 | const char *sid, *version; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
299 | 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
|
300 | 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
|
301 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
302 | 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
|
303 | 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
|
304 | return; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
305 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
306 | 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
|
307 | 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
|
308 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
309 | 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
|
310 | 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
|
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 | if (sid) { |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
313 | 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
|
314 | } else { |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
315 | 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
|
316 | 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
|
317 | _("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
|
318 | return; |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
319 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
320 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
321 | if (version) { |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
322 | const char *dot = strstr(version, "."); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
323 | int major = atoi(version); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
324 | int minor = atoi(dot + 1); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
325 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
326 | 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
|
327 | |
|
24885
353c663c8110
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <darkrain42@pidgin.im>
parents:
24884
diff
changeset
|
328 | if (major != 1 || minor < 6) { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
329 | 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
|
330 | 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
|
331 | _("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
|
332 | return; |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
333 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
334 | } else { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
335 | 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
|
336 | } |
|
24885
353c663c8110
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <darkrain42@pidgin.im>
parents:
24884
diff
changeset
|
337 | |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
338 | if (inactivity) { |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
339 | 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
|
340 | 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
|
341 | 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
|
342 | inactivity); |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
343 | 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
|
344 | } else { |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
345 | /* 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
|
346 | 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
|
347 | 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
|
348 | conn); |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
349 | } |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
350 | } |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
351 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
352 | if (requests) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
353 | conn->max_requests = atoi(requests); |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
354 | |
|
24885
353c663c8110
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <darkrain42@pidgin.im>
parents:
24884
diff
changeset
|
355 | /* 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
|
356 | 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
|
357 | 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
|
358 | 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
|
359 | jabber_stream_features_parse(conn->js, packet); |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
360 | } |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
361 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
362 | static PurpleHTTPConnection * |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
363 | 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
|
364 | { |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
365 | int i; |
|
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 | /* 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
|
368 | * one TCP connection! */ |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
369 | if (conn->pipelining) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
370 | return conn->connections[0]; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
371 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
372 | /* 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
|
373 | 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
|
374 | 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
|
375 | conn->connections[i]->requests == 0) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
376 | return conn->connections[i]; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
377 | } |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
378 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
379 | /* 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
|
380 | 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
|
381 | if (!conn->connections[i]) { |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
382 | 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
|
383 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
384 | 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
|
385 | return NULL; |
|
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 | } |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
388 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
389 | /* None available. */ |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
390 | return NULL; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
391 | } |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
392 | |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
393 | 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
|
394 | GString *buf = g_string_new(""); |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
395 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
396 | 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
|
397 | "secure='true' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
398 | "to='%s' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
399 | "xml:lang='en' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
400 | "xmpp:version='1.0' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
401 | "ver='1.6' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
402 | "xmlns:xmpp='urn:xmpp:bosh' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
403 | "rid='%" G_GUINT64_FORMAT "' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
404 | /* 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
|
405 | * realtime network behavior */ |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
406 | "wait='60' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
407 | "hold='1' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
408 | "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
|
409 | conn->js->user->domain, |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
410 | ++conn->rid); |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
411 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
412 | 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
|
413 | 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
|
414 | g_string_free(buf, TRUE); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
415 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
416 | |
|
25488
acdb4dbab299
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <darkrain42@pidgin.im>
parents:
25487
diff
changeset
|
417 | static void |
|
25489
9c591341d172
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <darkrain42@pidgin.im>
parents:
25488
diff
changeset
|
418 | 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
|
419 | { |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
420 | 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
|
421 | 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
|
422 | 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
|
423 | 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
|
424 | 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
|
425 | 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
|
426 | 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
|
427 | 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
|
428 | } 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
|
429 | 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
|
430 | } |
|
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
|
431 | } 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
|
432 | 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
|
433 | } |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
434 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
435 | |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
436 | 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
|
437 | jabber_bosh_connection_send_native(conn, PACKET_NORMAL, node); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
438 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
439 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
440 | void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
441 | const char *data, int len) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
442 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
443 | xmlnode *node = xmlnode_from_str(data, len); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
444 | if (node) { |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
445 | jabber_bosh_connection_send_native(conn, PACKET_NORMAL, node); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
446 | xmlnode_free(node); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
447 | } else { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
448 | /* |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
449 | * This best emulates what a normal XMPP server would do |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
450 | * if you send bad XML. |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
451 | */ |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
452 | purple_connection_error_reason(conn->js->gc, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
453 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
454 | _("Cannot send malformed XML")); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
455 | } |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
456 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
457 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
458 | static void |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
459 | 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
|
460 | xmlnode *node) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
461 | { |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
462 | PurpleHTTPConnection *chosen; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
463 | GString *packet = NULL; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
464 | char *buf = NULL; |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
465 | int len; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
466 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
467 | 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
|
468 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
469 | if (type != PACKET_NORMAL && !chosen) { |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
470 | /* |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
471 | * 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
|
472 | * connection. |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
473 | */ |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
474 | 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
|
475 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
476 | if (!chosen->ready) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
477 | 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
|
478 | "things may happen.\n"); |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
479 | } |
|
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 | if (node) |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
482 | 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
|
483 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
484 | if (type == PACKET_NORMAL && (!chosen || |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
485 | (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
|
486 | /* |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
487 | * 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
|
488 | * 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
|
489 | * 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
|
490 | */ |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
491 | if (buf) { |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
492 | 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
|
493 | g_free(buf); |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
494 | } |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
495 | return; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
496 | } |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
497 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
498 | packet = g_string_new(""); |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
499 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
500 | g_string_printf(packet, "<body " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
501 | "rid='%" G_GUINT64_FORMAT "' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
502 | "sid='%s' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
503 | "to='%s' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
504 | "xml:lang='en' " |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
505 | "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
|
506 | "xmlns:xmpp='urn:xmpp:xbosh'", |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
507 | ++conn->rid, |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
508 | conn->sid, |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
509 | conn->js->user->domain); |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
510 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
511 | if (type == PACKET_STREAM_RESTART) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
512 | 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
|
513 | else { |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
514 | gsize read_amt; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
515 | if (type == PACKET_TERMINATE) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
516 | 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
|
517 | |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
518 | packet = g_string_append_c(packet, '>'); |
|
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
519 | |
|
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
520 | 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
|
521 | 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
|
522 | 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
|
523 | } |
|
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
524 | |
|
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
525 | if (buf) |
|
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
526 | 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
|
527 | 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
|
528 | } |
|
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 | g_free(buf); |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
531 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
532 | 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
|
533 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
534 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
535 | static void http_connection_connected(PurpleHTTPConnection *conn) |
|
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
536 | { |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
537 | /* 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
|
538 | conn->ready = TRUE; |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
539 | conn->requests = 0; |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
540 | if (conn->buf) { |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
541 | g_string_free(conn->buf, TRUE); |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
542 | conn->buf = NULL; |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
543 | } |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
544 | conn->headers_done = FALSE; |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
545 | 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
|
546 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
547 | 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
|
548 | 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
|
549 | 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
|
550 | /* Send the pending data */ |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
551 | 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
|
552 | } |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
553 | #if 0 |
|
25489
9c591341d172
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <darkrain42@pidgin.im>
parents:
25488
diff
changeset
|
554 | 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
|
555 | if (conn->bosh->connect_cb) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
556 | 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
|
557 | #endif |
|
25489
9c591341d172
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <darkrain42@pidgin.im>
parents:
25488
diff
changeset
|
558 | } else |
|
9c591341d172
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <darkrain42@pidgin.im>
parents:
25488
diff
changeset
|
559 | 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
|
560 | } |
|
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
|
561 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
562 | void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
563 | { |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
564 | 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
|
565 | } |
|
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
|
566 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
567 | 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
|
568 | { |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
569 | /* |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
570 | * 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
|
571 | * with AIM! |
|
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 | conn->ready = FALSE; |
|
26079
4d75323e1e6b
Close a small race with disconnecting while establishing a connection and
Paul Aurich <darkrain42@pidgin.im>
parents:
26078
diff
changeset
|
574 | conn->fd = -1; |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
575 | purple_input_remove(conn->ie_handle); |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
576 | conn->ie_handle = 0; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
577 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
578 | if (conn->bosh->pipelining) |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
579 | /* 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
|
580 | conn->bosh->pipelining = FALSE; |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
581 | |
|
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
582 | /* No! Please! Take me back. It was me, not you! I was weak! */ |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
583 | http_connection_connect(conn); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
584 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
585 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
586 | 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
|
587 | 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
|
588 | http_connection_connect(conn); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
589 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
590 | |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
591 | static void |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
592 | 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
|
593 | { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
594 | const char *cursor; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
595 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
596 | 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
|
597 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
598 | if (!conn->headers_done) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
599 | 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
|
600 | 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
|
601 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
602 | /* 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
|
603 | 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
|
604 | char *sep = strstr(content_length, ": "); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
605 | int len = atoi(sep + 2); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
606 | if (len == 0) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
607 | 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
|
608 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
609 | conn->body_len = len; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
610 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
611 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
612 | if (end_of_headers) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
613 | conn->headers_done = TRUE; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
614 | 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
|
615 | cursor = end_of_headers + 4; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
616 | } else { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
617 | 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
|
618 | 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
|
619 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
620 | } |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
621 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
622 | /* 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
|
623 | 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
|
624 | return; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
625 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
626 | /* 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
|
627 | 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
|
628 | return; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
629 | |
|
25488
acdb4dbab299
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <darkrain42@pidgin.im>
parents:
25487
diff
changeset
|
630 | --conn->requests; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
631 | --conn->bosh->requests; |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
632 | |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
633 | 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
|
634 | conn->bosh); |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
635 | |
|
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
636 | if (conn->bosh->ready && |
|
26084
5e8895515af0
Use a PurpleCircBuffer for the queued stanzas
Paul Aurich <darkrain42@pidgin.im>
parents:
26083
diff
changeset
|
637 | (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
|
638 | 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
|
639 | 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
|
640 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
641 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
642 | 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
|
643 | 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
|
644 | 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
|
645 | 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
|
646 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
647 | |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
648 | static void |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
649 | jabber_bosh_http_connection_read(gpointer data, gint fd, |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
650 | PurpleInputCondition condition) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
651 | { |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
652 | PurpleHTTPConnection *conn = data; |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
653 | char buffer[1025]; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
654 | int cnt, count = 0; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
655 | |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
656 | if (!conn->buf) |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
657 | conn->buf = g_string_new(""); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
658 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
659 | while ((cnt = read(fd, buffer, sizeof(buffer))) > 0) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
660 | count += cnt; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
661 | g_string_append_len(conn->buf, buffer, cnt); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
662 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
663 | |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
664 | 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
|
665 | if (cnt < 0) |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
666 | 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
|
667 | else |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
668 | purple_debug_info("jabber", "bosh server closed connection\n"); |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
669 | |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
670 | /* |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
671 | * 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
|
672 | * 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
|
673 | */ |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
674 | http_connection_disconnected(conn); |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
675 | |
|
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
676 | /* 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
|
677 | } |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
678 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
679 | 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
|
680 | } |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
681 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
682 | static void http_connection_cb(gpointer data, gint source, const gchar *error) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
683 | { |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
684 | PurpleHTTPConnection *conn = data; |
|
25489
9c591341d172
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <darkrain42@pidgin.im>
parents:
25488
diff
changeset
|
685 | PurpleConnection *gc = conn->bosh->js->gc; |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
686 | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
687 | if (source < 0) { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
688 | gchar *tmp; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
689 | 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
|
690 | error); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
691 | 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
|
692 | g_free(tmp); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
693 | return; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
694 | } |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
695 | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
696 | conn->fd = source; |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
697 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
698 | http_connection_connected(conn); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
699 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
700 | conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ, |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
701 | jabber_bosh_http_connection_read, conn); |
| 23609 | 702 | } |
| 703 | ||
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
704 | static void http_connection_connect(PurpleHTTPConnection *conn) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
705 | { |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
706 | PurpleBOSHConnection *bosh = conn->bosh; |
|
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
707 | PurpleConnection *gc = bosh->js->gc; |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
708 | PurpleAccount *account = purple_connection_get_account(gc); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
709 | |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
710 | if ((purple_proxy_connect(conn, account, bosh->host, bosh->port, |
|
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
711 | http_connection_cb, conn)) == NULL) { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
712 | purple_connection_error_reason(gc, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
713 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
714 | _("Unable to create socket")); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
715 | } |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
716 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
717 | |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
718 | static void |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
719 | http_connection_send_request(PurpleHTTPConnection *conn, const GString *req) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
720 | { |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
721 | char *packet; |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
722 | int ret; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
723 | |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
724 | 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
|
725 | "Host: %s\r\n" |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
726 | "User-Agent: %s\r\n" |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
727 | "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
|
728 | "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
|
729 | "%s", |
|
26078
3526ac955ce3
Rename a few functions and drop some data members.
Paul Aurich <darkrain42@pidgin.im>
parents:
26076
diff
changeset
|
730 | 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
|
731 | 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
|
732 | |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
733 | /* 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
|
734 | * low-level code in jabber.c */ |
|
26082
7e3952f2713d
Obey the 'inactivity' attribute and send blank updates often enough. Also,
Paul Aurich <darkrain42@pidgin.im>
parents:
26081
diff
changeset
|
735 | 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
|
736 | |
|
25488
acdb4dbab299
Don't track a cb-per-POST and remove the PurpleHTTPResponse structure.
Paul Aurich <darkrain42@pidgin.im>
parents:
25487
diff
changeset
|
737 | ++conn->requests; |
|
26076
1755f871f1d1
Restore BOSH to a more-or-less working state.
Paul Aurich <darkrain42@pidgin.im>
parents:
25489
diff
changeset
|
738 | ++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
|
739 | g_free(packet); |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
740 | |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
741 | if (ret < 0 && errno == EAGAIN) |
|
26081
ef41d4bd0dfa
Clean up BOSH reading and disconnection handling.
Paul Aurich <darkrain42@pidgin.im>
parents:
26079
diff
changeset
|
742 | 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
|
743 | |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
744 | if (ret <= 0) { |
|
25489
9c591341d172
Store PurpleBOSHConnection* instead of void* userdata
Paul Aurich <darkrain42@pidgin.im>
parents:
25488
diff
changeset
|
745 | 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
|
746 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
747 | _("Write error")); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
748 | return; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
749 | } |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
750 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
751 |