diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-09-13 13:24:23 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-09-13 13:24:23 +0100 |
commit | 84bd17328a4dc027e689ca7b2a85744d6e2b7cf5 (patch) | |
tree | e1d2e7c0f5b26500715c8cb17a12a391afc032b8 /src/uaLookup.cpp | |
parent | 55439681e7a45489e5a77c2d6169f4b722525c96 (diff) | |
download | webstat-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/uaLookup.cpp')
-rw-r--r-- | src/uaLookup.cpp | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/src/uaLookup.cpp b/src/uaLookup.cpp index 5b31065..dbef015 100644 --- a/src/uaLookup.cpp +++ b/src/uaLookup.cpp @@ -1,44 +1,24 @@ #include "uaLookup.hpp" -#include <memory> -#include <string_view> +#include "sql.hpp" +#include <connection.h> +#include <dbTypes.h> +#include <modifycommand.h> namespace WebStat { - namespace { - size_t - stringAppend(const char * ptr, size_t size, size_t nmemb, std::string * result) - { - result->append(ptr, nmemb * size); - return nmemb * size; - } - } - - CurlOperation::CurlOperation() : hnd {curl_easy_init()}, err {} - { - curl_easy_setopt(hnd.get(), CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(hnd.get(), CURLOPT_MAXREDIRS, 50L); - curl_easy_setopt(hnd.get(), CURLOPT_TCP_KEEPALIVE, 1L); - curl_easy_setopt(hnd.get(), CURLOPT_FAILONERROR, 1L); - curl_easy_setopt(hnd.get(), CURLOPT_ERRORBUFFER, err.data()); - curl_easy_setopt(hnd.get(), CURLOPT_WRITEDATA, &result); - curl_easy_setopt(hnd.get(), CURLOPT_WRITEFUNCTION, &stringAppend); - } + UserAgentLookupOperation::UserAgentLookupOperation(Crc32Value entityId) : entityId {entityId} { } void - CurlOperation::addForm(const char * name, const std::string_view data) + UserAgentLookupOperation::whenComplete(DB::Connection * dbconn) const { - if (!mime) { - mime.reset(curl_mime_init(hnd.get())); - curl_easy_setopt(hnd.get(), CURLOPT_MIMEPOST, mime.get()); - } - auto part = curl_mime_addpart(mime.get()); - curl_mime_data(part, data.data(), data.length()); - curl_mime_name(part, name); + auto upd = dbconn->modify(SQL::ENTITY_UPDATE_DETAIL, SQL::ENTITY_UPDATE_DETAIL_OPTS); + bindMany(upd, 0, entityId, result); + upd->execute(); } std::unique_ptr<CurlOperation> - curlGetUserAgentDetail(const std::string_view uas, const char * baseUrl) + curlGetUserAgentDetail(Crc32Value entityId, const std::string_view uas, const char * baseUrl) { - auto request = std::make_unique<CurlOperation>(); + auto request = std::make_unique<UserAgentLookupOperation>(entityId); curl_easy_setopt(request->hnd.get(), CURLOPT_URL, baseUrl); curl_easy_setopt( |