diff options
author | Susant Sahani <susant@redhat.com> | 2017-04-27 10:41:46 +0530 |
---|---|---|
committer | Susant Sahani <susant@redhat.com> | 2017-04-29 22:33:50 +0530 |
commit | 177d0b20321a4548f27ba769e35d44f747c10852 (patch) | |
tree | f0b3ef41977c28197157d55a7f1b313ef0173ae7 /src | |
parent | db7076bf78bd8e466ae927b6d3ddf64190c8d299 (diff) |
config parser: Introduce config_parse_ip_port
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/conf-parser.c | 37 | ||||
-rw-r--r-- | src/shared/conf-parser.h | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index d8393cbc8d..dae521ef9f 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -960,3 +960,40 @@ int config_parse_ifname( return 0; } + +int config_parse_ip_port( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + uint16_t *s = data; + uint16_t port; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if (isempty(rvalue)) { + *s = 0; + return 0; + } + + r = parse_ip_port(rvalue, &port); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse port '%s'.", rvalue); + return 0; + } + + *s = port; + + return 0; +} diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 82ea5c1288..ce1113485d 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -140,6 +140,7 @@ int config_parse_log_level(const char *unit, const char *filename, unsigned line int config_parse_signal(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_personality(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_ifname(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_ip_port(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \ int function(const char *unit, \ |