From 84bd17328a4dc027e689ca7b2a85744d6e2b7cf5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 13 Sep 2025 13:24:23 +0100 Subject: Create and perform UA lookup curl op when new user agent is encountered --- src/uaLookup.cpp | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) (limited to 'src/uaLookup.cpp') 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 -#include +#include "sql.hpp" +#include +#include +#include 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 - 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(); + auto request = std::make_unique(entityId); curl_easy_setopt(request->hnd.get(), CURLOPT_URL, baseUrl); curl_easy_setopt( -- cgit v1.2.3