summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@nokia.com>2011-10-17 18:30:52 +0200
committerFawzi Mohamed <fawzi.mohamed@nokia.com>2011-10-18 11:50:32 +0200
commitbb5c27c180f7ff66768718ab51ac72897a83076c (patch)
tree7d7c6499c8a16e62ce5a5d66398fd3f75d58267d
parenta0e0a125c9cde1636b653fdf56f1b9f1958a8a9b (diff)
downloadqt-creator-bb5c27c180f7ff66768718ab51ac72897a83076c.tar.gz
zeroconf: native avahi, and working fallbacks
* supports avahi through its native interface * starts embedded deamon if found * tested all fallbacks on ubuntu * Service is a normal object now * several smaller improvements Change-Id: I36288ec6fcefb64a60b6284e4d86d4b589ba37b5 Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
-rw-r--r--src/libs/zeroconf/avahi-client/client.h117
-rw-r--r--src/libs/zeroconf/avahi-client/lookup.h314
-rw-r--r--src/libs/zeroconf/avahi-common/address.h119
-rw-r--r--src/libs/zeroconf/avahi-common/cdecl.h38
-rw-r--r--src/libs/zeroconf/avahi-common/defs.h356
-rw-r--r--src/libs/zeroconf/avahi-common/error.h107
-rw-r--r--src/libs/zeroconf/avahi-common/gccmacro.h74
-rw-r--r--src/libs/zeroconf/avahi-common/malloc.h96
-rw-r--r--src/libs/zeroconf/avahi-common/simple-watch.h85
-rw-r--r--src/libs/zeroconf/avahi-common/strlst.h180
-rw-r--r--src/libs/zeroconf/avahi-common/watch.h97
-rw-r--r--src/libs/zeroconf/avahiLib.cpp478
-rw-r--r--src/libs/zeroconf/embeddedLib.cpp194
-rw-r--r--src/libs/zeroconf/mdnsderived.cpp37
-rw-r--r--src/libs/zeroconf/mdnsderived.h11
-rw-r--r--src/libs/zeroconf/nativeLib.cpp209
-rw-r--r--src/libs/zeroconf/servicebrowser.cpp474
-rw-r--r--src/libs/zeroconf/servicebrowser.h5
-rw-r--r--src/libs/zeroconf/servicebrowser_p.h117
-rw-r--r--src/libs/zeroconf/zeroconf.pro6
-rw-r--r--src/libs/zeroconf/zeroconf_global.h2
21 files changed, 2645 insertions, 471 deletions
diff --git a/src/libs/zeroconf/avahi-client/client.h b/src/libs/zeroconf/avahi-client/client.h
new file mode 100644
index 0000000000..1039da57af
--- /dev/null
+++ b/src/libs/zeroconf/avahi-client/client.h
@@ -0,0 +1,117 @@
+#ifndef fooclienthfoo
+#define fooclienthfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <inttypes.h>
+
+#include <avahi-common/cdecl.h>
+#include <avahi-common/address.h>
+#include <avahi-common/strlst.h>
+#include <avahi-common/defs.h>
+#include <avahi-common/watch.h>
+#include <avahi-common/gccmacro.h>
+
+/** \file client.h Definitions and functions for the client API over D-Bus */
+
+AVAHI_C_DECL_BEGIN
+
+/** A connection context */
+typedef struct AvahiClient AvahiClient;
+
+/** States of a client object, a superset of AvahiServerState */
+typedef enum {
+ AVAHI_CLIENT_S_REGISTERING = AVAHI_SERVER_REGISTERING, /**< Server state: REGISTERING */
+ AVAHI_CLIENT_S_RUNNING = AVAHI_SERVER_RUNNING, /**< Server state: RUNNING */
+ AVAHI_CLIENT_S_COLLISION = AVAHI_SERVER_COLLISION, /**< Server state: COLLISION */
+ AVAHI_CLIENT_FAILURE = 100, /**< Some kind of error happened on the client side */
+ AVAHI_CLIENT_CONNECTING = 101 /**< We're still connecting. This state is only entered when AVAHI_CLIENT_NO_FAIL has been passed to avahi_client_new() and the daemon is not yet available. */
+} AvahiClientState;
+
+typedef enum {
+ AVAHI_CLIENT_IGNORE_USER_CONFIG = 1, /**< Don't read user configuration */
+ AVAHI_CLIENT_NO_FAIL = 2 /**< Don't fail if the daemon is not available when avahi_client_new() is called, instead enter AVAHI_CLIENT_CONNECTING state and wait for the daemon to appear */
+} AvahiClientFlags;
+
+/** The function prototype for the callback of an AvahiClient */
+typedef void (*AvahiClientCallback) (
+ AvahiClient *s,
+ AvahiClientState state /**< The new state of the client */,
+ void* userdata /**< The user data that was passed to avahi_client_new() */);
+
+/** @{ \name Construction and destruction */
+
+/** Creates a new client instance */
+AvahiClient* avahi_client_new (
+ const AvahiPoll *poll_api /**< The abstract event loop API to use */,
+ AvahiClientFlags flags /**< Some flags to modify the behaviour of the client library */,
+ AvahiClientCallback callback /**< A callback that is called whenever the state of the client changes. This may be NULL. Please note that this function is called for the first time from within the avahi_client_new() context! Thus, in the callback you should not make use of global variables that are initialized only after your call to avahi_client_new(). A common mistake is to store the AvahiClient pointer returned by avahi_client_new() in a global variable and assume that this global variable already contains the valid pointer when the callback is called for the first time. A work-around for this is to always use the AvahiClient pointer passed to the callback function instead of the global pointer. */,
+ void *userdata /**< Some arbitrary user data pointer that will be passed to the callback function */,
+ int *error /**< If creation of the client fails, this integer will contain the error cause. May be NULL if you aren't interested in the reason why avahi_client_new() failed. */);
+
+/** Free a client instance. This will automatically free all
+ * associated browser, resolve and entry group objects. All pointers
+ * to such objects become invalid! */
+void avahi_client_free(AvahiClient *client);
+
+/** @} */
+
+/** @{ \name Properties */
+
+/** Get the version of the server */
+const char* avahi_client_get_version_string (AvahiClient*);
+
+/** Get host name */
+const char* avahi_client_get_host_name (AvahiClient*);
+
+/** Set host name. \since 0.6.13 */
+int avahi_client_set_host_name(AvahiClient*, const char *name);
+
+/** Get domain name */
+const char* avahi_client_get_domain_name (AvahiClient*);
+
+/** Get FQDN domain name */
+const char* avahi_client_get_host_name_fqdn (AvahiClient*);
+
+/** Get state */
+AvahiClientState avahi_client_get_state(AvahiClient *client);
+
+/** @{ \name Error Handling */
+
+/** Get the last error number. See avahi_strerror() for converting this error code into a human readable string. */
+int avahi_client_errno (AvahiClient*);
+
+/** @} */
+
+/** \cond fulldocs */
+/** Return the local service cookie. returns AVAHI_SERVICE_COOKIE_INVALID on failure. */
+uint32_t avahi_client_get_local_service_cookie(AvahiClient *client);
+/** \endcond */
+
+/** @{ \name Libc NSS Support */
+
+/** Return 1 if gethostbyname() supports mDNS lookups, 0 otherwise. \since 0.6.5 */
+int avahi_nss_support(void);
+
+/** @} */
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-client/lookup.h b/src/libs/zeroconf/avahi-client/lookup.h
new file mode 100644
index 0000000000..52407f4aa5
--- /dev/null
+++ b/src/libs/zeroconf/avahi-client/lookup.h
@@ -0,0 +1,314 @@
+#ifndef fooclientlookuphfoo
+#define fooclientlookuphfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <inttypes.h>
+
+#include <avahi-common/cdecl.h>
+#include <avahi-common/address.h>
+#include <avahi-common/strlst.h>
+#include <avahi-common/defs.h>
+#include <avahi-common/watch.h>
+#include <avahi-common/gccmacro.h>
+
+#include <avahi-client/client.h>
+
+/** \file avahi-client/lookup.h Lookup Client API */
+
+/** \example client-browse-services.c Example how to browse for DNS-SD
+ * services using the client interface to avahi-daemon. */
+
+AVAHI_C_DECL_BEGIN
+
+/** @{ \name Domain Browser */
+
+/** A domain browser object */
+typedef struct AvahiDomainBrowser AvahiDomainBrowser;
+
+/** The function prototype for the callback of an AvahiDomainBrowser */
+typedef void (*AvahiDomainBrowserCallback) (
+ AvahiDomainBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *domain,
+ AvahiLookupResultFlags flags,
+ void *userdata);
+
+/** Browse for domains on the local network */
+AvahiDomainBrowser* avahi_domain_browser_new (
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const char *domain,
+ AvahiDomainBrowserType btype,
+ AvahiLookupFlags flags,
+ AvahiDomainBrowserCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiDomainBrowser object */
+AvahiClient* avahi_domain_browser_get_client (AvahiDomainBrowser *);
+
+/** Cleans up and frees an AvahiDomainBrowser object */
+int avahi_domain_browser_free (AvahiDomainBrowser *);
+
+/** @} */
+
+/** @{ \name Service Browser */
+
+/** A service browser object */
+typedef struct AvahiServiceBrowser AvahiServiceBrowser;
+
+/** The function prototype for the callback of an AvahiServiceBrowser */
+typedef void (*AvahiServiceBrowserCallback) (
+ AvahiServiceBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *name,
+ const char *type,
+ const char *domain,
+ AvahiLookupResultFlags flags,
+ void *userdata);
+
+/** Browse for services of a type on the network. In most cases you
+ * probably want to pass AVAHI_IF_UNSPEC and AVAHI_PROTO_UNSPED in
+ * interface, resp. protocol to browse on all local networks. The
+ * specified callback will be called whenever a new service appears
+ * or is removed from the network. Please note that events may be
+ * collapsed to minimize traffic (i.e. a REMOVED followed by a NEW for
+ * the same service data is dropped because redundant). If you want to
+ * subscribe to service data changes, you should use
+ * avahi_service_resolver_new() and keep it open, in which case you
+ * will be notified via AVAHI_RESOLVE_FOUND everytime the service data
+ * changes. */
+AvahiServiceBrowser* avahi_service_browser_new (
+ AvahiClient *client,
+ AvahiIfIndex interface, /**< In most cases pass AVAHI_IF_UNSPEC here */
+ AvahiProtocol protocol, /**< In most cases pass AVAHI_PROTO_UNSPEC here */
+ const char *type, /**< A service type such as "_http._tcp" */
+ const char *domain, /**< A domain to browse in. In most cases you want to pass NULL here for the default domain (usually ".local") */
+ AvahiLookupFlags flags,
+ AvahiServiceBrowserCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiServiceBrowser object */
+AvahiClient* avahi_service_browser_get_client (AvahiServiceBrowser *);
+
+/** Cleans up and frees an AvahiServiceBrowser object */
+int avahi_service_browser_free (AvahiServiceBrowser *);
+
+/** @} */
+
+/** \cond fulldocs */
+/** A service type browser object */
+typedef struct AvahiServiceTypeBrowser AvahiServiceTypeBrowser;
+
+/** The function prototype for the callback of an AvahiServiceTypeBrowser */
+typedef void (*AvahiServiceTypeBrowserCallback) (
+ AvahiServiceTypeBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *type,
+ const char *domain,
+ AvahiLookupResultFlags flags,
+ void *userdata);
+
+/** Browse for service types on the local network */
+AvahiServiceTypeBrowser* avahi_service_type_browser_new (
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const char *domain,
+ AvahiLookupFlags flags,
+ AvahiServiceTypeBrowserCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiServiceTypeBrowser object */
+AvahiClient* avahi_service_type_browser_get_client (AvahiServiceTypeBrowser *);
+
+/** Cleans up and frees an AvahiServiceTypeBrowser object */
+int avahi_service_type_browser_free (AvahiServiceTypeBrowser *);
+
+/** \endcond */
+
+/** @{ \name Service Resolver */
+
+/** A service resolver object */
+typedef struct AvahiServiceResolver AvahiServiceResolver;
+
+/** The function prototype for the callback of an AvahiServiceResolver */
+typedef void (*AvahiServiceResolverCallback) (
+ AvahiServiceResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
+ const char *type,
+ const char *domain,
+ const char *host_name,
+ const AvahiAddress *a,
+ uint16_t port,
+ AvahiStringList *txt,
+ AvahiLookupResultFlags flags,
+ void *userdata);
+
+/** Create a new service resolver object. Please make sure to pass all
+ * the service data you received via avahi_service_browser_new()'s
+ * callback function, especially interface and protocol. The protocol
+ * argument specifies the protocol (IPv4 or IPv6) to use as transport
+ * for the queries which are sent out by this resolver. The
+ * aprotocol argument specifies the adress family (IPv4 or IPv6) of
+ * the address of the service we are looking for. Generally, on
+ * "protocol" you should only pass what was supplied to you as
+ * parameter to your AvahiServiceBrowserCallback. In "aprotocol" you
+ * should pass what your application code can deal with when
+ * connecting to the service. Or, more technically speaking: protocol
+ * specifies if the mDNS queries should be sent as UDP/IPv4
+ * resp. UDP/IPv6 packets. aprotocol specifies whether the query is for a A
+ * resp. AAAA resource record. */
+AvahiServiceResolver * avahi_service_resolver_new(
+ AvahiClient *client,
+ AvahiIfIndex interface, /**< Pass the interface argument you received in AvahiServiceBrowserCallback here. */
+ AvahiProtocol protocol, /**< Pass the protocol argument you received in AvahiServiceBrowserCallback here. */
+ const char *name, /**< Pass the name argument you received in AvahiServiceBrowserCallback here. */
+ const char *type, /**< Pass the type argument you received in AvahiServiceBrowserCallback here. */
+ const char *domain, /**< Pass the domain argument you received in AvahiServiceBrowserCallback here. */
+ AvahiProtocol aprotocol, /**< The desired address family of the service address to resolve. AVAHI_PROTO_UNSPEC if your application can deal with both IPv4 and IPv6 */
+ AvahiLookupFlags flags,
+ AvahiServiceResolverCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiServiceResolver object */
+AvahiClient* avahi_service_resolver_get_client (AvahiServiceResolver *);
+
+/** Free a service resolver object */
+int avahi_service_resolver_free(AvahiServiceResolver *r);
+
+/** @} */
+
+/** \cond fulldocs */
+/** A service resolver object */
+typedef struct AvahiHostNameResolver AvahiHostNameResolver;
+
+/** The function prototype for the callback of an AvahiHostNameResolver */
+typedef void (*AvahiHostNameResolverCallback) (
+ AvahiHostNameResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
+ const AvahiAddress *a,
+ AvahiLookupResultFlags flags,
+ void *userdata);
+
+/** Create a new hostname resolver object */
+AvahiHostNameResolver * avahi_host_name_resolver_new(
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const char *name,
+ AvahiProtocol aprotocol,
+ AvahiLookupFlags flags,
+ AvahiHostNameResolverCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiHostNameResolver object */
+AvahiClient* avahi_host_name_resolver_get_client (AvahiHostNameResolver *);
+
+/** Free a hostname resolver object */
+int avahi_host_name_resolver_free(AvahiHostNameResolver *r);
+
+/** An address resolver object */
+typedef struct AvahiAddressResolver AvahiAddressResolver;
+
+/** The function prototype for the callback of an AvahiAddressResolver */
+typedef void (*AvahiAddressResolverCallback) (
+ AvahiAddressResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const AvahiAddress *a,
+ const char *name,
+ AvahiLookupResultFlags flags,
+ void *userdata);
+
+/** Create a new address resolver object from an AvahiAddress object */
+AvahiAddressResolver* avahi_address_resolver_new(
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const AvahiAddress *a,
+ AvahiLookupFlags flags,
+ AvahiAddressResolverCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiAddressResolver object */
+AvahiClient* avahi_address_resolver_get_client (AvahiAddressResolver *);
+
+/** Free a AvahiAddressResolver resolver object */
+int avahi_address_resolver_free(AvahiAddressResolver *r);
+
+/** \endcond */
+
+/** @{ \name Record Browser */
+
+/** A record browser object */
+typedef struct AvahiRecordBrowser AvahiRecordBrowser;
+
+/** The function prototype for the callback of an AvahiRecordBrowser */
+typedef void (*AvahiRecordBrowserCallback) (
+ AvahiRecordBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *name,
+ uint16_t clazz,
+ uint16_t type,
+ const void *rdata,
+ size_t size,
+ AvahiLookupResultFlags flags,
+ void *userdata);
+
+/** Browse for records of a type on the local network */
+AvahiRecordBrowser* avahi_record_browser_new(
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const char *name,
+ uint16_t clazz,
+ uint16_t type,
+ AvahiLookupFlags flags,
+ AvahiRecordBrowserCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiRecordBrowser object */
+AvahiClient* avahi_record_browser_get_client(AvahiRecordBrowser *);
+
+/** Cleans up and frees an AvahiRecordBrowser object */
+int avahi_record_browser_free(AvahiRecordBrowser *);
+
+/** @} */
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/address.h b/src/libs/zeroconf/avahi-common/address.h
new file mode 100644
index 0000000000..a14104fad6
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/address.h
@@ -0,0 +1,119 @@
+#ifndef fooaddresshfoo
+#define fooaddresshfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file address.h Definitions and functions to manipulate IP addresses. */
+
+#include <inttypes.h>
+#include <sys/types.h>
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+/** Protocol family specification, takes the values AVAHI_PROTO_INET, AVAHI_PROTO_INET6, AVAHI_PROTO_UNSPEC */
+typedef int AvahiProtocol;
+
+/** Numeric network interface index. Takes OS dependent values and the special constant AVAHI_IF_UNSPEC */
+typedef int AvahiIfIndex;
+
+/** Values for AvahiProtocol */
+enum {
+ AVAHI_PROTO_INET = 0, /**< IPv4 */
+ AVAHI_PROTO_INET6 = 1, /**< IPv6 */
+ AVAHI_PROTO_UNSPEC = -1 /**< Unspecified/all protocol(s) */
+};
+
+/** Special values for AvahiIfIndex */
+enum {
+ AVAHI_IF_UNSPEC = -1 /**< Unspecified/all interface(s) */
+};
+
+/** Maximum size of an address in string form */
+#define AVAHI_ADDRESS_STR_MAX 40 /* IPv6 Max = 4*8 + 7 + 1 for NUL */
+
+/** Return TRUE if the specified interface index is valid */
+#define AVAHI_IF_VALID(ifindex) (((ifindex) >= 0) || ((ifindex) == AVAHI_IF_UNSPEC))
+
+/** Return TRUE if the specified protocol is valid */
+#define AVAHI_PROTO_VALID(protocol) (((protocol) == AVAHI_PROTO_INET) || ((protocol) == AVAHI_PROTO_INET6) || ((protocol) == AVAHI_PROTO_UNSPEC))
+
+/** An IPv4 address */
+typedef struct AvahiIPv4Address {
+ uint32_t address; /**< Address data in network byte order. */
+} AvahiIPv4Address;
+
+/** An IPv6 address */
+typedef struct AvahiIPv6Address {
+ uint8_t address[16]; /**< Address data */
+} AvahiIPv6Address;
+
+/** Protocol (address family) independent address structure */
+typedef struct AvahiAddress {
+ AvahiProtocol proto; /**< Address family */
+
+ union {
+ AvahiIPv6Address ipv6; /**< Address when IPv6 */
+ AvahiIPv4Address ipv4; /**< Address when IPv4 */
+ uint8_t data[1]; /**< Type-independent data field */
+ } data;
+} AvahiAddress;
+
+/** @{ \name Comparison */
+
+/** Compare two addresses. Returns 0 when equal, a negative value when a < b, a positive value when a > b. */
+int avahi_address_cmp(const AvahiAddress *a, const AvahiAddress *b);
+
+/** @} */
+
+/** @{ \name String conversion */
+
+/** Convert the specified address *a to a human readable character string, use AVAHI_ADDRESS_STR_MAX to allocate an array of the right size */
+char *avahi_address_snprint(char *ret_s, size_t length, const AvahiAddress *a);
+
+/** Convert the specified human readable character string to an
+ * address structure. Set af to AVAHI_UNSPEC for automatic address
+ * family detection. */
+AvahiAddress *avahi_address_parse(const char *s, AvahiProtocol af, AvahiAddress *ret_addr);
+
+/** @} */
+
+/** \cond fulldocs */
+/** Generate the DNS reverse lookup name for an IPv4 or IPv6 address. */
+char* avahi_reverse_lookup_name(const AvahiAddress *a, char *ret_s, size_t length);
+/** \endcond */
+
+/** @{ \name Protocol/address family handling */
+
+/** Map AVAHI_PROTO_xxx constants to Unix AF_xxx constants */
+int avahi_proto_to_af(AvahiProtocol proto);
+
+/** Map Unix AF_xxx constants to AVAHI_PROTO_xxx constants */
+AvahiProtocol avahi_af_to_proto(int af);
+
+/** Return a textual representation of the specified protocol number. i.e. "IPv4", "IPv6" or "UNSPEC" */
+const char* avahi_proto_to_string(AvahiProtocol proto);
+
+/** @} */
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/cdecl.h b/src/libs/zeroconf/avahi-common/cdecl.h
new file mode 100644
index 0000000000..aef6aba0e9
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/cdecl.h
@@ -0,0 +1,38 @@
+#ifndef foocdeclhfoo
+#define foocdeclhfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file cdecl.h C++ compatibility */
+#ifdef __cplusplus
+/** If using C++ this macro enables C mode, otherwise does nothing */
+#define AVAHI_C_DECL_BEGIN extern "C" {
+/** If using C++ this macro switches back to C++ mode, otherwise does nothing */
+#define AVAHI_C_DECL_END }
+
+#else
+/** If using C++ this macro enables C mode, otherwise does nothing */
+#define AVAHI_C_DECL_BEGIN
+/** If using C++ this macro switches back to C++ mode, otherwise does nothing */
+#define AVAHI_C_DECL_END
+
+#endif
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/defs.h b/src/libs/zeroconf/avahi-common/defs.h
new file mode 100644
index 0000000000..bb73a9dfdb
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/defs.h
@@ -0,0 +1,356 @@
+#ifndef foodefshfoo
+#define foodefshfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file defs.h Some common definitions */
+
+#include <avahi-common/cdecl.h>
+
+/** \mainpage
+ *
+ * \section choose_api Choosing an API
+ *
+ * Avahi provides three programming APIs for integration of
+ * mDNS/DNS-SD features into your C progams:
+ *
+ * \li <b>avahi-core</b>: an API for embedding a complete mDNS/DNS-SD stack
+ * into your software. This is intended for developers of embedded
+ * appliances only. We dissuade from using this API in normal desktop
+ * applications since it is not a good idea to run multiple mDNS
+ * stacks simultaneously on the same host.
+ * \li <b>the D-Bus API</b>: an extensive D-Bus interface for browsing and
+ * registering mDNS/DNS-SD services using avahi-daemon. We recommend
+ * using this API for software written in any language other than
+ * C (e.g. Python).
+ * \li <b>avahi-client</b>: a simplifying C wrapper around the D-Bus API. We
+ * recommend using this API in C or C++ progams. The D-Bus internals
+ * are hidden completely.
+ * \li <b>avahi-gobject</b>: an object-oriented C wrapper based on
+ * GLib's GObject. We recommd using this API for GNOME/Gtk programs.
+ *
+ * All three APIs are very similar, however avahi-core is the most powerful.
+ *
+ * In addition to the three APIs described above Avahi supports two
+ * compatibility libraries:
+ *
+ * \li <b>avahi-compat-libdns_sd</b>: the original Bonjour API as documented
+ * in the header file "dns_sd.h" by Apple Computer, Inc.
+ *
+ * \li <b>avahi-compat-howl</b>: the HOWL API as released with HOWL 0.9.8 by
+ * Porchdog Software.
+ *
+ * Please note that these compatibility layers are incomplete and
+ * generally a waste of resources. We strongly encourage everyone to
+ * use our native APIs for newly written programs and to port older
+ * programs to avahi-client!
+ *
+ * The native APIs (avahi-client and avahi-core) can be integrated
+ * into external event loops. We provide adapters for the following
+ * event loop implementations:
+ *
+ * \li <b>avahi-glib</b>: The GLIB main loop as used by GTk+/GNOME
+ *
+ * \li <b>avahi-qt</b>: The Qt main loop as used by Qt/KDE
+ *
+ * Finally, we provide a high-level Gtk+ GUI dialog called
+ * <b>avahi-ui</b> for user-friendly browsing for services.
+ *
+ * The doxygen-generated API documentation covers avahi-client
+ * (including its auxiliary APIs), the event loop adapters and
+ * avahi-ui. For the other APIs please consult the original
+ * documentation (for the compatibility APIs) or the header files.
+ *
+ * Please note that the doxygen-generated API documentation of the
+ * native Avahi API is not complete. A few definitions that are part
+ * of the Avahi API have been removed from this documentation, either
+ * because they are only relevant in a very few low-level applications
+ * or because they are considered obsolete. Please consult the C header
+ * files for all definitions that are part of the Avahi API. Please
+ * note that these hidden definitions are considered part of the Avahi
+ * API and will stay available in the API in the future.
+ *
+ * \section error_reporting Error Reporting
+ *
+ * Some notes on the Avahi error handling:
+ *
+ * - Error codes are negative integers and defined as AVAHI_ERR_xx
+ * - If a function returns some kind of non-negative integer value on
+ * success, a failure is indicated by returning the error code
+ * directly.
+ * - If a function returns a pointer of some kind on success, a
+ * failure is indicated by returning NULL
+ * - The last error number may be retrieved by calling
+ * avahi_client_errno()
+ * - Just like the libc errno variable the Avahi errno is NOT reset to
+ * AVAHI_OK if a function call succeeds.
+ * - You may convert a numeric error code into a human readable string
+ * using avahi_strerror()
+ * - The constructor function avahi_client_new() returns the error
+ * code in a call-by-reference argument
+ *
+ * \section event_loop Event Loop Abstraction
+ *
+ * Avahi uses a simple event loop abstraction layer. A table AvahiPoll
+ * which contains function pointers for user defined timeout and I/O
+ * condition event source implementations needs to be passed to
+ * avahi_client_new(). An adapter for this abstraction layer is
+ * available for the GLib main loop in the object AvahiGLibPoll. A
+ * simple stand-alone implementation is available under the name
+ * AvahiSimplePoll. An adpater for the Qt main loop is available from
+ * avahi_qt_poll_get().
+ *
+ * \section good_publish How to Register Services
+ *
+ * - Subscribe to server state changes. Pass a callback function
+ * pointer to avahi_client_new(). It will be called
+ * whenever the server state changes.
+ * - Only register your services when the server is in state
+ * AVAHI_SERVER_RUNNING. If you register your services in other server
+ * states they might not be accessible since the local host name might not necessarily
+ * be established.
+ * - Remove your services when the server enters
+ * AVAHI_SERVER_COLLISION or AVAHI_SERVER_REGISTERING state. Your
+ * services may not be reachable anymore since the local host name is
+ * no longer established or is currently in the process of being
+ * established.
+ * - When registering services, use the following algorithm:
+ * - Create a new entry group (i.e. avahi_entry_group_new())
+ * - Add your service(s)/additional RRs/subtypes (e.g. avahi_entry_group_add_service())
+ * - Commit the entry group (i.e. avahi_entry_group_commit())
+ * - Subscribe to entry group state changes.
+ * - If the entry group enters AVAHI_ENTRY_GROUP_COLLISION state the
+ * services of the entry group are automatically removed from the
+ * server. You may immediately add your services back to the entry
+ * group (but with new names, perhaps using
+ * avahi_alternative_service_name()) and commit again. Please do not
+ * free the entry group and create a new one. This would inhibit some
+ * traffic limiting algorithms in mDNS.
+ * - When you need to modify your services (i.e. change the TXT data
+ * or the port number), use the AVAHI_PUBLISH_UPDATE flag. Please do
+ * not free the entry group and create a new one. This would inhibit
+ * some traffic limiting algorithms in mDNS. When changing just the
+ * TXT data avahi_entry_group_update_txt() is a shortcut for
+ * AVAHI_PUBLISH_UPDATE. Please note that you cannot use
+ * AVAHI_PUBLISH_UPDATE when changing the service name! Renaming a
+ * DNS-SD service is identical to deleting and creating a new one, and
+ * that's exactly what you should do in that case. First call
+ * avahi_entry_group_reset() to remove it and then read it normally.
+ *
+ * \section good_browse How to Browse for Services
+ *
+ * - For normal applications you need to call avahi_service_browser_new()
+ * for the service type you want to browse for. Use
+ * avahi_service_resolver_new() to acquire service data for a service
+ * name.
+ * - You can use avahi_domain_browser_new() to get a list of announced
+ * browsing domains. Please note that not all domains whith services
+ * on the LAN are mandatorily announced.
+ * - There is no need to subscribe to server state changes.
+ *
+ * \section daemon_dies How to Write a Client That Can Deal with Daemon Restarts
+ *
+ * With Avahi it is possible to write client applications that can
+ * deal with Avahi daemon restarts. To accomplish that make sure to
+ * pass AVAHI_CLIENT_NO_FAIL to avahi_client_new()'s flags
+ * parameter. That way avahi_client_new() will succeed even when the
+ * daemon is not running. In that case the object will enter
+ * AVAHI_CLIENT_CONNECTING state. As soon as the daemon becomes
+ * available the object will enter one of the AVAHI_CLIENT_S_xxx
+ * states. Make sure to not create browsers or entry groups before the
+ * client object has entered one of those states. As usual you will be
+ * informed about state changes with the callback function supplied to
+ * avahi_client_new(). If the client is forced to disconnect from the
+ * server it will enter AVAHI_CLIENT_FAILURE state with
+ * avahi_client_errno() == AVAHI_ERR_DISCONNECTED. Free the
+ * AvahiClient object in that case (and all its associated objects
+ * such as entry groups and browser objects prior to that) and
+ * reconnect to the server anew - again with passing
+ * AVAHI_CLIENT_NO_FAIL to avahi_client_new().
+ *
+ * We encourage implementing this in all software where service
+ * discovery is not an integral part of application. e.g. use it in
+ * all kinds of background daemons, but not necessarily in software
+ * like iChat compatible IM software.
+ *
+ * For now AVAHI_CLIENT_NO_FAIL cannot deal with D-Bus daemon restarts.
+ *
+ * \section domains How to Deal Properly with Browsing Domains
+ *
+ * Due to the introduction of wide-area DNS-SD the correct handling of
+ * domains becomes more important for Avahi enabled applications. All
+ * applications that offer the user a list of services discovered with
+ * Avahi should offer some kind of editable drop down box where the
+ * user can either enter his own domain or select one of those offered
+ * by AvahiDomainBrowser. The default domain to browse should be the
+ * one returned by avahi_client_get_domain_name(). The list of domains
+ * returned by AvahiDomainBrowser is assembled by the browsing domains
+ * configured in the daemon's configuration file, the domains
+ * announced inside the default domain, the domains set with the
+ * environment variable $AVAHI_BROWSE_DOMAINS (colon-seperated) on the
+ * client side and the domains set in the XDG configuration file
+ * ~/.config/avahi/browse-domains on the client side (seperated by
+ * newlines). File managers offering some kind of "Network
+ * Neighborhood" folder should show the entries of the default domain
+ * right inside that and offer subfolders for the browsing domains
+ * returned by AvahiDomainBrowser.
+ */
+
+AVAHI_C_DECL_BEGIN
+
+/** @{ \name States */
+
+/** States of a server object */
+typedef enum {
+ AVAHI_SERVER_INVALID, /**< Invalid state (initial) */
+ AVAHI_SERVER_REGISTERING, /**< 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_FAILURE /**< Some fatal failure happened, the server is unable to proceed */
+} AvahiServerState;
+
+/** States of an entry group object */
+typedef enum {
+ AVAHI_ENTRY_GROUP_UNCOMMITED, /**< The group has not yet been commited, the user must still call avahi_entry_group_commit() */
+ AVAHI_ENTRY_GROUP_REGISTERING, /**< The entries of the group are currently being registered */
+ AVAHI_ENTRY_GROUP_ESTABLISHED, /**< The entries have successfully been established */
+ AVAHI_ENTRY_GROUP_COLLISION, /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */
+ AVAHI_ENTRY_GROUP_FAILURE /**< Some kind of failure happened, the entries have been withdrawn */
+} AvahiEntryGroupState;
+
+/** @} */
+
+/** @{ \name Flags */
+
+/** Some flags for publishing functions */
+typedef enum {
+ AVAHI_PUBLISH_UNIQUE = 1, /**< For raw records: The RRset is intended to be unique */
+ AVAHI_PUBLISH_NO_PROBE = 2, /**< For raw records: Though the RRset is intended to be unique no probes shall be sent */
+ AVAHI_PUBLISH_NO_ANNOUNCE = 4, /**< For raw records: Do not announce this RR to other hosts */
+ AVAHI_PUBLISH_ALLOW_MULTIPLE = 8, /**< For raw records: Allow multiple local records of this type, even if they are intended to be unique */
+/** \cond fulldocs */
+ AVAHI_PUBLISH_NO_REVERSE = 16, /**< For address records: don't create a reverse (PTR) entry */
+ AVAHI_PUBLISH_NO_COOKIE = 32, /**< For service records: do not implicitly add the local service cookie to TXT data */
+/** \endcond */
+ AVAHI_PUBLISH_UPDATE = 64, /**< Update existing records instead of adding new ones */
+/** \cond fulldocs */
+ AVAHI_PUBLISH_USE_WIDE_AREA = 128, /**< Register the record using wide area DNS (i.e. unicast DNS update) */
+ AVAHI_PUBLISH_USE_MULTICAST = 256 /**< Register the record using multicast DNS */
+/** \endcond */
+} AvahiPublishFlags;
+
+/** Some flags for lookup functions */
+typedef enum {
+/** \cond fulldocs */
+ AVAHI_LOOKUP_USE_WIDE_AREA = 1, /**< Force lookup via wide area DNS */
+ AVAHI_LOOKUP_USE_MULTICAST = 2, /**< Force lookup via multicast DNS */
+/** \endcond */
+ AVAHI_LOOKUP_NO_TXT = 4, /**< When doing service resolving, don't lookup TXT record */
+ AVAHI_LOOKUP_NO_ADDRESS = 8 /**< When doing service resolving, don't lookup A/AAAA record */
+} AvahiLookupFlags;
+
+/** Some flags for lookup callback functions */
+typedef enum {
+ AVAHI_LOOKUP_RESULT_CACHED = 1, /**< This response originates from the cache */
+ AVAHI_LOOKUP_RESULT_WIDE_AREA = 2, /**< This response originates from wide area DNS */
+ AVAHI_LOOKUP_RESULT_MULTICAST = 4, /**< This response originates from multicast DNS */
+ AVAHI_LOOKUP_RESULT_LOCAL = 8, /**< This record/service resides on and was announced by the local host. Only available in service and record browsers and only on AVAHI_BROWSER_NEW. */
+ AVAHI_LOOKUP_RESULT_OUR_OWN = 16, /**< This service belongs to the same local client as the browser object. Only available in avahi-client, and only for service browsers and only on AVAHI_BROWSER_NEW. */
+ AVAHI_LOOKUP_RESULT_STATIC = 32 /**< The returned data has been defined statically by some configuration option */
+} AvahiLookupResultFlags;
+
+/** @} */
+
+/** @{ \name Events */
+
+/** Type of callback event when browsing */
+typedef enum {
+ AVAHI_BROWSER_NEW, /**< The object is new on the network */
+ AVAHI_BROWSER_REMOVE, /**< The object has been removed from the network */
+ AVAHI_BROWSER_CACHE_EXHAUSTED, /**< One-time event, to notify the user that all entries from the caches have been sent */
+ AVAHI_BROWSER_ALL_FOR_NOW, /**< One-time event, to notify the user that more records will probably not show up in the near future, i.e. all cache entries have been read and all static servers been queried */
+ AVAHI_BROWSER_FAILURE /**< Browsing failed due to some reason which can be retrieved using avahi_server_errno()/avahi_client_errno() */
+} AvahiBrowserEvent;
+
+/** Type of callback event when resolving */
+typedef enum {
+ AVAHI_RESOLVER_FOUND, /**< RR found, resolving successful */
+ AVAHI_RESOLVER_FAILURE /**< Resolving failed due to some reason which can be retrieved using avahi_server_errno()/avahi_client_errno() */
+} AvahiResolverEvent;
+
+/** @} */
+
+/** @{ \name Other definitions */
+
+/** The type of domain to browse for */
+typedef enum {
+ 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_REGISTER, /**< Browse for a list of available registering domains */
+ AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT, /**< Browse for the default registering domain */
+ AVAHI_DOMAIN_BROWSER_BROWSE_LEGACY, /**< Legacy browse domain - see DNS-SD spec for more information */
+ AVAHI_DOMAIN_BROWSER_MAX
+} AvahiDomainBrowserType;
+
+/** @} */
+
+/** \cond fulldocs */
+/** For every service a special TXT item is implicitly added, which
+ * contains a random cookie which is private to the local daemon. This
+ * can be used by clients to determine if two services on two
+ * different subnets are effectively the same. */
+#define AVAHI_SERVICE_COOKIE "org.freedesktop.Avahi.cookie"
+
+/** In invalid cookie as special value */
+#define AVAHI_SERVICE_COOKIE_INVALID (0)
+/** \endcond fulldocs */
+
+/** @{ \name DNS RR definitions */
+
+/** DNS record types, see RFC 1035 */
+enum {
+ AVAHI_DNS_TYPE_A = 0x01,
+ AVAHI_DNS_TYPE_NS = 0x02,
+ AVAHI_DNS_TYPE_CNAME = 0x05,
+ AVAHI_DNS_TYPE_SOA = 0x06,
+ AVAHI_DNS_TYPE_PTR = 0x0C,
+ AVAHI_DNS_TYPE_HINFO = 0x0D,
+ AVAHI_DNS_TYPE_MX = 0x0F,
+ AVAHI_DNS_TYPE_TXT = 0x10,
+ AVAHI_DNS_TYPE_AAAA = 0x1C,
+ AVAHI_DNS_TYPE_SRV = 0x21
+};
+
+/** DNS record classes, see RFC 1035 */
+enum {
+ AVAHI_DNS_CLASS_IN = 0x01 /**< Probably the only class we will ever use */
+};
+
+/** @} */
+
+/** The default TTL for RRs which contain a host name of some kind. */
+#define AVAHI_DEFAULT_TTL_HOST_NAME (120)
+
+/** The default TTL for all other records. */
+#define AVAHI_DEFAULT_TTL (75*60)
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/error.h b/src/libs/zeroconf/avahi-common/error.h
new file mode 100644
index 0000000000..392aaf53bd
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/error.h
@@ -0,0 +1,107 @@
+#ifndef fooerrorhfoo
+#define fooerrorhfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file error.h Error codes and auxiliary functions */
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+/** 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_COLLISION = -8, /**< 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_INVALID_OPERATION = -21, /**< Invalid operation */
+ AVAHI_ERR_DBUS_ERROR = -22, /**< An unexpected D-Bus error occured */
+ AVAHI_ERR_DISCONNECTED = -23, /**< Daemon connection failed */
+ AVAHI_ERR_NO_MEMORY = -24, /**< Memory exhausted */
+ AVAHI_ERR_INVALID_OBJECT = -25, /**< The object passed to this function was invalid */
+ AVAHI_ERR_NO_DAEMON = -26, /**< Daemon not running */
+ AVAHI_ERR_INVALID_INTERFACE = -27, /**< Invalid interface */
+ AVAHI_ERR_INVALID_PROTOCOL = -28, /**< Invalid protocol */
+ AVAHI_ERR_INVALID_FLAGS = -29, /**< Invalid flags */
+
+ AVAHI_ERR_NOT_FOUND = -30, /**< Not found */
+ AVAHI_ERR_INVALID_CONFIG = -31, /**< Configuration error */
+ AVAHI_ERR_VERSION_MISMATCH = -32, /**< Verson mismatch */
+ AVAHI_ERR_INVALID_SERVICE_SUBTYPE = -33, /**< Invalid service subtype */
+ AVAHI_ERR_INVALID_PACKET = -34, /**< Invalid packet */
+ AVAHI_ERR_INVALID_DNS_ERROR = -35, /**< Invlaid DNS return code */
+ AVAHI_ERR_DNS_FORMERR = -36, /**< DNS Error: Form error */
+ AVAHI_ERR_DNS_SERVFAIL = -37, /**< DNS Error: Server Failure */
+ AVAHI_ERR_DNS_NXDOMAIN = -38, /**< DNS Error: No such domain */
+ AVAHI_ERR_DNS_NOTIMP = -39, /**< DNS Error: Not implemented */
+
+ AVAHI_ERR_DNS_REFUSED = -40, /**< DNS Error: Operation refused */
+ AVAHI_ERR_DNS_YXDOMAIN = -41,
+ AVAHI_ERR_DNS_YXRRSET = -42,
+ AVAHI_ERR_DNS_NXRRSET = -43,
+ AVAHI_ERR_DNS_NOTAUTH = -44, /**< DNS Error: Not authorized */
+ AVAHI_ERR_DNS_NOTZONE = -45,
+ AVAHI_ERR_INVALID_RDATA = -46, /**< Invalid RDATA */
+ AVAHI_ERR_INVALID_DNS_CLASS = -47, /**< Invalid DNS class */
+ AVAHI_ERR_INVALID_DNS_TYPE = -48, /**< Invalid DNS type */
+ AVAHI_ERR_NOT_SUPPORTED = -49, /**< Not supported */
+
+ AVAHI_ERR_NOT_PERMITTED = -50, /**< Operation not permitted */
+ AVAHI_ERR_INVALID_ARGUMENT = -51, /**< Invalid argument */
+ AVAHI_ERR_IS_EMPTY = -52, /**< Is empty */
+ AVAHI_ERR_NO_CHANGE = -53, /**< The requested operation is invalid because it is redundant */
+
+ /****
+ **** IF YOU ADD A NEW ERROR CODE HERE, PLEASE DON'T FORGET TO ADD
+ **** IT TO THE STRING ARRAY IN avahi_strerror() IN error.c AND
+ **** TO THE ARRAY IN dbus.c AND FINALLY TO dbus.h!
+ ****
+ **** Also remember to update the MAX value below.
+ ****/
+
+ AVAHI_ERR_MAX = -54
+};
+
+/** Return a human readable error string for the specified error code */
+const char *avahi_strerror(int error);
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/gccmacro.h b/src/libs/zeroconf/avahi-common/gccmacro.h
new file mode 100644
index 0000000000..4c97111aaf
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/gccmacro.h
@@ -0,0 +1,74 @@
+#ifndef foogccmacrohfoo
+#define foogccmacrohfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file gccmacro.h Defines some macros for GCC extensions */
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+#if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
+#define AVAHI_GCC_ALLOC_SIZE(x) __attribute__ ((__alloc_size__(x)))
+#define AVAHI_GCC_ALLOC_SIZE2(x,y) __attribute__ ((__alloc_size__(x,y)))
+#else
+/** Macro for usage of GCC's alloc_size attribute */
+#define AVAHI_GCC_ALLOC_SIZE(x)
+#define AVAHI_GCC_ALLOC_SIZE2(x,y)
+#endif
+
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define AVAHI_GCC_SENTINEL __attribute__ ((sentinel))
+#else
+/** Macro for usage of GCC's sentinel compilation warnings */
+#define AVAHI_GCC_SENTINEL
+#endif
+
+#ifdef __GNUC__
+#define AVAHI_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
+#else
+/** Macro for usage of GCC's printf compilation warnings */
+#define AVAHI_GCC_PRINTF_ATTR(a,b)
+#endif
+
+/** Same as AVAHI_GCC_PRINTF_ATTR but hard coded to arguments 1 and 2 */
+#define AVAHI_GCC_PRINTF_ATTR12 AVAHI_GCC_PRINTF_ATTR(1,2)
+
+/** Same as AVAHI_GCC_PRINTF_ATTR but hard coded to arguments 2 and 3 */
+#define AVAHI_GCC_PRINTF_ATTR23 AVAHI_GCC_PRINTF_ATTR(2,3)
+
+#ifdef __GNUC__
+#define AVAHI_GCC_NORETURN __attribute__((noreturn))
+#else
+/** Macro for no-return functions */
+#define AVAHI_GCC_NORETURN
+#endif
+
+#ifdef __GNUC__
+#define AVAHI_GCC_UNUSED __attribute__ ((unused))
+#else
+/** Macro for not used parameter */
+#define AVAHI_GCC_UNUSED
+#endif
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/malloc.h b/src/libs/zeroconf/avahi-common/malloc.h
new file mode 100644
index 0000000000..ffaac3f3c7
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/malloc.h
@@ -0,0 +1,96 @@
+#ifndef foomallochfoo
+#define foomallochfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file malloc.h Memory allocation */
+
+#include <sys/types.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <assert.h>
+
+#include <avahi-common/cdecl.h>
+#include <avahi-common/gccmacro.h>
+
+AVAHI_C_DECL_BEGIN
+
+/** Allocate some memory, just like the libc malloc() */
+void *avahi_malloc(size_t size) AVAHI_GCC_ALLOC_SIZE(1);
+
+/** Similar to avahi_malloc() but set the memory to zero */
+void *avahi_malloc0(size_t size) AVAHI_GCC_ALLOC_SIZE(1);
+
+/** Free some memory */
+void avahi_free(void *p);
+
+/** Similar to libc's realloc() */
+void *avahi_realloc(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2);
+
+/** Internal helper for avahi_new() */
+static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
+ assert(n < INT_MAX/k);
+ return avahi_malloc(n*k);
+}
+
+/** Allocate n new structures of the specified type. */
+#define avahi_new(type, n) ((type*) avahi_new_internal((n), sizeof(type)))
+
+/** Internal helper for avahi_new0() */
+static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new0_internal(unsigned n, size_t k) {
+ assert(n < INT_MAX/k);
+ return avahi_malloc0(n*k);
+}
+
+/** Same as avahi_new() but set the memory to zero */
+#define avahi_new0(type, n) ((type*) avahi_new0_internal((n), sizeof(type)))
+
+/** Just like libc's strdup() */
+char *avahi_strdup(const char *s);
+
+/** Just like libc's strndup() */
+char *avahi_strndup(const char *s, size_t l);
+
+/** Duplicate the given memory block into a new one allocated with avahi_malloc() */
+void *avahi_memdup(const void *s, size_t l) AVAHI_GCC_ALLOC_SIZE(2);
+
+/** Wraps allocator functions */
+typedef struct AvahiAllocator {
+ void* (*malloc)(size_t size) AVAHI_GCC_ALLOC_SIZE(1);
+ void (*free)(void *p);
+ void* (*realloc)(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2);
+ void* (*calloc)(size_t nmemb, size_t size) AVAHI_GCC_ALLOC_SIZE2(1,2); /**< May be NULL */
+} AvahiAllocator;
+
+/** Change the allocator. May be NULL to return to default (libc)
+ * allocators. The structure is not copied! */
+void avahi_set_allocator(const AvahiAllocator *a);
+
+/** Like sprintf() but store the result in a freshly allocated buffer. Free this with avahi_free() */
+char *avahi_strdup_printf(const char *fmt, ... ) AVAHI_GCC_PRINTF_ATTR12;
+
+/** \cond fulldocs */
+/** Same as avahi_strdup_printf() but take a va_list instead of varargs */
+char *avahi_strdup_vprintf(const char *fmt, va_list ap);
+/** \endcond */
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/simple-watch.h b/src/libs/zeroconf/avahi-common/simple-watch.h
new file mode 100644
index 0000000000..72c1905bcb
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/simple-watch.h
@@ -0,0 +1,85 @@
+#ifndef foosimplewatchhfoo
+#define foosimplewatchhfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file simple-watch.h Simple poll() based main loop implementation */
+
+#include <sys/poll.h>
+#include <avahi-common/cdecl.h>
+#include <avahi-common/watch.h>
+
+AVAHI_C_DECL_BEGIN
+
+/** A main loop object. Main loops of this type aren't very flexible
+ * since they only support a single wakeup type. Nevertheless it
+ * should suffice for small test and example applications. */
+typedef struct AvahiSimplePoll AvahiSimplePoll;
+
+/** Create a new main loop object */
+AvahiSimplePoll *avahi_simple_poll_new(void);
+
+/** Free a main loop object */
+void avahi_simple_poll_free(AvahiSimplePoll *s);
+
+/** Return the abstracted poll API object for this main loop
+ * object. The is will return the same pointer each time it is
+ * called. */
+const AvahiPoll* avahi_simple_poll_get(AvahiSimplePoll *s);
+
+/** Run a single main loop iteration of this main loop. If sleep_time
+is < 0 this will block until any of the registered events happens,
+then it will execute the attached callback function. If sleep_time is
+0 the routine just checks if any event is pending. If yes the attached
+callback function is called, otherwise the function returns
+immediately. If sleep_time > 0 the function will block for at most the
+specified time in msecs. Returns -1 on error, 0 on success and 1 if a
+quit request has been scheduled. Usually this function should be called
+in a loop until it returns a non-zero value*/
+int avahi_simple_poll_iterate(AvahiSimplePoll *s, int sleep_time);
+
+/** Request that the main loop quits. If this is called the next
+ call to avahi_simple_poll_iterate() will return 1 */
+void avahi_simple_poll_quit(AvahiSimplePoll *s);
+
+/** Prototype for a poll() type function */
+typedef int (*AvahiPollFunc)(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata);
+
+/** Replace the internally used poll() function. By default the system's poll() will be used */
+void avahi_simple_poll_set_func(AvahiSimplePoll *s, AvahiPollFunc func, void *userdata);
+
+/** The first stage of avahi_simple_poll_iterate(), use this function only if you know what you do */
+int avahi_simple_poll_prepare(AvahiSimplePoll *s, int timeout);
+
+/** The second stage of avahi_simple_poll_iterate(), use this function only if you know what you do */
+int avahi_simple_poll_run(AvahiSimplePoll *s);
+
+/** The third and final stage of avahi_simple_poll_iterate(), use this function only if you know what you do */
+int avahi_simple_poll_dispatch(AvahiSimplePoll *s);
+
+/** Call avahi_simple_poll_iterate() in a loop and return if it returns non-zero */
+int avahi_simple_poll_loop(AvahiSimplePoll *s);
+
+/** Wakeup the main loop. (for threaded environments) */
+void avahi_simple_poll_wakeup(AvahiSimplePoll *s);
+
+AVAHI_C_DECL_END
+
+#endif
diff --git a/src/libs/zeroconf/avahi-common/strlst.h b/src/libs/zeroconf/avahi-common/strlst.h
new file mode 100644
index 0000000000..94adcea8af
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/strlst.h
@@ -0,0 +1,180 @@
+#ifndef footxtlisthfoo
+#define footxtlisthfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file strlst.h Implementation of a data type to store lists of strings */
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdarg.h>
+
+#include <avahi-common/cdecl.h>
+#include <avahi-common/gccmacro.h>
+
+AVAHI_C_DECL_BEGIN
+
+/** Linked list of strings that can contain any number of binary
+ * characters, including NUL bytes. An empty list is created by
+ * assigning a NULL to a pointer to AvahiStringList. The string list
+ * is stored in reverse order, so that appending to the string list is
+ * effectively a prepending to the linked list. This object is used
+ * primarily for storing DNS TXT record data. */
+typedef struct AvahiStringList {
+ struct AvahiStringList *next; /**< Pointer to the next linked list element */
+ size_t size; /**< Size of text[] */
+ uint8_t text[1]; /**< Character data */
+} AvahiStringList;
+
+/** @{ \name Construction and destruction */
+
+/** Create a new string list by taking a variable list of NUL
+ * terminated strings. The strings are copied using g_strdup(). The
+ * argument list must be terminated by a NULL pointer. */
+AvahiStringList *avahi_string_list_new(const char *txt, ...) AVAHI_GCC_SENTINEL;
+
+/** \cond fulldocs */
+/** Same as avahi_string_list_new() but pass a va_list structure */
+AvahiStringList *avahi_string_list_new_va(va_list va);
+/** \endcond */
+
+/** Create a new string list from a string array. The strings are
+ * copied using g_strdup(). length should contain the length of the
+ * array, or -1 if the array is NULL terminated*/
+AvahiStringList *avahi_string_list_new_from_array(const char **array, int length);
+
+/** Free a string list */
+void avahi_string_list_free(AvahiStringList *l);
+
+/** @} */
+
+/** @{ \name Adding strings */
+
+/** Append a NUL terminated string to the specified string list. The
+ * passed string is copied using g_strdup(). Returns the new list
+ * start. */
+AvahiStringList *avahi_string_list_add(AvahiStringList *l, const char *text);
+
+/** Append a new NUL terminated formatted string to the specified string list */
+AvahiStringList *avahi_string_list_add_printf(AvahiStringList *l, const char *format, ...) AVAHI_GCC_PRINTF_ATTR23;
+
+/** \cond fulldocs */
+/** Append a new NUL terminated formatted string to the specified string list */
+AvahiStringList *avahi_string_list_add_vprintf(AvahiStringList *l, const char *format, va_list va);
+/** \endcond */
+
+/** Append an arbitrary length byte string to the list. Returns the
+ * new list start. */
+AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const uint8_t *text, size_t size);
+
+/** Append a new entry to the string list. The string is not filled
+with data. The caller should fill in string data afterwards by writing
+it to l->text, where l is the pointer returned by this function. This
+function exists solely to optimize a few operations where otherwise
+superfluous string copying would be necessary. */
+AvahiStringList*avahi_string_list_add_anonymous(AvahiStringList *l, size_t size);
+
+/** Same as avahi_string_list_add(), but takes a variable number of
+ * NUL terminated strings. The argument list must be terminated by a
+ * NULL pointer. Returns the new list start. */
+AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...) AVAHI_GCC_SENTINEL;
+
+/** \cond fulldocs */
+/** Same as avahi_string_list_add_many(), but use a va_list
+ * structure. Returns the new list start. */
+AvahiStringList *avahi_string_list_add_many_va(AvahiStringList *r, va_list va);
+/** \endcond */
+
+/** @} */
+
+/** @{ \name String list operations */
+
+/** Convert the string list object to a single character string,
+ * seperated by spaces and enclosed in "". avahi_free() the result! This
+ * function doesn't work well with strings that contain NUL bytes. */
+char* avahi_string_list_to_string(AvahiStringList *l);
+
+/** \cond fulldocs */
+/** Serialize the string list object in a way that is compatible with
+ * the storing of DNS TXT records. Strings longer than 255 bytes are truncated. */
+size_t avahi_string_list_serialize(AvahiStringList *l, void * data, size_t size);
+
+/** Inverse of avahi_string_list_serialize() */
+int avahi_string_list_parse(const void *data, size_t size, AvahiStringList **ret);
+/** \endcond */
+
+/** Compare to string lists */
+int avahi_string_list_equal(const AvahiStringList *a, const AvahiStringList *b);
+
+/** Copy a string list */
+AvahiStringList *avahi_string_list_copy(const AvahiStringList *l);
+
+/** Reverse the string list. */
+AvahiStringList* avahi_string_list_reverse(AvahiStringList *l);
+
+/** Return the number of elements in the string list */
+unsigned avahi_string_list_length(const AvahiStringList *l);
+
+/** @} */
+
+/** @{ \name Accessing items */
+
+/** Returns the next item in the string list */
+AvahiStringList *avahi_string_list_get_next(AvahiStringList *l);
+
+/** Returns the text for the current item */
+uint8_t *avahi_string_list_get_text(AvahiStringList *l);
+
+/** Returns the size of the current text */
+size_t avahi_string_list_get_size(AvahiStringList *l);
+
+/** @} */
+
+/** @{ \name DNS-SD TXT pair handling */
+
+/** Find the string list entry for the given DNS-SD TXT key */
+AvahiStringList *avahi_string_list_find(AvahiStringList *l, const char *key);
+
+/** Return the DNS-SD TXT key and value for the specified string list
+ * item. If size is not NULL it will be filled with the length of
+ * value. (for strings containing NUL bytes). If the entry doesn't
+ * contain a value *value will be set to NULL. You need to
+ * avahi_free() the strings returned in *key and *value. */
+int avahi_string_list_get_pair(AvahiStringList *l, char **key, char **value, size_t *size);
+
+/** Add a new DNS-SD TXT key value pair to the string list. value may
+ * be NULL in case you want to specify a key without a value */
+AvahiStringList *avahi_string_list_add_pair(AvahiStringList *l, const char *key, const char *value);
+
+/** Same as avahi_string_list_add_pair() but allow strings containing NUL bytes in *value. */
+AvahiStringList *avahi_string_list_add_pair_arbitrary(AvahiStringList *l, const char *key, const uint8_t *value, size_t size);
+
+/** @} */
+
+/** \cond fulldocs */
+/** Try to find a magic service cookie in the specified DNS-SD string
+ * list. Or return AVAHI_SERVICE_COOKIE_INVALID if none is found. */
+uint32_t avahi_string_list_get_service_cookie(AvahiStringList *l);
+/** \endcond */
+
+AVAHI_C_DECL_END
+
+#endif
+
diff --git a/src/libs/zeroconf/avahi-common/watch.h b/src/libs/zeroconf/avahi-common/watch.h
new file mode 100644
index 0000000000..86e63d3bf5
--- /dev/null
+++ b/src/libs/zeroconf/avahi-common/watch.h
@@ -0,0 +1,97 @@
+#ifndef foowatchhfoo
+#define foowatchhfoo
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+/** \file watch.h Simplistic main loop abstraction */
+
+#include <sys/poll.h>
+#include <sys/time.h>
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+/** An I/O watch object */
+typedef struct AvahiWatch AvahiWatch;
+
+/** A timeout watch object */
+typedef struct AvahiTimeout AvahiTimeout;
+
+/** An event polling abstraction object */
+typedef struct AvahiPoll AvahiPoll;
+
+/** Type of watch events */
+typedef enum {
+ AVAHI_WATCH_IN = POLLIN, /**< Input event */
+ AVAHI_WATCH_OUT = POLLOUT, /**< Output event */
+ AVAHI_WATCH_ERR = POLLERR, /**< Error event */
+ AVAHI_WATCH_HUP = POLLHUP /**< Hangup event */
+} AvahiWatchEvent;
+
+/** Called whenever an I/O event happens on an I/O watch */
+typedef void (*AvahiWatchCallback)(AvahiWatch *w, int fd, AvahiWatchEvent event, void *userdata);
+
+/** Called when the timeout is reached */
+typedef void (*AvahiTimeoutCallback)(AvahiTimeout *t, void *userdata);
+
+/** Defines an abstracted event polling API. This may be used to
+ connect Avahi to other main loops. This is loosely based on Unix
+ poll(2). A consumer will call watch_new() for all file descriptors it
+ wants to listen for events on. In addition he can call timeout_new()
+ to define time based events .*/
+struct AvahiPoll {
+
+ /** Some abstract user data usable by the provider of the API */
+ void* userdata;
+
+ /** Create a new watch for the specified file descriptor and for
+ * the specified events. The API will call the callback function
+ * whenever any of the events happens. */
+ AvahiWatch* (*watch_new)(const AvahiPoll *api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata);
+
+ /** Update the events to wait for. It is safe to call this function from an AvahiWatchCallback */
+ void (*watch_update)(AvahiWatch *w, AvahiWatchEvent event);
+
+ /** Return the events that happened. It is safe to call this function from an AvahiWatchCallback */
+ AvahiWatchEvent (*watch_get_events)(AvahiWatch *w);
+
+ /** Free a watch. It is safe to call this function from an AvahiWatchCallback */
+ void (*watch_free)(AvahiWatch *w);
+
+ /** Set a wakeup time for the polling loop. The API will call the
+ callback function when the absolute time *tv is reached. If tv is
+ NULL, the timeout is disabled. After the timeout expired the
+ callback function will be called and the timeout is disabled. You
+ can reenable it by calling timeout_update() */
+ AvahiTimeout* (*timeout_new)(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata);
+
+ /** Update the absolute expiration time for a timeout, If tv is
+ * NULL, the timeout is disabled. It is safe to call this function from an AvahiTimeoutCallback */
+ void (*timeout_update)(AvahiTimeout *, const struct timeval *tv);
+
+ /** Free a timeout. It is safe to call this function from an AvahiTimeoutCallback */
+ void (*timeout_free)(AvahiTimeout *t);
+};
+
+AVAHI_C_DECL_END
+
+#endif
+
diff --git a/src/libs/zeroconf/avahiLib.cpp b/src/libs/zeroconf/avahiLib.cpp
new file mode 100644
index 0000000000..9558d02306
--- /dev/null
+++ b/src/libs/zeroconf/avahiLib.cpp
@@ -0,0 +1,478 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this file.
+** Please review the following information to ensure the GNU Lesser General
+** Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "servicebrowser.h"
+#include "servicebrowser_p.h"
+
+#include <QDebug>
+#include <QLibrary>
+#include <QString>
+#include <QStringList>
+
+//#ifdef Q_OS_LINUX
+#define AVAHI_LIB
+//#endif
+
+#ifdef AVAHI_LIB
+
+#include <avahi-client/client.h>
+#include <avahi-client/lookup.h>
+
+#include <avahi-common/simple-watch.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/error.h>
+
+#include <netinet/in.h>
+
+namespace ZeroConf {
+namespace Internal {
+
+extern "C" void cAvahiResolveReply( AvahiServiceResolver * r, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
+ AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *hostName,
+ const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags /*flags*/, void* context);
+extern "C" void cAvahiResolveEmptyReply(AvahiServiceResolver * r, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent, const char *, const char *,
+ const char *, const char *, const AvahiAddress *, uint16_t, AvahiStringList *, AvahiLookupResultFlags, void*);
+extern "C" void cAvahiClientReply (AvahiClient * /*s*/, AvahiClientState state, void* context);
+extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
+ AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
+ AvahiLookupResultFlags /*flags*/, void* context);
+
+extern "C" {
+typedef const AvahiPoll* (*AvahiSimplePollGet)(AvahiSimplePoll *s);
+typedef AvahiSimplePoll *(*AvahiSimplePollNewPtr)(void);
+typedef int (*AvahiSimplePollIteratePtr)(AvahiSimplePoll *s, int sleep_time);
+typedef void (*AvahiSimplePollQuitPtr)(AvahiSimplePoll *s);
+typedef void (*AvahiSimplePollFreePtr)(AvahiSimplePoll *s);
+typedef AvahiClient* (*AvahiClientNewPtr)(const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback,
+ void *userdata, int *error);
+typedef void (*AvahiClientFreePtr)(AvahiClient *client);
+typedef AvahiServiceBrowser* (*AvahiServiceBrowserNewPtr) (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol,
+ const char *type, const char *domain, AvahiLookupFlags flags,
+ AvahiServiceBrowserCallback callback, void *userdata);
+typedef int (*AvahiServiceBrowserFreePtr)(AvahiServiceBrowser *);
+
+typedef AvahiServiceResolver * (*AvahiServiceResolverNewPtr)(AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol,
+ const char *name, const char *type, const char *domain, AvahiProtocol aprotocol, AvahiLookupFlags flags,
+ AvahiServiceResolverCallback callback, void *userdata);
+typedef int (*AvahiServiceResolverFreePtr)(AvahiServiceResolver *r);
+}
+
+class AvahiZConfLib;
+
+struct MyAvahiConnection
+{
+ AvahiClient *client;
+ AvahiSimplePoll *simple_poll;
+ AvahiZConfLib *lib;
+ MyAvahiConnection() : client(0), simple_poll(0), lib(0)
+ { }
+};
+
+// represents an avahi library
+class AvahiZConfLib : public ZConfLib{
+private:
+ AvahiSimplePollGet m_simplePollGet;
+ AvahiSimplePollNewPtr m_simplePollNew;
+ AvahiSimplePollIteratePtr m_simplePollIterate;
+ AvahiSimplePollQuitPtr m_simplePollQuit;
+ AvahiSimplePollFreePtr m_simplePollFree;
+ AvahiClientNewPtr m_clientNew;
+ AvahiClientFreePtr m_clientFree;
+ AvahiServiceBrowserNewPtr m_serviceBrowserNew;
+ AvahiServiceBrowserFreePtr m_serviceBrowserFree;
+ AvahiServiceResolverNewPtr m_serviceResolverNew;
+ AvahiServiceResolverFreePtr m_serviceResolverFree;
+ QLibrary nativeLib;
+public:
+
+ AvahiZConfLib(QString libName = QLatin1String("avahi"), ZConfLib *fallBack = 0) : ZConfLib(fallBack), nativeLib(libName)
+ {
+#ifndef ZCONF_AVAHI_STATIC_LINKING
+ // dynamic linking
+ if (!nativeLib.load()) {
+ setError(true, tr("AvahiZConfLib could not load native library"));
+ }
+ m_simplePollGet = reinterpret_cast<AvahiSimplePollGet>(nativeLib.resolve("avahi_simple_poll_get"));
+ m_simplePollNew = reinterpret_cast<AvahiSimplePollNewPtr>(nativeLib.resolve("avahi_simple_poll_new"));
+ m_simplePollIterate = reinterpret_cast<AvahiSimplePollIteratePtr>(nativeLib.resolve("avahi_simple_poll_iterate"));
+ m_simplePollQuit = reinterpret_cast<AvahiSimplePollQuitPtr>(nativeLib.resolve("avahi_simple_poll_quit"));
+ m_simplePollFree = reinterpret_cast<AvahiSimplePollFreePtr>(nativeLib.resolve("avahi_simple_poll_free"));
+ m_clientNew = reinterpret_cast<AvahiClientNewPtr>(nativeLib.resolve("avahi_client_new"));
+ m_clientFree = reinterpret_cast<AvahiClientFreePtr>(nativeLib.resolve("avahi_client_free"));
+ m_serviceBrowserNew = reinterpret_cast<AvahiServiceBrowserNewPtr>(nativeLib.resolve("avahi_service_browser_new"));
+ m_serviceBrowserFree = reinterpret_cast<AvahiServiceBrowserFreePtr>(nativeLib.resolve("avahi_service_browser_free"));
+ m_serviceResolverNew = reinterpret_cast<AvahiServiceResolverNewPtr>(nativeLib.resolve("avahi_service_resolver_new"));
+ m_serviceResolverFree = reinterpret_cast<AvahiServiceResolverFreePtr>(nativeLib.resolve("avahi_service_resolver_free"));
+#else
+ m_simplePollGet = reinterpret_cast<AvahiSimplePollGet>(&avahi_simple_poll_get);
+ m_simplePollNew = reinterpret_cast<AvahiSimplePollNewPtr>(&avahi_simple_poll_new);
+ m_simplePollIterate = reinterpret_cast<AvahiSimplePollIteratePtr>(&avahi_simple_poll_iterate);
+ m_simplePollQuit = reinterpret_cast<AvahiSimplePollQuitPtr>(&avahi_simple_poll_quit);
+ m_simplePollFree = reinterpret_cast<AvahiSimplePollFreePtr>(&avahi_simple_poll_free);
+ m_clientNew = reinterpret_cast<AvahiClientNewPtr>(&avahi_client_new);
+ m_clientFree = reinterpret_cast<AvahiClientFreePtr>(&avahi_client_free);
+ m_serviceBrowserNew = reinterpret_cast<AvahiServiceBrowserNewPtr>(&avahi_service_browser_new);
+ m_serviceBrowserFree = reinterpret_cast<AvahiServiceBrowserFreePtr>(&avahi_service_browser_free);
+ m_serviceResolverNew = reinterpret_cast<AvahiServiceResolverNewPtr>(&avahi_service_resolver_new);
+ m_serviceResolverFree = reinterpret_cast<AvahiServiceResolverFreePtr>(&avahi_service_resolver_free);
+#endif
+ if (DEBUG_ZEROCONF) {
+ if (!m_simplePollGet) qDebug() << name() << " has null m_simplePollGet";
+ if (!m_simplePollNew) qDebug() << name() << " has null m_simplePollNew";
+ if (!m_simplePollIterate) qDebug() << name() << " has null m_simplePollIterate";
+ if (!m_simplePollQuit) qDebug() << name() << " has null m_simplePollQuit";
+ if (!m_simplePollFree) qDebug() << name() << " has null m_simplePollFree";
+ if (!m_clientNew) qDebug() << name() << " has null m_clientNew";
+ if (!m_clientFree) qDebug() << name() << " has null m_clientFree";
+ if (!m_serviceBrowserNew) qDebug() << name() << " has null m_serviceBrowserNew";
+ if (!m_serviceBrowserFree) qDebug() << name() << " has null m_serviceBrowserFree";
+ if (!m_serviceResolverNew) qDebug() << name() << " has null m_serviceResolverNew";
+ if (!m_serviceResolverFree) qDebug() << name() << " has null m_serviceResolverFree";
+ }
+ }
+
+ ~AvahiZConfLib() {
+ }
+
+ QString name(){
+ return QString::fromUtf8("AvahiZeroConfLib@%1").arg(size_t(this),0,16);
+ }
+
+ // bool tryStartDaemon();
+ void refDeallocate(DNSServiceRef /*sdRef*/) {
+ }
+
+ void browserDeallocate(BrowserRef *sdRef) {
+ if (sdRef && (*sdRef) && m_serviceBrowserFree) {
+ m_serviceBrowserFree(*reinterpret_cast<AvahiServiceBrowser **>(sdRef));
+ *sdRef = 0;
+ }
+ }
+
+ void destroyConnection(ConnectionRef *sdRef) {
+ MyAvahiConnection **connection = reinterpret_cast<MyAvahiConnection **>(sdRef);
+ if (connection && (*connection)) {
+ if ((*connection)->client && m_clientFree)
+ m_clientFree((*connection)->client);
+
+ if ((*connection)->simple_poll && m_simplePollFree)
+ m_simplePollFree((*connection)->simple_poll);
+ delete(*connection);
+ *connection = 0;
+ }
+ }
+
+ DNSServiceErrorType resolve(ConnectionRef cRef, DNSServiceRef *sdRef, uint32_t interfaceIndex,
+ const char *name, const char *regtype, const char *domain,
+ ServiceGatherer *gatherer)
+ {
+ if (!sdRef) {
+ qDebug() << "Error: sdRef is null in resolve";
+ return kDNSServiceErr_Unknown;
+ }
+ MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
+ if (!m_serviceResolverNew)
+ return kDNSServiceErr_Unknown;
+ AvahiServiceResolver *resolver = m_serviceResolverNew(connection->client, interfaceIndex, AVAHI_PROTO_INET, name, regtype, domain, AVAHI_PROTO_INET,
+ AvahiLookupFlags(0), &cAvahiResolveReply, gatherer);
+ // *sdRef = reinterpret_cast<DNSServiceRef>(resolver); // as we delete in the callback we don't need it...
+ if (!resolver)
+ return kDNSServiceErr_Unknown; // avahi_strerror(avahi_client_errno(connection->client));
+ return kDNSServiceErr_NoError;
+ }
+
+ DNSServiceErrorType queryRecord(ConnectionRef, DNSServiceRef *, uint32_t,
+ const char *, ServiceGatherer *)
+ {
+ return kDNSServiceErr_NoError;
+ }
+
+ DNSServiceErrorType getAddrInfo(ConnectionRef, DNSServiceRef *, uint32_t,
+ DNSServiceProtocol, const char *, ServiceGatherer *)
+ {
+ return kDNSServiceErr_NoError;
+ }
+
+ DNSServiceErrorType reconfirmRecord(ConnectionRef cRef, uint32_t interfaceIndex,
+ const char *name, const char *type, const char *domain,
+ const char * /*fullname */)
+ {
+ MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
+ if (!connection)
+ return kDNSServiceErr_Unknown;
+ AvahiServiceResolver *resolver = m_serviceResolverNew(connection->client, interfaceIndex, AVAHI_PROTO_INET, name, type, domain, AVAHI_PROTO_INET,
+ AvahiLookupFlags(AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), &cAvahiResolveEmptyReply,
+ this);
+ return ((resolver==0)?kDNSServiceErr_Unknown:kDNSServiceErr_NoError);
+ }
+
+ DNSServiceErrorType browse(ConnectionRef cRef, BrowserRef *sdRef, uint32_t interfaceIndex,
+ const char *regtype, const char *domain, ServiceBrowserPrivate *browser)
+ {
+ if (!sdRef) {
+ qDebug() << "Error: sdRef is null in browse";
+ return kDNSServiceErr_Unknown;
+ }
+ if (!m_serviceBrowserNew)
+ return kDNSServiceErr_Unknown;
+ MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
+ AvahiServiceBrowser *sb = m_serviceBrowserNew(connection->client,
+ ((interfaceIndex==0)?static_cast<uint32_t>(AVAHI_IF_UNSPEC):static_cast<uint32_t>(interfaceIndex)),
+ AVAHI_PROTO_UNSPEC, regtype, domain, AvahiLookupFlags(0), &cAvahiBrowseReply, browser);
+ *sdRef = reinterpret_cast<BrowserRef>(sb);
+ if (!sb) {
+ return kDNSServiceErr_Unknown;
+ //avahi_strerror(avahi_client_errno(client));
+ }
+ return kDNSServiceErr_NoError;
+ }
+
+ DNSServiceErrorType getProperty(const char * /*property*/, // Requested property (i.e. kDNSServiceProperty_DaemonVersion)
+ void * /*result*/, // Pointer to place to store result
+ uint32_t * /*size*/ // size of result location
+ )
+ {
+ return 0;
+ }
+
+ ProcessStatus processResult(ConnectionRef cRef) {
+ if (!m_simplePollIterate)
+ return ProcessedFailure;
+ MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
+ if (!connection)
+ return ProcessedError;
+ if (m_simplePollIterate(connection->simple_poll,-1))
+ return ProcessedError;
+ return ProcessedOk;
+ }
+
+ DNSServiceErrorType createConnection(ConnectionRef *sdRef) {
+ if (!m_simplePollNew || !m_clientNew)
+ return kDNSServiceErr_Unknown;
+ MyAvahiConnection *connection = new MyAvahiConnection;
+ connection->lib = this;
+ if (sdRef == 0) {
+ qDebug() << "Error: sdRef is null in createConnection";
+ return kDNSServiceErr_Unknown;
+ }
+ /* Allocate main loop object */
+ connection->simple_poll = m_simplePollNew();
+ if (!connection->simple_poll) {
+ delete connection;
+ return kDNSServiceErr_Unknown;
+ }
+ /* Allocate a new client */
+ int error;
+ connection->client = m_clientNew(m_simplePollGet(connection->simple_poll), AvahiClientFlags(0), &cAvahiClientReply, connection, &error);
+ if (!connection->client) {
+ if (m_simplePollFree)
+ m_simplePollFree(connection->simple_poll);
+ delete connection;
+ setError(true,tr("%1 could not create a client (probably the daemon is not running)"));
+ return kDNSServiceErr_Unknown;
+ }
+ *sdRef = reinterpret_cast<ConnectionRef>(connection);
+ return ((isOk())?kDNSServiceErr_NoError:kDNSServiceErr_Unknown);
+ }
+
+ void stopConnection(ConnectionRef cRef)
+ {
+ MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
+ if (m_simplePollQuit && connection)
+ m_simplePollQuit(connection->simple_poll);
+ }
+
+ int refSockFD(ConnectionRef) {
+ return -1;
+ }
+
+ void serviceResolverFree(AvahiServiceResolver *r) {
+ if (m_serviceResolverFree)
+ m_serviceResolverFree(r);
+ }
+};
+
+ZConfLib *ZConfLib::createAvahiLib(const QString &libName, ZConfLib *fallback) {
+ return new AvahiZConfLib(libName, fallback);
+}
+
+extern "C" void cAvahiResolveReply( AvahiServiceResolver * r, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
+ AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *hostName,
+ const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags /*flags*/, void* context)
+{
+ enum { defaultTtl = 0 };
+ ServiceGatherer *sg = reinterpret_cast<ServiceGatherer *>(context);
+ if (!sg){
+ qDebug() << "context was null in cAvahiResolveReply";
+ return;
+ }
+ const unsigned char * txtPtr = 0;
+ unsigned short txtLen = 0;
+ AvahiStringList *txtAtt=0;
+ switch (event) {
+ case AVAHI_RESOLVER_FAILURE:
+ sg->serviceResolveReply(0, kDNSServiceErr_Timeout, interface, 0, QString(), 0, 0);
+ break;
+ case AVAHI_RESOLVER_FOUND:
+ if (txt) {
+ txtPtr = txt->text;
+ txtLen = static_cast<unsigned short>(txt->size);
+ qDebug() << "Error: txt was null in cAvahiResolveReply for service:" << name << " type:" << type << " domain:" << domain;
+ }
+ txtAtt=(txt?txt->next:0);
+ sg->serviceResolveReply(kDNSServiceFlagsAdd|((txtAtt || address)?kDNSServiceFlagsMoreComing:0), interface, kDNSServiceErr_NoError,
+ hostName, QString::number(port), txtLen, txtPtr);
+ while (txtAtt) {
+ sg->txtRecordReply(kDNSServiceFlagsAdd|((txtAtt->next || address)?kDNSServiceFlagsMoreComing:0),kDNSServiceErr_NoError,
+ static_cast<unsigned short>(txtAtt->size),txtAtt->text,-1);
+ txtAtt = txtAtt->next;
+ }
+ if (address){
+ sockaddr_in ipv4;
+ sockaddr_in6 ipv6;
+//#ifdef HAVE_SA_LEN
+ switch (address->proto){
+ case (AVAHI_PROTO_INET):
+ memset(&ipv4,0,sizeof(ipv4));
+ ipv4.sin_family = AF_INET;
+ memcpy(&(ipv4.sin_addr),&(address->data.ipv4.address),sizeof(ipv4.sin_addr));
+ sg->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError, hostName, reinterpret_cast<sockaddr*>(&ipv4), defaultTtl);
+ case (AVAHI_PROTO_INET6):
+ memset(&ipv6,0,sizeof(ipv6));
+ ipv6.sin6_family = AF_INET6;
+ memcpy(&(ipv6.sin6_addr), &(address->data.ipv6.address), sizeof(ipv6.sin6_addr));
+ sg->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError, hostName, reinterpret_cast<sockaddr*>(&ipv6), defaultTtl);
+ default:
+ if (DEBUG_ZEROCONF)
+ qDebug() << "Warning: ignoring address with protocol " << address->proto << " for service " << sg->fullName();
+ }
+ }
+ break;
+ default:
+ qDebug() << "Error: unexpected avahi event " << event << " in cAvahiResolveReply";
+ break;
+ }
+ AvahiZConfLib *lib = dynamic_cast<AvahiZConfLib *>(sg->serviceBrowser->mainConnection->lib);
+ if (lib)
+ lib->serviceResolverFree(r);
+}
+
+extern "C" void cAvahiResolveEmptyReply(AvahiServiceResolver * r, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent, const char *, const char *,
+ const char *, const char *, const AvahiAddress *, uint16_t, AvahiStringList *, AvahiLookupResultFlags, void* context)
+{
+ AvahiZConfLib *lib = reinterpret_cast<AvahiZConfLib *>(context);
+ if (lib)
+ lib->serviceResolverFree(r);
+}
+
+extern "C" void cAvahiClientReply (AvahiClient * /*s*/, AvahiClientState state, void* context)
+{
+ MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(context);
+ ZConfLib *lib = connection->lib;
+ if (!lib) {
+ qDebug() << "Error: context was null in cAvahiClientReply, ignoring state " << state;
+ return;
+ }
+ if (DEBUG_ZEROCONF)
+ qDebug() << "cAvahiClientReply called with state " << state;
+ switch (state){
+ case (AVAHI_CLIENT_S_REGISTERING):
+ /* Server state: REGISTERING */
+ break;
+ case (AVAHI_CLIENT_S_RUNNING):
+ /* Server state: RUNNING */
+ lib->setError(false, QString(""));
+ break;
+ case (AVAHI_CLIENT_S_COLLISION):
+ /* Server state: COLLISION */
+ lib->setError(true, lib->tr("cAvahiClient, server collision"));
+ break;
+ case (AVAHI_CLIENT_FAILURE):
+ lib->setError(true, lib->tr("cAvahiClient, some kind of error happened on the client side"));
+ break;
+ case (AVAHI_CLIENT_CONNECTING):
+ lib->setError(false, lib->tr("cAvahiClient, still connecting, no server available"));
+ break;
+ default:
+ lib->setError(true, lib->tr("Error: unexpected state %1 in cAvahiClientReply, ignoring it").arg(state));
+ }
+}
+
+extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
+ AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
+ AvahiLookupResultFlags /*flags*/, void* context)
+{
+
+ ServiceBrowserPrivate *browser = reinterpret_cast<ServiceBrowserPrivate *>(context);
+ if (browser == 0) {
+ qDebug() << "Error context is null in cAvahiBrowseReply";
+ }
+ switch (event) {
+ case AVAHI_BROWSER_FAILURE:
+ browser->browseReply(kDNSServiceFlagsMoreComing, 0, kDNSServiceErr_Unknown, 0, 0, 0);
+ break;
+ case AVAHI_BROWSER_NEW:
+ browser->browseReply(kDNSServiceFlagsAdd|kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface), kDNSServiceErr_NoError,
+ name, type, domain);
+ break;
+ case AVAHI_BROWSER_REMOVE:
+ browser->browseReply(kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface), kDNSServiceErr_NoError,
+ name, type, domain);
+ break;
+ case AVAHI_BROWSER_ALL_FOR_NOW:
+ browser->updateFlowStatusForFlags(0);
+ break;
+ case AVAHI_BROWSER_CACHE_EXHAUSTED:
+ browser->updateFlowStatusForFlags(0);
+ break;
+ default:
+ browser->mainConnection->lib->setError(true,browser->mainConnection->lib->tr("Error: unexpected state %1 in cAvahiBrowseReply, ignoring it").arg(event));
+ }
+}
+
+} // namespace Internal
+} // namespace ZeroConf
+
+#else // no native lib
+
+namespace ZeroConf {
+namespace Internal {
+
+ZConfLib *ZConfLib::createAvahiLib(const QString &/*extraPaths*/, ZConfLib * fallback) {
+ return fallback;
+}
+
+} // namespace Internal
+} // namespace ZeroConf
+#endif
+
+
diff --git a/src/libs/zeroconf/embeddedLib.cpp b/src/libs/zeroconf/embeddedLib.cpp
index 25eb1be7c6..8c9ac039af 100644
--- a/src/libs/zeroconf/embeddedLib.cpp
+++ b/src/libs/zeroconf/embeddedLib.cpp
@@ -29,7 +29,7 @@
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
-
+#include <qglobal.h>
#ifdef Q_OS_LINUX
#define EMBEDDED_LIB
#endif
@@ -41,6 +41,9 @@
#include <QtCore/QString>
#include <QtCore/QStringList>
+#include <QtCore/QProcess>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDebug>
#ifdef EMBEDDED_LIB
#include "embed/dnssd_ipc.c"
@@ -53,127 +56,157 @@
namespace ZeroConf {
namespace Internal {
// represents a zero conf library exposing the dns-sd interface
-class EmbeddedZConfLib : public ZConfLib{
+class EmbeddedZConfLib : public ZConfLib
+{
public:
QString daemonPath;
EmbeddedZConfLib(const QString &daemonPath, ZConfLib *fallBack = 0) : ZConfLib(fallBack), daemonPath(daemonPath)
- { }
-
- virtual ~EmbeddedZConfLib() {
+ {
+ if (!daemonPath.isEmpty() && daemonPath.at(0) != '/' && daemonPath.at(0) != '.')
+ this->daemonPath = QCoreApplication::applicationDirPath() + QChar('/') + daemonPath;
}
- virtual QString name(){
+ ~EmbeddedZConfLib()
+ { }
+
+ QString name()
+ {
return QString::fromUtf8("EmbeddedZeroConfLib@%1").arg(size_t(this),0,16);
}
- // virtual bool tryStartDaemon();
+ bool tryStartDaemon()
+ {
+ if (!daemonPath.isEmpty()) {
+ if (QProcess::startDetached(daemonPath)) {
+ QThread::yieldCurrentThread();
+ // sleep a bit?
+ if (DEBUG_ZEROCONF)
+ qDebug() << name() << " started " << daemonPath;
+ return true;
+ } else {
+ this->setError(true, tr("%1 failed starting embedded daemon at %2").arg(name()).arg(daemonPath));
+ }
+ }
+ return false;
+ }
- virtual void refDeallocate(DNSServiceRef sdRef){
+ void refDeallocate(DNSServiceRef sdRef)
+ {
embeddedLib::DNSServiceRefDeallocate(sdRef);
}
- virtual DNSServiceErrorType resolve(DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *name,
- const char *regtype,
- const char *domain,
- DNSServiceResolveReply callBack,
- void *context)
+ void browserDeallocate(BrowserRef *bRef)
+ {
+ if (bRef){
+ embeddedLib::DNSServiceRefDeallocate(*reinterpret_cast<DNSServiceRef*>(bRef));
+ *bRef=0;
+ }
+ }
+
+ void stopConnection(ConnectionRef cRef)
{
- return embeddedLib::DNSServiceResolve(sdRef, flags, interfaceIndex, name, regtype, domain, callBack, context);
+ int sock = refSockFD(cRef);
+ if (sock>0)
+ shutdown(sock,SHUT_RDWR);
}
- virtual DNSServiceErrorType queryRecord(DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- DNSServiceQueryRecordReply callBack,
- void *context)
+ void destroyConnection(ConnectionRef *sdRef)
{
- return embeddedLib::DNSServiceQueryRecord(sdRef, flags, interfaceIndex, fullname,
- rrtype, rrclass, callBack, context);
+ if (sdRef) {
+ embeddedLib::DNSServiceRefDeallocate(*reinterpret_cast<DNSServiceRef*>(sdRef));
+ *sdRef = 0;
+ }
}
- virtual DNSServiceErrorType getAddrInfo(DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceProtocol protocol,
- const char *hostname,
- DNSServiceGetAddrInfoReply callBack,
- void *context)
+ DNSServiceErrorType resolve(ConnectionRef cRef,
+ DNSServiceRef *sdRef,
+ uint32_t interfaceIndex,
+ const char *name,
+ const char *regtype,
+ const char *domain,
+ ServiceGatherer *gatherer)
{
- return embeddedLib::DNSServiceGetAddrInfo(sdRef, flags, interfaceIndex, protocol,
- hostname, callBack, context);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return embeddedLib::DNSServiceResolve(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
+ interfaceIndex, name, regtype, domain, &cServiceResolveReply, gatherer);
}
- virtual uint16_t txtRecordGetCount(uint16_t txtLen,
- const void *txtRecord)
+ DNSServiceErrorType queryRecord(ConnectionRef cRef,
+ DNSServiceRef *sdRef,
+ uint32_t interfaceIndex,
+ const char *fullname,
+ ServiceGatherer *gatherer)
{
- return embeddedLib::TXTRecordGetCount(txtLen, txtRecord);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return embeddedLib::DNSServiceQueryRecord(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
+ interfaceIndex, fullname,
+ kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply ,gatherer);
}
- virtual DNSServiceErrorType txtRecordGetItemAtIndex(uint16_t txtLen,
- const void *txtRecord,
- uint16_t itemIndex,
- uint16_t keyBufLen,
- char *key,
- uint8_t *valueLen,
- const void **value)
+ DNSServiceErrorType getAddrInfo(ConnectionRef cRef,
+ DNSServiceRef *sdRef,
+ uint32_t interfaceIndex,
+ DNSServiceProtocol protocol,
+ const char *hostname,
+ ServiceGatherer *gatherer)
{
- return embeddedLib::TXTRecordGetItemAtIndex(txtLen, txtRecord, itemIndex, keyBufLen,
- key, valueLen, value);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return embeddedLib::DNSServiceGetAddrInfo(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
+ interfaceIndex, protocol,
+ hostname, &cAddrReply, gatherer);
}
- virtual DNSServiceErrorType reconfirmRecord(DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- uint16_t rdlen,
- const void *rdata)
+ DNSServiceErrorType reconfirmRecord(ConnectionRef /*cRef*/, uint32_t /*interfaceIndex*/,
+ const char * /*name*/, const char * /*type*/, const char * /*domain*/,
+ const char * /*fullname*/)
{
- return embeddedLib::DNSServiceReconfirmRecord(flags, interfaceIndex, fullname, rrtype,
- rrclass, rdlen, rdata);
- }
-
- virtual DNSServiceErrorType browse(DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *regtype,
- const char *domain, /* may be NULL */
- DNSServiceBrowseReply callBack,
- void *context /* may be NULL */
- )
+ // reload and force update with in the callback with
+ // embeddedLib::DNSServiceReconfirmRecord(flags, interfaceIndex, fullname, rrtype,
+ // rrclass, rdlen, rdata);
+ return kDNSServiceErr_Unsupported;
+ }
+
+ DNSServiceErrorType browse(ConnectionRef cRef,
+ BrowserRef *bRef,
+ uint32_t interfaceIndex,
+ const char *regtype,
+ const char *domain, /* may be NULL */
+ ServiceBrowserPrivate *browser)
{
- return embeddedLib::DNSServiceBrowse(sdRef, flags, interfaceIndex, regtype, domain, callBack, context);
+ DNSServiceRef *sdRef = reinterpret_cast<DNSServiceRef *>(bRef);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return embeddedLib::DNSServiceBrowse(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable,
+ interfaceIndex, regtype, domain, &cBrowseReply, browser);
}
- virtual DNSServiceErrorType getProperty(const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
- void *result, /* Pointer to place to store result */
- uint32_t *size /* size of result location */
- )
+ DNSServiceErrorType getProperty(const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
+ void *result, /* Pointer to place to store result */
+ uint32_t *size /* size of result location */
+ )
{
return embeddedLib::DNSServiceGetProperty(property, result, size);
}
- virtual DNSServiceErrorType processResult(DNSServiceRef sdRef){
- return embeddedLib::DNSServiceProcessResult(sdRef);
+ ProcessStatus processResult(ConnectionRef sdRef) {
+ if (embeddedLib::DNSServiceProcessResult(reinterpret_cast<DNSServiceRef>(sdRef)) != kDNSServiceErr_NoError)
+ return ProcessedError;
+ return ProcessedOk;
}
- virtual DNSServiceErrorType createConnection(DNSServiceRef *sdRef){
- return embeddedLib::DNSServiceCreateConnection(sdRef);
+ DNSServiceErrorType createConnection(ConnectionRef *sdRef)
+ {
+ return embeddedLib::DNSServiceCreateConnection(reinterpret_cast<DNSServiceRef*>(sdRef));
}
- virtual int refSockFD(DNSServiceRef sdRef){
- return embeddedLib::DNSServiceRefSockFD(sdRef);
+ int refSockFD(ConnectionRef sdRef)
+ {
+ return embeddedLib::DNSServiceRefSockFD(reinterpret_cast<DNSServiceRef>(sdRef));
}
};
-ZConfLib *ZConfLib::createEmbeddedLib(const QString &daemonPath, ZConfLib *fallback){
+ZConfLib *ZConfLib::createEmbeddedLib(const QString &daemonPath, ZConfLib *fallback)
+{
return new EmbeddedZConfLib(daemonPath, fallback);
}
} // namespace Internal
@@ -184,7 +217,8 @@ ZConfLib *ZConfLib::createEmbeddedLib(const QString &daemonPath, ZConfLib *fallb
namespace ZeroConf {
namespace Internal {
-ZConfLib *ZConfLib::createEmbeddedLib(const QString &, ZConfLib * fallback){
+ZConfLib *ZConfLib::createEmbeddedLib(const QString &, ZConfLib * fallback)
+{
return fallback;
}
diff --git a/src/libs/zeroconf/mdnsderived.cpp b/src/libs/zeroconf/mdnsderived.cpp
index 985f73d6c5..fec910a0fa 100644
--- a/src/libs/zeroconf/mdnsderived.cpp
+++ b/src/libs/zeroconf/mdnsderived.cpp
@@ -113,5 +113,42 @@ fail:
return kDNSServiceErr_BadParam;
}
+uint16_t txtRecordGetCount(uint16_t txtLen, const void *txtRecord)
+{
+ uint16_t count = 0;
+ uint8_t *p = (uint8_t*)txtRecord;
+ uint8_t *e = p + txtLen;
+ while (p<e) { p += 1 + p[0]; count++; }
+ return((p>e) ? (uint16_t)0 : count);
+}
+
+DNSServiceErrorType txtRecordGetItemAtIndex(uint16_t txtLen, const void *txtRecord,
+ uint16_t itemIndex, uint16_t keyBufLen, char *key, uint8_t *valueLen, const void **value)
+{
+ uint16_t count = 0;
+ uint8_t *p = (uint8_t*)txtRecord;
+ uint8_t *e = p + txtLen;
+ while (p<e && count<itemIndex) { p += 1 + p[0]; count++; } // Find requested item
+ if (p<e && p + 1 + p[0] <= e) { // If valid
+ uint8_t *x = p+1;
+ unsigned long len = 0;
+ e = p + 1 + p[0];
+ while (x+len<e && x[len] != '=') len++;
+ if (len >= keyBufLen) return(kDNSServiceErr_NoMemory);
+ memcpy(key, x, len);
+ key[len] = 0;
+ if (x+len<e) { // If we found '='
+ *value = x + len + 1;
+ *valueLen = (uint8_t)(p[0] - (len + 1));
+ } else {
+ *value = NULL;
+ *valueLen = 0;
+ }
+ return(kDNSServiceErr_NoError);
+ }
+ return(kDNSServiceErr_Invalid);
+}
+
+
} // namespace ZeroConf
} // namespace Internal
diff --git a/src/libs/zeroconf/mdnsderived.h b/src/libs/zeroconf/mdnsderived.h
index 1068fa13d9..a96c707809 100644
--- a/src/libs/zeroconf/mdnsderived.h
+++ b/src/libs/zeroconf/mdnsderived.h
@@ -32,10 +32,13 @@
namespace ZeroConf {
namespace Internal {
-DNSServiceErrorType myDNSServiceConstructFullName(char *const fullName,
- const char *const service,
- const char *const regtype,
- const char *const domain);
+DNSServiceErrorType myDNSServiceConstructFullName(char *const fullName, const char *const service,
+ const char *const regtype, const char *const domain);
+
+uint16_t txtRecordGetCount(uint16_t txtLen, const void *txtRecord);
+
+DNSServiceErrorType txtRecordGetItemAtIndex(uint16_t txtLen, const void *txtRecord,
+ uint16_t itemIndex, uint16_t keyBufLen, char *key, uint8_t *valueLen, const void **value);
}
}
diff --git a/src/libs/zeroconf/nativeLib.cpp b/src/libs/zeroconf/nativeLib.cpp
index 4ebf9e949f..d5bb674676 100644
--- a/src/libs/zeroconf/nativeLib.cpp
+++ b/src/libs/zeroconf/nativeLib.cpp
@@ -33,18 +33,21 @@
#include "servicebrowser.h"
#include "servicebrowser_p.h"
+#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QLibrary>
#include <QtCore/QString>
#include <QtCore/QStringList>
+#include <errno.h>
+
#ifndef NO_NATIVE_LIB
#ifdef Q_OS_MACX
-#define ZCONF_STATIC_LINKING
+#define ZCONF_MDNS_STATIC_LINKING
#endif
-#ifdef ZCONF_STATIC_LINKING
+#ifdef ZCONF_MDNS_STATIC_LINKING
extern "C" {
#include "dns_sd_funct.h"
}
@@ -73,10 +76,6 @@ typedef DNSServiceErrorType (DNSSD_API *GetAddrInfoPtr)(DNSServiceRef *sdRef, DN
uint32_t interfaceIndex, DNSServiceProtocol protocol,
const char *hostname, DNSServiceGetAddrInfoReply callBack,
void *context);
-typedef uint16_t (DNSSD_API *TxtRecordGetCountPtr)(uint16_t txtLen, const void *txtRecord);
-typedef DNSServiceErrorType (DNSSD_API *TxtRecordGetItemAtIndexPtr)(uint16_t txtLen, const void *txtRecord,
- uint16_t itemIndex, uint16_t keyBufLen,
- char *key, uint8_t *valueLen, const void **value);
typedef DNSServiceErrorType (DNSSD_API *ReconfirmRecordPtr)(DNSServiceFlags flags, uint32_t interfaceIndex,
const char *fullname, uint16_t rrtype,
uint16_t rrclass, uint16_t rdlen, const void *rdata);
@@ -91,13 +90,12 @@ typedef int (DNSSD_API *RefSockFDPtr)(DNSServiceRef sdRef);
// represents a zero conf library exposing the dns-sd interface
class NativeZConfLib : public ZConfLib{
+ Q_DECLARE_TR_FUNCTIONS(ZeroConf)
private:
RefDeallocatePtr m_refDeallocate;
ResolvePtr m_resolve;
QueryRecordPtr m_queryRecord;
GetAddrInfoPtr m_getAddrInfo;
- TxtRecordGetCountPtr m_txtRecordGetCount;
- TxtRecordGetItemAtIndexPtr m_txtRecordGetItemAtIndex;
ReconfirmRecordPtr m_reconfirmRecord;
BrowsePtr m_browse;
GetPropertyPtr m_getProperty;
@@ -106,20 +104,23 @@ private:
RefSockFDPtr m_refSockFD;
QLibrary nativeLib;
public:
+ enum {
+ // Note: the select() implementation on Windows (Winsock2) fails with any timeout much larger than this
+ LONG_TIME = 100000000
+ };
NativeZConfLib(QString libName = QLatin1String("dns_sd"), ZConfLib *fallBack = 0) : ZConfLib(fallBack), nativeLib(libName)
{
-#ifndef ZCONF_STATIC_LINKING
+#ifndef ZCONF_MDNS_STATIC_LINKING
// dynamic linking
if (!nativeLib.load()) {
- qDebug() << "NativeZConfLib could not load native library";
+ m_isOk = false;
+ m_errorMsg=tr("NativeZConfLib could not load native library");
}
m_refDeallocate = reinterpret_cast<RefDeallocatePtr>(nativeLib.resolve("DNSServiceRefDeallocate"));
m_resolve = reinterpret_cast<ResolvePtr>(nativeLib.resolve("DNSServiceResolve"));
m_queryRecord = reinterpret_cast<QueryRecordPtr>(nativeLib.resolve("DNSServiceQueryRecord"));
m_getAddrInfo = reinterpret_cast<GetAddrInfoPtr>(nativeLib.resolve("DNSServiceGetAddrInfo"));
- m_txtRecordGetCount = reinterpret_cast<TxtRecordGetCountPtr>(nativeLib.resolve("TXTRecordGetCount"));
- m_txtRecordGetItemAtIndex = reinterpret_cast<TxtRecordGetItemAtIndexPtr>(nativeLib.resolve("TXTRecordGetItemAtIndex")) ;
m_reconfirmRecord = reinterpret_cast<ReconfirmRecordPtr>(nativeLib.resolve("DNSServiceReconfirmRecord"));
m_browse = reinterpret_cast<BrowsePtr>(nativeLib.resolve("DNSServiceBrowse"));
m_getProperty = reinterpret_cast<GetPropertyPtr>(nativeLib.resolve("DNSServiceGetProperty"));
@@ -132,8 +133,6 @@ public:
m_resolve = reinterpret_cast<ResolvePtr>(&DNSServiceResolve);
m_queryRecord = reinterpret_cast<QueryRecordPtr>(DNSServiceQueryRecord);
m_getAddrInfo = reinterpret_cast<GetAddrInfoPtr>(&DNSServiceGetAddrInfo);
- m_txtRecordGetCount = reinterpret_cast<TxtRecordGetCountPtr>(&TXTRecordGetCount);
- m_txtRecordGetItemAtIndex = reinterpret_cast<TxtRecordGetItemAtIndexPtr>(&TXTRecordGetItemAtIndex) ;
m_reconfirmRecord = reinterpret_cast<ReconfirmRecordPtr>(&DNSServiceReconfirmRecord);
m_browse = reinterpret_cast<BrowsePtr>(&DNSServiceBrowse);
m_getProperty = reinterpret_cast<GetPropertyPtr>(&DNSServiceGetProperty);
@@ -141,18 +140,18 @@ public:
m_createConnection = reinterpret_cast<CreateConnectionPtr>(&DNSServiceCreateConnection);
m_refSockFD = reinterpret_cast<RefSockFDPtr>(&DNSServiceRefSockFD);
#endif
- if (m_refDeallocate == 0) qDebug() << QLatin1String("NativeZConfLib.m_refDeallocate == 0");
- if (m_resolve == 0) qDebug() << QLatin1String("NativeZConfLib.m_resolve == 0");
- if (m_queryRecord == 0) qDebug() << QLatin1String("NativeZConfLib.m_queryRecord == 0");
- if (m_getAddrInfo == 0) qDebug() << QLatin1String("NativeZConfLib.m_getAddrInfo == 0");
- if (m_txtRecordGetCount == 0) qDebug() << QLatin1String("NativeZConfLib.m_txtRecordGetCount == 0");
- if (m_txtRecordGetItemAtIndex == 0) qDebug() << QLatin1String("NativeZConfLib.m_txtRecordGetItemAtIndex == 0");
- if (m_reconfirmRecord == 0) qDebug() << QLatin1String("NativeZConfLib.m_reconfirmRecord == 0");
- if (m_browse == 0) qDebug() << QLatin1String("NativeZConfLib.m_browse == 0");
- if (m_getProperty == 0) qDebug() << QLatin1String("NativeZConfLib.m_getProperty == 0");
- if (m_processResult == 0) qDebug() << QLatin1String("NativeZConfLib.m_processResult == 0");
- if (m_createConnection == 0) qDebug() << QLatin1String("NativeZConfLib.m_createConnection == 0");
- if (m_refSockFD == 0) qDebug() << QLatin1String("NativeZConfLib.m_refSockFD == 0");
+ if (DEBUG_ZEROCONF){
+ if (m_refDeallocate == 0) qDebug() << QLatin1String("NativeZConfLib.m_refDeallocate == 0");
+ if (m_resolve == 0) qDebug() << QLatin1String("NativeZConfLib.m_resolve == 0");
+ if (m_queryRecord == 0) qDebug() << QLatin1String("NativeZConfLib.m_queryRecord == 0");
+ if (m_getAddrInfo == 0) qDebug() << QLatin1String("NativeZConfLib.m_getAddrInfo == 0");
+ if (m_reconfirmRecord == 0) qDebug() << QLatin1String("NativeZConfLib.m_reconfirmRecord == 0");
+ if (m_browse == 0) qDebug() << QLatin1String("NativeZConfLib.m_browse == 0");
+ if (m_getProperty == 0) qDebug() << QLatin1String("NativeZConfLib.m_getProperty == 0");
+ if (m_processResult == 0) qDebug() << QLatin1String("NativeZConfLib.m_processResult == 0");
+ if (m_createConnection == 0) qDebug() << QLatin1String("NativeZConfLib.m_createConnection == 0");
+ if (m_refSockFD == 0) qDebug() << QLatin1String("NativeZConfLib.m_refSockFD == 0");
+ }
}
~NativeZConfLib() {
@@ -162,35 +161,61 @@ public:
return QString::fromUtf8("NativeZeroConfLib@%1").arg(size_t(this),0,16);
}
- // virtual bool tryStartDaemon();
+ // bool tryStartDaemon();
void refDeallocate(DNSServiceRef sdRef) {
if (m_refDeallocate == 0) return;
m_refDeallocate(sdRef);
}
- DNSServiceErrorType resolve(DNSServiceRef *sdRef, DNSServiceFlags flags,
+ void browserDeallocate(BrowserRef *bRef) {
+ if (m_refDeallocate == 0) return;
+ if (bRef) {
+ m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(bRef));
+ *bRef=0;
+ }
+ }
+
+ void stopConnection(ConnectionRef cRef)
+ {
+ int sock = refSockFD(cRef);
+ if (sock>0)
+ shutdown(sock,SHUT_RDWR);
+ }
+
+ void destroyConnection(ConnectionRef *sdRef) {
+ if (m_refDeallocate == 0) return;
+ if (sdRef) {
+ m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(sdRef));
+ *sdRef=0;
+ }
+ }
+
+ DNSServiceErrorType resolve(ConnectionRef cRef, DNSServiceRef *sdRef,
uint32_t interfaceIndex, const char *name,
const char *regtype, const char *domain,
- DNSServiceResolveReply callBack, void *context)
+ ServiceGatherer *gatherer)
{
if (m_resolve == 0) return kDNSServiceErr_Unsupported;
- return m_resolve(sdRef, flags, interfaceIndex, name, regtype, domain, callBack, context);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return m_resolve(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
+ interfaceIndex, name, regtype, domain, &cServiceResolveReply, gatherer
+ );
}
- DNSServiceErrorType queryRecord(DNSServiceRef *sdRef, DNSServiceFlags flags,
+ DNSServiceErrorType queryRecord(ConnectionRef cRef, DNSServiceRef *sdRef,
uint32_t interfaceIndex, const char *fullname,
- uint16_t rrtype, uint16_t rrclass,
- DNSServiceQueryRecordReply callBack, void *context)
+ ServiceGatherer *gatherer)
{
if (m_queryRecord == 0) return kDNSServiceErr_Unsupported;
- return m_queryRecord(sdRef, flags, interfaceIndex, fullname,
- rrtype, rrclass, callBack, context);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return m_queryRecord(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
+ interfaceIndex, fullname,
+ kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply, gatherer);
}
- DNSServiceErrorType getAddrInfo(DNSServiceRef *sdRef, DNSServiceFlags flags,
+ DNSServiceErrorType getAddrInfo(ConnectionRef cRef, DNSServiceRef *sdRef,
uint32_t interfaceIndex, DNSServiceProtocol protocol,
- const char *hostname, DNSServiceGetAddrInfoReply callBack,
- void *context)
+ const char *hostname, ServiceGatherer *gatherer)
{
enum { longTTL = 100 };
if (m_getAddrInfo == 0) {
@@ -207,8 +232,8 @@ public:
return kDNSServiceErr_Unsupported; // use another error here???
}
for (struct addrinfo *ansAtt = ans; ansAtt != 0; ansAtt = ansAtt->ai_next){
- callBack(*sdRef, kDNSServiceFlagsAdd, interfaceIndex, kDNSServiceErr_NoError,
- hostname, ansAtt->ai_addr, longTTL, context);
+ gatherer->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError,
+ hostname, ansAtt->ai_addr, longTTL);
}
freeaddrinfo(ans);
return kDNSServiceErr_NoError;
@@ -216,41 +241,31 @@ public:
return kDNSServiceErr_Unsupported;
#endif
}
- return m_getAddrInfo(sdRef, flags, interfaceIndex, protocol,
- hostname, callBack, context);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return m_getAddrInfo(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
+ interfaceIndex, protocol, hostname, &cAddrReply, gatherer);
}
- uint16_t txtRecordGetCount(uint16_t txtLen, const void *txtRecord)
- {
- if (m_txtRecordGetCount == 0) return 0;
- return m_txtRecordGetCount(txtLen, txtRecord);
- }
-
- DNSServiceErrorType txtRecordGetItemAtIndex(uint16_t txtLen, const void *txtRecord,
- uint16_t itemIndex, uint16_t keyBufLen,
- char *key, uint8_t *valueLen, const void **value)
- {
- if (m_txtRecordGetItemAtIndex == 0) return kDNSServiceErr_Unsupported;
- return m_txtRecordGetItemAtIndex(txtLen, txtRecord, itemIndex, keyBufLen,
- key, valueLen, value);
- }
-
- DNSServiceErrorType reconfirmRecord(DNSServiceFlags flags, uint32_t interfaceIndex,
- const char *fullname, uint16_t rrtype,
- uint16_t rrclass, uint16_t rdlen, const void *rdata)
+ DNSServiceErrorType reconfirmRecord(ConnectionRef /*cRef*/, uint32_t /*interfaceIndex*/,
+ const char * /*name*/, const char * /*type*/, const char * /*domain*/,
+ const char * /*fullname*/)
{
if (m_reconfirmRecord == 0) return kDNSServiceErr_Unsupported;
- return m_reconfirmRecord(flags, interfaceIndex, fullname, rrtype,
- rrclass, rdlen, rdata);
+ // reload and force update with in the callback with
+ // m_reconfirmRecord(flags, interfaceIndex, fullname, rrtype,
+ // rrclass, rdlen, rdata);
+ return kDNSServiceErr_Unsupported;
}
- DNSServiceErrorType browse(DNSServiceRef *sdRef, DNSServiceFlags flags,
+ DNSServiceErrorType browse(ConnectionRef cRef, BrowserRef *bRef,
uint32_t interfaceIndex, const char *regtype,
- const char *domain, DNSServiceBrowseReply callBack,
- void *context)
+ const char *domain, ServiceBrowserPrivate *browser)
{
if (m_browse == 0) return kDNSServiceErr_Unsupported;
- return m_browse(sdRef, flags, interfaceIndex, regtype, domain, callBack, context);
+ DNSServiceRef *sdRef = reinterpret_cast<DNSServiceRef *>(bRef);
+ *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
+ return m_browse(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable,
+ interfaceIndex, regtype, domain, &cBrowseReply, browser);
}
DNSServiceErrorType getProperty(const char *property, // Requested property (i.e. kDNSServiceProperty_DaemonVersion)
@@ -263,19 +278,67 @@ public:
return m_getProperty(property, result, size);
}
- DNSServiceErrorType processResult(DNSServiceRef sdRef) {
- if (m_processResult == 0) return kDNSServiceErr_Unsupported;
- return m_processResult(sdRef);
+ ProcessStatus processResult(ConnectionRef sdRef) {
+ if (m_processResult == 0)
+ return ProcessedFailure;
+ if (m_processResult(reinterpret_cast<DNSServiceRef>(sdRef)) != kDNSServiceErr_NoError)
+ return ProcessedError;
+ return ProcessedOk;
+ }
+
+ // alternative processResult implementation using select
+ DNSServiceErrorType processResultSelect(ConnectionRef cRef)
+ {
+#if _DNS_SD_LIBDISPATCH
+ {
+ main_queue = dispatch_get_main_queue();
+ if (mainRef) DNSServiceSetDispatchQueue(mainRef, main_queue);
+ dispatch_main();
+ }
+#else
+ {
+ if (m_processResult == 0) return kDNSServiceErr_Unsupported;
+ int dns_sd_fd = (cRef?refSockFD(cRef):-1);
+ int nfds = dns_sd_fd + 1;
+ fd_set readfds;
+ struct timeval tv;
+ int result;
+ while (true) {
+ dns_sd_fd = (cRef?refSockFD(cRef):-1);
+ if (dns_sd_fd < 0)
+ return false;
+ nfds = dns_sd_fd + 1;
+ FD_ZERO(&readfds);
+ FD_SET(dns_sd_fd , &readfds);
+
+ tv.tv_sec = LONG_TIME;
+ tv.tv_usec = 0;
+
+ result = select(nfds, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
+ if (result > 0) {
+ if (FD_ISSET(dns_sd_fd , &readfds)) {
+ m_processResult(reinterpret_cast<DNSServiceRef>(cRef));
+ return true;
+ }
+ } else if (result == 0) {
+ // we are idle... could do something productive... :)
+ } else if (errno != EINTR) {
+ qDebug() << "select() returned " << result << " errno " << errno << strerror(errno);
+ return false;
+ }
+ }
+ }
+#endif
}
- DNSServiceErrorType createConnection(DNSServiceRef *sdRef) {
+ DNSServiceErrorType createConnection(ConnectionRef *sdRef) {
if (m_createConnection == 0) return kDNSServiceErr_Unsupported;
- return m_createConnection(sdRef);
+ return m_createConnection(reinterpret_cast<DNSServiceRef *>(sdRef));
}
- int refSockFD(DNSServiceRef sdRef) {
+ int refSockFD(ConnectionRef sdRef) {
if (m_refSockFD == 0) return kDNSServiceErr_Unsupported;
- return m_refSockFD(sdRef);
+ return m_refSockFD(reinterpret_cast<DNSServiceRef>(sdRef));
}
};
diff --git a/src/libs/zeroconf/servicebrowser.cpp b/src/libs/zeroconf/servicebrowser.cpp
index f5ad913f61..bab9e511e5 100644
--- a/src/libs/zeroconf/servicebrowser.cpp
+++ b/src/libs/zeroconf/servicebrowser.cpp
@@ -67,7 +67,6 @@
namespace { // anonymous namespace for free functions
// ----------------- free functions -----------------
-enum { DEBUG_SERVICEBROWSER = false };
using namespace ZeroConf;
using namespace ZeroConf::Internal;
@@ -123,92 +122,6 @@ int fromFullNameC(const char * const fullName, QString &service, QString &regtyp
return 0;
}
-// ----------------- C callbacks -----------------
-
-extern "C" void DNSSD_API cServiceResolveReply(DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *fullname,
- const char *hosttarget,
- uint16_t port, /* In network byte order */
- uint16_t txtLen,
- const unsigned char *txtRecord,
- void *context)
-{
- if (DEBUG_SERVICEBROWSER)
- qDebug() << "cServiceResolveReply(" << ((size_t)sdRef) << ", " << ((quint32)flags) << ", " << interfaceIndex
- << ", " << ((int)errorCode) << ", " << fullname << ", " << hosttarget << ", " << port << ", "
- << txtLen << ", '" << QString::fromUtf8((const char *)txtRecord, txtLen) << "', " << ((size_t)context);
- ServiceGatherer *ctxGatherer = reinterpret_cast<ServiceGatherer *>(context);
- if (ctxGatherer){
- ctxGatherer->serviceResolveReply(sdRef, flags, interfaceIndex, errorCode, fullname, hosttarget, port, txtLen, txtRecord);
- }
-}
-
-extern "C" void DNSSD_API cTxtRecordReply(DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- uint16_t rdlen,
- const void *rdata,
- uint32_t ttl,
- void *context)
-{
- if (DEBUG_SERVICEBROWSER)
- qDebug() << "cTxtRecordReply(" << ((size_t)sdRef) << ", " << ((int)flags) << ", " << interfaceIndex
- << ", " << ((int)errorCode) << ", " << fullname << ", " << rrtype << ", " << rrclass << ", "
- << ", " << rdlen << QString::fromUtf8((const char *)rdata, rdlen) << "', " << ttl << ", " << ((size_t)context);
- ServiceGatherer *ctxGatherer = reinterpret_cast<ServiceGatherer *>(context);
- if (ctxGatherer){
- ctxGatherer->txtRecordReply(sdRef, flags, interfaceIndex, errorCode, fullname, rrtype, rrclass, rdlen, rdata, ttl);
- }
-}
-
-extern "C" void DNSSD_API cAddrReply(DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *hostname,
- const struct sockaddr *address,
- uint32_t ttl,
- void *context)
-{
- if (DEBUG_SERVICEBROWSER)
- qDebug() << "cAddrReply(" << ((size_t)sdRef) << ", " << ((int)flags) << ", " << interfaceIndex
- << ", " << ((int)errorCode) << ", " << hostname << ", " << QHostAddress(address).toString() << ", " << ttl << ", "
- << ((size_t)context);
- ServiceGatherer *ctxGatherer = reinterpret_cast<ServiceGatherer *>(context);
- if (ctxGatherer){
- ctxGatherer->addrReply(sdRef, flags, interfaceIndex, errorCode, hostname, address, ttl);
- }
-}
-
-/// callback for service browsing
-extern "C" void DNSSD_API cBrowseReply(DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *serviceName,
- const char *regtype,
- const char *replyDomain,
- void *context)
-{
- if (DEBUG_SERVICEBROWSER)
- qDebug() << "cBrowseReply(" << ((size_t)sdRef) << ", " << flags << ", " << interfaceIndex
- << ", " << ((int)errorCode) << ", " << serviceName << ", " << regtype << ", " << replyDomain << ", "
- << ((size_t)context);
- ServiceBrowserPrivate *sb = (ServiceBrowserPrivate *)(context);
- if (sb == 0){
- qDebug() << "ServiceBrowser ignoring reply because context was null ";
- return;
- }
- sb->browseReply(sdRef, flags, interfaceIndex, errorCode, serviceName, regtype, replyDomain);
-}
-
/// singleton for lib setup
class ZeroConfLib
{
@@ -224,10 +137,12 @@ private:
Q_GLOBAL_STATIC(ZeroConfLib, zeroConfLibInstance)
-ZeroConfLib::ZeroConfLib(): m_defaultLib(ZConfLib::createNativeLib(QLatin1String("dns_sd"),
- ZConfLib::createEmbeddedLib(QString(), 0)))
+ZeroConfLib::ZeroConfLib(): m_lock(QMutex::Recursive),
+ m_defaultLib(ZConfLib::createAvahiLib(QLatin1String("avahi-client"),
+ ZConfLib::createNativeLib(QLatin1String("dns_sd"),
+ ZConfLib::createEmbeddedLib(QString("mdnssd"), 0))))
{
- qRegisterMetaType<Service::ConstPtr>("Service::ConstPtr");
+ qRegisterMetaType<Service::ConstPtr>("ZeroConf::Service::ConstPtr");
}
ZConfLib *ZeroConfLib::defaultLib(){
@@ -269,7 +184,6 @@ namespace ZeroConf {
*/
Service::Service(const Service &o) :
- QObject(0),
m_name(o.m_name),
m_type(o.m_type),
m_domain(o.m_domain),
@@ -282,7 +196,7 @@ Service::Service(const Service &o) :
{
}
-Service::Service(QObject *parent) : QObject(parent), m_host(0), m_interfaceNr(0), m_outdated(false)
+Service::Service() : m_host(0), m_interfaceNr(0), m_outdated(false)
{ }
Service::~Service()
@@ -526,6 +440,102 @@ void initLib(LibUsage usage, const QString &libName, const QString &daemonPath)
}
namespace Internal {
+// ----------------- dns-sd C callbacks -----------------
+
+extern "C" void cServiceResolveReply(DNSServiceRef sdRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode,
+ const char *fullname,
+ const char *hosttarget,
+ uint16_t port, /* In network byte order */
+ uint16_t txtLen,
+ const unsigned char *txtRecord,
+ void *context)
+{
+ if (DEBUG_ZEROCONF)
+ qDebug() << "cServiceResolveReply(" << ((size_t)sdRef) << ", " << ((quint32)flags) << ", " << interfaceIndex
+ << ", " << ((int)errorCode) << ", " << fullname << ", " << hosttarget << ", " << qFromBigEndian(port) << ", "
+ << txtLen << ", '" << QString::fromUtf8((const char *)txtRecord, txtLen) << "', " << ((size_t)context);
+ ServiceGatherer *ctxGatherer = reinterpret_cast<ServiceGatherer *>(context);
+ if (ctxGatherer){
+ if (ctxGatherer->currentService->fullName() != fullname){
+ qDebug() << "ServiceBrowser " << ctxGatherer->serviceBrowser->serviceType << " for service "
+ << ctxGatherer->currentService->name() << " ignoring resolve reply for " << fullname << " vs. " << ctxGatherer->currentService->fullName();
+ return;
+ }
+ ctxGatherer->serviceResolveReply(flags, interfaceIndex, errorCode, hosttarget, QString::number(qFromBigEndian(port)),
+ txtLen, txtRecord);
+ }
+}
+
+extern "C" void cTxtRecordReply(DNSServiceRef sdRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode,
+ const char *fullname,
+ uint16_t rrtype,
+ uint16_t rrclass,
+ uint16_t rdlen,
+ const void *rdata,
+ uint32_t ttl,
+ void *context)
+{
+ if (DEBUG_ZEROCONF)
+ qDebug() << "cTxtRecordReply(" << ((size_t)sdRef) << ", " << ((int)flags) << ", " << interfaceIndex
+ << ", " << ((int)errorCode) << ", " << fullname << ", " << rrtype << ", " << rrclass << ", "
+ << ", " << rdlen << QString::fromUtf8((const char *)rdata, rdlen) << "', " << ttl << ", " << ((size_t)context);
+ ServiceGatherer *ctxGatherer = reinterpret_cast<ServiceGatherer *>(context);
+ if (ctxGatherer){
+ if (rrtype != kDNSServiceType_TXT || rrclass != kDNSServiceClass_IN) {
+ qDebug() << "ServiceBrowser " << ctxGatherer->serviceBrowser->serviceType << " for service "
+ << ctxGatherer->currentService->fullName() << " received an unexpected rrtype/class:" << rrtype << "/" << rrclass;
+ }
+ ctxGatherer->txtRecordReply(flags, errorCode, rdlen, rdata, ttl);
+ }
+}
+
+extern "C" void cAddrReply(DNSServiceRef sdRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode,
+ const char *hostname,
+ const struct sockaddr *address,
+ uint32_t ttl,
+ void *context)
+{
+ if (DEBUG_ZEROCONF)
+ qDebug() << "cAddrReply(" << ((size_t)sdRef) << ", " << ((int)flags) << ", " << interfaceIndex
+ << ", " << ((int)errorCode) << ", " << hostname << ", " << QHostAddress(address).toString() << ", " << ttl << ", "
+ << ((size_t)context);
+ ServiceGatherer *ctxGatherer = reinterpret_cast<ServiceGatherer *>(context);
+ if (ctxGatherer){
+ ctxGatherer->addrReply(flags, errorCode, hostname, address, ttl);
+ }
+}
+
+/// callback for service browsing
+extern "C" void cBrowseReply(DNSServiceRef sdRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode,
+ const char *serviceName,
+ const char *regtype,
+ const char *replyDomain,
+ void *context)
+{
+ if (DEBUG_ZEROCONF)
+ qDebug() << "cBrowseReply(" << ((size_t)sdRef) << ", " << flags << ", " << interfaceIndex
+ << ", " << ((int)errorCode) << ", " << serviceName << ", " << regtype << ", " << replyDomain << ", "
+ << ((size_t)context);
+ ServiceBrowserPrivate *sb = (ServiceBrowserPrivate *)(context);
+ if (sb == 0){
+ qDebug() << "ServiceBrowser ignoring reply because context was null ";
+ return;
+ }
+ sb->browseReply(flags, interfaceIndex, errorCode, serviceName, regtype, replyDomain);
+}
+
// ----------------- ConnectionThread impl -----------------
void ConnectionThread::run()
@@ -544,10 +554,14 @@ ZConfLib *ServiceGatherer::lib()
return serviceBrowser->mainConnection->lib;
}
+QString ServiceGatherer::fullName(){
+ return currentService->fullName();
+}
+
void ServiceGatherer::enactServiceChange()
{
- if (DEBUG_SERVICEBROWSER)
- qDebug() << "ServiceGatherer::enactServiceChange() for service " << serviceName;
+ if (DEBUG_ZEROCONF)
+ qDebug() << "ServiceGatherer::enactServiceChange() for service " << currentService->fullName();
if (currentServiceCanBePublished()) {
Service::Ptr nService = Service::Ptr(currentService);
serviceBrowser->serviceChanged(publishedService, nService, serviceBrowser->q);
@@ -586,14 +600,13 @@ void ServiceGatherer::stopResolve()
void ServiceGatherer::restartResolve()
{
stopResolve();
- resolveConnection = serviceBrowser->mainRef();
DNSServiceErrorType err = lib()->resolve(
+ serviceBrowser->mainRef(),
&resolveConnection,
- kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
- interfaceIndex, serviceName.toUtf8().constData(),
- serviceType.toUtf8().constData(), domain.toUtf8().constData(), &cServiceResolveReply, this);
+ currentService->interfaceNr(), currentService->name().toUtf8().constData(),
+ currentService->type().toUtf8().constData(), currentService->domain().toUtf8().constData(), this);
if (err != kDNSServiceErr_NoError) {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed discovery of service " << serviceName
+ qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed discovery of service " << currentService->fullName()
<< " due to error " << err;
status = status | ResolveConnectionFailed;
} else {
@@ -612,14 +625,11 @@ void ServiceGatherer::stopTxt()
void ServiceGatherer::restartTxt()
{
stopTxt();
- txtConnection = serviceBrowser->mainRef();
- DNSServiceErrorType err = lib()->queryRecord(&txtConnection,
- kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
- interfaceIndex, fullName.toUtf8().constData(),
- kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply, this);
+ DNSServiceErrorType err = lib()->queryRecord(serviceBrowser->mainRef(), &txtConnection,
+ currentService->interfaceNr(), currentService->fullName().toUtf8().constData(), this);
if (err != kDNSServiceErr_NoError) {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed query of TXT record of service " << serviceName
+ qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed query of TXT record of service " << currentService->fullName()
<< " due to error " << err;
status = status | TxtConnectionFailed;
} else {
@@ -638,21 +648,19 @@ void ServiceGatherer::stopHostResolution()
void ServiceGatherer::restartHostResolution()
{
stopHostResolution();
- if (DEBUG_SERVICEBROWSER)
- qDebug() << "ServiceGatherer::restartHostResolution for host " << hostName << " service " << serviceName;
+ if (DEBUG_ZEROCONF)
+ qDebug() << "ServiceGatherer::restartHostResolution for host " << hostName << " service " << currentService->fullName();
if (hostName.isEmpty()){
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " cannot start host resolution without hostname for service "
- << serviceName;
+ << currentService->fullName();
}
- addrConnection = serviceBrowser->mainRef();
- DNSServiceErrorType err = lib()->getAddrInfo(&addrConnection,
- kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
- interfaceIndex, 0 /* kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6 */,
- hostName.toUtf8().constData(), &cAddrReply, this);
+ DNSServiceErrorType err = lib()->getAddrInfo(serviceBrowser->mainRef(), &addrConnection,
+ currentService->interfaceNr(), 0 /* kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6 */,
+ hostName.toUtf8().constData(), this);
if (err != kDNSServiceErr_NoError) {
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed starting resolution of host "
- << hostName << " for service " << serviceName << " due to error " << err;
+ << hostName << " for service " << currentService->fullName() << " due to error " << err;
status = status | AddrConnectionFailed;
} else {
status = ((status & ~AddrConnectionFailed) | AddrConnectionActive);
@@ -667,14 +675,18 @@ bool ServiceGatherer::currentServiceCanBePublished()
ServiceGatherer::ServiceGatherer(const QString &newServiceName, const QString &newType, const QString &newDomain,
const QString &fullName, uint32_t interfaceIndex, ServiceBrowserPrivate *serviceBrowser):
- port(0), serviceName(newServiceName), serviceType(newType), domain(newDomain), fullName(fullName), serviceBrowser(serviceBrowser),
- publishedService(0), currentService(new Service()), interfaceIndex(interfaceIndex), status(0)
+ serviceBrowser(serviceBrowser), publishedService(0), currentService(new Service()), status(0)
{
- if (DEBUG_SERVICEBROWSER)
+ if (DEBUG_ZEROCONF)
qDebug() << " creating ServiceGatherer(" << newServiceName << ", " << newType << ", " << newDomain << ", "
<< fullName << ", " << interfaceIndex << ", " << ((size_t) serviceBrowser);
+ currentService->m_name = newServiceName;
+ currentService->m_type = newType;
+ currentService->m_domain = newDomain;
+ currentService->m_fullName = fullName;
+ currentService->m_interfaceNr = interfaceIndex;
if (fullName.isEmpty())
- this->fullName = toFullNameC(serviceName.toUtf8().data(), serviceType.toUtf8().data(), domain.toUtf8().data());
+ currentService->m_fullName = toFullNameC(currentService->name().toUtf8().data(), currentService->type().toUtf8().data(), currentService->domain().toUtf8().data());
restartResolve();
restartTxt();
}
@@ -700,13 +712,11 @@ ServiceGatherer::Ptr ServiceGatherer::gatherer() {
return self.toStrongRef();
}
-void ServiceGatherer::serviceResolveReply(DNSServiceRef /*sdRef*/,
- DNSServiceFlags flags,
+void ServiceGatherer::serviceResolveReply(DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
- const char *fullname,
const char *hosttarget,
- uint16_t port, /* In network byte order */
+ const QString &port,
uint16_t txtLen,
const unsigned char *rawTxtRecord)
{
@@ -714,12 +724,12 @@ void ServiceGatherer::serviceResolveReply(DNSServiceRef /*sdRef*/,
if (errorCode == kDNSServiceErr_Timeout){
if ((status & ResolveConnectionSuccess) == 0){
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed service resolution for service "
- << serviceName << " as it did timeout";
+ << currentService->fullName() << " as it did timeout";
status |= ResolveConnectionFailed;
}
} else {
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed service resolution for service "
- << serviceName << " with error " << errorCode;
+ << currentService->fullName() << " with error " << errorCode;
status |= ResolveConnectionFailed;
}
if (status & ResolveConnectionActive) {
@@ -732,23 +742,17 @@ void ServiceGatherer::serviceResolveReply(DNSServiceRef /*sdRef*/,
if (publishedService) publishedService->invalidate(); // delay this to enactServiceChange?
serviceBrowser->updateFlowStatusForFlags(flags);
- if (fullName != fullname){
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " for service "
- << serviceName << " ignoring resolve reply for " << fullname << " vs. " << fullName;
- return;
- }
-
- uint16_t nKeys = lib()->txtRecordGetCount(txtLen, rawTxtRecord);
+ uint16_t nKeys = txtRecordGetCount(txtLen, rawTxtRecord);
for (uint16_t i = 0; i < nKeys; ++i){
enum { maxTxtLen= 256 };
char keyBuf[maxTxtLen];
uint8_t valLen;
const char *valueCStr;
- DNSServiceErrorType txtErr = lib()->txtRecordGetItemAtIndex(txtLen, rawTxtRecord, i, maxTxtLen,
+ DNSServiceErrorType txtErr = txtRecordGetItemAtIndex(txtLen, rawTxtRecord, i, maxTxtLen,
keyBuf, &valLen, (const void **)&valueCStr);
if (txtErr != kDNSServiceErr_NoError){
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " error " << txtErr
- << " decoding txt record of service " << serviceName;
+ << " decoding txt record of service " << currentService->fullName();
break;
}
keyBuf[maxTxtLen-1] = 0; // just to be sure
@@ -758,13 +762,8 @@ void ServiceGatherer::serviceResolveReply(DNSServiceRef /*sdRef*/,
txtRecord.remove(QString::fromUtf8(keyBuf)); // check value???
}
}
- this->interfaceIndex = interfaceIndex;
- currentService->m_name = serviceName;
- currentService->m_type = serviceType;
- currentService->m_domain = domain;
- currentService->m_fullName = fullName;
currentService->m_interfaceNr = interfaceIndex;
- currentService->m_port = QString::number(qFromBigEndian(port));
+ currentService->m_port = port;
if (hostName != hosttarget) {
hostName = QString::fromUtf8(hosttarget);
if (!currentService->host())
@@ -780,13 +779,8 @@ void ServiceGatherer::serviceResolveReply(DNSServiceRef /*sdRef*/,
serviceBrowser->pendingGathererAdd(gatherer());
}
-void ServiceGatherer::txtRecordReply(DNSServiceRef /*sdRef*/,
- DNSServiceFlags flags,
- uint32_t /*interfaceIndex*/,
+void ServiceGatherer::txtRecordReply(DNSServiceFlags flags,
DNSServiceErrorType errorCode,
- const char * /*fullname*/,
- uint16_t rrtype,
- uint16_t rrclass,
uint16_t txtLen,
const void *rawTxtRecord,
uint32_t /*ttl*/)
@@ -795,12 +789,12 @@ void ServiceGatherer::txtRecordReply(DNSServiceRef /*sdRef
if (errorCode == kDNSServiceErr_Timeout){
if ((status & TxtConnectionSuccess) == 0){
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed txt gathering for service "
- << serviceName << " as it did timeout";
+ << currentService->fullName() << " as it did timeout";
status |= TxtConnectionFailed;
}
} else {
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed txt gathering for service "
- << serviceName << " with error " << errorCode;
+ << currentService->fullName() << " with error " << errorCode;
status |= TxtConnectionFailed;
}
if (status & TxtConnectionActive) {
@@ -811,20 +805,16 @@ void ServiceGatherer::txtRecordReply(DNSServiceRef /*sdRef
return;
}
serviceBrowser->updateFlowStatusForFlags(flags);
- if (rrtype != kDNSServiceType_TXT || rrclass != kDNSServiceClass_IN) {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " for service "
- << serviceName << " received an unexpected rrtype/class:" << rrtype << "/" << rrclass;
- }
- uint16_t nKeys = lib()->txtRecordGetCount(txtLen, rawTxtRecord);
+ uint16_t nKeys = txtRecordGetCount(txtLen, rawTxtRecord);
for (uint16_t i = 0; i < nKeys; ++i){
char keyBuf[256];
uint8_t valLen;
const char *valueCStr;
- DNSServiceErrorType txtErr = lib()->txtRecordGetItemAtIndex(txtLen, rawTxtRecord, i, 256, keyBuf, &valLen, (const void **)&valueCStr);
+ DNSServiceErrorType txtErr = txtRecordGetItemAtIndex(txtLen, rawTxtRecord, i, 256, keyBuf, &valLen, (const void **)&valueCStr);
if (txtErr != kDNSServiceErr_NoError){
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " error " << txtErr
- << " decoding txt record of service " << serviceName;
+ << " decoding txt record of service " << currentService->fullName();
if ((flags & kDNSServiceFlagsAdd) == 0)
txtRecord.clear();
break;
@@ -843,9 +833,7 @@ void ServiceGatherer::txtRecordReply(DNSServiceRef /*sdRef
serviceBrowser->pendingGathererAdd(gatherer());
}
-void ServiceGatherer::addrReply(DNSServiceRef /*sdRef*/,
- DNSServiceFlags flags,
- uint32_t /*interfaceIndex*/,
+void ServiceGatherer::addrReply(DNSServiceFlags flags,
DNSServiceErrorType errorCode,
const char *hostname,
const struct sockaddr *address,
@@ -855,11 +843,11 @@ void ServiceGatherer::addrReply(DNSServiceRef /*sdRef*/,
if (errorCode == kDNSServiceErr_Timeout){
if ((status & AddrConnectionSuccess) == 0){
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed address resolve for service "
- << serviceName << " as it did timeout";
+ << currentService->fullName() << " as it did timeout";
status |= AddrConnectionFailed;
}
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " failed addr resolve for service "
- << serviceName << " with error " << errorCode;
+ << currentService->fullName() << " with error " << errorCode;
status |= AddrConnectionFailed;
}
if (status & AddrConnectionActive){
@@ -877,13 +865,13 @@ void ServiceGatherer::addrReply(DNSServiceRef /*sdRef*/,
currentService->m_host->setHostName(QString::fromUtf8(hostname));
if (currentService->host()->addresses().isEmpty()) {
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " for service "
- << serviceName << " add with name " << hostname << " while old name "
+ << currentService->fullName() << " add with name " << hostname << " while old name "
<< currentService->host()->hostName() << " has still adresses, removing them";
currentService->m_host->setAddresses(QList<QHostAddress>());
}
else{
qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " for service "
- << serviceName << " ignoring remove for " << hostname << " as current hostname is "
+ << currentService->fullName() << " ignoring remove for " << hostname << " as current hostname is "
<< currentService->host()->hostName();
return;
}
@@ -939,8 +927,8 @@ void ServiceGatherer::reload(qint32 interfaceIndex)
void ServiceGatherer::remove()
{
stop();
- if (serviceBrowser->gatherers.contains(fullName) && serviceBrowser->gatherers[fullName] == this)
- serviceBrowser->gatherers.remove(fullName);
+ if (serviceBrowser->gatherers.contains(currentService->fullName()) && serviceBrowser->gatherers[currentService->fullName()] == this)
+ serviceBrowser->gatherers.remove(currentService->fullName());
}
/// forces a full reload of the record
void ServiceGatherer::reconfirm()
@@ -957,7 +945,7 @@ void ServiceGatherer::reconfirm()
// ----------------- ServiceBrowserPrivate impl -----------------
-DNSServiceRef ServiceBrowserPrivate::mainRef()
+ZConfLib::ConnectionRef ServiceBrowserPrivate::mainRef()
{
return mainConnection->mainRef();
}
@@ -977,7 +965,7 @@ void ServiceBrowserPrivate::pendingGathererAdd(ServiceGatherer::Ptr gatherer)
int ng = pendingGatherers.count();
for (int i = 0; i < ng; ++i){
const ServiceGatherer::Ptr &g=pendingGatherers.at(i);
- if (g->fullName == gatherer->fullName){
+ if (g->fullName() == gatherer->fullName()){
if (g != gatherer){
gatherer->publishedService = g->publishedService;
pendingGatherers[i] = gatherer;
@@ -1025,7 +1013,7 @@ void ServiceBrowserPrivate::maybeUpdateLists()
QMap<QString, ServiceGatherer::Ptr>::iterator j = gatherers.begin();
while (i != endi && j != gatherers.end()) {
const QString vi = *i;
- const QString vj = (*j)->fullName;
+ QString vj = (*j)->fullName();
if (vi == vj){
++i;
++j;
@@ -1057,15 +1045,14 @@ void ServiceBrowserPrivate::maybeUpdateLists()
}
/// callback announcing
-void ServiceBrowserPrivate::browseReply(DNSServiceRef /*sdRef*/,
- DNSServiceFlags flags,
+void ServiceBrowserPrivate::browseReply(DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
const char *serviceName,
const char *regtype,
const char *replyDomain)
{
- if (DEBUG_SERVICEBROWSER)
+ if (DEBUG_ZEROCONF)
qDebug() << "browseReply(" << ((int)flags) << ", " << interfaceIndex << ", " << ((int)errorCode) << ", " << serviceName << ", "
<< regtype << ", " << replyDomain << ")";
if (errorCode != kDNSServiceErr_NoError){
@@ -1109,18 +1096,15 @@ bool ServiceBrowserPrivate::startBrowsing(quint32 interfaceIndex)
if (mainConnection.isNull())
mainConnection = MainConnectionPtr(new MainConnection());
mainConnection->addBrowser(this);
- serviceConnection = mainRef();
DNSServiceErrorType err;
- err = mainConnection->lib->browse(&serviceConnection, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable, interfaceIndex,
- serviceType.toUtf8().constData(),
- ((domain.isEmpty()) ? 0 : (domain.toUtf8().constData())),
- &cBrowseReply, this);
+ err = mainConnection->lib->browse(mainRef(), &serviceConnection, interfaceIndex,
+ serviceType.toUtf8().constData(), ((domain.isEmpty()) ? 0 : (domain.toUtf8().constData())), this);
if (err != kDNSServiceErr_NoError){
qDebug() << "ServiceBrowser " << serviceType << " failed initializing serviceConnection";
return false;
}
browsing = true;
- if (DEBUG_SERVICEBROWSER)
+ if (DEBUG_ZEROCONF)
qDebug() << "startBrowsing(" << interfaceIndex << ") for serviceType:" << serviceType << " domain:" << domain;
return true;
}
@@ -1130,16 +1114,18 @@ void ServiceBrowserPrivate::stopBrowsing()
QMutexLocker l(mainConnection->lock());
if (browsing){
if (serviceConnection) {
- mainConnection->lib->refDeallocate(serviceConnection);
+ mainConnection->lib->browserDeallocate(&serviceConnection);
updateFlowStatusForCancel();
serviceConnection=0;
}
}
}
-void ServiceBrowserPrivate::reconfirmService(Service::ConstPtr /*s*/)
+void ServiceBrowserPrivate::reconfirmService(Service::ConstPtr s)
{
- // to do
+ if (!s->outdated())
+ mainConnection->lib->reconfirmRecord(mainRef(), s->interfaceNr(), s->name().toUtf8().data(), s->type().toUtf8().data(),
+ s->domain().toUtf8().data(), s->fullName().toUtf8().data());
}
/// called when a service is added removed or changes. oldService or newService might be null (covers both add and remove)
@@ -1180,10 +1166,8 @@ void MainConnection::stop(bool wait)
{
if (m_status < Stopping)
increaseStatusTo(Stopping);
- if (m_mainRef) {
- int sock=lib->refSockFD(m_mainRef);
- if (sock>0) shutdown(sock,SHUT_RDWR); // quite brutal, but avoids any locking/long wait in read
- }
+ if (m_mainRef)
+ lib->stopConnection(m_mainRef);
if (!m_thread)
increaseStatusTo(Stopped);
else if (wait && QThread::currentThread() != m_thread)
@@ -1191,7 +1175,7 @@ void MainConnection::stop(bool wait)
}
MainConnection::MainConnection():
- lib(zeroConfLibInstance()->defaultLib()),m_mainRef(0), m_timeOut(LONG_TIME), m_failed(false), m_status(Starting), m_nErrs(0), m_useSelect(false)
+ lib(zeroConfLibInstance()->defaultLib()), m_lock(QMutex::Recursive), m_mainRef(0), m_failed(false), m_status(Starting), m_nErrs(0)
{
if (lib == 0){
qDebug() << "could not load a valid library for ZeroConf::MainConnection, failing";
@@ -1228,10 +1212,13 @@ void MainConnection::waitStartup()
{
int sAtt;
while (true){
- QMutexLocker l(lock());
- sAtt = m_status;
- if (sAtt >= Running)
- return;
+ {
+ QMutexLocker l(lock());
+ sAtt = m_status;
+ if (sAtt >= Running)
+ return;
+ }
+ QThread::yieldCurrentThread();
}
}
@@ -1275,16 +1262,12 @@ void MainConnection::maybeUpdateLists()
}
}
-QString MainConnection::tr(const char *s)
-{
- return QCoreApplication::translate("ZeroConf", s, 0, QCoreApplication::CodecForTr);
-}
-
void MainConnection::gotoValidLib(){
while (lib){
if (lib->isOk()) break;
- appendError(QStringList(tr("MainConnection giving up on non Ok lib %1")
- .arg(lib->name())), false);
+ appendError(QStringList(tr("MainConnection giving up on non Ok lib %1 (%2)")
+ .arg(lib->name()).arg(lib->errorMsg())), false);
+ lib = lib->fallbackLib;
}
if (!lib) {
appendError(QStringList(tr("MainConnection has no valid library, aborting connection")
@@ -1315,6 +1298,10 @@ void MainConnection::createConnection()
{
gotoValidLib();
while (m_status <= Running) {
+ if (!lib) {
+ increaseStatusTo(Stopped);
+ break;
+ }
uint32_t version;
uint32_t size=(uint32_t)sizeof(uint32_t);
DNSServiceErrorType err=lib->getProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
@@ -1324,7 +1311,7 @@ void MainConnection::createConnection()
appendError(QStringList(tr("MainConnection using lib %1 failed the initialization of mainRef with error %2")
.arg(lib->name()).arg(error)),false);
++m_nErrs;
- if (m_nErrs > 10)
+ if (m_nErrs > 10 || !lib->isOk())
abortLib();
} else {
increaseStatusTo(Running);
@@ -1355,18 +1342,17 @@ void MainConnection::createConnection()
}
}
-bool MainConnection::handleEvent()
+ZConfLib::ProcessStatus MainConnection::handleEvent()
{
- int err = lib->processResult(m_mainRef);
- if (err) {
- qDebug() << "DNSServiceProcessResult returned " << err;
+ ZConfLib::ProcessStatus err = lib->processResult(m_mainRef);
+ if (err != ZConfLib::ProcessedOk) {
+ qDebug() << "processResult returned " << err;
++m_nErrs;
- return false;
} else {
m_nErrs=0;
maybeUpdateLists();
- return true;
}
+ return err;
}
void MainConnection::destroyConnection()
@@ -1378,57 +1364,10 @@ void MainConnection::destroyConnection()
bAtt->stopBrowsing();
}
if (m_mainRef != 0)
- lib->refDeallocate(m_mainRef);
+ lib->destroyConnection(&m_mainRef);
m_mainRef=0;
}
-void MainConnection::selectLoop()
-{
-#if _DNS_SD_LIBDISPATCH
- {
- main_queue = dispatch_get_main_queue();
- if (_mainRef) DNSServiceSetDispatchQueue(_mainRef, main_queue);
- dispatch_main();
- }
-#else
- {
- int dns_sd_fd = (m_mainRef?lib->refSockFD(m_mainRef):-1);
- int nfds = dns_sd_fd + 1;
- fd_set readfds;
- struct timeval tv;
- int result;
- while (m_status < Stopping) {
- while ((!m_mainRef) && m_status < Stopping) {
- if (++m_nErrs > 10)
- increaseStatusTo(Stopping);
- destroyConnection();
- createConnection();
- dns_sd_fd = (m_mainRef?lib->refSockFD(m_mainRef):-1);
- nfds = dns_sd_fd + 1;
- }
- FD_ZERO(&readfds);
-
- FD_SET(dns_sd_fd , &readfds);
-
- tv.tv_sec = m_timeOut;
- tv.tv_usec = 0;
-
- result = select(nfds, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
- if (result > 0) {
- if (FD_ISSET(dns_sd_fd , &readfds))
- handleEvent();
- } else if (result == 0) {
- // we are idle... could do something productive... :)
- } else if (errno != EINTR) {
- qDebug() << "select() returned " << result << " errno " << errno << strerror(errno);
- ++m_nErrs;
- if (++m_nErrs > 5) break;
- }
- }
- }
-#endif
-}
-
void MainConnection::handleEvents()
{
if (!m_status.testAndSetAcquire(Starting, Started)){
@@ -1442,13 +1381,23 @@ void MainConnection::handleEvents()
while (m_status < Stopping) {
if (m_nErrs > 10)
increaseStatusTo(Stopping);
- if (m_useSelect) {
- selectLoop();
-#if _DNS_SD_LIBDISPATCH
- return;
-#endif
- } else {
- handleEvent();
+ switch (handleEvent()) {
+ case ZConfLib::ProcessedOk :
+ break;
+ case ZConfLib::ProcessedError :
+ ++m_nErrs;
+ break;
+ case ZConfLib::ProcessedFailure :
+ increaseStatusTo(Stopping);
+ ++m_nErrs;
+ break;
+ case ZConfLib::ProcessedQuit :
+ increaseStatusTo(Stopping);
+ break;
+ default:
+ appendError(QStringList(tr("MainConnection::handleEvents unexpected return status of handleEvent")),true);
+ increaseStatusTo(Stopping);
+ break;
}
}
destroyConnection();
@@ -1459,7 +1408,7 @@ void MainConnection::handleEvents()
increaseStatusTo(Stopped);
}
-DNSServiceRef MainConnection::mainRef()
+ZConfLib::ConnectionRef MainConnection::mainRef()
{
while (m_status < Running){
QThread::yieldCurrentThread();
@@ -1521,5 +1470,16 @@ bool ZConfLib::isOk()
return m_isOk;
}
+QString ZConfLib::errorMsg()
+{
+ return m_errorMsg;
+}
+
+void ZConfLib::setError(bool failure, const QString &eMsg)
+{
+ m_errorMsg = eMsg;
+ m_isOk = !failure;
+}
+
} // namespace Internal
} // namespace ZeroConf
diff --git a/src/libs/zeroconf/servicebrowser.h b/src/libs/zeroconf/servicebrowser.h
index de229cac24..9f22bc27ae 100644
--- a/src/libs/zeroconf/servicebrowser.h
+++ b/src/libs/zeroconf/servicebrowser.h
@@ -54,9 +54,8 @@ typedef QSharedPointer<Internal::MainConnection> MainConnectionPtr;
typedef QHash<QString, QString> ServiceTxtRecord;
-class ZEROCONFSHARED_EXPORT Service : public QObject
+class ZEROCONFSHARED_EXPORT Service
{
- Q_OBJECT
friend class Internal::ServiceGatherer;
public:
@@ -64,7 +63,7 @@ public:
typedef QSharedPointer<Service> Ptr;
Service(const Service &o);
- Service(QObject *parent = 0);
+ Service();
~Service();
bool outdated() const { return m_outdated; }
diff --git a/src/libs/zeroconf/servicebrowser_p.h b/src/libs/zeroconf/servicebrowser_p.h
index 62eae41d60..3833ea50b1 100644
--- a/src/libs/zeroconf/servicebrowser_p.h
+++ b/src/libs/zeroconf/servicebrowser_p.h
@@ -36,6 +36,7 @@
#include "dns_sd_types.h"
#include "servicebrowser.h"
+#include <QtCore/QCoreApplication>
#include <QtCore/QAtomicInt>
#include <QtCore/QHash>
#include <QtCore/QList>
@@ -50,9 +51,21 @@ class QHostInfo;
namespace ZeroConf {
namespace Internal {
+class ServiceGatherer;
+class ServiceBrowserPrivate;
+
// represents a zero conf library exposing the dns-sd interface
class ZConfLib {
+ Q_DECLARE_TR_FUNCTIONS(ZeroConf)
public:
+ typedef void *ConnectionRef;
+ typedef void *BrowserRef;
+ enum ProcessStatus {
+ ProcessedOk,
+ ProcessedQuit,
+ ProcessedError,
+ ProcessedFailure
+ };
ZConfLib *fallbackLib;
ZConfLib(ZConfLib *fallBack);
@@ -63,50 +76,43 @@ public:
virtual bool tryStartDaemon();
virtual void refDeallocate(DNSServiceRef sdRef) = 0;
- virtual DNSServiceErrorType resolve(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+ virtual void browserDeallocate(BrowserRef *sdRef) = 0;
+ virtual DNSServiceErrorType resolve(ConnectionRef cRef, DNSServiceRef *sdRef, uint32_t interfaceIndex,
const char *name, const char *regtype, const char *domain,
- DNSServiceResolveReply callBack, void *context) = 0;
- virtual DNSServiceErrorType queryRecord(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- const char *fullname, uint16_t rrtype, uint16_t rrclass,
- DNSServiceQueryRecordReply callBack, void *context) = 0;
- virtual DNSServiceErrorType getAddrInfo(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+ ServiceGatherer *gatherer) = 0;
+ virtual DNSServiceErrorType queryRecord(ConnectionRef cRef, DNSServiceRef *sdRef, uint32_t interfaceIndex,
+ const char *fullname, ServiceGatherer *gatherer) = 0;
+ virtual DNSServiceErrorType getAddrInfo(ConnectionRef cRef, DNSServiceRef *sdRef, uint32_t interfaceIndex,
DNSServiceProtocol protocol, const char *hostname,
- DNSServiceGetAddrInfoReply callBack, void *context) = 0;
-
- // remove txt functions from lib and always embed?
- virtual uint16_t txtRecordGetCount(uint16_t txtLen, const void *txtRecord) = 0;
- virtual DNSServiceErrorType txtRecordGetItemAtIndex(uint16_t txtLen, const void *txtRecord,
- uint16_t itemIndex, uint16_t keyBufLen, char *key,
- uint8_t *valueLen, const void **value) = 0;
-
- virtual DNSServiceErrorType reconfirmRecord(DNSServiceFlags flags, uint32_t interfaceIndex,
- const char *fullname, uint16_t rrtype, uint16_t rrclass,
- uint16_t rdlen, const void *rdata) = 0; // opt
- virtual DNSServiceErrorType browse(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- const char *regtype, const char *domain, DNSServiceBrowseReply callBack,
- void *context) = 0;
+ ServiceGatherer *gatherer) = 0;
+
+ virtual DNSServiceErrorType reconfirmRecord(ConnectionRef cRef, uint32_t interfaceIndex,
+ const char *name, const char *type, const char *domain,
+ const char *fullname) = 0; // opt
+ virtual DNSServiceErrorType browse(ConnectionRef cRef, BrowserRef *sdRef, uint32_t interfaceIndex,
+ const char *regtype, const char *domain, ServiceBrowserPrivate *browser) = 0;
virtual DNSServiceErrorType getProperty(const char *property, void *result, uint32_t *size) = 0;
- virtual DNSServiceErrorType processResult(DNSServiceRef sdRef) = 0;
- virtual DNSServiceErrorType createConnection(DNSServiceRef *sdRef) = 0;
- virtual int refSockFD(DNSServiceRef sdRef) = 0;
+ virtual ProcessStatus processResult(ConnectionRef sdRef) = 0;
+ virtual DNSServiceErrorType createConnection(ConnectionRef *sdRef) = 0;
+ virtual void stopConnection(ConnectionRef cRef) = 0;
+ virtual void destroyConnection(ConnectionRef *sdRef) = 0;
bool isOk();
+ QString errorMsg();
+ void setError(bool failure, const QString &eMsg);
static ZConfLib *createEmbeddedLib(const QString &daemonPath, ZConfLib *fallback=0);
static ZConfLib *createNativeLib(const QString &libName, ZConfLib *fallback=0);
+ static ZConfLib *createAvahiLib(const QString &libName, ZConfLib *fallback=0);
static ZConfLib *defaultLib();
-private:
+protected:
bool m_isOk;
+ QString m_errorMsg;
};
/// class that gathers all needed info on a service, all its methods (creation included) are supposed to be called by the listener/reaction thread
class ServiceGatherer {
public:
QHash<QString, QString> txtRecord;
- short port;
- QString serviceName;
- QString serviceType;
- QString domain;
- QString fullName;
QString hostName;
ServiceBrowserPrivate *serviceBrowser;
QHostInfo *host;
@@ -127,6 +133,7 @@ public:
AddrConnectionSuccess = 1 << 8
};
+ QString fullName();
void enactServiceChange();
void retireService();
Ptr gatherer();
@@ -144,17 +151,15 @@ public:
static Ptr createGatherer(const QString &newService, const QString &newType, const QString &newDomain,
const QString &fullName, uint32_t interfaceIndex, ServiceBrowserPrivate *serviceBrowser);
- void serviceResolveReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget,
- uint16_t port /* In network byte order */, uint16_t txtLen,
+ void serviceResolveReply(DNSServiceFlags flags, uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode, const char *hosttarget,
+ const QString &port, uint16_t txtLen,
const unsigned char *rawTxtRecord);
- void txtRecordReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *fullname, uint16_t rrtype,
- uint16_t rrclass, uint16_t txtLen, const void *rawTxtRecord, uint32_t ttl);
+ void txtRecordReply(DNSServiceFlags flags, DNSServiceErrorType errorCode,
+ uint16_t txtLen, const void *rawTxtRecord, uint32_t ttl);
- void addrReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *hostname, const struct sockaddr *address,
+ void addrReply(DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *hostname, const struct sockaddr *address,
uint32_t ttl);
void maybeRemove();
void stop();
@@ -180,6 +185,7 @@ private:
class ConnectionThread;
class MainConnection{
+ Q_DECLARE_TR_FUNCTIONS(ZeroConf)
public:
enum RequestFlowStatus {
NormalRFS,
@@ -187,10 +193,6 @@ public:
ForceUpdateRFS
};
RequestFlowStatus flowStatus;
- enum {
- // Note: the select() implementation on Windows (Winsock2) fails with any timeout much larger than this
- LONG_TIME = 100000000
- };
/// WARNING order matters in this enum, and status should only be changed with increaseStatusTo
enum Status {
Starting,
@@ -211,16 +213,14 @@ public:
void updateFlowStatusForCancel();
void updateFlowStatusForFlags(DNSServiceFlags flags);
void maybeUpdateLists();
- QString tr(const char *s);
void gotoValidLib();
void abortLib();
void createConnection();
void destroyConnection();
- bool handleEvent();
+ ZConfLib::ProcessStatus handleEvent();
bool increaseStatusTo(int s);
- void selectLoop();
void handleEvents();
- DNSServiceRef mainRef();
+ ZConfLib::ConnectionRef mainRef();
QStringList errors();
void clearErrors();
@@ -229,13 +229,11 @@ public:
private:
mutable QMutex m_lock;
QList<ServiceBrowserPrivate *> m_browsers;
- DNSServiceRef m_mainRef;
- volatile int m_timeOut;
+ ZConfLib::ConnectionRef m_mainRef;
bool m_failed;
ConnectionThread *m_thread;
QAtomicInt m_status;
int m_nErrs;
- bool m_useSelect;
QStringList m_errors;
};
@@ -245,8 +243,8 @@ public:
ServiceBrowser *q;
QString serviceType;
QString domain;
- MainConnectionPtr mainConnection;
- DNSServiceRef serviceConnection;
+ MainConnectionPtr mainConnection;
+ ZConfLib::BrowserRef serviceConnection;
DNSServiceFlags flags;
uint32_t interfaceIndex;
QList<QString> knownServices;
@@ -259,7 +257,7 @@ public:
bool autoResolveAddresses;
bool requireAddresses;
- DNSServiceRef mainRef();
+ ZConfLib::ConnectionRef mainRef();
void updateFlowStatusForCancel();
void updateFlowStatusForFlags(DNSServiceFlags flags);
@@ -276,7 +274,7 @@ public:
void stopBrowsing();
void reconfirmService(Service::ConstPtr s);
- void browseReply(DNSServiceRef sdRef, DNSServiceFlags flags,
+ void browseReply(DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName,
const char *regtype, const char *replyDomain);
void serviceChanged(const Service::ConstPtr &oldService, const Service::ConstPtr &newService, ServiceBrowser *browser);
@@ -293,6 +291,21 @@ class ConnectionThread: public QThread{
public:
ConnectionThread(MainConnection &mc, QObject *parent=0);
};
+
+extern "C" void DNSSD_API cServiceResolveReply(DNSServiceRef sdRef, DNSServiceFlags flags,
+ uint32_t interfaceIndex, DNSServiceErrorType errorCode,
+ const char *fullname, const char *hosttarget, uint16_t port,
+ uint16_t txtLen, const unsigned char *txtRecord, void *context);
+extern "C" void DNSSD_API cTxtRecordReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode, const char *fullname,
+ uint16_t rrtype, uint16_t rrclass, uint16_t rdlen,
+ const void *rdata, uint32_t ttl, void *context);
+extern "C" void DNSSD_API cAddrReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode, const char *hostname,
+ const struct sockaddr *address, uint32_t ttl, void *context);
+extern "C" void DNSSD_API cBrowseReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
+ DNSServiceErrorType errorCode, const char *serviceName,
+ const char *regtype, const char *replyDomain, void *context);
} // namespace Internal
} // namespace Zeroconf
diff --git a/src/libs/zeroconf/zeroconf.pro b/src/libs/zeroconf/zeroconf.pro
index a592be4f29..7081d4646a 100644
--- a/src/libs/zeroconf/zeroconf.pro
+++ b/src/libs/zeroconf/zeroconf.pro
@@ -9,9 +9,10 @@ DEFINES += ZEROCONF_LIBRARY
SOURCES += servicebrowser.cpp \
embeddedLib.cpp \
nativeLib.cpp \
- mdnsderived.cpp
+ mdnsderived.cpp \
+ avahiLib.cpp
-HEADERS += servicebrowser.h\
+HEADERS += servicebrowser.h \
zeroconf_global.h \
dns_sd_types.h \
servicebrowser_p.h \
@@ -23,3 +24,4 @@ win32{
LIBS += -lws2_32
}
+
diff --git a/src/libs/zeroconf/zeroconf_global.h b/src/libs/zeroconf/zeroconf_global.h
index fc349cfea0..97e317cc85 100644
--- a/src/libs/zeroconf/zeroconf_global.h
+++ b/src/libs/zeroconf/zeroconf_global.h
@@ -41,4 +41,6 @@
# define ZEROCONFSHARED_EXPORT Q_DECL_IMPORT
#endif
+enum { DEBUG_ZEROCONF = false } ;
+
#endif // ZEROCONF_GLOBAL_H