]> git.meshlink.io Git - catta/blob - avahi-core/rr.h
94126a6ec90804c2ed52d0a9e54e558296e396c6
[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, in addition to those defined in defs.h */
37 enum {
38     AVAHI_DNS_TYPE_ANY = 0xFF,   /**< Special query type for requesting all records */
39     AVAHI_DNS_TYPE_OPT = 41,     /**< EDNS0 option */
40     AVAHI_DNS_TYPE_TKEY = 249,
41     AVAHI_DNS_TYPE_TSIG = 250,
42     AVAHI_DNS_TYPE_IXFR = 251,
43     AVAHI_DNS_TYPE_AXFR = 252
44 };
45
46 /** DNS record classes, see RFC 1035, in addition to those defined in defs.h */
47 enum {
48     AVAHI_DNS_CLASS_ANY = 0xFF,         /**< Special query type for requesting all records */
49     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 */
50     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 */
51 };
52
53 /** Encapsulates a DNS query key consisting of class, type and
54     name. Use avahi_key_ref()/avahi_key_unref() for manipulating the
55     reference counter. The structure is intended to be treated as "immutable", no
56     changes should be imposed after creation */
57 typedef struct AvahiKey {
58     int ref;           /**< Reference counter */
59     char *name;        /**< Record name */
60     uint16_t clazz;    /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */
61     uint16_t type;     /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */
62 } AvahiKey;
63
64 /** Encapsulates a DNS resource record. The structure is intended to
65  * be treated as "immutable", no changes should be imposed after
66  * creation. */
67 typedef struct AvahiRecord {
68     int ref;         /**< Reference counter */
69     AvahiKey *key;   /**< Reference to the query key of this record */
70
71     uint32_t ttl;     /**< DNS TTL of this record */
72
73     union {
74
75         struct {
76             void* data;
77             uint16_t size;
78         } generic; /**< Generic record data for unknown types */
79
80         struct {
81             uint16_t priority;
82             uint16_t weight;
83             uint16_t port;
84             char *name;
85         } srv; /**< Data for SRV records */
86
87         struct {
88             char *name;
89         } ptr, ns, cname; /**< Data for PTR, NS and CNAME records */
90
91         struct {
92             char *cpu;
93             char *os;
94         } hinfo; /**< Data for HINFO records */
95
96         struct {
97             AvahiStringList *string_list;
98         } txt; /**< Data for TXT records */
99
100         struct {
101             AvahiIPv4Address address;
102         } a; /**< Data for A records */
103
104         struct {
105             AvahiIPv6Address address;
106         } aaaa; /**< Data for AAAA records */
107
108     } data; /**< Record data */
109
110 } AvahiRecord;
111
112 /** Create a new AvahiKey object. The reference counter will be set to 1. */
113 AvahiKey *avahi_key_new(const char *name, uint16_t clazz, uint16_t type);
114
115 /** Increase the reference counter of an AvahiKey object by one */
116 AvahiKey *avahi_key_ref(AvahiKey *k);
117
118 /** Decrease the reference counter of an AvahiKey object by one */
119 void avahi_key_unref(AvahiKey *k);
120
121 /** Check whether two AvahiKey object contain the same
122  * data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any
123  * other class/type. */
124 int avahi_key_equal(const AvahiKey *a, const AvahiKey *b);
125
126 /** Return a numeric hash value for a key for usage in hash tables. */
127 unsigned avahi_key_hash(const AvahiKey *k);
128
129 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
130 AvahiRecord *avahi_record_new(AvahiKey *k, uint32_t ttl);
131
132 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
133 AvahiRecord *avahi_record_new_full(const char *name, uint16_t clazz, uint16_t type, uint32_t ttl);
134
135 /** Increase the reference counter of an AvahiRecord by one. */
136 AvahiRecord *avahi_record_ref(AvahiRecord *r);
137
138 /** Decrease the reference counter of an AvahiRecord by one. */
139 void avahi_record_unref(AvahiRecord *r);
140
141 /** Return a textual representation of the specified DNS class. The
142  * returned pointer points to a read only internal string. */
143 const char *avahi_dns_class_to_string(uint16_t clazz);
144
145 /** Return a textual representation of the specified DNS class. The
146  * returned pointer points to a read only internal string. */
147 const char *avahi_dns_type_to_string(uint16_t type);
148
149 /** Create a textual representation of the specified key. avahi_free() the
150  * result! */
151 char *avahi_key_to_string(const AvahiKey *k);
152
153 /** Create a textual representation of the specified record, similar
154  * in style to BIND zone file data. avahi_free() the result! */
155 char *avahi_record_to_string(const AvahiRecord *r);
156
157 /** Check whether two records are equal (regardless of the TTL */
158 int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
159
160 /** Check whether the specified key is valid */
161 int avahi_key_is_valid(AvahiKey *k);
162
163 /** Check whether the specified record is valid */
164 int avahi_record_is_valid(AvahiRecord *r);
165
166 /** Parse a binary rdata object and fill it into *record. This function is actually implemented in dns.c */
167 int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size);
168
169 /** Serialize an AvahiRecord object into binary rdata. This function is actually implemented in dns.c */
170 size_t avahi_rdata_serialize(AvahiRecord *record, void *rdata, size_t max_size);
171
172 /** Return TRUE if the AvahiRecord object is a link-local A or AAAA address */
173 int avahi_record_is_link_local_address(const AvahiRecord *r);
174
175 AVAHI_C_DECL_END
176
177 #endif