Attempt to fix compilation when Avahi is not available

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1152784 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 15 years ago
parent cfa3abbed0
commit 847c48556b

@ -34,6 +34,7 @@
namespace DNSSD namespace DNSSD
{ {
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain, void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
AvahiLookupResultFlags, void* context); 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 domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
void* context); void* context);
#endif #endif
#endif
class DomainBrowserPrivate class DomainBrowserPrivate
{ {
public: 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) {} m_browser(0), m_owner(owner) {}
~DomainBrowserPrivate() { if (m_browser) avahi_domain_browser_free(m_browser); } ~DomainBrowserPrivate() { if (m_browser) avahi_domain_browser_free(m_browser); }
QStringList m_domains; QStringList m_domains;
@ -55,7 +57,7 @@ public:
bool m_started; bool m_started;
AvahiDomainBrowser* m_browser; AvahiDomainBrowser* m_browser;
DomainBrowser* m_owner; DomainBrowser* m_owner;
}; };
void DomainBrowserPrivate::customEvent(QCustomEvent* event) void DomainBrowserPrivate::customEvent(QCustomEvent* event)
{ {
@ -66,7 +68,7 @@ void DomainBrowserPrivate::customEvent(QCustomEvent* event)
} }
} }
DomainBrowser::DomainBrowser(QObject *parent) : QObject(parent) DomainBrowser::DomainBrowser(QObject *parent) : QObject(parent)
{ {
d = new DomainBrowserPrivate(this); d = new DomainBrowserPrivate(this);
@ -100,7 +102,8 @@ void DomainBrowser::startBrowse()
if (ServiceBrowser::isAvailable()!=ServiceBrowser::Working) return; if (ServiceBrowser::isAvailable()!=ServiceBrowser::Working) return;
QStringList::const_iterator itEnd = d->m_domains.end(); QStringList::const_iterator itEnd = d->m_domains.end();
for (QStringList::const_iterator it=d->m_domains.begin(); it!=itEnd; ++it ) emit domainAdded(*it); 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 #ifdef AVAHI_API_0_6
d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 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); "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, d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
"local.", AVAHI_DOMAIN_BROWSER_BROWSE, domains_callback, this); "local.", AVAHI_DOMAIN_BROWSER_BROWSE, domains_callback, this);
#endif #endif
#endif
} }
void DomainBrowser::gotNewDomain(const QString& domain) void DomainBrowser::gotNewDomain(const QString& domain)
@ -128,7 +132,7 @@ void DomainBrowser::domainListChanged(int message,int)
if (message!=KIPCDomainsChanged) return; if (message!=KIPCDomainsChanged) return;
bool was_started = d->m_started; bool was_started = d->m_started;
if (d->m_browser) { if (d->m_browser) {
avahi_domain_browser_free(d->m_browser); // LAN query avahi_domain_browser_free(d->m_browser); // LAN query
d->m_browser=0; d->m_browser=0;
} }
@ -163,6 +167,7 @@ bool DomainBrowser::isRunning() const
void DomainBrowser::virtual_hook(int, void*) void DomainBrowser::virtual_hook(int, void*)
{} {}
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain, void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
AvahiLookupResultFlags,void* context) AvahiLookupResultFlags,void* context)
@ -173,11 +178,11 @@ void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBr
{ {
QObject *obj = reinterpret_cast<QObject*>(context); QObject *obj = reinterpret_cast<QObject*>(context);
AddRemoveEvent* arev=new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add : AddRemoveEvent* arev=new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
AddRemoveEvent::Remove, QString::null, QString::null, AddRemoveEvent::Remove, QString::null, QString::null,
DNSToDomain(replyDomain)); DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev); QApplication::postEvent(obj, arev);
} }
#endif
} }
#include "domainbrowser.moc" #include "domainbrowser.moc"

