X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Frr.c;h=90c62360605ef47e737871a2b0cd7040c6d809f5;hb=7df29f3e6c12a937e7cf7e476c428da57b6a5d16;hp=821ca8f0d198e7edfb70ecd57c91016bfdbcb983;hpb=6e35536bddb52c8e6bc201265c77a846d879b5a3;p=catta diff --git a/avahi-core/rr.c b/avahi-core/rr.c index 821ca8f..90c6236 100644 --- a/avahi-core/rr.c +++ b/avahi-core/rr.c @@ -36,6 +36,7 @@ #include "rr.h" #include "log.h" #include "util.h" +#include "hashmap.h" AvahiKey *avahi_key_new(const char *name, uint16_t class, uint16_t type) { AvahiKey *k; @@ -59,6 +60,19 @@ AvahiKey *avahi_key_new(const char *name, uint16_t class, uint16_t type) { return k; } +AvahiKey *avahi_key_new_cname(AvahiKey *key) { + assert(key); + + if (key->clazz != AVAHI_DNS_CLASS_IN) + return NULL; + + if (key->type == AVAHI_DNS_TYPE_CNAME) + return NULL; + + return avahi_key_new(key->name, key->clazz, AVAHI_DNS_TYPE_CNAME); +} + + AvahiKey *avahi_key_ref(AvahiKey *k) { assert(k); assert(k->ref >= 1); @@ -263,12 +277,12 @@ char *avahi_record_to_string(const AvahiRecord *r) { return s; } -gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b) { +int avahi_key_equal(const AvahiKey *a, const AvahiKey *b) { assert(a); assert(b); if (a == b) - return TRUE; + return 1; /* g_message("equal: %p %p", a, b); */ @@ -277,7 +291,7 @@ gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b) { a->clazz == b->clazz; } -gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) { +int avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) { assert(pattern); assert(k); @@ -286,14 +300,14 @@ gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) { assert(!avahi_key_is_pattern(k)); if (pattern == k) - return TRUE; + return 1; return avahi_domain_equal(pattern->name, k->name) && (pattern->type == k->type || pattern->type == AVAHI_DNS_TYPE_ANY) && (pattern->clazz == k->clazz || pattern->clazz == AVAHI_DNS_CLASS_ANY); } -gboolean avahi_key_is_pattern(const AvahiKey *k) { +int avahi_key_is_pattern(const AvahiKey *k) { assert(k); return @@ -301,7 +315,7 @@ gboolean avahi_key_is_pattern(const AvahiKey *k) { k->clazz == AVAHI_DNS_CLASS_ANY; } -guint avahi_key_hash(const AvahiKey *k) { +unsigned avahi_key_hash(const AvahiKey *k) { assert(k); return @@ -310,7 +324,7 @@ guint avahi_key_hash(const AvahiKey *k) { k->clazz; } -static gboolean rdata_equal(const AvahiRecord *a, const AvahiRecord *b) { +static int rdata_equal(const AvahiRecord *a, const AvahiRecord *b) { assert(a); assert(b); assert(a->key->type == b->key->type); @@ -357,12 +371,12 @@ static gboolean rdata_equal(const AvahiRecord *a, const AvahiRecord *b) { } -gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b) { +int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b) { assert(a); assert(b); if (a == b) - return TRUE; + return 1; return avahi_key_equal(a->key, b->key) && @@ -446,7 +460,7 @@ size_t avahi_key_get_estimate_size(AvahiKey *k) { } size_t avahi_record_get_estimate_size(AvahiRecord *r) { - guint n; + size_t n; assert(r); n = avahi_key_get_estimate_size(r->key) + 4 + 2; @@ -552,12 +566,16 @@ int avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) { case AVAHI_DNS_TYPE_TXT: { - guint8 *ma, *mb; - guint asize, bsize; + uint8_t *ma = NULL, *mb = NULL; + size_t asize, bsize; - if (!(ma = avahi_new(guint8, asize = avahi_string_list_serialize(a->data.txt.string_list, NULL, 0)))) + asize = avahi_string_list_serialize(a->data.txt.string_list, NULL, 0); + bsize = avahi_string_list_serialize(b->data.txt.string_list, NULL, 0); + + if (asize > 0 && !(ma = avahi_new(uint8_t, asize))) goto fail; - if (!(mb = g_new(guint8, bsize = avahi_string_list_serialize(b->data.txt.string_list, NULL, 0)))) { + + if (bsize > 0 && !(mb = avahi_new(uint8_t, bsize))) { avahi_free(ma); goto fail; } @@ -593,7 +611,7 @@ int avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) { fail: - avahi_log_error("Out of memory"); + avahi_log_error(__FILE__": Out of memory"); return -1; /* or whatever ... */ } @@ -607,9 +625,9 @@ int avahi_key_is_valid(AvahiKey *k) { assert(k); if (!avahi_is_valid_domain_name(k->name)) - return FALSE; + return 0; - return TRUE; + return 1; } int avahi_record_is_valid(AvahiRecord *r) {