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