chiark / gitweb /
config parser: Introduce config_parse_ip_port
[elogind.git] / src / shared / conf-parser.c
index 0f6bf85b0386809443bc3bdb3029b6445ea11ed1..06c05a0ce35cdf70d2baf12951792842e894612f 100644 (file)
@@ -508,6 +508,7 @@ int config_parse_many(
 DEFINE_PARSER(int, int, safe_atoi);
 DEFINE_PARSER(long, long, safe_atoli);
 #if 0 /// UNNEEDED by elogind
+DEFINE_PARSER(uint8, uint8_t, safe_atou8);
 DEFINE_PARSER(uint16, uint16_t, safe_atou16);
 DEFINE_PARSER(uint32, uint32_t, safe_atou32);
 #endif // 0
@@ -972,3 +973,40 @@ int config_parse_ifname(
         return 0;
 }
 #endif // 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;
+}