dns-domain: reduce indentation in dns_service_split()
This commit is contained in:
+38
-41
@@ -1024,7 +1024,7 @@ static bool dns_service_name_label_is_valid(const char *label, size_t n) {
|
||||
|
||||
int dns_service_split(const char *joined, char **ret_name, char **ret_type, char **ret_domain) {
|
||||
_cleanup_free_ char *name = NULL, *type = NULL, *domain = NULL;
|
||||
const char *p = joined, *q = NULL, *d = NULL;
|
||||
const char *p = joined, *q = NULL, *d = joined;
|
||||
char a[DNS_LABEL_MAX+1], b[DNS_LABEL_MAX+1], c[DNS_LABEL_MAX+1];
|
||||
int an, bn, cn, r;
|
||||
unsigned x = 0;
|
||||
@@ -1045,6 +1045,9 @@ int dns_service_split(const char *joined, char **ret_name, char **ret_type, char
|
||||
return bn;
|
||||
|
||||
if (bn > 0) {
|
||||
if (!srv_type_label_is_valid(b, bn))
|
||||
goto finish;
|
||||
|
||||
x++;
|
||||
|
||||
/* If there was a second label, try to get the third one */
|
||||
@@ -1053,50 +1056,44 @@ int dns_service_split(const char *joined, char **ret_name, char **ret_type, char
|
||||
if (cn < 0)
|
||||
return cn;
|
||||
|
||||
if (cn > 0)
|
||||
if (cn > 0 && srv_type_label_is_valid(c, cn))
|
||||
x++;
|
||||
} else
|
||||
cn = 0;
|
||||
} else
|
||||
an = 0;
|
||||
|
||||
if (x >= 2 && srv_type_label_is_valid(b, bn)) {
|
||||
|
||||
if (x >= 3 && srv_type_label_is_valid(c, cn)) {
|
||||
|
||||
if (dns_service_name_label_is_valid(a, an)) {
|
||||
/* OK, got <name> . <type> . <type2> . <domain> */
|
||||
|
||||
name = strndup(a, an);
|
||||
if (!name)
|
||||
return -ENOMEM;
|
||||
|
||||
type = strjoin(b, ".", c);
|
||||
if (!type)
|
||||
return -ENOMEM;
|
||||
|
||||
d = p;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
} else if (srv_type_label_is_valid(a, an)) {
|
||||
|
||||
/* OK, got <type> . <type2> . <domain> */
|
||||
|
||||
name = NULL;
|
||||
|
||||
type = strjoin(a, ".", b);
|
||||
if (!type)
|
||||
return -ENOMEM;
|
||||
|
||||
d = q;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
name = NULL;
|
||||
type = NULL;
|
||||
d = joined;
|
||||
switch (x) {
|
||||
case 2:
|
||||
if (!srv_type_label_is_valid(a, an))
|
||||
break;
|
||||
|
||||
/* OK, got <type> . <type2> . <domain> */
|
||||
|
||||
name = NULL;
|
||||
|
||||
type = strjoin(a, ".", b);
|
||||
if (!type)
|
||||
return -ENOMEM;
|
||||
|
||||
d = q;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (!dns_service_name_label_is_valid(a, an))
|
||||
break;
|
||||
|
||||
/* OK, got <name> . <type> . <type2> . <domain> */
|
||||
|
||||
name = strndup(a, an);
|
||||
if (!name)
|
||||
return -ENOMEM;
|
||||
|
||||
type = strjoin(b, ".", c);
|
||||
if (!type)
|
||||
return -ENOMEM;
|
||||
|
||||
d = p;
|
||||
break;
|
||||
}
|
||||
|
||||
finish:
|
||||
r = dns_name_normalize(d, 0, &domain);
|
||||
|
||||
Reference in New Issue
Block a user