]> git.meshlink.io Git - catta/blob - rr.h
fix some memory corruption bugs
[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 };
26
27 #define FLX_DEFAULT_TTL (120*60)
28
29 typedef struct {
30     guint ref;
31     gchar *name;
32     guint16 class;
33     guint16 type;
34 } flxKey;
35
36 typedef struct  {
37     guint ref;
38     flxKey *key;
39     
40     guint32 ttl;
41
42     union {
43         struct {
44             gpointer data;
45             guint16 size;
46         } generic;
47
48         struct {
49             guint16 priority;
50             guint16 weight;
51             guint16 port;
52             gchar *name;
53         } srv;
54
55         struct {
56             gchar *name;
57         } ptr; /* and cname */
58
59         struct {
60             gchar *cpu;
61             gchar *os;
62         } hinfo;
63
64         struct {
65             flxStringList *string_list;
66         } txt;
67
68         struct {
69             flxIPv4Address address;
70         } a;
71
72         struct {
73             flxIPv6Address address;
74         } aaaa;
75
76     } data;
77     
78 } flxRecord;
79
80 flxKey *flx_key_new(const gchar *name, guint16 class, guint16 type);
81 flxKey *flx_key_ref(flxKey *k);
82 void flx_key_unref(flxKey *k);
83
84 gboolean flx_key_equal(const flxKey *a, const flxKey *b);  /* Treat FLX_DNS_CLASS_ANY like any other type */
85 gboolean flx_key_pattern_match(const flxKey *pattern, const flxKey *k); /* If pattern.type is FLX_DNS_CLASS_ANY, k.type is ignored */
86
87 gboolean flx_key_is_pattern(const flxKey *k);
88
89 guint flx_key_hash(const flxKey *k);
90
91 flxRecord *flx_record_new(flxKey *k);
92 flxRecord *flx_record_new_full(const gchar *name, guint16 class, guint16 type);
93 flxRecord *flx_record_ref(flxRecord *r);
94 void flx_record_unref(flxRecord *r);
95
96 const gchar *flx_dns_class_to_string(guint16 class);
97 const gchar *flx_dns_type_to_string(guint16 type);
98
99 gchar *flx_key_to_string(const flxKey *k); /* g_free() the result! */
100 gchar *flx_record_to_string(const flxRecord *r);  /* g_free() the result! */
101
102 gboolean flx_record_equal_no_ttl(const flxRecord *a, const flxRecord *b);
103
104 flxRecord *flx_record_copy(flxRecord *r);
105
106 #endif