From 29b49dd630f6e587c904b43b829402ba5ab37299 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 24 Feb 2021 15:03:58 +0100 Subject: [PATCH] zeroconf/{bonjour,avahi}: pass service_type as parameter --- src/zeroconf/Bonjour.cxx | 11 ++++++----- src/zeroconf/Bonjour.hxx | 6 ++++-- src/zeroconf/Glue.cxx | 6 +++++- src/zeroconf/Helper.cxx | 4 ++-- src/zeroconf/Helper.hxx | 2 +- src/zeroconf/Internal.hxx | 26 -------------------------- src/zeroconf/avahi/Helper.cxx | 6 +++--- src/zeroconf/avahi/Helper.hxx | 3 ++- test/RunZeroconf.cxx | 2 +- 9 files changed, 24 insertions(+), 42 deletions(-) delete mode 100644 src/zeroconf/Internal.hxx diff --git a/src/zeroconf/Bonjour.cxx b/src/zeroconf/Bonjour.cxx index eb2e58adb..c8a03083c 100644 --- a/src/zeroconf/Bonjour.cxx +++ b/src/zeroconf/Bonjour.cxx @@ -18,7 +18,6 @@ */ #include "Bonjour.hxx" -#include "Internal.hxx" #include "util/Domain.hxx" #include "Log.hxx" #include "util/Compiler.h" @@ -53,8 +52,9 @@ RegisterBonjour(const char *name, const char *type, unsigned port, return ref; } -BonjourHelper::BonjourHelper(EventLoop &_loop, const char *name, unsigned port) - :service_ref(RegisterBonjour(name, SERVICE_TYPE, port, +BonjourHelper::BonjourHelper(EventLoop &_loop, const char *name, + const char *service_type, unsigned port) + :service_ref(RegisterBonjour(name, service_type, port, Callback, this)), socket_event(_loop, BIND_THIS_METHOD(OnSocketReady), @@ -86,7 +86,8 @@ BonjourHelper::Callback([[maybe_unused]] DNSServiceRef sdRef, } std::unique_ptr -BonjourInit(EventLoop &loop, const char *service_name, unsigned port) +BonjourInit(EventLoop &loop, const char *name, + const char *service_type, unsigned port) { - return std::make_unique(loop, service_name, port); + return std::make_unique(loop, name, service_type, port); } diff --git a/src/zeroconf/Bonjour.hxx b/src/zeroconf/Bonjour.hxx index 3cb728366..17d0821ab 100644 --- a/src/zeroconf/Bonjour.hxx +++ b/src/zeroconf/Bonjour.hxx @@ -34,7 +34,8 @@ class BonjourHelper final { SocketEvent socket_event; public: - BonjourHelper(EventLoop &_loop, const char *name, unsigned port); + BonjourHelper(EventLoop &_loop, const char *name, + const char *service_name, unsigned port); ~BonjourHelper() noexcept { DNSServiceRefDeallocate(service_ref); @@ -64,6 +65,7 @@ private: * Throws on error. */ std::unique_ptr -BonjourInit(EventLoop &loop, const char *service_name, unsigned port); +BonjourInit(EventLoop &loop, const char *name, + const char *service_type, unsigned port); #endif diff --git a/src/zeroconf/Glue.cxx b/src/zeroconf/Glue.cxx index 34c9612f3..7789efc44 100644 --- a/src/zeroconf/Glue.cxx +++ b/src/zeroconf/Glue.cxx @@ -52,6 +52,9 @@ static constexpr Domain zeroconf_domain("zeroconf"); */ #define SERVICE_NAME "Music Player @ %h" +/* The dns-sd service type qualifier to publish */ +#define SERVICE_TYPE "_mpd._tcp" + #define DEFAULT_ZEROCONF_ENABLED 1 std::unique_ptr @@ -84,5 +87,6 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop) } } - return std::make_unique(loop, serviceName, listen_port); + return std::make_unique(loop, serviceName, + SERVICE_TYPE, listen_port); } diff --git a/src/zeroconf/Helper.cxx b/src/zeroconf/Helper.cxx index b996823b1..fe5586353 100644 --- a/src/zeroconf/Helper.cxx +++ b/src/zeroconf/Helper.cxx @@ -30,7 +30,7 @@ #endif ZeroconfHelper::ZeroconfHelper(EventLoop &event_loop, const char *name, - unsigned port) - :helper(CreateHelper(event_loop, name, port)) {} + const char *service_type, unsigned port) + :helper(CreateHelper(event_loop, name, service_type, port)) {} ZeroconfHelper::~ZeroconfHelper() noexcept = default; diff --git a/src/zeroconf/Helper.hxx b/src/zeroconf/Helper.hxx index 1b39bf440..d020cd0ed 100644 --- a/src/zeroconf/Helper.hxx +++ b/src/zeroconf/Helper.hxx @@ -39,7 +39,7 @@ class ZeroconfHelper final { public: ZeroconfHelper(EventLoop &event_loop, const char *name, - unsigned port); + const char *service_type, unsigned port); ~ZeroconfHelper() noexcept; }; diff --git a/src/zeroconf/Internal.hxx b/src/zeroconf/Internal.hxx deleted file mode 100644 index d270a128e..000000000 --- a/src/zeroconf/Internal.hxx +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2003-2021 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef ZEROCONF_INTERNAL_HXX -#define ZEROCONF_INTERNAL_HXX - -/* The dns-sd service type qualifier to publish */ -#define SERVICE_TYPE "_mpd._tcp" - -#endif diff --git a/src/zeroconf/avahi/Helper.cxx b/src/zeroconf/avahi/Helper.cxx index 213479d36..43548261c 100644 --- a/src/zeroconf/avahi/Helper.cxx +++ b/src/zeroconf/avahi/Helper.cxx @@ -22,7 +22,6 @@ #include "ErrorHandler.hxx" #include "Publisher.hxx" #include "Service.hxx" -#include "../Internal.hxx" #include "util/RuntimeError.hxx" #include "Log.hxx" @@ -53,7 +52,8 @@ AvahiHelper::AvahiHelper(std::shared_ptr _client, AvahiHelper::~AvahiHelper() noexcept = default; std::unique_ptr -AvahiInit(EventLoop &event_loop, const char *service_name, unsigned port) +AvahiInit(EventLoop &event_loop, const char *service_name, + const char *service_type, unsigned port) { if (!avahi_is_valid_service_name(service_name)) throw FormatRuntimeError("Invalid zeroconf_name \"%s\"", @@ -67,7 +67,7 @@ AvahiInit(EventLoop &event_loop, const char *service_name, unsigned port) std::forward_list services; services.emplace_front(AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, - SERVICE_TYPE, port); + service_type, port); auto publisher = std::make_unique(client->client, service_name, diff --git a/src/zeroconf/avahi/Helper.hxx b/src/zeroconf/avahi/Helper.hxx index 3807dcea3..aab4df99b 100644 --- a/src/zeroconf/avahi/Helper.hxx +++ b/src/zeroconf/avahi/Helper.hxx @@ -38,6 +38,7 @@ public: }; std::unique_ptr -AvahiInit(EventLoop &event_loop, const char *service_name, unsigned port); +AvahiInit(EventLoop &event_loop, const char *service_name, + const char *service_type, unsigned port); #endif diff --git a/test/RunZeroconf.cxx b/test/RunZeroconf.cxx index b1d730758..ae74d3d62 100644 --- a/test/RunZeroconf.cxx +++ b/test/RunZeroconf.cxx @@ -29,7 +29,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) EventLoop event_loop; const ShutdownHandler shutdown_handler(event_loop); - const ZeroconfHelper helper(event_loop, "test", 1234); + const ZeroconfHelper helper(event_loop, "test", "_mpd._tcp", 1234); event_loop.Run();