Commit 90697297 authored by Max Kellermann's avatar Max Kellermann

case-insensitive URI scheme comparison

Required according to RFC 3986: > An implementation should accept uppercase letters as equivalent to > lowercase in scheme names Closes #330
parent 116edf5f
...@@ -5,6 +5,7 @@ ver 0.20.21 (not yet released) ...@@ -5,6 +5,7 @@ ver 0.20.21 (not yet released)
- simple: allow .mpdignore comments only at start of line - simple: allow .mpdignore comments only at start of line
* output * output
- httpd: remove broken DLNA support code - httpd: remove broken DLNA support code
* URI schemes are case insensitive
ver 0.20.20 (2018/05/22) ver 0.20.20 (2018/05/22)
* protocol * protocol
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "ls.hxx" #include "ls.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
#include "storage/StorageInterface.hxx" #include "storage/StorageInterface.hxx"
...@@ -83,7 +83,7 @@ LocateUri(const char *uri, const Client *client ...@@ -83,7 +83,7 @@ LocateUri(const char *uri, const Client *client
) )
{ {
/* skip the obsolete "file://" prefix */ /* skip the obsolete "file://" prefix */
const char *path_utf8 = StringAfterPrefix(uri, "file://"); const char *path_utf8 = StringAfterPrefixCaseASCII(uri, "file://");
if (path_utf8 != nullptr) { if (path_utf8 != nullptr) {
if (!PathTraitsUTF8::IsAbsolute(path_utf8)) if (!PathTraitsUTF8::IsAbsolute(path_utf8))
throw std::runtime_error("Malformed file:// URI"); throw std::runtime_error("Malformed file:// URI");
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#include <stdexcept> #include <stdexcept>
...@@ -77,8 +77,8 @@ gcc_pure ...@@ -77,8 +77,8 @@ gcc_pure
static bool static bool
ExpensiveSeeking(const char *uri) noexcept ExpensiveSeeking(const char *uri) noexcept
{ {
return StringStartsWith(uri, "http://") || return StringStartsWithCaseASCII(uri, "http://") ||
StringStartsWith(uri, "https://"); StringStartsWithCaseASCII(uri, "https://");
} }
bool bool
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/ReusableArray.hxx" #include "util/ReusableArray.hxx"
#include "util/ASCII.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "event/MultiSocketMonitor.hxx" #include "event/MultiSocketMonitor.hxx"
#include "event/DeferredMonitor.hxx" #include "event/DeferredMonitor.hxx"
...@@ -147,7 +147,7 @@ private: ...@@ -147,7 +147,7 @@ private:
inline InputStream * inline InputStream *
AlsaInputStream::Create(const char *uri, Mutex &mutex, Cond &cond) AlsaInputStream::Create(const char *uri, Mutex &mutex, Cond &cond)
{ {
const char *device = StringAfterPrefix(uri, "alsa://"); const char *device = StringAfterPrefixCaseASCII(uri, "alsa://");
if (device == nullptr) if (device == nullptr)
return nullptr; return nullptr;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "../InputStream.hxx" #include "../InputStream.hxx"
#include "../InputPlugin.hxx" #include "../InputPlugin.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "system/ByteOrder.hxx" #include "system/ByteOrder.hxx"
...@@ -128,7 +128,7 @@ struct cdio_uri { ...@@ -128,7 +128,7 @@ struct cdio_uri {
static bool static bool
parse_cdio_uri(struct cdio_uri *dest, const char *src) parse_cdio_uri(struct cdio_uri *dest, const char *src)
{ {
if (!StringStartsWith(src, "cdda://")) if (!StringStartsWithCaseASCII(src, "cdda://"))
return false; return false;
src += 7; src += 7;
......
...@@ -458,8 +458,8 @@ CurlInputStream::Open(const char *url, Mutex &mutex, Cond &cond) ...@@ -458,8 +458,8 @@ CurlInputStream::Open(const char *url, Mutex &mutex, Cond &cond)
static InputStream * static InputStream *
input_curl_open(const char *url, Mutex &mutex, Cond &cond) input_curl_open(const char *url, Mutex &mutex, Cond &cond)
{ {
if (strncmp(url, "http://", 7) != 0 && if (!StringStartsWithCaseASCII(url, "http://") &&
strncmp(url, "https://", 8) != 0) !StringStartsWithCaseASCII(url, "https://"))
return nullptr; return nullptr;
return CurlInputStream::Open(url, mutex, cond); return CurlInputStream::Open(url, mutex, cond);
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "../InputStream.hxx" #include "../InputStream.hxx"
#include "../InputPlugin.hxx" #include "../InputPlugin.hxx"
#include "PluginUnavailable.hxx" #include "PluginUnavailable.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
extern "C" { extern "C" {
#include <libavformat/avio.h> #include <libavformat/avio.h>
...@@ -85,12 +85,12 @@ static InputStream * ...@@ -85,12 +85,12 @@ static InputStream *
input_ffmpeg_open(const char *uri, input_ffmpeg_open(const char *uri,
Mutex &mutex, Cond &cond) Mutex &mutex, Cond &cond)
{ {
if (!StringStartsWith(uri, "gopher://") && if (!StringStartsWithCaseASCII(uri, "gopher://") &&
!StringStartsWith(uri, "rtp://") && !StringStartsWithCaseASCII(uri, "rtp://") &&
!StringStartsWith(uri, "rtsp://") && !StringStartsWithCaseASCII(uri, "rtsp://") &&
!StringStartsWith(uri, "rtmp://") && !StringStartsWithCaseASCII(uri, "rtmp://") &&
!StringStartsWith(uri, "rtmpt://") && !StringStartsWithCaseASCII(uri, "rtmpt://") &&
!StringStartsWith(uri, "rtmps://")) !StringStartsWithCaseASCII(uri, "rtmps://"))
return nullptr; return nullptr;
AVIOContext *h; AVIOContext *h;
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "input/ThreadInputStream.hxx" #include "input/ThreadInputStream.hxx"
#include "input/InputPlugin.hxx" #include "input/InputPlugin.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#include <libmms/mmsx.h> #include <libmms/mmsx.h>
...@@ -74,10 +74,10 @@ static InputStream * ...@@ -74,10 +74,10 @@ static InputStream *
input_mms_open(const char *url, input_mms_open(const char *url,
Mutex &mutex, Cond &cond) Mutex &mutex, Cond &cond)
{ {
if (!StringStartsWith(url, "mms://") && if (!StringStartsWithCaseASCII(url, "mms://") &&
!StringStartsWith(url, "mmsh://") && !StringStartsWithCaseASCII(url, "mmsh://") &&
!StringStartsWith(url, "mmst://") && !StringStartsWithCaseASCII(url, "mmst://") &&
!StringStartsWith(url, "mmsu://")) !StringStartsWithCaseASCII(url, "mmsu://"))
return nullptr; return nullptr;
auto m = new MmsInputStream(url, mutex, cond); auto m = new MmsInputStream(url, mutex, cond);
......
...@@ -23,9 +23,7 @@ ...@@ -23,9 +23,7 @@
#include "../InputPlugin.hxx" #include "../InputPlugin.hxx"
#include "lib/nfs/Glue.hxx" #include "lib/nfs/Glue.hxx"
#include "lib/nfs/FileReader.hxx" #include "lib/nfs/FileReader.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#include <string.h>
/** /**
* Do not buffer more than this number of bytes. It should be a * Do not buffer more than this number of bytes. It should be a
...@@ -219,7 +217,7 @@ static InputStream * ...@@ -219,7 +217,7 @@ static InputStream *
input_nfs_open(const char *uri, input_nfs_open(const char *uri,
Mutex &mutex, Cond &cond) Mutex &mutex, Cond &cond)
{ {
if (!StringStartsWith(uri, "nfs://")) if (!StringStartsWithCaseASCII(uri, "nfs://"))
return nullptr; return nullptr;
NfsInputStream *is = new NfsInputStream(uri, mutex, cond); NfsInputStream *is = new NfsInputStream(uri, mutex, cond);
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "../InputPlugin.hxx" #include "../InputPlugin.hxx"
#include "PluginUnavailable.hxx" #include "PluginUnavailable.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#include <libsmbclient.h> #include <libsmbclient.h>
...@@ -87,7 +87,7 @@ static InputStream * ...@@ -87,7 +87,7 @@ static InputStream *
input_smbclient_open(const char *uri, input_smbclient_open(const char *uri,
Mutex &mutex, Cond &cond) Mutex &mutex, Cond &cond)
{ {
if (!StringStartsWith(uri, "smb://")) if (!StringStartsWithCaseASCII(uri, "smb://"))
return nullptr; return nullptr;
const std::lock_guard<Mutex> protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "Connection.hxx" #include "Connection.hxx"
#include "event/Call.hxx" #include "event/Call.hxx"
#include "IOThread.hxx" #include "IOThread.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#include <utility> #include <utility>
...@@ -93,7 +93,7 @@ NfsFileReader::Open(const char *uri) ...@@ -93,7 +93,7 @@ NfsFileReader::Open(const char *uri)
{ {
assert(state == State::INITIAL); assert(state == State::INITIAL);
if (!StringStartsWith(uri, "nfs://")) if (!StringStartsWithCaseASCII(uri, "nfs://"))
throw std::runtime_error("Malformed nfs:// URI"); throw std::runtime_error("Malformed nfs:// URI");
uri += 6; uri += 6;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "ls.hxx" #include "ls.hxx"
#include "client/Response.hxx" #include "client/Response.hxx"
#include "util/StringCompare.hxx" #include "util/ASCII.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include <assert.h> #include <assert.h>
...@@ -97,7 +97,7 @@ uri_supported_scheme(const char *uri) noexcept ...@@ -97,7 +97,7 @@ uri_supported_scheme(const char *uri) noexcept
assert(uri_has_scheme(uri)); assert(uri_has_scheme(uri));
while (*urlPrefixes) { while (*urlPrefixes) {
if (StringStartsWith(uri, *urlPrefixes)) if (StringStartsWithCaseASCII(uri, *urlPrefixes))
return true; return true;
urlPrefixes++; urlPrefixes++;
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "config/Block.hxx" #include "config/Block.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "tag/TagBuilder.hxx" #include "tag/TagBuilder.hxx"
#include "util/ASCII.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
...@@ -68,7 +69,7 @@ soundcloud_resolve(const char* uri) ...@@ -68,7 +69,7 @@ soundcloud_resolve(const char* uri)
{ {
char *u, *ru; char *u, *ru;
if (StringStartsWith(uri, "https://")) { if (StringStartsWithCaseASCII(uri, "https://")) {
u = xstrdup(uri); u = xstrdup(uri);
} else if (StringStartsWith(uri, "soundcloud.com")) { } else if (StringStartsWith(uri, "soundcloud.com")) {
u = xstrcatdup("https://", uri); u = xstrcatdup("https://", uri);
...@@ -273,7 +274,7 @@ try { ...@@ -273,7 +274,7 @@ try {
static SongEnumerator * static SongEnumerator *
soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond) soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond)
{ {
assert(strncmp(uri, "soundcloud://", 13) == 0); assert(StringEqualsCaseASCII(uri, "soundcloud://", 13));
uri += 13; uri += 13;
char *u = nullptr; char *u = nullptr;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "event/DeferredMonitor.hxx" #include "event/DeferredMonitor.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "util/ASCII.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/StringFormat.hxx" #include "util/StringFormat.hxx"
...@@ -590,8 +591,8 @@ CurlStorage::OpenDirectory(const char *uri_utf8) ...@@ -590,8 +591,8 @@ CurlStorage::OpenDirectory(const char *uri_utf8)
static Storage * static Storage *
CreateCurlStorageURI(EventLoop &event_loop, const char *uri) CreateCurlStorageURI(EventLoop &event_loop, const char *uri)
{ {
if (strncmp(uri, "http://", 7) != 0 && if (!StringStartsWithCaseASCII(uri, "http://") &&
strncmp(uri, "https://", 8) != 0) !StringStartsWithCaseASCII(uri, "https://"))
return nullptr; return nullptr;
return new CurlStorage(event_loop, uri); return new CurlStorage(event_loop, uri);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "event/Call.hxx" #include "event/Call.hxx"
#include "event/DeferredMonitor.hxx" #include "event/DeferredMonitor.hxx"
#include "event/TimeoutMonitor.hxx" #include "event/TimeoutMonitor.hxx"
#include "util/ASCII.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
extern "C" { extern "C" {
...@@ -401,11 +402,10 @@ NfsStorage::OpenDirectory(const char *uri_utf8) ...@@ -401,11 +402,10 @@ NfsStorage::OpenDirectory(const char *uri_utf8)
static Storage * static Storage *
CreateNfsStorageURI(EventLoop &event_loop, const char *base) CreateNfsStorageURI(EventLoop &event_loop, const char *base)
{ {
if (strncmp(base, "nfs://", 6) != 0) const char *p = StringAfterPrefixCaseASCII(base, "nfs://");
if (p == nullptr)
return nullptr; return nullptr;
const char *p = base + 6;
const char *mount = strchr(p, '/'); const char *mount = strchr(p, '/');
if (mount == nullptr) if (mount == nullptr)
throw std::runtime_error("Malformed nfs:// URI"); throw std::runtime_error("Malformed nfs:// URI");
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include "util/ASCII.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
...@@ -182,7 +183,7 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow) ...@@ -182,7 +183,7 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow)
static Storage * static Storage *
CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base) CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base)
{ {
if (strncmp(base, "smb://", 6) != 0) if (!StringStartsWithCaseASCII(base, "smb://"))
return nullptr; return nullptr;
SmbclientInit(); SmbclientInit();
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "UriUtil.hxx" #include "UriUtil.hxx"
#include "StringCompare.hxx" #include "ASCII.hxx"
#include "CharUtil.hxx" #include "CharUtil.hxx"
#include <assert.h> #include <assert.h>
...@@ -169,7 +169,7 @@ SkipUriScheme(const char *uri) noexcept ...@@ -169,7 +169,7 @@ SkipUriScheme(const char *uri) noexcept
{ {
const char *const schemes[] = { "http://", "https://", "ftp://" }; const char *const schemes[] = { "http://", "https://", "ftp://" };
for (auto scheme : schemes) { for (auto scheme : schemes) {
auto result = StringAfterPrefix(uri, scheme); auto result = StringAfterPrefixCaseASCII(uri, scheme);
if (result != nullptr) if (result != nullptr)
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment