Ardour  9.0-pre0-1234-gb6d8f77173
ardour_http.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include <string>
22 #include <map>
23 
24 #include "pbd/ccurl.h"
25 
26 namespace ArdourCurl {
27 
28 class HttpGet {
29 public:
30  HttpGet (bool persist = false);
32 
33  struct MemStruct {
34  MemStruct () : data (0), size (0) {}
35  char* data;
36  size_t size;
37  };
38 
39  struct HeaderInfo {
40  std::map<std::string, std::string> h;
41  };
42 
43  char* get (const char* url, bool with_error_logging = false);
44 
45  std::string get (const std::string& url, bool with_error_logging = false) {
46  char *rv = get (url.c_str (), with_error_logging);
47  return rv ? std::string (rv) : std::string ("");
48  }
49 
50  char* data () const { return mem.data; }
51  size_t data_size () const { return mem.size; }
52 
53  long int status () const { return _status; }
54 
55  std::map<std::string, std::string> header () const { return nfo.h; }
56 
57  char* escape (const char* s, int l) const {
58  return curl_easy_escape (_ccurl.curl (), s, l);
59  }
60 
61  char* unescape (const char* s, int l, int *o) const {
62  return curl_easy_unescape (_ccurl.curl (), s, l, o);
63  }
64 
65  /* this is only to be used for data returned by from
66  * \ref escape() and \ref unescape() */
67  void free (void *p) const {
68  curl_free (p);
69  }
70 
71  std::string error () const;
72 
73  CURL* curl () const { return _ccurl.curl (); }
74 
75  static void ca_setopt (CURL*);
76 
77 private:
79 
80  bool persist;
81 
82  long int _status;
83  long int _result;
84 
85  char error_buffer[CURL_ERROR_SIZE];
86 
87  struct MemStruct mem;
88  struct HeaderInfo nfo;
89 };
90 
91 char* http_get (const char* url, int* status, bool with_error_logging);
92 std::string http_get (const std::string& url, bool with_error_logging);
93 
94 } // namespace
95 
CURL * curl() const
Definition: ardour_http.h:73
char * unescape(const char *s, int l, int *o) const
Definition: ardour_http.h:61
std::string error() const
std::string get(const std::string &url, bool with_error_logging=false)
Definition: ardour_http.h:45
static void ca_setopt(CURL *)
char * get(const char *url, bool with_error_logging=false)
struct HeaderInfo nfo
Definition: ardour_http.h:88
HttpGet(bool persist=false)
std::map< std::string, std::string > header() const
Definition: ardour_http.h:55
char error_buffer[CURL_ERROR_SIZE]
Definition: ardour_http.h:85
struct MemStruct mem
Definition: ardour_http.h:87
size_t data_size() const
Definition: ardour_http.h:51
void free(void *p) const
Definition: ardour_http.h:67
char * escape(const char *s, int l) const
Definition: ardour_http.h:57
PBD::CCurl _ccurl
Definition: ardour_http.h:78
char * data() const
Definition: ardour_http.h:50
long int status() const
Definition: ardour_http.h:53
CURL * curl() const
char * http_get(const char *url, int *status, bool with_error_logging)
std::map< std::string, std::string > h
Definition: ardour_http.h:40