Example #1
0
void PublicService::publishAsync()
{
    if(d->isRunning())
        stop();
#ifdef HAVE_DNSSD
    if(ServiceBrowser::isAvailable() == ServiceBrowser::Working)
    {
        TXTRecordRef txt;
        TXTRecordCreate(&txt, 0, 0);
        QMap< QString, QString >::ConstIterator itEnd = m_textData.end();
        for(QMap< QString, QString >::ConstIterator it = m_textData.begin(); it != itEnd; ++it)
        {
            QCString value = it.data().utf8();
            if(TXTRecordSetValue(&txt, it.key().utf8(), value.length(), value) != kDNSServiceErr_NoError)
            {
                TXTRecordDeallocate(&txt);
                emit published(false);
                return;
            }
        }
        DNSServiceRef ref;
        if(DNSServiceRegister(&ref, 0, 0, m_serviceName.utf8(), m_type.ascii(), domainToDNS(m_domain), NULL, htons(m_port), TXTRecordGetLength(&txt),
                              TXTRecordGetBytesPtr(&txt), publish_callback, reinterpret_cast< void * >(this))
           == kDNSServiceErr_NoError)
            d->setRef(ref);
        TXTRecordDeallocate(&txt);
    }
#endif
    if(!d->isRunning())
        emit published(false);
}
void RemoteService::resolveAsync()
{
	K_D;
	if (d->isRunning()) return;
	d->m_resolved = false;
	kDebug() << this << ":Starting resolve of : " << d->m_serviceName << " " << d->m_type << " " << d->m_domain << "\n";
	DNSServiceRef ref;
	if (DNSServiceResolve(&ref,0,0,d->m_serviceName.toUtf8(), d->m_type.toAscii().constData(), 
 		domainToDNS(d->m_domain),(DNSServiceResolveReply)resolve_callback,reinterpret_cast<void*>(d))
		== kDNSServiceErr_NoError) d->setRef(ref);
	if (!d->isRunning()) emit resolved(false);
}
Example #3
0
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,
	    resolve_callback, this);
#else
	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
	if (d->m_resolver) d->m_running=true;
	    else  emit resolved(false);
#endif
}
void PublicService::publishAsync()
{
	K_D;
	if (d->isRunning()) stop();
	TXTRecordRef txt;
	TXTRecordCreate(&txt,0,0);
	QMap<QString,QByteArray>::ConstIterator itEnd = d->m_textData.end();
	for (QMap<QString,QByteArray>::ConstIterator it = d->m_textData.begin(); it!=itEnd ; ++it) {
		if (TXTRecordSetValue(&txt,it.key().toUtf8(),it.value().length(),it.value())!=kDNSServiceErr_NoError) {
			TXTRecordDeallocate(&txt);
			emit published(false);
			return;
		}
	}
	DNSServiceRef ref;
	QString fullType=d->m_type;
	Q_FOREACH(const QString &subtype, d->m_subtypes) fullType+=','+subtype;
	if (DNSServiceRegister(&ref,0,0,d->m_serviceName.toUtf8(),fullType.toAscii().constData(),domainToDNS(d->m_domain),NULL,
	    htons(d->m_port),TXTRecordGetLength(&txt),TXTRecordGetBytesPtr(&txt),publish_callback,
	    reinterpret_cast<void*>(d)) == kDNSServiceErr_NoError) d->setRef(ref);
	TXTRecordDeallocate(&txt);
	if (!d->isRunning()) emit published(false);
}
Example #5
0
Avahi::Avahi()
{
    org::freedesktop::Avahi::Server server("org.freedesktop.Avahi", "/", QDBusConnection::systemBus());
    QDBusReply<QDBusObjectPath> reply=server.ServiceBrowserNew(-1, -1, constServiceType, domainToDNS(QString()), 0);

    if (reply.isValid()) {
        service=new OrgFreedesktopAvahiServiceBrowserInterface("org.freedesktop.Avahi", reply.value().path(), QDBusConnection::systemBus());
        connect(service, SIGNAL(ItemNew(int,int,QString,QString,QString,uint)), SLOT(addService(int,int,QString,QString,QString,uint)));
        connect(service, SIGNAL(ItemRemove(int,int,QString,QString,QString,uint)), SLOT(removeService(int,int,QString,QString,QString,uint)));
    }
}