diff --git a/build b/build index c793025..f11c82a 100644 --- a/build +++ b/build @@ -1 +1 @@ -7 \ No newline at end of file +9 \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index 9526e4a..3f76c8f 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -440,11 +440,11 @@ namespace OpenWifi::ProvObjects { return false; } - void UserList::to_json(Poco::JSON::Object &Obj) const { + void UuidList::to_json(Poco::JSON::Object &Obj) const { field_to_json(Obj, "list", list); } - bool UserList::from_json(const Poco::JSON::Object::Ptr &Obj) { + bool UuidList::from_json(const Poco::JSON::Object::Ptr &Obj) { try { field_from_json(Obj, "list", list); return true; @@ -454,14 +454,46 @@ namespace OpenWifi::ProvObjects { return false; } + void field_to_json(Poco::JSON::Object &Obj, const char * FieldName, ACLACCESS A) { + switch(A) { + case READ: Obj.set(FieldName,"read"); break; + case MODIFY: Obj.set(FieldName,"modify"); break; + case CREATE: Obj.set(FieldName,"create"); break; + case DELETE: Obj.set(FieldName,"delete"); break; + case NONE: + default: + Obj.set(FieldName,"none"); + } + } + + void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char * FieldName, ACLACCESS &A) { + if(Obj->has(FieldName)) { + auto V = Obj->getValue(FieldName); + if(V=="read") + A = READ; + else if(V=="modify") + A = MODIFY; + else if(V=="create") + A = CREATE; + else if(V=="delete") + A = DELETE; + else if(V=="none") + A = NONE; + else + throw Poco::Exception("invalid JSON"); + } + } + void ObjectACL::to_json(Poco::JSON::Object &Obj) const { - field_to_json(Obj, "users", users); + RESTAPI_utils::field_to_json(Obj, "users", users); + RESTAPI_utils::field_to_json(Obj, "roles", roles); field_to_json(Obj, "access", access); } bool ObjectACL::from_json(const Poco::JSON::Object::Ptr &Obj) { try { - field_from_json(Obj, "users", users); + RESTAPI_utils::field_from_json(Obj, "users", users); + RESTAPI_utils::field_from_json(Obj, "roles", roles); field_from_json(Obj, "access", access); return true; } catch(...) { @@ -471,12 +503,12 @@ namespace OpenWifi::ProvObjects { } void ObjectACLList::to_json(Poco::JSON::Object &Obj) const { - field_to_json(Obj, "list", list); + RESTAPI_utils::field_to_json(Obj, "list", list); } bool ObjectACLList::from_json(const Poco::JSON::Object::Ptr &Obj) { try { - field_from_json(Obj, "list", list); + RESTAPI_utils::field_from_json(Obj, "list", list); return true; } catch(...) { @@ -484,23 +516,54 @@ namespace OpenWifi::ProvObjects { return false; } + std::string to_string(VISIBILITY A) { + switch(A) { + case PUBLIC: return "public"; + case SELECT: return "select"; + case PRIVATE: + default: + return "private"; + } + } + + void field_to_json(Poco::JSON::Object &Obj, const char * FieldName, VISIBILITY A) { + Obj.set(FieldName,to_string(A)); + } + + VISIBILITY visibility_from_string(const std::string &V) { + if(V=="public") + return PUBLIC; + else if(V=="select") + return SELECT; + else if(V=="private") + return PRIVATE; + throw Poco::Exception("invalid json"); + } + + void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char * FieldName, VISIBILITY &A) { + if(Obj->has(FieldName)) { + auto V = Obj->getValue(FieldName); + A = visibility_from_string(V); + } + } + void Map::to_json(Poco::JSON::Object &Obj) const { info.to_json(Obj); - field_to_json( Obj,"data",data); - field_to_json( Obj,"entity",entity); - field_to_json( Obj,"creator",creator); + RESTAPI_utils::field_to_json( Obj,"data",data); + RESTAPI_utils::field_to_json( Obj,"entity",entity); + RESTAPI_utils::field_to_json( Obj,"creator",creator); field_to_json( Obj,"visibility",visibility); - field_to_json( Obj,"access",access); + RESTAPI_utils::field_to_json( Obj,"access",access); } bool Map::from_json(const Poco::JSON::Object::Ptr &Obj) { try { info.from_json(Obj); - field_from_json( Obj,"data",data); - field_from_json( Obj,"entity",entity); - field_from_json( Obj,"creator",creator); + RESTAPI_utils::field_from_json( Obj,"data",data); + RESTAPI_utils::field_from_json( Obj,"entity",entity); + RESTAPI_utils::field_from_json( Obj,"creator",creator); field_from_json( Obj,"visibility",visibility); - field_from_json( Obj,"access",access); + RESTAPI_utils::field_from_json( Obj,"access",access); return true; } catch(...) { @@ -509,12 +572,12 @@ namespace OpenWifi::ProvObjects { } void MapList::to_json(Poco::JSON::Object &Obj) const { - field_to_json( Obj,"list",list); + RESTAPI_utils::field_to_json( Obj,"list",list); } bool MapList::from_json(const Poco::JSON::Object::Ptr &Obj) { try { - field_from_json( Obj,"list",list); + RESTAPI_utils::field_from_json( Obj,"list",list); return true; } catch(...) { @@ -530,7 +593,7 @@ namespace OpenWifi::ProvObjects { if(I.name.empty()) return false; - if(O->has("description")) + if(O->has("description")) I.description = O->get("description").toString(); SecurityObjects::MergeNotes(O,U,I.notes); SecurityObjects::NoteInfoVec N; @@ -566,4 +629,5 @@ namespace OpenWifi::ProvObjects { return true; } -}; +} + diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 3963c23..7ee555e 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -324,16 +324,21 @@ namespace OpenWifi::ProvObjects { bool from_json(const Poco::JSON::Object::Ptr &Obj); }; - struct UserList { + struct UuidList { std::vector list; void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); }; + enum ACLACCESS { + NONE, READ, MODIFY, CREATE, DELETE + }; + struct ObjectACL { - UserList users; - std::string access; + UuidList users; + UuidList roles; + ACLACCESS access = NONE; void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); @@ -346,12 +351,19 @@ namespace OpenWifi::ProvObjects { bool from_json(const Poco::JSON::Object::Ptr &Obj); }; + enum VISIBILITY { + PUBLIC, PRIVATE, SELECT + }; + + std::string to_string(VISIBILITY A); + VISIBILITY visibility_from_string(const std::string &V); + struct Map { ObjectInfo info; std::string data; std::string entity; std::string creator; - std::string visibility; + VISIBILITY visibility = PRIVATE; ObjectACLList access; void to_json(Poco::JSON::Object &Obj) const; @@ -367,7 +379,6 @@ namespace OpenWifi::ProvObjects { bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I); bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I); - }; diff --git a/src/framework/ConfigurationValidator.h b/src/framework/ConfigurationValidator.h index 7f62313..522697c 100644 --- a/src/framework/ConfigurationValidator.h +++ b/src/framework/ConfigurationValidator.h @@ -2,8 +2,7 @@ // Created by stephane bourque on 2021-09-14. // -#ifndef OWPROV_CONFIGURATIONVALIDATOR_H -#define OWPROV_CONFIGURATIONVALIDATOR_H +#pragma once #include #include "framework/MicroService.h" @@ -43,4 +42,3 @@ namespace OpenWifi { inline bool ValidateUCentralConfiguration(const std::string &C, std::string &Error) { return ConfigurationValidator::instance()->Validate(C, Error); } } -#endif //OWPROV_CONFIGURATIONVALIDATOR_H diff --git a/src/framework/CountryCodes.h b/src/framework/CountryCodes.h index 8f33af4..92a002a 100644 --- a/src/framework/CountryCodes.h +++ b/src/framework/CountryCodes.h @@ -2,8 +2,7 @@ // Created by stephane bourque on 2021-10-08. // -#ifndef OWPROV_COUNTRYCODES_H -#define OWPROV_COUNTRYCODES_H +#pragma once #include #include @@ -270,4 +269,3 @@ namespace OpenWifi { } -#endif //OWPROV_COUNTRYCODES_H diff --git a/src/framework/KafkaTopics.h b/src/framework/KafkaTopics.h index d2b7348..393b355 100644 --- a/src/framework/KafkaTopics.h +++ b/src/framework/KafkaTopics.h @@ -5,8 +5,8 @@ // Created by Stephane Bourque on 2021-03-04. // Arilia Wireless Inc. // -#ifndef UCENTRALGW_KAFKA_TOPICS_H -#define UCENTRALGW_KAFKA_TOPICS_H + +#pragma once namespace OpenWifi::KafkaTopics { static const std::string HEALTHCHECK{"healthcheck"}; @@ -37,4 +37,3 @@ namespace OpenWifi::KafkaTopics { } } -#endif // UCENTRALGW_KAFKA_TOPICS_H diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 3b5ca09..b5f337b 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -803,6 +803,20 @@ namespace OpenWifi::Utils { return R; } + [[nodiscard]] inline std::string IntToSerialNumber(uint64_t S) { + char b[16]; + for(int i=0;i<12;++i) { + int B = (S & 0x0f); + if(B<10) + b[11-i] = B+'0'; + else + b[11-i] = B - 10 + 'a'; + S >>= 4 ; + } + b[12]=0; + return b; + } + [[nodiscard]] inline bool SerialNumberMatch(const std::string &S1, const std::string &S2, int Bits=2) { auto S1_i = SerialNumberToInt(S1); @@ -1904,7 +1918,7 @@ namespace OpenWifi { QB_.SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, ""); QB_.StartDate = GetParameter(RESTAPI::Protocol::STARTDATE, 0); QB_.EndDate = GetParameter(RESTAPI::Protocol::ENDDATE, 0); - QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 1); + QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 0); QB_.Limit = GetParameter(RESTAPI::Protocol::LIMIT, 100); QB_.Filter = GetParameter(RESTAPI::Protocol::FILTER, ""); QB_.Select = GetParameter(RESTAPI::Protocol::SELECT, ""); @@ -1916,7 +1930,7 @@ namespace OpenWifi { QB_.AdditionalInfo = GetBoolParameter(RESTAPI::Protocol::WITHEXTENDEDINFO,false); if(QB_.Offset<1) - QB_.Offset=1; + QB_.Offset=0; return true; } diff --git a/src/framework/RESTAPI_errors.h b/src/framework/RESTAPI_errors.h index 362a1a4..b203797 100644 --- a/src/framework/RESTAPI_errors.h +++ b/src/framework/RESTAPI_errors.h @@ -2,8 +2,7 @@ // Created by stephane bourque on 2021-09-12. // -#ifndef OWPROV_RESTAPI_ERRORS_H -#define OWPROV_RESTAPI_ERRORS_H +#pragma once namespace OpenWifi::RESTAPI::Errors { static const std::string MissingUUID{"Missing UUID."}; @@ -62,4 +61,3 @@ namespace OpenWifi::RESTAPI::Errors { static const std::string ExpiredToken{"Token has expired, user must login."}; } -#endif //OWPROV_RESTAPI_ERRORS_H diff --git a/src/framework/RESTAPI_protocol.h b/src/framework/RESTAPI_protocol.h index 4edf5f5..fdfe4b5 100644 --- a/src/framework/RESTAPI_protocol.h +++ b/src/framework/RESTAPI_protocol.h @@ -6,8 +6,7 @@ // Arilia Wireless Inc. // -#ifndef UCENTRALGW_RESTAPI_PROTOCOL_H -#define UCENTRALGW_RESTAPI_PROTOCOL_H +#pragma once namespace OpenWifi::RESTAPI::Protocol { static const char * CAPABILITIES = "capabilities"; @@ -136,5 +135,3 @@ namespace OpenWifi::RESTAPI::Protocol { static const char * UI = "UI"; } - -#endif // UCENTRALGW_RESTAPI_PROTOCOL_H diff --git a/src/framework/StorageClass.h b/src/framework/StorageClass.h index f42bcce..95dba62 100644 --- a/src/framework/StorageClass.h +++ b/src/framework/StorageClass.h @@ -2,8 +2,7 @@ // Created by stephane bourque on 2021-10-06. // -#ifndef OPENWIFI_STORAGE_H -#define OPENWIFI_STORAGE_H +#pragma once #include "Poco/Data/Session.h" #include "Poco/Data/SessionPool.h" @@ -54,13 +53,13 @@ namespace OpenWifi { [[nodiscard]] inline std::string ComputeRange(uint64_t From, uint64_t HowMany) { if(dbType_==sqlite) { - return " LIMIT " + std::to_string(From-1) + ", " + std::to_string(HowMany) + " "; + return " LIMIT " + std::to_string(From) + ", " + std::to_string(HowMany) + " "; } else if(dbType_==pgsql) { - return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " "; + return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " "; } else if(dbType_==mysql) { - return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " "; + return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " "; } - return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " "; + return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " "; } inline std::string ConvertParams(const std::string & S) const { @@ -165,5 +164,3 @@ namespace OpenWifi { #endif } - -#endif //OPENWIFI_STORAGE_H diff --git a/src/framework/orm.h b/src/framework/orm.h index 0c868f0..f2d1ddb 100644 --- a/src/framework/orm.h +++ b/src/framework/orm.h @@ -6,8 +6,7 @@ // Arilia Wireless Inc. // -#ifndef __OPENWIFI_ORM_H__ -#define __OPENWIFI_ORM_H__ +#pragma once #include #include @@ -755,4 +754,3 @@ namespace ORM { }; } -#endif \ No newline at end of file diff --git a/src/framework/uCentral_Protocol.h b/src/framework/uCentral_Protocol.h index 33c7558..8a6094a 100644 --- a/src/framework/uCentral_Protocol.h +++ b/src/framework/uCentral_Protocol.h @@ -5,9 +5,7 @@ // Created by Stephane Bourque on 2021-03-04. // Arilia Wireless Inc. // - -#ifndef UCENTRALGW_UCENTRALPROTOCOL_H -#define UCENTRALGW_UCENTRALPROTOCOL_H +#pragma once #include "Poco/String.h" @@ -130,5 +128,3 @@ namespace OpenWifi::uCentralProtocol { return ET_UNKNOWN; }; } - -#endif // UCENTRALGW_UCENTRALPROTOCOL_H