1#ifndef foopublishhfoo
2#define foopublishhfoo
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/** \file core/publish.h Functions for publising local services and RRs */
26
27/** \example core-publish-service.c Example how to register a DNS-SD
28 * service using an embedded mDNS stack. It behaves like a network
29 * printer registering both an IPP and a BSD LPR service. */
30
31/** A group of locally registered DNS RRs */
32typedef struct AvahiSEntryGroup AvahiSEntryGroup;
33
34#include <avahi-common/cdecl.h>
35#include <avahi-core/core.h>
36
37AVAHI_C_DECL_BEGIN
38
39/** Prototype for callback functions which are called whenever the state of an AvahiSEntryGroup object changes */
40typedef void (*AvahiSEntryGroupCallback) (AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata);
41
42/** Iterate through all local entries of the server. (when g is NULL)
43 * or of a specified entry group. At the first call state should point
44 * to a NULL initialized void pointer, That pointer is used to track
45 * the current iteration. It is not safe to call any other
46 * avahi_server_xxx() function during the iteration. If the last entry
47 * has been read, NULL is returned. */
48const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiSEntryGroup *g, void **state);
49
50/** Create a new entry group. The specified callback function is
51 * called whenever the state of the group changes. Use entry group
52 * objects to keep track of you RRs. Add new RRs to a group using
53 * avahi_server_add_xxx(). Make sure to call avahi_s_entry_group_commit()
54 * to start the registration process for your RRs */
55AvahiSEntryGroup *avahi_s_entry_group_new(AvahiServer *s, AvahiSEntryGroupCallback callback, void* userdata);
56
57/** Free an entry group. All RRs assigned to the group are removed from the server */
58void avahi_s_entry_group_free(AvahiSEntryGroup *g);
59
60/** Commit an entry group. This starts the probing and registration process for all RRs in the group */
61int avahi_s_entry_group_commit(AvahiSEntryGroup *g);
62
63/** Remove all entries from the entry group and reset the state to AVAHI_ENTRY_GROUP_UNCOMMITED. */
64void avahi_s_entry_group_reset(AvahiSEntryGroup *g);
65
66/** Return 1 if the entry group is empty, i.e. has no records attached. */
67int avahi_s_entry_group_is_empty(AvahiSEntryGroup *g);
68
69/** Return the current state of the specified entry group */
70AvahiEntryGroupState avahi_s_entry_group_get_state(AvahiSEntryGroup *g);
71
72/** Change the opaque user data pointer attached to an entry group object */
73void avahi_s_entry_group_set_data(AvahiSEntryGroup *g, void* userdata);
74
75/** Return the opaque user data pointer currently set for the entry group object */
76void* avahi_s_entry_group_get_data(AvahiSEntryGroup *g);
77
78/** Add a new resource record to the server. Returns 0 on success, negative otherwise. */
79int avahi_server_add(
80    AvahiServer *s,           /**< The server object to add this record to */
81    AvahiSEntryGroup *g,       /**< An entry group object if this new record shall be attached to one, or NULL. If you plan to remove the record sometime later you a required to pass an entry group object here. */
82    AvahiIfIndex interface,   /**< A numeric index of a network interface to attach this record to, or AVAHI_IF_UNSPEC to attach this record to all interfaces */
83    AvahiProtocol protocol,   /**< A protocol family to attach this record to. One of the AVAHI_PROTO_xxx constants. Use AVAHI_PROTO_UNSPEC to make this record available on all protocols (wich means on both IPv4 and IPv6). */
84    AvahiPublishFlags flags,    /**< Special flags for this record */
85    AvahiRecord *r            /**< The record to add. This function increases the reference counter of this object. */);
86
87/** Add an IP address mapping to the server. This will add both the
88 * host-name-to-address and the reverse mapping to the server. See
89 * avahi_server_add() for more information. If adding one of the RRs
90 * fails, the function returns with an error, but it is not defined if
91 * the other RR is deleted from the server or not. Therefore, you have
92 * to free the AvahiSEntryGroup and create a new one before
93 * proceeding. */
94int avahi_server_add_address(
95    AvahiServer *s,
96    AvahiSEntryGroup *g,
97    AvahiIfIndex interface,
98    AvahiProtocol protocol,
99    AvahiPublishFlags flags,
100    const char *name,
101    AvahiAddress *a);
102
103/** Add an DNS-SD service to the Server. This will add all required
104 * RRs to the server. See avahi_server_add() for more information.  If
105 * adding one of the RRs fails, the function returns with an error,
106 * but it is not defined if the other RR is deleted from the server or
107 * not. Therefore, you have to free the AvahiSEntryGroup and create a
108 * new one before proceeding. */
109int avahi_server_add_service(
110    AvahiServer *s,
111    AvahiSEntryGroup *g,
112    AvahiIfIndex interface,
113    AvahiProtocol protocol,
114    AvahiPublishFlags flags,
115    const char *name,         /**< Service name, e.g. "Lennart's Files" */
116    const char *type,         /**< DNS-SD type, e.g. "_http._tcp" */
117    const char *domain,
118    const char *host,         /**< Host name where this servcie resides, or NULL if on the local host */
119    uint16_t port,              /**< Port number of the service */
120    ...  /**< Text records, terminated by NULL */) AVAHI_GCC_SENTINEL;
121
122/** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records.  The AvahiStringList object is copied. */
123int avahi_server_add_service_strlst(
124    AvahiServer *s,
125    AvahiSEntryGroup *g,
126    AvahiIfIndex interface,
127    AvahiProtocol protocol,
128    AvahiPublishFlags flags,
129    const char *name,
130    const char *type,
131    const char *domain,
132    const char *host,
133    uint16_t port,
134    AvahiStringList *strlst);
135
136/** Add a subtype for an already existing service */
137int avahi_server_add_service_subtype(
138    AvahiServer *s,
139    AvahiSEntryGroup *g,
140    AvahiIfIndex interface,
141    AvahiProtocol protocol,
142    AvahiPublishFlags flags,
143    const char *name,         /**< Specify the name of main service you already added here */
144    const char *type,         /**< Specify the main type of the service you already added here */
145    const char *domain,       /**< Specify the main type of the service you already added here */
146    const char *subtype       /**< The new subtype for the specified service */ );
147
148/** Update the TXT record for a service with the data from the specified string list */
149int avahi_server_update_service_txt_strlst(
150    AvahiServer *s,
151    AvahiSEntryGroup *g,
152    AvahiIfIndex interface,
153    AvahiProtocol protocol,
154    AvahiPublishFlags flags,
155    const char *name,
156    const char *type,
157    const char *domain,
158    AvahiStringList *strlst);
159
160/** Update the TXT record for a service with the NULL termonate list of strings */
161int avahi_server_update_service_txt(
162    AvahiServer *s,
163    AvahiSEntryGroup *g,
164    AvahiIfIndex interface,
165    AvahiProtocol protocol,
166    AvahiPublishFlags flags,
167    const char *name,
168    const char *type,
169    const char *domain,
170    ...) AVAHI_GCC_SENTINEL;
171
172/** Check if there is a service locally defined and return the entry group it is attached to. Returns NULL if the service isn't local*/
173int avahi_server_get_group_of_service(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiSEntryGroup** ret_group);
174
175AVAHI_C_DECL_END
176
177#endif
178