forked from jbagg/QtZeroConf
Add txt records to service publication.
This commit is contained in:
@@ -39,6 +39,7 @@ public:
|
||||
{
|
||||
qint32 error;
|
||||
|
||||
txt = NULL;
|
||||
pub = parent;
|
||||
group = NULL;
|
||||
browser = NULL;
|
||||
@@ -72,7 +73,7 @@ public:
|
||||
emit ref->pub->error(QZeroConf::serviceRegistrationFailed);
|
||||
break;
|
||||
case AVAHI_ENTRY_GROUP_UNCOMMITED:
|
||||
ret = avahi_entry_group_add_service(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_UPDATE, ref->name.toUtf8(), ref->type.toUtf8(), ref->domain.toUtf8(), NULL, ref->port, NULL);
|
||||
ret = avahi_entry_group_add_service_strlst(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_UPDATE, ref->name.toUtf8(), ref->type.toUtf8(), ref->domain.toUtf8(), NULL, ref->port, ref->txt);
|
||||
if (ret < 0) {
|
||||
avahi_entry_group_free(g);
|
||||
ref->group = NULL;
|
||||
@@ -197,10 +198,10 @@ public:
|
||||
const AvahiPoll *poll;
|
||||
AvahiClient *client;
|
||||
AvahiEntryGroup *group;
|
||||
AvahiServiceBrowser *browser;
|
||||
AvahiStringList *txt;
|
||||
QString name, type, domain;
|
||||
quint16 port;
|
||||
|
||||
AvahiServiceBrowser *browser;
|
||||
};
|
||||
|
||||
|
||||
@@ -211,6 +212,7 @@ QZeroConf::QZeroConf()
|
||||
|
||||
QZeroConf::~QZeroConf()
|
||||
{
|
||||
avahi_string_list_free(pri->txt);
|
||||
pri->broswerCleanUp();
|
||||
if (pri->client)
|
||||
avahi_client_free(pri->client);
|
||||
@@ -242,6 +244,26 @@ void QZeroConf::stopServicePublish(void)
|
||||
}
|
||||
}
|
||||
|
||||
// http://www.zeroconf.org/rendezvous/txtrecords.html
|
||||
|
||||
void QZeroConf::addServiceTxtRecord(QString nameOnly)
|
||||
{
|
||||
pri->txt = avahi_string_list_add(pri->txt, nameOnly.toUtf8());
|
||||
}
|
||||
|
||||
void QZeroConf::addServiceTxtRecord(QString name, QString value)
|
||||
{
|
||||
name.append("=");
|
||||
name.append(value);
|
||||
addServiceTxtRecord(name);
|
||||
}
|
||||
|
||||
void QZeroConf::clearServiceTxtRecords()
|
||||
{
|
||||
avahi_string_list_free(pri->txt);
|
||||
pri->txt = NULL;
|
||||
}
|
||||
|
||||
void QZeroConf::startBrowser(QString type, QAbstractSocket::NetworkLayerProtocol protocol)
|
||||
{
|
||||
AvahiProtocol avahiProtocol;
|
||||
|
@@ -43,6 +43,7 @@ public:
|
||||
pub = parent;
|
||||
group = NULL;
|
||||
browser = NULL;
|
||||
txt = NULL;
|
||||
ready = 0;
|
||||
registerWaiting = 0;
|
||||
|
||||
@@ -214,7 +215,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
ret = avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_UPDATE, name, type, domain, NULL, port, NULL);
|
||||
ret = avahi_server_add_service_strlst(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_UPDATE, name, type, domain, NULL, port, txt);
|
||||
if (ret < 0) {
|
||||
avahi_s_entry_group_free(group);
|
||||
group = NULL;
|
||||
@@ -236,6 +237,7 @@ public:
|
||||
AvahiServerConfig config;
|
||||
AvahiSEntryGroup *group;
|
||||
AvahiSServiceBrowser *browser;
|
||||
AvahiStringList *txt;
|
||||
bool ready, registerWaiting;
|
||||
QString name, type, domain;
|
||||
qint32 port;
|
||||
@@ -249,6 +251,7 @@ QZeroConf::QZeroConf()
|
||||
|
||||
QZeroConf::~QZeroConf()
|
||||
{
|
||||
avahi_string_list_free(pri->txt);
|
||||
pri->broswerCleanUp();
|
||||
avahi_server_config_free(&pri->config);
|
||||
if (pri->server)
|
||||
@@ -281,6 +284,26 @@ void QZeroConf::stopServicePublish(void)
|
||||
}
|
||||
}
|
||||
|
||||
// http://www.zeroconf.org/rendezvous/txtrecords.html
|
||||
|
||||
void QZeroConf::addServiceTxtRecord(QString nameOnly)
|
||||
{
|
||||
pri->txt = avahi_string_list_add(pri->txt, nameOnly.toUtf8());
|
||||
}
|
||||
|
||||
void QZeroConf::addServiceTxtRecord(QString name, QString value)
|
||||
{
|
||||
name.append("=");
|
||||
name.append(value);
|
||||
addServiceTxtRecord(name);
|
||||
}
|
||||
|
||||
void QZeroConf::clearServiceTxtRecords()
|
||||
{
|
||||
avahi_string_list_free(pri->txt);
|
||||
pri->txt = NULL;
|
||||
}
|
||||
|
||||
void QZeroConf::startBrowser(QString type, QAbstractSocket::NetworkLayerProtocol protocol)
|
||||
{
|
||||
AvahiProtocol avahiProtocol;
|
||||
|
22
bonjour.cpp
22
bonjour.cpp
@@ -279,7 +279,9 @@ void QZeroConf::startServicePublish(const char *name, const char *type, const ch
|
||||
type,
|
||||
domain,
|
||||
NULL,
|
||||
qFromBigEndian<quint16>(port), NULL, NULL, (DNSServiceRegisterReply) QZeroConfPrivate::registerCallback, pri);
|
||||
qFromBigEndian<quint16>(port),
|
||||
pri->txt.size(), pri->txt.data(),
|
||||
(DNSServiceRegisterReply) QZeroConfPrivate::registerCallback, pri);
|
||||
|
||||
if (err == kDNSServiceErr_NoError) {
|
||||
int sockfd = DNSServiceRefSockFD(pri->dnssRef);
|
||||
@@ -303,6 +305,24 @@ void QZeroConf::stopServicePublish(void)
|
||||
pri->cleanUp(pri->dnssRef);
|
||||
}
|
||||
|
||||
void QZeroConf::addServiceTxtRecord(QString nameOnly)
|
||||
{
|
||||
pri->txt.append((quint8) nameOnly.size());
|
||||
pri->txt.append(nameOnly.toUtf8());
|
||||
}
|
||||
|
||||
void QZeroConf::addServiceTxtRecord(QString name, QString value)
|
||||
{
|
||||
name.append("=");
|
||||
name.append(value);
|
||||
addServiceTxtRecord(name);
|
||||
}
|
||||
|
||||
void QZeroConf::clearServiceTxtRecords()
|
||||
{
|
||||
pri->txt.clear();
|
||||
}
|
||||
|
||||
void QZeroConf::startBrowser(QString type, QAbstractSocket::NetworkLayerProtocol protocol)
|
||||
{
|
||||
DNSServiceErrorType err;
|
||||
|
@@ -66,6 +66,7 @@ public:
|
||||
QSocketNotifier *bs, *browserSocket, *resolverSocket, *addressSocket;
|
||||
QZeroConfService *newService;
|
||||
QList<QZeroConfService *> work;
|
||||
QByteArray txt;
|
||||
|
||||
public slots:
|
||||
void bsRead();
|
||||
|
@@ -105,6 +105,9 @@ void mainWindow::startPublish()
|
||||
if (publishEnabled)
|
||||
return;
|
||||
publishEnabled = 1;
|
||||
|
||||
zeroConf.addServiceTxtRecord("Qt", "the best!");
|
||||
zeroConf.addServiceTxtRecord("ZeroConf is nice too");
|
||||
zeroConf.startServicePublish(buildName().toUtf8(), "_qtzeroconf_test._tcp", "local", 11437);
|
||||
}
|
||||
|
||||
|
@@ -79,6 +79,9 @@ public:
|
||||
}
|
||||
void startBrowser(QString type, QAbstractSocket::NetworkLayerProtocol protocol);
|
||||
void stopBrowser(void);
|
||||
void addServiceTxtRecord(QString nameOnly);
|
||||
void addServiceTxtRecord(QString name, QString value);
|
||||
void clearServiceTxtRecords();
|
||||
|
||||
signals:
|
||||
void servicePublished(void);
|
||||
|
Reference in New Issue
Block a user