Browse Source

update the configuration

Sven Czarnian 3 years ago
parent
commit
b1ab52d717

+ 10 - 6
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() { }
     };
 }

+ 0 - 3
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::uint16_t>(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);

+ 14 - 25
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;
-        }
-        else if (2 < entry.size()) {
-            for (std::size_t idx = 1; idx < entry.size() - 1; ++idx)
-                value += gsl::at(entry, idx) + "=";
-            value += entry.back();
+        if (0 == config.serverPublicIdentifier.length()) {
+            config.serverPublicIdentifier = 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;
+        else if (0 == config.clientPublicIdentifier.length()) {
+            config.clientPublicIdentifier = trimmed;
         }
-
-        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;
 }