From b1ab52d717573ba9dec1941e9a016156ae1f248f Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Tue, 17 Aug 2021 17:30:10 +0200 Subject: [PATCH] update the configuration --- include/aman/types/Communication.h | 16 +++++++---- src/config/CommunicationFileFormat.cpp | 3 -- src/config/IdentifierFileFormat.cpp | 39 +++++++++----------------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/include/aman/types/Communication.h b/include/aman/types/Communication.h index 72ef757..0577ace 100644 --- a/include/aman/types/Communication.h +++ b/include/aman/types/Communication.h @@ -16,11 +16,13 @@ namespace aman { * @ingroup types */ struct Communication { - bool valid; /**< Marks if the configuration is valid */ - std::string address; /**< The address of the backend */ - std::uint16_t portReporter; /**< The reported port of the backend */ - std::uint16_t portNotification; /**< The notification port of the backend */ - std::string identifier; /**< The user's identifier for the connection */ + bool valid; /**< Marks if the configuration is valid */ + std::string address; /**< The address of the backend */ + std::uint16_t portReporter; /**< The reported port of the backend */ + std::uint16_t portNotification; /**< The notification port of the backend */ + std::string serverPublicIdentifier; /**< The server's public identifier */ + std::string clientPublicIdentifier; /**< The client's public identifier */ + std::string clientPrivateIdentifier; /**< The client's private identifier */ /** * @brief Initializes an invalid configuration @@ -30,6 +32,8 @@ namespace aman { address(), portReporter(0), portNotification(0), - identifier() { } + serverPublicIdentifier(), + clientPublicIdentifier(), + clientPrivateIdentifier() { } }; } diff --git a/src/config/CommunicationFileFormat.cpp b/src/config/CommunicationFileFormat.cpp index 6ea32fd..6c7a60c 100644 --- a/src/config/CommunicationFileFormat.cpp +++ b/src/config/CommunicationFileFormat.cpp @@ -81,9 +81,6 @@ bool CommunicationFileFormat::parse(const std::string& filename, Communication& else if ("PortNotification" == gsl::at(entry, 0)) { config.portNotification = static_cast(std::atoi(gsl::at(entry, 1).c_str())); } - else if ("UID" == gsl::at(entry, 0)) { - config.identifier = gsl::at(entry, 1); - } else { this->m_errorLine = lineOffset; this->m_errorMessage = "Unknown entry: " + gsl::at(entry, 0); diff --git a/src/config/IdentifierFileFormat.cpp b/src/config/IdentifierFileFormat.cpp index 5e5e36c..98b0ff7 100644 --- a/src/config/IdentifierFileFormat.cpp +++ b/src/config/IdentifierFileFormat.cpp @@ -48,36 +48,18 @@ bool IdentifierFileFormat::parse(const std::string& filename, Communication& con if (0 == trimmed.find_first_of('#', 0)) continue; - auto entry = String::splitString(trimmed, "="); - if (2 > entry.size()) { - this->m_errorLine = lineOffset; - this->m_errorMessage = "Invalid configuration entry"; - config.valid = false; - return false; + if (0 == config.serverPublicIdentifier.length()) { + config.serverPublicIdentifier = trimmed; } - else if (2 < entry.size()) { - for (std::size_t idx = 1; idx < entry.size() - 1; ++idx) - value += gsl::at(entry, idx) + "="; - value += entry.back(); + else if (0 == config.clientPublicIdentifier.length()) { + config.clientPublicIdentifier = trimmed; } - else { - value = gsl::at(entry, 1); - } - - /* found an invalid line */ - if (0 == value.length()) { - this->m_errorLine = lineOffset; - this->m_errorMessage = "Invalid entry"; - config.valid = false; - return false; - } - - if ("UID" == gsl::at(entry, 0)) { - config.identifier = gsl::at(entry, 1); + else if (0 == config.clientPrivateIdentifier.length()) { + config.clientPrivateIdentifier = trimmed; } else { this->m_errorLine = lineOffset; - this->m_errorMessage = "Unknown entry: " + gsl::at(entry, 0); + this->m_errorMessage = "Invalid number of keys found"; config.valid = false; return false; } @@ -90,5 +72,12 @@ bool IdentifierFileFormat::parse(const std::string& filename, Communication& con return false; } + if (0 == config.serverPublicIdentifier.length() || 0 == config.clientPublicIdentifier.length() || 0 == config.clientPrivateIdentifier.length()) { + this->m_errorLine = 0; + this->m_errorMessage = "Not enough keys found"; + config.valid = false; + return false; + } + return true; }