[mpd] Consistent playlist name setup (#450)
This commit is contained in:
parent
bb451802d2
commit
b363c0dac2
57
src/mpd.c
57
src/mpd.c
|
@ -1968,7 +1968,7 @@ mpd_command_plchangesposid(struct evbuffer *evbuf, int argc, char **argv, char *
|
||||||
static int
|
static int
|
||||||
mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx)
|
mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char *path;
|
||||||
struct playlist_info *pli;
|
struct playlist_info *pli;
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct db_media_file_info dbmfi;
|
struct db_media_file_info dbmfi;
|
||||||
|
@ -1980,18 +1980,19 @@ mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **e
|
||||||
return ACK_ERROR_ARG;
|
return ACK_ERROR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(argv[1], "/", 1) == 0)
|
if (!default_pl_dir || strstr(argv[1], ":/"))
|
||||||
ret = snprintf(path, sizeof(path), "%s", argv[1]);
|
|
||||||
else
|
|
||||||
ret = snprintf(path, sizeof(path), "/%s", argv[1]);
|
|
||||||
|
|
||||||
if (ret >= sizeof(path))
|
|
||||||
{
|
{
|
||||||
*errmsg = safe_asprintf("Length of path exceeds the PATH_MAX value '%s'", argv[1]);
|
// Argument is a virtual path, make sure it starts with a '/'
|
||||||
return ACK_ERROR_ARG;
|
path = prepend_slash(argv[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Argument is a playlist name, prepend default playlist directory
|
||||||
|
path = safe_asprintf("%s/%s%s", default_pl_dir, argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pli = db_pl_fetch_byvirtualpath(path);
|
pli = db_pl_fetch_byvirtualpath(path);
|
||||||
|
free(path);
|
||||||
if (!pli)
|
if (!pli)
|
||||||
{
|
{
|
||||||
*errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
|
*errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
|
||||||
|
@ -2036,7 +2037,7 @@ mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **e
|
||||||
static int
|
static int
|
||||||
mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx)
|
mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char *path;
|
||||||
struct playlist_info *pli;
|
struct playlist_info *pli;
|
||||||
struct query_params qp;
|
struct query_params qp;
|
||||||
struct db_media_file_info dbmfi;
|
struct db_media_file_info dbmfi;
|
||||||
|
@ -2048,18 +2049,19 @@ mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char
|
||||||
return ACK_ERROR_ARG;
|
return ACK_ERROR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(argv[1], "/", 1) == 0)
|
if (!default_pl_dir || strstr(argv[1], ":/"))
|
||||||
ret = snprintf(path, sizeof(path), "%s", argv[1]);
|
|
||||||
else
|
|
||||||
ret = snprintf(path, sizeof(path), "/%s", argv[1]);
|
|
||||||
|
|
||||||
if (ret >= sizeof(path))
|
|
||||||
{
|
{
|
||||||
*errmsg = safe_asprintf("Length of path exceeds the PATH_MAX value '%s'", argv[1]);
|
// Argument is a virtual path, make sure it starts with a '/'
|
||||||
return ACK_ERROR_ARG;
|
path = prepend_slash(argv[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Argument is a playlist name, prepend default playlist directory
|
||||||
|
path = safe_asprintf("%s/%s%s", default_pl_dir, argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pli = db_pl_fetch_byvirtualpath(path);
|
pli = db_pl_fetch_byvirtualpath(path);
|
||||||
|
free(path);
|
||||||
if (!pli)
|
if (!pli)
|
||||||
{
|
{
|
||||||
*errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
|
*errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
|
||||||
|
@ -2161,7 +2163,7 @@ mpd_command_listplaylists(struct evbuffer *evbuf, int argc, char **argv, char **
|
||||||
static int
|
static int
|
||||||
mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx)
|
mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char *path;
|
||||||
struct playlist_info *pli;
|
struct playlist_info *pli;
|
||||||
struct player_status status;
|
struct player_status status;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -2172,18 +2174,19 @@ mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, s
|
||||||
return ACK_ERROR_ARG;
|
return ACK_ERROR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(argv[1], "/", 1) == 0)
|
if (!default_pl_dir || strstr(argv[1], ":/"))
|
||||||
ret = snprintf(path, sizeof(path), "%s", argv[1]);
|
|
||||||
else
|
|
||||||
ret = snprintf(path, sizeof(path), "/%s", argv[1]);
|
|
||||||
|
|
||||||
if (ret >= sizeof(path))
|
|
||||||
{
|
{
|
||||||
*errmsg = safe_asprintf("Length of path exceeds the PATH_MAX value '%s'", argv[1]);
|
// Argument is a virtual path, make sure it starts with a '/'
|
||||||
return ACK_ERROR_ARG;
|
path = prepend_slash(argv[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Argument is a playlist name, prepend default playlist directory
|
||||||
|
path = safe_asprintf("%s/%s%s", default_pl_dir, argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pli = db_pl_fetch_byvirtualpath(path);
|
pli = db_pl_fetch_byvirtualpath(path);
|
||||||
|
free(path);
|
||||||
if (!pli)
|
if (!pli)
|
||||||
{
|
{
|
||||||
*errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
|
*errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
|
||||||
|
|
Loading…
Reference in New Issue