Commit 6ea69060 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

zeroconf: codestyle



Trying to avoid long lines and fixing other spacing issues.

Change-Id: Ie0024743ef66c52a7922be046a8f7d8701a94ad6
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent 3c4f6cd4
...@@ -56,15 +56,20 @@ ...@@ -56,15 +56,20 @@
namespace ZeroConf { namespace ZeroConf {
namespace Internal { namespace Internal {
extern "C" void cAvahiResolveReply( AvahiServiceResolver * r, AvahiIfIndex interface, AvahiProtocol /*protocol*/, extern "C" void cAvahiResolveReply(
AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *hostName, AvahiServiceResolver * r, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags /*flags*/, void* context); AvahiResolverEvent event, const char *name, const char *type, const char *domain,
extern "C" void cAvahiResolveEmptyReply(AvahiServiceResolver * r, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent, const char *, const char *, const char *hostName, const AvahiAddress *address, uint16_t port, AvahiStringList *txt,
const char *, const char *, const AvahiAddress *, uint16_t, AvahiStringList *, AvahiLookupResultFlags, void*); 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 cAvahiClientReply (AvahiClient * /*s*/, AvahiClientState state, void* context);
extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/, extern "C" void cAvahiBrowseReply(
AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
AvahiLookupResultFlags /*flags*/, void* context); AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
AvahiLookupResultFlags /*flags*/, void* context);
extern "C" { extern "C" {
typedef const AvahiPoll* (*AvahiSimplePollGet)(AvahiSimplePoll *s); typedef const AvahiPoll* (*AvahiSimplePollGet)(AvahiSimplePoll *s);
...@@ -72,17 +77,20 @@ typedef AvahiSimplePoll *(*AvahiSimplePollNewPtr)(void); ...@@ -72,17 +77,20 @@ typedef AvahiSimplePoll *(*AvahiSimplePollNewPtr)(void);
typedef int (*AvahiSimplePollIteratePtr)(AvahiSimplePoll *s, int sleep_time); typedef int (*AvahiSimplePollIteratePtr)(AvahiSimplePoll *s, int sleep_time);
typedef void (*AvahiSimplePollQuitPtr)(AvahiSimplePoll *s); typedef void (*AvahiSimplePollQuitPtr)(AvahiSimplePoll *s);
typedef void (*AvahiSimplePollFreePtr)(AvahiSimplePoll *s); typedef void (*AvahiSimplePollFreePtr)(AvahiSimplePoll *s);
typedef AvahiClient* (*AvahiClientNewPtr)(const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback, typedef AvahiClient* (*AvahiClientNewPtr)(
void *userdata, int *error); const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback,
void *userdata, int *error);
typedef void (*AvahiClientFreePtr)(AvahiClient *client); typedef void (*AvahiClientFreePtr)(AvahiClient *client);
typedef AvahiServiceBrowser* (*AvahiServiceBrowserNewPtr) (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, typedef AvahiServiceBrowser* (*AvahiServiceBrowserNewPtr)(
const char *type, const char *domain, AvahiLookupFlags flags, AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *type,
AvahiServiceBrowserCallback callback, void *userdata); const char *domain, AvahiLookupFlags flags, AvahiServiceBrowserCallback callback,
void *userdata);
typedef int (*AvahiServiceBrowserFreePtr)(AvahiServiceBrowser *); typedef int (*AvahiServiceBrowserFreePtr)(AvahiServiceBrowser *);
typedef AvahiServiceResolver * (*AvahiServiceResolverNewPtr)(AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, typedef AvahiServiceResolver * (*AvahiServiceResolverNewPtr)(
const char *name, const char *type, const char *domain, AvahiProtocol aprotocol, AvahiLookupFlags flags, AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *name,
AvahiServiceResolverCallback callback, void *userdata); const char *type, const char *domain, AvahiProtocol aprotocol, AvahiLookupFlags flags,
AvahiServiceResolverCallback callback, void *userdata);
typedef int (*AvahiServiceResolverFreePtr)(AvahiServiceResolver *r); typedef int (*AvahiServiceResolverFreePtr)(AvahiServiceResolver *r);
} }
...@@ -114,7 +122,9 @@ private: ...@@ -114,7 +122,9 @@ private:
QLibrary nativeLib; QLibrary nativeLib;
public: public:
AvahiZConfLib(QString libName = QLatin1String("avahi"), ZConfLib::Ptr fallBack = ZConfLib::Ptr(0)) : ZConfLib(fallBack), nativeLib(libName) AvahiZConfLib(QString libName = QLatin1String("avahi"),
ZConfLib::Ptr fallBack = ZConfLib::Ptr(0)) :
ZConfLib(fallBack), nativeLib(libName)
{ {
#ifndef ZCONF_AVAHI_STATIC_LINKING #ifndef ZCONF_AVAHI_STATIC_LINKING
// dynamic linking // dynamic linking
...@@ -164,7 +174,7 @@ public: ...@@ -164,7 +174,7 @@ public:
} }
QString name(){ QString name(){
return QString::fromUtf8("AvahiZeroConfLib@%1").arg(size_t(this),0,16); return QString::fromUtf8("AvahiZeroConfLib@%1").arg(size_t(this), 0, 16);
} }
// bool tryStartDaemon(); // bool tryStartDaemon();
...@@ -202,8 +212,9 @@ public: ...@@ -202,8 +212,9 @@ public:
MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef); MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
if (!m_serviceResolverNew) if (!m_serviceResolverNew)
return kDNSServiceErr_Unknown; return kDNSServiceErr_Unknown;
AvahiServiceResolver *resolver = m_serviceResolverNew(connection->client, interfaceIndex, AVAHI_PROTO_INET, name, regtype, domain, AVAHI_PROTO_INET, AvahiServiceResolver *resolver = m_serviceResolverNew(
AvahiLookupFlags(0), &cAvahiResolveReply, gatherer); connection->client, interfaceIndex, AVAHI_PROTO_INET, name, regtype, domain,
AVAHI_PROTO_INET, AvahiLookupFlags(0), &cAvahiResolveReply, gatherer);
//*sdRef = reinterpret_cast<DNSServiceRef>(resolver); // add for restart? //*sdRef = reinterpret_cast<DNSServiceRef>(resolver); // add for restart?
if (!resolver) if (!resolver)
return kDNSServiceErr_Unknown; // avahi_strerror(avahi_client_errno(connection->client)); return kDNSServiceErr_Unknown; // avahi_strerror(avahi_client_errno(connection->client));
...@@ -223,20 +234,23 @@ public: ...@@ -223,20 +234,23 @@ public:
} }
DNSServiceErrorType reconfirmRecord(ConnectionRef cRef, uint32_t interfaceIndex, DNSServiceErrorType reconfirmRecord(ConnectionRef cRef, uint32_t interfaceIndex,
const char *name, const char *type, const char *domain, const char *name, const char *type, const char *domain,
const char * /*fullname */) const char * /*fullname */)
{ {
MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef); MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
if (!connection) if (!connection)
return kDNSServiceErr_Unknown; return kDNSServiceErr_Unknown;
AvahiServiceResolver *resolver = m_serviceResolverNew(connection->client, interfaceIndex, AVAHI_PROTO_INET, name, type, domain, AVAHI_PROTO_INET, AvahiServiceResolver *resolver = m_serviceResolverNew(
AvahiLookupFlags(AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), &cAvahiResolveEmptyReply, connection->client, interfaceIndex, AVAHI_PROTO_INET, name, type, domain,
this); AVAHI_PROTO_INET, AvahiLookupFlags(AVAHI_LOOKUP_USE_WIDE_AREA|
return ((resolver==0)?kDNSServiceErr_Unknown:kDNSServiceErr_NoError); AVAHI_LOOKUP_USE_MULTICAST),
&cAvahiResolveEmptyReply, this);
return ((resolver == 0)?kDNSServiceErr_Unknown:kDNSServiceErr_NoError);
} }
DNSServiceErrorType browse(ConnectionRef cRef, BrowserRef *sdRef, uint32_t interfaceIndex, DNSServiceErrorType browse(ConnectionRef cRef, BrowserRef *sdRef, uint32_t interfaceIndex,
const char *regtype, const char *domain, ServiceBrowserPrivate *browser) const char *regtype, const char *domain,
ServiceBrowserPrivate *browser)
{ {
if (!sdRef) { if (!sdRef) {
qDebug() << "Error: sdRef is null in browse"; qDebug() << "Error: sdRef is null in browse";
...@@ -245,9 +259,12 @@ public: ...@@ -245,9 +259,12 @@ public:
if (!m_serviceBrowserNew) if (!m_serviceBrowserNew)
return kDNSServiceErr_Unknown; return kDNSServiceErr_Unknown;
MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef); MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
AvahiServiceBrowser *sb = m_serviceBrowserNew(connection->client, AvahiServiceBrowser *sb = m_serviceBrowserNew(
((interfaceIndex==0)?static_cast<uint32_t>(AVAHI_IF_UNSPEC):static_cast<uint32_t>(interfaceIndex)), connection->client,
AVAHI_PROTO_UNSPEC, regtype, domain, AvahiLookupFlags(0), &cAvahiBrowseReply, browser); ((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); *sdRef = reinterpret_cast<BrowserRef>(sb);
if (!sb) { if (!sb) {
return kDNSServiceErr_Unknown; return kDNSServiceErr_Unknown;
...@@ -256,9 +273,9 @@ public: ...@@ -256,9 +273,9 @@ public:
return kDNSServiceErr_NoError; return kDNSServiceErr_NoError;
} }
DNSServiceErrorType getProperty(const char * /*property*/, // Requested property (i.e. kDNSServiceProperty_DaemonVersion) DNSServiceErrorType getProperty(const char * /*property*/,
void * /*result*/, // Pointer to place to store result void * /*result*/,
uint32_t * /*size*/ // size of result location uint32_t * /*size*/
) )
{ {
return 0; return 0;
...@@ -292,12 +309,14 @@ public: ...@@ -292,12 +309,14 @@ public:
} }
/* Allocate a new client */ /* Allocate a new client */
int error; int error;
connection->client = m_clientNew(m_simplePollGet(connection->simple_poll), AvahiClientFlags(0), &cAvahiClientReply, connection, &error); connection->client = m_clientNew(m_simplePollGet(connection->simple_poll),
AvahiClientFlags(0), &cAvahiClientReply,
connection, &error);
if (!connection->client) { if (!connection->client) {
if (m_simplePollFree) if (m_simplePollFree)
m_simplePollFree(connection->simple_poll); m_simplePollFree(connection->simple_poll);
delete connection; delete connection;
setError(true,tr("%1 could not create a client (probably the daemon is not running)")); setError(true, tr("%1 could not create a client (probably the daemon is not running)"));
return kDNSServiceErr_Unknown; return kDNSServiceErr_Unknown;
} }
*sdRef = reinterpret_cast<ConnectionRef>(connection); *sdRef = reinterpret_cast<ConnectionRef>(connection);
...@@ -337,19 +356,22 @@ extern "C" void cAvahiResolveReply( ...@@ -337,19 +356,22 @@ extern "C" void cAvahiResolveReply(
qDebug() << "context was null in cAvahiResolveReply"; qDebug() << "context was null in cAvahiResolveReply";
return; return;
} }
AvahiStringList *txtAtt=0; AvahiStringList *txtAtt = 0;
const unsigned char emptyTxt[1]=""; const unsigned char emptyTxt[1]="";
switch (event) { switch (event) {
case AVAHI_RESOLVER_FAILURE: case AVAHI_RESOLVER_FAILURE:
sg->serviceResolveReply(0, kDNSServiceErr_Timeout, interface, 0, QString(), 0, 0); sg->serviceResolveReply(0, kDNSServiceErr_Timeout, interface, 0, QString(), 0, 0);
break; break;
case AVAHI_RESOLVER_FOUND: case AVAHI_RESOLVER_FOUND:
sg->serviceResolveReply(kDNSServiceFlagsAdd|((txtAtt || address)?kDNSServiceFlagsMoreComing:0), interface, kDNSServiceErr_NoError, sg->serviceResolveReply(
hostName, QString::number(port), 0, emptyTxt); kDNSServiceFlagsAdd | ((txtAtt || address)?kDNSServiceFlagsMoreComing:0),
txtAtt=txt; interface, kDNSServiceErr_NoError, hostName, QString::number(port), 0, emptyTxt);
txtAtt = txt;
while (txtAtt) { while (txtAtt) {
sg->txtFieldReply(kDNSServiceFlagsAdd|((txtAtt->next || address)?kDNSServiceFlagsMoreComing:0),kDNSServiceErr_NoError, sg->txtFieldReply(
static_cast<unsigned short>(txtAtt->size),txtAtt->text,-1); kDNSServiceFlagsAdd | ((txtAtt->next || address)?kDNSServiceFlagsMoreComing:0),
kDNSServiceErr_NoError, static_cast<unsigned short>(txtAtt->size),
txtAtt->text, -1);
txtAtt = txtAtt->next; txtAtt = txtAtt->next;
} }
if (address){ if (address){
...@@ -358,20 +380,23 @@ extern "C" void cAvahiResolveReply( ...@@ -358,20 +380,23 @@ extern "C" void cAvahiResolveReply(
//#ifdef HAVE_SA_LEN //#ifdef HAVE_SA_LEN
switch (address->proto){ switch (address->proto){
case (AVAHI_PROTO_INET): case (AVAHI_PROTO_INET):
memset(&ipv4,0,sizeof(ipv4)); memset(&ipv4, 0, sizeof(ipv4));
ipv4.sin_family = AF_INET; ipv4.sin_family = AF_INET;
memcpy(&(ipv4.sin_addr),&(address->data.ipv4.address),sizeof(ipv4.sin_addr)); memcpy(&(ipv4.sin_addr),&(address->data.ipv4.address), sizeof(ipv4.sin_addr));
sg->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError, hostName, reinterpret_cast<sockaddr*>(&ipv4), defaultTtl); sg->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError, hostName,
reinterpret_cast<sockaddr*>(&ipv4), defaultTtl);
break; break;
case (AVAHI_PROTO_INET6): case (AVAHI_PROTO_INET6):
memset(&ipv6,0,sizeof(ipv6)); memset(&ipv6, 0, sizeof(ipv6));
ipv6.sin6_family = AF_INET6; ipv6.sin6_family = AF_INET6;
memcpy(&(ipv6.sin6_addr), &(address->data.ipv6.address), sizeof(ipv6.sin6_addr)); memcpy(&(ipv6.sin6_addr), &(address->data.ipv6.address), sizeof(ipv6.sin6_addr));
sg->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError, hostName, reinterpret_cast<sockaddr*>(&ipv6), defaultTtl); sg->addrReply(kDNSServiceFlagsAdd, kDNSServiceErr_NoError, hostName,
reinterpret_cast<sockaddr*>(&ipv6), defaultTtl);
break; break;
default: default:
if (DEBUG_ZEROCONF) if (DEBUG_ZEROCONF)
qDebug() << "Warning: ignoring address with protocol " << address->proto << " for service " << sg->fullName(); qDebug() << "Warning: ignoring address with protocol " << address->proto
<< " for service " << sg->fullName();
} }
} }
break; break;
...@@ -385,8 +410,10 @@ extern "C" void cAvahiResolveReply( ...@@ -385,8 +410,10 @@ extern "C" void cAvahiResolveReply(
lib->serviceResolverFree(r); lib->serviceResolverFree(r);
} }
extern "C" void cAvahiResolveEmptyReply(AvahiServiceResolver * r, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent, const char *, const char *, extern "C" void cAvahiResolveEmptyReply(
const char *, const char *, const AvahiAddress *, uint16_t, AvahiStringList *, AvahiLookupResultFlags, void* context) 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); AvahiZConfLib *lib = reinterpret_cast<AvahiZConfLib *>(context);
if (lib) if (lib)
...@@ -422,13 +449,15 @@ extern "C" void cAvahiClientReply (AvahiClient * /*s*/, AvahiClientState state, ...@@ -422,13 +449,15 @@ extern "C" void cAvahiClientReply (AvahiClient * /*s*/, AvahiClientState state,
lib->setError(false, lib->tr("cAvahiClient, still connecting, no server available")); lib->setError(false, lib->tr("cAvahiClient, still connecting, no server available"));
break; break;
default: default:
lib->setError(true, lib->tr("Error: unexpected state %1 in cAvahiClientReply, ignoring it").arg(state)); lib->setError(true, lib->tr("Error: unexpected state %1 in cAvahiClientReply, ignoring it")
.arg(state));
} }
} }
extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/, extern "C" void cAvahiBrowseReply(
AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
AvahiLookupResultFlags /*flags*/, void* context) AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
AvahiLookupResultFlags /*flags*/, void* context)
{ {
ServiceBrowserPrivate *browser = reinterpret_cast<ServiceBrowserPrivate *>(context); ServiceBrowserPrivate *browser = reinterpret_cast<ServiceBrowserPrivate *>(context);
...@@ -440,12 +469,13 @@ extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex inte ...@@ -440,12 +469,13 @@ extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex inte
browser->browseReply(kDNSServiceFlagsMoreComing, 0, kDNSServiceErr_Unknown, 0, 0, 0); browser->browseReply(kDNSServiceFlagsMoreComing, 0, kDNSServiceErr_Unknown, 0, 0, 0);
break; break;
case AVAHI_BROWSER_NEW: case AVAHI_BROWSER_NEW:
browser->browseReply(kDNSServiceFlagsAdd|kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface), kDNSServiceErr_NoError, browser->browseReply(kDNSServiceFlagsAdd|kDNSServiceFlagsMoreComing,
static_cast<uint32_t>(interface), kDNSServiceErr_NoError,
name, type, domain); name, type, domain);
break; break;
case AVAHI_BROWSER_REMOVE: case AVAHI_BROWSER_REMOVE:
browser->browseReply(kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface), kDNSServiceErr_NoError, browser->browseReply(kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface),
name, type, domain); kDNSServiceErr_NoError, name, type, domain);
break; break;
case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_ALL_FOR_NOW:
browser->updateFlowStatusForFlags(0); browser->updateFlowStatusForFlags(0);
...@@ -454,7 +484,9 @@ extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex inte ...@@ -454,7 +484,9 @@ extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex inte
browser->updateFlowStatusForFlags(0); browser->updateFlowStatusForFlags(0);
break; break;
default: default:
browser->mainConnection->lib->setError(true,browser->mainConnection->lib->tr("Error: unexpected state %1 in cAvahiBrowseReply, ignoring it").arg(event)); browser->mainConnection->lib->setError(true, browser->mainConnection->lib->tr(
"Error: unexpected state %1 in cAvahiBrowseReply, ignoring it")
.arg(event));
} }
} }
......
...@@ -117,7 +117,7 @@ public: ...@@ -117,7 +117,7 @@ public:
// dynamic linking // dynamic linking
if (!dnsSdLib.load()) { if (!dnsSdLib.load()) {
m_isOk = false; m_isOk = false;
m_errorMsg=tr("DnsSdZConfLib could not load native library"); m_errorMsg = tr("DnsSdZConfLib could not load native library");
} }
m_refDeallocate = reinterpret_cast<RefDeallocatePtr>(dnsSdLib.resolve("DNSServiceRefDeallocate")); m_refDeallocate = reinterpret_cast<RefDeallocatePtr>(dnsSdLib.resolve("DNSServiceRefDeallocate"));
m_resolve = reinterpret_cast<ResolvePtr>(dnsSdLib.resolve("DNSServiceResolve")); m_resolve = reinterpret_cast<ResolvePtr>(dnsSdLib.resolve("DNSServiceResolve"));
...@@ -160,7 +160,7 @@ public: ...@@ -160,7 +160,7 @@ public:
} }
QString name(){ QString name(){
return QString::fromUtf8("DnsSdZeroConfLib@%1").arg(size_t(this),0,16); return QString::fromUtf8("DnsSdZeroConfLib@%1").arg(size_t(this), 0, 16);
} }
// bool tryStartDaemon(); // bool tryStartDaemon();
...@@ -173,7 +173,7 @@ public: ...@@ -173,7 +173,7 @@ public:
if (m_refDeallocate == 0) return; if (m_refDeallocate == 0) return;
if (bRef) { if (bRef) {
m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(bRef)); m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(bRef));
*bRef=0; *bRef = 0;
} }
} }
...@@ -181,14 +181,14 @@ public: ...@@ -181,14 +181,14 @@ public:
{ {
int sock = refSockFD(cRef); int sock = refSockFD(cRef);
if (sock>0) if (sock>0)
shutdown(sock,SHUT_RDWR); shutdown(sock, SHUT_RDWR);
} }
void destroyConnection(ConnectionRef *sdRef) { void destroyConnection(ConnectionRef *sdRef) {
if (m_refDeallocate == 0) return; if (m_refDeallocate == 0) return;
if (sdRef) { if (sdRef) {
m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(sdRef)); m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(sdRef));
*sdRef=0; *sdRef = 0;
} }
} }
...@@ -210,7 +210,8 @@ public: ...@@ -210,7 +210,8 @@ public:
{ {
if (m_queryRecord == 0) return kDNSServiceErr_Unsupported; if (m_queryRecord == 0) return kDNSServiceErr_Unsupported;
*sdRef = reinterpret_cast<DNSServiceRef>(cRef); *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return m_queryRecord(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout, return m_queryRecord(sdRef, kDNSServiceFlagsShareConnection
| kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
interfaceIndex, fullname, interfaceIndex, fullname,
kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply, gatherer); kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply, gatherer);
} }
...@@ -224,7 +225,7 @@ public: ...@@ -224,7 +225,7 @@ public:
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
// try to use getaddrinfo (for example on linux with avahi) // try to use getaddrinfo (for example on linux with avahi)
struct addrinfo req, *ans; int err; struct addrinfo req, *ans; int err;
memset(&req,0,sizeof(req)); memset(&req, 0, sizeof(req));
req.ai_flags = 0; req.ai_flags = 0;
req.ai_family = AF_UNSPEC; req.ai_family = AF_UNSPEC;
req.ai_socktype = SOCK_STREAM; req.ai_socktype = SOCK_STREAM;
...@@ -244,13 +245,14 @@ public: ...@@ -244,13 +245,14 @@ public:
#endif #endif
} }
*sdRef = reinterpret_cast<DNSServiceRef>(cRef); *sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return m_getAddrInfo(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout, return m_getAddrInfo(sdRef, kDNSServiceFlagsShareConnection
| kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
interfaceIndex, protocol, hostname, &cAddrReply, gatherer); interfaceIndex, protocol, hostname, &cAddrReply, gatherer);
} }
DNSServiceErrorType reconfirmRecord(ConnectionRef /*cRef*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType reconfirmRecord(ConnectionRef /*cRef*/, uint32_t /*interfaceIndex*/,
const char * /*name*/, const char * /*type*/, const char * /*domain*/, const char * /*name*/, const char * /*type*/,
const char * /*fullname*/) const char * /*domain*/, const char * /*fullname*/)
{ {
if (m_reconfirmRecord == 0) return kDNSServiceErr_Unsupported; if (m_reconfirmRecord == 0) return kDNSServiceErr_Unsupported;
// reload and force update with in the callback with // reload and force update with in the callback with
...@@ -270,10 +272,7 @@ public: ...@@ -270,10 +272,7 @@ public:
interfaceIndex, regtype, domain, &cBrowseReply, browser); interfaceIndex, regtype, domain, &cBrowseReply, browser);
} }
DNSServiceErrorType getProperty(const char *property, // Requested property (i.e. kDNSServiceProperty_DaemonVersion) DNSServiceErrorType getProperty(const char *property, void *result, uint32_t *size)
void *result, // Pointer to place to store result
uint32_t *size // size of result location
)
{ {
if (m_getProperty == 0) if (m_getProperty == 0)
return kDNSServiceErr_Unsupported; return kDNSServiceErr_Unsupported;
...@@ -325,7 +324,8 @@ public: ...@@ -325,7 +324,8 @@ public:
} else if (result == 0) { } else if (result == 0) {
// we are idle... could do something productive... :) // we are idle... could do something productive... :)
} else if (errno != EINTR) { } else if (errno != EINTR) {
qDebug() << "select() returned " << result << " errno " << errno << strerror(errno); qDebug() << "select() returned " << result << " errno " << errno
<< strerror(errno);
return false; return false;
} }
} }
......
...@@ -60,7 +60,8 @@ class EmbeddedZConfLib : public ZConfLib ...@@ -60,7 +60,8 @@ class EmbeddedZConfLib : public ZConfLib
public: public:
QString daemonPath; QString daemonPath;
EmbeddedZConfLib(const QString &daemonPath, ZConfLib::Ptr fallBack) : ZConfLib(fallBack), daemonPath(daemonPath) EmbeddedZConfLib(const QString &daemonPath, ZConfLib::Ptr fallBack) : ZConfLib(fallBack),
daemonPath(daemonPath)
{ {
if (!daemonPath.isEmpty() && daemonPath.at(0) != '/' && daemonPath.at(0) != '.') if (!daemonPath.isEmpty() && daemonPath.at(0) != '/' && daemonPath.at(0) != '.')
this->daemonPath = QCoreApplication::applicationDirPath() + QChar('/') + daemonPath; this->daemonPath = QCoreApplication::applicationDirPath() + QChar('/') + daemonPath;
...@@ -71,7 +72,7 @@ public: ...@@ -71,7 +72,7 @@ public:
QString name() QString name()
{ {
return QString::fromUtf8("EmbeddedZeroConfLib@%1").arg(size_t(this),0,16); return QString::fromUtf8("EmbeddedZeroConfLib@%1").arg(size_t(this), 0, 16);
} }
bool tryStartDaemon() bool tryStartDaemon()
...@@ -84,7 +85,8 @@ public: ...@@ -84,7 +85,8 @@ public:
qDebug() << name() << " started " << daemonPath; qDebug() << name() << " started " << daemonPath;
return true; return true;
} else { } else {
this->setError(true, tr("%1 failed starting embedded daemon at %2").arg(name()).arg(daemonPath)); this->setError(true, tr("%1 failed starting embedded daemon at %2")
.arg(name()).arg(daemonPath));
} }
} }
return false; return false;
...@@ -99,7 +101,7 @@ public: ...@@ -99,7 +101,7 @@ public:
{ {
if (bRef){ if (bRef){
embeddedLib::DNSServiceRefDeallocate(*reinterpret_cast<DNSServiceRef*>(bRef)); embeddedLib::DNSServiceRefDeallocate(*reinterpret_cast<DNSServiceRef*>(bRef));
*bRef=0; *bRef = 0;
} }
} }
...@@ -107,7 +109,7 @@ public: ...@@ -107,7 +109,7 @@ public:
{ {
int sock = refSockFD(cRef); int sock = refSockFD(cRef);
if (sock>0) if (sock>0)
shutdown(sock,SHUT_RDWR); shutdown(sock, SHUT_RDWR);
} }
void destroyConnection(ConnectionRef *sdRef) void destroyConnection(ConnectionRef *sdRef)
...@@ -127,8 +129,11 @@ public: ...@@ -127,8 +129,11 @@ public: