Skip to content

Commit

Permalink
fix DMAP parsing and a few compiler warning - release
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe44 committed Aug 26, 2023
1 parent 888371e commit b5b7dc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
16 changes: 9 additions & 7 deletions components/raop/dmap_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ typedef struct {
} dmap_field;

static const dmap_field dmap_fields[] = {
#ifdef DMAP_FULL
{ "abal", DMAP_DICT, DMAP_STR, "daap.browsealbumlisting" },
{ "abar", DMAP_DICT, DMAP_STR, "daap.browseartistlisting" },
{ "abcp", DMAP_DICT, DMAP_STR, "daap.browsecomposerlisting" },
{ "abgn", DMAP_DICT, DMAP_STR, "daap.browsegenrelisting" },
#ifdef DMAP_FULL
{ "abpl", DMAP_UINT, 0, "daap.baseplaylist" },
{ "abro", DMAP_DICT, 0, "daap.databasebrowse" },
{ "adbs", DMAP_DICT, 0, "daap.databasesongs" },
Expand Down Expand Up @@ -139,8 +139,10 @@ static const dmap_field dmap_fields[] = {
{ "asaa", DMAP_STR, 0, "daap.songalbumartist" },
{ "asac", DMAP_UINT, 0, "daap.songartworkcount" },
{ "asai", DMAP_UINT, 0, "daap.songalbumid" },
#endif
{ "asal", DMAP_STR, 0, "daap.songalbum" },
{ "asar", DMAP_STR, 0, "daap.songartist" },
#ifdef DMAP_FULL
{ "asas", DMAP_UINT, 0, "daap.songalbumuserratingstatus" },
{ "asbk", DMAP_UINT, 0, "daap.bookmarkable" },
{ "asbo", DMAP_UINT, 0, "daap.songbookmark" },
Expand Down Expand Up @@ -257,12 +259,12 @@ static const dmap_field dmap_fields[] = {
{ "meia", DMAP_UINT, 0, "dmap.itemdateadded" },
{ "meip", DMAP_UINT, 0, "dmap.itemdateplayed" },
{ "mext", DMAP_UINT, 0, "dmap.objectextradata" },
#endif
{ "miid", DMAP_UINT, 0, "dmap.itemid" },
{ "mikd", DMAP_UINT, 0, "dmap.itemkind" },
{ "mimc", DMAP_UINT, 0, "dmap.itemcount" },
#endif
{ "minm", DMAP_STR, 0, "dmap.itemname" },
#ifdef DMAP_FULL
#ifdef DMAP_FULL
{ "mlcl", DMAP_DICT, DMAP_DICT, "dmap.listing" },
{ "mlid", DMAP_UINT, 0, "dmap.sessionid" },
{ "mlit", DMAP_ITEM, 0, "dmap.listingitem" },
Expand Down Expand Up @@ -317,7 +319,7 @@ static const dmap_field dmap_fields[] = {
{ "prat", DMAP_UINT, 0, "dpap.imagerating" },
{ "pret", DMAP_DICT, 0, "dpap.retryids" },
{ "pwth", DMAP_UINT, 0, "dpap.imagepixelwidth" }
#endif
#endif
};
static const size_t dmap_field_count = sizeof(dmap_fields) / sizeof(dmap_field);

Expand Down Expand Up @@ -424,7 +426,7 @@ static int dmap_parse_internal(const dmap_settings *settings, const char *buf, s
/* Make a best guess of the type */
field_type = DMAP_UNKNOWN;
field_name = code;
#ifdef DMAP_FULL

if (field_len >= 8) {
/* Look for a four char code followed by a length within the current field */
if (isalpha(p[0] & 0xff) &&
Expand All @@ -435,7 +437,7 @@ static int dmap_parse_internal(const dmap_settings *settings, const char *buf, s
field_type = DMAP_DICT;
}
}

#ifdef DMAP_FULL
if (field_type == DMAP_UNKNOWN) {
size_t i;
int is_string = 1;
Expand All @@ -448,7 +450,7 @@ static int dmap_parse_internal(const dmap_settings *settings, const char *buf, s

field_type = is_string ? DMAP_STR : DMAP_UINT;
}
#endif
#endif
}

switch (field_type) {
Expand Down
12 changes: 6 additions & 6 deletions components/raop/raop.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ struct raop_ctx_s *raop_create(uint32_t host, char *name,
#endif
ctx->running = true;
memcpy(ctx->mac, mac, 6);
snprintf(id, 64, "%02X%02X%02X%02X%02X%02X@%s", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], name);
snprintf(id, 64, "%02X%02X%02X%02X%02X%02X@%s", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], name);
#ifdef WIN32
// seems that Windows snprintf does not add NULL char if actual size > max
id[63] = '\0';
ctx->svc = mdnsd_register_svc(ctx->svr, id, "_raop._tcp.local", ctx->port, NULL, (const char**) txt);
pthread_create(&ctx->thread, NULL, &rtsp_thread, ctx);
#else
LOG_INFO("starting mDNS with %s", id);
ESP_ERROR_CHECK( mdns_service_add(id, "_raop", "_tcp", ctx->port, txt, sizeof(txt) / sizeof(mdns_txt_item_t)) );
mdns_service_add(id, "_raop", "_tcp", ctx->port, (mdns_txt_item_t*) txt, sizeof(txt) / sizeof(mdns_txt_item_t));

ctx->xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
ctx->thread = xTaskCreateStaticPinnedToCore( (TaskFunction_t) rtsp_thread, "RTSP", RTSP_STACK_SIZE, ctx,
Expand Down Expand Up @@ -619,12 +619,12 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
NULL
};

LOG_INFO("[%p]: received metadata", ctx);
settings.ctx = &metadata;
memset(&metadata, 0, sizeof(struct metadata_s));
if (!dmap_parse(&settings, body, len)) {
LOG_INFO("[%p]: received metadata\n\tartist: %s\n\talbum: %s\n\ttitle: %s",
ctx, metadata.artist, metadata.album, metadata.title);
ctx, metadata.artist ? metadata.artist : "", metadata.album ? metadata.album : "",
metadata.title ? metadata.title : "");
success = ctx->cmd_cb(RAOP_METADATA, metadata.artist, metadata.album, metadata.title);
free_metadata(&metadata);
}
Expand Down Expand Up @@ -873,7 +873,7 @@ static int base64_pad(char *src, char **padded)
/*----------------------------------------------------------------------------*/
static int pos(char c)
{
char *p;
const char *p;
for (p = base64_chars; *p; p++)
if (*p == c)
return p - base64_chars;
Expand Down Expand Up @@ -959,7 +959,7 @@ static int base64_decode(const char *str, void *data)
/*----------------------------------------------------------------------------*/
static void on_dmap_string(void *ctx, const char *code, const char *name, const char *buf, size_t len) {
struct metadata_s *metadata = (struct metadata_s *) ctx;
// to gain space, most of the code have been removed from dmap_parser.c (define DMAP_FULL)
// to gain space, most of the code have been removed from dmap_parser.c (define DMAP_FULL
if (!strcasecmp(code, "asar")) metadata->artist = strndup(buf, len);
else if (!strcasecmp(code, "asal")) metadata->album = strndup(buf, len);
else if (!strcasecmp(code, "minm")) metadata->title = strndup(buf, len);
Expand Down

0 comments on commit b5b7dc6

Please sign in to comment.