libmusicbrainz3  3.0.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
webservice.h
Go to the documentation of this file.
1 /*
2  * MusicBrainz -- The Internet music metadatabase
3  *
4  * Copyright (C) 2006 Lukas Lalinsky
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  *
21  */
22 
23 #ifndef __MUSICBRAINZ3_WEBSERVICE_H__
24 #define __MUSICBRAINZ3_WEBSERVICE_H__
25 
26 #include <string>
29 
30 namespace MusicBrainz
31 {
32 
40  {
41  public:
42  WebServiceError(const std::string &msg = std::string()) : Exception(msg) {}
43  };
44 
53  {
54  public:
55  ConnectionError(const std::string &msg = std::string()) : WebServiceError(msg) {}
56  };
57 
63  {
64  public:
65  TimeOutError(const std::string &msg = std::string()) : WebServiceError(msg) {}
66  };
67 
72  {
73  public:
74  ResourceNotFoundError(const std::string &msg = std::string()) : WebServiceError(msg) {}
75  };
76 
84  {
85  public:
86  AuthenticationError(const std::string &msg = std::string()) : WebServiceError(msg) {}
87  };
88 
97  {
98  public:
99  ResponseError(const std::string &msg = std::string()) : WebServiceError(msg) {}
100  };
101 
110  {
111  public:
112  RequestError(const std::string &msg = std::string()) : WebServiceError(msg) {}
113  };
114 
125  {
126  public:
127 
141  WebService(const std::string &host = "musicbrainz.org",
142  const int port = 80,
143  const std::string &pathPrefix = "/ws",
144  const std::string &username = std::string(),
145  const std::string &password = std::string(),
146  const std::string &realm = "musicbrainz.org");
147 
151  virtual ~WebService();
152 
158  void setHost(const std::string &host);
159 
165  std::string getHost() const;
166 
172  void setPort(const int port);
173 
179  int getPort() const;
180 
186  void setPathPrefix(const std::string &pathPrefix);
187 
193  std::string getPathPrefix() const;
194 
200  void setUserName(const std::string &username);
201 
207  std::string getUserName() const;
208 
214  void setPassword(const std::string &password);
215 
221  std::string getPassword() const;
222 
228  void setRealm(const std::string &realm);
229 
235  std::string getRealm() const;
236 
242  void setProxyHost(const std::string &host);
243 
249  std::string getProxyHost() const;
250 
256  void setProxyPort(const int port);
257 
263  int getProxyPort() const;
264 
270  void setProxyUserName(const std::string &username);
271 
277  std::string getProxyUserName() const;
278 
284  void setProxyPassword(const std::string &password);
285 
291  std::string getProxyPassword() const;
292 
308  std::string get(const std::string &entity,
309  const std::string &id,
310  const IIncludes::IncludeList &include,
311  const IFilter::ParameterList &filter,
312  const std::string &version = "1");
313 
328  void post(const std::string &entity,
329  const std::string &id,
330  const std::string &data,
331  const std::string &version = "1");
332 
333  private:
334 
335  static int httpAuth(void *userdata, const char *realm, int attempts,
336  char *username, char *password);
337  static int proxyAuth(void *userdata, const char *realm, int attempts,
338  char *username, char *password);
339  static int httpResponseReader(void *userdata, const char *buf, size_t len);
340 
341  class WebServicePrivate;
342  WebServicePrivate *d;
343  };
344 
345 }
346 
347 #endif
WebServiceError(const std::string &msg=std::string())
Definition: webservice.h:42
std::vector< std::string > IncludeList
Definition: includes.h:39
RequestError(const std::string &msg=std::string())
Definition: webservice.h:112
std::vector< std::pair< std::string, std::string > > ParameterList
Definition: filters.h:43
TimeOutError(const std::string &msg=std::string())
Definition: webservice.h:65
An interface to the MusicBrainz XML web service via HTTP.
Definition: webservice.h:124
Definition: musicbrainz.h:34
ResponseError(const std::string &msg=std::string())
Definition: webservice.h:99
No resource with the given ID exists.
Definition: webservice.h:71
A web service error has occurred.
Definition: webservice.h:39
Connection to a server timed out.
Definition: webservice.h:62
An interface all concrete web service classes have to implement.
Definition: iwebservice.h:40
An invalid request was made.
Definition: webservice.h:109
AuthenticationError(const std::string &msg=std::string())
Definition: webservice.h:86
Authentication failed.
Definition: webservice.h:83
Getting a server connection failed.
Definition: webservice.h:52
#define MB_API
Definition: defines.h:40
ConnectionError(const std::string &msg=std::string())
Definition: webservice.h:55
ResourceNotFoundError(const std::string &msg=std::string())
Definition: webservice.h:74
The returned resource was invalid.
Definition: webservice.h:96