diff --git a/src/Listen.cxx b/src/Listen.cxx index 0f620325b..6110c0dfc 100644 --- a/src/Listen.cxx +++ b/src/Listen.cxx @@ -68,7 +68,7 @@ listen_add_config_param(unsigned int port, if (0 == strcmp(param->value.c_str(), "any")) { return listen_socket->AddPort(port, error_r); } else if (param->value[0] == '/' || param->value[0] == '~') { - auto path = config_parse_path(param, error_r); + auto path = param->GetPath(error_r); return !path.IsNull() && listen_socket->AddPath(std::move(path), error_r); } else { diff --git a/src/config/ConfigGlobal.cxx b/src/config/ConfigGlobal.cxx index 05290024b..017354d14 100644 --- a/src/config/ConfigGlobal.cxx +++ b/src/config/ConfigGlobal.cxx @@ -128,18 +128,7 @@ config_get_path(ConfigOption option, Error &error) if (param == nullptr) return AllocatedPath::Null(); - return config_parse_path(param, error); -} - -AllocatedPath -config_parse_path(const ConfigParam *param, Error & error) -{ - AllocatedPath path = ParsePath(param->value.c_str(), error); - if (gcc_unlikely(path.IsNull())) - error.FormatPrefix("Invalid path at line %i: ", - param->line); - - return path; + return param->GetPath(error); } unsigned diff --git a/src/config/ConfigGlobal.hxx b/src/config/ConfigGlobal.hxx index 5d97302a3..bd64452fc 100644 --- a/src/config/ConfigGlobal.hxx +++ b/src/config/ConfigGlobal.hxx @@ -84,14 +84,6 @@ config_get_string(enum ConfigOption option, const char *default_value=nullptr); AllocatedPath config_get_path(enum ConfigOption option, Error &error); -/** - * Parse a configuration parameter as a path. - * If there is a tilde prefix, it is expanded. If the path could - * not be parsed, returns AllocatedPath::Null() and sets the error. - */ -AllocatedPath -config_parse_path(const ConfigParam *param, Error & error_r); - gcc_pure unsigned config_get_unsigned(enum ConfigOption option, unsigned default_value); diff --git a/src/config/Param.cxx b/src/config/Param.cxx index a3959c330..46e9ce024 100644 --- a/src/config/Param.cxx +++ b/src/config/Param.cxx @@ -19,6 +19,9 @@ #include "config.h" #include "Param.hxx" +#include "ConfigPath.hxx" +#include "fs/AllocatedPath.hxx" +#include "util/Error.hxx" ConfigParam::ConfigParam(const char *_value, int _line) :next(nullptr), value(_value), line(_line), used(false) {} @@ -27,3 +30,14 @@ ConfigParam::~ConfigParam() { delete next; } + +AllocatedPath +ConfigParam::GetPath(Error &error) const +{ + auto path = ParsePath(value.c_str(), error); + if (gcc_unlikely(path.IsNull())) + error.FormatPrefix("Invalid path at line %i: ", line); + + return path; + +} diff --git a/src/config/Param.hxx b/src/config/Param.hxx index 469bcc79a..c009ea0a4 100644 --- a/src/config/Param.hxx +++ b/src/config/Param.hxx @@ -25,6 +25,9 @@ #include +class Error; +class AllocatedPath; + struct ConfigParam { /** * The next ConfigParam with the same name. The destructor @@ -62,6 +65,13 @@ struct ConfigParam { bool IsNull() const { return line < 0; } + + /** + * Parse the value as a path. If there is a tilde prefix, it + * is expanded. If the path could not be parsed, returns + * AllocatedPath::Null() and sets the error. + */ + AllocatedPath GetPath(Error &error) const; }; #endif