playlist: moved is_valid_playlist_name() to stored_playlist.c

This commit is contained in:
Max Kellermann 2009-01-25 14:19:28 +01:00
parent 98cb8f3969
commit bdfb6c239a
4 changed files with 32 additions and 22 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -22,6 +22,7 @@
#include "playlist.h"
#include <glib.h>
#include <stdbool.h>
#include <time.h>
struct song;
@ -40,6 +41,13 @@ extern bool playlist_saveAbsolutePaths;
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.