summaryrefslogtreecommitdiff
path: root/src/uaLookup.hpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-09-05 00:14:24 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-09-05 00:14:24 +0100
commitdae750d7dfa576b516ff55d6d486114b665103dc (patch)
tree9c549bc3fc6fdce01b2e8a54d5c70fbdf1d5ad02 /src/uaLookup.hpp
parent944f788a33e5c65e5ac1013500f78c0658401464 (diff)
downloadwebstat-dae750d7dfa576b516ff55d6d486114b665103dc.tar.bz2
webstat-dae750d7dfa576b516ff55d6d486114b665103dc.tar.xz
webstat-dae750d7dfa576b516ff55d6d486114b665103dc.zip
Change getUserAgentDetail to return a packaged CURL object
This will be usable with curl_multi_* instead of being a single synchronous request.
Diffstat (limited to 'src/uaLookup.hpp')
-rw-r--r--src/uaLookup.hpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/uaLookup.hpp b/src/uaLookup.hpp
index 5492f05..843283e 100644
--- a/src/uaLookup.hpp
+++ b/src/uaLookup.hpp
@@ -1,6 +1,8 @@
#pragma once
+#include "util.hpp"
#include <curl/curl.h>
+#include <memory>
#include <stdexcept>
#include <string>
@@ -12,5 +14,21 @@ namespace WebStat {
CURLcode code;
};
- std::string getUserAgentDetail(std::string_view uas, const char * baseUrl = "https://useragentstring.com");
+ 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");
}