mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-14 16:25:03 -05:00
Keep Avahi code inside mdns_avahi.c
This commit is contained in:
parent
7ba3b23f63
commit
8411aa48b7
@ -2,9 +2,9 @@
|
||||
#ifndef __MDNS_H__
|
||||
#define __MDNS_H__
|
||||
|
||||
#include <avahi-common/strlst.h>
|
||||
#include "misc.h"
|
||||
|
||||
typedef void (* mdns_browse_cb)(const char *name, const char *type, const char *domain, const char *hostname, int family, const char *address, int port, AvahiStringList *txt);
|
||||
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);
|
||||
|
||||
/* mDNS interface functions */
|
||||
/* Call only from the main thread */
|
||||
|
@ -365,9 +365,12 @@ browse_resolve_callback(AvahiServiceResolver *r, AvahiIfIndex intf, AvahiProtoco
|
||||
const char *name, const char *type, const char *domain, const char *hostname, const AvahiAddress *addr,
|
||||
uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void *userdata)
|
||||
{
|
||||
struct mdns_browser *mb;
|
||||
char address[AVAHI_ADDRESS_STR_MAX + IF_NAMESIZE + 2];
|
||||
char ifname[IF_NAMESIZE];
|
||||
struct keyval txt_kv;
|
||||
struct mdns_browser *mb;
|
||||
char *key;
|
||||
char *value;
|
||||
size_t len;
|
||||
int family;
|
||||
int ll;
|
||||
@ -440,9 +443,46 @@ browse_resolve_callback(AvahiServiceResolver *r, AvahiIfIndex intf, AvahiProtoco
|
||||
break;
|
||||
}
|
||||
|
||||
if (family == -1)
|
||||
break;
|
||||
|
||||
memset(&txt_kv, 0, sizeof(struct keyval));
|
||||
|
||||
while (txt)
|
||||
{
|
||||
len = avahi_string_list_get_size(txt);
|
||||
key = (char *)avahi_string_list_get_text(txt);
|
||||
|
||||
value = memchr(key, '=', len);
|
||||
if (!value)
|
||||
{
|
||||
value = "";
|
||||
len = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*value = '\0';
|
||||
value++;
|
||||
|
||||
len -= strlen(key) + 1;
|
||||
}
|
||||
|
||||
ret = keyval_add_size(&txt_kv, key, value, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_MDNS, "Could not build TXT record keyval\n");
|
||||
|
||||
goto out_clear_txt_kv;
|
||||
}
|
||||
|
||||
txt = avahi_string_list_get_next(txt);
|
||||
}
|
||||
|
||||
/* Execute callback (mb->cb) with all the data */
|
||||
if (family != -1)
|
||||
mb->cb(name, type, domain, hostname, family, address, port, txt);
|
||||
mb->cb(name, type, domain, hostname, family, address, port, &txt_kv);
|
||||
|
||||
out_clear_txt_kv:
|
||||
keyval_clear(&txt_kv);
|
||||
break;
|
||||
}
|
||||
|
||||
|
42
src/player.c
42
src/player.c
@ -43,8 +43,6 @@
|
||||
# include <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
#include <avahi-common/malloc.h>
|
||||
|
||||
#include <event.h>
|
||||
|
||||
#include <gcrypt.h>
|
||||
@ -2883,19 +2881,16 @@ player_set_update_handler(player_status_handler handler)
|
||||
|
||||
/* Thread: main (mdns) */
|
||||
static void
|
||||
raop_device_cb(const char *name, const char *type, const char *domain, const char *hostname, int family, const char *address, int port, AvahiStringList *txt)
|
||||
raop_device_cb(const char *name, const char *type, const char *domain, const char *hostname, int family, const char *address, int port, struct keyval *txt)
|
||||
{
|
||||
struct player_status status;
|
||||
AvahiStringList *p;
|
||||
struct raop_device *rd;
|
||||
struct raop_device *prev;
|
||||
cfg_t *apex;
|
||||
const char *p;
|
||||
char *at_name;
|
||||
char *password;
|
||||
char *key;
|
||||
char *val;
|
||||
uint64_t id;
|
||||
size_t valsz;
|
||||
int has_password;
|
||||
int encrypt;
|
||||
int last_active;
|
||||
@ -2999,7 +2994,7 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
|
||||
}
|
||||
else
|
||||
{
|
||||
p = avahi_string_list_find(txt, "tp");
|
||||
p = keyval_get(txt, "tp");
|
||||
if (!p)
|
||||
{
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: no tp field in TXT record!\n", name);
|
||||
@ -3007,27 +3002,22 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
|
||||
return;
|
||||
}
|
||||
|
||||
avahi_string_list_get_pair(p, &key, &val, &valsz);
|
||||
avahi_free(key);
|
||||
if (!val)
|
||||
if (*p == '\0')
|
||||
{
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: tp has no value\n", name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strstr(val, "UDP"))
|
||||
if (!strstr(p, "UDP"))
|
||||
{
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: device does not support AirTunes v2 (tp=%s), discarding\n", name, val);
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: device does not support AirTunes v2 (tp=%s), discarding\n", name, p);
|
||||
|
||||
avahi_free(val);
|
||||
return;
|
||||
}
|
||||
|
||||
avahi_free(val);
|
||||
|
||||
password = NULL;
|
||||
p = avahi_string_list_find(txt, "pw");
|
||||
p = keyval_get(txt, "pw");
|
||||
if (!p)
|
||||
{
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: no pw field in TXT record!\n", name);
|
||||
@ -3035,18 +3025,14 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
|
||||
return;
|
||||
}
|
||||
|
||||
avahi_string_list_get_pair(p, &key, &val, &valsz);
|
||||
avahi_free(key);
|
||||
if (!val)
|
||||
if (*p == '\0')
|
||||
{
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: pw has no value\n", name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
has_password = (strcmp(val, "false") != 0);
|
||||
|
||||
avahi_free(val);
|
||||
has_password = (strcmp(p, "false") != 0);
|
||||
|
||||
if (has_password)
|
||||
{
|
||||
@ -3061,7 +3047,7 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
|
||||
}
|
||||
|
||||
encrypt = 1;
|
||||
p = avahi_string_list_find(txt, "am");
|
||||
p = keyval_get(txt, "am");
|
||||
if (!p)
|
||||
{
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: no am field in TXT record!\n", name);
|
||||
@ -3069,20 +3055,16 @@ raop_device_cb(const char *name, const char *type, const char *domain, const cha
|
||||
goto no_am;
|
||||
}
|
||||
|
||||
avahi_string_list_get_pair(p, &key, &val, &valsz);
|
||||
avahi_free(key);
|
||||
if (!val)
|
||||
if (*p == '\0')
|
||||
{
|
||||
DPRINTF(E_LOG, L_PLAYER, "AirTunes %s: am has no value\n", name);
|
||||
|
||||
goto no_am;
|
||||
}
|
||||
|
||||
if (strncmp(val, "AppleTV", strlen("AppleTV")) == 0)
|
||||
if (strncmp(p, "AppleTV", strlen("AppleTV")) == 0)
|
||||
encrypt = 0;
|
||||
|
||||
avahi_free(val);
|
||||
|
||||
no_am:
|
||||
pthread_mutex_lock(&dev_lck);
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
@ -45,8 +46,6 @@
|
||||
# include <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
#include <avahi-common/malloc.h>
|
||||
|
||||
#include <event.h>
|
||||
#include "evhttp/evhttp.h"
|
||||
|
||||
@ -671,14 +670,11 @@ pairing_cb(int fd, short event, void *arg)
|
||||
|
||||
/* Thread: main (mdns) */
|
||||
static void
|
||||
touch_remote_cb(const char *name, const char *type, const char *domain, const char *hostname, int family, const char *address, int port, AvahiStringList *txt)
|
||||
touch_remote_cb(const char *name, const char *type, const char *domain, const char *hostname, int family, const char *address, int port, struct keyval *txt)
|
||||
{
|
||||
AvahiStringList *p;
|
||||
const char *p;
|
||||
char *devname;
|
||||
char *paircode;
|
||||
char *key;
|
||||
char *val;
|
||||
size_t valsz;
|
||||
int ret;
|
||||
|
||||
if (port < 0)
|
||||
@ -696,7 +692,7 @@ touch_remote_cb(const char *name, const char *type, const char *domain, const ch
|
||||
else
|
||||
{
|
||||
/* Get device name (DvNm field in TXT record) */
|
||||
p = avahi_string_list_find(txt, "DvNm");
|
||||
p = keyval_get(txt, "DvNm");
|
||||
if (!p)
|
||||
{
|
||||
DPRINTF(E_LOG, L_REMOTE, "Remote %s: no DvNm in TXT record!\n", name);
|
||||
@ -704,17 +700,14 @@ touch_remote_cb(const char *name, const char *type, const char *domain, const ch
|
||||
return;
|
||||
}
|
||||
|
||||
avahi_string_list_get_pair(p, &key, &val, &valsz);
|
||||
avahi_free(key);
|
||||
if (!val)
|
||||
if (*p == '\0')
|
||||
{
|
||||
DPRINTF(E_LOG, L_REMOTE, "Remote %s: DvNm has no value\n", name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
devname = strndup(val, valsz);
|
||||
avahi_free(val);
|
||||
devname = strdup(p);
|
||||
if (!devname)
|
||||
{
|
||||
DPRINTF(E_LOG, L_REMOTE, "Out of memory for device name\n");
|
||||
@ -723,7 +716,7 @@ touch_remote_cb(const char *name, const char *type, const char *domain, const ch
|
||||
}
|
||||
|
||||
/* Get pairing code (Pair field in TXT record) */
|
||||
p = avahi_string_list_find(txt, "Pair");
|
||||
p = keyval_get(txt, "Pair");
|
||||
if (!p)
|
||||
{
|
||||
DPRINTF(E_LOG, L_REMOTE, "Remote %s: no Pair in TXT record!\n", name);
|
||||
@ -732,9 +725,7 @@ touch_remote_cb(const char *name, const char *type, const char *domain, const ch
|
||||
return;
|
||||
}
|
||||
|
||||
avahi_string_list_get_pair(p, &key, &val, &valsz);
|
||||
avahi_free(key);
|
||||
if (!val)
|
||||
if (*p == '\0')
|
||||
{
|
||||
DPRINTF(E_LOG, L_REMOTE, "Remote %s: Pair has no value\n", name);
|
||||
|
||||
@ -742,8 +733,7 @@ touch_remote_cb(const char *name, const char *type, const char *domain, const ch
|
||||
return;
|
||||
}
|
||||
|
||||
paircode = strndup(val, valsz);
|
||||
avahi_free(val);
|
||||
paircode = strdup(p);
|
||||
if (!paircode)
|
||||
{
|
||||
DPRINTF(E_LOG, L_REMOTE, "Out of memory for paircode\n");
|
||||
|
Loading…
Reference in New Issue
Block a user