Sun, 18 Jan 2009 04:13:39 +0000
Jabber BOSH: memory management fixes
* jabber_process_packet might free the packet.
* logic in a g_return_if_fail was backward
* copy the node when putting it into the BOSH node (double free)
|
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" |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
22 | #include "core.h" |
|
23607
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
23 | #include "cipher.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
24 | #include "debug.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
25 | #include "prpl.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
26 | #include "util.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
27 | #include "xmlnode.h" |
|
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
28 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
29 | #include "bosh.h" |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
30 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
31 | typedef struct _PurpleHTTPRequest PurpleHTTPRequest; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
32 | typedef struct _PurpleHTTPResponse PurpleHTTPResponse; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
33 | typedef struct _PurpleHTTPConnection PurpleHTTPConnection; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
34 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
35 | typedef void (*PurpleHTTPConnectionConnectFunction)(PurpleHTTPConnection *conn); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
36 | typedef void (*PurpleHTTPConnectionDisconnectFunction)(PurpleHTTPConnection *conn); |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
37 | typedef void (*PurpleHTTPRequestCallback)(PurpleHTTPResponse *res, void *userdata); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
38 | typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
39 | typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
40 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
41 | static char *bosh_useragent = NULL; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
42 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
43 | struct _PurpleBOSHConnection { |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
44 | /* decoded URL */ |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
45 | char *host; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
46 | int port; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
47 | char *path; |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
48 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
49 | /* Must be big enough to hold 2^53 - 1 */ |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
50 | guint64 rid; |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
51 | char *sid; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
52 | int wait; |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
53 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
54 | JabberStream *js; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
55 | gboolean pipelining; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
56 | PurpleHTTPConnection *conn_a; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
57 | PurpleHTTPConnection *conn_b; |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
58 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
59 | gboolean ready; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
60 | PurpleBOSHConnectionConnectFunction connect_cb; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
61 | PurpleBOSHConnectionReceiveFunction receive_cb; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
62 | }; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
63 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
64 | struct _PurpleHTTPConnection { |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
65 | int fd; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
66 | char *host; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
67 | int port; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
68 | int ie_handle; |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
69 | GQueue *requests; /* Queue of PurpleHTTPRequestCallbacks */ |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
70 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
71 | PurpleHTTPResponse *current_response; |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
72 | GString *buf; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
73 | gboolean headers_done; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
74 | gsize handled_len; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
75 | gsize body_len; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
76 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
77 | int pih; /* what? */ |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
78 | PurpleHTTPConnectionConnectFunction connect_cb; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
79 | PurpleHTTPConnectionConnectFunction disconnect_cb; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
80 | void *userdata; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
81 | }; |
|
23607
bc82598d3798
* looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff
changeset
|
82 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
83 | struct _PurpleHTTPRequest { |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
84 | PurpleHTTPRequestCallback cb; |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
85 | const char *path; |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
86 | char *data; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
87 | int data_len; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
88 | void *userdata; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
89 | }; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
90 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
91 | struct _PurpleHTTPResponse { |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
92 | char *data; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
93 | int data_len; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
94 | }; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
95 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
96 | static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
97 | 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
|
98 | static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node); |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
99 | static void jabber_bosh_connection_http_received_cb(PurpleHTTPResponse *res, void *userdata); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
100 | static void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, xmlnode *node); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
101 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
102 | static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
103 | static void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
104 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
105 | void jabber_bosh_init(void) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
106 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
107 | GHashTable *ui_info = purple_core_get_ui_info(); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
108 | const char *ui_version = NULL; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
109 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
110 | if (ui_info) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
111 | ui_version = g_hash_table_lookup(ui_info, "version"); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
112 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
113 | if (ui_version) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
114 | bosh_useragent = g_strdup_printf("%s (libpurple " VERSION ")", ui_version); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
115 | else |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
116 | bosh_useragent = g_strdup("libpurple " VERSION); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
117 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
118 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
119 | void jabber_bosh_uninit(void) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
120 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
121 | g_free(bosh_useragent); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
122 | bosh_useragent = NULL; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
123 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
124 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
125 | static void |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
126 | jabber_bosh_http_request_destroy(PurpleHTTPRequest *req) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
127 | { |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
128 | g_free(req->data); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
129 | g_free(req); |
|
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 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
132 | static void |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
133 | jabber_bosh_http_response_destroy(PurpleHTTPResponse *res) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
134 | { |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
135 | g_free(res->data); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
136 | g_free(res); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
137 | } |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
138 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
139 | static PurpleHTTPConnection* |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
140 | jabber_bosh_http_connection_init(const char *host, int port) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
141 | { |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
142 | PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
143 | conn->host = g_strdup(host); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
144 | conn->port = port; |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
145 | conn->fd = -1; |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
146 | conn->requests = g_queue_new(); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
147 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
148 | return conn; |
|
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 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
151 | static void |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
152 | jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
153 | { |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
154 | g_free(conn->host); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
155 | |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
156 | if (conn->buf) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
157 | 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
|
158 | |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
159 | if (conn->requests) |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
160 | g_queue_free(conn->requests); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
161 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
162 | if (conn->current_response) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
163 | jabber_bosh_http_response_destroy(conn->current_response); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
164 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
165 | if (conn->ie_handle) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
166 | purple_input_remove(conn->ie_handle); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
167 | if (conn->fd > 0) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
168 | close(conn->fd); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
169 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
170 | g_free(conn); |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
171 | } |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
172 | |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
173 | PurpleBOSHConnection* |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
174 | jabber_bosh_connection_init(JabberStream *js, const char *url) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
175 | { |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
176 | PurpleBOSHConnection *conn; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
177 | char *host, *path, *user, *passwd; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
178 | int port; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
179 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
180 | 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
|
181 | 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
|
182 | return NULL; |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
183 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
184 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
185 | conn = g_new0(PurpleBOSHConnection, 1); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
186 | conn->host = host; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
187 | conn->port = port; |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
188 | 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
|
189 | g_free(path); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
190 | conn->pipelining = TRUE; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
191 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
192 | if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
193 | purple_debug_info("jabber", "Ignoring unexpected username and password " |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
194 | "in BOSH URL.\n"); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
195 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
196 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
197 | g_free(user); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
198 | g_free(passwd); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
199 | |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
200 | conn->js = js; |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
201 | /* FIXME: This doesn't seem very random */ |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
202 | conn->rid = rand() % 100000 + 1728679472; |
|
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
|
203 | conn->ready = FALSE; |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
204 | conn->conn_a = jabber_bosh_http_connection_init(conn->host, conn->port); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
205 | conn->conn_a->userdata = conn; |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
206 | |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
207 | return conn; |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
208 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
209 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
210 | void |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
211 | jabber_bosh_connection_destroy(PurpleBOSHConnection *conn) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
212 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
213 | g_free(conn->host); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
214 | g_free(conn->path); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
215 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
216 | if (conn->conn_a) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
217 | jabber_bosh_http_connection_destroy(conn->conn_a); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
218 | if (conn->conn_b) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
219 | jabber_bosh_http_connection_destroy(conn->conn_b); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
220 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
221 | g_free(conn); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
222 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
223 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
224 | void jabber_bosh_connection_close(PurpleBOSHConnection *conn) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
225 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
226 | xmlnode *packet = xmlnode_new("body"); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
227 | /* XEP-0124: The rid must not exceed 16 characters */ |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
228 | char rid[17]; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
229 | g_snprintf(rid, sizeof(rid), "%" G_GUINT64_FORMAT, ++conn->rid); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
230 | xmlnode_set_attrib(packet, "type", "terminate"); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
231 | xmlnode_set_attrib(packet, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
232 | xmlnode_set_attrib(packet, "sid", conn->sid); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
233 | xmlnode_set_attrib(packet, "rid", rid); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
234 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
235 | jabber_bosh_connection_send_native(conn, packet); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
236 | xmlnode_free(packet); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
237 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
238 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
239 | static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) { |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
240 | xmlnode *restart = xmlnode_new("body"); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
241 | /* XEP-0124: The rid must not exceed 16 characters */ |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
242 | char rid[17]; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
243 | g_snprintf(rid, sizeof(rid), "%" G_GUINT64_FORMAT, ++conn->rid); |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
244 | xmlnode_set_attrib(restart, "rid", rid); |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
245 | xmlnode_set_attrib(restart, "sid", conn->sid); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
246 | xmlnode_set_attrib(restart, "to", conn->js->user->domain); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
247 | xmlnode_set_attrib(restart, "xml:lang", "en"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
248 | xmlnode_set_attrib(restart, "xmpp:restart", "true"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
249 | xmlnode_set_attrib(restart, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
250 | xmlnode_set_attrib(restart, "xmlns:xmpp", "urn:xmpp:xbosh"); |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
251 | |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
252 | jabber_bosh_connection_send_native(conn, restart); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
253 | xmlnode_free(restart); |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
254 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
255 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
256 | 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
|
257 | 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
|
258 | |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
259 | 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
|
260 | |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
261 | 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
|
262 | conn->ready = FALSE; |
|
23624
84b42375e411
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23623
diff
changeset
|
263 | purple_connection_error_reason (conn->js->gc, |
|
84b42375e411
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23623
diff
changeset
|
264 | PURPLE_CONNECTION_ERROR_OTHER_ERROR, |
|
84b42375e411
* removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23623
diff
changeset
|
265 | _("The BOSH conncetion manager suggested to terminate 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
|
266 | return TRUE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
267 | } |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
268 | return FALSE; |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
269 | } |
|
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
270 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
271 | 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
|
272 | 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
|
273 | 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
|
274 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
275 | 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
|
276 | 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
|
277 | return; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
278 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
279 | 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
|
280 | while (child != NULL) { |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
281 | /* jabber_process_packet might free child */ |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
282 | 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
|
283 | if (child->type == XMLNODE_TYPE_TAG) { |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
284 | if (!strcmp(child->name, "iq")) { |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
285 | if (xmlnode_get_child(child, "session")) |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
286 | 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
|
287 | } |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
288 | |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
289 | 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
|
290 | } |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
291 | |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
292 | 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
|
293 | } |
|
23619
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
294 | } |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
295 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
296 | 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
|
297 | xmlnode *child; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
298 | |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
299 | 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
|
300 | 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
|
301 | return; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
302 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
303 | 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
|
304 | 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
|
305 | 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
|
306 | } |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
307 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
308 | /* 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
|
309 | 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
|
310 | 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
|
311 | 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
|
312 | 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
|
313 | 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
|
314 | 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
|
315 | } else { |
|
5c215ab46f1e
* moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23618
diff
changeset
|
316 | 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
|
317 | 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
|
318 | } |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
319 | } else { |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
320 | 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
|
321 | } |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
322 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
323 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
324 | 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
|
325 | const char *sid, *version; |
|
24885
353c663c8110
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <darkrain42@pidgin.im>
parents:
24884
diff
changeset
|
326 | 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
|
327 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
328 | 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
|
329 | 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
|
330 | return; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
331 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
332 | 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
|
333 | 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
|
334 | |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
335 | if (sid) { |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
336 | 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
|
337 | } else { |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
338 | 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
|
339 | 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
|
340 | _("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
|
341 | return; |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
342 | } |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
343 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
344 | if (version) { |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
345 | const char *dot = strstr(version, "."); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
346 | int major = atoi(version); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
347 | int minor = atoi(dot + 1); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
348 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
349 | 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
|
350 | |
|
24885
353c663c8110
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <darkrain42@pidgin.im>
parents:
24884
diff
changeset
|
351 | if (major != 1 || minor < 6) { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
352 | 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
|
353 | 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
|
354 | _("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
|
355 | return; |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
356 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
357 | } else { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
358 | 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
|
359 | } |
|
24885
353c663c8110
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <darkrain42@pidgin.im>
parents:
24884
diff
changeset
|
360 | |
|
353c663c8110
Jabber BOSH: Try to continue with no BOSH version attribute
Paul Aurich <darkrain42@pidgin.im>
parents:
24884
diff
changeset
|
361 | /* 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
|
362 | 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
|
363 | 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
|
364 | 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
|
365 | jabber_stream_features_parse(conn->js, packet); |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
366 | } |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
367 | |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
368 | static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
369 | xmlnode *init = xmlnode_new("body"); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
370 | /* XEP-0124: The rid must not exceed 16 characters */ |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
371 | char rid[17]; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
372 | g_snprintf(rid, sizeof(rid), "%" G_GUINT64_FORMAT, ++conn->rid); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
373 | xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
374 | xmlnode_set_attrib(init, "secure", "true"); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
375 | /* |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
376 | xmlnode_set_attrib(init, "route", tmp = g_strdup_printf("xmpp:%s:5222", conn->js->user->domain)); |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
377 | g_free(tmp); |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
378 | */ |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
379 | xmlnode_set_attrib(init, "to", conn->js->user->domain); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
380 | xmlnode_set_attrib(init, "xml:lang", "en"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
381 | xmlnode_set_attrib(init, "xmpp:version", "1.0"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
382 | xmlnode_set_attrib(init, "ver", "1.6"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
383 | xmlnode_set_attrib(init, "xmlns:xmpp", "urn:xmpp:xbosh"); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
384 | xmlnode_set_attrib(init, "rid", rid); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
385 | xmlnode_set_attrib(init, "wait", "60"); /* this should be adjusted automatically according to real time network behavior */ |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
386 | xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
387 | xmlnode_set_attrib(init, "hold", "1"); |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
388 | |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
389 | conn->receive_cb = boot_response_cb; |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
390 | jabber_bosh_connection_send_native(conn, init); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
391 | xmlnode_free(init); |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
392 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
393 | |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
394 | static void jabber_bosh_connection_http_received_cb(PurpleHTTPResponse *res, void *userdata) { |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
395 | PurpleBOSHConnection *conn = userdata; |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
396 | if (conn->receive_cb) { |
|
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
397 | xmlnode *node = xmlnode_from_str(res->data, res->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
|
398 | 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
|
399 | char *txt = xmlnode_to_formatted_str(node, NULL); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
400 | printf("\njabber_bosh_connection_http_received_cb\n%s\n", txt); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
401 | 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
|
402 | 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
|
403 | 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
|
404 | } else { |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
405 | printf("\njabber_bosh_connection_http_received_cb: XML ERROR: %s\n", res->data); |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
406 | } |
|
23616
5e5d6a440ee6
* calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23615
diff
changeset
|
407 | } else purple_debug_info("jabber", "missing receive_cb of PurpleBOSHConnection.\n"); |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
408 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
409 | |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
410 | void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) { |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
411 | xmlnode *packet = xmlnode_new("body"); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
412 | /* XEP-0124: The rid must not exceed 16 characters */ |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
413 | char rid[17]; |
|
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
414 | g_snprintf(rid, sizeof(rid), "%" G_GUINT64_FORMAT, ++conn->rid); |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
415 | xmlnode_set_attrib(packet, "xmlns", "http://jabber.org/protocol/httpbind"); |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
416 | xmlnode_set_attrib(packet, "sid", conn->sid); |
|
24875
0fa0cf6ea28e
Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <darkrain42@pidgin.im>
parents:
24874
diff
changeset
|
417 | xmlnode_set_attrib(packet, "rid", rid); |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
418 | |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
419 | if (node) { |
|
24886
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
420 | xmlnode *copy = xmlnode_copy(node); |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
421 | xmlnode_insert_child(packet, copy); |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
422 | if (conn->ready == TRUE) |
|
de0388948ac8
Jabber BOSH: memory management fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
24885
diff
changeset
|
423 | xmlnode_set_attrib(copy, "xmlns", "jabber:client"); |
|
23623
b7b226b72971
* fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23621
diff
changeset
|
424 | } |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
425 | jabber_bosh_connection_send_native(conn, packet); |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
426 | xmlnode_free(packet); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
427 | } |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
428 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
429 | void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
430 | const char *data, int len) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
431 | { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
432 | xmlnode *node = xmlnode_from_str(data, len); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
433 | if (node) { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
434 | jabber_bosh_connection_send(conn, node); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
435 | xmlnode_free(node); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
436 | } else { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
437 | /* |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
438 | * This best emulates what a normal XMPP server would do |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
439 | * if you send bad XML. |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
440 | */ |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
441 | purple_connection_error_reason(conn->js->gc, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
442 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
443 | _("Cannot send malformed XML")); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
444 | } |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
445 | } |
|
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
446 | |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
447 | static void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, xmlnode *node) { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
448 | PurpleHTTPRequest *request; |
|
23618
8497c2f5e62d
* using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23617
diff
changeset
|
449 | |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
450 | request = g_new0(PurpleHTTPRequest, 1); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
451 | request->path = conn->path; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
452 | request->cb = jabber_bosh_connection_http_received_cb; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
453 | request->userdata = conn; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
454 | |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
455 | request->data = xmlnode_to_str(node, &(request->data_len)); |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
456 | |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
457 | jabber_bosh_http_connection_send_request(conn->conn_a, request); |
|
23612
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
458 | } |
|
0d8cc9f7f223
* adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23611
diff
changeset
|
459 | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
460 | static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
461 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
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
|
462 | if (bosh_conn->ready == TRUE && bosh_conn->connect_cb) { |
|
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
|
463 | purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n"); |
|
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
|
464 | bosh_conn->receive_cb = jabber_bosh_connection_received; |
|
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
|
465 | bosh_conn->connect_cb(bosh_conn); |
|
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
|
466 | } else jabber_bosh_connection_boot(bosh_conn); |
|
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
|
467 | } |
|
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
|
468 | |
|
24874
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
469 | void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn) |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
470 | { |
|
33902e1daba1
Reorder some functions to eliminate prototypes and
Paul Aurich <darkrain42@pidgin.im>
parents:
24873
diff
changeset
|
471 | 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
|
472 | } |
|
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
|
473 | |
|
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
|
474 | static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn) { |
|
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
|
475 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
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
|
476 | bosh_conn->conn_a->connect_cb = jabber_bosh_connection_connected; |
|
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
|
477 | jabber_bosh_http_connection_connect(bosh_conn->conn_a); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
478 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
479 | |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
480 | void jabber_bosh_connection_connect(PurpleBOSHConnection *conn) { |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
481 | conn->conn_a->connect_cb = jabber_bosh_connection_connected; |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
482 | jabber_bosh_http_connection_connect(conn->conn_a); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
483 | } |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
484 | |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
485 | static void |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
486 | 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
|
487 | { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
488 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
489 | PurpleHTTPRequestCallback cb; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
490 | const char *cursor; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
491 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
492 | if (!conn->current_response) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
493 | conn->current_response = g_new0(PurpleHTTPResponse, 1); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
494 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
495 | 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
|
496 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
497 | if (!conn->headers_done) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
498 | 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
|
499 | 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
|
500 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
501 | /* 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
|
502 | 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
|
503 | char *sep = strstr(content_length, ": "); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
504 | int len = atoi(sep + 2); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
505 | if (len == 0) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
506 | 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
|
507 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
508 | conn->body_len = len; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
509 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
510 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
511 | if (end_of_headers) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
512 | conn->headers_done = TRUE; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
513 | 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
|
514 | cursor = end_of_headers + 4; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
515 | } else { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
516 | 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
|
517 | 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
|
518 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
519 | } |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
520 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
521 | /* 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
|
522 | 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
|
523 | return; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
524 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
525 | /* 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
|
526 | 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
|
527 | return; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
528 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
529 | cb = g_queue_pop_head(conn->requests); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
530 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
531 | #warning For a pure HTTP 1.1 stack, this would need to be handled elsewhere. |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
532 | if (bosh_conn->ready && g_queue_is_empty(conn->requests)) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
533 | jabber_bosh_connection_send(bosh_conn, NULL); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
534 | printf("\n SEND AN EMPTY REQUEST \n"); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
535 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
536 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
537 | if (cb) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
538 | conn->current_response->data_len = conn->body_len; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
539 | conn->current_response->data = g_memdup(conn->buf->str + 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
|
540 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
541 | cb(conn->current_response, conn->userdata); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
542 | } else { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
543 | purple_debug_warning("jabber", "Received HTTP response before POST\n"); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
544 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
545 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
546 | 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
|
547 | conn->buf = NULL; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
548 | jabber_bosh_http_response_destroy(conn->current_response); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
549 | conn->current_response = NULL; |
|
23620
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
550 | } |
|
e306af5178d7
* data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23619
diff
changeset
|
551 | |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
552 | static void |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
553 | 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
|
554 | PurpleInputCondition condition) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
555 | { |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
556 | PurpleHTTPConnection *conn = data; |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
557 | char buffer[1025]; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
558 | int perrno; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
559 | int cnt, count = 0; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
560 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
561 | purple_debug_info("jabber", "jabber_bosh_http_connection_read\n"); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
562 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
563 | if (conn->buf == NULL) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
564 | conn->buf = g_string_new(""); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
565 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
566 | 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
|
567 | purple_debug_info("jabber", "bosh read %d bytes\n", cnt); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
568 | count += cnt; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
569 | 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
|
570 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
571 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
572 | perrno = errno; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
573 | if (cnt == 0 && count) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
574 | /* TODO: process should know this response ended with a closed socket |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
575 | * and throw an error if it's not a complete response. */ |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
576 | jabber_bosh_http_connection_process(conn); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
577 | } |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
578 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
579 | if (cnt == 0 || (cnt < 0 && perrno != EAGAIN)) { |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
580 | if (cnt < 0) |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
581 | purple_debug_info("jabber", "bosh read: %d\n", cnt); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
582 | else |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
583 | purple_debug_info("jabber", "bosh socket closed\n"); |
|
23615
6a9e7febac16
* parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23614
diff
changeset
|
584 | |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
585 | purple_input_remove(conn->ie_handle); |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
586 | conn->ie_handle = 0; |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
587 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
588 | if (conn->disconnect_cb) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
589 | conn->disconnect_cb(conn); |
|
24884
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
590 | |
|
896733ece217
Jabber BOSH: Model the parsing on the SOAP stuff
Paul Aurich <darkrain42@pidgin.im>
parents:
24883
diff
changeset
|
591 | return; |
|
23614
cb637468e183
* preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23613
diff
changeset
|
592 | } |
|
24884
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 | 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
|
595 | } |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
596 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
597 | static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
598 | { |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
599 | PurpleHTTPConnection *conn = data; |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
600 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
601 | PurpleConnection *gc = bosh_conn->js->gc; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
602 | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
603 | if (source < 0) { |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
604 | gchar *tmp; |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
605 | 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
|
606 | error); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
607 | 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
|
608 | g_free(tmp); |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
609 | return; |
|
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
610 | } |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
611 | |
|
23611
d811757e19b5
* adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23609
diff
changeset
|
612 | conn->fd = source; |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
613 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
614 | if (conn->connect_cb) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
615 | conn->connect_cb(conn); |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
616 | |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
617 | 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
|
618 | jabber_bosh_http_connection_read, conn); |
| 23609 | 619 | } |
| 620 | ||
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
621 | static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn) |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
622 | { |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
623 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
624 | PurpleConnection *gc = bosh_conn->js->gc; |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
625 | PurpleAccount *account = purple_connection_get_account(gc); |
|
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
626 | |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
627 | if ((purple_proxy_connect(conn, account, conn->host, conn->port, jabber_bosh_http_connection_callback, conn)) == NULL) { |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
628 | purple_connection_error_reason(gc, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
629 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
630 | _("Unable to create socket")); |
|
24872
68de61b562f6
Jabber BOSH: Many fixes
Paul Aurich <darkrain42@pidgin.im>
parents:
23625
diff
changeset
|
631 | } |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
632 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
633 | |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
634 | static void |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
635 | jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
636 | PurpleHTTPRequest *req) |
|
24873
7d1e91d5ec46
Jabber BOSH: more fixes.
Paul Aurich <darkrain42@pidgin.im>
parents:
24872
diff
changeset
|
637 | { |
|
24883
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
638 | PurpleBOSHConnection *bosh_conn = conn->userdata; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
639 | GString *packet = g_string_new(""); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
640 | int ret; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
641 | |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
642 | /* TODO: Should we lie about this HTTP/1.1 support? */ |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
643 | g_string_append_printf(packet, "POST %s HTTP/1.1\r\n" |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
644 | "Host: %s\r\n" |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
645 | "User-Agent: %s\r\n" |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
646 | "Content-Encoding: text/xml; charset=utf-8\r\n" |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
647 | "Content-Length: %d\r\n", |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
648 | req->path, conn->host, bosh_useragent, req->data_len); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
649 | |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
650 | printf("Sending %s\n", packet->str); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
651 | /* 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
|
652 | * low-level code in jabber.c */ |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
653 | ret = write(conn->fd, packet->str, packet->len); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
654 | |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
655 | g_string_free(packet, TRUE); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
656 | g_queue_push_tail(conn->requests, req->cb); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
657 | jabber_bosh_http_request_destroy(req); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
658 | |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
659 | if (ret < 0 && errno == EAGAIN) |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
660 | purple_debug_warning("jabber", "BOSH write would have blocked\n"); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
661 | |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
662 | if (ret <= 0) { |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
663 | purple_connection_error_reason(bosh_conn->js->gc, |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
664 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
665 | _("Write error")); |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
666 | return; |
|
c283f8737645
Jabber BOSH: Store less for each Request/Response
Paul Aurich <darkrain42@pidgin.im>
parents:
24875
diff
changeset
|
667 | } |
|
23613
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
668 | } |
|
1da7c5cbcc54
* doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23612
diff
changeset
|
669 |