diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 8 | ||||
-rw-r--r-- | src/decoder_thread.c | 4 | ||||
-rw-r--r-- | src/ls.c | 11 | ||||
-rw-r--r-- | src/ls.h | 18 | ||||
-rw-r--r-- | src/song.c | 4 | ||||
-rw-r--r-- | src/update.c | 2 |
6 files changed, 29 insertions, 18 deletions
diff --git a/src/command.c b/src/command.c index 1d0f14dab..19aeaba32 100644 --- a/src/command.c +++ b/src/command.c @@ -285,7 +285,7 @@ handle_urlhandlers(struct client *client, { if (client_get_uid(client) > 0) client_puts(client, "handler: file://\n"); - printRemoteUrlHandlers(client); + print_supported_uri_schemes(client); return COMMAND_RETURN_OK; } @@ -462,7 +462,7 @@ handle_add(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) } if (uri_has_scheme(uri)) { - if (!isRemoteUrl(uri)) { + if (!uri_supported_scheme(uri)) { command_error(client, ACK_ERROR_NO_EXIST, "unsupported URI scheme"); return COMMAND_RETURN_ERROR; @@ -497,7 +497,7 @@ handle_addid(struct client *client, int argc, char *argv[]) &added_id); #endif } else { - if (uri_has_scheme(uri) && !isRemoteUrl(uri)) { + if (uri_has_scheme(uri) && !uri_supported_scheme(uri)) { command_error(client, ACK_ERROR_NO_EXIST, "unsupported URI scheme"); return COMMAND_RETURN_ERROR; @@ -1258,7 +1258,7 @@ handle_playlistadd(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) enum playlist_result result; if (uri_has_scheme(uri)) { - if (!isRemoteUrl(uri)) { + if (!uri_supported_scheme(uri)) { command_error(client, ACK_ERROR_NO_EXIST, "unsupported URI scheme"); return COMMAND_RETURN_ERROR; diff --git a/src/decoder_thread.c b/src/decoder_thread.c index e6e521764..061048d94 100644 --- a/src/decoder_thread.c +++ b/src/decoder_thread.c @@ -142,7 +142,7 @@ static void decoder_run_song(const struct song *song, const char *uri) /* if that fails, try suffix matching the URL: */ if (plugin == NULL) { - const char *s = getSuffix(uri); + const char *s = uri_get_suffix(uri); next = 0; while ((plugin = decoder_plugin_from_suffix(s, next++))) { if (plugin->stream_decode == NULL) @@ -169,7 +169,7 @@ static void decoder_run_song(const struct song *song, const char *uri) } } else { unsigned int next = 0; - const char *s = getSuffix(uri); + const char *s = uri_get_suffix(uri); while ((plugin = decoder_plugin_from_suffix(s, next++))) { if (plugin->file_decode != NULL) { input_stream_close(&input_stream); @@ -20,6 +20,7 @@ #include "client.h" #include "config.h" +#include <assert.h> #include <string.h> static const char *remoteUrlPrefixes[] = { @@ -29,7 +30,7 @@ static const char *remoteUrlPrefixes[] = { NULL }; -void printRemoteUrlHandlers(struct client *client) +void print_supported_uri_schemes(struct client *client) { const char **prefixes = remoteUrlPrefixes; @@ -44,12 +45,14 @@ bool uri_has_scheme(const char *uri) return strstr(uri, "://") != NULL; } -bool isRemoteUrl(const char *url) +bool uri_supported_scheme(const char *uri) { const char **urlPrefixes = remoteUrlPrefixes; + assert(uri_has_scheme(uri)); + while (*urlPrefixes) { - if (g_str_has_prefix(url, *urlPrefixes)) + if (g_str_has_prefix(uri, *urlPrefixes)) return true; urlPrefixes++; } @@ -58,7 +61,7 @@ bool isRemoteUrl(const char *url) } /* suffixes should be ascii only characters */ -const char *getSuffix(const char *utf8file) +const char *uri_get_suffix(const char *utf8file) { const char *dot = strrchr(g_basename(utf8file), '.'); @@ -21,19 +21,27 @@ #include <stdbool.h> -struct stat; struct client; -const char *getSuffix(const char *utf8file); - /** * Checks whether the specified URI has a schema in the form * "scheme://". */ bool uri_has_scheme(const char *uri); -bool isRemoteUrl(const char *url); +/** + * Checks whether the scheme of the specified URI is supported by MPD. + * It is not allowed to pass an URI without a scheme, check with + * uri_has_scheme() first. + */ +bool uri_supported_scheme(const char *url); + +/** + * Send a list of supported URI schemes to the client. This is the + * response to the "urlhandlers" command. + */ +void print_supported_uri_schemes(struct client *client); -void printRemoteUrlHandlers(struct client *client); +const char *uri_get_suffix(const char *utf8file); #endif diff --git a/src/song.c b/src/song.c index e89b2ac80..f56853895 100644 --- a/src/song.c +++ b/src/song.c @@ -110,7 +110,7 @@ song_file_update(struct song *song) /* check if there's a suffix and a plugin */ - suffix = getSuffix(song->url); + suffix = uri_get_suffix(song->url); if (suffix == NULL) return false; @@ -156,7 +156,7 @@ song_file_update_inarchive(struct song *song) /* check if there's a suffix and a plugin */ - suffix = getSuffix(song->url); + suffix = uri_get_suffix(song->url); if (suffix == NULL) return false; diff --git a/src/update.c b/src/update.c index 72fee3946..daf658e68 100644 --- a/src/update.c +++ b/src/update.c @@ -346,7 +346,7 @@ static void update_regular_file(struct directory *directory, const char *name, const struct stat *st) { - const char *suffix = getSuffix(name); + const char *suffix = uri_get_suffix(name); if (suffix == NULL) return; |