mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 19:31:02 +01:00
Truncate name used for mdns service.
This commit is contained in:
parent
def697c31a
commit
04db045c30
@ -12,7 +12,7 @@ namespace {
|
||||
void AddService(
|
||||
const QString domain,
|
||||
const QString type,
|
||||
const QString name,
|
||||
const QByteArray name,
|
||||
quint16 port,
|
||||
QDBusPendingReply<QDBusObjectPath> path_reply);
|
||||
void Commit(OrgFreedesktopAvahiEntryGroupInterface* interface);
|
||||
@ -20,10 +20,10 @@ void LogCommit(QDBusPendingReply<> reply);
|
||||
|
||||
} // namespace
|
||||
|
||||
void Avahi::Publish(
|
||||
void Avahi::PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
const QByteArray& name,
|
||||
quint16 port) {
|
||||
OrgFreedesktopAvahiServerInterface server_interface(
|
||||
"org.freedesktop.Avahi",
|
||||
@ -46,7 +46,7 @@ namespace {
|
||||
void AddService(
|
||||
const QString domain,
|
||||
const QString type,
|
||||
const QString name,
|
||||
const QByteArray name,
|
||||
quint16 port,
|
||||
QDBusPendingReply<QDBusObjectPath> path_reply) {
|
||||
if (path_reply.isError()) {
|
||||
@ -68,7 +68,8 @@ void AddService(
|
||||
-1, // Interface (all)
|
||||
-1, // Protocol (v4 & v6)
|
||||
0, // Flags
|
||||
name, // Service name, eg. Clementine
|
||||
// Service name, eg. Clementine
|
||||
QString::fromUtf8(name.constData(), name.size()),
|
||||
type, // Service type, eg. _clementine._tcp
|
||||
domain, // Domain, eg. local
|
||||
QString::null, // Hostname (filled in by Avahi)
|
||||
|
@ -4,11 +4,11 @@
|
||||
#include "zeroconf.h"
|
||||
|
||||
class Avahi : public Zeroconf {
|
||||
public:
|
||||
virtual void Publish(
|
||||
protected:
|
||||
virtual void PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
const QByteArray& name,
|
||||
quint16 port);
|
||||
};
|
||||
|
||||
|
@ -13,10 +13,12 @@ class Bonjour : public Zeroconf {
|
||||
public:
|
||||
Bonjour();
|
||||
virtual ~Bonjour();
|
||||
virtual void Publish(
|
||||
|
||||
protected:
|
||||
virtual void PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
const QByteArray& name,
|
||||
quint16 port);
|
||||
|
||||
private:
|
||||
|
@ -49,16 +49,16 @@ Bonjour::~Bonjour() {
|
||||
[delegate_ release];
|
||||
}
|
||||
|
||||
void Bonjour::Publish(
|
||||
void Bonjour::PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
const QByteArray& name,
|
||||
quint16 port) {
|
||||
ScopedNSAutoreleasePool pool;
|
||||
NSNetService* service = [[NSNetService alloc]
|
||||
initWithDomain: NSStringFromQString(domain)
|
||||
type: NSStringFromQString(type)
|
||||
name: NSStringFromQString(name)
|
||||
name: [NSString stringWithUTF8String(name.constData())]
|
||||
port: port];
|
||||
if (service) {
|
||||
[service setDelegate: delegate_];
|
||||
|
@ -48,10 +48,10 @@ TinySVCMDNS::~TinySVCMDNS() {
|
||||
}
|
||||
}
|
||||
|
||||
void TinySVCMDNS::Publish(
|
||||
void TinySVCMDNS::PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
const QByteArray& name,
|
||||
quint16 port) {
|
||||
if (!mdnsd_) {
|
||||
return;
|
||||
@ -65,7 +65,7 @@ void TinySVCMDNS::Publish(
|
||||
|
||||
mdnsd_register_svc(
|
||||
mdnsd_,
|
||||
name.toUtf8().constData(),
|
||||
name.constData(),
|
||||
QString(type + ".local").toUtf8().constData(),
|
||||
port,
|
||||
NULL,
|
||||
|
@ -10,10 +10,11 @@ class TinySVCMDNS : public Zeroconf {
|
||||
TinySVCMDNS();
|
||||
virtual ~TinySVCMDNS();
|
||||
|
||||
virtual void Publish(
|
||||
protected:
|
||||
virtual void PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
const QByteArray& name,
|
||||
quint16 port);
|
||||
|
||||
private:
|
||||
|
@ -52,3 +52,16 @@ QByteArray Zeroconf::TruncateName(const QString& name) {
|
||||
truncated_utf8.append('\0');
|
||||
return truncated_utf8;
|
||||
}
|
||||
|
||||
void Zeroconf::Publish(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
quint16 port) {
|
||||
QByteArray truncated_name = TruncateName(name);
|
||||
PublishInternal(
|
||||
domain,
|
||||
type,
|
||||
truncated_name,
|
||||
port);
|
||||
}
|
||||
|
@ -7,17 +7,24 @@ class Zeroconf {
|
||||
public:
|
||||
virtual ~Zeroconf();
|
||||
|
||||
virtual void Publish(
|
||||
void Publish(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
quint16 port) = 0;
|
||||
quint16 port);
|
||||
|
||||
static Zeroconf* GetZeroconf();
|
||||
|
||||
// Truncate a QString to 63 bytes of UTF-8.
|
||||
static QByteArray TruncateName(const QString& name);
|
||||
|
||||
protected:
|
||||
virtual void PublishInternal(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QByteArray& name,
|
||||
quint16 port) = 0;
|
||||
|
||||
private:
|
||||
static Zeroconf* sInstance;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user