Tue, 16 Oct 2012 13:28:10 +0200
Allow infinite amount of redirects
|
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" |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
30 | #include "debug.h" |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
31 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
32 | #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
|
33 | #define PURPLE_HTTP_MAX_RECV_BUFFER_LEN 10240 |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
34 | |
|
33444
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
35 | #define PURPLE_HTTP_REQUEST_DEFAULT_MAX_REDIRECTS 20 |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
36 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
37 | typedef struct _PurpleHttpURL PurpleHttpURL; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
38 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
39 | typedef struct _PurpleHttpSocket PurpleHttpSocket; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
40 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
41 | typedef struct _PurpleHttpHeaders PurpleHttpHeaders; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
42 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
43 | struct _PurpleHttpSocket |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
44 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
45 | gboolean is_ssl; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
46 | PurpleSslConnection *ssl_connection; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
47 | PurpleProxyConnectData *raw_connection; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
48 | int fd; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
49 | guint inpa; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
50 | }; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
51 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
52 | struct _PurpleHttpRequest |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
53 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
54 | int ref_count; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
55 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
56 | gchar *url; |
|
33444
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
57 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
58 | int max_redirects; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
59 | gboolean http11; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
60 | }; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
61 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
62 | struct _PurpleHttpConnection |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
63 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
64 | PurpleConnection *gc; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
65 | PurpleHttpCallback callback; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
66 | gpointer user_data; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
67 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
68 | PurpleHttpURL *url; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
69 | PurpleHttpRequest *request; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
70 | PurpleHttpResponse *response; |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
71 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
72 | PurpleHttpSocket socket; |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
73 | GString *request_header; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
74 | int request_header_written; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
75 | gboolean main_header_got, headers_got; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
76 | GString *response_buffer; |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
77 | |
|
33444
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
78 | int redirects_count; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
79 | |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
80 | int length_expected, length_got; |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
81 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
82 | gboolean is_chunked, in_chunk, chunks_done; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
83 | int chunk_length, chunk_got; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
84 | }; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
85 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
86 | struct _PurpleHttpResponse |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
87 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
88 | int code; |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
89 | gchar *error; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
90 | |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
91 | GString *contents; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
92 | PurpleHttpHeaders *headers; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
93 | }; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
94 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
95 | struct _PurpleHttpURL |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
96 | { |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
97 | gchar *protocol; |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
98 | gchar *user; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
99 | gchar *password; |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
100 | gchar *host; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
101 | int port; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
102 | gchar *path; |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
103 | gchar *fragment; |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
104 | }; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
105 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
106 | struct _PurpleHttpHeaders |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
107 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
108 | GList *list; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
109 | GHashTable *by_name; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
110 | }; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
111 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
112 | static PurpleHttpConnection * purple_http_connection_new( |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
113 | PurpleHttpRequest *request); |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
114 | 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
|
115 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
116 | 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
|
117 | 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
|
118 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
119 | static PurpleHttpURL * purple_http_url_parse(const char *url); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
120 | static void purple_http_url_free(PurpleHttpURL *parsed_url); |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
121 | static void purple_http_url_relative(PurpleHttpURL *base_url, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
122 | PurpleHttpURL *relative_url); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
123 | static gchar * purple_http_url_print(PurpleHttpURL *parsed_url); |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
124 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
125 | 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
|
126 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
127 | /*** Headers collection *******************************************************/ |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
128 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
129 | static PurpleHttpHeaders * purple_http_headers_new(void); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
130 | static void purple_http_headers_free(PurpleHttpHeaders *hdrs); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
131 | 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
|
132 | const gchar *value); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
133 | static const GList * purple_http_headers_get_all(PurpleHttpHeaders *hdrs); |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
134 | 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
|
135 | const gchar *key); |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
136 | 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
|
137 | const gchar *key, int *dst); |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
138 | static gboolean purple_http_headers_match(PurpleHttpHeaders *hdrs, |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
139 | const gchar *key, const gchar *value); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
140 | static gchar * purple_http_headers_dump(PurpleHttpHeaders *hdrs); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
141 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
142 | static PurpleHttpHeaders * purple_http_headers_new(void) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
143 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
144 | PurpleHttpHeaders *hdrs = g_new0(PurpleHttpHeaders, 1); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
145 | |
|
33437
fb792f8b6265
Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33436
diff
changeset
|
146 | 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
|
147 | (GDestroyNotify)g_list_free); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
148 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
149 | return hdrs; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
150 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
151 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
152 | 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
|
153 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
154 | g_free(kvp->key); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
155 | g_free(kvp->value); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
156 | g_free(kvp); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
157 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
158 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
159 | static void purple_http_headers_free(PurpleHttpHeaders *hdrs) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
160 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
161 | if (hdrs == NULL) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
162 | return; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
163 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
164 | g_hash_table_destroy(hdrs->by_name); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
165 | g_list_free_full(hdrs->list, |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
166 | (GDestroyNotify)purple_http_headers_free_kvp); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
167 | g_free(hdrs); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
168 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
169 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
170 | 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
|
171 | const gchar *value) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
172 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
173 | PurpleKeyValuePair *kvp; |
|
33437
fb792f8b6265
Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33436
diff
changeset
|
174 | GList *named_values, *new_values; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
175 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
176 | g_return_if_fail(hdrs != NULL); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
177 | g_return_if_fail(key != NULL); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
178 | g_return_if_fail(value != NULL); |
|
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 | kvp = g_new0(PurpleKeyValuePair, 1); |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
181 | kvp->key = g_ascii_strdown(key, -1); |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
182 | key = kvp->key; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
183 | kvp->value = g_strdup(value); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
184 | hdrs->list = g_list_append(hdrs->list, kvp); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
185 | |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
186 | named_values = g_hash_table_lookup(hdrs->by_name, key); |
|
33437
fb792f8b6265
Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33436
diff
changeset
|
187 | new_values = g_list_append(named_values, kvp->value); |
|
fb792f8b6265
Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33436
diff
changeset
|
188 | if (!named_values) |
|
fb792f8b6265
Fix leak caused by my previous temporary fix
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33436
diff
changeset
|
189 | g_hash_table_insert(hdrs->by_name, g_strdup(key), new_values); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
190 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
191 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
192 | 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
|
193 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
194 | return hdrs->list; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
195 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
196 | |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
197 | 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
|
198 | const gchar *key) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
199 | { |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
200 | GList *values; |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
201 | gchar *key_low; |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
202 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
203 | g_return_val_if_fail(hdrs != NULL, NULL); |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
204 | g_return_val_if_fail(key != NULL, NULL); |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
205 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
206 | key_low = g_ascii_strdown(key, -1); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
207 | 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
|
208 | g_free(key_low); |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
209 | if (!values) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
210 | return NULL; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
211 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
212 | return values->data; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
213 | } |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
214 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
215 | 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
|
216 | const gchar *key, int *dst) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
217 | { |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
218 | int val; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
219 | const gchar *str; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
220 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
221 | str = purple_http_headers_get(hdrs, key); |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
222 | if (!str) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
223 | return FALSE; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
224 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
225 | if (1 != sscanf(str, "%d", &val)) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
226 | return FALSE; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
227 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
228 | *dst = val; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
229 | return TRUE; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
230 | } |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
231 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
232 | static gboolean purple_http_headers_match(PurpleHttpHeaders *hdrs, |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
233 | const gchar *key, const gchar *value) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
234 | { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
235 | const gchar *str; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
236 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
237 | str = purple_http_headers_get(hdrs, key); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
238 | if (str == NULL || value == NULL) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
239 | return str == value; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
240 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
241 | return (g_ascii_strcasecmp(str, value) == 0); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
242 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
243 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
244 | static gchar * purple_http_headers_dump(PurpleHttpHeaders *hdrs) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
245 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
246 | const GList *hdr; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
247 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
248 | GString *s = g_string_new(""); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
249 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
250 | hdr = purple_http_headers_get_all(hdrs); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
251 | while (hdr) { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
252 | PurpleKeyValuePair *kvp = hdr->data; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
253 | hdr = g_list_next(hdr); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
254 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
255 | 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
|
256 | (gchar*)kvp->value, hdr ? "\n" : ""); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
257 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
258 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
259 | return g_string_free(s, FALSE); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
260 | } |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
261 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
262 | /*** HTTP protocol backend ****************************************************/ |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
263 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
264 | static void _purple_http_disconnect(PurpleHttpConnection *hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
265 | |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
266 | static void _purple_http_gen_headers(PurpleHttpConnection *hc); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
267 | 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
|
268 | static void _purple_http_recv_ssl(gpointer _hc, |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
269 | PurpleSslConnection *ssl_connection, PurpleInputCondition cond); |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
270 | 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
|
271 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
272 | static void _purple_http_connected_raw(gpointer _hc, gint source, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
273 | const gchar *error_message); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
274 | static void _purple_http_connected_ssl(gpointer _hc, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
275 | PurpleSslConnection *ssl_connection, PurpleInputCondition cond); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
276 | static void _purple_http_connected_ssl_error( |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
277 | PurpleSslConnection *ssl_connection, PurpleSslErrorType error, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
278 | gpointer _hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
279 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
280 | /* closes current connection (if exists), estabilishes one and proceeds with |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
281 | * request */ |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
282 | static gboolean _purple_http_reconnect(PurpleHttpConnection *hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
283 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
284 | static void _purple_http_error(PurpleHttpConnection *hc, const char *format, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
285 | ...) G_GNUC_PRINTF(2, 3); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
286 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
287 | static void _purple_http_error(PurpleHttpConnection *hc, const char *format, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
288 | ...) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
289 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
290 | va_list args; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
291 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
292 | va_start(args, format); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
293 | hc->response->error = g_strdup_vprintf(format, args); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
294 | va_end(args); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
295 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
296 | purple_http_conn_cancel(hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
297 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
298 | |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
299 | static void _purple_http_gen_headers(PurpleHttpConnection *hc) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
300 | { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
301 | GString *h; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
302 | PurpleHttpURL *url; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
303 | PurpleProxyInfo *proxy; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
304 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
305 | g_return_if_fail(hc != NULL); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
306 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
307 | if (hc->request_header != NULL) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
308 | return; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
309 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
310 | url = hc->url; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
311 | proxy = purple_proxy_get_setup(hc->gc ? |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
312 | purple_connection_get_account(hc->gc) : NULL); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
313 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
314 | hc->request_header = h = g_string_new(""); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
315 | hc->request_header_written = 0; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
316 | |
|
33444
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
317 | g_string_append_printf(h, "GET %s HTTP/%s\r\n", url->path, |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
318 | hc->request->http11 ? "1.1" : "1.0"); |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
319 | g_string_append_printf(h, "Host: %s\r\n", url->host); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
320 | g_string_append_printf(h, "Connection: close\r\n"); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
321 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
322 | /* TODO: don't put here, if exists */ |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
323 | g_string_append_printf(h, "Accept: */*\r\n"); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
324 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
325 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
326 | if (purple_proxy_info_get_username(proxy) != NULL && |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
327 | (purple_proxy_info_get_type(proxy) == PURPLE_PROXY_USE_ENVVAR || |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
328 | purple_proxy_info_get_type(proxy) == PURPLE_PROXY_HTTP)) { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
329 | purple_debug_error("http", |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
330 | "Proxy authorization is not yet supported\n"); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
331 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
332 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
333 | g_string_append_printf(h, "\r\n"); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
334 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
335 | if (purple_debug_is_unsafe() && purple_debug_is_verbose()) { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
336 | purple_debug_misc("http", "Generated request headers:\n%s", |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
337 | h->str); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
338 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
339 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
340 | |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
341 | 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
|
342 | const gchar *buf, int len) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
343 | { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
344 | gchar *eol, *delim; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
345 | |
|
33435
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
346 | if (hc->headers_got) { |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
347 | purple_debug_error("http", "Headers already got\n"); |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
348 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
349 | return FALSE; |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
350 | } |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
351 | |
|
33443
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
352 | 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
|
353 | 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
|
354 | purple_debug_error("http", |
|
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
355 | "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
|
356 | _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
|
357 | return FALSE; |
|
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
358 | } |
|
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
359 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
360 | 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
|
361 | != NULL) { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
362 | gchar *hdrline = hc->response_buffer->str; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
363 | int hdrline_len = eol - hdrline; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
364 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
365 | hdrline[hdrline_len] = '\0'; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
366 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
367 | if (hdrline[0] == '\0') { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
368 | if (!hc->main_header_got) { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
369 | hc->response->code = 0; |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
370 | purple_debug_warning("http", |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
371 | "Main header not present\n"); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
372 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
373 | return FALSE; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
374 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
375 | hc->headers_got = TRUE; |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
376 | if (purple_debug_is_verbose()) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
377 | 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
|
378 | } else if (!hc->main_header_got) { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
379 | hc->main_header_got = TRUE; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
380 | delim = strchr(hdrline, ' '); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
381 | if (delim == NULL || 1 != sscanf(delim + 1, "%d", |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
382 | &hc->response->code)) { |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
383 | purple_debug_warning("http", |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
384 | "Invalid response code\n"); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
385 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
386 | return FALSE; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
387 | } |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
388 | if (purple_debug_is_verbose()) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
389 | purple_debug_misc("http", "Got main header\n"); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
390 | } else { |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
391 | if (purple_debug_is_verbose() && |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
392 | purple_debug_is_unsafe()) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
393 | purple_debug_misc("http", "Got header: %s\n", |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
394 | hdrline); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
395 | delim = strchr(hdrline, ':'); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
396 | if (delim == NULL || delim == hdrline) { |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
397 | purple_debug_warning("http", |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
398 | "Bad header delimiter\n"); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
399 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
400 | return FALSE; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
401 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
402 | *delim++ = '\0'; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
403 | while (*delim == ' ') |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
404 | delim++; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
405 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
406 | 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
|
407 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
408 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
409 | 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
|
410 | if (hc->headers_got) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
411 | break; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
412 | } |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
413 | return TRUE; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
414 | } |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
415 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
416 | static void _purple_http_recv_body_data(PurpleHttpConnection *hc, |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
417 | const gchar *buf, int len) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
418 | { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
419 | g_string_append_len(hc->response->contents, buf, len); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
420 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
421 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
422 | static gboolean _purple_http_recv_body_chunked(PurpleHttpConnection *hc, |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
423 | const gchar *buf, int len) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
424 | { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
425 | gchar *eol, *line; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
426 | int line_len; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
427 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
428 | if (hc->chunks_done) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
429 | return FALSE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
430 | if (!hc->response_buffer) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
431 | hc->response_buffer = g_string_new(""); |
|
33436
abec627c3a47
Segfault found, temporarily fixed
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33435
diff
changeset
|
432 | |
|
33443
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
433 | 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
|
434 | 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
|
435 | purple_debug_error("http", |
|
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
436 | "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
|
437 | _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
|
438 | return FALSE; |
|
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
439 | } |
|
ab563d4c927a
Don't eat resources with malicious http server
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33439
diff
changeset
|
440 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
441 | while (hc->response_buffer->len > 0) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
442 | if (hc->in_chunk) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
443 | int got_now = hc->response_buffer->len; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
444 | if (hc->chunk_got + got_now > hc->chunk_length) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
445 | got_now = hc->chunk_length - hc->chunk_got; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
446 | hc->chunk_got += got_now; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
447 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
448 | _purple_http_recv_body_data(hc, |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
449 | hc->response_buffer->str, got_now); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
450 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
451 | g_string_erase(hc->response_buffer, 0, got_now); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
452 | hc->in_chunk = (hc->chunk_got < hc->chunk_length); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
453 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
454 | if (purple_debug_is_verbose()) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
455 | purple_debug_misc("http", "Chunk (%d/%d)\n", |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
456 | hc->chunk_got, hc->chunk_length); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
457 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
458 | continue; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
459 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
460 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
461 | line = hc->response_buffer->str; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
462 | eol = strstr(line, "\r\n"); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
463 | if (eol == NULL) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
464 | /* waiting for more data (unlikely, but possible) */ |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
465 | if (hc->response_buffer->len > 20) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
466 | purple_debug_warning("http", "Chunk length not " |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
467 | "found (buffer too large)\n"); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
468 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
469 | return FALSE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
470 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
471 | return TRUE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
472 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
473 | line_len = eol - line; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
474 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
475 | if (1 != sscanf(line, "%x", &hc->chunk_length)) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
476 | purple_debug_warning("http", |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
477 | "Chunk length not found\n"); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
478 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
479 | return FALSE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
480 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
481 | hc->chunk_got = 0; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
482 | hc->in_chunk = TRUE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
483 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
484 | if (purple_debug_is_verbose()) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
485 | 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
|
486 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
487 | 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
|
488 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
489 | if (hc->chunk_length == 0) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
490 | hc->chunks_done = TRUE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
491 | hc->in_chunk = FALSE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
492 | return TRUE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
493 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
494 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
495 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
496 | return TRUE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
497 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
498 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
499 | 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
|
500 | const gchar *buf, int len) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
501 | { |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
502 | if (hc->response->contents == NULL) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
503 | hc->response->contents = g_string_new(""); |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
504 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
505 | if (hc->is_chunked) |
|
33435
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
506 | { |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
507 | hc->length_got += len; |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
508 | return _purple_http_recv_body_chunked(hc, buf, len); |
|
33435
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
509 | } |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
510 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
511 | if (hc->length_expected >= 0 && |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
512 | len + hc->length_got > hc->length_expected) |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
513 | len = hc->length_expected - hc->length_got; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
514 | hc->length_got += len; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
515 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
516 | _purple_http_recv_body_data(hc, buf, len); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
517 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
518 | return TRUE; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
519 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
520 | |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
521 | 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
|
522 | { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
523 | PurpleHttpConnection *hc = _hc; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
524 | PurpleHttpSocket *hs = &hc->socket; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
525 | int len; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
526 | gchar buf[4096]; |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
527 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
528 | if (hs->is_ssl) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
529 | len = purple_ssl_read(hs->ssl_connection, buf, sizeof(buf)); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
530 | else |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
531 | len = read(fd, buf, sizeof(buf)); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
532 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
533 | if (len < 0 && errno == EAGAIN) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
534 | return; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
535 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
536 | if (len < 0) { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
537 | _purple_http_error(hc, _("Error reading from %s: %s"), |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
538 | hc->url->host, g_strerror(errno)); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
539 | return; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
540 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
541 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
542 | /* EOF */ |
|
33435
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
543 | if (len == 0) { |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
544 | if (hc->length_expected >= 0 && |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
545 | hc->length_got < hc->length_expected) { |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
546 | purple_debug_warning("http", "No more data while reading" |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
547 | " contents\n"); |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
548 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
549 | return; |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
550 | } |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
551 | if (hc->headers_got) |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
552 | hc->length_expected = hc->length_got; |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
553 | else { |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
554 | purple_debug_warning("http", "No more data while " |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
555 | "parsing headers\n"); |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
556 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
557 | return; |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
558 | } |
|
ab0560aa8ca4
Segfault shotgun debugging
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33434
diff
changeset
|
559 | } |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
560 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
561 | if (!hc->headers_got && len > 0) { |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
562 | if (!_purple_http_recv_headers(hc, buf, len)) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
563 | return; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
564 | if (hc->headers_got) { |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
565 | 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
|
566 | "Content-Length", &hc->length_expected)) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
567 | hc->length_expected = -1; |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
568 | hc->is_chunked = (purple_http_headers_match( |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
569 | hc->response->headers, |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
570 | "Transfer-Encoding", "chunked")); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
571 | } |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
572 | if (hc->headers_got && hc->response_buffer && |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
573 | hc->response_buffer->len > 0) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
574 | int buffer_len = hc->response_buffer->len; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
575 | gchar *buffer = g_string_free(hc->response_buffer, FALSE); |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
576 | hc->response_buffer = NULL; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
577 | _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
|
578 | } |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
579 | return; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
580 | } |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
581 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
582 | if (len > 0) { |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
583 | if (!_purple_http_recv_body(hc, buf, len)) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
584 | return; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
585 | } |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
586 | |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
587 | if (hc->is_chunked && hc->chunks_done) |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
588 | hc->length_expected = hc->length_got; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
589 | |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
590 | 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
|
591 | const gchar *redirect; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
592 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
593 | if (!hc->headers_got) { |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
594 | hc->response->code = 0; |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
595 | 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
|
596 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
597 | return; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
598 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
599 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
600 | 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
|
601 | gchar *hdrs = purple_http_headers_dump( |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
602 | hc->response->headers); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
603 | 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
|
604 | hdrs); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
605 | g_free(hdrs); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
606 | } |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
607 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
608 | redirect = purple_http_headers_get(hc->response->headers, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
609 | "location"); |
|
33445
1bcbdca07787
Allow infinite amount of redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33444
diff
changeset
|
610 | if (redirect && (hc->request->max_redirects == -1 || |
|
1bcbdca07787
Allow infinite amount of redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33444
diff
changeset
|
611 | hc->request->max_redirects > hc->redirects_count)) { |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
612 | PurpleHttpURL *url = purple_http_url_parse(redirect); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
613 | |
|
33444
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
614 | hc->redirects_count++; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
615 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
616 | if (!url) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
617 | if (purple_debug_is_unsafe()) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
618 | purple_debug_warning("http", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
619 | "Invalid redirect to %s\n", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
620 | redirect); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
621 | else |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
622 | purple_debug_warning("http", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
623 | "Invalid redirect\n"); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
624 | _purple_http_error(hc, _("Error parsing HTTP")); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
625 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
626 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
627 | purple_http_url_relative(hc->url, url); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
628 | purple_http_url_free(url); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
629 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
630 | _purple_http_reconnect(hc); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
631 | return; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
632 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
633 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
634 | _purple_http_disconnect(hc); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
635 | purple_http_connection_terminate(hc); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
636 | return; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
637 | } |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
638 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
639 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
640 | static void _purple_http_recv_ssl(gpointer _hc, |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
641 | PurpleSslConnection *ssl_connection, PurpleInputCondition cond) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
642 | { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
643 | _purple_http_recv(_hc, -1, cond); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
644 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
645 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
646 | 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
|
647 | { |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
648 | PurpleHttpConnection *hc = _hc; |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
649 | PurpleHttpSocket *hs = &hc->socket; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
650 | int written, write_len; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
651 | const gchar *write_from; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
652 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
653 | _purple_http_gen_headers(hc); |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
654 | |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
655 | write_from = hc->request_header->str + hc->request_header_written; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
656 | write_len = hc->request_header->len - hc->request_header_written; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
657 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
658 | if (hs->is_ssl) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
659 | written = purple_ssl_write(hs->ssl_connection, |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
660 | write_from, write_len); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
661 | else |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
662 | written = write(hs->fd, write_from, write_len); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
663 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
664 | if (written < 0 && errno == EAGAIN) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
665 | return; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
666 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
667 | if (written < 0) { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
668 | _purple_http_error(hc, _("Error writing to %s: %s"), |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
669 | hc->url->host, g_strerror(errno)); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
670 | return; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
671 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
672 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
673 | hc->request_header_written += written; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
674 | if (hc->request_header_written < hc->request_header->len) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
675 | return; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
676 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
677 | /* TODO: write contents */ |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
678 | |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
679 | /* request is completely written, let's read the response */ |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
680 | purple_input_remove(hs->inpa); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
681 | hs->inpa = 0; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
682 | if (hs->is_ssl) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
683 | purple_ssl_input_add(hs->ssl_connection, |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
684 | _purple_http_recv_ssl, hc); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
685 | else |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
686 | hs->inpa = purple_input_add(hs->fd, PURPLE_INPUT_READ, |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
687 | _purple_http_recv, hc); |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
688 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
689 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
690 | static void _purple_http_connected_raw(gpointer _hc, gint fd, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
691 | const gchar *error_message) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
692 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
693 | PurpleHttpConnection *hc = _hc; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
694 | PurpleHttpSocket *hs = &hc->socket; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
695 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
696 | hs->raw_connection = NULL; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
697 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
698 | if (fd == -1) { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
699 | _purple_http_error(hc, _("Unable to connect to %s: %s"), |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
700 | hc->url->host, error_message); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
701 | return; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
702 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
703 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
704 | hs->fd = fd; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
705 | hs->inpa = purple_input_add(fd, PURPLE_INPUT_WRITE, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
706 | _purple_http_send, hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
707 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
708 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
709 | static void _purple_http_connected_ssl(gpointer _hc, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
710 | PurpleSslConnection *ssl_connection, PurpleInputCondition cond) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
711 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
712 | PurpleHttpConnection *hc = _hc; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
713 | PurpleHttpSocket *hs = &hc->socket; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
714 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
715 | hs->fd = hs->ssl_connection->fd; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
716 | hs->inpa = purple_input_add(hs->fd, PURPLE_INPUT_WRITE, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
717 | _purple_http_send, hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
718 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
719 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
720 | static void _purple_http_connected_ssl_error( |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
721 | PurpleSslConnection *ssl_connection, PurpleSslErrorType error, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
722 | gpointer _hc) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
723 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
724 | PurpleHttpConnection *hc = _hc; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
725 | PurpleHttpSocket *hs = &hc->socket; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
726 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
727 | hs->ssl_connection = NULL; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
728 | _purple_http_error(hc, _("Unable to connect to %s: %s"), |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
729 | hc->url->host, purple_ssl_strerror(error)); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
730 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
731 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
732 | static void _purple_http_disconnect(PurpleHttpConnection *hc) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
733 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
734 | PurpleHttpSocket *hs; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
735 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
736 | g_return_if_fail(hc != NULL); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
737 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
738 | hs = &hc->socket; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
739 | |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
740 | if (hc->request_header) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
741 | g_string_free(hc->request_header, TRUE); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
742 | hc->request_header = NULL; |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
743 | if (hc->response_buffer) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
744 | g_string_free(hc->response_buffer, TRUE); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
745 | hc->response_buffer = NULL; |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
746 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
747 | if (hs->inpa != 0) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
748 | purple_input_remove(hs->inpa); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
749 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
750 | if (hs->is_ssl) { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
751 | if (hs->ssl_connection != NULL) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
752 | purple_ssl_close(hs->ssl_connection); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
753 | } else { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
754 | if (hs->raw_connection != NULL) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
755 | purple_proxy_connect_cancel(hs->raw_connection); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
756 | if (hs->fd > 0) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
757 | close(hs->fd); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
758 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
759 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
760 | memset(hs, 0, sizeof(PurpleHttpSocket)); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
761 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
762 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
763 | static gboolean _purple_http_reconnect(PurpleHttpConnection *hc) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
764 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
765 | PurpleHttpURL *url; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
766 | gboolean is_ssl = FALSE; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
767 | PurpleAccount *account = NULL; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
768 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
769 | g_return_val_if_fail(hc != NULL, FALSE); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
770 | g_return_val_if_fail(hc->url != NULL, FALSE); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
771 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
772 | _purple_http_disconnect(hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
773 | |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
774 | if (purple_debug_is_verbose()) { |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
775 | if (purple_debug_is_unsafe()) { |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
776 | gchar *url = purple_http_url_print(hc->url); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
777 | purple_debug_misc("http", "Connecting to %s...\n", url); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
778 | g_free(url); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
779 | } else |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
780 | purple_debug_misc("http", "Connecting to %s...\n", |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
781 | hc->url->host); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
782 | } |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
783 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
784 | if (hc->gc) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
785 | account = purple_connection_get_account(hc->gc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
786 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
787 | url = hc->url; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
788 | if (url->protocol[0] == '\0' || |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
789 | g_ascii_strcasecmp(url->protocol, "http") == 0) { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
790 | /* do nothing */ |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
791 | } else if (g_ascii_strcasecmp(url->protocol, "https") == 0) { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
792 | is_ssl = TRUE; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
793 | } else { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
794 | _purple_http_error(hc, _("Unsupported protocol: %s"), |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
795 | url->protocol); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
796 | return FALSE; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
797 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
798 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
799 | hc->socket.is_ssl = is_ssl; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
800 | if (is_ssl) { |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
801 | if (!purple_ssl_is_supported()) { |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
802 | _purple_http_error(hc, _("Unable to connect to %s: %s"), |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
803 | url->host, _("Server requires TLS/SSL, " |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
804 | "but no TLS/SSL support was found.")); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
805 | return FALSE; |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
806 | } |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
807 | hc->socket.ssl_connection = purple_ssl_connect(account, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
808 | url->host, url->port, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
809 | _purple_http_connected_ssl, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
810 | _purple_http_connected_ssl_error, hc); |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
811 | // purple_ssl_set_compatibility_level(hc->socket.ssl_connection, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
812 | // PURPLE_SSL_COMPATIBILITY_SECURE); |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
813 | } else { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
814 | hc->socket.raw_connection = purple_proxy_connect(hc->gc, account, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
815 | url->host, url->port, |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
816 | _purple_http_connected_raw, hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
817 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
818 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
819 | if (hc->socket.ssl_connection == NULL && |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
820 | hc->socket.raw_connection == NULL) { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
821 | _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
|
822 | return FALSE; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
823 | } |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
824 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
825 | purple_http_headers_free(hc->response->headers); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
826 | hc->response->headers = purple_http_headers_new(); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
827 | hc->response_buffer = g_string_new(""); |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
828 | hc->main_header_got = FALSE; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
829 | hc->headers_got = FALSE; |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
830 | if (hc->response->contents != NULL) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
831 | g_string_free(hc->response->contents, TRUE); |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
832 | hc->response->contents = NULL; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
833 | hc->length_got = 0; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
834 | hc->length_expected = -1; |
|
33434
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
835 | hc->is_chunked = FALSE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
836 | hc->in_chunk = FALSE; |
|
ec4f343af107
Chunked file transfers support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33433
diff
changeset
|
837 | hc->chunks_done = FALSE; |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
838 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
839 | return TRUE; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
840 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
841 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
842 | /*** Performing HTTP requests *************************************************/ |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
843 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
844 | 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
|
845 | PurpleHttpCallback callback, gpointer user_data) |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
846 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
847 | PurpleHttpRequest *request; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
848 | PurpleHttpConnection *hc; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
849 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
850 | 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
|
851 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
852 | request = purple_http_request_new(url); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
853 | 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
|
854 | purple_http_request_unref(request); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
855 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
856 | return hc; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
857 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
858 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
859 | PurpleHttpConnection * purple_http_request(PurpleConnection *gc, |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
860 | PurpleHttpRequest *request, PurpleHttpCallback callback, |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
861 | gpointer user_data) |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
862 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
863 | PurpleHttpConnection *hc; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
864 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
865 | 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
|
866 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
867 | hc = purple_http_connection_new(request); |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
868 | hc->gc = gc; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
869 | hc->callback = callback; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
870 | hc->user_data = user_data; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
871 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
872 | if (purple_debug_is_unsafe()) |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
873 | 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
|
874 | hc, request->url); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
875 | else |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
876 | purple_debug_misc("http", "Performing new request %p.\n", hc); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
877 | |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
878 | hc->url = purple_http_url_parse(request->url); |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
879 | if (!hc->url || hc->url->host[0] == '\0') { |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
880 | purple_debug_error("http", "Invalid URL requested.\n"); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
881 | purple_http_connection_terminate(hc); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
882 | return NULL; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
883 | } |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
884 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
885 | _purple_http_reconnect(hc); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
886 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
887 | /* TODO: timeout */ |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
888 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
889 | return hc; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
890 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
891 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
892 | /*** HTTP connection API ******************************************************/ |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
893 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
894 | 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
|
895 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
896 | static PurpleHttpConnection * purple_http_connection_new(PurpleHttpRequest *request) |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
897 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
898 | PurpleHttpConnection *hc = g_new0(PurpleHttpConnection, 1); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
899 | |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
900 | hc->request = request; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
901 | purple_http_request_ref(request); |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
902 | hc->response = purple_http_response_new(); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
903 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
904 | return hc; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
905 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
906 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
907 | 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
|
908 | { |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
909 | purple_http_url_free(hc->url); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
910 | 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
|
911 | purple_http_response_free(hc->response); |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
912 | |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
913 | if (hc->request_header) |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
914 | g_string_free(hc->request_header, TRUE); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
915 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
916 | g_free(hc); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
917 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
918 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
919 | /* call callback and do the cleanup */ |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
920 | 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
|
921 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
922 | g_return_if_fail(hc != NULL); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
923 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
924 | 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
|
925 | 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
|
926 | "successfully" : "without success"); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
927 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
928 | if (hc->callback) |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
929 | 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
|
930 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
931 | purple_http_connection_free(hc); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
932 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
933 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
934 | void purple_http_conn_cancel(PurpleHttpConnection *http_conn) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
935 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
936 | http_conn->response->code = 0; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
937 | _purple_http_disconnect(http_conn); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
938 | purple_http_connection_terminate(http_conn); |
|
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 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
941 | 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
|
942 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
943 | purple_debug_warning("http", "purple_http_conn_cancel_all: To be implemented\n"); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
944 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
945 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
946 | /*** Request API **************************************************************/ |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
947 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
948 | 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
|
949 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
950 | 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
|
951 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
952 | PurpleHttpRequest *request; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
953 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
954 | 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
|
955 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
956 | request = g_new0(PurpleHttpRequest, 1); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
957 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
958 | request->ref_count = 1; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
959 | request->url = g_strdup(url); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
960 | |
|
33444
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
961 | 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
|
962 | request->http11 = TRUE; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
963 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
964 | return request; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
965 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
966 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
967 | 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
|
968 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
969 | g_free(request->url); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
970 | g_free(request); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
971 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
972 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
973 | 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
|
974 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
975 | g_return_if_fail(request != NULL); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
976 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
977 | request->ref_count++; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
978 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
979 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
980 | 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
|
981 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
982 | if (request == NULL) |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
983 | return NULL; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
984 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
985 | 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
|
986 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
987 | request->ref_count--; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
988 | if (request->ref_count > 0) |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
989 | return request; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
990 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
991 | purple_http_request_free(request); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
992 | return NULL; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
993 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
994 | |
|
33444
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
995 | 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
|
996 | int max_redirects) |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
997 | { |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
998 | 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
|
999 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1000 | if (max_redirects < -1) |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1001 | max_redirects = -1; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1002 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1003 | 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
|
1004 | } |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1005 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1006 | 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
|
1007 | { |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1008 | 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
|
1009 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1010 | return request->max_redirects; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1011 | } |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1012 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1013 | 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
|
1014 | { |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1015 | 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
|
1016 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1017 | request->http11 = http11; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1018 | } |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1019 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1020 | 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
|
1021 | { |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1022 | 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
|
1023 | |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1024 | return request->http11; |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1025 | } |
|
b3afec292014
New features: http version switching and limits for redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33443
diff
changeset
|
1026 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1027 | /*** HTTP response API ********************************************************/ |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1028 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1029 | 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
|
1030 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1031 | PurpleHttpResponse *response = g_new0(PurpleHttpResponse, 1); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1032 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1033 | return response; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1034 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1035 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1036 | 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
|
1037 | { |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1038 | if (response->contents != NULL) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1039 | g_string_free(response->contents, TRUE); |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1040 | g_free(response->error); |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1041 | 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
|
1042 | g_free(response); |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1043 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1044 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1045 | 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
|
1046 | { |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1047 | int code; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1048 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1049 | 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
|
1050 | |
|
33432
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1051 | code = response->code; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1052 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1053 | if (code <= 0) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1054 | return FALSE; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1055 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1056 | if (code == 200) |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1057 | return TRUE; |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1058 | |
|
9c4acb75b2e6
Let's parse response headers
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33431
diff
changeset
|
1059 | return FALSE; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1060 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1061 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1062 | 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
|
1063 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1064 | 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
|
1065 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1066 | return response->code; |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1067 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1068 | |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1069 | const gchar * purple_http_response_get_error(PurpleHttpResponse *response) |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1070 | { |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1071 | g_return_val_if_fail(response != NULL, NULL); |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1072 | |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1073 | return response->error; |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1074 | } |
|
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1075 | |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1076 | 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
|
1077 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1078 | 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
|
1079 | |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1080 | if (response->contents == NULL) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1081 | return 0; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1082 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1083 | return response->contents->len; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1084 | } |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1085 | |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1086 | 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
|
1087 | { |
|
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1088 | 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
|
1089 | |
|
33433
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1090 | if (response->contents == NULL) |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1091 | return ""; |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1092 | |
|
fb7ac52ed7df
Let's get response contents
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33432
diff
changeset
|
1093 | return response->contents->str; |
|
33427
dd0c0860e293
Basic API and testing actions for it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33425
diff
changeset
|
1094 | } |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1095 | |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1096 | /*** URL functions ************************************************************/ |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1097 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1098 | 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
|
1099 | { |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1100 | PurpleHttpURL *url; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1101 | GMatchInfo *match_info; |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1102 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1103 | gchar *host_full, *tmp; |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1104 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1105 | g_return_val_if_fail(raw_url != NULL, NULL); |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1106 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1107 | url = g_new0(PurpleHttpURL, 1); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1108 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1109 | 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
|
1110 | if (purple_debug_is_verbose() && purple_debug_is_unsafe()) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1111 | purple_debug_warning("http", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1112 | "Invalid URL provided: %s\n", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1113 | raw_url); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1114 | } |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1115 | return NULL; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1116 | } |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1117 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1118 | url->protocol = g_match_info_fetch(match_info, 1); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1119 | host_full = g_match_info_fetch(match_info, 2); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1120 | url->path = g_match_info_fetch(match_info, 3); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1121 | url->fragment = g_match_info_fetch(match_info, 4); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1122 | g_match_info_free(match_info); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1123 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1124 | if (url->protocol[0] == '\0') { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1125 | g_free(url->protocol); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1126 | url->protocol = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1127 | } else if (url->protocol != NULL) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1128 | tmp = url->protocol; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1129 | url->protocol = g_ascii_strdown(url->protocol, -1); |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
1130 | g_free(tmp); |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
1131 | } |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1132 | if (host_full[0] == '\0') { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1133 | g_free(host_full); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1134 | host_full = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1135 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1136 | if (url->path[0] == '\0') { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1137 | g_free(url->path); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1138 | url->path = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1139 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1140 | if ((url->protocol == NULL) != (host_full == NULL)) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1141 | purple_debug_warning("http", "Protocol or host not present " |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1142 | "(unlikely case)\n"); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1143 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1144 | if (host_full) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1145 | gchar *port_str; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1146 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1147 | 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
|
1148 | &match_info)) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1149 | if (purple_debug_is_verbose() && |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1150 | purple_debug_is_unsafe()) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1151 | purple_debug_warning("http", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1152 | "Invalid host provided for URL: %s\n", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1153 | raw_url); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1154 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1155 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1156 | g_free(host_full); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1157 | purple_http_url_free(url); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1158 | return NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1159 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1160 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1161 | url->user = g_match_info_fetch(match_info, 1); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1162 | url->password = g_match_info_fetch(match_info, 2); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1163 | url->host = g_match_info_fetch(match_info, 3); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1164 | port_str = g_match_info_fetch(match_info, 4); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1165 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1166 | if (port_str && port_str[0]) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1167 | url->port = atoi(port_str); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1168 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1169 | if (url->user[0] == '\0') { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1170 | g_free(url->user); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1171 | url->user = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1172 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1173 | if (url->password[0] == '\0') { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1174 | g_free(url->password); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1175 | url->password = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1176 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1177 | if (url->host[0] == '\0') { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1178 | g_free(url->host); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1179 | url->host = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1180 | } else if (url->host != NULL) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1181 | tmp = url->host; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1182 | url->host = g_ascii_strdown(url->host, -1); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1183 | g_free(tmp); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1184 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1185 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1186 | g_free(port_str); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1187 | g_match_info_free(match_info); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1188 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1189 | g_free(host_full); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1190 | host_full = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1191 | } |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
1192 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1193 | if (url->host != NULL) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1194 | if (url->protocol == NULL) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1195 | url->protocol = g_strdup("http"); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1196 | if (url->port == 0 && 0 == strcmp(url->protocol, "http")) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1197 | url->port = 80; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1198 | if (url->port == 0 && 0 == strcmp(url->protocol, "https")) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1199 | url->port = 443; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1200 | if (url->path == NULL) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1201 | url->path = g_strdup("/"); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1202 | if (url->path[0] != '/') |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1203 | purple_debug_warning("http", |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1204 | "URL path doesn't start with slash\n"); |
|
33431
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
1205 | } |
|
704de181d1d2
Let's request
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33430
diff
changeset
|
1206 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1207 | return url; |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1208 | } |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1209 | |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1210 | static void purple_http_url_free(PurpleHttpURL *parsed_url) |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1211 | { |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1212 | if (parsed_url == NULL) |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1213 | return; |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1214 | |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1215 | g_free(parsed_url->protocol); |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1216 | g_free(parsed_url->user); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1217 | g_free(parsed_url->password); |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1218 | g_free(parsed_url->host); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1219 | g_free(parsed_url->path); |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1220 | g_free(parsed_url->fragment); |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1221 | g_free(parsed_url); |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1222 | } |
|
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1223 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1224 | static void purple_http_url_relative(PurpleHttpURL *base_url, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1225 | PurpleHttpURL *relative_url) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1226 | { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1227 | g_return_if_fail(base_url != NULL); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1228 | g_return_if_fail(relative_url != NULL); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1229 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1230 | if (relative_url->host) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1231 | g_free(base_url->protocol); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1232 | base_url->protocol = g_strdup(relative_url->protocol); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1233 | g_free(base_url->user); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1234 | base_url->user = g_strdup(relative_url->user); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1235 | g_free(base_url->password); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1236 | base_url->password = g_strdup(relative_url->password); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1237 | g_free(base_url->host); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1238 | base_url->host = g_strdup(relative_url->host); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1239 | base_url->port = relative_url->port; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1240 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1241 | g_free(base_url->path); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1242 | base_url->path = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1243 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1244 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1245 | if (relative_url->path) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1246 | if (relative_url->path[0] == '/' || |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1247 | base_url->path == NULL) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1248 | g_free(base_url->path); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1249 | base_url->path = g_strdup(relative_url->path); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1250 | } else { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1251 | gchar *last_slash = strrchr(base_url->path, '/'); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1252 | gchar *tmp; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1253 | if (last_slash == NULL) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1254 | base_url->path[0] = '\0'; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1255 | else |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1256 | last_slash[1] = '\0'; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1257 | tmp = base_url->path; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1258 | base_url->path = g_strconcat(base_url->path, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1259 | relative_url->path, NULL); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1260 | g_free(tmp); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1261 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1262 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1263 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1264 | g_free(base_url->fragment); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1265 | base_url->fragment = g_strdup(relative_url->fragment); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1266 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1267 | |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1268 | static gchar * purple_http_url_print(PurpleHttpURL *parsed_url) |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1269 | { |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1270 | GString *url = g_string_new(""); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1271 | gboolean before_host_printed = FALSE, host_printed = FALSE; |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1272 | gboolean port_is_default = FALSE; |
|
33430
013c5aebb665
Let's connect
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33429
diff
changeset
|
1273 | |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1274 | if (parsed_url->protocol) { |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1275 | g_string_append_printf(url, "%s://", parsed_url->protocol); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1276 | before_host_printed = TRUE; |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1277 | if (parsed_url->port == 80 && 0 == strcmp(parsed_url->protocol, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1278 | "http")) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1279 | port_is_default = TRUE; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1280 | if (parsed_url->port == 443 && 0 == strcmp(parsed_url->protocol, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1281 | "https")) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1282 | port_is_default = TRUE; |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1283 | } |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1284 | if (parsed_url->user || parsed_url->password) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1285 | if (parsed_url->user) |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1286 | g_string_append(url, parsed_url->user); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1287 | g_string_append_printf(url, ":%s", parsed_url->password); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1288 | g_string_append(url, "@"); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1289 | before_host_printed = TRUE; |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1290 | } |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1291 | if (parsed_url->host || parsed_url->port) { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1292 | if (!parsed_url->host) |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1293 | g_string_append_printf(url, "{???}:%d", |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1294 | parsed_url->port); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1295 | else { |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1296 | g_string_append(url, parsed_url->host); |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1297 | if (!port_is_default) |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1298 | g_string_append_printf(url, ":%d", |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1299 | parsed_url->port); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1300 | } |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1301 | host_printed = TRUE; |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1302 | } |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1303 | if (parsed_url->path) { |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1304 | if (!host_printed && before_host_printed) |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1305 | g_string_append(url, "{???}"); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1306 | g_string_append(url, parsed_url->path); |
|
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1307 | } |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1308 | if (parsed_url->fragment) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1309 | g_string_append_printf(url, "#%s", parsed_url->fragment); |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1310 | |
|
33438
66c4b90ff08a
More debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33437
diff
changeset
|
1311 | return g_string_free(url, FALSE); |
|
33429
1ce1faf4e675
Extend URL parsing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33427
diff
changeset
|
1312 | } |
|
33439
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1313 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1314 | /*** HTTP Subsystem ***********************************************************/ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1315 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1316 | void purple_http_init(void) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1317 | { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1318 | purple_http_re_url = g_regex_new("^" |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1319 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1320 | "(?:" /* host part beginning */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1321 | "([a-z]+)\\:/*" /* protocol */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1322 | "([^/]+)" /* username, password, host, port */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1323 | ")?" /* host part ending */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1324 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1325 | "([^#]*)" /* path */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1326 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1327 | "(?:#" "(.*)" ")?" /* fragment */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1328 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1329 | "$", G_REGEX_OPTIMIZE | G_REGEX_CASELESS, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1330 | G_REGEX_MATCH_NOTEMPTY, NULL); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1331 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1332 | purple_http_re_url_host = g_regex_new("^" |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1333 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1334 | "(?:" /* user credentials part beginning */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1335 | "([" PURPLE_HTTP_URL_CREDENTIALS_CHARS "]+)" /* username */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1336 | "(?::([" PURPLE_HTTP_URL_CREDENTIALS_CHARS "]+))" /* password */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1337 | "@)?" /* user credentials part ending */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1338 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1339 | "([a-z0-9.-]+)" /* host */ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1340 | "(?::([0-9]+))?" /* port*/ |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1341 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1342 | "$", G_REGEX_OPTIMIZE | G_REGEX_CASELESS, |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1343 | G_REGEX_MATCH_NOTEMPTY, NULL); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1344 | } |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1345 | |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1346 | void purple_http_uninit(void) |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1347 | { |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1348 | g_regex_unref(purple_http_re_url); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1349 | purple_http_re_url = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1350 | g_regex_unref(purple_http_re_url_host); |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1351 | purple_http_re_url_host = NULL; |
|
178eb69a3f11
Handle redirects
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33438
diff
changeset
|
1352 | } |