]> git.meshlink.io Git - catta/blob - avahi-core/core.h
* rename the configuration variables register_xxx and announce_xxx to publish_xxx
[catta] / avahi-core / core.h
1 #ifndef foocorehfoo
2 #define foocorehfoo
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 <stdio.h>
26 #include <glib.h>
27
28 /** An mDNS responder object */
29 typedef struct AvahiServer AvahiServer;
30
31 /** A locally registered DNS resource record */
32 typedef struct AvahiEntry AvahiEntry;
33
34 /** A group of locally registered DNS RRs */
35 typedef struct AvahiEntryGroup AvahiEntryGroup;
36
37 #include <avahi-common/address.h>
38 #include <avahi-common/rr.h>
39 #include <avahi-common/alternative.h>
40
41 /** States of a server object */
42 typedef enum {
43     AVAHI_SERVER_INVALID = -1,     /**< Invalid state (initial) */ 
44     AVAHI_SERVER_REGISTERING = 0,  /**< Host RRs are being registered */
45     AVAHI_SERVER_RUNNING,          /**< All host RRs have been established */
46     AVAHI_SERVER_COLLISION,        /**< There is a collision with a host RR. All host RRs have been withdrawn, the user should set a new host name via avahi_server_set_host_name() */
47     AVAHI_SERVER_SLEEPING          /**< The host or domain name has changed and the server waits for old entries to be expired */
48 } AvahiServerState;
49
50 /** Flags for server entries */
51 typedef enum {
52     AVAHI_ENTRY_NULL = 0,          /**< No special flags */
53     AVAHI_ENTRY_UNIQUE = 1,        /**< The RRset is intended to be unique */
54     AVAHI_ENTRY_NOPROBE = 2,       /**< Though the RRset is intended to be unique no probes shall be sent */
55     AVAHI_ENTRY_NOANNOUNCE = 4     /**< Do not announce this RR to other hosts */
56 } AvahiEntryFlags;
57
58 /** States of an entry group object */
59 typedef enum {
60     AVAHI_ENTRY_GROUP_UNCOMMITED = -1,   /**< The group has not yet been commited, the user must still call avahi_entry_group_commit() */
61     AVAHI_ENTRY_GROUP_REGISTERING = 0,   /**< The entries of the group are currently being registered */
62     AVAHI_ENTRY_GROUP_ESTABLISHED,       /**< The entries have successfully been established */
63     AVAHI_ENTRY_GROUP_COLLISION          /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */ 
64 } AvahiEntryGroupState;
65
66 /** Prototype for callback functions which are called whenever the state of an AvahiServer object changes */
67 typedef void (*AvahiServerCallback) (AvahiServer *s, AvahiServerState state, gpointer userdata);
68
69 /** Prototype for callback functions which are called whenever the state of an AvahiEntryGroup object changes */
70 typedef void (*AvahiEntryGroupCallback) (AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata);
71
72 /** Stores configuration options for a server instance */
73 typedef struct AvahiServerConfig {
74     gchar *host_name;                      /**< Default host name. If left empty defaults to the result of gethostname(2) of the libc */
75     gchar *domain_name;                    /**< Default domain name. If left empty defaults to .local */
76     gboolean use_ipv4;                     /**< Enable IPv4 support */
77     gboolean use_ipv6;                     /**< Enable IPv6 support */
78     gboolean publish_hinfo;                /**< Register a HINFO record for the host containing the local OS and CPU type */
79     gboolean publish_addresses;            /**< Register A, AAAA and PTR records for all local IP addresses */
80     gboolean publish_workstation;          /**< Register a _workstation._tcp service */
81     gboolean publish_domain;               /**< Announce the local domain for browsing */
82     gboolean check_response_ttl;           /**< If enabled the server ignores all incoming responses with IP TTL != 255 */
83     gboolean use_iff_running;        /**< Require IFF_RUNNING on local network interfaces. This is the official way to check for link beat. Unfortunately this doesn't work with all drivers. So bettere leave this off. */
84     gboolean enable_reflector;             /**< Reflect incoming mDNS traffic to all local networks. This allows mDNS based network browsing beyond ethernet borders */
85     gboolean reflect_ipv;                  /**< if enable_reflector is TRUE, enable/disable reflecting between IPv4 and IPv6 */
86 } AvahiServerConfig;
87
88 /** Allocate a new mDNS responder object. */
89 AvahiServer *avahi_server_new(
90     GMainContext *c,               /**< The GLIB main loop context to attach to */
91     const AvahiServerConfig *sc,   /**< If non-NULL a pointer to a configuration structure for the server. The server makes an internal deep copy of this structure, so you may free it using avahi_server_config_done() immediately after calling this function. */
92     AvahiServerCallback callback,  /**< A callback which is called whenever the state of the server changes */
93     gpointer userdata              /**< An opaque pointer which is passed to the callback function */);
94
95 /** Free an mDNS responder object */
96 void avahi_server_free(AvahiServer* s);
97
98 /** Fill in default values for a server configuration structure. If you
99  * make use of an AvahiServerConfig structure be sure to initialize
100  * it with this function for the sake of upwards library
101  * compatibility. This call may allocate strings on the heap. To
102  * release this memory make sure to call
103  * avahi_server_config_done(). If you want to replace any strings in
104  * the structure be sure to free the strings filled in by this
105  * function with g_free() first and allocate the replacements with
106  * g_malloc() (or g_strdup()).*/
107 AvahiServerConfig* avahi_server_config_init(
108    AvahiServerConfig *c /**< A structure which shall be filled in */ );
109
110 /** Make a deep copy of the configuration structure *c to *ret. */
111 AvahiServerConfig* avahi_server_config_copy(
112     AvahiServerConfig *ret /**< destination */,
113     const AvahiServerConfig *c /**< source */);
114
115 /** Free the data in a server configuration structure. */
116 void avahi_server_config_free(AvahiServerConfig *c);
117
118 /** Return the currently chosen domain name of the server object. The
119  * return value points to an internally allocated string. Be sure to
120  * make a copy of the string before calling any other library
121  * functions. */
122 const gchar* avahi_server_get_domain_name(AvahiServer *s);
123
124 /** Return the currently chosen host name. The return value points to a internally allocated string. */
125 const gchar* avahi_server_get_host_name(AvahiServer *s);
126
127 /** Return the currently chosen host name as a FQDN ("fully qualified
128  * domain name", i.e. the concatenation of the host and domain
129  * name). The return value points to a internally allocated string. */
130 const gchar* avahi_server_get_host_name_fqdn(AvahiServer *s);
131
132 /** Change the host name of a running mDNS responder. This will drop
133 all automicatilly generated RRs and readd them with the new
134 name. Since the responder has to probe for the new RRs this function
135 takes some time to take effect altough it returns immediately. This
136 function is intended to be called when a host name conflict is
137 reported using AvahiServerCallback. The caller should readd all user
138 defined RRs too since they otherwise continue to point to the outdated
139 host name..*/
140 gint avahi_server_set_host_name(AvahiServer *s, const gchar *host_name);
141
142 /** Change the domain name of a running mDNS responder. The same rules
143  * as with avahi_server_set_host_name() apply. */
144 gint avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name);
145
146 /** Return the opaque user data pointer attached to a server object */
147 gpointer avahi_server_get_data(AvahiServer *s);
148
149 /** Change the opaque user data pointer attached to a server object */
150 void avahi_server_set_data(AvahiServer *s, gpointer userdata);
151
152 /** Return the current state of the server object */
153 AvahiServerState avahi_server_get_state(AvahiServer *s);
154
155 /** Iterate through all local entries of the server. (when g is NULL)
156  * or of a specified entry group. At the first call state should point
157  * to a NULL initialized void pointer, That pointer is used to track
158  * the current iteration. It is not safe to call any other
159  * avahi_server_xxx() function during the iteration. If the last entry
160  * has been read, NULL is returned. */
161 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state);
162
163 /** Dump the current server status to the specified FILE object */
164 void avahi_server_dump(AvahiServer *s, FILE *f);
165
166 /** Create a new entry group. The specified callback function is
167  * called whenever the state of the group changes. Use entry group
168  * objects to keep track of you RRs. Add new RRs to a group using
169  * avahi_server_add_xxx(). Make sure to call avahi_entry_group_commit()
170  * to start the registration process for your RRs */
171 AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, gpointer userdata);
172
173 /** Free an entry group. All RRs assigned to the group are removed from the server */
174 void avahi_entry_group_free(AvahiEntryGroup *g);
175
176 /** Commit an entry group. This starts the probing and registration process for all RRs in the group */
177 gint avahi_entry_group_commit(AvahiEntryGroup *g);
178
179 /** Return the current state of the specified entry group */
180 AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g);
181
182 /** Change the opaque user data pointer attached to an entry group object */
183 void avahi_entry_group_set_data(AvahiEntryGroup *g, gpointer userdata);
184
185 /** Return the opaque user data pointer currently set for the entry group object */
186 gpointer avahi_entry_group_get_data(AvahiEntryGroup *g);
187
188 gint avahi_server_add(
189     AvahiServer *s,
190     AvahiEntryGroup *g,
191     gint interface,
192     guchar protocol,
193     AvahiEntryFlags flags,
194     AvahiRecord *r);
195
196 gint avahi_server_add_ptr(
197     AvahiServer *s,
198     AvahiEntryGroup *g,
199     gint interface,
200     guchar protocol,
201     AvahiEntryFlags flags,
202     const gchar *name,
203     const gchar *dest);
204
205 gint avahi_server_add_address(
206     AvahiServer *s,
207     AvahiEntryGroup *g,
208     gint interface,
209     guchar protocol,
210     AvahiEntryFlags flags,
211     const gchar *name,
212     AvahiAddress *a);
213
214 gint avahi_server_add_text(
215     AvahiServer *s,
216     AvahiEntryGroup *g,
217     gint interface,
218     guchar protocol,
219     AvahiEntryFlags flags,
220     const gchar *name,
221     ... /* text records, terminated by NULL */);
222
223 gint avahi_server_add_text_va(
224     AvahiServer *s,
225     AvahiEntryGroup *g,
226     gint interface,
227     guchar protocol,
228     AvahiEntryFlags flags,
229     const gchar *name,
230     va_list va);
231
232 gint avahi_server_add_text_strlst(
233     AvahiServer *s,
234     AvahiEntryGroup *g,
235     gint interface,
236     guchar protocol,
237     AvahiEntryFlags flags,
238     const gchar *name,
239     AvahiStringList *strlst);
240
241 gint avahi_server_add_service(
242     AvahiServer *s,
243     AvahiEntryGroup *g,
244     gint interface,
245     guchar protocol,
246     const gchar *type,
247     const gchar *name,
248     const gchar *domain,
249     const gchar *host,
250     guint16 port,
251     ...  /* text records, terminated by NULL */);
252
253 gint avahi_server_add_service_va(
254     AvahiServer *s,
255     AvahiEntryGroup *g,
256     gint interface,
257     guchar protocol,
258     const gchar *type,
259     const gchar *name,
260     const gchar *domain,
261     const gchar *host,
262     guint16 port,
263     va_list va);
264
265 gint avahi_server_add_service_strlst(
266     AvahiServer *s,
267     AvahiEntryGroup *g,
268     gint interface,
269     guchar protocol,
270     const gchar *type,
271     const gchar *name,
272     const gchar *domain,
273     const gchar *host,
274     guint16 port,
275     AvahiStringList *strlst);
276
277 typedef enum {
278     AVAHI_BROWSER_NEW = 0,
279     AVAHI_BROWSER_REMOVE = -1
280 } AvahiBrowserEvent;
281
282 typedef enum {
283     AVAHI_RESOLVER_FOUND = 0,
284     AVAHI_RESOLVER_TIMEOUT = -1
285 } AvahiResolverEvent;
286
287
288 typedef struct AvahiRecordBrowser AvahiRecordBrowser;
289 typedef void (*AvahiRecordBrowserCallback)(AvahiRecordBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata);
290 AvahiRecordBrowser *avahi_record_browser_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordBrowserCallback callback, gpointer userdata);
291 void avahi_record_browser_free(AvahiRecordBrowser *b);
292
293 typedef struct AvahiHostNameResolver AvahiHostNameResolver;
294 typedef void (*AvahiHostNameResolverCallback)(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata);
295 AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *host_name, guchar aprotocol, AvahiHostNameResolverCallback calback, gpointer userdata);
296 void avahi_host_name_resolver_free(AvahiHostNameResolver *r);
297
298 typedef struct AvahiAddressResolver AvahiAddressResolver;
299 typedef void (*AvahiAddressResolverCallback)(AvahiAddressResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const AvahiAddress *a, const gchar *host_name, gpointer userdata);
300 AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, gint interface, guchar protocol, const AvahiAddress *address, AvahiAddressResolverCallback calback, gpointer userdata);
301 void avahi_address_resolver_free(AvahiAddressResolver *r);
302
303 /** The type of domain to browse for */
304 typedef enum {
305     AVAHI_DOMAIN_BROWSER_REGISTER,          /**< Browse for a list of available registering domains */
306     AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT,  /**< Browse for the default registering domain */
307     AVAHI_DOMAIN_BROWSER_BROWSE,            /**< Browse for a list of available browsing domains */
308     AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT     /**< Browse for the default browsing domain */
309 } AvahiDomainBrowserType;
310
311 typedef struct AvahiDomainBrowser AvahiDomainBrowser;
312 typedef void (*AvahiDomainBrowserCallback)(AvahiDomainBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata);
313 AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiDomainBrowserType type, AvahiDomainBrowserCallback callback, gpointer userdata);
314 void avahi_domain_browser_free(AvahiDomainBrowser *b);
315
316 typedef struct AvahiServiceTypeBrowser AvahiServiceTypeBrowser;
317 typedef void (*AvahiServiceTypeBrowserCallback)(AvahiServiceTypeBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *type, const gchar *domain, gpointer userdata);
318 AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata);
319 void avahi_service_type_browser_free(AvahiServiceTypeBrowser *b);
320
321 typedef struct AvahiServiceBrowser AvahiServiceBrowser;
322 typedef void (*AvahiServiceBrowserCallback)(AvahiServiceBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar *type, const gchar *domain, gpointer userdata);
323 AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata);
324 void avahi_service_browser_free(AvahiServiceBrowser *b);
325
326 typedef struct AvahiServiceResolver AvahiServiceResolver;
327 typedef void (*AvahiServiceResolverCallback)(AvahiServiceResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *host_name, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata);
328 AvahiServiceResolver *avahi_service_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *name, const gchar *type, const gchar *domain, guchar aprotocol, AvahiServiceResolverCallback calback, gpointer userdata);
329 void avahi_service_resolver_free(AvahiServiceResolver *r);
330
331 #endif