From 177d0b20321a4548f27ba769e35d44f747c10852 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 27 Apr 2017 10:41:46 +0530 Subject: config parser: Introduce config_parse_ip_port --- src/shared/conf-parser.c | 37 +++++++++++++++++++++++++++++++++++++ src/shared/conf-parser.h | 1 + 2 files changed, 38 insertions(+) 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, \ -- cgit v1.2.3-54-g00ecf