]>
Commit | Line | Data |
---|---|---|
224ce89b WB |
1 | #include <map> |
2 | #include <string> | |
3 | #include <iostream> | |
4 | ||
5 | #include "include/types.h" | |
6 | ||
7 | #include "rgw_tag_s3.h" | |
8 | ||
9 | bool RGWObjTagEntry_S3::xml_end(const char*){ | |
10 | RGWObjTagKey_S3 *key_obj = static_cast<RGWObjTagKey_S3 *>(find_first("Key")); | |
11 | RGWObjTagValue_S3 *val_obj = static_cast<RGWObjTagValue_S3 *>(find_first("Value")); | |
12 | ||
13 | if (!key_obj) | |
14 | return false; | |
15 | ||
16 | string s = key_obj->get_data(); | |
17 | if (s.empty()){ | |
18 | return false; | |
19 | } | |
20 | ||
21 | key = s; | |
22 | if (val_obj) { | |
23 | val = val_obj->get_data(); | |
24 | } | |
25 | ||
26 | return true; | |
27 | } | |
28 | ||
29 | bool RGWObjTagSet_S3::xml_end(const char*){ | |
30 | XMLObjIter iter = find("Tag"); | |
31 | RGWObjTagEntry_S3 *tagentry = static_cast<RGWObjTagEntry_S3 *>(iter.get_next()); | |
32 | while (tagentry) { | |
33 | const std::string& key = tagentry->get_key(); | |
34 | const std::string& val = tagentry->get_val(); | |
35 | if (!add_tag(key,val)) | |
36 | return false; | |
37 | ||
38 | tagentry = static_cast<RGWObjTagEntry_S3 *>(iter.get_next()); | |
39 | } | |
40 | return true; | |
41 | } | |
42 | ||
43 | int RGWObjTagSet_S3::rebuild(RGWObjTags& dest){ | |
44 | int ret; | |
45 | for (const auto &it: tag_map){ | |
46 | ret = dest.check_and_add_tag(it.first, it.second); | |
47 | if (ret < 0) | |
48 | return ret; | |
49 | } | |
50 | return 0; | |
51 | } | |
52 | ||
53 | bool RGWObjTagging_S3::xml_end(const char*){ | |
54 | RGWObjTagSet_S3 *tagset = static_cast<RGWObjTagSet_S3 *> (find_first("TagSet")); | |
55 | return tagset != nullptr; | |
56 | ||
57 | } | |
58 | ||
59 | void RGWObjTagSet_S3::dump_xml(Formatter *f){ | |
60 | for (const auto& tag: tag_map){ | |
61 | f->open_object_section("Tag"); | |
62 | f->dump_string("Key", tag.first); | |
63 | f->dump_string("Value", tag.second); | |
64 | f->close_section(); | |
65 | } | |
66 | } | |
67 | ||
68 | XMLObj *RGWObjTagsXMLParser::alloc_obj(const char *el){ | |
69 | XMLObj* obj = nullptr; | |
70 | if(strcmp(el,"Tagging") == 0) { | |
71 | obj = new RGWObjTagging_S3(); | |
72 | } else if (strcmp(el,"TagSet") == 0) { | |
73 | obj = new RGWObjTagSet_S3(); | |
74 | } else if (strcmp(el,"Tag") == 0) { | |
75 | obj = new RGWObjTagEntry_S3(); | |
76 | } else if (strcmp(el,"Key") == 0) { | |
77 | obj = new RGWObjTagKey_S3(); | |
78 | } else if (strcmp(el,"Value") == 0) { | |
79 | obj = new RGWObjTagValue_S3(); | |
80 | } | |
81 | ||
82 | return obj; | |
83 | } |