forked from qt-creator/qt-creator
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>
This commit is contained in:
Vendored
+3
@@ -71,4 +71,7 @@ QNX
|
||||
|
||||
BareMetal
|
||||
|
||||
Tools:
|
||||
* Removed unused zeroconf wrapper
|
||||
|
||||
Credits for these changes go to:
|
||||
|
||||
+1
-2
@@ -12,8 +12,7 @@ SUBDIRS = \
|
||||
qmldebug \
|
||||
qmleditorwidgets \
|
||||
glsl \
|
||||
ssh \
|
||||
zeroconf
|
||||
ssh
|
||||
|
||||
for(l, SUBDIRS) {
|
||||
QTC_LIB_DEPENDS =
|
||||
|
||||
@@ -16,6 +16,5 @@ Project {
|
||||
"utils/process_stub.qbs",
|
||||
"utils/process_ctrlc_stub.qbs",
|
||||
"utils/utils.qbs",
|
||||
"zeroconf/zeroconf.qbs",
|
||||
].concat(project.additionalLibs)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -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__ ")";
|
||||
}}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
}
|
||||
}}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
QTC_LIB_NAME = zeroconf
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user