summaryrefslogtreecommitdiff
path: root/gtk2_ardour/ardour_http.h
blob: 28b4372dc83b396becd237136b9f5dff2dde3076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __gtk_ardour_http_h__
#define __gtk_ardour_http_h__

#include <curl/curl.h>
#include <string>
#include <map>

namespace ArdourCurl {

class HttpGet {
	public:
	HttpGet (bool persist = false, bool ssl = true);
	~HttpGet ();

	struct MemStruct {
		MemStruct () : data (0), size (0) {}
		char*  data;
		size_t size;
	};

	struct HeaderInfo {
		std::map<std::string, std::string> h;
	};

	char* get (const char* url, bool with_error_logging = false);

	std::string get (const std::string& url, bool with_error_logging = false) {
		char *rv = get (url.c_str (), with_error_logging);
		return rv ? std::string (rv) : std::string ("");
	}

	char* data () const { return mem.data; }
	size_t data_size () const { return mem.size; }

	long int status () const { return _status; }

	std::map<std::string, std::string> header () const { return nfo.h; }

	char* escape (const char* s, int l) const {
		return curl_easy_escape (_curl, s, l);
	}

	char* unescape (const char* s, int l, int *o) const {
		return curl_easy_unescape (_curl, s, l, o);
	}

	void free (void *p) const {
		curl_free (p);
	}

	std::string error () const;

	CURL* curl () const { return _curl; }

	// called from fixup_bundle_environment
	static void setup_certificate_paths ();

	private:
	CURL* _curl;
	bool  persist;

	long int _status;
	long int _result;

	char error_buffer[CURL_ERROR_SIZE];

	struct MemStruct mem;
	struct HeaderInfo nfo;

	static const char* ca_path;
	static const char* ca_info;
};

char* http_get (const char* url, int* status, bool with_error_logging);
std::string http_get (const std::string& url, bool with_error_logging);



} // namespace

#endif /* __gtk_ardour_http_h__ */