Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/downloader/httpClient.h

Go to the documentation of this file.
00001 // Filename: httpClient.h
00002 // Created by:  drose (24Sep02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef HTTPCLIENT_H
00020 #define HTTPCLIENT_H
00021 
00022 #include "pandabase.h"
00023 
00024 // This module requires OpenSSL to compile, even if you do not intend
00025 // to use this to establish https connections; this is because it uses
00026 // the OpenSSL library to portably handle all of the socket
00027 // communications.
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 // Windows may define this macro inappropriately.
00039 #ifdef X509_NAME
00040 #undef X509_NAME
00041 #endif
00042 
00043 class Filename;
00044 class HTTPChannel;
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //       Class : HTTPClient
00048 // Description : Handles contacting an HTTP server and retrieving a
00049 //               document.  Each HTTPClient object represents a
00050 //               separate context; it is up to the programmer whether
00051 //               one HTTPClient should be used to retrieve all
00052 //               documents, or a separate one should be created each
00053 //               time.
00054 ////////////////////////////////////////////////////////////////////
00055 class EXPCL_PANDAEXPRESS HTTPClient {
00056 PUBLISHED:
00057   HTTPClient();
00058   HTTPClient(const HTTPClient &copy);
00059   void operator = (const HTTPClient &copy);
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,     // Don't care who we talk to
00077     VS_no_date_check, // Must identify certs, but old, expired certs are OK
00078     VS_normal         // Identify certs and also check expiration dates.
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   // List of allowable SSL servers to connect to.  If the list is
00132   // empty, any server is acceptable.
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   

Generated on Fri May 2 00:36:49 2003 for Panda by doxygen1.3