HTTPConnect.h

Go to the documentation of this file.
00001 
00002 // -*- mode: c++; c-basic-offset:4 -*-
00003 
00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00005 // Access Protocol.
00006 
00007 // Copyright (c) 2002,2003 OPeNDAP, Inc.
00008 // Author: James Gallagher <jgallagher@opendap.org>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00025 
00026 #ifndef _httpconnect_h
00027 #define _httpconnect_h
00028 
00029 
00030 #include <string>
00031 
00032 #include <curl/curl.h>
00033 #include <curl/types.h>
00034 #include <curl/easy.h>
00035 
00036 #ifndef _rc_reader_h_
00037 #include "RCReader.h"
00038 #endif
00039 
00040 #ifndef _object_type_h
00041 #include "ObjectType.h"
00042 #endif
00043 
00044 #ifndef _http_cache_h
00045 #include "HTTPCache.h"
00046 #endif
00047 
00048 #ifndef http_response_h
00049 #include "HTTPResponse.h"
00050 #endif
00051 
00052 #ifndef _util_h
00053 #include "util.h"
00054 #endif
00055 
00056 using std::string;
00057 using std::vector;
00058 
00059 namespace libdap
00060 {
00061 
00074 class HTTPConnect
00075 {
00076 private:
00077     CURL *d_curl;
00078     RCReader *d_rcr;
00079     HTTPCache *d_http_cache;
00080 
00081     char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
00082 
00083     bool d_accept_deflate;
00084 
00085     string d_username;  // extracted from URL
00086     string d_password;  // extracted from URL
00087     string d_upstring;  // used to pass info into curl
00088 
00089     vector<string> d_request_headers; // Request headers
00090 
00091     void www_lib_init();
00092     long read_url(const string &url, FILE *stream, vector<string> *resp_hdrs,
00093                   const vector<string> *headers = 0);
00094     // string get_temp_file(FILE *&stream) throw(InternalErr);
00095     HTTPResponse *plain_fetch_url(const string &url);
00096     HTTPResponse *caching_fetch_url(const string &url);
00097 
00098     bool url_uses_proxy_for(const string &url) throw();
00099     bool url_uses_no_proxy_for(const string &url) throw();
00100 
00101     void extract_auth_info(string &url);
00102 
00103     // bool cond_fetch_url(const string &url, const vector<string> &headers);
00104 
00105     friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb,
00106                                        void *http_connect);
00107     friend class HTTPConnectTest;
00108     friend class ParseHeader;
00109 
00110 protected:
00116     HTTPConnect()
00117     { }
00118     HTTPConnect(const HTTPConnect &)
00119     { }
00120     HTTPConnect &operator=(const HTTPConnect &)
00121     {
00122         throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment");
00123     }
00125 
00126 public:
00127     HTTPConnect(RCReader *rcr) throw(Error, InternalErr);
00128 
00129     virtual ~HTTPConnect();
00130 
00131     void set_credentials(const string &u, const string &p);
00132     void set_accept_deflate(bool defalte);
00133 
00139     void set_cache_enabled(bool enabled)
00140     {
00141         if (d_http_cache)
00142             d_http_cache->set_cache_enabled(enabled);
00143     }
00144 
00146     bool is_cache_enabled()
00147     {
00148         return (d_http_cache) ? d_http_cache->is_cache_enabled() : false;
00149     }
00150 
00151     HTTPResponse *fetch_url(const string &url);
00152 };
00153 
00154 } // namespace libdap
00155 
00156 #endif // _httpconnect_h

Generated on Wed Mar 5 15:27:11 2008 for libdap++ by  doxygen 1.5.4