summaryrefslogtreecommitdiffstats
path: root/avahi-common/domain.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-10-23 20:21:39 +0000
committerLennart Poettering <lennart@poettering.net>2005-10-23 20:21:39 +0000
commite865e3dba3c6ee5de5581dbfbafc025aa5c9947e (patch)
tree7630d4d1b2f9982d1c5df4dad767ea7511ad33ee /avahi-common/domain.c
parent0d0c9486e3fe26fdd67624ee57961ba2d5846ebb (diff)
* correctly handle empty domain names (i.e. the root zone)
* fix memory initialization error in wide-area.c * make server_add_xx() functions atomic, i.e. clean up half-created entries on failure * add some more validity checking macros and change everything to make use of them * clean up avahi_server_add_address() * change some functions from domain.[ch] to work on a stack buffer instead of malloced memory * update avahi-test.c a little * replace avahi_reverse_lookup_name_{ipv4,ipv6}() with a single function avahi_reverse_lookup_name() * remove avahi_server_add_dns_server_name() from public API git-svn-id: file:///home/lennart/svn/public/avahi/trunk@845 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common/domain.c')
-rw-r--r--avahi-common/domain.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/avahi-common/domain.c b/avahi-common/domain.c
index 988ba7e..7d954de 100644
--- a/avahi-common/domain.c
+++ b/avahi-common/domain.c
@@ -206,31 +206,35 @@ char *avahi_normalize_name(const char *s, char *ret_s, size_t size) {
assert(size > 0);
r = ret_s;
+ *ret_s = 0;
+
while (*s) {
char label[AVAHI_LABEL_MAX];
if (!(avahi_unescape_label(&s, label, sizeof(label))))
return NULL;
- if (strlen(label) > 0) {
-
- if (!empty) {
- if (size < 1)
- return NULL;
+ if (label[0] == 0) {
- *(r++) = '.';
- size--;
+ if (*s == 0 && empty)
+ return ret_s;
- } else
- empty = 0;
-
- avahi_escape_label(label, strlen(label), &r, &size);
+ return NULL;
}
+
+ if (!empty) {
+ if (size < 1)
+ return NULL;
+
+ *(r++) = '.';
+ size--;
+
+ } else
+ empty = 0;
+
+ avahi_escape_label(label, strlen(label), &r, &size);
}
- if (empty)
- return NULL;
-
return ret_s;
}
@@ -409,9 +413,10 @@ int avahi_is_valid_service_subtype(const char *t) {
}
int avahi_is_valid_domain_name(const char *t) {
+ int is_first = 1;
assert(t);
- if (strlen(t) >= AVAHI_DOMAIN_NAME_MAX || !*t)
+ if (strlen(t) >= AVAHI_DOMAIN_NAME_MAX)
return 0;
do {
@@ -420,7 +425,13 @@ int avahi_is_valid_domain_name(const char *t) {
if (!(avahi_unescape_label(&t, label, sizeof(label))))
return 0;
- if (strlen(label) < 1)
+ /* Explicitly allow the root domain name */
+ if (is_first && label[0] == 0 && *t == 0)
+ return 1;
+
+ is_first = 0;
+
+ if (label[0] == 0)
return 0;
} while (*t);