summaryrefslogtreecommitdiffstats
path: root/avahi-common
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-03-02 01:28:03 +0000
committerLennart Poettering <lennart@poettering.net>2006-03-02 01:28:03 +0000
commit4d4577c5a953e9b462cffe9a5d3ead122b7bbe42 (patch)
treecb9af054f9fd544934d22899ab4dc9f97c18f2d2 /avahi-common
parentcc7cabaf6b1b8e67a7d1fc92c97ad708ec270859 (diff)
add new API function avahi_is_valid_fqdn()
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1168 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common')
-rw-r--r--avahi-common/Makefile.am2
-rw-r--r--avahi-common/domain-test.c9
-rw-r--r--avahi-common/domain.c36
-rw-r--r--avahi-common/domain.h3
4 files changed, 50 insertions, 0 deletions
diff --git a/avahi-common/Makefile.am b/avahi-common/Makefile.am
index 96ef099..c786954 100644
--- a/avahi-common/Makefile.am
+++ b/avahi-common/Makefile.am
@@ -81,12 +81,14 @@ alternative_test_SOURCES = \
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)
diff --git a/avahi-common/domain-test.c b/avahi-common/domain-test.c
index c9ff32e..0f7d851 100644
--- a/avahi-common/domain-test.c
+++ b/avahi-common/domain-test.c
@@ -111,6 +111,15 @@ int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
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;
}
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;
+}
diff --git a/avahi-common/domain.h b/avahi-common/domain.h
index 53897e7..7073e1c 100644
--- a/avahi-common/domain.h
+++ b/avahi-common/domain.h
@@ -89,6 +89,9 @@ int avahi_is_valid_service_name(const char *t);
/** 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);