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