]> git.meshlink.io Git - catta/blobdiff - avahi-core/core.h
* add proper error codes and patch everything to make use of it
[catta] / avahi-core / core.h
index a41aee63bf7525f85f97c42f46d70cb04d0bdd5d..1adf244e8a98a4e47349766db736969a2317e0a8 100644 (file)
   USA.
 ***/
 
-#include <stdio.h>
 #include <glib.h>
 
 /** \file core.h The Avahi Multicast DNS and DNS Service Discovery implmentation. */
 
+/** \example publish-service.c Example how to register a DNS-SD
+ * service using an embedded mDNS stack. It behaves like a network
+ * printer registering both an IPP and a BSD LPR service. */
+
+/** \example browse-services.c Example how to browse for DNS-SD
+ * services using an embedded mDNS stack. */
+
 #include <avahi-common/cdecl.h>
 
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_BEGIN
+#endif
 
 /** An mDNS responder object */
 typedef struct AvahiServer AvahiServer;
@@ -40,21 +48,50 @@ typedef struct AvahiEntry AvahiEntry;
 /** A group of locally registered DNS RRs */
 typedef struct AvahiEntryGroup AvahiEntryGroup;
 
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_END
+#endif
 
 #include <avahi-common/address.h>
 #include <avahi-common/rr.h>
 #include <avahi-common/alternative.h>
 
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_BEGIN
+#endif
+
+/** Error codes used by avahi */
+enum { 
+    AVAHI_OK = 0,                          /**< OK */
+    AVAHI_ERR_FAILURE = -1,                /**< Generic error code */
+    AVAHI_ERR_BAD_STATE = -2,              /**< Object was in a bad state */
+    AVAHI_ERR_INVALID_HOST_NAME = -3,      /**< Invalid host name */
+    AVAHI_ERR_INVALID_DOMAIN_NAME = -4,    /**< Invalid domain name */
+    AVAHI_ERR_NO_NETWORK = -5,             /**< No suitable network protocol available */
+    AVAHI_ERR_INVALID_TTL = -6,            /**< Invalid DNS TTL */
+    AVAHI_ERR_IS_PATTERN = -7,             /**< RR key is pattern */
+    AVAHI_ERR_LOCAL_COLLISION = -8,        /**< Local name collision */
+    AVAHI_ERR_INVALID_RECORD = -9,         /**< Invalid RR */
+    AVAHI_ERR_INVALID_SERVICE_NAME = -10,  /**< Invalid service name */
+    AVAHI_ERR_INVALID_SERVICE_TYPE = -11,  /**< Invalid service type */
+    AVAHI_ERR_INVALID_PORT = -12,          /**< Invalid port number */
+    AVAHI_ERR_INVALID_KEY = -13,           /**< Invalid key */
+    AVAHI_ERR_INVALID_ADDRESS = -14,       /**< Invalid address */
+    AVAHI_ERR_TIMEOUT = -15,               /**< Timeout reached */
+    AVAHI_ERR_TOO_MANY_CLIENTS = -16,      /**< Too many clients */
+    AVAHI_ERR_TOO_MANY_OBJECTS = -17,      /**< Too many objects */
+    AVAHI_ERR_TOO_MANY_ENTRIES = -18,      /**< Too many entries */
+    AVAHI_ERR_OS = -19,                    /**< OS error */
+    AVAHI_ERR_ACCESS_DENIED = -20,         /**< Access denied */
+    AVAHI_ERR_MAX = -21
+};
 
 /** States of a server object */
 typedef enum {
     AVAHI_SERVER_INVALID = -1,     /**< Invalid state (initial) */ 
     AVAHI_SERVER_REGISTERING = 0,  /**< Host RRs are being registered */
     AVAHI_SERVER_RUNNING,          /**< All host RRs have been established */
-    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() */
-    AVAHI_SERVER_SLEEPING          /**< The host or domain name has changed and the server waits for old entries to be expired */
+    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() */
 } AvahiServerState;
 
 /** Flags for server entries */
@@ -101,7 +138,8 @@ AvahiServer *avahi_server_new(
     GMainContext *c,               /**< The GLIB main loop context to attach to */
     const AvahiServerConfig *sc,   /**< If non-NULL a pointer to a configuration structure for the server. The server makes an internal deep copy of this structure, so you may free it using avahi_server_config_done() immediately after calling this function. */
     AvahiServerCallback callback,  /**< A callback which is called whenever the state of the server changes */
-    gpointer userdata              /**< An opaque pointer which is passed to the callback function */);
+    gpointer userdata,             /**< An opaque pointer which is passed to the callback function */
+    gint *error);
 
 /** Free an mDNS responder object */
 void avahi_server_free(AvahiServer* s);
@@ -171,8 +209,11 @@ AvahiServerState avahi_server_get_state(AvahiServer *s);
  * has been read, NULL is returned. */
 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state);
 
