diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-09-05 00:14:24 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-09-05 00:14:24 +0100 |
commit | dae750d7dfa576b516ff55d6d486114b665103dc (patch) | |
tree | 9c549bc3fc6fdce01b2e8a54d5c70fbdf1d5ad02 /src/uaLookup.hpp | |
parent | 944f788a33e5c65e5ac1013500f78c0658401464 (diff) | |
download | webstat-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.hpp | 20 |
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"); } |