Skip to content

Commit

Permalink
Merge pull request #46 from Telecominfraproject/dev-2.1
Browse files Browse the repository at this point in the history
Fixing uploads dir
  • Loading branch information
stephb9959 authored Aug 26, 2021
2 parents 5ae99dd + a35d3d7 commit 8172b9c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32
33
11 changes: 10 additions & 1 deletion src/FileUploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ namespace OpenWifi {

Logger_.information(l);

Path_ = Daemon()->ConfigPath("ucentral.fileuploader.path","/tmp");
Poco::File UploadsDir(Daemon()->ConfigPath("ucentral.fileuploader.path","/tmp"));
Path_ = UploadsDir.path();
if(!UploadsDir.exists()) {
try {
UploadsDir.createDirectory();
} catch (const Poco::Exception &E) {
Logger_.log(E);
Path_ = "/tmp";
}
}

auto Sock{Svr.CreateSecureSocket(Logger_)};

Expand Down
28 changes: 26 additions & 2 deletions src/RESTAPI_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ namespace OpenWifi {
}

void RESTAPIHandler::ParseParameters(Poco::Net::HTTPServerRequest &request) {

Poco::URI uri(request.getURI());
Parameters_ = uri.getQueryParameters();
InitQueryBlock();
}

static bool is_number(const std::string &s) {
Expand Down Expand Up @@ -111,6 +111,26 @@ namespace OpenWifi {
return Default;
}

bool RESTAPIHandler::HasParameter(const std::string &Name, std::string &Value) {
for (const auto &i : Parameters_) {
if (i.first == Name) {
Value = i.second;
return true;
}
}
return false;
}

bool RESTAPIHandler::HasParameter(const std::string &Name, uint64_t & Value) {
for (const auto &i : Parameters_) {
if (i.first == Name) {
Value = std::stoi(i.second);
return true;
}
}
return false;
}

const std::string &RESTAPIHandler::GetBinding(const std::string &Name, const std::string &Default) {
auto E = Bindings_.find(Poco::toLower(Name));
if (E == Bindings_.end())
Expand Down Expand Up @@ -365,6 +385,9 @@ namespace OpenWifi {
}

bool RESTAPIHandler::InitQueryBlock() {
if(QueryBlockInitialized_)
return true;
QueryBlockInitialized_=true;
QB_.SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, "");
QB_.StartDate = GetParameter(RESTAPI::Protocol::STARTDATE, 0);
QB_.EndDate = GetParameter(RESTAPI::Protocol::ENDDATE, 0);
Expand All @@ -377,7 +400,8 @@ namespace OpenWifi {
QB_.LastOnly = GetBoolParameter(RESTAPI::Protocol::LASTONLY,false);
QB_.Newest = GetBoolParameter(RESTAPI::Protocol::NEWEST,false);

if(QB_.Offset<1) return false;
if(QB_.Offset<1)
QB_.Offset=1;
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/RESTAPI_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ namespace OpenWifi {
[[nodiscard]] static std::string GetS(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, const std::string & Default="");
[[nodiscard]] static bool GetB(const char *Parameter,const Poco::JSON::Object::Ptr &Obj, bool Default=false);
[[nodiscard]] static uint64_t GetWhen(const Poco::JSON::Object::Ptr &Obj);
bool HasParameter(const std::string &QueryParameter, std::string &Value);
bool HasParameter(const std::string &QueryParameter, uint64_t & Value);

protected:
BindingMap Bindings_;
Expand All @@ -156,6 +158,7 @@ namespace OpenWifi {
std::vector<std::string> Methods_;
QueryBlock QB_;
bool Internal_=false;
bool QueryBlockInitialized_=false;
};

class RESTAPI_UnknownRequestHandler : public RESTAPIHandler {
Expand Down

0 comments on commit 8172b9c

Please sign in to comment.