aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/playlist.c16
-rw-r--r--src/playlist_save.c2
-rw-r--r--src/stored_playlist.c28
-rw-r--r--src/stored_playlist.h8
4 files changed, 32 insertions, 22 deletions
diff --git a/src/playlist.c b/src/playlist.c
index 04cb59f3c..ab23691e3 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -1091,19 +1091,3 @@ unsigned getPlaylistSongId(unsigned song)
{
return queue_position_to_id(&playlist.queue, song);
}
-
-/*
- * Not supporting '/' was done out of laziness, and we should really
- * strive to support it in the future.
- *
- * Not supporting '\r' and '\n' is done out of protocol limitations (and
- * arguably laziness), but bending over head over heels to modify the
- * protocol (and compatibility with all clients) to support idiots who
- * put '\r' and '\n' in filenames isn't going to happen, either.
- */
-int is_valid_playlist_name(const char *utf8path)
-{
- return strchr(utf8path, '/') == NULL &&
- strchr(utf8path, '\n') == NULL &&
- strchr(utf8path, '\r') == NULL;
-}
diff --git a/src/playlist_save.c b/src/playlist_save.c
index d5b175071..41538b620 100644
--- a/src/playlist_save.c
+++ b/src/playlist_save.c
@@ -70,7 +70,7 @@ spl_save_queue(const char *name_utf8, const struct queue *queue)
char *path_fs;
FILE *file;
- if (!is_valid_playlist_name(name_utf8))
+ if (!spl_valid_name(name_utf8))
return PLAYLIST_RESULT_BAD_NAME;
path_fs = map_spl_utf8_to_fs(name_utf8);
diff --git a/src/stored_playlist.c b/src/stored_playlist.c
index f802add94..ca2951b5e 100644
--- a/src/stored_playlist.c
+++ b/src/stored_playlist.c
@@ -48,6 +48,25 @@ spl_global_init(void)
DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS);
}
+bool
+spl_valid_name(const char *name_utf8)
+{
+ /*
+ * Not supporting '/' was done out of laziness, and we should
+ * really strive to support it in the future.
+ *
+ * Not supporting '\r' and '\n' is done out of protocol
+ * limitations (and arguably laziness), but bending over head
+ * over heels to modify the protocol (and compatibility with
+ * all clients) to support idiots who put '\r' and '\n' in
+ * filenames isn't going to happen, either.
+ */
+
+ return strchr(name_utf8, '/') == NULL &&
+ strchr(name_utf8, '\n') == NULL &&
+ strchr(name_utf8, '\r') == NULL;
+}
+
static struct stored_playlist_info *
load_playlist_info(const char *parent_path_fs, const char *name_fs)
{
@@ -158,7 +177,7 @@ spl_load(const char *utf8path)
char buffer[MPD_PATH_MAX];
char *path_fs;
- if (!is_valid_playlist_name(utf8path))
+ if (!spl_valid_name(utf8path))
return NULL;
path_fs = map_spl_utf8_to_fs(utf8path);
@@ -279,7 +298,7 @@ spl_clear(const char *utf8path)
char *path_fs;
FILE *file;
- if (!is_valid_playlist_name(utf8path))
+ if (!spl_valid_name(utf8path))
return PLAYLIST_RESULT_BAD_NAME;
path_fs = map_spl_utf8_to_fs(utf8path);
@@ -350,7 +369,7 @@ spl_append_song(const char *utf8path, struct song *song)
struct stat st;
char *path_fs;
- if (!is_valid_playlist_name(utf8path))
+ if (!spl_valid_name(utf8path))
return PLAYLIST_RESULT_BAD_NAME;
path_fs = map_spl_utf8_to_fs(utf8path);
@@ -429,8 +448,7 @@ spl_rename(const char *utf8from, const char *utf8to)
char *from_path_fs, *to_path_fs;
static enum playlist_result ret;
- if (!is_valid_playlist_name(utf8from) ||
- !is_valid_playlist_name(utf8to))
+ if (!spl_valid_name(utf8from) || !spl_valid_name(utf8to))
return PLAYLIST_RESULT_BAD_NAME;
from_path_fs = map_spl_utf8_to_fs(utf8from);
diff --git a/src/stored_playlist.h b/src/stored_playlist.h
index 40372d376..45cc75644 100644
--- a/src/stored_playlist.h
+++ b/src/stored_playlist.h
@@ -22,6 +22,7 @@
#include "playlist.h"
#include <glib.h>
+#include <stdbool.h>
#include <time.h>
struct song;
@@ -41,6 +42,13 @@ void
spl_global_init(void);
/**
+ * Determines whether the specified string is a valid name for a
+ * stored playlist.
+ */
+bool
+spl_valid_name(const char *name_utf8);
+
+/**
* Returns a list of stored_playlist_info struct pointers. Returns
* NULL if an error occured.
*/