18 #include "pandabase.h"
26 #define OPENSSL_NO_KRB5
28 #include "httpClient.h"
31 #include "documentSpec.h"
33 #include "bioStreamPtr.h"
36 #include "pointerTo.h"
37 #include "config_downloader.h"
39 #include "openSSLWrapper.h"
40 #include "openssl/ssl.h"
41 #include "typedReferenceCount.h"
63 HTTPChannel(HTTPClient *client);
66 virtual ~HTTPChannel();
80 SC_socks_invalid_version,
81 SC_socks_no_acceptable_login_method,
83 SC_socks_no_connection,
84 SC_ssl_internal_failure,
89 SC_http_error_watermark,
91 SC_ssl_invalid_server_certificate,
92 SC_ssl_self_signed_server_certificate,
93 SC_ssl_unexpected_server,
97 SC_download_open_error,
98 SC_download_write_error,
99 SC_download_invalid_range,
102 INLINE HTTPClient *get_client()
const;
104 INLINE
bool is_valid()
const;
105 INLINE
bool is_connection_ready()
const;
107 INLINE
const URLSpec &get_url()
const;
109 INLINE HTTPEnum::HTTPVersion get_http_version()
const;
110 INLINE
const string &get_http_version_string()
const;
111 INLINE
int get_status_code()
const;
112 string get_status_string()
const;
113 INLINE
const string &get_www_realm()
const;
114 INLINE
const string &get_proxy_realm()
const;
115 INLINE
const URLSpec &get_redirect()
const;
116 string get_header_value(
const string &key)
const;
118 INLINE
int get_num_redirect_steps()
const;
119 INLINE
const URLSpec &get_redirect_step(
int n)
const;
120 MAKE_SEQ(get_redirect_steps, get_num_redirect_steps, get_redirect_step);
122 INLINE
void set_persistent_connection(
bool persistent_connection);
123 INLINE
bool get_persistent_connection()
const;
124 bool will_close_connection()
const;
126 INLINE
void set_allow_proxy(
bool allow_proxy);
127 INLINE
bool get_allow_proxy()
const;
128 INLINE
void set_proxy_tunnel(
bool proxy_tunnel);
129 INLINE
bool get_proxy_tunnel()
const;
131 INLINE
void set_connect_timeout(
double timeout_seconds);
132 INLINE
double get_connect_timeout()
const;
133 INLINE
void set_blocking_connect(
bool blocking_connect);
134 INLINE
bool get_blocking_connect()
const;
136 INLINE
void set_http_timeout(
double timeout_seconds);
137 INLINE
double get_http_timeout()
const;
139 INLINE
void set_skip_body_size(
size_t skip_body_size);
140 INLINE
size_t get_skip_body_size()
const;
141 INLINE
void set_idle_timeout(
double idle_timeout);
142 INLINE
double get_idle_timeout()
const;
144 INLINE
void set_download_throttle(
bool download_throttle);
145 INLINE
bool get_download_throttle()
const;
147 INLINE
void set_max_bytes_per_second(
double max_bytes_per_second);
148 INLINE
double get_max_bytes_per_second()
const;
150 INLINE
void set_max_updates_per_second(
double max_updates_per_second);
151 INLINE
double get_max_updates_per_second()
const;
153 INLINE
void set_expected_file_size(
size_t file_size);
154 streamsize get_file_size()
const;
155 INLINE
bool is_file_size_known()
const;
157 INLINE
size_t get_first_byte_requested()
const;
158 INLINE
size_t get_last_byte_requested()
const;
159 INLINE
size_t get_first_byte_delivered()
const;
160 INLINE
size_t get_last_byte_delivered()
const;
162 void write_headers(ostream &out)
const;
165 INLINE
void preserve_status();
167 INLINE
void clear_extra_headers();
168 INLINE
void send_extra_header(
const string &key,
const string &value);
170 BLOCKING INLINE
bool get_document(
const DocumentSpec &url);
171 BLOCKING INLINE
bool get_subdocument(
const DocumentSpec &url,
172 size_t first_byte,
size_t last_byte);
173 BLOCKING INLINE
bool get_header(
const DocumentSpec &url);
174 BLOCKING INLINE
bool post_form(
const DocumentSpec &url,
const string &body);
175 BLOCKING INLINE
bool put_document(
const DocumentSpec &url,
const string &body);
176 BLOCKING INLINE
bool delete_document(
const DocumentSpec &url);
177 BLOCKING INLINE
bool get_trace(
const DocumentSpec &url);
178 BLOCKING INLINE
bool connect_to(
const DocumentSpec &url);
179 BLOCKING INLINE
bool get_options(
const DocumentSpec &url);
181 INLINE
void begin_get_document(
const DocumentSpec &url);
182 INLINE
void begin_get_subdocument(
const DocumentSpec &url,
183 size_t first_byte,
size_t last_byte);
185 INLINE
void begin_post_form(
const DocumentSpec &url,
const string &body);
189 ISocketStream *open_read_body();
190 void close_read_body(istream *stream)
const;
192 BLOCKING
bool download_to_file(
const Filename &filename,
bool subdocument_resumes =
true);
193 BLOCKING
bool download_to_ram(
Ramfile *ramfile,
bool subdocument_resumes =
true);
194 BLOCKING
bool download_to_stream(ostream *strm,
bool subdocument_resumes =
true);
195 SocketStream *get_connection();
197 INLINE
size_t get_bytes_downloaded()
const;
198 INLINE
size_t get_bytes_requested()
const;
199 INLINE
bool is_download_complete()
const;
202 static string downcase(
const string &s);
203 void body_stream_destructs(ISocketStream *stream);
206 bool reached_done_state();
207 bool run_try_next_proxy();
208 bool run_connecting();
209 bool run_connecting_wait();
210 bool run_http_proxy_ready();
211 bool run_http_proxy_request_sent();
212 bool run_http_proxy_reading_header();
213 bool run_socks_proxy_greet();
214 bool run_socks_proxy_greet_reply();
215 bool run_socks_proxy_connect();
216 bool run_socks_proxy_connect_reply();
217 bool run_setup_ssl();
218 bool run_ssl_handshake();
220 bool run_request_sent();
221 bool run_reading_header();
222 bool run_start_direct_file_read();
223 bool run_read_header();
224 bool run_begin_body();
225 bool run_reading_body();
226 bool run_read_body();
227 bool run_read_trailer();
229 bool run_download_to_file();
230 bool run_download_to_ram();
231 bool run_download_to_stream();
233 void begin_request(HTTPEnum::Method method,
const DocumentSpec &url,
234 const string &body,
bool nonblocking,
235 size_t first_byte,
size_t last_byte);
236 void reconsider_proxy();
237 void reset_for_new_request();
239 void finished_body(
bool has_trailer);
240 bool open_download_file();
242 bool server_getline(
string &str);
243 bool server_getline_failsafe(
string &str);
244 bool server_get(
string &str,
size_t num_bytes);
245 bool server_get_failsafe(
string &str,
size_t num_bytes);
246 bool server_send(
const string &str,
bool secret);
247 bool parse_http_response(
const string &line);
248 bool parse_http_header();
249 bool parse_content_range(
const string &content_range);
253 void check_preapproved_server_certificate(X509 *cert,
bool &cert_preapproved,
254 bool &cert_name_preapproved)
const;
255 bool validate_server_name(X509 *cert);
256 static bool match_cert_name(
const string &cert_name,
const string &hostname);
257 static string get_x509_name_component(X509_NAME *name,
int nid);
260 void make_proxy_request_text();
261 void make_request_text();
264 void store_header_field(
const string &field_name,
const string &field_value);
267 static void show_send(
const string &message);
270 void reset_download_to();
271 void close_download_stream();
273 void reset_body_stream();
274 void close_connection();
276 static bool more_useful_status_code(
int a,
int b);
287 S_http_proxy_request_sent,
288 S_http_proxy_reading_header,
290 S_socks_proxy_greet_reply,
291 S_socks_proxy_connect,
292 S_socks_proxy_connect_reply,
298 S_start_direct_file_read,
310 INLINE StatusEntry();
312 string _status_string;
319 size_t _proxy_next_index;
320 StatusList _status_list;
323 PT(BioStreamPtr) _source;
324 bool _persistent_connection;
327 double _connect_timeout;
328 double _http_timeout;
329 size_t _skip_body_size;
330 double _idle_timeout;
331 bool _blocking_connect;
332 bool _download_throttle;
333 double _max_bytes_per_second;
334 double _max_updates_per_second;
335 double _seconds_per_update;
336 int _bytes_per_update;
338 bool _wanted_nonblocking;
339 string _send_extra_headers;
343 HTTPEnum::Method _method;
348 bool _proxy_serves_document;
349 bool _proxy_tunnel_now;
350 bool _server_response_has_no_body;
351 size_t _first_byte_requested;
352 size_t _last_byte_requested;
353 size_t _first_byte_delivered;
354 size_t _last_byte_delivered;
363 DownloadDest _download_dest;
364 bool _subdocument_resumes;
367 ostream *_download_to_stream;
371 HTTPEnum::HTTPVersion _http_version;
372 string _http_version_string;
373 StatusEntry _status_entry;
377 string _proxy_username;
378 PT(HTTPAuthorization) _proxy_auth;
381 string _www_username;
382 PT(HTTPAuthorization) _www_auth;
392 ResponseType _response_type;
398 size_t _expected_file_size;
400 size_t _transfer_file_size;
401 size_t _bytes_downloaded;
402 size_t _bytes_requested;
403 bool _got_expected_file_size;
405 bool _got_transfer_file_size;
415 double _started_connecting_time;
416 double _sent_request_time;
417 bool _started_download;
418 string _proxy_header;
419 string _proxy_request_text;
420 string _request_text;
423 string _current_field_name;
424 string _current_field_value;
425 ISocketStream *_body_stream;
426 bool _owns_body_stream;
430 int _last_status_code;
431 double _last_run_time;
435 double _extra_ssl_handshake_time;
439 return get_class_type();
441 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
445 static void init_type() {
446 TypedReferenceCount::init_type();
447 register_type(_type_handle,
"HTTPChannel",
448 TypedReferenceCount::get_class_type());
453 friend class ChunkedStreamBuf;
454 friend class IdentityStreamBuf;
455 friend class HTTPClient;
458 ostream &operator << (ostream &out, HTTPChannel::State state);
460 #include "httpChannel.I"
462 #endif // HAVE_OPENSSL
A container for a URL, e.g.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is our own Panda specialization on the default STL vector.
The name of a file, such as a texture file or an Egg file.
An in-memory buffer specifically designed for downloading files to memory.
A descriptor that refers to a particular version of a document.
TypeHandle is the identifier used to differentiate C++ class types.