]> git.meshlink.io Git - catta/blob - include/catta/rr.h
rename everything avahi to catta
[catta] / include / catta / rr.h
1 #ifndef foorrhfoo
2 #define foorrhfoo
3
4 /***
5   This file is part of catta.
6
7   catta is free software; you can redistribute it and/or modify it
8   under the terms of the GNU Lesser General Public License as
9   published by the Free Software Foundation; either version 2.1 of the
10   License, or (at your option) any later version.
11
12   catta is distributed in the hope that it will be useful, but WITHOUT
13   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15   Public License for more details.
16
17   You should have received a copy of the GNU Lesser General Public
18   License along with catta; if not, write to the Free Software
19   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20   USA.
21 ***/
22
23 /** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
24
25 #include <inttypes.h>
26 #include <sys/types.h>
27
28 #include <catta/strlst.h>
29 #include <catta/address.h>
30 #include <catta/cdecl.h>
31
32 CATTA_C_DECL_BEGIN
33
34 /** DNS record types, see RFC 1035, in addition to those defined in defs.h */
35 enum {
36     CATTA_DNS_TYPE_ANY = 0xFF,   /**< Special query type for requesting all records */
37     CATTA_DNS_TYPE_OPT = 41,     /**< EDNS0 option */
38     CATTA_DNS_TYPE_TKEY = 249,
39     CATTA_DNS_TYPE_TSIG = 250,
40     CATTA_DNS_TYPE_IXFR = 251,
41     CATTA_DNS_TYPE_AXFR = 252
42 };
43
44 /** DNS record classes, see RFC 1035, in addition to those defined in defs.h */
45 enum {
46     CATTA_DNS_CLASS_ANY = 0xFF,         /**< Special query type for requesting all records */
47     CATTA_DNS_CACHE_FLUSH = 0x8000,     /**< Not really a class but a bit which may be set in response packets, see mDNS spec for more information */
48     CATTA_DNS_UNICAST_RESPONSE = 0x8000 /**< Not really a class but a bit which may be set in query packets, see mDNS spec for more information */
49 };
50
51 /** Encapsulates a DNS query key consisting of class, type and
52     name. Use catta_key_ref()/catta_key_unref() for manipulating the
53     reference counter. The structure is intended to be treated as "immutable", no
54     changes should be imposed after creation */
55 typedef struct CattaKey {
56     int ref;           /**< Reference counter */
57     char *name;        /**< Record name */
58     uint16_t clazz;    /**< Record class, one of the CATTA_DNS_CLASS_xxx constants */
59     uint16_t type;     /**< Record type, one of the CATTA_DNS_TYPE_xxx constants */
60 } CattaKey;
61
62 /** Encapsulates a DNS resource record. The structure is intended to
63  * be treated as "immutable", no changes should be imposed after
64  * creation. */
65 typedef struct CattaRecord {
66     int ref;         /**< Reference counter */
67     CattaKey *key;   /**< Reference to the query key of this record */
68
69     uint32_t ttl;     /**< DNS TTL of this record */
70
71     union {
72
73         struct {
74             void* data;
75             uint16_t size;
76         } generic; /**< Generic record data for unknown types */
77
78         struct {
79             uint16_t priority;
80             uint16_t weight;
81             uint16_t port;
82             char *name;
83         } srv; /**< Data for SRV records */
84
85         struct {
86             char *name;
87         } ptr, ns, cname; /**< Data for PTR, NS and CNAME records */
88
89         struct {
90             char *cpu;
91             char *os;
92         } hinfo; /**< Data for HINFO records */
93
94         struct {
95             CattaStringList *string_list;
96         } txt; /**< Data for TXT records */
97
98         struct {
99             CattaIPv4Address address;
100         } a; /**< Data for A records */
101
102         struct {
103             CattaIPv6Address address;
104         } aaaa; /**< Data for AAAA records */
105
106     } data; /**< Record data */
107
108 } CattaRecord;
109
110 /** Create a new CattaKey object. The reference counter will be set to 1. */
111 CattaKey *catta_key_new(const char *name, uint16_t clazz, uint16_t type);
112
113 /** Increase the reference counter of an CattaKey object by one */
114 CattaKey *catta_key_ref(CattaKey *k);
115
116 /** Decrease the reference counter of an CattaKey object by one */
117 void catta_key_unref(CattaKey *k);
118
119 /** Check whether two CattaKey object contain the same
120  * data. CATTA_DNS_CLASS_ANY/CATTA_DNS_TYPE_ANY are treated like any
121  * other class/type. */
122 int catta_key_equal(const CattaKey *a, const CattaKey *b);
123
124 /** Return a numeric hash value for a key for usage in hash tables. */
125 unsigned catta_key_hash(const CattaKey *k);
126
127 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
128 CattaRecord *catta_record_new(CattaKey *k, uint32_t ttl);
129
130 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
131 CattaRecord *catta_record_new_full(const char *name, uint16_t clazz, uint16_t type, uint32_t ttl);
132
133 /** Increase the reference counter of an CattaRecord by one. */
134 CattaRecord *catta_record_ref(CattaRecord *r);
135
136 /** Decrease the reference counter of an CattaRecord by one. */
137 void catta_record_unref(CattaRecord *r);
138
139 /** Return a textual representation of the specified DNS class. The
140  * returned pointer points to a read only internal string. */
141 const char *catta_dns_class_to_string(uint16_t clazz);
142
143 /** Return a textual representation of the specified DNS class. The
144  * returned pointer points to a read only internal string. */
145 const char *catta_dns_type_to_string(uint16_t type);
146
147 /** Create a textual representation of the specified key. catta_free() the
148  * result! */
149 char *catta_key_to_string(const CattaKey *k);
150
151 /** Create a textual representation of the specified record, similar
152  * in style to BIND zone file data. catta_free() the result! */
153 char *catta_record_to_string(const CattaRecord *r);
154
155 /** Check whether two records are equal (regardless of the TTL */
156 int catta_record_equal_no_ttl(const CattaRecord *a, const CattaRecord *b);
157
158 /** Check whether the specified key is valid */
159 int catta_key_is_valid(CattaKey *k);
160
161 /** Check whether the specified record is valid */
162 int catta_record_is_valid(CattaRecord *r);
163
164 /** Parse a binary rdata object and fill it into *record. This function is actually implemented in dns.c */
165 int catta_rdata_parse(CattaRecord *record, const void* rdata, size_t size);
166
167 /** Serialize an CattaRecord object into binary rdata. This function is actually implemented in dns.c */
168 size_t catta_rdata_serialize(CattaRecord *record, void *rdata, size_t max_size);
169
170 /** Return TRUE if the CattaRecord object is a link-local A or AAAA address */
171 int catta_record_is_link_local_address(const CattaRecord *r);
172
173 CATTA_C_DECL_END
174
175 #endif