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,13 +56,18 @@
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*/,
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);
......@@ -72,16 +77,19 @@ 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,
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,
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));
......@@ -229,14 +240,17 @@ public:
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,11 +449,13 @@ 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*/,
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)
{
......@@ -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);
}
......
This diff is collapsed.
......@@ -142,7 +142,8 @@ enum LibUsage {
UseAvahiOrDnsSdOrEmbedded
};
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);
}
......
......@@ -78,20 +78,24 @@ public:
virtual void refDeallocate(DNSServiceRef sdRef) = 0;
virtual void browserDeallocate(BrowserRef *sdRef) = 0;
virtual DNSServiceErrorType resolve(ConnectionRef cRef, DNSServiceRef *sdRef, uint32_t interfaceIndex,
const char *name, const char *regtype, const char *domain,
virtual DNSServiceErrorType resolve(ConnectionRef cRef, DNSServiceRef *sdRef,
uint32_t interfaceIndex, 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,
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; // opt
virtual DNSServiceErrorType browse(ConnectionRef cRef, BrowserRef *sdRef, uint32_t interfaceIndex,
const char *regtype, const char *domain, ServiceBrowserPrivate *browser) = 0;
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 ProcessStatus processResult(ConnectionRef sdRef) = 0;
virtual DNSServiceErrorType createConnection(ConnectionRef *sdRef) = 0;
......@@ -109,7 +113,8 @@ protected:
QString m_errorMsg;
};
/// class that gathers all needed info on a service, all its methods (creation included) are supposed to be called by the listener/reaction thread
/// class 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;
......@@ -147,8 +152,9 @@ public:
bool currentServiceCanBePublished();
~ServiceGatherer();
static Ptr createGatherer(const QString &newService, const QString &newType, const QString &newDomain,
const QString &fullName, uint32_t interfaceIndex, ServiceBrowserPrivate *serviceBrowser);
static Ptr createGatherer(const QString &newService, const QString &newType,
const QString &newDomain, const QString &fullName,
uint32_t interfaceIndex, ServiceBrowserPrivate *serviceBrowser);
void serviceResolveReply(DNSServiceFlags flags, uint32_t interfaceIndex,
DNSServiceErrorType errorCode, const char *hosttarget,
......@@ -160,17 +166,18 @@ public:
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 addrReply(DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *hostname,
const struct sockaddr *address, uint32_t ttl);
void maybeRemove();
void stop();
void reload(qint32 interfaceIndex=0);
void reload(qint32 interfaceIndex = 0);
void remove();
void reconfirm();
ZConfLib::Ptr lib();
private:
ServiceGatherer(const QString &newService, const QString &newType, const QString &newDomain,
const QString &fullName, uint32_t interfaceIndex, ServiceBrowserPrivate *serviceBrowser);
const QString &fullName, uint32_t interfaceIndex,
ServiceBrowserPrivate *serviceBrowser);
DNSServiceRef resolveConnection;
DNSServiceRef txtConnection;
......@@ -208,7 +215,7 @@ public:
~MainConnection();
QMutex *lock();
void waitStartup();
void stop(bool wait=true);
void stop(bool wait = true);
void addBrowser(ServiceBrowserPrivate *browser);
void removeBrowser(ServiceBrowserPrivate *browser);
void updateFlowStatusForCancel();
......@@ -225,7 +232,7 @@ public:
QStringList errors();
void clearErrors();
void appendError(const QStringList &msgs,bool fullFailure);
void appendError(const QStringList &msgs, bool fullFailure);
bool isOk();
private:
mutable QMutex m_lock;
......@@ -277,9 +284,10 @@ public:
void reconfirmService(Service::ConstPtr s);
void browseReply(DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName,
const char *regtype, const char *replyDomain);
void serviceChanged(const Service::ConstPtr &oldService, const Service::ConstPtr &newService, ServiceBrowser *browser);