]> git.meshlink.io Git - catta/blob - avahi-core/rr.h
* do no longer include timeval.h in watch.h by default
[catta] / avahi-core / rr.h
1 #ifndef foorrhfoo
2 #define foorrhfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of avahi.
8  
9   avahi is free software; you can redistribute it and/or modify it
10   under the terms of the GNU Lesser General Public License as
11   published by the Free Software Foundation; either version 2.1 of the
12   License, or (at your option) any later version.
13  
14   avahi is distributed in the hope that it will be useful, but WITHOUT
15   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
17   Public License for more details.
18  
19   You should have received a copy of the GNU Lesser General Public
20   License along with avahi; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22   USA.
23 ***/
24
25 /** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
26
27 #include <inttypes.h>
28 #include <sys/types.h>
29
30 #include <avahi-common/strlst.h>
31 #include <avahi-common/address.h>
32 #include <avahi-common/cdecl.h>
33
34 AVAHI_C_DECL_BEGIN
35
36 /** DNS record types, see RFC 1035 */
37 enum {
38     AVAHI_DNS_TYPE_A = 0x01,
39     AVAHI_DNS_TYPE_NS = 0x02,
40     AVAHI_DNS_TYPE_CNAME = 0x05,
41     AVAHI_DNS_TYPE_SOA = 0x06,
42     AVAHI_DNS_TYPE_PTR = 0x0C,
43     AVAHI_DNS_TYPE_HINFO = 0x0D,
44     AVAHI_DNS_TYPE_MX = 0x0F,
45     AVAHI_DNS_TYPE_TXT = 0x10,
46     AVAHI_DNS_TYPE_AAAA = 0x1C,
47     AVAHI_DNS_TYPE_SRV = 0x21,
48     AVAHI_DNS_TYPE_ANY = 0xFF /**< Special query type for requesting all records */
49 };
50
51 /** DNS record classes, see RFC 1035 */
52 enum {
53     AVAHI_DNS_CLASS_IN = 0x01,          /**< Probably the only class we will ever use */
54     AVAHI_DNS_CLASS_ANY = 0xFF,         /**< Special query type for requesting all records */
55     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 */
56     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 */
57 };
58
59 /** The default TTL for RRs which contain a host name of some kind. */
60 #define AVAHI_DEFAULT_TTL_HOST_NAME (120)
61
62 /** The default TTL for all other records. */
63 #define AVAHI_DEFAULT_TTL (75*60)
64
65 /** Encapsulates a DNS query key consisting of class, type and
66     name. Use avahi_key_ref()/avahi_key_unref() for manipulating the
67     reference counter. The structure is intended to be treated as "immutable", no
68     changes should be imposed after creation */
69 typedef struct {
70     int ref;           /**< Reference counter */
71     char *name;        /**< Record name */
72     uint16_t clazz;    /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */
73     uint16_t type;     /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */
74 } AvahiKey;
75
76 /** Encapsulates a DNS resource record. The structure is intended to
77  * be treated as "immutable", no changes should be imposed after
78  * creation. */
79 typedef struct  {
80     int ref;         /**< Reference counter */
81     AvahiKey *key;   /**< Reference to the query key of this record */
82     
83     uint32_t ttl;     /**< DNS TTL of this record */
84
85     union {
86         
87         struct {
88             void* data;
89             uint16_t size;
90         } generic; /**< Generic record data for unknown types */
91         
92         struct {
93             uint16_t priority;
94             uint16_t weight;
95             uint16_t port;
96             char *name;
97         } srv; /**< Data for SRV records */
98
99         struct {
100             char *name;
101         } ptr; /**< Data for PTR an CNAME records */
102
103         struct {
104             char *cpu;
105             char *os;
106         } hinfo; /**< Data for HINFO records */
107
108         struct {
109             AvahiStringList *string_list;
110         } txt; /**< Data for TXT records */
111
112         struct {
113             AvahiIPv4Address address;
114         } a; /**< Data for A records */
115
116         struct {
117             AvahiIPv6Address address;
118         } aaaa; /**< Data for AAAA records */
119
120     } data; /**< Record data */
121     
122 } AvahiRecord;
123
124 /** Create a new AvahiKey object. The reference counter will be set to 1. */
125 AvahiKey *avahi_key_new(const char *name, uint16_t clazz, uint16_t type);
126
127 /** Creaze new AvahiKey object based on an existing key but replaceing the type by CNAME */
128 AvahiKey *avahi_key_new_cname(AvahiKey *key);
129
130 /** Increase the reference counter of an AvahiKey object by one */
131 AvahiKey *avahi_key_ref(AvahiKey *k);
132
133 /** Decrease the reference counter of an AvahiKey object by one */
134 void avahi_key_unref(AvahiKey *k);
135
136 /** Check whether two AvahiKey object contain the same
137  * data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any
138  * other class/type. */
139 int avahi_key_equal(const AvahiKey *a, const AvahiKey *b); 
140
141 /** Match a key to a key pattern. The pattern has a type of
142 AVAHI_DNS_CLASS_ANY, the classes are taken to be equal. Same for the
143 type. If the pattern has neither class nor type with ANY constants,
144 this function is identical to avahi_key_equal(). In contrast to
145 avahi_equal() this function is not commutative. */
146 int avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k);
147
148 /** Check whether a key is a pattern key, i.e. the class/type has a
149  * value of AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY */
150 int avahi_key_is_pattern(const AvahiKey *k);
151
152 /** Return a numeric hash value for a key for usage in hash tables. */
153 unsigned avahi_key_hash(const AvahiKey *k);
154
155 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
156 AvahiRecord *avahi_record_new(AvahiKey *k, uint32_t ttl);
157
158 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
159 AvahiRecord *avahi_record_new_full(const char *name, uint16_t clazz, uint16_t type, uint32_t ttl);
160
161 /** Increase the reference counter of an AvahiRecord by one. */
162 AvahiRecord *avahi_record_ref(AvahiRecord *r);
163
164 /** Decrease the reference counter of an AvahiRecord by one. */
165 void avahi_record_unref(AvahiRecord *r);
166
167 /** Return a textual representation of the specified DNS class. The
168  * returned pointer points to a read only internal string. */
169 const char *avahi_dns_class_to_string(uint16_t clazz);
170
171 /** Return a textual representation of the specified DNS class. The
172  * returned pointer points to a read only internal string. */
173 const char *avahi_dns_type_to_string(uint16_t type);
174
175 /** Create a textual representation of the specified key. avahi_free() the
176  * result! */
177 char *avahi_key_to_string(const AvahiKey *k);
178
179 /** Create a textual representation of the specified record, similar
180  * in style to BIND zone file data. avahi_free() the result! */
181 char *avahi_record_to_string(const AvahiRecord *r); 
182
183 /** Check whether two records are equal (regardless of the TTL */
184 int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
185
186 /** Make a deep copy of an AvahiRecord object */
187 AvahiRecord *avahi_record_copy(AvahiRecord *r);
188
189 /** Returns a maximum estimate for the space that is needed to store
190  * this key in a DNS packet. */
191 size_t avahi_key_get_estimate_size(AvahiKey *k);
192
193 /** Returns a maximum estimate for the space that is needed to store
194  * the record in a DNS packet. */
195 size_t avahi_record_get_estimate_size(AvahiRecord *r);
196
197 /** Do a mDNS spec conforming lexicographical comparison of the two
198  * records. Return a negative value if a < b, a positive if a > b,
199  * zero if equal. */
200 int avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b);
201
202 /** Return 1 if the specified record is an mDNS goodbye record. i.e. TTL is zero. */
203 int avahi_record_is_goodbye(AvahiRecord *r);
204
205 /** Check whether the specified key is valid */
206 int avahi_key_is_valid(AvahiKey *k);
207
208 /** Check whether the specified record is valid */
209 int avahi_record_is_valid(AvahiRecord *r);
210
211 AVAHI_C_DECL_END
212
213 #endif