diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/rgw/rgw_tag.cc | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/rgw/rgw_tag.cc')
-rw-r--r-- | src/rgw/rgw_tag.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/rgw/rgw_tag.cc b/src/rgw/rgw_tag.cc new file mode 100644 index 000000000..e60a265e7 --- /dev/null +++ b/src/rgw/rgw_tag.cc @@ -0,0 +1,52 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab ft=cpp + +#include <map> +#include <string> + +#include <common/errno.h> +#include <boost/algorithm/string.hpp> + +#include "rgw_tag.h" +#include "rgw_common.h" + +void RGWObjTags::add_tag(const string& key, const string& val){ + tag_map.emplace(std::make_pair(key,val)); +} + +void RGWObjTags::emplace_tag(std::string&& key, std::string&& val){ + tag_map.emplace(std::move(key), std::move(val)); +} + +int RGWObjTags::check_and_add_tag(const string&key, const string& val){ + if (tag_map.size() == max_obj_tags || + key.size() > max_tag_key_size || + val.size() > max_tag_val_size || + key.size() == 0){ + return -ERR_INVALID_TAG; + } + + add_tag(key,val); + + return 0; +} + +int RGWObjTags::set_from_string(const string& input){ + int ret=0; + vector <string> kvs; + boost::split(kvs, input, boost::is_any_of("&")); + for (const auto& kv: kvs){ + auto p = kv.find("="); + string key,val; + if (p != string::npos) { + ret = check_and_add_tag(url_decode(kv.substr(0,p)), + url_decode(kv.substr(p+1))); + } else { + ret = check_and_add_tag(url_decode(kv)); + } + + if (ret < 0) + return ret; + } + return ret; +} |