]> git.meshlink.io Git - catta/blob - avahi-core/server.h
remove or unexport avahi_server_add_txt_strlst(), avahi_server_add_txt_va(), avahi_se...
[catta] / avahi-core / server.h
1 #ifndef fooserverhfoo
2 #define fooserverhfoo
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 #include <avahi-common/llist.h>
26 #include <avahi-common/watch.h>
27
28 /** A locally registered DNS resource record */
29 typedef struct AvahiEntry AvahiEntry;
30
31 #include "core.h"
32 #include "iface.h"
33 #include "prioq.h"
34 #include "timeeventq.h"
35 #include "announce.h"
36 #include "browse.h"
37 #include "dns.h"
38 #include "rrlist.h"
39 #include "hashmap.h"
40 #include "wide-area.h"
41 #include "multicast-lookup.h"
42
43 #define AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS 100
44
45 #define AVAHI_FLAGS_VALID(flags, max) (!((flags) & ~(max)))
46
47 #define AVAHI_RR_HOLDOFF_MSEC 1000
48 #define AVAHI_RR_HOLDOFF_MSEC_RATE_LIMIT 60000
49 #define AVAHI_RR_RATE_LIMIT_COUNT 15
50
51 typedef struct AvahiLegacyUnicastReflectSlot AvahiLegacyUnicastReflectSlot;
52
53 struct AvahiLegacyUnicastReflectSlot {
54     AvahiServer *server;
55     
56     uint16_t id, original_id;
57     AvahiAddress address;
58     uint16_t port;
59     int interface;
60     struct timeval elapse_time;
61     AvahiTimeEvent *time_event;
62 };
63
64 struct AvahiEntry {
65     AvahiServer *server;
66     AvahiSEntryGroup *group;
67
68     int dead;
69     
70     AvahiPublishFlags flags;
71     AvahiRecord *record;
72     AvahiIfIndex interface;
73     AvahiProtocol protocol;
74
75     AVAHI_LLIST_FIELDS(AvahiEntry, entries);
76     AVAHI_LLIST_FIELDS(AvahiEntry, by_key);
77     AVAHI_LLIST_FIELDS(AvahiEntry, by_group);
78     
79     AVAHI_LLIST_HEAD(AvahiAnnouncer, announcers);
80 };
81
82 struct AvahiSEntryGroup {
83     AvahiServer *server;
84     int dead;
85
86     AvahiEntryGroupState state;
87     void* userdata;
88     AvahiSEntryGroupCallback callback;
89
90     unsigned n_probing;
91     
92     unsigned n_register_try;
93     struct timeval register_time;
94     AvahiTimeEvent *register_time_event;
95
96     struct timeval established_at;
97     
98     AVAHI_LLIST_FIELDS(AvahiSEntryGroup, groups);
99     AVAHI_LLIST_HEAD(AvahiEntry, entries);
100 };
101
102 struct AvahiServer {
103     const AvahiPoll *poll_api;
104     
105     AvahiInterfaceMonitor *monitor;
106     AvahiServerConfig config;
107
108     AVAHI_LLIST_HEAD(AvahiEntry, entries);
109     AvahiHashmap *entries_by_key;
110
111     AVAHI_LLIST_HEAD(AvahiSEntryGroup, groups);
112     
113     AVAHI_LLIST_HEAD(AvahiSRecordBrowser, record_browsers);
114     AvahiHashmap *record_browser_hashmap;
115     AVAHI_LLIST_HEAD(AvahiSHostNameResolver, host_name_resolvers);
116     AVAHI_LLIST_HEAD(AvahiSAddressResolver, address_resolvers);
117     AVAHI_LLIST_HEAD(AvahiSDomainBrowser, domain_browsers);
118     AVAHI_LLIST_HEAD(AvahiSServiceTypeBrowser, service_type_browsers);
119     AVAHI_LLIST_HEAD(AvahiSServiceBrowser, service_browsers);
120     AVAHI_LLIST_HEAD(AvahiSServiceResolver, service_resolvers);
121     AVAHI_LLIST_HEAD(AvahiSDNSServerBrowser, dns_server_browsers);
122
123     int need_entry_cleanup, need_group_cleanup, need_browser_cleanup;
124     
125     AvahiTimeEventQueue *time_event_queue;
126     
127     char *host_name, *host_name_fqdn, *domain_name;
128
129     int fd_ipv4, fd_ipv6,
130         /* The following two sockets two are used for reflection only */
131         fd_legacy_unicast_ipv4, fd_legacy_unicast_ipv6;
132
133     AvahiWatch *watch_ipv4, *watch_ipv6,
134         *watch_legacy_unicast_ipv4, *watch_legacy_unicast_ipv6;
135
136     AvahiServerState state;
137     AvahiServerCallback callback;
138     void* userdata;
139
140     AvahiSEntryGroup *hinfo_entry_group;
141     AvahiSEntryGroup *browse_domain_entry_group;
142     unsigned n_host_rr_pending;
143
144     /* Used for assembling responses */
145     AvahiRecordList *record_list;
146
147     /* Used for reflection of legacy unicast packets */
148     AvahiLegacyUnicastReflectSlot **legacy_unicast_reflect_slots;
149     uint16_t legacy_unicast_reflect_id;
150
151     /* The last error code */
152     int error;
153
154     /* The local service cookie */
155     uint32_t local_service_cookie;
156
157     AvahiMulticastLookupEngine *multicast_lookup_engine;
158     AvahiWideAreaLookupEngine *wide_area_lookup_engine;
159 };
160
161 void avahi_entry_free(AvahiServer*s, AvahiEntry *e);
162 void avahi_entry_group_free(AvahiServer *s, AvahiSEntryGroup *g);
163
164 void avahi_cleanup_dead_entries(AvahiServer *s);
165
166 void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry *e, int unicast_response, int auxiliary);
167 void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, int unicast_response);
168 void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port, int legacy_unicast, int is_probe);
169
170 void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state);
171
172 int avahi_entry_is_commited(AvahiEntry *e);
173
174 void avahi_server_enumerate_aux_records(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, void (*callback)(AvahiServer *s, AvahiRecord *r, int flush_cache, void* userdata), void* userdata);
175
176 void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata);
177
178 void avahi_server_decrease_host_rr_pending(AvahiServer *s);
179 void avahi_server_increase_host_rr_pending(AvahiServer *s);
180
181 int avahi_server_set_errno(AvahiServer *s, int error);
182
183 int avahi_server_add_ptr(
184     AvahiServer *s,
185     AvahiSEntryGroup *g,
186     AvahiIfIndex interface,
187     AvahiProtocol protocol,
188     AvahiPublishFlags flags,
189     uint32_t ttl,          
190     const char *name,      
191     const char *dest);
192
193
194 #define AVAHI_CHECK_VALIDITY_RETURN_NULL(server, expression, error) { \
195         if (!(expression)) { \
196             avahi_server_set_errno((server), (error)); \
197             return NULL; \
198         } \
199 }
200
201 #define AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(server, expression, error) {\
202     if (!(expression)) { \
203         ret = avahi_server_set_errno((server), (error)); \
204         goto fail; \
205     } \
206 }
207
208 #endif