Commit 7a341516 authored by Max Kellermann's avatar Max Kellermann

config/Param: add method GetPath()

Move code from config_parse_path().
parent 5b2b4bf1
......@@ -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 {
......
......@@ -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
......
......@@ -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);
......
......@@ -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;
}
......@@ -25,6 +25,9 @@
#include <string>
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment