]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: move dnssd parsers to resolved-dnssd.c 34373/head
authorLennart Poettering <lennart@poettering.net>
Tue, 3 Sep 2024 14:05:48 +0000 (16:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Sep 2024 15:00:03 +0000 (17:00 +0200)
Let's keep only the parsers for the main config in resolved-conf.c

src/resolve/resolved-conf.c
src/resolve/resolved-conf.h
src/resolve/resolved-dnssd.c
src/resolve/resolved-dnssd.h

index 65a5611d091169175dd465401af40492541744f6..9d70d98d1d41b80c6765b528061fee77ab6354be 100644 (file)
@@ -209,227 +209,6 @@ int config_parse_search_domains(
         return 0;
 }
 
-int config_parse_dnssd_service_name(
-                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) {
-
-        static const Specifier specifier_table[] = {
-                { 'a', specifier_architecture,    NULL },
-                { 'b', specifier_boot_id,         NULL },
-                { 'B', specifier_os_build_id,     NULL },
-                { 'H', specifier_hostname,        NULL }, /* We will use specifier_dnssd_hostname(). */
-                { 'm', specifier_machine_id,      NULL },
-                { 'o', specifier_os_id,           NULL },
-                { 'v', specifier_kernel_release,  NULL },
-                { 'w', specifier_os_version_id,   NULL },
-                { 'W', specifier_os_variant_id,   NULL },
-                {}
-        };
-        DnssdService *s = ASSERT_PTR(userdata);
-        _cleanup_free_ char *name = NULL;
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        if (isempty(rvalue)) {
-                s->name_template = mfree(s->name_template);
-                return 0;
-        }
-
-        r = specifier_printf(rvalue, DNS_LABEL_MAX, specifier_table, NULL, NULL, &name);
-        if (r < 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Invalid service instance name template '%s', ignoring assignment: %m", rvalue);
-                return 0;
-        }
-
-        if (!dns_service_name_is_valid(name)) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0,
-                           "Service instance name template '%s' renders to invalid name '%s'. Ignoring assignment.",
-                           rvalue, name);
-                return 0;
-        }
-
-        return free_and_strdup_warn(&s->name_template, rvalue);
-}
-
-int config_parse_dnssd_service_type(
-                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) {
-
-        DnssdService *s = ASSERT_PTR(userdata);
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        if (isempty(rvalue)) {
-                s->type = mfree(s->type);
-                return 0;
-        }
-
-        if (!dnssd_srv_type_is_valid(rvalue)) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0, "Service type is invalid. Ignoring.");
-                return 0;
-        }
-
-        r = free_and_strdup(&s->type, rvalue);
-        if (r < 0)
-                return log_oom();
-
-        return 0;
-}
-
-int config_parse_dnssd_service_subtype(
-                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) {
-
-        DnssdService *s = ASSERT_PTR(userdata);
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        if (isempty(rvalue)) {
-                s->subtype = mfree(s->subtype);
-                return 0;
-        }
-
-        if (!dns_subtype_name_is_valid(rvalue)) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0, "Service subtype is invalid. Ignoring.");
-                return 0;
-        }
-
-        return free_and_strdup_warn(&s->subtype, rvalue);
-}
-
-int config_parse_dnssd_txt(
-                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) {
-
-        _cleanup_(dnssd_txtdata_freep) DnssdTxtData *txt_data = NULL;
-        DnssdService *s = ASSERT_PTR(userdata);
-        DnsTxtItem *last = NULL;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        if (isempty(rvalue)) {
-                /* Flush out collected items */
-                s->txt_data_items = dnssd_txtdata_free_all(s->txt_data_items);
-                return 0;
-        }
-
-        txt_data = new0(DnssdTxtData, 1);
-        if (!txt_data)
-                return log_oom();
-
-        for (;;) {
-                _cleanup_free_ char *word = NULL, *key = NULL, *value = NULL;
-                _cleanup_free_ void *decoded = NULL;
-                size_t length = 0;
-                DnsTxtItem *i;
-                int r;
-
-                r = extract_first_word(&rvalue, &word, NULL,
-                                       EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_RELAX);
-                if (r == 0)
-                        break;
-                if (r == -ENOMEM)
-                        return log_oom();
-                if (r < 0) {
-                        log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
-                        return 0;
-                }
-
-                r = split_pair(word, "=", &key, &value);
-                if (r == -ENOMEM)
-                        return log_oom();
-                if (r == -EINVAL)
-                        key = TAKE_PTR(word);
-
-                if (!ascii_is_valid(key)) {
-                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid key, ignoring: %s", key);
-                        continue;
-                }
-
-                switch (ltype) {
-
-                case DNS_TXT_ITEM_DATA:
-                        if (value) {
-                                r = unbase64mem(value, &decoded, &length);
-                                if (r == -ENOMEM)
-                                        return log_oom();
-                                if (r < 0) {
-                                        log_syntax(unit, LOG_WARNING, filename, line, r,
-                                                   "Invalid base64 encoding, ignoring: %s", value);
-                                        continue;
-                                }
-                        }
-
-                        r = dnssd_txt_item_new_from_data(key, decoded, length, &i);
-                        if (r < 0)
-                                return log_oom();
-                        break;
-
-                case DNS_TXT_ITEM_TEXT:
-                        r = dnssd_txt_item_new_from_string(key, value, &i);
-                        if (r < 0)
-                                return log_oom();
-                        break;
-
-                default:
-                        assert_not_reached();
-                }
-
-                LIST_INSERT_AFTER(items, txt_data->txts, last, i);
-                last = i;
-        }
-
-        if (txt_data->txts) {
-                LIST_PREPEND(items, s->txt_data_items, txt_data);
-                TAKE_PTR(txt_data);
-        }
-
-        return 0;
-}
-
 int config_parse_dns_stub_listener_extra(
                 const char *unit,
                 const char *filename,
index 517254bcc069bd5bfc941b0bbbdcc454adce9276..ce280cb0a32c710976368b284248d492c21bee3a 100644 (file)
@@ -23,8 +23,4 @@ const struct ConfigPerfItem* resolved_gperf_lookup(const char *key, GPERF_LEN_TY
 CONFIG_PARSER_PROTOTYPE(config_parse_dns_servers);
 CONFIG_PARSER_PROTOTYPE(config_parse_search_domains);
 CONFIG_PARSER_PROTOTYPE(config_parse_dns_stub_listener_mode);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_name);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_subtype);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_type);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_txt);
 CONFIG_PARSER_PROTOTYPE(config_parse_dns_stub_listener_extra);
