summaryrefslogtreecommitdiff
path: root/src/uaLookup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/uaLookup.cpp')
-rw-r--r--src/uaLookup.cpp42
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(