]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Improve playlist_open().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 7 Mar 2022 18:20:07 +0000 (19:20 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Oct 2022 18:36:21 +0000 (20:36 +0200)
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.

afs.c
afs.h
playlist.c

diff --git a/afs.c b/afs.c
index f9dd7583df42a3b5d8bf48fe36ccdea88020c3d4..0aa81cface17c1e7665561a24d2115312c9baf6e 100644 (file)
--- 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)) {
                }
        } 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);
                        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 fb3a4f26015def92762069e39804561b4e05acfb..14d943f8154035edff69c04fd37b2397d79eca3d 100644 (file)
--- 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 */
 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);
 
 void playlist_close(void);
 int playlist_check_callback(struct afs_callback_arg *aca);
 
index db9d091a388af704b69cb3fa7667e5070cca0de1..5cfe1a75196d5baf446507b21ee551044ecf446a 100644 (file)
@@ -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 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.
  *
  *
  * 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;
 {
        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) {
        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();
                return ret;
        }
        playlist_close();