Skip to content

Commit

Permalink
Feat: Support new "protocol" command (MPD 0.24) #1353
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Oct 26, 2024
1 parent 4fa218b commit 2f7ff75
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is a small maintenance release.

- Feat: Add Last-Modified and Added to sort tags in Search and Current Queue view
- Feat: Support new "tagtypes available" command (MPD 0.24) #1352
- Feat: Support new "protocol" command (MPD 0.24) #1353
- Upd: Translations
- Upd: libmympdclient 1.0.31
- Upd: bootstrap.native
Expand Down
42 changes: 26 additions & 16 deletions src/mpd_client/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "src/lib/log.h"
#include "src/lib/sds_extras.h"
#include "src/mpd_client/errorhandler.h"
#include "src/mpd_client/shortcuts.h"
#include "src/mpd_client/tags.h"
#include "src/mympd_api/requests.h"

Expand Down Expand Up @@ -83,7 +84,7 @@ bool mpd_client_connect(struct t_partition_state *partition_state) {
* @param partition_state pointer to partition state
* @return true on success, else false
*/
bool mpd_client_set_keepalive(struct t_partition_state *partition_state) {
static bool mpd_client_set_keepalive(struct t_partition_state *partition_state) {
if (partition_state->mpd_state->mpd_keepalive == true) {
MYMPD_LOG_INFO(partition_state->name, "Enabling keepalive");
}
Expand All @@ -98,41 +99,50 @@ bool mpd_client_set_keepalive(struct t_partition_state *partition_state) {
* @param partition_state pointer to partition state
* @return true on success, else false
*/
bool mpd_client_set_timeout(struct t_partition_state *partition_state) {
static bool mpd_client_set_timeout(struct t_partition_state *partition_state) {
MYMPD_LOG_INFO(partition_state->name, "Setting timeout to %u ms", partition_state->mpd_state->mpd_timeout);
mpd_connection_set_timeout(partition_state->conn, partition_state->mpd_state->mpd_timeout);
return true;
}

/**
* Sets the binary limit
* Sets mpd connection options binarylimit and protocol features
* @param partition_state pointer to partition state
* @return true on success, else false
*/
bool mpd_client_set_binarylimit(struct t_partition_state *partition_state) {
bool rc = true;
if (mpd_connection_cmp_server_version(partition_state->conn, 0, 22, 4) >= 0 ) {
MYMPD_LOG_INFO(partition_state->name, "Setting binarylimit to %u kB", partition_state->mpd_state->mpd_binarylimit);
mpd_run_binarylimit(partition_state->conn, partition_state->mpd_state->mpd_binarylimit);
sds message = sdsempty();
if (mympd_check_error_and_recover_notify(partition_state, &message, "mpd_run_binarylimit") == false) {
static bool mpd_client_set_protocol_options(struct t_partition_state *partition_state) {
if (mpd_command_list_begin(partition_state->conn, false)) {
if (mpd_connection_cmp_server_version(partition_state->conn, 0, 22, 4) >= 0 ) {
MYMPD_LOG_INFO(partition_state->name, "Setting binarylimit to %u kB", partition_state->mpd_state->mpd_binarylimit);
if (mpd_send_binarylimit(partition_state->conn, partition_state->mpd_state->mpd_binarylimit) == false) {
mympd_set_mpd_failure(partition_state, "Failure adding command to command list mpd_send_binarylimit");
}
}
if (mpd_connection_cmp_server_version(partition_state->conn, 0, 24, 0) >= 0 ) {
MYMPD_LOG_INFO(partition_state->name, "Enabling all protocol features");
if (mpd_send_all_protocol_features(partition_state->conn) == false) {
mympd_set_mpd_failure(partition_state, "Failure adding command to command list mpd_send_all_protocol_features");
}
}
if (mpd_client_command_list_end_check(partition_state) == false) {
sds message = sdsnew("Failure setting protocol options");
ws_notify(message, partition_state->name);
rc = false;
FREE_SDS(message);
}
FREE_SDS(message);
}
return rc;
mpd_response_finish(partition_state->conn);
return mympd_check_error_and_recover(partition_state, NULL, "protocol options");
}

/**
* Sets mpd connection options binarylimit, keepalive and timeout
* Sets mpd connection settings and features
* @param partition_state pointer to partition state
* @return true on success, else false
*/
bool mpd_client_set_connection_options(struct t_partition_state *partition_state) {
return mpd_client_set_binarylimit(partition_state) &&
mpd_client_set_keepalive(partition_state) &&
return mpd_client_set_keepalive(partition_state) &&
mpd_client_set_timeout(partition_state) &&
mpd_client_set_protocol_options(partition_state) &&
enable_mpd_tags(partition_state, &partition_state->mpd_state->tags_mympd);
}

Expand Down
3 changes: 0 additions & 3 deletions src/mpd_client/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
#include "src/lib/mympd_state.h"

bool mpd_client_connect(struct t_partition_state *partition_state);
bool mpd_client_set_keepalive(struct t_partition_state *partition_state);
bool mpd_client_set_timeout(struct t_partition_state *partition_state);
bool mpd_client_set_binarylimit(struct t_partition_state *partition_state);
bool mpd_client_set_connection_options(struct t_partition_state *partition_state);
void mpd_client_disconnect(struct t_partition_state *partition_state);
void mpd_client_disconnect_silent(struct t_partition_state *partition_state);
Expand Down
19 changes: 11 additions & 8 deletions src/mympd_api/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ sds mympd_api_browse_filesystem(struct t_mympd_state *mympd_state, struct t_part
case MPD_ENTITY_TYPE_PLAYLIST: {
const struct mpd_playlist *pl = mpd_entity_get_playlist(entity);
const char *pl_path = mpd_playlist_get_path(pl);
if (path[0] == '/') {
//do not show mpd playlists in root directory
const char *ext = get_extension_from_filename(pl_path);
if (ext == NULL ||
(strcasecmp(ext, "m3u") != 0 && strcasecmp(ext, "pls") != 0))
{
mpd_entity_free(entity);
break;
if (partition_state->mpd_state->feat.mpd_0_24_0 == false) {
// Workaround for older clients
if (path[0] == '/') {
//do not show mpd playlists in root directory
const char *ext = get_extension_from_filename(pl_path);
if (ext == NULL ||
(strcasecmp(ext, "m3u") != 0 && strcasecmp(ext, "pls") != 0))
{
mpd_entity_free(entity);
break;
}
}
}
sds entity_name = sdsnew(pl_path);
Expand Down

0 comments on commit 2f7ff75

Please sign in to comment.