blob: f7e52592f7711dc9dd05aaea042f87671000b6e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// -*- 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"
using namespace std;
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){
if (input.empty()) {
return 0;
}
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;
}
void RGWObjTags::dump(Formatter *f) const
{
f->open_object_section("tagset");
for (auto& tag: tag_map){
f->dump_string(tag.first.c_str(), tag.second);
}
f->close_section();
}
|