X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-common%2Fdomain.c;h=8d339c7a487b2a6ddecb9103f7038f10f2f7131b;hb=451be30b300b390b46738af3fd24fc942ba3158f;hp=4927086b2f62738f6a9c88557606cf6d915affad;hpb=c3575017e2137ef664e4735bd6f9ff1209653ef3;p=catta diff --git a/avahi-common/domain.c b/avahi-common/domain.c index 4927086..8d339c7 100644 --- a/avahi-common/domain.c +++ b/avahi-common/domain.c @@ -36,6 +36,8 @@ #include "domain.h" #include "malloc.h" #include "error.h" +#include "address.h" +#include "utf8.h" /* Read the first label from string *name, unescape "\" and write it to dest */ char *avahi_unescape_label(const char **name, char *dest, size_t size) { @@ -106,6 +108,9 @@ char *avahi_unescape_label(const char **name, char *dest, size_t size) { *d = 0; + if (!avahi_utf8_valid(dest)) + return NULL; + return dest; } @@ -569,3 +574,38 @@ int avahi_service_name_split(const char *p, char *name, size_t name_size, char * return 0; } +int avahi_is_valid_fqdn(const char *t) { + char label[AVAHI_LABEL_MAX]; + char normalized[AVAHI_DOMAIN_NAME_MAX]; + const char *k = t; + AvahiAddress a; + assert(t); + + if (strlen(t) >= AVAHI_DOMAIN_NAME_MAX) + return 0; + + if (!avahi_is_valid_domain_name(t)) + return 0; + + /* Check if there are at least two labels*/ + if (!(avahi_unescape_label(&k, label, sizeof(label)))) + return 0; + + if (label[0] == 0 || !k) + return 0; + + if (!(avahi_unescape_label(&k, label, sizeof(label)))) + return 0; + + if (label[0] == 0 || !k) + return 0; + + /* Make sure that the name is not an IP address */ + if (!(avahi_normalize_name(t, normalized, sizeof(normalized)))) + return 0; + + if (avahi_address_parse(normalized, AVAHI_PROTO_UNSPEC, &a)) + return 0; + + return 1; +}