remove incomplete override path feature
This commit is contained in:
+10
-39
@@ -82,7 +82,6 @@ static struct options opt = {
|
|||||||
0, // extraLatency
|
0, // extraLatency
|
||||||
|
|
||||||
CONFIG_PATH, // configPath
|
CONFIG_PATH, // configPath
|
||||||
"", // overridePath
|
|
||||||
false, // scanConfig
|
false, // scanConfig
|
||||||
0, // initialScan
|
0, // initialScan
|
||||||
getenv("LANG"), // preferLanguage
|
getenv("LANG"), // preferLanguage
|
||||||
@@ -136,9 +135,6 @@ static MainLoop* s_mainLoop = nullptr;
|
|||||||
/** the path prefix (including trailing "/") for retrieving configuration files from local files (empty for HTTP). */
|
/** the path prefix (including trailing "/") for retrieving configuration files from local files (empty for HTTP). */
|
||||||
static string s_configLocalPrefix;
|
static string s_configLocalPrefix;
|
||||||
|
|
||||||
/** the path prefix (including trailing "/") for overriding configuration files from local files (empty if unset). */
|
|
||||||
static string s_configOverridePrefix;
|
|
||||||
|
|
||||||
/** the URI prefix (including trailing "/") for retrieving configuration files from HTTP (empty for local files). */
|
/** the URI prefix (including trailing "/") for retrieving configuration files from HTTP (empty for local files). */
|
||||||
static string s_configUriPrefix;
|
static string s_configUriPrefix;
|
||||||
|
|
||||||
@@ -195,7 +191,6 @@ static const struct argp_option argpoptions[] = {
|
|||||||
{nullptr, 0, nullptr, 0, "Message configuration options:", 2 },
|
{nullptr, 0, nullptr, 0, "Message configuration options:", 2 },
|
||||||
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH
|
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH
|
||||||
"]", 0 },
|
"]", 0 },
|
||||||
{"overridepath", 'o', "PATH", 0, "Read override CSV config files from PATH (local folder only) []", 0 },
|
|
||||||
{"scanconfig", 's', "ADDR", OPTION_ARG_OPTIONAL, "Pick CSV config files matching initial scan (ADDR="
|
{"scanconfig", 's', "ADDR", OPTION_ARG_OPTIONAL, "Pick CSV config files matching initial scan (ADDR="
|
||||||
"\"none\" or empty for no initial scan message, \"full\" for full scan, or a single hex address to scan, "
|
"\"none\" or empty for no initial scan message, \"full\" for full scan, or a single hex address to scan, "
|
||||||
"default is broadcast ident message). If combined with --checkconfig, you can add scan message data as "
|
"default is broadcast ident message). If combined with --checkconfig, you can add scan message data as "
|
||||||
@@ -320,13 +315,6 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
}
|
}
|
||||||
opt->configPath = arg;
|
opt->configPath = arg;
|
||||||
break;
|
break;
|
||||||
case 'o': // --overridepath=/etc/ebusd/
|
|
||||||
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
|
|
||||||
argp_error(state, "invalid overridepath");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
opt->overridePath = arg;
|
|
||||||
break;
|
|
||||||
case 's': // --scanconfig[=ADDR] (ADDR=<empty>|full|<hexaddr>)
|
case 's': // --scanconfig[=ADDR] (ADDR=<empty>|full|<hexaddr>)
|
||||||
opt->scanConfig = true;
|
opt->scanConfig = true;
|
||||||
if (opt->pollInterval == 0) {
|
if (opt->pollInterval == 0) {
|
||||||
@@ -780,11 +768,11 @@ void signalHandler(int sig) {
|
|||||||
* @return the result code.
|
* @return the result code.
|
||||||
*/
|
*/
|
||||||
static result_t collectConfigFiles(const string& relPath, const string& prefix, const string& extension,
|
static result_t collectConfigFiles(const string& relPath, const string& prefix, const string& extension,
|
||||||
bool fromOverride, vector<string>* files,
|
vector<string>* files,
|
||||||
bool ignoreAddressPrefix = false, const string& query = "",
|
bool ignoreAddressPrefix = false, const string& query = "",
|
||||||
vector<string>* dirs = nullptr, bool* hasTemplates = nullptr) {
|
vector<string>* dirs = nullptr, bool* hasTemplates = nullptr) {
|
||||||
const string relPathWithSlash = relPath.empty() ? "" : relPath + "/";
|
const string relPathWithSlash = relPath.empty() ? "" : relPath + "/";
|
||||||
if (!fromOverride && !s_configUriPrefix.empty()) {
|
if (!s_configUriPrefix.empty()) {
|
||||||
string uri = s_configUriPrefix + relPathWithSlash + "?t=" + extension.substr(1) + query;
|
string uri = s_configUriPrefix + relPathWithSlash + "?t=" + extension.substr(1) + query;
|
||||||
string names;
|
string names;
|
||||||
if (!s_configHttpClient.get(uri, "", &names)) {
|
if (!s_configHttpClient.get(uri, "", &names)) {
|
||||||
@@ -809,7 +797,7 @@ static result_t collectConfigFiles(const string& relPath, const string& prefix,
|
|||||||
}
|
}
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
const string path = (fromOverride ? s_configOverridePrefix : s_configLocalPrefix) + relPathWithSlash;
|
const string path = s_configLocalPrefix + relPathWithSlash;
|
||||||
DIR* dir = opendir(path.c_str());
|
DIR* dir = opendir(path.c_str());
|
||||||
if (dir == nullptr) {
|
if (dir == nullptr) {
|
||||||
return RESULT_ERR_NOTFOUND;
|
return RESULT_ERR_NOTFOUND;
|
||||||
@@ -918,17 +906,16 @@ static bool readTemplates(const string relPath, const string extension, bool ava
|
|||||||
* @param relPath the relative path from which to read the files (without trailing "/").
|
* @param relPath the relative path from which to read the files (without trailing "/").
|
||||||
* @param extension the filename extension of the files to read.
|
* @param extension the filename extension of the files to read.
|
||||||
* @param messages the @a MessageMap to load the messages into.
|
* @param messages the @a MessageMap to load the messages into.
|
||||||
* @param fromOverride whether to load from the override path.
|
|
||||||
* @param recursive whether to load all files recursively.
|
* @param recursive whether to load all files recursively.
|
||||||
* @param verbose whether to verbosely log problems.
|
* @param verbose whether to verbosely log problems.
|
||||||
* @param errorDescription a string in which to store the error description in case of error.
|
* @param errorDescription a string in which to store the error description in case of error.
|
||||||
* @return the result code.
|
* @return the result code.
|
||||||
*/
|
*/
|
||||||
static result_t readConfigFiles(const string& relPath, const string& extension, bool fromOverride, bool recursive,
|
static result_t readConfigFiles(const string& relPath, const string& extension, bool recursive,
|
||||||
bool verbose, string* errorDescription, MessageMap* messages) {
|
bool verbose, string* errorDescription, MessageMap* messages) {
|
||||||
vector<string> files, dirs;
|
vector<string> files, dirs;
|
||||||
bool hasTemplates = false;
|
bool hasTemplates = false;
|
||||||
result_t result = collectConfigFiles(relPath, "", extension, fromOverride, &files, false, "", &dirs, &hasTemplates);
|
result_t result = collectConfigFiles(relPath, "", extension, &files, false, "", &dirs, &hasTemplates);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -944,7 +931,7 @@ static result_t readConfigFiles(const string& relPath, const string& extension,
|
|||||||
if (recursive) {
|
if (recursive) {
|
||||||
for (const auto& name : dirs) {
|
for (const auto& name : dirs) {
|
||||||
logInfo(lf_main, "reading dir %s", name.c_str());
|
logInfo(lf_main, "reading dir %s", name.c_str());
|
||||||
result = readConfigFiles(name, extension, fromOverride, true, verbose, errorDescription, messages);
|
result = readConfigFiles(name, extension, true, verbose, errorDescription, messages);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1026,7 +1013,7 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive)
|
|||||||
s_templatesByPath.clear();
|
s_templatesByPath.clear();
|
||||||
|
|
||||||
string errorDescription;
|
string errorDescription;
|
||||||
result_t result = readConfigFiles("", ".csv", false,
|
result_t result = readConfigFiles("", ".csv",
|
||||||
(!opt.scanConfig || opt.checkConfig) && !denyRecursive, verbose, &errorDescription, messages);
|
(!opt.scanConfig || opt.checkConfig) && !denyRecursive, verbose, &errorDescription, messages);
|
||||||
if (result == RESULT_OK) {
|
if (result == RESULT_OK) {
|
||||||
logInfo(lf_main, "read config files");
|
logInfo(lf_main, "read config files");
|
||||||
@@ -1034,17 +1021,6 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive)
|
|||||||
logError(lf_main, "error reading config files from %s: %s, last error: %s", opt.configPath,
|
logError(lf_main, "error reading config files from %s: %s, last error: %s", opt.configPath,
|
||||||
getResultCode(result), errorDescription.c_str());
|
getResultCode(result), errorDescription.c_str());
|
||||||
}
|
}
|
||||||
if (s_configOverridePrefix.length() > 0) {
|
|
||||||
logInfo(lf_main, "loading override config files from %s", opt.overridePath);
|
|
||||||
result = readConfigFiles("", ".csv", true,
|
|
||||||
(!opt.scanConfig || opt.checkConfig) && !denyRecursive, verbose, &errorDescription, messages);
|
|
||||||
if (result == RESULT_OK) {
|
|
||||||
logInfo(lf_main, "read override config files");
|
|
||||||
} else {
|
|
||||||
logError(lf_main, "error reading config files from %s: %s, last error: %s", opt.overridePath,
|
|
||||||
getResultCode(result), errorDescription.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
messages->unlock();
|
messages->unlock();
|
||||||
return opt.checkConfig ? result : RESULT_OK;
|
return opt.checkConfig ? result : RESULT_OK;
|
||||||
}
|
}
|
||||||
@@ -1122,12 +1098,12 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
|||||||
string query;
|
string query;
|
||||||
if (!fromLocal) {
|
if (!fromLocal) {
|
||||||
out << "&a=" << addrStr << "&i=" << ident << "&h=" << dec << static_cast<unsigned>(hw) << "&s=" << dec
|
out << "&a=" << addrStr << "&i=" << ident << "&h=" << dec << static_cast<unsigned>(hw) << "&s=" << dec
|
||||||
<< static_cast<unsigned>(sw);;
|
<< static_cast<unsigned>(sw);
|
||||||
query = out.str();
|
query = out.str();
|
||||||
out.str("");
|
out.str("");
|
||||||
out.clear();
|
out.clear();
|
||||||
}
|
}
|
||||||
result = collectConfigFiles(manufStr, addrStr + ".", ".csv", false, &files, false, query, nullptr, &hasTemplates);
|
result = collectConfigFiles(manufStr, addrStr + ".", ".csv", &files, false, query, nullptr, &hasTemplates);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
logError(lf_main, "unable to load scan config %2.2x: list files in %s %s", address, manufStr.c_str(),
|
logError(lf_main, "unable to load scan config %2.2x: list files in %s %s", address, manufStr.c_str(),
|
||||||
getResultCode(result));
|
getResultCode(result));
|
||||||
@@ -1190,7 +1166,7 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
|
|||||||
// found the right file. load the templates if necessary, then load the file itself
|
// found the right file. load the templates if necessary, then load the file itself
|
||||||
bool readCommon = readTemplates(manufStr, ".csv", hasTemplates, opt.checkConfig);
|
bool readCommon = readTemplates(manufStr, ".csv", hasTemplates, opt.checkConfig);
|
||||||
if (readCommon) {
|
if (readCommon) {
|
||||||
result = collectConfigFiles(manufStr, "", ".csv", false, &files, true, "&a=-");
|
result = collectConfigFiles(manufStr, "", ".csv", &files, true, "&a=-");
|
||||||
if (result == RESULT_OK && !files.empty()) {
|
if (result == RESULT_OK && !files.empty()) {
|
||||||
for (const auto& name : files) {
|
for (const auto& name : files) {
|
||||||
string baseName = name.substr(manufStr.length()+1, name.length()-manufStr.length()-strlen(".csv")); // *.
|
string baseName = name.substr(manufStr.length()+1, name.length()-manufStr.length()-strlen(".csv")); // *.
|
||||||
@@ -1336,11 +1312,6 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
s_configHttpClient.disconnect();
|
s_configHttpClient.disconnect();
|
||||||
}
|
}
|
||||||
configPath = string(opt.overridePath);
|
|
||||||
if (configPath.length() > 0) {
|
|
||||||
configPath[configPath.length()-1] == '/' ? configPath : configPath + "/";
|
|
||||||
}
|
|
||||||
s_configOverridePrefix = configPath;
|
|
||||||
if (!opt.readOnly && opt.scanConfig && opt.initialScan == 0) {
|
if (!opt.readOnly && opt.scanConfig && opt.initialScan == 0) {
|
||||||
opt.initialScan = BROADCAST;
|
opt.initialScan = BROADCAST;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ struct options {
|
|||||||
unsigned int extraLatency; //!< extra transfer latency in ms [0 for USB, 10 for IP]
|
unsigned int extraLatency; //!< extra transfer latency in ms [0 for USB, 10 for IP]
|
||||||
|
|
||||||
const char* configPath; //!< path to CSV configuration files [http://cfg.ebusd.eu/]
|
const char* configPath; //!< path to CSV configuration files [http://cfg.ebusd.eu/]
|
||||||
const char* overridePath; //!< path to CSV configuration files to override the main files with
|
|
||||||
bool scanConfig; //!< pick configuration files matching initial scan
|
bool scanConfig; //!< pick configuration files matching initial scan
|
||||||
/** the initial address to scan for scanconfig
|
/** the initial address to scan for scanconfig
|
||||||
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
|
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
|
||||||
|
|||||||
Reference in New Issue
Block a user