Optimize automation-event process splitting
[ardour.git] / gtk2_ardour / ardour_http.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 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);
31         ~HttpGet ();
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         void free (void *p) const {
66                 curl_free (p);
67         }
68
69         std::string error () const;
70
71         CURL* curl () const { return _curl; }
72
73         // called from fixup_bundle_environment
74         static void setup_certificate_paths ();
75
76         private:
77         CURL* _curl;
78         bool  persist;
79
80         long int _status;
81         long int _result;
82
83         char error_buffer[CURL_ERROR_SIZE];
84
85         struct MemStruct mem;
86         struct HeaderInfo nfo;
87
88         static const char* ca_path;
89         static const char* ca_info;
90 };
91
92 char* http_get (const char* url, int* status, bool with_error_logging);
93 std::string http_get (const std::string& url, bool with_error_logging);
94
95
96
97 } // namespace
98
99 #endif /* __gtk_ardour_http_h__ */