Remaining Avahi fixes

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

@ -48,14 +48,21 @@ void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBr
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) {} #ifdef HAVE_DNSSD
, m_browser(0), m_owner(owner)
#endif
{}
#ifdef HAVE_DNSSD
~DomainBrowserPrivate() { if (m_browser) avahi_domain_browser_free(m_browser); } ~DomainBrowserPrivate() { if (m_browser) avahi_domain_browser_free(m_browser); }
#endif
QStringList m_domains; QStringList m_domains;
virtual void customEvent(QCustomEvent* event); virtual void customEvent(QCustomEvent* event);
bool m_browseLAN; bool m_browseLAN;
bool m_started; bool m_started;
#ifdef HAVE_DNSSD
AvahiDomainBrowser* m_browser; AvahiDomainBrowser* m_browser;
#endif
DomainBrowser* m_owner; DomainBrowser* m_owner;
}; };
@ -132,10 +139,12 @@ 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;
#ifdef HAVE_DNSSD
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;
} }
#endif
d->m_started = false; d->m_started = false;
// remove all domains and resolvers // remove all domains and resolvers

@ -30,12 +30,14 @@
#include <network/ksocketaddress.h> #include <network/ksocketaddress.h>
#include <kurl.h> #include <kurl.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_DNSSD
#include <avahi-client/client.h> #include <avahi-client/client.h>
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
#include <avahi-client/publish.h> #include <avahi-client/publish.h>
#endif #endif
#include <avahi-common/alternative.h> #include <avahi-common/alternative.h>
#include <avahi-common/strlst.h> #include <avahi-common/strlst.h>
#endif
#include "sdevent.h" #include "sdevent.h"
#include "responder.h" #include "responder.h"
#include "servicebrowser.h" #include "servicebrowser.h"
@ -52,15 +54,22 @@ void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context)
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)
#ifdef HAVE_DNSSD
, m_group(false)
#endif
{} {}
bool m_published; bool m_published;
bool m_running; bool m_running;
bool m_collision; bool m_collision;
#ifdef HAVE_DNSSD
AvahiEntryGroup* m_group; AvahiEntryGroup* m_group;
#endif
void commit() void commit()
{ {
#ifdef HAVE_DNSSD
if (!m_collision) avahi_entry_group_commit(m_group); 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) : QObject(), ServiceBase(name, type, QString::null, domain, port)
{ {
d = new PublicServicePrivate; d = new PublicServicePrivate;
#ifdef HAVE_DNSSD
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)));
} }
#endif
if (domain.isNull()) if (domain.isNull())
if (Configuration::publishType()==Configuration::EnumPublishType::LAN) m_domain="local."; if (Configuration::publishType()==Configuration::EnumPublishType::LAN) m_domain="local.";
else m_domain=Configuration::publishDomain(); else m_domain=Configuration::publishDomain();
@ -82,7 +93,9 @@ PublicService::PublicService(const QString& name, const QString& type, unsigned
PublicService::~PublicService() PublicService::~PublicService()
{ {
#ifdef HAVE_DNSSD
if (d->m_group) avahi_entry_group_free(d->m_group); if (d->m_group) avahi_entry_group_free(d->m_group);
#endif
delete d; delete d;
} }
@ -98,47 +111,57 @@ void PublicService::tryApply()
void PublicService::setServiceName(const QString& serviceName) void PublicService::setServiceName(const QString& serviceName)
{ {
m_serviceName = serviceName; m_serviceName = serviceName;
#ifdef HAVE_DNSSD
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
#endif
} }
void PublicService::setDomain(const QString& domain) void PublicService::setDomain(const QString& domain)
{ {
m_domain = domain; m_domain = domain;
#ifdef HAVE_DNSSD
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
#endif
} }
void PublicService::setType(const QString& type) void PublicService::setType(const QString& type)
{ {
m_type = type; m_type = type;
#ifdef HAVE_DNSSD
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
#endif
} }
void PublicService::setPort(unsigned short port) void PublicService::setPort(unsigned short port)
{ {
m_port = port; m_port = port;
#ifdef HAVE_DNSSD
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
#endif
} }
void PublicService::setTextData(const QMap<QString,QString>& textData) void PublicService::setTextData(const QMap<QString,QString>& textData)
{ {
m_textData = textData; m_textData = textData;
#ifdef HAVE_DNSSD
if (d->m_running) { if (d->m_running) {
avahi_entry_group_reset(d->m_group); avahi_entry_group_reset(d->m_group);
tryApply(); tryApply();
} }
#endif
} }
bool PublicService::isPublished() const bool PublicService::isPublished() const
@ -155,11 +178,14 @@ bool PublicService::publish()
void PublicService::stop() void PublicService::stop()
{ {
#ifdef HAVE_DNSSD
if (d->m_group) avahi_entry_group_reset(d->m_group); if (d->m_group) avahi_entry_group_reset(d->m_group);
#endif
d->m_published = false; d->m_published = false;
} }
bool PublicService::fillEntryGroup() bool PublicService::fillEntryGroup()
{ {
#ifdef HAVE_DNSSD
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)
@ -175,11 +201,15 @@ bool PublicService::fillEntryGroup()
#endif #endif
avahi_string_list_free(s); avahi_string_list_free(s);
return res; return res;
#else
return FALSE;
#endif
} }
void PublicService::clientState(AvahiClientState s) void PublicService::clientState(AvahiClientState s)
{ {
if (!d->m_running) return; if (!d->m_running) return;
#ifdef HAVE_DNSSD
switch (s) { switch (s) {
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
case AVAHI_CLIENT_FAILURE: case AVAHI_CLIENT_FAILURE:
@ -201,22 +231,25 @@ void PublicService::clientState(AvahiClientState s)
tryApply(); tryApply();
} }
} }
#endif
} }
void PublicService::publishAsync() void PublicService::publishAsync()
{ {
if (d->m_running) stop(); if (d->m_running) stop();
#ifdef HAVE_DNSSD
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();
#endif #endif
d->m_running=true; 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
#ifdef HAVE_DNSSD
clientState(s); clientState(s);
#endif
} }
#ifdef HAVE_DNSSD #ifdef HAVE_DNSSD
@ -251,6 +284,7 @@ const KURL PublicService::toInvitation(const QString& host)
void PublicService::customEvent(QCustomEvent* event) void PublicService::customEvent(QCustomEvent* event)
{ {
#ifdef HAVE_DNSSD
if (event->type()==QEvent::User+SD_PUBLISH) { if (event->type()==QEvent::User+SD_PUBLISH) {
if (!static_cast<PublishEvent*>(event)->m_ok) { if (!static_cast<PublishEvent*>(event)->m_ok) {
setServiceName(QString::fromUtf8(avahi_alternative_service_name(m_serviceName.utf8()))); setServiceName(QString::fromUtf8(avahi_alternative_service_name(m_serviceName.utf8())));
@ -259,6 +293,7 @@ void PublicService::customEvent(QCustomEvent* event)
d->m_published=true; d->m_published=true;
emit published(true); emit published(true);
} }
#endif
} }
void PublicService::virtual_hook(int, void*) void PublicService::virtual_hook(int, void*)

@ -23,7 +23,11 @@
#include <qobject.h> #include <qobject.h>
#include <dnssd/servicebase.h> #include <dnssd/servicebase.h>
#ifdef HAVE_DNSSD
#include <avahi-client/client.h> #include <avahi-client/client.h>
#else
#define AvahiClientState void*
#endif
class KURL; class KURL;
namespace DNSSD namespace DNSSD

@ -26,10 +26,12 @@
#include <qapplication.h> #include <qapplication.h>
#include <qtimer.h> #include <qtimer.h>
#ifdef HAVE_DNSSD
#include <avahi-client/client.h> #include <avahi-client/client.h>
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
#include <avahi-client/lookup.h> #include <avahi-client/lookup.h>
#endif #endif
#endif
#define TIMEOUT_LAN 200 #define TIMEOUT_LAN 200
@ -78,12 +80,14 @@ Query::Query(const QString& type, const QString& domain)
Query::~Query() Query::~Query()
{ {
#ifdef HAVE_DNSSD
if (d->m_browser) { if (d->m_browser) {
switch (d->m_browserType) { switch (d->m_browserType) {
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;
} }
} }
#endif
delete d; delete d;
} }

@ -27,11 +27,13 @@
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#include <netinet/in.h> #include <netinet/in.h>
#ifdef HAVE_DNSSD
#include <avahi-client/client.h> #include <avahi-client/client.h>
#include <avahi-common/strlst.h> #include <avahi-common/strlst.h>
#ifdef AVAHI_API_0_6 #ifdef AVAHI_API_0_6
#include <avahi-client/lookup.h> #include <avahi-client/lookup.h>
#endif #endif
#endif
#include "remoteservice.h" #include "remoteservice.h"
#include "responder.h" #include "responder.h"
#include "sdevent.h" #include "sdevent.h"
@ -53,15 +55,21 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto,
class RemoteServicePrivate : public Responder class RemoteServicePrivate : public Responder
{ {
public: 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_resolved;
bool m_running; bool m_running;
#ifdef HAVE_DNSSD
AvahiServiceResolver* m_resolver; AvahiServiceResolver* m_resolver;
void stop() { void stop() {
m_running = false; m_running = false;
if (m_resolver) avahi_service_resolver_free(m_resolver); if (m_resolver) avahi_service_resolver_free(m_resolver);
m_resolver=0; m_resolver=0;
} }
#endif
}; };
RemoteService::RemoteService(const QString& label) RemoteService::RemoteService(const QString& label)
@ -91,7 +99,9 @@ RemoteService::RemoteService(const KURL& url)
RemoteService::~RemoteService() RemoteService::~RemoteService()
{ {
#ifdef HAVE_DNSSD
if (d->m_resolver) avahi_service_resolver_free(d->m_resolver); if (d->m_resolver) avahi_service_resolver_free(d->m_resolver);
#endif
delete d; delete d;
} }
@ -99,7 +109,9 @@ bool RemoteService::resolve()
{ {
resolveAsync(); resolveAsync();
while (d->m_running && !d->m_resolved) Responder::self().process(); while (d->m_running && !d->m_resolved) Responder::self().process();
#ifdef HAVE_DNSSD
d->stop(); d->stop();
#endif
return d->m_resolved; return d->m_resolved;
} }
@ -116,10 +128,10 @@ 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);
#endif
} }
bool RemoteService::isResolved() const bool RemoteService::isResolved() const
@ -130,7 +142,9 @@ bool RemoteService::isResolved() const
void RemoteService::customEvent(QCustomEvent* event) void RemoteService::customEvent(QCustomEvent* event)
{ {
if (event->type() == QEvent::User+SD_ERROR) { if (event->type() == QEvent::User+SD_ERROR) {
#ifdef HAVE_DNSSD
d->stop(); d->stop();
#endif
d->m_resolved=false; d->m_resolved=false;
emit resolved(false); emit resolved(false);
} }
@ -160,7 +174,9 @@ QDataStream & operator<< (QDataStream & s, const RemoteService & a)
QDataStream & operator>> (QDataStream & s, RemoteService & a) QDataStream & operator>> (QDataStream & s, RemoteService & a)
{ {
// stop any possible resolve going on // stop any possible resolve going on
#ifdef HAVE_DNSSD
a.d->stop(); a.d->stop();
#endif
Q_INT8 resolved; Q_INT8 resolved;
operator>>(s,(static_cast<ServiceBase&>(a))); operator>>(s,(static_cast<ServiceBase&>(a)));
s >> resolved; s >> resolved;

@ -24,8 +24,9 @@
#include <kstaticdeleter.h> #include <kstaticdeleter.h>
#include <kidna.h> #include <kidna.h>
#include <kdebug.h> #include <kdebug.h>
#ifdef HAVE_DNSSD
#include <avahi-qt3/qt-watch.h> #include <avahi-qt3/qt-watch.h>
#endif
namespace DNSSD namespace DNSSD
{ {

@ -29,6 +29,7 @@
#include <avahi-client/client.h> #include <avahi-client/client.h>
#else #else
#define DNSServiceRef void* #define DNSServiceRef void*
#define AvahiClientState void*
#endif #endif
namespace DNSSD namespace DNSSD

Loading…
Cancel
Save