libmusicbrainz5  5.1.0
HTTPFetch.h
Go to the documentation of this file.
1 /* --------------------------------------------------------------------------
2 
3  libmusicbrainz5 - Client library to access MusicBrainz
4 
5  Copyright (C) 2012 Andrew Hawkins
6 
7  This file is part of libmusicbrainz5.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  libmusicbrainz5 is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this library. If not, see <http://www.gnu.org/licenses/>.
21 
22  $Id$
23 
24 ----------------------------------------------------------------------------*/
25 
26 #ifndef _MUSICBRAINZ5_HTTP_FETCH_
27 #define _MUSICBRAINZ5_HTTP_FETCH_
28 
29 #include <string>
30 #include <vector>
31 
32 namespace MusicBrainz5
33 {
34  class CHTTPFetchPrivate;
35 
36  class CExceptionBase: public std::exception
37  {
38  public:
39  CExceptionBase(const std::string& ErrorMessage, const std::string& Exception)
40  : m_ErrorMessage(ErrorMessage),
41  m_Exception(Exception)
42  {
43  m_FullMessage=m_Exception + ": " + m_ErrorMessage;
44  }
45 
46  virtual ~CExceptionBase() throw() {};
47 
48  virtual const char* what() const throw()
49  {
50  return m_FullMessage.c_str();
51  }
52 
53  private:
54  std::string m_ErrorMessage;
55  std::string m_Exception;
56  std::string m_FullMessage;
57  };
58 
64  {
65  public:
66  CConnectionError(const std::string& ErrorMessage)
67  : CExceptionBase(ErrorMessage,"Connection error")
68  {
69  }
70  };
71 
77  {
78  public:
79  CTimeoutError(const std::string& ErrorMessage)
80  : CExceptionBase(ErrorMessage,"Timeout error")
81  {
82  }
83  };
84 
90  {
91  public:
92  CAuthenticationError(const std::string& ErrorMessage)
93  : CExceptionBase(ErrorMessage,"Authentication error")
94  {
95  }
96  };
97 
103  {
104  public:
105  CFetchError(const std::string& ErrorMessage)
106  : CExceptionBase(ErrorMessage,"Fetch error")
107  {
108  }
109  };
110 
116  {
117  public:
118  CRequestError(const std::string& ErrorMessage)
119  : CExceptionBase(ErrorMessage,"Request error")
120  {
121  }
122  };
123 
129  {
130  public:
131  CResourceNotFoundError(const std::string& ErrorMessage)
132  : CExceptionBase(ErrorMessage,"Resource not found error")
133  {
134  }
135  };
136 
144  {
145  public:
157  CHTTPFetch(const std::string& UserAgent, const std::string& Host, int Port=80);
159 
168  void SetUserName(const std::string& UserName);
169 
178  void SetPassword(const std::string& Password);
179 
188  void SetProxyHost(const std::string& ProxyHost);
189 
198  void SetProxyPort(int ProxyPort);
199 
208  void SetProxyUserName(const std::string& ProxyUserName);
209 
218  void SetProxyPassword(const std::string& ProxyPassword);
219 
238  int Fetch(const std::string& URL, const std::string& Request="GET");
239 
248  std::vector<unsigned char> Data() const;
249 
258  int Result() const;
259 
268  int Status() const;
269 
278  std::string ErrorMessage() const;
279 
280  private:
281  CHTTPFetchPrivate * const m_d;
282 
283  static int httpAuth(void *userdata, const char *realm, int attempts, char *username, char *password);
284  static int proxyAuth(void *userdata, const char *realm, int attempts, char *username, char *password);
285  static int httpResponseReader(void *userdata, const char *buf, size_t len);
286  };
287 }
288 
289 #endif
Exception thrown when an authentication error occurs.
Definition: HTTPFetch.h:90
CAuthenticationError(const std::string &ErrorMessage)
Definition: HTTPFetch.h:92
Exception thrown when an error occurs connecting to web service.
Definition: HTTPFetch.h:64
CConnectionError(const std::string &ErrorMessage)
Definition: HTTPFetch.h:66
Definition: HTTPFetch.h:37
CExceptionBase(const std::string &ErrorMessage, const std::string &Exception)
Definition: HTTPFetch.h:39
virtual ~CExceptionBase()
Definition: HTTPFetch.h:46
virtual const char * what() const
Definition: HTTPFetch.h:48
Exception thrown when an error occurs fetching data.
Definition: HTTPFetch.h:103
CFetchError(const std::string &ErrorMessage)
Definition: HTTPFetch.h:105
Object for make HTTP requests.
Definition: HTTPFetch.h:144
int Fetch(const std::string &URL, const std::string &Request="GET")
Make a request to the server.
CHTTPFetch(const std::string &UserAgent, const std::string &Host, int Port=80)
Constructor.
void SetProxyPort(int ProxyPort)
Set the proxy port to use.
void SetProxyHost(const std::string &ProxyHost)
Set the proxy server to use.
std::string ErrorMessage() const
Return the error message from the request.
void SetProxyPassword(const std::string &ProxyPassword)
Set the proxy password to use.
std::vector< unsigned char > Data() const
Get the data receieved.
void SetUserName(const std::string &UserName)
Set the user name to use.
int Result() const
libneon result code from the request
int Status() const
Status.
void SetPassword(const std::string &Password)
Set the password to use.
void SetProxyUserName(const std::string &ProxyUserName)
Set the proxy user name to use.
Exception thrown when an invalid request is made.
Definition: HTTPFetch.h:116
CRequestError(const std::string &ErrorMessage)
Definition: HTTPFetch.h:118
Exception thrown when the requested resource is not found.
Definition: HTTPFetch.h:129
CResourceNotFoundError(const std::string &ErrorMessage)
Definition: HTTPFetch.h:131
Exception thrown when a connection to the web service times out.
Definition: HTTPFetch.h:77
CTimeoutError(const std::string &ErrorMessage)
Definition: HTTPFetch.h:79
Definition: Alias.h:37