util/UriUtil: add uri_is_child_or_same()
This commit is contained in:
parent
205448c1e8
commit
44581dbef5
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user