]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
config parser: Introduce config_parse_ip_port
authorSusant Sahani <susant@redhat.com>
Thu, 27 Apr 2017 05:11:46 +0000 (10:41 +0530)
committerSusant Sahani <susant@redhat.com>
Sat, 29 Apr 2017 17:03:50 +0000 (22:33 +0530)
src/shared/conf-parser.c
src/shared/conf-parser.h

index d8393cbc8d3dbe5f6ed5c8ee063bfaeaa820125f..dae521ef9fed50df3b753e1a20d83128e91cdc8e 100644 (file)
@@ -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;
+}
index 82ea5c1288ae731f7bfe395779e646da8a6488dc..ce1113485d5915797bacdcad8f25e1e5da4d2cd2 100644 (file)
@@ -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,                                  \