]> git.meshlink.io Git - catta/blob - rr.h
fix two memory leaks
[catta] / rr.h
1 #ifndef foorrhfoo
2 #define foorrhfoo
3
4 #include <glib.h>
5
6 #include "strlst.h"
7 #include "address.h"
8
9 enum {
10     FLX_DNS_TYPE_A = 0x01,
11     FLX_DNS_TYPE_NS = 0x02,
12     FLX_DNS_TYPE_CNAME = 0x05,
13     FLX_DNS_TYPE_SOA = 0x06,
14     FLX_DNS_TYPE_PTR = 0x0C,
15     FLX_DNS_TYPE_HINFO = 0x0D,
16     FLX_DNS_TYPE_MX = 0x0F,
17     FLX_DNS_TYPE_TXT = 0x10,
18     FLX_DNS_TYPE_AAAA = 0x1C,
19     FLX_DNS_TYPE_SRV = 0x21,
20     FLX_DNS_TYPE_ANY = 0xFF
21 };
22
23 enum {
24     FLX_DNS_CLASS_IN = 0x01,
25     FLX_DNS_CACHE_FLUSH = 0x8000
26 };
27
28 #define FLX_DEFAULT_TTL (120*60)
29
30 typedef struct {
31     guint ref;
32     gchar *name;
33     guint16 class;
34     guint16 type;
35 } flxKey;
36
37 typedef struct  {
38     guint ref;
39     flxKey *key;
40     
41     guint32 ttl;
42
43     union {
44         struct {
45             gpointer data;
46             guint16 size;
47         } generic;
48
49         struct {
50             guint16 priority;
51             guint16 weight;
52             guint16 port;
53             gchar *name;
54         } srv;
55
56         struct {
57             gchar *name;
58         } ptr; /* and cname */
59
60         struct {
61             gchar *cpu;
62             gchar *os;
63         } hinfo;
64
65         struct {
66             flxStringList *string_list;
67         } txt;
68
69         struct {
70             flxIPv4Address address;
71         } a;
72
73         struct {
74             flxIPv6Address address;
75         } aaaa;
76
77     } data;
78     
79 } flxRecord;
80
81 flxKey *flx_key_new(const gchar *name, guint16 class, guint16 type);
82 flxKey *flx_key_ref(flxKey *k);
83 void flx_key_unref(flxKey *k);
84
85 gboolean flx_key_equal(const flxKey *a, const flxKey *b);  /* Treat FLX_DNS_CLASS_ANY like any other type */
86 gboolean flx_key_pattern_match(const flxKey *pattern, const flxKey *k); /* If pattern.type is FLX_DNS_CLASS_ANY, k.type is ignored */
87
88 gboolean flx_key_is_pattern(const flxKey *k);
89
90 guint flx_key_hash(const flxKey *k);
91
92 flxRecord *flx_record_new(flxKey *k);
93 flxRecord *flx_record_new_full(const gchar *name, guint16 class, guint16 type);
94 flxRecord *flx_record_ref(flxRecord *r);
95 void flx_record_unref(flxRecord *r);
96
97 const gchar *flx_dns_class_to_string(guint16 class);
98 const gchar *flx_dns_type_to_string(guint16 type);
99
100 gchar *flx_key_to_string(const flxKey *k); /* g_free() the result! */
101 gchar *flx_record_to_string(const flxRecord *r);  /* g_free() the result! */
102
103 gboolean flx_record_equal_no_ttl(const flxRecord *a, const flxRecord *b);
104
105 flxRecord *flx_record_copy(flxRecord *r);
106
107 /* returns a maximum estimate for the space that is needed to store
108  * this key in a DNS packet */
109 guint flx_key_get_estimate_size(flxKey *k);
110
111 /* ditto */
112 guint flx_record_get_estimate_size(flxRecord *r);
113
114 gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b);
115
116 #endif