@ -45,9 +45,11 @@ namespace DNSSD
{ {
static unsigned long publicIP(); static unsigned long publicIP();
#ifdef HAVE_DNSSD
void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context); void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context);
#endif
class PublicServicePrivate class PublicServicePrivate
{ {
public: public:
PublicServicePrivate() : m_published(false), m_running(false), m_collision(false), m_group(false) PublicServicePrivate() : m_published(false), m_running(false), m_collision(false), m_group(false)
@ -59,8 +61,8 @@ public:
void commit() void commit()
{ {
if (!m_collision) avahi_entry_group_commit(m_group); if (!m_collision) avahi_entry_group_commit(m_group);
} }
}; };
PublicService::PublicService(const QString& name, const QString& type, unsigned int port, 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) : QObject(), ServiceBase(name, type, QString::null, domain, port)
{ {
d = new PublicServicePrivate; d = new PublicServicePrivate;
if (Responder::self().client()) { if (Responder::self().client()) {
d->m_group = avahi_entry_group_new(Responder::self().client(), publish_callback,this); d->m_group = avahi_entry_group_new(Responder::self().client(), publish_callback,this);
connect(&Responder::self(),SIGNAL(stateChanged(AvahiClientState)),this,SLOT(clientState(AvahiClientState))); connect(&Responder::self(),SIGNAL(stateChanged(AvahiClientState)),this,SLOT(clientState(AvahiClientState)));
} }
@ -99,7 +101,7 @@ void PublicService::setServiceName(const QString& serviceName)
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
} }
void PublicService::setDomain(const QString& domain) void PublicService::setDomain(const QString& domain)
@ -108,7 +110,7 @@ void PublicService::setDomain(const QString& domain)
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
} }
@ -118,7 +120,7 @@ void PublicService::setType(const QString& type)
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
} }
void PublicService::setPort(unsigned short port) void PublicService::setPort(unsigned short port)
@ -127,7 +129,7 @@ void PublicService::setPort(unsigned short port)
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
} }
void PublicService::setTextData(const QMap<QString,QString>& textData) void PublicService::setTextData(const QMap<QString,QString>& textData)
@ -136,7 +138,7 @@ void PublicService::setTextData(const QMap<QString,QString>& textData)
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
} }
bool PublicService::isPublished() const bool PublicService::isPublished() const
@ -160,14 +162,14 @@ bool PublicService::fillEntryGroup()
{ {
AvahiStringList *s=0; AvahiStringList *s=0;
QMap<QString,QString>::ConstIterator itEnd = m_textData.end(); 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()); s = avahi_string_list_add_pair(s, it.key().utf8(),it.data().utf8());
#ifdef AVAHI_API_0_6 #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_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)); m_type.ascii(),domainToDNS(m_domain),m_hostName.utf8(),m_port,s));
#else #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_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)); m_type.ascii(),m_domain.utf8(),m_hostName.utf8(),m_port,s));
#endif #endif
@ -199,22 +201,25 @@ void PublicService::clientState(AvahiClientState s)
tryApply(); tryApply();
} }
} }
} }
void PublicService::publishAsync() void PublicService::publishAsync()
{ {
if (d->m_running) stop(); if (d->m_running) stop();
if (!d->m_group) { if (!d->m_group) {
emit published(false); emit published(false);
return; return;
} }
#ifdef HAVE_DNSSD
AvahiClientState s=Responder::self().state(); 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 d->m_collision=true; // make it look like server is getting out of collision to force registering
clientState(s); clientState(s);
} }
#ifdef HAVE_DNSSD
void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context) void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context)
{ {
QObject *obj = reinterpret_cast<QObject*>(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); PublishEvent* pev=new PublishEvent(s==AVAHI_ENTRY_GROUP_ESTABLISHED);
QApplication::postEvent(obj, pev); QApplication::postEvent(obj, pev);
} }
#endif
const KURL PublicService::toInvitation(const QString& host) const KURL PublicService::toInvitation(const QString& host)
{ {

@ -18,7 +18,7 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "query.h" #include "query.h"
#include "responder.h" #include "responder.h"
#include "remoteservice.h" #include "remoteservice.h"
#include "sdevent.h" #include "sdevent.h"
@ -35,6 +35,7 @@
namespace DNSSD namespace DNSSD
{ {
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
void services_callback(AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* name, 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 domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
void* context); void* context);
#endif #endif
#endif
enum BrowserType { Types, Services }; enum BrowserType { Types, Services };
class QueryPrivate class QueryPrivate
{ {
public: public:
QueryPrivate(const QString& type, const QString& domain) : m_finished(false), m_browser(0), 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 Services: avahi_service_browser_free((AvahiServiceBrowser*)d->m_browser); break;
case Types: avahi_service_type_browser_free((AvahiServiceTypeBrowser*)d->m_browser); break; case Types: avahi_service_type_browser_free((AvahiServiceTypeBrowser*)d->m_browser); break;
} }
} }
delete d; delete d;
} }
@ -106,21 +108,25 @@ void Query::startQuery()
d->m_finished = false; d->m_finished = false;
if (d->m_type=="_services._dns-sd._udp") { if (d->m_type=="_services._dns-sd._udp") {
d->m_browserType = Types; d->m_browserType = Types;
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
d->m_browser = avahi_service_type_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 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); domainToDNS(d->m_domain), (AvahiLookupFlags)0, types_callback, this);
#else #else
d->m_browser = avahi_service_type_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, d->m_browser = avahi_service_type_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
d->m_domain.utf8(), types_callback, this); d->m_domain.utf8(), types_callback, this);
#endif
#endif #endif
} else { } else {
d->m_browserType = Services; d->m_browserType = Services;
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
d->m_browser = avahi_service_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 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); d->m_type.ascii(),domainToDNS(d->m_domain), (AvahiLookupFlags)0, services_callback,this);
#else #else
d->m_browser = avahi_service_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 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); d->m_type.ascii(),d->m_domain.utf8(),services_callback,this);
#endif
#endif #endif
} }
if (d->m_browser) { if (d->m_browser) {
@ -152,17 +158,18 @@ void Query::timeout()
emit finished(); emit finished();
} }
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #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) const char* serviceName, const char* regtype, const char* replyDomain, AvahiLookupResultFlags, void* context)
#else #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) const char* serviceName, const char* regtype, const char* replyDomain, void* context)
#endif #endif
{ {
QObject *obj = reinterpret_cast<QObject*>(context); QObject *obj = reinterpret_cast<QObject*>(context);
AddRemoveEvent* arev = new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add : AddRemoveEvent* arev = new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
AddRemoveEvent::Remove, QString::fromUtf8(serviceName), regtype, AddRemoveEvent::Remove, QString::fromUtf8(serviceName), regtype,
DNSToDomain(replyDomain)); DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev); QApplication::postEvent(obj, arev);
} }
@ -177,10 +184,11 @@ void types_callback(AvahiServiceTypeBrowser*, AvahiIfIndex, AvahiProtocol, Avahi
{ {
QObject *obj = reinterpret_cast<QObject*>(context); QObject *obj = reinterpret_cast<QObject*>(context);
AddRemoveEvent* arev = new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add : AddRemoveEvent* arev = new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
AddRemoveEvent::Remove, QString::null, regtype, AddRemoveEvent::Remove, QString::null, regtype,
DNSToDomain(replyDomain)); DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev); QApplication::postEvent(obj, arev);
} }
#endif
} }
#include "query.moc" #include "query.moc"

