diff options
Diffstat (limited to 'src/util/UriUtil.cxx')
-rw-r--r-- | src/util/UriUtil.cxx | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx index 6dd5a42e1..54d0ded77 100644 --- a/src/util/UriUtil.cxx +++ b/src/util/UriUtil.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -27,6 +27,16 @@ bool uri_has_scheme(const char *uri) return strstr(uri, "://") != nullptr; } +std::string +uri_get_scheme(const char *uri) +{ + const char *end = strstr(uri, "://"); + if (end == nullptr) + end = uri; + + return std::string(uri, end); +} + /* suffixes should be ascii only characters */ const char * uri_get_suffix(const char *uri) @@ -105,6 +115,8 @@ uri_remove_auth(const char *uri) auth = uri + 7; else if (memcmp(uri, "https://", 8) == 0) auth = uri + 8; + else if (memcmp(uri, "ftp://", 6) == 0) + auth = uri + 6; else /* unrecognized URI */ return std::string(); @@ -145,3 +157,31 @@ uri_is_child_or_same(const char *parent, const char *child) { return strcmp(parent, child) == 0 || uri_is_child(parent, child); } + +std::string +uri_apply_base(const std::string &uri, const std::string &base) +{ + if (uri.front() == '/') { + /* absolute path: replace the whole URI path in base */ + + auto i = base.find("://"); + if (i == base.npos) + /* no scheme: override base completely */ + return uri; + + /* find the first slash after the host part */ + i = base.find('/', i + 3); + if (i == base.npos) + /* there's no URI path - simply append uri */ + i = base.length(); + + return base.substr(0, i) + uri; + } + + std::string out(base); + if (out.back() != '/') + out.push_back('/'); + + out += uri; + return out; +} |