Files
shairport-sync/bonjour_strings.c
T
Mike Brady 11052b7896 Lot of changes here.
1. check_classic_mac_basic.yml — update to latest macOS-latest
2. docker-on-push-tag-or-pr — dependant updates
3. FFTConvolver — fix a compilation warning when the DEBUG flag is turned off
4. Reorganise some source files — e.g. move most of the metadata stuff into a subdirectory
5. Remove unused special-purpose AirPlay 2 RC event handler.
6. Reorganise source files and source code relating to the standard event handler.
7. Check configuration settings a little more carefully to offer more meaningful diagnostics.
8. Add password to AirPlay 2 and reorganise initialisation to set AirPlay 2 flags accordingly.  Also, remove redundant airplay_pin.
9. Remove redundant debug facility definitions from common.h
10. Make it possible to omit all the dacp stuff from a build.
11. Make it possible to omit metadata multicast from a build.
12. Add AP2-native metadata by setting bit 50 of features to true.
13. Improve stability when pre-empting an existing play session.
14. Fix a few compiler warnings in the pair_ap library.
15. Ensure that the audio format is known before starting synchronisation.
16. Improve handle_configure to set/clear a new config setting. Doesn’t seem to do anything…
17. Experimentally turn off bit 46 of AirPlay 2 features — seems to stop failing pair-verify attempts.
2026-04-26 10:23:18 +01:00

195 lines
8.0 KiB
C

