aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-29 21:13:11 +0100
committerMax Kellermann <max@duempel.org>2013-10-29 21:13:40 +0100
commit44581dbef53ba2ae589cbc8e481285697363941f (patch)
tree64dbe587a3253a310eed0dfb643f7e14afbf1e80
parent205448c1e839360a2b18abc685e8b185b89eb72f (diff)
downloadmpd-44581dbef53ba2ae589cbc8e481285697363941f.tar.gz
mpd-44581dbef53ba2ae589cbc8e481285697363941f.tar.xz
mpd-44581dbef53ba2ae589cbc8e481285697363941f.zip
util/UriUtil: add uri_is_child_or_same()
-rw-r--r--src/util/UriUtil.cxx18
-rw-r--r--src/util/UriUtil.hxx13
2 files changed, 31 insertions, 0 deletions
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx
index d542fc0a9..7997bd5c9 100644
--- a/src/util/UriUtil.cxx
+++ b/src/util/UriUtil.cxx
@@ -106,3 +106,21 @@ uri_remove_auth(const char *uri)
result.erase(auth - uri, at + 1 - auth);
return result;
}
+
+bool
+uri_is_child(const char *parent, const char *child)
+{
+ assert(parent != nullptr);
+ assert(child != nullptr);
+
+ const size_t parent_length = strlen(parent);
+ return memcmp(parent, child, parent_length) == 0 &&
+ child[parent_length] == '/';
+}
+
+
+bool
+uri_is_child_or_same(const char *parent, const char *child)
+{
+ return strcmp(parent, child) == 0 || uri_is_child(parent, child);
+}
diff --git a/src/util/UriUtil.hxx b/src/util/UriUtil.hxx
index d93296b10..78d0a6bff 100644
--- a/src/util/UriUtil.hxx
+++ b/src/util/UriUtil.hxx
@@ -57,4 +57,17 @@ gcc_pure
std::string
uri_remove_auth(const char *uri);
+/**
+ * Check whether #child specifies a resource "inside" the directory
+ * specified by #parent. If the strings are equal, the function
+ * returns false.
+ */
+gcc_pure gcc_nonnull_all
+bool
+uri_is_child(const char *parent, const char *child);
+
+gcc_pure gcc_nonnull_all
+bool
+uri_is_child_or_same(const char *parent, const char *child);
+
#endif