]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_tag.cc
update sources to v12.1.1
[ceph.git] / ceph / src / rgw / rgw_tag.cc
1
2 #include <map>
3 #include <string>
4
5 #include <common/errno.h>
6 #include <boost/algorithm/string.hpp>
7
8 #include "rgw_tag.h"
9
10 static constexpr uint32_t MAX_OBJ_TAGS=10;
11 static constexpr uint32_t MAX_TAG_KEY_SIZE=128;
12 static constexpr uint32_t MAX_TAG_VAL_SIZE=256;
13
14 bool RGWObjTags::add_tag(const string&key, const string& val){
15 return tag_map.emplace(std::make_pair(key,val)).second;
16 }
17
18 int RGWObjTags::check_and_add_tag(const string&key, const string& val){
19 if (tag_map.size() == MAX_OBJ_TAGS ||
20 key.size() > MAX_TAG_KEY_SIZE ||
21 val.size() > MAX_TAG_VAL_SIZE ||
22 key.size() == 0){
23 return -ERR_INVALID_TAG;
24 }
25
26 // if we get a conflicting key, either the XML is malformed or the user
27 // supplied an invalid string
28 if (!add_tag(key,val))
29 return -EINVAL;
30
31 return 0;
32 }
33
34 int RGWObjTags::set_from_string(const string& input){
35 int ret=0;
36 vector <string> kvs;
37 boost::split(kvs, input, boost::is_any_of("&"));
38 for (const auto& kv: kvs){
39 auto p = kv.find("=");
40 string key,val;
41 if (p != string::npos) {
42 ret = check_and_add_tag(url_decode(kv.substr(0,p)),
43 url_decode(kv.substr(p+1)));
44 } else {
45 ret = check_and_add_tag(url_decode(kv));
46 }
47
48 if (ret < 0)
49 return ret;
50 }
51 return ret;
52 }