1 /*
2 * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <alibabacloud/oss/model/ListBucketInventoryConfigurationsResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23
ListBucketInventoryConfigurationsResult()24 ListBucketInventoryConfigurationsResult::ListBucketInventoryConfigurationsResult() :
25 OssResult()
26 {
27 }
28
ListBucketInventoryConfigurationsResult(const std::string & result)29 ListBucketInventoryConfigurationsResult::ListBucketInventoryConfigurationsResult(const std::string& result) :
30 ListBucketInventoryConfigurationsResult()
31 {
32 *this = result;
33 }
34
ListBucketInventoryConfigurationsResult(const std::shared_ptr<std::iostream> & result)35 ListBucketInventoryConfigurationsResult::ListBucketInventoryConfigurationsResult(const std::shared_ptr<std::iostream>& result) :
36 ListBucketInventoryConfigurationsResult()
37 {
38 std::istreambuf_iterator<char> isb(*result.get()), end;
39 std::string str(isb, end);
40 *this = str;
41 }
42
operator =(const std::string & result)43 ListBucketInventoryConfigurationsResult& ListBucketInventoryConfigurationsResult::operator =(const std::string& result)
44 {
45 XMLDocument doc;
46 XMLError xml_err;
47 if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
48 XMLElement* root = doc.RootElement();
49 if (root && !std::strncmp("ListInventoryConfigurationsResult", root->Name(), 33)) {
50 XMLElement* node;
51
52 node = root->FirstChildElement("InventoryConfiguration");
53
54 for (; node; node = node->NextSiblingElement("InventoryConfiguration")) {
55 XMLElement* conf_node;
56
57 InventoryConfiguration inventoryConfiguration;
58
59 conf_node = node->FirstChildElement("Id");
60 if (conf_node && conf_node->GetText()) inventoryConfiguration.setId(conf_node->GetText());
61
62 conf_node = node->FirstChildElement("IsEnabled");
63 if (conf_node && conf_node->GetText()) inventoryConfiguration.setIsEnabled((std::strncmp(conf_node->GetText(), "true", 4) ? false : true));
64
65 conf_node = node->FirstChildElement("Filter");
66 if (conf_node) {
67 InventoryFilter filter;
68 XMLElement* prefix_node = conf_node->FirstChildElement("Prefix");
69 if (prefix_node && prefix_node->GetText()) filter.setPrefix(prefix_node->GetText());
70 inventoryConfiguration.setFilter(filter);
71 }
72 conf_node = node->FirstChildElement("Destination");
73 if (conf_node) {
74 XMLElement* next_node;
75 next_node = conf_node->FirstChildElement("OSSBucketDestination");
76 if (next_node) {
77 XMLElement* sub_node;
78 InventoryOSSBucketDestination dest;
79 sub_node = next_node->FirstChildElement("Format");
80 if (sub_node && sub_node->GetText()) dest.setFormat(ToInventoryFormatType(sub_node->GetText()));
81 sub_node = next_node->FirstChildElement("AccountId");
82 if (sub_node && sub_node->GetText()) dest.setAccountId(sub_node->GetText());
83 sub_node = next_node->FirstChildElement("RoleArn");
84 if (sub_node && sub_node->GetText()) dest.setRoleArn(sub_node->GetText());
85 sub_node = next_node->FirstChildElement("Bucket");
86 if (sub_node && sub_node->GetText()) dest.setBucket(ToInventoryBucketShortName(sub_node->GetText()));
87 sub_node = next_node->FirstChildElement("Prefix");
88 if (sub_node && sub_node->GetText()) dest.setPrefix(sub_node->GetText());
89 sub_node = next_node->FirstChildElement("Encryption");
90 if (sub_node) {
91 InventoryEncryption encryption;
92 XMLElement* sse_node;
93 sse_node = sub_node->FirstChildElement("SSE-KMS");
94 if (sse_node) {
95 InventorySSEKMS ssekms;
96 XMLElement* key_node;
97 key_node = sse_node->FirstChildElement("KeyId");
98 if (key_node && key_node->GetText()) ssekms.setKeyId(key_node->GetText());
99 encryption.setSSEKMS(ssekms);
100 }
101
102 sse_node = sub_node->FirstChildElement("SSE-OSS");
103 if (sse_node) {
104 encryption.setSSEOSS(InventorySSEOSS());
105 }
106 dest.setEncryption(encryption);
107 }
108 inventoryConfiguration.setDestination(InventoryDestination(dest));
109 }
110 }
111
112 conf_node = node->FirstChildElement("Schedule");
113 if (conf_node) {
114 XMLElement* freq_node = conf_node->FirstChildElement("Frequency");
115 if (freq_node && freq_node->GetText()) inventoryConfiguration.setSchedule(ToInventoryFrequencyType(freq_node->GetText()));
116 }
117
118 conf_node = node->FirstChildElement("IncludedObjectVersions");
119 if (conf_node && conf_node->GetText()) inventoryConfiguration.setIncludedObjectVersions(ToInventoryIncludedObjectVersionsType(conf_node->GetText()));
120
121 conf_node = node->FirstChildElement("OptionalFields");
122 if (conf_node) {
123 InventoryOptionalFields field;
124 XMLElement* field_node = conf_node->FirstChildElement("Field");
125 for (; field_node; field_node = field_node->NextSiblingElement()) {
126 if (field_node->GetText())
127 field.push_back(ToInventoryOptionalFieldType(field_node->GetText()));
128 }
129 inventoryConfiguration.setOptionalFields(field);
130 }
131
132 inventoryConfigurationList_.push_back(inventoryConfiguration);
133 }
134
135 node = root->FirstChildElement("IsTruncated");
136 if (node && node->GetText()) isTruncated_ = (std::strncmp(node->GetText(), "true", 4) ? false : true);
137
138 node = root->FirstChildElement("NextContinuationToken");
139 if (node && node->GetText()) nextContinuationToken_ = node->GetText();
140
141 parseDone_ = true;
142 }
143 }
144 return *this;
145 }
146