From: Andre Noll Date: Mon, 7 Mar 2022 18:20:07 +0000 (+0100) Subject: Improve playlist_open(). X-Git-Tag: v0.7.2~14^2~16 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=b36883d75a07842740562eb654d5642914042d4b;p=paraslash.git Improve playlist_open(). It's easier to let playlist_open() fill in the error text than to do this in the caller. This is also how the counterpart of playlist_open(), change_current_mood(), is implemented. Drop the server log message because this error is usually caused by a client passing a misspelt playlist name. Fix the documentation of the return value of the function while at it: It returns the playlist length on success, and activate_mood_or_playlist(), its single caller in afs.c, depends on that. --- diff --git a/afs.c b/afs.c index f9dd7583..0aa81cfa 100644 --- a/afs.c +++ b/afs.c @@ -438,10 +438,7 @@ static int activate_mood_or_playlist(const char *arg, int *num_admissible, } } else { if (!strncmp(arg, "p/", 2)) { - ret = playlist_open(arg + 2); - if (ret < 0 && errmsg) - *errmsg = make_message( "could not open %s", - arg); + ret = playlist_open(arg + 2, errmsg); mode = PLAY_MODE_PLAYLIST; } else if (!strncmp(arg, "m/", 2)) { ret = change_current_mood(arg + 2, errmsg); diff --git a/afs.h b/afs.h index fb3a4f26..14d943f8 100644 --- a/afs.h +++ b/afs.h @@ -264,7 +264,7 @@ int aft_check_callback(struct afs_callback_arg *aca); void free_status_items(void); /* playlist */ -int playlist_open(const char *name); +int playlist_open(const char *name, char **errmsg); void playlist_close(void); int playlist_check_callback(struct afs_callback_arg *aca); diff --git a/playlist.c b/playlist.c index db9d091a..5cfe1a75 100644 --- a/playlist.c +++ b/playlist.c @@ -147,16 +147,18 @@ void playlist_close(void) } /** - * Open the given playlist. + * Open and load the given playlist. * * \param name The name of the playlist to open. + * \param errmsg To be sent to the client (if called via select command). * * Files which are listed in the playlist, but not contained in the database * are ignored. This is not considered an error. * - * \return Standard. + * \return The length of the loaded playlist on success, negative error code + * else. */ -int playlist_open(const char *name) +int playlist_open(const char *name, char **errmsg) { struct osl_object obj; int ret; @@ -166,7 +168,9 @@ int playlist_open(const char *name) obj.size = strlen(obj.data); ret = osl(osl_get_row(playlists_table, BLOBCOL_NAME, &obj, &row)); if (ret < 0) { - PARA_NOTICE_LOG("failed to load playlist %s\n", name); + if (errmsg) + *errmsg = make_message("could not open playlist %s", + name); return ret; } playlist_close();