Suggested by Casey in review, this makes the XML prettier.
also: fix filter parsing, remove unused code
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
using namespace librados;
-static inline std::string_view sv_trim(std::string_view str) {
- while (isspace(str.front())) {
- str.remove_prefix(1);
- }
- while (isspace(str.back())) {
- str.remove_suffix(1);
- }
- return str;
-}
-
-uint32_t LCFilter::recognize_flags(const std::string& flag_expr)
-{
- uint32_t flags = 0;
- ceph::split sp_flags(flag_expr); // default separators are ,;=\t\n
- for (auto it = sp_flags.begin(); it != sp_flags.end(); ++it) {
- auto token = sv_trim(string_view{*it});
- for (auto& flag_tok : LCFilter::filter_flags) {
- if (token == flag_tok.name) {
- flags |= LCFilter::make_flag(flag_tok.bit);
- }
- }
- }
- return flags;
-}
-
bool LCRule::valid() const
{
if (id.length() > MAX_ID_LEN) {
uint32_t flags;
public:
-static uint32_t recognize_flags(const std::string& flag_expr);
LCFilter() : flags(make_flag(LCFlagType::none))
{}
RGWXMLDecoder::decode_xml("Prefix", prefix, o);
- /* parse optional flags (extension) */
- auto flags_iter = o->find("Flag");
- while (auto flag_xml = flags_iter.get_next()){
- flags |= LCFilter::recognize_flags(flag_xml->get_data());
+ /* parse optional ArchiveZone flag (extension) */
+ if (o->find_first("ArchiveZone")) {
+ flags |= make_flag(LCFlagType::ArchiveZone);
}
obj_tags.clear(); // why is this needed?
static const char* xmldoc_2 =
R"(<Filter>
<And>
- <Flag>
- ArchiveZone
- </Flag>
- <Flag>
- ArchiveZone
- </Flag>
+ <ArchiveZone />
<Tag>
<Key>spongebob</Key>
<Value>squarepants</Value>
LCFilter_S3 filter;
auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
ASSERT_TRUE(result);
- /* check repeated Tag element */
+ /* check tags */
auto tag_map = filter.get_tags().get_tags();
auto val1 = tag_map.find("spongebob");
ASSERT_EQ(val1->second, "squarepants");
/* check our flags */
- ASSERT_EQ(filter.get_flags(), uint32_t(LCFlagType::ArchiveZone));
+ ASSERT_EQ(filter.get_flags(), LCFilter::make_flag(LCFlagType::ArchiveZone));
}
// invalid And element placement