Ardour  9.0-pre0-582-g084a23a80d
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 <curl/curl.h>
22 #include <string>
23 #include <map>
24 
25 namespace ArdourCurl {
26 
27 class HttpGet {
28 public:
29  HttpGet (bool persist = false, bool ssl = true);
31 
32  struct MemStruct {
33  MemStruct () : data (0), size (0) {}
34  char* data;
35  size_t size;
36  };
37 
38  struct HeaderInfo {
39  std::map<std::string, std::string> h;
40  };
41 
42  char* get (const char* url, bool with_error_logging = false);
43 
44  std::string get (const std::string& url, bool with_error_logging = false) {
45  char *rv = get (url.c_str (), with_error_logging);
46  return rv ? std::string (rv) : std::string ("");
47  }
48 
49  char* data () const { return mem.data; }
50  size_t data_size () const { return mem.size; }
51 
52  long int status () const { return _status; }
53 
54  std::map<std::string, std::string> header () const { return nfo.h; }
55 
56  char* escape (const char* s, int l) const {
57  return curl_easy_escape (_curl, s, l);
58  }
59 
60  char* unescape (const char* s, int l, int *o) const {
61  return curl_easy_unescape (_curl, s, l, o);
62  }
63 
64  /* this is only to be used for data returned by from
65  * \ref escape() and \ref unescape() */
66  void free (void *p) const {
67  curl_free (p);
68  }
69 
70  std::string error () const;
71 
72  CURL* curl () const { return _curl; }
73 
74  // called from fixup_bundle_environment
75  static void setup_certificate_paths ();
76 
77  static void ca_setopt (CURL*);
78 
79 private:
80  CURL* _curl;
81  bool persist;
82 
83  long int _status;
84  long int _result;
85 
86  char error_buffer[CURL_ERROR_SIZE];
87 
88  struct MemStruct mem;
89  struct HeaderInfo nfo;
90 
91  static const char* ca_path;
92  static const char* ca_info;
93 };
94 
95 char* http_get (const char* url, int* status, bool with_error_logging);
96 std::string http_get (const std::string& url, bool with_error_logging);
97 
98 } // namespace
99 
CURL * curl() const
Definition: ardour_http.h:72
static void setup_certificate_paths()
char * unescape(const char *s, int l, int *o) const
Definition: ardour_http.h:60
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:44
static void ca_setopt(CURL *)
char * get(const char *url, bool with_error_logging=false)
struct HeaderInfo nfo
Definition: ardour_http.h:89
static const char * ca_info
Definition: ardour_http.h:92
std::map< std::string, std::string > header() const
Definition: ardour_http.h:54
char error_buffer[CURL_ERROR_SIZE]
Definition: ardour_http.h:86
struct MemStruct mem
Definition: ardour_http.h:88
size_t data_size() const
Definition: ardour_http.h:50
void free(void *p) const
Definition: ardour_http.h:66
char * escape(const char *s, int l) const
Definition: ardour_http.h:56
static const char * ca_path
Definition: ardour_http.h:91
char * data() const
Definition: ardour_http.h:49
long int status() const
Definition: ardour_http.h:52
char * http_get(const char *url, int *status, bool with_error_logging)
std::map< std::string, std::string > h
Definition: ardour_http.h:39