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 <stdio.h>
00031 
00032 #include <string>
00033 
00034 #include <curl/curl.h>
00035 #include <curl/types.h>
00036 #include <curl/easy.h>
00037 
00038 #ifndef _rc_reader_h_
00039 #include "RCReader.h"
00040 #endif
00041 
00042 #ifndef _object_type_h
00043 #include "ObjectType.h"
00044 #endif
00045 
00046 #ifndef _http_cache_h
00047 #include "HTTPCache.h"
00048 #endif
00049 
00050 #ifndef http_response_h
00051 #include "HTTPResponse.h"
00052 #endif
00053 
00054 #ifndef _util_h
00055 #include "util.h"
00056 #endif
00057 
00058 using std::string;
00059 using std::vector;
00060 
00061 // This is defined in Connect.cc. ObjectType should be its own class.
00062 // 6/17/2002 jhrg
00063 extern ObjectType get_type(const string &value);
00064 
00077 class HTTPConnect
00078 {
00079 private:
00080     CURL *d_curl;
00081     RCReader *d_rcr;
00082     HTTPCache *d_http_cache;
00083 
00084     char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
00085 
00086     bool d_accept_deflate;
00087 
00088     string d_username;  // extracted from URL
00089     string d_password;  // extracted from URL
00090     string d_upstring;  // used to pass info into curl
00091 
00092     vector<string> d_request_headers; // Request headers
00093 
00094     void www_lib_init();
00095     long read_url(const string &url, FILE *stream, vector<string> *resp_hdrs,
00096                   const vector<string> *headers = 0);
00097     // string get_temp_file(FILE *&stream) throw(InternalErr);
00098     HTTPResponse *plain_fetch_url(const string &url);
00099     HTTPResponse *caching_fetch_url(const string &url);
00100 
00101     bool url_uses_proxy_for(const string &url) throw();
00102     bool url_uses_no_proxy_for(const string &url) throw();
00103 
00104     void extract_auth_info(string &url);
00105 
00106     // bool cond_fetch_url(const string &url, const vector<string> &headers);
00107 
00108     friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb,
00109                                        void *http_connect);
00110     friend class HTTPConnectTest;
00111     friend class ParseHeader;
00112 
00113 protected:
00119     HTTPConnect()
00120     { }
00121     HTTPConnect(const HTTPConnect &)
00122     { }
00123     HTTPConnect &operator=(const HTTPConnect &)
00124     {
00125         throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment");
00126     }
00128 
00129 public:
00130     HTTPConnect(RCReader *rcr) throw(Error, InternalErr);
00131 
00132     virtual ~HTTPConnect();
00133 
00134     void set_credentials(const string &u, const string &p);
00135     void set_accept_deflate(bool defalte);
00136 
00142     void set_cache_enabled(bool enabled)
00143     {
00144         if (d_http_cache)
00145             d_http_cache->set_cache_enabled(enabled);
00146     }
00147 
00149     bool is_cache_enabled()
00150     {
00151         return (d_http_cache) ? d_http_cache->is_cache_enabled() : false;
00152     }
00153 
00154     HTTPResponse *fetch_url(const string &url);
00155 };
00156 
00157 #endif // _httpconnect_h

Generated on Wed Jun 27 12:56:39 2007 for libdap++ by  doxygen 1.4.7