]> git.meshlink.io Git - catta/blob - avahi-core/core.h
* add support for _workstation._tcp
[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-core/address.h>
38 #include <avahi-core/rr.h>
39
40 /** States of a server object */
41 typedef enum {
42     AVAHI_SERVER_INVALID = -1,     /**< Invalid state (initial) */ 
43     AVAHI_SERVER_REGISTERING = 0,  /**< Host RRs are being registered */
44     AVAHI_SERVER_RUNNING,          /**< All host RRs have been established */
45     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() */
46     AVAHI_SERVER_SLEEPING          /**< The host or domain name has changed and the server waits for old entries to be expired */
47 } AvahiServerState;
48
49 /** Flags for server entries */
50 typedef enum {
51     AVAHI_ENTRY_NULL = 0,          /**< No special flags */
52     AVAHI_ENTRY_UNIQUE = 1,        /**< The RRset is intended to be unique */
53     AVAHI_ENTRY_NOPROBE = 2,       /**< Though the RRset is intended to be unique no probes shall be sent */
54     AVAHI_ENTRY_NOANNOUNCE = 4     /**< Do not announce this RR to other hosts */
55 } AvahiEntryFlags;
56
57 /** States of an entry group object */
58 typedef enum {
59     AVAHI_ENTRY_GROUP_UNCOMMITED = -1,   /**< The group has not yet been commited, the user must still call avahi_entry_group_commit() */
60     AVAHI_ENTRY_GROUP_REGISTERING = 0,   /**< The entries of the group are currently being registered */
61     AVAHI_ENTRY_GROUP_ESTABLISHED,       /**< The entries have successfully been established */
62     AVAHI_ENTRY_GROUP_COLLISION          /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */ 
63 } AvahiEntryGroupState;
64
65 /** Prototype for callback functions which are called whenever the state of an AvahiServer object changes */
66 typedef void (*AvahiServerCallback) (AvahiServer *s, AvahiServerState state, gpointer userdata);
67
68 /** Prototype for callback functions which are called whenever the state of an AvahiEntryGroup object changes */
69 typedef void (*AvahiEntryGroupCallback) (AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata);
70
71 /** Stores configuration options for a server instance */
72 typedef struct AvahiServerConfig {
73     gchar *host_name;                      /**< Default host name. If left empty defaults to the result of gethostname(2) of the libc */
74     gchar *domain_name;                    /**< Default domain name. If left empty defaults to .local */
75     gboolean use_ipv4;                     /**< Enable IPv4 support */
76     gboolean use_ipv6;                     /**< Enable IPv6 support */
77     gboolean register_hinfo;               /**< Register a HINFO record for the host containing the local OS and CPU type */
78     gboolean register_addresses;           /**< Register A, AAAA and PTR records for all local IP addresses */
79     gboolean register_workstation;         /**< Register a _workstation._tcp service */
80     gboolean check_response_ttl;           /**< If enabled the server ignores all incoming responses with IP TTL != 255 */
81     gboolean announce_domain;              /**< Announce the local domain for browsing */
82     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. */
83     gboolean enable_reflector;             /**< Reflect incoming mDNS traffic to all local networks. This allows mDNS based network browsing beyond ethernet borders */
84     gboolean ipv_reflect;                  /**< if enable_reflector is TRUE, enable/disable reflecting between IPv4 and IPv6 */
85 } AvahiServerConfig;
86
87 /** Allocate a new mDNS responder object. */
88 AvahiServer *avahi_server_new(
89     GMainContext *c,               /**< The GLIB main loop context to attach to */
90     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. */
91     AvahiServerCallback callback,  /**< A callback which is called whenever the state of the server changes */
92     gpointer userdata              /**< An opaque pointer which is passed to the callback function */);
93
94 /** Free an mDNS responder object */
95 void avahi_server_free(AvahiServer* s);
96
97 /** Fill in default values for a server configuration structure. If you
98  * make use of an AvahiServerConfig structure be sure to initialize
99  * it with this function for the sake of upwards library
100  * compatibility. This call may allocate strings on the heap. To
101  * release this memory make sure to call
102  * avahi_server_config_done(). If you want to replace any strings in
103  * the structure be sure to free the strings filled in by this
104  * function with g_free() first and allocate the replacements with
105  * g_malloc() (or g_strdup()).*/
106 AvahiServerConfig* avahi_server_config_init(
107    AvahiServerConfig *c /**< A structure which shall be filled in */ );
108
109 /** Make a deep copy of the configuration structure *c to *ret. */
110 AvahiServerConfig* avahi_server_config_copy(
111     AvahiServerConfig *ret /**< destination */,
112     const AvahiServerConfig *c /**< source */);
113
114 /** Free the data in a server configuration structure. */
115 void avahi_server_config_free(AvahiServerConfig *c);
116
117 /** Return the currently chosen domain name of the server object. The
118  * return value points to an internally allocated string. Be sure to
119  * make a copy of the string before calling any other library
120  * functions. */
121 const gchar* avahi_server_get_domain_name(AvahiServer *s);
122
123 /** Return the currently chosen host name. The return value points to a internally allocated string. */
124 const gchar* avahi_server_get_host_name(AvahiServer *s);
125
126 /** Return the currently chosen host name as a FQDN ("fully qualified
127  * domain name", i.e. the concatenation of the host and domain
128  * name). The return value points to a internally allocated string. */
129 const gchar* avahi_server_get_host_name_fqdn(AvahiServer *s);
130
131 void avahi_server_set_host_name(AvahiServer *s, const gchar *host_name);
132 void avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name);
133
134 gpointer avahi_server_get_data(AvahiServer *s);
135 void avahi_server_set_data(AvahiServer *s, gpointer userdata);
136
137 AvahiServerState avahi_server_get_state(AvahiServer *s);
138
139 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state);
140 void avahi_server_dump(AvahiServer *s, FILE *f);
141
142 AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, gpointer userdata);
143 void avahi_entry_group_free(AvahiEntryGroup *g);
144 void avahi_entry_group_commit(AvahiEntryGroup *g);
145 AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g);
146 void avahi_entry_group_set_data(AvahiEntryGroup *g, gpointer userdata);
147 gpointer avahi_entry_group_get_data(AvahiEntryGroup *g);
148
149 void avahi_server_add(
150     AvahiServer *s,
151     AvahiEntryGroup *g,
152     gint interface,
153     guchar protocol,
154     AvahiEntryFlags flags,
155     AvahiRecord *r);
156
157 void avahi_server_add_ptr(
158     AvahiServer *s,
159     AvahiEntryGroup *g,
160     gint interface,
161     guchar protocol,
162     AvahiEntryFlags flags,
163     const gchar *name,
164     const gchar *dest);
165
166 void avahi_server_add_address(
167     AvahiServer *s,
168     AvahiEntryGroup *g,
169     gint interface,
170     guchar protocol,
171     AvahiEntryFlags flags,
172     const gchar *name,
173     AvahiAddress *a);
174
175 void avahi_server_add_text(
176     AvahiServer *s,
177     AvahiEntryGroup *g,
178     gint interface,
179     guchar protocol,
180     AvahiEntryFlags flags,
181     const gchar *name,
182     ... /* text records, terminated by NULL */);
183
184 void avahi_server_add_text_va(
185     AvahiServer *s,
186     AvahiEntryGroup *g,
187     gint interface,
188     guchar protocol,
189     AvahiEntryFlags flags,
190     const gchar *name,
191     va_list va);
192
193 void avahi_server_add_text_strlst(
194     AvahiServer *s,
195     AvahiEntryGroup *g,
196     gint interface,
197     guchar protocol,
198     AvahiEntryFlags flags,
199     const gchar *name,
200     AvahiStringList *strlst);
201
202 void avahi_server_add_service(
203     AvahiServer *s,
204     AvahiEntryGroup *g,
205     gint interface,
206     guchar protocol,
207     const gchar *type,
208     const gchar *name,
209     const gchar *domain,
210     const gchar *host,
211     guint16 port,
212     ...  /* text records, terminated by NULL */);
213
214 void avahi_server_add_service_va(
215     AvahiServer *s,
216     AvahiEntryGroup *g,
217     gint interface,
218     guchar protocol,
219     const gchar *type,
220     const gchar *name,
221     const gchar *domain,
222     const gchar *host,
223     guint16 port,
224     va_list va);
225
226 void avahi_server_add_service_strlst(
227     AvahiServer *s,
228     AvahiEntryGroup *g,
229     gint interface,
230     guchar protocol,
231     const gchar *type,
232     const gchar *name,
233     const gchar *domain,
234     const gchar *host,
235     guint16 port,
236     AvahiStringList *strlst);
237
238 typedef enum {
239     AVAHI_BROWSER_NEW = 0,
240     AVAHI_BROWSER_REMOVE = -1
241 } AvahiBrowserEvent;
242
243 typedef enum {
244     AVAHI_RESOLVER_FOUND = 0,
245     AVAHI_RESOLVER_TIMEOUT = -1
246 } AvahiResolverEvent;
247
248
249 typedef struct AvahiRecordBrowser AvahiRecordBrowser;
250 typedef void (*AvahiRecordBrowserCallback)(AvahiRecordBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata);
251 AvahiRecordBrowser *avahi_record_browser_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordBrowserCallback callback, gpointer userdata);
252 void avahi_record_browser_free(AvahiRecordBrowser *b);
253
254 typedef struct AvahiHostNameResolver AvahiHostNameResolver;
255 typedef void (*AvahiHostNameResolverCallback)(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata);
256 AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *host_name, guchar aprotocol, AvahiHostNameResolverCallback calback, gpointer userdata);
257 void avahi_host_name_resolver_free(AvahiHostNameResolver *r);
258
259 typedef struct AvahiAddressResolver AvahiAddressResolver;
260 typedef void (*AvahiAddressResolverCallback)(AvahiAddressResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const AvahiAddress *a, const gchar *host_name, gpointer userdata);
261 AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, gint interface, guchar protocol, const AvahiAddress *address, AvahiAddressResolverCallback calback, gpointer userdata);
262 void avahi_address_resolver_free(AvahiAddressResolver *r);
263
264 typedef enum {
265     AVAHI_DOMAIN_BROWSER_REGISTER,
266     AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT,
267     AVAHI_DOMAIN_BROWSER_BROWSE,
268     AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT
269 } AvahiDomainBrowserType;
270
271 typedef struct AvahiDomainBrowser AvahiDomainBrowser;
272 typedef void (*AvahiDomainBrowserCallback)(AvahiDomainBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata);
273 AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiDomainBrowserType type, AvahiDomainBrowserCallback callback, gpointer userdata);
274 void avahi_domain_browser_free(AvahiDomainBrowser *b);
275
276 typedef struct AvahiServiceTypeBrowser AvahiServiceTypeBrowser;
277 typedef void (*AvahiServiceTypeBrowserCallback)(AvahiServiceTypeBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *type, const gchar *domain, gpointer userdata);
278 AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata);
279 void avahi_service_type_browser_free(AvahiServiceTypeBrowser *b);
280
281 typedef struct AvahiServiceBrowser AvahiServiceBrowser;
282 typedef void (*AvahiServiceBrowserCallback)(AvahiServiceBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar *type, const gchar *domain, gpointer userdata);
283 AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata);
284 void avahi_service_browser_free(AvahiServiceBrowser *b);
285
286 typedef struct AvahiServiceResolver AvahiServiceResolver;
287 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);
288 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);
289 void avahi_service_resolver_free(AvahiServiceResolver *r);
290
291 #endif