From: Lennart Poettering Date: Tue, 9 Aug 2005 15:00:34 +0000 (+0000) Subject: move rr.[ch] back to avahi-core/ X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=baf1f046e0255c4e0f864044ce06fe3d360eb4da;p=catta move rr.[ch] back to avahi-core/ git-svn-id: file:///home/lennart/svn/public/avahi/trunk@286 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/avahi-common/Makefile.am b/avahi-common/Makefile.am index 6788f31..ad8d1a7 100644 --- a/avahi-common/Makefile.am +++ b/avahi-common/Makefile.am @@ -32,7 +32,6 @@ avahi_commoninclude_HEADERS = \ strlst.h \ address.h \ alternative.h \ - rr.h \ util.h \ cdecl.h \ defs.h @@ -56,7 +55,6 @@ libavahi_common_la_SOURCES = \ address.c address.h \ strlst.c strlst.h \ alternative.c alternative.h \ - rr.c rr.h \ util.c util.h \ error.c error.h libavahi_common_la_CFLAGS = $(AM_CFLAGS) diff --git a/avahi-common/rr.c b/avahi-common/rr.c deleted file mode 100644 index 1a30146..0000000 --- a/avahi-common/rr.c +++ /dev/null @@ -1,600 +0,0 @@ -/* $Id$ */ - -/*** - This file is part of avahi. - - avahi is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - avahi is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General - Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with avahi; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. -***/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "util.h" -#include "rr.h" - -AvahiKey *avahi_key_new(const gchar *name, guint16 class, guint16 type) { - AvahiKey *k; - g_assert(name); - - k = g_new(AvahiKey, 1); - k->ref = 1; - k->name = avahi_normalize_name(name); - k->clazz = class; - k->type = type; - -/* g_message("%p %% ref=1", k); */ - - return k; -} - -AvahiKey *avahi_key_ref(AvahiKey *k) { - g_assert(k); - g_assert(k->ref >= 1); - - k->ref++; - -/* g_message("%p ++ ref=%i", k, k->ref); */ - - return k; -} - -void avahi_key_unref(AvahiKey *k) { - g_assert(k); - g_assert(k->ref >= 1); - -/* g_message("%p -- ref=%i", k, k->ref-1); */ - - if ((--k->ref) <= 0) { - g_free(k->name); - g_free(k); - } -} - -AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl) { - AvahiRecord *r; - - g_assert(k); - - r = g_new(AvahiRecord, 1); - r->ref = 1; - r->key = avahi_key_ref(k); - - memset(&r->data, 0, sizeof(r->data)); - - r->ttl = ttl != (guint32) -1 ? ttl : AVAHI_DEFAULT_TTL; - - return r; -} - -AvahiRecord *avahi_record_new_full(const gchar *name, guint16 class, guint16 type, guint32 ttl) { - AvahiRecord *r; - AvahiKey *k; - - g_assert(name); - - k = avahi_key_new(name, class, type); - r = avahi_record_new(k, ttl); - avahi_key_unref(k); - - return r; -} - -AvahiRecord *avahi_record_ref(AvahiRecord *r) { - g_assert(r); - g_assert(r->ref >= 1); - - r->ref++; - return r; -} - -void avahi_record_unref(AvahiRecord *r) { - g_assert(r); - g_assert(r->ref >= 1); - - if ((--r->ref) <= 0) { - switch (r->key->type) { - - case AVAHI_DNS_TYPE_SRV: - g_free(r->data.srv.name); - break; - - case AVAHI_DNS_TYPE_PTR: - case AVAHI_DNS_TYPE_CNAME: - g_free(r->data.ptr.name); - break; - - case AVAHI_DNS_TYPE_HINFO: - g_free(r->data.hinfo.cpu); - g_free(r->data.hinfo.os); - break; - - case AVAHI_DNS_TYPE_TXT: - avahi_string_list_free(r->data.txt.string_list); - break; - - case AVAHI_DNS_TYPE_A: - case AVAHI_DNS_TYPE_AAAA: - break; - - default: - g_free(r->data.generic.data); - } - - avahi_key_unref(r->key); - g_free(r); - } -} - -const gchar *avahi_dns_class_to_string(guint16 class) { - if (class & AVAHI_DNS_CACHE_FLUSH) - return "FLUSH"; - - switch (class) { - case AVAHI_DNS_CLASS_IN: - return "IN"; - case AVAHI_DNS_CLASS_ANY: - return "ANY"; - default: - return NULL; - } -} - -const gchar *avahi_dns_type_to_string(guint16 type) { - switch (type) { - case AVAHI_DNS_TYPE_CNAME: - return "CNAME"; - case AVAHI_DNS_TYPE_A: - return "A"; - case AVAHI_DNS_TYPE_AAAA: - return "AAAA"; - case AVAHI_DNS_TYPE_PTR: - return "PTR"; - case AVAHI_DNS_TYPE_HINFO: - return "HINFO"; - case AVAHI_DNS_TYPE_TXT: - return "TXT"; - case AVAHI_DNS_TYPE_SRV: - return "SRV"; - case AVAHI_DNS_TYPE_ANY: - return "ANY"; - default: - return NULL; - } -} - -gchar *avahi_key_to_string(const AvahiKey *k) { - g_assert(k); - g_assert(k->ref >= 1); - - return g_strdup_printf("%s\t%s\t%s", - k->name, - avahi_dns_class_to_string(k->clazz), - avahi_dns_type_to_string(k->type)); -} - -gchar *avahi_record_to_string(const AvahiRecord *r) { - gchar *p, *s; - char buf[257], *t = NULL, *d = NULL; - - g_assert(r); - g_assert(r->ref >= 1); - - switch (r->key->type) { - case AVAHI_DNS_TYPE_A: - inet_ntop(AF_INET, &r->data.a.address.address, t = buf, sizeof(buf)); - break; - - case AVAHI_DNS_TYPE_AAAA: - inet_ntop(AF_INET6, &r->data.aaaa.address.address, t = buf, sizeof(buf)); - break; - - case AVAHI_DNS_TYPE_PTR: - case AVAHI_DNS_TYPE_CNAME : - - t = r->data.ptr.name; - break; - - case AVAHI_DNS_TYPE_TXT: - t = d = avahi_string_list_to_string(r->data.txt.string_list); - break; - - case AVAHI_DNS_TYPE_HINFO: - - snprintf(t = buf, sizeof(buf), "\"%s\" \"%s\"", r->data.hinfo.cpu, r->data.hinfo.os); - break; - - case AVAHI_DNS_TYPE_SRV: - - snprintf(t = buf, sizeof(buf), "%u %u %u %s", - r->data.srv.priority, - r->data.srv.weight, - r->data.srv.port, - r->data.srv.name); - - break; - } - - p = avahi_key_to_string(r->key); - s = g_strdup_printf("%s %s ; ttl=%u", p, t ? t : "", r->ttl); - g_free(p); - g_free(d); - - return s; -} - -gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b) { - g_assert(a); - g_assert(b); - - if (a == b) - return TRUE; - -/* g_message("equal: %p %p", a, b); */ - - return avahi_domain_equal(a->name, b->name) && - a->type == b->type && - a->clazz == b->clazz; -} - -gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) { - g_assert(pattern); - g_assert(k); - -/* g_message("equal: %p %p", a, b); */ - - g_assert(!avahi_key_is_pattern(k)); - - if (pattern == k) - return TRUE; - - 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) { - g_assert(k); - - return - k->type == AVAHI_DNS_TYPE_ANY || - k->clazz == AVAHI_DNS_CLASS_ANY; -} - -guint avahi_key_hash(const AvahiKey *k) { - g_assert(k); - - return - avahi_domain_hash(k->name) + - k->type + - k->clazz; -} - -static gboolean rdata_equal(const AvahiRecord *a, const AvahiRecord *b) { - g_assert(a); - g_assert(b); - g_assert(a->key->type == b->key->type); - -/* t = avahi_record_to_string(a); */ -/* g_message("comparing %s", t); */ -/* g_free(t); */ - -/* t = avahi_record_to_string(b); */ -/* g_message("and %s", t); */ -/* g_free(t); */ - - - switch (a->key->type) { - case AVAHI_DNS_TYPE_SRV: - return - a->data.srv.priority == b->data.srv.priority && - a->data.srv.weight == b->data.srv.weight && - a->data.srv.port == b->data.srv.port && - avahi_domain_equal(a->data.srv.name, b->data.srv.name); - - case AVAHI_DNS_TYPE_PTR: - case AVAHI_DNS_TYPE_CNAME: - return avahi_domain_equal(a->data.ptr.name, b->data.ptr.name); - - case AVAHI_DNS_TYPE_HINFO: - return - !strcmp(a->data.hinfo.cpu, b->data.hinfo.cpu) && - !strcmp(a->data.hinfo.os, b->data.hinfo.os); - - case AVAHI_DNS_TYPE_TXT: - return avahi_string_list_equal(a->data.txt.string_list, b->data.txt.string_list); - - case AVAHI_DNS_TYPE_A: - return memcmp(&a->data.a.address, &b->data.a.address, sizeof(AvahiIPv4Address)) == 0; - - case AVAHI_DNS_TYPE_AAAA: - return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(AvahiIPv6Address)) == 0; - - default: - return a->data.generic.size == b->data.generic.size && - (a->data.generic.size == 0 || memcmp(a->data.generic.data, b->data.generic.data, a->data.generic.size) == 0); - } - -} - -gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b) { - g_assert(a); - g_assert(b); - - if (a == b) - return TRUE; - - return - avahi_key_equal(a->key, b->key) && - rdata_equal(a, b); -} - - -AvahiRecord *avahi_record_copy(AvahiRecord *r) { - AvahiRecord *copy; - - copy = g_new(AvahiRecord, 1); - copy->ref = 1; - copy->key = avahi_key_ref(r->key); - copy->ttl = r->ttl; - - switch (r->key->type) { - case AVAHI_DNS_TYPE_PTR: - case AVAHI_DNS_TYPE_CNAME: - copy->data.ptr.name = g_strdup(r->data.ptr.name); - break; - - case AVAHI_DNS_TYPE_SRV: - copy->data.srv.priority = r->data.srv.priority; - copy->data.srv.weight = r->data.srv.weight; - copy->data.srv.port = r->data.srv.port; - copy->data.srv.name = g_strdup(r->data.srv.name); - break; - - case AVAHI_DNS_TYPE_HINFO: - copy->data.hinfo.os = g_strdup(r->data.hinfo.os); - copy->data.hinfo.cpu = g_strdup(r->data.hinfo.cpu); - break; - - case AVAHI_DNS_TYPE_TXT: - copy->data.txt.string_list = avahi_string_list_copy(r->data.txt.string_list); - break; - - case AVAHI_DNS_TYPE_A: - copy->data.a.address = r->data.a.address; - break; - - case AVAHI_DNS_TYPE_AAAA: - copy->data.aaaa.address = r->data.aaaa.address; - break; - - default: - copy->data.generic.data = g_memdup(r->data.generic.data, r->data.generic.size); - copy->data.generic.size = r->data.generic.size; - break; - - } - - return copy; -} - - -guint avahi_key_get_estimate_size(AvahiKey *k) { - g_assert(k); - - return strlen(k->name)+1+4; -} - -guint avahi_record_get_estimate_size(AvahiRecord *r) { - guint n; - g_assert(r); - - n = avahi_key_get_estimate_size(r->key) + 4 + 2; - - switch (r->key->type) { - case AVAHI_DNS_TYPE_PTR: - case AVAHI_DNS_TYPE_CNAME: - n += strlen(r->data.ptr.name) + 1; - break; - - case AVAHI_DNS_TYPE_SRV: - n += 6 + strlen(r->data.srv.name) + 1; - break; - - case AVAHI_DNS_TYPE_HINFO: - n += strlen(r->data.hinfo.os) + 1 + strlen(r->data.hinfo.cpu) + 1; - break; - - case AVAHI_DNS_TYPE_TXT: - n += avahi_string_list_serialize(r->data.txt.string_list, NULL, 0); - break; - - case AVAHI_DNS_TYPE_A: - n += sizeof(AvahiIPv4Address); - break; - - case AVAHI_DNS_TYPE_AAAA: - n += sizeof(AvahiIPv6Address); - break; - - default: - n += r->data.generic.size; - } - - return n; -} - -static gint lexicographical_memcmp(gconstpointer a, size_t al, gconstpointer b, size_t bl) { - size_t c; - gint ret; - - g_assert(a); - g_assert(b); - - c = al < bl ? al : bl; - if ((ret = memcmp(a, b, c))) - return ret; - - if (al == bl) - return 0; - else - return al == c ? 1 : -1; -} - -static gint uint16_cmp(guint16 a, guint16 b) { - return a == b ? 0 : (a < b ? -1 : 1); -} - -gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) { - gint r; -/* gchar *t1, *t2; */ - - g_assert(a); - g_assert(b); - -/* t1 = avahi_record_to_string(a); */ -/* t2 = avahi_record_to_string(b); */ -/* g_message("lexicocmp: %s %s", t1, t2); */ -/* g_free(t1); */ -/* g_free(t2); */ - - if (a == b) - return 0; - - if ((r = uint16_cmp(a->key->clazz, b->key->clazz)) || - (r = uint16_cmp(a->key->type, b->key->type))) - return r; - - switch (a->key->type) { - - case AVAHI_DNS_TYPE_PTR: - case AVAHI_DNS_TYPE_CNAME: - return avahi_binary_domain_cmp(a->data.ptr.name, b->data.ptr.name); - - case AVAHI_DNS_TYPE_SRV: { - if ((r = uint16_cmp(a->data.srv.priority, b->data.srv.priority)) == 0 && - (r = uint16_cmp(a->data.srv.weight, b->data.srv.weight)) == 0 && - (r = uint16_cmp(a->data.srv.port, b->data.srv.port)) == 0) - r = avahi_binary_domain_cmp(a->data.srv.name, b->data.srv.name); - - return r; - } - - case AVAHI_DNS_TYPE_HINFO: { - - if ((r = strcmp(a->data.hinfo.cpu, b->data.hinfo.cpu)) || - (r = strcmp(a->data.hinfo.os, b->data.hinfo.os))) - return r; - - return 0; - - } - - case AVAHI_DNS_TYPE_TXT: { - - guint8 *ma, *mb; - guint asize, bsize; - - ma = g_new(guint8, asize = avahi_string_list_serialize(a->data.txt.string_list, NULL, 0)); - mb = g_new(guint8, bsize = avahi_string_list_serialize(b->data.txt.string_list, NULL, 0)); - avahi_string_list_serialize(a->data.txt.string_list, ma, asize); - avahi_string_list_serialize(b->data.txt.string_list, mb, bsize); - - if (asize && bsize) - r = lexicographical_memcmp(ma, asize, mb, bsize); - else if (asize && !bsize) - r = 1; - else if (!asize && bsize) - r = -1; - else - r = 0; - - g_free(ma); - g_free(mb); - - return r; - } - - case AVAHI_DNS_TYPE_A: - return memcmp(&a->data.a.address, &b->data.a.address, sizeof(AvahiIPv4Address)); - - case AVAHI_DNS_TYPE_AAAA: - return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(AvahiIPv6Address)); - - default: - return lexicographical_memcmp(a->data.generic.data, a->data.generic.size, - b->data.generic.data, b->data.generic.size); - } - -} - -gboolean avahi_record_is_goodbye(AvahiRecord *r) { - g_assert(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 deleted file mode 100644 index f5349e9..0000000 --- a/avahi-common/rr.h +++ /dev/null @@ -1,209 +0,0 @@ -#ifndef foorrhfoo -#define foorrhfoo - -/* $Id$ */ - -/*** - This file is part of avahi. - - avahi is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - avahi is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General - Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with avahi; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. -***/ - -#include - -#include -#include -#include - -/** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */ - -AVAHI_C_DECL_BEGIN - -/** 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, - AVAHI_DNS_TYPE_ANY = 0xFF /**< Special query type for requesting all records */ -}; - -/** DNS record classes, see RFC 1035 */ -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 - changes should be imposed after creation */ -typedef struct { - guint ref; /**< Reference counter */ - gchar *name; /**< Record name */ - guint16 clazz; /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */ - guint16 type; /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */ -} AvahiKey; - -/** Encapsulates a DNS resource record. The structure is intended to - * be treated as "immutable", no changes should be imposed after - * creation. */ -typedef struct { - guint ref; /**< Reference counter */ - AvahiKey *key; /**< Reference to the query key of thsi record */ - - guint32 ttl; /**< DNS TTL of this record */ - - union { - - struct { - gpointer data; - guint16 size; - } generic; /**< Generic record data for unknown types */ - - struct { - guint16 priority; - guint16 weight; - guint16 port; - gchar *name; - } srv; /**< Data for SRV records */ - - struct { - gchar *name; - } ptr; /**< Data for PTR an CNAME records */ - - struct { - gchar *cpu; - gchar *os; - } hinfo; /**< Data for HINFO records */ - - struct { - AvahiStringList *string_list; - } txt; /**< Data for TXT records */ - - struct { - AvahiIPv4Address address; - } a; /**< Data for A records */ - - struct { - AvahiIPv6Address address; - } aaaa; /**< Data for AAAA records */ - - } data; /**< Record data */ - -} AvahiRecord; - -/** Create a new AvahiKey object. The reference counter will be set to 1. */ -AvahiKey *avahi_key_new(const gchar *name, guint16 clazz, guint16 type); - -/** Increase the reference counter of an AvahiKey object by one */ -AvahiKey *avahi_key_ref(AvahiKey *k); - -/** Decrease the reference counter of an AvahiKey object by one */ -void avahi_key_unref(AvahiKey *k); - -/** Check whether two AvahiKey object contain the same - * data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any - * other class/type. */ -gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b); - -/** Match a key to a key pattern. The pattern has a type of -AVAHI_DNS_CLASS_ANY, the classes are taken to be equal. Same for the -type. If the pattern has neither class nor type with ANY constants, -this function is identical to avahi_key_equal(). In contrast to -avahi_equal() this function is not commutative. */ -gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k); - -/** Check whether a key is a pattern key, i.e. the class/type has a - * value of AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY */ -gboolean avahi_key_is_pattern(const AvahiKey *k); - -/** Return a numeric hash value for a key for usage in hash tables. */ -guint avahi_key_hash(const AvahiKey *k); - -/** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */ -AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl); - -/** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */ -AvahiRecord *avahi_record_new_full(const gchar *name, guint16 clazz, guint16 type, guint32 ttl); - -/** Increase the reference counter of an AvahiRecord by one. */ -AvahiRecord *avahi_record_ref(AvahiRecord *r); - -/** Decrease the reference counter of an AvahiRecord by one. */ -void avahi_record_unref(AvahiRecord *r); - -/** Return a textual representation of the specified DNS class. The - * returned pointer points to a read only internal string. */ -const gchar *avahi_dns_class_to_string(guint16 clazz); - -/** Return a textual representation of the specified DNS class. The - * returned pointer points to a read only internal string. */ -const gchar *avahi_dns_type_to_string(guint16 type); - -/** Create a textual representation of the specified key. g_free() the - * result! */ -gchar *avahi_key_to_string(const AvahiKey *k); - -/** Create a textual representation of the specified record, similar - * in style to BIND zone file data. g_free() the result! */ -gchar *avahi_record_to_string(const AvahiRecord *r); - -/** Check whether two records are equal (regardless of the TTL */ -gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b); - -/** Make a deep copy of an AvahiRecord object */ -AvahiRecord *avahi_record_copy(AvahiRecord *r); - -/** Returns a maximum estimate for the space that is needed to store - * this key in a DNS packet. */ -guint avahi_key_get_estimate_size(AvahiKey *k); - -/** Returns a maximum estimate for the space that is needed to store - * the record in a DNS packet. */ -guint avahi_record_get_estimate_size(AvahiRecord *r); - -/** Do a mDNS spec conforming lexicographical comparison of the two - * records. Return a negative value if a < b, a positive if a > b, - * zero if equal. */ -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-core/Makefile.am b/avahi-core/Makefile.am index af7830c..2e436a6 100644 --- a/avahi-core/Makefile.am +++ b/avahi-core/Makefile.am @@ -34,7 +34,8 @@ avahiincludedir=$(includedir)/avahi-core avahiinclude_HEADERS = \ core.h \ - log.h + log.h \ + rr.h lib_LTLIBRARIES = \ libavahi-core.la @@ -68,6 +69,7 @@ libavahi_core_la_SOURCES = \ browse-service.c \ resolve-service.c \ dns.c dns.h \ + rr.c rr.h \ core.h \ log.c log.h \ browse-dns-server.c @@ -98,7 +100,8 @@ avahi_reflector_LDADD = $(AM_LDADD) $(COMMON_LDADD) libavahi-core.la dns_test_SOURCES = \ dns.c dns.h \ dns-test.c \ - log.c log.h + log.c log.h \ + rr.c rr.h dns_test_CFLAGS = $(AM_CFLAGS) dns_test_LDADD = $(AM_LDADD) $(COMMON_LDADD) diff --git a/avahi-core/core.h b/avahi-core/core.h index ec0b981..f51bd6b 100644 --- a/avahi-core/core.h +++ b/avahi-core/core.h @@ -34,7 +34,6 @@ * services using an embedded mDNS stack. */ #include -#include #ifndef DOXYGEN_SHOULD_SKIP_THIS AVAHI_C_DECL_BEGIN @@ -53,10 +52,11 @@ typedef struct AvahiEntryGroup AvahiEntryGroup; AVAHI_C_DECL_END #endif +#include #include -#include #include #include +#include #ifndef DOXYGEN_SHOULD_SKIP_THIS AVAHI_C_DECL_BEGIN diff --git a/avahi-core/rr.c b/avahi-core/rr.c new file mode 100644 index 0000000..1a30146 --- /dev/null +++ b/avahi-core/rr.c @@ -0,0 +1,600 @@ +/* $Id$ */ + +/*** + This file is part of avahi. + + avahi is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + avahi is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with avahi; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "util.h" +#include "rr.h" + +AvahiKey *avahi_key_new(const gchar *name, guint16 class, guint16 type) { + AvahiKey *k; + g_assert(name); + + k = g_new(AvahiKey, 1); + k->ref = 1; + k->name = avahi_normalize_name(name); + k->clazz = class; + k->type = type; + +/* g_message("%p %% ref=1", k); */ + + return k; +} + +AvahiKey *avahi_key_ref(AvahiKey *k) { + g_assert(k); + g_assert(k->ref >= 1); + + k->ref++; + +/* g_message("%p ++ ref=%i", k, k->ref); */ + + return k; +} + +void avahi_key_unref(AvahiKey *k) { + g_assert(k); + g_assert(k->ref >= 1); + +/* g_message("%p -- ref=%i", k, k->ref-1); */ + + if ((--k->ref) <= 0) { + g_free(k->name); + g_free(k); + } +} + +AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl) { + AvahiRecord *r; + + g_assert(k); + + r = g_new(AvahiRecord, 1); + r->ref = 1; + r->key = avahi_key_ref(k); + + memset(&r->data, 0, sizeof(r->data)); + + r->ttl = ttl != (guint32) -1 ? ttl : AVAHI_DEFAULT_TTL; + + return r; +} + +AvahiRecord *avahi_record_new_full(const gchar *name, guint16 class, guint16 type, guint32 ttl) { + AvahiRecord *r; + AvahiKey *k; + + g_assert(name); + + k = avahi_key_new(name, class, type); + r = avahi_record_new(k, ttl); + avahi_key_unref(k); + + return r; +} + +AvahiRecord *avahi_record_ref(AvahiRecord *r) { + g_assert(r); + g_assert(r->ref >= 1); + + r->ref++; + return r; +} + +void avahi_record_unref(AvahiRecord *r) { + g_assert(r); + g_assert(r->ref >= 1); + + if ((--r->ref) <= 0) { + switch (r->key->type) { + + case AVAHI_DNS_TYPE_SRV: + g_free(r->data.srv.name); + break; + + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: + g_free(r->data.ptr.name); + break; + + case AVAHI_DNS_TYPE_HINFO: + g_free(r->data.hinfo.cpu); + g_free(r->data.hinfo.os); + break; + + case AVAHI_DNS_TYPE_TXT: + avahi_string_list_free(r->data.txt.string_list); + break; + + case AVAHI_DNS_TYPE_A: + case AVAHI_DNS_TYPE_AAAA: + break; + + default: + g_free(r->data.generic.data); + } + + avahi_key_unref(r->key); + g_free(r); + } +} + +const gchar *avahi_dns_class_to_string(guint16 class) { + if (class & AVAHI_DNS_CACHE_FLUSH) + return "FLUSH"; + + switch (class) { + case AVAHI_DNS_CLASS_IN: + return "IN"; + case AVAHI_DNS_CLASS_ANY: + return "ANY"; + default: + return NULL; + } +} + +const gchar *avahi_dns_type_to_string(guint16 type) { + switch (type) { + case AVAHI_DNS_TYPE_CNAME: + return "CNAME"; + case AVAHI_DNS_TYPE_A: + return "A"; + case AVAHI_DNS_TYPE_AAAA: + return "AAAA"; + case AVAHI_DNS_TYPE_PTR: + return "PTR"; + case AVAHI_DNS_TYPE_HINFO: + return "HINFO"; + case AVAHI_DNS_TYPE_TXT: + return "TXT"; + case AVAHI_DNS_TYPE_SRV: + return "SRV"; + case AVAHI_DNS_TYPE_ANY: + return "ANY"; + default: + return NULL; + } +} + +gchar *avahi_key_to_string(const AvahiKey *k) { + g_assert(k); + g_assert(k->ref >= 1); + + return g_strdup_printf("%s\t%s\t%s", + k->name, + avahi_dns_class_to_string(k->clazz), + avahi_dns_type_to_string(k->type)); +} + +gchar *avahi_record_to_string(const AvahiRecord *r) { + gchar *p, *s; + char buf[257], *t = NULL, *d = NULL; + + g_assert(r); + g_assert(r->ref >= 1); + + switch (r->key->type) { + case AVAHI_DNS_TYPE_A: + inet_ntop(AF_INET, &r->data.a.address.address, t = buf, sizeof(buf)); + break; + + case AVAHI_DNS_TYPE_AAAA: + inet_ntop(AF_INET6, &r->data.aaaa.address.address, t = buf, sizeof(buf)); + break; + + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME : + + t = r->data.ptr.name; + break; + + case AVAHI_DNS_TYPE_TXT: + t = d = avahi_string_list_to_string(r->data.txt.string_list); + break; + + case AVAHI_DNS_TYPE_HINFO: + + snprintf(t = buf, sizeof(buf), "\"%s\" \"%s\"", r->data.hinfo.cpu, r->data.hinfo.os); + break; + + case AVAHI_DNS_TYPE_SRV: + + snprintf(t = buf, sizeof(buf), "%u %u %u %s", + r->data.srv.priority, + r->data.srv.weight, + r->data.srv.port, + r->data.srv.name); + + break; + } + + p = avahi_key_to_string(r->key); + s = g_strdup_printf("%s %s ; ttl=%u", p, t ? t : "", r->ttl); + g_free(p); + g_free(d); + + return s; +} + +gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b) { + g_assert(a); + g_assert(b); + + if (a == b) + return TRUE; + +/* g_message("equal: %p %p", a, b); */ + + return avahi_domain_equal(a->name, b->name) && + a->type == b->type && + a->clazz == b->clazz; +} + +gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) { + g_assert(pattern); + g_assert(k); + +/* g_message("equal: %p %p", a, b); */ + + g_assert(!avahi_key_is_pattern(k)); + + if (pattern == k) + return TRUE; + + 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) { + g_assert(k); + + return + k->type == AVAHI_DNS_TYPE_ANY || + k->clazz == AVAHI_DNS_CLASS_ANY; +} + +guint avahi_key_hash(const AvahiKey *k) { + g_assert(k); + + return + avahi_domain_hash(k->name) + + k->type + + k->clazz; +} + +static gboolean rdata_equal(const AvahiRecord *a, const AvahiRecord *b) { + g_assert(a); + g_assert(b); + g_assert(a->key->type == b->key->type); + +/* t = avahi_record_to_string(a); */ +/* g_message("comparing %s", t); */ +/* g_free(t); */ + +/* t = avahi_record_to_string(b); */ +/* g_message("and %s", t); */ +/* g_free(t); */ + + + switch (a->key->type) { + case AVAHI_DNS_TYPE_SRV: + return + a->data.srv.priority == b->data.srv.priority && + a->data.srv.weight == b->data.srv.weight && + a->data.srv.port == b->data.srv.port && + avahi_domain_equal(a->data.srv.name, b->data.srv.name); + + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: + return avahi_domain_equal(a->data.ptr.name, b->data.ptr.name); + + case AVAHI_DNS_TYPE_HINFO: + return + !strcmp(a->data.hinfo.cpu, b->data.hinfo.cpu) && + !strcmp(a->data.hinfo.os, b->data.hinfo.os); + + case AVAHI_DNS_TYPE_TXT: + return avahi_string_list_equal(a->data.txt.string_list, b->data.txt.string_list); + + case AVAHI_DNS_TYPE_A: + return memcmp(&a->data.a.address, &b->data.a.address, sizeof(AvahiIPv4Address)) == 0; + + case AVAHI_DNS_TYPE_AAAA: + return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(AvahiIPv6Address)) == 0; + + default: + return a->data.generic.size == b->data.generic.size && + (a->data.generic.size == 0 || memcmp(a->data.generic.data, b->data.generic.data, a->data.generic.size) == 0); + } + +} + +gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b) { + g_assert(a); + g_assert(b); + + if (a == b) + return TRUE; + + return + avahi_key_equal(a->key, b->key) && + rdata_equal(a, b); +} + + +AvahiRecord *avahi_record_copy(AvahiRecord *r) { + AvahiRecord *copy; + + copy = g_new(AvahiRecord, 1); + copy->ref = 1; + copy->key = avahi_key_ref(r->key); + copy->ttl = r->ttl; + + switch (r->key->type) { + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: + copy->data.ptr.name = g_strdup(r->data.ptr.name); + break; + + case AVAHI_DNS_TYPE_SRV: + copy->data.srv.priority = r->data.srv.priority; + copy->data.srv.weight = r->data.srv.weight; + copy->data.srv.port = r->data.srv.port; + copy->data.srv.name = g_strdup(r->data.srv.name); + break; + + case AVAHI_DNS_TYPE_HINFO: + copy->data.hinfo.os = g_strdup(r->data.hinfo.os); + copy->data.hinfo.cpu = g_strdup(r->data.hinfo.cpu); + break; + + case AVAHI_DNS_TYPE_TXT: + copy->data.txt.string_list = avahi_string_list_copy(r->data.txt.string_list); + break; + + case AVAHI_DNS_TYPE_A: + copy->data.a.address = r->data.a.address; + break; + + case AVAHI_DNS_TYPE_AAAA: + copy->data.aaaa.address = r->data.aaaa.address; + break; + + default: + copy->data.generic.data = g_memdup(r->data.generic.data, r->data.generic.size); + copy->data.generic.size = r->data.generic.size; + break; + + } + + return copy; +} + + +guint avahi_key_get_estimate_size(AvahiKey *k) { + g_assert(k); + + return strlen(k->name)+1+4; +} + +guint avahi_record_get_estimate_size(AvahiRecord *r) { + guint n; + g_assert(r); + + n = avahi_key_get_estimate_size(r->key) + 4 + 2; + + switch (r->key->type) { + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: + n += strlen(r->data.ptr.name) + 1; + break; + + case AVAHI_DNS_TYPE_SRV: + n += 6 + strlen(r->data.srv.name) + 1; + break; + + case AVAHI_DNS_TYPE_HINFO: + n += strlen(r->data.hinfo.os) + 1 + strlen(r->data.hinfo.cpu) + 1; + break; + + case AVAHI_DNS_TYPE_TXT: + n += avahi_string_list_serialize(r->data.txt.string_list, NULL, 0); + break; + + case AVAHI_DNS_TYPE_A: + n += sizeof(AvahiIPv4Address); + break; + + case AVAHI_DNS_TYPE_AAAA: + n += sizeof(AvahiIPv6Address); + break; + + default: + n += r->data.generic.size; + } + + return n; +} + +static gint lexicographical_memcmp(gconstpointer a, size_t al, gconstpointer b, size_t bl) { + size_t c; + gint ret; + + g_assert(a); + g_assert(b); + + c = al < bl ? al : bl; + if ((ret = memcmp(a, b, c))) + return ret; + + if (al == bl) + return 0; + else + return al == c ? 1 : -1; +} + +static gint uint16_cmp(guint16 a, guint16 b) { + return a == b ? 0 : (a < b ? -1 : 1); +} + +gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) { + gint r; +/* gchar *t1, *t2; */ + + g_assert(a); + g_assert(b); + +/* t1 = avahi_record_to_string(a); */ +/* t2 = avahi_record_to_string(b); */ +/* g_message("lexicocmp: %s %s", t1, t2); */ +/* g_free(t1); */ +/* g_free(t2); */ + + if (a == b) + return 0; + + if ((r = uint16_cmp(a->key->clazz, b->key->clazz)) || + (r = uint16_cmp(a->key->type, b->key->type))) + return r; + + switch (a->key->type) { + + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: + return avahi_binary_domain_cmp(a->data.ptr.name, b->data.ptr.name); + + case AVAHI_DNS_TYPE_SRV: { + if ((r = uint16_cmp(a->data.srv.priority, b->data.srv.priority)) == 0 && + (r = uint16_cmp(a->data.srv.weight, b->data.srv.weight)) == 0 && + (r = uint16_cmp(a->data.srv.port, b->data.srv.port)) == 0) + r = avahi_binary_domain_cmp(a->data.srv.name, b->data.srv.name); + + return r; + } + + case AVAHI_DNS_TYPE_HINFO: { + + if ((r = strcmp(a->data.hinfo.cpu, b->data.hinfo.cpu)) || + (r = strcmp(a->data.hinfo.os, b->data.hinfo.os))) + return r; + + return 0; + + } + + case AVAHI_DNS_TYPE_TXT: { + + guint8 *ma, *mb; + guint asize, bsize; + + ma = g_new(guint8, asize = avahi_string_list_serialize(a->data.txt.string_list, NULL, 0)); + mb = g_new(guint8, bsize = avahi_string_list_serialize(b->data.txt.string_list, NULL, 0)); + avahi_string_list_serialize(a->data.txt.string_list, ma, asize); + avahi_string_list_serialize(b->data.txt.string_list, mb, bsize); + + if (asize && bsize) + r = lexicographical_memcmp(ma, asize, mb, bsize); + else if (asize && !bsize) + r = 1; + else if (!asize && bsize) + r = -1; + else + r = 0; + + g_free(ma); + g_free(mb); + + return r; + } + + case AVAHI_DNS_TYPE_A: + return memcmp(&a->data.a.address, &b->data.a.address, sizeof(AvahiIPv4Address)); + + case AVAHI_DNS_TYPE_AAAA: + return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(AvahiIPv6Address)); + + default: + return lexicographical_memcmp(a->data.generic.data, a->data.generic.size, + b->data.generic.data, b->data.generic.size); + } + +} + +gboolean avahi_record_is_goodbye(AvahiRecord *r) { + g_assert(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-core/rr.h b/avahi-core/rr.h new file mode 100644 index 0000000..f5349e9 --- /dev/null +++ b/avahi-core/rr.h @@ -0,0 +1,209 @@ +#ifndef foorrhfoo +#define foorrhfoo + +/* $Id$ */ + +/*** + This file is part of avahi. + + avahi is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + avahi is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with avahi; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include + +#include +#include +#include + +/** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */ + +AVAHI_C_DECL_BEGIN + +/** 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, + AVAHI_DNS_TYPE_ANY = 0xFF /**< Special query type for requesting all records */ +}; + +/** DNS record classes, see RFC 1035 */ +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 + changes should be imposed after creation */ +typedef struct { + guint ref; /**< Reference counter */ + gchar *name; /**< Record name */ + guint16 clazz; /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */ + guint16 type; /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */ +} AvahiKey; + +/** Encapsulates a DNS resource record. The structure is intended to + * be treated as "immutable", no changes should be imposed after + * creation. */ +typedef struct { + guint ref; /**< Reference counter */ + AvahiKey *key; /**< Reference to the query key of thsi record */ + + guint32 ttl; /**< DNS TTL of this record */ + + union { + + struct { + gpointer data; + guint16 size; + } generic; /**< Generic record data for unknown types */ + + struct { + guint16 priority; + guint16 weight; + guint16 port; + gchar *name; + } srv; /**< Data for SRV records */ + + struct { + gchar *name; + } ptr; /**< Data for PTR an CNAME records */ + + struct { + gchar *cpu; + gchar *os; + } hinfo; /**< Data for HINFO records */ + + struct { + AvahiStringList *string_list; + } txt; /**< Data for TXT records */ + + struct { + AvahiIPv4Address address; + } a; /**< Data for A records */ + + struct { + AvahiIPv6Address address; + } aaaa; /**< Data for AAAA records */ + + } data; /**< Record data */ + +} AvahiRecord; + +/** Create a new AvahiKey object. The reference counter will be set to 1. */ +AvahiKey *avahi_key_new(const gchar *name, guint16 clazz, guint16 type); + +/** Increase the reference counter of an AvahiKey object by one */ +AvahiKey *avahi_key_ref(AvahiKey *k); + +/** Decrease the reference counter of an AvahiKey object by one */ +void avahi_key_unref(AvahiKey *k); + +/** Check whether two AvahiKey object contain the same + * data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any + * other class/type. */ +gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b); + +/** Match a key to a key pattern. The pattern has a type of +AVAHI_DNS_CLASS_ANY, the classes are taken to be equal. Same for the +type. If the pattern has neither class nor type with ANY constants, +this function is identical to avahi_key_equal(). In contrast to +avahi_equal() this function is not commutative. */ +gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k); + +/** Check whether a key is a pattern key, i.e. the class/type has a + * value of AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY */ +gboolean avahi_key_is_pattern(const AvahiKey *k); + +/** Return a numeric hash value for a key for usage in hash tables. */ +guint avahi_key_hash(const AvahiKey *k); + +/** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */ +AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl); + +/** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */ +AvahiRecord *avahi_record_new_full(const gchar *name, guint16 clazz, guint16 type, guint32 ttl); + +/** Increase the reference counter of an AvahiRecord by one. */ +AvahiRecord *avahi_record_ref(AvahiRecord *r); + +/** Decrease the reference counter of an AvahiRecord by one. */ +void avahi_record_unref(AvahiRecord *r); + +/** Return a textual representation of the specified DNS class. The + * returned pointer points to a read only internal string. */ +const gchar *avahi_dns_class_to_string(guint16 clazz); + +/** Return a textual representation of the specified DNS class. The + * returned pointer points to a read only internal string. */ +const gchar *avahi_dns_type_to_string(guint16 type); + +/** Create a textual representation of the specified key. g_free() the + * result! */ +gchar *avahi_key_to_string(const AvahiKey *k); + +/** Create a textual representation of the specified record, similar + * in style to BIND zone file data. g_free() the result! */ +gchar *avahi_record_to_string(const AvahiRecord *r); + +/** Check whether two records are equal (regardless of the TTL */ +gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b); + +/** Make a deep copy of an AvahiRecord object */ +AvahiRecord *avahi_record_copy(AvahiRecord *r); + +/** Returns a maximum estimate for the space that is needed to store + * this key in a DNS packet. */ +guint avahi_key_get_estimate_size(AvahiKey *k); + +/** Returns a maximum estimate for the space that is needed to store + * the record in a DNS packet. */ +guint avahi_record_get_estimate_size(AvahiRecord *r); + +/** Do a mDNS spec conforming lexicographical comparison of the two + * records. Return a negative value if a < b, a positive if a > b, + * zero if equal. */ +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/doxygen.cfg b/doxygen.cfg index 2242c32..a2e3678 100644 --- a/doxygen.cfg +++ b/doxygen.cfg @@ -67,7 +67,7 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = $(SRCDIR)/avahi-common/cdecl.h $(SRCDIR)/avahi-core/core.h $(SRCDIR)/avahi-common/address.h $(SRCDIR)/avahi-common/rr.h $(SRCDIR)/avahi-common/strlst.h $(SRCDIR)/avahi-common/alternative.h $(SRCDIR)/avahi-core/log.h $(SRCDIR)/avahi-common/defs.h $(SRCDIR)/avahi-client/client.h $(SRCDIR)/avahi-common/error.h +INPUT = $(SRCDIR)/avahi-common/cdecl.h $(SRCDIR)/avahi-core/core.h $(SRCDIR)/avahi-common/address.h $(SRCDIR)/avahi-core/rr.h $(SRCDIR)/avahi-common/strlst.h $(SRCDIR)/avahi-common/alternative.h $(SRCDIR)/avahi-core/log.h $(SRCDIR)/avahi-common/defs.h $(SRCDIR)/avahi-client/client.h $(SRCDIR)/avahi-common/error.h FILE_PATTERNS = RECURSIVE = NO EXCLUDE =