diff options
author | Tom Gundersen <teg@jklm.no> | 2015-08-21 15:26:45 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-08-21 15:26:45 +0200 |
commit | ef7051360aefca01d20f700ee74ac1baced59879 (patch) | |
tree | 7e74c19fc5928d35012d1ff99ddce20406cf92a6 /src/shared | |
parent | 6b8b67e7aed7d4f98881f823b89f5f4079e52066 (diff) | |
parent | 78c6a153c47f8d597c827bdcaf8c4e42ac87f738 (diff) |
Merge pull request #1002 from poettering/resolved-various
resolved: synthesize more RRs locally and other fixes
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/dns-domain.c | 40 | ||||
-rw-r--r-- | src/shared/dns-domain.h | 10 |
2 files changed, 34 insertions, 16 deletions
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index 8a0dec1540..6dc04d51e4 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -308,14 +308,14 @@ int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded, #endif } -int dns_name_normalize(const char *s, char **_ret) { +int dns_name_concat(const char *a, const char *b, char **_ret) { _cleanup_free_ char *ret = NULL; size_t n = 0, allocated = 0; - const char *p = s; + const char *p = a; bool first = true; int r; - assert(s); + assert(a); for (;;) { _cleanup_free_ char *t = NULL; @@ -328,6 +328,14 @@ int dns_name_normalize(const char *s, char **_ret) { if (r == 0) { if (*p != 0) return -EINVAL; + + if (b) { + /* Now continue with the second string, if there is one */ + p = b; + b = NULL; + continue; + } + break; } @@ -341,27 +349,29 @@ int dns_name_normalize(const char *s, char **_ret) { if (r < 0) return r; - if (!GREEDY_REALLOC(ret, allocated, n + !first + strlen(t) + 1)) - return -ENOMEM; + if (_ret) { + if (!GREEDY_REALLOC(ret, allocated, n + !first + strlen(t) + 1)) + return -ENOMEM; - if (!first) - ret[n++] = '.'; - else - first = false; + if (!first) + ret[n++] = '.'; + else + first = false; + + memcpy(ret + n, t, r); + } - memcpy(ret + n, t, r); n += r; } if (n > DNS_NAME_MAX) return -EINVAL; - if (!GREEDY_REALLOC(ret, allocated, n + 1)) - return -ENOMEM; - - ret[n] = 0; - if (_ret) { + if (!GREEDY_REALLOC(ret, allocated, n + 1)) + return -ENOMEM; + + ret[n] = 0; *_ret = ret; ret = NULL; } diff --git a/src/shared/dns-domain.h b/src/shared/dns-domain.h index bd50ad3e6d..8e73d9c20f 100644 --- a/src/shared/dns-domain.h +++ b/src/shared/dns-domain.h @@ -35,9 +35,17 @@ int dns_label_escape(const char *p, size_t l, char **ret); int dns_label_apply_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max); int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max); -int dns_name_normalize(const char *s, char **_ret); +int dns_name_concat(const char *a, const char *b, char **ret); + +static inline int dns_name_normalize(const char *s, char **ret) { + /* dns_name_concat() normalizes as a side-effect */ + return dns_name_concat(s, NULL, ret); +} + static inline int dns_name_is_valid(const char *s) { int r; + + /* dns_name_normalize() verifies as a side effect */ r = dns_name_normalize(s, NULL); if (r == -EINVAL) return 0; |