From db083ab09ab74cce490b82295a8b70232f57e499 Mon Sep 17 00:00:00 2001 From: Dario Date: Fri, 18 Oct 2019 10:12:05 +0200 Subject: [PATCH] write elopage request into file and use it to create new account if necessary --- src/cpp/HTTPInterface/ElopageWebhook.cpp | 30 +++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cpp/HTTPInterface/ElopageWebhook.cpp b/src/cpp/HTTPInterface/ElopageWebhook.cpp index f366fc2be..a5c3301d8 100644 --- a/src/cpp/HTTPInterface/ElopageWebhook.cpp +++ b/src/cpp/HTTPInterface/ElopageWebhook.cpp @@ -24,10 +24,13 @@ using namespace Poco::Data::Keywords; void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { // simply write request to file for later lookup - ServerConfig::writeToFile(request.stream(), "elopage_webhook_requests.txt"); + //ServerConfig::writeToFile(request.stream(), "elopage_webhook_requests.txt"); + + std::istream& stream = request.stream(); + std::string completeRequest; Poco::Net::NameValueCollection elopageRequestData; int breakCount = 100; while (stream.good() && breakCount > 0) { @@ -42,6 +45,7 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: int cursor = 0; for (int i = 0; i < line.size(); i++) { char c = line.at(i); + completeRequest += c; if (c == '\n') break; if (c == '+') { c = ' '; @@ -85,6 +89,30 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: stream.good(); breakCount--; } + + // write stream result also to file + static Poco::Mutex mutex; + + mutex.lock(); + + Poco::FileOutputStream file("elopage_webhook_requests.txt", std::ios::out | std::ios::app); + + if (!file.good()) { + printf("[ElopageWebhook::handleRequest] error creating file with name: elopage_webhook_requests.txt\n"); + mutex.unlock(); + return; + } + + Poco::LocalDateTime now; + + std::string dateTimeStr = Poco::DateTimeFormatter::format(now, Poco::DateTimeFormat::ISO8601_FORMAT); + file << dateTimeStr << std::endl; + file << completeRequest << std::endl; + file << std::endl; + file.close(); + mutex.unlock(); + + UniLib::controller::TaskPtr handleElopageTask(new HandleElopageRequestTask(elopageRequestData)); handleElopageTask->scheduleTask(handleElopageTask);