From 3794f321e9d5324730f0e92bf0e202d77df64837 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 6 Sep 2020 14:14:38 +0100 Subject: [PATCH] Upgrade the ini file parsing. --- NXDNGateway/Conf.cpp | 20 ++++++++++++++++++++ NXDNReflector/Conf.cpp | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/NXDNGateway/Conf.cpp b/NXDNGateway/Conf.cpp index c9cbc63..5eec9ae 100644 --- a/NXDNGateway/Conf.cpp +++ b/NXDNGateway/Conf.cpp @@ -139,6 +139,26 @@ bool CConf::read() continue; char* value = ::strtok(NULL, "\r\n"); + if (value == NULL) + continue; + + // Remove quotes from the value + size_t len = ::strlen(value); + if (len > 1U && *value == '"' && value[len - 1U] == '"') { + value[len - 1U] = '\0'; + value++; + } else { + char *p; + + // if value is not quoted, remove after # (to make comment) + if ((p = strchr(value, '#')) != NULL) + *p = '\0'; + + // remove trailing tab/space + for (p = value + strlen(value) - 1U; p >= value && (*p == '\t' || *p == ' '); p--) + *p = '\0'; + } + if (section == SECTION_GENERAL) { if (::strcmp(key, "Callsign") == 0) { // Convert the callsign to upper case diff --git a/NXDNReflector/Conf.cpp b/NXDNReflector/Conf.cpp index fac5759..59ebca9 100644 --- a/NXDNReflector/Conf.cpp +++ b/NXDNReflector/Conf.cpp @@ -104,6 +104,26 @@ bool CConf::read() continue; char* value = ::strtok(NULL, "\r\n"); + if (value == NULL) + continue; + + // Remove quotes from the value + size_t len = ::strlen(value); + if (len > 1U && *value == '"' && value[len - 1U] == '"') { + value[len - 1U] = '\0'; + value++; + } else { + char *p; + + // if value is not quoted, remove after # (to make comment) + if ((p = strchr(value, '#')) != NULL) + *p = '\0'; + + // remove trailing tab/space + for (p = value + strlen(value) - 1U; p >= value && (*p == '\t' || *p == ' '); p--) + *p = '\0'; + } + if (section == SECTION_GENERAL) { if (::strcmp(key, "Daemon") == 0) m_daemon = ::atoi(value) == 1;