index 5f66e3c5019fbc4c37e69fa76f5ff8845c3f1820..00fd7250441a32d459b9dfee3f60c310b0e4e839 100644 (file)
@@ -3,6 +3,7 @@
 #include "conf-files.h"
 #include "conf-parser.h"
 #include "constants.h"
+#include "hexdecoct.h"
 #include "path-util.h"
 #include "resolved-conf.h"
 #include "resolved-dns-rr.h"
@@ -402,3 +403,224 @@ int dnssd_signal_conflict(Manager *manager, const char *name) {
 
         return 0;
 }
+
+int config_parse_dnssd_service_name(
+                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) {
+
+        static const Specifier specifier_table[] = {
+                { 'a', specifier_architecture,    NULL },
+                { 'b', specifier_boot_id,         NULL },
+                { 'B', specifier_os_build_id,     NULL },
+                { 'H', specifier_hostname,        NULL }, /* We will use specifier_dnssd_hostname(). */
+                { 'm', specifier_machine_id,      NULL },
+                { 'o', specifier_os_id,           NULL },
+                { 'v', specifier_kernel_release,  NULL },
+                { 'w', specifier_os_version_id,   NULL },
+                { 'W', specifier_os_variant_id,   NULL },
+                {}
+        };
+        DnssdService *s = ASSERT_PTR(userdata);
+        _cleanup_free_ char *name = NULL;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                s->name_template = mfree(s->name_template);
+                return 0;
+        }
+
+        r = specifier_printf(rvalue, DNS_LABEL_MAX, specifier_table, NULL, NULL, &name);
+        if (r < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r,
+                           "Invalid service instance name template '%s', ignoring assignment: %m", rvalue);
+                return 0;
+        }
+
+        if (!dns_service_name_is_valid(name)) {
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
+                           "Service instance name template '%s' renders to invalid name '%s'. Ignoring assignment.",
+                           rvalue, name);
+                return 0;
+        }
+
+        return free_and_strdup_warn(&s->name_template, rvalue);
+}
+
+int config_parse_dnssd_service_type(
+                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) {
+
+        DnssdService *s = ASSERT_PTR(userdata);
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                s->type = mfree(s->type);
+                return 0;
+        }
+
+        if (!dnssd_srv_type_is_valid(rvalue)) {
+                log_syntax(unit, LOG_WARNING, filename, line, 0, "Service type is invalid. Ignoring.");
+                return 0;
+        }
+
+        r = free_and_strdup(&s->type, rvalue);
+        if (r < 0)
+                return log_oom();
+
+        return 0;
+}
+
+int config_parse_dnssd_service_subtype(
+                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) {
+
+        DnssdService *s = ASSERT_PTR(userdata);
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                s->subtype = mfree(s->subtype);
+                return 0;
+        }
+
+        if (!dns_subtype_name_is_valid(rvalue)) {
+                log_syntax(unit, LOG_WARNING, filename, line, 0, "Service subtype is invalid. Ignoring.");
+                return 0;
+        }
+
+        return free_and_strdup_warn(&s->subtype, rvalue);
+}
+
+int config_parse_dnssd_txt(
+                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) {
+
+        _cleanup_(dnssd_txtdata_freep) DnssdTxtData *txt_data = NULL;
+        DnssdService *s = ASSERT_PTR(userdata);
+        DnsTxtItem *last = NULL;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                /* Flush out collected items */
+                s->txt_data_items = dnssd_txtdata_free_all(s->txt_data_items);
+                return 0;
+        }
+
+        txt_data = new0(DnssdTxtData, 1);
+        if (!txt_data)
+                return log_oom();
+
+        for (;;) {
+                _cleanup_free_ char *word = NULL, *key = NULL, *value = NULL;
+                _cleanup_free_ void *decoded = NULL;
+                size_t length = 0;
+                DnsTxtItem *i;
+                int r;
+
+                r = extract_first_word(&rvalue, &word, NULL,
+                                       EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_RELAX);
+                if (r == 0)
+                        break;
+                if (r == -ENOMEM)
+                        return log_oom();
+                if (r < 0) {
+                        log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
+                        return 0;
+                }
+
+                r = split_pair(word, "=", &key, &value);
+                if (r == -ENOMEM)
+                        return log_oom();
+                if (r == -EINVAL)
+                        key = TAKE_PTR(word);
+
+                if (!ascii_is_valid(key)) {
+                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid key, ignoring: %s", key);
+                        continue;
+                }
+
+                switch (ltype) {
+
+                case DNS_TXT_ITEM_DATA:
+                        if (value) {
+                                r = unbase64mem(value, &decoded, &length);
+                                if (r == -ENOMEM)
+                                        return log_oom();
+                                if (r < 0) {
+                                        log_syntax(unit, LOG_WARNING, filename, line, r,
+                                                   "Invalid base64 encoding, ignoring: %s", value);
+                                        continue;
+                                }
+                        }
+
+                        r = dnssd_txt_item_new_from_data(key, decoded, length, &i);
+                        if (r < 0)
+                                return log_oom();
+                        break;
+
+                case DNS_TXT_ITEM_TEXT:
+                        r = dnssd_txt_item_new_from_string(key, value, &i);
+                        if (r < 0)
+                                return log_oom();
+                        break;
+
+                default:
+                        assert_not_reached();
+                }
+
+                LIST_INSERT_AFTER(items, txt_data->txts, last, i);
+                last = i;
+        }
+
+        if (txt_data->txts) {
+                LIST_PREPEND(items, s->txt_data_items, txt_data);
+                TAKE_PTR(txt_data);
+        }
+
+        return 0;
+}
index 06ad1f9705ef1758865cf94d29c4745241ce066b..8aaa9da748dbdc8e7481ea037a354854807229de 100644 (file)
@@ -68,3 +68,8 @@ int dnssd_update_rrs(DnssdService *s);
 int dnssd_signal_conflict(Manager *manager, const char *name);
 
 const struct ConfigPerfItem* resolved_dnssd_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
+
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_name);
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_subtype);
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_type);
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_txt);