summaryrefslogtreecommitdiffstats
path: root/dnssd
diff options
context:
space:
mode:
Diffstat (limited to 'dnssd')
-rw-r--r--dnssd/domainbrowser.cpp21
-rw-r--r--dnssd/publicservice.cpp36
-rw-r--r--dnssd/query.cpp22
-rw-r--r--dnssd/remoteservice.cpp10
-rw-r--r--dnssd/responder.cpp14
-rw-r--r--dnssd/responder.h15
-rw-r--r--dnssd/servicebrowser.cpp18
7 files changed, 93 insertions, 43 deletions
diff --git a/dnssd/domainbrowser.cpp b/dnssd/domainbrowser.cpp
index 294ce2576..3739bc520 100644
--- a/dnssd/domainbrowser.cpp
+++ b/dnssd/domainbrowser.cpp
@@ -34,6 +34,7 @@
namespace DNSSD
{
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
AvahiLookupResultFlags, void* context);
@@ -41,12 +42,13 @@ void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBr
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
void* context);
#endif
+#endif
-class DomainBrowserPrivate
+class DomainBrowserPrivate
{
public:
- DomainBrowserPrivate(DomainBrowser* owner) : m_browseLAN(false), m_started(false),
+ DomainBrowserPrivate(DomainBrowser* owner) : m_browseLAN(false), m_started(false),
m_browser(0), m_owner(owner) {}
~DomainBrowserPrivate() { if (m_browser) avahi_domain_browser_free(m_browser); }
QStringList m_domains;
@@ -55,7 +57,7 @@ public:
bool m_started;
AvahiDomainBrowser* m_browser;
DomainBrowser* m_owner;
-};
+};
void DomainBrowserPrivate::customEvent(QCustomEvent* event)
{
@@ -66,7 +68,7 @@ void DomainBrowserPrivate::customEvent(QCustomEvent* event)
}
}
-
+
DomainBrowser::DomainBrowser(QObject *parent) : QObject(parent)
{
d = new DomainBrowserPrivate(this);
@@ -100,7 +102,8 @@ void DomainBrowser::startBrowse()
if (ServiceBrowser::isAvailable()!=ServiceBrowser::Working) return;
QStringList::const_iterator itEnd = d->m_domains.end();
for (QStringList::const_iterator it=d->m_domains.begin(); it!=itEnd; ++it ) emit domainAdded(*it);
- if (d->m_browseLAN)
+#ifdef HAVE_DNSSD
+ if (d->m_browseLAN)
#ifdef AVAHI_API_0_6
d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
"local.", AVAHI_DOMAIN_BROWSER_BROWSE, (AvahiLookupFlags)0, domains_callback, this);
@@ -108,6 +111,7 @@ void DomainBrowser::startBrowse()
d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
"local.", AVAHI_DOMAIN_BROWSER_BROWSE, domains_callback, this);
#endif
+#endif
}
void DomainBrowser::gotNewDomain(const QString& domain)
@@ -128,7 +132,7 @@ void DomainBrowser::domainListChanged(int message,int)
if (message!=KIPCDomainsChanged) return;
bool was_started = d->m_started;
- if (d->m_browser) {
+ if (d->m_browser) {
avahi_domain_browser_free(d->m_browser); // LAN query
d->m_browser=0;
}
@@ -163,6 +167,7 @@ bool DomainBrowser::isRunning() const
void DomainBrowser::virtual_hook(int, void*)
{}
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
AvahiLookupResultFlags,void* context)
@@ -173,11 +178,11 @@ void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBr
{
QObject *obj = reinterpret_cast<QObject*>(context);
AddRemoveEvent* arev=new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
- AddRemoveEvent::Remove, QString::null, QString::null,
+ AddRemoveEvent::Remove, QString::null, QString::null,
DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev);
}
-
+#endif
}
#include "domainbrowser.moc"
diff --git a/dnssd/publicservice.cpp b/dnssd/publicservice.cpp
index ad1ebdbb6..6432b4f6a 100644
--- a/dnssd/publicservice.cpp
+++ b/dnssd/publicservice.cpp
@@ -45,9 +45,11 @@ namespace DNSSD
{
static unsigned long publicIP();
+#ifdef HAVE_DNSSD
void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context);
+#endif
-class PublicServicePrivate
+class PublicServicePrivate
{
public:
PublicServicePrivate() : m_published(false), m_running(false), m_collision(false), m_group(false)
@@ -59,8 +61,8 @@ public:
void commit()
{
if (!m_collision) avahi_entry_group_commit(m_group);
- }
-
+ }
+
};
PublicService::PublicService(const QString& name, const QString& type, unsigned int port,
@@ -68,7 +70,7 @@ PublicService::PublicService(const QString& name, const QString& type, unsigned
: QObject(), ServiceBase(name, type, QString::null, domain, port)
{
d = new PublicServicePrivate;
- if (Responder::self().client()) {
+ 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)));
}
@@ -99,7 +101,7 @@ void PublicService::setServiceName(const QString& serviceName)
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
- }
+ }
}
void PublicService::setDomain(const QString& domain)
@@ -108,7 +110,7 @@ void PublicService::setDomain(const QString& domain)
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
- }
+ }
}
@@ -118,7 +120,7 @@ void PublicService::setType(const QString& type)
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
- }
+ }
}
void PublicService::setPort(unsigned short port)
@@ -127,7 +129,7 @@ void PublicService::setPort(unsigned short port)
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
- }
+ }
}
void PublicService::setTextData(const QMap<QString,QString>& textData)
@@ -136,7 +138,7 @@ void PublicService::setTextData(const QMap<QString,QString>& textData)
if (d->m_running) {
avahi_entry_group_reset(d->m_group);
tryApply();
- }
+ }
}
bool PublicService::isPublished() const
@@ -160,14 +162,14 @@ bool PublicService::fillEntryGroup()
{
AvahiStringList *s=0;
QMap<QString,QString>::ConstIterator itEnd = m_textData.end();
- for (QMap<QString,QString>::ConstIterator it = m_textData.begin(); it!=itEnd ; ++it)
+ for (QMap<QString,QString>::ConstIterator it = m_textData.begin(); it!=itEnd ; ++it)
s = avahi_string_list_add_pair(s, it.key().utf8(),it.data().utf8());
#ifdef AVAHI_API_0_6
- bool res = (!avahi_entry_group_add_service_strlst(d->m_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0,
+ bool res = (!avahi_entry_group_add_service_strlst(d->m_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0,
m_serviceName.isNull() ? avahi_client_get_host_name(Responder::self().client()) : m_serviceName.utf8().data(),
m_type.ascii(),domainToDNS(m_domain),m_hostName.utf8(),m_port,s));
#else
- bool res = (!avahi_entry_group_add_service_strlst(d->m_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
+ bool res = (!avahi_entry_group_add_service_strlst(d->m_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
m_serviceName.isNull() ? avahi_client_get_host_name(Responder::self().client()) : m_serviceName.utf8().data(),
m_type.ascii(),m_domain.utf8(),m_hostName.utf8(),m_port,s));
#endif
@@ -199,22 +201,25 @@ void PublicService::clientState(AvahiClientState s)
tryApply();
}
}
-}
+}
void PublicService::publishAsync()
{
if (d->m_running) stop();
-
+
if (!d->m_group) {
emit published(false);
return;
}
+#ifdef HAVE_DNSSD
AvahiClientState s=Responder::self().state();
- d->m_running=true;
+#endif
+ d->m_running=true;
d->m_collision=true; // make it look like server is getting out of collision to force registering
clientState(s);
}
+#ifdef HAVE_DNSSD
void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context)
{
QObject *obj = reinterpret_cast<QObject*>(context);
@@ -222,6 +227,7 @@ void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context)
PublishEvent* pev=new PublishEvent(s==AVAHI_ENTRY_GROUP_ESTABLISHED);
QApplication::postEvent(obj, pev);
}
+#endif
const KURL PublicService::toInvitation(const QString& host)
{
diff --git a/dnssd/query.cpp b/dnssd/query.cpp
index 27b297816..cab14b6ad 100644
--- a/dnssd/query.cpp
+++ b/dnssd/query.cpp
@@ -18,7 +18,7 @@
* Boston, MA 02110-1301, USA.
*/
-#include "query.h"
+#include "query.h"
#include "responder.h"
#include "remoteservice.h"
#include "sdevent.h"
@@ -35,6 +35,7 @@
namespace DNSSD
{
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void services_callback(AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* name,
@@ -49,10 +50,11 @@ void types_callback(AvahiServiceTypeBrowser*, AvahiIfIndex, AvahiProtocol, Avahi
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
void* context);
#endif
+#endif
enum BrowserType { Types, Services };
-class QueryPrivate
+class QueryPrivate
{
public:
QueryPrivate(const QString& type, const QString& domain) : m_finished(false), m_browser(0),
@@ -81,7 +83,7 @@ Query::~Query()
case Services: avahi_service_browser_free((AvahiServiceBrowser*)d->m_browser); break;
case Types: avahi_service_type_browser_free((AvahiServiceTypeBrowser*)d->m_browser); break;
}
- }
+ }
delete d;
}
@@ -106,6 +108,7 @@ void Query::startQuery()
d->m_finished = false;
if (d->m_type=="_services._dns-sd._udp") {
d->m_browserType = Types;
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
d->m_browser = avahi_service_type_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
domainToDNS(d->m_domain), (AvahiLookupFlags)0, types_callback, this);
@@ -113,8 +116,10 @@ void Query::startQuery()
d->m_browser = avahi_service_type_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
d->m_domain.utf8(), types_callback, this);
#endif
+#endif
} else {
d->m_browserType = Services;
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
d->m_browser = avahi_service_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
d->m_type.ascii(),domainToDNS(d->m_domain), (AvahiLookupFlags)0, services_callback,this);
@@ -122,6 +127,7 @@ void Query::startQuery()
d->m_browser = avahi_service_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
d->m_type.ascii(),d->m_domain.utf8(),services_callback,this);
#endif
+#endif
}
if (d->m_browser) {
d->m_running=true;
@@ -152,17 +158,18 @@ void Query::timeout()
emit finished();
}
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
-void services_callback (AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
+void services_callback (AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
const char* serviceName, const char* regtype, const char* replyDomain, AvahiLookupResultFlags, void* context)
#else
-void services_callback (AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
+void services_callback (AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
const char* serviceName, const char* regtype, const char* replyDomain, void* context)
#endif
{
QObject *obj = reinterpret_cast<QObject*>(context);
AddRemoveEvent* arev = new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
- AddRemoveEvent::Remove, QString::fromUtf8(serviceName), regtype,
+ AddRemoveEvent::Remove, QString::fromUtf8(serviceName), regtype,
DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev);
}
@@ -177,10 +184,11 @@ void types_callback(AvahiServiceTypeBrowser*, AvahiIfIndex, AvahiProtocol, Avahi
{
QObject *obj = reinterpret_cast<QObject*>(context);
AddRemoveEvent* arev = new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
- AddRemoveEvent::Remove, QString::null, regtype,
+ AddRemoveEvent::Remove, QString::null, regtype,
DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev);
}
+#endif
}
#include "query.moc"
diff --git a/dnssd/remoteservice.cpp b/dnssd/remoteservice.cpp
index 9fa1a3fe2..8205aea00 100644
--- a/dnssd/remoteservice.cpp
+++ b/dnssd/remoteservice.cpp
@@ -38,6 +38,7 @@
namespace DNSSD
{
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto, AvahiResolverEvent e,
const char* name, const char* type, const char* domain, const char* hostname, const AvahiAddress* a,
@@ -47,6 +48,7 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto,
const char* name, const char* type, const char* domain, const char* hostname, const AvahiAddress* a,
uint16_t port, AvahiStringList* txt, void* context);
#endif
+#endif
class RemoteServicePrivate : public Responder
{
@@ -106,6 +108,7 @@ void RemoteService::resolveAsync()
if (d->m_running) return;
d->m_resolved = false;
// FIXME: first protocol should be set?
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
d->m_resolver = avahi_service_resolver_new(Responder::self().client(),AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
m_serviceName.utf8(), m_type.ascii(), domainToDNS(m_domain), AVAHI_PROTO_UNSPEC, AVAHI_LOOKUP_NO_ADDRESS,
@@ -114,6 +117,7 @@ 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);
}
@@ -160,10 +164,11 @@ QDataStream & operator>> (QDataStream & s, RemoteService & a)
Q_INT8 resolved;
operator>>(s,(static_cast<ServiceBase&>(a)));
s >> resolved;
- a.d->m_resolved = (resolved == 1);
+ a.d->m_resolved = (resolved == 1);
return s;
}
+#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent e,
const char*, const char*, const char*, const char* hostname, const AvahiAddress*,
@@ -177,7 +182,7 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiR
QObject *obj = reinterpret_cast<QObject*>(context);
if (e != AVAHI_RESOLVER_FOUND) {
ErrorEvent err;
- QApplication::sendEvent(obj, &err);
+ QApplication::sendEvent(obj, &err);
return;
}
QMap<QString,QString> map;
@@ -191,6 +196,7 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiR
ResolveEvent rev(DNSToDomain(hostname),port,map);
QApplication::sendEvent(obj, &rev);
}
+#endif
}
diff --git a/dnssd/responder.cpp b/dnssd/responder.cpp
index 43be68b28..ae9182a30 100644
--- a/dnssd/responder.cpp
+++ b/dnssd/responder.cpp
@@ -33,16 +33,19 @@ namespace DNSSD
static KStaticDeleter<Responder> responder_sd;
Responder* Responder::m_self = 0;
-void client_callback(AvahiClient *, AvahiClientState s, void* u)
+#ifdef HAVE_DNSSD
+void client_callback(AvahiClient *, AvahiClientState s, void* u)
{
- Responder *r = reinterpret_cast<Responder*>(u);
+ Responder *r = reinterpret_cast<Responder*>(u);
emit (r->stateChanged(s));
}
+#endif
Responder::Responder()
{
int error;
+#ifdef HAVE_DNSSD
const AvahiPoll* poll = avahi_qt_poll_get();
#ifdef AVAHI_API_0_6
m_client = avahi_client_new(poll, AVAHI_CLIENT_IGNORE_USER_CONFIG,client_callback, this, &error);
@@ -50,11 +53,14 @@ Responder::Responder()
m_client = avahi_client_new(poll, client_callback, this, &error);
#endif
if (!m_client) kdWarning() << "Failed to create avahi client" << endl;
+#endif
}
-
+
Responder::~Responder()
{
+#ifdef HAVE_DNSSD
if (m_client) avahi_client_free(m_client);
+#endif
}
Responder& Responder::self()
@@ -68,6 +74,7 @@ void Responder::process()
qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
}
+#ifdef HAVE_DNSSD
AvahiClientState Responder::state() const
{
#ifdef AVAHI_API_0_6
@@ -76,6 +83,7 @@ AvahiClientState Responder::state() const
return (m_client) ? (avahi_client_get_state(m_client)) : AVAHI_CLIENT_DISCONNECTED;
#endif
}
+#endif
bool domainIsLocal(const QString& domain)
{
diff --git a/dnssd/responder.h b/dnssd/responder.h
index 32ccb7a0b..0eb59bfab 100644
--- a/dnssd/responder.h
+++ b/dnssd/responder.h
@@ -25,13 +25,18 @@
#include <qsocketnotifier.h>
#include <qsignal.h>
#include <config.h>
+#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
+#else
+#define DNSServiceRef void*
+#endif
+
namespace DNSSD
{
/**
This class should not be used directly.
-
+
@author Jakub Stachowski
@short Internal class wrapping avahi client
*/
@@ -45,22 +50,28 @@ public:
~Responder();
static Responder& self();
+#ifdef HAVE_DNSSD
AvahiClientState state() const;
AvahiClient* client() const { return m_client; }
+#endif
void process();
signals:
void stateChanged(AvahiClientState);
private:
+#ifdef HAVE_DNSSD
AvahiClient* m_client;
+#endif
static Responder* m_self;
+#ifdef HAVE_DNSSD
friend void client_callback(AvahiClient*, AvahiClientState, void*);
+#endif
};
/* Utils functions */
bool domainIsLocal(const QString& domain);
-// Encodes domain name using utf8() or IDN
+// Encodes domain name using utf8() or IDN
QCString domainToDNS(const QString &domain);
QString DNSToDomain(const char* domain);
diff --git a/dnssd/servicebrowser.cpp b/dnssd/servicebrowser.cpp
index 542580c1b..20e1b11e0 100644
--- a/dnssd/servicebrowser.cpp
+++ b/dnssd/servicebrowser.cpp
@@ -26,7 +26,9 @@
#include "responder.h"
#include "query.h"
#include "servicebrowser.h"
+#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
+#endif
#include <config.h>
namespace DNSSD
@@ -34,10 +36,10 @@ namespace DNSSD
const QString ServiceBrowser::AllServices = "_services._dns-sd._udp";
-class ServiceBrowserPrivate
+class ServiceBrowserPrivate
{
-public:
- ServiceBrowserPrivate() : m_running(false)
+public:
+ ServiceBrowserPrivate() : m_running(false)
{}
QValueList<RemoteService::Ptr> m_services;
QValueList<RemoteService::Ptr> m_duringResolve;
@@ -82,12 +84,16 @@ ServiceBrowser::ServiceBrowser(const QString& type,const QString& domain,int fla
const ServiceBrowser::State ServiceBrowser::isAvailable()
{
+#ifdef HAVE_DNSSD
AvahiClientState s = Responder::self().state();
#ifdef AVAHI_API_0_6
return (s==AVAHI_CLIENT_FAILURE) ? Stopped : Working;
#else
return (s==AVAHI_CLIENT_S_INVALID || s==AVAHI_CLIENT_DISCONNECTED) ? Stopped : Working;
-#endif
+#endif
+#else
+ return Unsupported;
+#endif
}
ServiceBrowser::~ ServiceBrowser()
{
@@ -158,7 +164,7 @@ void ServiceBrowser::removeDomain(const QString& domain)
{
while (d->resolvers[domain]) d->resolvers.remove(domain);
QValueList<RemoteService::Ptr>::Iterator it = d->m_services.begin();
- while (it!=d->m_services.end())
+ while (it!=d->m_services.end())
// use section to skip possible trailing dot
if ((*it)->domain().section('.',0) == domain.section('.',0)) {
emit serviceRemoved(*it);
@@ -209,7 +215,7 @@ void ServiceBrowser::virtual_hook(int, void*)
QValueList<RemoteService::Ptr>::Iterator ServiceBrowser::findDuplicate(RemoteService::Ptr src)
{
QValueList<RemoteService::Ptr>::Iterator itEnd = d->m_services.end();
- for (QValueList<RemoteService::Ptr>::Iterator it = d->m_services.begin(); it!=itEnd; ++it)
+ for (QValueList<RemoteService::Ptr>::Iterator it = d->m_services.begin(); it!=itEnd; ++it)
if ((src->type()==(*it)->type()) && (src->serviceName()==(*it)->serviceName()) &&
(src->domain() == (*it)->domain())) return it;
return itEnd;