publish.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef foopublishhfoo
  2. #define foopublishhfoo
  3. /***
  4. This file is part of avahi.
  5. avahi is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. avahi is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
  12. Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with avahi; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  16. USA.
  17. ***/
  18. /** \file core/publish.h Functions for publising local services and RRs */
  19. /** \example core-publish-service.c Example how to register a DNS-SD
  20. * service using an embedded mDNS stack. It behaves like a network
  21. * printer registering both an IPP and a BSD LPR service. */
  22. /** A group of locally registered DNS RRs */
  23. typedef struct AvahiSEntryGroup AvahiSEntryGroup;
  24. #include <avahi-common/cdecl.h>
  25. #include <avahi-core/core.h>
  26. AVAHI_C_DECL_BEGIN
  27. /** Prototype for callback functions which are called whenever the state of an AvahiSEntryGroup object changes */
  28. typedef void (*AvahiSEntryGroupCallback) (AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata);
  29. /** Iterate through all local entries of the server. (when g is NULL)
  30. * or of a specified entry group. At the first call state should point
  31. * to a NULL initialized void pointer, That pointer is used to track
  32. * the current iteration. It is not safe to call any other
  33. * avahi_server_xxx() function during the iteration. If the last entry
  34. * has been read, NULL is returned. */
  35. const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiSEntryGroup *g, void **state);
  36. /** Create a new entry group. The specified callback function is
  37. * called whenever the state of the group changes. Use entry group
  38. * objects to keep track of you RRs. Add new RRs to a group using
  39. * avahi_server_add_xxx(). Make sure to call avahi_s_entry_group_commit()
  40. * to start the registration process for your RRs */
  41. AvahiSEntryGroup *avahi_s_entry_group_new(AvahiServer *s, AvahiSEntryGroupCallback callback, void* userdata);
  42. /** Free an entry group. All RRs assigned to the group are removed from the server */
  43. void avahi_s_entry_group_free(AvahiSEntryGroup *g);
  44. /** Commit an entry group. This starts the probing and registration process for all RRs in the group */
  45. int avahi_s_entry_group_commit(AvahiSEntryGroup *g);
  46. /** Remove all entries from the entry group and reset the state to AVAHI_ENTRY_GROUP_UNCOMMITED. */
  47. void avahi_s_entry_group_reset(AvahiSEntryGroup *g);
  48. /** Return 1 if the entry group is empty, i.e. has no records attached. */
  49. int avahi_s_entry_group_is_empty(AvahiSEntryGroup *g);
  50. /** Return the current state of the specified entry group */
  51. AvahiEntryGroupState avahi_s_entry_group_get_state(AvahiSEntryGroup *g);
  52. /** Change the opaque user data pointer attached to an entry group object */
  53. void avahi_s_entry_group_set_data(AvahiSEntryGroup *g, void* userdata);
  54. /** Return the opaque user data pointer currently set for the entry group object */
  55. void* avahi_s_entry_group_get_data(AvahiSEntryGroup *g);
  56. /** Add a new resource record to the server. Returns 0 on success, negative otherwise. */
  57. int avahi_server_add(
  58. AvahiServer *s, /**< The server object to add this record to */
  59. 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. */
  60. 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 */
  61. 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). */
  62. AvahiPublishFlags flags, /**< Special flags for this record */
  63. AvahiRecord *r /**< The record to add. This function increases the reference counter of this object. */);
  64. /** Add an IP address mapping to the server. This will add both the
  65. * host-name-to-address and the reverse mapping to the server. See
  66. * avahi_server_add() for more information. If adding one of the RRs
  67. * fails, the function returns with an error, but it is not defined if
  68. * the other RR is deleted from the server or not. Therefore, you have
  69. * to free the AvahiSEntryGroup and create a new one before
  70. * proceeding. */
  71. int avahi_server_add_address(
  72. AvahiServer *s,
  73. AvahiSEntryGroup *g,
  74. AvahiIfIndex interface,
  75. AvahiProtocol protocol,
  76. AvahiPublishFlags flags,
  77. const char *name,
  78. AvahiAddress *a);
  79. /** Add an DNS-SD service to the Server. This will add all required
  80. * RRs to the server. See avahi_server_add() for more information. If
  81. * adding one of the RRs fails, the function returns with an error,
  82. * but it is not defined if the other RR is deleted from the server or
  83. * not. Therefore, you have to free the AvahiSEntryGroup and create a
  84. * new one before proceeding. */
  85. int avahi_server_add_service(
  86. AvahiServer *s,
  87. AvahiSEntryGroup *g,
  88. AvahiIfIndex interface,
  89. AvahiProtocol protocol,
  90. AvahiPublishFlags flags,
  91. const char *name, /**< Service name, e.g. "Lennart's Files" */
  92. const char *type, /**< DNS-SD type, e.g. "_http._tcp" */
  93. const char *domain,
  94. const char *host, /**< Host name where this servcie resides, or NULL if on the local host */
  95. uint16_t port, /**< Port number of the service */
  96. ... /**< Text records, terminated by NULL */) AVAHI_GCC_SENTINEL;
  97. /** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records. The AvahiStringList object is copied. */
  98. int avahi_server_add_service_strlst(
  99. AvahiServer *s,
  100. AvahiSEntryGroup *g,
  101. AvahiIfIndex interface,
  102. AvahiProtocol protocol,
  103. AvahiPublishFlags flags,
  104. const char *name,
  105. const char *type,
  106. const char *domain,
  107. const char *host,
  108. uint16_t port,
  109. AvahiStringList *strlst);
  110. /** Add a subtype for an already existing service */
  111. int avahi_server_add_service_subtype(
  112. AvahiServer *s,
  113. AvahiSEntryGroup *g,
  114. AvahiIfIndex interface,
  115. AvahiProtocol protocol,
  116. AvahiPublishFlags flags,
  117. const char *name, /**< Specify the name of main service you already added here */
  118. const char *type, /**< Specify the main type of the service you already added here */
  119. const char *domain, /**< Specify the main type of the service you already added here */
  120. const char *subtype /**< The new subtype for the specified service */ );
  121. /** Update the TXT record for a service with the data from the specified string list */
  122. int avahi_server_update_service_txt_strlst(
  123. AvahiServer *s,
  124. AvahiSEntryGroup *g,
  125. AvahiIfIndex interface,
  126. AvahiProtocol protocol,
  127. AvahiPublishFlags flags,
  128. const char *name,
  129. const char *type,
  130. const char *domain,
  131. AvahiStringList *strlst);
  132. /** Update the TXT record for a service with the NULL termonate list of strings */
  133. int avahi_server_update_service_txt(
  134. AvahiServer *s,
  135. AvahiSEntryGroup *g,
  136. AvahiIfIndex interface,
  137. AvahiProtocol protocol,
  138. AvahiPublishFlags flags,
  139. const char *name,
  140. const char *type,
  141. const char *domain,
  142. ...) AVAHI_GCC_SENTINEL;
  143. /** 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*/
  144. 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);
  145. AVAHI_C_DECL_END
  146. #endif