@ -38,6 +38,7 @@
namespace DNSSD namespace DNSSD
{ {
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto, AvahiResolverEvent e, void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto, AvahiResolverEvent e,
const char* name, const char* type, const char* domain, const char* hostname, const AvahiAddress* a, 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, const char* name, const char* type, const char* domain, const char* hostname, const AvahiAddress* a,
uint16_t port, AvahiStringList* txt, void* context); uint16_t port, AvahiStringList* txt, void* context);
#endif #endif
#endif
class RemoteServicePrivate : public Responder class RemoteServicePrivate : public Responder
{ {
@ -106,6 +108,7 @@ void RemoteService::resolveAsync()
if (d->m_running) return; if (d->m_running) return;
d->m_resolved = false; d->m_resolved = false;
// FIXME: first protocol should be set? // FIXME: first protocol should be set?
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
d->m_resolver = avahi_service_resolver_new(Responder::self().client(),AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 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, m_serviceName.utf8(), m_type.ascii(), domainToDNS(m_domain), AVAHI_PROTO_UNSPEC, AVAHI_LOOKUP_NO_ADDRESS,
@ -113,6 +116,7 @@ void RemoteService::resolveAsync()
#else #else
d->m_resolver = avahi_service_resolver_new(Responder::self().client(),AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 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); m_serviceName.utf8(), m_type.ascii(), m_domain.utf8(), AVAHI_PROTO_UNSPEC, resolve_callback, this);
#endif
#endif #endif
if (d->m_resolver) d->m_running=true; if (d->m_resolver) d->m_running=true;
else emit resolved(false); else emit resolved(false);
@ -160,10 +164,11 @@ QDataStream & operator>> (QDataStream & s, RemoteService & a)
Q_INT8 resolved; Q_INT8 resolved;
operator>>(s,(static_cast<ServiceBase&>(a))); operator>>(s,(static_cast<ServiceBase&>(a)));
s >> resolved; s >> resolved;
a.d->m_resolved = (resolved == 1); a.d->m_resolved = (resolved == 1);
return s; return s;
} }
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent e, void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent e,
const char*, const char*, const char*, const char* hostname, const AvahiAddress*, 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); QObject *obj = reinterpret_cast<QObject*>(context);
if (e != AVAHI_RESOLVER_FOUND) { if (e != AVAHI_RESOLVER_FOUND) {
ErrorEvent err; ErrorEvent err;
QApplication::sendEvent(obj, &err); QApplication::sendEvent(obj, &err);
return; return;
} }
QMap<QString,QString> map; QMap<QString,QString> map;
@ -191,6 +196,7 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiR
ResolveEvent rev(DNSToDomain(hostname),port,map); ResolveEvent rev(DNSToDomain(hostname),port,map);
QApplication::sendEvent(obj, &rev); QApplication::sendEvent(obj, &rev);
} }
#endif
} }

