X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Frr.c;h=8b7fab7d861493814faac1e5ed6e0f2d6d5e4967;hb=1f36056b4cf212ae06aa9e4eca72accb17acebb0;hp=c1faa501f9be9a485e73213596f4888598eae243;hpb=d1dd07145bb3db5c6fd77c55aea762eb79ab3b5c;p=catta diff --git a/avahi-core/rr.c b/avahi-core/rr.c index c1faa50..8b7fab7 100644 --- a/avahi-core/rr.c +++ b/avahi-core/rr.c @@ -32,11 +32,14 @@ #include #include +#include #include "rr.h" #include "log.h" #include "util.h" #include "hashmap.h" +#include "domain-util.h" +#include "rr-util.h" AvahiKey *avahi_key_new(const char *name, uint16_t class, uint16_t type) { AvahiKey *k; @@ -72,7 +75,6 @@ AvahiKey *avahi_key_new_cname(AvahiKey *key) { return avahi_key_new(key->name, key->clazz, AVAHI_DNS_TYPE_CNAME); } - AvahiKey *avahi_key_ref(AvahiKey *k) { assert(k); assert(k->ref >= 1); @@ -223,18 +225,30 @@ const char *avahi_dns_type_to_string(uint16_t type) { } 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); @@ -273,10 +287,34 @@ char *avahi_record_to_string(const AvahiRecord *r) { 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 --, i++) { + + 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 : "", r->ttl); + s = avahi_strdup_printf("%s %s ; ttl=%u", p, t, r->ttl); avahi_free(p); avahi_free(d); @@ -290,8 +328,6 @@ int avahi_key_equal(const AvahiKey *a, const AvahiKey *b) { 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; @@ -301,8 +337,6 @@ int avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) { assert(pattern); assert(k); -/* g_message("equal: %p %p", a, b); */ - assert(!avahi_key_is_pattern(k)); if (pattern == k) @@ -335,15 +369,6 @@ static int rdata_equal(const AvahiRecord *a, const AvahiRecord *b) { 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 @@ -660,14 +685,13 @@ int avahi_record_is_valid(AvahiRecord *r) { 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) + if (strlst->size > 255 || strlst->size <= 0) return 0; return 1;