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