+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
#include <map>
#include <string>
#include <iostream>
#include "rgw_tag_s3.h"
-bool RGWObjTagEntry_S3::xml_end(const char*){
- RGWObjTagKey_S3 *key_obj = static_cast<RGWObjTagKey_S3 *>(find_first("Key"));
- RGWObjTagValue_S3 *val_obj = static_cast<RGWObjTagValue_S3 *>(find_first("Value"));
+void RGWObjTagEntry_S3::decode_xml(XMLObj *obj) {
+ RGWXMLDecoder::decode_xml("Key", key, obj, true);
+ RGWXMLDecoder::decode_xml("Value", val, obj, true);
+}
- if (!key_obj)
- return false;
+void RGWObjTagEntry_S3::dump_xml(Formatter *f) const {
+ encode_xml("Key", key, f);
+ encode_xml("Value", val, f);
- string s = key_obj->get_data();
- if (s.empty()){
- return false;
+ if (key.empty()) {
+ throw RGWXMLDecoder::err("empty key");
}
- key = s;
- if (val_obj) {
- val = val_obj->get_data();
+ if (val.empty()) {
+ throw RGWXMLDecoder::err("empty val");
}
-
- return true;
}
-bool RGWObjTagSet_S3::xml_end(const char*){
- XMLObjIter iter = find("Tag");
- RGWObjTagEntry_S3 *tagentry = static_cast<RGWObjTagEntry_S3 *>(iter.get_next());
- while (tagentry) {
- const std::string& key = tagentry->get_key();
- const std::string& val = tagentry->get_val();
- if (!add_tag(key,val))
- return false;
+void RGWObjTagSet_S3::decode_xml(XMLObj *obj) {
+ vector<RGWObjTagEntry_S3> entries;
+
+ RGWXMLDecoder::decode_xml("Tag", entries, obj, true);
- tagentry = static_cast<RGWObjTagEntry_S3 *>(iter.get_next());
+ for (auto& entry : entries) {
+ const std::string& key = entry.get_key();
+ const std::string& val = entry.get_val();
+ if (!add_tag(key,val)) {
+ throw RGWXMLDecoder::err("failed to add tag");
+ }
}
- return true;
}
-int RGWObjTagSet_S3::rebuild(RGWObjTags& dest){
+int RGWObjTagSet_S3::rebuild(RGWObjTags& dest) {
int ret;
- for (const auto &it: tag_map){
+ for (const auto &it : tag_map){
ret = dest.check_and_add_tag(it.first, it.second);
if (ret < 0)
return ret;
return 0;
}
-bool RGWObjTagging_S3::xml_end(const char*){
- RGWObjTagSet_S3 *tagset = static_cast<RGWObjTagSet_S3 *> (find_first("TagSet"));
- return tagset != nullptr;
-
+void RGWObjTagging_S3::decode_xml(XMLObj *obj) {
+ RGWXMLDecoder::decode_xml("TagSet", tagset, obj, true);
}
-void RGWObjTagSet_S3::dump_xml(Formatter *f){
- for (const auto& tag: tag_map){
- f->open_object_section("Tag");
- f->dump_string("Key", tag.first);
- f->dump_string("Value", tag.second);
- f->close_section();
+void RGWObjTagSet_S3::dump_xml(Formatter *f) const {
+ for (const auto& tag : tag_map){
+ Formatter::ObjectSection os(*f, "Tag");
+ encode_xml("Key", tag.first, f);
+ encode_xml("Value", tag.second, f);
}
}
-XMLObj *RGWObjTagsXMLParser::alloc_obj(const char *el){
- XMLObj* obj = nullptr;
- if(strcmp(el,"Tagging") == 0) {
- obj = new RGWObjTagging_S3();
- } else if (strcmp(el,"TagSet") == 0) {
- obj = new RGWObjTagSet_S3();
- } else if (strcmp(el,"Tag") == 0) {
- obj = new RGWObjTagEntry_S3();
- } else if (strcmp(el,"Key") == 0) {
- obj = new RGWObjTagKey_S3();
- } else if (strcmp(el,"Value") == 0) {
- obj = new RGWObjTagValue_S3();
- }
-
- return obj;
-}