aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-10-20 14:42:55 +0200
committerhjk <hjk121@nokiamail.com>2014-10-20 17:00:36 +0200
commit8d8b45d35fd0bd6473d7d4c391d9eb8a520fb0e2 (patch)
tree2e22a620055662584c92590ed828b6b9924d887a
parent12201a6304733589552822d00e0bd4b92004400b (diff)
Remove src/libs/zeroconf
The code has been unused for a while and shows up in the static analyzer. Change-Id: I7b59be985d7e6e140eaee217978660b767e7b11c Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
-rw-r--r--dist/changes-3.3.03
-rw-r--r--src/libs/libs.pro3
-rw-r--r--src/libs/libs.qbs1
-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.cpp570
-rw-r--r--src/libs/zeroconf/dnsSdLib.cpp324
-rw-r--r--src/libs/zeroconf/dns_sd_funct.h1364
-rw-r--r--src/libs/zeroconf/dns_sd_types.h1154
-rw-r--r--src/libs/zeroconf/embed/CommonServices.h1498
-rw-r--r--src/libs/zeroconf/embed/DebugServices.c3075
-rw-r--r--src/libs/zeroconf/embed/DebugServices.h1607
-rw-r--r--src/libs/zeroconf/embed/dnssd_clientlib.c372
-rw-r--r--src/libs/zeroconf/embed/dnssd_clientstub.c2053
-rw-r--r--src/libs/zeroconf/embed/dnssd_ipc.c163
-rw-r--r--src/libs/zeroconf/embed/dnssd_ipc.h225
-rw-r--r--src/libs/zeroconf/embeddedLib.cpp295
-rw-r--r--src/libs/zeroconf/mdnsderived.cpp154
-rw-r--r--src/libs/zeroconf/mdnsderived.h46
-rw-r--r--src/libs/zeroconf/servicebrowser.cpp2103
-rw-r--r--src/libs/zeroconf/servicebrowser.h199
-rw-r--r--src/libs/zeroconf/servicebrowser_p.h358
-rw-r--r--src/libs/zeroconf/syssocket.h54
-rw-r--r--src/libs/zeroconf/zeroconf.pro27
-rw-r--r--src/libs/zeroconf/zeroconf.qbs43
-rw-r--r--src/libs/zeroconf/zeroconf_dependencies.pri1
-rw-r--r--src/libs/zeroconf/zeroconf_global.h44
36 files changed, 4 insertions, 17315 deletions
diff --git a/dist/changes-3.3.0 b/dist/changes-3.3.0
index 10f4b28a0f..d7a20a9f63 100644
--- a/dist/changes-3.3.0
+++ b/dist/changes-3.3.0
@@ -71,4 +71,7 @@ QNX
BareMetal
+Tools:
+ * Removed unused zeroconf wrapper
+
Credits for these changes go to:
diff --git a/src/libs/libs.pro b/src/libs/libs.pro
index 6dc44a10fb..bc8e6ac3e9 100644
--- a/src/libs/libs.pro
+++ b/src/libs/libs.pro
@@ -12,8 +12,7 @@ SUBDIRS = \
qmldebug \
qmleditorwidgets \
glsl \
- ssh \
- zeroconf
+ ssh
for(l, SUBDIRS) {
QTC_LIB_DEPENDS =
diff --git a/src/libs/libs.qbs b/src/libs/libs.qbs
index a997225e81..6a43b7b2c0 100644
--- a/src/libs/libs.qbs
+++ b/src/libs/libs.qbs
@@ -16,6 +16,5 @@ Project {
"utils/process_stub.qbs",
"utils/process_ctrlc_stub.qbs",
"utils/utils.qbs",
- "zeroconf/zeroconf.qbs",
].concat(project.additionalLibs)
}
diff --git a/src/libs/zeroconf/avahi-client/client.h b/src/libs/zeroconf/avahi-client/client.h
deleted file mode 100644
index 1039da57af..0000000000
--- a/src/libs/zeroconf/avahi-client/client.h
+++ /dev/null
@@ -1,117 +0,0 @@
-#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
deleted file mode 100644
index 52407f4aa5..0000000000
--- a/src/libs/zeroconf/avahi-client/lookup.h
+++ /dev/null
@@ -1,314 +0,0 @@
-#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
deleted file mode 100644
index a14104fad6..0000000000
--- a/src/libs/zeroconf/avahi-common/address.h
+++ /dev/null
@@ -1,119 +0,0 @@
-#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
deleted file mode 100644
index aef6aba0e9..0000000000
--- a/src/libs/zeroconf/avahi-common/cdecl.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#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
deleted file mode 100644
index bb73a9dfdb..0000000000
--- a/src/libs/zeroconf/avahi-common/defs.h
+++ /dev/null
@@ -1,356 +0,0 @@
-#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
deleted file mode 100644
index 392aaf53bd..0000000000
--- a/src/libs/zeroconf/avahi-common/error.h
+++ /dev/null
@@ -1,107 +0,0 @@
-#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
deleted file mode 100644
index 4c97111aaf..0000000000
--- a/src/libs/zeroconf/avahi-common/gccmacro.h
+++ /dev/null
@@ -1,74 +0,0 @@
-#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
deleted file mode 100644
index ffaac3f3c7..0000000000
--- a/src/libs/zeroconf/avahi-common/malloc.h
+++ /dev/null
@@ -1,96 +0,0 @@
-#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
deleted file mode 100644
index 72c1905bcb..0000000000
--- a/src/libs/zeroconf/avahi-common/simple-watch.h
+++ /dev/null
@@ -1,85 +0,0 @@
-#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
deleted file mode 100644
index 94adcea8af..0000000000
--- a/src/libs/zeroconf/avahi-common/strlst.h
+++ /dev/null
@@ -1,180 +0,0 @@
-#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
deleted file mode 100644
index 86e63d3bf5..0000000000
--- a/src/libs/zeroconf/avahi-common/watch.h
+++ /dev/null
@@ -1,97 +0,0 @@
-#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
deleted file mode 100644
index f6bdc3605e..0000000000
--- a/src/libs/zeroconf/avahiLib.cpp
+++ /dev/null
@@ -1,570 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "servicebrowser.h"
-#include "servicebrowser_p.h"
-
-#include <QtGlobal>
-#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>
-#include <sys/poll.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" int cAvahiPollFunction(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata);
-
-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 void (*AvahiSimplePollSetFuncPtr)(AvahiSimplePoll *s, AvahiPollFunc func, void *userdata);
-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;
- AvahiSimplePollSetFuncPtr m_simplePollSetFunc;
- AvahiClientNewPtr m_clientNew;
- AvahiClientFreePtr m_clientFree;
- AvahiServiceBrowserNewPtr m_serviceBrowserNew;
- AvahiServiceBrowserFreePtr m_serviceBrowserFree;
- AvahiServiceResolverNewPtr m_serviceResolverNew;
- AvahiServiceResolverFreePtr m_serviceResolverFree;
- QLibrary nativeLib;
-public:
-
- AvahiZConfLib(const QString &libName = QLatin1String("avahi-client"),
- const QString &version = QLatin1String("3"),
- const ZConfLib::Ptr &fallBack = ZConfLib::Ptr(0)) :
- ZConfLib(fallBack), nativeLib(libName, version)
- {
-#ifndef ZCONF_AVAHI_STATIC_LINKING
- // dynamic linking
- if (!nativeLib.load()) {
- setError(true,
- ZConfLib::tr("AvahiZConfLib could not load the native library \"%1\": %2").arg(libName, nativeLib.errorString()));
- }
- 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_simplePollSetFunc = reinterpret_cast<AvahiSimplePollSetFuncPtr>(nativeLib.resolve("avahi_simple_poll_set_func"));
- 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_simplePollSetFunc = reinterpret_cast<AvahiSimplePollSetFuncPtr>(&avahi_simple_poll_set_func);
- 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_simplePollSetFunc) qDebug() << name() << " has null m_simplePollSetFunc";
- 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::fromLatin1("Avahi Library");
- }
-
- // 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,
- ZK_IP_Protocol protocol, 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;
- AvahiProtocol avahiProtocol = AVAHI_PROTO_UNSPEC;
- switch (protocol) {
- case ZK_PROTO_IPv4:
- avahiProtocol = AVAHI_PROTO_INET;
- break;
- case ZK_PROTO_IPv6:
- avahiProtocol = AVAHI_PROTO_INET6;
- break;
- case ZK_PROTO_IPv4_OR_IPv6:
- avahiProtocol = AVAHI_PROTO_UNSPEC;
- break;
- default:
- qDebug() << "Zeroconf: unexpected value " << static_cast<int>(protocol) <<
- " for protocol in avahiLib.resolve";
- }
- AvahiServiceResolver *resolver = m_serviceResolverNew(
- connection->client, interfaceIndex, avahiProtocol, name, regtype, domain,
- avahiProtocol, AvahiLookupFlags(0), &cAvahiResolveReply, gatherer);
- //*sdRef = reinterpret_cast<DNSServiceRef>(resolver); // add for restart?
- 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));
- }
- browser->activateAutoRefresh();
- return kDNSServiceErr_NoError;
- }
-
- DNSServiceErrorType getProperty(const char * /*property*/,
- void * /*result*/,
- uint32_t * /*size*/
- )
- {
- return 0;
- }
-
- RunLoopStatus processOneEvent(MainConnection *, ConnectionRef cRef, qint64 maxLockMs) {
- if (!m_simplePollIterate)
- return ProcessedFailure;
- MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
- if (!connection)
- return ProcessedError;
- if (m_simplePollIterate(connection->simple_poll, static_cast<int>(maxLockMs)))
- return ProcessedError;
- return ProcessedOk;
- }
-
- RunLoopStatus processOneEventBlock(ConnectionRef cRef) {
- return processOneEvent(NULL,cRef,-1);
- }
-
- DNSServiceErrorType createConnection(MainConnection *mainConnection, ConnectionRef *sdRef) {
- if (!m_simplePollNew || !m_clientNew || !m_simplePollSetFunc)
- return kDNSServiceErr_Unknown;
- if (sdRef == 0) {
- qDebug() << "Error: sdRef is null in createConnection";
- return kDNSServiceErr_Unknown;
- }
- MyAvahiConnection *connection = new MyAvahiConnection;
- connection->lib = this;
- /* Allocate main loop object */
- connection->simple_poll = m_simplePollNew();
- if (!connection->simple_poll) {
- delete connection;
- return kDNSServiceErr_Unknown;
- }
- m_simplePollSetFunc(connection->simple_poll, &cAvahiPollFunction, mainConnection);
- /* 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, ZConfLib::tr("%1 cannot create a client. The daemon is probably not running.").arg(name()));
- 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::Ptr ZConfLib::createAvahiLib(const QString &libName, const QString &version,
- const ZConfLib::Ptr &fallback)
-{
- return ZConfLib::Ptr(new AvahiZConfLib(libName, version, 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;
- }
- AvahiStringList *txtAtt = 0;
- const unsigned char emptyTxt[1]="";
- switch (event) {
- case AVAHI_RESOLVER_FAILURE:
- sg->serviceResolveReply(0, interface, kDNSServiceErr_Timeout, 0, QString(), 0, 0);
- break;
- case AVAHI_RESOLVER_FOUND:
- sg->serviceResolveReply(
- kDNSServiceFlagsAdd | ((txtAtt || address)?kDNSServiceFlagsMoreComing:0),
- interface, kDNSServiceErr_NoError, hostName, QString::number(port), 0, emptyTxt);
- txtAtt = txt;
- while (txtAtt) {
- sg->txtFieldReply(
- kDNSServiceFlagsAdd | ((txtAtt->next || address)?kDNSServiceFlagsMoreComing:0),
- kDNSServiceErr_NoError, static_cast<unsigned short>(txtAtt->size),
- txtAtt->text, ~0);
- 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);
- break;
- 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);
- break;
- 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;
- }
- ZConfLib::Ptr libBase = sg->serviceBrowser->mainConnection->lib;
- AvahiZConfLib *lib = dynamic_cast<AvahiZConfLib *>(libBase.data());
- 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, ZConfLib::tr("cAvahiClient, server collision."));
- break;
- case (AVAHI_CLIENT_FAILURE):
- lib->setError(true, ZConfLib::tr("cAvahiClient, an error occurred on the client side."));
- break;
- case (AVAHI_CLIENT_CONNECTING):
- lib->setError(false, ZConfLib::tr("cAvahiClient, still connecting, no server available."));
- break;
- default:
- lib->setError(true, ZConfLib::tr("Unexpected state %1 in cAvahiClientReply.")
- .arg(state));
- }
-}
-
-extern "C" void cAvahiBrowseReply(
- AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol avahiProtocol,
- AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
- AvahiLookupResultFlags /*flags*/, void* context)
-{
- ZK_IP_Protocol protocol = ZK_PROTO_IPv4_OR_IPv6;
- switch (avahiProtocol) {
- case AVAHI_PROTO_INET:
- protocol = ZK_PROTO_IPv4;
- break;
- case AVAHI_PROTO_INET6:
- protocol = ZK_PROTO_IPv6;
- break;
- case AVAHI_PROTO_UNSPEC:
- protocol = ZK_PROTO_IPv4_OR_IPv6;
- break;
- default:
- qDebug() << "Error unexpected protocol value " << avahiProtocol << " in cAvahiBrowseReply";
- }
-
- 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, protocol, kDNSServiceErr_Unknown,
- 0, 0, 0);
- break;
- case AVAHI_BROWSER_NEW:
- browser->browseReply(kDNSServiceFlagsAdd|kDNSServiceFlagsMoreComing,
- static_cast<uint32_t>(interface), protocol, kDNSServiceErr_NoError,
- name, type, domain);
- break;
- case AVAHI_BROWSER_REMOVE:
- browser->browseReply(kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface),
- protocol, 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, ZConfLib::tr(
- "Unexpected state %1 in cAvahiBrowseReply.")
- .arg(event));
- }
-}
-
-extern "C" int cAvahiPollFunction(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata)
-{
- MainConnection *mainConnection = static_cast<MainConnection *>(userdata);
- QMutex *lock = 0;
- if (mainConnection)
- lock = mainConnection->mainThreadLock();
- if (lock)
- lock->unlock();
- int res=poll(ufds,nfds,timeout);
- if (lock)
- lock->lock();
- return res;
-}
-
-} // namespace Internal
-} // namespace ZeroConf
-
-#else // no native lib
-
-namespace ZeroConf {
-namespace Internal {
-
-ZConfLib::Ptr ZConfLib::createAvahiLib(const QString &/*lib*/, const QString &/*version*/,
- const ZConfLib::Ptr &fallback)
-{
- return fallback;
-}
-
-} // namespace Internal
-} // namespace ZeroConf
-#endif
-
-
diff --git a/src/libs/zeroconf/dnsSdLib.cpp b/src/libs/zeroconf/dnsSdLib.cpp
deleted file mode 100644
index 61bb1c7b12..0000000000
--- a/src/libs/zeroconf/dnsSdLib.cpp
+++ /dev/null
@@ -1,324 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "syssocket.h" // this should be the first header included
-
-#include "servicebrowser.h"
-#include "servicebrowser_p.h"
-
-#include <QCoreApplication>
-#include <QDebug>
-#include <QLibrary>
-#include <QString>
-#include <QStringList>
-
-#include <errno.h>
-
-#ifndef NO_DNS_SD_LIB
-
-#ifdef Q_OS_MACX
-#define ZCONF_MDNS_STATIC_LINKING
-#endif
-
-#ifdef ZCONF_MDNS_STATIC_LINKING
-extern "C" {
-#include "dns_sd_funct.h"
-}
-#endif
-
-#ifdef Q_OS_UNIX
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#endif
-
-namespace ZeroConf {
-namespace Internal {
-
-extern "C" {
-typedef void (DNSSD_API *RefDeallocatePtr)(DNSServiceRef sdRef);
-typedef DNSServiceErrorType (DNSSD_API *ResolvePtr)(DNSServiceRef *sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, const char *name,
- const char *regtype, const char *domain,
- DNSServiceResolveReply callBack, void *context);
-typedef DNSServiceErrorType (DNSSD_API *QueryRecordPtr)(DNSServiceRef *sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, const char *fullname,
- uint16_t rrtype, uint16_t rrclass,
- DNSServiceQueryRecordReply callBack, void *context);
-typedef DNSServiceErrorType (DNSSD_API *GetAddrInfoPtr)(DNSServiceRef *sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, DNSServiceProtocol protocol,
- const char *hostname, DNSServiceGetAddrInfoReply callBack,
- void *context);
-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);
-typedef DNSServiceErrorType (DNSSD_API *BrowsePtr)(DNSServiceRef *sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, const char *regtype, const char *domain,
- DNSServiceBrowseReply callBack, void *context);
-typedef DNSServiceErrorType (DNSSD_API *GetPropertyPtr)(const char *property, void *result, uint32_t *size);
-typedef DNSServiceErrorType (DNSSD_API *ProcessResultPtr)(DNSServiceRef sdRef);
-typedef DNSServiceErrorType (DNSSD_API *CreateConnectionPtr)(DNSServiceRef *sdRef);
-typedef int (DNSSD_API *RefSockFDPtr)(DNSServiceRef sdRef);
-}
-
-// represents a zero conf library exposing the dns-sd interface
-class DnsSdZConfLib : public ZConfLib {
- Q_DECLARE_TR_FUNCTIONS(ZeroConf)
-private:
- RefDeallocatePtr m_refDeallocate;
- ResolvePtr m_resolve;
- QueryRecordPtr m_queryRecord;
- GetAddrInfoPtr m_getAddrInfo;
- ReconfirmRecordPtr m_reconfirmRecord;
- BrowsePtr m_browse;
- GetPropertyPtr m_getProperty;
- ProcessResultPtr m_processResult;
- CreateConnectionPtr m_createConnection;
- RefSockFDPtr m_refSockFD;
- QLibrary dnsSdLib;
-public:
-
- DnsSdZConfLib(QString libName = QLatin1String("dns_sd"), ZConfLib::Ptr fallBack = ZConfLib::Ptr(0)) : ZConfLib(fallBack), dnsSdLib(libName)
- {
-#ifndef ZCONF_MDNS_STATIC_LINKING
- // dynamic linking
- if (!dnsSdLib.load()) {
- m_isOk = false;
- m_errorMsg = tr("Could not load native library.");
- }
- m_refDeallocate = reinterpret_cast<RefDeallocatePtr>(dnsSdLib.resolve("DNSServiceRefDeallocate"));
- m_resolve = reinterpret_cast<ResolvePtr>(dnsSdLib.resolve("DNSServiceResolve"));
- m_queryRecord = reinterpret_cast<QueryRecordPtr>(dnsSdLib.resolve("DNSServiceQueryRecord"));
- m_getAddrInfo = reinterpret_cast<GetAddrInfoPtr>(dnsSdLib.resolve("DNSServiceGetAddrInfo"));
- m_reconfirmRecord = reinterpret_cast<ReconfirmRecordPtr>(dnsSdLib.resolve("DNSServiceReconfirmRecord"));
- m_browse = reinterpret_cast<BrowsePtr>(dnsSdLib.resolve("DNSServiceBrowse"));
- m_getProperty = reinterpret_cast<GetPropertyPtr>(dnsSdLib.resolve("DNSServiceGetProperty"));
- m_processResult = reinterpret_cast<ProcessResultPtr>(dnsSdLib.resolve("DNSServiceProcessResult")) ;
- m_createConnection = reinterpret_cast<CreateConnectionPtr>(dnsSdLib.resolve("DNSServiceCreateConnection"));
- m_refSockFD = reinterpret_cast<RefSockFDPtr>(dnsSdLib.resolve("DNSServiceRefSockFD"));
-#else
- // static linking
- m_refDeallocate = reinterpret_cast<RefDeallocatePtr>(&DNSServiceRefDeallocate);
- m_resolve = reinterpret_cast<ResolvePtr>(&DNSServiceResolve);
- m_queryRecord = reinterpret_cast<QueryRecordPtr>(DNSServiceQueryRecord);
- m_getAddrInfo = reinterpret_cast<GetAddrInfoPtr>(&DNSServiceGetAddrInfo);
- m_reconfirmRecord = reinterpret_cast<ReconfirmRecordPtr>(&DNSServiceReconfirmRecord);
- m_browse = reinterpret_cast<BrowsePtr>(&DNSServiceBrowse);
- m_getProperty = reinterpret_cast<GetPropertyPtr>(&DNSServiceGetProperty);
- m_processResult = reinterpret_cast<ProcessResultPtr>(&DNSServiceProcessResult) ;
- m_createConnection = reinterpret_cast<CreateConnectionPtr>(&DNSServiceCreateConnection);
- m_refSockFD = reinterpret_cast<RefSockFDPtr>(&DNSServiceRefSockFD);
-#endif
- if (m_isOk && m_getAddrInfo == 0) {
- m_isOk = false;
-#ifdef Q_OS_LINUX
- m_errorMsg = tr("Skipping over Avahi compatibility lib (or obsolete mdnsd).");
-#else
- m_errorMsg = tr("Warning: Detected an obsolete version of Apple Bonjour. Disable, uninstall, or upgrade it, or zeroconf will fail.");
-#endif
- }
- if (DEBUG_ZEROCONF){
- if (m_refDeallocate == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_refDeallocate == 0");
- if (m_resolve == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_resolve == 0");
- if (m_queryRecord == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_queryRecord == 0");
- if (m_getAddrInfo == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_getAddrInfo == 0");
- if (m_reconfirmRecord == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_reconfirmRecord == 0");
- if (m_browse == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_browse == 0");
- if (m_getProperty == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_getProperty == 0");
- if (m_processResult == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_processResult == 0");
- if (m_createConnection == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_createConnection == 0");
- if (m_refSockFD == 0) qDebug() << QLatin1String("DnsSdZConfLib.m_refSockFD == 0");
- }
- }
-
- ~DnsSdZConfLib() {
- }
-
- QString name(){
- return QString::fromLatin1("Dns_sd (Apple Bonjour) Library");
- }
-
- // bool tryStartDaemon();
- void refDeallocate(DNSServiceRef sdRef) {
- if (m_refDeallocate == 0) return;
- m_refDeallocate(sdRef);
- }
-
- 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, ZK_IP_Protocol /* protocol */, const char *name,
- const char *regtype, const char *domain,
- ServiceGatherer *gatherer)
- {
- if (m_resolve == 0) return kDNSServiceErr_Unsupported;
- *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
- return m_resolve(sdRef, kDNSServiceFlagsShareConnection /* | kDNSServiceFlagsSuppressUnusable*/ | kDNSServiceFlagsTimeout,
- interfaceIndex, name, regtype, domain, &cServiceResolveReply, gatherer
- );
- }
-
- DNSServiceErrorType queryRecord(ConnectionRef cRef, DNSServiceRef *sdRef,
- uint32_t interfaceIndex, const char *fullname,
- ServiceGatherer *gatherer)
- {
- if (m_queryRecord == 0) return kDNSServiceErr_Unsupported;
- *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
- return m_queryRecord(sdRef, kDNSServiceFlagsShareConnection
- /* | kDNSServiceFlagsSuppressUnusable*/ | kDNSServiceFlagsTimeout,
- interfaceIndex, fullname,
- kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply, gatherer);
- }
-
- DNSServiceErrorType getAddrInfo(ConnectionRef cRef, DNSServiceRef *sdRef,
- uint32_t interfaceIndex, DNSServiceProtocol protocol,
- const char *hostname, ServiceGatherer *gatherer)
- {
- enum { longTTL = 100 };
- if (m_getAddrInfo == 0) {
-#ifdef Q_OS_UNIX
- // try to use getaddrinfo (for example on linux with avahi)
- struct addrinfo req, *ans; int err;
- memset(&req, 0, sizeof(req));
- req.ai_flags = 0;
- req.ai_family = AF_UNSPEC;
- req.ai_socktype = SOCK_STREAM;
- req.ai_protocol = 0;
- if ((err = getaddrinfo(hostname, 0, &req, &ans)) != 0) {
- qDebug() << "getaddrinfo for " << hostname << " failed with " << gai_strerror(err);
- return kDNSServiceErr_Unsupported; // use another error here???
- }
- for (struct addrinfo *ansAtt = ans; ansAtt != 0; ansAtt = ansAtt->ai_next){
- gatherer->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError,
- hostname, ansAtt->ai_addr, longTTL);
- }
- freeaddrinfo(ans);
- return kDNSServiceErr_NoError;
-#else
- return kDNSServiceErr_Unsupported;
-#endif
- }
- *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
- return m_getAddrInfo(sdRef, kDNSServiceFlagsShareConnection
- /*| kDNSServiceFlagsSuppressUnusable */ | kDNSServiceFlagsTimeout,
- interfaceIndex, protocol, hostname, &cAddrReply, gatherer);
- }
-
- 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;
- // reload and force update with in the callback with
- // m_reconfirmRecord(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, ServiceBrowserPrivate *browser)
- {
- if (m_browse == 0) return kDNSServiceErr_Unsupported;
- 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, void *result, uint32_t *size)
- {
- if (m_getProperty == 0)
- return kDNSServiceErr_Unsupported;
- return m_getProperty(property, result, size);
- }
-
- RunLoopStatus processOneEventBlock(ConnectionRef cRef)
- {
- if (m_processResult == 0)
- return ProcessedFailure;
- if (m_processResult(reinterpret_cast<DNSServiceRef>(cRef)) != kDNSServiceErr_NoError)
- return ProcessedError;
- return ProcessedOk;
- }
-
- DNSServiceErrorType createConnection(MainConnection *, ConnectionRef *sdRef)
- {
- if (m_createConnection == 0) return kDNSServiceErr_Unsupported;
- return m_createConnection(reinterpret_cast<DNSServiceRef *>(sdRef));
- }
-
- int refSockFD(ConnectionRef sdRef)
- {
- if (m_refSockFD == 0) return kDNSServiceErr_Unsupported;
- return m_refSockFD(reinterpret_cast<DNSServiceRef>(sdRef));
- }
-};
-
-ZConfLib::Ptr ZConfLib::createDnsSdLib(const QString &libName, const ZConfLib::Ptr &fallback) {
- return ZConfLib::Ptr(new DnsSdZConfLib(libName, fallback));
-}
-} // namespace Internal
-} // namespace ZeroConf
-
-#else // NO_DNS_SD_LIB
-
-namespace ZeroConf {
-namespace Internal {
-
-ZConfLib::Ptr ZConfLib::createDnsSdLib(const QString &/*extraPaths*/, const ZConfLib::Ptr &fallback) {
- return fallback;
-}
-
-} // namespace Internal
-} // namespace ZeroConf
-#endif
-
diff --git a/src/libs/zeroconf/dns_sd_funct.h b/src/libs/zeroconf/dns_sd_funct.h
deleted file mode 100644
index da5a5f827c..0000000000
--- a/src/libs/zeroconf/dns_sd_funct.h
+++ /dev/null
@@ -1,1364 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-/*! @header DNS Service Discovery
- *
- * @discussion This section describes the functions, callbacks, and data structures
- * that make up the DNS Service Discovery API.
- *
- * The DNS Service Discovery API is part of Bonjour, Apple's implementation
- * of zero-configuration networking (ZEROCONF).
- *
- * Bonjour allows you to register a network service, such as a
- * printer or file server, so that it can be found by name or browsed
- * for by service type and domain. Using Bonjour, applications can
- * discover what services are available on the network, along with
- * all the information -- such as name, IP address, and port --
- * necessary to access a particular service.
- *
- * In effect, Bonjour combines the functions of a local DNS server and
- * AppleTalk. Bonjour allows applications to provide user-friendly printer
- * and server browsing, among other things, over standard IP networks.
- * This behavior is a result of combining protocols such as multicast and
- * DNS to add new functionality to the network (such as multicast DNS).
- *
- * Bonjour gives applications easy access to services over local IP
- * networks without requiring the service or the application to support
- * an AppleTalk or a Netbeui stack, and without requiring a DNS server
- * for the local network.
- */
-
-
-/* _DNS_SD_H contains the mDNSResponder version number for this header file, formatted as follows:
- * Major part of the build number * 10000 +
- * minor part of the build number * 100
- * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as
- * version 1080400. This allows C code to do simple greater-than and less-than comparisons:
- * e.g. an application that requires the DNSServiceGetProperty() call (new in mDNSResponder-126) can check:
- *
- * #if _DNS_SD_H+0 >= 1260000
- * ... some C code that calls DNSServiceGetProperty() ...
- * #endif
- *
- * The version defined in this header file symbol allows for compile-time
- * checking, so that C code building with earlier versions of the header file
- * can avoid compile errors trying to use functions that aren't even defined
- * in those earlier versions. Similar checks may also be performed at run-time:
- * => weak linking -- to avoid link failures if run with an earlier
- * version of the library that's missing some desired symbol, or
- * => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon
- * ("system service" on Windows) meets some required minimum functionality level.
- */
-
-#ifndef _DNS_SD_H
-#define _DNS_SD_H 3200500
-
-#include "dns_sd_types.h"
-/*********************************************************************************************
- *
- * Version checking
- *
- *********************************************************************************************/
-
-/* DNSServiceGetProperty() Parameters:
- *
- * property: The requested property.
- * Currently the only property defined is kDNSServiceProperty_DaemonVersion.
- *
- * result: Place to store result.
- * For retrieving DaemonVersion, this should be the address of a uint32_t.
- *
- * size: Pointer to uint32_t containing size of the result location.
- * For retrieving DaemonVersion, this should be sizeof(uint32_t).
- * On return the uint32_t is updated to the size of the data returned.
- * For DaemonVersion, the returned size is always sizeof(uint32_t), but
- * future properties could be defined which return variable-sized results.
- *
- * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning
- * if the daemon (or "system service" on Windows) is not running.
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceGetProperty
- (
- const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
- void *result, /* Pointer to place to store result */
- uint32_t *size /* size of result location */
- );
-
-
-/*********************************************************************************************
- *
- * Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions
- *
- *********************************************************************************************/
-
-/* DNSServiceRefSockFD()
- *
- * Access underlying Unix domain socket for an initialized DNSServiceRef.
- * The DNS Service Discovery implementation uses this socket to communicate between the client and
- * the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket.
- * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop
- * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/
- * select/CFRunLoop etc.) indicates to the client that data is available for reading on the
- * socket, the client should call DNSServiceProcessResult(), which will extract the daemon's
- * reply from the socket, and pass it to the appropriate application callback. By using a run
- * loop or select(), results from the daemon can be processed asynchronously. Alternatively,
- * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);"
- * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it
- * will block until data does become available, and then process the data and return to the caller.
- * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref)
- * in a timely fashion -- if the client allows a large backlog of data to build up the daemon
- * may terminate the connection.
- *
- * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
- *
- * return value: The DNSServiceRef's underlying socket descriptor, or -1 on
- * error.
- */
-
-int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef);
-
-
-/* DNSServiceProcessResult()
- *
- * Read a reply from the daemon, calling the appropriate application callback. This call will
- * block until the daemon's response is received. Use DNSServiceRefSockFD() in
- * conjunction with a run loop or select() to determine the presence of a response from the
- * server before calling this function to process the reply without blocking. Call this function
- * at any point if it is acceptable to block until the daemon's response arrives. Note that the
- * client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is
- * a reply from the daemon - the daemon may terminate its connection with a client that does not
- * process the daemon's responses.
- *
- * sdRef: A DNSServiceRef initialized by any of the DNSService calls
- * that take a callback parameter.
- *
- * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
- * an error code indicating the specific failure that occurred.
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef);
-
-
-/* DNSServiceRefDeallocate()
- *
- * Terminate a connection with the daemon and free memory associated with the DNSServiceRef.
- * Any services or records registered with this DNSServiceRef will be deregistered. Any
- * Browse, Resolve, or Query operations called with this reference will be terminated.
- *
- * Note: If the reference's underlying socket is used in a run loop or select() call, it should
- * be removed BEFORE DNSServiceRefDeallocate() is called, as this function closes the reference's
- * socket.
- *
- * Note: If the reference was initialized with DNSServiceCreateConnection(), any DNSRecordRefs
- * created via this reference will be invalidated by this call - the resource records are
- * deregistered, and their DNSRecordRefs may not be used in subsequent functions. Similarly,
- * if the reference was initialized with DNSServiceRegister, and an extra resource record was
- * added to the service via DNSServiceAddRecord(), the DNSRecordRef created by the Add() call
- * is invalidated when this function is called - the DNSRecordRef may not be used in subsequent
- * functions.
- *
- * Note: This call is to be used only with the DNSServiceRef defined by this API. It is
- * not compatible with dns_service_discovery_ref objects defined in the legacy Mach-based
- * DNSServiceDiscovery.h API.
- *
- * sdRef: A DNSServiceRef initialized by any of the DNSService calls.
- *
- */
-
-void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef);
-
-
-/*********************************************************************************************
- *
- * Domain Enumeration
- *
- *********************************************************************************************/
-
-
-/* DNSServiceEnumerateDomains() Parameters:
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
- * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
- * and the enumeration operation will run indefinitely until the client
- * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
- *
- * flags: Possible values are:
- * kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing.
- * kDNSServiceFlagsRegistrationDomains to enumerate domains recommended
- * for registration.
- *
- * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
- * (the index for a given interface is determined via the if_nametoindex()
- * family of calls.) Most applications will pass 0 to enumerate domains on
- * all interfaces. See "Constants for specifying an interface index" for more details.
- *
- * callBack: The function to be called when a domain is found or the call asynchronously
- * fails.
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred (the callback is not invoked and the DNSServiceRef
- * is not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceDomainEnumReply callBack,
- void *context /* may be NULL */
- );
-
-
-/*********************************************************************************************
- *
- * Service Registration
- *
- *********************************************************************************************/
-
-/* DNSServiceRegister() Parameters:
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
- * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
- * and the registration will remain active indefinitely until the client
- * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
- *
- * interfaceIndex: If non-zero, specifies the interface on which to register the service
- * (the index for a given interface is determined via the if_nametoindex()
- * family of calls.) Most applications will pass 0 to register on all
- * available interfaces. See "Constants for specifying an interface index" for more details.
- *
- * flags: Indicates the renaming behavior on name conflict (most applications
- * will pass 0). See flag definitions above for details.
- *
- * name: If non-NULL, specifies the service name to be registered.
- * Most applications will not specify a name, in which case the computer
- * name is used (this name is communicated to the client via the callback).
- * If a name is specified, it must be 1-63 bytes of UTF-8 text.
- * If the name is longer than 63 bytes it will be automatically truncated
- * to a legal length, unless the NoAutoRename flag is set,
- * in which case kDNSServiceErr_BadParam will be returned.
- *
- * regtype: The service type followed by the protocol, separated by a dot
- * (e.g. "_ftp._tcp"). The service type must be an underscore, followed
- * by 1-15 characters, which may be letters, digits, or hyphens.
- * The transport protocol must be "_tcp" or "_udp". New service types
- * should be registered at <http://www.dns-sd.org/ServiceTypes.html>.
- *
- * Additional subtypes of the primary service type (where a service
- * type has defined subtypes) follow the primary service type in a
- * comma-separated list, with no additional spaces, e.g.
- * "_primarytype._tcp,_subtype1,_subtype2,_subtype3"
- * Subtypes provide a mechanism for filtered browsing: A client browsing
- * for "_primarytype._tcp" will discover all instances of this type;
- * a client browsing for "_primarytype._tcp,_subtype2" will discover only
- * those instances that were registered with "_subtype2" in their list of
- * registered subtypes.
- *
- * The subtype mechanism can be illustrated with some examples using the
- * dns-sd command-line tool:
- *
- * % dns-sd -R Simple _test._tcp "" 1001 &
- * % dns-sd -R Better _test._tcp,HasFeatureA "" 1002 &
- * % dns-sd -R Best _test._tcp,HasFeatureA,HasFeatureB "" 1003 &
- *
- * Now:
- * % dns-sd -B _test._tcp # will find all three services
- * % dns-sd -B _test._tcp,HasFeatureA # finds "Better" and "Best"
- * % dns-sd -B _test._tcp,HasFeatureB # finds only "Best"
- *
- * Subtype labels may be up to 63 bytes long, and may contain any eight-
- * bit byte values, including zero bytes. However, due to the nature of
- * using a C-string-based API, conventional DNS escaping must be used for
- * dots ('.'), commas (','), backslashes ('\') and zero bytes, as shown below:
- *
- * % dns-sd -R Test '_test._tcp,s\.one,s\,two,s\\three,s\000four' local 123
- *
- * domain: If non-NULL, specifies the domain on which to advertise the service.
- * Most applications will not specify a domain, instead automatically
- * registering in the default domain(s).
- *
- * host: If non-NULL, specifies the SRV target host name. Most applications
- * will not specify a host, instead automatically using the machine's
- * default host name(s). Note that specifying a non-NULL host does NOT
- * create an address record for that host - the application is responsible
- * for ensuring that the appropriate address record exists, or creating it
- * via DNSServiceRegisterRecord().
- *
- * port: The port, in network byte order, on which the service accepts connections.
- * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
- * by browsing, but will cause a name conflict if another client tries to
- * register that same name). Most clients will not use placeholder services.
- *
- * txtLen: The length of the txtRecord, in bytes. Must be zero if the txtRecord is NULL.
- *
- * txtRecord: The TXT record rdata. A non-NULL txtRecord MUST be a properly formatted DNS
- * TXT record, i.e. <length byte> <data> <length byte> <data> ...
- * Passing NULL for the txtRecord is allowed as a synonym for txtLen=1, txtRecord="",
- * i.e. it creates a TXT record of length one containing a single empty string.
- * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty
- * string is the smallest legal DNS TXT record.
- * As with the other parameters, the DNSServiceRegister call copies the txtRecord
- * data; e.g. if you allocated the storage for the txtRecord parameter with malloc()
- * then you can safely free that memory right after the DNSServiceRegister call returns.
- *
- * callBack: The function to be called when the registration completes or asynchronously
- * fails. The client MAY pass NULL for the callback - The client will NOT be notified
- * of the default values picked on its behalf, and the client will NOT be notified of any
- * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
- * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
- * The client may still deregister the service at any time via DNSServiceRefDeallocate().
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred (the callback is never invoked and the DNSServiceRef
- * is not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceRegister
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *name, /* may be NULL */
- const char *regtype,
- const char *domain, /* may be NULL */
- const char *host, /* may be NULL */
- uint16_t port, /* In network byte order */
- uint16_t txtLen,
- const void *txtRecord, /* may be NULL */
- DNSServiceRegisterReply callBack, /* may be NULL */
- void *context /* may be NULL */
- );
-
-
-/* DNSServiceAddRecord()
- *
- * Add a record to a registered service. The name of the record will be the same as the
- * registered service's name.
- * The record can later be updated or deregistered by passing the RecordRef initialized
- * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
- *
- * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe
- * with respect to a single DNSServiceRef. If you plan to have multiple threads
- * in your program simultaneously add, update, or remove records from the same
- * DNSServiceRef, then it's the caller's responsibility to use a mutext lock
- * or take similar appropriate precautions to serialize those calls.
- *
- * Parameters;
- *
- * sdRef: A DNSServiceRef initialized by DNSServiceRegister().
- *
- * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
- * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
- * If the above DNSServiceRef is passed to DNSServiceRefDeallocate(), RecordRef is also
- * invalidated and may not be used further.
- *
- * flags: Currently ignored, reserved for future use.
- *
- * rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc)
- *
- * rdlen: The length, in bytes, of the rdata.
- *
- * rdata: The raw rdata to be contained in the added resource record.
- *
- * ttl: The time to live of the resource record, in seconds.
- * Most clients should pass 0 to indicate that the system should
- * select a sensible default value.
- *
- * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
- * error code indicating the error that occurred (the RecordRef is not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceAddRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef *RecordRef,
- DNSServiceFlags flags,
- uint16_t rrtype,
- uint16_t rdlen,
- const void *rdata,
- uint32_t ttl
- );
-
-
-/* DNSServiceUpdateRecord
- *
- * Update a registered resource record. The record must either be:
- * - The primary txt record of a service registered via DNSServiceRegister()
- * - A record added to a registered service via DNSServiceAddRecord()
- * - An individual record registered by DNSServiceRegisterRecord()
- *
- * Parameters:
- *
- * sdRef: A DNSServiceRef that was initialized by DNSServiceRegister()
- * or DNSServiceCreateConnection().
- *
- * RecordRef: A DNSRecordRef initialized by DNSServiceAddRecord, or NULL to update the
- * service's primary txt record.
- *
- * flags: Currently ignored, reserved for future use.
- *
- * rdlen: The length, in bytes, of the new rdata.
- *
- * rdata: The new rdata to be contained in the updated resource record.
- *
- * ttl: The time to live of the updated resource record, in seconds.
- * Most clients should pass 0 to indicate that the system should
- * select a sensible default value.
- *
- * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
- * error code indicating the error that occurred.
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef RecordRef, /* may be NULL */
- DNSServiceFlags flags,
- uint16_t rdlen,
- const void *rdata,
- uint32_t ttl
- );
-
-
-/* DNSServiceRemoveRecord
- *
- * Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister
- * an record registered individually via DNSServiceRegisterRecord().
- *
- * Parameters:
- *
- * sdRef: A DNSServiceRef initialized by DNSServiceRegister() (if the
- * record being removed was registered via DNSServiceAddRecord()) or by
- * DNSServiceCreateConnection() (if the record being removed was registered via
- * DNSServiceRegisterRecord()).
- *
- * recordRef: A DNSRecordRef initialized by a successful call to DNSServiceAddRecord()
- * or DNSServiceRegisterRecord().
- *
- * flags: Currently ignored, reserved for future use.
- *
- * return value: Returns kDNSServiceErr_NoError on success, otherwise returns an
- * error code indicating the error that occurred.
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef RecordRef,
- DNSServiceFlags flags
- );
-
-
-/*********************************************************************************************
- *
- * Service Discovery
- *
- *********************************************************************************************/
-
-/* DNSServiceBrowse() Parameters:
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
- * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
- * and the browse operation will run indefinitely until the client
- * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
- *
- * flags: Currently ignored, reserved for future use.
- *
- * interfaceIndex: If non-zero, specifies the interface on which to browse for services
- * (the index for a given interface is determined via the if_nametoindex()
- * family of calls.) Most applications will pass 0 to browse on all available
- * interfaces. See "Constants for specifying an interface index" for more details.
- *
- * regtype: The service type being browsed for followed by the protocol, separated by a
- * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
- * A client may optionally specify a single subtype to perform filtered browsing:
- * e.g. browsing for "_primarytype._tcp,_subtype" will discover only those
- * instances of "_primarytype._tcp" that were registered specifying "_subtype"
- * in their list of registered subtypes.
- *
- * domain: If non-NULL, specifies the domain on which to browse for services.
- * Most applications will not specify a domain, instead browsing on the
- * default domain(s).
- *
- * callBack: The function to be called when an instance of the service being browsed for
- * is found, or if the call asynchronously fails.
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred (the callback is not invoked and the DNSServiceRef
- * is not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceBrowse
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *regtype,
- const char *domain, /* may be NULL */
- DNSServiceBrowseReply callBack,
- void *context /* may be NULL */
- );
-
-/* DNSServiceResolve() Parameters
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
- * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
- * and the resolve operation will run indefinitely until the client
- * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
- *
- * flags: Specifying kDNSServiceFlagsForceMulticast will cause query to be
- * performed with a link-local mDNS query, even if the name is an
- * apparently non-local name (i.e. a name not ending in ".local.")
- *
- * interfaceIndex: The interface on which to resolve the service. If this resolve call is
- * as a result of a currently active DNSServiceBrowse() operation, then the
- * interfaceIndex should be the index reported in the DNSServiceBrowseReply
- * callback. If this resolve call is using information previously saved
- * (e.g. in a preference file) for later use, then use interfaceIndex 0, because
- * the desired service may now be reachable via a different physical interface.
- * See "Constants for specifying an interface index" for more details.
- *
- * name: The name of the service instance to be resolved, as reported to the
- * DNSServiceBrowseReply() callback.
- *
- * regtype: The type of the service instance to be resolved, as reported to the
- * DNSServiceBrowseReply() callback.
- *
- * domain: The domain of the service instance to be resolved, as reported to the
- * DNSServiceBrowseReply() callback.
- *
- * callBack: The function to be called when a result is found, or if the call
- * asynchronously fails.
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred (the callback is never invoked and the DNSServiceRef
- * is not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceResolve
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *name,
- const char *regtype,
- const char *domain,
- DNSServiceResolveReply callBack,
- void *context /* may be NULL */
- );
-
-
-/*********************************************************************************************
- *
- * Querying Individual Specific Records
- *
- *********************************************************************************************/
-
-/* DNSServiceQueryRecord() Parameters:
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
- * then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
- * and the query operation will run indefinitely until the client
- * terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
- *
- * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
- * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
- * query in a non-local domain. Without setting this flag, unicast queries
- * will be one-shot - that is, only answers available at the time of the call
- * will be returned. By setting this flag, answers (including Add and Remove
- * events) that become available after the initial call is made will generate
- * callbacks. This flag has no effect on link-local multicast queries.
- *
- * interfaceIndex: If non-zero, specifies the interface on which to issue the query
- * (the index for a given interface is determined via the if_nametoindex()
- * family of calls.) Passing 0 causes the name to be queried for on all
- * interfaces. See "Constants for specifying an interface index" for more details.
- *
- * fullname: The full domain name of the resource record to be queried for.
- *
- * rrtype: The numerical type of the resource record to be queried for
- * (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
- *
- * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
- *
- * callBack: The function to be called when a result is found, or if the call
- * asynchronously fails.
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred (the callback is never invoked and the DNSServiceRef
- * is not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- DNSServiceQueryRecordReply callBack,
- void *context /* may be NULL */
- );
-
-
-/*********************************************************************************************
- *
- * Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname
- *
- *********************************************************************************************/
-
-/* DNSServiceGetAddrInfo() Parameters:
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
- * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the query
- * begins and will last indefinitely until the client terminates the query
- * by passing this DNSServiceRef to DNSServiceRefDeallocate().
- *
- * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery.
- * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast
- * query in a non-local domain. Without setting this flag, unicast queries
- * will be one-shot - that is, only answers available at the time of the call
- * will be returned. By setting this flag, answers (including Add and Remove
- * events) that become available after the initial call is made will generate
- * callbacks. This flag has no effect on link-local multicast queries.
- *
- * interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be
- * sent on all active interfaces via Multicast or the primary interface via Unicast.
- *
- * protocol: Pass in kDNSServiceProtocol_IPv4 to look up IPv4 addresses, or kDNSServiceProtocol_IPv6
- * to look up IPv6 addresses, or both to look up both kinds. If neither flag is
- * set, the system will apply an intelligent heuristic, which is (currently)
- * that it will attempt to look up both, except:
- *
- * * If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
- * but this host has no routable IPv6 address, then the call will not try to
- * look up IPv6 addresses for "hostname", since any addresses it found would be
- * unlikely to be of any use anyway. Similarly, if this host has no routable
- * IPv4 address, the call will not try to look up IPv4 addresses for "hostname".
- *
- * hostname: The fully qualified domain name of the host to be queried for.
- *
- * callBack: The function to be called when the query succeeds or fails asynchronously.
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred.
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceProtocol protocol,
- const char *hostname,
- DNSServiceGetAddrInfoReply callBack,
- void *context /* may be NULL */
- );
-
-
-/*********************************************************************************************
- *
- * Special Purpose Calls:
- * DNSServiceCreateConnection(), DNSServiceRegisterRecord(), DNSServiceReconfirmRecord()
- * (most applications will not use these)
- *
- *********************************************************************************************/
-
-/* DNSServiceCreateConnection()
- *
- * Create a connection to the daemon allowing efficient registration of
- * multiple individual records.
- *
- * Parameters:
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating
- * the reference (via DNSServiceRefDeallocate()) severs the
- * connection and deregisters all records registered on this connection.
- *
- * return value: Returns kDNSServiceErr_NoError on success, otherwise returns
- * an error code indicating the specific failure that occurred (in which
- * case the DNSServiceRef is not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef);
-
-/* DNSServiceRegisterRecord() Parameters:
- *
- * sdRef: A DNSServiceRef initialized by DNSServiceCreateConnection().
- *
- * RecordRef: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this
- * call, this ref may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord().
- * (To deregister ALL records registered on a single connected DNSServiceRef
- * and deallocate each of their corresponding DNSServiceRecordRefs, call
- * DNSServiceRefDeallocate()).
- *
- * flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique
- * (see flag type definitions for details).
- *
- * interfaceIndex: If non-zero, specifies the interface on which to register the record
- * (the index for a given interface is determined via the if_nametoindex()
- * family of calls.) Passing 0 causes the record to be registered on all interfaces.
- * See "Constants for specifying an interface index" for more details.
- *
- * fullname: The full domain name of the resource record.
- *
- * rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
- *
- * rrclass: The class of the resource record (usually kDNSServiceClass_IN)
- *
- * rdlen: Length, in bytes, of the rdata.
- *
- * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
- *
- * ttl: The time to live of the resource record, in seconds.
- * Most clients should pass 0 to indicate that the system should
- * select a sensible default value.
- *
- * callBack: The function to be called when a result is found, or if the call
- * asynchronously fails (e.g. because of a name conflict.)
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred (the callback is never invoked and the DNSRecordRef is
- * not initialized).
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef *RecordRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- uint16_t rdlen,
- const void *rdata,
- uint32_t ttl,
- DNSServiceRegisterRecordReply callBack,
- void *context /* may be NULL */
- );
-
-
-/* DNSServiceReconfirmRecord
- *
- * Instruct the daemon to verify the validity of a resource record that appears
- * to be out of date (e.g. because TCP connection to a service's target failed.)
- * Causes the record to be flushed from the daemon's cache (as well as all other
- * daemons' caches on the network) if the record is determined to be invalid.
- * Use this routine conservatively. Reconfirming a record necessarily consumes
- * network bandwidth, so this should not be done indiscriminately.
- *
- * Parameters:
- *
- * flags: Pass kDNSServiceFlagsForce to force immediate deletion of record,
- * instead of after some number of reconfirmation queries have gone unanswered.
- *
- * interfaceIndex: Specifies the interface of the record in question.
- * The caller must specify the interface.
- * This API (by design) causes increased network traffic, so it requires
- * the caller to be precise about which record should be reconfirmed.
- * It is not possible to pass zero for the interface index to perform
- * a "wildcard" reconfirmation, where *all* matching records are reconfirmed.
- *
- * fullname: The resource record's full domain name.
- *
- * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
- *
- * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
- *
- * rdlen: The length, in bytes, of the resource record rdata.
- *
- * rdata: The raw rdata of the resource record.
- *
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
- (
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- uint16_t rdlen,
- const void *rdata
- );
-
-
-/*********************************************************************************************
- *
- * NAT Port Mapping
- *
- *********************************************************************************************/
-
-/* DNSServiceNATPortMappingCreate() Parameters:
- *
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds then it
- * initializes the DNSServiceRef, returns kDNSServiceErr_NoError, and the nat
- * port mapping will last indefinitely until the client terminates the port
- * mapping request by passing this DNSServiceRef to DNSServiceRefDeallocate().
- *
- * flags: Currently ignored, reserved for future use.
- *
- * interfaceIndex: The interface on which to create port mappings in a NAT gateway. Passing 0 causes
- * the port mapping request to be sent on the primary interface.
- *
- * protocol: To request a port mapping, pass in kDNSServiceProtocol_UDP, or kDNSServiceProtocol_TCP,
- * or (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP) to map both.
- * The local listening port number must also be specified in the internalPort parameter.
- * To just discover the NAT gateway's external IP address, pass zero for protocol,
- * internalPort, externalPort and ttl.
- *
- * internalPort: The port number in network byte order on the local machine which is listening for packets.
- *
- * externalPort: The requested external port in network byte order in the NAT gateway that you would
- * like to map to the internal port. Pass 0 if you don't care which external port is chosen for you.
- *
- * ttl: The requested renewal period of the NAT port mapping, in seconds.
- * If the client machine crashes, suffers a power failure, is disconnected from
- * the network, or suffers some other unfortunate demise which causes it to vanish
- * unexpectedly without explicitly removing its NAT port mappings, then the NAT gateway
- * will garbage-collect old stale NAT port mappings when their lifetime expires.
- * Requesting a short TTL causes such orphaned mappings to be garbage-collected
- * more promptly, but consumes system resources and network bandwidth with
- * frequent renewal packets to keep the mapping from expiring.
- * Requesting a long TTL is more efficient on the network, but in the event of the
- * client vanishing, stale NAT port mappings will not be garbage-collected as quickly.
- * Most clients should pass 0 to use a system-wide default value.
- *
- * callBack: The function to be called when the port mapping request succeeds or fails asynchronously.
- *
- * context: An application context pointer which is passed to the callback function
- * (may be NULL).
- *
- * return value: Returns kDNSServiceErr_NoError on success (any subsequent, asynchronous
- * errors are delivered to the callback), otherwise returns an error code indicating
- * the error that occurred.
- *
- * If you don't actually want a port mapped, and are just calling the API
- * because you want to find out the NAT's external IP address (e.g. for UI
- * display) then pass zero for protocol, internalPort, externalPort and ttl.
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceProtocol protocol, /* TCP and/or UDP */
- uint16_t internalPort, /* network byte order */
- uint16_t externalPort, /* network byte order */
- uint32_t ttl, /* time to live in seconds */
- DNSServiceNATPortMappingReply callBack,
- void *context /* may be NULL */
- );
-
-
-/*********************************************************************************************
- *
- * General Utility Functions
- *
- *********************************************************************************************/
-
-/* DNSServiceConstructFullName()
- *
- * Concatenate a three-part domain name (as returned by the above callbacks) into a
- * properly-escaped full domain name. Note that callbacks in the above functions ALREADY ESCAPE
- * strings where necessary.
- *
- * Parameters:
- *
- * fullName: A pointer to a buffer that where the resulting full domain name is to be written.
- * The buffer must be kDNSServiceMaxDomainName (1009) bytes in length to
- * accommodate the longest legal domain name without buffer overrun.
- *
- * service: The service name - any dots or backslashes must NOT be escaped.
- * May be NULL (to construct a PTR record name, e.g.
- * "_ftp._tcp.apple.com.").
- *
- * regtype: The service type followed by the protocol, separated by a dot
- * (e.g. "_ftp._tcp").
- *
- * domain: The domain name, e.g. "apple.com.". Literal dots or backslashes,
- * if any, must be escaped, e.g. "1st\. Floor.apple.com."
- *
- * return value: Returns kDNSServiceErr_NoError (0) on success, kDNSServiceErr_BadParam on error.
- *
- */
-
-DNSServiceErrorType DNSSD_API DNSServiceConstructFullName
- (
- char * const fullName,
- const char * const service, /* may be NULL */
- const char * const regtype,
- const char * const domain
- );
-
-
-/*********************************************************************************************
- *
- * TXT Record Construction Functions
- *
- *********************************************************************************************/
-
-/*
- * A typical calling sequence for TXT record construction is something like:
- *
- * Client allocates storage for TXTRecord data (e.g. declare buffer on the stack)
- * TXTRecordCreate();
- * TXTRecordSetValue();
- * TXTRecordSetValue();
- * TXTRecordSetValue();
- * ...
- * DNSServiceRegister( ... TXTRecordGetLength(), TXTRecordGetBytesPtr() ... );
- * TXTRecordDeallocate();
- * Explicitly deallocate storage for TXTRecord data (if not allocated on the stack)
- */
-
-
-/* TXTRecordCreate()
- *
- * Creates a new empty TXTRecordRef referencing the specified storage.
- *
- * If the buffer parameter is NULL, or the specified storage size is not
- * large enough to hold a key subsequently added using TXTRecordSetValue(),
- * then additional memory will be added as needed using malloc().
- *
- * On some platforms, when memory is low, malloc() may fail. In this
- * case, TXTRecordSetValue() will return kDNSServiceErr_NoMemory, and this
- * error condition will need to be handled as appropriate by the caller.
- *
- * You can avoid the need to handle this error condition if you ensure
- * that the storage you initially provide is large enough to hold all
- * the key/value pairs that are to be added to the record.
- * The caller can precompute the exact length required for all of the
- * key/value pairs to be added, or simply provide a fixed-sized buffer
- * known in advance to be large enough.
- * A no-value (key-only) key requires (1 + key length) bytes.
- * A key with empty value requires (1 + key length + 1) bytes.
- * A key with non-empty value requires (1 + key length + 1 + value length).
- * For most applications, DNS-SD TXT records are generally
- * less than 100 bytes, so in most cases a simple fixed-sized
- * 256-byte buffer will be more than sufficient.
- * Recommended size limits for DNS-SD TXT Records are discussed in
- * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
- *
- * Note: When passing parameters to and from these TXT record APIs,
- * the key name does not include the '=' character. The '=' character
- * is the separator between the key and value in the on-the-wire
- * packet format; it is not part of either the key or the value.
- *
- * txtRecord: A pointer to an uninitialized TXTRecordRef.
- *
- * bufferLen: The size of the storage provided in the "buffer" parameter.
- *
- * buffer: Optional caller-supplied storage used to hold the TXTRecord data.
- * This storage must remain valid for as long as
- * the TXTRecordRef.
- */
-
-void DNSSD_API TXTRecordCreate
- (
- TXTRecordRef *txtRecord,
- uint16_t bufferLen,
- void *buffer
- );
-
-
-/* TXTRecordDeallocate()
- *
- * Releases any resources allocated in the course of preparing a TXT Record
- * using TXTRecordCreate()/TXTRecordSetValue()/TXTRecordRemoveValue().
- * Ownership of the buffer provided in TXTRecordCreate() returns to the client.
- *
- * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
- *
- */
-
-void DNSSD_API TXTRecordDeallocate
- (
- TXTRecordRef *txtRecord
- );
-
-
-/* TXTRecordSetValue()
- *
- * Adds a key (optionally with value) to a TXTRecordRef. If the "key" already
- * exists in the TXTRecordRef, then the current value will be replaced with
- * the new value.
- * Keys may exist in four states with respect to a given TXT record:
- * - Absent (key does not appear at all)
- * - Present with no value ("key" appears alone)
- * - Present with empty value ("key=" appears in TXT record)
- * - Present with non-empty value ("key=value" appears in TXT record)
- * For more details refer to "Data Syntax for DNS-SD TXT Records" in
- * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
- *
- * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
- *
- * key: A null-terminated string which only contains printable ASCII
- * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
- * 9 characters or fewer (not counting the terminating null).
- *
- * valueSize: The size of the value.
- *
- * value: Any binary value. For values that represent
- * textual data, UTF-8 is STRONGLY recommended.
- * For values that represent textual data, valueSize
- * should NOT include the terminating null (if any)
- * at the end of the string.
- * If NULL, then "key" will be added with no value.
- * If non-NULL but valueSize is zero, then "key=" will be
- * added with empty value.
- *
- * return value: Returns kDNSServiceErr_NoError on success.
- * Returns kDNSServiceErr_Invalid if the "key" string contains
- * illegal characters.
- * Returns kDNSServiceErr_NoMemory if adding this key would
- * exceed the available storage.
- */
-
-DNSServiceErrorType DNSSD_API TXTRecordSetValue
- (
- TXTRecordRef *txtRecord,
- const char *key,
- uint8_t valueSize, /* may be zero */
- const void *value /* may be NULL */
- );
-
-
-/* TXTRecordRemoveValue()
- *
- * Removes a key from a TXTRecordRef. The "key" must be an
- * ASCII string which exists in the TXTRecordRef.
- *
- * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
- *
- * key: A key name which exists in the TXTRecordRef.
- *
- * return value: Returns kDNSServiceErr_NoError on success.
- * Returns kDNSServiceErr_NoSuchKey if the "key" does not
- * exist in the TXTRecordRef.
- */
-
-DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
- (
- TXTRecordRef *txtRecord,
- const char *key
- );
-
-
-/* TXTRecordGetLength()
- *
- * Allows you to determine the length of the raw bytes within a TXTRecordRef.
- *
- * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
- *
- * return value: Returns the size of the raw bytes inside a TXTRecordRef
- * which you can pass directly to DNSServiceRegister() or
- * to DNSServiceUpdateRecord().
- * Returns 0 if the TXTRecordRef is empty.
- */
-
-uint16_t DNSSD_API TXTRecordGetLength
- (
- const TXTRecordRef *txtRecord
- );
-
-
-/* TXTRecordGetBytesPtr()
- *
- * Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.
- *
- * txtRecord: A TXTRecordRef initialized by calling TXTRecordCreate().
- *
- * return value: Returns a pointer to the raw bytes inside the TXTRecordRef
- * which you can pass directly to DNSServiceRegister() or
- * to DNSServiceUpdateRecord().
- */
-
-const void * DNSSD_API TXTRecordGetBytesPtr
- (
- const TXTRecordRef *txtRecord
- );
-
-
-/*********************************************************************************************
- *
- * TXT Record Parsing Functions
- *
- *********************************************************************************************/
-
-/*
- * A typical calling sequence for TXT record parsing is something like:
- *
- * Receive TXT record data in DNSServiceResolve() callback
- * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
- * val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
- * val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
- * ...
- * memcpy(myval1, val1ptr, len1);
- * memcpy(myval2, val2ptr, len2);
- * ...
- * return;
- *
- * If you wish to retain the values after return from the DNSServiceResolve()
- * callback, then you need to copy the data to your own storage using memcpy()
- * or similar, as shown in the example above.
- *
- * If for some reason you need to parse a TXT record you built yourself
- * using the TXT record construction functions above, then you can do
- * that using TXTRecordGetLength and TXTRecordGetBytesPtr calls:
- * TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);
- *
- * Most applications only fetch keys they know about from a TXT record and
- * ignore the rest.
- * However, some debugging tools wish to fetch and display all keys.
- * To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.
- */
-
-/* TXTRecordContainsKey()
- *
- * Allows you to determine if a given TXT Record contains a specified key.
- *
- * txtLen: The size of the received TXT Record.
- *
- * txtRecord: Pointer to the received TXT Record bytes.
- *
- * key: A null-terminated ASCII string containing the key name.
- *
- * return value: Returns 1 if the TXT Record contains the specified key.
- * Otherwise, it returns 0.
- */
-
-int DNSSD_API TXTRecordContainsKey
- (
- uint16_t txtLen,
- const void *txtRecord,
- const char *key
- );
-
-
-/* TXTRecordGetValuePtr()
- *
- * Allows you to retrieve the value for a given key from a TXT Record.
- *
- * txtLen: The size of the received TXT Record
- *
- * txtRecord: Pointer to the received TXT Record bytes.
- *
- * key: A null-terminated ASCII string containing the key name.
- *
- * valueLen: On output, will be set to the size of the "value" data.
- *
- * return value: Returns NULL if the key does not exist in this TXT record,
- * or exists with no value (to differentiate between
- * these two cases use TXTRecordContainsKey()).
- * Returns pointer to location within TXT Record bytes
- * if the key exists with empty or non-empty value.
- * For empty value, valueLen will be zero.
- * For non-empty value, valueLen will be length of value data.
- */
-
-const void * DNSSD_API TXTRecordGetValuePtr
- (
- uint16_t txtLen,
- const void *txtRecord,
- const char *key,
- uint8_t *valueLen
- );
-
-
-/* TXTRecordGetCount()
- *
- * Returns the number of keys stored in the TXT Record. The count
- * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
- *
- * txtLen: The size of the received TXT Record.
- *
- * txtRecord: Pointer to the received TXT Record bytes.
- *
- * return value: Returns the total number of keys in the TXT Record.
- *
- */
-
-uint16_t DNSSD_API TXTRecordGetCount
- (
- uint16_t txtLen,
- const void *txtRecord
- );
-
-
-/* TXTRecordGetItemAtIndex()
- *
- * Allows you to retrieve a key name and value pointer, given an index into
- * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
- * It's also possible to iterate through keys in a TXT record by simply
- * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
- * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
- *
- * On return:
- * For keys with no value, *value is set to NULL and *valueLen is zero.
- * For keys with empty value, *value is non-NULL and *valueLen is zero.
- * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
- *
- * txtLen: The size of the received TXT Record.
- *
- * txtRecord: Pointer to the received TXT Record bytes.
- *
- * itemIndex: An index into the TXT Record.
- *
- * keyBufLen: The size of the string buffer being supplied.
- *
- * key: A string buffer used to store the key name.
- * On return, the buffer contains a null-terminated C string
- * giving the key name. DNS-SD TXT keys are usually
- * 9 characters or fewer. To hold the maximum possible
- * key name, the buffer should be 256 bytes long.
- *
- * valueLen: On output, will be set to the size of the "value" data.
- *
- * value: On output, *value is set to point to location within TXT
- * Record bytes that holds the value data.
- *
- * return value: Returns kDNSServiceErr_NoError on success.
- * Returns kDNSServiceErr_NoMemory if keyBufLen is too short.
- * Returns kDNSServiceErr_Invalid if index is greater than
- * TXTRecordGetCount()-1.
- */
-
-DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
- (
- uint16_t txtLen,
- const void *txtRecord,
- uint16_t itemIndex,
- uint16_t keyBufLen,
- char *key,
- uint8_t *valueLen,
- const void **value
- );
-
-#if _DNS_SD_LIBDISPATCH
-/*
-* DNSServiceSetDispatchQueue
-*
-* Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous
-* callbacks. It's the clients responsibility to ensure that the provided dispatch queue is running.
-*
-* A typical application that uses CFRunLoopRun or dispatch_main on its main thread will
-* usually schedule DNSServiceRefs on its main queue (which is always a serial queue)
-* using "DNSServiceSetDispatchQueue(sdref, dispatch_get_main_queue());"
-*
-* If there is any error during the processing of events, the application callback will
-* be called with an error code. For shared connections, each subordinate DNSServiceRef
-* will get its own error callback. Currently these error callbacks only happen
-* if the mDNSResponder daemon is manually terminated or crashes, and the error
-* code in this case is kDNSServiceErr_ServiceNotRunning. The application must call
-* DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code.
-* These error callbacks are rare and should not normally happen on customer machines,
-* but application code should be written defensively to handle such error callbacks
-* gracefully if they occur.
-*
-* After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult
-* on the same DNSServiceRef will result in undefined behavior and should be avoided.
-*
-* Once the application successfully schedules a DNSServiceRef on a serial dispatch queue using
-* DNSServiceSetDispatchQueue, it cannot remove the DNSServiceRef from the dispatch queue, or use
-* DNSServiceSetDispatchQueue a second time to schedule the DNSServiceRef onto a different serial dispatch
-* queue. Once scheduled onto a dispatch queue a DNSServiceRef will deliver events to that queue until
-* the application no longer requires that operation and terminates it using DNSServiceRefDeallocate.
-*
-* service: DNSServiceRef that was allocated and returned to the application, when the
-* application calls one of the DNSService API.
-*
-* queue: dispatch queue where the application callback will be scheduled
-*
-* return value: Returns kDNSServiceErr_NoError on success.
-* Returns kDNSServiceErr_NoMemory if it cannot create a dispatch source
-* Returns kDNSServiceErr_BadParam if the service param is invalid or the
-* queue param is invalid
-*/
-
-DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue
- (
- DNSServiceRef service,
- dispatch_queue_t queue
- );
-#endif //_DNS_SD_LIBDISPATCH
-
-#ifdef __APPLE_API_PRIVATE
-
-#define kDNSServiceCompPrivateDNS "PrivateDNS"
-#define kDNSServiceCompMulticastDNS "MulticastDNS"
-
-#endif //__APPLE_API_PRIVATE
-
-/* Some C compiler cleverness. We can make the compiler check certain things for us,
- * and report errors at compile-time if anything is wrong. The usual way to do this would
- * be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but
- * then you don't find out what's wrong until you run the software. This way, if the assertion
- * condition is false, the array size is negative, and the complier complains immediately.
- */
-
-struct CompileTimeAssertionChecks_DNS_SD
- {
- char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1];
- };
-
-#endif /* _DNS_SD_H */
diff --git a/src/libs/zeroconf/dns_sd_types.h b/src/libs/zeroconf/dns_sd_types.h
deleted file mode 100644
index 58a68f132a..0000000000
--- a/src/libs/zeroconf/dns_sd_types.h
+++ /dev/null
@@ -1,1154 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-/*! @header DNS Service Discovery
- *
- * @discussion This section describes the functions, callbacks, and data structures
- * that make up the DNS Service Discovery API.
- *
- * The DNS Service Discovery API is part of Bonjour, Apple's implementation
- * of zero-configuration networking (ZEROCONF).
- *
- * Bonjour allows you to register a network service, such as a
- * printer or file server, so that it can be found by name or browsed
- * for by service type and domain. Using Bonjour, applications can
- * discover what services are available on the network, along with
- * all the information -- such as name, IP address, and port --
- * necessary to access a particular service.
- *
- * In effect, Bonjour combines the functions of a local DNS server and
- * AppleTalk. Bonjour allows applications to provide user-friendly printer
- * and server browsing, among other things, over standard IP networks.
- * This behavior is a result of combining protocols such as multicast and
- * DNS to add new functionality to the network (such as multicast DNS).
- *
- * Bonjour gives applications easy access to services over local IP
- * networks without requiring the service or the application to support
- * an AppleTalk or a Netbeui stack, and without requiring a DNS server
- * for the local network.
- */
-
-
-/* _DNS_SD_H contains the mDNSResponder version number for this header file, formatted as follows:
- * Major part of the build number * 10000 +
- * minor part of the build number * 100
- * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as
- * version 1080400. This allows C code to do simple greater-than and less-than comparisons:
- * e.g. an application that requires the DNSServiceGetProperty() call (new in mDNSResponder-126) can check:
- *
- * #if _DNS_SD_H+0 >= 1260000
- * ... some C code that calls DNSServiceGetProperty() ...
- * #endif
- *
- * The version defined in this header file symbol allows for compile-time
- * checking, so that C code building with earlier versions of the header file
- * can avoid compile errors trying to use functions that aren't even defined
- * in those earlier versions. Similar checks may also be performed at run-time:
- * => weak linking -- to avoid link failures if run with an earlier
- * version of the library that's missing some desired symbol, or
- * => DNSServiceGetProperty(DaemonVersion) -- to verify whether the running daemon
- * ("system service" on Windows) meets some required minimum functionality level.
- */
-
-#ifndef _DNS_SD_TYPES_H
-#define _DNS_SD_TYPES_H 3200500
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Set to 1 if libdispatch is supported
- * Note: May also be set by project and/or Makefile
- */
-#ifndef _DNS_SD_LIBDISPATCH
-#define _DNS_SD_LIBDISPATCH 0
-#endif /* ndef _DNS_SD_LIBDISPATCH */
-
-/* standard calling convention under Win32 is __stdcall */
-/* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */
-/* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */
-#if defined(_WIN32) && !defined(EFI32) && !defined(EFI64)
-#define DNSSD_API __stdcall
-#else
-#define DNSSD_API
-#endif
-
-/* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */
-#if defined(__FreeBSD__) && (__FreeBSD__ < 5)
-#include <sys/types.h>
-
-/* Likewise, on Sun, standard integer types are in sys/types.h */
-#elif defined(__sun__)
-#include <sys/types.h>
-
-/* EFI does not have stdint.h, or anything else equivalent */
-#elif defined(EFI32) || defined(EFI64) || defined(EFIX64)
-#include "Tiano.h"
-#if !defined(_STDINT_H_)
-typedef UINT8 uint8_t;
-typedef INT8 int8_t;
-typedef UINT16 uint16_t;
-typedef INT16 int16_t;
-typedef UINT32 uint32_t;
-typedef INT32 int32_t;
-#endif
-/* Windows has its own differences */
-#elif defined(_WIN32) && !defined(__MINGW32__)
-#include <windows.h>
-#define _UNUSED
-#ifndef _MSL_STDINT_H
-typedef UINT8 uint8_t;
-typedef INT8 int8_t;
-typedef UINT16 uint16_t;
-typedef INT16 int16_t;
-typedef UINT32 uint32_t;
-typedef INT32 int32_t;
-#endif
-
-/* All other Posix platforms use stdint.h */
-#else
-#include <stdint.h>
-#endif
-
-#if _DNS_SD_LIBDISPATCH
-#include <dispatch/dispatch.h>
-#endif
-
-/* DNSServiceRef, DNSRecordRef
- *
- * Opaque internal data types.
- * Note: client is responsible for serializing access to these structures if
- * they are shared between concurrent threads.
- */
-
-typedef struct _DNSServiceRef_t *DNSServiceRef;
-typedef struct _DNSRecordRef_t *DNSRecordRef;
-
-struct sockaddr;
-
-/*! @enum General flags
- * Most DNS-SD API functions and callbacks include a DNSServiceFlags parameter.
- * As a general rule, any given bit in the 32-bit flags field has a specific fixed meaning,
- * regardless of the function or callback being used. For any given function or callback,
- * typically only a subset of the possible flags are meaningful, and all others should be zero.
- * The discussion section for each API call describes which flags are valid for that call
- * and callback. In some cases, for a particular call, it may be that no flags are currently
- * defined, in which case the DNSServiceFlags parameter exists purely to allow future expansion.
- * In all cases, developers should expect that in future releases, it is possible that new flag
- * values will be defined, and write code with this in mind. For example, code that tests
- * if (flags == kDNSServiceFlagsAdd) ...
- * will fail if, in a future release, another bit in the 32-bit flags field is also set.
- * The reliable way to test whether a particular bit is set is not with an equality test,
- * but with a bitwise mask:
- * if (flags & kDNSServiceFlagsAdd) ...
- */
-enum
- {
- kDNSServiceFlagsMoreComing = 0x1,
- /* MoreComing indicates to a callback that at least one more result is
- * queued and will be delivered following immediately after this one.
- * When the MoreComing flag is set, applications should not immediately
- * update their UI, because this can result in a great deal of ugly flickering
- * on the screen, and can waste a great deal of CPU time repeatedly updating
- * the screen with content that is then immediately erased, over and over.
- * Applications should wait until until MoreComing is not set, and then
- * update their UI when no more changes are imminent.
- * When MoreComing is not set, that doesn't mean there will be no more
- * answers EVER, just that there are no more answers immediately
- * available right now at this instant. If more answers become available
- * in the future they will be delivered as usual.
- */
-
- kDNSServiceFlagsAdd = 0x2,
- kDNSServiceFlagsDefault = 0x4,
- /* Flags for domain enumeration and browse/query reply callbacks.
- * "Default" applies only to enumeration and is only valid in
- * conjunction with "Add". An enumeration callback with the "Add"
- * flag NOT set indicates a "Remove", i.e. the domain is no longer
- * valid.
- */
-
- kDNSServiceFlagsNoAutoRename = 0x8,
- /* Flag for specifying renaming behavior on name conflict when registering
- * non-shared records. By default, name conflicts are automatically handled
- * by renaming the service. NoAutoRename overrides this behavior - with this
- * flag set, name conflicts will result in a callback. The NoAutorename flag
- * is only valid if a name is explicitly specified when registering a service
- * (i.e. the default name is not used.)
- */
-
- kDNSServiceFlagsShared = 0x10,
- kDNSServiceFlagsUnique = 0x20,
- /* Flag for registering individual records on a connected
- * DNSServiceRef. Shared indicates that there may be multiple records
- * with this name on the network (e.g. PTR records). Unique indicates that the
- * record's name is to be unique on the network (e.g. SRV records).
- */
-
- kDNSServiceFlagsBrowseDomains = 0x40,
- kDNSServiceFlagsRegistrationDomains = 0x80,
- /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomains.
- * BrowseDomains enumerates domains recommended for browsing, RegistrationDomains
- * enumerates domains recommended for registration.
- */
-
- kDNSServiceFlagsLongLivedQuery = 0x100,
- /* Flag for creating a long-lived unicast query for the DNSServiceQueryRecord call. */
-
- kDNSServiceFlagsAllowRemoteQuery = 0x200,
- /* Flag for creating a record for which we will answer remote queries
- * (queries from hosts more than one hop away; hosts not directly connected to the local link).
- */
-
- kDNSServiceFlagsForceMulticast = 0x400,
- /* Flag for signifying that a query or registration should be performed exclusively via multicast
- * DNS, even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
- */
-
- kDNSServiceFlagsForce = 0x800,
- /* Flag for signifying a "stronger" variant of an operation.
- * Currently defined only for DNSServiceReconfirmRecord(), where it forces a record to
- * be removed from the cache immediately, instead of querying for a few seconds before
- * concluding that the record is no longer valid and then removing it. This flag should
- * be used with caution because if a service browsing PTR record is indeed still valid
- * on the network, forcing its removal will result in a user-interface flap -- the
- * discovered service instance will disappear, and then re-appear moments later.
- */
-
- kDNSServiceFlagsReturnIntermediates = 0x1000,
- /* Flag for returning intermediate results.
- * For example, if a query results in an authoritative NXDomain (name does not exist)
- * then that result is returned to the client. However the query is not implicitly
- * cancelled -- it remains active and if the answer subsequently changes
- * (e.g. because a VPN tunnel is subsequently established) then that positive
- * result will still be returned to the client.
- * Similarly, if a query results in a CNAME record, then in addition to following
- * the CNAME referral, the intermediate CNAME result is also returned to the client.
- * When this flag is not set, NXDomain errors are not returned, and CNAME records
- * are followed silently without informing the client of the intermediate steps.
- * (In earlier builds this flag was briefly calledkDNSServiceFlagsReturnCNAME)
- */
-
- kDNSServiceFlagsNonBrowsable = 0x2000,
- /* A service registered with the NonBrowsable flag set can be resolved using
- * DNSServiceResolve(), but will not be discoverable using DNSServiceBrowse().
- * This is for cases where the name is actually a GUID; it is found by other means;
- * there is no end-user benefit to browsing to find a long list of opaque GUIDs.
- * Using the NonBrowsable flag creates SRV+TXT without the cost of also advertising
- * an associated PTR record.
- */
-
- kDNSServiceFlagsShareConnection = 0x4000,
- /* For efficiency, clients that perform many concurrent operations may want to use a
- * single Unix Domain Socket connection with the background daemon, instead of having a
- * separate connection for each independent operation. To use this mode, clients first
- * call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef.
- * For each subsequent operation that is to share that same connection, the client copies
- * the MainRef, and then passes the address of that copy, setting the ShareConnection flag
- * to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef;
- * it's a copy of an existing DNSServiceRef whose connection information should be reused.
- *
- * For example:
- *
- * DNSServiceErrorType error;
- * DNSServiceRef MainRef;
- * error = DNSServiceCreateConnection(&MainRef);
- * if (error) ...
- * DNSServiceRef BrowseRef = MainRef; // Important: COPY the primary DNSServiceRef first...
- * error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, ...); // then use the copy
- * if (error) ...
- * ...
- * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation
- * DNSServiceRefDeallocate(MainRef); // Terminate the shared connection
- *
- * Notes:
- *
- * 1. Collective kDNSServiceFlagsMoreComing flag
- * When callbacks are invoked using a shared DNSServiceRef, the
- * kDNSServiceFlagsMoreComing flag applies collectively to *all* active
- * operations sharing the same parent DNSServiceRef. If the MoreComing flag is
- * set it means that there are more results queued on this parent DNSServiceRef,
- * but not necessarily more results for this particular callback function.
- * The implication of this for client programmers is that when a callback
- * is invoked with the MoreComing flag set, the code should update its
- * internal data structures with the new result, and set a variable indicating
- * that its UI needs to be updated. Then, later when a callback is eventually
- * invoked with the MoreComing flag not set, the code should update *all*
- * stale UI elements related to that shared parent DNSServiceRef that need
- * updating, not just the UI elements related to the particular callback
- * that happened to be the last one to be invoked.
- *
- * 2. Canceling operations and kDNSServiceFlagsMoreComing
- * Whenever you cancel any operation for which you had deferred UI updates
- * waiting because of a kDNSServiceFlagsMoreComing flag, you should perform
- * those deferred UI updates. This is because, after cancelling the operation,
- * you can no longer wait for a callback *without* MoreComing set, to tell
- * you do perform your deferred UI updates (the operation has been canceled,
- * so there will be no more callbacks). An implication of the collective
- * kDNSServiceFlagsMoreComing flag for shared connections is that this
- * guideline applies more broadly -- any time you cancel an operation on
- * a shared connection, you should perform all deferred UI updates for all
- * operations sharing that connection. This is because the MoreComing flag
- * might have been referring to events coming for the operation you canceled,
- * which will now not be coming because the operation has been canceled.
- *
- * 3. Only share DNSServiceRef's created with DNSServiceCreateConnection
- * Calling DNSServiceCreateConnection(&ref) creates a special shareable DNSServiceRef.
- * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve()
- * cannot be shared by copying them and using kDNSServiceFlagsShareConnection.
- *
- * 4. Don't Double-Deallocate
- * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates
- * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef
- * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref))
- * automatically terminates the shared connection and all operations that were still using it.
- * After doing this, DO NOT then attempt to deallocate any remaining subordinate DNSServiceRef's.
- * The memory used by those subordinate DNSServiceRef's has already been freed, so any attempt
- * to do a DNSServiceRefDeallocate (or any other operation) on them will result in accesses
- * to freed memory, leading to crashes or other equally undesirable results.
- *
- * 5. Thread Safety
- * The dns_sd.h API does not presuppose any particular threading model, and consequently
- * does no locking of its own (which would require linking some specific threading library).
- * If client code calls API routines on the same DNSServiceRef concurrently
- * from multiple threads, it is the client's responsibility to use a mutext
- * lock or take similar appropriate precautions to serialize those calls.
- */
-
- kDNSServiceFlagsSuppressUnusable = 0x8000,
- /*
- * This flag is meaningful only in DNSServiceQueryRecord which suppresses unusable queries on the
- * wire. If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name)
- * but this host has no routable IPv6 address, then the call will not try to look up IPv6 addresses
- * for "hostname", since any addresses it found would be unlikely to be of any use anyway. Similarly,
- * if this host has no routable IPv4 address, the call will not try to look up IPv4 addresses for
- * "hostname".
- */
-
- kDNSServiceFlagsTimeout = 0x10000,
- /*
- * When kDNServiceFlagsTimeout is passed to DNSServiceQueryRecord or DNSServiceGetAddrInfo, the query is
- * stopped after a certain number of seconds have elapsed. The time at which the query will be stopped
- * is determined by the system and cannot be configured by the user. The query will be stopped irrespective
- * of whether a response was given earlier or not. When the query is stopped, the callback will be called
- * with an error code of kDNSServiceErr_Timeout and a NULL sockaddr will be returned for DNSServiceGetAddrInfo
- * and zero length rdata will be returned for DNSServiceQueryRecord.
- */
-
- kDNSServiceFlagsIncludeP2P = 0x20000,
- /*
- * Include P2P interfaces when kDNSServiceInterfaceIndexAny is specified.
- * By default, specifying kDNSServiceInterfaceIndexAny does not include P2P interfaces.
- */
- kDNSServiceFlagsWakeOnResolve = 0x40000
- /*
- * This flag is meaningful only in DNSServiceResolve. When set, it tries to send a magic packet
- * to wake up the client.
- */
- };
-
-/* Possible protocols for DNSServiceNATPortMappingCreate(). */
-enum
- {
- kDNSServiceProtocol_IPv4 = 0x01,
- kDNSServiceProtocol_IPv6 = 0x02,
- /* 0x04 and 0x08 reserved for future internetwork protocols */
-
- kDNSServiceProtocol_UDP = 0x10,
- kDNSServiceProtocol_TCP = 0x20
- /* 0x40 and 0x80 reserved for future transport protocols, e.g. SCTP [RFC 2960]
- * or DCCP [RFC 4340]. If future NAT gateways are created that support port
- * mappings for these protocols, new constants will be defined here.
- */
- };
-
-/*
- * The values for DNS Classes and Types are listed in RFC 1035, and are available
- * on every OS in its DNS header file. Unfortunately every OS does not have the
- * same header file containing DNS Class and Type constants, and the names of
- * the constants are not consistent. For example, BIND 8 uses "T_A",
- * BIND 9 uses "ns_t_a", Windows uses "DNS_TYPE_A", etc.
- * For this reason, these constants are also listed here, so that code using
- * the DNS-SD programming APIs can use these constants, so that the same code
- * can compile on all our supported platforms.
- */
-
-enum
- {
- kDNSServiceClass_IN = 1 /* Internet */
- };
-
-enum
- {
- kDNSServiceType_A = 1, /* Host address. */
- kDNSServiceType_NS = 2, /* Authoritative server. */
- kDNSServiceType_MD = 3, /* Mail destination. */
- kDNSServiceType_MF = 4, /* Mail forwarder. */
- kDNSServiceType_CNAME = 5, /* Canonical name. */
- kDNSServiceType_SOA = 6, /* Start of authority zone. */
- kDNSServiceType_MB = 7, /* Mailbox domain name. */
- kDNSServiceType_MG = 8, /* Mail group member. */
- kDNSServiceType_MR = 9, /* Mail rename name. */
- kDNSServiceType_NULL = 10, /* Null resource record. */
- kDNSServiceType_WKS = 11, /* Well known service. */
- kDNSServiceType_PTR = 12, /* Domain name pointer. */
- kDNSServiceType_HINFO = 13, /* Host information. */
- kDNSServiceType_MINFO = 14, /* Mailbox information. */
- kDNSServiceType_MX = 15, /* Mail routing information. */
- kDNSServiceType_TXT = 16, /* One or more text strings (NOT "zero or more..."). */
- kDNSServiceType_RP = 17, /* Responsible person. */
- kDNSServiceType_AFSDB = 18, /* AFS cell database. */
- kDNSServiceType_X25 = 19, /* X_25 calling address. */
- kDNSServiceType_ISDN = 20, /* ISDN calling address. */
- kDNSServiceType_RT = 21, /* Router. */
- kDNSServiceType_NSAP = 22, /* NSAP address. */
- kDNSServiceType_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */
- kDNSServiceType_SIG = 24, /* Security signature. */
- kDNSServiceType_KEY = 25, /* Security key. */
- kDNSServiceType_PX = 26, /* X.400 mail mapping. */
- kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */
- kDNSServiceType_AAAA = 28, /* IPv6 Address. */
- kDNSServiceType_LOC = 29, /* Location Information. */
- kDNSServiceType_NXT = 30, /* Next domain (security). */
- kDNSServiceType_EID = 31, /* Endpoint identifier. */
- kDNSServiceType_NIMLOC = 32, /* Nimrod Locator. */
- kDNSServiceType_SRV = 33, /* Server Selection. */
- kDNSServiceType_ATMA = 34, /* ATM Address */
- kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */
- kDNSServiceType_KX = 36, /* Key Exchange */
- kDNSServiceType_CERT = 37, /* Certification record */
- kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */
- kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */
- kDNSServiceType_SINK = 40, /* Kitchen sink (experimental) */
- kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */
- kDNSServiceType_APL = 42, /* Address Prefix List */
- kDNSServiceType_DS = 43, /* Delegation Signer */
- kDNSServiceType_SSHFP = 44, /* SSH Key Fingerprint */
- kDNSServiceType_IPSECKEY = 45, /* IPSECKEY */
- kDNSServiceType_RRSIG = 46, /* RRSIG */
- kDNSServiceType_NSEC = 47, /* Denial of Existence */
- kDNSServiceType_DNSKEY = 48, /* DNSKEY */
- kDNSServiceType_DHCID = 49, /* DHCP Client Identifier */
- kDNSServiceType_NSEC3 = 50, /* Hashed Authenticated Denial of Existence */
- kDNSServiceType_NSEC3PARAM = 51, /* Hashed Authenticated Denial of Existence */
-
- kDNSServiceType_HIP = 55, /* Host Identity Protocol */
-
- kDNSServiceType_SPF = 99, /* Sender Policy Framework for E-Mail */
- kDNSServiceType_UINFO = 100, /* IANA-Reserved */
- kDNSServiceType_UID = 101, /* IANA-Reserved */
- kDNSServiceType_GID = 102, /* IANA-Reserved */
- kDNSServiceType_UNSPEC = 103, /* IANA-Reserved */
-
- kDNSServiceType_TKEY = 249, /* Transaction key */
- kDNSServiceType_TSIG = 250, /* Transaction signature. */
- kDNSServiceType_IXFR = 251, /* Incremental zone transfer. */
- kDNSServiceType_AXFR = 252, /* Transfer zone of authority. */
- kDNSServiceType_MAILB = 253, /* Transfer mailbox records. */
- kDNSServiceType_MAILA = 254, /* Transfer mail agent records. */
- kDNSServiceType_ANY = 255 /* Wildcard match. */
- };
-
-/* possible error code values */
-enum
- {
- kDNSServiceErr_NoError = 0,
- kDNSServiceErr_Unknown = -65537, /* 0xFFFE FFFF */
- kDNSServiceErr_NoSuchName = -65538,
- kDNSServiceErr_NoMemory = -65539,
- kDNSServiceErr_BadParam = -65540,
- kDNSServiceErr_BadReference = -65541,
- kDNSServiceErr_BadState = -65542,
- kDNSServiceErr_BadFlags = -65543,
- kDNSServiceErr_Unsupported = -65544,
- kDNSServiceErr_NotInitialized = -65545,
- kDNSServiceErr_AlreadyRegistered = -65547,
- kDNSServiceErr_NameConflict = -65548,
- kDNSServiceErr_Invalid = -65549,
- kDNSServiceErr_Firewall = -65550,
- kDNSServiceErr_Incompatible = -65551, /* client library incompatible with daemon */
- kDNSServiceErr_BadInterfaceIndex = -65552,
- kDNSServiceErr_Refused = -65553,
- kDNSServiceErr_NoSuchRecord = -65554,
- kDNSServiceErr_NoAuth = -65555,
- kDNSServiceErr_NoSuchKey = -65556,
- kDNSServiceErr_NATTraversal = -65557,
- kDNSServiceErr_DoubleNAT = -65558,
- kDNSServiceErr_BadTime = -65559, /* Codes up to here existed in Tiger */
- kDNSServiceErr_BadSig = -65560,
- kDNSServiceErr_BadKey = -65561,
- kDNSServiceErr_Transient = -65562,
- kDNSServiceErr_ServiceNotRunning = -65563, /* Background daemon not running */
- kDNSServiceErr_NATPortMappingUnsupported = -65564, /* NAT doesn't support NAT-PMP or UPnP */
- kDNSServiceErr_NATPortMappingDisabled = -65565, /* NAT supports NAT-PMP or UPnP but it's disabled by the administrator */
- kDNSServiceErr_NoRouter = -65566, /* No router currently configured (probably no network connectivity) */
- kDNSServiceErr_PollingMode = -65567,
- kDNSServiceErr_Timeout = -65568
-
- /* mDNS Error codes are in the range
- * FFFE FF00 (-65792) to FFFE FFFF (-65537) */
- };
-
-/* Maximum length, in bytes, of a service name represented as a */
-/* literal C-String, including the terminating NULL at the end. */
-
-#define kDNSServiceMaxServiceName 64
-
-/* Maximum length, in bytes, of a domain name represented as an *escaped* C-String */
-/* including the final trailing dot, and the C-String terminating NULL at the end. */
-
-#define kDNSServiceMaxDomainName 1009
-
-/*
- * Notes on DNS Name Escaping
- * -- or --
- * "Why is kDNSServiceMaxDomainName 1009, when the maximum legal domain name is 256 bytes?"
- *
- * All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below,
- * the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules:
- *
- * '\\' represents a single literal '\' in the name
- * '\.' represents a single literal '.' in the name
- * '\ddd', where ddd is a three-digit decimal value from 000 to 255,
- * represents a single literal byte with that value.
- * A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
- *
- * The exceptions, that do not use escaping, are the routines where the full
- * DNS name of a resource is broken, for convenience, into servicename/regtype/domain.
- * In these routines, the "servicename" is NOT escaped. It does not need to be, since
- * it is, by definition, just a single literal string. Any characters in that string
- * represent exactly what they are. The "regtype" portion is, technically speaking,
- * escaped, but since legal regtypes are only allowed to contain letters, digits,
- * and hyphens, there is nothing to escape, so the issue is moot. The "domain"
- * portion is also escaped, though most domains in use on the public Internet
- * today, like regtypes, don't contain any characters that need to be escaped.
- * As DNS-SD becomes more popular, rich-text domains for service discovery will
- * become common, so software should be written to cope with domains with escaping.
- *
- * The servicename may be up to 63 bytes of UTF-8 text (not counting the C-String
- * terminating NULL at the end). The regtype is of the form _service._tcp or
- * _service._udp, where the "service" part is 1-15 characters, which may be
- * letters, digits, or hyphens. The domain part of the three-part name may be
- * any legal domain, providing that the resulting servicename+regtype+domain
- * name does not exceed 256 bytes.
- *
- * For most software, these issues are transparent. When browsing, the discovered
- * servicenames should simply be displayed as-is. When resolving, the discovered
- * servicename/regtype/domain are simply passed unchanged to DNSServiceResolve().
- * When a DNSServiceResolve() succeeds, the returned fullname is already in
- * the correct format to pass to standard system DNS APIs such as res_query().
- * For converting from servicename/regtype/domain to a single properly-escaped
- * full DNS name, the helper function DNSServiceConstructFullName() is provided.
- *
- * The following (highly contrived) example illustrates the escaping process.
- * Suppose you have an service called "Dr. Smith\Dr. Johnson", of type "_ftp._tcp"
- * in subdomain "4th. Floor" of subdomain "Building 2" of domain "apple.com."
- * The full (escaped) DNS name of this service's SRV record would be:
- * Dr\.\032Smith\\Dr\.\032Johnson._ftp._tcp.4th\.\032Floor.Building\0322.apple.com.
- */
-
-
-/*
- * Constants for specifying an interface index
- *
- * Specific interface indexes are identified via a 32-bit unsigned integer returned
- * by the if_nametoindex() family of calls.
- *
- * If the client passes 0 for interface index, that means "do the right thing",
- * which (at present) means, "if the name is in an mDNS local multicast domain
- * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
- * on all applicable interfaces, otherwise send via unicast to the appropriate
- * DNS server." Normally, most clients will use 0 for interface index to
- * automatically get the default sensible behaviour.
- *
- * If the client passes a positive interface index, then for multicast names that
- * indicates to do the operation only on that one interface. For unicast names the
- * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
- *
- * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
- * a service, then that service will be found *only* by other local clients
- * on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
- * or kDNSServiceInterfaceIndexAny.
- * If a client has a 'private' service, accessible only to other processes
- * running on the same machine, this allows the client to advertise that service
- * in a way such that it does not inadvertently appear in service lists on
- * all the other machines on the network.
- *
- * If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
- * then it will find *all* records registered on that same local machine.
- * Clients explicitly wishing to discover *only* LocalOnly services can
- * accomplish this by inspecting the interfaceIndex of each service reported
- * to their DNSServiceBrowseReply() callback function, and discarding those
- * where the interface index is not kDNSServiceInterfaceIndexLocalOnly.
- *
- * kDNSServiceInterfaceIndexP2P is meaningful only in Browse, QueryRecord,
- * and Resolve operations. It should not be used in other DNSService APIs.
- *
- * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceBrowse or
- * DNSServiceQueryRecord, it restricts the operation to P2P.
- *
- * - If kDNSServiceInterfaceIndexP2P is passed to DNSServiceResolve, it is
- * mapped internally to kDNSServiceInterfaceIndexAny, because resolving
- * a P2P service may create and/or enable an interface whose index is not
- * known a priori. The resolve callback will indicate the index of the
- * interface via which the service can be accessed.
- *
- * If applications pass kDNSServiceInterfaceIndexAny to DNSServiceBrowse
- * or DNSServiceQueryRecord, they must set the kDNSServiceFlagsIncludeP2P flag
- * to include P2P. In this case, if a service instance or the record being queried
- * is found over P2P, the resulting ADD event will indicate kDNSServiceInterfaceIndexP2P
- * as the interface index.
- */
-
-#define kDNSServiceInterfaceIndexAny 0
-#define kDNSServiceInterfaceIndexLocalOnly ((uint32_t)-1)
-#define kDNSServiceInterfaceIndexUnicast ((uint32_t)-2)
-#define kDNSServiceInterfaceIndexP2P ((uint32_t)-3)
-
-typedef uint32_t DNSServiceFlags;
-typedef uint32_t DNSServiceProtocol;
-typedef int32_t DNSServiceErrorType;
-
-/*
- * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point
- * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t).
- *
- * On return, the 32-bit unsigned integer contains the version number, formatted as follows:
- * Major part of the build number * 10000 +
- * minor part of the build number * 100
- *
- * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as
- * version 1080400. This allows applications to do simple greater-than and less-than comparisons:
- * e.g. an application that requires at least mDNSResponder-108.4 can check:
- *
- * if (version >= 1080400) ...
- *
- * Example usage:
- *
- * uint32_t version;
- * uint32_t size = sizeof(version);
- * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
- * if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100);
- */
-
-#define kDNSServiceProperty_DaemonVersion "DaemonVersion"
-
-
-/* DNSServiceEnumerateDomains()
- *
- * Asynchronously enumerate domains available for browsing and registration.
- *
- * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
- * are to be found.
- *
- * Note that the names returned are (like all of DNS-SD) UTF-8 strings,
- * and are escaped using standard DNS escaping rules.
- * (See "Notes on DNS Name Escaping" earlier in this file for more details.)
- * A graphical browser displaying a hierarchical tree-structured view should cut
- * the names at the bare dots to yield individual labels, then de-escape each
- * label according to the escaping rules, and then display the resulting UTF-8 text.
- *
- * DNSServiceDomainEnumReply Callback Parameters:
- *
- * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
- *
- * flags: Possible values are:
- * kDNSServiceFlagsMoreComing
- * kDNSServiceFlagsAdd
- * kDNSServiceFlagsDefault
- *
- * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
- * interface is determined via the if_nametoindex() family of calls.)
- *
- * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates
- * the failure that occurred (other parameters are undefined if errorCode is nonzero).
- *
- * replyDomain: The name of the domain.
- *
- * context: The context pointer passed to DNSServiceEnumerateDomains.
- *
- */
-
-typedef void (DNSSD_API *DNSServiceDomainEnumReply)
- (
- DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *replyDomain,
- void *context
- );
-
-
-/* Register a service that is discovered via Browse() and Resolve() calls.
- *
- * DNSServiceRegisterReply() Callback Parameters:
- *
- * sdRef: The DNSServiceRef initialized by DNSServiceRegister().
- *
- * flags: When a name is successfully registered, the callback will be
- * invoked with the kDNSServiceFlagsAdd flag set. When Wide-Area
- * DNS-SD is in use, it is possible for a single service to get
- * more than one success callback (e.g. one in the "local" multicast
- * DNS domain, and another in a wide-area unicast DNS domain).
- * If a successfully-registered name later suffers a name conflict
- * or similar problem and has to be deregistered, the callback will
- * be invoked with the kDNSServiceFlagsAdd flag not set. The callback
- * is *not* invoked in the case where the caller explicitly terminates
- * the service registration by calling DNSServiceRefDeallocate(ref);
- *
- * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
- * indicate the failure that occurred (including name conflicts,
- * if the kDNSServiceFlagsNoAutoRename flag was used when registering.)
- * Other parameters are undefined if errorCode is nonzero.
- *
- * name: The service name registered (if the application did not specify a name in
- * DNSServiceRegister(), this indicates what name was automatically chosen).
- *
- * regtype: The type of service registered, as it was passed to the callout.
- *
- * domain: The domain on which the service was registered (if the application did not
- * specify a domain in DNSServiceRegister(), this indicates the default domain
- * on which the service was registered).
- *
- * context: The context pointer that was passed to the callout.
- *
- */
-
-typedef void (DNSSD_API *DNSServiceRegisterReply)
- (
- DNSServiceRef sdRef,
- DNSServiceFlags flags,
- DNSServiceErrorType errorCode,
- const char *name,
- const char *regtype,
- const char *domain,
- void *context
- );
-
-
-/* Browse for instances of a service.
- *
- * DNSServiceBrowseReply() Parameters:
- *
- * sdRef: The DNSServiceRef initialized by DNSServiceBrowse().
- *
- * flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
- * See flag definitions for details.
- *
- * interfaceIndex: The interface on which the service is advertised. This index should
- * be passed to DNSServiceResolve() when resolving the service.
- *
- * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
- * indicate the failure that occurred. Other parameters are undefined if
- * the errorCode is nonzero.
- *
- * serviceName: The discovered service name. This name should be displayed to the user,
- * and stored for subsequent use in the DNSServiceResolve() call.
- *
- * regtype: The service type, which is usually (but not always) the same as was passed
- * to DNSServiceBrowse(). One case where the discovered service type may
- * not be the same as the requested service type is when using subtypes:
- * The client may want to browse for only those ftp servers that allow
- * anonymous connections. The client will pass the string "_ftp._tcp,_anon"
- * to DNSServiceBrowse(), but the type of the service that's discovered
- * is simply "_ftp._tcp". The regtype for each discovered service instance
- * should be stored along with the name, so that it can be passed to
- * DNSServiceResolve() when the service is later resolved.
- *
- * domain: The domain of the discovered service instance. This may or may not be the
- * same as the domain that was passed to DNSServiceBrowse(). The domain for each
- * discovered service instance should be stored along with the name, so that
- * it can be passed to DNSServiceResolve() when the service is later resolved.
- *
- * context: The context pointer that was passed to the callout.
- *
- */
-
-typedef void (DNSSD_API *DNSServiceBrowseReply)
- (
- DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *serviceName,
- const char *regtype,
- const char *replyDomain,
- void *context
- );
-
-
-
-/* DNSServiceResolve()
- *
- * Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and
- * txt record.
- *
- * Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring - use
- * DNSServiceQueryRecord() instead, as it is more efficient for this task.
- *
- * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
- * DNSServiceRefDeallocate().
- *
- * Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record
- * and a single TXT record. To resolve non-standard services with multiple SRV or TXT records,
- * DNSServiceQueryRecord() should be used.
- *
- * DNSServiceResolveReply Callback Parameters:
- *
- * sdRef: The DNSServiceRef initialized by DNSServiceResolve().
- *
- * flags: Possible values: kDNSServiceFlagsMoreComing
- *
- * interfaceIndex: The interface on which the service was resolved.
- *
- * errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will
- * indicate the failure that occurred. Other parameters are undefined if
- * the errorCode is nonzero.
- *
- * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
- * (This name is escaped following standard DNS rules, making it suitable for
- * passing to standard system DNS APIs such as res_query(), or to the
- * special-purpose functions included in this API that take fullname parameters.
- * See "Notes on DNS Name Escaping" earlier in this file for more details.)
- *
- * hosttarget: The target hostname of the machine providing the service. This name can
- * be passed to functions like gethostbyname() to identify the host's IP address.
- *
- * port: The port, in network byte order, on which connections are accepted for this service.
- *
- * txtLen: The length of the txt record, in bytes.
- *
- * txtRecord: The service's primary txt record, in standard txt record format.
- *
- * context: The context pointer that was passed to the callout.
- *
- * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *"
- * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127.
- * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings.
- * These should be fixed by updating your own callback function definition to match the corrected
- * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent
- * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250
- * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes.
- * If you need to maintain portable code that will compile cleanly with both the old and new versions of
- * this header file, you should update your callback function definition to use the correct unsigned value,
- * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate
- * the compiler warning, e.g.:
- * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context);
- * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly)
- * with both the old header and with the new corrected version.
- *
- */
-
-typedef void (DNSSD_API *DNSServiceResolveReply)
- (
- 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
- );
-
-
-/* DNSServiceQueryRecord
- *
- * Query for an arbitrary DNS record.
- *
- * DNSServiceQueryRecordReply() Callback Parameters:
- *
- * sdRef: The DNSServiceRef initialized by DNSServiceQueryRecord().
- *
- * flags: Possible values are kDNSServiceFlagsMoreComing and
- * kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records
- * with a ttl of 0, i.e. "Remove" events.
- *
- * interfaceIndex: The interface on which the query was resolved (the index for a given
- * interface is determined via the if_nametoindex() family of calls).
- * See "Constants for specifying an interface index" for more details.
- *
- * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
- * indicate the failure that occurred. Other parameters are undefined if
- * errorCode is nonzero.
- *
- * fullname: The resource record's full domain name.
- *
- * rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc)
- *
- * rrclass: The class of the resource record (usually kDNSServiceClass_IN).
- *
- * rdlen: The length, in bytes, of the resource record rdata.
- *
- * rdata: The raw rdata of the resource record.
- *
- * ttl: If the client wishes to cache the result for performance reasons,
- * the TTL indicates how long the client may legitimately hold onto
- * this result, in seconds. After the TTL expires, the client should
- * consider the result no longer valid, and if it requires this data
- * again, it should be re-fetched with a new query. Of course, this
- * only applies to clients that cancel the asynchronous operation when
- * they get a result. Clients that leave the asynchronous operation
- * running can safely assume that the data remains valid until they
- * get another callback telling them otherwise.
- *
- * context: The context pointer that was passed to the callout.
- *
- */
-
-typedef void (DNSSD_API *DNSServiceQueryRecordReply)
- (
- 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
- );
-
-/* DNSServiceGetAddrInfo
- *
- * Queries for the IP address of a hostname by using either Multicast or Unicast DNS.
- *
- * DNSServiceGetAddrInfoReply() parameters:
- *
- * sdRef: The DNSServiceRef initialized by DNSServiceGetAddrInfo().
- *
- * flags: Possible values are kDNSServiceFlagsMoreComing and
- * kDNSServiceFlagsAdd.
- *
- * interfaceIndex: The interface to which the answers pertain.
- *
- * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
- * indicate the failure that occurred. Other parameters are
- * undefined if errorCode is nonzero.
- *
- * hostname: The fully qualified domain name of the host to be queried for.
- *
- * address: IPv4 or IPv6 address.
- *
- * ttl: If the client wishes to cache the result for performance reasons,
- * the TTL indicates how long the client may legitimately hold onto
- * this result, in seconds. After the TTL expires, the client should
- * consider the result no longer valid, and if it requires this data
- * again, it should be re-fetched with a new query. Of course, this
- * only applies to clients that cancel the asynchronous operation when
- * they get a result. Clients that leave the asynchronous operation
- * running can safely assume that the data remains valid until they
- * get another callback telling them otherwise.
- *
- * context: The context pointer that was passed to the callout.
- *
- */
-
-typedef void (DNSSD_API *DNSServiceGetAddrInfoReply)
- (
- DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *hostname,
- const struct sockaddr *address,
- uint32_t ttl,
- void *context
- );
-
-
-
-/* DNSServiceRegisterRecord
- *
- * Register an individual resource record on a connected DNSServiceRef.
- *
- * Note that name conflicts occurring for records registered via this call must be handled
- * by the client in the callback.
- *
- * DNSServiceRegisterRecordReply() parameters:
- *
- * sdRef: The connected DNSServiceRef initialized by
- * DNSServiceCreateConnection().
- *
- * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above
- * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is
- * invalidated, and may not be used further.
- *
- * flags: Currently unused, reserved for future use.
- *
- * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
- * indicate the failure that occurred (including name conflicts.)
- * Other parameters are undefined if errorCode is nonzero.
- *
- * context: The context pointer that was passed to the callout.
- *
- */
-
- typedef void (DNSSD_API *DNSServiceRegisterRecordReply)
- (
- DNSServiceRef sdRef,
- DNSRecordRef RecordRef,
- DNSServiceFlags flags,
- DNSServiceErrorType errorCode,
- void *context
- );
-
-
-/* DNSServiceNATPortMappingCreate
- *
- * Request a port mapping in the NAT gateway, which maps a port on the local machine
- * to an external port on the NAT. The NAT should support either the NAT-PMP or the UPnP IGD
- * protocol for this API to create a successful mapping.
- *
- * The port mapping will be renewed indefinitely until the client process exits, or
- * explicitly terminates the port mapping request by calling DNSServiceRefDeallocate().
- * The client callback will be invoked, informing the client of the NAT gateway's
- * external IP address and the external port that has been allocated for this client.
- * The client should then record this external IP address and port using whatever
- * directory service mechanism it is using to enable peers to connect to it.
- * (Clients advertising services using Wide-Area DNS-SD DO NOT need to use this API
- * -- when a client calls DNSServiceRegister() NAT mappings are automatically created
- * and the external IP address and port for the service are recorded in the global DNS.
- * Only clients using some directory mechanism other than Wide-Area DNS-SD need to use
- * this API to explicitly map their own ports.)
- *
- * It's possible that the client callback could be called multiple times, for example
- * if the NAT gateway's IP address changes, or if a configuration change results in a
- * different external port being mapped for this client. Over the lifetime of any long-lived
- * port mapping, the client should be prepared to handle these notifications of changes
- * in the environment, and should update its recorded address and/or port as appropriate.
- *
- * NOTE: There are two unusual aspects of how the DNSServiceNATPortMappingCreate API works,
- * which were intentionally designed to help simplify client code:
- *
- * 1. It's not an error to request a NAT mapping when the machine is not behind a NAT gateway.
- * In other NAT mapping APIs, if you request a NAT mapping and the machine is not behind a NAT
- * gateway, then the API returns an error code -- it can't get you a NAT mapping if there's no
- * NAT gateway. The DNSServiceNATPortMappingCreate API takes a different view. Working out
- * whether or not you need a NAT mapping can be tricky and non-obvious, particularly on
- * a machine with multiple active network interfaces. Rather than make every client recreate
- * this logic for deciding whether a NAT mapping is required, the PortMapping API does that
- * work for you. If the client calls the PortMapping API when the machine already has a
- * routable public IP address, then instead of complaining about it and giving an error,
- * the PortMapping API just invokes your callback, giving the machine's public address
- * and your own port number. This means you don't need to write code to work out whether
- * your client needs to call the PortMapping API -- just call it anyway, and if it wasn't
- * necessary, no harm is done:
- *
- * - If the machine already has a routable public IP address, then your callback
- * will just be invoked giving your own address and port.
- * - If a NAT mapping is required and obtained, then your callback will be invoked
- * giving you the external address and port.
- * - If a NAT mapping is required but not obtained from the local NAT gateway,
- * or the machine has no network connectivity, then your callback will be
- * invoked giving zero address and port.
- *
- * 2. In other NAT mapping APIs, if a laptop computer is put to sleep and woken up on a new
- * network, it's the client's job to notice this, and work out whether a NAT mapping
- * is required on the new network, and make a new NAT mapping request if necessary.
- * The DNSServiceNATPortMappingCreate API does this for you, automatically.
- * The client just needs to make one call to the PortMapping API, and its callback will
- * be invoked any time the mapping state changes. This property complements point (1) above.
- * If the client didn't make a NAT mapping request just because it determined that one was
- * not required at that particular moment in time, the client would then have to monitor
- * for network state changes to determine if a NAT port mapping later became necessary.
- * By unconditionally making a NAT mapping request, even when a NAT mapping not to be
- * necessary, the PortMapping API will then begin monitoring network state changes on behalf of
- * the client, and if a NAT mapping later becomes necessary, it will automatically create a NAT
- * mapping and inform the client with a new callback giving the new address and port information.
- *
- * DNSServiceNATPortMappingReply() parameters:
- *
- * sdRef: The DNSServiceRef initialized by DNSServiceNATPortMappingCreate().
- *
- * flags: Currently unused, reserved for future use.
- *
- * interfaceIndex: The interface through which the NAT gateway is reached.
- *
- * errorCode: Will be kDNSServiceErr_NoError on success.
- * Will be kDNSServiceErr_DoubleNAT when the NAT gateway is itself behind one or
- * more layers of NAT, in which case the other parameters have the defined values.
- * For other failures, will indicate the failure that occurred, and the other
- * parameters are undefined.
- *
- * externalAddress: Four byte IPv4 address in network byte order.
- *
- * protocol: Will be kDNSServiceProtocol_UDP or kDNSServiceProtocol_TCP or both.
- *
- * internalPort: The port on the local machine that was mapped.
- *
- * externalPort: The actual external port in the NAT gateway that was mapped.
- * This is likely to be different than the requested external port.
- *
- * ttl: The lifetime of the NAT port mapping created on the gateway.
- * This controls how quickly stale mappings will be garbage-collected
- * if the client machine crashes, suffers a power failure, is disconnected
- * from the network, or suffers some other unfortunate demise which
- * causes it to vanish without explicitly removing its NAT port mapping.
- * It's possible that the ttl value will differ from the requested ttl value.
- *
- * context: The context pointer that was passed to the callout.
- *
- */
-
-typedef void (DNSSD_API *DNSServiceNATPortMappingReply)
- (
- DNSServiceRef sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- uint32_t externalAddress, /* four byte IPv4 address in network byte order */
- DNSServiceProtocol protocol,
- uint16_t internalPort, /* In network byte order */
- uint16_t externalPort, /* In network byte order and may be different than the requested port */
- uint32_t ttl, /* may be different than the requested ttl */
- void *context
- );
-
-
-
-/* TXTRecordRef
- *
- * Opaque internal data type.
- * Note: Represents a DNS-SD TXT record.
- */
-
-typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef;
-
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif
diff --git a/src/libs/zeroconf/embed/CommonServices.h b/src/libs/zeroconf/embed/CommonServices.h
deleted file mode 100644
index d0b9e87087..0000000000
--- a/src/libs/zeroconf/embed/CommonServices.h
+++ /dev/null
@@ -1,1498 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @header CommonServices
-
- Common Services for Mac OS X, Linux, Palm, VxWorks, Windows, and Windows CE.
-*/
-
-#ifndef __COMMON_SERVICES__
-#define __COMMON_SERVICES__
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#if 0
-#pragma mark == Target ==
-#endif
-
-//===========================================================================================================================
-// Target
-//===========================================================================================================================
-
-// Macintosh
-
-#if( !defined( TARGET_OS_MAC ) )
- #if( ( macintosh || __MACH__ ) && !KERNEL )
- // ConditionalMacros.h in CoreServices will define this TARGET_* flag.
- #else
- #define TARGET_OS_MAC 0
- #endif
-#endif
-
-#if( !defined( TARGET_API_MAC_OSX_KERNEL ) )
- #if( __MACH__ && KERNEL )
- #define TARGET_API_MAC_OSX_KERNEL 1
- #else
- #define TARGET_API_MAC_OSX_KERNEL 0
- #endif
-#endif
-
-// Linux
-
-#if( !defined( TARGET_OS_LINUX ) )
- #if( defined( __linux__ ) )
- #define TARGET_OS_LINUX 1
- #else
- #define TARGET_OS_LINUX 0
- #endif
-#endif
-
-// Solaris
-
-#if( !defined( TARGET_OS_SOLARIS ) )
- #if( defined(solaris) || (defined(__SVR4) && defined(sun)) )
- #define TARGET_OS_SOLARIS 1
- #else
- #define TARGET_OS_SOLARIS 0
- #endif
-#endif
-
-// Palm
-
-#if( !defined( TARGET_OS_PALM ) )
- #if( defined( __PALMOS_TRAPS__ ) || defined( __PALMOS_ARMLET__ ) )
- #define TARGET_OS_PALM 1
- #else
- #define TARGET_OS_PALM 0
- #endif
-#endif
-
-// VxWorks
-
-#if( !defined( TARGET_OS_VXWORKS ) )
-
- // No predefined macro for VxWorks so just assume VxWorks if nothing else is set.
-
- #if( !macintosh && !__MACH__ && !defined( __linux__ ) && !defined ( __SVR4 ) && !defined ( __sun ) && !defined( __PALMOS_TRAPS__ ) && !defined( __PALMOS_ARMLET__ ) && !defined( _WIN32 ) )
- #define TARGET_OS_VXWORKS 1
- #else
- #define TARGET_OS_VXWORKS 0
- #endif
-#endif
-
-// Windows
-
-#if( !defined( TARGET_OS_WIN32 ) )
- #if( macintosh || __MACH__ )
- // ConditionalMacros.h in CoreServices will define this TARGET_* flag.
- #else
- #if( defined( _WIN32 ) )
- #define TARGET_OS_WIN32 1
- #else
- #define TARGET_OS_WIN32 0
- #endif
- #endif
-#endif
-
-// Windows CE
-
-#if( !defined( TARGET_OS_WINDOWS_CE ) )
- #if( defined( _WIN32_WCE ) )
- #define TARGET_OS_WINDOWS_CE 1
- #else
- #define TARGET_OS_WINDOWS_CE 0
- #endif
-#endif
-
-#if 0
-#pragma mark == Includes ==
-#endif
-
-//===========================================================================================================================
-// Includes
-//===========================================================================================================================
-
-#if( !KERNEL )
- #if defined(WIN32) && !defined(_WSPIAPI_COUNTOF)
- #define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
- #endif
- #include <stddef.h>
-#endif
-
-#if( ( macintosh || __MACH__ ) && !KERNEL )
-
- #if( defined( __MWERKS__ ) )
- #if( __option( c9x ) )
- #include <stdbool.h>
- #endif
- #else
- #include <stdbool.h>
- #endif
-
- #include <stdint.h>
-
- #if( __MACH__ )
-
- // Mac OS X
-
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <fcntl.h>
- #include <pthread.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <unistd.h>
-
- #else
-
- // Classic Mac OS
-
- #include <ConditionalMacros.h>
- #include <MacTypes.h>
-
- #endif
-
-#elif( KERNEL )
-
- // Mac OS X Kernel
-
- #include <stdint.h>
-
- #include <libkern/OSTypes.h>
- #include <sys/types.h>
-
-#elif( TARGET_OS_LINUX )
-
- // Linux
-
- #include <stdint.h>
- #include <arpa/inet.h>
-
-#elif( TARGET_OS_SOLARIS )
-
- // Solaris
-
- #include <stdint.h>
-
- #include <arpa/inet.h>
- #include <arpa/nameser.h>
-
- #if ( defined( BYTE_ORDER ) && defined( LITTLE_ENDIAN ) && ( BYTE_ORDER == LITTLE_ENDIAN ) )
- #define TARGET_RT_LITTLE_ENDIAN 1
- #endif
- #if ( defined( BYTE_ORDER ) && defined( BIG_ENDIAN ) && ( BYTE_ORDER == BIG_ENDIAN ) )
- #define TARGET_RT_BIG_ENDIAN 1
- #endif
-
-#elif( TARGET_OS_PALM )
-
- // Palm (no special includes yet).
-
-#elif( TARGET_OS_VXWORKS )
-
- // VxWorks
-
- #include "vxWorks.h"
-
-#elif( TARGET_OS_WIN32 )
-
- // Windows
-
- #if( !defined( WIN32_WINDOWS ) )
- #define WIN32_WINDOWS 0x0401
- #endif
-
- #if( !defined( _WIN32_WINDOWS ) )
- #define _WIN32_WINDOWS 0x0401
- #endif
-
- #if( !defined( WIN32_LEAN_AND_MEAN ) )
- #define WIN32_LEAN_AND_MEAN // Needed to avoid redefinitions by Windows interfaces.
- #endif
-
- #if( defined( __MWERKS__ ) )
-
- #if( __option( c9x ) )
- #include <stdbool.h>
- #endif
-
- #include <stdint.h>
-
- #elif( defined( _MSC_VER ) )
-
- #pragma warning( disable:4127 ) // Disable "conditional expression is constant" warning for debug macros.
- #pragma warning( disable:4706 ) // Disable "assignment within conditional expression" for Microsoft headers.
-
- #endif
-
- #include <windows.h>
- #include <winsock2.h>
- #include <ws2tcpip.h>
-
- #if( defined( _MSC_VER ) )
- #pragma warning( default:4706 )
- #endif
-
-#else
- #error unknown OS - update this file to support your OS
-#endif
-
-#if( !defined( TARGET_BUILD_MAIN ) )
- #if( !TARGET_OS_VXWORKS )
- #define TARGET_BUILD_MAIN 1
- #endif
-#endif
-
-#if( __GNUC__ || !TARGET_OS_VXWORKS )
- #define TARGET_LANGUAGE_C_LIKE 1
-#else
- #define TARGET_LANGUAGE_C_LIKE 0
-#endif
-
-#if 0
-#pragma mark == CPU ==
-#endif
-
-//===========================================================================================================================
-// CPU
-//===========================================================================================================================
-
-// PowerPC
-
-#if( !defined( TARGET_CPU_PPC ) )
- #if( defined( __ppc__ ) || defined( __PPC__ ) || defined( powerpc ) || defined( ppc ) || defined( _M_MPPC ) )
- #define TARGET_CPU_PPC 1
- #else
- #define TARGET_CPU_PPC 0
- #endif
-#endif
-
-// x86
-
-#if( !defined( TARGET_CPU_X86 ) )
- #if( __INTEL__ || defined( __i386__ ) || defined( i386 ) || defined( intel ) || defined( _M_IX86 ) )
- #define TARGET_CPU_X86 1
- #else
- #define TARGET_CPU_X86 0
- #endif
-#endif
-
-// MIPS
-
-#if( !defined( TARGET_CPU_MIPS ) )
- #if( __MIPS__ || defined( MIPS32 ) || defined( R3000 ) || defined( R4000 ) || defined( R4650 ) || defined( _M_MRX000 ) )
- #define TARGET_CPU_MIPS 1
- #else
- #define TARGET_CPU_MIPS 0
- #endif
-#endif
-
-#if( !defined( TARGET_CPU_PPC ) && !defined( TARGET_CPU_X86 ) && !defined( TARGET_CPU_MIPS ) )
- #error unknown CPU - update this file to support your CPU
-#endif
-
-#if 0
-#pragma mark == Byte Order ==
-#endif
-
-//===========================================================================================================================
-// Byte Order
-//===========================================================================================================================
-
-// TARGET_RT_LITTLE_ENDIAN
-
-#if( !defined( TARGET_RT_LITTLE_ENDIAN ) )
- #if( MIPSEL || IL_LITTLE_ENDIAN || defined( __LITTLE_ENDIAN__ ) || \
- ( defined( BYTE_ORDER ) && defined( LITTLE_ENDIAN ) && ( BYTE_ORDER == LITTLE_ENDIAN ) ) || \
- ( defined( _BYTE_ORDER ) && defined( _LITTLE_ENDIAN ) && ( _BYTE_ORDER == _LITTLE_ENDIAN ) ) || \
- ( defined( __BYTE_ORDER ) && defined( __LITTLE_ENDIAN ) && ( __BYTE_ORDER == __LITTLE_ENDIAN ) ) || \
- TARGET_CPU_X86 || ( defined( TARGET_RT_BIG_ENDIAN ) && !TARGET_RT_BIG_ENDIAN ) )
- #define TARGET_RT_LITTLE_ENDIAN 1
- #else
- #define TARGET_RT_LITTLE_ENDIAN 0
- #endif
-#endif
-
-// TARGET_RT_BIG_ENDIAN
-
-#if( !defined( TARGET_RT_BIG_ENDIAN ) )
- #if( MIPSEB || IL_BIG_ENDIAN || defined( __BIG_ENDIAN__ ) || \
- ( defined( BYTE_ORDER ) && defined( BIG_ENDIAN ) && ( BYTE_ORDER == BIG_ENDIAN ) ) || \
- ( defined( _BYTE_ORDER ) && defined( _BIG_ENDIAN ) && ( _BYTE_ORDER == _BIG_ENDIAN ) ) || \
- ( defined( __BYTE_ORDER ) && defined( __BIG_ENDIAN ) && ( __BYTE_ORDER == __BIG_ENDIAN ) ) || \
- ( defined( TARGET_RT_LITTLE_ENDIAN ) && !TARGET_RT_LITTLE_ENDIAN ) )
- #define TARGET_RT_BIG_ENDIAN 1
- #else
- #define TARGET_RT_BIG_ENDIAN 0
- #endif
-#endif
-
-#if( defined( TARGET_RT_LITTLE_ENDIAN ) && !defined( TARGET_RT_BIG_ENDIAN ) )
- #if( TARGET_RT_LITTLE_ENDIAN )
- #define TARGET_RT_BIG_ENDIAN 0
- #else
- #define TARGET_RT_BIG_ENDIAN 1
- #endif
-#endif
-
-#if( defined( TARGET_RT_BIG_ENDIAN ) && !defined( TARGET_RT_LITTLE_ENDIAN ) )
- #if( TARGET_RT_BIG_ENDIAN )
- #define TARGET_RT_LITTLE_ENDIAN 0
- #else
- #define TARGET_RT_LITTLE_ENDIAN 1
- #endif
-#endif
-
-#if( !defined( TARGET_RT_LITTLE_ENDIAN ) || !defined( TARGET_RT_BIG_ENDIAN ) )
- #error unknown byte order - update this file to support your byte order
-#endif
-
-// TARGET_RT_BYTE_ORDER
-
-#if( !defined( TARGET_RT_BYTE_ORDER_BIG_ENDIAN ) )
- #define TARGET_RT_BYTE_ORDER_BIG_ENDIAN 1234
-#endif
-
-#if( !defined( TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN ) )
- #define TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN 4321
-#endif
-
-#if( !defined( TARGET_RT_BYTE_ORDER ) )
- #if( TARGET_RT_LITTLE_ENDIAN )
- #define TARGET_RT_BYTE_ORDER TARGET_RT_BYTE_ORDER_LITTLE_ENDIAN
- #else
- #define TARGET_RT_BYTE_ORDER TARGET_RT_BYTE_ORDER_BIG_ENDIAN
- #endif
-#endif
-
-#if 0
-#pragma mark == Constants ==
-#endif
-
-//===========================================================================================================================
-// Constants
-//===========================================================================================================================
-
-#if( !TARGET_OS_MAC )
- #define CR '\r'
-#endif
-
-#define LF '\n'
-#define CRSTR "\r"
-#define LFSTR "\n"
-#define CRLF "\r\n"
-#define CRCR "\r\r"
-
-#if 0
-#pragma mark == Compatibility ==
-#endif
-
-//===========================================================================================================================
-// Compatibility
-//===========================================================================================================================
-
-// Macros to allow the same code to work on Windows and other sockets API-compatible platforms.
-
-#if( TARGET_OS_WIN32 )
- #define close_compat( X ) closesocket( X )
- #define errno_compat() (int) GetLastError()
- #define set_errno_compat( X ) SetLastError( X )
- #define EWOULDBLOCK_compat WSAEWOULDBLOCK
- #define ETIMEDOUT_compat WSAETIMEDOUT
- #define ENOTCONN_compat WSAENOTCONN
- #define IsValidSocket( X ) ( ( X ) != INVALID_SOCKET )
- #define kInvalidSocketRef INVALID_SOCKET
- #if( TARGET_LANGUAGE_C_LIKE )
- typedef SOCKET SocketRef;
- #endif
-#else
- #define close_compat( X ) close( X )
- #define errno_compat() errno
- #define set_errno_compat( X ) do { errno = ( X ); } while( 0 )
- #define EWOULDBLOCK_compat EWOULDBLOCK
- #define ETIMEDOUT_compat ETIMEDOUT
- #define ENOTCONN_compat ENOTCONN
- #define IsValidSocket( X ) ( ( X ) >= 0 )
- #define kInvalidSocketRef -1
- #if( TARGET_LANGUAGE_C_LIKE )
- typedef int SocketRef;
- #endif
-#endif
-
-// socklen_t is not defined on the following platforms so emulate it if not defined:
-//
-// - Pre-Panther Mac OS X. Panther defines SO_NOADDRERR so trigger off that.
-// - Windows SDK prior to 2003. 2003+ SDK's define EAI_AGAIN so trigger off that.
-// - VxWorks
-
-#if( TARGET_LANGUAGE_C_LIKE )
- #if( ( TARGET_OS_MAC && !defined( SO_NOADDRERR ) ) || ( TARGET_OS_WIN32 && !defined( EAI_AGAIN ) ) || TARGET_OS_VXWORKS )
- typedef int socklen_t;
- #endif
-#endif
-
-// ssize_t is not defined on the following platforms so emulate it if not defined:
-//
-// - Mac OS X when not building with BSD headers
-// - Windows
-
-#if( TARGET_LANGUAGE_C_LIKE )
- #if( !defined(_SSIZE_T) && ( TARGET_OS_WIN32 || !defined( _BSD_SSIZE_T_DEFINED_ ) ) && !TARGET_OS_LINUX && !TARGET_OS_VXWORKS && !TARGET_OS_MAC)
- typedef int ssize_t;
- #endif
-#endif
-
-// sockaddr_storage is not supported on non-IPv6 machines so alias it to an IPv4-compatible structure.
-
-#if( TARGET_LANGUAGE_C_LIKE )
- #if( !defined( AF_INET6 ) )
- #define sockaddr_storage sockaddr_in
- #define ss_family sin_family
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined SOCKADDR_IS_IP_LOOPBACK
-
- @abstract Determines if a sockaddr is an IPv4 or IPv6 loopback address (if IPv6 is supported).
-*/
-
-#if( defined( AF_INET6 ) )
- #define SOCKADDR_IS_IP_LOOPBACK( SA ) \
- ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( (const struct sockaddr_in *)( SA ) )->sin_addr.s_addr == htonl( INADDR_LOOPBACK ) ) \
- : ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET6 ) \
- ? IN6_IS_ADDR_LOOPBACK( &( (const struct sockaddr_in6 *)( SA ) )->sin6_addr ) \
- : 0
-#else
- #define SOCKADDR_IS_IP_LOOPBACK( SA ) \
- ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( (const struct sockaddr_in *)( SA ) )->sin_addr.s_addr == htonl( INADDR_LOOPBACK ) ) \
- : 0
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined SOCKADDR_IS_IP_LINK_LOCAL
-
- @abstract Determines if a sockaddr is an IPv4 or IPv6 link-local address (if IPv6 is supported).
-*/
-
-#if( defined( AF_INET6 ) )
- #define SOCKADDR_IS_IP_LINK_LOCAL( SA ) \
- ( ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 0 ] == 169 ) && \
- ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 1 ] == 254 ) ) \
- : IN6_IS_ADDR_LOOPBACK( &( (const struct sockaddr_in6 *)( SA ) )->sin6_addr ) )
-#else
- #define SOCKADDR_IS_IP_LINK_LOCAL( SA ) \
- ( ( ( (const struct sockaddr *)( SA ) )->sa_family == AF_INET ) \
- ? ( ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 0 ] == 169 ) && \
- ( ( (uint8_t *)( &( (const struct sockaddr_in *)( SA ) )->sin_addr ) )[ 1 ] == 254 ) ) \
- : 0 )
-#endif
-
-// _beginthreadex and _endthreadex are not supported on Windows CE 2.1 or later (the C runtime issues with leaking
-// resources have apparently been resolved and they seem to have just ripped out support for the API) so map it to
-// CreateThread on Windows CE.
-
-#if( TARGET_OS_WINDOWS_CE )
- #define _beginthreadex_compat( SECURITY_PTR, STACK_SIZE, START_ADDRESS, ARG_LIST, FLAGS, THREAD_ID_PTR ) \
- (uintptr_t) CreateThread( SECURITY_PTR, STACK_SIZE, (LPTHREAD_START_ROUTINE) START_ADDRESS, ARG_LIST, FLAGS, \
- (LPDWORD) THREAD_ID_PTR )
-
- #define _endthreadex_compat( RESULT ) ExitThread( (DWORD) RESULT )
-#elif( TARGET_OS_WIN32 )
- #define _beginthreadex_compat _beginthreadex
- #define _endthreadex_compat _endthreadex
-#endif
-
-// The C99 "inline" keyword is not supported by Microsoft compilers, but they do support __inline so map it when needed.
-
-#if( defined( _MSC_VER ) )
- #define inline_compat __inline
-#else
- #define inline_compat inline
-#endif
-
-// Calling conventions
-
-#if( !defined( CALLBACK_COMPAT ) )
- #if( TARGET_OS_WIN32 || TARGET_OS_WINDOWS_CE )
- #define CALLBACK_COMPAT CALLBACK
- #else
- #define CALLBACK_COMPAT
- #endif
-#endif
-
-#if 0
-#pragma mark == Macros ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined kSizeCString
-
- @abstract A meta-value to pass to supported routines to indicate the size should be calculated with strlen.
-*/
-
-#define kSizeCString ( (size_t) -1 )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined sizeof_array
-
- @abstract Determines the number of elements in an array.
-*/
-
-#define sizeof_array( X ) ( sizeof( X ) / sizeof( X[ 0 ] ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined sizeof_element
-
- @abstract Determines the size of an array element.
-*/
-
-#define sizeof_element( X ) sizeof( X[ 0 ] )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined sizeof_string
-
- @abstract Determines the size of a constant C string, excluding the null terminator.
-*/
-
-#define sizeof_string( X ) ( sizeof( ( X ) ) - 1 )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined sizeof_field
-
- @abstract Determines the size of a field of a type.
-*/
-
-#define sizeof_field( TYPE, FIELD ) sizeof( ( ( (TYPE *) 0 )->FIELD ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function RoundUp
-
- @abstract Rounds X up to a multiple of Y.
-*/
-
-#define RoundUp( X, Y ) ( ( X ) + ( ( Y ) - ( ( X ) % ( Y ) ) ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function IsAligned
-
- @abstract Returns non-zero if X is aligned to a Y byte boundary and 0 if not. Y must be a power of 2.
-*/
-
-#define IsAligned( X, Y ) ( ( ( X ) & ( ( Y ) - 1 ) ) == 0 )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function IsFieldAligned
-
- @abstract Returns non-zero if FIELD of type TYPE is aligned to a Y byte boundary and 0 if not. Y must be a power of 2.
-*/
-
-#define IsFieldAligned( X, TYPE, FIELD, Y ) IsAligned( ( (uintptr_t)( X ) ) + offsetof( TYPE, FIELD ), ( Y ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function AlignDown
-
- @abstract Aligns X down to a Y byte boundary. Y must be a power of 2.
-*/
-
-#define AlignDown( X, Y ) ( ( X ) & ~( ( Y ) - 1 ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function AlignUp
-
- @abstract Aligns X up to a Y byte boundary. Y must be a power of 2.
-*/
-
-#define AlignUp( X, Y ) ( ( ( X ) + ( ( Y ) - 1 ) ) & ~( ( Y ) - 1 ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function Min
-
- @abstract Returns the lesser of X and Y.
-*/
-
-#if( !defined( Min ) )
- #define Min( X, Y ) ( ( ( X ) < ( Y ) ) ? ( X ) : ( Y ) )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function Max
-
- @abstract Returns the greater of X and Y.
-*/
-
-#if( !defined( Max ) )
- #define Max( X, Y ) ( ( ( X ) > ( Y ) ) ? ( X ) : ( Y ) )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function InsertBits
-
- @abstract Inserts BITS (both 0 and 1 bits) into X, controlled by MASK and SHIFT, and returns the result.
-
- @discussion
-
- MASK is the bitmask of the bits in the final position.
- SHIFT is the number of bits to shift left for 1 to reach the first bit position of MASK.
-
- For example, if you wanted to insert 0x3 into the leftmost 4 bits of a 32-bit value:
-
- InsertBits( 0, 0x3, 0xF0000000U, 28 ) == 0x30000000
-*/
-
-#define InsertBits( X, BITS, MASK, SHIFT ) ( ( ( X ) & ~( MASK ) ) | ( ( ( BITS ) << ( SHIFT ) ) & ( MASK ) ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function ExtractBits
-
- @abstract Extracts bits from X, controlled by MASK and SHIFT, and returns the result.
-
- @discussion
-
- MASK is the bitmask of the bits in the final position.
- SHIFT is the number of bits to shift right to right justify MASK.
-
- For example, if you had a 32-bit value (e.g. 0x30000000) wanted the left-most 4 bits (e.g. 3 in this example):
-
- ExtractBits( 0x30000000U, 0xF0000000U, 28 ) == 0x3
-*/
-
-#define ExtractBits( X, MASK, SHIFT ) ( ( ( X ) >> ( SHIFT ) ) & ( ( MASK ) >> ( SHIFT ) ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function Stringify
-
- @abstract Stringify's an expression.
-
- @discussion
-
- Stringify macros to process raw text passed via -D options to C string constants. The double-wrapping is necessary
- because the C preprocessor doesn't perform its normal argument expansion pre-scan with stringified macros so the
- -D macro needs to be expanded once via the wrapper macro then stringified so the raw text is stringified. Otherwise,
- the replacement value would be used instead of the symbolic name (only for preprocessor symbols like #defines).
-
- For example:
-
- #define kMyConstant 1
-
- printf( "%s", Stringify( kMyConstant ) ); // Prints "kMyConstant"
- printf( "%s", StringifyExpansion( kMyConstant ) ); // Prints "1"
-
- Non-preprocessor symbols do not have this issue. For example:
-
- enum
- {
- kMyConstant = 1
- };
-
- printf( "%s", Stringify( kMyConstant ) ); // Prints "kMyConstant"
- printf( "%s", StringifyExpansion( kMyConstant ) ); // Prints "kMyConstant"
-
- See <http://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html> for more info on C preprocessor pre-scanning.
-*/
-
-#define Stringify( X ) # X
-#define StringifyExpansion( X ) Stringify( X )
-
-#if 0
-#pragma mark == Types ==
-#endif
-
-#if( TARGET_LANGUAGE_C_LIKE )
-//===========================================================================================================================
-// Standard Types
-//===========================================================================================================================
-
-#if( !defined( INT8_MIN ) )
-
- #define INT8_MIN SCHAR_MIN
-
- #if( defined( _MSC_VER ) )
-
- // C99 stdint.h not supported in VC++/VS.NET yet.
-
- typedef INT8 int8_t;
- typedef UINT8 uint8_t;
- typedef INT16 int16_t;
- typedef UINT16 uint16_t;
- typedef INT32 int32_t;
- typedef UINT32 uint32_t;
- typedef __int64 int64_t;
- typedef unsigned __int64 uint64_t;
-
- #elif( TARGET_OS_VXWORKS && ( TORNADO_VERSION < 220 ) )
- typedef long long int64_t;
- typedef unsigned long long uint64_t;
- #endif
-
- #if (( !defined( _MSC_VER ) || TARGET_OS_WINDOWS_CE ) && !defined( _WIN32 ) )
- typedef long int intptr_t;
- typedef unsigned long int uintptr_t;
- #endif
-
-#endif
-
-// Macros for minimum-width integer constants
-
-#if( !defined( INT8_C ) )
- #define INT8_C( value ) value
-#endif
-
-#if( !defined( INT16_C ) )
- #define INT16_C( value ) value
-#endif
-
-#if( !defined( INT32_C ) )
- #define INT32_C( value ) value ## L
-#endif
-
-#if( !defined( INT64_C ) )
- #if( defined( _MSC_VER ) )
- #define INT64_C( value ) value ## i64
- #else
- #define INT64_C( value ) value ## LL
- #endif
-#endif
-
-#if( !defined( UINT8_C ) )
- #define UINT8_C( value ) value ## U
-#endif
-
-#if( !defined( UINT16_C ) )
- #define UINT16_C( value ) value ## U
-#endif
-
-#if( !defined( UINT32_C ) )
- #define UINT32_C( value ) value ## UL
-#endif
-
-#if( !defined( UINT64_C ) )
- #if( defined( _MSC_VER ) )
- #define UINT64_C( value ) value ## UI64
- #else
- #define UINT64_C( value ) value ## ULL
- #endif
-#endif
-
-#if 0
-#pragma mark == bool ==
-#endif
-
-//===========================================================================================================================
-// Boolean Constants and Types
-//===========================================================================================================================
-
-// C++ defines bool, true, and false. Metrowerks allows this to be controlled by the "bool" option though.
-// C99 defines __bool_true_false_are_defined when bool, true, and false are defined.
-// MacTypes.h defines true and false (Mac builds only).
-//
-// Note: The Metrowerks has to be in its own block because Microsoft Visual Studio .NET does not completely
-// short-circuit and gets confused by the option( bool ) portion of the conditional.
-
-#if( defined( __MWERKS__ ) )
-
- // Note: The following test is done on separate lines because CodeWarrior doesn't like it all on one line.
-
- #if( !__bool_true_false_are_defined && ( !defined( __cplusplus ) || !__option( bool ) ) )
- #define COMMON_SERVICES_NEEDS_BOOL 1
- #else
- #define COMMON_SERVICES_NEEDS_BOOL 0
- #endif
-
- // Workaround when building with CodeWarrior, but using the Apple stdbool.h header, which uses _Bool.
-
- #if( __bool_true_false_are_defined && !defined( __cplusplus ) && !__option( c9x ) )
- #define _Bool int
- #endif
-
- // Workaround when building with CodeWarrior for C++ with bool disabled and using the Apple stdbool.h header,
- // which defines true and false to map to C++ true and false (which are not enabled). Serenity Now!
-
- #if( __bool_true_false_are_defined && defined( __cplusplus ) && !__option( bool ) )
- #define true 1
- #define false 0
- #endif
-#else
- #define COMMON_SERVICES_NEEDS_BOOL ( !defined( __cplusplus ) && !__bool_true_false_are_defined )
-#endif
-
-#if( COMMON_SERVICES_NEEDS_BOOL )
-
- typedef int bool;
-
- #define bool bool
-
- #if( !defined( __MACTYPES__ ) && !defined( true ) && !defined( false ) )
- #define true 1
- #define false 0
- #endif
-
- #define __bool_true_false_are_defined 1
-#endif
-
-// IOKit IOTypes.h typedef's bool if TYPE_BOOL is not defined so define it here to prevent redefinition by IOTypes.h.
-
-#if( TARGET_API_MAC_OSX_KERNEL )
- #define TYPE_BOOL 1
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef CStr255
-
- @abstract 255 character null-terminated (C-style) string.
-*/
-
-#if( TARGET_LANGUAGE_C_LIKE )
- typedef char CStr255[ 256 ];
-#endif
-
-#endif // TARGET_LANGUAGE_C_LIKE
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined TYPE_LONGLONG_NATIVE
-
- @abstract Defines whether long long (or its equivalent) is natively supported or requires special libraries.
-*/
-
-#if( !defined( TYPE_LONGLONG_NATIVE ) )
- #if( !TARGET_OS_VXWORKS )
- #define TYPE_LONGLONG_NATIVE 1
- #else
- #define TYPE_LONGLONG_NATIVE 0
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined long_long_compat
-
- @abstract Compatibility type to map to the closest thing to long long and unsigned long long.
-
- @discussion
-
- Neither long long nor unsigned long long are supported by Microsoft compilers, but they do support proprietary
- "__int64" and "unsigned __int64" equivalents so map to those types if the real long long is not supported.
-*/
-
-#if( TARGET_LANGUAGE_C_LIKE )
- #if( TARGET_OS_WIN32 )
- typedef __int64 long_long_compat;
- typedef unsigned __int64 unsigned_long_long_compat;
- #else
- typedef signed long long long_long_compat;
- typedef unsigned long long unsigned_long_long_compat;
- #endif
-#endif
-
-#if 0
-#pragma mark == Errors ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @enum OSStatus
-
- @abstract Status Code
-
- @constant kNoErr 0 No error occurred.
- @constant kInProgressErr 1 Operation in progress.
- @constant kUnknownErr -6700 Unknown error occurred.
- @constant kOptionErr -6701 Option was not acceptable.
- @constant kSelectorErr -6702 Selector passed in is invalid or unknown.
- @constant kExecutionStateErr -6703 Call made in the wrong execution state (e.g. called at interrupt time).
- @constant kPathErr -6704 Path is invalid, too long, or otherwise not usable.
- @constant kParamErr -6705 Parameter is incorrect, missing, or not appropriate.
- @constant kParamCountErr -6706 Incorrect or unsupported number of parameters.
- @constant kCommandErr -6707 Command invalid or not supported.
- @constant kIDErr -6708 Unknown, invalid, or inappropriate identifier.
- @constant kStateErr -6709 Not in appropriate state to perform operation.
- @constant kRangeErr -6710 Index is out of range or not valid.
- @constant kRequestErr -6711 Request was improperly formed or not appropriate.
- @constant kResponseErr -6712 Response was incorrect or out of sequence.
- @constant kChecksumErr -6713 Checksum does not match the actual data.
- @constant kNotHandledErr -6714 Operation was not handled (or not handled completely).
- @constant kVersionErr -6715 Version is not incorrect or not compatibile.
- @constant kSignatureErr -6716 Signature did not match what was expected.
- @constant kFormatErr -6717 Unknown, invalid, or inappropriate file/data format.
- @constant kNotInitializedErr -6718 Action request before needed services were initialized.
- @constant kAlreadyInitializedErr -6719 Attempt made to initialize when already initialized.
- @constant kNotInUseErr -6720 Object not in use (e.g. cannot abort if not already in use).
- @constant kInUseErr -6721 Object is in use (e.g. cannot reuse active param blocks).
- @constant kTimeoutErr -6722 Timeout occurred.
- @constant kCanceledErr -6723 Operation canceled (successful cancel).
- @constant kAlreadyCanceledErr -6724 Operation has already been canceled.
- @constant kCannotCancelErr -6725 Operation could not be canceled (maybe already done or invalid).
- @constant kDeletedErr -6726 Object has already been deleted.
- @constant kNotFoundErr -6727 Something was not found.
- @constant kNoMemoryErr -6728 Not enough memory was available to perform the operation.
- @constant kNoResourcesErr -6729 Resources unavailable to perform the operation.
- @constant kDuplicateErr -6730 Duplicate found or something is a duplicate.
- @constant kImmutableErr -6731 Entity is not changeable.
- @constant kUnsupportedDataErr -6732 Data is unknown or not supported.
- @constant kIntegrityErr -6733 Data is corrupt.
- @constant kIncompatibleErr -6734 Data is not compatible or it is in an incompatible format.
- @constant kUnsupportedErr -6735 Feature or option is not supported.
- @constant kUnexpectedErr -6736 Error occurred that was not expected.
- @constant kValueErr -6737 Value is not appropriate.
- @constant kNotReadableErr -6738 Could not read or reading is not allowed.
- @constant kNotWritableErr -6739 Could not write or writing is not allowed.
- @constant kBadReferenceErr -6740 An invalid or inappropriate reference was specified.
- @constant kFlagErr -6741 An invalid, inappropriate, or unsupported flag was specified.
- @constant kMalformedErr -6742 Something was not formed correctly.
- @constant kSizeErr -6743 Size was too big, too small, or not appropriate.
- @constant kNameErr -6744 Name was not correct, allowed, or appropriate.
- @constant kNotReadyErr -6745 Device or service is not ready.
- @constant kReadErr -6746 Could not read.
- @constant kWriteErr -6747 Could not write.
- @constant kMismatchErr -6748 Something does not match.
- @constant kDateErr -6749 Date is invalid or out-of-range.
- @constant kUnderrunErr -6750 Less data than expected.
- @constant kOverrunErr -6751 More data than expected.
- @constant kEndingErr -6752 Connection, session, or something is ending.
- @constant kConnectionErr -6753 Connection failed or could not be established.
- @constant kAuthenticationErr -6754 Authentication failed or is not supported.
- @constant kOpenErr -6755 Could not open file, pipe, device, etc.
- @constant kTypeErr -6756 Incorrect or incompatible type (e.g. file, data, etc.).
- @constant kSkipErr -6757 Items should be or was skipped.
- @constant kNoAckErr -6758 No acknowledge.
- @constant kCollisionErr -6759 Collision occurred (e.g. two on bus at same time).
- @constant kBackoffErr -6760 Backoff in progress and operation intentionally failed.
- @constant kNoAddressAckErr -6761 No acknowledge of address.
- @constant kBusyErr -6762 Cannot perform because something is busy.
- @constant kNoSpaceErr -6763 Not enough space to perform operation.
-*/
-
-#if( TARGET_LANGUAGE_C_LIKE )
- #if( !TARGET_OS_MAC && !TARGET_API_MAC_OSX_KERNEL )
- typedef int32_t OSStatus;
- #endif
-#endif
-
-#define kNoErr 0
-#define kInProgressErr 1
-
-// Generic error codes are in the range -6700 to -6779.
-
-#define kGenericErrorBase -6700 // Starting error code for all generic errors.
-
-#define kUnknownErr -6700
-#define kOptionErr -6701
-#define kSelectorErr -6702
-#define kExecutionStateErr -6703
-#define kPathErr -6704
-#define kParamErr -6705
-#define kParamCountErr -6706
-#define kCommandErr -6707
-#define kIDErr -6708
-#define kStateErr -6709
-#define kRangeErr -6710
-#define kRequestErr -6711
-#define kResponseErr -6712
-#define kChecksumErr -6713
-#define kNotHandledErr -6714
-#define kVersionErr -6715
-#define kSignatureErr -6716
-#define kFormatErr -6717
-#define kNotInitializedErr -6718
-#define kAlreadyInitializedErr -6719
-#define kNotInUseErr -6720
-#define kInUseErr -6721
-#define kTimeoutErr -6722
-#define kCanceledErr -6723
-#define kAlreadyCanceledErr -6724
-#define kCannotCancelErr -6725
-#define kDeletedErr -6726
-#define kNotFoundErr -6727
-#define kNoMemoryErr -6728
-#define kNoResourcesErr -6729
-#define kDuplicateErr -6730
-#define kImmutableErr -6731
-#define kUnsupportedDataErr -6732
-#define kIntegrityErr -6733
-#define kIncompatibleErr -6734
-#define kUnsupportedErr -6735
-#define kUnexpectedErr -6736
-#define kValueErr -6737
-#define kNotReadableErr -6738
-#define kNotWritableErr -6739
-#define kBadReferenceErr -6740
-#define kFlagErr -6741
-#define kMalformedErr -6742
-#define kSizeErr -6743
-#define kNameErr -6744
-#define kNotReadyErr -6745
-#define kReadErr -6746
-#define kWriteErr -6747
-#define kMismatchErr -6748
-#define kDateErr -6749
-#define kUnderrunErr -6750
-#define kOverrunErr -6751
-#define kEndingErr -6752
-#define kConnectionErr -6753
-#define kAuthenticationErr -6754
-#define kOpenErr -6755
-#define kTypeErr -6756
-#define kSkipErr -6757
-#define kNoAckErr -6758
-#define kCollisionErr -6759
-#define kBackoffErr -6760
-#define kNoAddressAckErr -6761
-#define kBusyErr -6762
-#define kNoSpaceErr -6763
-
-#define kGenericErrorEnd -6779 // Last generic error code (inclusive)
-
-#if 0
-#pragma mark == Mac Compatibility ==
-#endif
-
-//===========================================================================================================================
-// Mac Compatibility
-//===========================================================================================================================
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @enum Duration
-
- @abstract Type used to specify a duration of time.
-
- @constant kDurationImmediate Indicates no delay/wait time.
- @constant kDurationMicrosecond Microsecond units.
- @constant kDurationMillisecond Millisecond units.
- @constant kDurationSecond Second units.
- @constant kDurationMinute Minute units.
- @constant kDurationHour Hour units.
- @constant kDurationDay Day units.
- @constant kDurationForever Infinite period of time (no timeout).
-
- @discussion
-
- Duration values are intended to be multiplied by the specific interval to achieve an actual duration. For example,
- to wait for 5 seconds you would use "5 * kDurationSecond".
-*/
-
-#if( TARGET_LANGUAGE_C_LIKE )
- #if( !TARGET_OS_MAC )
- typedef int32_t Duration;
- #endif
-#endif
-
-#define kDurationImmediate 0L
-#define kDurationMicrosecond -1L
-#define kDurationMillisecond 1L
-#define kDurationSecond ( 1000L * kDurationMillisecond )
-#define kDurationMinute ( 60L * kDurationSecond )
-#define kDurationHour ( 60L * kDurationMinute )
-#define kDurationDay ( 24L * kDurationHour )
-#define kDurationForever 0x7FFFFFFFL
-
-// Seconds <-> Minutes <-> Hours <-> Days <-> Weeks <-> Months <-> Years conversions
-
-#define kNanosecondsPerMicrosecond 1000
-#define kNanosecondsPerMillisecond 1000000
-#define kNanosecondsPerSecond 1000000000
-#define kMicrosecondsPerSecond 1000000
-#define kMicrosecondsPerMillisecond 1000
-#define kMillisecondsPerSecond 1000
-#define kSecondsPerMinute 60
-#define kSecondsPerHour ( 60 * 60 ) // 3600
-#define kSecondsPerDay ( 60 * 60 * 24 ) // 86400
-#define kSecondsPerWeek ( 60 * 60 * 24 * 7 ) // 604800
-#define kMinutesPerHour 60
-#define kMinutesPerDay ( 60 * 24 ) // 1440
-#define kHoursPerDay 24
-#define kDaysPerWeek 7
-#define kWeeksPerYear 52
-#define kMonthsPerYear 12
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined VersionStages
-
- @abstract NumVersion-style version stages.
-*/
-
-#define kVersionStageDevelopment 0x20
-#define kVersionStageAlpha 0x40
-#define kVersionStageBeta 0x60
-#define kVersionStageFinal 0x80
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function NumVersionBuild
-
- @abstract Builds a 32-bit Mac-style NumVersion value (e.g. NumVersionBuild( 1, 2, 3, kVersionStageBeta, 4 ) -> 1.2.3b4).
-*/
-
-#define NumVersionBuild( MAJOR, MINOR, BUGFIX, STAGE, REV ) \
- ( ( ( ( MAJOR ) & 0xFF ) << 24 ) | \
- ( ( ( MINOR ) & 0x0F ) << 20 ) | \
- ( ( ( BUGFIX ) & 0x0F ) << 16 ) | \
- ( ( ( STAGE ) & 0xFF ) << 8 ) | \
- ( ( ( REV ) & 0xFF ) ) )
-
-#define NumVersionExtractMajor( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 24 ) & 0xFF ) )
-#define NumVersionExtractMinorAndBugFix( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 16 ) & 0xFF ) )
-#define NumVersionExtractMinor( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 20 ) & 0x0F ) )
-#define NumVersionExtractBugFix( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 16 ) & 0x0F ) )
-#define NumVersionExtractStage( VERSION ) ( (uint8_t)( ( ( VERSION ) >> 8 ) & 0xFF ) )
-#define NumVersionExtractRevision( VERSION ) ( (uint8_t)( ( VERSION ) & 0xFF ) )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function NumVersionCompare
-
- @abstract Compares two NumVersion values and returns the following values:
-
- left < right -> -1
- left > right -> 1
- left = right -> 0
-*/
-
-#if( TARGET_LANGUAGE_C_LIKE )
- int NumVersionCompare( uint32_t inLeft, uint32_t inRight );
-#endif
-
-#if 0
-#pragma mark == Binary Constants ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined binary_4
-
- @abstract Macro to generate an 4-bit constant using binary notation (e.g. binary_4( 1010 ) == 0xA).
-*/
-
-#define binary_4( a ) binary_4_hex_wrap( hex_digit4( a ) )
-#define binary_4_hex_wrap( a ) binary_4_hex( a )
-#define binary_4_hex( a ) ( 0x ## a )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined binary_8
-
- @abstract Macro to generate an 8-bit constant using binary notation (e.g. binary_8( 01111011 ) == 0x7B).
-*/
-
-#define binary_8( a ) binary_8_hex_wrap( hex_digit8( a ) )
-#define binary_8_hex_wrap( a ) binary_8_hex( a )
-#define binary_8_hex( a ) ( 0x ## a )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined binary_16
-
- @abstract Macro to generate an 16-bit constant using binary notation (e.g. binary_16( 01111011, 01111011 ) == 0x7B7B).
-*/
-
-#define binary_16( a, b ) binary_16_hex_wrap( hex_digit8( a ), hex_digit8( b ) )
-#define binary_16_hex_wrap( a, b ) binary_16_hex( a, b )
-#define binary_16_hex( a, b ) ( 0x ## a ## b )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined binary_32
-
- @abstract Macro to generate an 32-bit constant using binary notation
- (e.g. binary_32( 01111011, 01111011, 01111011, 01111011 ) == 0x7B7B7B7B).
-*/
-
-#define binary_32( a, b, c, d ) binary_32_hex_wrap( hex_digit8( a ), hex_digit8( b ), hex_digit8( c ), hex_digit8( d ) )
-#define binary_32_hex_wrap( a, b, c, d ) binary_32_hex( a, b, c, d )
-#define binary_32_hex( a, b, c, d ) ( 0x ## a ## b ## c ## d )
-
-// Binary Constant Helpers
-
-#define hex_digit8( a ) HEX_DIGIT_ ## a
-#define hex_digit4( a ) HEX_DIGIT_ ## 0000 ## a
-
-#define HEX_DIGIT_00000000 00
-#define HEX_DIGIT_00000001 01
-#define HEX_DIGIT_00000010 02
-#define HEX_DIGIT_00000011 03
-#define HEX_DIGIT_00000100 04
-#define HEX_DIGIT_00000101 05
-#define HEX_DIGIT_00000110 06
-#define HEX_DIGIT_00000111 07
-#define HEX_DIGIT_00001000 08
-#define HEX_DIGIT_00001001 09
-#define HEX_DIGIT_00001010 0A
-#define HEX_DIGIT_00001011 0B
-#define HEX_DIGIT_00001100 0C
-#define HEX_DIGIT_00001101 0D
-#define HEX_DIGIT_00001110 0E
-#define HEX_DIGIT_00001111 0F
-#define HEX_DIGIT_00010000 10
-#define HEX_DIGIT_00010001 11
-#define HEX_DIGIT_00010010 12
-#define HEX_DIGIT_00010011 13
-#define HEX_DIGIT_00010100 14
-#define HEX_DIGIT_00010101 15
-#define HEX_DIGIT_00010110 16
-#define HEX_DIGIT_00010111 17
-#define HEX_DIGIT_00011000 18
-#define HEX_DIGIT_00011001 19
-#define HEX_DIGIT_00011010 1A
-#define HEX_DIGIT_00011011 1B
-#define HEX_DIGIT_00011100 1C
-#define HEX_DIGIT_00011101 1D
-#define HEX_DIGIT_00011110 1E
-#define HEX_DIGIT_00011111 1F
-#define HEX_DIGIT_00100000 20
-#define HEX_DIGIT_00100001 21
-#define HEX_DIGIT_00100010 22
-#define HEX_DIGIT_00100011 23
-#define HEX_DIGIT_00100100 24
-#define HEX_DIGIT_00100101 25
-#define HEX_DIGIT_00100110 26
-#define HEX_DIGIT_00100111 27
-#define HEX_DIGIT_00101000 28
-#define HEX_DIGIT_00101001 29
-#define HEX_DIGIT_00101010 2A
-#define HEX_DIGIT_00101011 2B
-#define HEX_DIGIT_00101100 2C
-#define HEX_DIGIT_00101101 2D
-#define HEX_DIGIT_00101110 2E
-#define HEX_DIGIT_00101111 2F
-#define HEX_DIGIT_00110000 30
-#define HEX_DIGIT_00110001 31
-#define HEX_DIGIT_00110010 32
-#define HEX_DIGIT_00110011 33
-#define HEX_DIGIT_00110100 34
-#define HEX_DIGIT_00110101 35
-#define HEX_DIGIT_00110110 36
-#define HEX_DIGIT_00110111 37
-#define HEX_DIGIT_00111000 38
-#define HEX_DIGIT_00111001 39
-#define HEX_DIGIT_00111010 3A
-#define HEX_DIGIT_00111011 3B
-#define HEX_DIGIT_00111100 3C
-#define HEX_DIGIT_00111101 3D
-#define HEX_DIGIT_00111110 3E
-#define HEX_DIGIT_00111111 3F
-#define HEX_DIGIT_01000000 40
-#define HEX_DIGIT_01000001 41
-#define HEX_DIGIT_01000010 42
-#define HEX_DIGIT_01000011 43
-#define HEX_DIGIT_01000100 44
-#define HEX_DIGIT_01000101 45
-#define HEX_DIGIT_01000110 46
-#define HEX_DIGIT_01000111 47
-#define HEX_DIGIT_01001000 48
-#define HEX_DIGIT_01001001 49
-#define HEX_DIGIT_01001010 4A
-#define HEX_DIGIT_01001011 4B
-#define HEX_DIGIT_01001100 4C
-#define HEX_DIGIT_01001101 4D
-#define HEX_DIGIT_01001110 4E
-#define HEX_DIGIT_01001111 4F
-#define HEX_DIGIT_01010000 50
-#define HEX_DIGIT_01010001 51
-#define HEX_DIGIT_01010010 52
-#define HEX_DIGIT_01010011 53
-#define HEX_DIGIT_01010100 54
-#define HEX_DIGIT_01010101 55
-#define HEX_DIGIT_01010110 56
-#define HEX_DIGIT_01010111 57
-#define HEX_DIGIT_01011000 58
-#define HEX_DIGIT_01011001 59
-#define HEX_DIGIT_01011010 5A
-#define HEX_DIGIT_01011011 5B
-#define HEX_DIGIT_01011100 5C
-#define HEX_DIGIT_01011101 5D
-#define HEX_DIGIT_01011110 5E
-#define HEX_DIGIT_01011111 5F
-#define HEX_DIGIT_01100000 60
-#define HEX_DIGIT_01100001 61
-#define HEX_DIGIT_01100010 62
-#define HEX_DIGIT_01100011 63
-#define HEX_DIGIT_01100100 64
-#define HEX_DIGIT_01100101 65
-#define HEX_DIGIT_01100110 66
-#define HEX_DIGIT_01100111 67
-#define HEX_DIGIT_01101000 68
-#define HEX_DIGIT_01101001 69
-#define HEX_DIGIT_01101010 6A
-#define HEX_DIGIT_01101011 6B
-#define HEX_DIGIT_01101100 6C
-#define HEX_DIGIT_01101101 6D
-#define HEX_DIGIT_01101110 6E
-#define HEX_DIGIT_01101111 6F
-#define HEX_DIGIT_01110000 70
-#define HEX_DIGIT_01110001 71
-#define HEX_DIGIT_01110010 72
-#define HEX_DIGIT_01110011 73
-#define HEX_DIGIT_01110100 74
-#define HEX_DIGIT_01110101 75
-#define HEX_DIGIT_01110110 76
-#define HEX_DIGIT_01110111 77
-#define HEX_DIGIT_01111000 78
-#define HEX_DIGIT_01111001 79
-#define HEX_DIGIT_01111010 7A
-#define HEX_DIGIT_01111011 7B
-#define HEX_DIGIT_01111100 7C
-#define HEX_DIGIT_01111101 7D
-#define HEX_DIGIT_01111110 7E
-#define HEX_DIGIT_01111111 7F
-#define HEX_DIGIT_10000000 80
-#define HEX_DIGIT_10000001 81
-#define HEX_DIGIT_10000010 82
-#define HEX_DIGIT_10000011 83
-#define HEX_DIGIT_10000100 84
-#define HEX_DIGIT_10000101 85
-#define HEX_DIGIT_10000110 86
-#define HEX_DIGIT_10000111 87
-#define HEX_DIGIT_10001000 88
-#define HEX_DIGIT_10001001 89
-#define HEX_DIGIT_10001010 8A
-#define HEX_DIGIT_10001011 8B
-#define HEX_DIGIT_10001100 8C
-#define HEX_DIGIT_10001101 8D
-#define HEX_DIGIT_10001110 8E
-#define HEX_DIGIT_10001111 8F
-#define HEX_DIGIT_10010000 90
-#define HEX_DIGIT_10010001 91
-#define HEX_DIGIT_10010010 92
-#define HEX_DIGIT_10010011 93
-#define HEX_DIGIT_10010100 94
-#define HEX_DIGIT_10010101 95
-#define HEX_DIGIT_10010110 96
-#define HEX_DIGIT_10010111 97
-#define HEX_DIGIT_10011000 98
-#define HEX_DIGIT_10011001 99
-#define HEX_DIGIT_10011010 9A
-#define HEX_DIGIT_10011011 9B
-#define HEX_DIGIT_10011100 9C
-#define HEX_DIGIT_10011101 9D
-#define HEX_DIGIT_10011110 9E
-#define HEX_DIGIT_10011111 9F
-#define HEX_DIGIT_10100000 A0
-#define HEX_DIGIT_10100001 A1
-#define HEX_DIGIT_10100010 A2
-#define HEX_DIGIT_10100011 A3
-#define HEX_DIGIT_10100100 A4
-#define HEX_DIGIT_10100101 A5
-#define HEX_DIGIT_10100110 A6
-#define HEX_DIGIT_10100111 A7
-#define HEX_DIGIT_10101000 A8
-#define HEX_DIGIT_10101001 A9
-#define HEX_DIGIT_10101010 AA
-#define HEX_DIGIT_10101011 AB
-#define HEX_DIGIT_10101100 AC
-#define HEX_DIGIT_10101101 AD
-#define HEX_DIGIT_10101110 AE
-#define HEX_DIGIT_10101111 AF
-#define HEX_DIGIT_10110000 B0
-#define HEX_DIGIT_10110001 B1
-#define HEX_DIGIT_10110010 B2
-#define HEX_DIGIT_10110011 B3
-#define HEX_DIGIT_10110100 B4
-#define HEX_DIGIT_10110101 B5
-#define HEX_DIGIT_10110110 B6
-#define HEX_DIGIT_10110111 B7
-#define HEX_DIGIT_10111000 B8
-#define HEX_DIGIT_10111001 B9
-#define HEX_DIGIT_10111010 BA
-#define HEX_DIGIT_10111011 BB
-#define HEX_DIGIT_10111100 BC
-#define HEX_DIGIT_10111101 BD
-#define HEX_DIGIT_10111110 BE
-#define HEX_DIGIT_10111111 BF
-#define HEX_DIGIT_11000000 C0
-#define HEX_DIGIT_11000001 C1
-#define HEX_DIGIT_11000010 C2
-#define HEX_DIGIT_11000011 C3
-#define HEX_DIGIT_11000100 C4
-#define HEX_DIGIT_11000101 C5
-#define HEX_DIGIT_11000110 C6
-#define HEX_DIGIT_11000111 C7
-#define HEX_DIGIT_11001000 C8
-#define HEX_DIGIT_11001001 C9
-#define HEX_DIGIT_11001010 CA
-#define HEX_DIGIT_11001011 CB
-#define HEX_DIGIT_11001100 CC
-#define HEX_DIGIT_11001101 CD
-#define HEX_DIGIT_11001110 CE
-#define HEX_DIGIT_11001111 CF
-#define HEX_DIGIT_11010000 D0
-#define HEX_DIGIT_11010001 D1
-#define HEX_DIGIT_11010010 D2
-#define HEX_DIGIT_11010011 D3
-#define HEX_DIGIT_11010100 D4
-#define HEX_DIGIT_11010101 D5
-#define HEX_DIGIT_11010110 D6
-#define HEX_DIGIT_11010111 D7
-#define HEX_DIGIT_11011000 D8
-#define HEX_DIGIT_11011001 D9
-#define HEX_DIGIT_11011010 DA
-#define HEX_DIGIT_11011011 DB
-#define HEX_DIGIT_11011100 DC
-#define HEX_DIGIT_11011101 DD
-#define HEX_DIGIT_11011110 DE
-#define HEX_DIGIT_11011111 DF
-#define HEX_DIGIT_11100000 E0
-#define HEX_DIGIT_11100001 E1
-#define HEX_DIGIT_11100010 E2
-#define HEX_DIGIT_11100011 E3
-#define HEX_DIGIT_11100100 E4
-#define HEX_DIGIT_11100101 E5
-#define HEX_DIGIT_11100110 E6
-#define HEX_DIGIT_11100111 E7
-#define HEX_DIGIT_11101000 E8
-#define HEX_DIGIT_11101001 E9
-#define HEX_DIGIT_11101010 EA
-#define HEX_DIGIT_11101011 EB
-#define HEX_DIGIT_11101100 EC
-#define HEX_DIGIT_11101101 ED
-#define HEX_DIGIT_11101110 EE
-#define HEX_DIGIT_11101111 EF
-#define HEX_DIGIT_11110000 F0
-#define HEX_DIGIT_11110001 F1
-#define HEX_DIGIT_11110010 F2
-#define HEX_DIGIT_11110011 F3
-#define HEX_DIGIT_11110100 F4
-#define HEX_DIGIT_11110101 F5
-#define HEX_DIGIT_11110110 F6
-#define HEX_DIGIT_11110111 F7
-#define HEX_DIGIT_11111000 F8
-#define HEX_DIGIT_11111001 F9
-#define HEX_DIGIT_11111010 FA
-#define HEX_DIGIT_11111011 FB
-#define HEX_DIGIT_11111100 FC
-#define HEX_DIGIT_11111101 FD
-#define HEX_DIGIT_11111110 FE
-#define HEX_DIGIT_11111111 FF
-
-#if 0
-#pragma mark == Debugging ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function CommonServicesTest
-
- @abstract Unit test.
-*/
-
-#if( DEBUG )
- #if( TARGET_LANGUAGE_C_LIKE )
- OSStatus CommonServicesTest( void );
- #endif
-#endif
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif // __COMMON_SERVICES__
diff --git a/src/libs/zeroconf/embed/DebugServices.c b/src/libs/zeroconf/embed/DebugServices.c
deleted file mode 100644
index 647329628c..0000000000
--- a/src/libs/zeroconf/embed/DebugServices.c
+++ /dev/null
@@ -1,3075 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-
- To Do:
-
- - Use StackWalk on Windows to optionally print stack frames.
-*/
-
-#if 0
-#pragma mark == Includes ==
-#endif
-
-//===========================================================================================================================
-// Includes
-//===========================================================================================================================
-
-#if( !KERNEL )
- #include <ctype.h>
- #include <stdio.h>
- #include <string.h>
-#endif
-
-#include "CommonServices.h"
-
-#include "DebugServices.h"
-
-#if( DEBUG )
-
-#if( TARGET_OS_VXWORKS )
- #include "intLib.h"
-#endif
-
-#if( TARGET_OS_WIN32 )
- #include <time.h>
-
- #if( !TARGET_OS_WINDOWS_CE )
- #include <fcntl.h>
- #include <io.h>
- #endif
-#endif
-
-#if( DEBUG_IDEBUG_ENABLED && TARGET_API_MAC_OSX_KERNEL )
- #include <IOKit/IOLib.h>
-#endif
-
-// If MDNS_DEBUGMSGS is defined (even if defined 0), it is aware of mDNS and it is probably safe to include mDNSEmbeddedAPI.h.
-
-#if( defined( MDNS_DEBUGMSGS ) )
- #include "mDNSEmbeddedAPI.h"
-#endif
-
-#if 0
-#pragma mark == Macros ==
-#endif
-
-//===========================================================================================================================
-// Macros
-//===========================================================================================================================
-
-#define DebugIsPrint( C ) ( ( ( C ) >= 0x20 ) && ( ( C ) <= 0x7E ) )
-
-#if 0
-#pragma mark == Prototypes ==
-#endif
-
-//===========================================================================================================================
-// Prototypes
-//===========================================================================================================================
-
-static OSStatus DebugPrint( DebugLevel inLevel, char *inData, size_t inSize );
-
-// fprintf
-
-#if( DEBUG_FPRINTF_ENABLED )
- static OSStatus DebugFPrintFInit( DebugOutputTypeFlags inFlags, const char *inFilename );
- static void DebugFPrintFPrint( char *inData, size_t inSize );
-#endif
-
-// iDebug (Mac OS X user and kernel)
-
-#if( DEBUG_IDEBUG_ENABLED )
- static OSStatus DebugiDebugInit( void );
- static void DebugiDebugPrint( char *inData, size_t inSize );
-#endif
-
-// kprintf (Mac OS X Kernel)
-
-#if( DEBUG_KPRINTF_ENABLED )
- static void DebugKPrintFPrint( char *inData, size_t inSize );
-#endif
-
-// Mac OS X IOLog (Mac OS X Kernel)
-
-#if( DEBUG_MAC_OS_X_IOLOG_ENABLED )
- static void DebugMacOSXIOLogPrint( char *inData, size_t inSize );
-#endif
-
-// Mac OS X Log
-
-#if( TARGET_OS_MAC )
- static OSStatus DebugMacOSXLogInit( void );
- static void DebugMacOSXLogPrint( char *inData, size_t inSize );
-#endif
-
-// Windows Debugger
-
-#if( TARGET_OS_WIN32 )
- static void DebugWindowsDebuggerPrint( char *inData, size_t inSize );
-#endif
-
-// Windows Event Log
-
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- static OSStatus DebugWindowsEventLogInit( const char *inName, HMODULE inModule );
- static void DebugWindowsEventLogPrint( DebugLevel inLevel, char *inData, size_t inSize );
-#endif
-
-// DebugLib support
-
-#if( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
- static pascal void
- DebugAssertOutputHandler(
- OSType inComponentSignature,
- UInt32 inOptions,
- const char * inAssertionString,
- const char * inExceptionString,
- const char * inErrorString,
- const char * inFileName,
- long inLineNumber,
- void * inValue,
- ConstStr255Param inOutputMsg );
-#endif
-
-// Utilities
-
-static char * DebugNumVersionToString( uint32_t inVersion, char *inString );
-
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- static void DebugWinEnableConsole( void );
-#endif
-
-#if( TARGET_OS_WIN32 )
- static TCHAR *
- DebugWinCharToTCharString(
- const char * inCharString,
- size_t inCharCount,
- TCHAR * outTCharString,
- size_t inTCharCountMax,
- size_t * outTCharCount );
-#endif
-
-#if 0
-#pragma mark == Globals ==
-#endif
-
-//===========================================================================================================================
-// Private Globals
-//===========================================================================================================================
-
-#if( TARGET_OS_VXWORKS )
- // TCP States for inetstatShow.
-
- extern char ** pTcpstates; // defined in tcpLib.c
-
- const char * kDebugTCPStates[] =
- {
- "(0) TCPS_CLOSED",
- "(1) TCPS_LISTEN",
- "(2) TCPS_SYN_SENT",
- "(3) TCPS_SYN_RECEIVED",
- "(4) TCPS_ESTABLISHED",
- "(5) TCPS_CLOSE_WAIT",
- "(6) TCPS_FIN_WAIT_1",
- "(7) TCPS_CLOSING",
- "(8) TCPS_LAST_ACK",
- "(9) TCPS_FIN_WAIT_2",
- "(10) TCPS_TIME_WAIT",
- };
-#endif
-
-// General
-
-static bool gDebugInitialized = false;
-static DebugOutputType gDebugOutputType = kDebugOutputTypeNone;
-static DebugLevel gDebugPrintLevelMin = kDebugLevelInfo;
-static DebugLevel gDebugPrintLevelMax = kDebugLevelMax;
-static DebugLevel gDebugBreakLevel = kDebugLevelAssert;
-#if( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
- static DebugAssertOutputHandlerUPP gDebugAssertOutputHandlerUPP = NULL;
-#endif
-
-// Custom
-
-static DebugOutputFunctionPtr gDebugCustomOutputFunction = NULL;
-static void * gDebugCustomOutputContext = NULL;
-
-// fprintf
-
-#if( DEBUG_FPRINTF_ENABLED )
- static FILE * gDebugFPrintFFile = NULL;
-#endif
-
-// MacOSXLog
-
-#if( TARGET_OS_MAC )
- typedef int ( *DebugMacOSXLogFunctionPtr )( const char *inFormat, ... );
-
- static DebugMacOSXLogFunctionPtr gDebugMacOSXLogFunction = NULL;
-#endif
-
-// WindowsEventLog
-
-
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- static HANDLE gDebugWindowsEventLogEventSource = NULL;
-#endif
-
-#if 0
-#pragma mark -
-#pragma mark == General ==
-#endif
-
-//===========================================================================================================================
-// DebugInitialize
-//===========================================================================================================================
-
-DEBUG_EXPORT OSStatus DebugInitialize( DebugOutputType inType, ... )
-{
- OSStatus err;
- DebugOutputType type;
- va_list args;
-
- va_start( args, inType );
-
-#if( TARGET_OS_VXWORKS )
- // Set up the TCP state strings if they are not already set up by VxWorks (normally not set up for some reason).
-
- if( !pTcpstates )
- {
- pTcpstates = (char **) kDebugTCPStates;
- }
-#endif
-
- // Set up DebugLib stuff (if building with Debugging.h).
-
-#if( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
- if( !gDebugAssertOutputHandlerUPP )
- {
- gDebugAssertOutputHandlerUPP = NewDebugAssertOutputHandlerUPP( DebugAssertOutputHandler );
- check( gDebugAssertOutputHandlerUPP );
- if( gDebugAssertOutputHandlerUPP )
- {
- InstallDebugAssertOutputHandler( gDebugAssertOutputHandlerUPP );
- }
- }
-#endif
-
- // Pre-process meta-output kind to pick an appropriate output kind for the platform.
-
- type = inType;
- if( type == kDebugOutputTypeMetaConsole )
- {
- #if( TARGET_OS_MAC )
- type = kDebugOutputTypeMacOSXLog;
- #elif( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- #if( DEBUG_FPRINTF_ENABLED )
- type = kDebugOutputTypeFPrintF;
- #else
- type = kDebugOutputTypeWindowsDebugger;
- #endif
- #elif( TARGET_API_MAC_OSX_KERNEL )
- #if( DEBUG_MAC_OS_X_IOLOG_ENABLED )
- type = kDebugOutputTypeMacOSXIOLog;
- #elif( DEBUG_IDEBUG_ENABLED )
- type = kDebugOutputTypeiDebug;
- #elif( DEBUG_KPRINTF_ENABLED )
- type = kDebugOutputTypeKPrintF;
- #endif
- #elif( TARGET_OS_VXWORKS )
- #if( DEBUG_FPRINTF_ENABLED )
- type = kDebugOutputTypeFPrintF;
- #else
- #error target is VxWorks, but fprintf output is disabled
- #endif
- #else
- #if( DEBUG_FPRINTF_ENABLED )
- type = kDebugOutputTypeFPrintF;
- #endif
- #endif
- }
-
- // Process output kind.
-
- gDebugOutputType = type;
- switch( type )
- {
- case kDebugOutputTypeNone:
- err = kNoErr;
- break;
-
- case kDebugOutputTypeCustom:
- gDebugCustomOutputFunction = va_arg( args, DebugOutputFunctionPtr );
- gDebugCustomOutputContext = va_arg( args, void * );
- err = kNoErr;
- break;
-
-#if( DEBUG_FPRINTF_ENABLED )
- case kDebugOutputTypeFPrintF:
- if( inType == kDebugOutputTypeMetaConsole )
- {
- err = DebugFPrintFInit( kDebugOutputTypeFlagsStdErr, NULL );
- }
- else
- {
- DebugOutputTypeFlags flags;
- const char * filename;
-
- flags = (DebugOutputTypeFlags) va_arg( args, unsigned int );
- if( ( flags & kDebugOutputTypeFlagsTypeMask ) == kDebugOutputTypeFlagsFile )
- {
- filename = va_arg( args, const char * );
- }
- else
- {
- filename = NULL;
- }
- err = DebugFPrintFInit( flags, filename );
- }
- break;
-#endif
-
-#if( DEBUG_IDEBUG_ENABLED )
- case kDebugOutputTypeiDebug:
- err = DebugiDebugInit();
- break;
-#endif
-
-#if( DEBUG_KPRINTF_ENABLED )
- case kDebugOutputTypeKPrintF:
- err = kNoErr;
- break;
-#endif
-
-#if( DEBUG_MAC_OS_X_IOLOG_ENABLED )
- case kDebugOutputTypeMacOSXIOLog:
- err = kNoErr;
- break;
-#endif
-
-#if( TARGET_OS_MAC )
- case kDebugOutputTypeMacOSXLog:
- err = DebugMacOSXLogInit();
- break;
-#endif
-
-#if( TARGET_OS_WIN32 )
- case kDebugOutputTypeWindowsDebugger:
- err = kNoErr;
- break;
-#endif
-
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- case kDebugOutputTypeWindowsEventLog:
- {
- const char * name;
- HMODULE module;
-
- name = va_arg( args, const char * );
- module = va_arg( args, HMODULE );
- err = DebugWindowsEventLogInit( name, module );
- }
- break;
-#endif
-
- default:
- err = kParamErr;
- goto exit;
- }
- gDebugInitialized = true;
-
-exit:
- va_end( args );
- return( err );
-}
-
-//===========================================================================================================================
-// DebugFinalize
-//===========================================================================================================================
-
-DEBUG_EXPORT void DebugFinalize( void )
-{
-#if( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
- check( gDebugAssertOutputHandlerUPP );
- if( gDebugAssertOutputHandlerUPP )
- {
- InstallDebugAssertOutputHandler( NULL );
- DisposeDebugAssertOutputHandlerUPP( gDebugAssertOutputHandlerUPP );
- gDebugAssertOutputHandlerUPP = NULL;
- }
-#endif
-}
-
-//===========================================================================================================================
-// DebugGetProperty
-//===========================================================================================================================
-
-DEBUG_EXPORT OSStatus DebugGetProperty( DebugPropertyTag inTag, ... )
-{
- OSStatus err;
- va_list args;
- DebugLevel * level;
-
- va_start( args, inTag );
- switch( inTag )
- {
- case kDebugPropertyTagPrintLevelMin:
- level = va_arg( args, DebugLevel * );
- *level = gDebugPrintLevelMin;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagPrintLevelMax:
- level = va_arg( args, DebugLevel * );
- *level = gDebugPrintLevelMax;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagBreakLevel:
- level = va_arg( args, DebugLevel * );
- *level = gDebugBreakLevel;
- err = kNoErr;
- break;
-
- default:
- err = kUnsupportedErr;
- break;
- }
- va_end( args );
- return( err );
-}
-
-//===========================================================================================================================
-// DebugSetProperty
-//===========================================================================================================================
-
-DEBUG_EXPORT OSStatus DebugSetProperty( DebugPropertyTag inTag, ... )
-{
- OSStatus err;
- va_list args;
- DebugLevel level;
-
- va_start( args, inTag );
- switch( inTag )
- {
- case kDebugPropertyTagPrintLevelMin:
- level = va_arg( args, DebugLevel );
- gDebugPrintLevelMin = level;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagPrintLevelMax:
- level = va_arg( args, DebugLevel );
- gDebugPrintLevelMax = level;
- err = kNoErr;
- break;
-
- case kDebugPropertyTagBreakLevel:
- level = va_arg( args, DebugLevel );
- gDebugBreakLevel = level;
- err = kNoErr;
- break;
-
- default:
- err = kUnsupportedErr;
- break;
- }
- va_end( args );
- return( err );
-}
-
-#if 0
-#pragma mark -
-#pragma mark == Output ==
-#endif
-
-//===========================================================================================================================
-// DebugPrintF
-//===========================================================================================================================
-
-DEBUG_EXPORT size_t DebugPrintF( DebugLevel inLevel, const char *inFormat, ... )
-{
- va_list args;
- size_t n;
-
- // Skip if the level is not in the enabled range..
-
- if( ( inLevel < gDebugPrintLevelMin ) || ( inLevel > gDebugPrintLevelMax ) )
- {
- n = 0;
- goto exit;
- }
-
- va_start( args, inFormat );
- n = DebugPrintFVAList( inLevel, inFormat, args );
- va_end( args );
-
-exit:
- return( n );
-}
-
-//===========================================================================================================================
-// DebugPrintFVAList
-//===========================================================================================================================
-
-DEBUG_EXPORT size_t DebugPrintFVAList( DebugLevel inLevel, const char *inFormat, va_list inArgs )
-{
- size_t n;
- char buffer[ 512 ];
-
- // Skip if the level is not in the enabled range..
-
- if( ( inLevel < gDebugPrintLevelMin ) || ( inLevel > gDebugPrintLevelMax ) )
- {
- n = 0;
- goto exit;
- }
-
- n = DebugSNPrintFVAList( buffer, sizeof( buffer ), inFormat, inArgs );
- DebugPrint( inLevel, buffer, (size_t) n );
-
-exit:
- return( n );
-}
-
-//===========================================================================================================================
-// DebugPrint
-//===========================================================================================================================
-
-static OSStatus DebugPrint( DebugLevel inLevel, char *inData, size_t inSize )
-{
- OSStatus err;
-
- // Skip if the level is not in the enabled range..
-
- if( ( inLevel < gDebugPrintLevelMin ) || ( inLevel > gDebugPrintLevelMax ) )
- {
- err = kRangeErr;
- goto exit;
- }
-
- // Printing is not safe at interrupt time so check for this and warn with an interrupt safe mechanism (if available).
-
- if( DebugTaskLevel() & kDebugInterruptLevelMask )
- {
- #if( TARGET_OS_VXWORKS )
- logMsg( "\ncannot print at interrupt time\n\n", 1, 2, 3, 4, 5, 6 );
- #endif
-
- err = kExecutionStateErr;
- goto exit;
- }
-
- // Initialize the debugging library if it hasn't already been initialized (allows for zero-config usage).
-
- if( !gDebugInitialized )
- {
- debug_initialize( kDebugOutputTypeMetaConsole );
- }
-
- // Print based on the current output type.
-
- switch( gDebugOutputType )
- {
- case kDebugOutputTypeNone:
- break;
-
- case kDebugOutputTypeCustom:
- if( gDebugCustomOutputFunction )
- {
- gDebugCustomOutputFunction( inData, inSize, gDebugCustomOutputContext );
- }
- break;
-
-#if( DEBUG_FPRINTF_ENABLED )
- case kDebugOutputTypeFPrintF:
- DebugFPrintFPrint( inData, inSize );
- break;
-#endif
-
-#if( DEBUG_IDEBUG_ENABLED )
- case kDebugOutputTypeiDebug:
- DebugiDebugPrint( inData, inSize );
- break;
-#endif
-
-#if( DEBUG_KPRINTF_ENABLED )
- case kDebugOutputTypeKPrintF:
- DebugKPrintFPrint( inData, inSize );
- break;
-#endif
-
-#if( DEBUG_MAC_OS_X_IOLOG_ENABLED )
- case kDebugOutputTypeMacOSXIOLog:
- DebugMacOSXIOLogPrint( inData, inSize );
- break;
-#endif
-
-#if( TARGET_OS_MAC )
- case kDebugOutputTypeMacOSXLog:
- DebugMacOSXLogPrint( inData, inSize );
- break;
-#endif
-
-#if( TARGET_OS_WIN32 )
- case kDebugOutputTypeWindowsDebugger:
- DebugWindowsDebuggerPrint( inData, inSize );
- break;
-#endif
-
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- case kDebugOutputTypeWindowsEventLog:
- DebugWindowsEventLogPrint( inLevel, inData, inSize );
- break;
-#endif
-
- default:
- break;
- }
- err = kNoErr;
-
-exit:
- return( err );
-}
-
-//===========================================================================================================================
-// DebugPrintAssert
-//
-// Warning: This routine relies on several of the strings being string constants that will exist forever because the
-// underlying logMsg API that does the printing is asynchronous so it cannot use temporary/stack-based
-// pointer variables (e.g. local strings). The debug macros that invoke this function only use constant
-// constant strings, but if this function is invoked directly from other places, it must use constant strings.
-//===========================================================================================================================
-
-DEBUG_EXPORT void
- DebugPrintAssert(
- int_least32_t inErrorCode,
- const char * inAssertString,
- const char * inMessage,
- const char * inFilename,
- int_least32_t inLineNumber,
- const char * inFunction )
-{
- // Skip if the level is not in the enabled range..
-
- if( ( kDebugLevelAssert < gDebugPrintLevelMin ) || ( kDebugLevelAssert > gDebugPrintLevelMax ) )
- {
- return;
- }
-
- if( inErrorCode != 0 )
- {
- DebugPrintF(
- kDebugLevelAssert,
- "\n"
- "[ASSERT] error: %ld (%m)\n"
- "[ASSERT] where: \"%s\", line %ld, \"%s\"\n"
- "\n",
- inErrorCode, inErrorCode,
- inFilename ? inFilename : "",
- inLineNumber,
- inFunction ? inFunction : "" );
- }
- else
- {
- DebugPrintF(
- kDebugLevelAssert,
- "\n"
- "[ASSERT] assert: \"%s\" %s\n"
- "[ASSERT] where: \"%s\", line %ld, \"%s\"\n"
- "\n",
- inAssertString ? inAssertString : "",
- inMessage ? inMessage : "",
- inFilename ? inFilename : "",
- inLineNumber,
- inFunction ? inFunction : "" );
- }
-
- // Break into the debugger if enabled.
-
- #if( TARGET_OS_WIN32 )
- if( gDebugBreakLevel <= kDebugLevelAssert )
- {
- if( IsDebuggerPresent() )
- {
- DebugBreak();
- }
- }
- #endif
-}
-
-#if 0
-#pragma mark -
-#endif
-
-#if( DEBUG_FPRINTF_ENABLED )
-//===========================================================================================================================
-// DebugFPrintFInit
-//===========================================================================================================================
-
-static OSStatus DebugFPrintFInit( DebugOutputTypeFlags inFlags, const char *inFilename )
-{
- OSStatus err;
- DebugOutputTypeFlags typeFlags;
-
- typeFlags = inFlags & kDebugOutputTypeFlagsTypeMask;
- if( typeFlags == kDebugOutputTypeFlagsStdOut )
- {
- #if( TARGET_OS_WIN32 )
- DebugWinEnableConsole();
- #endif
-
- gDebugFPrintFFile = stdout;
- }
- else if( typeFlags == kDebugOutputTypeFlagsStdErr )
- {
- #if( TARGET_OS_WIN32 )
- DebugWinEnableConsole();
- #endif
-
- gDebugFPrintFFile = stdout;
- }
- else if( typeFlags == kDebugOutputTypeFlagsFile )
- {
- require_action_quiet( inFilename && ( *inFilename != '\0' ), exit, err = kOpenErr );
-
- gDebugFPrintFFile = fopen( inFilename, "a" );
- require_action_quiet( gDebugFPrintFFile, exit, err = kOpenErr );
- }
- else
- {
- err = kParamErr;
- goto exit;
- }
- err = kNoErr;
-
-exit:
- return( err );
-}
-
-//===========================================================================================================================
-// DebugFPrintFPrint
-//===========================================================================================================================
-
-static void DebugFPrintFPrint( char *inData, size_t inSize )
-{
- char * p;
- char * q;
-
- // Convert \r to \n. fprintf will interpret \n and convert to whatever is appropriate for the platform.
-
- p = inData;
- q = p + inSize;
- while( p < q )
- {
- if( *p == '\r' )
- {
- *p = '\n';
- }
- ++p;
- }
-
- // Write the data and flush.
-
- if( gDebugFPrintFFile )
- {
- fprintf( gDebugFPrintFFile, "%.*s", (int) inSize, inData );
- fflush( gDebugFPrintFFile );
- }
-}
-#endif // DEBUG_FPRINTF_ENABLED
-
-#if( DEBUG_IDEBUG_ENABLED )
-//===========================================================================================================================
-// DebugiDebugInit
-//===========================================================================================================================
-
-static OSStatus DebugiDebugInit( void )
-{
- OSStatus err;
-
- #if( TARGET_API_MAC_OSX_KERNEL )
-
- extern uint32_t * _giDebugReserved1;
-
- // Emulate the iDebugSetOutputType macro in iDebugServices.h.
- // Note: This is not thread safe, but neither is iDebugServices.h nor iDebugKext.
-
- if( !_giDebugReserved1 )
- {
- _giDebugReserved1 = (uint32_t *) IOMalloc( sizeof( uint32_t ) );
- require_action_quiet( _giDebugReserved1, exit, err = kNoMemoryErr );
- }
- *_giDebugReserved1 = 0x00010000U;
- err = kNoErr;
-exit:
- #else
-
- __private_extern__ void iDebugSetOutputTypeInternal( uint32_t inType );
-
- iDebugSetOutputTypeInternal( 0x00010000U );
- err = kNoErr;
-
- #endif
-
- return( err );
-}
-
-//===========================================================================================================================
-// DebugiDebugPrint
-//===========================================================================================================================
-
-static void DebugiDebugPrint( char *inData, size_t inSize )
-{
- #if( TARGET_API_MAC_OSX_KERNEL )
-
- // Locally declared here so we do not need to include iDebugKext.h.
- // Note: IOKit uses a global namespace for all code and only a partial link occurs at build time. When the
- // KEXT is loaded, the runtime linker will link in this extern'd symbol (assuming iDebug is present).
- // _giDebugLogInternal is actually part of IOKit proper so this should link even if iDebug is not present.
-
- typedef void ( *iDebugLogFunctionPtr )( uint32_t inLevel, uint32_t inTag, const char *inFormat, ... );
-
- extern iDebugLogFunctionPtr _giDebugLogInternal;
-
- if( _giDebugLogInternal )
- {
- _giDebugLogInternal( 0, 0, "%.*s", (int) inSize, inData );
- }
-
- #else
-
- __private_extern__ void iDebugLogInternal( uint32_t inLevel, uint32_t inTag, const char *inFormat, ... );
-
- iDebugLogInternal( 0, 0, "%.*s", (int) inSize, inData );
-
- #endif
-}
-#endif
-
-#if( DEBUG_KPRINTF_ENABLED )
-//===========================================================================================================================
-// DebugKPrintFPrint
-//===========================================================================================================================
-
-static void DebugKPrintFPrint( char *inData, size_t inSize )
-{
- extern void kprintf( const char *inFormat, ... );
-
- kprintf( "%.*s", (int) inSize, inData );
-}
-#endif
-
-#if( DEBUG_MAC_OS_X_IOLOG_ENABLED )
-//===========================================================================================================================
-// DebugMacOSXIOLogPrint
-//===========================================================================================================================
-
-static void DebugMacOSXIOLogPrint( char *inData, size_t inSize )
-{
- extern void IOLog( const char *inFormat, ... );
-
- IOLog( "%.*s", (int) inSize, inData );
-}
-#endif
-
-#if( TARGET_OS_MAC )
-//===========================================================================================================================
-// DebugMacOSXLogInit
-//===========================================================================================================================
-
-static OSStatus DebugMacOSXLogInit( void )
-{
- OSStatus err;
- CFStringRef path;
- CFURLRef url;
- CFBundleRef bundle;
- CFStringRef functionName;
- void * functionPtr;
-
- bundle = NULL;
-
- // Create a bundle reference for System.framework.
-
- path = CFSTR( "/System/Library/Frameworks/System.framework" );
- url = CFURLCreateWithFileSystemPath( NULL, path, kCFURLPOSIXPathStyle, true );
- require_action_quiet( url, exit, err = memFullErr );
-
- bundle = CFBundleCreate( NULL, url );
- CFRelease( url );
- require_action_quiet( bundle, exit, err = memFullErr );
-
- // Get a ptr to the system's "printf" function from System.framework.
-
- functionName = CFSTR( "printf" );
- functionPtr = CFBundleGetFunctionPointerForName( bundle, functionName );
- require_action_quiet( functionPtr, exit, err = memFullErr );
-
- // Success! Note: The bundle cannot be released because it would invalidate the function ptr.
-
- gDebugMacOSXLogFunction = (DebugMacOSXLogFunctionPtr) functionPtr;
- bundle = NULL;
- err = noErr;
-
-exit:
- if( bundle )
- {
- CFRelease( bundle );
- }
- return( err );
-}
-
-//===========================================================================================================================
-// DebugMacOSXLogPrint
-//===========================================================================================================================
-
-static void DebugMacOSXLogPrint( char *inData, size_t inSize )
-{
- if( gDebugMacOSXLogFunction )
- {
- gDebugMacOSXLogFunction( "%.*s", (int) inSize, inData );
- }
-}
-#endif
-
-#if( TARGET_OS_WIN32 )
-//===========================================================================================================================
-// DebugWindowsDebuggerPrint
-//===========================================================================================================================
-
-void DebugWindowsDebuggerPrint( char *inData, size_t inSize )
-{
- TCHAR buffer[ 512 ];
- const char * src;
- const char * end;
- TCHAR * dst;
- char c;
-
- // Copy locally and null terminate the string. This also converts from char to TCHAR in case we are
- // building with UNICODE enabled since the input is always char. Also convert \r to \n in the process.
-
- src = inData;
- if( inSize >= sizeof_array( buffer ) )
- {
- inSize = sizeof_array( buffer ) - 1;
- }
- end = src + inSize;
- dst = buffer;
- while( src < end )
- {
- c = *src++;
- if( c == '\r' )
- {
- c = '\n';
- }
- *dst++ = (TCHAR) c;
- }
- *dst = 0;
-
- // Print out the string to the debugger.
-
- OutputDebugString( buffer );
-}
-#endif
-
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
-//===========================================================================================================================
-// DebugWindowsEventLogInit
-//===========================================================================================================================
-
-static OSStatus DebugWindowsEventLogInit( const char *inName, HMODULE inModule )
-{
- OSStatus err;
- HKEY key;
- TCHAR name[ 128 ];
- const char * src;
- TCHAR path[ MAX_PATH ];
- size_t size;
- DWORD typesSupported;
- DWORD n;
-
- key = NULL;
-
- // Use a default name if needed then convert the name to TCHARs so it works on ANSI or Unicode builds.
-
- if( !inName || ( *inName == '\0' ) )
- {
- inName = "DefaultApp";
- }
- DebugWinCharToTCharString( inName, kSizeCString, name, sizeof( name ), NULL );
-
- // Build the path string using the fixed registry path and app name.
-
- src = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\";
- DebugWinCharToTCharString( src, kSizeCString, path, sizeof_array( path ), &size );
- DebugWinCharToTCharString( inName, kSizeCString, path + size, sizeof_array( path ) - size, NULL );
-
- // Add/Open the source name as a sub-key under the Application key in the EventLog registry key.
-
- err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL );
- require_noerr_quiet( err, exit );
-
- // Set the path in the EventMessageFile subkey. Add 1 to the TCHAR count to include the null terminator.
-
- n = GetModuleFileName( inModule, path, sizeof_array( path ) );
- err = translate_errno( n > 0, (OSStatus) GetLastError(), kParamErr );
- require_noerr_quiet( err, exit );
- n += 1;
- n *= sizeof( TCHAR );
-
- err = RegSetValueEx( key, TEXT( "EventMessageFile" ), 0, REG_EXPAND_SZ, (const LPBYTE) path, n );
- require_noerr_quiet( err, exit );
-
- // Set the supported event types in the TypesSupported subkey.
-
- typesSupported = EVENTLOG_SUCCESS | EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE |
- EVENTLOG_AUDIT_SUCCESS | EVENTLOG_AUDIT_FAILURE;
- err = RegSetValueEx( key, TEXT( "TypesSupported" ), 0, REG_DWORD, (const LPBYTE) &typesSupported, sizeof( DWORD ) );
- require_noerr_quiet( err, exit );
-
- // Set up the event source.
-
- gDebugWindowsEventLogEventSource = RegisterEventSource( NULL, name );
- err = translate_errno( gDebugWindowsEventLogEventSource, (OSStatus) GetLastError(), kParamErr );
- require_noerr_quiet( err, exit );
-
-exit:
- if( key )
- {
- RegCloseKey( key );
- }
- return( err );
-}
-
-//===========================================================================================================================
-// DebugWindowsEventLogPrint
-//===========================================================================================================================
-
-static void DebugWindowsEventLogPrint( DebugLevel inLevel, char *inData, size_t inSize )
-{
- WORD type;
- TCHAR buffer[ 512 ];
- const char * src;
- const char * end;
- TCHAR * dst;
- char c;
- const TCHAR * array[ 1 ];
-
- // Map the debug level to a Windows EventLog type.
-
- if( inLevel <= kDebugLevelNotice )
- {
- type = EVENTLOG_INFORMATION_TYPE;
- }
- else if( inLevel <= kDebugLevelWarning )
- {
- type = EVENTLOG_WARNING_TYPE;
- }
- else
- {
- type = EVENTLOG_ERROR_TYPE;
- }
-
- // Copy locally and null terminate the string. This also converts from char to TCHAR in case we are
- // building with UNICODE enabled since the input is always char. Also convert \r to \n in the process.
-
- src = inData;
- if( inSize >= sizeof_array( buffer ) )
- {
- inSize = sizeof_array( buffer ) - 1;
- }
- end = src + inSize;
- dst = buffer;
- while( src < end )
- {
- c = *src++;
- if( c == '\r' )
- {
- c = '\n';
- }
- *dst++ = (TCHAR) c;
- }
- *dst = 0;
-
- // Add the the string to the event log.
-
- array[ 0 ] = buffer;
- if( gDebugWindowsEventLogEventSource )
- {
- ReportEvent( gDebugWindowsEventLogEventSource, type, 0, 0x20000001L, NULL, 1, 0, array, NULL );
- }
-}
-#endif // TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE
-
-#if( DEBUG_CORE_SERVICE_ASSERTS_ENABLED )
-//===========================================================================================================================
-// DebugAssertOutputHandler
-//===========================================================================================================================
-
-static pascal void
- DebugAssertOutputHandler(
- OSType inComponentSignature,
- UInt32 inOptions,
- const char * inAssertString,
- const char * inExceptionString,
- const char * inErrorString,
- const char * inFileName,
- long inLineNumber,
- void * inValue,
- ConstStr255Param inOutputMsg )
-{
- DEBUG_UNUSED( inComponentSignature );
- DEBUG_UNUSED( inOptions );
- DEBUG_UNUSED( inExceptionString );
- DEBUG_UNUSED( inValue );
- DEBUG_UNUSED( inOutputMsg );
-
- DebugPrintAssert( 0, inAssertString, inErrorString, inFileName, (int_least32_t) inLineNumber, "" );
-}
-#endif
-
-#if 0
-#pragma mark -
-#pragma mark == Utilities ==
-#endif
-
-//===========================================================================================================================
-// DebugSNPrintF
-//
-// Stolen from mDNS.c's mDNS_snprintf/mDNS_vsnprintf with the following changes:
-//
-// Changed names to avoid name collisions with the mDNS versions.
-// Changed types to standard C types since mDNSEmbeddedAPI.h may not be available.
-// Conditionalized mDNS stuff so it can be used with or with mDNSEmbeddedAPI.h.
-// Added 64-bit support for %d (%lld), %i (%lli), %u (%llu), %o (%llo), %x (%llx), and %b (%llb).
-// Added %@ - Cocoa/CoreFoundation object. Param is the object. Strings are used directly. Others use CFCopyDescription.
-// Added %.8a - FIbre Channel address. Arg=ptr to address.
-// Added %##a - IPv4 (if AF_INET defined) or IPv6 (if AF_INET6 defined) sockaddr. Arg=ptr to sockaddr.
-// Added %b - Binary representation of integer (e.g. 01101011). Modifiers and arg=the same as %d, %x, etc.
-// Added %C - Mac-style FourCharCode (e.g. 'APPL'). Arg=32-bit value to print as a Mac-style FourCharCode.
-// Added %H - Hex Dump (e.g. "\x6b\xa7" -> "6B A7"). 1st arg=ptr, 2nd arg=size, 3rd arg=max size.
-// Added %#H - Hex Dump & ASCII (e.g. "\x41\x62" -> "6B A7 'Ab'"). 1st arg=ptr, 2nd arg=size, 3rd arg=max size.
-// Added %m - Error Message (e.g. 0 -> "kNoErr"). Modifiers and error code args are the same as %d, %x, etc.
-// Added %S - UTF-16 string. Host order if no BOM. Precision is UTF-16 char count. BOM counts in any precision. Arg=ptr.
-// Added %#S - Big Endian UTF-16 string (unless BOM overrides). Otherwise the same as %S.
-// Added %##S - Little Endian UTF-16 string (unless BOM overrides). Otherwise the same as %S.
-// Added %U - Universally Unique Identifier (UUID) (e.g. 6ba7b810-9dad-11d1-80b4-00c04fd430c8). Arg=ptr to 16-byte UUID.
-//===========================================================================================================================
-
-DEBUG_EXPORT size_t DebugSNPrintF(char *sbuffer, size_t buflen, const char *fmt, ...)
- {
- size_t length;
-
- va_list ptr;
- va_start(ptr,fmt);
- length = DebugSNPrintFVAList(sbuffer, buflen, fmt, ptr);
- va_end(ptr);
-
- return(length);
- }
-
-//===========================================================================================================================
-// DebugSNPrintFVAList - va_list version of DebugSNPrintF. See DebugSNPrintF for more info.
-//===========================================================================================================================
-
-DEBUG_EXPORT size_t DebugSNPrintFVAList(char *sbuffer, size_t buflen, const char *fmt, va_list arg)
- {
- static const struct DebugSNPrintF_format
- {
- unsigned leftJustify : 1;
- unsigned forceSign : 1;
- unsigned zeroPad : 1;
- unsigned havePrecision : 1;
- unsigned hSize : 1;
- char lSize;
- char altForm;
- char sign; // +, - or space
- unsigned int fieldWidth;
- unsigned int precision;
- } DebugSNPrintF_format_default = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
- size_t nwritten = 0;
- int c;
- if (buflen == 0) return(0);
- buflen--; // Pre-reserve one space in the buffer for the terminating nul
- if (buflen == 0) goto exit;
-
- for (c = *fmt; c != 0; c = *++fmt)
- {
- if (c != '%')
- {
- *sbuffer++ = (char)c;
- if (++nwritten >= buflen) goto exit;
- }
- else
- {
- size_t i=0, j;
- // The mDNS Vsprintf Argument Conversion Buffer is used as a temporary holding area for
- // generating decimal numbers, hexdecimal numbers, IP addresses, domain name strings, etc.
- // The size needs to be enough for a 256-byte domain name plus some error text.
- #define mDNS_VACB_Size 300
- char mDNS_VACB[mDNS_VACB_Size];
- #define mDNS_VACB_Lim (&mDNS_VACB[mDNS_VACB_Size])
- #define mDNS_VACB_Remain(s) ((size_t)(mDNS_VACB_Lim - s))
- char *s = mDNS_VACB_Lim;
- const char *digits = "0123456789ABCDEF";
- struct DebugSNPrintF_format F = DebugSNPrintF_format_default;
-
- for(;;) // decode flags
- {
- c = *++fmt;
- if (c == '-') F.leftJustify = 1;
- else if (c == '+') F.forceSign = 1;
- else if (c == ' ') F.sign = ' ';
- else if (c == '#') F.altForm++;
- else if (c == '0') F.zeroPad = 1;
- else break;
- }
-
- if (c == '*') // decode field width
- {
- int f = va_arg(arg, int);
- if (f < 0) { f = -f; F.leftJustify = 1; }
- F.fieldWidth = (unsigned int)f;
- c = *++fmt;
- }
- else
- {
- for (; c >= '0' && c <= '9'; c = *++fmt)
- F.fieldWidth = (10 * F.fieldWidth) + (c - '0');
- }
-
- if (c == '.') // decode precision
- {
- if ((c = *++fmt) == '*')
- { F.precision = va_arg(arg, unsigned int); c = *++fmt; }
- else for (; c >= '0' && c <= '9'; c = *++fmt)
- F.precision = (10 * F.precision) + (c - '0');
- F.havePrecision = 1;
- }
-
- if (F.leftJustify) F.zeroPad = 0;
-
- conv:
- switch (c) // perform appropriate conversion
- {
- #if TYPE_LONGLONG_NATIVE
- unsigned_long_long_compat n;
- unsigned_long_long_compat base;
- #else
- unsigned long n;
- unsigned long base;
- #endif
- case 'h' : F.hSize = 1; c = *++fmt; goto conv;
- case 'l' : // fall through
- case 'L' : F.lSize++; c = *++fmt; goto conv;
- case 'd' :
- case 'i' : base = 10;
- goto canBeSigned;
- case 'u' : base = 10;
- goto notSigned;
- case 'o' : base = 8;
- goto notSigned;
- case 'b' : base = 2;
- goto notSigned;
- case 'p' : n = va_arg(arg, uintptr_t);
- F.havePrecision = 1;
- F.precision = (sizeof(uintptr_t) == 4) ? 8 : 16;
- F.sign = 0;
- base = 16;
- c = 'x';
- goto number;
- case 'x' : digits = "0123456789abcdef";
- case 'X' : base = 16;
- goto notSigned;
- canBeSigned:
- #if TYPE_LONGLONG_NATIVE
- if (F.lSize == 1) n = (unsigned_long_long_compat)va_arg(arg, long);
- else if (F.lSize == 2) n = (unsigned_long_long_compat)va_arg(arg, long_long_compat);
- else n = (unsigned_long_long_compat)va_arg(arg, int);
- #else
- if (F.lSize == 1) n = (unsigned long)va_arg(arg, long);
- else if (F.lSize == 2) goto exit;
- else n = (unsigned long)va_arg(arg, int);
- #endif
- if (F.hSize) n = (short) n;
- #if TYPE_LONGLONG_NATIVE
- if ((long_long_compat) n < 0) { n = (unsigned_long_long_compat)-(long_long_compat)n; F.sign = '-'; }
- #else
- if ((long) n < 0) { n = (unsigned long)-(long)n; F.sign = '-'; }
- #endif
- else if (F.forceSign) F.sign = '+';
- goto number;
-
- notSigned: if (F.lSize == 1) n = va_arg(arg, unsigned long);
- else if (F.lSize == 2)
- {
- #if TYPE_LONGLONG_NATIVE
- n = va_arg(arg, unsigned_long_long_compat);
- #else
- goto exit;
- #endif
- }
- else n = va_arg(arg, unsigned int);
- if (F.hSize) n = (unsigned short) n;
- F.sign = 0;
- goto number;
-
- number: if (!F.havePrecision)
- {
- if (F.zeroPad)
- {
- F.precision = F.fieldWidth;
- if (F.altForm) F.precision -= 2;
- if (F.sign) --F.precision;
- }
- if (F.precision < 1) F.precision = 1;
- }
- if (F.precision > mDNS_VACB_Size - 1)
- F.precision = mDNS_VACB_Size - 1;
- for (i = 0; n; n /= base, i++) *--s = (char)(digits[n % base]);
- for (; i < F.precision; i++) *--s = '0';
- if (F.altForm) { *--s = (char)c; *--s = '0'; i += 2; }
- if (F.sign) { *--s = F.sign; i++; }
- break;
-
- case 'a' : {
- unsigned char *a = va_arg(arg, unsigned char *);
- char pre[4] = "";
- char post[32] = "";
- if (!a) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- else
- {
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- if (F.altForm == 1)
- {
- #if(defined(MDNS_DEBUGMSGS))
- mDNSAddr *ip = (mDNSAddr*)a;
- switch (ip->type)
- {
- case mDNSAddrType_IPv4: F.precision = 4; a = (unsigned char *)&ip->ip.v4; break;
- case mDNSAddrType_IPv6: F.precision = 16; a = (unsigned char *)&ip->ip.v6; break;
- default: F.precision = 0; break;
- }
- #else
- F.precision = 0; // mDNSEmbeddedAPI.h not included so no mDNSAddr support
- #endif
- }
- else if (F.altForm == 2)
- {
- #ifdef AF_INET
- const struct sockaddr *sa;
- unsigned char *port;
- sa = (const struct sockaddr*)a;
- switch (sa->sa_family)
- {
- case AF_INET: F.precision = 4; a = (unsigned char*)&((const struct sockaddr_in *)a)->sin_addr;
- port = (unsigned char*)&((const struct sockaddr_in *)sa)->sin_port;
- DebugSNPrintF(post, sizeof(post), ":%d", (port[0] << 8) | port[1]); break;
- #ifdef AF_INET6
- case AF_INET6: F.precision = 16; a = (unsigned char*)&((const struct sockaddr_in6 *)a)->sin6_addr;
- pre[0] = '['; pre[1] = '\0';
- port = (unsigned char*)&((const struct sockaddr_in6 *)sa)->sin6_port;
- DebugSNPrintF(post, sizeof(post), "%%%d]:%d",
- (int)((const struct sockaddr_in6 *)sa)->sin6_scope_id,
- (port[0] << 8) | port[1]); break;
- #endif
- default: F.precision = 0; break;
- }
- #else
- F.precision = 0; // socket interfaces not included so no sockaddr support
- #endif
- }
- switch (F.precision)
- {
- case 4: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%d.%d.%d.%d%s",
- a[0], a[1], a[2], a[3], post); break;
- case 6: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%02X:%02X:%02X:%02X:%02X:%02X",
- a[0], a[1], a[2], a[3], a[4], a[5]); break;
- case 8: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
- a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]); break;
- case 16: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB),
- "%s%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X%s",
- pre, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8],
- a[9], a[10], a[11], a[12], a[13], a[14], a[15], post); break;
- default: i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%s", "<< ERROR: Must specify address size "
- "(i.e. %.4a=IPv4, %.6a=Ethernet, %.8a=Fibre Channel %.16a=IPv6) >>"); break;
- }
- }
- }
- break;
-
- case 'U' : {
- unsigned char *a = va_arg(arg, unsigned char *);
- if (!a) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- else
- {
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- *((uint32_t*) &a[0]), *((uint16_t*) &a[4]), *((uint16_t*) &a[6]),
- a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]); break;
- }
- }
- break;
-
- case 'c' : *--s = (char)va_arg(arg, int); i = 1; break;
-
- case 'C' : if (F.lSize) n = va_arg(arg, unsigned long);
- else n = va_arg(arg, unsigned int);
- if (F.hSize) n = (unsigned short) n;
- c = (int)( n & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- c = (int)((n >> 8) & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- c = (int)((n >> 16) & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- c = (int)((n >> 24) & 0xFF); *--s = (char)(DebugIsPrint(c) ? c : '^');
- i = 4;
- break;
-
- case 's' : s = va_arg(arg, char *);
- if (!s) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- else switch (F.altForm)
- {
- case 0: i=0;
- if (F.havePrecision) // C string
- {
- while((i < F.precision) && s[i]) i++;
- // Make sure we don't truncate in the middle of a UTF-8 character.
- // If the last character is part of a multi-byte UTF-8 character, back up to the start of it.
- j=0;
- while((i > 0) && ((c = s[i-1]) & 0x80)) { j++; i--; if((c & 0xC0) != 0x80) break; }
- // If the actual count of UTF-8 characters matches the encoded UTF-8 count, add it back.
- if((j > 1) && (j <= 6))
- {
- int test = (0xFF << (8-j)) & 0xFF;
- int mask = test | (1 << ((8-j)-1));
- if((c & mask) == test) i += j;
- }
- }
- else
- while(s[i]) i++;
- break;
- case 1: i = (unsigned char) *s++; break; // Pascal string
- case 2: { // DNS label-sequence name
- unsigned char *a = (unsigned char *)s;
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- if (*a == 0) *s++ = '.'; // Special case for root DNS name
- while (*a)
- {
- if (*a > 63) { s += DebugSNPrintF(s, mDNS_VACB_Remain(s), "<<INVALID LABEL LENGTH %u>>", *a); break; }
- if (s + *a >= &mDNS_VACB[254]) { s += DebugSNPrintF(s, mDNS_VACB_Remain(s), "<<NAME TOO LONG>>"); break; }
- s += DebugSNPrintF(s, mDNS_VACB_Remain(s), "%#s.", a);
- a += 1 + *a;
- }
- i = (size_t)(s - mDNS_VACB);
- s = mDNS_VACB; // Reset s back to the start of the buffer
- break;
- }
- }
- if (F.havePrecision && i > F.precision) // Make sure we don't truncate in the middle of a UTF-8 character
- { i = F.precision; while (i>0 && (s[i] & 0xC0) == 0x80) i--; }
- break;
-
- case 'S': { // UTF-16 string
- unsigned char *a = va_arg(arg, unsigned char *);
- uint16_t *u = (uint16_t*)a;
- if (!u) { static char emsg[] = "<<NULL>>"; s = emsg; i = sizeof(emsg)-1; }
- if ((!F.havePrecision || F.precision))
- {
- if ((a[0] == 0xFE) && (a[1] == 0xFF)) { F.altForm = 1; u += 1; a += 2; F.precision--; } // Big Endian
- else if ((a[0] == 0xFF) && (a[1] == 0xFE)) { F.altForm = 2; u += 1; a += 2; F.precision--; } // Little Endian
- }
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- switch (F.altForm)
- {
- case 0: while ((!F.havePrecision || (i < F.precision)) && u[i] && mDNS_VACB_Remain(s)) // Host Endian
- { c = u[i]; *s++ = (char)(DebugIsPrint(c) ? c : '^'); i++; }
- break;
- case 1: while ((!F.havePrecision || (i < F.precision)) && u[i] && mDNS_VACB_Remain(s)) // Big Endian
- { c = ((a[0] << 8) | a[1]) & 0xFF; *s++ = (char)(DebugIsPrint(c) ? c : '^'); i++; a += 2; }
- break;
- case 2: while ((!F.havePrecision || (i < F.precision)) && u[i] && mDNS_VACB_Remain(s)) // Little Endian
- { c = ((a[1] << 8) | a[0]) & 0xFF; *s++ = (char)(DebugIsPrint(c) ? c : '^'); i++; a += 2; }
- break;
- }
- }
- s = mDNS_VACB; // Reset s back to the start of the buffer
- break;
-
- #if TARGET_OS_MAC
- case '@': { // Cocoa/CoreFoundation object
- CFTypeRef cfObj;
- CFStringRef cfStr;
- cfObj = (CFTypeRef) va_arg(arg, void *);
- cfStr = (CFGetTypeID(cfObj) == CFStringGetTypeID()) ? (CFStringRef)CFRetain(cfObj) : CFCopyDescription(cfObj);
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- if (cfStr)
- {
- CFRange range;
- CFIndex m;
- range = CFRangeMake(0, CFStringGetLength(cfStr));
- m = 0;
- CFStringGetBytes(cfStr, range, kCFStringEncodingUTF8, '^', false, (UInt8*)mDNS_VACB, (CFIndex)sizeof(mDNS_VACB), &m);
- CFRelease(cfStr);
- i = (size_t) m;
- }
- else
- {
- i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "%s", "ERROR: <invalid CF object>" );
- }
- }
- if (F.havePrecision && i > F.precision) // Make sure we don't truncate in the middle of a UTF-8 character
- { i = F.precision; while (i>0 && (s[i] & 0xC0) == 0x80) i--; }
- break;
- #endif
-
- case 'm' : { // Error Message
- long err;
- if (F.lSize) err = va_arg(arg, long);
- else err = va_arg(arg, int);
- if (F.hSize) err = (short)err;
- DebugGetErrorString(err, mDNS_VACB, sizeof(mDNS_VACB));
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- for(i=0;s[i];i++) {}
- }
- break;
-
- case 'H' : { // Hex Dump
- void *a = va_arg(arg, void *);
- size_t size = (size_t)va_arg(arg, int);
- size_t max = (size_t)va_arg(arg, int);
- DebugFlags flags =
- kDebugFlagsNoAddress | kDebugFlagsNoOffset | kDebugFlagsNoNewLine |
- kDebugFlags8BitSeparator | kDebugFlagsNo32BitSeparator |
- kDebugFlagsNo16ByteHexPad | kDebugFlagsNoByteCount;
- if (F.altForm == 0) flags |= kDebugFlagsNoASCII;
- size = (max < size) ? max : size;
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- i = DebugHexDump(kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, a, a, size, flags, mDNS_VACB, sizeof(mDNS_VACB));
- }
- break;
-
- case 'v' : { // Version
- uint32_t version;
- version = va_arg(arg, unsigned int);
- DebugNumVersionToString(version, mDNS_VACB);
- s = mDNS_VACB; // Adjust s to point to the start of the buffer, not the end
- for(i=0;s[i];i++) {}
- }
- break;
-
- case 'n' : s = va_arg(arg, char *);
- if (F.hSize) * (short *) s = (short)nwritten;
- else if (F.lSize) * (long *) s = (long)nwritten;
- else * (int *) s = (int)nwritten;
- continue;
-
- default: s = mDNS_VACB;
- i = DebugSNPrintF(mDNS_VACB, sizeof(mDNS_VACB), "<<UNKNOWN FORMAT CONVERSION CODE %%%c>>", c);
-
- case '%' : *sbuffer++ = (char)c;
- if (++nwritten >= buflen) goto exit;
- break;
- }
-
- if (i < F.fieldWidth && !F.leftJustify) // Pad on the left
- do {
- *sbuffer++ = ' ';
- if (++nwritten >= buflen) goto exit;
- } while (i < --F.fieldWidth);
-
- if (i > buflen - nwritten) // Make sure we don't truncate in the middle of a UTF-8 character
- { i = buflen - nwritten; while (i>0 && (s[i] & 0xC0) == 0x80) i--; }
- for (j=0; j<i; j++) *sbuffer++ = *s++; // Write the converted result
- nwritten += i;
- if (nwritten >= buflen) goto exit;
-
- for (; i < F.fieldWidth; i++) // Pad on the right
- {
- *sbuffer++ = ' ';
- if (++nwritten >= buflen) goto exit;
- }
- }
- }
- exit:
- *sbuffer++ = 0;
- return(nwritten);
- }
-
-//===========================================================================================================================
-// DebugGetErrorString
-//===========================================================================================================================
-
-DEBUG_EXPORT const char * DebugGetErrorString( int_least32_t inErrorCode, char *inBuffer, size_t inBufferSize )
-{
- const char * s;
- char * dst;
- char * end;
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- char buffer[ 256 ];
-#endif
-
- switch( inErrorCode )
- {
- #define CaseErrorString( X, STR ) case X: s = STR; break
- #define CaseErrorStringify( X ) case X: s = # X; break
- #define CaseErrorStringifyHardCode( VALUE, X ) case VALUE: s = # X; break
-
- // General Errors
-
- CaseErrorString( 0, "no error" );
- CaseErrorString( 1, "in-progress/waiting" );
- CaseErrorString( -1, "catch-all unknown error" );
-
- // ACP Errors
-
- CaseErrorStringifyHardCode( -2, kACPBadRequestErr );
- CaseErrorStringifyHardCode( -3, kACPNoMemoryErr );
- CaseErrorStringifyHardCode( -4, kACPBadParamErr );
- CaseErrorStringifyHardCode( -5, kACPNotFoundErr );
- CaseErrorStringifyHardCode( -6, kACPBadChecksumErr );
- CaseErrorStringifyHardCode( -7, kACPCommandNotHandledErr );
- CaseErrorStringifyHardCode( -8, kACPNetworkErr );
- CaseErrorStringifyHardCode( -9, kACPDuplicateCommandHandlerErr );
- CaseErrorStringifyHardCode( -10, kACPUnknownPropertyErr );
- CaseErrorStringifyHardCode( -11, kACPImmutablePropertyErr );
- CaseErrorStringifyHardCode( -12, kACPBadPropertyValueErr );
- CaseErrorStringifyHardCode( -13, kACPNoResourcesErr );
- CaseErrorStringifyHardCode( -14, kACPBadOptionErr );
- CaseErrorStringifyHardCode( -15, kACPBadSizeErr );
- CaseErrorStringifyHardCode( -16, kACPBadPasswordErr );
- CaseErrorStringifyHardCode( -17, kACPNotInitializedErr );
- CaseErrorStringifyHardCode( -18, kACPNonReadablePropertyErr );
- CaseErrorStringifyHardCode( -19, kACPBadVersionErr );
- CaseErrorStringifyHardCode( -20, kACPBadSignatureErr );
- CaseErrorStringifyHardCode( -21, kACPBadIndexErr );
- CaseErrorStringifyHardCode( -22, kACPUnsupportedErr );
- CaseErrorStringifyHardCode( -23, kACPInUseErr );
- CaseErrorStringifyHardCode( -24, kACPParamCountErr );
- CaseErrorStringifyHardCode( -25, kACPIDErr );
- CaseErrorStringifyHardCode( -26, kACPFormatErr );
- CaseErrorStringifyHardCode( -27, kACPUnknownUserErr );
- CaseErrorStringifyHardCode( -28, kACPAccessDeniedErr );
- CaseErrorStringifyHardCode( -29, kACPIncorrectFWErr );
-
- // Common Services Errors
-
- CaseErrorStringify( kUnknownErr );
- CaseErrorStringify( kOptionErr );
- CaseErrorStringify( kSelectorErr );
- CaseErrorStringify( kExecutionStateErr );
- CaseErrorStringify( kPathErr );
- CaseErrorStringify( kParamErr );
- CaseErrorStringify( kParamCountErr );
- CaseErrorStringify( kCommandErr );
- CaseErrorStringify( kIDErr );
- CaseErrorStringify( kStateErr );
- CaseErrorStringify( kRangeErr );
- CaseErrorStringify( kRequestErr );
- CaseErrorStringify( kResponseErr );
- CaseErrorStringify( kChecksumErr );
- CaseErrorStringify( kNotHandledErr );
- CaseErrorStringify( kVersionErr );
- CaseErrorStringify( kSignatureErr );
- CaseErrorStringify( kFormatErr );
- CaseErrorStringify( kNotInitializedErr );
- CaseErrorStringify( kAlreadyInitializedErr );
- CaseErrorStringify( kNotInUseErr );
- CaseErrorStringify( kInUseErr );
- CaseErrorStringify( kTimeoutErr );
- CaseErrorStringify( kCanceledErr );
- CaseErrorStringify( kAlreadyCanceledErr );
- CaseErrorStringify( kCannotCancelErr );
- CaseErrorStringify( kDeletedErr );
- CaseErrorStringify( kNotFoundErr );
- CaseErrorStringify( kNoMemoryErr );
- CaseErrorStringify( kNoResourcesErr );
- CaseErrorStringify( kDuplicateErr );
- CaseErrorStringify( kImmutableErr );
- CaseErrorStringify( kUnsupportedDataErr );
- CaseErrorStringify( kIntegrityErr );
- CaseErrorStringify( kIncompatibleErr );
- CaseErrorStringify( kUnsupportedErr );
- CaseErrorStringify( kUnexpectedErr );
- CaseErrorStringify( kValueErr );
- CaseErrorStringify( kNotReadableErr );
- CaseErrorStringify( kNotWritableErr );
- CaseErrorStringify( kBadReferenceErr );
- CaseErrorStringify( kFlagErr );
- CaseErrorStringify( kMalformedErr );
- CaseErrorStringify( kSizeErr );
- CaseErrorStringify( kNameErr );
- CaseErrorStringify( kNotReadyErr );
- CaseErrorStringify( kReadErr );
- CaseErrorStringify( kWriteErr );
- CaseErrorStringify( kMismatchErr );
- CaseErrorStringify( kDateErr );
- CaseErrorStringify( kUnderrunErr );
- CaseErrorStringify( kOverrunErr );
- CaseErrorStringify( kEndingErr );
- CaseErrorStringify( kConnectionErr );
- CaseErrorStringify( kAuthenticationErr );
- CaseErrorStringify( kOpenErr );
- CaseErrorStringify( kTypeErr );
- CaseErrorStringify( kSkipErr );
- CaseErrorStringify( kNoAckErr );
- CaseErrorStringify( kCollisionErr );
- CaseErrorStringify( kBackoffErr );
- CaseErrorStringify( kNoAddressAckErr );
- CaseErrorStringify( kBusyErr );
- CaseErrorStringify( kNoSpaceErr );
-
- // mDNS/DNS-SD Errors
-
- CaseErrorStringifyHardCode( -65537, mStatus_UnknownErr );
- CaseErrorStringifyHardCode( -65538, mStatus_NoSuchNameErr );
- CaseErrorStringifyHardCode( -65539, mStatus_NoMemoryErr );
- CaseErrorStringifyHardCode( -65540, mStatus_BadParamErr );
- CaseErrorStringifyHardCode( -65541, mStatus_BadReferenceErr );
- CaseErrorStringifyHardCode( -65542, mStatus_BadStateErr );
- CaseErrorStringifyHardCode( -65543, mStatus_BadFlagsErr );
- CaseErrorStringifyHardCode( -65544, mStatus_UnsupportedErr );
- CaseErrorStringifyHardCode( -65545, mStatus_NotInitializedErr );
- CaseErrorStringifyHardCode( -65546, mStatus_NoCache );
- CaseErrorStringifyHardCode( -65547, mStatus_AlreadyRegistered );
- CaseErrorStringifyHardCode( -65548, mStatus_NameConflict );
- CaseErrorStringifyHardCode( -65549, mStatus_Invalid );
- CaseErrorStringifyHardCode( -65550, mStatus_GrowCache );
- CaseErrorStringifyHardCode( -65551, mStatus_BadInterfaceErr );
- CaseErrorStringifyHardCode( -65552, mStatus_Incompatible );
- CaseErrorStringifyHardCode( -65791, mStatus_ConfigChanged );
- CaseErrorStringifyHardCode( -65792, mStatus_MemFree );
-
- // RSP Errors
-
- CaseErrorStringifyHardCode( -400000, kRSPUnknownErr );
- CaseErrorStringifyHardCode( -400050, kRSPParamErr );
- CaseErrorStringifyHardCode( -400108, kRSPNoMemoryErr );
- CaseErrorStringifyHardCode( -405246, kRSPRangeErr );
- CaseErrorStringifyHardCode( -409057, kRSPSizeErr );
- CaseErrorStringifyHardCode( -400200, kRSPHardwareErr );
- CaseErrorStringifyHardCode( -401712, kRSPTimeoutErr );
- CaseErrorStringifyHardCode( -402053, kRSPUnsupportedErr );
- CaseErrorStringifyHardCode( -402419, kRSPIDErr );
- CaseErrorStringifyHardCode( -403165, kRSPFlagErr );
- CaseErrorString( -200000, "kRSPControllerStatusBase - 0x50" );
- CaseErrorString( -200080, "kRSPCommandSucceededErr - 0x50" );
- CaseErrorString( -200001, "kRSPCommandFailedErr - 0x01" );
- CaseErrorString( -200051, "kRSPChecksumErr - 0x33" );
- CaseErrorString( -200132, "kRSPCommandTimeoutErr - 0x84" );
- CaseErrorString( -200034, "kRSPPasswordRequiredErr - 0x22 OBSOLETE" );
- CaseErrorString( -200128, "kRSPCanceledErr - 0x02 Async" );
-
- // XML Errors
-
- CaseErrorStringifyHardCode( -100043, kXMLNotFoundErr );
- CaseErrorStringifyHardCode( -100050, kXMLParamErr );
- CaseErrorStringifyHardCode( -100108, kXMLNoMemoryErr );
- CaseErrorStringifyHardCode( -100206, kXMLFormatErr );
- CaseErrorStringifyHardCode( -100586, kXMLNoRootElementErr );
- CaseErrorStringifyHardCode( -101703, kXMLWrongDataTypeErr );
- CaseErrorStringifyHardCode( -101726, kXMLKeyErr );
- CaseErrorStringifyHardCode( -102053, kXMLUnsupportedErr );
- CaseErrorStringifyHardCode( -102063, kXMLMissingElementErr );
- CaseErrorStringifyHardCode( -103026, kXMLParseErr );
- CaseErrorStringifyHardCode( -103159, kXMLBadDataErr );
- CaseErrorStringifyHardCode( -103170, kXMLBadNameErr );
- CaseErrorStringifyHardCode( -105246, kXMLRangeErr );
- CaseErrorStringifyHardCode( -105251, kXMLUnknownElementErr );
- CaseErrorStringifyHardCode( -108739, kXMLMalformedInputErr );
- CaseErrorStringifyHardCode( -109057, kXMLBadSizeErr );
- CaseErrorStringifyHardCode( -101730, kXMLMissingChildElementErr );
- CaseErrorStringifyHardCode( -102107, kXMLMissingParentElementErr );
- CaseErrorStringifyHardCode( -130587, kXMLNonRootElementErr );
- CaseErrorStringifyHardCode( -102015, kXMLDateErr );
-
- #if( __MACH__ )
-
- // Mach Errors
-
- CaseErrorStringifyHardCode( 0x00002000, MACH_MSG_IPC_SPACE );
- CaseErrorStringifyHardCode( 0x00001000, MACH_MSG_VM_SPACE );
- CaseErrorStringifyHardCode( 0x00000800, MACH_MSG_IPC_KERNEL );
- CaseErrorStringifyHardCode( 0x00000400, MACH_MSG_VM_KERNEL );
- CaseErrorStringifyHardCode( 0x10000001, MACH_SEND_IN_PROGRESS );
- CaseErrorStringifyHardCode( 0x10000002, MACH_SEND_INVALID_DATA );
- CaseErrorStringifyHardCode( 0x10000003, MACH_SEND_INVALID_DEST );
- CaseErrorStringifyHardCode( 0x10000004, MACH_SEND_TIMED_OUT );
- CaseErrorStringifyHardCode( 0x10000007, MACH_SEND_INTERRUPTED );
- CaseErrorStringifyHardCode( 0x10000008, MACH_SEND_MSG_TOO_SMALL );
- CaseErrorStringifyHardCode( 0x10000009, MACH_SEND_INVALID_REPLY );
- CaseErrorStringifyHardCode( 0x1000000A, MACH_SEND_INVALID_RIGHT );
- CaseErrorStringifyHardCode( 0x1000000B, MACH_SEND_INVALID_NOTIFY );
- CaseErrorStringifyHardCode( 0x1000000C, MACH_SEND_INVALID_MEMORY );
- CaseErrorStringifyHardCode( 0x1000000D, MACH_SEND_NO_BUFFER );
- CaseErrorStringifyHardCode( 0x1000000E, MACH_SEND_TOO_LARGE );
- CaseErrorStringifyHardCode( 0x1000000F, MACH_SEND_INVALID_TYPE );
- CaseErrorStringifyHardCode( 0x10000010, MACH_SEND_INVALID_HEADER );
- CaseErrorStringifyHardCode( 0x10000011, MACH_SEND_INVALID_TRAILER );
- CaseErrorStringifyHardCode( 0x10000015, MACH_SEND_INVALID_RT_OOL_SIZE );
- CaseErrorStringifyHardCode( 0x10004001, MACH_RCV_IN_PROGRESS );
- CaseErrorStringifyHardCode( 0x10004002, MACH_RCV_INVALID_NAME );
- CaseErrorStringifyHardCode( 0x10004003, MACH_RCV_TIMED_OUT );
- CaseErrorStringifyHardCode( 0x10004004, MACH_RCV_TOO_LARGE );
- CaseErrorStringifyHardCode( 0x10004005, MACH_RCV_INTERRUPTED );
- CaseErrorStringifyHardCode( 0x10004006, MACH_RCV_PORT_CHANGED );
- CaseErrorStringifyHardCode( 0x10004007, MACH_RCV_INVALID_NOTIFY );
- CaseErrorStringifyHardCode( 0x10004008, MACH_RCV_INVALID_DATA );
- CaseErrorStringifyHardCode( 0x10004009, MACH_RCV_PORT_DIED );
- CaseErrorStringifyHardCode( 0x1000400A, MACH_RCV_IN_SET );
- CaseErrorStringifyHardCode( 0x1000400B, MACH_RCV_HEADER_ERROR );
- CaseErrorStringifyHardCode( 0x1000400C, MACH_RCV_BODY_ERROR );
- CaseErrorStringifyHardCode( 0x1000400D, MACH_RCV_INVALID_TYPE );
- CaseErrorStringifyHardCode( 0x1000400E, MACH_RCV_SCATTER_SMALL );
- CaseErrorStringifyHardCode( 0x1000400F, MACH_RCV_INVALID_TRAILER );
- CaseErrorStringifyHardCode( 0x10004011, MACH_RCV_IN_PROGRESS_TIMED );
-
- // Mach OSReturn Errors
-
- CaseErrorStringifyHardCode( 0xDC000001, kOSReturnError );
- CaseErrorStringifyHardCode( 0xDC004001, kOSMetaClassInternal );
- CaseErrorStringifyHardCode( 0xDC004002, kOSMetaClassHasInstances );
- CaseErrorStringifyHardCode( 0xDC004003, kOSMetaClassNoInit );
- CaseErrorStringifyHardCode( 0xDC004004, kOSMetaClassNoTempData );
- CaseErrorStringifyHardCode( 0xDC004005, kOSMetaClassNoDicts );
- CaseErrorStringifyHardCode( 0xDC004006, kOSMetaClassNoKModSet );
- CaseErrorStringifyHardCode( 0xDC004007, kOSMetaClassNoInsKModSet );
- CaseErrorStringifyHardCode( 0xDC004008, kOSMetaClassNoSuper );
- CaseErrorStringifyHardCode( 0xDC004009, kOSMetaClassInstNoSuper );
- CaseErrorStringifyHardCode( 0xDC00400A, kOSMetaClassDuplicateClass );
-
- // IOKit Errors
-
- CaseErrorStringifyHardCode( 0xE00002BC, kIOReturnError );
- CaseErrorStringifyHardCode( 0xE00002BD, kIOReturnNoMemory );
- CaseErrorStringifyHardCode( 0xE00002BE, kIOReturnNoResources );
- CaseErrorStringifyHardCode( 0xE00002BF, kIOReturnIPCError );
- CaseErrorStringifyHardCode( 0xE00002C0, kIOReturnNoDevice );
- CaseErrorStringifyHardCode( 0xE00002C1, kIOReturnNotPrivileged );
- CaseErrorStringifyHardCode( 0xE00002C2, kIOReturnBadArgument );
- CaseErrorStringifyHardCode( 0xE00002C3, kIOReturnLockedRead );
- CaseErrorStringifyHardCode( 0xE00002C4, kIOReturnLockedWrite );
- CaseErrorStringifyHardCode( 0xE00002C5, kIOReturnExclusiveAccess );
- CaseErrorStringifyHardCode( 0xE00002C6, kIOReturnBadMessageID );
- CaseErrorStringifyHardCode( 0xE00002C7, kIOReturnUnsupported );
- CaseErrorStringifyHardCode( 0xE00002C8, kIOReturnVMError );
- CaseErrorStringifyHardCode( 0xE00002C9, kIOReturnInternalError );
- CaseErrorStringifyHardCode( 0xE00002CA, kIOReturnIOError );
- CaseErrorStringifyHardCode( 0xE00002CC, kIOReturnCannotLock );
- CaseErrorStringifyHardCode( 0xE00002CD, kIOReturnNotOpen );
- CaseErrorStringifyHardCode( 0xE00002CE, kIOReturnNotReadable );
- CaseErrorStringifyHardCode( 0xE00002CF, kIOReturnNotWritable );
- CaseErrorStringifyHardCode( 0xE00002D0, kIOReturnNotAligned );
- CaseErrorStringifyHardCode( 0xE00002D1, kIOReturnBadMedia );
- CaseErrorStringifyHardCode( 0xE00002D2, kIOReturnStillOpen );
- CaseErrorStringifyHardCode( 0xE00002D3, kIOReturnRLDError );
- CaseErrorStringifyHardCode( 0xE00002D4, kIOReturnDMAError );
- CaseErrorStringifyHardCode( 0xE00002D5, kIOReturnBusy );
- CaseErrorStringifyHardCode( 0xE00002D6, kIOReturnTimeout );
- CaseErrorStringifyHardCode( 0xE00002D7, kIOReturnOffline );
- CaseErrorStringifyHardCode( 0xE00002D8, kIOReturnNotReady );
- CaseErrorStringifyHardCode( 0xE00002D9, kIOReturnNotAttached );
- CaseErrorStringifyHardCode( 0xE00002DA, kIOReturnNoChannels );
- CaseErrorStringifyHardCode( 0xE00002DB, kIOReturnNoSpace );
- CaseErrorStringifyHardCode( 0xE00002DD, kIOReturnPortExists );
- CaseErrorStringifyHardCode( 0xE00002DE, kIOReturnCannotWire );
- CaseErrorStringifyHardCode( 0xE00002DF, kIOReturnNoInterrupt );
- CaseErrorStringifyHardCode( 0xE00002E0, kIOReturnNoFrames );
- CaseErrorStringifyHardCode( 0xE00002E1, kIOReturnMessageTooLarge );
- CaseErrorStringifyHardCode( 0xE00002E2, kIOReturnNotPermitted );
- CaseErrorStringifyHardCode( 0xE00002E3, kIOReturnNoPower );
- CaseErrorStringifyHardCode( 0xE00002E4, kIOReturnNoMedia );
- CaseErrorStringifyHardCode( 0xE00002E5, kIOReturnUnformattedMedia );
- CaseErrorStringifyHardCode( 0xE00002E6, kIOReturnUnsupportedMode );
- CaseErrorStringifyHardCode( 0xE00002E7, kIOReturnUnderrun );
- CaseErrorStringifyHardCode( 0xE00002E8, kIOReturnOverrun );
- CaseErrorStringifyHardCode( 0xE00002E9, kIOReturnDeviceError );
- CaseErrorStringifyHardCode( 0xE00002EA, kIOReturnNoCompletion );
- CaseErrorStringifyHardCode( 0xE00002EB, kIOReturnAborted );
- CaseErrorStringifyHardCode( 0xE00002EC, kIOReturnNoBandwidth );
- CaseErrorStringifyHardCode( 0xE00002ED, kIOReturnNotResponding );
- CaseErrorStringifyHardCode( 0xE00002EE, kIOReturnIsoTooOld );
- CaseErrorStringifyHardCode( 0xE00002EF, kIOReturnIsoTooNew );
- CaseErrorStringifyHardCode( 0xE00002F0, kIOReturnNotFound );
- CaseErrorStringifyHardCode( 0xE0000001, kIOReturnInvalid );
-
- // IOKit FireWire Errors
-
- CaseErrorStringifyHardCode( 0xE0008010, kIOFireWireResponseBase );
- CaseErrorStringifyHardCode( 0xE0008020, kIOFireWireBusReset );
- CaseErrorStringifyHardCode( 0xE0008001, kIOConfigNoEntry );
- CaseErrorStringifyHardCode( 0xE0008002, kIOFireWirePending );
- CaseErrorStringifyHardCode( 0xE0008003, kIOFireWireLastDCLToken );
- CaseErrorStringifyHardCode( 0xE0008004, kIOFireWireConfigROMInvalid );
- CaseErrorStringifyHardCode( 0xE0008005, kIOFireWireAlreadyRegistered );
- CaseErrorStringifyHardCode( 0xE0008006, kIOFireWireMultipleTalkers );
- CaseErrorStringifyHardCode( 0xE0008007, kIOFireWireChannelActive );
- CaseErrorStringifyHardCode( 0xE0008008, kIOFireWireNoListenerOrTalker );
- CaseErrorStringifyHardCode( 0xE0008009, kIOFireWireNoChannels );
- CaseErrorStringifyHardCode( 0xE000800A, kIOFireWireChannelNotAvailable );
- CaseErrorStringifyHardCode( 0xE000800B, kIOFireWireSeparateBus );
- CaseErrorStringifyHardCode( 0xE000800C, kIOFireWireBadSelfIDs );
- CaseErrorStringifyHardCode( 0xE000800D, kIOFireWireLowCableVoltage );
- CaseErrorStringifyHardCode( 0xE000800E, kIOFireWireInsufficientPower );
- CaseErrorStringifyHardCode( 0xE000800F, kIOFireWireOutOfTLabels );
- CaseErrorStringifyHardCode( 0xE0008101, kIOFireWireBogusDCLProgram );
- CaseErrorStringifyHardCode( 0xE0008102, kIOFireWireTalkingAndListening );
- CaseErrorStringifyHardCode( 0xE0008103, kIOFireWireHardwareSlept );
- CaseErrorStringifyHardCode( 0xE00087D0, kIOFWMessageServiceIsRequestingClose );
- CaseErrorStringifyHardCode( 0xE00087D1, kIOFWMessagePowerStateChanged );
- CaseErrorStringifyHardCode( 0xE00087D2, kIOFWMessageTopologyChanged );
-
- // IOKit USB Errors
-
- CaseErrorStringifyHardCode( 0xE0004061, kIOUSBUnknownPipeErr );
- CaseErrorStringifyHardCode( 0xE0004060, kIOUSBTooManyPipesErr );
- CaseErrorStringifyHardCode( 0xE000405F, kIOUSBNoAsyncPortErr );
- CaseErrorStringifyHardCode( 0xE000405E, kIOUSBNotEnoughPipesErr );
- CaseErrorStringifyHardCode( 0xE000405D, kIOUSBNotEnoughPowerErr );
- CaseErrorStringifyHardCode( 0xE0004057, kIOUSBEndpointNotFound );
- CaseErrorStringifyHardCode( 0xE0004056, kIOUSBConfigNotFound );
- CaseErrorStringifyHardCode( 0xE0004051, kIOUSBTransactionTimeout );
- CaseErrorStringifyHardCode( 0xE0004050, kIOUSBTransactionReturned );
- CaseErrorStringifyHardCode( 0xE000404F, kIOUSBPipeStalled );
- CaseErrorStringifyHardCode( 0xE000404E, kIOUSBInterfaceNotFound );
- CaseErrorStringifyHardCode( 0xE000404D, kIOUSBLowLatencyBufferNotPreviouslyAllocated );
- CaseErrorStringifyHardCode( 0xE000404C, kIOUSBLowLatencyFrameListNotPreviouslyAllocated );
- CaseErrorStringifyHardCode( 0xE000404B, kIOUSBHighSpeedSplitError );
- CaseErrorStringifyHardCode( 0xE0004010, kIOUSBLinkErr );
- CaseErrorStringifyHardCode( 0xE000400F, kIOUSBNotSent2Err );
- CaseErrorStringifyHardCode( 0xE000400E, kIOUSBNotSent1Err );
- CaseErrorStringifyHardCode( 0xE000400D, kIOUSBBufferUnderrunErr );
- CaseErrorStringifyHardCode( 0xE000400C, kIOUSBBufferOverrunErr );
- CaseErrorStringifyHardCode( 0xE000400B, kIOUSBReserved2Err );
- CaseErrorStringifyHardCode( 0xE000400A, kIOUSBReserved1Err );
- CaseErrorStringifyHardCode( 0xE0004007, kIOUSBWrongPIDErr );
- CaseErrorStringifyHardCode( 0xE0004006, kIOUSBPIDCheckErr );
- CaseErrorStringifyHardCode( 0xE0004003, kIOUSBDataToggleErr );
- CaseErrorStringifyHardCode( 0xE0004002, kIOUSBBitstufErr );
- CaseErrorStringifyHardCode( 0xE0004001, kIOUSBCRCErr );
-
- #endif // __MACH__
-
- // Other Errors
-
- default:
- s = NULL;
- #if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
- if( inBuffer && ( inBufferSize > 0 ) )
- {
- DWORD n;
-
- n = FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD) inErrorCode,
- MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), buffer, sizeof( buffer ), NULL );
- if( n > 0 )
- {
- // Remove any trailing CR's or LF's since some messages have them.
-
- while( ( n > 0 ) && isspace( ( (unsigned char *) buffer )[ n - 1 ] ) )
- {
- buffer[ --n ] = '\0';
- }
- s = buffer;
- }
- }
- #endif
-
- if( !s )
- {
- #if( !TARGET_API_MAC_OSX_KERNEL && !TARGET_OS_WINDOWS_CE )
- s = strerror( inErrorCode );
- #endif
- if( !s )
- {
- s = "<unknown error code>";
- }
- }
- break;
- }
-
- // Copy the string to the output buffer. If no buffer is supplied or it is empty, return an empty string.
-
- if( inBuffer && ( inBufferSize > 0 ) )
- {
- dst = inBuffer;
- end = dst + ( inBufferSize - 1 );
- while( ( ( end - dst ) > 0 ) && ( *s != '\0' ) )
- {
- *dst++ = *s++;
- }
- *dst = '\0';
- s = inBuffer;
- }
- return( s );
-}
-
-//===========================================================================================================================
-// DebugHexDump
-//===========================================================================================================================
-
-DEBUG_EXPORT size_t
- DebugHexDump(
- DebugLevel inLevel,
- int inIndent,
- const char * inLabel,
- size_t inLabelSize,
- int inLabelMinWidth,
- const char * inType,
- size_t inTypeSize,
- const void * inDataStart,
- const void * inData,
- size_t inDataSize,
- DebugFlags inFlags,
- char * outBuffer,
- size_t inBufferSize )
-{
- static const char kHexChars[] = "0123456789ABCDEF";
- const uint8_t * start;
- const uint8_t * src;
- char * dst;
- char * end;
- size_t n;
- int offset;
- int width;
- const char * newline;
- char separator[ 8 ];
- char * s;
-
- DEBUG_UNUSED( inType );
- DEBUG_UNUSED( inTypeSize );
-
- // Set up the function-wide variables.
-
- if( inLabelSize == kSizeCString )
- {
- inLabelSize = strlen( inLabel );
- }
- start = (const uint8_t *) inData;
- src = start;
- dst = outBuffer;
- end = dst + inBufferSize;
- offset = (int)( (intptr_t) inData - (intptr_t) inDataStart );
- width = ( (int) inLabelSize > inLabelMinWidth ) ? (int) inLabelSize : inLabelMinWidth;
- newline = ( inFlags & kDebugFlagsNoNewLine ) ? "" : "\n";
-
- // Set up the separator string. This is used to insert spaces on subsequent "lines" when not using newlines.
-
- s = separator;
- if( inFlags & kDebugFlagsNoNewLine )
- {
- if( inFlags & kDebugFlags8BitSeparator )
- {
- *s++ = ' ';
- }
- if( inFlags & kDebugFlags16BitSeparator )
- {
- *s++ = ' ';
- }
- if( !( inFlags & kDebugFlagsNo32BitSeparator ) )
- {
- *s++ = ' ';
- }
- check( ( (size_t)( s - separator ) ) < sizeof( separator ) );
- }
- *s = '\0';
-
- for( ;; )
- {
- char prefixString[ 32 ];
- char hexString[ 64 ];
- char asciiString[ 32 ];
- char byteCountString[ 32 ];
- int c;
- size_t chunkSize;
- size_t i;
-
- // If this is a label-only item (i.e. no data), print the label (accounting for prefix string spacing) and exit.
-
- if( inDataSize == 0 )
- {
- if( inLabel && ( inLabelSize > 0 ) )
- {
- width = 0;
- if( !( inFlags & kDebugFlagsNoAddress ) )
- {
- width += 8; // "00000000"
- if( !( inFlags & kDebugFlagsNoOffset ) )
- {
- width += 1; // "+"
- }
- }
- if( inFlags & kDebugFlags32BitOffset )
- {
- width += 8; // "00000000"
- }
- else if( !( inFlags & kDebugFlagsNoOffset ) )
- {
- width += 4; // "0000"
- }
-
- if( outBuffer )
- {
- dst += DebugSNPrintF( dst, (size_t)( end - dst ), "%*s" "%-*.*s" "%.*s" "%s",
- width, "",
- ( width > 0 ) ? ": " : "",
- width, (int) inLabelSize, inLabel,
- newline );
- }
- else
- {
- dst += DebugPrintF( inLevel, "%*s" "%-*.*s" "%.*s" "%s",
- width, "",
- ( width > 0 ) ? ": " : "",
- width, (int) inLabelSize, inLabel,
- newline );
- }
- }
- break;
- }
-
- // Build the prefix string. It will be in one of the following formats:
- //
- // 1) "00000000+0000[0000]" (address and offset)
- // 2) "00000000" (address only)
- // 3) "0000[0000]" (offset only)
- // 4) "" (no address or offset)
- //
- // Note: If we're printing multiple "lines", but not printing newlines, a space is used to separate.
-
- s = prefixString;
- if( !( inFlags & kDebugFlagsNoAddress ) )
- {
- *s++ = kHexChars[ ( ( (uintptr_t) src ) >> 28 ) & 0xF ];
- *s++ = kHexChars[ ( ( (uintptr_t) src ) >> 24 ) & 0xF ];
- *s++ = kHexChars[ ( ( (uintptr_t) src ) >> 20 ) & 0xF ];
- *s++ = kHexChars[ ( ( (uintptr_t) src ) >> 16 ) & 0xF ];
- *s++ = kHexChars[ ( ( (uintptr_t) src ) >> 12 ) & 0xF ];
- *s++ = kHexChars[ ( ( (uintptr_t) src ) >> 8 ) & 0xF ];
- *s++ = kHexChars[ ( ( (uintptr_t) src ) >> 4 ) & 0xF ];
- *s++ = kHexChars[ ( (uintptr_t) src ) & 0xF ];
-
- if( !( inFlags & kDebugFlagsNoOffset ) )
- {
- *s++ = '+';
- }
- }
- if( !( inFlags & kDebugFlagsNoOffset ) )
- {
- if( inFlags & kDebugFlags32BitOffset )
- {
- *s++ = kHexChars[ ( offset >> 28 ) & 0xF ];
- *s++ = kHexChars[ ( offset >> 24 ) & 0xF ];
- *s++ = kHexChars[ ( offset >> 20 ) & 0xF ];
- *s++ = kHexChars[ ( offset >> 16 ) & 0xF ];
- }
- *s++ = kHexChars[ ( offset >> 12 ) & 0xF ];
- *s++ = kHexChars[ ( offset >> 8 ) & 0xF ];
- *s++ = kHexChars[ ( offset >> 4 ) & 0xF ];
- *s++ = kHexChars[ offset & 0xF ];
- }
- if( s != prefixString )
- {
- *s++ = ':';
- *s++ = ' ';
- }
- check( ( (size_t)( s - prefixString ) ) < sizeof( prefixString ) );
- *s = '\0';
-
- // Build a hex string with a optional spaces after every 1, 2, and/or 4 bytes to make it easier to read.
- // Optionally pads the hex string with space to fill the full 16 byte range (so it lines up).
-
- s = hexString;
- chunkSize = ( inDataSize < 16 ) ? inDataSize : 16;
- n = ( inFlags & kDebugFlagsNo16ByteHexPad ) ? chunkSize : 16;
- for( i = 0; i < n; ++i )
- {
- if( ( inFlags & kDebugFlags8BitSeparator ) && ( i > 0 ) )
- {
- *s++ = ' ';
- }
- if( ( inFlags & kDebugFlags16BitSeparator ) && ( i > 0 ) && ( ( i % 2 ) == 0 ) )
- {
- *s++ = ' ';
- }
- if( !( inFlags & kDebugFlagsNo32BitSeparator ) && ( i > 0 ) && ( ( i % 4 ) == 0 ) )
- {
- *s++ = ' ';
- }
- if( i < chunkSize )
- {
- *s++ = kHexChars[ src[ i ] >> 4 ];
- *s++ = kHexChars[ src[ i ] & 0xF ];
- }
- else
- {
- *s++ = ' ';
- *s++ = ' ';
- }
- }
- check( ( (size_t)( s - hexString ) ) < sizeof( hexString ) );
- *s = '\0';
-
- // Build a string with the ASCII version of the data (replaces non-printable characters with '^').
- // Optionally pads the string with '`' to fill the full 16 byte range (so it lines up).
-
- s = asciiString;
- if( !( inFlags & kDebugFlagsNoASCII ) )
- {
- *s++ = ' ';
- *s++ = '|';
- for( i = 0; i < n; ++i )
- {
- if( i < chunkSize )
- {
- c = src[ i ];
- if( !DebugIsPrint( c ) )
- {
- c = '^';
- }
- }
- else
- {
- c = '`';
- }
- *s++ = (char) c;
- }
- *s++ = '|';
- check( ( (size_t)( s - asciiString ) ) < sizeof( asciiString ) );
- }
- *s = '\0';
-
- // Build a string indicating how bytes are in the hex dump. Only printed on the first line.
-
- s = byteCountString;
- if( !( inFlags & kDebugFlagsNoByteCount ) )
- {
- if( src == start )
- {
- s += DebugSNPrintF( s, sizeof( byteCountString ), " (%d bytes)", (int) inDataSize );
- }
- }
- check( ( (size_t)( s - byteCountString ) ) < sizeof( byteCountString ) );
- *s = '\0';
-
- // Build the entire line from all the pieces we've previously built.
-
- if( outBuffer )
- {
- if( src == start )
- {
- dst += DebugSNPrintF( dst, (size_t)( end - dst ),
- "%*s" // Indention
- "%s" // Separator (only if needed)
- "%s" // Prefix
- "%-*.*s" // Label
- "%s" // Separator
- "%s" // Hex
- "%s" // ASCII
- "%s" // Byte Count
- "%s", // Newline
- inIndent, "",
- ( src != start ) ? separator : "",
- prefixString,
- width, (int) inLabelSize, inLabel ? inLabel : "",
- ( width > 0 ) ? " " : "",
- hexString,
- asciiString,
- byteCountString,
- newline );
- }
- else
- {
- dst += DebugSNPrintF( dst, (size_t)( end - dst ),
- "%*s" // Indention
- "%s" // Separator (only if needed)
- "%s" // Prefix
- "%*s" // Label Spacing
- "%s" // Separator
- "%s" // Hex
- "%s" // ASCII
- "%s" // Byte Count
- "%s", // Newline
- inIndent, "",
- ( src != start ) ? separator : "",
- prefixString,
- width, "",
- ( width > 0 ) ? " " : "",
- hexString,
- asciiString,
- byteCountString,
- newline );
- }
- }
- else
- {
- if( src == start )
- {
- dst += DebugPrintF( inLevel,
- "%*s" // Indention
- "%s" // Separator (only if needed)
- "%s" // Prefix
- "%-*.*s" // Label
- "%s" // Separator
- "%s" // Hex
- "%s" // ASCII
- "%s" // Byte Count
- "%s", // Newline
- inIndent, "",
- ( src != start ) ? separator : "",
- prefixString,
- width, (int) inLabelSize, inLabel,
- ( width > 0 ) ? " " : "",
- hexString,
- asciiString,
- byteCountString,
- newline );
- }
- else
- {
- dst += DebugPrintF( inLevel,
- "%*s" // Indention
- "%s" // Separator (only if needed)
- "%s" // Prefix
- "%*s" // Label Spacing
- "%s" // Separator
- "%s" // Hex
- "%s" // ASCII
- "%s" // Byte Count
- "%s", // Newline
- inIndent, "",
- ( src != start ) ? separator : "",
- prefixString,
- width, "",
- ( width > 0 ) ? " " : "",
- hexString,
- asciiString,
- byteCountString,
- newline );
- }
- }
-
- // Move to the next chunk. Exit if there is no more data.
-
- offset += (int) chunkSize;
- src += chunkSize;
- inDataSize -= chunkSize;
- if( inDataSize == 0 )
- {
- break;
- }
- }
-
- // Note: The "dst - outBuffer" size calculation works even if "outBuffer" is NULL because it's all relative.
-
- return( (size_t)( dst - outBuffer ) );
-}
-
-//===========================================================================================================================
-// DebugNumVersionToString
-//===========================================================================================================================
-
-static char * DebugNumVersionToString( uint32_t inVersion, char *inString )
-{
- char * s;
- uint8_t majorRev;
- uint8_t minor;
- uint8_t bugFix;
- uint8_t stage;
- uint8_t revision;
-
- check( inString );
-
- majorRev = (uint8_t)( ( inVersion >> 24 ) & 0xFF );
- minor = (uint8_t)( ( inVersion >> 20 ) & 0x0F );
- bugFix = (uint8_t)( ( inVersion >> 16 ) & 0x0F );
- stage = (uint8_t)( ( inVersion >> 8 ) & 0xFF );
- revision = (uint8_t)( inVersion & 0xFF );
-
- // Convert the major, minor, and bugfix numbers.
-
- s = inString;
- s += sprintf( s, "%u", majorRev );
- s += sprintf( s, ".%u", minor );
- if( bugFix != 0 )
- {
- s += sprintf( s, ".%u", bugFix );
- }
-
- // Convert the version stage and non-release revision number.
-
- switch( stage )
- {
- case kVersionStageDevelopment:
- s += sprintf( s, "d%u", revision );
- break;
-
- case kVersionStageAlpha:
- s += sprintf( s, "a%u", revision );
- break;
-
- case kVersionStageBeta:
- s += sprintf( s, "b%u", revision );
- break;
-
- case kVersionStageFinal:
-
- // A non-release revision of zero is a special case indicating the software is GM (at the golden master
- // stage) and therefore, the non-release revision should not be added to the string.
-
- if( revision != 0 )
- {
- s += sprintf( s, "f%u", revision );
- }
- break;
-
- default:
- dlog( kDebugLevelError, "invalid NumVersion stage (0x%02X)\n", stage );
- break;
- }
- return( inString );
-}
-
-//===========================================================================================================================
-// DebugTaskLevel
-//===========================================================================================================================
-
-DEBUG_EXPORT uint32_t DebugTaskLevel( void )
-{
- uint32_t level;
-
- level = 0;
-
-#if( TARGET_OS_VXWORKS )
- if( intContext() )
- {
- level |= ( ( 1 << kDebugInterruptLevelShift ) & kDebugInterruptLevelMask );
- }
-#endif
-
- return( level );
-}
-
-#if( TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE )
-//===========================================================================================================================
-// DebugWinEnableConsole
-//===========================================================================================================================
-
-#pragma warning( disable:4311 )
-
-static void DebugWinEnableConsole( void )
-{
- static bool sConsoleEnabled = false;
- BOOL result;
- int fileHandle;
- FILE * file;
- int err;
-
- if( sConsoleEnabled )
- {
- goto exit;
- }
-
- // Create console window.
-
- result = AllocConsole();
- require_quiet( result, exit );
-
- // Redirect stdin to the console stdin.
-
- fileHandle = _open_osfhandle( (long) GetStdHandle( STD_INPUT_HANDLE ), _O_TEXT );
-
- #if( defined( __MWERKS__ ) )
- file = __handle_reopen( (unsigned long) fileHandle, "r", stdin );
- require_quiet( file, exit );
- #else
- file = _fdopen( fileHandle, "r" );
- require_quiet( file, exit );
-
- *stdin = *file;
- #endif
-
- err = setvbuf( stdin, NULL, _IONBF, 0 );
- require_noerr_quiet( err, exit );
-
- // Redirect stdout to the console stdout.
-
- fileHandle = _open_osfhandle( (long) GetStdHandle( STD_OUTPUT_HANDLE ), _O_TEXT );
-
- #if( defined( __MWERKS__ ) )
- file = __handle_reopen( (unsigned long) fileHandle, "w", stdout );
- require_quiet( file, exit );
- #else
- file = _fdopen( fileHandle, "w" );
- require_quiet( file, exit );
-
- *stdout = *file;
- #endif
-
- err = setvbuf( stdout, NULL, _IONBF, 0 );
- require_noerr_quiet( err, exit );
-
- // Redirect stderr to the console stdout.
-
- fileHandle = _open_osfhandle( (long) GetStdHandle( STD_OUTPUT_HANDLE ), _O_TEXT );
-
- #if( defined( __MWERKS__ ) )
- file = __handle_reopen( (unsigned long) fileHandle, "w", stderr );
- require_quiet( file, exit );
- #else
- file = _fdopen( fileHandle, "w" );
- require_quiet( file, exit );
-
- *stderr = *file;
- #endif
-
- err = setvbuf( stderr, NULL, _IONBF, 0 );
- require_noerr_quiet( err, exit );
-
- sConsoleEnabled = true;
-
-exit:
- return;
-}
-
-#pragma warning( default:4311 )
-
-#endif // TARGET_OS_WIN32 && !TARGET_OS_WINDOWS_CE
-
-#if( TARGET_OS_WIN32 )
-//===========================================================================================================================
-// DebugWinCharToTCharString
-//===========================================================================================================================
-
-static TCHAR *
- DebugWinCharToTCharString(
- const char * inCharString,
- size_t inCharCount,
- TCHAR * outTCharString,
- size_t inTCharCountMax,
- size_t * outTCharCount )
-{
- const char * src;
- TCHAR * dst;
- TCHAR * end;
-
- if( inCharCount == kSizeCString )
- {
- inCharCount = strlen( inCharString );
- }
- src = inCharString;
- dst = outTCharString;
- if( inTCharCountMax > 0 )
- {
- inTCharCountMax -= 1;
- if( inTCharCountMax > inCharCount )
- {
- inTCharCountMax = inCharCount;
- }
-
- end = dst + inTCharCountMax;
- while( dst < end )
- {
- *dst++ = (TCHAR) *src++;
- }
- *dst = 0;
- }
- if( outTCharCount )
- {
- *outTCharCount = (size_t)( dst - outTCharString );
- }
- return( outTCharString );
-}
-#endif
-
-#if 0
-#pragma mark -
-#pragma mark == Debugging ==
-#endif
-
-//===========================================================================================================================
-// DebugServicesTest
-//===========================================================================================================================
-
-DEBUG_EXPORT OSStatus DebugServicesTest( void )
-{
- OSStatus err;
- char s[ 512 ];
- uint8_t * p;
- uint8_t data[] =
- {
- 0x11, 0x22, 0x33, 0x44,
- 0x55, 0x66,
- 0x77, 0x88, 0x99, 0xAA,
- 0xBB, 0xCC, 0xDD,
- 0xEE,
- 0xFF,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
- 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0,
- 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, 0x81, 0x91, 0xA1
- };
-
- debug_initialize( kDebugOutputTypeMetaConsole );
-
- // check's
-
- check( 0 && "SHOULD SEE: check" );
- check( 1 && "SHOULD *NOT* SEE: check (valid)" );
- check_string( 0, "SHOULD SEE: check_string" );
- check_string( 1, "SHOULD *NOT* SEE: check_string (valid)" );
- check_noerr( -123 );
- check_noerr( 10038 );
- check_noerr( 22 );
- check_noerr( 0 );
- check_noerr_string( -6712, "SHOULD SEE: check_noerr_string" );
- check_noerr_string( 0, "SHOULD *NOT* SEE: check_noerr_string (valid)" );
- check_translated_errno( 0 >= 0 && "SHOULD *NOT* SEE", -384, -999 );
- check_translated_errno( -1 >= 0 && "SHOULD SEE", -384, -999 );
- check_translated_errno( -1 >= 0 && "SHOULD SEE", 0, -999 );
- check_ptr_overlap( "SHOULD *NOT* SEE" ? 10 : 0, 10, 22, 10 );
- check_ptr_overlap( "SHOULD SEE" ? 10 : 0, 10, 5, 10 );
- check_ptr_overlap( "SHOULD SEE" ? 10 : 0, 10, 12, 6 );
- check_ptr_overlap( "SHOULD SEE" ? 12 : 0, 6, 10, 10 );
- check_ptr_overlap( "SHOULD SEE" ? 12 : 0, 10, 10, 10 );
- check_ptr_overlap( "SHOULD *NOT* SEE" ? 22 : 0, 10, 10, 10 );
- check_ptr_overlap( "SHOULD *NOT* SEE" ? 10 : 0, 10, 20, 10 );
- check_ptr_overlap( "SHOULD *NOT* SEE" ? 20 : 0, 10, 10, 10 );
-
- // require's
-
- require( 0 && "SHOULD SEE", require1 );
- { err = kResponseErr; goto exit; }
-require1:
- require( 1 && "SHOULD *NOT* SEE", require2 );
- goto require2Good;
-require2:
- { err = kResponseErr; goto exit; }
-require2Good:
- require_string( 0 && "SHOULD SEE", require3, "SHOULD SEE: require_string" );
- { err = kResponseErr; goto exit; }
-require3:
- require_string( 1 && "SHOULD *NOT* SEE", require4, "SHOULD *NOT* SEE: require_string (valid)" );
- goto require4Good;
-require4:
- { err = kResponseErr; goto exit; }
-require4Good:
- require_quiet( 0 && "SHOULD SEE", require5 );
- { err = kResponseErr; goto exit; }
-require5:
- require_quiet( 1 && "SHOULD *NOT* SEE", require6 );
- goto require6Good;
-require6:
- { err = kResponseErr; goto exit; }
-require6Good:
- require_noerr( -1, require7 );
- { err = kResponseErr; goto exit; }
-require7:
- require_noerr( 0, require8 );
- goto require8Good;
-require8:
- { err = kResponseErr; goto exit; }
-require8Good:
- require_noerr_string( -2, require9, "SHOULD SEE: require_noerr_string");
- { err = kResponseErr; goto exit; }
-require9:
- require_noerr_string( 0, require10, "SHOULD *NOT* SEE: require_noerr_string (valid)" );
- goto require10Good;
-require10:
- { err = kResponseErr; goto exit; }
-require10Good:
- require_noerr_action_string( -3, require11, dlog( kDebugLevelMax, "action 1 (expected)\n" ), "require_noerr_action_string" );
- { err = kResponseErr; goto exit; }
-require11:
- require_noerr_action_string( 0, require12, dlog( kDebugLevelMax, "action 2\n" ), "require_noerr_action_string (valid)" );
- goto require12Good;
-require12:
- { err = kResponseErr; goto exit; }
-require12Good:
- require_noerr_quiet( -4, require13 );
- { err = kResponseErr; goto exit; }
-require13:
- require_noerr_quiet( 0, require14 );
- goto require14Good;
-require14:
- { err = kResponseErr; goto exit; }
-require14Good:
- require_noerr_action( -5, require15, dlog( kDebugLevelMax, "SHOULD SEE: action 3 (expected)\n" ) );
- { err = kResponseErr; goto exit; }
-require15:
- require_noerr_action( 0, require16, dlog( kDebugLevelMax, "SHOULD *NOT* SEE: action 4\n" ) );
- goto require16Good;
-require16:
- { err = kResponseErr; goto exit; }
-require16Good:
- require_noerr_action_quiet( -4, require17, dlog( kDebugLevelMax, "SHOULD SEE: action 5 (expected)\n" ) );
- { err = kResponseErr; goto exit; }
-require17:
- require_noerr_action_quiet( 0, require18, dlog( kDebugLevelMax, "SHOULD *NOT* SEE: action 6\n" ) );
- goto require18Good;
-require18:
- { err = kResponseErr; goto exit; }
-require18Good:
- require_action( 0 && "SHOULD SEE", require19, dlog( kDebugLevelMax, "SHOULD SEE: action 7 (expected)\n" ) );
- { err = kResponseErr; goto exit; }
-require19:
- require_action( 1 && "SHOULD *NOT* SEE", require20, dlog( kDebugLevelMax, "SHOULD *NOT* SEE: action 8\n" ) );
- goto require20Good;
-require20:
- { err = kResponseErr; goto exit; }
-require20Good:
- require_action_quiet( 0, require21, dlog( kDebugLevelMax, "SHOULD SEE: action 9 (expected)\n" ) );
- { err = kResponseErr; goto exit; }
-require21:
- require_action_quiet( 1, require22, dlog( kDebugLevelMax, "SHOULD *NOT* SEE: action 10\n" ) );
- goto require22Good;
-require22:
- { err = kResponseErr; goto exit; }
-require22Good:
- require_action_string( 0, require23, dlog( kDebugLevelMax, "SHOULD SEE: action 11 (expected)\n" ), "SHOULD SEE: require_action_string" );
- { err = kResponseErr; goto exit; }
-require23:
- require_action_string( 1, require24, dlog( kDebugLevelMax, "SHOULD *NOT* SEE: action 12\n" ), "SHOULD *NOT* SEE: require_action_string" );
- goto require24Good;
-require24:
- { err = kResponseErr; goto exit; }
-require24Good:
-
-#if( defined( __MWERKS__ ) )
- #if( defined( __cplusplus ) && __option( exceptions ) )
- #define COMPILER_HAS_EXCEPTIONS 1
- #else
- #define COMPILER_HAS_EXCEPTIONS 0
- #endif
-#else
- #if( defined( __cplusplus ) )
- #define COMPILER_HAS_EXCEPTIONS 1
- #else
- #define COMPILER_HAS_EXCEPTIONS 0
- #endif
-#endif
-
-#if( COMPILER_HAS_EXCEPTIONS )
- try
- {
- require_throw( 1 && "SHOULD *NOT* SEE" );
- require_throw( 0 && "SHOULD SEE" );
- }
- catch( ... )
- {
- goto require26Good;
- }
- { err = kResponseErr; goto exit; }
-require26Good:
-#endif
-
- // translate_errno
-
- err = translate_errno( 1 != -1, -123, -567 );
- require( ( err == 0 ) && "SHOULD *NOT* SEE", exit );
-
- err = translate_errno( -1 != -1, -123, -567 );
- require( ( err == -123 ) && "SHOULD *NOT* SEE", exit );
-
- err = translate_errno( -1 != -1, 0, -567 );
- require( ( err == -567 ) && "SHOULD *NOT* SEE", exit );
-
- // debug_string
-
- debug_string( "debug_string" );
-
- // DebugSNPrintF
-
- DebugSNPrintF( s, sizeof( s ), "%d", 1234 );
- require_action( strcmp( s, "1234" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%X", 0x2345 );
- require_action( strcmp( s, "2345" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%#s", "\05test" );
- require_action( strcmp( s, "test" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%##s", "\03www\05apple\03com" );
- require_action( strcmp( s, "www.apple.com." ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%ld", (long) INT32_C( 2147483647 ) );
- require_action( strcmp( s, "2147483647" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%lu", (unsigned long) UINT32_C( 4294967295 ) );
- require_action( strcmp( s, "4294967295" ) == 0, exit, err = -1 );
-
- #if( TYPE_LONGLONG_NATIVE )
- DebugSNPrintF( s, sizeof( s ), "%lld", (long_long_compat) INT64_C( 9223372036854775807 ) );
- require_action( strcmp( s, "9223372036854775807" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%lld", (long_long_compat) INT64_C( -9223372036854775807 ) );
- require_action( strcmp( s, "-9223372036854775807" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%llu", (unsigned_long_long_compat) UINT64_C( 18446744073709551615 ) );
- require_action( strcmp( s, "18446744073709551615" ) == 0, exit, err = -1 );
- #endif
-
- DebugSNPrintF( s, sizeof( s ), "%lb", (unsigned long) binary_32( 01111011, 01111011, 01111011, 01111011 ) );
- require_action( strcmp( s, "1111011011110110111101101111011" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%C", 0x41624364 ); // 'AbCd'
- require_action( strcmp( s, "AbCd" ) == 0, exit, err = -1 );
-
- #if( defined( MDNS_DEBUGMSGS ) )
- {
- mDNSAddr maddr;
-
- memset( &maddr, 0, sizeof( maddr ) );
- maddr.type = mDNSAddrType_IPv4;
- maddr.ip.v4.b[ 0 ] = 127;
- maddr.ip.v4.b[ 1 ] = 0;
- maddr.ip.v4.b[ 2 ] = 0;
- maddr.ip.v4.b[ 3 ] = 1;
- DebugSNPrintF( s, sizeof( s ), "%#a", &maddr );
- require_action( strcmp( s, "127.0.0.1" ) == 0, exit, err = -1 );
-
- memset( &maddr, 0, sizeof( maddr ) );
- maddr.type = mDNSAddrType_IPv6;
- maddr.ip.v6.b[ 0 ] = 0xFE;
- maddr.ip.v6.b[ 1 ] = 0x80;
- maddr.ip.v6.b[ 15 ] = 0x01;
- DebugSNPrintF( s, sizeof( s ), "%#a", &maddr );
- require_action( strcmp( s, "FE80:0000:0000:0000:0000:0000:0000:0001" ) == 0, exit, err = -1 );
- }
- #endif
-
- #if( AF_INET )
- {
- struct sockaddr_in sa4;
-
- memset( &sa4, 0, sizeof( sa4 ) );
- sa4.sin_family = AF_INET;
- p = (uint8_t *) &sa4.sin_port;
- p[ 0 ] = (uint8_t)( ( 80 >> 8 ) & 0xFF );
- p[ 1 ] = (uint8_t)( 80 & 0xFF );
- p = (uint8_t *) &sa4.sin_addr.s_addr;
- p[ 0 ] = (uint8_t)( ( INADDR_LOOPBACK >> 24 ) & 0xFF );
- p[ 1 ] = (uint8_t)( ( INADDR_LOOPBACK >> 16 ) & 0xFF );
- p[ 2 ] = (uint8_t)( ( INADDR_LOOPBACK >> 8 ) & 0xFF );
- p[ 3 ] = (uint8_t)( INADDR_LOOPBACK & 0xFF );
- DebugSNPrintF( s, sizeof( s ), "%##a", &sa4 );
- require_action( strcmp( s, "127.0.0.1:80" ) == 0, exit, err = -1 );
- }
- #endif
-
- #if( AF_INET6 )
- {
- struct sockaddr_in6 sa6;
-
- memset( &sa6, 0, sizeof( sa6 ) );
- sa6.sin6_family = AF_INET6;
- p = (uint8_t *) &sa6.sin6_port;
- p[ 0 ] = (uint8_t)( ( 80 >> 8 ) & 0xFF );
- p[ 1 ] = (uint8_t)( 80 & 0xFF );
- sa6.sin6_addr.s6_addr[ 0 ] = 0xFE;
- sa6.sin6_addr.s6_addr[ 1 ] = 0x80;
- sa6.sin6_addr.s6_addr[ 15 ] = 0x01;
- sa6.sin6_scope_id = 2;
- DebugSNPrintF( s, sizeof( s ), "%##a", &sa6 );
- require_action( strcmp( s, "[FE80:0000:0000:0000:0000:0000:0000:0001%2]:80" ) == 0, exit, err = -1 );
- }
- #endif
-
- // Unicode
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "tes" );
- require_action( strcmp( s, "tes" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "test" );
- require_action( strcmp( s, "test" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "testing" );
- require_action( strcmp( s, "test" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "te\xC3\xA9" );
- require_action( strcmp( s, "te\xC3\xA9" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "te\xC3\xA9ing" );
- require_action( strcmp( s, "te\xC3\xA9" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "tes\xC3\xA9ing" );
- require_action( strcmp( s, "tes" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "t\xed\x9f\xbf" );
- require_action( strcmp( s, "t\xed\x9f\xbf" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "t\xed\x9f\xbfing" );
- require_action( strcmp( s, "t\xed\x9f\xbf" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "te\xed\x9f\xbf" );
- require_action( strcmp( s, "te" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 4, "te\xed\x9f\xbfing" );
- require_action( strcmp( s, "te" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 7, "te\xC3\xA9\xed\x9f\xbfing" );
- require_action( strcmp( s, "te\xC3\xA9\xed\x9f\xbf" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 6, "te\xC3\xA9\xed\x9f\xbfing" );
- require_action( strcmp( s, "te\xC3\xA9" ) == 0, exit, err = kResponseErr );
-
- DebugSNPrintF(s, sizeof(s), "%.*s", 5, "te\xC3\xA9\xed\x9f\xbfing" );
- require_action( strcmp( s, "te\xC3\xA9" ) == 0, exit, err = kResponseErr );
-
- #if( TARGET_RT_BIG_ENDIAN )
- DebugSNPrintF( s, sizeof( s ), "%S", "\x00" "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" "\x00" );
- require_action( strcmp( s, "abcd" ) == 0, exit, err = -1 );
- #else
- DebugSNPrintF( s, sizeof( s ), "%S", "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" "\x00" "\x00" );
- require_action( strcmp( s, "abcd" ) == 0, exit, err = -1 );
- #endif
-
- DebugSNPrintF( s, sizeof( s ), "%S",
- "\xFE\xFF" "\x00" "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" "\x00" ); // Big Endian BOM
- require_action( strcmp( s, "abcd" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%S",
- "\xFF\xFE" "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" "\x00" "\x00" ); // Little Endian BOM
- require_action( strcmp( s, "abcd" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%#S", "\x00" "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" "\x00" ); // Big Endian
- require_action( strcmp( s, "abcd" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%##S", "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" "\x00" "\x00" ); // Little Endian
- require_action( strcmp( s, "abcd" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%.*S",
- 4, "\xFE\xFF" "\x00" "a" "\x00" "b" "\x00" "c" "\x00" "d" ); // Big Endian BOM
- require_action( strcmp( s, "abc" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%.*S",
- 4, "\xFF\xFE" "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" ); // Little Endian BOM
- require_action( strcmp( s, "abc" ) == 0, exit, err = -1 );
-
- #if( TARGET_RT_BIG_ENDIAN )
- DebugSNPrintF( s, sizeof( s ), "%.*S", 3, "\x00" "a" "\x00" "b" "\x00" "c" "\x00" "d" );
- require_action( strcmp( s, "abc" ) == 0, exit, err = -1 );
- #else
- DebugSNPrintF( s, sizeof( s ), "%.*S", 3, "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" );
- require_action( strcmp( s, "abc" ) == 0, exit, err = -1 );
- #endif
-
- DebugSNPrintF( s, sizeof( s ), "%#.*S", 3, "\x00" "a" "\x00" "b" "\x00" "c" "\x00" "d" ); // Big Endian
- require_action( strcmp( s, "abc" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%##.*S", 3, "a" "\x00" "b" "\x00" "c" "\x00" "d" "\x00" ); // Little Endian
- require_action( strcmp( s, "abc" ) == 0, exit, err = -1 );
-
- // Misc
-
- DebugSNPrintF( s, sizeof( s ), "%U", "\x10\xb8\xa7\x6b" "\xad\x9d" "\xd1\x11" "\x80\xb4" "\x00\xc0\x4f\xd4\x30\xc8" );
- require_action( strcmp( s, "6ba7b810-9dad-11d1-80b4-00c04fd430c8" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%m", 0 );
- require_action( strcmp( s, "no error" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "%lm", (long) 0 );
- require_action( strcmp( s, "no error" ) == 0, exit, err = -1 );
-
- DebugSNPrintF( s, sizeof( s ), "\"%H\"", "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", 16, 16 );
- DebugPrintF( kDebugLevelMax, "%s\n\n", s );
-
- DebugSNPrintF( s, sizeof( s ), "\"%H\"",
- "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"
- "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8",
- 32, 32 );
- DebugPrintF( kDebugLevelMax, "%s\n\n", s );
-
- DebugSNPrintF( s, sizeof( s ), "\"%H\"", "\x6b\xa7", 2, 2 );
- DebugPrintF( kDebugLevelMax, "%s\n\n", s );
-
- // Hex Dumps
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, "My Label", kSizeCString, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNone, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoAddress | kDebugFlagsNoOffset, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, "My Label", kSizeCString, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoAddress | kDebugFlagsNoOffset, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, "My Label", kSizeCString, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoAddress, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoOffset, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoAddress, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoOffset, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoByteCount, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, "\x41\x62\x43\x64", "\x41\x62\x43\x64", 4, // 'AbCd'
- kDebugFlagsNoAddress | kDebugFlagsNoOffset | kDebugFlagsNoNewLine |
- kDebugFlagsNo32BitSeparator | kDebugFlagsNo16ByteHexPad | kDebugFlagsNoByteCount,
- s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 0, NULL, 0, 0, NULL, 0, data, data, sizeof( data ),
- kDebugFlagsNoAddress | kDebugFlagsNoOffset | kDebugFlagsNoASCII | kDebugFlagsNoNewLine |
- kDebugFlags16BitSeparator | kDebugFlagsNo32BitSeparator |
- kDebugFlagsNo16ByteHexPad | kDebugFlagsNoByteCount, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- s[ 0 ] = '\0';
- DebugHexDump( kDebugLevelMax, 8, NULL, 0, 0, NULL, 0, data, data, sizeof( data ), kDebugFlagsNone, s, sizeof( s ) );
- DebugPrintF( kDebugLevelMax, "%s\n", s );
-
- // dlog's
-
- dlog( kDebugLevelNotice, "dlog\n" );
- dlog( kDebugLevelNotice, "dlog integer: %d\n", 123 );
- dlog( kDebugLevelNotice, "dlog string: \"%s\"\n", "test string" );
- dlogmem( kDebugLevelNotice, data, sizeof( data ) );
-
- // Done
-
- DebugPrintF( kDebugLevelMax, "\n\nALL TESTS DONE\n\n" );
- err = kNoErr;
-
-exit:
- if( err )
- {
- DebugPrintF( kDebugLevelMax, "\n\n### TEST FAILED ###\n\n" );
- }
- return( err );
-}
-
-#endif // DEBUG
diff --git a/src/libs/zeroconf/embed/DebugServices.h b/src/libs/zeroconf/embed/DebugServices.h
deleted file mode 100644
index d4e5c7203d..0000000000
--- a/src/libs/zeroconf/embed/DebugServices.h
+++ /dev/null
@@ -1,1607 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @header DebugServices
-
- Debugging Library
-*/
-
-#ifndef __DEBUG_SERVICES__
-#define __DEBUG_SERVICES__
-
-#include <stdarg.h>
-
-#include "CommonServices.h"
-
-#if( TARGET_OS_VXWORKS )
- #include "logLib.h"
-#endif
-
-#if 0
-#pragma mark == Settings ==
-#endif
-
-//===========================================================================================================================
-// Settings
-//===========================================================================================================================
-
-// General
-
-#if( !defined( DEBUG ) )
- #define DEBUG 0
-#endif
-
-#if( defined( NDEBUG ) && DEBUG )
- #error NDEBUG defined and DEBUG is also enabled...they need to be in-sync
-#endif
-
-// AssertMacros.h/Debugging.h overrides.
-
-#if( !defined( DEBUG_OVERRIDE_APPLE_MACROS ) )
- #define DEBUG_OVERRIDE_APPLE_MACROS 1
-#endif
-
-// Routine name. Uses ISO __func__ where possible. Otherwise, uses the best thing that is available (if anything).
-
-#if( defined( __MWERKS__ ) || ( __GNUC__ > 2 ) || ( ( __GNUC__ == 2 ) && ( __GNUC_MINOR__ >= 9 ) ) )
- #define __ROUTINE__ __func__
-#elif( defined( __GNUC__ ) )
- #define __ROUTINE__ __PRETTY_FUNCTION__
-#elif( defined( _MSC_VER ) && !defined( _WIN32_WCE ) )
- #define __ROUTINE__ __FUNCTION__
-#else
- #define __ROUTINE__ ""
-#endif
-
-// Variable argument macro support. Use ANSI C99 __VA_ARGS__ where possible. Otherwise, use the next best thing.
-
-#if( defined( __GNUC__ ) )
- #if( ( __GNUC__ > 3 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 3) ) )
- #define DEBUG_C99_VA_ARGS 1
- #define DEBUG_GNU_VA_ARGS 0
- #else
- #define DEBUG_C99_VA_ARGS 0
- #define DEBUG_GNU_VA_ARGS 1
- #endif
-#elif( defined( __MWERKS__ ) )
- #define DEBUG_C99_VA_ARGS 1
- #define DEBUG_GNU_VA_ARGS 0
-#else
- #define DEBUG_C99_VA_ARGS 0
- #define DEBUG_GNU_VA_ARGS 0
-#endif
-
-#if 0
-#pragma mark == Output ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_FPRINTF_ENABLED
-
- @abstract Enables ANSI C fprintf output.
-*/
-
-#if( !defined( DEBUG_FPRINTF_ENABLED ) )
- #if( !TARGET_API_MAC_OSX_KERNEL && !TARGET_OS_WINDOWS_CE )
- #define DEBUG_FPRINTF_ENABLED 1
- #else
- #define DEBUG_FPRINTF_ENABLED 0
- #endif
-#else
- #if( TARGET_API_MAC_OSX_KERNEL || TARGET_OS_WINDOWS_CE )
- #error fprintf enabled, but not supported on Mac OS X kernel or Windows CE
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_MAC_OS_X_IOLOG_ENABLED
-
- @abstract Enables IOLog (Mac OS X Kernel) output.
-*/
-
-#if( !defined( DEBUG_MAC_OS_X_IOLOG_ENABLED ) )
- #define DEBUG_MAC_OS_X_IOLOG_ENABLED TARGET_API_MAC_OSX_KERNEL
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_KPRINTF_ENABLED
-
- @abstract Enables kprintf (Mac OS X Kernel) output.
-*/
-
-#if( !defined( DEBUG_KPRINTF_ENABLED ) )
- #define DEBUG_KPRINTF_ENABLED TARGET_API_MAC_OSX_KERNEL
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_IDEBUG_ENABLED
-
- @abstract Enables iDebug (Mac OS X user and Kernel) output.
-
- @discussion
-
- For Mac OS X kernel development, iDebug is enabled by default because we can dynamically check for the presence
- of iDebug via some exported IOKit symbols. Mac OS X app usage doesn't allow dynamic detection because it relies
- on statically linking to the iDebugServices.cp file so for Mac OS X app usage, you have to manually enable iDebug.
-*/
-
-#if( !defined( DEBUG_IDEBUG_ENABLED ) )
- #define DEBUG_IDEBUG_ENABLED TARGET_API_MAC_OSX_KERNEL
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_CORE_SERVICE_ASSERTS_ENABLED
-
- @abstract Controls whether Core Services assert handling is enabled. Enabling requires CoreServices framework.
-*/
-
-#if( !defined( DEBUG_CORE_SERVICE_ASSERTS_ENABLED ) )
- #if( defined( __DEBUGGING__ ) )
- #define DEBUG_CORE_SERVICE_ASSERTS_ENABLED 1
- #else
- #define DEBUG_CORE_SERVICE_ASSERTS_ENABLED 0
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef DebugOutputType
-
- @abstract Type of debug output (i.e. where the output goes).
-*/
-
-typedef uint32_t DebugOutputType;
-
-#define kDebugOutputTypeNone 0x6E6F6E65U // 'none' - no params
-#define kDebugOutputTypeCustom 0x63757374U // 'cust' - 1st param = function ptr, 2nd param = context
-#define kDebugOutputTypeFPrintF 0x66707269U // 'fpri' - 1st param = DebugOutputTypeFlags [, 2nd param = filename]
-#define kDebugOutputTypeiDebug 0x69646267U // 'idbg' - no params
-#define kDebugOutputTypeKPrintF 0x6B707266U // 'kprf' - no params
-#define kDebugOutputTypeMacOSXIOLog 0x696C6F67U // 'ilog' - no params
-#define kDebugOutputTypeMacOSXLog 0x786C6F67U // 'xlog' - no params
-#define kDebugOutputTypeWindowsDebugger 0x77696E64U // 'wind' - no params
-#define kDebugOutputTypeWindowsEventLog 0x7765766CU // 'wevl' - 1st param = C-string name, 2nd param = HMODULE or NULL.
-
-// Console meta output kind - Any kind of Console output (in horizontal order of preference):
-//
-// Mac OS X = ANSI printf (viewable in Console.app)
-// Mac OS X Kernel = IOLog (/var/log/system.log) or kprintf (serial).
-// Windows = ANSI printf (Console window) or OutputDebugString (debugger).
-// Other = ANSI printf (viewer varies).
-
-#define kDebugOutputTypeMetaConsole 0x434F4E53U // 'CONS' - no params
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef DebugOutputTypeFlags
-
- @abstract Flags controlling how the output type is configured.
-
- @constant kDebugOutputTypeFlagsTypeMask Bit mask for the output type (e.g. stdout, stderr, file, etc.).
- @constant kDebugOutputTypeFlagsStdOut fprintf should go to stdout.
- @constant kDebugOutputTypeFlagsStdErr fprintf should go to stderr.
- @constant kDebugOutputTypeFlagsFile fprintf should go to a specific file (filename passed as va_arg).
-*/
-
-typedef unsigned int DebugOutputTypeFlags;
-
-#define kDebugOutputTypeFlagsTypeMask 0xF
-#define kDebugOutputTypeFlagsStdOut 1
-#define kDebugOutputTypeFlagsStdErr 2
-#define kDebugOutputTypeFlagsFile 10
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef DebugOutputFunctionPtr
-
- @abstract Function ptr for a custom callback to print debug output.
-*/
-
-typedef void ( *DebugOutputFunctionPtr )( char *inData, size_t inSize, void *inContext );
-
-//===========================================================================================================================
-// Constants
-//===========================================================================================================================
-
-#if 0
-#pragma mark == Flags ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef DebugFlags
-
- @abstract Flags controlling how output is printed.
-*/
-
-typedef uint32_t DebugFlags;
-
-#define kDebugFlagsNone 0
-#define kDebugFlagsNoAddress ( 1 << 0 )
-#define kDebugFlagsNoOffset ( 1 << 1 )
-#define kDebugFlags32BitOffset ( 1 << 2 )
-#define kDebugFlagsNoASCII ( 1 << 3 )
-#define kDebugFlagsNoNewLine ( 1 << 4 )
-#define kDebugFlags8BitSeparator ( 1 << 5 )
-#define kDebugFlags16BitSeparator ( 1 << 6 )
-#define kDebugFlagsNo32BitSeparator ( 1 << 7 )
-#define kDebugFlagsNo16ByteHexPad ( 1 << 8 )
-#define kDebugFlagsNoByteCount ( 1 << 9 )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @enum DebugTaskLevelFlags
-
- @abstract Flags indicating the task level.
-*/
-
-enum
-{
- kDebugInterruptLevelShift = 0,
- kDebugInterruptLevelMask = 0x00000007,
- kDebugInVBLTaskMask = 0x00000010,
- kDebugInDeferredTaskMask = 0x00000020,
- kDebugInSecondaryInterruptHandlerMask = 0x00000040,
- kDebugPageFaultFatalMask = 0x00000100, // There should be a "kPageFaultFatalMask" in Debugging.h.
- kDebugMPTaskLevelMask = 0x00000200, // There should be a "kMPTaskLevelMask" in Debugging.h.
- kDebugInterruptDepthShift = 16,
- kDebugInterruptDepthMask = 0x00FF0000
-};
-
-#define DebugExtractTaskLevelInterruptLevel( LEVEL ) \
- ( ( ( LEVEL ) & kDebugInterruptLevelMask ) >> kDebugInterruptLevelShift )
-
-#define DebugExtractTaskLevelInterruptDepth( LEVEL ) \
- ( ( ( LEVEL ) & kDebugInterruptDepthMask ) >> kDebugInterruptDepthShift )
-
-#if 0
-#pragma mark == Levels ==
-#endif
-
-//===========================================================================================================================
-// Constants & Types - Levels
-//===========================================================================================================================
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef DebugLevel
-
- @abstract Level used to control debug logging.
-*/
-
-typedef int32_t DebugLevel;
-
-// Levels
-
-#define kDebugLevelMask 0x0000FFFF
-#define kDebugLevelChatty 100
-#define kDebugLevelVerbose 500
-#define kDebugLevelTrace 800
-#define kDebugLevelInfo 1000
-#define kDebugLevelNotice 3000
-#define kDebugLevelWarning 5000
-#define kDebugLevelAssert 6000
-#define kDebugLevelRequire 7000
-#define kDebugLevelError 8000
-#define kDebugLevelCritical 9000
-#define kDebugLevelAlert 10000
-#define kDebugLevelEmergency 11000
-#define kDebugLevelTragic 12000
-#define kDebugLevelMax 0x0000FFFF
-
-// Level Flags
-
-#define kDebugLevelFlagMask 0xFFFF0000
-#define kDebugLevelFlagStackTrace 0x00010000
-#define kDebugLevelFlagDebugBreak 0x00020000
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef LogLevel
-
- @abstract Level used to control which events are logged.
-*/
-
-typedef int32_t LogLevel;
-
-#define kLogLevelUninitialized -1L
-#define kLogLevelAll 0L
-#define kLogLevelChatty 100L
-#define kLogLevelVerbose 500L
-#define kLogLevelTrace 800L
-#define kLogLevelInfo 1000L
-#define kLogLevelNotice 3000L
-#define kLogLevelWarning 4000L
-#define kLogLevelAssert 6000L
-#define kLogLevelRequire 7000L
-#define kLogLevelError 8000L
-#define kLogLevelCritical 9000L
-#define kLogLevelAlert 10000L
-#define kLogLevelEmergency 11000L
-#define kLogLevelTragic 12000L
-#define kLogLevelOff 0x0000FFFEL
-
-#if 0
-#pragma mark == Properties ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @typedef DebugPropertyTag
-
- @abstract Tag for properties.
-*/
-
-typedef uint32_t DebugPropertyTag;
-
-#define kDebugPropertyTagPrintLevelMin 0x6D696E70U // 'minp' Get: 1st param = DebugLevel *
- // Set: 1st param = DebugLevel
-
-#define kDebugPropertyTagPrintLevel kDebugPropertyTagPrintLevelMin
-
-#define kDebugPropertyTagPrintLevelMax 0x706D786CU // 'maxp' Get: 1st param = DebugLevel *
- // Set: 1st param = DebugLevel
-
-#define kDebugPropertyTagBreakLevel 0x62726B6CU // 'brkl' Get: 1st param = DebugLevel *
- // Set: 1st param = DebugLevel
-#if 0
-#pragma mark == General macros ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_UNUSED
-
- @abstract Macro to mark a paramter as unused to avoid unused parameter warnings.
-
- @discussion
-
- There is no universally supported pragma/attribute for indicating a variable is unused. DEBUG_UNUSED lets us
- indicate a variable is unused in a manner that is supported by most compilers.
-*/
-
-#define DEBUG_UNUSED( X ) (void)( X )
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_USE_ONLY
-
- @abstract Macro to mark a variable as used only when debugging is enabled.
-
- @discussion
-
- Variables are sometimes needed only for debugging. When debugging is turned off, these debug-only variables generate
- compiler warnings about unused variables. To eliminate these warnings, use these macros to indicate variables that
- are only used for debugging.
-*/
-
-#if( DEBUG )
- #define DEBUG_USE_ONLY( X )
-#else
- #define DEBUG_USE_ONLY( X ) (void)( X )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_LOCAL
-
- @abstract Macros to make variables and functions static when debugging is off, but extern when debugging is on.
-
- @discussion
-
- Rather than using "static" directly, using this macros allows you to access these variables external while
- debugging without being penalized for production builds.
-*/
-
-#if( DEBUG )
- #define DEBUG_LOCAL
-#else
- #define DEBUG_LOCAL static
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_STATIC
-
- @abstract Macros to make variables and functions static when debugging is off, but extern when debugging is on.
-
- @discussion
-
- Rather than using "static" directly, using this macros allows you to access these variables external while
- debugging without being penalized for production builds.
-*/
-
-#if( DEBUG )
- #define DEBUG_STATIC
-#else
- #define DEBUG_STATIC static
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DEBUG_EXPORT
-
- @abstract Macros to export variables.
-
- @discussion
-
- "__private_extern__" is a hack for IOKit to allow symbols to be exported from compilation units, but
- // not exported outside a driver (IOKit uses a lame global namespace for symbols). This still does not
- // solve the problem of multiple drivers in the same dependency chain since they share symbols.
-*/
-
-#if( TARGET_API_MAC_OSX_KERNEL )
- #define DEBUG_EXPORT __private_extern__
-#else
- #define DEBUG_EXPORT extern
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined debug_add
-
- @abstract Macro to add (or subtract if negative) a value when debugging is on. Does nothing if debugging is off.
-*/
-
-#if( DEBUG )
- #define debug_add( A, B ) ( A ) += ( B )
-#else
- #define debug_add( A, B )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined debug_perform
-
- @abstract Macro to perform something in debug-only builds.
-*/
-
-#if( DEBUG )
- #define debug_perform( X ) do { X; } while( 0 )
-#else
- #define debug_perform( X )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function translate_errno
-
- @abstract Returns 0 if the test success. If the test fails, returns errno if non-zero and othewise the alternate error.
-*/
-
-#define translate_errno( TEST, ERRNO, ALTERNATE_ERROR ) ( ( TEST ) ? 0 : ( ERRNO ) ? ( ERRNO ) : ( ALTERNATE_ERROR ) )
-
-#if 0
-#pragma mark == Compile Time macros ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check_compile_time
-
- @abstract Performs a compile-time check of something such as the size of an int.
-
- @discussion
-
- This declares an array with a size that is determined by a compile-time expression. If the expression evaluates
- to 0, the array has a size of -1, which is illegal and generates a compile-time error.
-
- For example:
-
- check_compile_time( sizeof( int ) == 4 );
-
- Note: This only works with compile-time expressions.
- Note: This only works in places where extern declarations are allowed (e.g. global scope).
-
- References:
-
- <http://www.jaggersoft.com/pubs/CVu11_3.html>
- <http://www.jaggersoft.com/pubs/CVu11_5.html>
-
- Note: The following macros differ from the macros on the www.jaggersoft.com web site because those versions do not
- work with GCC due to GCC allow a zero-length array. Using a -1 condition turned out to be more portable.
-*/
-
-#define check_compile_time( X ) extern int debug_compile_time_name[ ( X ) ? 1 : -1 ]
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check_compile_time_code
-
- @abstract Perform a compile-time check, suitable for placement in code, of something such as the size of an int.
-
- @discussion
-
- This creates a switch statement with an existing case for 0 and an additional case using the result of a
- compile-time expression. A switch statement cannot have two case labels with the same constant so if the
- compile-time expression evaluates to 0, it is illegal and generates a compile-time error. If the compile-time
- expression does not evaluate to 0, the resulting value is used as the case label and it compiles without error.
-
- For example:
-
- check_compile_time_code( sizeof( int ) == 4 );
-
- Note: This only works with compile-time expressions.
- Note: This does not work in a global scope so it must be inside a function.
-
- References:
-
- <http://www.jaggersoft.com/pubs/CVu11_3.html>
- <http://www.jaggersoft.com/pubs/CVu11_5.html>
-*/
-
-#define check_compile_time_code( X ) switch( 0 ) { case 0: case X:; }
-
-#if 0
-#pragma mark == check macros ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check
-
- @abstract Check that an expression is true (non-zero).
-
- @discussion
-
- If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
- function name, etc.) using the default debugging output method.
-
- Code inside check() statements is not compiled into production builds.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef check
-#endif
-#if( !defined( check ) )
- #if( DEBUG )
- #define check( X ) \
- do \
- { \
- if( !( X ) ) \
- { \
- debug_print_assert( 0, #X, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- } \
- } while( 0 )
- #else
- #define check( X )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check_string
-
- @abstract Check that an expression is true (non-zero) with an explanation.
-
- @discussion
-
- If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
- function name, etc.) and a custom explanation string using the default debugging output method.
-
- Code inside check_string() statements is not compiled into production builds.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef check_string
-#endif
-#if( !defined( check_string ) )
- #if( DEBUG )
- #define check_string( X, STR ) \
- do \
- { \
- if( !( X ) ) \
- { \
- debug_print_assert( 0, #X, STR, __FILE__, __LINE__, __ROUTINE__ ); \
- } \
- \
- } while( 0 )
- #else
- #define check_string( X, STR )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check_noerr
-
- @abstract Check that an error code is noErr (0).
-
- @discussion
-
- If the error code is non-0, this prints debugging information (actual expression string, file, line number,
- function name, etc.) using the default debugging output method.
-
- Code inside check_noerr() statements is not compiled into production builds.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef check_noerr
-#endif
-#if( !defined( check_noerr ) )
- #if( DEBUG )
- #define check_noerr( ERR ) \
- do \
- { \
- int_least32_t localErr; \
- \
- localErr = (int_least32_t)( ERR ); \
- if( localErr != 0 ) \
- { \
- debug_print_assert( localErr, NULL, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- } \
- \
- } while( 0 )
- #else
- #define check_noerr( ERR )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check_noerr_string
-
- @abstract Check that an error code is noErr (0) with an explanation.
-
- @discussion
-
- If the error code is non-0, this prints debugging information (actual expression string, file, line number,
- function name, etc.) and a custom explanation string using the default debugging output method.
-
- Code inside check_noerr_string() statements is not compiled into production builds.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef check_noerr_string
-#endif
-#if( !defined( check_noerr_string ) )
- #if( DEBUG )
- #define check_noerr_string( ERR, STR ) \
- do \
- { \
- int_least32_t localErr; \
- \
- localErr = (int_least32_t)( ERR ); \
- if( localErr != 0 ) \
- { \
- debug_print_assert( localErr, NULL, STR, __FILE__, __LINE__, __ROUTINE__ ); \
- } \
- \
- } while( 0 )
- #else
- #define check_noerr_string( ERR, STR )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check_translated_errno
-
- @abstract Check a condition and prints errno (if non-zero) to the log.
-
- @discussion
-
- Code inside check_translated_errno() statements is not compiled into production builds.
-*/
-
-#if( !defined( check_translated_errno ) )
- #if( DEBUG )
- #define check_translated_errno( TEST, ERRNO, ALTERNATE_ERROR ) \
- do \
- { \
- if( !( TEST ) ) \
- { \
- int_least32_t localErr; \
- \
- localErr = (int_least32_t)( ERRNO ); \
- localErr = ( localErr != 0 ) ? localErr : (int_least32_t)( ALTERNATE_ERROR ); \
- debug_print_assert( localErr, #TEST, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- } \
- \
- } while( 0 )
- #else
- #define check_translated_errno( TEST, ERRNO, ALTERNATE_ERROR )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined check_ptr_overlap
-
- @abstract Checks that two ptrs do not overlap.
-*/
-
-#define check_ptr_overlap( P1, P1_SIZE, P2, P2_SIZE ) \
- do \
- { \
- check( !( ( (uintptr_t)( P1 ) >= (uintptr_t)( P2 ) ) && \
- ( (uintptr_t)( P1 ) < ( ( (uintptr_t)( P2 ) ) + ( P2_SIZE ) ) ) ) ); \
- check( !( ( (uintptr_t)( P2 ) >= (uintptr_t)( P1 ) ) && \
- ( (uintptr_t)( P2 ) < ( ( (uintptr_t)( P1 ) ) + ( P1_SIZE ) ) ) ) ); \
- \
- } while( 0 )
-
-#if 0
-#pragma mark == require macros ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require
-
- @abstract Requires that an expression evaluate to true.
-
- @discussion
-
- If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
- function name, etc.) using the default debugging output method then jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require
-#endif
-#if( !defined( require ) )
- #define require( X, LABEL ) \
- do \
- { \
- if( !( X ) ) \
- { \
- debug_print_assert( 0, #X, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_string
-
- @abstract Requires that an expression evaluate to true with an explanation.
-
- @discussion
-
- If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
- function name, etc.) and a custom explanation string using the default debugging output method then jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_string
-#endif
-#if( !defined( require_string ) )
- #define require_string( X, LABEL, STR ) \
- do \
- { \
- if( !( X ) ) \
- { \
- debug_print_assert( 0, #X, STR, __FILE__, __LINE__, __ROUTINE__ ); \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_quiet
-
- @abstract Requires that an expression evaluate to true.
-
- @discussion
-
- If expression evalulates to false, this jumps to a label. No debugging information is printed.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_quiet
-#endif
-#if( !defined( require_quiet ) )
- #define require_quiet( X, LABEL ) \
- do \
- { \
- if( !( X ) ) \
- { \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_noerr
-
- @abstract Require that an error code is noErr (0).
-
- @discussion
-
- If the error code is non-0, this prints debugging information (actual expression string, file, line number,
- function name, etc.) using the default debugging output method then jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_noerr
-#endif
-#if( !defined( require_noerr ) )
- #define require_noerr( ERR, LABEL ) \
- do \
- { \
- int_least32_t localErr; \
- \
- localErr = (int_least32_t)( ERR ); \
- if( localErr != 0 ) \
- { \
- debug_print_assert( localErr, NULL, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_noerr_string
-
- @abstract Require that an error code is noErr (0).
-
- @discussion
-
- If the error code is non-0, this prints debugging information (actual expression string, file, line number,
- function name, etc.), and a custom explanation string using the default debugging output method using the
- default debugging output method then jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_noerr_string
-#endif
-#if( !defined( require_noerr_string ) )
- #define require_noerr_string( ERR, LABEL, STR ) \
- do \
- { \
- int_least32_t localErr; \
- \
- localErr = (int_least32_t)( ERR ); \
- if( localErr != 0 ) \
- { \
- debug_print_assert( localErr, NULL, STR, __FILE__, __LINE__, __ROUTINE__ ); \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_noerr_action_string
-
- @abstract Require that an error code is noErr (0).
-
- @discussion
-
- If the error code is non-0, this prints debugging information (actual expression string, file, line number,
- function name, etc.), and a custom explanation string using the default debugging output method using the
- default debugging output method then executes an action and jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_noerr_action_string
-#endif
-#if( !defined( require_noerr_action_string ) )
- #define require_noerr_action_string( ERR, LABEL, ACTION, STR ) \
- do \
- { \
- int_least32_t localErr; \
- \
- localErr = (int_least32_t)( ERR ); \
- if( localErr != 0 ) \
- { \
- debug_print_assert( localErr, NULL, STR, __FILE__, __LINE__, __ROUTINE__ ); \
- { ACTION; } \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_noerr_quiet
-
- @abstract Require that an error code is noErr (0).
-
- @discussion
-
- If the error code is non-0, this jumps to a label. No debugging information is printed.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_noerr_quiet
-#endif
-#if( !defined( require_noerr_quiet ) )
- #define require_noerr_quiet( ERR, LABEL ) \
- do \
- { \
- if( ( ERR ) != 0 ) \
- { \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_noerr_action
-
- @abstract Require that an error code is noErr (0) with an action to execute otherwise.
-
- @discussion
-
- If the error code is non-0, this prints debugging information (actual expression string, file, line number,
- function name, etc.) using the default debugging output method then executes an action and jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_noerr_action
-#endif
-#if( !defined( require_noerr_action ) )
- #define require_noerr_action( ERR, LABEL, ACTION ) \
- do \
- { \
- int_least32_t localErr; \
- \
- localErr = (int_least32_t)( ERR ); \
- if( localErr != 0 ) \
- { \
- debug_print_assert( localErr, NULL, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- { ACTION; } \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_noerr_action_quiet
-
- @abstract Require that an error code is noErr (0) with an action to execute otherwise.
-
- @discussion
-
- If the error code is non-0, this executes an action and jumps to a label. No debugging information is printed.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_noerr_action_quiet
-#endif
-#if( !defined( require_noerr_action_quiet ) )
- #define require_noerr_action_quiet( ERR, LABEL, ACTION ) \
- do \
- { \
- if( ( ERR ) != 0 ) \
- { \
- { ACTION; } \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_action
-
- @abstract Requires that an expression evaluate to true with an action to execute otherwise.
-
- @discussion
-
- If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
- function name, etc.) using the default debugging output method then executes an action and jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_action
-#endif
-#if( !defined( require_action ) )
- #define require_action( X, LABEL, ACTION ) \
- do \
- { \
- if( !( X ) ) \
- { \
- debug_print_assert( 0, #X, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- { ACTION; } \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_action_quiet
-
- @abstract Requires that an expression evaluate to true with an action to execute otherwise.
-
- @discussion
-
- If expression evalulates to false, this executes an action and jumps to a label. No debugging information is printed.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_action_quiet
-#endif
-#if( !defined( require_action_quiet ) )
- #define require_action_quiet( X, LABEL, ACTION ) \
- do \
- { \
- if( !( X ) ) \
- { \
- { ACTION; } \
- goto LABEL; \
- } \
- \
- } while( 0 )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_action_string
-
- @abstract Requires that an expression evaluate to true with an explanation and action to execute otherwise.
-
- @discussion
-
- If expression evalulates to false, this prints debugging information (actual expression string, file, line number,
- function name, etc.) and a custom explanation string using the default debugging output method then executes an
- action and jumps to a label.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef require_action_string
-#endif
-#if( !defined( require_action_string ) )
- #define require_action_string( X, LABEL, ACTION, STR ) \
- do \
- { \
- if( !( X ) ) \
- { \
- debug_print_assert( 0, #X, STR, __FILE__, __LINE__, __ROUTINE__ ); \
- { ACTION; } \
- goto LABEL; \
- } \
- \
- } while( 0 )
-
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined require_throw
-
- @abstract Requires that an expression evaluates to true or an exception is thrown.
-
- @discussion
-
- If the expression evaluates to false, this prints debugging information (actual expression string, file,
- line number, function name, etc.) using the default debugging output method then throws an exception.
-*/
-
-#if( defined( __cplusplus ) )
- #define require_throw( X ) \
- do \
- { \
- if( !( X ) ) \
- { \
- debug_print_assert( 0, #X, NULL, __FILE__, __LINE__, __ROUTINE__ ); \
- throw kUnknownErr; \
- } \
- \
- } while( 0 )
-#endif
-
-#if 0
-#pragma mark == Design-By-Contract macros ==
-#endif
-
-//===========================================================================================================================
-// Design-By-Contract macros
-//===========================================================================================================================
-
-#define ensure( X ) check( X )
-#define ensure_string( X, STR ) check_string( X, STR )
-#define ensure_noerr( ERR ) check_noerr( ERR )
-#define ensure_noerr_string( ERR, STR ) check_noerr_string( ERR, STR )
-#define ensure_translated_errno( TEST, ERRNO, ALTERNATE_ERROR ) check_translated_errno( TEST, ERRNO, ALTERNATE_ERROR )
-
-// Note: Design-By-Contract "require" macros are already defined elsewhere.
-
-#if 0
-#pragma mark == Expect macros ==
-#endif
-
-//===========================================================================================================================
-// Expect macros
-//===========================================================================================================================
-
-// Expect macros allow code to include runtime checking of things that should not happen in shipping code (e.g. internal
-// programmer errors, such as a NULL parameter where it is not allowed). Once the code has been verified to work correctly
-// without asserting, the DEBUG_EXPECT_VERIFIED conditional can be set to eliminate the error checking entirely. It can
-// also be useful to measure the cost of error checking code by profiling with it enable and with it disabled.
-
-#if( DEBUG_EXPECT_VERIFIED )
- #define require_expect
- #define require_string_expect
- #define require_quiet_expect
- #define require_noerr_expect
- #define require_noerr_string_expect
- #define require_noerr_action_string_expect
- #define require_noerr_quiet_expect
- #define require_noerr_action_expect
- #define require_noerr_action_quiet_expect
- #define require_action_expect
- #define require_action_quiet_expect
- #define require_action_string_expect
-#else
- #define require_expect require
- #define require_string_expect require_string
- #define require_quiet_expect require_quiet
- #define require_noerr_expect require_noerr
- #define require_noerr_string_expect require_noerr_string
- #define require_noerr_action_string_expect require_noerr_action_string
- #define require_noerr_quiet_expect require_noerr_quiet
- #define require_noerr_action_expect require_noerr_action
- #define require_noerr_action_quiet_expect require_noerr_action_quiet
- #define require_action_expect require_action
- #define require_action_quiet_expect require_action_quiet
- #define require_action_string_expect require_action_string
-#endif
-
-#if 0
-#pragma mark == Output macros ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined debug_string
-
- @abstract Prints a debugging C string.
-*/
-
-#if( DEBUG_OVERRIDE_APPLE_MACROS )
- #undef debug_string
-#endif
-#if( !defined( debug_string ) )
- #if( DEBUG )
- #define debug_string( STR ) \
- do \
- { \
- debug_print_assert( 0, NULL, STR, __FILE__, __LINE__, __ROUTINE__ ); \
- \
- } while( 0 )
- #else
- #define debug_string( STR )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined debug_print_assert
-
- @abstract Prints an assertion.
-*/
-
-#if( DEBUG )
- #define debug_print_assert( ERROR_CODE, ASSERT_STRING, MESSAGE, FILENAME, LINE_NUMBER, FUNCTION ) \
- DebugPrintAssert( ERROR_CODE, ASSERT_STRING, MESSAGE, FILENAME, LINE_NUMBER, FUNCTION )
-#else
- #define debug_print_assert( ERROR_CODE, ASSERT_STRING, MESSAGE, FILENAME, LINE_NUMBER, FUNCTION )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined dlog
-
- @abstract Prints a debug-only message.
-*/
-
-#if( DEBUG )
- #if( DEBUG_C99_VA_ARGS )
- #define dlog( ... ) DebugPrintF( __VA_ARGS__ )
- #elif( DEBUG_GNU_VA_ARGS )
- #define dlog( ARGS... ) DebugPrintF( ## ARGS )
- #else
- #define dlog DebugPrintF
- #endif
-#else
- #if( DEBUG_C99_VA_ARGS )
- #define dlog( ... )
- #elif( DEBUG_GNU_VA_ARGS )
- #define dlog( ARGS... )
- #else
- #define dlog while( 0 )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined dlogv
-
- @abstract Prints a debug-only message.
-*/
-
-#if( DEBUG )
- #define dlogv( LEVEL, FORMAT, LIST ) DebugPrintFVAList( ( LEVEL ), ( FORMAT ), ( LIST ) )
-#else
- #define dlogv( LEVEL, FORMAT, LIST )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined dlogmem
-
- @abstract Prints a debug-only dump of memory.
-*/
-
-#if( DEBUG )
- #define dlogmem( LEVEL, PTR, SIZE ) \
- DebugHexDump( ( LEVEL ), 0, NULL, 0, 0, NULL, 0, ( PTR ), ( PTR ), ( SIZE ), kDebugFlagsNone, NULL, 0 )
-#else
- #define dlogmem( LEVEL, PTR, SIZE )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DebugNSLog
-
- @abstract Debug-only macro for the Cocoa NSLog function.
-*/
-
-#if( DEBUG )
- #if( DEBUG_C99_VA_ARGS )
- #define DebugNSLog( ... ) NSLog( __VA_ARGS__ )
- #elif( DEBUG_GNU_VA_ARGS )
- #define DebugNSLog( ARGS... ) NSLog( ## ARGS )
- #else
- #define DebugNSLog NSLog
- #endif
-#else
- #if( DEBUG_C99_VA_ARGS )
- #define DebugNSLog( ... )
- #elif( DEBUG_GNU_VA_ARGS )
- #define DebugNSLog( ARGS... )
- #else
- #define DebugNSLog while( 0 )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @defined DebugLogMsg
-
- @abstract Debug-only macro for the VxWorks logMsg function.
-*/
-
-#if( TARGET_OS_VXWORKS )
- #if( DEBUG )
- #define DebugLogMsg( LEVEL, FORMAT, P1, P2, P3, P4, P5, P6 ) \
- do \
- { \
- if( ( inLevel >= gDebugPrintLevelMin ) || ( inLevel <= gDebugPrintLevelMax ) ) \
- { \
- logMsg( ( FORMAT ), ( P1 ), ( P2 ), ( P3 ), ( P4 ), ( P5 ), ( P6 ) ); \
- } \
- \
- } while( 0 )
- #else
- #define DebugLogMsg( LEVEL, FORMAT, P1, P2, P3, P4, P5, P6 )
- #endif
-#else
- #define DebugLogMsg dlog
-#endif
-
-#if 0
-#pragma mark == Routines - General ==
-#endif
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugInitialize
-
- @abstract Initializes the debugging library for a specific kind of output.
-
- @param inType
- @param varArg Variable number parameters, controlled by the "inType" parameter.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT OSStatus DebugInitialize( DebugOutputType inType, ... );
-#endif
-
-#if( DEBUG )
- #if( DEBUG_C99_VA_ARGS )
- #define debug_initialize( ... ) DebugInitialize( __VA_ARGS__ )
- #elif( DEBUG_GNU_VA_ARGS )
- #define debug_initialize( ARGS... ) DebugInitialize( ## ARGS )
- #else
- #define debug_initialize DebugInitialize
- #endif
-#else
- #if( DEBUG_C99_VA_ARGS )
- #define debug_initialize( ... )
- #elif( DEBUG_GNU_VA_ARGS )
- #define debug_initialize( ARGS... )
- #else
- #define debug_initialize while( 0 )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugFinalize
-
- @abstract Releases any resources used by the debugging library
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT void DebugFinalize( void );
-#endif
-
-#if( DEBUG )
- #define debug_terminate() DebugFinalize()
-#else
- #define debug_terminate()
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugGetProperty
-
- @abstract Gets the specified property from the debugging library.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT OSStatus DebugGetProperty( DebugPropertyTag inTag, ... );
-#endif
-
-#if( DEBUG )
- #if( DEBUG_C99_VA_ARGS )
- #define debug_get_property( ... ) DebugGetProperty( __VA_ARGS__ )
- #elif( DEBUG_GNU_VA_ARGS )
- #define debug_get_property( ARGS... ) DebugGetProperty( ## ARGS )
- #else
- #define debug_get_property DebugGetProperty
- #endif
-#else
- #if( DEBUG_C99_VA_ARGS )
- #define debug_get_property( ... )
- #elif( DEBUG_GNU_VA_ARGS )
- #define debug_get_property( ARGS... )
- #else
- #define debug_get_property while( 0 )
- #endif
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugSetProperty
-
- @abstract Sets the specified property from the debugging library.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT OSStatus DebugSetProperty( DebugPropertyTag inTag, ... );
-#endif
-
-#if( DEBUG )
- #if( DEBUG_C99_VA_ARGS )
- #define debug_set_property( ... ) DebugSetProperty( __VA_ARGS__ )
- #elif( DEBUG_GNU_VA_ARGS )
- #define debug_set_property( ARGS... ) DebugSetProperty( ## ARGS )
- #else
- #define debug_set_property DebugSetProperty
- #endif
-#else
- #if( DEBUG_C99_VA_ARGS )
- #define debug_set_property( ... )
- #elif( DEBUG_GNU_VA_ARGS )
- #define debug_set_property( ARGS... )
- #else
- #define debug_set_property while( 0 )
- #endif
-#endif
-
-#if 0
-#pragma mark == Routines - Debugging Output ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugPrintF
-
- @abstract Prints a debug message with printf-style formatting.
-
- @param inLevel Error that generated this assert or noErr.
-
- @param inFormatString
- C string containing assertion text.
-
- @param VAR_ARG
- Variable number of arguments depending on the format string.
-
- @result Number of bytes printed or -1 on error.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT size_t DebugPrintF( DebugLevel inLevel, const char *inFormat, ... );
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugPrintFVAList
-
- @abstract va_list version of DebugPrintF. See DebugPrintF for more info.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT size_t DebugPrintFVAList( DebugLevel inLevel, const char *inFormat, va_list inArgs );
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugPrintAssert
-
- @abstract Prints a message describing the reason the (e.g. an assert failed), an optional error message,
- an optional source filename, an optional source line number.
-
- @param inErrorCode Error that generated this assert or noErr.
- @param inAssertString C string containing assertion text.
- @param inMessage C string containing a message about the assert.
- @param inFileName C string containing path of file where the error occurred.
- @param inLineNumber Line number in source file where the error occurred.
- @param inFunction C string containing name of function where assert occurred.
-
- @discussion
-
- Example output:
-
- [ASSERT] assert: "dataPtr != NULL" allocate memory for object failed
- [ASSERT] where: "MyFile.c", line 123, ("MyFunction")
-
- OR
-
- [ASSERT] error: -6728 (kNoMemoryErr)
- [ASSERT] where: "MyFile.c", line 123, ("MyFunction")
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT void
- DebugPrintAssert(
- int_least32_t inErrorCode,
- const char * inAssertString,
- const char * inMessage,
- const char * inFilename,
- int_least32_t inLineNumber,
- const char * inFunction );
-#endif
-
-#if 0
-#pragma mark == Routines - Utilities ==
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugSNPrintF
-
- @abstract Debugging versions of standard C snprintf with extra features.
-
- @param sbuffer Buffer to receive result. Null terminated unless the buffer size is 0.
- @param buflen Size of the buffer including space for the null terminator.
- @param fmt printf-style format string.
- @param VAR_ARG Variable number of arguments depending on the format string.
-
- @result Number of characters written (minus the null terminator).
-
- @discussion
-
- Extra features over the standard C snprintf:
- <pre>
- 64-bit support for %d (%lld), %i (%lli), %u (%llu), %o (%llo), %x (%llx), and %b (%llb).
- %@ - Cocoa/CoreFoundation object. Param is the object. Strings are used directly. Others use CFCopyDescription.
- %a - Network Address: %.4a=IPv4, %.6a=Ethernet, %.8a Fibre Channel, %.16a=IPv6. Arg=ptr to network address.
- %#a - IPv4 or IPv6 mDNSAddr. Arg=ptr to mDNSAddr.
- %##a - IPv4 (if AF_INET defined) or IPv6 (if AF_INET6 defined) sockaddr. Arg=ptr to sockaddr.
- %b - Binary representation of integer (e.g. 01101011). Modifiers and arg=the same as %d, %x, etc.
- %C - Mac-style FourCharCode (e.g. 'APPL'). Arg=32-bit value to print as a Mac-style FourCharCode.
- %H - Hex Dump (e.g. "\x6b\xa7" -> "6B A7"). 1st arg=ptr, 2nd arg=size, 3rd arg=max size.
- %#H - Hex Dump & ASCII (e.g. "\x41\x62" -> "6B A7 'Ab'"). 1st arg=ptr, 2nd arg=size, 3rd arg=max size.
- %m - Error Message (e.g. 0 -> "kNoErr"). Modifiers and error code arg=the same as %d, %x, etc.
- %#s - Pascal-style length-prefixed string. Arg=ptr to string.
- %##s - DNS label-sequence name. Arg=ptr to name.
- %S - UTF-16 string, 0x0000 terminated. Host order if no BOM. Precision is UTF-16 count. Precision includes BOM.
- %#S - Big Endian UTF-16 string (unless BOM overrides). Otherwise, the same as %S.
- %##S - Little Endian UTF-16 string (unless BOM overrides). Otherwise, the same as %S.
- %U - Universally Unique Identifier (UUID) (e.g. 6ba7b810-9dad-11d1-80b4-00c04fd430c8). Arg=ptr to 16-byte UUID.
- </pre>
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT size_t DebugSNPrintF(char *sbuffer, size_t buflen, const char *fmt, ...);
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugSNPrintFVAList
-
- @abstract va_list version of DebugSNPrintF. See DebugSNPrintF for more info.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT size_t DebugSNPrintFVAList(char *sbuffer, size_t buflen, const char *fmt, va_list arg);
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugGetErrorString
-
- @abstract Gets an error string from an error code.
-
- @param inStatus Error code to get the string for.
- @param inBuffer Optional buffer to copy the string to for non-static strings. May be null.
- @param inBufferSize Size of optional buffer. May be 0.
-
- @result C string containing error string for the error code. Guaranteed to be a valid, static string. If a
- buffer is supplied, the return value will always be a pointer to the supplied buffer, which will
- contain the best available description of the error code. If a buffer is not supplied, the return
- value will be the best available description of the error code that can be represented as a static
- string. This allows code that cannot use a temporary buffer to hold the result to still get a useful
- error string in most cases, but also allows code that can use a temporary buffer to get the best
- available description.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT const char * DebugGetErrorString( int_least32_t inErrorCode, char *inBuffer, size_t inBufferSize );
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugHexDump
-
- @abstract Hex dumps data to a string or to the output device.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT size_t
- DebugHexDump(
- DebugLevel inLevel,
- int inIndent,
- const char * inLabel,
- size_t inLabelSize,
- int inLabelMinWidth,
- const char * inType,
- size_t inTypeSize,
- const void * inDataStart,
- const void * inData,
- size_t inDataSize,
- DebugFlags inFlags,
- char * outBuffer,
- size_t inBufferSize );
-#endif
-
-#if( DEBUG )
- #define dloghex( LEVEL, INDENT, LABEL, LABEL_SIZE, LABEL_MIN_SIZE, TYPE, TYPE_SIZE, DATA_START, DATA, DATA_SIZE, FLAGS, BUFFER, BUFFER_SIZE ) \
- DebugHexDump( ( LEVEL ), (INDENT), ( LABEL ), ( LABEL_SIZE ), ( LABEL_MIN_SIZE ), ( TYPE ), ( TYPE_SIZE ), \
- ( DATA_START ), ( DATA ), ( DATA_SIZE ), ( FLAGS ), ( BUFFER ), ( BUFFER_SIZE ) )
-#else
- #define dloghex( LEVEL, INDENT, LABEL, LABEL_SIZE, LABEL_MIN_SIZE, TYPE, TYPE_SIZE, DATA_START, DATA, DATA_SIZE, FLAGS, BUFFER, BUFFER_SIZE )
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugTaskLevel
-
- @abstract Returns the current task level.
-
- @result Current task level
-
- @discussion
-
- Bit masks to isolate portions of the result (note that some masks may also need bit shifts to right justify):
- <pre>
- kDebugInterruptLevelMask - Indicates the current interrupt level (> 0 means interrupt time).
- kDebugInVBLTaskMask - Indicates if a VBL task is currently being executed.
- kDebugInDeferredTaskMask - Indicates if a Deferred Task is currently being executed.
- kDebugInSecondaryInterruptHandlerMask - Indicates if a Secondary Interrupt Handler is currently being executed.
- kDebugPageFaultFatalMask - Indicates if it is unsafe to cause a page fault (worse than interrupt time).
- kDebugMPTaskLevelMask - Indicates if being called from an MP task.
- kDebugInterruptDepthMask - 0 means task level, 1 means in interrupt, > 1 means in nested interrupt.
- </pre>
-
- Helpers:
- <pre>
- DebugExtractTaskLevelInterruptDepth() - Macro to extract interrupt depth from task level value.
- </pre>
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT uint32_t DebugTaskLevel( void );
-#endif
-
-//---------------------------------------------------------------------------------------------------------------------------
-/*! @function DebugServicesTest
-
- @abstract Unit test.
-*/
-
-#if( DEBUG )
- DEBUG_EXPORT OSStatus DebugServicesTest( void );
-#endif
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif // __DEBUG_SERVICES__
diff --git a/src/libs/zeroconf/embed/dnssd_clientlib.c b/src/libs/zeroconf/embed/dnssd_clientlib.c
deleted file mode 100644
index c4fcf7cd88..0000000000
--- a/src/libs/zeroconf/embed/dnssd_clientlib.c
+++ /dev/null
@@ -1,372 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "../dns_sd_types.h"
-
-#if MDNS_BUILDINGSHAREDLIBRARY || MDNS_BUILDINGSTUBLIBRARY
-//#pragma export on
-#endif
-
-#if defined(_WIN32)
-#ifdef _MSC_VER
-// disable warning "conversion from <data> to uint16_t"
-#pragma warning(disable:4244)
-#endif
-#define strncasecmp _strnicmp
-#define strcasecmp _stricmp
-#endif
-
-/*********************************************************************************************
- *
- * Supporting Functions
- *
- *********************************************************************************************/
-namespace ZeroConf { namespace embeddedLib {
-
-#include "../dns_sd_funct.h"
-
-#define mDNSIsDigit(X) ((X) >= '0' && (X) <= '9')
-
-// DomainEndsInDot returns 1 if name ends with a dot, 0 otherwise
-// (DNSServiceConstructFullName depends this returning 1 for true, rather than any non-zero value meaning true)
-
-static int DomainEndsInDot(const char *dom)
- {
- while (dom[0] && dom[1])
- {
- if (dom[0] == '\\') // advance past escaped byte sequence
- {
- if (mDNSIsDigit(dom[1]) && mDNSIsDigit(dom[2]) && mDNSIsDigit(dom[3]))
- dom += 4; // If "\ddd" then skip four
- else dom += 2; // else if "\x" then skip two
- }
- else dom++; // else goto next character
- }
- return (dom[0] == '.');
- }
-
-static uint8_t *InternalTXTRecordSearch
- (
- uint16_t txtLen,
- const void *txtRecord,
- const char *key,
- unsigned long *keylen
- )
- {
- uint8_t *p = (uint8_t*)txtRecord;
- uint8_t *e = p + txtLen;
- *keylen = (unsigned long) strlen(key);
- while (p<e)
- {
- uint8_t *x = p;
- p += 1 + p[0];
- if (p <= e && *keylen <= x[0] && !strncasecmp(key, (char*)x+1, *keylen))
- if (*keylen == x[0] || x[1+*keylen] == '=') return(x);
- }
- return(NULL);
- }
-
-/*********************************************************************************************
- *
- * General Utility Functions
- *
- *********************************************************************************************/
-
-// Note: Need to make sure we don't write more than kDNSServiceMaxDomainName (1009) bytes to fullName
-// In earlier builds this constant was defined to be 1005, so to avoid buffer overruns on clients
-// compiled with that constant we'll actually limit the output to 1005 bytes.
-
-DNSServiceErrorType DNSSD_API DNSServiceConstructFullName
- (
- char *const fullName,
- const char *const service, // May be NULL
- const char *const regtype,
- const char *const domain
- )
- {
- const size_t len = !regtype ? 0 : strlen(regtype) - DomainEndsInDot(regtype);
- char *fn = fullName;
- char *const lim = fullName + 1005;
- const char *s = service;
- const char *r = regtype;
- const char *d = domain;
-
- // regtype must be at least "x._udp" or "x._tcp"
- if (len < 6 || !domain || !domain[0]) return kDNSServiceErr_BadParam;
- if (strncasecmp((regtype + len - 4), "_tcp", 4) && strncasecmp((regtype + len - 4), "_udp", 4)) return kDNSServiceErr_BadParam;
-
- if (service && *service)
- {
- while (*s)
- {
- unsigned char c = *s++; // Needs to be unsigned, or values like 0xFF will be interpreted as < 32
- if (c <= ' ') // Escape non-printable characters
- {
- if (fn+4 >= lim) goto fail;
- *fn++ = '\\';
- *fn++ = '0' + (c / 100);
- *fn++ = '0' + (c / 10) % 10;
- c = '0' + (c ) % 10;
- }
- else if (c == '.' || (c == '\\')) // Escape dot and backslash literals
- {
- if (fn+2 >= lim) goto fail;
- *fn++ = '\\';
- }
- else
- if (fn+1 >= lim) goto fail;
- *fn++ = (char)c;
- }
- *fn++ = '.';
- }
-
- while (*r) if (fn+1 >= lim) goto fail; else *fn++ = *r++;
- if (!DomainEndsInDot(regtype)) { if (fn+1 >= lim) goto fail; else *fn++ = '.'; }
-
- while (*d) if (fn+1 >= lim) goto fail; else *fn++ = *d++;
- if (!DomainEndsInDot(domain)) { if (fn+1 >= lim) goto fail; else *fn++ = '.'; }
-
- *fn = '\0';
- return kDNSServiceErr_NoError;
-
-fail:
- *fn = '\0';
- return kDNSServiceErr_BadParam;
- }
-
-/*********************************************************************************************
- *
- * TXT Record Construction Functions
- *
- *********************************************************************************************/
-
-typedef struct _TXTRecordRefRealType
- {
- uint8_t *buffer; // Pointer to data
- uint16_t buflen; // Length of buffer
- uint16_t datalen; // Length currently in use
- uint16_t malloced; // Non-zero if buffer was allocated via malloc()
- } TXTRecordRefRealType;
-
-#define txtRec ((TXTRecordRefRealType*)txtRecord)
-
-// The opaque storage defined in the public dns_sd.h header is 16 bytes;
-// make sure we don't exceed that.
-struct CompileTimeAssertionCheck_dnssd_clientlib
- {
- char assert0[(sizeof(TXTRecordRefRealType) <= 16) ? 1 : -1];
- };
-
-void DNSSD_API TXTRecordCreate
- (
- TXTRecordRef *txtRecord,
- uint16_t bufferLen,
- void *buffer
- )
- {
- txtRec->buffer = static_cast<uint8_t *>(buffer);
- txtRec->buflen = buffer ? bufferLen : (uint16_t)0;
- txtRec->datalen = 0;
- txtRec->malloced = 0;
- }
-
-void DNSSD_API TXTRecordDeallocate(TXTRecordRef *txtRecord)
- {
- if (txtRec->malloced) free(txtRec->buffer);
- }
-
-DNSServiceErrorType DNSSD_API TXTRecordSetValue
- (
- TXTRecordRef *txtRecord,
- const char *key,
- uint8_t valueSize,
- const void *value
- )
- {
- uint8_t *start, *p;
- const char *k;
- unsigned long keysize, keyvalsize;
-
- for (k = key; *k; k++) if (*k < 0x20 || *k > 0x7E || *k == '=') return(kDNSServiceErr_Invalid);
- keysize = (unsigned long)(k - key);
- keyvalsize = 1 + keysize + (value ? (1 + valueSize) : 0);
- if (keysize < 1 || keyvalsize > 255) return(kDNSServiceErr_Invalid);
- (void)TXTRecordRemoveValue(txtRecord, key);
- if (txtRec->datalen + keyvalsize > txtRec->buflen)
- {
- unsigned char *newbuf;
- unsigned long newlen = txtRec->datalen + keyvalsize;
- if (newlen > 0xFFFF) return(kDNSServiceErr_Invalid);
- newbuf = static_cast<unsigned char *>(malloc((size_t)newlen));
- if (!newbuf) return(kDNSServiceErr_NoMemory);
- memcpy(newbuf, txtRec->buffer, txtRec->datalen);
- if (txtRec->malloced) free(txtRec->buffer);
- txtRec->buffer = newbuf;
- txtRec->buflen = (uint16_t)(newlen);
- txtRec->malloced = 1;
- }
- start = txtRec->buffer + txtRec->datalen;
- p = start + 1;
- memcpy(p, key, keysize);
- p += keysize;
- if (value)
- {
- *p++ = '=';
- memcpy(p, value, valueSize);
- p += valueSize;
- }
- *start = (uint8_t)(p - start - 1);
- txtRec->datalen += p - start;
- return(kDNSServiceErr_NoError);
- }
-
-DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
- (
- TXTRecordRef *txtRecord,
- const char *key
- )
- {
- unsigned long keylen, itemlen, remainder;
- uint8_t *item = InternalTXTRecordSearch(txtRec->datalen, txtRec->buffer, key, &keylen);
- if (!item) return(kDNSServiceErr_NoSuchKey);
- itemlen = (unsigned long)(1 + item[0]);
- remainder = (unsigned long)((txtRec->buffer + txtRec->datalen) - (item + itemlen));
- // Use memmove because memcpy behaviour is undefined for overlapping regions
- memmove(item, item + itemlen, remainder);
- txtRec->datalen -= itemlen;
- return(kDNSServiceErr_NoError);
- }
-
-uint16_t DNSSD_API TXTRecordGetLength (const TXTRecordRef *txtRecord) { return(txtRec->datalen); }
-const void * DNSSD_API TXTRecordGetBytesPtr(const TXTRecordRef *txtRecord) { return(txtRec->buffer); }
-
-/*********************************************************************************************
- *
- * TXT Record Parsing Functions
- *
- *********************************************************************************************/
-
-int DNSSD_API TXTRecordContainsKey
- (
- uint16_t txtLen,
- const void *txtRecord,
- const char *key
- )
- {
- unsigned long keylen;
- return (InternalTXTRecordSearch(txtLen, txtRecord, key, &keylen) ? 1 : 0);
- }
-
-const void * DNSSD_API TXTRecordGetValuePtr
- (
- uint16_t txtLen,
- const void *txtRecord,
- const char *key,
- uint8_t *valueLen
- )
- {
- unsigned long keylen;
- uint8_t *item = InternalTXTRecordSearch(txtLen, txtRecord, key, &keylen);
- if (!item || item[0] <= keylen) return(NULL); // If key not found, or found with no value, return NULL
- *valueLen = (uint8_t)(item[0] - (keylen + 1));
- return (item + 1 + keylen + 1);
- }
-
-uint16_t DNSSD_API 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 DNSSD_API 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);
- }
-
-/*********************************************************************************************
- *
- * SCCS-compatible version string
- *
- *********************************************************************************************/
-
-// For convenience when using the "strings" command, this is the last thing in the file
-
-// Note: The C preprocessor stringify operator ('#') makes a string from its argument, without macro expansion
-// e.g. If "version" is #define'd to be "4", then STRINGIFY_AWE(version) will return the string "version", not "4"
-// To expand "version" to its value before making the string, use STRINGIFY(version) instead
-#define STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s) #s
-#define STRINGIFY(s) STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s)
-
-// NOT static -- otherwise the compiler may optimize it out
-// The "@(#) " pattern is a special prefix the "what" command looks for
-const char VersionString_SCCS_libdnssd[] = "@(#) libdns_sd " STRINGIFY(mDNSResponderVersion) " (" __DATE__ " " __TIME__ ")";
- }}
diff --git a/src/libs/zeroconf/embed/dnssd_clientstub.c b/src/libs/zeroconf/embed/dnssd_clientstub.c
deleted file mode 100644
index 3367a20f9a..0000000000
--- a/src/libs/zeroconf/embed/dnssd_clientstub.c
+++ /dev/null
@@ -1,2053 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <stdlib.h>
-
-#if APPLE_OSX_mDNSResponder
-#include <mach-o/dyld.h>
-#endif
-
-#include "dnssd_ipc.h"
-
-namespace ZeroConf {
-extern int gQuickStop;
-namespace embeddedLib {
-#include "../dns_sd_funct.h"
-static int gDaemonErr = kDNSServiceErr_NoError;
- }}
-
-#if defined(_WIN32)
-
- #define _SSIZE_T
- #include "CommonServices.h"
- #include "DebugServices.h"
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #include <windows.h>
- #include <stdarg.h>
- #include <stdio.h>
-
- #define sockaddr_mdns sockaddr_in
- #define AF_MDNS AF_INET
-
- #ifdef _MSC_VER
- // Disable warning: "'type cast' : from data pointer 'void *' to function pointer"
- #pragma warning(disable:4055)
-
- // Disable warning: "nonstandard extension, function/data pointer conversion in expression"
- #pragma warning(disable:4152)
- #endif
-
- //extern BOOL IsSystemServiceDisabled();
-
- #define sleep(X) Sleep((X) * 1000)
- #define NOT_HAVE_SA_LEN
-namespace ZeroConf { namespace embeddedLib {
-
- static int g_initWinsock = 0;
- #define LOG_WARNING kDebugLevelWarning
- #define LOG_INFO kDebugLevelInfo
- static void syslog( int priority, const char * message, ...)
- {
- va_list args;
- int len;
- char * buffer;
- DWORD err = WSAGetLastError();
- (void) priority;
- va_start( args, message );
- #ifdef _MSC_VER
- len = _vscprintf( message, args ) + 1;
- buffer = reinterpret_cast<char*>(malloc( len * sizeof(char) ));
- if ( buffer ) {
- vsprintf(buffer, message, args);
- OutputDebugStringA(buffer);
- free(buffer);
- }
- #else // MinGW 4.4, no longer required for 4.6
- len = vsnprintf(NULL, 0, message, args);
- va_end(args);
- if (len == -1) // encoding error
- return;
- buffer = reinterpret_cast<char*>(malloc((len + 1) * sizeof(char)));
- if (buffer == NULL) // no memory allocation possible
- return;
- va_start(args, message);
- len = vsnprintf(buffer, (len + 1) * sizeof(char), message, args);
- va_end(args);
- if (len == -1) { // encoding error
- free(buffer);
- return;
- } else {
- OutputDebugStringA(buffer);
- free(buffer);
- }
- #endif
- WSASetLastError( err );
- }
-}}
-#else
-
- #include <sys/fcntl.h> // For O_RDWR etc.
- #include <sys/time.h>
- #include <sys/socket.h>
- #include <syslog.h>
-
- #define sockaddr_mdns sockaddr_un
- #define AF_MDNS AF_LOCAL
-
-#endif
-
-#ifdef Q_OS_LINUX
-#define NOT_HAVE_SA_LEN
-#endif
-
-// <rdar://problem/4096913> Specifies how many times we'll try and connect to the server.
-
-#define DNSSD_CLIENT_MAXTRIES 4
-
-// Uncomment the line below to use the old error return mechanism of creating a temporary named socket (e.g. in /var/tmp)
-//#define USE_NAMED_ERROR_RETURN_SOCKET 1
-
-#define DNSSD_CLIENT_TIMEOUT 10 // In seconds
-
-#ifndef CTL_PATH_PREFIX
-#define CTL_PATH_PREFIX "/var/tmp/dnssd_result_socket."
-#endif
-
-extern "C" {
-typedef struct
- {
- ipc_msg_hdr ipc_hdr;
- DNSServiceFlags cb_flags;
- uint32_t cb_interface;
- DNSServiceErrorType cb_err;
- } CallbackHeader;
-
-typedef struct _DNSServiceRef_t DNSServiceOp;
-typedef struct _DNSRecordRef_t DNSRecord;
-
-// client stub callback to process message from server and deliver results to client application
-typedef void (*ProcessReplyFn)(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *msg, const char *const end);
-
-#define ValidatorBits 0x12345678
-#define DNSServiceRefValid(X) (dnssd_SocketValid((X)->sockfd) && (((X)->sockfd ^ (X)->validator) == ValidatorBits))
-
-// When using kDNSServiceFlagsShareConnection, there is one primary _DNSServiceOp_t, and zero or more subordinates
-// For the primary, the 'next' field points to the first subordinate, and its 'next' field points to the next, and so on.
-// For the primary, the 'primary' field is NULL; for subordinates the 'primary' field points back to the associated primary
-//
-// _DNS_SD_LIBDISPATCH is defined where libdispatch/GCD is available. This does not mean that the application will use the
-// DNSServiceSetDispatchQueue API. Hence any new code guarded with _DNS_SD_LIBDISPATCH should still be backwards compatible.
-struct _DNSServiceRef_t
- {
- DNSServiceOp *next; // For shared connection
- DNSServiceOp *primary; // For shared connection
- dnssd_sock_t sockfd; // Connected socket between client and daemon
- dnssd_sock_t validator; // Used to detect memory corruption, double disposals, etc.
- client_context_t uid; // For shared connection requests, each subordinate DNSServiceRef has its own ID,
- // unique within the scope of the same shared parent DNSServiceRef
- uint32_t op; // request_op_t or reply_op_t
- uint32_t max_index; // Largest assigned record index - 0 if no additional records registered
- uint32_t logcounter; // Counter used to control number of syslog messages we write
- int *moreptr; // Set while DNSServiceProcessResult working on this particular DNSServiceRef
- ProcessReplyFn ProcessReply; // Function pointer to the code to handle received messages
- void *AppCallback; // Client callback function and context
- void *AppContext;
- DNSRecord *rec;
-#if _DNS_SD_LIBDISPATCH
- dispatch_source_t disp_source;
- dispatch_queue_t disp_queue;
-#endif
- };
-
-struct _DNSRecordRef_t
- {
- DNSRecord *recnext;
- void *AppContext;
- DNSServiceRegisterRecordReply AppCallback;
- DNSRecordRef recref;
- uint32_t record_index; // index is unique to the ServiceDiscoveryRef
- DNSServiceOp *sdr;
- };
-}
-namespace ZeroConf { namespace embeddedLib {
-
-// Write len bytes. Return 0 on success, -1 on error
-static int write_all(dnssd_sock_t sd, char *buf, size_t len)
- {
- // Don't use "MSG_WAITALL"; it returns "Invalid argument" on some Linux versions; use an explicit while () loop instead.
- //if (send(sd, buf, len, MSG_WAITALL) != len) return -1;
- while (len)
- {
- ssize_t num_written = send(sd, buf, (long)len, 0);
- if (num_written < 0 || (size_t)num_written > len)
- {
- // Should never happen. If it does, it indicates some OS bug,
- // or that the mDNSResponder daemon crashed (which should never happen).
- #if !defined(__ppc__) && defined(SO_ISDEFUNCT)
- int defunct;
- socklen_t dlen = sizeof (defunct);
- if (getsockopt(sd, SOL_SOCKET, SO_ISDEFUNCT, &defunct, &dlen) < 0)
- syslog(LOG_WARNING, "dnssd_clientstub write_all: SO_ISDEFUNCT failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno));
- if (!defunct)
- syslog(LOG_WARNING, "dnssd_clientstub write_all(%d) failed %ld/%ld %d %s", sd,
- (long)num_written, (long)len,
- (num_written < 0) ? dnssd_errno : 0,
- (num_written < 0) ? dnssd_strerror(dnssd_errno) : "");
- else
- syslog(LOG_INFO, "dnssd_clientstub write_all(%d) DEFUNCT", sd);
- #else
- syslog(LOG_WARNING, "dnssd_clientstub write_all(%d) failed %ld/%ld %d %s", sd,
- (long)num_written, (long)len,
- (num_written < 0) ? dnssd_errno : 0,
- (num_written < 0) ? dnssd_strerror(dnssd_errno) : "");
- #endif
- return -1;
- }
- buf += num_written;
- len -= num_written;
- }
- return 0;
- }
-
-enum { read_all_success = 0, read_all_fail = -1, read_all_wouldblock = -2 };
-
-// Read len bytes. Return 0 on success, read_all_fail on error, or read_all_wouldblock for
-static int read_all(dnssd_sock_t sd, char *buf, int len)
- {
- // Don't use "MSG_WAITALL"; it returns "Invalid argument" on some Linux versions; use an explicit while () loop instead.
- //if (recv(sd, buf, len, MSG_WAITALL) != len) return -1;
-
- while (len)
- {
- timeval timeout;
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
- fd_set readFds, writeFds, exceptFds;
- memset(&readFds,0,sizeof(readFds));
- memset(&writeFds,0,sizeof(writeFds));
- memset(&exceptFds,0,sizeof(exceptFds));
- FD_SET(sd, &readFds);
- FD_SET(sd, &writeFds);
- FD_SET(sd, &exceptFds);
- ssize_t num_read = 0;
- int nVal=select(sd+1, &readFds, &writeFds, &exceptFds, &timeout);
- if (nVal < 1 || !(FD_ISSET(sd, &readFds) || FD_ISSET(sd, &exceptFds))) {
- if (! ZeroConf::gQuickStop)
- continue;
- } else {
- num_read = recv(sd, buf, len, 0);
- }
- // It is valid to get an interrupted system call error e.g., somebody attaching
- // in a debugger, retry without failing
- if ((num_read < 0) && (errno == EINTR)) { syslog(LOG_INFO, "dnssd_clientstub read_all: EINTR continue"); continue; }
- if ((num_read == 0) || (num_read < 0) || (num_read > len))
- {
- int printWarn = 0;
- int defunct = 0;
- // Should never happen. If it does, it indicates some OS bug,
- // or that the mDNSResponder daemon crashed (which should never happen).
-#if defined(WIN32)
- // <rdar://problem/7481776> Suppress logs for "A non-blocking socket operation
- // could not be completed immediately"
- if (WSAGetLastError() != WSAEWOULDBLOCK)
- printWarn = 1;
-#endif
-#if !defined(__ppc__) && defined(SO_ISDEFUNCT)
- {
- socklen_t dlen = sizeof (defunct);
- if (getsockopt(sd, SOL_SOCKET, SO_ISDEFUNCT, &defunct, &dlen) < 0)
- syslog(LOG_WARNING, "dnssd_clientstub read_all: SO_ISDEFUNCT failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno));
- }
- if (!defunct)
- printWarn = 1;
-#endif
- if (printWarn)
- syslog(LOG_WARNING, "dnssd_clientstub read_all(%d) failed %ld/%ld %d %s", sd,
- (long)num_read, (long)len,
- (num_read < 0) ? dnssd_errno : 0,
- (num_read < 0) ? dnssd_strerror(dnssd_errno) : "");
- else if (defunct)
- syslog(LOG_INFO, "dnssd_clientstub read_all(%d) DEFUNCT", sd);
- return (num_read < 0 && dnssd_errno == dnssd_EWOULDBLOCK) ? read_all_wouldblock : read_all_fail;
- }
- buf += num_read;
- len -= num_read;
- }
- return read_all_success;
- }
-
-// Returns 1 if more bytes remain to be read on socket descriptor sd, 0 otherwise
-static int more_bytes(dnssd_sock_t sd)
- {
- struct timeval tv = { 0, 0 };
- fd_set readfds;
- fd_set *fs;
- int ret;
-
- if (sd < FD_SETSIZE)
- {
- fs = &readfds;
- FD_ZERO(fs);
- }
- else
- {
- // Compute the number of integers needed for storing "sd". Internally fd_set is stored
- // as an array of ints with one bit for each fd and hence we need to compute
- // the number of ints needed rather than the number of bytes. If "sd" is 32, we need
- // two ints and not just one.
- int nfdbits = sizeof (int) * 8;
- int nints = (sd/nfdbits) + 1;
- fs = (fd_set *)calloc(nints, sizeof(int));
- if (fs == NULL) { syslog(LOG_WARNING, "dnssd_clientstub more_bytes: malloc failed"); return 0; }
- }
- FD_SET(sd, fs);
- ret = select((int)sd+1, fs, (fd_set*)NULL, (fd_set*)NULL, &tv);
- if (fs != &readfds) free(fs);
- return (ret > 0);
- }
-
-// Wait for daemon to write to socket
-static int wait_for_daemon(dnssd_sock_t sock, int timeout)
- {
-#ifndef WIN32
- // At this point the next operation (accept() or read()) on this socket may block for a few milliseconds waiting
- // for the daemon to respond, but that's okay -- the daemon is a trusted service and we know if won't take more
- // than a few milliseconds to respond. So we'll forego checking for readability of the socket.
- (void) sock;
- (void) timeout;
-#else
- // Windows on the other hand suffers from 3rd party software (primarily 3rd party firewall software) that
- // interferes with proper functioning of the TCP protocol stack. Because of this and because we depend on TCP
- // to communicate with the system service, we want to make sure that the next operation on this socket (accept() or
- // read()) doesn't block indefinitely.
- if (!gDaemonErr)
- {
- struct timeval tv;
- fd_set set;
-
- FD_ZERO(&set);
- FD_SET(sock, &set);
- tv.tv_sec = timeout;
- tv.tv_usec = 0;
- if (!select((int)(sock + 1), &set, NULL, NULL, &tv))
- {
- syslog(LOG_WARNING, "dnssd_clientstub wait_for_daemon timed out");
- gDaemonErr = kDNSServiceErr_Timeout;
- }
- }
-#endif
- return gDaemonErr;
- }
-
-/* create_hdr
- *
- * allocate and initialize an ipc message header. Value of len should initially be the
- * length of the data, and is set to the value of the data plus the header. data_start
- * is set to point to the beginning of the data section. SeparateReturnSocket should be
- * non-zero for calls that can't receive an immediate error return value on their primary
- * socket, and therefore require a separate return path for the error code result.
- * if zero, the path to a control socket is appended at the beginning of the message buffer.
- * data_start is set past this string.
- */
-static ipc_msg_hdr *create_hdr(uint32_t op, size_t *len, char **data_start, int SeparateReturnSocket, DNSServiceOp *ref)
- {
- char *msg = NULL;
- ipc_msg_hdr *hdr;
- int datalen;
-#if !defined(USE_TCP_LOOPBACK)
- char ctrl_path[64] = ""; // "/var/tmp/dnssd_result_socket.xxxxxxxxxx-xxx-xxxxxx"
-#endif
-
- if (SeparateReturnSocket)
- {
-#if defined(USE_TCP_LOOPBACK)
- *len += 2; // Allocate space for two-byte port number
-#elif defined(USE_NAMED_ERROR_RETURN_SOCKET)
- struct timeval tv;
- if (gettimeofday(&tv, NULL) < 0)
- { syslog(LOG_WARNING, "dnssd_clientstub create_hdr: gettimeofday failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno)); return NULL; }
- sprintf(ctrl_path, "%s%d-%.3lx-%.6lu", CTL_PATH_PREFIX, (int)getpid(),
- (unsigned long)(tv.tv_sec & 0xFFF), (unsigned long)(tv.tv_usec));
- *len += strlen(ctrl_path) + 1;
-#else
- *len += 1; // Allocate space for single zero byte (empty C string)
-#endif
- }
-
- datalen = (int) *len;
- *len += sizeof(ipc_msg_hdr);
-
- // Write message to buffer
- msg = static_cast<char*>(malloc(*len));
- if (!msg) { syslog(LOG_WARNING, "dnssd_clientstub create_hdr: malloc failed"); return NULL; }
-
- memset(msg, 0, *len);
- hdr = (ipc_msg_hdr *)msg;
- hdr->version = VERSION;
- hdr->datalen = datalen;
- hdr->ipc_flags = 0;
- hdr->op = op;
- hdr->client_context = ref->uid;
- hdr->reg_index = 0;
- *data_start = msg + sizeof(ipc_msg_hdr);
-#if defined(USE_TCP_LOOPBACK)
- // Put dummy data in for the port, since we don't know what it is yet.
- // The data will get filled in before we send the message. This happens in deliver_request().
- if (SeparateReturnSocket) put_uint16(0, data_start);
-#else
- if (SeparateReturnSocket) put_string(ctrl_path, data_start);
-#endif
- return hdr;
- }
-
-static void FreeDNSRecords(DNSServiceOp *sdRef)
- {
- DNSRecord *rec = sdRef->rec;
- while (rec)
- {
- DNSRecord *next = rec->recnext;
- free(rec);
- rec = next;
- }
- }
-
-static void FreeDNSServiceOp(DNSServiceOp *x)
- {
- // We don't use our DNSServiceRefValid macro here because if we're cleaning up after a socket() call failed
- // then sockfd could legitimately contain a failing value (e.g. dnssd_InvalidSocket)
- if ((x->sockfd ^ x->validator) != ValidatorBits)
- syslog(LOG_WARNING, "dnssd_clientstub attempt to dispose invalid DNSServiceRef %p %08X %08X", x, x->sockfd, x->validator);
- else
- {
- x->next = NULL;
- x->primary = NULL;
- x->sockfd = dnssd_InvalidSocket;
- x->validator = 0xDDDDDDDD;
- x->op = request_op_none;
- x->max_index = 0;
- x->logcounter = 0;
- x->moreptr = NULL;
- x->ProcessReply = NULL;
- x->AppCallback = NULL;
- x->AppContext = NULL;
-#if _DNS_SD_LIBDISPATCH
- if (x->disp_source) dispatch_release(x->disp_source);
- x->disp_source = NULL;
- x->disp_queue = NULL;
-#endif
- // DNSRecords may have been added to subordinate sdRef e.g., DNSServiceRegister/DNSServiceAddRecord
- // or on the main sdRef e.g., DNSServiceCreateConnection/DNSServiveRegisterRecord. DNSRecords may have
- // been freed if the application called DNSRemoveRecord
- FreeDNSRecords(x);
- free(x);
- }
- }
-
-// Return a connected service ref (deallocate with DNSServiceRefDeallocate)
-static DNSServiceErrorType ConnectToServer(DNSServiceRef *ref, DNSServiceFlags flags, uint32_t op, ProcessReplyFn ProcessReply, void *AppCallback, void *AppContext)
- {
- static int quickCheck = 1;
- #if APPLE_OSX_mDNSResponder
- int NumTries = DNSSD_CLIENT_MAXTRIES;
- #else
- int NumTries = 0;
- #endif
-
- dnssd_sockaddr_t saddr;
- DNSServiceOp *sdr;
-
- if (!ref) { syslog(LOG_WARNING, "dnssd_clientstub DNSService operation with NULL DNSServiceRef"); return kDNSServiceErr_BadParam; }
-
- if (flags & kDNSServiceFlagsShareConnection)
- {
- if (!*ref)
- {
- syslog(LOG_WARNING, "dnssd_clientstub kDNSServiceFlagsShareConnection used with NULL DNSServiceRef");
- return kDNSServiceErr_BadParam;
- }
- if (!DNSServiceRefValid(*ref) || (*ref)->op != connection_request || (*ref)->primary)
- {
- syslog(LOG_WARNING, "dnssd_clientstub kDNSServiceFlagsShareConnection used with invalid DNSServiceRef %p %08X %08X",
- (*ref), (*ref)->sockfd, (*ref)->validator);
- *ref = NULL;
- return kDNSServiceErr_BadReference;
- }
- }
-
- #if defined(_WIN32)
- if (!g_initWinsock)
- {
- WSADATA wsaData;
- g_initWinsock = 1;
- if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) { *ref = NULL; return kDNSServiceErr_ServiceNotRunning; }
- }
- // <rdar://problem/4096913> If the system service is disabled, we only want to try to connect once
- //if (IsSystemServiceDisabled()) NumTries = DNSSD_CLIENT_MAXTRIES;
- #endif
-
- sdr = static_cast<DNSServiceOp*>(malloc(sizeof(DNSServiceOp)));
- if (!sdr) { syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: malloc failed"); *ref = NULL; return kDNSServiceErr_NoMemory; }
- sdr->next = NULL;
- sdr->primary = NULL;
- sdr->sockfd = dnssd_InvalidSocket;
- sdr->validator = sdr->sockfd ^ ValidatorBits;
- sdr->op = op;
- sdr->max_index = 0;
- sdr->logcounter = 0;
- sdr->moreptr = NULL;
- sdr->uid.u32[0] = 0;
- sdr->uid.u32[1] = 0;
- sdr->ProcessReply = ProcessReply;
- sdr->AppCallback = AppCallback;
- sdr->AppContext = AppContext;
- sdr->rec = NULL;
-#if _DNS_SD_LIBDISPATCH
- sdr->disp_source = NULL;
- sdr->disp_queue = NULL;
-#endif
-
- if (flags & kDNSServiceFlagsShareConnection)
- {
- DNSServiceOp **p = &(*ref)->next; // Append ourselves to end of primary's list
- while (*p) p = &(*p)->next;
- *p = sdr;
- // Preincrement counter before we use it -- it helps with debugging if we know the all-zeroes ID should never appear
- if (++(*ref)->uid.u32[0] == 0) ++(*ref)->uid.u32[1]; // In parent DNSServiceOp increment UID counter
- sdr->primary = *ref; // Set our primary pointer
- sdr->sockfd = (*ref)->sockfd; // Inherit primary's socket
- sdr->validator = (*ref)->validator;
- sdr->uid = (*ref)->uid;
- //printf("ConnectToServer sharing socket %d\n", sdr->sockfd);
- }
- else
- {
- #ifdef SO_NOSIGPIPE
- const unsigned long optval = 1;
- #endif
- *ref = NULL;
- sdr->sockfd = socket(AF_DNSSD, SOCK_STREAM, 0);
- sdr->validator = sdr->sockfd ^ ValidatorBits;
- if (!dnssd_SocketValid(sdr->sockfd))
- {
- syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: socket failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno));
- FreeDNSServiceOp(sdr);
- return kDNSServiceErr_NoMemory;
- }
- #ifdef SO_NOSIGPIPE
- // Some environments (e.g. OS X) support turning off SIGPIPE for a socket
- if (setsockopt(sdr->sockfd, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval)) < 0)
- syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: SO_NOSIGPIPE failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno));
- #endif
- #if defined(USE_TCP_LOOPBACK)
- saddr.sin_family = AF_INET;
- saddr.sin_addr.s_addr = inet_addr(MDNS_TCP_SERVERADDR);
- saddr.sin_port = htons(MDNS_TCP_SERVERPORT);
- #else
- saddr.sun_family = AF_LOCAL;
- strcpy(saddr.sun_path, MDNS_UDS_SERVERPATH);
- #if !defined(__ppc__) && defined(SO_DEFUNCTOK)
- {
- int defunct = 1;
- if (setsockopt(sdr->sockfd, SOL_SOCKET, SO_DEFUNCTOK, &defunct, sizeof(defunct)) < 0)
- syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: SO_DEFUNCTOK failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno));
- }
- #endif
- #endif
-
- while (1)
- {
- int err = connect(sdr->sockfd, (struct sockaddr *) &saddr, sizeof(saddr));
- if (!err) break; // If we succeeded, return sdr
- // If we failed, then it may be because the daemon is still launching.
- // This can happen for processes that launch early in the boot process, while the
- // daemon is still coming up. Rather than fail here, we'll wait a bit and try again.
- // If, after four seconds, we still can't connect to the daemon,
- // then we give up and return a failure code.
- if (++NumTries < DNSSD_CLIENT_MAXTRIES && !(quickCheck && NumTries > 1)) sleep(1); // Sleep a bit, then try again
- else {
- quickCheck = 0;
- dnssd_close(sdr->sockfd); FreeDNSServiceOp(sdr); return kDNSServiceErr_ServiceNotRunning; }
- }
- //printf("ConnectToServer opened socket %d\n", sdr->sockfd);
- }
- quickCheck = 0;
-
- *ref = sdr;
- return kDNSServiceErr_NoError;
- }
-
-#define deliver_request_bailout(MSG) \
- do { syslog(LOG_WARNING, "dnssd_clientstub deliver_request: %s failed %d (%s)", (MSG), dnssd_errno, dnssd_strerror(dnssd_errno)); goto cleanup; } while (0)
-
-static DNSServiceErrorType deliver_request(ipc_msg_hdr *hdr, DNSServiceOp *sdr)
- {
- uint32_t datalen;
- #if defined(USE_TCP_LOOPBACK) || defined(USE_NAMED_ERROR_RETURN_SOCKET)
- char *const data = (char *)hdr + sizeof(ipc_msg_hdr);
- #endif
- dnssd_sock_t listenfd = dnssd_InvalidSocket, errsd = dnssd_InvalidSocket;
- DNSServiceErrorType err = kDNSServiceErr_Unknown; // Default for the "goto cleanup" cases
- int MakeSeparateReturnSocket = 0;
-
- if (!hdr) { syslog(LOG_WARNING, "dnssd_clientstub deliver_request: !hdr"); return kDNSServiceErr_Unknown; }
-
- datalen = hdr->datalen; // We take a copy here because we're going to convert hdr->datalen to network byte order
-
- // Note: need to check hdr->op, not sdr->op.
- // hdr->op contains the code for the specific operation we're currently doing, whereas sdr->op
- // contains the original parent DNSServiceOp (e.g. for an add_record_request, hdr->op will be
- // add_record_request but the parent sdr->op will be connection_request or reg_service_request)
- if (sdr->primary ||
- hdr->op == reg_record_request || hdr->op == add_record_request || hdr->op == update_record_request || hdr->op == remove_record_request)
- MakeSeparateReturnSocket = 1;
-
- if (!DNSServiceRefValid(sdr))
- {
- syslog(LOG_WARNING, "dnssd_clientstub deliver_request: invalid DNSServiceRef %p %08X %08X", sdr, sdr->sockfd, sdr->validator);
- return kDNSServiceErr_BadReference;
- }
-
- if (MakeSeparateReturnSocket)
- {
- #if defined(USE_TCP_LOOPBACK)
- {
- union { uint16_t s; u_char b[2]; } port;
- dnssd_sockaddr_t caddr;
- dnssd_socklen_t len = (dnssd_socklen_t) sizeof(caddr);
- listenfd = socket(AF_DNSSD, SOCK_STREAM, 0);
- if (!dnssd_SocketValid(listenfd)) deliver_request_bailout("TCP socket");
-
- caddr.sin_family = AF_INET;
- caddr.sin_port = 0;
- caddr.sin_addr.s_addr = inet_addr(MDNS_TCP_SERVERADDR);
- if (bind(listenfd, (struct sockaddr*) &caddr, sizeof(caddr)) < 0) deliver_request_bailout("TCP bind");
- if (getsockname(listenfd, (struct sockaddr*) &caddr, &len) < 0) deliver_request_bailout("TCP getsockname");
- if (listen(listenfd, 1) < 0) deliver_request_bailout("TCP listen");
- port.s = caddr.sin_port;
- data[0] = port.b[0]; // don't switch the byte order, as the
- data[1] = port.b[1]; // daemon expects it in network byte order
- }
- #elif defined(USE_NAMED_ERROR_RETURN_SOCKET)
- {
- mode_t mask;
- int bindresult;
- dnssd_sockaddr_t caddr;
- listenfd = socket(AF_DNSSD, SOCK_STREAM, 0);
- if (!dnssd_SocketValid(listenfd)) deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET socket");
-
- caddr.sun_family = AF_LOCAL;
- // According to Stevens (section 3.2), there is no portable way to
- // determine whether sa_len is defined on a particular platform.
- #ifndef NOT_HAVE_SA_LEN
- caddr.sun_len = sizeof(struct sockaddr_un);
- #endif
- strcpy(caddr.sun_path, data);
- mask = umask(0);
- bindresult = bind(listenfd, (struct sockaddr *)&caddr, sizeof(caddr));
- umask(mask);
- if (bindresult < 0) deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET bind");
- if (listen(listenfd, 1) < 0) deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET listen");
- }
- #else
- {
- dnssd_sock_t sp[2];
- if (socketpair(AF_DNSSD, SOCK_STREAM, 0, sp) < 0) deliver_request_bailout("socketpair");
- else
- {
- errsd = sp[0]; // We'll read our four-byte error code from sp[0]
- listenfd = sp[1]; // We'll send sp[1] to the daemon
- #if !defined(__ppc__) && defined(SO_DEFUNCTOK)
- {
- int defunct = 1;
- if (setsockopt(errsd, SOL_SOCKET, SO_DEFUNCTOK, &defunct, sizeof(defunct)) < 0)
- syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: SO_DEFUNCTOK failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno));
- }
- #endif
- }
- }
- #endif
- }
-
-#if !defined(USE_TCP_LOOPBACK) && !defined(USE_NAMED_ERROR_RETURN_SOCKET)
- // If we're going to make a separate error return socket, and pass it to the daemon
- // using sendmsg, then we'll hold back one data byte to go with it.
- // On some versions of Unix (including Leopard) sending a control message without
- // any associated data does not work reliably -- e.g. one particular issue we ran
- // into is that if the receiving program is in a kqueue loop waiting to be notified
- // of the received message, it doesn't get woken up when the control message arrives.
- if (MakeSeparateReturnSocket || sdr->op == send_bpf) datalen--; // Okay to use sdr->op when checking for op == send_bpf
-#endif
-
- // At this point, our listening socket is set up and waiting, if necessary, for the daemon to connect back to
- ConvertHeaderBytes(hdr);
- //syslog(LOG_WARNING, "dnssd_clientstub deliver_request writing %lu bytes", (unsigned long)(datalen + sizeof(ipc_msg_hdr)));
- //if (MakeSeparateReturnSocket) syslog(LOG_WARNING, "dnssd_clientstub deliver_request name is %s", data);
-#if TEST_SENDING_ONE_BYTE_AT_A_TIME
- unsigned int i;
- for (i=0; i<datalen + sizeof(ipc_msg_hdr); i++)
- {
- syslog(LOG_WARNING, "dnssd_clientstub deliver_request writing %d", i);
- if (write_all(sdr->sockfd, ((char *)hdr)+i, 1) < 0)
- { syslog(LOG_WARNING, "write_all (byte %u) failed", i); goto cleanup; }
- usleep(10000);
- }
-#else
- if (write_all(sdr->sockfd, (char *)hdr, datalen + sizeof(ipc_msg_hdr)) < 0)
- {
- // write_all already prints an error message if there is an error writing to
- // the socket except for DEFUNCT. Logging here is unnecessary and also wrong
- // in the case of DEFUNCT sockets
- syslog(LOG_INFO, "dnssd_clientstub deliver_request ERROR: write_all(%d, %lu bytes) failed",
- sdr->sockfd, (unsigned long)(datalen + sizeof(ipc_msg_hdr)));
- goto cleanup;
- }
-#endif
-
- if (!MakeSeparateReturnSocket) errsd = sdr->sockfd;
- if (MakeSeparateReturnSocket || sdr->op == send_bpf) // Okay to use sdr->op when checking for op == send_bpf
- {
-#if defined(USE_TCP_LOOPBACK) || defined(USE_NAMED_ERROR_RETURN_SOCKET)
- // At this point we may block in accept for a few milliseconds waiting for the daemon to connect back to us,
- // but that's okay -- the daemon is a trusted service and we know if won't take more than a few milliseconds to respond.
- dnssd_sockaddr_t daddr;
- dnssd_socklen_t len = sizeof(daddr);
- if ((err = wait_for_daemon(listenfd, DNSSD_CLIENT_TIMEOUT)) != kDNSServiceErr_NoError) goto cleanup;
- errsd = accept(listenfd, (struct sockaddr *)&daddr, &len);
- if (!dnssd_SocketValid(errsd)) deliver_request_bailout("accept");
-#else
-
-#if APPLE_OSX_mDNSResponder
-// On Leopard, the stock definitions of the CMSG_* macros in /usr/include/sys/socket.h,
-// while arguably correct in theory, nonetheless in practice produce code that doesn't work on 64-bit machines
-// For details see <rdar://problem/5565787> Bonjour API broken for 64-bit apps (SCM_RIGHTS sendmsg fails)
-#undef CMSG_DATA
-#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + (sizeof(struct cmsghdr)))
-#undef CMSG_SPACE
-#define CMSG_SPACE(l) ((sizeof(struct cmsghdr)) + (l))
-#undef CMSG_LEN
-#define CMSG_LEN(l) ((sizeof(struct cmsghdr)) + (l))
-#endif
-
- struct iovec vec = { ((char *)hdr) + sizeof(ipc_msg_hdr) + datalen, 1 }; // Send the last byte along with the SCM_RIGHTS
- struct msghdr msg;
- struct cmsghdr *cmsg;
- char cbuf[CMSG_SPACE(sizeof(dnssd_sock_t))];
- dnssd_sock_t *sock;
-
- if (sdr->op == send_bpf) // Okay to use sdr->op when checking for op == send_bpf
- {
- int i;
- char p[12]; // Room for "/dev/bpf999" with terminating null
- for (i=0; i<100; i++)
- {
- snprintf(p, sizeof(p), "/dev/bpf%d", i);
- listenfd = open(p, O_RDWR, 0);
- //if (dnssd_SocketValid(listenfd)) syslog(LOG_WARNING, "Sending fd %d for %s", listenfd, p);
- if (!dnssd_SocketValid(listenfd) && dnssd_errno != EBUSY)
- syslog(LOG_WARNING, "Error opening %s %d (%s)", p, dnssd_errno, dnssd_strerror(dnssd_errno));
- if (dnssd_SocketValid(listenfd) || dnssd_errno != EBUSY) break;
- }
- }
-
- msg.msg_name = 0;
- msg.msg_namelen = 0;
- msg.msg_iov = &vec;
- msg.msg_iovlen = 1;
- msg.msg_control = cbuf;
- msg.msg_controllen = CMSG_LEN(sizeof(dnssd_sock_t));
- msg.msg_flags = 0;
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_len = CMSG_LEN(sizeof(dnssd_sock_t));
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- sock = (dnssd_sock_t *)CMSG_DATA(cmsg);
- *sock = listenfd;
-
-#if TEST_KQUEUE_CONTROL_MESSAGE_BUG
- sleep(1);
-#endif
-
-#if DEBUG_64BIT_SCM_RIGHTS
- syslog(LOG_WARNING, "dnssd_clientstub sendmsg read sd=%d write sd=%d %ld %ld %ld/%ld/%ld/%ld",
- errsd, listenfd, sizeof(dnssd_sock_t), sizeof(void*),
- sizeof(struct cmsghdr) + sizeof(dnssd_sock_t),
- CMSG_LEN(sizeof(dnssd_sock_t)), (long)CMSG_SPACE(sizeof(dnssd_sock_t)),
- (long)((char*)CMSG_DATA(cmsg) + 4 - cbuf));
-#endif // DEBUG_64BIT_SCM_RIGHTS
-
- if (sendmsg(sdr->sockfd, &msg, 0) < 0)
- {
- syslog(LOG_WARNING, "dnssd_clientstub deliver_request ERROR: sendmsg failed read sd=%d write sd=%d errno %d (%s)",
- errsd, listenfd, dnssd_errno, dnssd_strerror(dnssd_errno));
- err = kDNSServiceErr_Incompatible;
- goto cleanup;
- }
-
-#if DEBUG_64BIT_SCM_RIGHTS
- syslog(LOG_WARNING, "dnssd_clientstub sendmsg read sd=%d write sd=%d okay", errsd, listenfd);
-#endif // DEBUG_64BIT_SCM_RIGHTS
-
-#endif
- // Close our end of the socketpair *before* blocking in read_all to get the four-byte error code.
- // Otherwise, if the daemon closes our socket (or crashes), we block in read_all() forever
- // because the socket is not closed (we still have an open reference to it ourselves).
- dnssd_close(listenfd);
- listenfd = dnssd_InvalidSocket; // Make sure we don't close it a second time in the cleanup handling below
- }
-
- // At this point we may block in read_all for a few milliseconds waiting for the daemon to send us the error code,
- // but that's okay -- the daemon is a trusted service and we know if won't take more than a few milliseconds to respond.
- if (sdr->op == send_bpf) // Okay to use sdr->op when checking for op == send_bpf
- err = kDNSServiceErr_NoError;
- else if ((err = wait_for_daemon(errsd, DNSSD_CLIENT_TIMEOUT)) == kDNSServiceErr_NoError)
- {
- if (read_all(errsd, (char*)&err, (int)sizeof(err)) < 0)
- err = kDNSServiceErr_ServiceNotRunning; // On failure read_all will have written a message to syslog for us
- else
- err = ntohl(err);
- }
-
- //syslog(LOG_WARNING, "dnssd_clientstub deliver_request: retrieved error code %d", err);
-
-cleanup:
- if (MakeSeparateReturnSocket)
- {
- if (dnssd_SocketValid(listenfd)) dnssd_close(listenfd);
- if (dnssd_SocketValid(errsd)) dnssd_close(errsd);
-#if defined(USE_NAMED_ERROR_RETURN_SOCKET)
- // syslog(LOG_WARNING, "dnssd_clientstub deliver_request: removing UDS: %s", data);
- if (unlink(data) != 0)
- syslog(LOG_WARNING, "dnssd_clientstub WARNING: unlink(\"%s\") failed errno %d (%s)", data, dnssd_errno, dnssd_strerror(dnssd_errno));
- // else syslog(LOG_WARNING, "dnssd_clientstub deliver_request: removed UDS: %s", data);
-#endif
- }
-
- free(hdr);
- return err;
- }
-
-int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef)
- {
- if (!sdRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRefSockFD called with NULL DNSServiceRef"); return dnssd_InvalidSocket; }
-
- if (!DNSServiceRefValid(sdRef))
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRefSockFD called with invalid DNSServiceRef %p %08X %08X",
- sdRef, sdRef->sockfd, sdRef->validator);
- return dnssd_InvalidSocket;
- }
-
- if (sdRef->primary)
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRefSockFD undefined for kDNSServiceFlagsShareConnection subordinate DNSServiceRef %p", sdRef);
- return dnssd_InvalidSocket;
- }
-
- return (int) sdRef->sockfd;
- }
-
-#if _DNS_SD_LIBDISPATCH
-static void CallbackWithError(DNSServiceRef sdRef, DNSServiceErrorType error)
- {
- DNSServiceOp *sdr = sdRef;
- DNSServiceOp *sdrNext;
- DNSRecord *rec;
- DNSRecord *recnext;
- int morebytes;
-
- while (sdr)
- {
- // We can't touch the sdr after the callback as it can be deallocated in the callback
- sdrNext = sdr->next;
- morebytes = 1;
- sdr->moreptr = &morebytes;
- switch (sdr->op)
- {
- case resolve_request:
- if (sdr->AppCallback)((DNSServiceResolveReply) sdr->AppCallback)(sdr, 0, 0, error, NULL, 0, 0, 0, NULL, sdr->AppContext);
- break;
- case query_request:
- if (sdr->AppCallback)((DNSServiceQueryRecordReply)sdr->AppCallback)(sdr, 0, 0, error, NULL, 0, 0, 0, NULL, 0, sdr->AppContext);
- break;
- case addrinfo_request:
- if (sdr->AppCallback)((DNSServiceGetAddrInfoReply)sdr->AppCallback)(sdr, 0, 0, error, NULL, NULL, 0, sdr->AppContext);
- break;
- case browse_request:
- if (sdr->AppCallback)((DNSServiceBrowseReply) sdr->AppCallback)(sdr, 0, 0, error, NULL, 0, NULL, sdr->AppContext);
- break;
- case reg_service_request:
- if (sdr->AppCallback)((DNSServiceRegisterReply) sdr->AppCallback)(sdr, 0, error, NULL, 0, NULL, sdr->AppContext);
- break;
- case enumeration_request:
- if (sdr->AppCallback)((DNSServiceDomainEnumReply) sdr->AppCallback)(sdr, 0, 0, error, NULL, sdr->AppContext);
- break;
- case connection_request:
- // This means Register Record, walk the list of DNSRecords to do the callback
- rec = sdr->rec;
- while (rec)
- {
- recnext = rec->recnext;
- if (rec->AppCallback) ((DNSServiceRegisterRecordReply)rec->AppCallback)(sdr, 0, 0, error, rec->AppContext);
- // The Callback can call DNSServiceRefDeallocate which in turn frees sdr and all the records.
- // Detect that and return early
- if (!morebytes){syslog(LOG_WARNING, "dnssdclientstub:Record: CallbackwithError morebytes zero"); return;}
- rec = recnext;
- }
- break;
- case port_mapping_request:
- if (sdr->AppCallback)((DNSServiceNATPortMappingReply)sdr->AppCallback)(sdr, 0, 0, error, 0, 0, 0, 0, 0, sdr->AppContext);
- break;
- default:
- syslog(LOG_WARNING, "dnssd_clientstub CallbackWithError called with bad op %d", sdr->op);
- }
- // If DNSServiceRefDeallocate was called in the callback, morebytes will be zero. It means
- // all other sdrefs have been freed. This happens for shared connections where the
- // DNSServiceRefDeallocate on the first sdRef frees all other sdrefs.
- if (!morebytes){syslog(LOG_WARNING, "dnssdclientstub:sdRef: CallbackwithError morebytes zero"); return;}
- sdr = sdrNext;
- }
- }
-#endif // _DNS_SD_LIBDISPATCH
-
-// Handle reply from server, calling application client callback. If there is no reply
-// from the daemon on the socket contained in sdRef, the call will block.
-DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdRef)
- {
- int morebytes = 0;
-
- if (!sdRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceProcessResult called with NULL DNSServiceRef"); return kDNSServiceErr_BadParam; }
-
- if (!DNSServiceRefValid(sdRef))
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceProcessResult called with invalid DNSServiceRef %p %08X %08X", sdRef, sdRef->sockfd, sdRef->validator);
- return kDNSServiceErr_BadReference;
- }
-
- if (sdRef->primary)
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceProcessResult undefined for kDNSServiceFlagsShareConnection subordinate DNSServiceRef %p", sdRef);
- return kDNSServiceErr_BadReference;
- }
-
- if (!sdRef->ProcessReply)
- {
- static int num_logs = 0;
- if (num_logs < 10) syslog(LOG_WARNING, "dnssd_clientstub DNSServiceProcessResult called with DNSServiceRef with no ProcessReply function");
- if (num_logs < 1000) num_logs++; else sleep(1);
- return kDNSServiceErr_BadReference;
- }
-
- do
- {
- CallbackHeader cbh;
- char *data;
-
- // return NoError on EWOULDBLOCK. This will handle the case
- // where a non-blocking socket is told there is data, but it was a false positive.
- // On error, read_all will write a message to syslog for us, so don't need to duplicate that here
- // Note: If we want to properly support using non-blocking sockets in the future
- int result = read_all(sdRef->sockfd, (char *)&cbh.ipc_hdr, sizeof(cbh.ipc_hdr));
- if (result == read_all_fail)
- {
- // Set the ProcessReply to NULL before callback as the sdRef can get deallocated
- // in the callback.
- sdRef->ProcessReply = NULL;
-#if _DNS_SD_LIBDISPATCH
- // Call the callbacks with an error if using the dispatch API, as DNSServiceProcessResult
- // is not called by the application and hence need to communicate the error. Cancel the
- // source so that we don't get any more events
- if (sdRef->disp_source)
- {
- dispatch_source_cancel(sdRef->disp_source);
- dispatch_release(sdRef->disp_source);
- sdRef->disp_source = NULL;
- CallbackWithError(sdRef, kDNSServiceErr_ServiceNotRunning);
- }
-#endif
- // Don't touch sdRef anymore as it might have been deallocated
- return kDNSServiceErr_ServiceNotRunning;
- }
- else if (result == read_all_wouldblock)
- {
- if (morebytes && sdRef->logcounter < 100)
- {
- sdRef->logcounter++;
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceProcessResult error: select indicated data was waiting but read_all returned EWOULDBLOCK");
- }
- return kDNSServiceErr_NoError;
- }
-
- ConvertHeaderBytes(&cbh.ipc_hdr);
- if (cbh.ipc_hdr.version != VERSION)
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceProcessResult daemon version %d does not match client version %d", cbh.ipc_hdr.version, VERSION);
- sdRef->ProcessReply = NULL;
- return kDNSServiceErr_Incompatible;
- }
-
- data = static_cast<char *>(malloc(cbh.ipc_hdr.datalen));
- if (!data) return kDNSServiceErr_NoMemory;
- if (read_all(sdRef->sockfd, data, cbh.ipc_hdr.datalen) < 0) // On error, read_all will write a message to syslog for us
- {
- // Set the ProcessReply to NULL before callback as the sdRef can get deallocated
- // in the callback.
- sdRef->ProcessReply = NULL;
-#if _DNS_SD_LIBDISPATCH
- // Call the callbacks with an error if using the dispatch API, as DNSServiceProcessResult
- // is not called by the application and hence need to communicate the error. Cancel the
- // source so that we don't get any more events
- if (sdRef->disp_source)
- {
- dispatch_source_cancel(sdRef->disp_source);
- dispatch_release(sdRef->disp_source);
- sdRef->disp_source = NULL;
- CallbackWithError(sdRef, kDNSServiceErr_ServiceNotRunning);
- }
-#endif
- // Don't touch sdRef anymore as it might have been deallocated
- free(data);
- return kDNSServiceErr_ServiceNotRunning;
- }
- else
- {
- const char *ptr = data;
- cbh.cb_flags = get_flags (&ptr, data + cbh.ipc_hdr.datalen);
- cbh.cb_interface = get_uint32 (&ptr, data + cbh.ipc_hdr.datalen);
- cbh.cb_err = get_error_code(&ptr, data + cbh.ipc_hdr.datalen);
-
- // CAUTION: We have to handle the case where the client calls DNSServiceRefDeallocate from within the callback function.
- // To do this we set moreptr to point to morebytes. If the client does call DNSServiceRefDeallocate(),
- // then that routine will clear morebytes for us, and cause us to exit our loop.
- morebytes = more_bytes(sdRef->sockfd);
- if (morebytes)
- {
- cbh.cb_flags |= kDNSServiceFlagsMoreComing;
- sdRef->moreptr = &morebytes;
- }
- if (ptr) sdRef->ProcessReply(sdRef, &cbh, ptr, data + cbh.ipc_hdr.datalen);
- // Careful code here:
- // If morebytes is non-zero, that means we set sdRef->moreptr above, and the operation was not
- // cancelled out from under us, so now we need to clear sdRef->moreptr so we don't leave a stray
- // dangling pointer pointing to a long-gone stack variable.
- // If morebytes is zero, then one of two thing happened:
- // (a) morebytes was 0 above, so we didn't set sdRef->moreptr, so we don't need to clear it
- // (b) morebytes was 1 above, and we set sdRef->moreptr, but the operation was cancelled (with DNSServiceRefDeallocate()),
- // so we MUST NOT try to dereference our stale sdRef pointer.
- if (morebytes) sdRef->moreptr = NULL;
- }
- free(data);
- } while (morebytes);
-
- return kDNSServiceErr_NoError;
- }
-
-void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdRef)
- {
- if (!sdRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRefDeallocate called with NULL DNSServiceRef"); return; }
-
- if (!DNSServiceRefValid(sdRef)) // Also verifies dnssd_SocketValid(sdRef->sockfd) for us too
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRefDeallocate called with invalid DNSServiceRef %p %08X %08X", sdRef, sdRef->sockfd, sdRef->validator);
- return;
- }
-
- // If we're in the middle of a DNSServiceProcessResult() invocation for this DNSServiceRef, clear its morebytes flag to break it out of its while loop
- if (sdRef->moreptr) *(sdRef->moreptr) = 0;
-
- if (sdRef->primary) // If this is a subordinate DNSServiceOp, just send a 'stop' command
- {
- DNSServiceOp **p = &sdRef->primary->next;
- while (*p && *p != sdRef) p = &(*p)->next;
- if (*p)
- {
- char *ptr;
- size_t len = 0;
- ipc_msg_hdr *hdr = create_hdr(cancel_request, &len, &ptr, 0, sdRef);
- if (hdr)
- {
- ConvertHeaderBytes(hdr);
- write_all(sdRef->sockfd, (char *)hdr, len);
- free(hdr);
- }
- *p = sdRef->next;
- FreeDNSServiceOp(sdRef);
- }
- }
- else // else, make sure to terminate all subordinates as well
- {
-#if _DNS_SD_LIBDISPATCH
- // The cancel handler will close the fd if a dispatch source has been set
- if (sdRef->disp_source)
- {
- // By setting the ProcessReply to NULL, we make sure that we never call
- // the application callbacks ever, after returning from this function. We
- // assume that DNSServiceRefDeallocate is called from the serial queue
- // that was passed to DNSServiceSetDispatchQueue. Hence, dispatch_source_cancel
- // should cancel all the blocks on the queue and hence there should be no more
- // callbacks when we return from this function. Setting ProcessReply to NULL
- // provides extra protection.
- sdRef->ProcessReply = NULL;
- dispatch_source_cancel(sdRef->disp_source);
- dispatch_release(sdRef->disp_source);
- sdRef->disp_source = NULL;
- }
- // if disp_queue is set, it means it used the DNSServiceSetDispatchQueue API. In that case,
- // when the source was cancelled, the fd was closed in the handler. Currently the source
- // is cancelled only when the mDNSResponder daemon dies
- else if (!sdRef->disp_queue) dnssd_close(sdRef->sockfd);
-#else
- dnssd_close(sdRef->sockfd);
-#endif
- // Free DNSRecords added in DNSRegisterRecord if they have not
- // been freed in DNSRemoveRecord
- while (sdRef)
- {
- DNSServiceOp *p = sdRef;
- sdRef = sdRef->next;
- FreeDNSServiceOp(p);
- }
- }
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceGetProperty(const char *property, void *result, uint32_t *size)
- {
- char *ptr;
- size_t len = strlen(property) + 1;
- ipc_msg_hdr *hdr;
- DNSServiceOp *tmp;
- uint32_t actualsize;
-
- DNSServiceErrorType err = ConnectToServer(&tmp, 0, getproperty_request, NULL, NULL, NULL);
- if (err) return err;
-
- hdr = create_hdr(getproperty_request, &len, &ptr, 0, tmp);
- if (!hdr) { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_NoMemory; }
-
- put_string(property, &ptr);
- err = deliver_request(hdr, tmp); // Will free hdr for us
- if (read_all(tmp->sockfd, (char*)&actualsize, (int)sizeof(actualsize)) < 0)
- { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_ServiceNotRunning; }
-
- actualsize = ntohl(actualsize);
- if (read_all(tmp->sockfd, (char*)result, actualsize < *size ? actualsize : *size) < 0)
- { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_ServiceNotRunning; }
- DNSServiceRefDeallocate(tmp);
-
- // Swap version result back to local process byte order
- if (!strcmp(property, kDNSServiceProperty_DaemonVersion) && *size >= 4)
- *(uint32_t*)result = ntohl(*(uint32_t*)result);
-
- *size = actualsize;
- return kDNSServiceErr_NoError;
- }
-
-static void handle_resolve_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *end)
- {
- char fullname[kDNSServiceMaxDomainName];
- char target[kDNSServiceMaxDomainName];
- uint16_t txtlen;
- union { uint16_t s; u_char b[2]; } port;
- unsigned char *txtrecord;
-
- get_string(&data, end, fullname, kDNSServiceMaxDomainName);
- get_string(&data, end, target, kDNSServiceMaxDomainName);
- if (!data || data + 2 > end) goto fail;
-
- port.b[0] = *data++;
- port.b[1] = *data++;
- txtlen = get_uint16(&data, end);
- txtrecord = (unsigned char *)get_rdata(&data, end, txtlen);
-
- if (!data) goto fail;
- ((DNSServiceResolveReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, fullname, target, port.s, txtlen, txtrecord, sdr->AppContext);
- return;
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
-fail:
- syslog(LOG_WARNING, "dnssd_clientstub handle_resolve_response: error reading result from daemon");
- }
-
-#if APPLE_OSX_mDNSResponder
-
-static int32_t libSystemVersion = 0;
-
-// Return true if the application linked against a version of libsystem where P2P
-// interfaces were included by default when using kDNSServiceInterfaceIndexAny.
-// Using 160.0.0 == 0xa00000 as the version threshold.
-static int includeP2PWithIndexAny()
- {
- if (libSystemVersion == 0)
- libSystemVersion = NSVersionOfLinkTimeLibrary("System");
-
- if (libSystemVersion < 0xa00000)
- return 1;
- else
- return 0;
- }
-
-#else // APPLE_OSX_mDNSResponder
-
-// always return false for non Apple platforms
-static int includeP2PWithIndexAny()
- {
- return 0;
- }
-
-#endif // APPLE_OSX_mDNSResponder
-
-DNSServiceErrorType DNSSD_API DNSServiceResolve
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *name,
- const char *regtype,
- const char *domain,
- DNSServiceResolveReply callBack,
- void *context
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err;
-
- if (!name || !regtype || !domain || !callBack) return kDNSServiceErr_BadParam;
-
- // Need a real InterfaceID for WakeOnResolve
- if ((flags & kDNSServiceFlagsWakeOnResolve) != 0 &&
- ((interfaceIndex == kDNSServiceInterfaceIndexAny) ||
- (interfaceIndex == kDNSServiceInterfaceIndexLocalOnly) ||
- (interfaceIndex == kDNSServiceInterfaceIndexUnicast) ||
- (interfaceIndex == kDNSServiceInterfaceIndexP2P)))
- {
- return kDNSServiceErr_BadParam;
- }
-
- if ((interfaceIndex == kDNSServiceInterfaceIndexAny) && includeP2PWithIndexAny())
- flags |= kDNSServiceFlagsIncludeP2P;
-
- err = ConnectToServer(sdRef, flags, resolve_request, handle_resolve_response, reinterpret_cast<void*>(callBack), context);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- // Calculate total message length
- len = sizeof(flags);
- len += sizeof(interfaceIndex);
- len += strlen(name) + 1;
- len += strlen(regtype) + 1;
- len += strlen(domain) + 1;
-
- hdr = create_hdr(resolve_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_string(name, &ptr);
- put_string(regtype, &ptr);
- put_string(domain, &ptr);
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-static void handle_query_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
- {
- uint32_t ttl;
- char name[kDNSServiceMaxDomainName];
- uint16_t rrtype, rrclass, rdlen;
- const char *rdata;
-
- get_string(&data, end, name, kDNSServiceMaxDomainName);
- rrtype = get_uint16(&data, end);
- rrclass = get_uint16(&data, end);
- rdlen = get_uint16(&data, end);
- rdata = get_rdata(&data, end, rdlen);
- ttl = get_uint32(&data, end);
-
- if (!data) syslog(LOG_WARNING, "dnssd_clientstub handle_query_response: error reading result from daemon");
- else ((DNSServiceQueryRecordReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, name, rrtype, rrclass, rdlen, rdata, ttl, sdr->AppContext);
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *name,
- uint16_t rrtype,
- uint16_t rrclass,
- DNSServiceQueryRecordReply callBack,
- void *context
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err;
-
- if ((interfaceIndex == kDNSServiceInterfaceIndexAny) && includeP2PWithIndexAny())
- flags |= kDNSServiceFlagsIncludeP2P;
-
- err = ConnectToServer(sdRef, flags, query_request, handle_query_response, reinterpret_cast<void*>(callBack), context);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- if (!name) name = "\0";
-
- // Calculate total message length
- len = sizeof(flags);
- len += sizeof(uint32_t); // interfaceIndex
- len += strlen(name) + 1;
- len += 2 * sizeof(uint16_t); // rrtype, rrclass
-
- hdr = create_hdr(query_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_string(name, &ptr);
- put_uint16(rrtype, &ptr);
- put_uint16(rrclass, &ptr);
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-static void handle_addrinfo_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
- {
- char hostname[kDNSServiceMaxDomainName];
- uint16_t rrtype, rdlen;
- const char *rdata;
- uint32_t ttl;
-
- get_string(&data, end, hostname, kDNSServiceMaxDomainName);
- rrtype = get_uint16(&data, end);
- get_uint16(&data, end); // rrclass
- rdlen = get_uint16(&data, end);
- rdata = get_rdata (&data, end, rdlen);
- ttl = get_uint32(&data, end);
-
- // We only generate client callbacks for A and AAAA results (including NXDOMAIN results for
- // those types, if the client has requested those with the kDNSServiceFlagsReturnIntermediates).
- // Other result types, specifically CNAME referrals, are not communicated to the client, because
- // the DNSServiceGetAddrInfoReply interface doesn't have any meaningful way to communiate CNAME referrals.
- if (!data) syslog(LOG_WARNING, "dnssd_clientstub handle_addrinfo_response: error reading result from daemon");
- else if (rrtype == kDNSServiceType_A || rrtype == kDNSServiceType_AAAA)
- {
- struct sockaddr_in sa4;
- struct sockaddr_in6 sa6;
- const struct sockaddr *const sa = (rrtype == kDNSServiceType_A) ? (struct sockaddr*)&sa4 : (struct sockaddr*)&sa6;
- if (rrtype == kDNSServiceType_A)
- {
- memset(&sa4, 0, sizeof(sa4));
- #ifndef NOT_HAVE_SA_LEN
- sa4.sin_len = sizeof(struct sockaddr_in);
- #endif
- sa4.sin_family = AF_INET;
- // sin_port = 0;
- if (!cbh->cb_err) memcpy(&sa4.sin_addr, rdata, rdlen);
- }
- else
- {
- memset(&sa6, 0, sizeof(sa6));
- #ifndef NOT_HAVE_SA_LEN
- sa6.sin6_len = sizeof(struct sockaddr_in6);
- #endif
- sa6.sin6_family = AF_INET6;
- // sin6_port = 0;
- // sin6_flowinfo = 0;
- // sin6_scope_id = 0;
- if (!cbh->cb_err)
- {
- memcpy(&sa6.sin6_addr, rdata, rdlen);
- if (IN6_IS_ADDR_LINKLOCAL(&sa6.sin6_addr)) sa6.sin6_scope_id = cbh->cb_interface;
- }
- }
- ((DNSServiceGetAddrInfoReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, hostname, sa, ttl, sdr->AppContext);
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
- }
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- uint32_t protocol,
- const char *hostname,
- DNSServiceGetAddrInfoReply callBack,
- void *context /* may be NULL */
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err;
-
- if (!hostname) return kDNSServiceErr_BadParam;
-
- err = ConnectToServer(sdRef, flags, addrinfo_request, handle_addrinfo_response, reinterpret_cast<void*>(callBack), context);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- // Calculate total message length
- len = sizeof(flags);
- len += sizeof(uint32_t); // interfaceIndex
- len += sizeof(uint32_t); // protocol
- len += strlen(hostname) + 1;
-
- hdr = create_hdr(addrinfo_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_uint32(protocol, &ptr);
- put_string(hostname, &ptr);
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-static void handle_browse_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
- {
- char replyName[256], replyType[kDNSServiceMaxDomainName], replyDomain[kDNSServiceMaxDomainName];
- get_string(&data, end, replyName, 256);
- get_string(&data, end, replyType, kDNSServiceMaxDomainName);
- get_string(&data, end, replyDomain, kDNSServiceMaxDomainName);
- if (!data) syslog(LOG_WARNING, "dnssd_clientstub handle_browse_response: error reading result from daemon");
- else ((DNSServiceBrowseReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, replyName, replyType, replyDomain, sdr->AppContext);
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceBrowse
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *regtype,
- const char *domain,
- DNSServiceBrowseReply callBack,
- void *context
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err;
-
- if ((interfaceIndex == kDNSServiceInterfaceIndexAny) && includeP2PWithIndexAny())
- flags |= kDNSServiceFlagsIncludeP2P;
-
- err = ConnectToServer(sdRef, flags, browse_request, handle_browse_response, reinterpret_cast<void*>(callBack), context);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- if (!domain) domain = "";
- len = sizeof(flags);
- len += sizeof(interfaceIndex);
- len += strlen(regtype) + 1;
- len += strlen(domain) + 1;
-
- hdr = create_hdr(browse_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_string(regtype, &ptr);
- put_string(domain, &ptr);
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser(DNSServiceFlags flags, const char *domain);
-DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser(DNSServiceFlags flags, const char *domain)
- {
- DNSServiceOp *tmp;
- char *ptr;
- size_t len = sizeof(flags) + strlen(domain) + 1;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err = ConnectToServer(&tmp, 0, setdomain_request, NULL, NULL, NULL);
- if (err) return err;
-
- hdr = create_hdr(setdomain_request, &len, &ptr, 0, tmp);
- if (!hdr) { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_string(domain, &ptr);
- err = deliver_request(hdr, tmp); // Will free hdr for us
- DNSServiceRefDeallocate(tmp);
- return err;
- }
-
-static void handle_regservice_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
- {
- char name[256], regtype[kDNSServiceMaxDomainName], domain[kDNSServiceMaxDomainName];
- get_string(&data, end, name, 256);
- get_string(&data, end, regtype, kDNSServiceMaxDomainName);
- get_string(&data, end, domain, kDNSServiceMaxDomainName);
- if (!data) syslog(LOG_WARNING, "dnssd_clientstub handle_regservice_response: error reading result from daemon");
- else ((DNSServiceRegisterReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_err, name, regtype, domain, sdr->AppContext);
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceRegister
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *name,
- const char *regtype,
- const char *domain,
- const char *host,
- uint16_t PortInNetworkByteOrder,
- uint16_t txtLen,
- const void *txtRecord,
- DNSServiceRegisterReply callBack,
- void *context
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err;
- union { uint16_t s; u_char b[2]; } port = { PortInNetworkByteOrder };
-
- if (!name) name = "";
- if (!regtype) return kDNSServiceErr_BadParam;
- if (!domain) domain = "";
- if (!host) host = "";
- if (!txtRecord) txtRecord = (void*)"";
-
- // No callback must have auto-rename
- if (!callBack && (flags & kDNSServiceFlagsNoAutoRename)) return kDNSServiceErr_BadParam;
-
- if ((interfaceIndex == kDNSServiceInterfaceIndexAny) && includeP2PWithIndexAny())
- flags |= kDNSServiceFlagsIncludeP2P;
-
- err = ConnectToServer(sdRef, flags, reg_service_request, callBack ? handle_regservice_response : NULL, reinterpret_cast<void*>(callBack), context);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- len = sizeof(DNSServiceFlags);
- len += sizeof(uint32_t); // interfaceIndex
- len += strlen(name) + strlen(regtype) + strlen(domain) + strlen(host) + 4;
- len += 2 * sizeof(uint16_t); // port, txtLen
- len += txtLen;
-
- hdr = create_hdr(reg_service_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
- if (!callBack) hdr->ipc_flags |= IPC_FLAGS_NOREPLY;
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_string(name, &ptr);
- put_string(regtype, &ptr);
- put_string(domain, &ptr);
- put_string(host, &ptr);
- *ptr++ = port.b[0];
- *ptr++ = port.b[1];
- put_uint16(txtLen, &ptr);
- put_rdata(txtLen, static_cast<const unsigned char *>(txtRecord), &ptr);
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-static void handle_enumeration_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
- {
- char domain[kDNSServiceMaxDomainName];
- get_string(&data, end, domain, kDNSServiceMaxDomainName);
- if (!data) syslog(LOG_WARNING, "dnssd_clientstub handle_enumeration_response: error reading result from daemon");
- else ((DNSServiceDomainEnumReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, domain, sdr->AppContext);
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceDomainEnumReply callBack,
- void *context
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err;
-
- int f1 = (flags & kDNSServiceFlagsBrowseDomains) != 0;
- int f2 = (flags & kDNSServiceFlagsRegistrationDomains) != 0;
- if (f1 + f2 != 1) return kDNSServiceErr_BadParam;
-
- err = ConnectToServer(sdRef, flags, enumeration_request, handle_enumeration_response, reinterpret_cast<void*>(callBack), context);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- len = sizeof(DNSServiceFlags);
- len += sizeof(uint32_t);
-
- hdr = create_hdr(enumeration_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-static void ConnectionResponse(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *const data, const char *const end)
- {
- DNSRecordRef rref = static_cast<DNSRecordRef>(cbh->ipc_hdr.client_context.context);
- (void)data; // Unused
-
- //printf("ConnectionResponse got %d\n", cbh->ipc_hdr.op);
- if (cbh->ipc_hdr.op != reg_record_reply_op)
- {
- // When using kDNSServiceFlagsShareConnection, need to search the list of associated DNSServiceOps
- // to find the one this response is intended for, and then call through to its ProcessReply handler.
- // We start with our first subordinate DNSServiceRef -- don't want to accidentally match the parent DNSServiceRef.
- DNSServiceOp *op = sdr->next;
- while (op && (op->uid.u32[0] != cbh->ipc_hdr.client_context.u32[0] || op->uid.u32[1] != cbh->ipc_hdr.client_context.u32[1]))
- op = op->next;
- // Note: We may sometimes not find a matching DNSServiceOp, in the case where the client has
- // cancelled the subordinate DNSServiceOp, but there are still messages in the pipeline from the daemon
- if (op && op->ProcessReply) op->ProcessReply(op, cbh, data, end);
- // WARNING: Don't touch op or sdr after this -- client may have called DNSServiceRefDeallocate
- return;
- }
-
- if (sdr->op == connection_request)
- rref->AppCallback(rref->sdr, rref, cbh->cb_flags, cbh->cb_err, rref->AppContext);
- else
- {
- syslog(LOG_WARNING, "dnssd_clientstub ConnectionResponse: sdr->op != connection_request");
- rref->AppCallback(rref->sdr, rref, 0, kDNSServiceErr_Unknown, rref->AppContext);
- }
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef)
- {
- char *ptr;
- size_t len = 0;
- ipc_msg_hdr *hdr;
- DNSServiceErrorType err = ConnectToServer(sdRef, 0, connection_request, ConnectionResponse, NULL, NULL);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- hdr = create_hdr(connection_request, &len, &ptr, 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef *RecordRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- uint16_t rdlen,
- const void *rdata,
- uint32_t ttl,
- DNSServiceRegisterRecordReply callBack,
- void *context
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr = NULL;
- DNSRecordRef rref = NULL;
- DNSRecord **p;
- int f1 = (flags & kDNSServiceFlagsShared) != 0;
- int f2 = (flags & kDNSServiceFlagsUnique) != 0;
- if (f1 + f2 != 1) return kDNSServiceErr_BadParam;
-
- if ((interfaceIndex == kDNSServiceInterfaceIndexAny) && includeP2PWithIndexAny())
- flags |= kDNSServiceFlagsIncludeP2P;
-
- if (!sdRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRegisterRecord called with NULL DNSServiceRef"); return kDNSServiceErr_BadParam; }
-
- if (!DNSServiceRefValid(sdRef))
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRegisterRecord called with invalid DNSServiceRef %p %08X %08X", sdRef, sdRef->sockfd, sdRef->validator);
- return kDNSServiceErr_BadReference;
- }
-
- if (sdRef->op != connection_request)
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRegisterRecord called with non-DNSServiceCreateConnection DNSServiceRef %p %d", sdRef, sdRef->op);
- return kDNSServiceErr_BadReference;
- }
-
- *RecordRef = NULL;
-
- len = sizeof(DNSServiceFlags);
- len += 2 * sizeof(uint32_t); // interfaceIndex, ttl
- len += 3 * sizeof(uint16_t); // rrtype, rrclass, rdlen
- len += strlen(fullname) + 1;
- len += rdlen;
-
- hdr = create_hdr(reg_record_request, &len, &ptr, 1, sdRef);
- if (!hdr) return kDNSServiceErr_NoMemory;
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_string(fullname, &ptr);
- put_uint16(rrtype, &ptr);
- put_uint16(rrclass, &ptr);
- put_uint16(rdlen, &ptr);
- put_rdata(rdlen, static_cast<const unsigned char*>(rdata), &ptr);
- put_uint32(ttl, &ptr);
-
- rref = static_cast<DNSRecordRef>(malloc(sizeof(DNSRecord)));
- if (!rref) { free(hdr); return kDNSServiceErr_NoMemory; }
- rref->AppContext = context;
- rref->AppCallback = callBack;
- rref->record_index = sdRef->max_index++;
- rref->sdr = sdRef;
- rref->recnext = NULL;
- *RecordRef = rref;
- hdr->client_context.context = rref;
- hdr->reg_index = rref->record_index;
-
- p = &(sdRef)->rec;
- while (*p) p = &(*p)->recnext;
- *p = rref;
-
- return deliver_request(hdr, sdRef); // Will free hdr for us
- }
-
-// sdRef returned by DNSServiceRegister()
-DNSServiceErrorType DNSSD_API DNSServiceAddRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef *RecordRef,
- DNSServiceFlags flags,
- uint16_t rrtype,
- uint16_t rdlen,
- const void *rdata,
- uint32_t ttl
- )
- {
- ipc_msg_hdr *hdr;
- size_t len = 0;
- char *ptr;
- DNSRecordRef rref;
- DNSRecord **p;
-
- if (!sdRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceAddRecord called with NULL DNSServiceRef"); return kDNSServiceErr_BadParam; }
- if (!RecordRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceAddRecord called with NULL DNSRecordRef pointer"); return kDNSServiceErr_BadParam; }
- if (sdRef->op != reg_service_request)
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceAddRecord called with non-DNSServiceRegister DNSServiceRef %p %d", sdRef, sdRef->op);
- return kDNSServiceErr_BadReference;
- }
-
- if (!DNSServiceRefValid(sdRef))
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceAddRecord called with invalid DNSServiceRef %p %08X %08X", sdRef, sdRef->sockfd, sdRef->validator);
- return kDNSServiceErr_BadReference;
- }
-
- *RecordRef = NULL;
-
- len += 2 * sizeof(uint16_t); // rrtype, rdlen
- len += rdlen;
- len += sizeof(uint32_t);
- len += sizeof(DNSServiceFlags);
-
- hdr = create_hdr(add_record_request, &len, &ptr, 1, sdRef);
- if (!hdr) return kDNSServiceErr_NoMemory;
- put_flags(flags, &ptr);
- put_uint16(rrtype, &ptr);
- put_uint16(rdlen, &ptr);
- put_rdata(rdlen, static_cast<const unsigned char*>(rdata), &ptr);
- put_uint32(ttl, &ptr);
-
- rref = static_cast<DNSRecordRef>(malloc(sizeof(DNSRecord)));
- if (!rref) { free(hdr); return kDNSServiceErr_NoMemory; }
- rref->AppContext = NULL;
- rref->AppCallback = NULL;
- rref->record_index = sdRef->max_index++;
- rref->sdr = sdRef;
- rref->recnext = NULL;
- *RecordRef = rref;
- hdr->reg_index = rref->record_index;
-
- p = &(sdRef)->rec;
- while (*p) p = &(*p)->recnext;
- *p = rref;
-
- return deliver_request(hdr, sdRef); // Will free hdr for us
- }
-
-// DNSRecordRef returned by DNSServiceRegisterRecord or DNSServiceAddRecord
-DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef RecordRef,
- DNSServiceFlags flags,
- uint16_t rdlen,
- const void *rdata,
- uint32_t ttl
- )
- {
- ipc_msg_hdr *hdr;
- size_t len = 0;
- char *ptr;
-
- if (!sdRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceUpdateRecord called with NULL DNSServiceRef"); return kDNSServiceErr_BadParam; }
-
- if (!DNSServiceRefValid(sdRef))
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceUpdateRecord called with invalid DNSServiceRef %p %08X %08X", sdRef, sdRef->sockfd, sdRef->validator);
- return kDNSServiceErr_BadReference;
- }
-
- // Note: RecordRef is allowed to be NULL
-
- len += sizeof(uint16_t);
- len += rdlen;
- len += sizeof(uint32_t);
- len += sizeof(DNSServiceFlags);
-
- hdr = create_hdr(update_record_request, &len, &ptr, 1, sdRef);
- if (!hdr) return kDNSServiceErr_NoMemory;
- hdr->reg_index = RecordRef ? RecordRef->record_index : TXT_RECORD_INDEX;
- put_flags(flags, &ptr);
- put_uint16(rdlen, &ptr);
- put_rdata(rdlen, static_cast<const unsigned char*>(rdata), &ptr);
- put_uint32(ttl, &ptr);
- return deliver_request(hdr, sdRef); // Will free hdr for us
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
- (
- DNSServiceRef sdRef,
- DNSRecordRef RecordRef,
- DNSServiceFlags flags
- )
- {
- ipc_msg_hdr *hdr;
- size_t len = 0;
- char *ptr;
- DNSServiceErrorType err;
-
- if (!sdRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRemoveRecord called with NULL DNSServiceRef"); return kDNSServiceErr_BadParam; }
- if (!RecordRef) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRemoveRecord called with NULL DNSRecordRef"); return kDNSServiceErr_BadParam; }
- if (!sdRef->max_index) { syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRemoveRecord called with bad DNSServiceRef"); return kDNSServiceErr_BadReference; }
-
- if (!DNSServiceRefValid(sdRef))
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceRemoveRecord called with invalid DNSServiceRef %p %08X %08X", sdRef, sdRef->sockfd, sdRef->validator);
- return kDNSServiceErr_BadReference;
- }
-
- len += sizeof(flags);
- hdr = create_hdr(remove_record_request, &len, &ptr, 1, sdRef);
- if (!hdr) return kDNSServiceErr_NoMemory;
- hdr->reg_index = RecordRef->record_index;
- put_flags(flags, &ptr);
- err = deliver_request(hdr, sdRef); // Will free hdr for us
- if (!err)
- {
- // This RecordRef could have been allocated in DNSServiceRegisterRecord or DNSServiceAddRecord.
- // If so, delink from the list before freeing
- DNSRecord **p = &sdRef->rec;
- while (*p && *p != RecordRef) p = &(*p)->recnext;
- if (*p) *p = RecordRef->recnext;
- free(RecordRef);
- }
- return err;
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
- (
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- const char *fullname,
- uint16_t rrtype,
- uint16_t rrclass,
- uint16_t rdlen,
- const void *rdata
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- DNSServiceOp *tmp;
-
- DNSServiceErrorType err = ConnectToServer(&tmp, flags, reconfirm_record_request, NULL, NULL, NULL);
- if (err) return err;
-
- len = sizeof(DNSServiceFlags);
- len += sizeof(uint32_t);
- len += strlen(fullname) + 1;
- len += 3 * sizeof(uint16_t);
- len += rdlen;
- hdr = create_hdr(reconfirm_record_request, &len, &ptr, 0, tmp);
- if (!hdr) { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_string(fullname, &ptr);
- put_uint16(rrtype, &ptr);
- put_uint16(rrclass, &ptr);
- put_uint16(rdlen, &ptr);
- put_rdata(rdlen, static_cast<const unsigned char*>(rdata), &ptr);
-
- err = deliver_request(hdr, tmp); // Will free hdr for us
- DNSServiceRefDeallocate(tmp);
- return err;
- }
-
-static void handle_port_mapping_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
- {
- union { uint32_t l; u_char b[4]; } addr;
- uint8_t protocol;
- union { uint16_t s; u_char b[2]; } internalPort;
- union { uint16_t s; u_char b[2]; } externalPort;
- uint32_t ttl;
-
- if (!data || data + 13 > end) goto fail;
-
- addr .b[0] = *data++;
- addr .b[1] = *data++;
- addr .b[2] = *data++;
- addr .b[3] = *data++;
- protocol = *data++;
- internalPort.b[0] = *data++;
- internalPort.b[1] = *data++;
- externalPort.b[0] = *data++;
- externalPort.b[1] = *data++;
- ttl = get_uint32(&data, end);
- if (!data) goto fail;
-
- ((DNSServiceNATPortMappingReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, addr.l, protocol, internalPort.s, externalPort.s, ttl, sdr->AppContext);
- return;
- // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
-
-fail:
- syslog(LOG_WARNING, "dnssd_clientstub handle_port_mapping_response: error reading result from daemon");
- }
-
-DNSServiceErrorType DNSSD_API DNSServiceNATPortMappingCreate
- (
- DNSServiceRef *sdRef,
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- uint32_t protocol, /* TCP and/or UDP */
- uint16_t internalPortInNetworkByteOrder,
- uint16_t externalPortInNetworkByteOrder,
- uint32_t ttl, /* time to live in seconds */
- DNSServiceNATPortMappingReply callBack,
- void *context /* may be NULL */
- )
- {
- char *ptr;
- size_t len;
- ipc_msg_hdr *hdr;
- union { uint16_t s; u_char b[2]; } internalPort = { internalPortInNetworkByteOrder };
- union { uint16_t s; u_char b[2]; } externalPort = { externalPortInNetworkByteOrder };
-
- DNSServiceErrorType err = ConnectToServer(sdRef, flags, port_mapping_request, handle_port_mapping_response, reinterpret_cast<void*>(callBack), context);
- if (err) return err; // On error ConnectToServer leaves *sdRef set to NULL
-
- len = sizeof(flags);
- len += sizeof(interfaceIndex);
- len += sizeof(protocol);
- len += sizeof(internalPort);
- len += sizeof(externalPort);
- len += sizeof(ttl);
-
- hdr = create_hdr(port_mapping_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef);
- if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; }
-
- put_flags(flags, &ptr);
- put_uint32(interfaceIndex, &ptr);
- put_uint32(protocol, &ptr);
- *ptr++ = internalPort.b[0];
- *ptr++ = internalPort.b[1];
- *ptr++ = externalPort.b[0];
- *ptr++ = externalPort.b[1];
- put_uint32(ttl, &ptr);
-
- err = deliver_request(hdr, *sdRef); // Will free hdr for us
- if (err) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; }
- return err;
- }
-
-#if _DNS_SD_LIBDISPATCH
-DNSServiceErrorType DNSSD_API DNSServiceSetDispatchQueue
- (
- DNSServiceRef service,
- dispatch_queue_t queue
- )
- {
- int dnssd_fd = DNSServiceRefSockFD(service);
- if (dnssd_fd == dnssd_InvalidSocket) return kDNSServiceErr_BadParam;
- if (!queue)
- {
- syslog(LOG_WARNING, "dnssd_clientstub: DNSServiceSetDispatchQueue dispatch queue NULL");
- return kDNSServiceErr_BadParam;
- }
- if (service->disp_queue)
- {
- syslog(LOG_WARNING, "dnssd_clientstub DNSServiceSetDispatchQueue dispatch queue set already");
- return kDNSServiceErr_BadParam;
- }
- if (service->disp_source)
- {
- syslog(LOG_WARNING, "DNSServiceSetDispatchQueue dispatch source set already");
- return kDNSServiceErr_BadParam;
- }
- service->disp_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, dnssd_fd, 0, queue);
- if (!service->disp_source)
- {
- syslog(LOG_WARNING, "DNSServiceSetDispatchQueue dispatch_source_create failed");
- return kDNSServiceErr_NoMemory;
- }
- service->disp_queue = queue;
- dispatch_source_set_event_handler(service->disp_source, ^{DNSServiceProcessResult(service);});
- dispatch_source_set_cancel_handler(service->disp_source, ^{dnssd_close(dnssd_fd);});
- dispatch_resume(service->disp_source);
- return kDNSServiceErr_NoError;
- }
-#endif // _DNS_SD_LIBDISPATCH
-}}
diff --git a/src/libs/zeroconf/embed/dnssd_ipc.c b/src/libs/zeroconf/embed/dnssd_ipc.c
deleted file mode 100644
index ec3958395a..0000000000
--- a/src/libs/zeroconf/embed/dnssd_ipc.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "dnssd_ipc.h"
-
-namespace ZeroConf { namespace embeddedLib {
-#if defined(_WIN32)
-
-char *win32_strerror(int inErrorCode)
- {
- static char buffer[1024];
- DWORD n;
- memset(buffer, 0, sizeof(buffer));
- n = FormatMessageA(
- FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- (DWORD) inErrorCode,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- buffer,
- sizeof(buffer),
- NULL);
- if (n > 0)
- {
- // Remove any trailing CR's or LF's since some messages have them.
- while ((n > 0) && isspace(((unsigned char *) buffer)[n - 1]))
- buffer[--n] = '\0';
- }
- return buffer;
- }
-
-#endif
-
-void put_uint32(const uint32_t l, char **ptr)
- {
- (*ptr)[0] = (char)((l >> 24) & 0xFF);
- (*ptr)[1] = (char)((l >> 16) & 0xFF);
- (*ptr)[2] = (char)((l >> 8) & 0xFF);
- (*ptr)[3] = (char)((l ) & 0xFF);
- *ptr += sizeof(uint32_t);
- }
-
-uint32_t get_uint32(const char **ptr, const char *end)
- {
- if (!*ptr || *ptr + sizeof(uint32_t) > end)
- {
- *ptr = NULL;
- return(0);
- }
- else
- {
- uint8_t *p = (uint8_t*) *ptr;
- *ptr += sizeof(uint32_t);
- return((uint32_t) ((uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | p[3]));
- }
- }
-
-void put_uint16(uint16_t s, char **ptr)
- {
- (*ptr)[0] = (char)((s >> 8) & 0xFF);
- (*ptr)[1] = (char)((s ) & 0xFF);
- *ptr += sizeof(uint16_t);
- }
-
-uint16_t get_uint16(const char **ptr, const char *end)
- {
- if (!*ptr || *ptr + sizeof(uint16_t) > end)
- {
- *ptr = NULL;
- return(0);
- }
- else
- {
- uint8_t *p = (uint8_t*) *ptr;
- *ptr += sizeof(uint16_t);
- return((uint16_t) ((uint16_t)p[0] << 8 | p[1]));
- }
- }
-
-int put_string(const char *str, char **ptr)
- {
- if (!str) str = "";
- strcpy(*ptr, str);
- *ptr += strlen(str) + 1;
- return 0;
- }
-
-int get_string(const char **ptr, const char *const end, char *buffer, int buflen)
- {
- if (!*ptr)
- {
- *buffer = 0;
- return(-1);
- }
- else
- {
- char *lim = buffer + buflen; // Calculate limit
- while (*ptr < end && buffer < lim)
- {
- char c = *buffer++ = *(*ptr)++;
- if (c == 0) return(0); // Success
- }
- if (buffer == lim) buffer--;
- *buffer = 0; // Failed, so terminate string,
- *ptr = NULL; // clear pointer,
- return(-1); // and return failure indication
- }
- }
-
-void put_rdata(const int rdlen, const unsigned char *rdata, char **ptr)
- {
- memcpy(*ptr, rdata, rdlen);
- *ptr += rdlen;
- }
-
-const char *get_rdata(const char **ptr, const char *end, int rdlen)
- {
- if (!*ptr || *ptr + rdlen > end)
- {
- *ptr = NULL;
- return(0);
- }
- else
- {
- const char *rd = *ptr;
- *ptr += rdlen;
- return rd;
- }
- }
-
-void ConvertHeaderBytes(ipc_msg_hdr *hdr)
- {
- hdr->version = htonl(hdr->version);
- hdr->datalen = htonl(hdr->datalen);
- hdr->ipc_flags = htonl(hdr->ipc_flags);
- hdr->op = htonl(hdr->op );
- hdr->reg_index = htonl(hdr->reg_index);
- }
- }}
diff --git a/src/libs/zeroconf/embed/dnssd_ipc.h b/src/libs/zeroconf/embed/dnssd_ipc.h
deleted file mode 100644
index e116515e35..0000000000
--- a/src/libs/zeroconf/embed/dnssd_ipc.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/* -*- Mode: C; tab-width: 4 -*-
- *
- * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef DNSSD_IPC_H
-#define DNSSD_IPC_H
-
-#include "../dns_sd_types.h"
-
-//
-// Common cross platform services
-//
-#if defined(WIN32)
-# include <winsock2.h>
-# define dnssd_InvalidSocket INVALID_SOCKET
-# define dnssd_SocketValid(s) ((s) != INVALID_SOCKET)
-# define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
-# define dnssd_EINTR WSAEINTR
-# define dnssd_ECONNRESET WSAECONNRESET
-# define dnssd_sock_t SOCKET
-# define dnssd_socklen_t int
-# define dnssd_close(sock) closesocket(sock)
-# define dnssd_errno WSAGetLastError()
-# define dnssd_strerror(X) win32_strerror(X)
-# define ssize_t int
-# define getpid _getpid
-# define unlink _unlink
-extern char *win32_strerror(int inErrorCode);
-# define USE_TCP_LOOPBACK
-#else
-# include <sys/types.h>
-# include <unistd.h>
-# include <sys/un.h>
-# include <string.h>
-# include <stdio.h>
-# include <stdlib.h>
-# include <sys/stat.h>
-# include <sys/socket.h>
-# include <netinet/in.h>
-# define dnssd_InvalidSocket -1
-# define dnssd_SocketValid(s) ((s) >= 0)
-# define dnssd_EWOULDBLOCK EWOULDBLOCK
-# define dnssd_EINTR EINTR
-# define dnssd_ECONNRESET ECONNRESET
-# define dnssd_EPIPE EPIPE
-# define dnssd_sock_t int
-# define dnssd_socklen_t unsigned int
-# define dnssd_close(sock) close(sock)
-# define dnssd_errno errno
-# define dnssd_strerror(X) strerror(X)
-#endif
-
-#if defined(USE_TCP_LOOPBACK)
-# define AF_DNSSD AF_INET
-# define MDNS_TCP_SERVERADDR "127.0.0.1"
-# define MDNS_TCP_SERVERPORT 5354
-# define LISTENQ 5
-# define dnssd_sockaddr_t struct sockaddr_in
-#else
-# define AF_DNSSD AF_LOCAL
-# ifndef MDNS_UDS_SERVERPATH
-# define MDNS_UDS_SERVERPATH "/var/run/mdnsd"
-# endif
-# define LISTENQ 100
- // longest legal control path length
-# define MAX_CTLPATH 256
-# define dnssd_sockaddr_t struct sockaddr_un
-#endif
-
-// Compatibility workaround
-#ifndef AF_LOCAL
-#define AF_LOCAL AF_UNIX
-#endif
-
-// General UDS constants
-#define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
-
-// IPC data encoding constants and types
-#define VERSION 1
-#define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
-
-// Structure packing macro. If we're not using GNUC, it's not fatal. Most compilers naturally pack the on-the-wire
-// structures correctly anyway, so a plain "struct" is usually fine. In the event that structures are not packed
-// correctly, our compile-time assertion checks will catch it and prevent inadvertent generation of non-working code.
-#ifndef packedstruct
- #if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9)))
- #define packedstruct struct __attribute__((__packed__))
- #define packedunion union __attribute__((__packed__))
- #else
- #define packedstruct struct
- #define packedunion union
- #endif
-#endif
-
-namespace ZeroConf { namespace embeddedLib {
-typedef enum
- {
- request_op_none = 0, // No request yet received on this connection
- connection_request = 1, // connected socket via DNSServiceConnect()
- reg_record_request, // reg/remove record only valid for connected sockets
- remove_record_request,
- enumeration_request,
- reg_service_request,
- browse_request,
- resolve_request,
- query_request,
- reconfirm_record_request,
- add_record_request,
- update_record_request,
- setdomain_request, // Up to here is in Tiger and B4W 1.0.3
- getproperty_request, // New in B4W 1.0.4
- port_mapping_request, // New in Leopard and B4W 2.0
- addrinfo_request,
- send_bpf, // New in SL
-
- cancel_request = 63
- } request_op_t;
-
-typedef enum
- {
- enumeration_reply_op = 64,
- reg_service_reply_op,
- browse_reply_op,
- resolve_reply_op,
- query_reply_op,
- reg_record_reply_op, // Up to here is in Tiger and B4W 1.0.3
- getproperty_reply_op, // New in B4W 1.0.4
- port_mapping_reply_op, // New in Leopard and B4W 2.0
- addrinfo_reply_op
- } reply_op_t;
-}}
-extern "C" {
-
-#if defined(_WIN64)
-# pragma pack(push,4)
-#endif
-
-// Define context object big enough to hold a 64-bit pointer,
-// to accomodate 64-bit clients communicating with 32-bit daemon.
-// There's no reason for the daemon to ever be a 64-bit process, but its clients might be
-typedef packedunion
- {
- void *context;
- uint32_t u32[2];
- } client_context_t;
-
-typedef packedstruct
- {
- uint32_t version;
- uint32_t datalen;
- uint32_t ipc_flags;
- uint32_t op; // request_op_t or reply_op_t
- client_context_t client_context; // context passed from client, returned by server in corresponding reply
- uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
- // socket connected by DNSServiceCreateConnection(). Must be unique in the scope of the connection, such that and
- // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
- } ipc_msg_hdr;
-
-#if defined(_WIN64)
-# pragma pack(pop)
-#endif
-
-// routines to write to and extract data from message buffers.
-// caller responsible for bounds checking.
-// ptr is the address of the pointer to the start of the field.
-// it is advanced to point to the next field, or the end of the message
-}
-
-namespace ZeroConf { namespace embeddedLib {
-
-void put_uint32(const uint32_t l, char **ptr);
-uint32_t get_uint32(const char **ptr, const char *end);
-
-void put_uint16(uint16_t s, char **ptr);
-uint16_t get_uint16(const char **ptr, const char *end);
-
-#define put_flags put_uint32
-#define get_flags get_uint32
-
-#define put_error_code put_uint32
-#define get_error_code get_uint32
-
-int put_string(const char *str, char **ptr);
-int get_string(const char **ptr, const char *const end, char *buffer, int buflen);
-
-void put_rdata(const int rdlen, const unsigned char *rdata, char **ptr);
-const char *get_rdata(const char **ptr, const char *end, int rdlen); // return value is rdata pointed to by *ptr -
- // rdata is not copied from buffer.
-
-void ConvertHeaderBytes(ipc_msg_hdr *hdr);
-
-struct CompileTimeAssertionChecks_dnssd_ipc
- {
- // Check that the compiler generated our on-the-wire packet format structure definitions
- // properly packed, without adding padding bytes to align fields on 32-bit or 64-bit boundaries.
- char assert0[(sizeof(client_context_t) == 8) ? 1 : -1];
- char assert1[(sizeof(ipc_msg_hdr) == 28) ? 1 : -1];
- };
- }}
-
-#endif // DNSSD_IPC_H
diff --git a/src/libs/zeroconf/embeddedLib.cpp b/src/libs/zeroconf/embeddedLib.cpp
deleted file mode 100644
index 0c24ce8edc..0000000000
--- a/src/libs/zeroconf/embeddedLib.cpp
+++ /dev/null
@@ -1,295 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "syssocket.h" // this should be the first header included
-
-#include "servicebrowser_p.h"
-
-#include <QCoreApplication>
-#include <QDebug>
-#include <QDir>
-#include <QFileInfo>
-#include <QString>
-#include <QStringList>
-#include <QProcess>
-
-#ifdef Q_OS_LINUX
-#define EMBEDDED_LIB
-#endif
-
-#ifdef Q_OS_WIN32
-#define EMBEDDED_LIB
-#endif
-
-#ifdef EMBEDDED_LIB
-#define PID_FILE "/tmp/mdnsd.pid"
-#define MDNS_UDS_SERVERPATH "/tmp/mdnsd"
-
-#include "embed/dnssd_ipc.c"
-#include "embed/dnssd_clientlib.c"
-#include "embed/dnssd_clientstub.c"
-#ifdef Q_OS_WIN
-#include "embed/DebugServices.c"
-#endif
-
-namespace ZeroConf {
-namespace Internal {
-// represents a zero conf library exposing the dns-sd interface
-class EmbeddedZConfLib : public ZConfLib
-{
-public:
- QString daemonPath;
-
- EmbeddedZConfLib(const QString &daemonPath, ZConfLib::Ptr fallBack) : ZConfLib(fallBack),
- daemonPath(daemonPath)
- {
- if (daemonPath.isEmpty())
- m_maxErrors = 0;
- if (!daemonPath.isEmpty() && daemonPath.at(0) != QLatin1Char('/') && daemonPath.at(0) != QLatin1Char('.'))
- this->daemonPath = QCoreApplication::applicationDirPath() + QLatin1Char('/') + daemonPath;
- }
-
- ~EmbeddedZConfLib()
- { }
-
- QString name()
- {
- return QString::fromLatin1("Embedded Dns_sd Library");
- }
-
- bool tryStartDaemon(ErrorMessage::ErrorLogger *logger)
- {
- if (!daemonPath.isEmpty()) {
- QFileInfo dPath(daemonPath);
- QProcess killall;
- bool killAllFailed = false;
-#ifdef Q_OS_WIN
- QString cmd = QLatin1String("taskill /im ") + dPath.fileName()
- + QLatin1String(" /f /t");
-#else
- QString cmd = QLatin1String("killall ") + dPath.fileName()
- + QLatin1String(" 2> /dev/null");
-#endif
- killall.start(cmd);
- if (!killall.waitForStarted()) {
- killAllFailed = true;
- } else {
- killall.closeWriteChannel();
- killall.waitForFinished();
- }
- if (killAllFailed) {
- if (logger)
- logger->appendError(ErrorMessage::WarningLevel,
- ZConfLib::tr("%1 failed to kill other daemons with \"%2\".")
- .arg(name()).arg(cmd));
- if (DEBUG_ZEROCONF)
- qDebug() << name() << " had an error trying to kill other daemons with " << cmd;
- }
- QString daemonCmd = daemonPath;
- QStringList daemonArgs;
-#ifdef Q_OS_LINUX
- if (QFile::exists(QLatin1String("/tmp/mdnsd")) && logger)
- logger->appendError(ErrorMessage::WarningLevel,
- ZConfLib::tr("%1 detected a file at /tmp/mdnsd, daemon startup will probably fail.")
- .arg(name()));
- QString logFile = QString::fromLatin1("/tmp/mdnssd.log");
- static int didFail = 0;
- QFile oldLog(logFile);
- if (didFail > 1 && oldLog.exists()) {
- oldLog.open(QIODevice::ReadOnly);
- if (logger) {
- QByteArray logBA = oldLog.readAll();
- logger->appendError(ErrorMessage::NoteLevel,
- ZConfLib::tr("%1: log of previous daemon run is: \"%2\".")
- .arg(name(), QString::fromLatin1(logBA.constData(), logBA.size())) + QLatin1Char('\n'));
- qDebug()<<logBA.size()<<oldLog.error()<<oldLog.errorString();
- }
- oldLog.close();
- }
- if (++didFail > 1)
- daemonArgs << QString::fromLatin1("-debug");
-#endif
- if (QProcess::startDetached(daemonCmd, daemonArgs)) {
- QThread::yieldCurrentThread();
- // sleep a bit?
- if (DEBUG_ZEROCONF)
- qDebug() << name() << " started " << daemonCmd << daemonArgs;
- return true;
- } else {
- this->setError(true, ZConfLib::tr("%1 failed starting embedded daemon at %2.")
- .arg(name()).arg(daemonPath));
- }
- }
- return false;
- }
-
- void refDeallocate(DNSServiceRef sdRef)
- {
- embeddedLib::DNSServiceRefDeallocate(sdRef);
- }
-
- void browserDeallocate(BrowserRef *bRef)
- {
- if (bRef){
- embeddedLib::DNSServiceRefDeallocate(*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 (sdRef) {
- embeddedLib::DNSServiceRefDeallocate(*reinterpret_cast<DNSServiceRef*>(sdRef));
- *sdRef = 0;
- }
- }
-
- DNSServiceErrorType resolve(ConnectionRef cRef,
- DNSServiceRef *sdRef,
- uint32_t interfaceIndex,
- ZK_IP_Protocol /* protocol */,
- const char *name,
- const char *regtype,
- const char *domain,
- ServiceGatherer *gatherer)
- {
- *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
- return embeddedLib::DNSServiceResolve(sdRef, kDNSServiceFlagsShareConnection
- // | kDNSServiceFlagsSuppressUnusable
- | kDNSServiceFlagsTimeout,
- interfaceIndex, name, regtype, domain,
- &cServiceResolveReply, gatherer);
- }
-
- DNSServiceErrorType queryRecord(ConnectionRef cRef,
- DNSServiceRef *sdRef,
- uint32_t interfaceIndex,
- const char *fullname,
- ServiceGatherer *gatherer)
- {
- *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
- return embeddedLib::DNSServiceQueryRecord(sdRef, kDNSServiceFlagsShareConnection
- // | kDNSServiceFlagsSuppressUnusable
- | kDNSServiceFlagsTimeout,
- interfaceIndex, fullname,
- kDNSServiceType_TXT, kDNSServiceClass_IN,
- &cTxtRecordReply , gatherer);
- }
-
- DNSServiceErrorType getAddrInfo(ConnectionRef cRef,
- DNSServiceRef *sdRef,
- uint32_t interfaceIndex,
- DNSServiceProtocol protocol,
- const char *hostname,
- ServiceGatherer *gatherer)
- {
- *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
- return embeddedLib::DNSServiceGetAddrInfo(sdRef, kDNSServiceFlagsShareConnection
- // | kDNSServiceFlagsSuppressUnusable
- | kDNSServiceFlagsTimeout,
- interfaceIndex, protocol,
- hostname, &cAddrReply, gatherer);
- }
-
- DNSServiceErrorType reconfirmRecord(ConnectionRef /*cRef*/, uint32_t /*interfaceIndex*/,
- const char * /*name*/, const char * /*type*/,
- const char * /*domain*/, const char * /*fullname*/)
- {
- // 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)
- {
- DNSServiceRef *sdRef = reinterpret_cast<DNSServiceRef *>(bRef);
- *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
- return embeddedLib::DNSServiceBrowse(sdRef, kDNSServiceFlagsShareConnection
- /* | kDNSServiceFlagsSuppressUnusable */,
- interfaceIndex, regtype, domain, &cBrowseReply,
- browser);
- }
-
- DNSServiceErrorType getProperty(const char *property, void *result, uint32_t *size)
- {
- return embeddedLib::DNSServiceGetProperty(property, result, size);
- }
-
- RunLoopStatus processOneEventBlock(ConnectionRef cRef)
- {
- if (embeddedLib::DNSServiceProcessResult(reinterpret_cast<DNSServiceRef>(cRef)) != kDNSServiceErr_NoError)
- return ProcessedError;
- return ProcessedOk;
- }
-
- DNSServiceErrorType createConnection(MainConnection *, ConnectionRef *sdRef)
- {
- return embeddedLib::DNSServiceCreateConnection(reinterpret_cast<DNSServiceRef*>(sdRef));
- }
-
- int refSockFD(ConnectionRef sdRef)
- {
- return embeddedLib::DNSServiceRefSockFD(reinterpret_cast<DNSServiceRef>(sdRef));
- }
-};
-
-ZConfLib::Ptr ZConfLib::createEmbeddedLib(const QString &daemonPath, const ZConfLib::Ptr &fallback)
-{
- return ZConfLib::Ptr(new EmbeddedZConfLib(daemonPath, fallback));
-}
-} // namespace Internal
-} // namespace ZeroConf
-
-#else // no embedded lib
-
-namespace ZeroConf {
-namespace Internal {
-
-ZConfLib::Ptr ZConfLib::createEmbeddedLib(const QString &, const ZConfLib::Ptr &fallback)
-{
- return fallback;
-}
-
-} // namespace Internal
-} // namespace ZeroConf
-#endif
diff --git a/src/libs/zeroconf/mdnsderived.cpp b/src/libs/zeroconf/mdnsderived.cpp
deleted file mode 100644
index fec910a0fa..0000000000
--- a/src/libs/zeroconf/mdnsderived.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "mdnsderived.h"
-#include "cstddef"
-#include "cstring"
-#ifdef _WIN32
-#define strncasecmp _strnicmp
-#endif
-
-namespace ZeroConf {
-namespace Internal {
-
-// DomainEndsInDot returns 1 if name ends with a dot, 0 otherwise
-// (DNSServiceConstructFullName depends this returning 1 for true, rather than any non-zero value meaning true)
-static int DomainEndsInDot(const char *dom)
-{
- while (dom[0] && dom[1]) {
- if (dom[0] == '\\') { // advance past escaped byte sequence
- if ('0' <= dom[1] && dom[1] <= '9' &&
- '0' <= dom[2] && dom[2] <= '9' &&
- '0' <= dom[3] && dom[3] <= '9')
- {
- dom += 4; // If "\ddd" then skip four
- } else {
- dom += 2; // else if "\x" then skip two
- }
- } else {
- dom++; // else goto next character
- }
- }
- return (dom[0] == '.');
-}
-
-// Note: Need to make sure we don't write more than kDNSServiceMaxDomainName (1009) bytes to fullName
-// In earlier builds this constant was defined to be 1005, so to avoid buffer overruns on clients
-// compiled with that constant we'll actually limit the output to 1005 bytes.
-DNSServiceErrorType myDNSServiceConstructFullName(char *const fullName,
- const char *const service, // May be NULL
- const char *const regtype,
- const char *const domain)
-{
- const size_t len = !regtype ? 0 : strlen(regtype) - DomainEndsInDot(regtype);
- char *fn = fullName;
- char *const lim = fullName + 1005;
- const char *s = service;
- const char *r = regtype;
- const char *d = domain;
-
- // regtype must be at least "x._udp" or "x._tcp"
- if (len < 6 || !domain || !domain[0]) return kDNSServiceErr_BadParam;
- if (strncasecmp((regtype + len - 4), "_tcp", 4) && strncasecmp((regtype + len - 4), "_udp", 4)) return kDNSServiceErr_BadParam;
-
- if (service && *service)
- {
- while (*s)
- {
- unsigned char c = *s++; // Needs to be unsigned, or values like 0xFF will be interpreted as < 32
- if (c <= ' ') // Escape non-printable characters
- {
- if (fn + 4 >= lim) goto fail;
- *fn++ = '\\';
- *fn++ = '0' + (c / 100);
- *fn++ = '0' + (c / 10) % 10;
- c = '0' + (c ) % 10;
- }
- else if (c == '.' || (c == '\\')) // Escape dot and backslash literals
- {
- if (fn + 2 >= lim) goto fail;
- *fn++ = '\\';
- }
- else
- if (fn + 1 >= lim) goto fail;
- *fn++ = (char)c;
- }
- *fn++ = '.';
- }
-
- while (*r) if (fn + 1 >= lim) goto fail; else *fn++ = *r++;
- if (!DomainEndsInDot(regtype)) { if (fn + 1 >= lim) goto fail; else *fn++ = '.'; }
-
- while (*d) if (fn + 1 >= lim) goto fail; else *fn++ = *d++;
- if (!DomainEndsInDot(domain)) { if (fn + 1 >= lim) goto fail; else *fn++ = '.'; }
-
- *fn = '\0';
- return kDNSServiceErr_NoError;
-
-fail:
- *fn = '\0';
- 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
deleted file mode 100644
index 60139f22ee..0000000000
--- a/src/libs/zeroconf/mdnsderived.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef MDNSDERIVED_H
-#define MDNSDERIVED_H
-
-#include "zeroconf_global.h"
-#include "dns_sd_types.h"
-
-namespace ZeroConf {
-namespace Internal {
-
-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);
-
-}
-}
-#endif // MDNSDERIVED_H
diff --git a/src/libs/zeroconf/servicebrowser.cpp b/src/libs/zeroconf/servicebrowser.cpp
deleted file mode 100644
index 1ec63e8cda..0000000000
--- a/src/libs/zeroconf/servicebrowser.cpp
+++ /dev/null
@@ -1,2103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-#include "zeroconf_global.h"
-#ifdef Q_OS_WIN
-// Disable min max macros from windows headers,
-// because we want to use the template methods from std.
-# ifndef NOMINMAX
-# define NOMINMAX
-# endif
-# include <winsock2.h>
-#endif // Q_OS_WIN
-
-#include "mdnsderived.h"
-#include "servicebrowser_p.h"
-
-#include <algorithm>
-#include <errno.h>
-#include <limits>
-#include <signal.h>
-#ifdef Q_OS_UNIX
-// for select()
-# include <unistd.h>
-#endif
-
-#include <QAtomicPointer>
-#include <QCoreApplication>
-#include <QDateTime>
-#include <QGlobalStatic>
-#include <QMetaType>
-#include <QMutexLocker>
-#include <QNetworkInterface>
-#include <QString>
-#include <QStringList>
-#include <QtEndian>
-#include <QHostInfo>
-
-//the timeval struct under windows uses long instead of suseconds_t
-#ifdef Q_OS_WIN
-typedef long suseconds_t;
-#endif
-
-/*!
- \namespace ZeroConf
-
- \brief The ZeroConf namespace provides zeroconf (Bonjour/DNS-SD)
- functionality, currently mostly for browsing services.
-*/
-
-namespace { // anonymous namespace for free functions
-// ----------------- free functions -----------------
-
-using namespace ZeroConf;
-using namespace ZeroConf::Internal;
-
-QString toFullNameC(const char * const service, const char * const regtype, const char * const domain)
-{
- char fullName[kDNSServiceMaxDomainName];
- myDNSServiceConstructFullName(fullName, service, regtype, domain);
- fullName[kDNSServiceMaxDomainName - 1] = 0; // just to be sure
- return QString::fromUtf8(fullName);
-}
-
-int fromFullNameC(const char * const fullName, QString &service, QString &regtype, QString &domain)
-{
- char fullNameDecoded[kDNSServiceMaxDomainName];
- int encodedI = 0;
- int decodedI = 0;
- int oldPos[4];
- int iPos = 0;
- while (fullName[encodedI] != 0 && encodedI <kDNSServiceMaxDomainName){
- char c = fullName[encodedI++];
- if (c == '\\'){
- c = fullName[++encodedI];
- if (c == 0 || encodedI == kDNSServiceMaxDomainName)
- return 1;
- if (c >= '0' && c <= '9'){
- int val = (c - '0') * 100;
- c = fullName[++encodedI];
- if (c < '0' || c > '9' || encodedI == kDNSServiceMaxDomainName)
- return 2;
- val += (c - '0') * 10;
- c = fullName[++encodedI];
- if (c < '0' || c > '9')
- return 3;
- val += (c - '0');
- fullNameDecoded[decodedI++] = static_cast<char>(static_cast<unsigned char>(val));
- } else {
- fullNameDecoded[decodedI++] = c;
- }
- } else if (c == '.') {
- if (iPos < 4)
- oldPos[iPos++] = decodedI;
- fullNameDecoded[decodedI++] = c;
- } else {
- fullNameDecoded[decodedI++] = c;
- }
- }
- if (iPos != 4) return 5;
- service = QString::fromUtf8(&fullNameDecoded[0], oldPos[0]);
- regtype = QString::fromUtf8(&fullNameDecoded[oldPos[0] + 1], oldPos[3] - oldPos[0] - 1);
- domain = QString::fromUtf8(&fullNameDecoded[oldPos[3] + 1], decodedI - oldPos[3] - 1);
- return 0;
-}
-
-/// singleton for lib setup
-class ZeroConfLib
-{
-public:
- ZeroConfLib();
- ZConfLib::Ptr defaultLib();
- void setDefaultLib(LibUsage usage, const QString &avahiLibName, const QString &avahiVersion,
- const QString &dnsSdLibName, const QString &dnsSdDaemonPath);
- int nFallbacksTot() const;
-
-private:
- static const char *defaultmDnsSdLibName;
- static const char *defaultmDNSDaemonName;
- int m_nFallbacksTot;
- QMutex m_lock;
- ZConfLib::Ptr m_defaultLib;
-};
-
-Q_GLOBAL_STATIC(ZeroConfLib, zeroConfLibInstance)
-
-#ifdef Q_OS_WIN
- const char *ZeroConfLib::defaultmDnsSdLibName = "dnssd";
- const char *ZeroConfLib::defaultmDNSDaemonName = "mdnssd.exe";
-#else
- const char *ZeroConfLib::defaultmDnsSdLibName = "dns_sd";
- const char *ZeroConfLib::defaultmDNSDaemonName = "mdnssd";
-#endif
-
-ZeroConfLib::ZeroConfLib(): m_lock(QMutex::Recursive),
- m_defaultLib(ZConfLib::createDnsSdLib(QLatin1String(defaultmDnsSdLibName),
- ZConfLib::createEmbeddedLib(QString(),
- ZConfLib::createAvahiLib(QLatin1String("avahi-client"),QLatin1String("3"),
- ZConfLib::createEmbeddedLib(QLatin1String(defaultmDNSDaemonName))))))
-{
- qRegisterMetaType<ZeroConf::Service::ConstPtr>("ZeroConf::Service::ConstPtr");
- qRegisterMetaType<ZeroConf::ErrorMessage::SeverityLevel>("ZeroConf::ErrorMessage::SeverityLevel");
- qRegisterMetaType<ZeroConf::ErrorMessage>("ZeroConf::ErrorMessage");
- qRegisterMetaType<QList<ZeroConf::ErrorMessage> >("QList<ZeroConf::ErrorMessage>");
- m_nFallbacksTot = (m_defaultLib ? m_defaultLib->nFallbacks() : 0);
-
-}
-
-ZConfLib::Ptr ZeroConfLib::defaultLib(){
- QMutexLocker l(&m_lock);
- return m_defaultLib;
-}
-
-void ZeroConfLib::setDefaultLib(LibUsage usage, const QString &avahiLibName,
- const QString &avahiVersion, const QString &dnsSdLibName,
- const QString &dnsSdDaemonPath){
- QMutexLocker l(&m_lock);
- switch (usage){
- case (UseDnsSdOnly):
- m_defaultLib = ZConfLib::createDnsSdLib(dnsSdLibName);
- break;
- case (UseEmbeddedOnly):
- m_defaultLib = ZConfLib::createEmbeddedLib(dnsSdDaemonPath);
- break;
- case (UseAvahiOnly):
- m_defaultLib = ZConfLib::createAvahiLib(avahiLibName, avahiVersion);
- break;
- case (UseAvahiOrDnsSd):
- m_defaultLib = ZConfLib::createAvahiLib(avahiLibName, avahiVersion,
- ZConfLib::createDnsSdLib(dnsSdLibName));
- break;
- case (UseAvahiOrDnsSdOrEmbedded):
- m_defaultLib = ZConfLib::createAvahiLib(avahiLibName, avahiVersion,
- ZConfLib::createDnsSdLib(dnsSdLibName,
- ZConfLib::createEmbeddedLib(dnsSdDaemonPath)));
- break;
- default:
- qDebug() << "invalid usage " << usage;
- }
- int newNFallbacks = m_defaultLib->nFallbacks();
- if (m_nFallbacksTot < newNFallbacks)
- m_nFallbacksTot = newNFallbacks;
-}
-
-int ZeroConfLib::nFallbacksTot() const
-{
- return m_nFallbacksTot;
-}
-
-} // end anonymous namespace
-
-namespace ZeroConf {
-
-int gQuickStop = 0;
-
-// ----------------- ErrorMessage impl -----------------
-/*!
- \class ZeroConf::ErrorMessage
-
- \brief The ErrorMessage class represents an error message.
-
- */
-
-/// empty constructor (required by qRegisterMetaType)
-ErrorMessage::ErrorMessage(): severity(FailureLevel) {}
-/// constructor
-ErrorMessage::ErrorMessage(SeverityLevel s, const QString &m): severity(s), msg(m) {}
-
-/// returns a human readable string for each severity level
-QString ErrorMessage::severityLevelToString(ErrorMessage::SeverityLevel severity)
-{
- const char *ctx = "Zeroconf::SeverityLevel";
- switch (severity) {
- case NoteLevel:
- return QCoreApplication::translate(ctx, "NOTE");
- case WarningLevel:
- return QCoreApplication::translate(ctx, "WARNING");
- case ErrorLevel:
- return QCoreApplication::translate(ctx, "ERROR");
- case FailureLevel:
- return QCoreApplication::translate(ctx, "FATAL_ERROR");
- default:
- return QCoreApplication::translate(ctx, "UNKNOWN_LEVEL_%1").arg(severity);
- }
-}
-
-QDebug operator<<(QDebug dbg, const ErrorMessage &eMsg)
-{
- dbg << ErrorMessage::severityLevelToString(eMsg.severity) << eMsg.msg;
- return dbg;
-}
-
-// ----------------- Service impl -----------------
-/*!
- \class ZeroConf::Service
-
- \brief The Service class represents a zeroconf service.
-
- Instances of this class are basically constant, but can be outdated. They are normally accessed
- through a Shared pointer.
- This design avoids race conditions when used though multiple threads.
-
- \threadsafe
- */
-
-Service::Service(const Service &o) :
- m_name(o.m_name),
- m_type(o.m_type),
- m_domain(o.m_domain),
- m_fullName(o.m_fullName),
- m_port(o.m_port),
- m_txtRecord(o.m_txtRecord),
- m_host(o.m_host ? new QHostInfo(*o.m_host) : 0),
- m_interfaceNr(o.m_interfaceNr),
- m_outdated(o.m_outdated)
-{
-}
-
-Service::Service() : m_host(0), m_interfaceNr(0), m_outdated(false)
-{ }
-
-Service::~Service()
-{
- delete m_host;
-}
-
-/*!
- Returns the interface on which the service is reachable.
- */
-QNetworkInterface Service::networkInterface() const
-{
- return QNetworkInterface::interfaceFromIndex(m_interfaceNr);
-}
-
-QStringList Service::addresses(Service::AddressStyle style) const
-{
- QStringList res;
- if (host() == 0)
- return res;
- foreach (const QHostAddress &addr, host()->addresses()){
- QString addrStr;
- if (addr.protocol() == QAbstractSocket::IPv6Protocol) {
- // Add the interface to use to the address <address>%<interface>
- //
- // This is required only for link local addresses (like fe80:*)
- // but as we have it we do it (and most likely addresses here are
- // link local).
- //
- // on windows only addresses like fe80::42%22 work
- // on OSX 10.5 only things like fe80::42%en4 work
- // on later OSX versions and linux both <address>%<interface number>
- // and <address>%<interface name> work, we use the interface name as
- // it looks better
-#ifdef Q_OS_WIN
- QString interfaceStr = QString::number(networkInterface().index());
-#else
- QString interfaceStr = networkInterface().name();
-#endif
- addrStr = QString::fromLatin1("%1%%2").arg(addr.toString()).arg(interfaceStr);
- if (style == QuoteIPv6Adresses)
- addrStr = QString::fromLatin1("[%1]").arg(addrStr);
- } else {
- addrStr = addr.toString();
- }
- res.append(addrStr);
- }
- return res;
-}
-
-bool Service::operator==(const Service &o) const {
- bool eq = m_fullName == o.m_fullName
- && m_name == o.m_name && m_type == o.m_type
- && m_domain == o.m_domain && m_port == o.m_port
- && m_txtRecord == o.m_txtRecord && m_interfaceNr == o.m_interfaceNr
- && m_outdated == o.m_outdated;
- if (eq) {
- if (m_host != o.m_host) {
- if (m_host == 0 || o.m_host == 0)
- return false;
- return m_host->hostName() == o.m_host->hostName()
- && m_host->addresses() == o.m_host->addresses();
- }
- }
- return eq;
-}
-
-QDebug operator<<(QDebug dbg, const Service &service)
-{
- dbg.maybeSpace() << "Service{ name:" << service.name() << ", "
- << "type:" << service.type() << ", domain:" << service.domain() << ", "
- << " fullName:" << service.fullName() << ", port:" << service.port()
- << ", txtRecord:{";
- bool first = true;
- QHashIterator<QString, QString> i(service.txtRecord());
- while (i.hasNext()){
- i.next();
- if (first)
- first = false;
- else
- dbg << ", ";
- dbg << i.key() << ":" << i.value();
- }
- dbg << "}, ";
- if (const QHostInfo *host = service.host()){
- dbg << "host:{" << host->hostName() << ", addresses[";
- first = true;
- foreach (const QHostAddress &addr, host->addresses()){
- if (first)
- first = false;
- else
- dbg << ", ";
- dbg << addr.toString();
- }
- dbg << "], },";
- } else {
- dbg << " host:*null*,";
- }
- dbg << " interfaceNr:" << service.interfaceNr() << ", outdated:" << service.outdated() << " }";
- return dbg.space();
-}
-
-QDebug operator<<(QDebug dbg, const Service::ConstPtr &service){
- if (service.data() == 0)
- dbg << "Service{*NULL*}";
- else
- dbg << *service.data();
- return dbg;
-}
-
-// inline methods
-/*!
- \fn bool Service::outdated() const
-
- Returns whether the service data is outdated. Its value might change even on
- the (otherwise constant) objects returned by a ServiceBrowser.
-*/
-/*!
- \fn QString Service::name() const
-
- Returns the name of the service (non escaped).
-*/
-/*!
- \fn QString Service::type() const
-
- Returns the name of the service type (non escaped).
-*/
-/*!
- \fn QString Service::domain() const
-
- Returns the name of the domain (non escaped).
-*/
-/*!
- \fn QString Service::fullName() const
-
- Returns the full name (service.type.domain) with each component correctly escaped.
-*/
-/*!
- \fn QString Service::port() const
-
- Returns the port of the service (as a string, not as number).
-*/
-/*!
- \fn const Service::ServiceTxtRecord &txtRecord() const
-
- Returns the extra information on this service.
-*/
-/*!
- \fn const Service::QHostInfo *host() const
-
- Returns the host through which this service is reachable.
-*/
-/*!
- \fn int Service::interfaceNr() const
-
- Returns the interface on which the service is reachable, 1 based, 0 means to
- try all interfaces.
-*/
-/*!
- \fn bool Service::invalidate()
-
- Marks this service as outdated.
-*/
-
-// ----------------- ServiceBrowser impl -----------------
-/*!
- \class ZeroConf::ServiceBrowser
-
- \brief The ServiceBrowser class browses (searches) for a given zeronconf
- service.
-
- The actual browsing starts only when startBrowsing() is called. If you want to receive all service
- changes, connect before starting browsing.
-
- The current list of services can be gathered with the services() method.
-
- \threadsafe
- */
-
-/// starts the browsing, return true if successfull
-void ServiceBrowser::startBrowsing(qint32 interfaceIndex)
-{
- d->startBrowsing(interfaceIndex);
-}
-
-/// create a new brower for the given service type
-ServiceBrowser::ServiceBrowser(const QString &serviceType, const QString &domain,
- AddressesSetting addressesSetting, QObject *parent)
- : QObject(parent), timer(0),
- d(new ServiceBrowserPrivate(serviceType, domain, addressesSetting == RequireAddresses,
- MainConnectionPtr()))
-{
- connect(this,SIGNAL(activateAutoRefresh()),this,SLOT(autoRefresh()));
- d->q = this;
-}
-
-ServiceBrowser::ServiceBrowser(const MainConnectionPtr &mainConnection, const QString &serviceType,
- const QString &domain, AddressesSetting addressesSetting, QObject *parent)
- : QObject(parent), timer(0),
- d(new ServiceBrowserPrivate(serviceType, domain, addressesSetting == RequireAddresses,
- mainConnection))
-{
- d->q = this;
-}
-
-ServiceBrowser::~ServiceBrowser()
-{
- delete d;
-}
-
-/// returns the main connection used by this ServiceBrowser
-MainConnectionPtr ServiceBrowser::mainConnection() const
-{
- return d->mainConnection;
-}
-
-/// stops browsing, but does not delete all services found
-void ServiceBrowser::stopBrowsing()
-{
- if (timer) {
- timer->stop();
- delete timer;
- timer = 0;
- }
- d->stopBrowsing();
-}
-
-/// starts an explicit browse (important especially with avahi)
-void ServiceBrowser::triggerRefresh()
-{
- d->triggerRefresh();
-}
-
-/// if the service is currently active
-bool ServiceBrowser::isBrowsing() const
-{
- return d->browsing;
-}
-
-/// type of the service browsed (non escaped)
-const QString& ServiceBrowser::serviceType() const
-{
- return d->serviceType;
-}
-
-/// domain that is browser (non escaped)
-const QString& ServiceBrowser::domain() const
-{
- return d->domain;
-}
-
-/// if addresses should be resolved automatically for each service found
-bool ServiceBrowser::adressesAutoResolved() const
-{
- return d->autoResolveAddresses;
-}
-
-/// if addresses are required to add the service to the list of available services
-bool ServiceBrowser::addressesRequired() const
-{
- return d->requireAddresses;
-}
-
-/// list of current services (by copy on purpose)
-QList<Service::ConstPtr> ServiceBrowser::services() const
-{
- QMutexLocker l(d->mainConnection->lock());
- return d->activeServices;
-}
-
-/// forces a full update of a service (call this after a failure to connect to the service)
-/// this is an expensive call, use only when needed
-void ServiceBrowser::reconfirmService(Service::ConstPtr service)
-{
- d->reconfirmService(service);
-}
-
-void ServiceBrowser::autoRefresh()
-{
- QMutexLocker l(d->mainConnection->lock());
- if (!timer) {
- timer = new QTimer(this);
- connect(timer,SIGNAL(timeout()),this,SLOT(triggerRefresh()));
- timer->setSingleShot(true);
- }
- timer->start(5000);
-}
-
-// signals
-/*!
- \fn void ServiceBrowser::serviceChanged(
- Service::ConstPtr oldService, Service::ConstPtr newService, ServiceBrowser *browser)
-
- This signal is called when a service is added, removed, or changed.
- Both oldService or newService might be null (covers both add and remove).
- The services list might not be synchronized with respect to this signal.
-*/
-/*!
- \fn void ServiceBrowser::serviceAdded(Service::ConstPtr service, ServiceBrowser *browser)
-
- This signal is called when a service is added (convenience method).
- The services list might not be synchronized with respect to this signal.
-
- \sa serviceChanged()
-*/
-/*!
- \fn void ServiceBrowser::serviceRemoved(Service::ConstPtr service, ServiceBrowser *browser)
-
- This signal is called when a service is removed (convenience method).
- The services list might not be synchronized with respect to this signal.
-
- \sa serviceChanged()
-*/
-/*!
- \fn void ServiceBrowser::servicesUpdated(ServiceBrowser *browser)
-
- This signal is called when the list is updated.
- It might collect several serviceChanged signals together. If you use the list
- returned by services(), use this signal, not serviceChanged(), serviceAdded(),
- or serviceRemoved() to learn
- about changes to the list.
-*/
-/*!
- \fn void errorMessage(ZeroConf::ErrorMessage::SeverityLevel severity, const QString &msg, ZeroConf::ServiceBrowser *browser)
-
- This signal is called every time a warning or error is emitted (for example when a library
- cannot be used and another one has to be used). Zeroconf will still work if severity < FailureLevel.
-*/
-/*!
- \fn void hadFailure(const QList<ZeroConf::ErrorMessage> &messages, ZeroConf::ServiceBrowser *browser)
-
- This signal is emitted only when a full failure has happened, and all the previous errors/attempts to set up zeroconf
- are passed in messages.
-*/
-/*!
- \fn void startedBrowsing(ZeroConf::ServiceBrowser *browser)
-
- This signal is emitted when browsing has actually started.
- One can rely on either startedBrowsing or hadFailure to be emitted.
-*/
-
-// ----------------- library initialization impl -----------------
-/*!
- Sets the library used by future Service Browsers to preform the mdns queries.
- This changes the default library used by the next MainConnection, it does not change the already
- instantiated connections.
- \a usage can decide which libraries are tried,
- \a libName should be the name (or path) to the libdns library,
- \a daemonPath is the path to the daemon executable which should be started by the embedded library
- if no daemon is found.
-
- \threadsafe
-*/
-void setDefaultZConfLib(LibUsage usage, const QString &avahiLibName, const QString &version,
- const QString &dnsSdLibName,const QString &dnsSdDaemonPath)
-{
- zeroConfLibInstance()->setDefaultLib(usage, avahiLibName, version, dnsSdLibName, dnsSdDaemonPath);
-}
-
-namespace Internal {
-// ----------------- dns-sd 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_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() != QString::fromLocal8Bit(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 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_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 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_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 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_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, ZK_PROTO_IPv4_OR_IPv6,
- errorCode, serviceName, regtype, replyDomain);
-}
-
-// ----------------- ConnectionThread impl -----------------
-
-void ConnectionThread::run()
-{
-#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
- struct sigaction act;
- // ignore SIGPIPE
- act.sa_handler=SIG_IGN;
- sigemptyset(&act.sa_mask);
- act.sa_flags=0;
- sigaction(SIGPIPE, &act, NULL);
-#endif
- connection.handleEvents();
-}
-
-ConnectionThread::ConnectionThread(MainConnection &mc, QObject *parent):
- QThread(parent), connection(mc)
-{ }
-
-// ----------------- ServiceGatherer impl -----------------
-
-ZConfLib::Ptr ServiceGatherer::lib()
-{
- return serviceBrowser->mainConnection->lib;
-}
-
-QString ServiceGatherer::fullName(){
- return currentService->fullName();
-}
-
-bool ServiceGatherer::enactServiceChange()
-{
- if (DEBUG_ZEROCONF)
- qDebug() << "ServiceGatherer::enactServiceChange() for service "
- << currentService->fullName();
- if (currentServiceCanBePublished()) {
- if ((publishedService.data() == 0 && currentService == 0)
- || (publishedService.data() != 0 && currentService != 0
- && *publishedService == *currentService))
- return false;
- Service::Ptr nService = Service::Ptr(currentService);
- if (publishedService) {
- publishedService->invalidate();
- serviceBrowser->nextActiveServices.removeOne(publishedService);
- serviceBrowser->serviceRemoved(publishedService, serviceBrowser->q);
- }
- serviceBrowser->serviceChanged(publishedService, nService, serviceBrowser->q);
- publishedService = nService;
- if (nService) {
- serviceBrowser->nextActiveServices.append(nService);
- serviceBrowser->serviceAdded(nService, serviceBrowser->q);
- currentService = new Service(*currentService);
- }
- return true;
- }
- return false;
-}
-
-void ServiceGatherer::retireService()
-{
- if (publishedService) {
- if (DEBUG_ZEROCONF)
- qDebug() << "ServiceGatherer::retireService() for service "
- << currentService->fullName();
- Service::Ptr nService;
- serviceBrowser->nextActiveServices.removeOne(publishedService);
- publishedService->invalidate();
- serviceBrowser->serviceRemoved(publishedService, serviceBrowser->q);
- serviceBrowser->serviceChanged(publishedService, nService, serviceBrowser->q);
- publishedService = nService;
- } else if (DEBUG_ZEROCONF){
- qDebug() << "ServiceGatherer::retireService() for non published service "
- << currentService->fullName();
- }
-}
-
-void ServiceGatherer::stopResolve(ZK_IP_Protocol protocol)
-{
- if ((protocol == ZK_PROTO_IPv4_OR_IPv6 || protocol == ZK_PROTO_IPv4)
- && (status & ResolveConnectionActive) != 0) {
- QMutexLocker l(serviceBrowser->mainConnection->lock());
- if (serviceBrowser->mainConnection->status() < MainConnection::Stopping)
- lib()->refDeallocate(resolveConnection);
- status &= ~ResolveConnectionActive;
- serviceBrowser->updateFlowStatusForCancel();
- }
- if ((protocol == ZK_PROTO_IPv4_OR_IPv6 || protocol == ZK_PROTO_IPv6)
- && (status & ResolveConnectionV6Active) != 0) {
- QMutexLocker l(serviceBrowser->mainConnection->lock());
- if (serviceBrowser->mainConnection->status() < MainConnection::Stopping)
- lib()->refDeallocate(resolveConnectionV6);
- status &= ~ResolveConnectionV6Active;
- serviceBrowser->updateFlowStatusForCancel();
- }
-}
-
-void ServiceGatherer::restartResolve(ZK_IP_Protocol protocol)
-{
- stopResolve(protocol);
- if (protocol == ZK_PROTO_IPv6) {
- if (currentService->host()) {
- QList<QHostAddress> addrNow = currentService->host()->addresses();
- QMutableListIterator<QHostAddress> addr(addrNow);
- bool changed = false;
- while (addr.hasNext()) {
- if (addr.next().protocol() == QAbstractSocket::IPv6Protocol) {
- addr.remove();
- changed = true;
- }
- }
- if (changed)
- currentService->m_host->setAddresses(addrNow);
- }
- DNSServiceErrorType err = lib()->resolve(
- serviceBrowser->mainRef(),
- &resolveConnectionV6,
- currentService->interfaceNr(), protocol,
- currentService->name().toUtf8().constData(),
- currentService->type().toUtf8().constData(),
- currentService->domain().toUtf8().constData(), this);
- if (err != kDNSServiceErr_NoError) {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed IPv6 discovery of service " << currentService->fullName()
- << " due to error " << err;
- status = status | ResolveConnectionV6Failed;
- } else {
- status = ((status & ~ResolveConnectionV6Failed) | ResolveConnectionV6Active);
- }
- } else {
- if (currentService->host()) {
- if (protocol == ZK_PROTO_IPv4_OR_IPv6) {
- currentService->m_host->setAddresses(QList<QHostAddress>());
- } else {
- QList<QHostAddress> addrNow = currentService->host()->addresses();
- QMutableListIterator<QHostAddress> addr(addrNow);
- bool changed = false;
- while (addr.hasNext()) {
- if (addr.next().protocol() == QAbstractSocket::IPv4Protocol) {
- addr.remove();
- changed = true;
- }
- }
- if (changed)
- currentService->m_host->setAddresses(addrNow);
- }
- }
- DNSServiceErrorType err = lib()->resolve(
- serviceBrowser->mainRef(),
- &resolveConnection,
- currentService->interfaceNr(), protocol,
- 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 " << currentService->fullName()
- << " due to error " << err;
- status = status | ResolveConnectionFailed;
- } else {
- status = ((status & ~ResolveConnectionFailed) | ResolveConnectionActive);
- }
- }
-}
-
-void ServiceGatherer::stopTxt()
-{
- if ((status & TxtConnectionActive) == 0) return;
- QMutexLocker l(serviceBrowser->mainConnection->lock());
- if (serviceBrowser->mainConnection->status() < MainConnection::Stopping)
- lib()->refDeallocate(txtConnection);
- status &= ~TxtConnectionActive;
- serviceBrowser->updateFlowStatusForCancel();
-}
-
-void ServiceGatherer::restartTxt()
-{
- stopTxt();
- 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 " << currentService->fullName()
- << " due to error " << err;
- status = status | TxtConnectionFailed;
- } else {
- status = ((status & ~TxtConnectionFailed) | TxtConnectionActive);
- }
-}
-
-void ServiceGatherer::stopHostResolution()
-{
- if ((status & AddrConnectionActive) == 0) return;
- QMutexLocker l(serviceBrowser->mainConnection->lock());
- if (serviceBrowser->mainConnection->status() < MainConnection::Stopping)
- lib()->refDeallocate(addrConnection);
- status &= ~AddrConnectionActive;
- serviceBrowser->updateFlowStatusForCancel();
-}
-
-void ServiceGatherer::restartHostResolution()
-{
- stopHostResolution();
- 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 "
- << currentService->fullName();
- }
- 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 "
- << currentService->fullName() << " due to error " << err;
- status = status | AddrConnectionFailed;
- } else {
- status = ((status & ~AddrConnectionFailed) | AddrConnectionActive);
- }
-}
-
-/// if the current service can be added
-bool ServiceGatherer::currentServiceCanBePublished()
-{
- return (currentService->host() && !currentService->host()->addresses().isEmpty())
- || !serviceBrowser->requireAddresses;
-}
-
-ServiceGatherer::ServiceGatherer(const QString &newServiceName, const QString &newType,
- const QString &newDomain, const QString &fullName,
- uint32_t interfaceIndex, ZK_IP_Protocol protocol,
- ServiceBrowserPrivate *serviceBrowser):
- serviceBrowser(serviceBrowser), publishedService(0), currentService(new Service()), status(0)
-{
- 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())
- currentService->m_fullName = toFullNameC(currentService->name().toUtf8().data(),
- currentService->type().toUtf8().data(),
- currentService->domain().toUtf8().data());
- restartResolve(protocol);
- restartTxt();
-}
-
-ServiceGatherer::~ServiceGatherer()
-{
- stopHostResolution();
- stopResolve();
- stopTxt();
- delete currentService;
-}
-
-ServiceGatherer::Ptr ServiceGatherer::createGatherer(
- const QString &newServiceName, const QString &newType, const QString &newDomain,
- const QString &fullName, uint32_t interfaceIndex, ZK_IP_Protocol protocol,
- ServiceBrowserPrivate *serviceBrowser)
-{
- Ptr res(new ServiceGatherer(newServiceName, newType, newDomain, fullName, interfaceIndex,
- protocol, serviceBrowser));
- res->self = res.toWeakRef();
- return res;
-}
-
-ServiceGatherer::Ptr ServiceGatherer::gatherer() {
- return self.toStrongRef();
-}
-
-void ServiceGatherer::serviceResolveReply(DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *hosttarget,
- const QString &port,
- uint16_t txtLen,
- const unsigned char *rawTxtRecord)
-{
- if (errorCode != kDNSServiceErr_NoError){
- if (errorCode == kDNSServiceErr_Timeout){
- if ((status & ResolveConnectionSuccess) == 0){
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed service resolution for service "
- << currentService->fullName() << " as it did timeout";
- status |= ResolveConnectionFailed;
- }
- } else {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed service resolution for service " << currentService->fullName()
- << " with error " << errorCode;
- status |= ResolveConnectionFailed;
- }
- if (status & ResolveConnectionActive) {
- status &= ~ResolveConnectionActive;
- lib()->refDeallocate(resolveConnection);
- serviceBrowser->updateFlowStatusForCancel();
- }
- return;
- }
- serviceBrowser->updateFlowStatusForFlags(flags);
- 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 = 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 " << currentService->fullName();
- break;
- }
- keyBuf[maxTxtLen-1] = 0; // just to be sure
- currentService->m_txtRecord.insert(QString::fromUtf8(keyBuf),
- QString::fromUtf8(valueCStr, valLen));
- }
- currentService->m_interfaceNr = interfaceIndex;
- currentService->m_port = port;
- if (hostName != QString::fromUtf8(hosttarget)) {
- hostName = QString::fromUtf8(hosttarget);
- if (!currentService->host())
- currentService->m_host = new QHostInfo();
- else
- currentService->m_host->setAddresses(QList<QHostAddress>());
- currentService->m_host->setHostName(hostName);
- if (serviceBrowser->autoResolveAddresses)
- restartHostResolution();
- }
- if (currentServiceCanBePublished())
- serviceBrowser->pendingGathererAdd(gatherer());
-}
-
-void ServiceGatherer::txtRecordReply(DNSServiceFlags flags,
- DNSServiceErrorType errorCode,
- uint16_t txtLen,
- const void *rawTxtRecord,
- uint32_t /*ttl*/)
-{
- if (errorCode != kDNSServiceErr_NoError){
- if (errorCode == kDNSServiceErr_Timeout){
- if ((status & TxtConnectionSuccess) == 0){
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed txt gathering for service " << currentService->fullName()
- << " as it did timeout";
- status |= TxtConnectionFailed;
- }
- } else {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed txt gathering for service " << currentService->fullName()
- << " with error " << errorCode;
- status |= TxtConnectionFailed;
- }
- if (status & TxtConnectionActive) {
- status &= ~TxtConnectionActive;
- lib()->refDeallocate(txtConnection);
- serviceBrowser->updateFlowStatusForCancel();
- }
- return;
- }
- serviceBrowser->updateFlowStatusForFlags(flags);
-
- 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 = 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 " << currentService->fullName();
- if ((flags & kDNSServiceFlagsAdd) == 0)
- currentService->m_txtRecord.clear();
- break;
- }
- keyBuf[255] = 0; // just to be sure
- if (flags & kDNSServiceFlagsAdd) {
- currentService->m_txtRecord.insert(QString::fromUtf8(keyBuf),
- QString::fromUtf8(valueCStr, valLen));
- } else {
- currentService->m_txtRecord.remove(QString::fromUtf8(keyBuf)); // check value???
- }
- }
- if ((flags & kDNSServiceFlagsAdd) != 0)
- status |= TxtConnectionSuccess;
- if (currentService->m_txtRecord.count() != 0 && currentServiceCanBePublished())
- serviceBrowser->pendingGathererAdd(gatherer());
-}
-
-void ServiceGatherer::txtFieldReply(DNSServiceFlags flags,
- DNSServiceErrorType errorCode,
- uint16_t txtLen,
- const void *rawTxtRecord,
- uint32_t /*ttl*/){
- if (errorCode != kDNSServiceErr_NoError){
- if (errorCode == kDNSServiceErr_Timeout){
- if ((status & TxtConnectionSuccess) == 0){
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed txt gathering for service " << currentService->fullName()
- << " as it did timeout";
- status |= TxtConnectionFailed;
- }
- } else {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed txt gathering for service " << currentService->fullName()
- << " with error " << errorCode;
- status |= TxtConnectionFailed;
- }
- if (status & TxtConnectionActive) {
- status &= ~TxtConnectionActive;
- lib()->refDeallocate(txtConnection);
- serviceBrowser->updateFlowStatusForCancel();
- }
- return;
- }
- serviceBrowser->updateFlowStatusForFlags(flags);
- uint16_t keyLen = 0;
- const char *txt = reinterpret_cast<const char *>(rawTxtRecord);
- while (keyLen < txtLen) {
- if (txt[keyLen]=='=')
- break;
- ++keyLen;
- }
- if (flags & kDNSServiceFlagsAdd) {
- currentService->m_txtRecord.insert(
- QString::fromUtf8(txt, keyLen),
- QString::fromUtf8(txt + keyLen + 1, ((txtLen > keyLen)?txtLen - keyLen - 1:0)));
- } else {
- currentService->m_txtRecord.remove(QString::fromUtf8(txt, keyLen)); // check value???
- }
-
-}
-
-void ServiceGatherer::addrReply(DNSServiceFlags flags,
- DNSServiceErrorType errorCode,
- const char *hostname,
- const struct sockaddr *address,
- uint32_t /*ttl*/) // should we use this???
-{
- if (errorCode != kDNSServiceErr_NoError) {
- if (errorCode == kDNSServiceErr_Timeout){
- if ((status & AddrConnectionSuccess) == 0){
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed address resolve for service " << currentService->fullName()
- << " as it did timeout";
- status |= AddrConnectionFailed;
- }
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType
- << " failed addr resolve for service " << currentService->fullName()
- << " with error " << errorCode;
- status |= AddrConnectionFailed;
- }
- if (status & AddrConnectionActive){
- status &= ~AddrConnectionActive;
- lib()->refDeallocate(addrConnection);
- serviceBrowser->updateFlowStatusForCancel();
- }
- return;
- }
- serviceBrowser->updateFlowStatusForFlags(flags);
- if (!currentService->host())
- currentService->m_host = new QHostInfo();
- if (currentService->host()->hostName() != QString::fromUtf8(hostname)) {
- if ((flags & kDNSServiceFlagsAdd) == 1)
- currentService->m_host->setHostName(QString::fromUtf8(hostname));
- if (currentService->host()->addresses().isEmpty()) {
- qDebug() << "ServiceBrowser " << serviceBrowser->serviceType << " for service "
- << 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 "
- << currentService->fullName() << " ignoring remove for " << hostname
- << " as current hostname is " << currentService->host()->hostName();
- return;
- }
- }
- QHostAddress newAddr(address);
- QList<QHostAddress> addrNow = currentService->host()->addresses();
- if ((flags & kDNSServiceFlagsAdd) == 0) {
- if (addrNow.removeOne(newAddr))
- currentService->m_host->setAddresses(addrNow);
- } else {
- if (!addrNow.contains(newAddr)){
- switch (newAddr.protocol()){
-#ifdef Q_OS_WIN
- case QAbstractSocket::IPv4Protocol: // prefers IPv4 addresses
-#else
- case QAbstractSocket::IPv6Protocol: // prefers IPv6 addresses
-#endif
- addrNow.insert(0, newAddr);
- break;
- default:
- addrNow.append(newAddr);
- break;
- }
- currentService->m_host->setAddresses(addrNow);
- }
- }
- serviceBrowser->pendingGathererAdd(gatherer());
-}
-
-void ServiceGatherer::maybeRemove()
-{
- // could trigger an update, but for now we just ignore it (less chatty)
-}
-
-void ServiceGatherer::stop(ZK_IP_Protocol protocol)
-{
- if ((protocol == ZK_PROTO_IPv4_OR_IPv6 || protocol == ZK_PROTO_IPv4)
- && (status & ResolveConnectionActive) != 0){
- status &= ~ResolveConnectionActive;
- lib()->refDeallocate(resolveConnection);
- serviceBrowser->updateFlowStatusForCancel();
- }
- if ((protocol == ZK_PROTO_IPv4_OR_IPv6 || protocol == ZK_PROTO_IPv6)
- && (status & ResolveConnectionV6Active) != 0){
- status &= ~ResolveConnectionV6Active;
- lib()->refDeallocate(resolveConnectionV6);
- serviceBrowser->updateFlowStatusForCancel();
- }
- if (status & TxtConnectionActive){
- status &= ~TxtConnectionActive;
- lib()->refDeallocate(txtConnection);
- serviceBrowser->updateFlowStatusForCancel();
- }
- if (status & AddrConnectionActive) {
- status &= ~AddrConnectionActive;
- lib()->refDeallocate(addrConnection);
- serviceBrowser->updateFlowStatusForCancel();
- }
-}
-
-void ServiceGatherer::reload(qint32 interfaceIndex, ZK_IP_Protocol protocol)
-{
- this->interfaceIndex = interfaceIndex;
- stop(protocol);
- restartResolve(protocol);
- restartTxt();
- if (currentServiceCanBePublished()) // avoid???
- restartHostResolution();
-}
-
-void ServiceGatherer::remove()
-{
- stop();
- 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()
-{
- stop();
- /* DNSServiceErrorType err = DNSServiceReconfirmRecord(kDNSServiceFlagsShareConnection,
- interfaceIndex, fullName.toUtf8().constData(),
- kDNSServiceType_PTR, // kDNSServiceType_SRV could be another possibility
- kDNSServiceClass_IN //,
- // uint16_t rdlen, // not cached... what is the best solution???
- // const void *rdata
- ); */
-}
-
-// ----------------- ServiceBrowserPrivate impl -----------------
-
-ZConfLib::ConnectionRef ServiceBrowserPrivate::mainRef()
-{
- return mainConnection->mainRef();
-}
-
-void ServiceBrowserPrivate::updateFlowStatusForCancel()
-{
- mainConnection->updateFlowStatusForCancel();
-}
-
-void ServiceBrowserPrivate::updateFlowStatusForFlags(DNSServiceFlags flags)
-{
- mainConnection->updateFlowStatusForFlags(flags);
-}
-
-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 != gatherer){
- gatherer->publishedService = g->publishedService;
- pendingGatherers[i] = gatherer;
- }
- return;
- }
- }
- pendingGatherers.append(gatherer);
-}
-
-ServiceBrowserPrivate::ServiceBrowserPrivate(const QString &serviceType, const QString &domain,
- bool requireAddresses, MainConnectionPtr mconn):
- q(0), serviceType(serviceType), domain(domain), mainConnection(mconn), serviceConnection(0), flags(0), interfaceIndex(0),
- delayDeletesUntil(std::numeric_limits<qint64>::min()), failed(false), browsing(false),
- autoResolveAddresses(requireAddresses), requireAddresses(requireAddresses), shouldRefresh(false)
-{
-}
-
-ServiceBrowserPrivate::~ServiceBrowserPrivate()
-{
- if (DEBUG_ZEROCONF)
- qDebug() << "destroying ServiceBrowserPrivate " << serviceType;
- if (browsing)
- stopBrowsing();
- if (mainConnection)
- mainConnection->removeBrowser(this);
-}
-
-void ServiceBrowserPrivate::insertGatherer(const QString &fullName)
-{
- if (!gatherers.contains(fullName)){
- QString newServiceName, newType, newDomain;
- if (fromFullNameC(fullName.toUtf8().data(), *&newServiceName, *&newType, *&newDomain)){
- qDebug() << "Error unescaping fullname " << fullName;
- } else {
- ServiceGatherer::Ptr serviceGatherer = ServiceGatherer::createGatherer(
- newServiceName, newType, newDomain, fullName, 0, ZK_PROTO_IPv4_OR_IPv6, this);
- gatherers[fullName] = serviceGatherer;
- }
- }
-}
-
-void ServiceBrowserPrivate::maybeUpdateLists()
-{
- if (mainConnection->flowStatus != MainConnection::MoreComingRFS
- || pendingGatherers.count() > 50 || shouldRefresh)
- {
- qint64 now = QDateTime::currentMSecsSinceEpoch();
- QList<QString>::iterator i = knownServices.begin(), endi = knownServices.end();
- QMap<QString, ServiceGatherer::Ptr>::iterator j = gatherers.begin();
- bool hasServicesChanges = false;
- while (i != endi && j != gatherers.end()) {
- const QString vi = *i;
- QString vj = j.value()->fullName();
- if (vi == vj){
- ++i;
- ++j;
- } else if (vi < vj) {
- qDebug() << "ServiceBrowser " << serviceType << ", missing gatherer for " << vi;
- insertGatherer(vi);
- ++i;
- } else if (delayDeletesUntil <= now) {
- pendingGatherers.removeAll(j.value());
- j.value()->retireService();
- j = gatherers.erase(j);
- hasServicesChanges = true;
- } else {
- ++j;
- }
- }
- while (i != endi) {
- qDebug() << "ServiceBrowser " << serviceType << ", missing gatherer for " << *i;
- insertGatherer(*i);
- }
- while (j != gatherers.end()) {
- if (delayDeletesUntil <= now) {
- pendingGatherers.removeAll(j.value());
- j.value()->retireService();
- j = gatherers.erase(j);
- hasServicesChanges = true;
- } else {
- ++j;
- }
- }
- foreach (const ServiceGatherer::Ptr &g, pendingGatherers)
- if (delayDeletesUntil <= now || ! g->publishedService)
- hasServicesChanges = g->enactServiceChange() || hasServicesChanges;
- if (hasServicesChanges) {
- {
- QMutexLocker l(mainConnection->lock());
- activeServices = nextActiveServices;
- }
- emit q->servicesUpdated(q);
- }
- }
- {
- QMutexLocker l(mainConnection->lock());
- if (shouldRefresh)
- refresh();
- }
-}
-
-/// callback announcing
-void ServiceBrowserPrivate::browseReply(DNSServiceFlags flags,
- uint32_t interfaceIndex,
- ZK_IP_Protocol protocol,
- DNSServiceErrorType errorCode,
- const char *serviceName,
- const char *regtype,
- const char *replyDomain)
-{
- if (DEBUG_ZEROCONF)
- qDebug() << "browseReply(" << ((int)flags) << ", " << interfaceIndex << ", "
- << ((int)errorCode) << ", " << serviceName << ", " << regtype << ", "
- << replyDomain << ")";
- if (errorCode != kDNSServiceErr_NoError){
- qDebug() << "ServiceBrowser " << serviceType << " ignoring reply due to error " << errorCode;
- return;
- }
- QString newServiceName = QString::fromUtf8(serviceName);
- QString newType = serviceType;
- QString newDomain = domain;
- if (serviceType != QString::fromUtf8(regtype)) // discard? should not happen...
- newType = QString::fromUtf8(regtype);
- if (domain != QString::fromUtf8(replyDomain))
- domain = QString::fromUtf8(replyDomain);
- QString fullName = toFullNameC(serviceName, regtype, replyDomain);
- updateFlowStatusForFlags(flags);
- if (flags & kDNSServiceFlagsAdd){
- ServiceGatherer::Ptr serviceGatherer;
- if (!gatherers.contains(fullName)){
- serviceGatherer = ServiceGatherer::createGatherer(newServiceName, newType, newDomain,
- fullName, interfaceIndex, protocol,
- this);
- gatherers[fullName] = serviceGatherer;
- } else {
- serviceGatherer = gatherers[fullName];
- serviceGatherer->reload(interfaceIndex, protocol);
- }
- QList<QString>::iterator pos = std::lower_bound(knownServices.begin(), knownServices.end(),
- fullName);
- // could order later (more efficient, but then we have to handle eventual duplicates)
- if (pos == knownServices.end() || *pos != fullName)
- knownServices.insert(pos, fullName);
- } else {
- if (gatherers.contains(fullName))
- gatherers[fullName]->maybeRemove();
- knownServices.removeOne(fullName);
- }
- maybeUpdateLists(); // avoid?
-}
-
-void ServiceBrowserPrivate::activateAutoRefresh()
-{
- emit q->activateAutoRefresh();
-}
-
-void ServiceBrowserPrivate::startBrowsing(quint32 interfaceIndex)
-{
- this->interfaceIndex = interfaceIndex;
- if (failed || browsing)
- return;
- if (mainConnection.isNull()) {
- startupPhase(1, ServiceBrowser::tr("Starting Zeroconf Browsing"));
- mainConnection = MainConnectionPtr(new MainConnection(this));
- } else {
- mainConnection->addBrowser(this);
- }
-}
-
-bool ServiceBrowserPrivate::internalStartBrowsing()
-{
- mainConnection->updateFlowStatusForFlags(0);
- if (failed || browsing)
- return false;
- DNSServiceErrorType err;
- 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_ZEROCONF)
- qDebug() << "startBrowsing(" << interfaceIndex << ") for serviceType:" << serviceType
- << " domain:" << domain;
- return true;
-}
-
-void ServiceBrowserPrivate::triggerRefresh()
-{
- {
- QMutexLocker l(mainConnection->lock());
- const qint64 msecDelay = 5100;
- delayDeletesUntil = QDateTime::currentMSecsSinceEpoch() + msecDelay;
- stopBrowsing();
- shouldRefresh = true;
- }
- {
- QMutexLocker l(mainConnection->mainThreadLock());
- if (!browsing)
- refresh();
- }
-}
-
-void ServiceBrowserPrivate::refresh()
-{
- const qint64 msecDelay = 500;
- delayDeletesUntil = QDateTime::currentMSecsSinceEpoch() + msecDelay;
- shouldRefresh = false;
- internalStartBrowsing();
-}
-
-
-void ServiceBrowserPrivate::stopBrowsing()
-{
- QMutexLocker l(mainConnection->lock());
- if (browsing){
- if (serviceConnection) {
- mainConnection->lib->browserDeallocate(&serviceConnection);
- updateFlowStatusForCancel();
- serviceConnection = 0;
- }
- knownServices.clear();
- browsing = false;
- }
-}
-
-void ServiceBrowserPrivate::reconfirmService(Service::ConstPtr s)
-{
- 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)
-void ServiceBrowserPrivate::serviceChanged(const Service::ConstPtr &oldService,
- const Service::ConstPtr &newService,
- ServiceBrowser *browser)
-{
- emit q->serviceChanged(oldService, newService, browser);
-}
-
-/// called when a service is added (utility method)
-void ServiceBrowserPrivate::serviceAdded(const Service::ConstPtr &service, ServiceBrowser *browser)
-{
- emit q->serviceAdded(service, browser);
-}
-
-/// called when a service is removed (utility method)
-void ServiceBrowserPrivate::serviceRemoved(const Service::ConstPtr &service, ServiceBrowser *browser)
-{
- emit q->serviceRemoved(service, browser);
-}
-
-/// called when the list is updated (this might collect several serviceChanged signals together)
-void ServiceBrowserPrivate::servicesUpdated(ServiceBrowser *browser)
-{
- emit q->servicesUpdated(browser);
-}
-
-/// called to describe the current startup phase
-void ServiceBrowserPrivate::startupPhase(int progress, const QString &description)
-{
- emit q->startupPhase(progress, description, q);
-}
-
-
-/// called when there is an error message
-void ServiceBrowserPrivate::errorMessage(ErrorMessage::SeverityLevel severity, const QString &msg)
-{
- if (severity == ErrorMessage::FailureLevel)
- this->failed = true;
- emit q->errorMessage(severity, msg, q);
-}
-
-/// called when the browsing fails
-void ServiceBrowserPrivate::hadFailure(const QList<ErrorMessage> &messages)
-{
- emit q->hadFailure(messages, q);
-}
-
-void ServiceBrowserPrivate::startedBrowsing()
-{
- emit q->startedBrowsing(q);
-}
-
-// ----------------- MainConnection impl -----------------
-
-void MainConnection::stop(bool wait)
-{
- {
- if (QThread::currentThread() == m_thread)
- qCritical() << "ERROR ZerocConf::MainConnection::stop called from m_thread";
- // This will most likely lock if called from the connection thread (as mainThreadLock is non recusive)
- // Making it recursive would open a hole during the startup of the thread.
- // As of now this should always be called during the destruction of a browser,
- // so from another thread.
- increaseStatusTo(Stopping);
- QMutexLocker l(mainThreadLock());
- QMutexLocker l2(lock());
- }
- if (m_mainRef) {
- lib->stopConnection(m_mainRef);
- m_mainRef = 0;
- }
- if (!m_thread)
- increaseStatusTo(Stopped);
- else if (wait && QThread::currentThread() != m_thread)
- m_thread->wait();
-}
-
-MainConnection::MainConnection(ServiceBrowserPrivate *initialBrowser):
- flowStatus(NormalRFS),
- lib(zeroConfLibInstance()->defaultLib()), m_lock(QMutex::Recursive),
- m_mainThreadLock(QMutex::NonRecursive), m_mainRef(0), m_failed(false), m_status(Starting), m_nErrs(0)
-{
- if (initialBrowser)
- addBrowser(initialBrowser);
- if (lib.isNull()){
- appendError(ErrorMessage::FailureLevel, tr("Zeroconf could not load a valid library, failing."));
- } else {
- m_thread = new ConnectionThread(*this);
- m_mainThreadLock.lock();
- m_thread->start(); // delay startup??
- }
-}
-
-MainConnection::~MainConnection()
-{
- gQuickStop = 1;
- stop(true);
- gQuickStop = 0;
- delete m_thread;
-}
-
-bool MainConnection::increaseStatusTo(int s)
-{
- int sAtt = status();
- while (sAtt < s){
- if (m_status.testAndSetRelaxed(sAtt, s))
- return true;
- sAtt = status();
- }
- return false;
-}
-
-QMutex *MainConnection::lock()
-{
- return &m_lock;
-}
-
-QMutex *MainConnection::mainThreadLock()
-{
- return &m_mainThreadLock;
-}
-
-void MainConnection::waitStartup()
-{
- int sAtt;
- while (true){
- {
- QMutexLocker l(lock());
- sAtt = status();
- if (sAtt >= Running)
- return;
- }
- QThread::yieldCurrentThread();
- }
-}
-
-void MainConnection::addBrowser(ServiceBrowserPrivate *browser)
-{
- int actualStatus;
- QList<ErrorMessage> errs;
- {
- QMutexLocker l(lock());
- actualStatus = status();
- m_browsers.append(browser);
- errs = m_errors;
- }
- if (actualStatus == Running && browser->internalStartBrowsing())
- browser->startedBrowsing();
- bool didFail = false;
- foreach (const ErrorMessage &msg, errs) {
- browser->errorMessage(msg.severity, msg.msg);
- didFail = didFail || msg.severity == ErrorMessage::FailureLevel;
- }
- if (didFail)
- browser->hadFailure(errs);
-}
-
-void MainConnection::removeBrowser(ServiceBrowserPrivate *browser)
-{
- QMutexLocker l(lock());
- m_browsers.removeOne(browser);
-}
-
-void MainConnection::updateFlowStatusForCancel(){
- flowStatus = ForceUpdateRFS;
-}
-void MainConnection::updateFlowStatusForFlags(DNSServiceFlags flags)
-{
- if (flags & kDNSServiceFlagsMoreComing) {
- if (flowStatus == NormalRFS)
- flowStatus = MoreComingRFS;
- } else {
- flowStatus = NormalRFS;
- }
-}
-void MainConnection::maybeUpdateLists()
-{
- foreach (ServiceBrowserPrivate *sb, m_browsers) {
- sb->maybeUpdateLists();
- }
-}
-
-void MainConnection::gotoValidLib(){
- while (lib){
- if (lib->isOk()) break;
- appendError(ErrorMessage::WarningLevel, tr("Zeroconf giving up on non working %1 (%2).")
- .arg(lib->name()).arg(lib->errorMsg()));
- lib = lib->fallbackLib;
- }
- if (!lib) {
- appendError(ErrorMessage::FailureLevel, tr("Zeroconf has no valid library, aborting connection."));
- increaseStatusTo(Stopping);
- }
-}
-
-void MainConnection::abortLib(){
- if (!lib){
- appendError(ErrorMessage::FailureLevel, tr("Zeroconf has no valid library, aborting connection."));
- increaseStatusTo(Stopping);
- } else if (lib->fallbackLib){
- appendError(ErrorMessage::WarningLevel, tr("Zeroconf giving up on %1, switching to %2.")
- .arg(lib->name()).arg(lib->fallbackLib->name()));
- lib = lib->fallbackLib;
- m_nErrs = 0;
- gotoValidLib();
- } else {
- appendError(ErrorMessage::FailureLevel, tr("Zeroconf giving up on %1, no fallback provided, aborting connection.")
- .arg(lib->name()));
- increaseStatusTo(Stopping);
- }
-}
-
-void MainConnection::createConnection()
-{
- gotoValidLib();
- while (status() <= Running) {
- if (!lib) {
- increaseStatusTo(Stopped);
- break;
- }
- startupPhase(m_nErrs + zeroConfLibInstance()->nFallbacksTot() - lib->nFallbacks() + 2,
- tr("Trying %1...").arg(lib->name()));
- uint32_t version;
- uint32_t size = (uint32_t)sizeof(uint32_t);
- DNSServiceErrorType err = lib->getProperty(kDNSServiceProperty_DaemonVersion, &version, &size);
- if (err == kDNSServiceErr_NoError){
- DNSServiceErrorType error = lib->createConnection(this, &m_mainRef);
- if (error != kDNSServiceErr_NoError){
- appendError(ErrorMessage::WarningLevel, tr("Zeroconf using %1 failed the initialization of the main library connection with error %2.")
- .arg(lib->name()).arg(error));
- ++m_nErrs;
- if (m_nErrs > lib->nFallbacks() || !lib->isOk())
- abortLib();
- } else {
- QList<ServiceBrowserPrivate *> waitingBrowsers;
- {
- QMutexLocker l(lock());
- waitingBrowsers = m_browsers;
- increaseStatusTo(Running);
- }
- for (int i = waitingBrowsers.count(); i-- != 0; ){
- ServiceBrowserPrivate *actualBrowser = waitingBrowsers[i];
- if (actualBrowser && !actualBrowser->browsing
- && actualBrowser->internalStartBrowsing())
- actualBrowser->startedBrowsing();
- }
- break;
- }
- } else if (err == kDNSServiceErr_ServiceNotRunning) {
- appendError(ErrorMessage::WarningLevel, tr("Zeroconf using %1 failed because no daemon is running.")
- .arg(lib->name()));
- ++m_nErrs;
- if (m_nErrs > lib->maxErrors() || !lib->isOk()) {
- abortLib();
- } else if (lib->tryStartDaemon(this)) {
- appendError(ErrorMessage::WarningLevel, tr("Starting the Zeroconf daemon using %1 seems successful, continuing.")
- .arg(lib->name()));
- } else {
- appendError(ErrorMessage::WarningLevel, tr("Zeroconf using %1 failed because no daemon is running.")
- .arg(lib->name()));
- abortLib();
- }
- } else {
- appendError(ErrorMessage::WarningLevel, tr("Zeroconf using %1 failed getProperty call with error %2.")
- .arg(lib->name()).arg(err));
- abortLib();
- }
- }
- if (status() < Stopping) {
- startupPhase(zeroConfLibInstance()->nFallbacksTot() + 3, tr("Succeeded using %1.").arg(lib->name()));
- appendError(ErrorMessage::NoteLevel,
- tr("MainConnection could successfully create a connection using %1.")
- .arg(lib->name()));
- }
-}
-
-ZConfLib::RunLoopStatus MainConnection::handleEvent()
-{
- qint64 now = QDateTime::currentMSecsSinceEpoch();
- qint64 nextEvent = now; // worth keeping a heap to quickly calculate this?
- foreach (ServiceBrowserPrivate *bAtt, m_browsers) {
- if (nextEvent < bAtt->delayDeletesUntil)
- nextEvent = bAtt->delayDeletesUntil;
- }
- if (nextEvent <= now)
- nextEvent = -1;
- else
- nextEvent -= now;
- maybeUpdateLists();
- ZConfLib::RunLoopStatus err = lib->processOneEvent(this, m_mainRef, nextEvent);
- if (err != ZConfLib::ProcessedOk && err != ZConfLib::ProcessedIdle) {
- qDebug() << "processOneEvent returned " << err;
- ++m_nErrs;
- } else {
- m_nErrs = 0;
- }
- return err;
-}
-
-void MainConnection::destroyConnection()
-{
- // multithreading issues if we support multiple cycles of createConnection/destroyConnection
- for (int i = m_browsers.count(); i-- != 0;){
- ServiceBrowserPrivate *bAtt = m_browsers[i];
- if (bAtt->browsing)
- bAtt->stopBrowsing();
- }
- if (m_mainRef != 0)
- lib->destroyConnection(&m_mainRef);
- m_mainRef = 0;
-}
-
-void MainConnection::handleEvents()
-{
- try {
- if (!m_status.testAndSetAcquire(Starting, Started)){
- appendError(ErrorMessage::WarningLevel, tr("Zeroconf, unexpected start status, aborting."));
- increaseStatusTo(Stopped);
- return;
- }
- m_nErrs = 0;
- createConnection();
- } catch(...) {
- mainThreadLock()->unlock();
- throw;
- }
- mainThreadLock()->unlock();
- increaseStatusTo(Running);
- while (status() < Stopping) {
- QMutexLocker l(mainThreadLock());
- if (m_nErrs > 10)
- increaseStatusTo(Stopping);
- switch (handleEvent()) {
- case ZConfLib::ProcessedOk :
- case ZConfLib::ProcessedIdle :
- break;
- case ZConfLib::ProcessedError :
- ++m_nErrs;
- break;
- case ZConfLib::ProcessedFailure :
- increaseStatusTo(Stopping);
- ++m_nErrs;
- break;
- case ZConfLib::ProcessedQuit :
- increaseStatusTo(Stopping);
- break;
- default:
- appendError(ErrorMessage::FailureLevel, tr("Zeroconf detected an unexpected return status of handleEvent."));
- increaseStatusTo(Stopping);
- break;
- }
- }
- destroyConnection();
- if (m_nErrs > 0){
- QString browsersNames = (m_browsers.isEmpty() ? QString() : m_browsers.at(0)->serviceType)
- + ((m_browsers.count() > 1) ? QString::fromLatin1(",...") : QString());
- if (isOk())
- appendError(ErrorMessage::FailureLevel,
- tr("Zeroconf for [%1] accumulated %n consecutive errors, aborting.", 0, m_nErrs)
- .arg(browsersNames));
- }
- increaseStatusTo(Stopped);
-}
-
-ZConfLib::ConnectionRef MainConnection::mainRef()
-{
- while (status() < Running){
- QThread::yieldCurrentThread();
- }
- return m_mainRef;
-}
-
-MainConnection::Status MainConnection::status()
-{
- return static_cast<MainConnection::Status>(m_status.load());
-}
-
-QList<ErrorMessage> MainConnection::errors()
-{
- QMutexLocker l(lock());
- return m_errors;
-}
-
-void MainConnection::appendError(ErrorMessage::SeverityLevel severity, const QString &msg)
-{
- QList<ServiceBrowserPrivate *> browsersAtt;
- QList<ErrorMessage> errs;
- {
- QMutexLocker l(lock());
- m_errors.append(ErrorMessage(severity, msg));
- errs = m_errors;
- browsersAtt = m_browsers;
- m_failed = severity == ErrorMessage::FailureLevel || m_failed;
- }
- foreach (ServiceBrowserPrivate *b, browsersAtt) {
- b->errorMessage(severity, msg);
- if (severity == ErrorMessage::FailureLevel)
- b->hadFailure(errs);
- }
-}
-
-void MainConnection::startupPhase(int progress, const QString &description)
-{
- QList<ServiceBrowserPrivate *> browsersAtt;
- {
- QMutexLocker l(lock());
- browsersAtt = m_browsers;
- }
- foreach (ServiceBrowserPrivate *b, browsersAtt)
- b->startupPhase(progress, description);
-}
-
-bool MainConnection::isOk()
-{
- return !m_failed;
-}
-
-// ----------------- ZConfLib impl -----------------
-
-bool ZConfLib::tryStartDaemon(ErrorMessage::ErrorLogger * /* logger */)
-{
- return false;
-}
-
-QString ZConfLib::name(){
- return QString::fromLatin1("ZeroConfLib@%1").arg(size_t(this), 0, 16);
-}
-
-ZConfLib::ZConfLib(ZConfLib::Ptr f) : fallbackLib(f), m_isOk(true), m_maxErrors(4)
-{ }
-
-ZConfLib::~ZConfLib()
-{ }
-
-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;
-}
-
-int ZConfLib::maxErrors() const
-{
- return m_maxErrors;
-}
-
-int ZConfLib::nFallbacks() const
-{
- return (m_isOk ? ((m_maxErrors > 0) ? m_maxErrors : 1) : 0)
- + (fallbackLib ? fallbackLib->nFallbacks() : 0);
-}
-
-ZConfLib::RunLoopStatus ZConfLib::processOneEvent(MainConnection *mainConnection,
- ConnectionRef cRef, qint64 maxMsBlock)
-{
- if (maxMsBlock < 0) { // just block
- maxMsBlock = MAX_SEC_FOR_READ * static_cast<qint64>(1000);
- }
- // some stuff could be extracted for maximal performance
- int dns_sd_fd = (cRef ? refSockFD(cRef) : -1);
- int nfds = dns_sd_fd + 1;
- fd_set readfds;
- struct timeval tv;
- int result;
- dns_sd_fd = (cRef ? refSockFD(cRef) : -1);
- if (dns_sd_fd < 0)
- return ProcessedError;
- nfds = dns_sd_fd + 1;
- FD_ZERO(&readfds);
- FD_SET(dns_sd_fd, &readfds);
-
- if (maxMsBlock > MAX_SEC_FOR_READ * static_cast<qint64>(1000)) {
- tv.tv_sec = MAX_SEC_FOR_READ;
- tv.tv_usec = 0;
- } else {
- tv.tv_sec = static_cast<time_t>(maxMsBlock / 1000);
- tv.tv_usec = static_cast<suseconds_t>((maxMsBlock % 1000) * 1000);
- }
- QMutex *lock = (mainConnection ? mainConnection->mainThreadLock() : 0);
- if (lock)
- lock->unlock();
- result = select(nfds, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
- if (lock)
- lock->lock();
- if (result > 0) {
- if (FD_ISSET(dns_sd_fd, &readfds))
- return processOneEventBlock(cRef);
- } else if (result == 0) {
- return ProcessedIdle;
- } else if (errno != EINTR) {
- if (DEBUG_ZEROCONF)
- qDebug() << "select() returned " << result << " errno " << errno
- << strerror(errno);
- return ProcessedError;
- }
- return ProcessedIdle; // change? should never happen anyway
-}
-
-}
-
-int ServiceBrowser::maxProgress() const
-{
- return zeroConfLibInstance()->nFallbacksTot() + 3;
-}
-
-// namespace Internal
-} // namespace ZeroConf
diff --git a/src/libs/zeroconf/servicebrowser.h b/src/libs/zeroconf/servicebrowser.h
deleted file mode 100644
index e7612c16fd..0000000000
--- a/src/libs/zeroconf/servicebrowser.h
+++ /dev/null
@@ -1,199 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#ifndef SERVICEBROWSER_H
-#define SERVICEBROWSER_H
-
-#include "zeroconf_global.h"
-
-#include <QHash>
-#include <QObject>
-#include <QSharedPointer>
-#include <QStringList>
-#include <QTimer>
-
-QT_BEGIN_NAMESPACE
-class QHostInfo;
-class QNetworkInterface;
-QT_END_NAMESPACE
-
-namespace ZeroConf {
-
-namespace Internal {
-class ServiceGatherer;
-class MainConnection;
-class ServiceBrowserPrivate;
-}
-
-
-class ZEROCONFSHARED_EXPORT ErrorMessage
-{
-public:
- enum SeverityLevel
- {
- NoteLevel,
- WarningLevel,
- ErrorLevel,
- FailureLevel
- };
-
- static QString severityLevelToString(SeverityLevel);
-
- ErrorMessage();
- ErrorMessage(SeverityLevel s, const QString &m);
-
- SeverityLevel severity;
- QString msg;
-
- class ErrorLogger{
- public:
- virtual void appendError(ErrorMessage::SeverityLevel severity, const QString& msg) = 0;
- };
-};
-
-ZEROCONFSHARED_EXPORT QDebug operator<<(QDebug dbg, const ErrorMessage &eMsg);
-
-typedef QSharedPointer<Internal::MainConnection> MainConnectionPtr;
-
-typedef QHash<QString, QString> ServiceTxtRecord;
-
-class ZEROCONFSHARED_EXPORT Service
-{
- friend class Internal::ServiceGatherer;
-
-public:
- typedef QSharedPointer<const Service> ConstPtr;
- typedef QSharedPointer<Service> Ptr;
-
- enum AddressStyle
- {
- PlainAddresses,
- QuoteIPv6Adresses
- };
-
- Service(const Service &o);
- Service();
- ~Service();
-
- bool outdated() const { return m_outdated; }
-
- QString name() const { return m_name; }
- QString type() const { return m_type; }
- QString domain() const { return m_domain; }
- QString fullName() const { return m_fullName; }
- QString port() const { return m_port; }
- const ServiceTxtRecord &txtRecord() const { return m_txtRecord; }
- const QHostInfo *host() const { return m_host; }
- int interfaceNr() const { return m_interfaceNr; }
- QNetworkInterface networkInterface() const;
- QStringList addresses(AddressStyle style = PlainAddresses) const;
- bool operator==(const Service &o) const;
-
- bool invalidate() { bool res = m_outdated; m_outdated = true; return res; }
-private:
- QString m_name;
- QString m_type;
- QString m_domain;
- QString m_fullName;
- QString m_port;
- ServiceTxtRecord m_txtRecord;
- QHostInfo *m_host;
- int m_interfaceNr;
- bool m_outdated;
-};
-
-ZEROCONFSHARED_EXPORT QDebug operator<<(QDebug dbg, const Service &service);
-ZEROCONFSHARED_EXPORT QDebug operator<<(QDebug dbg, const Service::ConstPtr &service);
-
-class ZEROCONFSHARED_EXPORT ServiceBrowser : public QObject
-{
- Q_OBJECT
- friend class Internal::ServiceBrowserPrivate;
-public:
- enum AddressesSetting { RequireAddresses, DoNotRequireAddresses };
-
- ServiceBrowser(const QString &serviceType, const QString &domain = QLatin1String("local."),
- AddressesSetting addressesSetting = RequireAddresses, QObject *parent = 0);
- ServiceBrowser(const MainConnectionPtr &mainConnection, const QString &serviceType,
- const QString &domain = QLatin1String("local."),
- AddressesSetting addressesSetting = RequireAddresses, QObject *parent = 0);
- ~ServiceBrowser();
-
- MainConnectionPtr mainConnection() const;
-
- void startBrowsing(qint32 interfaceIndex = 0);
- void stopBrowsing();
- bool isBrowsing() const;
- bool didFail() const;
- int maxProgress() const;
-
- const QString& serviceType() const;
- const QString& domain() const;
-
- bool adressesAutoResolved() const;
- bool addressesRequired() const;
-
- QList<Service::ConstPtr> services() const;
- void reconfirmService(Service::ConstPtr service);
-public slots:
- void triggerRefresh();
- void autoRefresh();
-signals:
- void activateAutoRefresh();
- void serviceChanged(const ZeroConf::Service::ConstPtr &oldService,
- const ZeroConf::Service::ConstPtr &newService, ZeroConf::ServiceBrowser *browser);
- void serviceAdded(const ZeroConf::Service::ConstPtr &service,
- ZeroConf::ServiceBrowser *browser);
- void serviceRemoved(const ZeroConf::Service::ConstPtr &service,
- ZeroConf::ServiceBrowser *browser);
- void servicesUpdated(ZeroConf::ServiceBrowser *browser);
- void startupPhase(int progress, const QString &description, ZeroConf::ServiceBrowser *browser);
- void errorMessage(ZeroConf::ErrorMessage::SeverityLevel severity, const QString &msg, ZeroConf::ServiceBrowser *browser);
- void hadFailure(const QList<ZeroConf::ErrorMessage> &messages, ZeroConf::ServiceBrowser *browser);
- void startedBrowsing(ZeroConf::ServiceBrowser *browser);
-private:
- QTimer *timer;
- Internal::ServiceBrowserPrivate *d;
-};
-
-enum LibUsage {
- UseDnsSdOnly = 1,
- UseEmbeddedOnly,
- UseAvahiOnly,
- UseAvahiOrDnsSd,
- UseAvahiOrDnsSdOrEmbedded
-};
-
-void setDefaultZConfLib(LibUsage usage, const QString &avahiLibName, const QString &dnsSdLibName,
- const QString & dnsSdDaemonPath);
-
-}
-
-#endif // SERVICEBROWSER_H
diff --git a/src/libs/zeroconf/servicebrowser_p.h b/src/libs/zeroconf/servicebrowser_p.h
deleted file mode 100644
index 2a980845ff..0000000000
--- a/src/libs/zeroconf/servicebrowser_p.h
+++ /dev/null
@@ -1,358 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#ifndef SERVICEBROWSER_P_H
-#define SERVICEBROWSER_P_H
-
-#include "dns_sd_types.h"
-#include "servicebrowser.h"
-
-#include <QCoreApplication>
-#include <QAtomicInt>
-#include <QHash>
-#include <QList>
-#include <QMap>
-#include <QMutex>
-#include <QSharedPointer>
-#include <QStringList>
-#include <QThread>
-
-namespace ZeroConf {
-
-class ServiceBrowser;
-
-namespace Internal {
-
-class ServiceGatherer;
-class ServiceBrowserPrivate;
-
-enum ZK_IP_Protocol {
- ZK_PROTO_IPv4_OR_IPv6,
- ZK_PROTO_IPv4,
- ZK_PROTO_IPv6
-};
-
-// represents a zero conf library exposing the dns-sd interface
-class ZConfLib {
- Q_DECLARE_TR_FUNCTIONS(ZeroConf::Internal::ZConfLib)
-public:
- typedef QSharedPointer<ZConfLib> Ptr;
- typedef void *ConnectionRef;
- typedef void *BrowserRef;
- enum RunLoopStatus {
- ProcessedIdle,
- ProcessedOk,
- ProcessedQuit,
- ProcessedError,
- ProcessedFailure
- };
- enum {
- // Note: the select() implementation on Windows (Winsock2) fails with any timeout much larger than this
- MAX_SEC_FOR_READ = 100000000
- };
- Ptr fallbackLib;
-
- ZConfLib(Ptr fallBack);
- virtual ~ZConfLib();
-
- virtual QString name();
-
- virtual bool tryStartDaemon(ErrorMessage::ErrorLogger *logger = 0);
-
- virtual void refDeallocate(DNSServiceRef sdRef) = 0;
- virtual void browserDeallocate(BrowserRef *sdRef) = 0;
- virtual DNSServiceErrorType resolve(ConnectionRef cRef, DNSServiceRef *sdRef,
- uint32_t interfaceIndex, ZK_IP_Protocol protocol,
- const char *name, const char *regtype,
- const char *domain, 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, ServiceGatherer *gatherer) = 0;
-
- virtual DNSServiceErrorType reconfirmRecord(ConnectionRef cRef, uint32_t interfaceIndex,
- const char *name, const char *type,
- const char *domain, const char *fullname) = 0;
- 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 RunLoopStatus processOneEventBlock(ConnectionRef sdRef) = 0;
- virtual RunLoopStatus processOneEvent(MainConnection *mainConnection,
- ConnectionRef sdRef, qint64 maxMsBlock);
- virtual DNSServiceErrorType createConnection(MainConnection *mainConnection,
- ConnectionRef *sdRef) = 0;
- virtual void stopConnection(ConnectionRef cRef) = 0;
- virtual void destroyConnection(ConnectionRef *sdRef) = 0;
- virtual int refSockFD(ConnectionRef sdRef) = 0;
- bool isOk();
- QString errorMsg();
- void setError(bool failure, const QString &eMsg);
- int nFallbacks() const;
- int maxErrors() const;
-
- static Ptr createEmbeddedLib(const QString &daemonPath, const Ptr &fallback = Ptr(0));
- static Ptr createDnsSdLib(const QString &libName, const Ptr &fallback = Ptr(0));
- static Ptr createAvahiLib(const QString &libName, const QString &version, const Ptr &fallback = Ptr(0));
-protected:
- bool m_isOk;
- QString m_errorMsg;
- int m_maxErrors;
-};
-
-/// 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:
- QString hostName;
- ServiceBrowserPrivate *serviceBrowser;
- QHostInfo *host;
- Service::Ptr publishedService;
- Service *currentService;
-
- typedef QSharedPointer<ServiceGatherer> Ptr;
-
- enum Status {
- ResolveConnectionFailed = 1 << 0,
- ResolveConnectionActive = 1 << 1,
- ResolveConnectionSuccess = 1 << 2,
- ResolveConnectionV6Failed = 1 << 3,
- ResolveConnectionV6Active = 1 << 4,
- ResolveConnectionV6Success = 1 << 5,
- TxtConnectionFailed = 1 << 6,
- TxtConnectionActive = 1 << 7,
- TxtConnectionSuccess = 1 << 8,
- AddrConnectionFailed = 1 << 9,
- AddrConnectionActive = 1 << 10,
- AddrConnectionSuccess = 1 << 11
- };
-
- QString fullName();
- bool enactServiceChange();
- void retireService();
- Ptr gatherer();
-
- void stopResolve(ZK_IP_Protocol protocol = ZK_PROTO_IPv4_OR_IPv6);
- void stopTxt();
- void stopHostResolution();
- void restartResolve(ZK_IP_Protocol protocol = ZK_PROTO_IPv4_OR_IPv6);
- void restartTxt();
- void restartHostResolution();
-
- bool currentServiceCanBePublished();
-
- ~ServiceGatherer();
- static Ptr createGatherer(const QString &newService, const QString &newType,
- const QString &newDomain, const QString &fullName,
- uint32_t interfaceIndex, ZK_IP_Protocol protocol,
- ServiceBrowserPrivate *serviceBrowser);
-
- void serviceResolveReply(DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *hosttarget,
- const QString &port, uint16_t txtLen,
- const unsigned char *rawTxtRecord);
-
- void txtRecordReply(DNSServiceFlags flags, DNSServiceErrorType errorCode,
- uint16_t txtLen, const void *rawTxtRecord, uint32_t ttl);
- void txtFieldReply(DNSServiceFlags flags, DNSServiceErrorType errorCode,
- uint16_t txtLen, const void *rawTxtRecord, uint32_t ttl);
-
- void addrReply(DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *hostname,
- const struct sockaddr *address, uint32_t ttl);
- void maybeRemove();
- void stop(ZK_IP_Protocol protocol = ZK_PROTO_IPv4_OR_IPv6);
- void reload(qint32 interfaceIndex = 0, ZK_IP_Protocol protocol = ZK_PROTO_IPv4_OR_IPv6);
- void remove();
- void reconfirm();
- ZConfLib::Ptr lib();
-private:
- ServiceGatherer(const QString &newService, const QString &newType, const QString &newDomain,
- const QString &fullName, uint32_t interfaceIndex,
- ZK_IP_Protocol protocol, ServiceBrowserPrivate *serviceBrowser);
-
- DNSServiceRef resolveConnection;
- DNSServiceRef resolveConnectionV6;
- DNSServiceRef txtConnection;
- DNSServiceRef addrConnection;
- uint32_t interfaceIndex;
-
- quint32 status;
- QWeakPointer<ServiceGatherer> self;
-};
-
-//Q_DECLARE_METATYPE(Service::ConstPtr)
-
-class ConnectionThread;
-
-class MainConnection : private ErrorMessage::ErrorLogger {
- Q_DECLARE_TR_FUNCTIONS(ZeroConf)
-public:
- enum RequestFlowStatus {
- NormalRFS,
- MoreComingRFS,
- ForceUpdateRFS
- };
- RequestFlowStatus flowStatus;
- /// WARNING order matters in this enum, and status should only be changed with increaseStatusTo
- enum Status {
- Starting,
- Started,
- Running,
- Stopping,
- Stopped
- };
- ZConfLib::Ptr lib;
-
- MainConnection(ServiceBrowserPrivate *initialBrowser = 0);
- virtual ~MainConnection();
- QMutex *lock();
- QMutex *mainThreadLock();
- void waitStartup();
- void stop(bool wait = true);
- void addBrowser(ServiceBrowserPrivate *browser);
- void removeBrowser(ServiceBrowserPrivate *browser);
- void updateFlowStatusForCancel();
- void updateFlowStatusForFlags(DNSServiceFlags flags);
- void maybeUpdateLists();
- void gotoValidLib();
- void abortLib();
- void createConnection();
- void destroyConnection();
- ZConfLib::RunLoopStatus handleEvent();
- bool increaseStatusTo(int s);
- void handleEvents();
- ZConfLib::ConnectionRef mainRef();
- Status status();
-
- QList<ErrorMessage> errors();
- bool isOk();
- void startupPhase(int progress, const QString &msg);
-private:
- void appendError(ErrorMessage::SeverityLevel severity, const QString &msg);
-
- mutable QMutex m_lock, m_mainThreadLock;
- QList<ServiceBrowserPrivate *> m_browsers;
- ZConfLib::ConnectionRef m_mainRef;
- bool m_failed;
- ConnectionThread *m_thread;
- QAtomicInt m_status;
- int m_nErrs;
- QList<ErrorMessage> m_errors;
-};
-
-class ServiceBrowserPrivate {
-public:
- ServiceBrowser *q;
- QString serviceType;
- QString domain;
- MainConnectionPtr mainConnection;
- ZConfLib::BrowserRef serviceConnection;
- DNSServiceFlags flags;
- uint32_t interfaceIndex;
- QList<QString> knownServices;
- QMap<QString, ServiceGatherer::Ptr> gatherers;
- QList<Service::ConstPtr> activeServices;
- QList<Service::ConstPtr> nextActiveServices;
- QList<ServiceGatherer::Ptr> pendingGatherers;
- qint64 delayDeletesUntil;
- bool failed;
- bool browsing;
- bool autoResolveAddresses;
- bool requireAddresses;
- bool shouldRefresh;
-
- ZConfLib::ConnectionRef mainRef();
- void updateFlowStatusForCancel();
- void updateFlowStatusForFlags(DNSServiceFlags flags);
-
- void pendingGathererAdd(ServiceGatherer::Ptr gatherer);
-
- ServiceBrowserPrivate(const QString &serviceType, const QString &domain, bool requireAddresses,
- MainConnectionPtr conn);
- ~ServiceBrowserPrivate();
-
- void insertGatherer(const QString &fullName);
- void maybeUpdateLists();
-
- void startBrowsing(quint32 interfaceIndex);
- bool internalStartBrowsing();
- void stopBrowsing();
- void triggerRefresh();
- void refresh();
- void reconfirmService(Service::ConstPtr s);
-
- void browseReply(DNSServiceFlags flags,
- uint32_t interfaceIndex, ZK_IP_Protocol proto, DNSServiceErrorType errorCode,
- const char *serviceName, const char *regtype, const char *replyDomain);
-
- void activateAutoRefresh();
- void serviceChanged(const Service::ConstPtr &oldService, const Service::ConstPtr &newService,
- ServiceBrowser *browser);
- void serviceAdded(const Service::ConstPtr &service, ServiceBrowser *browser);
- void serviceRemoved(const Service::ConstPtr &service, ServiceBrowser *browser);
- void servicesUpdated(ServiceBrowser *browser);
- void startupPhase(int progress, const QString &description);
- void errorMessage(ErrorMessage::SeverityLevel severity, const QString &msg);
- void hadFailure(const QList<ErrorMessage> &msgs);
- void startedBrowsing();
-};
-
-class ConnectionThread: public QThread {
- MainConnection &connection;
-
- void run();
-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
-
-#endif // SERVICEBROWSER_P_H
diff --git a/src/libs/zeroconf/syssocket.h b/src/libs/zeroconf/syssocket.h
deleted file mode 100644
index b1a2fa1c8a..0000000000
--- a/src/libs/zeroconf/syssocket.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#ifndef SYSSOCKET_H
-#define SYSSOCKET_H
-
-// WARNING:
-//
-// we use Winsock2, which means that this header should be included *before*
-// any other windows header
-
-#include <qglobal.h>
-
-#ifdef Q_OS_WIN32
-# include <winsock2.h>
-# ifndef SHUT_RDWR
-# ifdef SD_BOTH
-# define SHUT_RDWR SD_BOTH
-# else
-# define SHUT_RDWR 2
-# endif
-# endif
-#else
-# include <sys/socket.h>
-#endif
-
-#endif // SYSSOCKET_H
diff --git a/src/libs/zeroconf/zeroconf.pro b/src/libs/zeroconf/zeroconf.pro
deleted file mode 100644
index 4980a869c8..0000000000
--- a/src/libs/zeroconf/zeroconf.pro
+++ /dev/null
@@ -1,27 +0,0 @@
-QT -= gui
-QT += network
-CONFIG += exceptions
-
-DEFINES += ZEROCONF_LIBRARY
-
-SOURCES += servicebrowser.cpp \
- embeddedLib.cpp \
- mdnsderived.cpp \
- avahiLib.cpp \
- dnsSdLib.cpp
-
-HEADERS += servicebrowser.h \
- zeroconf_global.h \
- dns_sd_types.h \
- servicebrowser_p.h \
- mdnsderived.h \
- syssocket.h
-
-include(../../qtcreatorlibrary.pri)
-
-win32{
- LIBS += -lws2_32
-}
-linux-* {
- DEFINES += _GNU_SOURCE HAVE_IPV6 USES_NETLINK HAVE_LINUX TARGET_OS_LINUX
-}
diff --git a/src/libs/zeroconf/zeroconf.qbs b/src/libs/zeroconf/zeroconf.qbs
deleted file mode 100644
index 935f63b406..0000000000
--- a/src/libs/zeroconf/zeroconf.qbs
+++ /dev/null
@@ -1,43 +0,0 @@
-import qbs 1.0
-import QtcLibrary
-
-QtcLibrary {
- name: "zeroconf"
-
- Depends { name: "Qt.network" }
- cpp.includePaths: base.concat(".")
-
- cpp.defines: {
- var list = base;
- list.push("ZEROCONF_LIBRARY");
- if (qbs.targetOS.contains("linux")) {
- list.push(
- "_GNU_SOURCE",
- "HAVE_IPV6",
- "USES_NETLINK",
- "HAVE_LINUX",
- "TARGET_OS_LINUX"
- );
- }
- return list;
- }
-
- Properties {
- condition: qbs.targetOS.contains("windows")
- cpp.dynamicLibraries: "ws2_32"
- }
-
- files: [
- "avahiLib.cpp",
- "dnsSdLib.cpp",
- "dns_sd_types.h",
- "embeddedLib.cpp",
- "mdnsderived.cpp",
- "mdnsderived.h",
- "servicebrowser.cpp",
- "servicebrowser.h",
- "servicebrowser_p.h",
- "syssocket.h",
- "zeroconf_global.h",
- ]
-}
diff --git a/src/libs/zeroconf/zeroconf_dependencies.pri b/src/libs/zeroconf/zeroconf_dependencies.pri
deleted file mode 100644
index 9e8d0ea9bc..0000000000
--- a/src/libs/zeroconf/zeroconf_dependencies.pri
+++ /dev/null
@@ -1 +0,0 @@
-QTC_LIB_NAME = zeroconf
diff --git a/src/libs/zeroconf/zeroconf_global.h b/src/libs/zeroconf/zeroconf_global.h
deleted file mode 100644
index c5595f232e..0000000000
--- a/src/libs/zeroconf/zeroconf_global.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://www.qt.io/licensing. For further information
-** use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#ifndef ZEROCONF_GLOBAL_H
-#define ZEROCONF_GLOBAL_H
-
-#include <qglobal.h>
-
-#if defined(ZEROCONF_LIBRARY)
-# define ZEROCONFSHARED_EXPORT Q_DECL_EXPORT
-#else
-# define ZEROCONFSHARED_EXPORT Q_DECL_IMPORT
-#endif
-
-enum { DEBUG_ZEROCONF = false } ;
-
-#endif // ZEROCONF_GLOBAL_H