]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_tag.cc
import ceph 15.2.10
[ceph.git] / ceph / src / rgw / rgw_tag.cc
CommitLineData
11fdf7f2 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
224ce89b
WB
3
4#include <map>
5#include <string>
6
7#include <common/errno.h>
8#include <boost/algorithm/string.hpp>
9
10#include "rgw_tag.h"
9f95a23c 11#include "rgw_common.h"
224ce89b
WB
12
13bool RGWObjTags::add_tag(const string&key, const string& val){
14 return tag_map.emplace(std::make_pair(key,val)).second;
15}
16
11fdf7f2
TL
17bool RGWObjTags::emplace_tag(std::string&& key, std::string&& val){
18 return tag_map.emplace(std::move(key), std::move(val)).second;
19}
20
224ce89b 21int RGWObjTags::check_and_add_tag(const string&key, const string& val){
9f95a23c
TL
22 if (tag_map.size() == max_obj_tags ||
23 key.size() > max_tag_key_size ||
24 val.size() > max_tag_val_size ||
224ce89b
WB
25 key.size() == 0){
26 return -ERR_INVALID_TAG;
27 }
28
29 // if we get a conflicting key, either the XML is malformed or the user
30 // supplied an invalid string
31 if (!add_tag(key,val))
32 return -EINVAL;
33
34 return 0;
35}
36
37int RGWObjTags::set_from_string(const string& input){
38 int ret=0;
39 vector <string> kvs;
40 boost::split(kvs, input, boost::is_any_of("&"));
41 for (const auto& kv: kvs){
42 auto p = kv.find("=");
43 string key,val;
44 if (p != string::npos) {
45 ret = check_and_add_tag(url_decode(kv.substr(0,p)),
46 url_decode(kv.substr(p+1)));
47 } else {
48 ret = check_and_add_tag(url_decode(kv));
49 }
50
51 if (ret < 0)
52 return ret;
53 }
54 return ret;
55}