summaryrefslogtreecommitdiffstats
path: root/avahi-common
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-05 18:59:21 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-05 18:59:21 +0000
commit0632e854728e8e64552ae08f90852d4a2658539e (patch)
tree0fab7d52e01da7ab9b81b8409dcf70cceb7d2852 /avahi-common
parentd76069e946b4e89c828c96340677e40f583080c9 (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')
-rw-r--r--avahi-common/dbus.h26
-rw-r--r--avahi-common/rr.c46
-rw-r--r--avahi-common/rr.h8
-rw-r--r--avahi-common/util.c94
-rw-r--r--avahi-common/util.h5
5 files changed, 170 insertions, 9 deletions
diff --git a/avahi-common/dbus.h b/avahi-common/dbus.h
index ddbd47a..64696d2 100644
--- a/avahi-common/dbus.h
+++ b/avahi-common/dbus.h
@@ -32,13 +32,25 @@ AVAHI_C_DECL_BEGIN
#define AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER AVAHI_DBUS_NAME".ServiceTypeBrowser"
#define AVAHI_DBUS_INTERFACE_SERVICE_BROWSER AVAHI_DBUS_NAME".ServiceBrowser"
-#define AVAHI_DBUS_ERROR_INVALID_SERVICE "org.freedesktop.Avahi.InvalidServiceError"
-#define AVAHI_DBUS_ERROR_INVALID_ADDRESS "org.freedesktop.Avahi.InvalidAddressError"
-#define AVAHI_DBUS_ERROR_TIMEOUT "org.freedesktop.Avahi.TimeoutError"
-#define AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS "org.freedesktop.Avahi.TooManyClientsError"
-#define AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS "org.freedesktop.Avahi.TooManyObjectsError"
-#define AVAHI_DBUS_ERROR_TOO_MANY_ENTRIES "org.freedesktop.Avahi.TooManyEntriesError"
-#define AVAHI_DBUS_ERROR_OS "org.freedesktop.Avahi.OSError"
+#define AVAHI_DBUS_ERR_FAILURE "org.freedesktop.Avahi.Failure"
+#define AVAHI_DBUS_ERR_BAD_STATE "org.freedesktop.Avahi.BadStateError"
+#define AVAHI_DBUS_ERR_INVALID_HOST_NAME "org.freedesktop.Avahi.InvalidHostNameError"
+#define AVAHI_DBUS_ERR_INVALID_DOMAIN_NAME "org.freedesktop.Avahi.InvalidDomainNameError"
+#define AVAHI_DBUS_ERR_NO_NETWORK "org.freedesktop.Avahi.NoNetworkError"
+#define AVAHI_DBUS_ERR_INVALID_TTL "org.freedesktop.Avahi.InvalidTTLError"
+#define AVAHI_DBUS_ERR_IS_PATTERN "org.freedesktop.Avahi.IsPatternError"
+#define AVAHI_DBUS_ERR_LOCAL_COLLISION "org.freedesktop.Avahi.LocalCollisionError"
+#define AVAHI_DBUS_ERR_INVALID_RECORD "org.freedesktop.Avahi.InvalidRecordError"
+#define AVAHI_DBUS_ERR_INVALID_SERVICE_NAME "org.freedesktop.Avahi.InvalidServiceNameError"
+#define AVAHI_DBUS_ERR_INVALID_SERVICE_TYPE "org.freedesktop.Avahi.InvalidServiceTypeError"
+#define AVAHI_DBUS_ERR_INVALID_PORT "org.freedesktop.Avahi.InvalidPortError"
+#define AVAHI_DBUS_ERR_INVALID_KEY "org.freedesktop.Avahi.InvalidKeyError"
+#define AVAHI_DBUS_ERR_INVALID_ADDRESS "org.freedesktop.Avahi.InvalidAddressError"
+#define AVAHI_DBUS_ERR_TIMEOUT "org.freedesktop.Avahi.TimeoutError"
+#define AVAHI_DBUS_ERR_TOO_MANY_CLIENTS "org.freedesktop.Avahi.TooManyClientsError"
+#define AVAHI_DBUS_ERR_TOO_MANY_OBJECTS "org.freedesktop.Avahi.TooManyObjectsError"
+#define AVAHI_DBUS_ERR_TOO_MANY_ENTRIES "org.freedesktop.Avahi.TooManyEntriesError"
+#define AVAHI_DBUS_ERR_OS "org.freedesktop.Avahi.OSError"
AVAHI_C_DECL_END
diff --git a/avahi-common/rr.c b/avahi-common/rr.c
index c510e7f..1a30146 100644
--- a/avahi-common/rr.c
+++ b/avahi-common/rr.c
@@ -552,3 +552,49 @@ gboolean avahi_record_is_goodbye(AvahiRecord *r) {
return r->ttl == 0;
}
+
+gboolean avahi_key_valid(AvahiKey *k) {
+ g_assert(k);
+
+ if (!avahi_valid_domain_name(k->name))
+ return FALSE;
+
+ return TRUE;
+}
+
+gboolean avahi_record_valid(AvahiRecord *r) {
+ g_assert(r);
+
+ if (!avahi_key_valid(r->key))
+ return FALSE;
+
+ switch (r->key->type) {
+
+ case AVAHI_DNS_TYPE_PTR:
+ case AVAHI_DNS_TYPE_CNAME:
+ return avahi_valid_domain_name(r->data.ptr.name);
+
+ case AVAHI_DNS_TYPE_SRV:
+ return avahi_valid_domain_name(r->data.srv.name);
+
+ case AVAHI_DNS_TYPE_HINFO:
+ return
+ strlen(r->data.hinfo.os) <= 255 &&
+ strlen(r->data.hinfo.cpu) <= 255;
+
+
+ case AVAHI_DNS_TYPE_TXT: {
+
+ AvahiStringList *strlst;
+
+ for (strlst = r->data.txt.string_list; strlst; strlst = strlst->next)
+ if (strlst->size > 255)
+ return FALSE;
+
+ return TRUE;
+ }
+ }
+
+
+ return TRUE;
+}
diff --git a/avahi-common/rr.h b/avahi-common/rr.h
index 25d6eee..f5349e9 100644
--- a/avahi-common/rr.h
+++ b/avahi-common/rr.h
@@ -82,13 +82,11 @@ typedef struct {
guint32 ttl; /**< DNS TTL of this record */
union {
-
struct {
gpointer data;
guint16 size;
} generic; /**< Generic record data for unknown types */
-
struct {
guint16 priority;
@@ -200,6 +198,12 @@ gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b);
/** Return TRUE if the specified record is an mDNS goodbye record. i.e. TTL is zero. */
gboolean avahi_record_is_goodbye(AvahiRecord *r);
+/** Check whether the specified key is valid */
+gboolean avahi_key_valid(AvahiKey *k);
+
+/** Check whether the specified record is valid */
+gboolean avahi_record_valid(AvahiRecord *r);
+
AVAHI_C_DECL_END
#endif
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;
+}
diff --git a/avahi-common/util.h b/avahi-common/util.h
index 731a5a1..0d4fb4b 100644
--- a/avahi-common/util.h
+++ b/avahi-common/util.h
@@ -60,6 +60,11 @@ guint avahi_domain_hash(const gchar *s);
gchar *avahi_format_mac_address(const guint8* mac, guint size);
+gboolean avahi_valid_service_type(const gchar *t);
+gboolean avahi_valid_domain_name(const gchar *t);
+gboolean avahi_valid_service_name(const gchar *t);
+gboolean avahi_valid_host_name(const gchar *t);
+
AVAHI_C_DECL_END
#endif