diff --git a/build b/build index b74e882..1758ddd 100644 --- a/build +++ b/build @@ -1 +1 @@ -31 \ No newline at end of file +32 \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_SubObjects.cpp b/src/RESTObjects/RESTAPI_SubObjects.cpp new file mode 100644 index 0000000..a42bca6 --- /dev/null +++ b/src/RESTObjects/RESTAPI_SubObjects.cpp @@ -0,0 +1,547 @@ +// +// Created by stephane bourque on 2021-10-27. +// + +#include "RESTAPI_SubObjects.h" +#include "framework/MicroService.h" + +using OpenWifi::RESTAPI_utils::field_to_json; +using OpenWifi::RESTAPI_utils::field_from_json; + + +namespace OpenWifi::SubObjects { + + void HomeDeviceMode::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "enableLEDS", enableLEDS); + field_to_json(Obj, "type", type); + field_to_json(Obj, "subnet", subnet); + field_to_json(Obj, "subnetMask", subnetMask); + field_to_json(Obj, "startIP", startIP); + field_to_json(Obj, "endIP", endIP); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + field_to_json(Obj, "subnetV6", subnetV6); + field_to_json(Obj, "subnetMaskV6", subnetMaskV6); + field_to_json(Obj, "startIPV6", startIPV6); + field_to_json(Obj, "endIPV6", endIPV6); + } + + bool HomeDeviceMode::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "enableLEDS", enableLEDS); + field_from_json(Obj, "type", type); + field_from_json(Obj, "subnet", subnet); + field_from_json(Obj, "subnetMask", subnetMask); + field_from_json(Obj, "startIP", startIP); + field_from_json(Obj, "endIP", endIP); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + field_from_json(Obj, "subnetV6", subnetV6); + field_from_json(Obj, "subnetMaskV6", subnetMaskV6); + field_from_json(Obj, "startIPV6", startIPV6); + field_from_json(Obj, "endIPV6", endIPV6); + return true; + } catch (...) { + } + return false; + } + + void IPReservation::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "nickname", nickname); + field_to_json(Obj, "ipAddress", ipAddress); + field_to_json(Obj, "macAddress", macAddress); + } + + bool IPReservation::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "nickname", nickname); + field_from_json(Obj, "ipAddress", ipAddress); + field_from_json(Obj, "macAddress", macAddress); + return true; + } catch (...) { + } + return false; + } + + void IPReservationList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "id", id); + field_to_json(Obj, "reservations", reservations); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + } + + bool IPReservationList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "id", id); + field_from_json(Obj, "reservations", reservations); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + return true; + } catch (...) { + } + return false; + } + + void DnsConfiguration::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "ISP", ISP); + field_to_json(Obj, "custom", custom); + field_to_json(Obj, "primary", primary); + field_to_json(Obj, "secondary", secondary); + field_to_json(Obj, "primaryV6", primaryV6); + field_to_json(Obj, "secondaryV6", secondaryV6); + } + + bool DnsConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "ISP", ISP); + field_from_json(Obj, "custom", custom); + field_from_json(Obj, "primary", primary); + field_from_json(Obj, "secondary", secondary); + field_from_json(Obj, "primaryV6", primaryV6); + field_from_json(Obj, "secondaryV6", secondaryV6); + return true; + } catch (...) { + } + return false; + } + + void InternetConnection::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "type", type); + field_to_json(Obj, "username", username); + field_to_json(Obj, "password", password); + field_to_json(Obj, "ipAddress", ipAddress); + field_to_json(Obj, "subnetMask", subnetMask); + field_to_json(Obj, "defaultGateway", defaultGateway); + field_to_json(Obj, "sendHostname", sendHostname); + field_to_json(Obj, "primaryDns", primaryDns); + field_to_json(Obj, "secondaryDns", secondaryDns); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + field_to_json(Obj, "ipV6Support", ipV6Support); + field_to_json(Obj, "ipAddressV6", ipAddressV6); + field_to_json(Obj, "subnetMaskV6", subnetMaskV6); + field_to_json(Obj, "defaultGatewayV6", defaultGatewayV6); + field_to_json(Obj, "primaryDnsV6", primaryDnsV6); + field_to_json(Obj, "secondaryDnsV6", secondaryDnsV6); + } + + bool InternetConnection::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "type", type); + field_from_json(Obj, "username", username); + field_from_json(Obj, "password", password); + field_from_json(Obj, "ipAddress", ipAddress); + field_from_json(Obj, "subnetMask", subnetMask); + field_from_json(Obj, "defaultGateway", defaultGateway); + field_from_json(Obj, "sendHostname", sendHostname); + field_from_json(Obj, "primaryDns", primaryDns); + field_from_json(Obj, "secondaryDns", secondaryDns); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + field_from_json(Obj, "ipV6Support", ipV6Support); + field_from_json(Obj, "ipAddressV6", ipAddressV6); + field_from_json(Obj, "subnetMaskV6", subnetMaskV6); + field_from_json(Obj, "defaultGatewayV6", defaultGatewayV6); + field_from_json(Obj, "primaryDnsV6", primaryDnsV6); + field_from_json(Obj, "secondaryDnsV6", secondaryDnsV6); + return true; + } catch (...) { + } + return false; + } + + void WifiNetwork::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "type", type); + field_to_json(Obj, "name", name); + field_to_json(Obj, "password", password); + field_to_json(Obj, "encryption", encryption); + field_to_json(Obj, "bands", bands); + } + + bool WifiNetwork::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "type", type); + field_from_json(Obj, "name", name); + field_from_json(Obj, "password", password); + field_from_json(Obj, "encryption", encryption); + field_from_json(Obj, "bands", bands); + return true; + } catch (...) { + } + return false; + } + + void WifiNetworkList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "wifiNetworks", wifiNetworks); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + } + + bool WifiNetworkList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "wifiNetworks", wifiNetworks); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + return true; + } catch (...) { + } + return false; + } + + void AccessTime::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "day", day); + field_to_json(Obj, "rangeList", rangeList); + } + + bool AccessTime::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "day", day); + field_from_json(Obj, "rangeList", rangeList); + return true; + } catch (...) { + } + return false; + } + + void AccessTimes::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "schedule", schedule); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + } + + bool AccessTimes::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "schedule", schedule); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + return true; + } catch (...) { + } + return false; + } + + void SubscriberDevice::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "name", name); + field_to_json(Obj, "description", description); + field_to_json(Obj, "macAddress", macAddress); + field_to_json(Obj, "manufacturer", manufacturer); + field_to_json(Obj, "firstContact", firstContact); + field_to_json(Obj, "lastContact", lastContact); + field_to_json(Obj, "group", group); + field_to_json(Obj, "icon", icon); + field_to_json(Obj, "suspended", suspended); + field_to_json(Obj, "ip", ip); + field_to_json(Obj, "schedule", schedule); + } + + bool SubscriberDevice::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "name", name); + field_from_json(Obj, "description", description); + field_from_json(Obj, "macAddress", macAddress); + field_from_json(Obj, "manufacturer", manufacturer); + field_from_json(Obj, "firstContact", firstContact); + field_from_json(Obj, "lastContact", lastContact); + field_from_json(Obj, "group", group); + field_from_json(Obj, "icon", icon); + field_from_json(Obj, "suspended", suspended); + field_from_json(Obj, "ip", ip); + field_from_json(Obj, "schedule", schedule); + return true; + } catch (...) { + } + return false; + } + + void SubscriberDeviceList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "devices", devices); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + } + + bool SubscriberDeviceList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "devices", devices); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + return true; + } catch (...) { + } + return false; + } + + void Association::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "name", name); + field_to_json(Obj, "ssid", ssid); + field_to_json(Obj, "macAddress", macAddress); + field_to_json(Obj, "rssi", rssi); + field_to_json(Obj, "power", power); + field_to_json(Obj, "ipv4", ipv4); + field_to_json(Obj, "ipv6", ipv6); + field_to_json(Obj, "tx", tx); + field_to_json(Obj, "rx", rx); + } + + bool Association::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "name", name); + field_from_json(Obj, "ssid", ssid); + field_from_json(Obj, "macAddress", macAddress); + field_from_json(Obj, "rssi", rssi); + field_from_json(Obj, "power", power); + field_from_json(Obj, "ipv4", ipv4); + field_from_json(Obj, "ipv6", ipv6); + field_from_json(Obj, "tx", tx); + field_from_json(Obj, "rx", rx); + return true; + } catch (...) { + } + return false; + } + + void AssociationList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "associations", associations); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + } + + bool AssociationList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "associations", associations); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + return true; + } catch (...) { + } + return false; + } + + void Client::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "macAddress", macAddress); + field_to_json(Obj, "speed", speed); + field_to_json(Obj, "mode", mode); + field_to_json(Obj, "ipv4", ipv4); + field_to_json(Obj, "ipv6", ipv6); + field_to_json(Obj, "tx", tx); + field_to_json(Obj, "rx", rx); + } + + bool Client::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "macAddress", macAddress); + field_from_json(Obj, "speed", speed); + field_from_json(Obj, "mode", mode); + field_from_json(Obj, "ipv4", ipv4); + field_from_json(Obj, "ipv6", ipv6); + field_from_json(Obj, "tx", tx); + field_from_json(Obj, "rx", rx); + return true; + } catch (...) { + } + return false; + } + + void ClientList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "clients", clients); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + } + + bool ClientList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "clients", clients); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + return true; + } catch (...) { + } + return false; + } + + void Location::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "buildingName", buildingName); + field_to_json(Obj, "addressLines", addressLines); + field_to_json(Obj, "city", city); + field_to_json(Obj, "state", state); + field_to_json(Obj, "postal", postal); + field_to_json(Obj, "country", country); + field_to_json(Obj, "phones", phones); + field_to_json(Obj, "mobiles", mobiles); + } + + bool Location::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "buildingName", buildingName); + field_from_json(Obj, "addressLines", addressLines); + field_from_json(Obj, "city", city); + field_from_json(Obj, "state", state); + field_from_json(Obj, "postal", postal); + field_from_json(Obj, "country", country); + field_from_json(Obj, "phones", phones); + field_from_json(Obj, "mobiles", mobiles); + return true; + } catch (...) { + } + return false; + } + + void RadioHE::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "multipleBSSID", multipleBSSID); + field_to_json(Obj, "ema", ema); + field_to_json(Obj, "bssColor", bssColor); + } + + bool RadioHE::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "multipleBSSID", multipleBSSID); + field_from_json(Obj, "ema", ema); + field_from_json(Obj, "bssColor", bssColor); + return true; + } catch (...) { + } + return false; + } + + void RadioRates::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "beacon", beacon); + field_to_json(Obj, "multicast", multicast); + } + + bool RadioRates::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "beacon", beacon); + field_from_json(Obj, "multicast", multicast); + return true; + } catch (...) { + } + return false; + } + + void RadioInformation::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "band", band); + field_to_json(Obj, "bandwidth", bandwidth); + field_to_json(Obj, "channel", channel); + field_to_json(Obj, "country", country); + field_to_json(Obj, "channelMode", channelMode); + field_to_json(Obj, "channelWidth", channelWidth); + field_to_json(Obj, "requireMode", requireMode); + field_to_json(Obj, "txpower", txpower); + field_to_json(Obj, "legacyRates", legacyRates); + field_to_json(Obj, "beaconInterval", beaconInterval); + field_to_json(Obj, "dtimPeriod", dtimPeriod); + field_to_json(Obj, "maximumClients", maximumClients); + field_to_json(Obj, "rates", rates); + field_to_json(Obj, "he", he); + field_to_json(Obj, "rawInfo", rawInfo); + } + + bool RadioInformation::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "band", band); + field_from_json(Obj, "bandwidth", bandwidth); + field_from_json(Obj, "channel", channel); + field_from_json(Obj, "country", country); + field_from_json(Obj, "channelMode", channelMode); + field_from_json(Obj, "channelWidth", channelWidth); + field_from_json(Obj, "requireMode", requireMode); + field_from_json(Obj, "txpower", txpower); + field_from_json(Obj, "legacyRates", legacyRates); + field_from_json(Obj, "beaconInterval", beaconInterval); + field_from_json(Obj, "dtimPeriod", dtimPeriod); + field_from_json(Obj, "maximumClients", maximumClients); + field_from_json(Obj, "rates", rates); + field_from_json(Obj, "he", he); + field_from_json(Obj, "rawInfo", rawInfo); + return true; + } catch (...) { + } + return false; + } + + void AccessPoint::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "id", id); + field_to_json(Obj, "macAddress", macAddress); + field_to_json(Obj, "name", name); + field_to_json(Obj, "deviceType", deviceType); + field_to_json(Obj, "subscriberDevices", subscriberDevices); + field_to_json(Obj, "ipReservations", ipReservations); + field_to_json(Obj, "address", address); + field_to_json(Obj, "wifiNetworks", wifiNetworks); + field_to_json(Obj, "internetConnection", internetConnection); + field_to_json(Obj, "deviceMode", deviceMode); + field_to_json(Obj, "dnsConfiguration", dnsConfiguration); + field_to_json(Obj, "radios", radios); + field_to_json(Obj, "automaticUpgrade", automaticUpgrade); + field_to_json(Obj, "configurationUUID", configurationUUID); + } + + bool AccessPoint::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "id", id); + field_from_json(Obj, "macAddress", macAddress); + field_from_json(Obj, "name", name); + field_from_json(Obj, "deviceType", deviceType); + field_from_json(Obj, "subscriberDevices", subscriberDevices); + field_from_json(Obj, "ipReservations", ipReservations); + field_from_json(Obj, "address", address); + field_from_json(Obj, "wifiNetworks", wifiNetworks); + field_from_json(Obj, "internetConnection", internetConnection); + field_from_json(Obj, "deviceMode", deviceMode); + field_from_json(Obj, "dnsConfiguration", dnsConfiguration); + field_from_json(Obj, "radios", radios); + field_from_json(Obj, "automaticUpgrade", automaticUpgrade); + field_from_json(Obj, "configurationUUID", configurationUUID); + return true; + } catch (...) { + } + return false; + } + + void AccessPointList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "list", list); + } + + bool AccessPointList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "list", list); + return true; + } catch (...) { + } + return false; + } + + void SubscriberInfo::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "id", id); + field_to_json(Obj, "userId", userId); + field_to_json(Obj, "firstName", firstName); + field_to_json(Obj, "initials", initials); + field_to_json(Obj, "lastName", lastName); + field_to_json(Obj, "phoneNumber", phoneNumber); + field_to_json(Obj, "secondaryEmail", secondaryEmail); + field_to_json(Obj, "accessPoints", accessPoints); + field_to_json(Obj, "serviceAddress", serviceAddress); + field_to_json(Obj, "billingAddress", billingAddress); + field_to_json(Obj, "created", created); + field_to_json(Obj, "modified", modified); + } + + bool SubscriberInfo::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "id", id); + field_from_json(Obj, "userId", userId); + field_from_json(Obj, "firstName", firstName); + field_from_json(Obj, "initials", initials); + field_from_json(Obj, "lastName", lastName); + field_from_json(Obj, "phoneNumber", phoneNumber); + field_from_json(Obj, "secondaryEmail", secondaryEmail); + field_from_json(Obj, "accessPoints", accessPoints); + field_from_json(Obj, "serviceAddress", serviceAddress); + field_from_json(Obj, "billingAddress", billingAddress); + field_from_json(Obj, "created", created); + field_from_json(Obj, "modified", modified); + return true; + } catch (...) { + } + return false; + } +} \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_SubObjects.h b/src/RESTObjects/RESTAPI_SubObjects.h new file mode 100644 index 0000000..b807f70 --- /dev/null +++ b/src/RESTObjects/RESTAPI_SubObjects.h @@ -0,0 +1,293 @@ +// +// Created by stephane bourque on 2021-10-27. +// + +#ifndef OWSUB_RESTAPI_SUBOBJECTS_H +#define OWSUB_RESTAPI_SUBOBJECTS_H + +#include + +#include "Poco/JSON/Object.h" + +namespace OpenWifi::SubObjects { + + struct HomeDeviceMode { + bool enableLEDS = true; + std::string type; // bridge, manual, automatic + std::string subnet; + std::string subnetMask; + std::string startIP; + std::string endIP; + uint64_t created = 0 ; + uint64_t modified = 0 ; + std::string subnetV6; + int subnetMaskV6=0; + std::string startIPV6; + std::string endIPV6; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct IPReservation { + std::string nickname; + std::string ipAddress; + std::string macAddress; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct IPReservationList { + std::string id; + std::vector reservations; + uint64_t created = 0 ; + uint64_t modified = 0 ; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct DnsConfiguration { + bool ISP=false; + bool custom=false; + std::string primary; + std::string secondary; + std::string primaryV6; + std::string secondaryV6; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct InternetConnection { + std::string type; // automatic, pppoe, manual + std::string username; + std::string password; + std::string ipAddress; + std::string subnetMask; + std::string defaultGateway; + bool sendHostname = true; + std::string primaryDns; + std::string secondaryDns; + uint64_t created=0; + uint64_t modified=0; + bool ipV6Support=false; + std::string ipAddressV6; + int subnetMaskV6=0; + std::string defaultGatewayV6; + std::string primaryDnsV6; + std::string secondaryDnsV6; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct WifiNetwork { + std::string type; // main, guest + std::string name; + std::string password; + std::string encryption; + std::vector bands; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct WifiNetworkList { + std::vector wifiNetworks; + uint64_t created=0; + uint64_t modified=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct AccessTime { + std::string day; + std::vector rangeList; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct AccessTimes { + std::vector schedule; + uint64_t created=0; + uint64_t modified=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct SubscriberDevice { + std::string name; + std::string description; + std::string macAddress; + std::string manufacturer; + uint64_t firstContact=0; + uint64_t lastContact=0; + std::string group; + std::string icon; + bool suspended=false; + std::string ip; + std::vector schedule; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct SubscriberDeviceList { + std::vector devices; + uint64_t created=0; + uint64_t modified=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct Association { + std::string name; + std::string ssid; + std::string macAddress; + int rssi=0; + int power=0; + std::string ipv4; + std::string ipv6; + uint64_t tx=0; + uint64_t rx=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct AssociationList { + std::vector associations; + uint64_t created=0; + uint64_t modified=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct Client { + std::string macAddress; + std::string speed; + std::string mode; + std::string ipv4; + std::string ipv6; + uint64_t tx=0; + uint64_t rx=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct ClientList { + std::vector clients; + uint64_t created=0; + uint64_t modified=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct Location { + std::string buildingName; + std::vector addressLines; + std::string city; + std::string state; + std::string postal; + std::string country; + std::vector phones; + std::vector mobiles; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct RadioHE { + bool multipleBSSID = false; + bool ema = false; + uint64_t bssColor = 64; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct RadioRates { + uint64_t beacon = 6000; + uint64_t multicast = 24000; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct RadioInformation { + std::string band; + uint64_t bandwidth; + uint64_t channel = 0 ; + std::string country; + std::string channelMode{"HE"}; + uint64_t channelWidth = 80; + std::string requireMode; + uint64_t txpower=0; + bool legacyRates = false; + uint64_t beaconInterval = 100; + uint64_t dtimPeriod = 2; + uint64_t maximumClients = 64; + RadioRates rates; + RadioHE he; + std::vector rawInfo; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct AccessPoint { + std::string id; + std::string macAddress; + std::string name; + std::string deviceType; + SubscriberDeviceList subscriberDevices; + IPReservationList ipReservations; + Location address; + WifiNetworkList wifiNetworks; + InternetConnection internetConnection; + HomeDeviceMode deviceMode; + DnsConfiguration dnsConfiguration; + std::vector radios; + bool automaticUpgrade = true; + std::string configurationUUID; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct AccessPointList { + std::vector list; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct SubscriberInfo { + std::string id; + std::string userId; + std::string firstName; + std::string initials; + std::string lastName; + std::string phoneNumber; + std::string secondaryEmail; + AccessPointList accessPoints; + Location serviceAddress; + Location billingAddress; + uint64_t created = 0; + uint64_t modified = 0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; +} + +#endif //OWSUB_RESTAPI_SUBOBJECTS_H diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 7f09730..40de8f6 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -239,6 +239,23 @@ namespace OpenWifi::RESTAPI_utils { Obj.set(Field,A); } + inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::Counted3DMapSII &M) { + Poco::JSON::Array A; + for(const auto &[OrgName,MonthlyNumberMap]:M) { + Poco::JSON::Object OrgObject; + OrgObject.set("tag",OrgName); + Poco::JSON::Array MonthlyArray; + for(const auto &[Month,Counter]:MonthlyNumberMap) { + Poco::JSON::Object Inner; + Inner.set("value", Month); + Inner.set("counter", Counter); + MonthlyArray.add(Inner); + } + OrgObject.set("index",MonthlyArray); + A.add(OrgObject); + } + } + template void field_to_json(Poco::JSON::Object &Obj, const char *Field, const T &V, @@ -1079,6 +1096,53 @@ namespace OpenWifi { typedef std::map ConfigurationMap_t; + template class FIFO { + public: + explicit FIFO(uint32_t Size) : Size_(Size) { + Buffer_->reserve(Size_); + } + + mutable Poco::BasicEvent Writable_; + mutable Poco::BasicEvent Readable_; + + inline bool Read(T &t) { + { + std::lock_guard M(Mutex_); + if (Write_ == Read_) { + return false; + } + + t = (*Buffer_)[Read_++]; + if (Read_ == Size_) { + Read_ = 0; + } + } + bool flag = true; + Writable_.notify(this, flag); + return true; + } + + inline bool Write(const T &t) { + { + std::lock_guard M(Mutex_); + (*Buffer_)[Write_++] = t; + if (Write_ == Size_) { + Write_ = 0; + } + } + bool flag = true; + Readable_.notify(this, flag); + return false; + } + + private: + std::mutex Mutex_; + uint32_t Size_; + uint32_t Read_=0; + uint32_t Write_=0; + std::unique_ptr> Buffer_=std::make_unique>(); + }; + template class RecordCache { public: explicit RecordCache( KeyType Record::* Q) : @@ -3552,11 +3616,51 @@ namespace OpenWifi { KafkaEnabled_ = MicroService::instance().ConfigGetBool("openwifi.kafka.enable",false); } + inline void KafkaLoggerFun(cppkafka::KafkaHandleBase & handle, int level, const std::string & facility, const std::string &messqge) { + switch ((cppkafka::LogLevel) level) { + case cppkafka::LogLevel::LogNotice: { + KafkaManager()->Logger().notice(Poco::format("kafka-log: facility: %s message: %s",facility, messqge)); + } + break; + case cppkafka::LogLevel::LogDebug: { + KafkaManager()->Logger().debug(Poco::format("kafka-log: facility: %s message: %s",facility, messqge)); + } + break; + case cppkafka::LogLevel::LogInfo: { + KafkaManager()->Logger().information(Poco::format("kafka-log: facility: %s message: %s",facility, messqge)); + } + break; + case cppkafka::LogLevel::LogWarning: { + KafkaManager()->Logger().warning(Poco::format("kafka-log: facility: %s message: %s",facility, messqge)); + } + break; + case cppkafka::LogLevel::LogAlert: + case cppkafka::LogLevel::LogCrit: { + KafkaManager()->Logger().critical(Poco::format("kafka-log: facility: %s message: %s",facility, messqge)); + } + break; + case cppkafka::LogLevel::LogErr: + case cppkafka::LogLevel::LogEmerg: + default: { + KafkaManager()->Logger().error(Poco::format("kafka-log: facility: %s message: %s",facility, messqge)); + } + break; + } + } + + inline void KafkaErrorFun(cppkafka::KafkaHandleBase & handle, int error, const std::string &reason) { + KafkaManager()->Logger().error(Poco::format("kafka-error: %d, reason: %s", error, reason)); + } + inline void KafkaProducer::run() { cppkafka::Configuration Config({ { "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") }, { "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") } }); + + Config.set_log_callback(KafkaLoggerFun); + Config.set_error_callback(KafkaErrorFun); + KafkaManager()->SystemInfoWrapper_ = R"lit({ "system" : { "id" : )lit" + std::to_string(MicroService::instance().ID()) + R"lit( , "host" : ")lit" + MicroService::instance().PrivateEndPoint() + @@ -3597,6 +3701,9 @@ namespace OpenWifi { { "enable.partition.eof", false } }); + Config.set_log_callback(KafkaLoggerFun); + Config.set_error_callback(KafkaErrorFun); + cppkafka::TopicConfiguration topic_config = { { "auto.offset.reset", "smallest" } }; diff --git a/src/framework/OpenWifiTypes.h b/src/framework/OpenWifiTypes.h index c5b3804..6e368b0 100644 --- a/src/framework/OpenWifiTypes.h +++ b/src/framework/OpenWifiTypes.h @@ -14,22 +14,24 @@ #include namespace OpenWifi::Types { - typedef std::pair StringPair; - 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::map CountedMap; - typedef std::vector TagList; - typedef std::string UUID_t; - typedef std::vector UUIDvec_t; + typedef std::pair StringPair; + 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::map CountedMap; + typedef std::vector TagList; + typedef std::string UUID_t; + typedef std::vector UUIDvec_t; + typedef std::map> Counted3DMapSII; } 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()) @@ -37,4 +39,22 @@ namespace OpenWifi { else it->second += Increment; } + + inline void UpdateCountedMap(OpenWifi::Types::Counted3DMapSII &M, const std::string &S, uint32_t Index, uint64_t Increment=1) { + auto it = M.find(S); + if(it==M.end()) { + std::map E; + E[Index] = Increment; + M[S] = E; + } + else { + std::map & IndexMap = it->second; + auto it_index = IndexMap.find(Index); + if(it_index == IndexMap.end()) { + IndexMap[Index] = Increment; + } else { + it_index->second += Increment; + } + } + } } diff --git a/src/framework/RESTAPI_errors.h b/src/framework/RESTAPI_errors.h index 061ba9a..c35f2fa 100644 --- a/src/framework/RESTAPI_errors.h +++ b/src/framework/RESTAPI_errors.h @@ -14,7 +14,7 @@ namespace OpenWifi::RESTAPI::Errors { static const std::string CouldNotBeDeleted{"Element could not be deleted."}; static const std::string NameMustBeSet{"The name property must be set."}; static const std::string ConfigBlockInvalid{"Configuration block type invalid."}; - static const std::string UnknownId{"Unknown management policy."}; + static const std::string UnknownId{"Unknown UUID."}; static const std::string InvalidDeviceTypes{"Unknown or invalid device type(s)."}; static const std::string RecordNotCreated{"Record could not be created."}; static const std::string RecordNotUpdated{"Record could not be updated."}; diff --git a/src/framework/orm.h b/src/framework/orm.h index 72e0e58..6b56371 100644 --- a/src/framework/orm.h +++ b/src/framework/orm.h @@ -615,7 +615,7 @@ namespace ORM { return false; } - bool Iterate( std::function F) { + bool Iterate( std::function F, const std::string & WhereClause = "" ) { try { uint64_t Offset=0; @@ -623,7 +623,7 @@ namespace ORM { bool Done=false; while(!Done) { std::vector Records; - if(GetRecords(Offset,Batch,Records)) { + if(GetRecords(Offset,Batch,Records, WhereClause)) { for(const auto &i:Records) { if(!F(i)) return true;