From 4d4577c5a953e9b462cffe9a5d3ead122b7bbe42 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 2 Mar 2006 01:28:03 +0000 Subject: add new API function avahi_is_valid_fqdn() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1168 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-common/domain.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'avahi-common/domain.c') diff --git a/avahi-common/domain.c b/avahi-common/domain.c index 4927086..1ac8577 100644 --- a/avahi-common/domain.c +++ b/avahi-common/domain.c @@ -36,6 +36,7 @@ #include "domain.h" #include "malloc.h" #include "error.h" +#include "address.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) { @@ -569,3 +570,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; +} -- cgit