]> git.meshlink.io Git - catta/blob - avahi-core/rr.h
move rr.[ch] back to avahi-core/
[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 #include <glib.h>
26
27 #include <avahi-common/strlst.h>
28 #include <avahi-common/address.h>
29 #include <avahi-common/cdecl.h>
30
31 /** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
32
33 AVAHI_C_DECL_BEGIN
34
35 /** DNS record types, see RFC 1035 */
36 enum {
37     AVAHI_DNS_TYPE_A = 0x01,
38     AVAHI_DNS_TYPE_NS = 0x02,
39     AVAHI_DNS_TYPE_CNAME = 0x05,
40     AVAHI_DNS_TYPE_SOA = 0x06,
41     AVAHI_DNS_TYPE_PTR = 0x0C,
42     AVAHI_DNS_TYPE_HINFO = 0x0D,
43     AVAHI_DNS_TYPE_MX = 0x0F,
44     AVAHI_DNS_TYPE_TXT = 0x10,
45     AVAHI_DNS_TYPE_AAAA = 0x1C,
46     AVAHI_DNS_TYPE_SRV = 0x21,
47     AVAHI_DNS_TYPE_ANY = 0xFF /**< Special query type for requesting all records */
48 };
49
50 /** DNS record classes, see RFC 1035 */
51 enum {
52     AVAHI_DNS_CLASS_IN = 0x01,          /**< Probably the only class we will ever use */
53     AVAHI_DNS_CLASS_ANY = 0xFF,         /**< Special query type for requesting all records */
54     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 */
55     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 */
56 };
57
58 /** The default TTL for RRs which contain a host name of some kind. */
59 #define AVAHI_DEFAULT_TTL_HOST_NAME (120)
60
61 /** The default TTL for all other records. */
62 #define AVAHI_DEFAULT_TTL (75*60)
63
64 /** Encapsulates a DNS query key consisting of class, type and
65     name. Use avahi_key_ref()/avahi_key_unref() for manipulating the
66     reference counter. The structure is intended to be treated as "immutable", no
67     changes should be imposed after creation */
68 typedef struct {
69     guint ref;         /**< Reference counter */
70     gchar *name;       /**< Record name */
71     guint16 clazz;     /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */
72     guint16 type;      /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */
73 } AvahiKey;
74
75 /** Encapsulates a DNS resource record. The structure is intended to
76  * be treated as "immutable", no changes should be imposed after
77  * creation. */
78 typedef struct  {
79     guint ref;       /**< Reference counter */
80     AvahiKey *key;   /**< Reference to the query key of thsi record */
81     
82     guint32 ttl;     /**< DNS TTL of this record */
83
84     union {
85         
86         struct {
87             gpointer data;
88             guint16 size;
89         } generic; /**< Generic record data for unknown types */
90         
91         struct {
92             guint16 priority;
93             guint16 weight;
94             guint16 port;
95             gchar *name;
96         } srv; /**< Data for SRV records */
97
98         struct {
99             gchar *name;
100         } ptr; /**< Data for PTR an CNAME records */
101
102         struct {
103             gchar *cpu;
104             gchar *os;
105         } hinfo; /**< Data for HINFO records */
106
107         struct {
108             AvahiStringList *string_list;
109         } txt; /**< Data for TXT records */
110
111         struct {
112             AvahiIPv4Address address;
113         } a; /**< Data for A records */
114
115         struct {
116             AvahiIPv6Address address;
117         } aaaa; /**< Data for AAAA records */
118
119     } data; /**< Record data */
120     
121 } AvahiRecord;
122
123 /** Create a new AvahiKey object. The reference counter will be set to 1. */
124 AvahiKey *avahi_key_new(const gchar *name, guint16 clazz, guint16 type);
125
126 /** Increase the reference counter of an AvahiKey object by one */
127 AvahiKey *avahi_key_ref(AvahiKey *k);
128
129 /** Decrease the reference counter of an AvahiKey object by one */
130 void avahi_key_unref(AvahiKey *k);
131
132 /** Check whether two AvahiKey object contain the same
133  * data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any
134  * other class/type. */
135 gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b); 
136
137 /** Match a key to a key pattern. The pattern has a type of
138 AVAHI_DNS_CLASS_ANY, the classes are taken to be equal. Same for the
139 type. If the pattern has neither class nor type with ANY constants,
140 this function is identical to avahi_key_equal(). In contrast to
141 avahi_equal() this function is not commutative. */
142 gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k);
143
144 /** Check whether a key is a pattern key, i.e. the class/type has a
145  * value of AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY */
146 gboolean avahi_key_is_pattern(const AvahiKey *k);
147
148 /** Return a numeric hash value for a key for usage in hash tables. */
149 guint avahi_key_hash(const AvahiKey *k);
150
151 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
152 AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl);
153
154 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
155 AvahiRecord *avahi_record_new_full(const gchar *name, guint16 clazz, guint16 type, guint32 ttl);
156
157 /** Increase the reference counter of an AvahiRecord by one. */
158 AvahiRecord *avahi_record_ref(AvahiRecord *r);
159
160 /** Decrease the reference counter of an AvahiRecord by one. */
161 void avahi_record_unref(AvahiRecord *r);
162
163 /** Return a textual representation of the specified DNS class. The
164  * returned pointer points to a read only internal string. */
165 const gchar *avahi_dns_class_to_string(guint16 clazz);
166
167 /** Return a textual representation of the specified DNS class. The
168  * returned pointer points to a read only internal string. */
169 const gchar *avahi_dns_type_to_string(guint16 type);
170
171 /** Create a textual representation of the specified key. g_free() the
172  * result! */
173 gchar *avahi_key_to_string(const AvahiKey *k);
174
175 /** Create a textual representation of the specified record, similar
176  * in style to BIND zone file data. g_free() the result! */
177 gchar *avahi_record_to_string(const AvahiRecord *r); 
178
179 /** Check whether two records are equal (regardless of the TTL */
180 gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
181
182 /** Make a deep copy of an AvahiRecord object */
183 AvahiRecord *avahi_record_copy(AvahiRecord *r);
184
185 /** Returns a maximum estimate for the space that is needed to store
186  * this key in a DNS packet. */
187 guint avahi_key_get_estimate_size(AvahiKey *k);
188
189 /** Returns a maximum estimate for the space that is needed to store
190  * the record in a DNS packet. */
191 guint avahi_record_get_estimate_size(AvahiRecord *r);
192
193 /** Do a mDNS spec conforming lexicographical comparison of the two
194  * records. Return a negative value if a < b, a positive if a > b,
195  * zero if equal. */
196 gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b);
197
198 /** Return TRUE if the specified record is an mDNS goodbye record. i.e. TTL is zero. */
199 gboolean avahi_record_is_goodbye(AvahiRecord *r);
200
201 /** Check whether the specified key is valid */
202 gboolean avahi_key_valid(AvahiKey *k);
203
204 /** Check whether the specified record is valid */
205 gboolean avahi_record_valid(AvahiRecord *r);
206
207 AVAHI_C_DECL_END
208
209 #endif