-/** Dump the current server status to the specified FILE object */
-void avahi_server_dump(AvahiServer *s, FILE *f);
+/** Callback prototype for avahi_server_dump() */
+typedef void (*AvahiDumpCallback)(const gchar *text, gpointer userdata);
+
+/** Dump the current server status by calling "callback" for each line.  */
+void avahi_server_dump(AvahiServer *s, AvahiDumpCallback callback, gpointer userdata);
 
 /** Create a new entry group. The specified callback function is
  * called whenever the state of the group changes. Use entry group
@@ -187,6 +228,12 @@ void avahi_entry_group_free(AvahiEntryGroup *g);
 /** Commit an entry group. This starts the probing and registration process for all RRs in the group */
 gint avahi_entry_group_commit(AvahiEntryGroup *g);
 
+/** Remove all entries from the entry group and reset the state to AVAHI_ENTRY_GROUP_UNCOMMITED. */
+void avahi_entry_group_reset(AvahiEntryGroup *g);
+
+/** Return TRUE if the entry group is empty, i.e. has no records attached. */
+gboolean avahi_entry_group_is_empty(AvahiEntryGroup *g);
+
 /** Return the current state of the specified entry group */
 AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g);
 
@@ -251,7 +298,7 @@ gint avahi_server_add_txt_strlst(
     AvahiEntryFlags flags,
     guint32 ttl,
     const gchar *name,
-    AvahiStringList *strlst  /**< TXT decord data as a AvahiString. Only the pointer to the object and not the object itself is copied into the RR. Therefore you should not free the strlst object yourself, this will be done by the library. If you want to add multiple records with the same RR data you MUST copy the strlst object prior to calling this function with avahi_strlst_copy(). */ );
+    AvahiStringList *strlst  /**< TXT decord data as a AvahiString. This routine makes a deep copy of this object. */ );
 
 /** Add an IP address mapping to the server. This will add both the
  * host-name-to-address and the reverse mapping to the server. See
@@ -300,7 +347,7 @@ gint avahi_server_add_service_va(
     guint16 port,
     va_list va);
 
-/** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records.  The AvahiStringList object is not copied. You need to make a copy if this object if you want to reuse it. The object is freed if the RR is removed from the server. */
+/** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records.  The AvahiStringList object is copied. */
 gint avahi_server_add_service_strlst(
     AvahiServer *s,
     AvahiEntryGroup *g,
@@ -438,7 +485,8 @@ typedef enum {
     AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT,  /**< Browse for the default registering domain */
     AVAHI_DOMAIN_BROWSER_BROWSE,            /**< Browse for a list of available browsing domains */
     AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT,    /**< Browse for the default browsing domain */
-    AVAHI_DOMAIN_BROWSER_BROWSE_LEGACY      /**< Legacy browse domain - see DNS-SD spec for more information */
+    AVAHI_DOMAIN_BROWSER_BROWSE_LEGACY,     /**< Legacy browse domain - see DNS-SD spec for more information */
+    AVAHI_DOMAIN_BROWSER_MAX
 } AvahiDomainBrowserType;
 
 /** A local domain browsing object. May be used to enumerate domains used on the local LAN */
@@ -500,9 +548,9 @@ typedef void (*AvahiServiceBrowserCallback)(
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiBrowserEvent event,
-    const gchar *name,     /**< Service name, e.g. "Lennart's Files" */ 
-    const gchar *type,     /**< DNS-SD type, e.g. "_http._tcp" */
-    const gchar *domain,   /**< Domain of this service, e.g. "local" */
+    const gchar *name     /**< Service name, e.g. "Lennart's Files" */,
+    const gchar *type     /**< DNS-SD type, e.g. "_http._tcp" */,
+    const gchar *domain   /**< Domain of this service, e.g. "local" */,
     gpointer userdata);
 
 /** Create a new AvahiServiceBrowser object. */
@@ -510,7 +558,7 @@ AvahiServiceBrowser *avahi_service_browser_new(
     AvahiServer *server,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
-    const gchar *service_type, /** DNS-SD service type, e.g. "_http._tcp" */
+    const gchar *service_type /** DNS-SD service type, e.g. "_http._tcp" */,
     const gchar *domain,
     AvahiServiceBrowserCallback callback,
     gpointer userdata);
@@ -581,6 +629,14 @@ AvahiDNSServerBrowser *avahi_dns_server_browser_new(
 /** Free an AvahiDNSServerBrowser object */
 void avahi_dns_server_browser_free(AvahiDNSServerBrowser *b);
 
+/** Return a human readable error string for the specified error code */
+const gchar *avahi_strerror(gint error);
+
+/** Return the last error code */
+gint avahi_server_errno(AvahiServer *s);
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_END
+#endif
 
 #endif