summaryrefslogtreecommitdiffstats
path: root/avahi-common/rr.h
blob: 13e6a4c7f0b2af57ec868eb1c48bf09c1bb74cd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef foorrhfoo
#define foorrhfoo

/* $Id$ */

/***
  This file is part of avahi.
 
  avahi is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2.1 of the
  License, or (at your option) any later version.
 
  avahi is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
  Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with avahi; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
***/

#include <glib.h>

#include <avahi-common/strlst.h>
#include <avahi-common/address.h>

enum {
    AVAHI_DNS_TYPE_A = 0x01,
    AVAHI_DNS_TYPE_NS = 0x02,
    AVAHI_DNS_TYPE_CNAME = 0x05,
    AVAHI_DNS_TYPE_SOA = 0x06,
    AVAHI_DNS_TYPE_PTR = 0x0C,
    AVAHI_DNS_TYPE_HINFO = 0x0D,
    AVAHI_DNS_TYPE_MX = 0x0F,
    AVAHI_DNS_TYPE_TXT = 0x10,
    AVAHI_DNS_TYPE_AAAA = 0x1C,
    AVAHI_DNS_TYPE_SRV = 0x21,
    AVAHI_DNS_TYPE_ANY = 0xFF
};

enum {
    AVAHI_DNS_CLASS_IN = 0x01,
    AVAHI_DNS_CLASS_ANY = 0xFF,
    AVAHI_DNS_CACHE_FLUSH = 0x8000,
    AVAHI_DNS_UNICAST_RESPONSE = 0x8000
};

/** The default TTL for RRs which contain a host name of some kind. */
#define AVAHI_DEFAULT_TTL_HOST_NAME (120)

/** The default TTL for all other records. */
#define AVAHI_DEFAULT_TTL (75*60)

typedef struct {
    guint ref;
    gchar *name;
    guint16 class;
    guint16 type;
} AvahiKey;

typedef struct  {
    guint ref;
    AvahiKey *key;
    
    guint32 ttl;

    union {
        struct {
            gpointer data;
            guint16 size;
        } generic;

        struct {
            guint16 priority;
            guint16 weight;
            guint16 port;
            gchar *name;
        } srv;

        struct {
            gchar *name;
        } ptr; /* and cname */

        struct {
            gchar *cpu;
            gchar *os;
        } hinfo;

        struct {
            AvahiStringList *string_list;
        } txt;

        struct {
            AvahiIPv4Address address;
        } a;

        struct {
            AvahiIPv6Address address;
        } aaaa;

    } data;
    
} AvahiRecord;

AvahiKey *avahi_key_new(const gchar *name, guint16 class, guint16 type);
AvahiKey *avahi_key_ref(AvahiKey *k);
void avahi_key_unref(AvahiKey *k);

gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b);  /* Treat AVAHI_DNS_CLASS_ANY like any other type */
gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k); /* If pattern.type is AVAHI_DNS_CLASS_ANY, k.type is ignored */

gboolean avahi_key_is_pattern(const AvahiKey *k);

guint avahi_key_hash(const AvahiKey *k);

AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl);
AvahiRecord *avahi_record_new_full(const gchar *name, guint16 class, guint16 type, guint32 ttl);
AvahiRecord *avahi_record_ref(AvahiRecord *r);
void avahi_record_unref(AvahiRecord *r);

const gchar *avahi_dns_class_to_string(guint16 class);
const gchar *avahi_dns_type_to_string(guint16 type);

gchar *avahi_key_to_string(const AvahiKey *k); /* g_free() the result! */
gchar *avahi_record_to_string(const AvahiRecord *r);  /* g_free() the result! */

gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);

AvahiRecord *avahi_record_copy(AvahiRecord *r);

/* returns a maximum estimate for the space that is needed to store
 * this key in a DNS packet */
guint avahi_key_get_estimate_size(AvahiKey *k);

/* ditto */
guint avahi_record_get_estimate_size(AvahiRecord *r);

gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b);

gboolean avahi_record_is_goodbye(AvahiRecord *r);

#endif