Framework update.

This commit is contained in:
stephb9959
2022-05-12 08:50:44 -07:00
parent b30b6c00f3
commit 1b6e8f37de
4 changed files with 563 additions and 20 deletions

View File

@@ -83,7 +83,7 @@ using namespace std::chrono_literals;
#include "Poco/Environment.h"
#include "Poco/NObserver.h"
#include "Poco/Net/SocketNotification.h"
#include "Poco/Base64Decoder.h"
#include "cppkafka/cppkafka.h"
#include "framework/OpenWifiTypes.h"
@@ -1121,6 +1121,39 @@ namespace OpenWifi::Utils {
return stream.str();
}
inline bool ExtractBase64CompressedData(const std::string &CompressedData,
std::string &UnCompressedData, uint64_t compress_sz ) {
std::istringstream ifs(CompressedData);
Poco::Base64Decoder b64in(ifs);
std::ostringstream ofs;
Poco::StreamCopier::copyStream(b64in, ofs);
int factor = 20;
unsigned long MaxSize = compress_sz ? (unsigned long) (compress_sz + 5000) : (unsigned long) (ofs.str().size() * factor);
while(true) {
std::vector<uint8_t> UncompressedBuffer(MaxSize);
unsigned long FinalSize = MaxSize;
auto status = uncompress((uint8_t *)&UncompressedBuffer[0], &FinalSize,
(uint8_t *)ofs.str().c_str(), ofs.str().size());
if(status==Z_OK) {
UncompressedBuffer[FinalSize] = 0;
UnCompressedData = (char *)&UncompressedBuffer[0];
return true;
}
if(status==Z_BUF_ERROR) {
if(factor<300) {
factor+=10;
MaxSize = ofs.str().size() * factor;
continue;
} else {
return false;
}
}
return false;
}
return false;
}
}
namespace OpenWifi {
@@ -1813,31 +1846,21 @@ namespace OpenWifi {
Request = &RequestIn;
Response = &ResponseIn;
Logger_.information(fmt::format("Line: {}",__LINE__));
Poco::Thread::current()->setName("WebServerThread_" + std::to_string(TransactionId_));
Logger_.information(fmt::format("Line: {}",__LINE__));
if(Request->getContentLength()>0) {
Logger_.information(fmt::format("Line: {}",__LINE__));
if(Request->getContentType().find("application/json")!=std::string::npos) {
Logger_.information(fmt::format("Line: {}",__LINE__));
ParsedBody_ = IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>();
Logger_.information(fmt::format("Line: {}",__LINE__));
}
Logger_.information(fmt::format("Line: {}",__LINE__));
}
Logger_.information(fmt::format("Line: {}",__LINE__));
if(RateLimited_ && RESTAPI_RateLimiter()->IsRateLimited(RequestIn,MyRates_.Interval, MyRates_.MaxCalls)) {
return UnAuthorized(RESTAPI::Errors::RATE_LIMIT_EXCEEDED);
}
Logger_.information(fmt::format("Line: {}",__LINE__));
if (!ContinueProcessing())
return;
Logger_.information(fmt::format("Line: {}",__LINE__));
bool Expired=false, Contacted=false;
if (AlwaysAuthorize_ && !IsAuthorized(Expired, Contacted, SubOnlyService_)) {
if(Expired)
@@ -4366,7 +4389,7 @@ namespace OpenWifi {
Path,
Poco::Net::HTTPMessage::HTTP_1_1);
Poco::Logger::get("REST-CALLER").information(fmt::format("GET: {}", URI.toString()));
Poco::Logger::get("REST-CALLER-GET").debug(fmt::format(" {}", URI.toString()));
if(BearerToken.empty()) {
Request.add("X-API-KEY", Svc.AccessKey);
@@ -4407,7 +4430,7 @@ namespace OpenWifi {
}
catch (const Poco::Exception &E)
{
std::cerr << E.displayText() << std::endl;
Poco::Logger::get("REST-CALLER-GET").log(E);
}
return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT;
}
@@ -4418,14 +4441,13 @@ namespace OpenWifi {
for(auto const &Svc:Services) {
Poco::URI URI(Svc.PrivateEndPoint);
auto Secure = (URI.getScheme() == "https");
URI.setPath(EndPoint_);
for (const auto &qp : QueryData_)
URI.addQueryParameter(qp.first, qp.second);
Poco::Logger::get("REST-CALLER").information(fmt::format("PUT: {}", URI.toString()));
Poco::Logger::get("REST-CALLER-PUT").debug(fmt::format("{}", URI.toString()));
std::string Path(URI.getPathAndQuery());
@@ -4485,7 +4507,7 @@ namespace OpenWifi {
}
catch (const Poco::Exception &E)
{
std::cerr << E.displayText() << std::endl;
Poco::Logger::get("REST-CALLER-PUT").log(E);
}
return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT;
}
@@ -4504,7 +4526,7 @@ namespace OpenWifi {
for (const auto &qp : QueryData_)
URI.addQueryParameter(qp.first, qp.second);
Poco::Logger::get("REST-CALLER").information(fmt::format("POST: {}", URI.toString()));
Poco::Logger::get("REST-CALLER-POST").debug(fmt::format(" {}", URI.toString()));
std::string Path(URI.getPathAndQuery());
@@ -4562,7 +4584,7 @@ namespace OpenWifi {
}
catch (const Poco::Exception &E)
{
std::cerr << E.displayText() << std::endl;
Poco::Logger::get("REST-CALLER-POST").log(E);
}
return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT;
}
@@ -4580,7 +4602,7 @@ namespace OpenWifi {
for (const auto &qp : QueryData_)
URI.addQueryParameter(qp.first, qp.second);
Poco::Logger::get("REST-CALLER").information(fmt::format("DELETE: {}", URI.toString()));
Poco::Logger::get("REST-CALLER-DELETE").debug(fmt::format(" {}", URI.toString()));
std::string Path(URI.getPathAndQuery());
@@ -4614,7 +4636,7 @@ namespace OpenWifi {
}
catch (const Poco::Exception &E)
{
std::cerr << E.displayText() << std::endl;
Poco::Logger::get("REST-CALLER-DELETE").log(E);
}
return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT;
}