AVAHI_DBUS_ERR_IS_PATTERN,
AVAHI_DBUS_ERR_COLLISION,
AVAHI_DBUS_ERR_INVALID_RECORD,
+
AVAHI_DBUS_ERR_INVALID_SERVICE_NAME,
AVAHI_DBUS_ERR_INVALID_SERVICE_TYPE,
AVAHI_DBUS_ERR_INVALID_PORT,
AVAHI_DBUS_ERR_TOO_MANY_OBJECTS,
AVAHI_DBUS_ERR_TOO_MANY_ENTRIES,
AVAHI_DBUS_ERR_OS,
+
AVAHI_DBUS_ERR_ACCESS_DENIED,
AVAHI_DBUS_ERR_INVALID_OPERATION,
AVAHI_DBUS_ERR_DBUS_ERROR,
AVAHI_DBUS_ERR_INVALID_INTERFACE,
AVAHI_DBUS_ERR_INVALID_PROTOCOL,
AVAHI_DBUS_ERR_INVALID_FLAGS,
+
AVAHI_DBUS_ERR_NOT_FOUND,
AVAHI_DBUS_ERR_INVALID_CONFIG,
AVAHI_DBUS_ERR_VERSION_MISMATCH,
AVAHI_DBUS_ERR_DNS_SERVFAIL,
AVAHI_DBUS_ERR_DNS_NXDOMAIN,
AVAHI_DBUS_ERR_DNS_NOTIMP,
+
AVAHI_DBUS_ERR_DNS_REFUSED,
AVAHI_DBUS_ERR_DNS_YXDOMAIN,
AVAHI_DBUS_ERR_DNS_YXRRSET,
AVAHI_DBUS_ERR_DNS_NXRRSET,
AVAHI_DBUS_ERR_DNS_NOTAUTH,
AVAHI_DBUS_ERR_DNS_NOTZONE,
- AVAHI_DBUS_ERR_INVALID_RDATA
+ AVAHI_DBUS_ERR_INVALID_RDATA,
+ AVAHI_DBUS_ERR_INVALID_DNS_CLASS,
+ AVAHI_DBUS_ERR_INVALID_DNS_TYPE
};
int avahi_error_dbus_to_number(const char *s) {
#define AVAHI_DBUS_ERR_IS_PATTERN "org.freedesktop.Avahi.IsPatternError"
#define AVAHI_DBUS_ERR_COLLISION "org.freedesktop.Avahi.CollisionError"
#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_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"
+
#define AVAHI_DBUS_ERR_ACCESS_DENIED DBUS_ERROR_ACCESS_DENIED
#define AVAHI_DBUS_ERR_INVALID_OPERATION "org.freedesktop.Avahi.InvalidOperationError"
#define AVAHI_DBUS_ERR_DBUS_ERROR "org.freedesktop.Avahi.DBusError"
#define AVAHI_DBUS_ERR_INVALID_INTERFACE "org.freedesktop.Avahi.InvalidInterfaceError"
#define AVAHI_DBUS_ERR_INVALID_PROTOCOL "org.freedesktop.Avahi.InvalidInterfaceProtocolError"
#define AVAHI_DBUS_ERR_INVALID_FLAGS "org.freedesktop.Avahi.InvalidFlagsError"
+
#define AVAHI_DBUS_ERR_NOT_FOUND "org.freedesktop.Avahi.NotFoundError"
#define AVAHI_DBUS_ERR_INVALID_CONFIG "org.freedesktop.Avahi.InvalidConfigurationError"
#define AVAHI_DBUS_ERR_VERSION_MISMATCH "org.freedesktop.Avahi.VersionMismatchError"
#define AVAHI_DBUS_ERR_DNS_SERVFAIL "org.freedesktop.Avahi.DNSSERVFAIL"
#define AVAHI_DBUS_ERR_DNS_NXDOMAIN "org.freedesktop.Avahi.DNSNXDOMAIN"
#define AVAHI_DBUS_ERR_DNS_NOTIMP "org.freedesktop.Avahi.DNSNOTIMP"
+
#define AVAHI_DBUS_ERR_DNS_REFUSED "org.freedesktop.Avahi.DNSREFUSED"
#define AVAHI_DBUS_ERR_DNS_YXDOMAIN "org.freedesktop.Avahi.DNSYXDOMAIN"
#define AVAHI_DBUS_ERR_DNS_YXRRSET "org.freedesktop.Avahi.DNSYXRRSET"
#define AVAHI_DBUS_ERR_DNS_NXRRSET "org.freedesktop.Avahi.DNSNXRRSET"
#define AVAHI_DBUS_ERR_DNS_NOTAUTH "org.freedesktop.Avahi.DNSNOTAUTH"
#define AVAHI_DBUS_ERR_DNS_NOTZONE "org.freedesktop.Avahi.DNSNOTZONE"
-#define AVAHI_DBUS_ERR_INVALID_RDATA "org.freedesktop.Avahi.InvalidRDATA"
+#define AVAHI_DBUS_ERR_INVALID_RDATA "org.freedesktop.Avahi.InvalidRDataError"
+#define AVAHI_DBUS_ERR_INVALID_DNS_CLASS "org.freedesktop.Avahi.InvalidDNSClass"
+#define AVAHI_DBUS_ERR_INVALID_DNS_TYPE "org.freedesktop.Avahi.InvalidDNSType"
/** Convert a DBus error string into an Avahi error number */
int avahi_error_dbus_to_number(const char *s);
/** In invalid cookie as special value */
#define AVAHI_SERVICE_COOKIE_INVALID (0)
+/** DNS record types, see RFC 1035 */
+enum {
+ AVAHI_DNS_TYPE_A = 0x01,
+ AVAHI_DNS_TYPE_NS = 0x02,
+ AVAHI_DNS_TYPE_CNAME = 0x05,
+ AVAHI_DNS_TYPE_SOA = 0x06,
+ AVAHI_DNS_TYPE_PTR = 0x0C,
+ AVAHI_DNS_TYPE_HINFO = 0x0D,
+ AVAHI_DNS_TYPE_MX = 0x0F,
+ AVAHI_DNS_TYPE_TXT = 0x10,
+ AVAHI_DNS_TYPE_AAAA = 0x1C,
+ AVAHI_DNS_TYPE_SRV = 0x21,
+};
+
+/** DNS record classes, see RFC 1035 */
+enum {
+ AVAHI_DNS_CLASS_IN = 0x01, /**< Probably the only class we will ever use */
+};
+
+/** The default TTL for RRs which contain a host name of some kind. */
+#define AVAHI_DEFAULT_TTL_HOST_NAME (120)
+
+/** The default TTL for all other records. */
+#define AVAHI_DEFAULT_TTL (75*60)
+
AVAHI_C_DECL_END
#endif
"DNS failure: NXRRSET",
"DNS failure: NOTAUTH",
"DNS failure: NOTZONE",
-
- "Invalid RDATA"
+ "Invalid RDATA",
+ "Invalid DNS type",
+ "Invalid DNS class"
};
if (-error < 0 || -error >= -AVAHI_ERR_MAX)
AVAHI_ERR_INVALID_SERVICE_SUBTYPE = -33, /**< Invalid service subtype */
AVAHI_ERR_INVALID_PACKET = -34, /**< Invalid packet */
AVAHI_ERR_INVALID_DNS_ERROR = -35, /**< Invlaid DNS return code */
- AVAHI_ERR_DNS_FORMERR = -36,
- AVAHI_ERR_DNS_SERVFAIL = -37,
- AVAHI_ERR_DNS_NXDOMAIN = -38,
- AVAHI_ERR_DNS_NOTIMP = -39,
+ AVAHI_ERR_DNS_FORMERR = -36, /**< DNS Error: Form error */
+ AVAHI_ERR_DNS_SERVFAIL = -37, /**< DNS Error: Server Failure */
+ AVAHI_ERR_DNS_NXDOMAIN = -38, /**< DNS Error: No such domain */
+ AVAHI_ERR_DNS_NOTIMP = -39, /**< DNS Error: Not implemented */
- AVAHI_ERR_DNS_REFUSED = -40,
+ AVAHI_ERR_DNS_REFUSED = -40, /**< DNS Error: Operation refused */
AVAHI_ERR_DNS_YXDOMAIN = -41,
AVAHI_ERR_DNS_YXRRSET = -42,
AVAHI_ERR_DNS_NXRRSET = -43,
- AVAHI_ERR_DNS_NOTAUTH = -44,
- AVAHI_ERR_DNS_NOTZONE = -45,
-
- AVAHI_ERR_INVALID_RDATA = -46,
+ AVAHI_ERR_DNS_NOTAUTH = -44, /**< DNS Error: Not authorized */
+ AVAHI_ERR_DNS_NOTZONE = -45,
+ AVAHI_ERR_INVALID_RDATA = -46, /**< Invalid RDATA */
+ AVAHI_ERR_INVALID_DNS_CLASS = -47, /**< Invalid DNS class */
+ AVAHI_ERR_INVALID_DNS_TYPE = -48, /**< Invalid DNS type */
/****
**** IF YOU ADD A NEW ERROR CODE HERE, PLEASE DON'T FORGET TO ADD
**** Also remember to update the MAX value below.
****/
- AVAHI_ERR_MAX = -47
+ AVAHI_ERR_MAX = -49
};
/** Return a human readable error string for the specified error code */
#include <arpa/inet.h>
#include <avahi-common/domain.h>
+#include <avahi-common/defs.h>
#include <avahi-common/malloc.h>
#include "dns.h"
#include "util.h"
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- char t[AVAHI_DOMAIN_NAME_MAX];
+ char t[AVAHI_DOMAIN_NAME_MAX], *m;
const char *a, *b, *c, *d;
AvahiDnsPacket *p;
AvahiRecord *r, *r2;
/* Free the records */
avahi_record_unref(r);
avahi_record_unref(r2);
+
+ r = avahi_record_new_full("foobar", 77, 77, AVAHI_DEFAULT_TTL);
+ assert(r);
+
+ assert(r->data.generic.data = avahi_memdup("HALLO", r->data.generic.size = 5));
+
+ m = avahi_record_to_string(r);
+ assert(m);
+
+ avahi_log_debug(">%s<", m);
+
+ avahi_free(m);
+ avahi_record_unref(r);
return 0;
}
#include <stdio.h>
#include <assert.h>
+#include <avahi-common/defs.h>
#include <avahi-common/domain.h>
#include <avahi-common/malloc.h>
AVAHI_CHECK_VALIDITY_RETURN_NULL(s, r->ttl != 0, AVAHI_ERR_INVALID_TTL);
AVAHI_CHECK_VALIDITY_RETURN_NULL(s, !avahi_key_is_pattern(r->key), AVAHI_ERR_IS_PATTERN);
AVAHI_CHECK_VALIDITY_RETURN_NULL(s, avahi_record_is_valid(r), AVAHI_ERR_INVALID_RECORD);
+ AVAHI_CHECK_VALIDITY_RETURN_NULL(s, r->key->clazz == AVAHI_DNS_CLASS_IN, AVAHI_ERR_INVALID_DNS_CLASS);
+ AVAHI_CHECK_VALIDITY_RETURN_NULL(s,
+ (r->key->type != 0) &&
+ (r->key->type != AVAHI_DNS_TYPE_ANY) &&
+ (r->key->type != AVAHI_DNS_TYPE_OPT) &&
+ (r->key->type != AVAHI_DNS_TYPE_TKEY) &&
+ (r->key->type != AVAHI_DNS_TYPE_TSIG) &&
+ (r->key->type != AVAHI_DNS_TYPE_IXFR) &&
+ (r->key->type != AVAHI_DNS_TYPE_AXFR), AVAHI_ERR_INVALID_DNS_TYPE);
if (flags & AVAHI_PUBLISH_UPDATE) {
AvahiRecord *old_record;
#include <avahi-common/domain.h>
#include <avahi-common/malloc.h>
+#include <avahi-common/defs.h>
#include "rr.h"
#include "log.h"
}
char *avahi_key_to_string(const AvahiKey *k) {
+ char class[16], type[16];
+ const char *c, *t;
+
assert(k);
assert(k->ref >= 1);
+
+ /* According to RFC3597 */
+
+ if (!(c = avahi_dns_class_to_string(k->clazz))) {
+ snprintf(class, sizeof(class), "CLASS%u", k->clazz);
+ c = class;
+ }
+
+ if (!(t = avahi_dns_type_to_string(k->type))) {
+ snprintf(type, sizeof(type), "TYPE%u", k->type);
+ t = type;
+ }
- return avahi_strdup_printf("%s\t%s\t%s",
- k->name,
- avahi_dns_class_to_string(k->clazz),
- avahi_dns_type_to_string(k->type));
+ return avahi_strdup_printf("%s\t%s\t%s", k->name, c, t);
}
char *avahi_record_to_string(const AvahiRecord *r) {
char *p, *s;
- char buf[257], *t = NULL, *d = NULL;
+ char buf[1024], *t = NULL, *d = NULL;
assert(r);
assert(r->ref >= 1);
r->data.srv.name);
break;
+
+ default: {
+
+ uint8_t *c;
+ uint16_t n;
+ int i;
+ char *e;
+
+ /* According to RFC3597 */
+
+ snprintf(t = buf, sizeof(buf), "\\# %u", r->data.generic.size);
+
+ e = strchr(t, 0);
+
+ for (c = r->data.generic.data, n = r->data.generic.size, i = 0;
+ n > 0 && i < 20;
+ c ++, n --) {
+
+ sprintf(e, " %02X", *c);
+ e = strchr(e, 0);
+ }
+
+ break;
+ }
}
p = avahi_key_to_string(r->key);
- s = avahi_strdup_printf("%s %s ; ttl=%u", p, t ? t : "<unparsable>", r->ttl);
+ s = avahi_strdup_printf("%s %s ; ttl=%u", p, t, r->ttl);
avahi_free(p);
avahi_free(d);
if (a == b)
return 1;
-/* g_message("equal: %p %p", a, b); */
-
return avahi_domain_equal(a->name, b->name) &&
a->type == b->type &&
a->clazz == b->clazz;
assert(pattern);
assert(k);
-/* g_message("equal: %p %p", a, b); */
-
assert(!avahi_key_is_pattern(k));
if (pattern == k)
assert(b);
assert(a->key->type == b->key->type);
-/* t = avahi_record_to_string(a); */
-/* g_message("comparing %s", t); */
-/* avahi_free(t); */
-
-/* t = avahi_record_to_string(b); */
-/* g_message("and %s", t); */
-/* avahi_free(t); */
-
-
switch (a->key->type) {
case AVAHI_DNS_TYPE_SRV:
return
return
strlen(r->data.hinfo.os) <= 255 &&
strlen(r->data.hinfo.cpu) <= 255;
-
case AVAHI_DNS_TYPE_TXT: {
AVAHI_C_DECL_BEGIN
-/** DNS record types, see RFC 1035 */
+/** DNS record types, see RFC 1035, in addition to those defined in defs.h */
enum {
- AVAHI_DNS_TYPE_A = 0x01,
- AVAHI_DNS_TYPE_NS = 0x02,
- AVAHI_DNS_TYPE_CNAME = 0x05,
- AVAHI_DNS_TYPE_SOA = 0x06,
- AVAHI_DNS_TYPE_PTR = 0x0C,
- AVAHI_DNS_TYPE_HINFO = 0x0D,
- AVAHI_DNS_TYPE_MX = 0x0F,
- AVAHI_DNS_TYPE_TXT = 0x10,
- AVAHI_DNS_TYPE_AAAA = 0x1C,
- AVAHI_DNS_TYPE_SRV = 0x21,
- AVAHI_DNS_TYPE_ANY = 0xFF /**< Special query type for requesting all records */
+ AVAHI_DNS_TYPE_ANY = 0xFF, /**< Special query type for requesting all records */
+ AVAHI_DNS_TYPE_OPT = 41, /**< EDNS0 option */
+ AVAHI_DNS_TYPE_TKEY = 249,
+ AVAHI_DNS_TYPE_TSIG = 250,
+ AVAHI_DNS_TYPE_IXFR = 251,
+ AVAHI_DNS_TYPE_AXFR = 252
};
-/** DNS record classes, see RFC 1035 */
+/** DNS record classes, see RFC 1035, in addition to those defined in defs.h */
enum {
- AVAHI_DNS_CLASS_IN = 0x01, /**< Probably the only class we will ever use */
AVAHI_DNS_CLASS_ANY = 0xFF, /**< Special query type for requesting all records */
AVAHI_DNS_CACHE_FLUSH = 0x8000, /**< Not really a class but a bit which may be set in response packets, see mDNS spec for more information */
AVAHI_DNS_UNICAST_RESPONSE = 0x8000 /**< Not really a class but a bit which may be set in query packets, see mDNS spec for more information */
};
-/** The default TTL for RRs which contain a host name of some kind. */
-#define AVAHI_DEFAULT_TTL_HOST_NAME (120)
-
-/** The default TTL for all other records. */
-#define AVAHI_DEFAULT_TTL (75*60)
-
/** Encapsulates a DNS query key consisting of class, type and
name. Use avahi_key_ref()/avahi_key_unref() for manipulating the
reference counter. The structure is intended to be treated as "immutable", no