7 This file is part of avahi.
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.
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.
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
25 /** \file core/publish.h Functions for publising local services and RRs */
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. */
31 /** A group of locally registered DNS RRs */
32 typedef struct AvahiSEntryGroup AvahiSEntryGroup;
34 #include <avahi-common/cdecl.h>
35 #include <avahi-core/core.h>
37 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 /** Prototype for callback functions which are called whenever the state of an AvahiSEntryGroup object changes */
42 typedef void (*AvahiSEntryGroupCallback) (AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata);
44 /** Iterate through all local entries of the server. (when g is NULL)
45 * or of a specified entry group. At the first call state should point
46 * to a NULL initialized void pointer, That pointer is used to track
47 * the current iteration. It is not safe to call any other
48 * avahi_server_xxx() function during the iteration. If the last entry
49 * has been read, NULL is returned. */
50 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiSEntryGroup *g, void **state);
52 /** Create a new entry group. The specified callback function is
53 * called whenever the state of the group changes. Use entry group
54 * objects to keep track of you RRs. Add new RRs to a group using
55 * avahi_server_add_xxx(). Make sure to call avahi_s_entry_group_commit()
56 * to start the registration process for your RRs */
57 AvahiSEntryGroup *avahi_s_entry_group_new(AvahiServer *s, AvahiSEntryGroupCallback callback, void* userdata);
59 /** Free an entry group. All RRs assigned to the group are removed from the server */
60 void avahi_s_entry_group_free(AvahiSEntryGroup *g);
62 /** Commit an entry group. This starts the probing and registration process for all RRs in the group */
63 int avahi_s_entry_group_commit(AvahiSEntryGroup *g);
65 /** Remove all entries from the entry group and reset the state to AVAHI_ENTRY_GROUP_UNCOMMITED. */
66 void avahi_s_entry_group_reset(AvahiSEntryGroup *g);
68 /** Return 1 if the entry group is empty, i.e. has no records attached. */
69 int avahi_s_entry_group_is_empty(AvahiSEntryGroup *g);
71 /** Return the current state of the specified entry group */
72 AvahiEntryGroupState avahi_s_entry_group_get_state(AvahiSEntryGroup *g);
74 /** Change the opaque user data pointer attached to an entry group object */
75 void avahi_s_entry_group_set_data(AvahiSEntryGroup *g, void* userdata);
77 /** Return the opaque user data pointer currently set for the entry group object */
78 void* avahi_s_entry_group_get_data(AvahiSEntryGroup *g);
80 /** Add a new resource record to the server. Returns 0 on success, negative otherwise. */
82 AvahiServer *s, /**< The server object to add this record to */
83 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. */
84 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 */
85 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). */
86 AvahiPublishFlags flags, /**< Special flags for this record */
87 AvahiRecord *r /**< The record to add. This function increases the reference counter of this object. */);
89 /** Add an IP address mapping to the server. This will add both the
90 * host-name-to-address and the reverse mapping to the server. See
91 * avahi_server_add() for more information. If adding one of the RRs
92 * fails, the function returns with an error, but it is not defined if
93 * the other RR is deleted from the server or not. Therefore, you have
94 * to free the AvahiSEntryGroup and create a new one before
96 int avahi_server_add_address(
99 AvahiIfIndex interface,
100 AvahiProtocol protocol,
101 AvahiPublishFlags flags,
105 /** Add an DNS-SD service to the Server. This will add all required
106 * RRs to the server. See avahi_server_add() for more information. If
107 * adding one of the RRs fails, the function returns with an error,
108 * but it is not defined if the other RR is deleted from the server or
109 * not. Therefore, you have to free the AvahiSEntryGroup and create a
110 * new one before proceeding. */
111 int avahi_server_add_service(
114 AvahiIfIndex interface,
115 AvahiProtocol protocol,
116 AvahiPublishFlags flags,
117 const char *name, /**< Service name, e.g. "Lennart's Files" */
118 const char *type, /**< DNS-SD type, e.g. "_http._tcp" */
120 const char *host, /**< Host name where this servcie resides, or NULL if on the local host */
121 uint16_t port, /**< Port number of the service */
122 ... /**< Text records, terminated by NULL */) AVAHI_GCC_SENTINEL;
124 /** Mostly identical to avahi_server_add_service(), but takes an va_list for the TXT records. */
125 int avahi_server_add_service_va(
128 AvahiIfIndex interface,
129 AvahiProtocol protocol,
130 AvahiPublishFlags flags,
138 /** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records. The AvahiStringList object is copied. */
139 int avahi_server_add_service_strlst(
142 AvahiIfIndex interface,
143 AvahiProtocol protocol,
144 AvahiPublishFlags flags,
150 AvahiStringList *strlst);
152 /** Add a subtype for an already existing service */
153 int avahi_server_add_service_subtype(
156 AvahiIfIndex interface,
157 AvahiProtocol protocol,
158 AvahiPublishFlags flags,
159 const char *name, /**< Specify the name of main service you already added here */
160 const char *type, /**< Specify the main type of the service you already added here */
161 const char *domain, /**< Specify the main type of the service you already added here */
162 const char *subtype /**< The new subtype for the specified service */ );
164 /** Update the TXT record for a service with the data from the specified string list */
165 int avahi_server_update_service_txt_strlst(
168 AvahiIfIndex interface,
169 AvahiProtocol protocol,
170 AvahiPublishFlags flags,
174 AvahiStringList *strlst);
176 /** Update the TXT record for a service with the NULL terminated list of strings of the va_list. */
177 int avahi_server_update_service_txt_va(
180 AvahiIfIndex interface,
181 AvahiProtocol protocol,
182 AvahiPublishFlags flags,
188 /** Update the TXT record for a service with the NULL termonate list of strings */
189 int avahi_server_update_service_txt(
192 AvahiIfIndex interface,
193 AvahiProtocol protocol,
194 AvahiPublishFlags flags,
198 ...) AVAHI_GCC_SENTINEL;
200 #ifndef DOXYGEN_SHOULD_SKIP_THIS