libpurple/http.c

Tue, 06 Nov 2012 01:10:40 +0100

author
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
date
Tue, 06 Nov 2012 01:10:40 +0100
changeset 33517
ddd9e37c4b07
parent 33469
6c2fa6d8037d
child 33521
43c34cda245d
permissions
-rw-r--r--

HTTP: PurpleHttpContentWriter support

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

mercurial