Add zeroconf TxtRecords (#449)

* txtrecords

* typo
This commit is contained in:
brindosch
2017-07-05 16:54:41 +02:00
committed by GitHub
parent c0336b640f
commit e98122c9cb
4 changed files with 34 additions and 8 deletions

View File

@@ -48,7 +48,7 @@ BonjourServiceRegister::~BonjourServiceRegister()
}
}
void BonjourServiceRegister::registerService(const BonjourRecord &record, quint16 servicePort)
void BonjourServiceRegister::registerService(const BonjourRecord &record, quint16 servicePort, std::vector<std::pair<std::string, std::string>> txt)
{
if (dnssref)
{
@@ -62,10 +62,25 @@ void BonjourServiceRegister::registerService(const BonjourRecord &record, quint1
}
#endif
// create txt record
TXTRecordRef txtRec;
TXTRecordCreate(&txtRec,0,NULL);
// add txt records
if(!txt.empty())
{
for(std::vector<std::pair<std::string, std::string> >::const_iterator it = txt.begin(); it != txt.end(); ++it)
{
//Debug(Logger::getInstance("BonJour"), "TXTRecord: key:%s, value:%s",it->first.c_str(),it->second.c_str());
uint8_t txtLen = (uint8_t)strlen(it->second.c_str());
TXTRecordSetValue(&txtRec, it->first.c_str(), txtLen, it->second.c_str());
}
}
DNSServiceErrorType err = DNSServiceRegister(&dnssref, 0, 0, record.serviceName.toUtf8().constData(),
record.registeredType.toUtf8().constData(),
(record.replyDomain.isEmpty() ? 0 : record.replyDomain.toUtf8().constData()),
0, bigEndianPort, 0, 0, bonjourRegisterService, this);
0, bigEndianPort, TXTRecordGetLength(&txtRec), TXTRecordGetBytesPtr(&txtRec), bonjourRegisterService, this);
if (err != kDNSServiceErr_NoError)
{
emit error(err);

View File

@@ -11,6 +11,7 @@
#include <QHostInfo>
#include <bonjour/bonjourserviceregister.h>
#include <bonjour/bonjourrecord.h>
#include <HyperionConfig.h>
#include <exception>
StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint16 port, QObject * parent)
@@ -47,10 +48,16 @@ void StaticFileServing::onServerStarted (quint16 port)
const QJsonObject & generalConfig = _hyperion->getQJsonConfig()["general"].toObject();
const QString mDNSDescr = generalConfig["name"].toString("") + "@" + QHostInfo::localHostName() + ":" + QString::number(port);
// txt record for zeroconf
QString id = _hyperion->id;
std::string version = HYPERION_VERSION;
std::vector<std::pair<std::string, std::string> > txtRecord = {{"id",id.toStdString()},{"version",version}};
BonjourServiceRegister *bonjourRegister_http = new BonjourServiceRegister();
bonjourRegister_http->registerService(
BonjourRecord(mDNSDescr, "_hyperiond-http._tcp", QString()),
port
port,
txtRecord
);
Debug(_log, "Web Config mDNS responder started");
}