From 018a08d669c8b732a9485c5f6f54e9328b31c6f6 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sat, 23 Apr 2022 17:07:19 -0700 Subject: [PATCH] Framework update. --- build | 2 +- src/RESTAPI/RESTAPI_board_devices_handler.h | 2 +- src/RESTAPI/RESTAPI_board_handler.h | 2 +- src/RESTAPI/RESTAPI_board_list_handler.h | 2 +- src/RESTAPI/RESTAPI_board_timepoint_handler.h | 2 +- src/RESTAPI/RESTAPI_routers.cpp | 4 ++-- src/RESTObjects/RESTAPI_ProvObjects.cpp | 4 ++++ src/RESTObjects/RESTAPI_ProvObjects.h | 2 ++ src/framework/MicroService.h | 22 +++++++++---------- src/framework/ow_constants.h | 19 +++++++++------- 10 files changed, 35 insertions(+), 26 deletions(-) diff --git a/build b/build index 7003e7f..8783e30 100644 --- a/build +++ b/build @@ -1 +1 @@ -51 \ No newline at end of file +53 \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_board_devices_handler.h b/src/RESTAPI/RESTAPI_board_devices_handler.h index 3739ffc..e817dba 100644 --- a/src/RESTAPI/RESTAPI_board_devices_handler.h +++ b/src/RESTAPI/RESTAPI_board_devices_handler.h @@ -20,7 +20,7 @@ namespace OpenWifi { TransactionId, Internal){} - static const std::list PathName() { return std::list{"/api/v1/board/{id}/devices"}; }; + static auto PathName() { return std::list{"/api/v1/board/{id}/devices"}; }; private: BoardsDB & DB_=StorageService()->BoardsDB(); diff --git a/src/RESTAPI/RESTAPI_board_handler.h b/src/RESTAPI/RESTAPI_board_handler.h index dc2db35..3422ff1 100644 --- a/src/RESTAPI/RESTAPI_board_handler.h +++ b/src/RESTAPI/RESTAPI_board_handler.h @@ -23,7 +23,7 @@ namespace OpenWifi { TransactionId, Internal){} - static const std::list PathName() { return std::list{"/api/v1/board/{id}"}; }; + static auto PathName() { return std::list{"/api/v1/board/{id}"}; }; private: BoardsDB & DB_=StorageService()->BoardsDB(); diff --git a/src/RESTAPI/RESTAPI_board_list_handler.h b/src/RESTAPI/RESTAPI_board_list_handler.h index 5f516b9..cc560b0 100644 --- a/src/RESTAPI/RESTAPI_board_list_handler.h +++ b/src/RESTAPI/RESTAPI_board_list_handler.h @@ -21,7 +21,7 @@ namespace OpenWifi { TransactionId, Internal){} - static const std::list PathName() { return std::list{"/api/v1/boards"}; }; + static auto PathName() { return std::list{"/api/v1/boards"}; }; private: BoardsDB & DB_=StorageService()->BoardsDB(); diff --git a/src/RESTAPI/RESTAPI_board_timepoint_handler.h b/src/RESTAPI/RESTAPI_board_timepoint_handler.h index 693ab57..7b72c94 100644 --- a/src/RESTAPI/RESTAPI_board_timepoint_handler.h +++ b/src/RESTAPI/RESTAPI_board_timepoint_handler.h @@ -21,7 +21,7 @@ namespace OpenWifi { TransactionId, Internal){} - static const std::list PathName() { return std::list{"/api/v1/board/{id}/timepoints"}; }; + static auto PathName() { return std::list{"/api/v1/board/{id}/timepoints"}; }; private: TimePointDB & DB_=StorageService()->TimePointsDB(); diff --git a/src/RESTAPI/RESTAPI_routers.cpp b/src/RESTAPI/RESTAPI_routers.cpp index c431e19..ebe9869 100644 --- a/src/RESTAPI/RESTAPI_routers.cpp +++ b/src/RESTAPI/RESTAPI_routers.cpp @@ -10,7 +10,7 @@ namespace OpenWifi { - Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) { return RESTAPI_Router< @@ -22,7 +22,7 @@ namespace OpenWifi { >(Path,Bindings,L, S, TransactionId); } - Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) { return RESTAPI_Router_I< diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index 8969b03..6720636 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -203,6 +203,7 @@ namespace OpenWifi::ProvObjects { field_to_json( Obj,"variables",variables); field_to_json( Obj,"defaultOperator",defaultOperator); field_to_json( Obj,"sourceIP",sourceIP); + field_to_json( Obj,"registrationId",registrationId); } bool Operator::from_json(const Poco::JSON::Object::Ptr &Obj) { @@ -216,6 +217,7 @@ namespace OpenWifi::ProvObjects { field_from_json( Obj,"variables",variables); field_from_json( Obj,"defaultOperator",defaultOperator); field_from_json( Obj,"sourceIP",sourceIP); + field_from_json( Obj,"registrationId",registrationId); return true; } catch(...) { } @@ -893,6 +895,7 @@ namespace OpenWifi::ProvObjects { field_to_json( Obj,"error", error); field_to_json( Obj,"statusCode", statusCode); field_to_json( Obj,"deviceID", deviceID); + field_to_json( Obj,"registrationId",registrationId); } bool SignupEntry::from_json(const Poco::JSON::Object::Ptr &Obj) { @@ -908,6 +911,7 @@ namespace OpenWifi::ProvObjects { field_from_json( Obj,"error", error); field_from_json( Obj,"statusCode", statusCode); field_from_json( Obj,"deviceID", deviceID); + field_from_json( Obj,"registrationId",registrationId); return true; } catch(...) { diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 18711d1..091e31c 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -533,6 +533,7 @@ namespace OpenWifi::ProvObjects { uint64_t error=0; uint64_t statusCode=0; std::string deviceID; + std::string registrationId; void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); @@ -586,6 +587,7 @@ namespace OpenWifi::ProvObjects { std::vector variables; bool defaultOperator=false; Types::StringVec sourceIP; + std::string registrationId; void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index a543a83..45d104f 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -1849,7 +1849,7 @@ namespace OpenWifi { } - inline static bool ParseBindings(const std::string & Request, const std::list & EndPoints, BindingMap &bindings) { + inline static bool ParseBindings(const std::string & Request, const std::list & EndPoints, BindingMap &bindings) { bindings.clear(); std::vector PathItems = Utils::Split(Request, '/'); @@ -2889,10 +2889,10 @@ namespace OpenWifi { inline auto ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); } - Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t Id); - Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t Id); @@ -2914,8 +2914,9 @@ namespace OpenWifi { inline void reinitialize(Poco::Util::Application &self) override; - inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path, uint64_t Id) { + inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; + Poco::Thread::current()->setName(fmt::format("RESTAPI_ExtServer_{}",Id)); return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id); } @@ -2939,9 +2940,8 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { try { Poco::URI uri(Request.getURI()); - auto *Path = uri.getPath().c_str(); - Poco::Thread::current()->setName("ExtWebServer_" + std::to_string(TransactionId_)); - return RESTAPI_ExtServer()->CallServer(Path, TransactionId_++); + Poco::Thread::current()->setName(fmt::format("ExtWebServer_{}",TransactionId_)); + return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++); } catch (...) { } @@ -3047,8 +3047,9 @@ namespace OpenWifi { inline void reinitialize(Poco::Util::Application &self) override; - inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path, uint64_t Id) { + inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; + Poco::Thread::current()->setName(fmt::format("RESTAPI_IntServer_{}",Id)); return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id); } private: @@ -3070,8 +3071,7 @@ namespace OpenWifi { inline IntRequestHandlerFactory() = default; inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { Poco::URI uri(Request.getURI()); - auto *Path = uri.getPath().c_str(); - return RESTAPI_IntServer()->CallServer(Path, TransactionId_); + return RESTAPI_IntServer()->CallServer(uri.getPath(), TransactionId_); } private: static inline std::atomic_uint64_t TransactionId_ = 1; @@ -4170,7 +4170,7 @@ namespace OpenWifi { Server, TransactionId, Internal) {} - static const std::list PathName() { return std::list{"/api/v1/system"};} + static auto PathName() { return std::list{"/api/v1/system"};} inline void DoGet() { std::string Arg; diff --git a/src/framework/ow_constants.h b/src/framework/ow_constants.h index 71ec00c..7311c28 100644 --- a/src/framework/ow_constants.h +++ b/src/framework/ow_constants.h @@ -91,14 +91,17 @@ namespace OpenWifi::RESTAPI::Errors { static const std::string InvalidIPAddresses{"Invalid IP addresses."}; static const std::string InvalidBillingCode{"Empty of invalid billing code."}; static const std::string InvalidBillingPeriod{"Invalid billing period."}; - static const std::string InvalidSubscriberId{"Invalid subscriber ID"}; - static const std::string InvalidContactId{"Invalid contact ID"}; - static const std::string InvalidLocationId{"Invalid location ID"}; - static const std::string InvalidContactType{"Invalid contact type"}; - static const std::string InvalidLocationType{"Invalid location type"}; - static const std::string InvalidOperatorId{"Invalid operator ID"}; - static const std::string InvalidServiceClassId{"Invalid service class ID"}; - static const std::string InvalidSubscriberDeviceId{"Invalid subscriber device ID"}; + static const std::string InvalidSubscriberId{"Invalid subscriber ID."}; + static const std::string InvalidContactId{"Invalid contact ID."}; + static const std::string InvalidLocationId{"Invalid location ID."}; + static const std::string InvalidContactType{"Invalid contact type."}; + static const std::string InvalidLocationType{"Invalid location type."}; + static const std::string InvalidOperatorId{"Invalid operator ID."}; + static const std::string InvalidServiceClassId{"Invalid service class ID."}; + static const std::string InvalidSubscriberDeviceId{"Invalid subscriber device ID."}; + static const std::string InvalidRegistrationOperatorId{"Invalid registration operator ID."}; + static const std::string InvalidRegistrationOperatorName{"Invalid registration operator name."}; + static const std::string RegistrationNameDuplicate{"Registration name must be unique."}; } namespace OpenWifi::RESTAPI::Protocol {