@ -33,16 +33,19 @@ namespace DNSSD
static KStaticDeleter<Responder> responder_sd; static KStaticDeleter<Responder> responder_sd;
Responder* Responder::m_self = 0; 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)); emit (r->stateChanged(s));
} }
#endif
Responder::Responder() Responder::Responder()
{ {
int error; int error;
#ifdef HAVE_DNSSD
const AvahiPoll* poll = avahi_qt_poll_get(); const AvahiPoll* poll = avahi_qt_poll_get();
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
m_client = avahi_client_new(poll, AVAHI_CLIENT_IGNORE_USER_CONFIG,client_callback, this, &error); 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); m_client = avahi_client_new(poll, client_callback, this, &error);
#endif #endif
if (!m_client) kdWarning() << "Failed to create avahi client" << endl; if (!m_client) kdWarning() << "Failed to create avahi client" << endl;
#endif
} }
Responder::~Responder() Responder::~Responder()
{ {
#ifdef HAVE_DNSSD
if (m_client) avahi_client_free(m_client); if (m_client) avahi_client_free(m_client);
#endif
} }
Responder& Responder::self() Responder& Responder::self()
@ -68,6 +74,7 @@ void Responder::process()
qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput); qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
} }
#ifdef HAVE_DNSSD
AvahiClientState Responder::state() const AvahiClientState Responder::state() const
{ {
#ifdef AVAHI_API_0_6 #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; return (m_client) ? (avahi_client_get_state(m_client)) : AVAHI_CLIENT_DISCONNECTED;
#endif #endif
} }
#endif
bool domainIsLocal(const QString& domain) bool domainIsLocal(const QString& domain)
{ {

@ -25,13 +25,18 @@
#include <qsocketnotifier.h> #include <qsocketnotifier.h>
#include <qsignal.h> #include <qsignal.h>
#include <config.h> #include <config.h>
#ifdef HAVE_DNSSD
#include <avahi-client/client.h> #include <avahi-client/client.h>
#else
#define DNSServiceRef void*
#endif
namespace DNSSD namespace DNSSD
{ {
/** /**
This class should not be used directly. This class should not be used directly.
@author Jakub Stachowski @author Jakub Stachowski
@short Internal class wrapping avahi client @short Internal class wrapping avahi client
*/ */
@ -45,22 +50,28 @@ public:
~Responder(); ~Responder();
static Responder& self(); static Responder& self();
#ifdef HAVE_DNSSD
AvahiClientState state() const; AvahiClientState state() const;
AvahiClient* client() const { return m_client; } AvahiClient* client() const { return m_client; }
#endif
void process(); void process();
signals: signals:
void stateChanged(AvahiClientState); void stateChanged(AvahiClientState);
private: private:
#ifdef HAVE_DNSSD
AvahiClient* m_client; AvahiClient* m_client;
#endif
static Responder* m_self; static Responder* m_self;
#ifdef HAVE_DNSSD
friend void client_callback(AvahiClient*, AvahiClientState, void*); friend void client_callback(AvahiClient*, AvahiClientState, void*);
#endif
}; };
/* Utils functions */ /* Utils functions */
bool domainIsLocal(const QString& domain); bool domainIsLocal(const QString& domain);
// Encodes domain name using utf8() or IDN // Encodes domain name using utf8() or IDN
QCString domainToDNS(const QString &domain); QCString domainToDNS(const QString &domain);
QString DNSToDomain(const char* domain); QString DNSToDomain(const char* domain);

@ -26,7 +26,9 @@
#include "responder.h" #include "responder.h"
#include "query.h" #include "query.h"
#include "servicebrowser.h" #include "servicebrowser.h"
#ifdef HAVE_DNSSD
#include <avahi-client/client.h> #include <avahi-client/client.h>
#endif
#include <config.h> #include <config.h>
namespace DNSSD namespace DNSSD
@ -34,10 +36,10 @@ namespace DNSSD
const QString ServiceBrowser::AllServices = "_services._dns-sd._udp"; const QString ServiceBrowser::AllServices = "_services._dns-sd._udp";
class ServiceBrowserPrivate class ServiceBrowserPrivate
{ {
public: public:
ServiceBrowserPrivate() : m_running(false) ServiceBrowserPrivate() : m_running(false)
{} {}
QValueList<RemoteService::Ptr> m_services; QValueList<RemoteService::Ptr> m_services;
QValueList<RemoteService::Ptr> m_duringResolve; QValueList<RemoteService::Ptr> m_duringResolve;
@ -82,12 +84,16 @@ ServiceBrowser::ServiceBrowser(const QString& type,const QString& domain,int fla
const ServiceBrowser::State ServiceBrowser::isAvailable() const ServiceBrowser::State ServiceBrowser::isAvailable()
{ {
#ifdef HAVE_DNSSD
AvahiClientState s = Responder::self().state(); AvahiClientState s = Responder::self().state();
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
return (s==AVAHI_CLIENT_FAILURE) ? Stopped : Working; return (s==AVAHI_CLIENT_FAILURE) ? Stopped : Working;
#else #else
return (s==AVAHI_CLIENT_S_INVALID || s==AVAHI_CLIENT_DISCONNECTED) ? Stopped : Working; return (s==AVAHI_CLIENT_S_INVALID || s==AVAHI_CLIENT_DISCONNECTED) ? Stopped : Working;
#endif #endif
#else
return Unsupported;
#endif
} }
ServiceBrowser::~ ServiceBrowser() ServiceBrowser::~ ServiceBrowser()
{ {
@ -158,7 +164,7 @@ void ServiceBrowser::removeDomain(const QString& domain)
{ {
while (d->resolvers[domain]) d->resolvers.remove(domain); while (d->resolvers[domain]) d->resolvers.remove(domain);
QValueList<RemoteService::Ptr>::Iterator it = d->m_services.begin(); 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 // use section to skip possible trailing dot
if ((*it)->domain().section('.',0) == domain.section('.',0)) { if ((*it)->domain().section('.',0) == domain.section('.',0)) {
emit serviceRemoved(*it); 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 ServiceBrowser::findDuplicate(RemoteService::Ptr src)
{ {
QValueList<RemoteService::Ptr>::Iterator itEnd = d->m_services.end(); 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()) && if ((src->type()==(*it)->type()) && (src->serviceName()==(*it)->serviceName()) &&
(src->domain() == (*it)->domain())) return it; (src->domain() == (*it)->domain())) return it;
return itEnd; return itEnd;

Loading…
Cancel
Save