]> git.meshlink.io Git - catta/blob - avahi-core/core.h
* implement AvahiServiceBrowser
[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 check_response_ttl;           /**< If enabled the server ignores all incoming responses with IP TTL != 255 */
80     gboolean announce_domain;              /**< Announce the local domain for browsing */
81     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. */
82 } AvahiServerConfig;
83
84 /** Allocate a new mDNS responder object. */
85 AvahiServer *avahi_server_new(
86     GMainContext *c,               /**< The GLIB main loop context to attach to */
87     const AvahiServerConfig *sc,   /**< If non-NULL a pointer to a configuration structure for the server */
88     AvahiServerCallback callback,  /**< A callback which is called whenever the state of the server changes */
89     gpointer userdata              /**< An opaque pointer which is passed to the callback function */);
90
91 /** Free an mDNS responder object */
92 void avahi_server_free(AvahiServer* s);
93
94 AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c);
95 AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const AvahiServerConfig *c);
96 void avahi_server_config_free(AvahiServerConfig *c);
97     
98 const gchar* avahi_server_get_domain_name(AvahiServer *s);
99 const gchar* avahi_server_get_host_name(AvahiServer *s);
100 const gchar* avahi_server_get_host_name_fqdn(AvahiServer *s);
101
102 void avahi_server_set_host_name(AvahiServer *s, const gchar *host_name);
103 void avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name);
104
105 gpointer avahi_server_get_data(AvahiServer *s);
106 void avahi_server_set_data(AvahiServer *s, gpointer userdata);
107
108 AvahiServerState avahi_server_get_state(AvahiServer *s);
109
110 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state);
111 void avahi_server_dump(AvahiServer *s, FILE *f);
112
113 AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, gpointer userdata);
114 void avahi_entry_group_free(AvahiEntryGroup *g);
115 void avahi_entry_group_commit(AvahiEntryGroup *g);
116 AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g);
117 void avahi_entry_group_set_data(AvahiEntryGroup *g, gpointer userdata);
118 gpointer avahi_entry_group_get_data(AvahiEntryGroup *g);
119
120 void avahi_server_add(
121     AvahiServer *s,
122     AvahiEntryGroup *g,
123     gint interface,
124     guchar protocol,
125     AvahiEntryFlags flags,
126     AvahiRecord *r);
127
128 void avahi_server_add_ptr(
129     AvahiServer *s,
130     AvahiEntryGroup *g,
131     gint interface,
132     guchar protocol,
133     AvahiEntryFlags flags,
134     const gchar *name,
135     const gchar *dest);
136
137 void avahi_server_add_address(
138     AvahiServer *s,
139     AvahiEntryGroup *g,
140     gint interface,
141     guchar protocol,
142     AvahiEntryFlags flags,
143     const gchar *name,
144     AvahiAddress *a);
145
146 void avahi_server_add_text(
147     AvahiServer *s,
148     AvahiEntryGroup *g,
149     gint interface,
150     guchar protocol,
151     AvahiEntryFlags flags,
152     const gchar *name,
153     ... /* text records, terminated by NULL */);
154
155 void avahi_server_add_text_va(
156     AvahiServer *s,
157     AvahiEntryGroup *g,
158     gint interface,
159     guchar protocol,
160     AvahiEntryFlags flags,
161     const gchar *name,
162     va_list va);
163
164 void avahi_server_add_text_strlst(
165     AvahiServer *s,
166     AvahiEntryGroup *g,
167     gint interface,
168     guchar protocol,
169     AvahiEntryFlags flags,
170     const gchar *name,
171     AvahiStringList *strlst);
172
173 void avahi_server_add_service(
174     AvahiServer *s,
175     AvahiEntryGroup *g,
176     gint interface,
177     guchar protocol,
178     const gchar *type,
179     const gchar *name,
180     const gchar *domain,
181     const gchar *host,
182     guint16 port,
183     ...  /* text records, terminated by NULL */);
184
185 void avahi_server_add_service_va(
186     AvahiServer *s,
187     AvahiEntryGroup *g,
188     gint interface,
189     guchar protocol,
190     const gchar *type,
191     const gchar *name,
192     const gchar *domain,
193     const gchar *host,
194     guint16 port,
195     va_list va);
196
197 void avahi_server_add_service_strlst(
198     AvahiServer *s,
199     AvahiEntryGroup *g,
200     gint interface,
201     guchar protocol,
202     const gchar *type,
203     const gchar *name,
204     const gchar *domain,
205     const gchar *host,
206     guint16 port,
207     AvahiStringList *strlst);
208
209 typedef enum {
210     AVAHI_BROWSER_NEW = 0,
211     AVAHI_BROWSER_REMOVE = -1
212 } AvahiBrowserEvent;
213
214 typedef enum {
215     AVAHI_RESOLVER_FOUND = 0,
216     AVAHI_RESOLVER_TIMEOUT = -1
217 } AvahiResolverEvent;
218
219
220 typedef struct AvahiRecordBrowser AvahiRecordBrowser;
221 typedef void (*AvahiRecordBrowserCallback)(AvahiRecordBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata);
222 AvahiRecordBrowser *avahi_record_browser_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordBrowserCallback callback, gpointer userdata);
223 void avahi_record_browser_free(AvahiRecordBrowser *b);
224
225 typedef struct AvahiHostNameResolver AvahiHostNameResolver;
226 typedef void (*AvahiHostNameResolverCallback)(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata);
227 AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *host_name, guchar aprotocol, AvahiHostNameResolverCallback calback, gpointer userdata);
228 void avahi_host_name_resolver_free(AvahiHostNameResolver *r);
229
230 typedef struct AvahiAddressResolver AvahiAddressResolver;
231 typedef void (*AvahiAddressResolverCallback)(AvahiAddressResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const AvahiAddress *a, const gchar *host_name, gpointer userdata);
232 AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, gint interface, guchar protocol, const AvahiAddress *address, AvahiAddressResolverCallback calback, gpointer userdata);
233 void avahi_address_resolver_free(AvahiAddressResolver *r);
234
235 typedef enum {
236     AVAHI_DOMAIN_BROWSER_REGISTER,
237     AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT,
238     AVAHI_DOMAIN_BROWSER_BROWSE,
239     AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT
240 } AvahiDomainBrowserType;
241
242 typedef struct AvahiDomainBrowser AvahiDomainBrowser;
243 typedef void (*AvahiDomainBrowserCallback)(AvahiDomainBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata);
244 AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiDomainBrowserType type, AvahiDomainBrowserCallback callback, gpointer userdata);
245 void avahi_domain_browser_free(AvahiDomainBrowser *b);
246
247 typedef struct AvahiServiceTypeBrowser AvahiServiceTypeBrowser;
248 typedef void (*AvahiServiceTypeBrowserCallback)(AvahiServiceTypeBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *type, const gchar *domain, gpointer userdata);
249 AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata);
250 void avahi_service_type_browser_free(AvahiServiceTypeBrowser *b);
251
252 typedef struct AvahiServiceBrowser AvahiServiceBrowser;
253 typedef void (*AvahiServiceBrowserCallback)(AvahiServiceBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar *type, const gchar *domain, gpointer userdata);
254 AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata);
255 void avahi_service_browser_free(AvahiServiceBrowser *b);
256
257 /* Not yet implemented */
258
259 typedef struct AvahiServiceResolver AvahiServiceResolver;
260
261 #endif