alternative.c alternative.h \
malloc.c malloc.h \
domain.c domain.h \
+ address.c address.h \
alternative-test.c
alternative_test_CFLAGS = $(AM_CFLAGS)
domain_test_SOURCES = \
domain.c domain.h \
malloc.c malloc.h \
+ address.c address.h \
domain-test.c
domain_test_CFLAGS = $(AM_CFLAGS)
assert(avahi_normalize_name(".", t, sizeof(t)));
assert(avahi_normalize_name("", t, sizeof(t)));
+ assert(!avahi_is_valid_fqdn("."));
+ assert(!avahi_is_valid_fqdn(""));
+ assert(!avahi_is_valid_fqdn("foo"));
+ assert(avahi_is_valid_fqdn("foo.bar"));
+ assert(avahi_is_valid_fqdn("foo.bar."));
+ assert(avahi_is_valid_fqdn("gnurz.foo.bar."));
+ assert(!avahi_is_valid_fqdn("192.168.50.1"));
+ assert(!avahi_is_valid_fqdn("::1"));
+ assert(!avahi_is_valid_fqdn(".192.168.50.1."));
return 0;
}
#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) {
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;
+}
/** Return 1 when the specified string contains a valid non-FQDN host name (i.e. without dots), 0 otherwise */
int avahi_is_valid_host_name(const char *t);
+/** Return 1 when the specified string contains a valid FQDN host name (i.e. with more than one label and non-numerical), 0 otherwise. \since 0.6.9 */
+int avahi_is_valid_fqdn(const char *t);
+
/** Return some kind of hash value for the domain, useful for using domains as hash table keys. */
unsigned avahi_domain_hash(const char *name);