libpurple/http.c

Wed, 16 Jan 2013 23:21:30 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Wed, 16 Jan 2013 23:21:30 -0600
changeset 33626
2522d124d883
parent 33522
7a3d131c3086
child 33854
5744cfb1c3d1
permissions
-rw-r--r--

update purple_http_response_get_data to take a second parameter that is a return address for the size of the data

33425
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
1 /**
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
2 * @file http.c HTTP API
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
3 * @ingroup core
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
4 */
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
5
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
6 /* purple
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
7 *
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
10 * source distribution.
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
11 *
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
15 * (at your option) any later version.
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
16 *
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
20 * GNU General Public License for more details.
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
21 *
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
25 */
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
26
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
27 #include "http.h"
379bf9ad6973 Initial HTTP API definitions
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
28
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
29 #include "internal.h"
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
30
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
31 #include "debug.h"
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
32 #include "ntlm.h"
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
33
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
34 #define PURPLE_HTTP_URL_CREDENTIALS_CHARS "a-z0-9.,~_/*!&%?=+\\^-"
33443
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
35 #define PURPLE_HTTP_MAX_RECV_BUFFER_LEN 10240
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
36 #define PURPLE_HTTP_MAX_READ_BUFFER_LEN 10240
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
37
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
38 #define PURPLE_HTTP_REQUEST_DEFAULT_MAX_REDIRECTS 20
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
39 #define PURPLE_HTTP_REQUEST_DEFAULT_TIMEOUT 30
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
40
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
41 typedef struct _PurpleHttpURL PurpleHttpURL;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
42
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
43 typedef struct _PurpleHttpSocket PurpleHttpSocket;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
44
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
45 typedef struct _PurpleHttpHeaders PurpleHttpHeaders;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
46
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
47 struct _PurpleHttpSocket
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
48 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
49 gboolean is_ssl;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
50 PurpleSslConnection *ssl_connection;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
51 PurpleProxyConnectData *raw_connection;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
52 int fd;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
53 guint inpa;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
54 };
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
55
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
56 struct _PurpleHttpRequest
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
57 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
58 int ref_count;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
59
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
60 gchar *url;
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
61 gchar *method;
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
62 PurpleHttpHeaders *headers;
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
63 PurpleHttpCookieJar *cookie_jar;
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
64
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
65 gchar *contents;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
66 int contents_length;
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
67 PurpleHttpContentReader contents_reader;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
68 gpointer contents_reader_data;
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
69 PurpleHttpContentWriter response_writer;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
70 gpointer response_writer_data;
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
71
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
72 int timeout;
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
73 int max_redirects;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
74 gboolean http11;
33446
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
75 int max_length;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
76 };
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
77
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
78 struct _PurpleHttpConnection
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
79 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
80 PurpleConnection *gc;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
81 PurpleHttpCallback callback;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
82 gpointer user_data;
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
83 gboolean is_reading;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
84
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
85 PurpleHttpURL *url;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
86 PurpleHttpRequest *request;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
87 PurpleHttpResponse *response;
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
88
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
89 PurpleHttpSocket socket;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
90 GString *request_header;
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
91 int request_header_written, request_contents_written;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
92 gboolean main_header_got, headers_got;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
93 GString *response_buffer;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
94
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
95 GString *contents_reader_buffer;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
96 gboolean contents_reader_requested;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
97
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
98 int redirects_count;
33446
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
99 int data_length_got;
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
100
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
101 int length_expected, length_got;
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
102
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
103 gboolean is_chunked, in_chunk, chunks_done;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
104 int chunk_length, chunk_got;
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
105
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
106 GList *link_global, *link_gc;
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
107
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
108 guint timeout_handle;
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
109
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
110 PurpleHttpProgressWatcher watcher;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
111 gpointer watcher_user_data;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
112 guint watcher_interval_threshold;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
113 gint64 watcher_last_call;
33521
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
114 guint watcher_delayed_handle;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
115 };
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
116
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
117 struct _PurpleHttpResponse
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
118 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
119 int code;
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
120 gchar *error;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
121
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
122 GString *contents;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
123 PurpleHttpHeaders *headers;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
124 };
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
125
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
126 struct _PurpleHttpURL
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
127 {
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
128 gchar *protocol;
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
129 gchar *user;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
130 gchar *password;
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
131 gchar *host;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
132 int port;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
133 gchar *path;
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
134 gchar *fragment;
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
135 };
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
136
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
137 struct _PurpleHttpHeaders
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
138 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
139 GList *list;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
140 GHashTable *by_name;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
141 };
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
142
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
143 typedef struct
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
144 {
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
145 time_t expires;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
146 gchar *value;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
147 } PurpleHttpCookie;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
148
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
149 struct _PurpleHttpCookieJar
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
150 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
151 int ref_count;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
152
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
153 GHashTable *tab;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
154 };
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
155
33462
f36899d03630 Cleaning up
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33460
diff changeset
156 static time_t purple_http_rfc1123_to_time(const gchar *str);
f36899d03630 Cleaning up
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33460
diff changeset
157
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
158 static PurpleHttpConnection * purple_http_connection_new(
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
159 PurpleHttpRequest *request, PurpleConnection *gc);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
160 static void purple_http_connection_terminate(PurpleHttpConnection *hc);
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
161 static void purple_http_conn_notify_progress_watcher(PurpleHttpConnection *hc);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
162
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
163 static PurpleHttpResponse * purple_http_response_new(void);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
164 static void purple_http_response_free(PurpleHttpResponse *response);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
165
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
166 static void purple_http_cookie_jar_parse(PurpleHttpCookieJar *cookie_jar,
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
167 GList *values);
33458
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
168 static gchar * purple_http_cookie_jar_gen(PurpleHttpCookieJar *cookie_jar);
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
169 gchar * purple_http_cookie_jar_dump(PurpleHttpCookieJar *cjar);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
170
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
171 static PurpleHttpURL * purple_http_url_parse(const char *url);
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
172 static void purple_http_url_free(PurpleHttpURL *parsed_url);
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
173 static void purple_http_url_relative(PurpleHttpURL *base_url,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
174 PurpleHttpURL *relative_url);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
175 static gchar * purple_http_url_print(PurpleHttpURL *parsed_url);
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
176
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
177 static GRegex *purple_http_re_url, *purple_http_re_url_host,
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
178 *purple_http_re_rfc1123;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
179
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
180 /**
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
181 * Values: pointers to running PurpleHttpConnection.
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
182 */
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
183 static GList *purple_http_hc_list;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
184
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
185 /**
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
186 * Keys: pointers to PurpleConnection.
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
187 * Values: GList of pointers to running PurpleHttpConnection.
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
188 */
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
189 static GHashTable *purple_http_hc_by_gc;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
190
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
191 /**
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
192 * Keys: pointers to PurpleHttpConnection.
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
193 * Values: pointers to links in purple_http_hc_list.
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
194 */
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
195 static GHashTable *purple_http_hc_by_ptr;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
196
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
197 /*** Helper functions *********************************************************/
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
198
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
199 static time_t purple_http_rfc1123_to_time(const gchar *str)
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
200 {
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
201 static const gchar *months[13] = {"jan", "feb", "mar", "apr", "may", "jun",
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
202 "jul", "aug", "sep", "oct", "nov", "dec", NULL};
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
203 GMatchInfo *match_info;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
204 gchar *d_date, *d_month, *d_year, *d_time;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
205 int month;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
206 gchar *iso_date;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
207 time_t t;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
208
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
209 g_return_val_if_fail(str != NULL, 0);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
210
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
211 g_regex_match(purple_http_re_rfc1123, str, 0, &match_info);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
212 if (!g_match_info_matches(match_info)) {
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
213 g_match_info_free(match_info);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
214 return 0;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
215 }
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
216 g_match_info_free(match_info);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
217
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
218 d_date = g_match_info_fetch(match_info, 1);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
219 d_month = g_match_info_fetch(match_info, 2);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
220 d_year = g_match_info_fetch(match_info, 3);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
221 d_time = g_match_info_fetch(match_info, 4);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
222
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
223 month = 0;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
224 while (months[month] != NULL)
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
225 {
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
226 if (0 == g_ascii_strcasecmp(d_month, months[month]))
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
227 break;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
228 month++;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
229 }
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
230 month++;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
231
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
232 iso_date = g_strdup_printf("%s-%02d-%sT%s+00:00",
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
233 d_year, month, d_date, d_time);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
234
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
235 g_free(d_date);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
236 g_free(d_month);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
237 g_free(d_year);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
238 g_free(d_time);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
239
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
240 if (month > 12) {
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
241 purple_debug_warning("http", "Invalid month: %s\n", d_month);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
242 g_free(iso_date);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
243 return 0;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
244 }
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
245
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
246 t = purple_str_to_time(iso_date, TRUE, NULL, NULL, NULL);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
247
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
248 g_free(iso_date);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
249
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
250 return t;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
251 }
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
252
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
253 /*** Headers collection *******************************************************/
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
254
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
255 static PurpleHttpHeaders * purple_http_headers_new(void);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
256 static void purple_http_headers_free(PurpleHttpHeaders *hdrs);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
257 static void purple_http_headers_add(PurpleHttpHeaders *hdrs, const gchar *key,
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
258 const gchar *value);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
259 static const GList * purple_http_headers_get_all(PurpleHttpHeaders *hdrs);
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
260 static GList * purple_http_headers_get_all_by_name(
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
261 PurpleHttpHeaders *hdrs, const gchar *key);
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
262 static const gchar * purple_http_headers_get(PurpleHttpHeaders *hdrs,
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
263 const gchar *key);
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
264 static gboolean purple_http_headers_get_int(PurpleHttpHeaders *hdrs,
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
265 const gchar *key, int *dst);
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
266 static gboolean purple_http_headers_match(PurpleHttpHeaders *hdrs,
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
267 const gchar *key, const gchar *value);
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
268 static gchar * purple_http_headers_dump(PurpleHttpHeaders *hdrs);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
269
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
270 static PurpleHttpHeaders * purple_http_headers_new(void)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
271 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
272 PurpleHttpHeaders *hdrs = g_new0(PurpleHttpHeaders, 1);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
273
33437
fb792f8b6265 Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33436
diff changeset
274 hdrs->by_name = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
fb792f8b6265 Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33436
diff changeset
275 (GDestroyNotify)g_list_free);
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
276
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
277 return hdrs;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
278 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
279
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
280 static void purple_http_headers_free_kvp(PurpleKeyValuePair *kvp)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
281 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
282 g_free(kvp->key);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
283 g_free(kvp->value);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
284 g_free(kvp);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
285 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
286
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
287 static void purple_http_headers_free(PurpleHttpHeaders *hdrs)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
288 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
289 if (hdrs == NULL)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
290 return;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
291
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
292 g_hash_table_destroy(hdrs->by_name);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
293 g_list_free_full(hdrs->list,
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
294 (GDestroyNotify)purple_http_headers_free_kvp);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
295 g_free(hdrs);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
296 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
297
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
298 static void purple_http_headers_add(PurpleHttpHeaders *hdrs, const gchar *key,
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
299 const gchar *value)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
300 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
301 PurpleKeyValuePair *kvp;
33437
fb792f8b6265 Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33436
diff changeset
302 GList *named_values, *new_values;
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
303 gchar *key_low;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
304
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
305 g_return_if_fail(hdrs != NULL);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
306 g_return_if_fail(key != NULL);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
307 g_return_if_fail(value != NULL);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
308
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
309 kvp = g_new0(PurpleKeyValuePair, 1);
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
310 kvp->key = g_strdup(key);
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
311 kvp->value = g_strdup(value);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
312 hdrs->list = g_list_append(hdrs->list, kvp);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
313
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
314 key_low = g_ascii_strdown(key, -1);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
315 named_values = g_hash_table_lookup(hdrs->by_name, key_low);
33437
fb792f8b6265 Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33436
diff changeset
316 new_values = g_list_append(named_values, kvp->value);
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
317 if (named_values)
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
318 g_free(key_low);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
319 else
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
320 g_hash_table_insert(hdrs->by_name, key_low, new_values);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
321 }
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
322
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
323 static void purple_http_headers_remove(PurpleHttpHeaders *hdrs,
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
324 const gchar *key)
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
325 {
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
326 GList *it, *curr;
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
327
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
328 g_return_if_fail(hdrs != NULL);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
329 g_return_if_fail(key != NULL);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
330
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
331 if (!g_hash_table_remove(hdrs->by_name, key))
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
332 return;
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
333
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
334 /* Could be optimized to O(1). */
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
335 it = g_list_first(hdrs->list);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
336 while (it)
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
337 {
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
338 PurpleKeyValuePair *kvp = it->data;
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
339 curr = it;
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
340 it = g_list_next(it);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
341 if (g_ascii_strcasecmp(kvp->key, key) != 0)
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
342 continue;
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
343
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
344 hdrs->list = g_list_delete_link(hdrs->list, curr);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
345 purple_http_headers_free_kvp(kvp);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
346 }
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
347 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
348
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
349 static const GList * purple_http_headers_get_all(PurpleHttpHeaders *hdrs)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
350 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
351 return hdrs->list;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
352 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
353
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
354 /* return const */
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
355 static GList * purple_http_headers_get_all_by_name(
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
356 PurpleHttpHeaders *hdrs, const gchar *key)
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
357 {
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
358 GList *values;
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
359 gchar *key_low;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
360
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
361 g_return_val_if_fail(hdrs != NULL, NULL);
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
362 g_return_val_if_fail(key != NULL, NULL);
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
363
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
364 key_low = g_ascii_strdown(key, -1);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
365 values = g_hash_table_lookup(hdrs->by_name, key_low);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
366 g_free(key_low);
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
367
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
368 return values;
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
369 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
370
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
371 static const gchar * purple_http_headers_get(PurpleHttpHeaders *hdrs,
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
372 const gchar *key)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
373 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
374 const GList *values = purple_http_headers_get_all_by_name(hdrs, key);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
375
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
376 if (!values)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
377 return NULL;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
378
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
379 return values->data;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
380 }
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
381
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
382 static gboolean purple_http_headers_get_int(PurpleHttpHeaders *hdrs,
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
383 const gchar *key, int *dst)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
384 {
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
385 int val;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
386 const gchar *str;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
387
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
388 str = purple_http_headers_get(hdrs, key);
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
389 if (!str)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
390 return FALSE;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
391
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
392 if (1 != sscanf(str, "%d", &val))
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
393 return FALSE;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
394
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
395 *dst = val;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
396 return TRUE;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
397 }
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
398
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
399 static gboolean purple_http_headers_match(PurpleHttpHeaders *hdrs,
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
400 const gchar *key, const gchar *value)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
401 {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
402 const gchar *str;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
403
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
404 str = purple_http_headers_get(hdrs, key);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
405 if (str == NULL || value == NULL)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
406 return str == value;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
407
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
408 return (g_ascii_strcasecmp(str, value) == 0);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
409 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
410
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
411 static gchar * purple_http_headers_dump(PurpleHttpHeaders *hdrs)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
412 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
413 const GList *hdr;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
414
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
415 GString *s = g_string_new("");
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
416
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
417 hdr = purple_http_headers_get_all(hdrs);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
418 while (hdr) {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
419 PurpleKeyValuePair *kvp = hdr->data;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
420 hdr = g_list_next(hdr);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
421
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
422 g_string_append_printf(s, "%s: %s%s", kvp->key,
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
423 (gchar*)kvp->value, hdr ? "\n" : "");
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
424 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
425
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
426 return g_string_free(s, FALSE);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
427 }
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
428
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
429 /*** HTTP protocol backend ****************************************************/
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
431 static void _purple_http_disconnect(PurpleHttpConnection *hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
432
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
433 static void _purple_http_gen_headers(PurpleHttpConnection *hc);
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
434 static gboolean _purple_http_recv_loopbody(PurpleHttpConnection *hc, gint fd);
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
435 static void _purple_http_recv(gpointer _hc, gint fd,
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
436 PurpleInputCondition cond);
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
437 static void _purple_http_recv_ssl(gpointer _hc,
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
438 PurpleSslConnection *ssl_connection, PurpleInputCondition cond);
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
439 static void _purple_http_send(gpointer _hc, gint fd, PurpleInputCondition cond);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
440
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
441 static void _purple_http_connected_raw(gpointer _hc, gint source,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
442 const gchar *error_message);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
443 static void _purple_http_connected_ssl(gpointer _hc,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
444 PurpleSslConnection *ssl_connection, PurpleInputCondition cond);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
445 static void _purple_http_connected_ssl_error(
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
446 PurpleSslConnection *ssl_connection, PurpleSslErrorType error,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
447 gpointer _hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
448
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
449 /* closes current connection (if exists), estabilishes one and proceeds with
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
450 * request */
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
451 static gboolean _purple_http_reconnect(PurpleHttpConnection *hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
452
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
453 static void _purple_http_error(PurpleHttpConnection *hc, const char *format,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
454 ...) G_GNUC_PRINTF(2, 3);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
455
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
456 static void _purple_http_error(PurpleHttpConnection *hc, const char *format,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
457 ...)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
458 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
459 va_list args;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
460
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
461 va_start(args, format);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
462 hc->response->error = g_strdup_vprintf(format, args);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
463 va_end(args);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
464
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
465 purple_http_conn_cancel(hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
466 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
467
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
468 static void _purple_http_gen_headers(PurpleHttpConnection *hc)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
469 {
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
470 GString *h;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
471 PurpleHttpURL *url;
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
472 const GList *hdr;
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
473 PurpleHttpRequest *req;
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
474 PurpleHttpHeaders *hdrs;
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
475 gchar *request_url, *tmp_url = NULL;
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
476
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
477 PurpleProxyInfo *proxy;
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
478 gboolean proxy_http = FALSE;
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
479 const gchar *proxy_username, *proxy_password;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
480
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
481 g_return_if_fail(hc != NULL);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
482
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
483 if (hc->request_header != NULL)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
484 return;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
485
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
486 req = hc->request;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
487 url = hc->url;
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
488 hdrs = req->headers;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
489 proxy = purple_proxy_get_setup(hc->gc ?
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
490 purple_connection_get_account(hc->gc) : NULL);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
491
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
492 proxy_http = (purple_proxy_info_get_type(proxy) == PURPLE_PROXY_HTTP ||
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
493 purple_proxy_info_get_type(proxy) == PURPLE_PROXY_USE_ENVVAR);
33454
c5c9135ffafa Tunelled http proxy is not a http proxy
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33453
diff changeset
494 /* this is HTTP proxy, but used with tunelling with CONNECT */
c5c9135ffafa Tunelled http proxy is not a http proxy
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33453
diff changeset
495 if (proxy_http && url->port != 80)
c5c9135ffafa Tunelled http proxy is not a http proxy
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33453
diff changeset
496 proxy_http = FALSE;
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
497
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
498 hc->request_header = h = g_string_new("");
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
499 hc->request_header_written = 0;
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
500 hc->request_contents_written = 0;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
501
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
502 if (proxy_http)
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
503 request_url = tmp_url = purple_http_url_print(url);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
504 else
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
505 request_url = url->path;
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
506
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
507 g_string_append_printf(h, "%s %s HTTP/%s\r\n",
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
508 req->method ? req->method : "GET",
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
509 request_url,
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
510 req->http11 ? "1.1" : "1.0");
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
511
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
512 if (tmp_url)
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
513 g_free(tmp_url);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
514
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
515 if (!purple_http_headers_get(hdrs, "host"))
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
516 g_string_append_printf(h, "Host: %s\r\n", url->host);
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
517 if (!purple_http_headers_get(hdrs, "connection"))
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
518 g_string_append(h, "Connection: close\r\n");
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
519 if (!purple_http_headers_get(hdrs, "accept"))
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
520 g_string_append(h, "Accept: */*\r\n");
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
521
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
522 if (req->contents_length > 0 && !purple_http_headers_get(hdrs,
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
523 "content-length"))
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
524 g_string_append_printf(h, "Content-Length: %u\r\n",
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
525 req->contents_length);
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
526
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
527 if (proxy_http)
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
528 g_string_append(h, "Proxy-Connection: close\r\n");
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
529
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
530 proxy_username = purple_proxy_info_get_username(proxy);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
531 if (proxy_http && proxy_username != NULL && proxy_username[0] != '\0') {
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
532 gchar *proxy_auth, *ntlm_type1, *tmp;
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
533 int len;
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
534
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
535 proxy_password = purple_proxy_info_get_password(proxy);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
536 if (proxy_password == NULL)
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
537 proxy_password = "";
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
538
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
539 tmp = g_strdup_printf("%s:%s", proxy_username, proxy_password);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
540 len = strlen(tmp);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
541 proxy_auth = purple_base64_encode((const guchar *)tmp, len);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
542 memset(tmp, 0, len);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
543 g_free(tmp);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
544
33469
6c2fa6d8037d HTTP: simplify hostname getting
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33468
diff changeset
545 ntlm_type1 = purple_ntlm_gen_type1(purple_get_host_name(), "");
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
546
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
547 g_string_append_printf(h, "Proxy-Authorization: Basic %s\r\n",
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
548 proxy_auth);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
549 g_string_append_printf(h, "Proxy-Authorization: NTLM %s\r\n",
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
550 ntlm_type1);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
551 g_string_append(h, "Proxy-Connection: Close\r\n");
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
552
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
553 memset(proxy_auth, 0, strlen(proxy_auth));
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
554 g_free(proxy_auth);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
555 g_free(ntlm_type1);
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
556 }
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
557
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
558 hdr = purple_http_headers_get_all(hdrs);
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
559 while (hdr) {
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
560 PurpleKeyValuePair *kvp = hdr->data;
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
561 hdr = g_list_next(hdr);
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
562
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
563 g_string_append_printf(h, "%s: %s\r\n",
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
564 kvp->key, (gchar*)kvp->value);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
565 }
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
566
33458
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
567 if (!purple_http_cookie_jar_is_empty(req->cookie_jar)) {
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
568 gchar * cookies = purple_http_cookie_jar_gen(req->cookie_jar);
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
569 g_string_append_printf(h, "Cookie: %s\r\n", cookies);
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
570 g_free(cookies);
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
571 }
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
572
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
573 g_string_append_printf(h, "\r\n");
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
574
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
575 if (purple_debug_is_unsafe() && purple_debug_is_verbose()) {
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
576 purple_debug_misc("http", "Generated request headers:\n%s",
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
577 h->str);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
578 }
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
579 }
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
580
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
581 static gboolean _purple_http_recv_headers(PurpleHttpConnection *hc,
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
582 const gchar *buf, int len)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
583 {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
584 gchar *eol, *delim;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
585
33435
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
586 if (hc->headers_got) {
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
587 purple_debug_error("http", "Headers already got\n");
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
588 _purple_http_error(hc, _("Error parsing HTTP"));
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
589 return FALSE;
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
590 }
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
591
33443
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
592 g_string_append_len(hc->response_buffer, buf, len);
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
593 if (hc->response_buffer->len > PURPLE_HTTP_MAX_RECV_BUFFER_LEN) {
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
594 purple_debug_error("http",
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
595 "Buffer too big when parsing headers\n");
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
596 _purple_http_error(hc, _("Error parsing HTTP"));
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
597 return FALSE;
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
598 }
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
599
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
600 while ((eol = strstr(hc->response_buffer->str, "\r\n"))
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
601 != NULL) {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
602 gchar *hdrline = hc->response_buffer->str;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
603 int hdrline_len = eol - hdrline;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
604
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
605 hdrline[hdrline_len] = '\0';
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
606
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
607 if (hdrline[0] == '\0') {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
608 if (!hc->main_header_got) {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
609 hc->response->code = 0;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
610 purple_debug_warning("http",
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
611 "Main header not present\n");
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
612 _purple_http_error(hc, _("Error parsing HTTP"));
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
613 return FALSE;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
614 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
615 hc->headers_got = TRUE;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
616 if (purple_debug_is_verbose())
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
617 purple_debug_misc("http", "Got headers end\n");
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
618 } else if (!hc->main_header_got) {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
619 hc->main_header_got = TRUE;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
620 delim = strchr(hdrline, ' ');
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
621 if (delim == NULL || 1 != sscanf(delim + 1, "%d",
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
622 &hc->response->code)) {
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
623 purple_debug_warning("http",
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
624 "Invalid response code\n");
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
625 _purple_http_error(hc, _("Error parsing HTTP"));
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
626 return FALSE;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
627 }
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
628 if (purple_debug_is_verbose())
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
629 purple_debug_misc("http",
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
630 "Got main header with code %d\n",
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
631 hc->response->code);
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
632 } else {
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
633 if (purple_debug_is_verbose() &&
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
634 purple_debug_is_unsafe())
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
635 purple_debug_misc("http", "Got header: %s\n",
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
636 hdrline);
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
637 delim = strchr(hdrline, ':');
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
638 if (delim == NULL || delim == hdrline) {
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
639 purple_debug_warning("http",
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
640 "Bad header delimiter\n");
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
641 _purple_http_error(hc, _("Error parsing HTTP"));
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
642 return FALSE;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
643 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
644 *delim++ = '\0';
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
645 while (*delim == ' ')
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
646 delim++;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
647
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
648 purple_http_headers_add(hc->response->headers, hdrline, delim);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
649 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
650
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
651 g_string_erase(hc->response_buffer, 0, hdrline_len + 2);
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
652 if (hc->headers_got)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
653 break;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
654 }
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
655 return TRUE;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
656 }
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
657
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
658 static gboolean _purple_http_recv_body_data(PurpleHttpConnection *hc,
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
659 const gchar *buf, int len)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
660 {
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
661 int current_offset = hc->data_length_got;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
662
33446
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
663 if (hc->request->max_length >= 0) {
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
664 if (hc->data_length_got + len > hc->request->max_length) {
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
665 len = hc->request->max_length - hc->data_length_got;
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
666 hc->length_expected = hc->length_got;
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
667 }
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
668 }
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
669 hc->data_length_got += len;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
670
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
671 if (len == 0)
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
672 return TRUE;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
673
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
674 if (hc->request->response_writer != NULL) {
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
675 gboolean succ;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
676 succ = hc->request->response_writer(hc, hc->response, buf,
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
677 current_offset, len, hc->request->response_writer_data);
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
678 if (!succ) {
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
679 purple_debug_error("http",
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
680 "Cannot write using callback\n");
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
681 _purple_http_error(hc,
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
682 _("Error handling retrieved data"));
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
683 return FALSE;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
684 }
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
685 } else {
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
686 if (hc->response->contents == NULL)
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
687 hc->response->contents = g_string_new("");
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
688 g_string_append_len(hc->response->contents, buf, len);
33446
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
689 }
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
690
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
691 purple_http_conn_notify_progress_watcher(hc);
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
692 return TRUE;
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
693 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
694
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
695 static gboolean _purple_http_recv_body_chunked(PurpleHttpConnection *hc,
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
696 const gchar *buf, int len)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
697 {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
698 gchar *eol, *line;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
699 int line_len;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
700
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
701 if (hc->chunks_done)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
702 return FALSE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
703 if (!hc->response_buffer)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
704 hc->response_buffer = g_string_new("");
33436
abec627c3a47 Segfault found, temporarily fixed
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33435
diff changeset
705
33443
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
706 g_string_append_len(hc->response_buffer, buf, len);
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
707 if (hc->response_buffer->len > PURPLE_HTTP_MAX_RECV_BUFFER_LEN) {
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
708 purple_debug_error("http",
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
709 "Buffer too big when searching for chunk\n");
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
710 _purple_http_error(hc, _("Error parsing HTTP"));
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
711 return FALSE;
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
712 }
ab563d4c927a Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33439
diff changeset
713
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
714 while (hc->response_buffer->len > 0) {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
715 if (hc->in_chunk) {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
716 int got_now = hc->response_buffer->len;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
717 if (hc->chunk_got + got_now > hc->chunk_length)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
718 got_now = hc->chunk_length - hc->chunk_got;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
719 hc->chunk_got += got_now;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
720
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
721 if (!_purple_http_recv_body_data(hc,
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
722 hc->response_buffer->str, got_now))
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
723 return FALSE;
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
724
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
725 g_string_erase(hc->response_buffer, 0, got_now);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
726 hc->in_chunk = (hc->chunk_got < hc->chunk_length);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
727
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
728 if (purple_debug_is_verbose())
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
729 purple_debug_misc("http", "Chunk (%d/%d)\n",
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
730 hc->chunk_got, hc->chunk_length);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
731
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
732 continue;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
733 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
734
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
735 line = hc->response_buffer->str;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
736 eol = strstr(line, "\r\n");
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
737 if (eol == line) {
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
738 g_string_erase(hc->response_buffer, 0, 2);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
739 line = hc->response_buffer->str;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
740 eol = strstr(line, "\r\n");
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
741 }
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
742 if (eol == NULL) {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
743 /* waiting for more data (unlikely, but possible) */
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
744 if (hc->response_buffer->len > 20) {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
745 purple_debug_warning("http", "Chunk length not "
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
746 "found (buffer too large)\n");
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
747 _purple_http_error(hc, _("Error parsing HTTP"));
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
748 return FALSE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
749 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
750 return TRUE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
751 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
752 line_len = eol - line;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
753
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
754 if (1 != sscanf(line, "%x", &hc->chunk_length)) {
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
755 if (purple_debug_is_unsafe())
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
756 purple_debug_warning("http",
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
757 "Chunk length not found in [%s]\n",
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
758 line);
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
759 else
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
760 purple_debug_warning("http",
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
761 "Chunk length not found\n");
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
762 _purple_http_error(hc, _("Error parsing HTTP"));
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
763 return FALSE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
764 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
765 hc->chunk_got = 0;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
766 hc->in_chunk = TRUE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
767
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
768 if (purple_debug_is_verbose())
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
769 purple_debug_misc("http", "Found chunk of length %d\n", hc->chunk_length);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
770
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
771 g_string_erase(hc->response_buffer, 0, line_len + 2);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
772
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
773 if (hc->chunk_length == 0) {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
774 hc->chunks_done = TRUE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
775 hc->in_chunk = FALSE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
776 return TRUE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
777 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
778 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
779
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
780 return TRUE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
781 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
782
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
783 static gboolean _purple_http_recv_body(PurpleHttpConnection *hc,
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
784 const gchar *buf, int len)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
785 {
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
786 if (hc->is_chunked)
33435
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
787 {
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
788 hc->length_got += len;
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
789 return _purple_http_recv_body_chunked(hc, buf, len);
33435
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
790 }
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
791
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
792 if (hc->length_expected >= 0 &&
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
793 len + hc->length_got > hc->length_expected)
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
794 len = hc->length_expected - hc->length_got;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
795 hc->length_got += len;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
796
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
797 return _purple_http_recv_body_data(hc, buf, len);
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
798 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
799
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
800 static gboolean _purple_http_recv_loopbody(PurpleHttpConnection *hc, gint fd)
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
801 {
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
802 PurpleHttpSocket *hs = &hc->socket;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
803 int len;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
804 gchar buf[4096];
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
805 gboolean got_anything;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
806
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
807 if (hs->is_ssl)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
808 len = purple_ssl_read(hs->ssl_connection, buf, sizeof(buf));
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
809 else
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
810 len = read(fd, buf, sizeof(buf));
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
811 got_anything = (len > 0);
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
812
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
813 if (len < 0 && errno == EAGAIN)
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
814 return FALSE;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
815
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
816 if (len < 0) {
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
817 _purple_http_error(hc, _("Error reading from %s: %s"),
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
818 hc->url->host, g_strerror(errno));
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
819 return FALSE;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
820 }
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
821
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
822 /* EOF */
33435
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
823 if (len == 0) {
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
824 if (hc->length_expected >= 0 &&
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
825 hc->length_got < hc->length_expected) {
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
826 purple_debug_warning("http", "No more data while reading"
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
827 " contents\n");
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
828 _purple_http_error(hc, _("Error parsing HTTP"));
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
829 return FALSE;
33435
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
830 }
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
831 if (hc->headers_got)
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
832 hc->length_expected = hc->length_got;
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
833 else {
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
834 purple_debug_warning("http", "No more data while "
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
835 "parsing headers\n");
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
836 _purple_http_error(hc, _("Error parsing HTTP"));
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
837 return FALSE;
33435
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
838 }
ab0560aa8ca4 Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33434
diff changeset
839 }
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
840
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
841 if (!hc->headers_got && len > 0) {
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
842 if (!_purple_http_recv_headers(hc, buf, len))
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
843 return FALSE;
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
844 len = 0;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
845 if (hc->headers_got) {
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
846 if (!purple_http_headers_get_int(hc->response->headers,
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
847 "Content-Length", &hc->length_expected))
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
848 hc->length_expected = -1;
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
849 hc->is_chunked = (purple_http_headers_match(
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
850 hc->response->headers,
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
851 "Transfer-Encoding", "chunked"));
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
852 }
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
853 if (hc->headers_got && hc->response_buffer &&
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
854 hc->response_buffer->len > 0) {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
855 int buffer_len = hc->response_buffer->len;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
856 gchar *buffer = g_string_free(hc->response_buffer, FALSE);
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
857 hc->response_buffer = NULL;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
858 _purple_http_recv_body(hc, buffer, buffer_len);
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
859 }
33455
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
860 if (!hc->headers_got)
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
861 return got_anything;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
862 }
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
863
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
864 if (len > 0) {
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
865 if (!_purple_http_recv_body(hc, buf, len))
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
866 return FALSE;
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
867 }
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
868
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
869 if (hc->is_chunked && hc->chunks_done)
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
870 hc->length_expected = hc->length_got;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
871
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
872 if (hc->length_expected >= 0 && hc->length_got >= hc->length_expected) {
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
873 const gchar *redirect;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
874
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
875 if (!hc->headers_got) {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
876 hc->response->code = 0;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
877 purple_debug_warning("http", "No headers got\n");
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
878 _purple_http_error(hc, _("Error parsing HTTP"));
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
879 return FALSE;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
880 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
881
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
882 if (purple_debug_is_unsafe() && purple_debug_is_verbose()) {
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
883 gchar *hdrs = purple_http_headers_dump(
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
884 hc->response->headers);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
885 purple_debug_misc("http", "Got response headers: %s\n",
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
886 hdrs);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
887 g_free(hdrs);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
888 }
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
889
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
890 purple_http_cookie_jar_parse(hc->request->cookie_jar,
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
891 purple_http_headers_get_all_by_name(
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
892 hc->response->headers, "Set-Cookie"));
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
893
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
894 if (purple_debug_is_unsafe() && purple_debug_is_verbose() &&
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
895 !purple_http_cookie_jar_is_empty(
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
896 hc->request->cookie_jar)) {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
897 gchar *cookies = purple_http_cookie_jar_dump(
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
898 hc->request->cookie_jar);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
899 purple_debug_misc("http", "Cookies: %s\n", cookies);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
900 g_free(cookies);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
901 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
902
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
903 if (hc->response->code == 407) {
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
904 _purple_http_error(hc, _("Invalid proxy credentials"));
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
905 return FALSE;
33453
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
906 }
3cb58ea9667c HTTP Proxy support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33452
diff changeset
907
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
908 redirect = purple_http_headers_get(hc->response->headers,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
909 "location");
33445
1bcbdca07787 Allow infinite amount of redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33444
diff changeset
910 if (redirect && (hc->request->max_redirects == -1 ||
1bcbdca07787 Allow infinite amount of redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33444
diff changeset
911 hc->request->max_redirects > hc->redirects_count)) {
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
912 PurpleHttpURL *url = purple_http_url_parse(redirect);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
913
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
914 hc->redirects_count++;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
915
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
916 if (!url) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
917 if (purple_debug_is_unsafe())
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
918 purple_debug_warning("http",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
919 "Invalid redirect to %s\n",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
920 redirect);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
921 else
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
922 purple_debug_warning("http",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
923 "Invalid redirect\n");
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
924 _purple_http_error(hc, _("Error parsing HTTP"));
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
925 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
926
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
927 purple_http_url_relative(hc->url, url);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
928 purple_http_url_free(url);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
929
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
930 _purple_http_reconnect(hc);
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
931 return FALSE;
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
932 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
933
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
934 _purple_http_disconnect(hc);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
935 purple_http_connection_terminate(hc);
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
936 return FALSE;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
937 }
33522
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
938
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
939 return got_anything;
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
940 }
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
941
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
942 static void _purple_http_recv(gpointer _hc, gint fd, PurpleInputCondition cond)
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
943 {
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
944 PurpleHttpConnection *hc = _hc;
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
945
7a3d131c3086 HTTP: don't freeze download on files larger than buffer size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33521
diff changeset
946 while (_purple_http_recv_loopbody(hc, fd));
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
947 }
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
948
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
949 static void _purple_http_recv_ssl(gpointer _hc,
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
950 PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
951 {
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
952 _purple_http_recv(_hc, -1, cond);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
953 }
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
954
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
955 static void _purple_http_send_got_data(PurpleHttpConnection *hc,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
956 gboolean success, gboolean eof, size_t stored)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
957 {
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
958 int estimated_length;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
959
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
960 g_return_if_fail(hc != NULL);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
961
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
962 if (!success) {
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
963 _purple_http_error(hc, _("Error requesting data to write"));
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
964 return;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
965 }
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
966
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
967 hc->contents_reader_requested = FALSE;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
968 g_string_set_size(hc->contents_reader_buffer, stored);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
969 if (!eof)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
970 return;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
971
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
972 estimated_length = hc->request_contents_written + stored;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
973
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
974 if (hc->request->contents_length != -1 &&
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
975 hc->request->contents_length != estimated_length) {
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
976 purple_debug_warning("http",
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
977 "Invalid amount of data has been written\n");
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
978 }
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
979 hc->request->contents_length = estimated_length;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
980 }
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
981
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
982 static void _purple_http_send(gpointer _hc, gint fd, PurpleInputCondition cond)
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
983 {
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
984 PurpleHttpConnection *hc = _hc;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
985 PurpleHttpSocket *hs = &hc->socket;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
986 int written, write_len;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
987 const gchar *write_from;
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
988 gboolean writing_headers;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
989
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
990 /* Waiting for data. This could be written more efficiently, by removing
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
991 * (and later, adding) hs->inpa. */
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
992 if (hc->contents_reader_requested)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
993 return;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
994
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
995 _purple_http_gen_headers(hc);
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
996
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
997 writing_headers =
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
998 (hc->request_header_written < hc->request_header->len);
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
999 if (writing_headers) {
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1000 write_from = hc->request_header->str +
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1001 hc->request_header_written;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1002 write_len = hc->request_header->len -
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1003 hc->request_header_written;
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1004 } else if (hc->request->contents_reader) {
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1005 if (hc->contents_reader_requested)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1006 return; /* waiting for data */
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1007 if (!hc->contents_reader_buffer)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1008 hc->contents_reader_buffer = g_string_new("");
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1009 if (hc->contents_reader_buffer->len == 0) {
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1010 hc->contents_reader_requested = TRUE;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1011 g_string_set_size(hc->contents_reader_buffer,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1012 PURPLE_HTTP_MAX_READ_BUFFER_LEN);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1013 hc->request->contents_reader(hc,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1014 hc->contents_reader_buffer->str,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1015 hc->request_contents_written,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1016 PURPLE_HTTP_MAX_READ_BUFFER_LEN,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1017 hc->request->contents_reader_data,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1018 _purple_http_send_got_data);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1019 return;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1020 }
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1021 write_from = hc->contents_reader_buffer->str;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1022 write_len = hc->contents_reader_buffer->len;
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1023 } else {
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1024 write_from = hc->request->contents +
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1025 hc->request_contents_written;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1026 write_len = hc->request->contents_length -
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1027 hc->request_contents_written;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1028 }
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1029
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1030 if (write_len == 0) {
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1031 purple_debug_warning("http", "Nothing to write\n");
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1032 written = 0;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1033 } else if (hs->is_ssl)
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1034 written = purple_ssl_write(hs->ssl_connection,
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1035 write_from, write_len);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1036 else
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1037 written = write(hs->fd, write_from, write_len);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1038
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1039 if (written < 0 && errno == EAGAIN)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1040 return;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1041
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1042 if (written < 0) {
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1043 _purple_http_error(hc, _("Error writing to %s: %s"),
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1044 hc->url->host, g_strerror(errno));
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1045 return;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1046 }
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1047
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1048 if (writing_headers) {
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1049 hc->request_header_written += written;
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1050 purple_http_conn_notify_progress_watcher(hc);
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1051 if (hc->request_header_written < hc->request_header->len)
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1052 return;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1053 if (hc->request->contents_length > 0)
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1054 return;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1055 } else {
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1056 hc->request_contents_written += written;
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1057 purple_http_conn_notify_progress_watcher(hc);
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1058 if (hc->contents_reader_buffer)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1059 g_string_erase(hc->contents_reader_buffer, 0, written);
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1060 if (hc->request_contents_written < hc->request->contents_length)
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1061 return;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1062 }
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1063
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1064 /* request is completely written, let's read the response */
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1065 hc->is_reading = TRUE;
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1066 purple_input_remove(hs->inpa);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1067 hs->inpa = 0;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1068 if (hs->is_ssl)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1069 purple_ssl_input_add(hs->ssl_connection,
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1070 _purple_http_recv_ssl, hc);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1071 else
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1072 hs->inpa = purple_input_add(hs->fd, PURPLE_INPUT_READ,
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1073 _purple_http_recv, hc);
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1074 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1075
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1076 static void _purple_http_connected_raw(gpointer _hc, gint fd,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1077 const gchar *error_message)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1078 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1079 PurpleHttpConnection *hc = _hc;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1080 PurpleHttpSocket *hs = &hc->socket;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1081
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1082 hs->raw_connection = NULL;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1083
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1084 if (fd == -1) {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1085 _purple_http_error(hc, _("Unable to connect to %s: %s"),
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1086 hc->url->host, error_message);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1087 return;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1088 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1089
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1090 hs->fd = fd;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1091 hs->inpa = purple_input_add(fd, PURPLE_INPUT_WRITE,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1092 _purple_http_send, hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1093 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1094
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1095 static void _purple_http_connected_ssl(gpointer _hc,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1096 PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1097 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1098 PurpleHttpConnection *hc = _hc;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1099 PurpleHttpSocket *hs = &hc->socket;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1100
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1101 hs->fd = hs->ssl_connection->fd;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1102 hs->inpa = purple_input_add(hs->fd, PURPLE_INPUT_WRITE,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1103 _purple_http_send, hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1104 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1105
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1106 static void _purple_http_connected_ssl_error(
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1107 PurpleSslConnection *ssl_connection, PurpleSslErrorType error,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1108 gpointer _hc)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1109 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1110 PurpleHttpConnection *hc = _hc;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1111 PurpleHttpSocket *hs = &hc->socket;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1112
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1113 hs->ssl_connection = NULL;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1114 _purple_http_error(hc, _("Unable to connect to %s: %s"),
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1115 hc->url->host, purple_ssl_strerror(error));
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1116 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1117
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1118 static void _purple_http_disconnect(PurpleHttpConnection *hc)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1119 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1120 PurpleHttpSocket *hs;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1121
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1122 g_return_if_fail(hc != NULL);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1123
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1124 hs = &hc->socket;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1125
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1126 if (hc->request_header)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1127 g_string_free(hc->request_header, TRUE);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1128 hc->request_header = NULL;
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1129 if (hc->response_buffer)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1130 g_string_free(hc->response_buffer, TRUE);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1131 hc->response_buffer = NULL;
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1132
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1133 if (hs->inpa != 0)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1134 purple_input_remove(hs->inpa);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1135
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1136 if (hs->is_ssl) {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1137 if (hs->ssl_connection != NULL)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1138 purple_ssl_close(hs->ssl_connection);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1139 } else {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1140 if (hs->raw_connection != NULL)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1141 purple_proxy_connect_cancel(hs->raw_connection);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1142 if (hs->fd > 0)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1143 close(hs->fd);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1144 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1145
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1146 memset(hs, 0, sizeof(PurpleHttpSocket));
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1147 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1148
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1149 static gboolean _purple_http_reconnect(PurpleHttpConnection *hc)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1150 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1151 PurpleHttpURL *url;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1152 gboolean is_ssl = FALSE;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1153 PurpleAccount *account = NULL;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1154
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1155 g_return_val_if_fail(hc != NULL, FALSE);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1156 g_return_val_if_fail(hc->url != NULL, FALSE);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1157
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1158 _purple_http_disconnect(hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1159
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1160 if (purple_debug_is_verbose()) {
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1161 if (purple_debug_is_unsafe()) {
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1162 gchar *url = purple_http_url_print(hc->url);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1163 purple_debug_misc("http", "Connecting to %s...\n", url);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1164 g_free(url);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1165 } else
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1166 purple_debug_misc("http", "Connecting to %s...\n",
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1167 hc->url->host);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1168 }
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
1169
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1170 if (hc->gc)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1171 account = purple_connection_get_account(hc->gc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1172
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1173 url = hc->url;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1174 if (url->protocol[0] == '\0' ||
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1175 g_ascii_strcasecmp(url->protocol, "http") == 0) {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1176 /* do nothing */
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1177 } else if (g_ascii_strcasecmp(url->protocol, "https") == 0) {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1178 is_ssl = TRUE;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1179 } else {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1180 _purple_http_error(hc, _("Unsupported protocol: %s"),
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1181 url->protocol);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1182 return FALSE;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1183 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1184
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1185 hc->socket.is_ssl = is_ssl;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1186 if (is_ssl) {
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1187 if (!purple_ssl_is_supported()) {
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1188 _purple_http_error(hc, _("Unable to connect to %s: %s"),
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1189 url->host, _("Server requires TLS/SSL, "
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1190 "but no TLS/SSL support was found."));
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1191 return FALSE;
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1192 }
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1193 hc->socket.ssl_connection = purple_ssl_connect(account,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1194 url->host, url->port,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1195 _purple_http_connected_ssl,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1196 _purple_http_connected_ssl_error, hc);
33452
51b479bcf51a Get rid of C++-style comments
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33451
diff changeset
1197 /* TODO
51b479bcf51a Get rid of C++-style comments
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33451
diff changeset
1198 purple_ssl_set_compatibility_level(hc->socket.ssl_connection,
51b479bcf51a Get rid of C++-style comments
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33451
diff changeset
1199 PURPLE_SSL_COMPATIBILITY_SECURE);
51b479bcf51a Get rid of C++-style comments
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33451
diff changeset
1200 */
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1201 } else {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1202 hc->socket.raw_connection = purple_proxy_connect(hc->gc, account,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1203 url->host, url->port,
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1204 _purple_http_connected_raw, hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1205 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1206
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1207 if (hc->socket.ssl_connection == NULL &&
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1208 hc->socket.raw_connection == NULL) {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1209 _purple_http_error(hc, _("Unable to connect to %s"), url->host);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1210 return FALSE;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1211 }
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1212
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1213 purple_http_headers_free(hc->response->headers);
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1214 hc->response->headers = purple_http_headers_new();
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1215 hc->response_buffer = g_string_new("");
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1216 hc->main_header_got = FALSE;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1217 hc->headers_got = FALSE;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
1218 if (hc->response->contents != NULL)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
1219 g_string_free(hc->response->contents, TRUE);
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
1220 hc->response->contents = NULL;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
1221 hc->length_got = 0;
33446
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1222 hc->data_length_got = 0;
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
1223 hc->length_expected = -1;
33434
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
1224 hc->is_chunked = FALSE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
1225 hc->in_chunk = FALSE;
ec4f343af107 Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33433
diff changeset
1226 hc->chunks_done = FALSE;
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1227
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1228 purple_http_conn_notify_progress_watcher(hc);
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1229
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1230 return TRUE;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1231 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1232
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1233 /*** Performing HTTP requests *************************************************/
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1234
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1235 static gboolean purple_http_request_timeout(gpointer _hc)
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1236 {
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1237 PurpleHttpConnection *hc = _hc;
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1238
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1239 purple_debug_warning("http", "Timeout reached for request %p\n", hc);
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1240
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1241 purple_http_conn_cancel(hc);
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1242
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1243 return FALSE;
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1244 }
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1245
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1246 PurpleHttpConnection * purple_http_get(PurpleConnection *gc, const gchar *url,
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1247 PurpleHttpCallback callback, gpointer user_data)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1248 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1249 PurpleHttpRequest *request;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1250 PurpleHttpConnection *hc;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1251
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1252 g_return_val_if_fail(url != NULL, NULL);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1253
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1254 request = purple_http_request_new(url);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1255 hc = purple_http_request(gc, request, callback, user_data);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1256 purple_http_request_unref(request);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1257
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1258 return hc;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1259 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1260
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1261 PurpleHttpConnection * purple_http_request(PurpleConnection *gc,
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1262 PurpleHttpRequest *request, PurpleHttpCallback callback,
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1263 gpointer user_data)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1264 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1265 PurpleHttpConnection *hc;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1266
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1267 g_return_val_if_fail(request != NULL, NULL);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1268
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1269 hc = purple_http_connection_new(request, gc);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1270 hc->callback = callback;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1271 hc->user_data = user_data;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1272
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1273 if (purple_debug_is_unsafe())
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1274 purple_debug_misc("http", "Performing new request %p for %s.\n",
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1275 hc, request->url);
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1276 else
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1277 purple_debug_misc("http", "Performing new request %p.\n", hc);
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1278
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1279 hc->url = purple_http_url_parse(request->url);
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1280 if (!hc->url || hc->url->host[0] == '\0') {
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1281 purple_debug_error("http", "Invalid URL requested.\n");
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1282 purple_http_connection_terminate(hc);
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1283 return NULL;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1284 }
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1285
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1286 _purple_http_reconnect(hc);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1287
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1288 hc->timeout_handle = purple_timeout_add_seconds(request->timeout,
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1289 purple_http_request_timeout, hc);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1290
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1291 return hc;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1292 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1293
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1294 /*** HTTP connection API ******************************************************/
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1295
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1296 static void purple_http_connection_free(PurpleHttpConnection *hc);
33521
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1297 static gboolean purple_http_conn_notify_progress_watcher_timeout(gpointer _hc);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1298
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1299 static PurpleHttpConnection * purple_http_connection_new(
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1300 PurpleHttpRequest *request, PurpleConnection *gc)
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1301 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1302 PurpleHttpConnection *hc = g_new0(PurpleHttpConnection, 1);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1303
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1304 hc->request = request;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1305 purple_http_request_ref(request);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1306 hc->response = purple_http_response_new();
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1307
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1308 hc->link_global = purple_http_hc_list =
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1309 g_list_prepend(purple_http_hc_list, hc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1310 g_hash_table_insert(purple_http_hc_by_ptr, hc, hc->link_global);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1311 if (gc) {
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1312 GList *gc_list = g_hash_table_lookup(purple_http_hc_by_gc, gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1313 g_hash_table_steal(purple_http_hc_by_gc, gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1314 hc->link_gc = gc_list = g_list_prepend(gc_list, hc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1315 g_hash_table_insert(purple_http_hc_by_gc, gc, gc_list);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1316 hc->gc = gc;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1317 }
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1318
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1319 return hc;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1320 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1321
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1322 static void purple_http_connection_free(PurpleHttpConnection *hc)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1323 {
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1324 if (hc->timeout_handle)
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1325 purple_timeout_remove(hc->timeout_handle);
33521
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1326 if (hc->watcher_delayed_handle)
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1327 purple_timeout_remove(hc->watcher_delayed_handle);
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1328
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1329 purple_http_url_free(hc->url);
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
1330 purple_http_request_unref(hc->request);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1331 purple_http_response_free(hc->response);
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1332
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1333 if (hc->contents_reader_buffer)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1334 g_string_free(hc->contents_reader_buffer, TRUE);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1335
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1336 if (hc->request_header)
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1337 g_string_free(hc->request_header, TRUE);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
1338
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1339 purple_http_hc_list = g_list_delete_link(purple_http_hc_list,
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1340 hc->link_global);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1341 g_hash_table_remove(purple_http_hc_by_ptr, hc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1342 if (hc->gc) {
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1343 GList *gc_list, *gc_list_new;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1344 gc_list = g_hash_table_lookup(purple_http_hc_by_gc, hc->gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1345 g_assert(gc_list != NULL);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1346
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1347 gc_list_new = g_list_delete_link(gc_list, hc->link_gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1348 if (gc_list != gc_list_new) {
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1349 g_hash_table_steal(purple_http_hc_by_gc, hc->gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1350 if (gc_list_new)
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1351 g_hash_table_insert(purple_http_hc_by_gc,
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1352 hc->gc, gc_list_new);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1353 }
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1354 }
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1355
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1356 g_free(hc);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1357 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1358
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1359 /* call callback and do the cleanup */
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1360 static void purple_http_connection_terminate(PurpleHttpConnection *hc)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1361 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1362 g_return_if_fail(hc != NULL);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1363
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1364 purple_debug_misc("http", "Request %p performed %s.\n", hc,
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1365 purple_http_response_is_successfull(hc->response) ?
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1366 "successfully" : "without success");
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1367
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1368 if (hc->callback)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1369 hc->callback(hc, hc->response, hc->user_data);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1370
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1371 purple_http_connection_free(hc);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1372 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1373
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1374 void purple_http_conn_cancel(PurpleHttpConnection *http_conn)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1375 {
33464
9605c0a2839e Don't crash when cancelling non-existent HTTP connection
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33462
diff changeset
1376 if (http_conn == NULL)
9605c0a2839e Don't crash when cancelling non-existent HTTP connection
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33462
diff changeset
1377 return;
9605c0a2839e Don't crash when cancelling non-existent HTTP connection
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33462
diff changeset
1378
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1379 http_conn->response->code = 0;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1380 _purple_http_disconnect(http_conn);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1381 purple_http_connection_terminate(http_conn);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1382 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1383
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1384 void purple_http_conn_cancel_all(PurpleConnection *gc)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1385 {
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1386 GList *gc_list = g_hash_table_lookup(purple_http_hc_by_gc, gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1387
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1388 while (gc_list) {
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1389 PurpleHttpConnection *hc = gc_list->data;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1390 gc_list = g_list_next(gc_list);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1391 purple_http_conn_cancel(hc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1392 }
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1393
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1394 if (NULL != g_hash_table_lookup(purple_http_hc_by_gc, gc))
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1395 purple_debug_error("http", "Couldn't cancel all connections "
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1396 "related to gc=%p\n", gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1397 }
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1398
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1399 gboolean purple_http_conn_is_running(PurpleHttpConnection *http_conn)
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1400 {
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1401 if (http_conn == NULL)
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1402 return FALSE;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
1403 return (NULL != g_hash_table_lookup(purple_http_hc_by_ptr, http_conn));
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1404 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1405
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1406 PurpleHttpRequest * purple_http_conn_get_request(PurpleHttpConnection *http_conn)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1407 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1408 g_return_val_if_fail(http_conn != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1409
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1410 return http_conn->request;
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1411 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1412
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1413 PurpleHttpCookieJar * purple_http_conn_get_cookie_jar(
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1414 PurpleHttpConnection *http_conn)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1415 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1416 return purple_http_request_get_cookie_jar(purple_http_conn_get_request(
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1417 http_conn));
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1418 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1419
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1420 PurpleConnection * purple_http_conn_get_purple_connection(
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1421 PurpleHttpConnection *http_conn)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1422 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1423 g_return_val_if_fail(http_conn != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1424
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1425 return http_conn->gc;
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1426 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1427
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1428 void purple_http_conn_set_progress_watcher(PurpleHttpConnection *http_conn,
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1429 PurpleHttpProgressWatcher watcher, gpointer user_data,
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1430 guint interval_threshold)
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1431 {
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1432 g_return_if_fail(http_conn != NULL);
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1433
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1434 http_conn->watcher = watcher;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1435 http_conn->watcher_user_data = user_data;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1436 http_conn->watcher_interval_threshold = interval_threshold;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1437 }
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1438
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1439 static void purple_http_conn_notify_progress_watcher(
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1440 PurpleHttpConnection *hc)
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1441 {
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1442 gint64 now;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1443 gboolean reading_state;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1444 int processed, total;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1445
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1446 g_return_if_fail(hc != NULL);
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1447
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1448 if (hc->watcher == NULL)
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1449 return;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1450
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1451 reading_state = hc->is_reading;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1452 if (reading_state) {
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1453 total = hc->length_expected;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1454 processed = hc->length_got;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1455 } else {
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1456 total = hc->request->contents_length;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1457 processed = hc->request_contents_written;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1458 if (total == 0)
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1459 total = -1;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1460 }
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1461 if (total != -1 && total < processed) {
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1462 purple_debug_warning("http", "Processed too much\n");
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1463 total = processed;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1464 }
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1465
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1466 now = g_get_monotonic_time();
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1467 if (hc->watcher_last_call + hc->watcher_interval_threshold
33521
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1468 > now && processed != total) {
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1469 if (hc->watcher_delayed_handle)
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1470 return;
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1471 hc->watcher_delayed_handle = purple_timeout_add_seconds(
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1472 1 + hc->watcher_interval_threshold / 1000000,
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1473 purple_http_conn_notify_progress_watcher_timeout, hc);
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1474 return;
33521
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1475 }
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1476
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1477 if (hc->watcher_delayed_handle)
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1478 purple_timeout_remove(hc->watcher_delayed_handle);
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1479 hc->watcher_delayed_handle = 0;
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1480
33468
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1481 hc->watcher_last_call = now;
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1482 hc->watcher(hc, reading_state, processed, total, hc->watcher_user_data);
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1483 }
b057fee9d11a HTTP progress watcher support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33466
diff changeset
1484
33521
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1485 static gboolean purple_http_conn_notify_progress_watcher_timeout(gpointer _hc)
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1486 {
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1487 PurpleHttpConnection *hc = _hc;
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1488
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1489 purple_http_conn_notify_progress_watcher(hc);
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1490
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1491 return FALSE;
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1492 }
43c34cda245d HTTP: don't forget to notify about progress before connection freeze
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33517
diff changeset
1493
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1494 /*** Cookie jar API ***********************************************************/
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1495
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1496 static PurpleHttpCookie * purple_http_cookie_new(const gchar *value);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1497 void purple_http_cookie_free(PurpleHttpCookie *cookie);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1498
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1499 static void purple_http_cookie_jar_set_ext(PurpleHttpCookieJar *cookie_jar,
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1500 const gchar *name, const gchar *value, time_t expires);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1501
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1502 static PurpleHttpCookie * purple_http_cookie_new(const gchar *value)
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1503 {
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1504 PurpleHttpCookie *cookie = g_new0(PurpleHttpCookie, 1);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1505
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1506 cookie->value = g_strdup(value);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1507 cookie->expires = -1;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1508
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1509 return cookie;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1510 }
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1511
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1512 void purple_http_cookie_free(PurpleHttpCookie *cookie)
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1513 {
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1514 g_free(cookie->value);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1515 g_free(cookie);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1516 }
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1517
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1518 void purple_http_cookie_jar_free(PurpleHttpCookieJar *cookie_jar);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1519
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1520 PurpleHttpCookieJar * purple_http_cookie_jar_new(void)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1521 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1522 PurpleHttpCookieJar *cjar = g_new0(PurpleHttpCookieJar, 1);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1523
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1524 cjar->ref_count = 1;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1525 cjar->tab = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1526 (GDestroyNotify)purple_http_cookie_free);
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1527
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1528 return cjar;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1529 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1530
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1531 void purple_http_cookie_jar_free(PurpleHttpCookieJar *cookie_jar)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1532 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1533 g_hash_table_destroy(cookie_jar->tab);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1534 g_free(cookie_jar);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1535 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1536
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1537 void purple_http_cookie_jar_ref(PurpleHttpCookieJar *cookie_jar)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1538 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1539 g_return_if_fail(cookie_jar != NULL);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1540
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1541 cookie_jar->ref_count++;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1542 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1543
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1544 PurpleHttpCookieJar * purple_http_cookie_jar_unref(
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1545 PurpleHttpCookieJar *cookie_jar)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1546 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1547 if (cookie_jar == NULL)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1548 return NULL;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1549
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1550 g_return_val_if_fail(cookie_jar->ref_count > 0, NULL);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1551
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1552 cookie_jar->ref_count--;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1553 if (cookie_jar->ref_count > 0)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1554 return cookie_jar;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1555
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1556 purple_http_cookie_jar_free(cookie_jar);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1557 return NULL;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1558 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1559
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1560 static void purple_http_cookie_jar_parse(PurpleHttpCookieJar *cookie_jar,
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1561 GList *values)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1562 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1563 values = g_list_first(values);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1564 while (values) {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1565 const gchar *cookie = values->data;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1566 const gchar *eqsign, *semicolon;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1567 gchar *name, *value;
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1568 time_t expires = -1;
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1569 values = g_list_next(values);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1570
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1571 eqsign = strchr(cookie, '=');
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1572 semicolon = strchr(cookie, ';');
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1573
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1574 if (eqsign == NULL || eqsign == cookie ||
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1575 (semicolon != NULL && semicolon < eqsign)) {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1576 if (purple_debug_is_unsafe())
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1577 purple_debug_warning("http",
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1578 "Invalid cookie: [%s]\n", cookie);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1579 else
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1580 purple_debug_warning("http", "Invalid cookie.");
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1581 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1582
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1583 name = g_strndup(cookie, eqsign - cookie);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1584 eqsign++;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1585 if (semicolon != NULL)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1586 value = g_strndup(eqsign, semicolon - eqsign);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1587 else
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1588 value = g_strdup(eqsign);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1589
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1590 if (semicolon != NULL) {
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1591 GMatchInfo *match_info;
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1592 GRegex *re_expires = g_regex_new(
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1593 "expires=([a-z0-9, :]+)",
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1594 G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1595 G_REGEX_MATCH_NOTEMPTY, NULL);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1596
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1597 g_regex_match(re_expires, semicolon, 0, &match_info);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1598 if (g_match_info_matches(match_info)) {
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1599 gchar *expire_date =
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1600 g_match_info_fetch(match_info, 1);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1601 expires = purple_http_rfc1123_to_time(
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1602 expire_date);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1603 g_free(expire_date);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1604 }
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1605 g_match_info_free(match_info);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1606
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1607 g_regex_unref(re_expires);
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1608 }
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1609
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1610 purple_http_cookie_jar_set_ext(cookie_jar, name, value, expires);
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1611
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1612 g_free(name);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1613 g_free(value);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1614 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1615 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1616
33458
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1617 static gchar * purple_http_cookie_jar_gen(PurpleHttpCookieJar *cookie_jar)
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1618 {
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1619 GHashTableIter it;
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1620 gchar *key;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1621 PurpleHttpCookie *cookie;
33458
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1622 GString *str;
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1623 time_t now = time(NULL);
33458
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1624
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1625 g_return_val_if_fail(cookie_jar != NULL, NULL);
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1626
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1627 str = g_string_new("");
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1628
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1629 g_hash_table_iter_init(&it, cookie_jar->tab);
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1630 while (g_hash_table_iter_next(&it, (gpointer*)&key,
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1631 (gpointer*)&cookie)) {
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1632 if (cookie->expires != -1 && cookie->expires <= now)
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1633 continue;
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1634 g_string_append_printf(str, "%s=%s; ", key, cookie->value);
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1635 }
33458
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1636
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1637 if (str->len > 0)
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1638 g_string_truncate(str, str->len - 2);
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1639 return g_string_free(str, FALSE);
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1640 }
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1641
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1642 void purple_http_cookie_jar_set(PurpleHttpCookieJar *cookie_jar,
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1643 const gchar *name, const gchar *value)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1644 {
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1645 purple_http_cookie_jar_set_ext(cookie_jar, name, value, -1);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1646 }
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1647
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1648 static void purple_http_cookie_jar_set_ext(PurpleHttpCookieJar *cookie_jar,
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1649 const gchar *name, const gchar *value, time_t expires)
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1650 {
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1651 g_return_if_fail(cookie_jar != NULL);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1652 g_return_if_fail(name != NULL);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1653
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
1654 if (expires != -1 && time(NULL) >= expires)
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1655 value = NULL;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1656
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1657 if (value != NULL) {
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1658 PurpleHttpCookie *cookie = purple_http_cookie_new(value);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1659 cookie->expires = expires;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1660 g_hash_table_insert(cookie_jar->tab, g_strdup(name), cookie);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1661 } else
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1662 g_hash_table_remove(cookie_jar->tab, name);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1663 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1664
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1665 const gchar * purple_http_cookie_jar_get(PurpleHttpCookieJar *cookie_jar,
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1666 const gchar *name)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1667 {
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1668 PurpleHttpCookie *cookie;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1669
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1670 g_return_val_if_fail(cookie_jar != NULL, NULL);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1671 g_return_val_if_fail(name != NULL, NULL);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1672
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1673 cookie = g_hash_table_lookup(cookie_jar->tab, name);
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1674 if (!cookie)
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1675 return NULL;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1676
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1677 return cookie->value;
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1678 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1679
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1680 gchar * purple_http_cookie_jar_dump(PurpleHttpCookieJar *cjar)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1681 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1682 GHashTableIter it;
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1683 gchar *key;
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1684 PurpleHttpCookie *cookie;
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1685 GString *str = g_string_new("");
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1686
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1687 g_hash_table_iter_init(&it, cjar->tab);
33459
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1688 while (g_hash_table_iter_next(&it, (gpointer*)&key, (gpointer*)&cookie))
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1689 g_string_append_printf(str, "%s: %s (expires: %lld)\n", key,
722a6d753cb2 Better cookies, better chunked transfer support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33458
diff changeset
1690 cookie->value, (long long int)cookie->expires);
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1691
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1692 if (str->len > 0)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1693 g_string_truncate(str, str->len - 1);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1694 return g_string_free(str, FALSE);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1695 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1696
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1697 gboolean purple_http_cookie_jar_is_empty(PurpleHttpCookieJar *cookie_jar)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1698 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1699 g_return_val_if_fail(cookie_jar != NULL, TRUE);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1700
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1701 return g_hash_table_size(cookie_jar->tab) == 0;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1702 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1703
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1704 /*** Request API **************************************************************/
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1705
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1706 static void purple_http_request_free(PurpleHttpRequest *request);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1707
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1708 PurpleHttpRequest * purple_http_request_new(const gchar *url)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1709 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1710 PurpleHttpRequest *request;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1711
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1712 g_return_val_if_fail(url != NULL, NULL);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1713
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1714 request = g_new0(PurpleHttpRequest, 1);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1715
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1716 request->ref_count = 1;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1717 request->url = g_strdup(url);
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1718 request->headers = purple_http_headers_new();
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1719 request->cookie_jar = purple_http_cookie_jar_new();
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1720
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1721 request->timeout = PURPLE_HTTP_REQUEST_DEFAULT_TIMEOUT;
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1722 request->max_redirects = PURPLE_HTTP_REQUEST_DEFAULT_MAX_REDIRECTS;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1723 request->http11 = TRUE;
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1724 request->max_length = -1;
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1725
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1726 return request;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1727 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1728
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1729 static void purple_http_request_free(PurpleHttpRequest *request)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1730 {
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1731 purple_http_headers_free(request->headers);
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1732 purple_http_cookie_jar_unref(request->cookie_jar);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1733 g_free(request->url);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1734 g_free(request);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1735 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1736
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1737 void purple_http_request_ref(PurpleHttpRequest *request)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1738 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1739 g_return_if_fail(request != NULL);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1740
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1741 request->ref_count++;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1742 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1743
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1744 PurpleHttpRequest * purple_http_request_unref(PurpleHttpRequest *request)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1745 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1746 if (request == NULL)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1747 return NULL;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1748
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1749 g_return_val_if_fail(request->ref_count > 0, NULL);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1750
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1751 request->ref_count--;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1752 if (request->ref_count > 0)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1753 return request;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1754
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1755 purple_http_request_free(request);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1756 return NULL;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1757 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1758
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1759 void purple_http_request_set_url(PurpleHttpRequest *request, const gchar *url)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1760 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1761 g_return_if_fail(request != NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1762 g_return_if_fail(url != NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1763
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1764 g_free(request->url);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1765 request->url = g_strdup(url);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1766 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1767
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1768 const gchar * purple_http_request_get_url(PurpleHttpRequest *request)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1769 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1770 g_return_val_if_fail(request != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1771
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1772 return request->url;
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1773 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1774
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1775 void purple_http_request_set_method(PurpleHttpRequest *request, const gchar *method)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1776 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1777 g_return_if_fail(request != NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1778
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1779 g_free(request->method);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1780 request->method = g_strdup(method);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1781 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1782
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1783 const gchar * purple_http_request_get_method(PurpleHttpRequest *request)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1784 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1785 g_return_val_if_fail(request != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1786
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1787 return request->method;
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1788 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
1789
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1790 void purple_http_request_set_contents(PurpleHttpRequest *request,
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1791 const gchar *contents, int length)
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1792 {
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1793 g_return_if_fail(request != NULL);
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1794 g_return_if_fail(length >= -1);
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1795
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1796 request->contents_reader = NULL;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1797 request->contents_reader_data = NULL;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1798
33457
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1799 g_free(request->contents);
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1800 if (contents == NULL || length == 0) {
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1801 request->contents = NULL;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1802 request->contents_length = 0;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1803 return;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1804 }
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1805
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1806 if (length == -1)
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1807 length = strlen(contents);
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1808 request->contents = g_memdup(contents, length);
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1809 request->contents_length = length;
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1810 }
81f92a310aff Writing request contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33456
diff changeset
1811
33466
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1812 void purple_http_request_set_contents_reader(PurpleHttpRequest *request,
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1813 PurpleHttpContentReader reader, int contents_length, gpointer user_data)
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1814 {
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1815 g_return_if_fail(request != NULL);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1816 g_return_if_fail(reader != NULL);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1817 g_return_if_fail(contents_length >= -1);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1818
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1819 g_free(request->contents);
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1820 request->contents = NULL;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1821 request->contents_length = contents_length;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1822 request->contents_reader = reader;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1823 request->contents_reader_data = user_data;
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1824 }
918507303f45 HTTP API: PurpleHttpContentReader support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33464
diff changeset
1825
33517
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1826 void purple_http_request_set_response_writer(PurpleHttpRequest *request,
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1827 PurpleHttpContentWriter writer, gpointer user_data)
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1828 {
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1829 g_return_if_fail(request != NULL);
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1830
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1831 if (writer == NULL)
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1832 user_data = NULL;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1833 request->response_writer = writer;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1834 request->response_writer_data = user_data;
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1835 }
ddd9e37c4b07 HTTP: PurpleHttpContentWriter support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33469
diff changeset
1836
33450
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1837 void purple_http_request_set_timeout(PurpleHttpRequest *request, int timeout)
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1838 {
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1839 g_return_if_fail(request != NULL);
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1840
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1841 if (timeout < -1)
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1842 timeout = -1;
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1843
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1844 request->timeout = timeout;
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1845 }
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1846
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1847 int purple_http_request_get_timeout(PurpleHttpRequest *request)
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1848 {
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1849 g_return_val_if_fail(request != NULL, -1);
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1850
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1851 return request->timeout;
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1852 }
4042907bcdf1 Timeout support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33448
diff changeset
1853
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1854 void purple_http_request_set_max_redirects(PurpleHttpRequest *request,
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1855 int max_redirects)
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1856 {
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1857 g_return_if_fail(request != NULL);
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1858
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1859 if (max_redirects < -1)
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1860 max_redirects = -1;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1861
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1862 request->max_redirects = max_redirects;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1863 }
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1864
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1865 int purple_http_request_get_max_redirects(PurpleHttpRequest *request)
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1866 {
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1867 g_return_val_if_fail(request != NULL, -1);
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1868
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1869 return request->max_redirects;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1870 }
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1871
33456
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1872 void purple_http_request_set_cookie_jar(PurpleHttpRequest *request,
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1873 PurpleHttpCookieJar *cookie_jar)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1874 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1875 g_return_if_fail(request != NULL);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1876 g_return_if_fail(cookie_jar != NULL);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1877
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1878 purple_http_cookie_jar_ref(cookie_jar);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1879 purple_http_cookie_jar_unref(request->cookie_jar);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1880 request->cookie_jar = cookie_jar;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1881 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1882
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1883 PurpleHttpCookieJar * purple_http_request_get_cookie_jar(
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1884 PurpleHttpRequest *request)
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1885 {
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1886 g_return_val_if_fail(request != NULL, NULL);
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1887
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1888 return request->cookie_jar;
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1889 }
35a2f951a850 Cookies support (reading)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33455
diff changeset
1890
33444
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1891 void purple_http_request_set_http11(PurpleHttpRequest *request, gboolean http11)
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1892 {
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1893 g_return_if_fail(request != NULL);
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1894
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1895 request->http11 = http11;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1896 }
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1897
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1898 gboolean purple_http_request_is_http11(PurpleHttpRequest *request)
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1899 {
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1900 g_return_val_if_fail(request != NULL, FALSE);
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1901
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1902 return request->http11;
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1903 }
b3afec292014 New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33443
diff changeset
1904
33446
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1905 void purple_http_request_set_max_len(PurpleHttpRequest *request, int max_len)
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1906 {
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1907 g_return_if_fail(request != NULL);
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1908
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1909 if (max_len < -1)
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1910 max_len = -1;
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1911
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1912 request->max_length = max_len;
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1913 }
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1914
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1915 int purple_http_request_get_max_len(PurpleHttpRequest *request)
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1916 {
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1917 g_return_val_if_fail(request != NULL, -1);
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1918
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1919 return request->max_length;
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1920 }
95fda782966c New feature: setting maximum length of response
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33445
diff changeset
1921
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1922 void purple_http_request_header_set(PurpleHttpRequest *request,
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1923 const gchar *key, const gchar *value)
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1924 {
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1925 g_return_if_fail(request != NULL);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1926 g_return_if_fail(key != NULL);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1927
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1928 purple_http_headers_remove(request->headers, key);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1929 if (value)
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1930 purple_http_headers_add(request->headers, key, value);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1931 }
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1932
33455
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1933 void purple_http_request_header_set_printf(PurpleHttpRequest *request,
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1934 const gchar *key, const gchar *format, ...)
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1935 {
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1936 va_list args;
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1937 gchar *value;
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1938
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1939 g_return_if_fail(request != NULL);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1940 g_return_if_fail(key != NULL);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1941 g_return_if_fail(format != NULL);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1942
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1943 va_start(args, format);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1944 value = g_strdup_vprintf(format, args);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1945 va_end(args);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1946
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1947 purple_http_request_header_set(request, key, value);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1948 g_free(value);
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1949 }
2de654702970 Print-like setting headers, vestigal keepalive support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33454
diff changeset
1950
33447
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1951 void purple_http_request_header_add(PurpleHttpRequest *request,
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1952 const gchar *key, const gchar *value)
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1953 {
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1954 g_return_if_fail(request != NULL);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1955 g_return_if_fail(key != NULL);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1956
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1957 purple_http_headers_add(request->headers, key, value);
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1958 }
b890f231e15f Request headers support, wrapping new API with legacy purple_util_fetch_url
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33446
diff changeset
1959
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1960 /*** HTTP response API ********************************************************/
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1961
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1962 static PurpleHttpResponse * purple_http_response_new(void)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1963 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1964 PurpleHttpResponse *response = g_new0(PurpleHttpResponse, 1);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1965
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1966 return response;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1967 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1968
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1969 static void purple_http_response_free(PurpleHttpResponse *response)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1970 {
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
1971 if (response->contents != NULL)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
1972 g_string_free(response->contents, TRUE);
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
1973 g_free(response->error);
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1974 purple_http_headers_free(response->headers);
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1975 g_free(response);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1976 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1977
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1978 gboolean purple_http_response_is_successfull(PurpleHttpResponse *response)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1979 {
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1980 int code;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1981
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1982 g_return_val_if_fail(response != NULL, FALSE);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1983
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1984 code = response->code;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1985
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1986 if (code <= 0)
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1987 return FALSE;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1988
33458
59b3364f690e Sending cookies
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33457
diff changeset
1989 if (code / 100 == 2)
33432
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1990 return TRUE;
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1991
9c4acb75b2e6 Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33431
diff changeset
1992 return FALSE;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1993 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1994
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1995 int purple_http_response_get_code(PurpleHttpResponse *response)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1996 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1997 g_return_val_if_fail(response != NULL, 0);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1998
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
1999 return response->code;
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2000 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2001
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2002 const gchar * purple_http_response_get_error(PurpleHttpResponse *response)
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2003 {
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2004 g_return_val_if_fail(response != NULL, NULL);
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2005
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2006 return response->error;
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2007 }
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2008
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2009 gsize purple_http_response_get_data_len(PurpleHttpResponse *response)
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2010 {
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2011 g_return_val_if_fail(response != NULL, 0);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2012
33433
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
2013 if (response->contents == NULL)
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
2014 return 0;
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
2015
fb7ac52ed7df Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33432
diff changeset
2016 return response->contents->len;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2017 }
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2018
33626
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2019 const gchar * purple_http_response_get_data(PurpleHttpResponse *response, size_t *len)
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2020 {
33626
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2021 const gchar *ret = "";
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2022
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2023 g_return_val_if_fail(response != NULL, NULL);
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2024
33626
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2025 if (response->contents != NULL) {
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2026 ret = response->contents->str;
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2027 if(len)
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2028 *len = response->contents->len;
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2029 } else {
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2030 if(len)
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2031 *len = 0;
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2032 }
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2033
2522d124d883 update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents: 33522
diff changeset
2034 return ret;
33427
dd0c0860e293 Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33425
diff changeset
2035 }
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2036
33451
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2037 const GList * purple_http_response_get_all_headers(PurpleHttpResponse *response)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2038 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2039 g_return_val_if_fail(response != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2040
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2041 return purple_http_headers_get_all(response->headers);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2042 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2043
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2044 const GList * purple_http_response_get_headers_by_name(
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2045 PurpleHttpResponse *response, const gchar *name)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2046 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2047 g_return_val_if_fail(response != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2048 g_return_val_if_fail(name != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2049
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2050 return purple_http_headers_get_all_by_name(response->headers, name);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2051 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2052
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2053 const gchar * purple_http_response_get_header(PurpleHttpResponse *response,
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2054 const gchar *name)
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2055 {
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2056 g_return_val_if_fail(response != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2057 g_return_val_if_fail(name != NULL, NULL);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2058
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2059 return purple_http_headers_get(response->headers, name);
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2060 }
27d0e5dbc2a1 Implement missing getters/setters and corresponding features
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33450
diff changeset
2061
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2062 /*** URL functions ************************************************************/
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2063
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2064 static PurpleHttpURL * purple_http_url_parse(const char *raw_url)
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2065 {
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2066 PurpleHttpURL *url;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2067 GMatchInfo *match_info;
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2068
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2069 gchar *host_full, *tmp;
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2070
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2071 g_return_val_if_fail(raw_url != NULL, NULL);
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2072
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2073 url = g_new0(PurpleHttpURL, 1);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2074
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2075 if (!g_regex_match(purple_http_re_url, raw_url, 0, &match_info)) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2076 if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2077 purple_debug_warning("http",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2078 "Invalid URL provided: %s\n",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2079 raw_url);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2080 }
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2081 return NULL;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2082 }
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2083
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2084 url->protocol = g_match_info_fetch(match_info, 1);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2085 host_full = g_match_info_fetch(match_info, 2);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2086 url->path = g_match_info_fetch(match_info, 3);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2087 url->fragment = g_match_info_fetch(match_info, 4);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2088 g_match_info_free(match_info);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2089
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2090 if (url->protocol[0] == '\0') {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2091 g_free(url->protocol);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2092 url->protocol = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2093 } else if (url->protocol != NULL) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2094 tmp = url->protocol;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2095 url->protocol = g_ascii_strdown(url->protocol, -1);
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
2096 g_free(tmp);
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
2097 }
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2098 if (host_full[0] == '\0') {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2099 g_free(host_full);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2100 host_full = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2101 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2102 if (url->path[0] == '\0') {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2103 g_free(url->path);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2104 url->path = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2105 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2106 if ((url->protocol == NULL) != (host_full == NULL))
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2107 purple_debug_warning("http", "Protocol or host not present "
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2108 "(unlikely case)\n");
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2109
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2110 if (host_full) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2111 gchar *port_str;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2112
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2113 if (!g_regex_match(purple_http_re_url_host, host_full, 0,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2114 &match_info)) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2115 if (purple_debug_is_verbose() &&
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2116 purple_debug_is_unsafe()) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2117 purple_debug_warning("http",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2118 "Invalid host provided for URL: %s\n",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2119 raw_url);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2120 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2121
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2122 g_free(host_full);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2123 purple_http_url_free(url);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2124 return NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2125 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2126
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2127 url->user = g_match_info_fetch(match_info, 1);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2128 url->password = g_match_info_fetch(match_info, 2);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2129 url->host = g_match_info_fetch(match_info, 3);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2130 port_str = g_match_info_fetch(match_info, 4);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2131
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2132 if (port_str && port_str[0])
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2133 url->port = atoi(port_str);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2134
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2135 if (url->user[0] == '\0') {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2136 g_free(url->user);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2137 url->user = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2138 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2139 if (url->password[0] == '\0') {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2140 g_free(url->password);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2141 url->password = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2142 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2143 if (url->host[0] == '\0') {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2144 g_free(url->host);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2145 url->host = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2146 } else if (url->host != NULL) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2147 tmp = url->host;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2148 url->host = g_ascii_strdown(url->host, -1);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2149 g_free(tmp);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2150 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2151
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2152 g_free(port_str);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2153 g_match_info_free(match_info);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2154
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2155 g_free(host_full);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2156 host_full = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2157 }
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
2158
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2159 if (url->host != NULL) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2160 if (url->protocol == NULL)
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2161 url->protocol = g_strdup("http");
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2162 if (url->port == 0 && 0 == strcmp(url->protocol, "http"))
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2163 url->port = 80;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2164 if (url->port == 0 && 0 == strcmp(url->protocol, "https"))
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2165 url->port = 443;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2166 if (url->path == NULL)
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2167 url->path = g_strdup("/");
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2168 if (url->path[0] != '/')
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2169 purple_debug_warning("http",
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2170 "URL path doesn't start with slash\n");
33431
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
2171 }
704de181d1d2 Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33430
diff changeset
2172
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2173 return url;
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2174 }
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2175
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2176 static void purple_http_url_free(PurpleHttpURL *parsed_url)
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2177 {
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2178 if (parsed_url == NULL)
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2179 return;
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2180
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2181 g_free(parsed_url->protocol);
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2182 g_free(parsed_url->user);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2183 g_free(parsed_url->password);
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2184 g_free(parsed_url->host);
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2185 g_free(parsed_url->path);
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2186 g_free(parsed_url->fragment);
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2187 g_free(parsed_url);
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2188 }
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2189
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2190 static void purple_http_url_relative(PurpleHttpURL *base_url,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2191 PurpleHttpURL *relative_url)
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2192 {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2193 g_return_if_fail(base_url != NULL);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2194 g_return_if_fail(relative_url != NULL);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2195
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2196 if (relative_url->host) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2197 g_free(base_url->protocol);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2198 base_url->protocol = g_strdup(relative_url->protocol);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2199 g_free(base_url->user);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2200 base_url->user = g_strdup(relative_url->user);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2201 g_free(base_url->password);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2202 base_url->password = g_strdup(relative_url->password);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2203 g_free(base_url->host);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2204 base_url->host = g_strdup(relative_url->host);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2205 base_url->port = relative_url->port;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2206
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2207 g_free(base_url->path);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2208 base_url->path = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2209 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2210
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2211 if (relative_url->path) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2212 if (relative_url->path[0] == '/' ||
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2213 base_url->path == NULL) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2214 g_free(base_url->path);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2215 base_url->path = g_strdup(relative_url->path);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2216 } else {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2217 gchar *last_slash = strrchr(base_url->path, '/');
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2218 gchar *tmp;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2219 if (last_slash == NULL)
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2220 base_url->path[0] = '\0';
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2221 else
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2222 last_slash[1] = '\0';
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2223 tmp = base_url->path;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2224 base_url->path = g_strconcat(base_url->path,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2225 relative_url->path, NULL);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2226 g_free(tmp);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2227 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2228 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2229
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2230 g_free(base_url->fragment);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2231 base_url->fragment = g_strdup(relative_url->fragment);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2232 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2233
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2234 static gchar * purple_http_url_print(PurpleHttpURL *parsed_url)
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2235 {
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2236 GString *url = g_string_new("");
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2237 gboolean before_host_printed = FALSE, host_printed = FALSE;
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2238 gboolean port_is_default = FALSE;
33430
013c5aebb665 Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33429
diff changeset
2239
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2240 if (parsed_url->protocol) {
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2241 g_string_append_printf(url, "%s://", parsed_url->protocol);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2242 before_host_printed = TRUE;
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2243 if (parsed_url->port == 80 && 0 == strcmp(parsed_url->protocol,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2244 "http"))
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2245 port_is_default = TRUE;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2246 if (parsed_url->port == 443 && 0 == strcmp(parsed_url->protocol,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2247 "https"))
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2248 port_is_default = TRUE;
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2249 }
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2250 if (parsed_url->user || parsed_url->password) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2251 if (parsed_url->user)
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2252 g_string_append(url, parsed_url->user);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2253 g_string_append_printf(url, ":%s", parsed_url->password);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2254 g_string_append(url, "@");
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2255 before_host_printed = TRUE;
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2256 }
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2257 if (parsed_url->host || parsed_url->port) {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2258 if (!parsed_url->host)
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2259 g_string_append_printf(url, "{???}:%d",
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2260 parsed_url->port);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2261 else {
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2262 g_string_append(url, parsed_url->host);
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2263 if (!port_is_default)
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2264 g_string_append_printf(url, ":%d",
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2265 parsed_url->port);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2266 }
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2267 host_printed = TRUE;
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2268 }
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2269 if (parsed_url->path) {
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2270 if (!host_printed && before_host_printed)
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2271 g_string_append(url, "{???}");
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2272 g_string_append(url, parsed_url->path);
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2273 }
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2274 if (parsed_url->fragment)
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2275 g_string_append_printf(url, "#%s", parsed_url->fragment);
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2276
33438
66c4b90ff08a More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33437
diff changeset
2277 return g_string_free(url, FALSE);
33429
1ce1faf4e675 Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33427
diff changeset
2278 }
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2279
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2280 /*** HTTP Subsystem ***********************************************************/
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2281
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2282 void purple_http_init(void)
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2283 {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2284 purple_http_re_url = g_regex_new("^"
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2285
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2286 "(?:" /* host part beginning */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2287 "([a-z]+)\\:/*" /* protocol */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2288 "([^/]+)" /* username, password, host, port */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2289 ")?" /* host part ending */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2290
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2291 "([^#]*)" /* path */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2292
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2293 "(?:#" "(.*)" ")?" /* fragment */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2294
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2295 "$", G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2296 G_REGEX_MATCH_NOTEMPTY, NULL);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2297
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2298 purple_http_re_url_host = g_regex_new("^"
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2299
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2300 "(?:" /* user credentials part beginning */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2301 "([" PURPLE_HTTP_URL_CREDENTIALS_CHARS "]+)" /* username */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2302 "(?::([" PURPLE_HTTP_URL_CREDENTIALS_CHARS "]+))" /* password */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2303 "@)?" /* user credentials part ending */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2304
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2305 "([a-z0-9.-]+)" /* host */
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2306 "(?::([0-9]+))?" /* port*/
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2307
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2308 "$", G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2309 G_REGEX_MATCH_NOTEMPTY, NULL);
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2310
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2311 purple_http_re_rfc1123 = g_regex_new(
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2312 "^[a-z]+, " /* weekday */
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2313 "([0-9]+) " /* date */
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2314 "([a-z]+) " /* month */
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2315 "([0-9]+) " /* year */
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2316 "([0-9]+:[0-9]+:[0-9]+) " /* time */
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2317 "(?:GMT|UTC)$",
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2318 G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2319 G_REGEX_MATCH_NOTEMPTY, NULL);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2320
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2321 purple_http_hc_list = NULL;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2322 purple_http_hc_by_ptr = g_hash_table_new(g_direct_hash, g_direct_equal);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2323 purple_http_hc_by_gc = g_hash_table_new_full(g_direct_hash,
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2324 g_direct_equal, NULL, (GDestroyNotify)g_list_free);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2325 }
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2326
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2327 static void purple_http_foreach_conn_cancel(gpointer _hc, gpointer user_data)
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2328 {
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2329 PurpleHttpConnection *hc = _hc;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2330 purple_http_conn_cancel(hc);
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2331 }
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2332
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2333 void purple_http_uninit(void)
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2334 {
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2335 g_regex_unref(purple_http_re_url);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2336 purple_http_re_url = NULL;
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2337 g_regex_unref(purple_http_re_url_host);
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2338 purple_http_re_url_host = NULL;
33460
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2339 g_regex_unref(purple_http_re_rfc1123);
c37dd51516aa Deleting (or expiring) a cookie
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33459
diff changeset
2340 purple_http_re_rfc1123 = NULL;
33448
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2341
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2342 g_list_foreach(purple_http_hc_list, purple_http_foreach_conn_cancel,
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2343 NULL);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2344
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2345 if (purple_http_hc_list != NULL ||
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2346 0 != g_hash_table_size(purple_http_hc_by_ptr) ||
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2347 0 != g_hash_table_size(purple_http_hc_by_gc))
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2348 purple_debug_warning("http",
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2349 "Couldn't cleanup all connections.\n");
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2350
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2351 g_list_free(purple_http_hc_list);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2352 purple_http_hc_list = NULL;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2353 g_hash_table_destroy(purple_http_hc_by_gc);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2354 purple_http_hc_by_gc = NULL;
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2355 g_hash_table_destroy(purple_http_hc_by_ptr);
4d41b1f7b95f Cancelling all HTTP connections on account disconnect or app shutdown
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33447
diff changeset
2356 purple_http_hc_by_ptr = NULL;
33439
178eb69a3f11 Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33438
diff changeset
2357 }

mercurial