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 @@
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 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" void cAvahiBrowseReply(
AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
AvahiLookupResultFlags /*flags*/, void* context);
extern "C" {
typedef const AvahiPoll* (*AvahiSimplePollGet)(AvahiSimplePoll *s);
......@@ -72,17 +77,20 @@ typedef AvahiSimplePoll *(*AvahiSimplePollNewPtr)(void);
typedef int (*AvahiSimplePollIteratePtr)(AvahiSimplePoll *s, int sleep_time);
typedef void (*AvahiSimplePollQuitPtr)(AvahiSimplePoll *s);
typedef void (*AvahiSimplePollFreePtr)(AvahiSimplePoll *s);
typedef AvahiClient* (*AvahiClientNewPtr)(const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback,
void *userdata, int *error);
typedef 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 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 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);
}
......@@ -114,7 +122,9 @@ private:
QLibrary nativeLib;
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
// dynamic linking
......@@ -164,7 +174,7 @@ public:
}
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();
......@@ -202,8 +212,9 @@ public:
MyAvahiConnection *connection = reinterpret_cast<MyAvahiConnection *>(cRef);
if (!m_serviceResolverNew)
return kDNSServiceErr_Unknown;
AvahiServiceResolver *resolver = m_serviceResolverNew(connection->client, interfaceIndex, AVAHI_PROTO_INET, name, regtype, domain, AVAHI_PROTO_INET,
AvahiLookupFlags(0), &cAvahiResolveReply, gatherer);
AvahiServiceResolver *resolver = m_serviceResolverNew(
connection->client, interfaceIndex, AVAHI_PROTO_INET, name, regtype, domain,
AVAHI_PROTO_INET, AvahiLookupFlags(0), &cAvahiResolveReply, gatherer);
//*sdRef = reinterpret_cast<DNSServiceRef>(resolver); // add for restart?
if (!resolver)
return kDNSServiceErr_Unknown; // avahi_strerror(avahi_client_errno(connection->client));
......@@ -223,20 +234,23 @@ public:
}
DNSServiceErrorType reconfirmRecord(ConnectionRef cRef, uint32_t interfaceIndex,
const char *name, const char *type, const char *domain,
const char * /*fullname */)
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);
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)
const char *regtype, const char *domain,
ServiceBrowserPrivate *browser)
{
if (!sdRef) {
qDebug() << "Error: sdRef is null in browse";
......@@ -245,9 +259,12 @@ public:
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);
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;
......@@ -256,9 +273,9 @@ public:
return kDNSServiceErr_NoError;
}
DNSServiceErrorType getProperty(const char * /*property*/, // Requested property (i.e. kDNSServiceProperty_DaemonVersion)
void * /*result*/, // Pointer to place to store result
uint32_t * /*size*/ // size of result location
DNSServiceErrorType getProperty(const char * /*property*/,
void * /*result*/,
uint32_t * /*size*/
)
{
return 0;
......@@ -292,12 +309,14 @@ public:
}
/* Allocate a new client */
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 (m_simplePollFree)
m_simplePollFree(connection->simple_poll);
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;
}
*sdRef = reinterpret_cast<ConnectionRef>(connection);
......@@ -337,19 +356,22 @@ extern "C" void cAvahiResolveReply(
qDebug() << "context was null in cAvahiResolveReply";
return;
}
AvahiStringList *txtAtt=0;
AvahiStringList *txtAtt = 0;
const unsigned char emptyTxt[1]="";
switch (event) {
case AVAHI_RESOLVER_FAILURE:
sg->serviceResolveReply(0, kDNSServiceErr_Timeout, interface, 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;
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,-1);
sg->txtFieldReply(
kDNSServiceFlagsAdd | ((txtAtt->next || address)?kDNSServiceFlagsMoreComing:0),
kDNSServiceErr_NoError, static_cast<unsigned short>(txtAtt->size),
txtAtt->text, -1);
txtAtt = txtAtt->next;
}
if (address){
......@@ -358,20 +380,23 @@ extern "C" void cAvahiResolveReply(
//#ifdef HAVE_SA_LEN
switch (address->proto){
case (AVAHI_PROTO_INET):
memset(&ipv4,0,sizeof(ipv4));
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);
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));
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);
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();
qDebug() << "Warning: ignoring address with protocol " << address->proto
<< " for service " << sg->fullName();
}
}
break;
......@@ -385,8 +410,10 @@ extern "C" void cAvahiResolveReply(
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)
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)
......@@ -422,13 +449,15 @@ extern "C" void cAvahiClientReply (AvahiClient * /*s*/, AvahiClientState state,
lib->setError(false, lib->tr("cAvahiClient, still connecting, no server available"));
break;
default:
lib->setError(true, lib->tr("Error: unexpected state %1 in cAvahiClientReply, ignoring it").arg(state));
lib->setError(true, lib->tr("Error: unexpected state %1 in cAvahiClientReply, ignoring it")
.arg(state));
}
}
extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
AvahiLookupResultFlags /*flags*/, void* context)
extern "C" void cAvahiBrowseReply(
AvahiServiceBrowser * /*b*/, AvahiIfIndex interface, AvahiProtocol /*protocol*/,
AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
AvahiLookupResultFlags /*flags*/, void* context)
{
ServiceBrowserPrivate *browser = reinterpret_cast<ServiceBrowserPrivate *>(context);
......@@ -440,12 +469,13 @@ extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex inte
browser->browseReply(kDNSServiceFlagsMoreComing, 0, kDNSServiceErr_Unknown, 0, 0, 0);
break;
case AVAHI_BROWSER_NEW:
browser->browseReply(kDNSServiceFlagsAdd|kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface), kDNSServiceErr_NoError,
browser->browseReply(kDNSServiceFlagsAdd|kDNSServiceFlagsMoreComing,
static_cast<uint32_t>(interface), kDNSServiceErr_NoError,
name, type, domain);
break;
case AVAHI_BROWSER_REMOVE:
browser->browseReply(kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface), kDNSServiceErr_NoError,
name, type, domain);
browser->browseReply(kDNSServiceFlagsMoreComing, static_cast<uint32_t>(interface),
kDNSServiceErr_NoError, name, type, domain);
break;
case AVAHI_BROWSER_ALL_FOR_NOW:
browser->updateFlowStatusForFlags(0);
......@@ -454,7 +484,9 @@ extern "C" void cAvahiBrowseReply(AvahiServiceBrowser * /*b*/, AvahiIfIndex inte
browser->updateFlowStatusForFlags(0);
break;
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:
// dynamic linking
if (!dnsSdLib.load()) {
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_resolve = reinterpret_cast<ResolvePtr>(dnsSdLib.resolve("DNSServiceResolve"));
......@@ -160,7 +160,7 @@ public:
}
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();
......@@ -173,7 +173,7 @@ public:
if (m_refDeallocate == 0) return;
if (bRef) {
m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(bRef));
*bRef=0;
*bRef = 0;
}
}
......@@ -181,14 +181,14 @@ public:
{
int sock = refSockFD(cRef);
if (sock>0)
shutdown(sock,SHUT_RDWR);
shutdown(sock, SHUT_RDWR);
}
void destroyConnection(ConnectionRef *sdRef) {
if (m_refDeallocate == 0) return;
if (sdRef) {
m_refDeallocate(*reinterpret_cast<DNSServiceRef *>(sdRef));
*sdRef=0;
*sdRef = 0;
}
}
......@@ -210,7 +210,8 @@ public:
{
if (m_queryRecord == 0) return kDNSServiceErr_Unsupported;
*sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return m_queryRecord(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
return m_queryRecord(sdRef, kDNSServiceFlagsShareConnection
| kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
interfaceIndex, fullname,
kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply, gatherer);
}
......@@ -224,7 +225,7 @@ public:
#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));
memset(&req, 0, sizeof(req));
req.ai_flags = 0;
req.ai_family = AF_UNSPEC;
req.ai_socktype = SOCK_STREAM;
......@@ -244,13 +245,14 @@ public:
#endif
}
*sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return m_getAddrInfo(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
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*/)
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
......@@ -270,10 +272,7 @@ public:
interfaceIndex, regtype, domain, &cBrowseReply, browser);
}
DNSServiceErrorType getProperty(const char *property, // Requested property (i.e. kDNSServiceProperty_DaemonVersion)
void *result, // Pointer to place to store result
uint32_t *size // size of result location
)
DNSServiceErrorType getProperty(const char *property, void *result, uint32_t *size)
{
if (m_getProperty == 0)
return kDNSServiceErr_Unsupported;
......@@ -325,7 +324,8 @@ public:
} else if (result == 0) {
// we are idle... could do something productive... :)
} else if (errno != EINTR) {
qDebug() << "select() returned " << result << " errno " << errno << strerror(errno);
qDebug() << "select() returned " << result << " errno " << errno
<< strerror(errno);
return false;
}
}
......
......@@ -60,7 +60,8 @@ class EmbeddedZConfLib : public ZConfLib
public:
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) != '.')
this->daemonPath = QCoreApplication::applicationDirPath() + QChar('/') + daemonPath;
......@@ -71,7 +72,7 @@ public:
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()
......@@ -84,7 +85,8 @@ public:
qDebug() << name() << " started " << daemonPath;
return true;
} 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;
......@@ -99,7 +101,7 @@ public:
{
if (bRef){
embeddedLib::DNSServiceRefDeallocate(*reinterpret_cast<DNSServiceRef*>(bRef));
*bRef=0;
*bRef = 0;
}
}
......@@ -107,7 +109,7 @@ public:
{
int sock = refSockFD(cRef);
if (sock>0)
shutdown(sock,SHUT_RDWR);
shutdown(sock, SHUT_RDWR);
}
void destroyConnection(ConnectionRef *sdRef)
......@@ -127,8 +129,11 @@ public:
ServiceGatherer *gatherer)
{
*sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return embeddedLib::DNSServiceResolve(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
interfaceIndex, name, regtype, domain, &cServiceResolveReply, gatherer);
return embeddedLib::DNSServiceResolve(sdRef, kDNSServiceFlagsShareConnection
| kDNSServiceFlagsSuppressUnusable
| kDNSServiceFlagsTimeout,
interfaceIndex, name, regtype, domain,
&cServiceResolveReply, gatherer);
}
DNSServiceErrorType queryRecord(ConnectionRef cRef,
......@@ -138,9 +143,12 @@ public:
ServiceGatherer *gatherer)
{
*sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return embeddedLib::DNSServiceQueryRecord(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
return embeddedLib::DNSServiceQueryRecord(sdRef, kDNSServiceFlagsShareConnection
| kDNSServiceFlagsSuppressUnusable
| kDNSServiceFlagsTimeout,
interfaceIndex, fullname,
kDNSServiceType_TXT, kDNSServiceClass_IN, &cTxtRecordReply ,gatherer);
kDNSServiceType_TXT, kDNSServiceClass_IN,
&cTxtRecordReply , gatherer);
}
DNSServiceErrorType getAddrInfo(ConnectionRef cRef,
......@@ -151,14 +159,16 @@ public:
ServiceGatherer *gatherer)
{
*sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return embeddedLib::DNSServiceGetAddrInfo(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable | kDNSServiceFlagsTimeout,
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*/)
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,
......@@ -175,14 +185,13 @@ public:
{
DNSServiceRef *sdRef = reinterpret_cast<DNSServiceRef *>(bRef);
*sdRef = reinterpret_cast<DNSServiceRef>(cRef);
return embeddedLib::DNSServiceBrowse(sdRef, kDNSServiceFlagsShareConnection | kDNSServiceFlagsSuppressUnusable,
interfaceIndex, regtype, domain, &cBrowseReply, browser);
return embeddedLib::DNSServiceBrowse(sdRef, kDNSServiceFlagsShareConnection
| kDNSServiceFlagsSuppressUnusable,
interfaceIndex, regtype, domain, &cBrowseReply,
browser);
}
DNSServiceErrorType getProperty(const char *property, /* Requested property (i.e. kDNSServiceProperty_DaemonVersion) */
void *result, /* Pointer to place to store result */
uint32_t *size /* size of result location */
)
DNSServiceErrorType getProperty(const char *property, void *result, uint32_t *size)
{
return embeddedLib::DNSServiceGetProperty(property, result, size);
}
......
......@@ -115,7 +115,8 @@ class ZeroConfLib
public:
ZeroConfLib();
ZConfLib::Ptr defaultLib();
void setDefaultLib(LibUsage usage, const QString &avahiLibName, const QString &dnsSdLibName, const QString &dnsSdDaemonPath);
void setDefaultLib(LibUsage usage, const QString &avahiLibName, const QString &dnsSdLibName,
const QString &dnsSdDaemonPath);
private:
QMutex m_lock;
......@@ -137,7 +138,8 @@ ZConfLib::Ptr ZeroConfLib::defaultLib(){
return m_defaultLib;
}
void ZeroConfLib::setDefaultLib(LibUsage usage, const QString &avahiLibName, const QString &dnsSdLibName, const QString &dnsSdDaemonPath){
void ZeroConfLib::setDefaultLib(LibUsage usage, const QString &avahiLibName,
const QString &dnsSdLibName, const QString &dnsSdDaemonPath){
QMutexLocker l(&m_lock);
switch (usage){
case (UseDnsSdOnly):
......@@ -153,7 +155,9 @@ void ZeroConfLib::setDefaultLib(LibUsage usage, const QString &avahiLibName, con
m_defaultLib = ZConfLib::createAvahiLib(avahiLibName, ZConfLib::createDnsSdLib(dnsSdLibName));
break;
case (UseAvahiOrDnsSdOrEmbedded):
m_defaultLib = ZConfLib::createAvahiLib(avahiLibName,ZConfLib::createDnsSdLib(dnsSdLibName, ZConfLib::createEmbeddedLib(dnsSdDaemonPath)));
m_defaultLib = ZConfLib::createAvahiLib(
avahiLibName, ZConfLib::createDnsSdLib(dnsSdLibName,
ZConfLib::createEmbeddedLib(dnsSdDaemonPath)));
break;
default:
qDebug() << "invalid usage " << usage;
......@@ -170,7 +174,8 @@ namespace ZeroConf {
\brief class representing a zeroconf service
Instances of this class are basically constant, but can be outdated. They are normally accessed through a Shared pointer.
Instances of this class are basically constant, but can be outdated. They are normally accessed
through a Shared pointer.
This design avoids race conditions when used though multiple threads.
\threadsafe
......@@ -203,7 +208,7 @@ QDebug operator<<(QDebug dbg, const Service &service)
<< "type:" << service.type() << ", domain:" << service.domain() << ", "
<< " fullName:" << service.fullName() << ", port:" << service.port()
<< ", txtRecord:{";
bool first=true;
bool first = true;
QHashIterator<QString, QString> i(service.txtRecord());
while (i.hasNext()){
i.next();
......@@ -216,7 +221,7 @@ QDebug operator<<(QDebug dbg, const Service &service)
dbg << "}, ";
if (const QHostInfo *host = service.host()){
dbg << "host:{" << host->hostName() << ", addresses[";
first=true;
first = true;
foreach (const QHostAddress &addr, host->addresses()){
if (first)
first = false;
......@@ -386,7 +391,8 @@ void ServiceBrowser::reconfirmService(Service::ConstPtr service)
// signals
/*!
\fn void ServiceBrowser::serviceChanged(Service::ConstPtr oldService, Service::ConstPtr newService, ServiceBrowser *browser)
\fn void ServiceBrowser::serviceChanged(
Service::ConstPtr oldService, Service::ConstPtr newService, ServiceBrowser *browser)
This signal is called when a service is added removed or changes.
Both oldService or newService might be null (covers both add and remove).
......@@ -412,23 +418,25 @@ void ServiceBrowser::reconfirmService(Service::ConstPtr service)
\fn void ServiceBrowser::servicesUpdated(ServiceBrowser *browser)
This signal is called when the list is updated.
It might collect several serviceChanged signals together, if you use the list returned by services(),
use this signal, not serviceChanged(), serviceAdded() or serviceRemoved() to know about changes to the list.
It might collect several serviceChanged signals together, if you use the list returned by
services(), use this signal, not serviceChanged(), serviceAdded() or serviceRemoved() to know
about changes to the list.
*/
// ----------------- library initialization impl -----------------
/*!
Sets the library used by future Service Browsers to preform the mdns queries.
This changes the default library used by the next MainConnection, it does not change the already instantiated
connections.
This changes the default library used by the next MainConnection, it does not change the already
instantiated connections.
\a usage can decide which libraries are tried,
\a libName should be the name (or path) to the libdns library,
\a daemonPath is the path to the daemon executable which should be started by the embedded library if no daemon
is found.
\a daemonPath is the path to the daemon executable which should be started by the embedded library
if no daemon is found.
\threadsafe
*/
void setDefaultZConfLib(LibUsage usage, const QString &avahiLibName, const QString &dnsSdLibName, const QString &dnsSdDaemonPath)
void setDefaultZConfLib(LibUsage usage, const QString &avahiLibName, const QString &dnsSdLibName,
const QString &dnsSdDaemonPath)
{
zeroConfLibInstance()->setDefaultLib(usage, avahiLibName, dnsSdLibName, dnsSdDaemonPath);
}
......@@ -442,24 +450,28 @@ extern "C" void DNSSD_API cServiceResolveReply(DNSServiceRef
DNSServiceErrorType errorCode,
const char *fullname,