update the configuration

This commit is contained in:
Sven Czarnian
2021-08-17 17:30:10 +02:00
parent 627361035c
commit b1ab52d717
3 changed files with 24 additions and 34 deletions

View File

@@ -20,7 +20,9 @@ namespace aman {
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 */
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() { }
};
}

View File

@@ -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);

View File

@@ -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;
}