]> git.meshlink.io Git - catta/blob - avahi-core/core.h
Add support for server state change callbacks
[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 } AvahiServerState;
47
48 /** Flags for server entries */
49 typedef enum {
50     AVAHI_ENTRY_NULL = 0,          /**< No special flags */
51     AVAHI_ENTRY_UNIQUE = 1,        /**< The RRset is intended to be unique */
52     AVAHI_ENTRY_NOPROBE = 2,       /**< Though the RRset is intended to be unique no probes shall be sent */
53     AVAHI_ENTRY_NOANNOUNCE = 4     /**< Do not announce this RR to other hosts */
54 } AvahiEntryFlags;
55
56 /** States of an entry group object */
57 typedef enum {
58     AVAHI_ENTRY_GROUP_UNCOMMITED = -1,   /**< The group has not yet been commited, the user must still call avahi_entry_group_commit() */
59     AVAHI_ENTRY_GROUP_REGISTERING = 0,   /**< The entries of the group are currently being registered */
60     AVAHI_ENTRY_GROUP_ESTABLISHED,       /**< The entries have successfully been established */
61     AVAHI_ENTRY_GROUP_COLLISION          /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */ 
62 } AvahiEntryGroupState;
63
64 /** Prototype for callback functions which are called whenever the state of an AvahiServer object changes */
65 typedef void (*AvahiServerCallback) (AvahiServer *s, AvahiServerState state, gpointer userdata);
66
67 /** Prototype for callback functions which are called whenever the state of an AvahiEntryGroup object changes */
68 typedef void (*AvahiEntryGroupCallback) (AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata);
69
70 /** Stores configuration options for a server instance */
71 typedef struct AvahiServerConfig {
72     gchar *host_name;                      /**< Default host name. If left empty defaults to the result of gethostname(2) of the libc */
73     gchar *domain_name;                    /**< Default domain name. If left empty defaults to .local */
74     gboolean use_ipv4;                     /**< Enable IPv4 support */
75     gboolean use_ipv6;                     /**< Enable IPv6 support */
76     gboolean register_hinfo;               /**< Register a HINFO record for the host containing the local OS and CPU type */
77     gboolean register_addresses;           /**< Register A, AAAA and PTR records for all local IP addresses */
78     gboolean check_response_ttl;           /**< If enabled the server ignores all incoming responses with IP TTL != 255 */
79 } AvahiServerConfig;
80
81 /** Allocate a new mDNS responder object. */
82 AvahiServer *avahi_server_new(
83     GMainContext *c,               /**< The GLIB main loop context to attach to */
84     const AvahiServerConfig *sc,   /**< If non-NULL a pointer to a configuration structure for the server */
85     AvahiServerCallback callback,  /**< A callback which is called whenever the state of the server changes */
86     gpointer userdata              /**< An opaque pointer which is passed to the callback function */);
87
88 /** Free an mDNS responder object */
89 void avahi_server_free(AvahiServer* s);
90
91 AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c);
92 AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const AvahiServerConfig *c);
93 void avahi_server_config_free(AvahiServerConfig *c);
94     
95 const gchar* avahi_server_get_domain_name(AvahiServer *s);
96 const gchar* avahi_server_get_host_name(AvahiServer *s);
97 const gchar* avahi_server_get_host_name_fqdn(AvahiServer *s);
98
99 void avahi_server_set_host_name(AvahiServer *s, const gchar *host_name);
100 void avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name);
101
102 gpointer avahi_server_get_data(AvahiServer *s);
103 void avahi_server_set_data(AvahiServer *s, gpointer userdata);
104
105 AvahiServerState avhai_server_get_state(AvahiServer *s);
106
107 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state);
108 void avahi_server_dump(AvahiServer *s, FILE *f);
109
110 AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, gpointer userdata);
111 void avahi_entry_group_free(AvahiEntryGroup *g);
112 void avahi_entry_group_commit(AvahiEntryGroup *g);
113 AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g);
114 void avahi_entry_group_set_data(AvahiEntryGroup *g, gpointer userdata);
115 gpointer avahi_entry_group_get_data(AvahiEntryGroup *g);
116
117 void avahi_server_add(
118     AvahiServer *s,
119     AvahiEntryGroup *g,
120     gint interface,
121     guchar protocol,
122     AvahiEntryFlags flags,
123     AvahiRecord *r);
124
125 void avahi_server_add_ptr(
126     AvahiServer *s,
127     AvahiEntryGroup *g,
128     gint interface,
129     guchar protocol,
130     AvahiEntryFlags flags,
131     const gchar *name,
132     const gchar *dest);
133
134 void avahi_server_add_address(
135     AvahiServer *s,
136     AvahiEntryGroup *g,
137     gint interface,
138     guchar protocol,
139     AvahiEntryFlags flags,
140     const gchar *name,
141     AvahiAddress *a);
142
143 void avahi_server_add_text(
144     AvahiServer *s,
145     AvahiEntryGroup *g,
146     gint interface,
147     guchar protocol,
148     AvahiEntryFlags flags,
149     const gchar *name,
150     ... /* text records, terminated by NULL */);
151
152 void avahi_server_add_text_va(
153     AvahiServer *s,
154     AvahiEntryGroup *g,
155     gint interface,
156     guchar protocol,
157     AvahiEntryFlags flags,
158     const gchar *name,
159     va_list va);
160
161 void avahi_server_add_text_strlst(
162     AvahiServer *s,
163     AvahiEntryGroup *g,
164     gint interface,
165     guchar protocol,
166     AvahiEntryFlags flags,
167     const gchar *name,
168     AvahiStringList *strlst);
169
170 void avahi_server_add_service(
171     AvahiServer *s,
172     AvahiEntryGroup *g,
173     gint interface,
174     guchar protocol,
175     const gchar *type,
176     const gchar *name,
177     const gchar *domain,
178     const gchar *host,
179     guint16 port,
180     ...  /* text records, terminated by NULL */);
181
182 void avahi_server_add_service_va(
183     AvahiServer *s,
184     AvahiEntryGroup *g,
185     gint interface,
186     guchar protocol,
187     const gchar *type,
188     const gchar *name,
189     const gchar *domain,
190     const gchar *host,
191     guint16 port,
192     va_list va);
193
194 void avahi_server_add_service_strlst(
195     AvahiServer *s,
196     AvahiEntryGroup *g,
197     gint interface,
198     guchar protocol,
199     const gchar *type,
200     const gchar *name,
201     const gchar *domain,
202     const gchar *host,
203     guint16 port,
204     AvahiStringList *strlst);
205
206 typedef enum {
207     AVAHI_SUBSCRIPTION_NEW,
208     AVAHI_SUBSCRIPTION_REMOVE,
209 } AvahiSubscriptionEvent;
210
211 typedef struct AvahiSubscription AvahiSubscription;
212
213 typedef void (*AvahiSubscriptionCallback)(AvahiSubscription *s, AvahiRecord *record, gint interface, guchar protocol, AvahiSubscriptionEvent event, gpointer userdata);
214
215 AvahiSubscription *avahi_subscription_new(AvahiServer *s, AvahiKey *key, gint interface, guchar protocol, AvahiSubscriptionCallback callback, gpointer userdata);
216 void avahi_subscription_free(AvahiSubscription *s);
217
218 #endif