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