]> git.meshlink.io Git - catta/blob - avahi-core/server.h
Rename some server side objects/symbols so that they do not conflict with the same...
[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
41 #define AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS 100
42
43 typedef struct AvahiLegacyUnicastReflectSlot AvahiLegacyUnicastReflectSlot;
44
45 struct AvahiLegacyUnicastReflectSlot {
46     AvahiServer *server;
47     
48     uint16_t id, original_id;
49     AvahiAddress address;
50     uint16_t port;
51     int interface;
52     struct timeval elapse_time;
53     AvahiTimeEvent *time_event;
54 };
55
56 struct AvahiEntry {
57     AvahiServer *server;
58     AvahiSEntryGroup *group;
59
60     int dead;
61     
62     AvahiEntryFlags flags;
63     AvahiRecord *record;
64     AvahiIfIndex interface;
65     AvahiProtocol protocol;
66
67     AVAHI_LLIST_FIELDS(AvahiEntry, entries);
68     AVAHI_LLIST_FIELDS(AvahiEntry, by_key);
69     AVAHI_LLIST_FIELDS(AvahiEntry, by_group);
70     
71     AVAHI_LLIST_HEAD(AvahiAnnouncement, announcements);
72 };
73
74 struct AvahiSEntryGroup {
75     AvahiServer *server;
76     int dead;
77
78     AvahiEntryGroupState state;
79     void* userdata;
80     AvahiSEntryGroupCallback callback;
81
82     unsigned n_probing;
83     
84     unsigned n_register_try;
85     struct timeval register_time;
86     AvahiTimeEvent *register_time_event;
87     
88     AVAHI_LLIST_FIELDS(AvahiSEntryGroup, groups);
89     AVAHI_LLIST_HEAD(AvahiEntry, entries);
90 };
91
92 struct AvahiServer {
93     AvahiPoll *poll_api;
94     
95     AvahiInterfaceMonitor *monitor;
96     AvahiServerConfig config;
97
98     AVAHI_LLIST_HEAD(AvahiEntry, entries);
99     AvahiHashmap *entries_by_key;
100
101     AVAHI_LLIST_HEAD(AvahiSEntryGroup, groups);
102     
103     AVAHI_LLIST_HEAD(AvahiSRecordBrowser, record_browsers);
104     AvahiHashmap *record_browser_hashmap;
105     AVAHI_LLIST_HEAD(AvahiSHostNameResolver, host_name_resolvers);
106     AVAHI_LLIST_HEAD(AvahiSAddressResolver, address_resolvers);
107     AVAHI_LLIST_HEAD(AvahiSDomainBrowser, domain_browsers);
108     AVAHI_LLIST_HEAD(AvahiSServiceTypeBrowser, service_type_browsers);
109     AVAHI_LLIST_HEAD(AvahiSServiceBrowser, service_browsers);
110     AVAHI_LLIST_HEAD(AvahiSServiceResolver, service_resolvers);
111     AVAHI_LLIST_HEAD(AvahiSDNSServerBrowser, dns_server_browsers);
112
113     int need_entry_cleanup, need_group_cleanup, need_browser_cleanup;
114     
115     AvahiTimeEventQueue *time_event_queue;
116     
117     char *host_name, *host_name_fqdn, *domain_name;
118
119     int fd_ipv4, fd_ipv6,
120         /* The following two sockets two are used for reflection only */
121         fd_legacy_unicast_ipv4, fd_legacy_unicast_ipv6;
122
123     AvahiWatch *watch_ipv4, *watch_ipv6,
124         *watch_legacy_unicast_ipv4, *watch_legacy_unicast_ipv6;
125
126     AvahiServerState state;
127     AvahiServerCallback callback;
128     void* userdata;
129
130     AvahiSEntryGroup *hinfo_entry_group;
131     AvahiSEntryGroup *browse_domain_entry_group;
132     unsigned n_host_rr_pending;
133
134     /* Used for assembling responses */
135     AvahiRecordList *record_list;
136
137     /* Used for reflection of legacy unicast packets */
138     AvahiLegacyUnicastReflectSlot **legacy_unicast_reflect_slots;
139     uint16_t legacy_unicast_reflect_id;
140
141     int error;
142 };
143
144 int avahi_server_entry_match_interface(AvahiEntry *e, AvahiInterface *i);
145
146 void avahi_server_post_query(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key);
147
148 void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry *e, int unicast_response, int auxiliary);
149 void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, int unicast_response);
150 void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port, int legacy_unicast, int is_probe);
151
152 void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state);
153
154 int avahi_entry_is_commited(AvahiEntry *e);
155
156 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);
157
158 void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata);
159
160 void avahi_server_decrease_host_rr_pending(AvahiServer *s);
161 void avahi_server_increase_host_rr_pending(AvahiServer *s);
162
163 int avahi_server_set_errno(AvahiServer *s, int error);
164
165 #endif