libmusicbrainz4  4.0.3
HTTPFetch.h
Go to the documentation of this file.
00001 /* --------------------------------------------------------------------------
00002 
00003    libmusicbrainz4 - Client library to access MusicBrainz
00004 
00005    Copyright (C) 2011 Andrew Hawkins
00006 
00007    This file is part of libmusicbrainz4.
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of v2 of the GNU Lesser General Public
00011    License as published by the Free Software Foundation.
00012 
00013    libmusicbrainz4 is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Lesser General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this library.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021      $Id$
00022 
00023 ----------------------------------------------------------------------------*/
00024 
00025 #ifndef _MUSICBRAINZ4_HTTP_FETCH_
00026 #define _MUSICBRAINZ4_HTTP_FETCH_
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 namespace MusicBrainz4
00032 {
00033         class CHTTPFetchPrivate;
00034 
00035         class CExceptionBase: public std::exception
00036         {
00037         public:
00038                 CExceptionBase(const std::string& ErrorMessage, const std::string& Exception)
00039                 :       m_ErrorMessage(ErrorMessage),
00040                         m_Exception(Exception)
00041                 {
00042                         m_FullMessage=m_Exception + ": " + m_ErrorMessage;
00043                 }
00044 
00045                 virtual ~CExceptionBase() throw() {};
00046 
00047           virtual const char* what() const throw()
00048           {
00049             return m_FullMessage.c_str();
00050           }
00051 
00052          private:
00053                 std::string m_ErrorMessage;
00054                 std::string m_Exception;
00055                 std::string m_FullMessage;
00056         };
00057 
00062         class CConnectionError: public CExceptionBase
00063         {
00064         public:
00065                         CConnectionError(const std::string& ErrorMessage)
00066                         : CExceptionBase(ErrorMessage,"Connection error")
00067                         {
00068                         }
00069         };
00070 
00075         class CTimeoutError: public CExceptionBase
00076         {
00077         public:
00078                         CTimeoutError(const std::string& ErrorMessage)
00079                         : CExceptionBase(ErrorMessage,"Timeout error")
00080                         {
00081                         }
00082         };
00083 
00088         class CAuthenticationError: public CExceptionBase
00089         {
00090         public:
00091                         CAuthenticationError(const std::string& ErrorMessage)
00092                         : CExceptionBase(ErrorMessage,"Authentication error")
00093                         {
00094                         }
00095         };
00096 
00101         class CFetchError: public CExceptionBase
00102         {
00103         public:
00104                         CFetchError(const std::string& ErrorMessage)
00105                         : CExceptionBase(ErrorMessage,"Fetch error")
00106                         {
00107                         }
00108         };
00109 
00114         class CRequestError: public CExceptionBase
00115         {
00116         public:
00117                         CRequestError(const std::string& ErrorMessage)
00118                         : CExceptionBase(ErrorMessage,"Request error")
00119                         {
00120                         }
00121         };
00122 
00127         class CResourceNotFoundError: public CExceptionBase
00128         {
00129         public:
00130                         CResourceNotFoundError(const std::string& ErrorMessage)
00131                         : CExceptionBase(ErrorMessage,"Resource not found error")
00132                         {
00133                         }
00134         };
00135 
00142         class CHTTPFetch
00143         {
00144         public:
00156                 CHTTPFetch(const std::string& UserAgent, const std::string& Host, int Port=80);
00157                 ~CHTTPFetch();
00158 
00167                 void SetUserName(const std::string& UserName);
00168 
00177                 void SetPassword(const std::string& Password);
00178 
00187                 void SetProxyHost(const std::string& ProxyHost);
00188 
00197                 void SetProxyPort(int ProxyPort);
00198 
00207                 void SetProxyUserName(const std::string& ProxyUserName);
00208 
00217                 void SetProxyPassword(const std::string& ProxyPassword);
00218 
00237                 int Fetch(const std::string& URL, const std::string& Request="GET");
00238 
00247                 std::vector<unsigned char> Data() const;
00248 
00257                 int Result() const;
00258 
00267                 int Status() const;
00268 
00277                 std::string ErrorMessage() const;
00278 
00279         private:
00280                 CHTTPFetchPrivate * const m_d;
00281 
00282                 static int httpAuth(void *userdata, const char *realm, int attempts, char *username, char *password);
00283                 static int proxyAuth(void *userdata, const char *realm, int attempts, char *username, char *password);
00284                 static int httpResponseReader(void *userdata, const char *buf, size_t len);
00285         };
00286 }
00287 
00288 #endif
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Defines