summaryrefslogtreecommitdiff
path: root/src/uaLookup.hpp
blob: 843283ebfea8e1260cd440c6cf8bd68363561c07 (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
#pragma once

#include "util.hpp"
#include <curl/curl.h>
#include <memory>
#include <stdexcept>
#include <string>

namespace WebStat {
	class CurlError : public std::runtime_error {
	public:
		explicit CurlError(CURLcode code, const char * msg) : std::runtime_error {msg}, code(code) { }

		CURLcode code;
	};

	using CurlPtr = std::unique_ptr<CURL, DeleteWith<&curl_easy_cleanup>>;
	using CurlMimePtr = std::unique_ptr<curl_mime, DeleteWith<&curl_mime_free>>;
	using CurlErrorBuf = std::array<char, CURL_ERROR_SIZE>;

	class CurlOperation {
	public:
		CurlOperation();
		void addForm(const char * name, std::string_view data);

		CurlPtr hnd;
		CurlMimePtr mime;
		CurlErrorBuf err;
		std::string result;
	};

	std::unique_ptr<CurlOperation> curlGetUserAgentDetail(
			std::string_view uas, const char * baseUrl = "https://useragentstring.com");
}