/*
* Bonjour strings manager. This file is part of Shairport Sync.
* Copyright (c) Mike Brady 2014--2025
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "bonjour_strings.h"
#include "common.h"
char *txt_records[128];
char *secondary_txt_records[128];
// mDNS advertisement strings
// Create these strings and then keep them updated.
// When necessary, update the mDNS service records, using e.g. Avahi
// from these sources.
char fwString[128];
char ap1_featuresString[128];
char ap1StatusFlagsString[128];
char ap1ModelString[128];
char ap1SrcversString[128];
char pkString[128];
#ifdef CONFIG_AIRPLAY_2
char deviceIdString[128];
char featuresString[128];
char statusflagsString[128];
char piString[128];
char gidString[128];
char psiString[128];
char fexString[128];
char modelString[128];
char srcversString[128];
char osversString[128];
char ap1OsversString[128];
#endif
#ifdef CONFIG_AIRPLAY_2
void build_bonjour_strings(rtsp_conn_info *conn) {
#else
void build_bonjour_strings(__attribute((unused)) rtsp_conn_info *conn) {
#endif
// Watch out here, the strings that form each entry
// need to be permanent, because we don't know
// when avahi will look at them.
// bnprintf is (should be) the same as snprintf except that it returns a pointer to the resulting
// character string. so this rather odd arranement below allows you to use a snprintf for
// convenience but get the character string as a result, both as a store for the item so that
// Avahi can see it in future and as a pointer
int entry_number = 0;
// the txt_records entries are for the _raop._tcp characteristics
// the secondary_txt_records are for the _airplay._tcp items.
#ifdef CONFIG_AIRPLAY_2
txt_records[entry_number++] = "cn=0,1";
txt_records[entry_number++] = "da=true";
txt_records[entry_number++] = "et=0,1";
if (config.password != NULL)
txt_records[entry_number++] = "pw=true";
uint64_t features_hi = config.airplay_features;
features_hi = (features_hi >> 32) & 0xffffffff;
uint64_t features_lo = config.airplay_features;
features_lo = features_lo & 0xffffffff;
txt_records[entry_number++] =
bnprintf(ap1_featuresString, sizeof(ap1_featuresString), "ft=0x%" PRIX64 ",0x%" PRIX64 "",
features_lo, features_hi);
txt_records[entry_number++] =
bnprintf(fwString, sizeof(fwString), "fv=%s", config.firmware_version);
txt_records[entry_number++] = bnprintf(ap1StatusFlagsString, sizeof(ap1StatusFlagsString),
"sf=0x%" PRIX32, config.airplay_statusflags);
#ifdef CONFIG_METADATA
if (config.get_coverart == 0)
txt_records[entry_number++] = "md=0,2";
else
txt_records[entry_number++] = "md=0,1,2";
#endif
txt_records[entry_number++] =
bnprintf(ap1ModelString, sizeof(ap1ModelString), "am=%s", config.model);
txt_records[entry_number++] = bnprintf(pkString, sizeof(pkString), "pk=%s", config.pk_string);
txt_records[entry_number++] = "tp=UDP";
txt_records[entry_number++] = "vn=65537";
txt_records[entry_number++] =
bnprintf(ap1SrcversString, sizeof(ap1SrcversString), "vs=%s", config.srcvers);
txt_records[entry_number++] =
bnprintf(ap1OsversString, sizeof(ap1OsversString), "ov=%s", config.osvers);
txt_records[entry_number++] = NULL;
#else
// here, just replicate what happens in mdns.h when using those #defines
txt_records[entry_number++] =
bnprintf(ap1StatusFlagsString, sizeof(ap1StatusFlagsString), "sf=0x4");
txt_records[entry_number++] =
bnprintf(fwString, sizeof(fwString), "fv=%s", config.firmware_version);
txt_records[entry_number++] =
bnprintf(ap1ModelString, sizeof(ap1ModelString), "am=%s", config.model);
txt_records[entry_number++] = bnprintf(ap1SrcversString, sizeof(ap1SrcversString), "vs=105.1");
txt_records[entry_number++] = "tp=TCP,UDP";
txt_records[entry_number++] = "vn=65537";
#ifdef CONFIG_METADATA
if (config.get_coverart == 0)
txt_records[entry_number++] = "md=0,2";
else
txt_records[entry_number++] = "md=0,1,2";
#endif
txt_records[entry_number++] = "ss=16";
txt_records[entry_number++] = "sr=44100";
txt_records[entry_number++] = "da=true";
txt_records[entry_number++] = "sv=false";
txt_records[entry_number++] = "et=0,1";
txt_records[entry_number++] = "ek=1";
txt_records[entry_number++] = "cn=0,1";
txt_records[entry_number++] = "ch=2";
txt_records[entry_number++] = "txtvers=1";
if (config.password == NULL)
txt_records[entry_number++] = "pw=false";
else
txt_records[entry_number++] = "pw=true";
txt_records[entry_number++] = NULL;
#endif
#ifdef CONFIG_AIRPLAY_2
// make up a secondary set of text records
entry_number = 0;
secondary_txt_records[entry_number++] = "acl=0";
// secondary_txt_records[entry_number++] = "btaddr=00:00:00:00:00:00";
secondary_txt_records[entry_number++] =
bnprintf(deviceIdString, sizeof(deviceIdString), "deviceid=%s", config.airplay_device_id);
secondary_txt_records[entry_number++] =
bnprintf(fexString, sizeof(fexString), "fex=%s", config.airplay_fex);
secondary_txt_records[entry_number++] =
bnprintf(featuresString, sizeof(featuresString), "features=0x%" PRIX64 ",0x%" PRIX64 "",
features_lo, features_hi); // features_hi and features_lo already calculated.
secondary_txt_records[entry_number++] = bnprintf(statusflagsString, sizeof(statusflagsString),
"flags=0x%" PRIX32, config.airplay_statusflags);
if ((conn != NULL) && (conn->airplay_gid != 0)) {
snprintf(gidString, sizeof(gidString), "gid=%s", conn->airplay_gid);
} else {
snprintf(gidString, sizeof(gidString), "gid=%s", config.airplay_pi);
}
secondary_txt_records[entry_number++] = gidString;
if ((conn != NULL) && (conn->groupContainsGroupLeader != 0)) {
secondary_txt_records[entry_number++] = "igl=0";
secondary_txt_records[entry_number++] = "gcgl=1";
} else {
secondary_txt_records[entry_number++] = "igl=0";
secondary_txt_records[entry_number++] = "gcgl=0";
}
// if ((conn != NULL) && (conn->airplay_gid != 0)) // if it's in a group
// secondary_txt_records[entry_number++] = "isGroupLeader=0";
secondary_txt_records[entry_number++] =
bnprintf(modelString, sizeof(modelString), "model=%s", config.model);
secondary_txt_records[entry_number++] = "protovers=1.1";
secondary_txt_records[entry_number++] =
bnprintf(piString, sizeof(piString), "pi=%s", config.airplay_pi);
secondary_txt_records[entry_number++] =
bnprintf(psiString, sizeof(psiString), "psi=%s", config.airplay_psi);
secondary_txt_records[entry_number++] = pkString; // already calculated
secondary_txt_records[entry_number++] =
bnprintf(srcversString, sizeof(srcversString), "srcvers=%s", config.srcvers);
secondary_txt_records[entry_number++] =
bnprintf(osversString, sizeof(osversString), "osvers=%s", config.osvers);
secondary_txt_records[entry_number++] = "vv=2";
secondary_txt_records[entry_number++] = fwString; // already calculated
secondary_txt_records[entry_number++] = NULL;
#endif
}