mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 07:05:57 -05:00
[mdns] Remove ipv4/ipv6 argument to mdns_browse
Make sure mdns_browse() always works the same, and follows user config.
This commit is contained in:
parent
7871d71a9c
commit
dd0f0ece78
@ -8,6 +8,8 @@ enum mdns_options
|
||||
{
|
||||
// Test connection to device and only call back if successful
|
||||
MDNS_CONNECTION_TEST = (1 << 1),
|
||||
// Only browse for ipv4 services
|
||||
MDNS_IPV4ONLY = (1 << 2),
|
||||
};
|
||||
|
||||
typedef void (* mdns_browse_cb)(const char *name, const char *type, const char *domain, const char *hostname, int family, const char *address, int port, struct keyval *txt);
|
||||
@ -58,13 +60,11 @@ mdns_cname(char *name);
|
||||
* Call only from the main thread!
|
||||
*
|
||||
* @in type Type of service to look for, e.g. "_raop._tcp"
|
||||
* @in family AF_INET to browse for ipv4 services, AF_INET6 for ipv6,
|
||||
AF_UNSPEC for both
|
||||
* @in flags See mdns_options (only supported by Avahi implementation)
|
||||
* @in cb Callback when service state changes (e.g. appears/disappears)
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
mdns_browse(char *type, int family, mdns_browse_cb cb, enum mdns_options flags);
|
||||
mdns_browse(char *type, mdns_browse_cb cb, enum mdns_options flags);
|
||||
|
||||
#endif /* !__MDNS_H__ */
|
||||
|
@ -52,6 +52,7 @@
|
||||
#endif
|
||||
|
||||
#include "logger.h"
|
||||
#include "conffile.h"
|
||||
#include "mdns.h"
|
||||
|
||||
#define MDNSERR avahi_strerror(avahi_client_errno(mdns_client))
|
||||
@ -1160,15 +1161,21 @@ mdns_cname(char *name)
|
||||
}
|
||||
|
||||
int
|
||||
mdns_browse(char *type, int family, mdns_browse_cb cb, enum mdns_options flags)
|
||||
mdns_browse(char *type, mdns_browse_cb cb, enum mdns_options flags)
|
||||
{
|
||||
struct mdns_browser *mb;
|
||||
AvahiServiceBrowser *b;
|
||||
int family;
|
||||
|
||||
DPRINTF(E_DBG, L_MDNS, "Adding service browser for type %s\n", type);
|
||||
|
||||
CHECK_NULL(L_MDNS, mb = calloc(1, sizeof(struct mdns_browser)));
|
||||
|
||||
if (flags & MDNS_IPV4ONLY || !cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"))
|
||||
family = AF_INET;
|
||||
else
|
||||
family = AF_UNSPEC;
|
||||
|
||||
mb->protocol = avahi_af_to_proto(family);
|
||||
mb->type = strdup(type);
|
||||
mb->flags = flags;
|
||||
|
@ -50,6 +50,7 @@
|
||||
#endif
|
||||
|
||||
#include "logger.h"
|
||||
#include "conffile.h"
|
||||
|
||||
/* Main event base, from main.c */
|
||||
extern struct event_base *evbase_main;
|
||||
@ -872,10 +873,11 @@ mdns_browse_callback(DNSServiceRef sdRef, DNSServiceFlags flags,
|
||||
}
|
||||
|
||||
int
|
||||
mdns_browse(char *regtype, int family, mdns_browse_cb cb, enum mdns_options flags)
|
||||
mdns_browse(char *regtype, mdns_browse_cb cb, enum mdns_options flags)
|
||||
{
|
||||
struct mdns_browser *mb;
|
||||
DNSServiceErrorType err;
|
||||
int family;
|
||||
|
||||
DPRINTF(E_DBG, L_MDNS, "Adding service browser for type %s\n", regtype);
|
||||
|
||||
@ -884,6 +886,11 @@ mdns_browse(char *regtype, int family, mdns_browse_cb cb, enum mdns_options flag
|
||||
mb->flags = flags;
|
||||
mb->cb = cb;
|
||||
|
||||
if (flags & MDNS_IPV4ONLY || !cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"))
|
||||
family = AF_INET;
|
||||
else
|
||||
family = AF_UNSPEC;
|
||||
|
||||
/* flags are ignored in DNS-SD implementation */
|
||||
switch(family) {
|
||||
case AF_UNSPEC:
|
||||
|
@ -4363,7 +4363,6 @@ static int
|
||||
airplay_init(void)
|
||||
{
|
||||
int v6enabled;
|
||||
int family;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
@ -4412,15 +4411,7 @@ airplay_init(void)
|
||||
goto out_stop_timing;
|
||||
}
|
||||
|
||||
if (v6enabled)
|
||||
v6enabled = !((timing_6svc.fd < 0) || (control_6svc.fd < 0));
|
||||
|
||||
if (v6enabled)
|
||||
family = AF_UNSPEC;
|
||||
else
|
||||
family = AF_INET;
|
||||
|
||||
ret = mdns_browse("_airplay._tcp", family, airplay_device_cb, MDNS_CONNECTION_TEST);
|
||||
ret = mdns_browse("_airplay._tcp", airplay_device_cb, MDNS_CONNECTION_TEST);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_AIRPLAY, "Could not add mDNS browser for AirPlay devices\n");
|
||||
|
@ -2445,7 +2445,6 @@ static int
|
||||
cast_init(void)
|
||||
{
|
||||
struct decode_ctx *decode_ctx;
|
||||
int family;
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
@ -2484,12 +2483,7 @@ cast_init(void)
|
||||
goto out_tls_deinit;
|
||||
}
|
||||
|
||||
if (cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"))
|
||||
family = AF_UNSPEC;
|
||||
else
|
||||
family = AF_INET;
|
||||
|
||||
ret = mdns_browse("_googlecast._tcp", family, cast_device_cb, 0);
|
||||
ret = mdns_browse("_googlecast._tcp", cast_device_cb, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_CAST, "Could not add mDNS browser for Chromecast devices\n");
|
||||
|
@ -4815,7 +4815,6 @@ raop_init(void)
|
||||
char *ptr;
|
||||
gpg_error_t gc_err;
|
||||
int v6enabled;
|
||||
int family;
|
||||
int ret;
|
||||
|
||||
timing_4svc.fd = -1;
|
||||
@ -4900,15 +4899,7 @@ raop_init(void)
|
||||
goto out_stop_timing;
|
||||
}
|
||||
|
||||
if (v6enabled)
|
||||
v6enabled = !((timing_6svc.fd < 0) || (control_6svc.fd < 0));
|
||||
|
||||
if (v6enabled)
|
||||
family = AF_UNSPEC;
|
||||
else
|
||||
family = AF_INET;
|
||||
|
||||
ret = mdns_browse("_raop._tcp", family, raop_device_cb, MDNS_CONNECTION_TEST);
|
||||
ret = mdns_browse("_raop._tcp", raop_device_cb, MDNS_CONNECTION_TEST);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_RAOP, "Could not add mDNS browser for AirPlay devices\n");
|
||||
|
@ -783,7 +783,7 @@ remote_pairing_init(void)
|
||||
cmdbase = commands_base_new(evbase_main, NULL);
|
||||
|
||||
// No ipv6 for remote at the moment
|
||||
ret = mdns_browse("_touch-remote._tcp", AF_INET, touch_remote_cb, 0);
|
||||
ret = mdns_browse("_touch-remote._tcp", touch_remote_cb, MDNS_IPV4ONLY);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_FATAL, L_REMOTE, "Could not browse for Remote services\n");
|
||||
|
Loading…
Reference in New Issue
Block a user