summaryrefslogtreecommitdiffstats
path: root/dnssd
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-22 00:43:26 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-22 00:43:26 +0000
commit856eea7169f7a4605aed28392857e6c5c80c644c (patch)
treeef60da2c0582e3d606699d8bb9f98317531362a3 /dnssd
parent847c48556bc8f7c17bd201ced9381e2fbb2d5d09 (diff)
downloadtdelibs-856eea7169f7a4605aed28392857e6c5c80c644c.tar.gz
tdelibs-856eea7169f7a4605aed28392857e6c5c80c644c.zip
Remaining Avahi fixes
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1152787 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'dnssd')
-rw-r--r--dnssd/domainbrowser.cpp13
-rw-r--r--dnssd/publicservice.cpp39
-rw-r--r--dnssd/publicservice.h4
-rw-r--r--dnssd/query.cpp4
-rw-r--r--dnssd/remoteservice.cpp20
-rw-r--r--dnssd/responder.cpp3
-rw-r--r--dnssd/responder.h1
7 files changed, 77 insertions, 7 deletions
diff --git a/dnssd/domainbrowser.cpp b/dnssd/domainbrowser.cpp
index 3739bc520..69bde48fe 100644
--- a/dnssd/domainbrowser.cpp
+++ b/dnssd/domainbrowser.cpp
@@ -48,14 +48,21 @@ void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBr
class DomainBrowserPrivate
{
public:
- DomainBrowserPrivate(DomainBrowser* owner) : m_browseLAN(false), m_started(false),
- m_browser(0), m_owner(owner) {}
+ DomainBrowserPrivate(DomainBrowser* owner) : m_browseLAN(false), m_started(false)
+#ifdef HAVE_DNSSD
+ , m_browser(0), m_owner(owner)
+#endif
+ {}
+#ifdef HAVE_DNSSD
~DomainBrowserPrivate() { if (m_browser) avahi_domain_browser_free(m_browser); }
+#endif
QStringList m_domains;
virtual void customEvent(QCustomEvent* event);
bool m_browseLAN;
bool m_started;
+#ifdef HAVE_DNSSD
AvahiDomainBrowser* m_browser;
+#endif
DomainBrowser* m_owner;
};
@@ -132,10 +139,12 @@ void DomainBrowser::domainListChanged(int message,int)
if (message!=KIPCDomainsChanged) return;
bool was_started = d->m_started;
+#ifdef HAVE_DNSSD
if (d->m_browser) {
avahi_domain_browser_free(d->m_browser); // LAN query
d->m_browser=0;
}
+#endif
d->m_started = false;
// remove all domains and resolvers
diff --git a/dnssd/publicservice.cpp b/dnssd/publicservice.cpp
index 6432b4f6a..63ab6750b 100644
--- a/dnssd/publicservice.cpp
+++ b/dnssd/publicservice.cpp
@@ -30,12 +30,14 @@
#include <network/ksocketaddress.h>
#include <kurl.h>
#include <unistd.h>
+#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
#ifdef AVAHI_API_0_6
#include <avahi-client/publish.h>
#endif
#include <avahi-common/alternative.h>
#include <avahi-common/strlst.h>
+#endif
#include "sdevent.h"
#include "responder.h"
#include "servicebrowser.h"
@@ -52,15 +54,22 @@ void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context)
class PublicServicePrivate
{
public:
- PublicServicePrivate() : m_published(false), m_running(false), m_collision(false), m_group(false)
+ PublicServicePrivate() : m_published(false), m_running(false), m_collision(false)
+#ifdef HAVE_DNSSD
+ , m_group(false)
+#endif
{}
bool m_published;
bool m_running;
bool m_collision;
+#ifdef HAVE_DNSSD
AvahiEntryGroup* m_group;
+#endif
void commit()
{
+#ifdef HAVE_DNSSD
if (!m_collision) avahi_entry_group_commit(m_group);
+#endif
}
};
@@ -70,10 +79,12 @@ PublicService::PublicService(const QString& name, const QString& type, unsigned
: QObject(), ServiceBase(name, type, QString::null, domain, port)
{
d = new PublicServicePrivate;
+#ifdef HAVE_DNSSD
if (Responder::self().client()) {
d->m_group = avahi_entry_group_new(Responder::self().client(), publish_callback,this);
connect(&Responder::self(),SIGNAL(stateChanged(AvahiClientState)),this,SLOT(clientState(AvahiClientState)));
}
+#endif
if (domain.isNull())
if (Configuration::publishType()==Configuration::EnumPublishType::LAN) m_domain="local.";
else m_domain=Configuration::publishDomain();
@@ -82,7 +93,9 @@ PublicService::PublicService(const QString& name, const QString& type, unsigned
PublicService::~PublicService()
{
+#ifdef HAVE_DNSSD
if (d->m_group) avahi_entry_group_free(d->m_group);
+#endif
delete d;
}
@@ -98,47 +111,57 @@ void PublicService::tryApply()
void PublicService::setServiceName(const QString& serviceName)
{
m_serviceName = serviceName;
+#ifdef HAVE_DNSSD
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
}
+#endif
}
void PublicService::setDomain(const QString& domain)
{
m_domain = domain;
+#ifdef HAVE_DNSSD
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
}
+#endif
}
void PublicService::setType(const QString& type)
{
m_type = type;
+#ifdef HAVE_DNSSD
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
}
+#endif
}
void PublicService::setPort(unsigned short port)
{
m_port = port;
+#ifdef HAVE_DNSSD
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
}
+#endif
}
void PublicService::setTextData(const QMap<QString,QString>& textData)
{
m_textData = textData;
+#ifdef HAVE_DNSSD
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
}
+#endif
}
bool PublicService::isPublished() const
@@ -155,11 +178,14 @@ bool PublicService::publish()
void PublicService::stop()
{
+#ifdef HAVE_DNSSD
if (d->m_group) avahi_entry_group_reset(d->m_group);
+#endif
d->m_published = false;
}
bool PublicService::fillEntryGroup()
{
+#ifdef HAVE_DNSSD
AvahiStringList *s=0;
QMap<QString,QString>::ConstIterator itEnd = m_textData.end();
for (QMap<QString,QString>::ConstIterator it = m_textData.begin(); it!=itEnd ; ++it)
@@ -175,11 +201,15 @@ bool PublicService::fillEntryGroup()
#endif
avahi_string_list_free(s);
return res;
+#else
+ return FALSE;
+#endif
}
void PublicService::clientState(AvahiClientState s)
{
if (!d->m_running) return;
+#ifdef HAVE_DNSSD
switch (s) {
#ifdef AVAHI_API_0_6
case AVAHI_CLIENT_FAILURE:
@@ -201,22 +231,25 @@ void PublicService::clientState(AvahiClientState s)
tryApply();
}
}
+#endif
}
void PublicService::publishAsync()
{
if (d->m_running) stop();
+#ifdef HAVE_DNSSD
if (!d->m_group) {
emit published(false);
return;
}
-#ifdef HAVE_DNSSD
AvahiClientState s=Responder::self().state();
#endif
d->m_running=true;
d->m_collision=true; // make it look like server is getting out of collision to force registering
+#ifdef HAVE_DNSSD
clientState(s);
+#endif
}
#ifdef HAVE_DNSSD
@@ -251,6 +284,7 @@ const KURL PublicService::toInvitation(const QString& host)
void PublicService::customEvent(QCustomEvent* event)
{
+#ifdef HAVE_DNSSD
if (event->type()==QEvent::User+SD_PUBLISH) {
if (!static_cast<PublishEvent*>(event)->m_ok) {
setServiceName(QString::fromUtf8(avahi_alternative_service_name(m_serviceName.utf8())));
@@ -259,6 +293,7 @@ void PublicService::customEvent(QCustomEvent* event)
d->m_published=true;
emit published(true);
}
+#endif
}
void PublicService::virtual_hook(int, void*)
diff --git a/dnssd/publicservice.h b/dnssd/publicservice.h
index ff090d354..31897a03e 100644
--- a/dnssd/publicservice.h
+++ b/dnssd/publicservice.h
@@ -23,7 +23,11 @@
#include <qobject.h>
#include <dnssd/servicebase.h>
+#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
+#else
+#define AvahiClientState void*
+#endif
class KURL;
namespace DNSSD
diff --git a/dnssd/query.cpp b/dnssd/query.cpp
index cab14b6ad..163891c71 100644
--- a/dnssd/query.cpp
+++ b/dnssd/query.cpp
@@ -26,10 +26,12 @@
#include <qapplication.h>
#include <qtimer.h>
+#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
#ifdef AVAHI_API_0_6
#include <avahi-client/lookup.h>
#endif
+#endif
#define TIMEOUT_LAN 200
@@ -78,12 +80,14 @@ Query::Query(const QString& type, const QString& domain)
Query::~Query()
{
+#ifdef HAVE_DNSSD
if (d->m_browser) {
switch (d->m_browserType) {
case Services: avahi_service_browser_free((AvahiServiceBrowser*)d->m_browser); break;
case Types: avahi_service_type_browser_free((AvahiServiceTypeBrowser*)d->m_browser); break;
}
}
+#endif
delete d;
}
diff --git a/dnssd/remoteservice.cpp b/dnssd/remoteservice.cpp
index 8205aea00..865c3be7f 100644
--- a/dnssd/remoteservice.cpp
+++ b/dnssd/remoteservice.cpp
@@ -27,11 +27,13 @@
#include <sys/types.h>
#endif
#include <netinet/in.h>
+#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
#include <avahi-common/strlst.h>
#ifdef AVAHI_API_0_6
#include <avahi-client/lookup.h>
#endif
+#endif
#include "remoteservice.h"
#include "responder.h"
#include "sdevent.h"
@@ -53,15 +55,21 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto,
class RemoteServicePrivate : public Responder
{
public:
- RemoteServicePrivate() : m_resolved(false), m_running(false), m_resolver(0) {}
+ RemoteServicePrivate() : m_resolved(false), m_running(false)
+#ifdef HAVE_DNSSD
+ , m_resolver(0)
+#endif
+ {}
bool m_resolved;
bool m_running;
+#ifdef HAVE_DNSSD
AvahiServiceResolver* m_resolver;
void stop() {
m_running = false;
if (m_resolver) avahi_service_resolver_free(m_resolver);
m_resolver=0;
}
+#endif
};
RemoteService::RemoteService(const QString& label)
@@ -91,7 +99,9 @@ RemoteService::RemoteService(const KURL& url)
RemoteService::~RemoteService()
{
+#ifdef HAVE_DNSSD
if (d->m_resolver) avahi_service_resolver_free(d->m_resolver);
+#endif
delete d;
}
@@ -99,7 +109,9 @@ bool RemoteService::resolve()
{
resolveAsync();
while (d->m_running && !d->m_resolved) Responder::self().process();
+#ifdef HAVE_DNSSD
d->stop();
+#endif
return d->m_resolved;
}
@@ -117,9 +129,9 @@ void RemoteService::resolveAsync()
d->m_resolver = avahi_service_resolver_new(Responder::self().client(),AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
m_serviceName.utf8(), m_type.ascii(), m_domain.utf8(), AVAHI_PROTO_UNSPEC, resolve_callback, this);
#endif
-#endif
if (d->m_resolver) d->m_running=true;
else emit resolved(false);
+#endif
}
bool RemoteService::isResolved() const
@@ -130,7 +142,9 @@ bool RemoteService::isResolved() const
void RemoteService::customEvent(QCustomEvent* event)
{
if (event->type() == QEvent::User+SD_ERROR) {
+#ifdef HAVE_DNSSD
d->stop();
+#endif
d->m_resolved=false;
emit resolved(false);
}
@@ -160,7 +174,9 @@ QDataStream & operator<< (QDataStream & s, const RemoteService & a)
QDataStream & operator>> (QDataStream & s, RemoteService & a)
{
// stop any possible resolve going on
+#ifdef HAVE_DNSSD
a.d->stop();
+#endif
Q_INT8 resolved;
operator>>(s,(static_cast<ServiceBase&>(a)));
s >> resolved;
diff --git a/dnssd/responder.cpp b/dnssd/responder.cpp
index ae9182a30..d92d30261 100644
--- a/dnssd/responder.cpp
+++ b/dnssd/responder.cpp
@@ -24,8 +24,9 @@
#include <kstaticdeleter.h>
#include <kidna.h>
#include <kdebug.h>
+#ifdef HAVE_DNSSD
#include <avahi-qt3/qt-watch.h>
-
+#endif
namespace DNSSD
{
diff --git a/dnssd/responder.h b/dnssd/responder.h
index 0eb59bfab..50c870aae 100644
--- a/dnssd/responder.h
+++ b/dnssd/responder.h
@@ -29,6 +29,7 @@
#include <avahi-client/client.h>
#else
#define DNSServiceRef void*
+#define AvahiClientState void*
#endif
namespace DNSSD