libpurple/http.c

Thu, 18 Oct 2012 23:21:30 +0200

author
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
date
Thu, 18 Oct 2012 23:21:30 +0200
changeset 33459
722a6d753cb2
parent 33458
59b3364f690e
child 33460
c37dd51516aa
permissions
-rw-r--r--

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

mercurial