diff options
author | Lennart Poettering <lennart@poettering.net> | 2005-08-05 18:59:21 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2005-08-05 18:59:21 +0000 |
commit | 0632e854728e8e64552ae08f90852d4a2658539e (patch) | |
tree | 0fab7d52e01da7ab9b81b8409dcf70cceb7d2852 /avahi-common/util.c | |
parent | d76069e946b4e89c828c96340677e40f583080c9 (diff) |
* add proper error codes and patch everything to make use of it
* parameter validity checkin in all user visible functions of libavahi-core
* two new python tools/examples avahi-resolve-host-name and avahi-resolve-address
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@238 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common/util.c')
-rw-r--r-- | avahi-common/util.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/avahi-common/util.c b/avahi-common/util.c index 8be7b88..a977bb2 100644 --- a/avahi-common/util.c +++ b/avahi-common/util.c @@ -414,3 +414,97 @@ gchar *avahi_format_mac_address(const guint8* mac, guint size) { *(--t) = 0; return r; } + +gboolean avahi_valid_service_type(const gchar *t) { + const gchar *p; + g_assert(t); + + if (strlen(t) < 5) + return FALSE; + + if (*t != '_') + return FALSE; + + if (!(p = strchr(t, '.'))) + return FALSE; + + if (p - t > 63 || p - t < 2) + return FALSE; + + if (*(++p) != '_') + return FALSE; + + if (strchr(p, '.')) + return FALSE; + + if (strlen(p) > 63 || strlen(p) < 2) + return FALSE; + + return TRUE; +} + +gboolean avahi_valid_domain_name(const gchar *t) { + const gchar *p, *dp; + gboolean dot = FALSE; + + g_assert(t); + + if (*t == 0) + return FALSE; + + /* Domains may not start with a dot */ + if (*t == '.') + return FALSE; + + dp = t; + + for (p = t; *p; p++) { + + if (*p == '.') { + if (dot) /* Two subsequent dots */ + return FALSE; + + if (p - dp > 63) + return FALSE; + + dot = TRUE; + dp = p + 1; + } else + dot = FALSE; + + } + + if (p - dp > 63) + return FALSE; + + /* A trailing dot IS allowed */ + + return TRUE; +} + +gboolean avahi_valid_service_name(const gchar *t) { + g_assert(t); + + if (*t == 0) + return FALSE; + + if (strlen(t) > 63) + return FALSE; + + return TRUE; +} + +gboolean avahi_valid_host_name(const gchar *t) { + g_assert(t); + + if (*t == 0) + return FALSE; + + if (strlen(t) > 63) + return FALSE; + + if (strchr(t, '.')) + return FALSE; + + return TRUE; +} |