annotate libpurple/protocols/jabber/bosh.c @ 25184:1ce32c6752fc

Make the Request ID a long long (fit in 2^53-1) Standardize the BOSHConnection receive callbacks and drop two prototypes Some annoying whitespace changes snuck in there, too. Sorry.
author Paul Aurich <paul@darkrain42.org>
date Fri, 05 Dec 2008 06:51:39 +0000
parents 62d9bce9ff74
children 592c2cf00fea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
37 typedef void (*PurpleHTTPRequestCallback)(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata);
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;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
69 GQueue *requests;
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;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
72 char *current_data;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
73 int current_len;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
74
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
75 int pih; /* what? */
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
76 PurpleHTTPConnectionConnectFunction connect_cb;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
77 PurpleHTTPConnectionConnectFunction disconnect_cb;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
78 void *userdata;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
79 };
25038
7768cad83127 * looking for alternative connection methods if direct connection fails
Tobias Markmann <tfar@soc.pidgin.im>
parents:
diff changeset
80
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
81 struct _PurpleHTTPRequest {
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
82 PurpleHTTPRequestCallback cb;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
83 char *method;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
84 char *path;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
85 GHashTable *header;
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 int status;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
93 GHashTable *header;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
94 char *data;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
95 int data_len;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
96 };
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
97
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
98 static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
99 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
100 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
101 static void jabber_bosh_connection_http_received_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
102 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
103
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
104 static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
105 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
106
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
107 static void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value);
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
108
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
109 void jabber_bosh_init(void)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
110 {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
111 GHashTable *ui_info = purple_core_get_ui_info();
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
112 const char *ui_version = NULL;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
113
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
114 if (ui_info)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
115 ui_version = g_hash_table_lookup(ui_info, "version");
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
116
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
117 if (ui_version)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
118 bosh_useragent = g_strdup_printf("%s (libpurple " VERSION ")", ui_version);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
119 else
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
120 bosh_useragent = g_strdup("libpurple " VERSION);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
121 }
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
122
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
123 void jabber_bosh_uninit(void)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
124 {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
125 g_free(bosh_useragent);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
126 bosh_useragent = NULL;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
127 }
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
128
25183
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
129 static PurpleHTTPRequest*
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
130 jabber_bosh_http_request_init(const char *method, const char *path,
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
131 PurpleHTTPRequestCallback cb, void *userdata)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
132 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
133 PurpleHTTPRequest *req = g_new(PurpleHTTPRequest, 1);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
134 req->method = g_strdup(method);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
135 req->path = g_strdup(path);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
136 req->cb = cb;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
137 req->userdata = userdata;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
138 req->header = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
139 return req;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
140 }
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 static void
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
143 jabber_bosh_http_request_destroy(PurpleHTTPRequest *req)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
144 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
145 g_hash_table_destroy(req->header);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
146 g_free(req->method);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
147 g_free(req->path);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
148 g_free(req->data);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
149 g_free(req);
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
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
152 static PurpleHTTPResponse*
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
153 jabber_bosh_http_response_init(void)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
154 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
155 PurpleHTTPResponse *res = g_new0(PurpleHTTPResponse, 1);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
156 res->header = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
157 return res;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
158 }
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
159
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
160 static void
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
161 jabber_bosh_http_response_destroy(PurpleHTTPResponse *res)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
162 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
163 g_hash_table_destroy(res->header);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
164 g_free(res->data);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
165 g_free(res);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
166 }
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
167
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
168 static PurpleHTTPConnection*
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
169 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
170 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
171 PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
172 conn->host = g_strdup(host);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
173 conn->port = port;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
174 conn->fd = -1;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
175 conn->requests = g_queue_new();
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
176
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
177 return conn;
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
178 }
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
179
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
180 static void
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
181 jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
182 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
183 g_free(conn->current_data);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
184 g_free(conn->host);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
185
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
186 if (conn->requests) {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
187 g_queue_foreach(conn->requests, (GFunc)jabber_bosh_http_request_destroy, NULL);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
188 g_queue_free(conn->requests);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
189 }
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
190
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
191 if (conn->current_response)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
192 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
193
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
194 if (conn->ie_handle)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
195 purple_input_remove(conn->ie_handle);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
196 if (conn->fd > 0)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
197 close(conn->fd);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
198
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
199 g_free(conn);
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
200 }
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
201
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
202 PurpleBOSHConnection*
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
203 jabber_bosh_connection_init(JabberStream *js, const char *url)
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
204 {
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
205 PurpleBOSHConnection *conn;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
206 char *host, *path, *user, *passwd;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
207 int port;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
208
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
209 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
210 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
211 return NULL;
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
212 }
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
213
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
214 conn = g_new0(PurpleBOSHConnection, 1);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
215 conn->host = host;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
216 conn->port = port;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
217 conn->path = path;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
218 conn->pipelining = TRUE;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
219
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
220 if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
221 purple_debug_info("jabber", "Ignoring unexpected username and password "
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
222 "in BOSH URL.\n");
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
223 }
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
224
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
225 g_free(user);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
226 g_free(passwd);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
227
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
228 conn->js = js;
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
229 /* FIXME: This doesn't seem very random */
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
230 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
231 conn->ready = FALSE;
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
232 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
233 conn->conn_a->userdata = conn;
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
234
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
235 return conn;
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
236 }
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
237
25183
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
238 void
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
239 jabber_bosh_connection_destroy(PurpleBOSHConnection *conn)
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
240 {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
241 g_free(conn->host);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
242 g_free(conn->path);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
243
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
244 if (conn->conn_a)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
245 jabber_bosh_http_connection_destroy(conn->conn_a);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
246 if (conn->conn_b)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
247 jabber_bosh_http_connection_destroy(conn->conn_b);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
248
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
249 g_free(conn);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
250 }
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
251
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
252 void jabber_bosh_connection_close(PurpleBOSHConnection *conn)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
253 {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
254 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
255 /* 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
256 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
257 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
258 xmlnode_set_attrib(packet, "type", "terminate");
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
259 xmlnode_set_attrib(packet, "xmlns", "http://jabber.org/protocol/httpbind");
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
260 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
261 xmlnode_set_attrib(packet, "rid", rid);
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
262
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
263 jabber_bosh_connection_send_native(conn, packet);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
264 xmlnode_free(packet);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
265 }
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
266
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
267 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
268 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
269 /* 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
270 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 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
279
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25049
diff changeset
280 jabber_bosh_connection_send_native(conn, restart);
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
281 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
282 }
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25049
diff changeset
283
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
284 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
285 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
286
25054
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
287 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
288
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
289 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
290 conn->ready = FALSE;
25055
480736bfcf45 * removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25054
diff changeset
291 purple_connection_error_reason (conn->js->gc,
480736bfcf45 * removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25054
diff changeset
292 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
480736bfcf45 * removing some comment with XML example
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25054
diff changeset
293 _("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
294 return TRUE;
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
295 }
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
296 return FALSE;
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
297 }
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
298
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
299 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
300 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
301 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
302
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
303 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
304 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
305 return;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
306
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
307 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
308 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
309 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
310 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
311 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
312 if (session) {
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
313 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
314 }
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
315 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
316 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
317 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
318 }
25050
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25049
diff changeset
319 }
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25049
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 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
322 xmlnode *child;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
323
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
324 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
325 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
326 return;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
327
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
328 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
329 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
330 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
331 }
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
332
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
333 /* 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
334 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
335 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
336 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
337 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
338 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
339 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
340 } else {
a03a953ba63d * moving BOSH interfacing from jabber_send to jabber_send_raw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25049
diff changeset
341 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
342 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
343 }
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
344 } else {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
345 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
346 }
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
347 }
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
348
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
349 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
350 const char *sid, *version;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
351
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
352 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
353 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
354 return;
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
355
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
356 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
357 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
358
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
359 if (sid) {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
360 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
361 } else {
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
362 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
363 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
364 _("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
365 return;
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
366 }
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
367
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
368 if (version) {
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
369 const char *dot = strstr(version, ".");
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
370 int major = atoi(version);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
371 int minor = atoi(dot + 1);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
372
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
373 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
374
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
375 /* TODO: Are major increments incompatible? */
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
376 if (major > 1 || (major == 1 && minor >= 6)) {
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
377 xmlnode *packet = xmlnode_get_child(node, "features");
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
378 conn->js->use_bosh = TRUE;
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
379 conn->receive_cb = auth_response_cb;
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
380 jabber_stream_features_parse(conn->js, packet);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
381 } else {
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
382 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
383 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
384 _("Unsupported version of BOSH protocol"));
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
385 }
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
386 } else {
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
387 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
388 }
25047
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25046
diff changeset
389 }
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25046
diff changeset
390
25043
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25042
diff changeset
391 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) {
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
392 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
393 /* 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
394 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
395 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
396 xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
397 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
398 /*
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
399 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
400 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
401 */
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
402 xmlnode_set_attrib(init, "to", conn->js->user->domain);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
403 xmlnode_set_attrib(init, "xml:lang", "en");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
404 xmlnode_set_attrib(init, "xmpp:version", "1.0");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
405 xmlnode_set_attrib(init, "ver", "1.6");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
406 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
407 xmlnode_set_attrib(init, "rid", rid);
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
408 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
409 xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
410 xmlnode_set_attrib(init, "hold", "1");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
411
25184
1ce32c6752fc Make the Request ID a long long (fit in 2^53-1)
Paul Aurich <paul@darkrain42.org>
parents: 25183
diff changeset
412 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
413 jabber_bosh_connection_send_native(conn, init);
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
414 xmlnode_free(init);
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
415 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
416
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
417 static void jabber_bosh_connection_http_received_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata) {
25047
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25046
diff changeset
418 PurpleBOSHConnection *conn = userdata;
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25046
diff changeset
419 if (conn->receive_cb) {
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25046
diff changeset
420 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
421 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
422 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
423 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
424 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
425 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
426 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
427 } else {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
428 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
429 }
25047
f747c682a0d9 * calling PurpleBOSHConnection's receive_cb
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25046
diff changeset
430 } 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
431 }
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25042
diff changeset
432
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25042
diff changeset
433 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
434 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
435 /* 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
436 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
437 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
438 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
439 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
440 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
441
25054
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
442 if (node) {
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
443 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
444 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
445 }
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
446 jabber_bosh_connection_send_native(conn, packet);
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
447 xmlnode_free(packet);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
448 }
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
449
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
450 void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
451 const char *data, int len)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
452 {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
453 xmlnode *node = xmlnode_from_str(data, len);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
454 if (node) {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
455 jabber_bosh_connection_send(conn, node);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
456 xmlnode_free(node);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
457 } else {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
458 /*
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
459 * This best emulates what a normal XMPP server would do
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
460 * if you send bad XML.
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
461 */
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
462 purple_connection_error_reason(conn->js->gc,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
463 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
464 _("Cannot send malformed XML"));
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
465 }
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
466 }
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
467
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
468 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
469 PurpleHTTPRequest *request;
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
470
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
471 char *txt = xmlnode_to_formatted_str(node, NULL);
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
472 printf("\njabber_bosh_connection_send\n%s\n", txt);
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
473 g_free(txt);
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
474
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
475 request = jabber_bosh_http_request_init("POST", g_strdup_printf("/%s", conn->path), jabber_bosh_connection_http_received_cb, conn);
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
476 jabber_bosh_http_request_add_to_header(request, "Content-Encoding", "text/xml; charset=utf-8");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
477 request->data = xmlnode_to_str(node, &(request->data_len));
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
478 jabber_bosh_http_request_add_to_header(request, "Content-Length", g_strdup_printf("%d", (int)strlen(request->data)));
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
479 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
480 }
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25042
diff changeset
481
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
482 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
483 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
484 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
485 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
486 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
487 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
488 } 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
489 }
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
490
25183
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
491 void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn)
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
492 {
62d9bce9ff74 Reorder some functions to eliminate prototypes and
Paul Aurich <paul@darkrain42.org>
parents: 25182
diff changeset
493 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
494 }
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
495
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
496 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
497 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
498 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
499 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
500 }
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
501
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
502 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
503 conn->conn_a->connect_cb = jabber_bosh_connection_connected;
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
504 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
505 }
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
506
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
507 static void jabber_bosh_http_connection_receive_parse_header(PurpleHTTPResponse *response, char **data, int *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
508 GHashTable *header = response->header;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
509 char *beginning = *data;
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
510 char *found = g_strstr_len(*data, *len, "\r\n\r\n");
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
511 char *field = NULL;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
512 char *value = NULL;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
513 char *old_data = *data;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
514
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
515 while (*beginning != 'H') ++beginning;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
516 beginning[12] = 0;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
517 response->status = atoi(&beginning[9]);
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
518 beginning = &beginning[13];
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
519 do {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
520 ++beginning;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
521 } while (*beginning != '\n');
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
522 ++beginning;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
523 /* parse HTTP response header */
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
524 for (;beginning != found; ++beginning) {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
525 if (!field) field = beginning;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
526 if (*beginning == ':') {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
527 *beginning = 0;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
528 value = beginning + 1;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
529 } else if (*beginning == '\r') {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
530 *beginning = 0;
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
531 g_hash_table_replace(header, g_ascii_strdown(field, -1), g_strdup(value));
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
532 value = field = 0;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
533 ++beginning;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
534 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
535 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
536 ++beginning; ++beginning; ++beginning; ++beginning;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
537 /* remove the header from data buffer */
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
538 *data = g_strdup(beginning);
25054
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
539 *len = *len - (beginning - old_data);
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
540 g_free(old_data);
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
541 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
542
25043
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25042
diff changeset
543 static void jabber_bosh_http_connection_receive(gpointer data, gint source, PurpleInputCondition condition) {
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
544 char buffer[1025];
25046
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
545 int len;
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
546 PurpleHTTPConnection *conn = data;
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
547 PurpleBOSHConnection *bosh_conn = conn->userdata;
25045
24b97b8359ff * preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25044
diff changeset
548 PurpleHTTPResponse *response = conn->current_response;
24b97b8359ff * preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25044
diff changeset
549
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
550 purple_debug_info("jabber", "jabber_bosh_http_connection_receive\n");
25046
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
551
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
552 len = read(source, buffer, 1024);
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
553 if (len > 0) {
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
554 buffer[len] = 0;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
555 if (conn->current_data == NULL) {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
556 conn->current_len = len;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
557 conn->current_data = g_strdup_printf("%s", buffer);
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
558 } else {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
559 char *old_data = conn->current_data;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
560 conn->current_len += len;
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
561 conn->current_data = g_strdup_printf("%s%s", conn->current_data, buffer);
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
562 g_free(old_data);
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
563 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
564
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
565 if (!response) {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
566 /* check for header footer */
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
567 char *found = g_strstr_len(conn->current_data, conn->current_len, "\r\n\r\n");
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
568 if (found) {
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
569 /* New response */
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
570 response = conn->current_response = jabber_bosh_http_response_init();
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
571 jabber_bosh_http_connection_receive_parse_header(response, &(conn->current_data), &(conn->current_len));
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
572 /* XXX: Crash if there is no Content-Length header */
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
573 response->data_len = atoi(g_hash_table_lookup(response->header, "content-length"));
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
574 } else {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
575 printf("\nDid not receive HTTP header\n");
25046
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
576 }
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
577 }
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
578
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
579 if (response) {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
580 if (conn->current_len >= response->data_len) {
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
581 PurpleHTTPRequest *request = g_queue_pop_head(conn->requests);
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
582
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
583 #warning For a pure HTTP 1.1 stack, this would need to be handled elsewhere.
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
584 if (bosh_conn->ready == TRUE && g_queue_is_empty(conn->requests) == TRUE) {
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
585 jabber_bosh_connection_send(bosh_conn, NULL);
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
586 printf("\n SEND AN EMPTY REQUEST \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
587 }
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
588
25046
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
589 if (request) {
25054
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
590 char *old_data = conn->current_data;
25051
5f70e13db5cc * data buffer for received data. Support for any HTTP resonse size now.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25050
diff changeset
591 response->data = g_memdup(conn->current_data, response->data_len);
25054
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
592 conn->current_data = g_strdup(&conn->current_data[response->data_len]);
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
593 conn->current_len -= response->data_len;
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
594 g_free(old_data);
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
595
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
596 if (request->cb) request->cb(request, response, conn->userdata);
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
597 else purple_debug_info("jabber", "missing request callback!\n");
8badac6cc7c9 * fixing a bug in jabber_bosh_http_connection_receive_parse_header()
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25052
diff changeset
598
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
599 jabber_bosh_http_request_destroy(request);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
600 jabber_bosh_http_response_destroy(response);
25049
f775f6021654 * using libpurple's internal SASL mechanisms during BOSH authentication phase
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25048
diff changeset
601 conn->current_response = NULL;
25046
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
602 } else {
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
603 purple_debug_info("jabber", "received HTTP response but haven't requested anything yet.\n");
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
604 }
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
605 }
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
606 }
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
607 } else if (len == 0) {
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
608 if (conn->ie_handle) {
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
609 purple_input_remove(conn->ie_handle);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
610 conn->ie_handle = 0;
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 if (conn->disconnect_cb)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
613 conn->disconnect_cb(conn);
25046
e28f1711f402 * parsing HTTP response and emitting HTTP request callback
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25045
diff changeset
614 } else {
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
615 purple_debug_info("jabber", "jabber_bosh_http_connection_receive: problem receiving data (%d)\n", len);
25045
24b97b8359ff * preparing handling of multiple requests for pipelining support
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25044
diff changeset
616 }
25043
15d9825a5621 * adding receive callback; preparing receiving and boot code
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25042
diff changeset
617 }
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
618
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
619 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
620 {
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
621 PurpleHTTPConnection *conn = data;
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
622 PurpleBOSHConnection *bosh_conn = conn->userdata;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
623 PurpleConnection *gc = bosh_conn->js->gc;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
624
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
625 if (source < 0) {
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
626 gchar *tmp;
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
627 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
628 error);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
629 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
630 g_free(tmp);
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
631 return;
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
632 }
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
633
25042
1cbe5a9f6efb * adding bosh files to Makefile.am & .mingw
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25040
diff changeset
634 conn->fd = source;
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
635
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
636 if (conn->connect_cb)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
637 conn->connect_cb(conn);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
638
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
639 conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
640 jabber_bosh_http_connection_receive, conn);
25040
b238da95f39a * some refactoring
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25038
diff changeset
641 }
b238da95f39a * some refactoring
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25038
diff changeset
642
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
643 static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
644 {
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
645 PurpleBOSHConnection *bosh_conn = conn->userdata;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
646 PurpleConnection *gc = bosh_conn->js->gc;
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
647 PurpleAccount *account = purple_connection_get_account(gc);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
648
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
649 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
650 purple_connection_error_reason(gc,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
651 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
652 _("Unable to create socket"));
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
653 }
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
654 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
655
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
656 static void jabber_bosh_http_connection_send_request_add_field_to_string(gpointer key, gpointer value, gpointer user_data)
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
657 {
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
658 char **ppacket = user_data;
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
659 char *tmp = *ppacket;
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
660 char *field = key;
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
661 char *val = value;
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
662 *ppacket = g_strdup_printf("%s%s: %s\r\n", tmp, field, val);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
663 g_free(tmp);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
664 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
665
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
666 void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req) {
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
667 char *packet;
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
668 char *tmp;
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
669 jabber_bosh_http_request_add_to_header(req, "Host", conn->host);
25182
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
670 jabber_bosh_http_request_add_to_header(req, "User-Agent", bosh_useragent);
17b60b844803 Jabber BOSH: more fixes.
Paul Aurich <paul@darkrain42.org>
parents: 25181
diff changeset
671
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
672 packet = tmp = g_strdup_printf("%s %s HTTP/1.1\r\n", req->method, req->path);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
673 g_hash_table_foreach(req->header, jabber_bosh_http_connection_send_request_add_field_to_string, &packet);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
674 tmp = packet;
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
675 packet = g_strdup_printf("%s\r\n%s", tmp, req->data);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
676 g_free(tmp);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
677 if (write(conn->fd, packet, strlen(packet)) == -1) purple_debug_info("jabber", "send error\n");
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
678 g_queue_push_tail(conn->requests, req);
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
679 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
680
25181
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
681 static void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value) {
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
682 char *f = g_strdup(field);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
683 char *v = g_strdup(value);
7de1f124f95a Jabber BOSH: Many fixes
Paul Aurich <paul@darkrain42.org>
parents: 25056
diff changeset
684 g_hash_table_replace(req->header, f, v);
25044
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
685 }
f9322be084c4 * doing HTTP requests
Tobias Markmann <tfar@soc.pidgin.im>
parents: 25043
diff changeset
686