diff --git a/CMakeLists.txt b/CMakeLists.txt index eac836a..1f6390c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,6 @@ add_executable( owsec src/framework/CountryCodes.h src/framework/KafkaTopics.h src/framework/MicroService.h - src/framework/OpenWifiTypes.h src/framework/orm.h src/framework/RESTAPI_errors.h src/framework/RESTAPI_protocol.h @@ -90,7 +89,7 @@ add_executable( owsec src/storage/storage_actionLinks.cpp src/storage/storage_actionLinks.h src/storage/storage_tokens.h src/ActionLinkManager.cpp src/ActionLinkManager.h - src/ACLProcessor.h src/RESTAPI/RESTAPI_preferences.cpp src/RESTAPI/RESTAPI_preferences.h src/storage/storage_preferences.cpp src/storage/storage_preferences.h) + src/ACLProcessor.h src/RESTAPI/RESTAPI_preferences.cpp src/RESTAPI/RESTAPI_preferences.h src/storage/storage_preferences.cpp src/storage/storage_preferences.h src/framework/OpenWifiTypes.h) if(NOT SMALL_BUILD) target_link_libraries(owsec PUBLIC diff --git a/build b/build index e440e5c..7813681 100644 --- a/build +++ b/build @@ -1 +1 @@ -3 \ No newline at end of file +5 \ No newline at end of file diff --git a/src/Daemon.h b/src/Daemon.h index ee50787..30ca216 100644 --- a/src/Daemon.h +++ b/src/Daemon.h @@ -20,7 +20,6 @@ #include "Poco/Crypto/CipherFactory.h" #include "Poco/Crypto/Cipher.h" -#include "framework/OpenWifiTypes.h" #include "framework/MicroService.h" namespace OpenWifi { diff --git a/src/RESTAPI/RESTAPI_preferences.cpp b/src/RESTAPI/RESTAPI_preferences.cpp index 9467cd4..be19867 100644 --- a/src/RESTAPI/RESTAPI_preferences.cpp +++ b/src/RESTAPI/RESTAPI_preferences.cpp @@ -17,8 +17,8 @@ namespace OpenWifi { void RESTAPI_preferences::DoPut() { SecurityObjects::Preferences P; - auto RawObject = ParseStream(); + auto RawObject = ParseStream(); if(!P.from_json(RawObject)) { return BadRequest(RESTAPI::Errors::InvalidJSONDocument); } diff --git a/src/RESTObjects/RESTAPI_FMSObjects.h b/src/RESTObjects/RESTAPI_FMSObjects.h index 86dfb70..7bff3c5 100644 --- a/src/RESTObjects/RESTAPI_FMSObjects.h +++ b/src/RESTObjects/RESTAPI_FMSObjects.h @@ -9,7 +9,6 @@ #include "RESTAPI_SecurityObjects.h" -#include "framework/OpenWifiTypes.h" namespace OpenWifi::FMSObjects { diff --git a/src/RESTObjects/RESTAPI_SecurityObjects.h b/src/RESTObjects/RESTAPI_SecurityObjects.h index 4eeadc9..647eb77 100644 --- a/src/RESTObjects/RESTAPI_SecurityObjects.h +++ b/src/RESTObjects/RESTAPI_SecurityObjects.h @@ -9,8 +9,8 @@ #ifndef UCENTRAL_RESTAPI_SECURITYOBJECTS_H #define UCENTRAL_RESTAPI_SECURITYOBJECTS_H -#include "Poco/JSON/Object.h" #include "framework/OpenWifiTypes.h" +#include "Poco/JSON/Object.h" namespace OpenWifi::SecurityObjects { diff --git a/src/StorageService.h b/src/StorageService.h index 9324e3c..1fce650 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -12,7 +12,6 @@ #include "RESTObjects/RESTAPI_SecurityObjects.h" #include "framework/StorageClass.h" #include "AuthService.h" -#include "framework/OpenWifiTypes.h" #include "Poco/Timer.h" diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 5cdfd24..db9c9d7 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -6,8 +6,7 @@ // Arilia Wireless Inc. // -#ifndef OPENWIFI_MICROSERVICE_H -#define OPENWIFI_MICROSERVICE_H +#pragma once #include #include @@ -20,6 +19,7 @@ #include #include #include +#include using namespace std::chrono_literals; @@ -58,10 +58,12 @@ using namespace std::chrono_literals; #include "Poco/Net/HTTPSClientSession.h" #include "Poco/Net/NetworkInterface.h" #include "Poco/ExpireLRUCache.h" +#include "Poco/JSON/Object.h" +#include "Poco/JSON/Parser.h" +#include "Poco/StringTokenizer.h" #include "cppkafka/cppkafka.h" -#include "framework/OpenWifiTypes.h" #include "framework/KafkaTopics.h" #include "framework/RESTAPI_protocol.h" #include "framework/RESTAPI_errors.h" @@ -168,7 +170,7 @@ namespace OpenWifi::RESTAPI_utils { Obj.set(Field,S); } - inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const std::vector & S) { + inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringPairVec & S) { Poco::JSON::Array Array; for(const auto &i:S) { Poco::JSON::Object O; @@ -241,6 +243,7 @@ namespace OpenWifi::RESTAPI_utils { V = (Obj->get(Field).toString() == "true"); } + inline void field_from_json(Poco::JSON::Object::Ptr Obj, const char *Field, Types::StringPairVec &Vec) { if(Obj->isArray(Field)) { auto O = Obj->getArray(Field); @@ -3898,5 +3901,3 @@ namespace OpenWifi::CIDR { return std::all_of(cbegin(Ranges), cend(Ranges), ValidateRange); } } - -#endif // UCENTRALGW_MICROSERVICE_H diff --git a/src/framework/OpenWifiTypes.h b/src/framework/OpenWifiTypes.h index 9ae111a..c5b3804 100644 --- a/src/framework/OpenWifiTypes.h +++ b/src/framework/OpenWifiTypes.h @@ -1,105 +1,40 @@ // -// License type: BSD 3-Clause License -// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE -// -// Created by Stephane Bourque on 2021-03-04. -// Arilia Wireless Inc. +// Created by stephane bourque on 2021-11-16. // -#ifndef UCENTRALGW_UCENTRALTYPES_H -#define UCENTRALGW_UCENTRALTYPES_H +#pragma once -#include -#include #include -#include -#include #include +#include +#include +#include #include - -#include "Poco/StringTokenizer.h" -#include "Poco/JSON/Parser.h" -#include "Poco/JSON/Stringifier.h" +#include +#include namespace OpenWifi::Types { typedef std::pair StringPair; - typedef std::vector StringPairVec; + typedef std::vector StringPairVec; typedef std::queue StringPairQueue; - typedef std::vector StringVec; - typedef std::set StringSet; - typedef std::map> StringMapStringSet; - typedef std::function TopicNotifyFunction; - typedef std::list> TopicNotifyFunctionList; - typedef std::map NotifyTable; + typedef std::vector StringVec; + typedef std::set StringSet; + typedef std::map> StringMapStringSet; + typedef std::function TopicNotifyFunction; + typedef std::list> TopicNotifyFunctionList; + typedef std::map NotifyTable; typedef std::map CountedMap; typedef std::vector TagList; typedef std::string UUID_t; typedef std::vector UUIDvec_t; +} - inline void UpdateCountedMap(CountedMap &M, const std::string &S, uint64_t Increment=1) { +namespace OpenWifi { + inline void UpdateCountedMap(OpenWifi::Types::CountedMap &M, const std::string &S, uint64_t Increment=1) { auto it = M.find(S); if(it==M.end()) M[S] = Increment; else it->second += Increment; } - - inline std::string to_string( const StringVec &V) { - Poco::JSON::Array O; - for(const auto &i:V) { - O.add(i); - } - std::stringstream SS; - Poco::JSON::Stringifier::stringify(O,SS); - return SS.str(); - } - -/* - inline std::string to_string( const StringPairVec &V) { - Poco::JSON::Array O; - for(const auto &i:V) { - Poco::JSON::Array OO; - OO.add(i.first); - OO.add(i.second); - O.add(OO); - } - - std::stringstream SS; - Poco::JSON::Stringifier::stringify(O,SS); - return SS.str(); - } - - inline void from_string(const std::string &S, StringPairVec &V) { - try { - Poco::JSON::Parser P; - auto O = P.parse(S).extract(); - - for(const auto &i:*O) { - auto Inner = i.extract(); - if(Inner->size()==2) { - auto S1 = Inner->getElement(0); - auto S2 = Inner->getElement(1); - V.push_back(std::make_pair(S1,S2)); - } - } - } catch (...) { - - } - } -*/ - - inline void from_string(const std::string &S, StringVec &V) { - try { - Poco::JSON::Parser P; - auto O = P.parse(S).extract(); - - for(auto const &i:*O) { - V.push_back(i.toString()); - } - } catch (...) { - - } - } -}; - -#endif // UCENTRALGW_UCENTRALTYPES_H +} diff --git a/test_scripts/curl/cli b/test_scripts/curl/cli index 8e25bb6..bbb7a28 100755 --- a/test_scripts/curl/cli +++ b/test_scripts/curl/cli @@ -263,7 +263,8 @@ sendsms() { } setpreferences() { - payload="{ \"data\" : [ [ \"$1\" , \"$2\" ] ] }" + payload="{ \"data\" : [ { \"tag\" : \"${1}\" , \"value\" : \"${2}\" } ] }" + echo ${payload} curl ${FLAGS} -X PUT "https://${OWSEC}/api/v1/preferences" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${token}" \