diff --git a/src/mpd_client/search.c b/src/mpd_client/search.c index ae6abac5b..9985ce7ac 100644 --- a/src/mpd_client/search.c +++ b/src/mpd_client/search.c @@ -151,13 +151,14 @@ bool mpd_client_search_add_to_queue_window(struct t_partition_state *partition_s * @param album_config album configuration * @return newly allocated sds string */ -sds get_search_expression_album(enum mpd_tag_type tag_albumartist, struct mpd_song *album, +sds get_search_expression_album(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album, const struct t_albums_config *album_config) { - sds expression = sdsnewlen("(", 1); - expression = append_search_expression_album(tag_albumartist, album, album_config, expression); - expression = sdscatlen(expression, ")", 1); - return expression; + sdsclear(buffer); + buffer = sdscatlen(buffer, "(", 1); + buffer = append_search_expression_album(tag_albumartist, album, album_config, buffer); + buffer = sdscatlen(buffer, ")", 1); + return buffer; } /** @@ -168,16 +169,17 @@ sds get_search_expression_album(enum mpd_tag_type tag_albumartist, struct mpd_so * @param album_config album configuration * @return newly allocated sds string */ -sds get_search_expression_album_disc(enum mpd_tag_type tag_albumartist, struct mpd_song *album, +sds get_search_expression_album_disc(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album, const char *disc, const struct t_albums_config *album_config) { - sds expression = sdsnewlen("(", 1); - expression = append_search_expression_album(tag_albumartist, album, album_config, expression); + sdsclear(buffer); + buffer = sdscatlen(buffer, "(", 1); + buffer = append_search_expression_album(tag_albumartist, album, album_config, buffer); //and for cd - expression = sdscat(expression, " AND "); - expression = escape_mpd_search_expression(expression, "Disc", "==", disc); - expression = sdscatlen(expression, ")", 1); - return expression; + buffer = sdscat(buffer, " AND "); + buffer = escape_mpd_search_expression(buffer, "Disc", "==", disc); + buffer = sdscatlen(buffer, ")", 1); + return buffer; } /** diff --git a/src/mpd_client/search.h b/src/mpd_client/search.h index 50ca9b9c2..486f84f6a 100644 --- a/src/mpd_client/search.h +++ b/src/mpd_client/search.h @@ -25,9 +25,9 @@ bool mpd_client_search_add_to_queue_window(struct t_partition_state *partition_s bool mpd_client_add_search_sort_param(struct t_partition_state *partition_state, const char *sort, bool sortdesc, bool check_version); bool mpd_client_add_search_group_param(struct mpd_connection *conn, enum mpd_tag_type tag); -sds get_search_expression_album(enum mpd_tag_type tag_albumartist, struct mpd_song *album, +sds get_search_expression_album(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album, const struct t_albums_config *album_config); -sds get_search_expression_album_disc(enum mpd_tag_type tag_albumartist, struct mpd_song *album, +sds get_search_expression_album_disc(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album, const char *disc, const struct t_albums_config *album_config); sds escape_mpd_search_expression(sds buffer, const char *tag, const char *operator, const char *value); #endif diff --git a/src/mpd_client/shortcuts.c b/src/mpd_client/shortcuts.c index e7d9fe44a..db746be5d 100644 --- a/src/mpd_client/shortcuts.c +++ b/src/mpd_client/shortcuts.c @@ -94,7 +94,7 @@ bool mpd_client_add_album_to_queue(struct t_partition_state *partition_state, st *error = sdscat(*error, "Album not found"); return false; } - sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist, + sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist, mpd_album, &partition_state->config->albums); const char *sort = NULL; bool sortdesc = false; diff --git a/src/mympd_api/albumart.c b/src/mympd_api/albumart.c index 5d8296857..fe3650100 100644 --- a/src/mympd_api/albumart.c +++ b/src/mympd_api/albumart.c @@ -61,7 +61,7 @@ sds mympd_api_albumart_getcover_by_album_id(struct t_partition_state *partition_ } // search for one song in the album - sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist, + sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist, album, &partition_state->config->albums); if (mpd_search_db_songs(partition_state->conn, false) == false || diff --git a/src/mympd_api/browse.c b/src/mympd_api/browse.c index abcd44a6b..33d74a060 100644 --- a/src/mympd_api/browse.c +++ b/src/mympd_api/browse.c @@ -67,7 +67,7 @@ sds mympd_api_browse_album_detail(struct t_mympd_state *mympd_state, struct t_pa JSONRPC_FACILITY_DATABASE, JSONRPC_SEVERITY_ERROR, "Album not found"); } - sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist, mpd_album, + sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist, mpd_album, &partition_state->config->albums); if (mpd_search_db_songs(partition_state->conn, true) == false || @@ -279,6 +279,7 @@ sds mympd_api_browse_album_list(struct t_mympd_state *mympd_state, struct t_part raxSeek(&iter, "$", NULL, 0); iterator = &raxPrev; } + sds album_exp = sdsempty(); while (iterator(&iter)) { if (entity_count >= offset) { if (entities_returned++) { @@ -291,9 +292,9 @@ sds mympd_api_browse_album_list(struct t_mympd_state *mympd_state, struct t_part buffer = tojson_char(buffer, "FirstSongUri", mpd_song_get_uri(album), false); if (print_stickers == true) { buffer = sdscatlen(buffer, ",", 1); - sds album_exp = get_search_expression_album(mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums); + album_exp = get_search_expression_album(album_exp, mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums); buffer = mympd_api_sticker_get_print_batch(buffer, mympd_state->stickerdb, STICKER_TYPE_FILTER, album_exp, &tagcols->stickers); - FREE_SDS(album_exp); + } buffer = sdscatlen(buffer, "}", 1); } @@ -303,6 +304,7 @@ sds mympd_api_browse_album_list(struct t_mympd_state *mympd_state, struct t_part } } raxStop(&iter); + FREE_SDS(album_exp); if (print_stickers == true) { stickerdb_enter_idle(mympd_state->stickerdb); } diff --git a/src/mympd_api/playlists.c b/src/mympd_api/playlists.c index 74721d93f..29b44db34 100644 --- a/src/mympd_api/playlists.c +++ b/src/mympd_api/playlists.c @@ -356,6 +356,7 @@ bool mympd_api_playlist_content_insert_albums(struct t_partition_state *partitio } struct t_list_node *current = albumids->head; bool rc = true; + sds expression = sdsempty(); while (current != NULL) { struct mpd_song *mpd_album = album_cache_get_album(album_cache, current->key); if (mpd_album == NULL) { @@ -363,17 +364,17 @@ bool mympd_api_playlist_content_insert_albums(struct t_partition_state *partitio *error = sdscat(*error, "Album not found"); break; } - sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist, mpd_album, + expression = get_search_expression_album(expression, partition_state->mpd_state->tag_albumartist, mpd_album, &partition_state->config->albums); const char *sort = NULL; bool sortdesc = false; rc = mpd_client_search_add_to_plist(partition_state, expression, plist, to, sort, sortdesc, error); - FREE_SDS(expression); if (rc == false) { break; } current = current->next; } + FREE_SDS(expression); return rc; } @@ -427,7 +428,7 @@ bool mympd_api_playlist_content_insert_album_disc(struct t_partition_state *part *error = sdscat(*error, "Album not found"); return false; } - sds expression = get_search_expression_album_disc(partition_state->mpd_state->tag_albumartist, mpd_album, + sds expression = get_search_expression_album_disc(sdsempty(), partition_state->mpd_state->tag_albumartist, mpd_album, disc, &partition_state->config->albums); const char *sort = NULL; bool sortdesc = false; diff --git a/src/mympd_api/queue.c b/src/mympd_api/queue.c index 244b02d1b..68dd9f720 100644 --- a/src/mympd_api/queue.c +++ b/src/mympd_api/queue.c @@ -495,7 +495,7 @@ bool mympd_api_queue_insert_album_disc(struct t_partition_state *partition_state *error = sdscat(*error, "Album not found"); return false; } - sds expression = get_search_expression_album_disc(partition_state->mpd_state->tag_albumartist, + sds expression = get_search_expression_album_disc(sdsempty(), partition_state->mpd_state->tag_albumartist, mpd_album, disc, &partition_state->config->albums); const char *sort = NULL; bool sortdesc = false; @@ -568,7 +568,7 @@ bool mympd_api_queue_insert_album_range(struct t_partition_state *partition_stat unsigned end_uint = end == -1 ? UINT_MAX : (unsigned)end; - sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist, + sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist, mpd_album, &partition_state->config->albums); const char *sort = "Disc"; bool sortdesc = false; diff --git a/src/mympd_api/sticker.c b/src/mympd_api/sticker.c index d8381ea88..e7f8487fc 100644 --- a/src/mympd_api/sticker.c +++ b/src/mympd_api/sticker.c @@ -259,7 +259,7 @@ sds mympd_api_get_sticker_uri(struct t_mympd_state *mympd_state, sds uri, enum m if (album != NULL) { *type = STICKER_TYPE_FILTER; FREE_SDS(uri); - return get_search_expression_album(mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums); + return get_search_expression_album(sdsempty(), mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums); } return uri; }