summaryrefslogtreecommitdiff
path: root/src/curlOp.hpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-09-13 13:24:23 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-09-13 13:24:23 +0100
commit84bd17328a4dc027e689ca7b2a85744d6e2b7cf5 (patch)
treee1d2e7c0f5b26500715c8cb17a12a391afc032b8 /src/curlOp.hpp
parent55439681e7a45489e5a77c2d6169f4b722525c96 (diff)
downloadwebstat-84bd17328a4dc027e689ca7b2a85744d6e2b7cf5.tar.bz2
webstat-84bd17328a4dc027e689ca7b2a85744d6e2b7cf5.tar.xz
webstat-84bd17328a4dc027e689ca7b2a85744d6e2b7cf5.zip
Create and perform UA lookup curl op when new user agent is encountered
Diffstat (limited to 'src/curlOp.hpp')
-rw-r--r--src/curlOp.hpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/curlOp.hpp b/src/curlOp.hpp
new file mode 100644
index 0000000..ce42fb4
--- /dev/null
+++ b/src/curlOp.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "util.hpp"
+#include <connection_fwd.h>
+#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>;
+ using CurlMultiPtr = std::unique_ptr<CURLM, DeleteWith<&curl_multi_cleanup>>;
+
+ class CurlOperation {
+ public:
+ CurlOperation();
+ virtual ~CurlOperation() = default;
+
+ SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(CurlOperation);
+
+ void addForm(const char * name, std::string_view data);
+
+ virtual void whenComplete(DB::Connection *) const = 0;
+ virtual void onError(DB::Connection *) const;
+
+ CurlPtr hnd;
+ CurlMimePtr mime;
+ CurlErrorBuf err;
+ std::string result;
+ };
+}