return rgw_parse_list_of_flags(op_type_mapping, str, perm);
}
-bool match_policy(std::string_view pattern, std::string_view input,
+bool match_policy(const std::string& pattern, const std::string& input,
uint32_t flag)
{
const uint32_t flag2 = flag & (MATCH_POLICY_ACTION|MATCH_POLICY_ARN) ?
static constexpr uint32_t MATCH_POLICY_ARN = 0x04;
static constexpr uint32_t MATCH_POLICY_STRING = 0x08;
-extern bool match_policy(std::string_view pattern, std::string_view input,
+extern bool match_policy(const std::string& pattern, const std::string& input,
uint32_t flag);
extern std::string camelcase_dash_http_attr(const std::string& orig);
t->action = allValue : t->notaction = allValue);
} else {
for (auto& p : actpairs) {
- if (match_policy({s, l}, p.name, MATCH_POLICY_ACTION)) {
+ if (match_policy(string(s, l), p.name, MATCH_POLICY_ACTION)) {
is_validaction = true;
(w->id == TokenID::Action ? t->action[p.bit] = 1 : t->notaction[p.bit] = 1);
}
// vim: ts=8 sw=2 smarttab ft=cpp
#include "rgw_string.h"
+#include <fnmatch.h>
-static bool char_eq(char c1, char c2)
-{
- return c1 == c2;
-}
-
-static bool ci_char_eq(char c1, char c2)
-{
- return tolower(c1) == tolower(c2);
-}
-
-bool match_wildcards(std::string_view pattern, std::string_view input,
+bool match_wildcards(const std::string& pattern, const std::string& input,
uint32_t flags)
{
- const auto eq = (flags & MATCH_CASE_INSENSITIVE) ? &ci_char_eq : &char_eq;
+ bool case_insensive = flags & MATCH_CASE_INSENSITIVE;
+ uint32_t flag = 0;
+
+ if (case_insensive) {
+ flag = FNM_CASEFOLD;
+ }
- auto it1 = pattern.begin();
- auto it2 = input.begin();
- while (true) {
- if (it1 == pattern.end())
- return it2 == input.end();
- if (*it1 == '*') {
- if (it1 + 1 == pattern.end())
- return true;
- if (it2 == input.end() || eq(*(it1 + 1), *it2))
- ++it1;
- else
- ++it2;
- continue;
- }
- if (it2 == input.end())
- return false;
- if (*it1 == '?' || eq(*it1, *it2)) {
- ++it1;
- ++it2;
- continue;
- }
+ if (fnmatch(pattern.data(), input.data(), flag) == 0) {
+ return true;
+ } else {
return false;
}
- return false;
}
/// attempt to match the given input string with the pattern, which may contain
/// the wildcard characters * and ?
-extern bool match_wildcards(std::string_view pattern,
- std::string_view input,
+extern bool match_wildcards(const std::string& pattern,
+ const std::string& input,
uint32_t flags = 0);
"http://example.com/index.html"));
EXPECT_TRUE(match_wildcards("http://example.com/*/*.jpg",
"http://example.com/fun/smiley.jpg"));
- // note: parsing of * is not greedy, so * does not match 'bc' here
- EXPECT_FALSE(match_wildcards("a*c", "abcc"));
- EXPECT_FALSE(match_wildcards("a*c", "abcc", MATCH_CASE_INSENSITIVE));
+ EXPECT_TRUE(match_wildcards("a*c", "abcc"));
+ EXPECT_TRUE(match_wildcards("a*c", "abcc", MATCH_CASE_INSENSITIVE));
}
TEST(MatchPolicy, Action)