00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef HTTPCLIENT_H
00020 #define HTTPCLIENT_H
00021
00022 #include "pandabase.h"
00023
00024
00025
00026
00027
00028
00029 #ifdef HAVE_SSL
00030
00031 #include "urlSpec.h"
00032 #include "httpAuthorization.h"
00033 #include "httpEnum.h"
00034 #include "pointerTo.h"
00035
00036 #include <openssl/ssl.h>
00037
00038
00039 #ifdef X509_NAME
00040 #undef X509_NAME
00041 #endif
00042
00043 class Filename;
00044 class HTTPChannel;
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 class EXPCL_PANDAEXPRESS HTTPClient {
00056 PUBLISHED:
00057 HTTPClient();
00058 HTTPClient(const HTTPClient ©);
00059 void operator = (const HTTPClient ©);
00060 ~HTTPClient();
00061
00062 INLINE void set_proxy(const URLSpec &proxy);
00063 INLINE const URLSpec &get_proxy() const;
00064
00065 void set_username(const string &server, const string &realm, const string &username);
00066 string get_username(const string &server, const string &realm) const;
00067
00068 INLINE void set_http_version(HTTPEnum::HTTPVersion version);
00069 INLINE HTTPEnum::HTTPVersion get_http_version() const;
00070 string get_http_version_string() const;
00071 static HTTPEnum::HTTPVersion parse_http_version_string(const string &version);
00072
00073 bool load_certificates(const Filename &filename);
00074
00075 enum VerifySSL {
00076 VS_no_verify,
00077 VS_no_date_check,
00078 VS_normal
00079 };
00080
00081 INLINE void set_verify_ssl(VerifySSL verify_ssl);
00082 INLINE VerifySSL get_verify_ssl() const;
00083
00084 bool add_expected_server(const string &server_attributes);
00085 void clear_expected_servers();
00086
00087 PT(HTTPChannel) make_channel(bool persistent_connection);
00088 PT(HTTPChannel) post_form(const URLSpec &url, const string &body);
00089 PT(HTTPChannel) get_document(const URLSpec &url);
00090 PT(HTTPChannel) get_header(const URLSpec &url);
00091
00092 public:
00093 SSL_CTX *get_ssl_ctx();
00094
00095 private:
00096 void add_http_username(const string &http_username);
00097 string select_username(const URLSpec &url, bool is_proxy,
00098 const string &realm) const;
00099
00100 HTTPAuthorization *select_auth(const URLSpec &url, bool is_proxy,
00101 const string &last_realm);
00102 PT(HTTPAuthorization) generate_auth(const URLSpec &url, bool is_proxy,
00103 const string &challenge);
00104
00105 static void initialize_ssl();
00106 static int load_verify_locations(SSL_CTX *ctx, const Filename &ca_file);
00107
00108 static X509_NAME *parse_x509_name(const string &source);
00109
00110 #if defined(SSL_097) && !defined(NDEBUG)
00111 static void ssl_msg_callback(int write_p, int version, int content_type,
00112 const void *buf, size_t len, SSL *ssl,
00113 void *arg);
00114 #endif
00115
00116 URLSpec _proxy;
00117 HTTPEnum::HTTPVersion _http_version;
00118 VerifySSL _verify_ssl;
00119
00120 typedef pmap<string, string> Usernames;
00121 Usernames _usernames;
00122
00123 typedef map<string, PT(HTTPAuthorization) > Realms;
00124 class Domain {
00125 public:
00126 Realms _realms;
00127 };
00128 typedef pmap<string, Domain> Domains;
00129 Domains _proxy_domains, _www_domains;
00130
00131
00132
00133 typedef pvector<X509_NAME *> ExpectedServers;
00134 ExpectedServers _expected_servers;
00135
00136 SSL_CTX *_ssl_ctx;
00137
00138 static bool _ssl_initialized;
00139 static X509_STORE *_x509_store;
00140 friend class HTTPChannel;
00141 };
00142
00143 #include "httpClient.I"
00144
00145 #endif // HAVE_SSL
00146
00147 #endif
00148