Ardour  8.12
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 #ifndef __gtk_ardour_http_h__
20 #define __gtk_ardour_http_h__
21 
22 #include <curl/curl.h>
23 #include <string>
24 #include <map>
25 
26 namespace ArdourCurl {
27 
28 class HttpGet {
29 public:
30  HttpGet (bool persist = false, bool ssl = true);
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 (_curl, s, l);
59  }
60 
61  char* unescape (const char* s, int l, int *o) const {
62  return curl_easy_unescape (_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 _curl; }
74 
75  // called from fixup_bundle_environment
76  static void setup_certificate_paths ();
77 
78  static void ca_setopt (CURL*);
79 
80 private:
81  CURL* _curl;
82  bool persist;
83 
84  long int _status;
85  long int _result;
86 
87  char error_buffer[CURL_ERROR_SIZE];
88 
89  struct MemStruct mem;
90  struct HeaderInfo nfo;
91 
92  static const char* ca_path;
93  static const char* ca_info;
94 };
95 
96 char* http_get (const char* url, int* status, bool with_error_logging);
97 std::string http_get (const std::string& url, bool with_error_logging);
98 
99 } // namespace
100 
101 #endif /* __gtk_ardour_http_h__ */
CURL * curl() const
Definition: ardour_http.h:73
static void setup_certificate_paths()
char * unescape(const char *s, int l, int *o) const
Definition: ardour_http.h:61
std::string error() const
HttpGet(bool persist=false, bool ssl=true)
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:90
static const char * ca_info
Definition: ardour_http.h:93
std::map< std::string, std::string > header() const
Definition: ardour_http.h:55
char error_buffer[CURL_ERROR_SIZE]
Definition: ardour_http.h:87
struct MemStruct mem
Definition: ardour_http.h:89
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
static const char * ca_path
Definition: ardour_http.h:92
char * data() const
Definition: ardour_http.h:50
long int status() const
Definition: ardour_http.h:53
char * http_get(const char *url, int *status, bool with_error_logging)
std::map< std::string, std::string > h
Definition: ardour_http.h:40