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>
39 /** Prototype for callback functions which are called whenever the state of an AvahiSEntryGroup object changes */
40 typedef void (*AvahiSEntryGroupCallback) (AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata);
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. */
48 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiSEntryGroup *g, void **state);
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 */
55 AvahiSEntryGroup *avahi_s_entry_group_new(AvahiServer *s, AvahiSEntryGroupCallback callback, void* userdata);
57 /** Free an entry group. All RRs assigned to the group are removed from the server */
58 void avahi_s_entry_group_free(AvahiSEntryGroup *g);
60 /** Commit an entry group. This starts the probing and registration process for all RRs in the group */
61 int avahi_s_entry_group_commit(AvahiSEntryGroup *g);
63 /** Remove all entries from the entry group and reset the state to AVAHI_ENTRY_GROUP_UNCOMMITED. */
64 void avahi_s_entry_group_reset(AvahiSEntryGroup *g);
66 /** Return 1 if the entry group is empty, i.e. has no records attached. */
67 int avahi_s_entry_group_is_empty(AvahiSEntryGroup *g);
69 /** Return the current state of the specified entry group */
70 AvahiEntryGroupState avahi_s_entry_group_get_state(AvahiSEntryGroup *g);
72 /** Change the opaque user data pointer attached to an entry group object */
73 void avahi_s_entry_group_set_data(AvahiSEntryGroup *g, void* userdata);
75 /** Return the opaque user data pointer currently set for the entry group object */
76 void* avahi_s_entry_group_get_data(AvahiSEntryGroup *g);
78 /** Add a new resource record to the server. Returns 0 on success, negative otherwise. */
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. */);
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
94 int avahi_server_add_address(
97 AvahiIfIndex interface,
98 AvahiProtocol protocol,
99 AvahiPublishFlags flags,
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. */
109 int avahi_server_add_service(
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" */
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;
122 /** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records. The AvahiStringList object is copied. */
123 int avahi_server_add_service_strlst(
126 AvahiIfIndex interface,
127 AvahiProtocol protocol,
128 AvahiPublishFlags flags,
134 AvahiStringList *strlst);
136 /** Add a subtype for an already existing service */
137 int avahi_server_add_service_subtype(
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 */ );
148 /** Update the TXT record for a service with the data from the specified string list */
149 int avahi_server_update_service_txt_strlst(
152 AvahiIfIndex interface,
153 AvahiProtocol protocol,
154 AvahiPublishFlags flags,
158 AvahiStringList *strlst);
160 /** Update the TXT record for a service with the NULL termonate list of strings */
161 int avahi_server_update_service_txt(
164 AvahiIfIndex interface,
165 AvahiProtocol protocol,
166 AvahiPublishFlags flags,
170 ...) AVAHI_GCC_SENTINEL;
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*/
173 int avahi_server_get_group_of_service(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiSEntryGroup** ret_group);