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/GetBucketInventoryConfigurationResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23 
GetBucketInventoryConfigurationResult()24 GetBucketInventoryConfigurationResult::GetBucketInventoryConfigurationResult() :
25     OssResult()
26 {
27 }
28 
GetBucketInventoryConfigurationResult(const std::string & result)29 GetBucketInventoryConfigurationResult::GetBucketInventoryConfigurationResult(const std::string& result) :
30     GetBucketInventoryConfigurationResult()
31 {
32     *this = result;
33 }
34 
GetBucketInventoryConfigurationResult(const std::shared_ptr<std::iostream> & result)35 GetBucketInventoryConfigurationResult::GetBucketInventoryConfigurationResult(const std::shared_ptr<std::iostream>& result) :
36     GetBucketInventoryConfigurationResult()
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 GetBucketInventoryConfigurationResult& GetBucketInventoryConfigurationResult::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("InventoryConfiguration", root->Name(), 22)) {
50             XMLElement* node;
51 
52             node = root->FirstChildElement("Id");
53             if (node && node->GetText()) inventoryConfiguration_.setId(node->GetText());
54 
55             node = root->FirstChildElement("IsEnabled");
56             if (node && node->GetText()) inventoryConfiguration_.setIsEnabled((std::strncmp(node->GetText(), "true", 4) ? false : true));
57 
58             node = root->FirstChildElement("Filter");
59             if (node) {
60                 InventoryFilter filter;
61                 XMLElement* prefix_node = node->FirstChildElement("Prefix");
62                 if (prefix_node && prefix_node->GetText()) filter.setPrefix(prefix_node->GetText());
63                 inventoryConfiguration_.setFilter(filter);
64             }
65             node = root->FirstChildElement("Destination");
66             if (node) {
67                 XMLElement* next_node;
68                 next_node = node->FirstChildElement("OSSBucketDestination");
69                 if (next_node) {
70                     XMLElement* sub_node;
71                     InventoryOSSBucketDestination dest;
72                     sub_node = next_node->FirstChildElement("Format");
73                     if (sub_node && sub_node->GetText()) dest.setFormat(ToInventoryFormatType(sub_node->GetText()));
74                     sub_node = next_node->FirstChildElement("AccountId");
75                     if (sub_node && sub_node->GetText()) dest.setAccountId(sub_node->GetText());
76                     sub_node = next_node->FirstChildElement("RoleArn");
77                     if (sub_node && sub_node->GetText()) dest.setRoleArn(sub_node->GetText());
78                     sub_node = next_node->FirstChildElement("Bucket");
79                     if (sub_node && sub_node->GetText()) dest.setBucket(ToInventoryBucketShortName(sub_node->GetText()));
80                     sub_node = next_node->FirstChildElement("Prefix");
81                     if (sub_node && sub_node->GetText()) dest.setPrefix(sub_node->GetText());
82                     sub_node = next_node->FirstChildElement("Encryption");
83                     if (sub_node) {
84                         InventoryEncryption encryption;
85                         XMLElement* sse_node;
86                         sse_node = sub_node->FirstChildElement("SSE-KMS");
87                         if (sse_node) {
88                             InventorySSEKMS ssekms;
89                             XMLElement* key_node;
90                             key_node = sse_node->FirstChildElement("KeyId");
91                             if (key_node && key_node->GetText()) ssekms.setKeyId(key_node->GetText());
92                             encryption.setSSEKMS(ssekms);
93                         }
94 
95                         sse_node = sub_node->FirstChildElement("SSE-OSS");
96                         if (sse_node) {
97                             encryption.setSSEOSS(InventorySSEOSS());
98                         }
99                         dest.setEncryption(encryption);
100                     }
101                     inventoryConfiguration_.setDestination(InventoryDestination(dest));
102                 }
103             }
104 
105             node = root->FirstChildElement("Schedule");
106             if (node) {
107                 XMLElement* freq_node = node->FirstChildElement("Frequency");
108                 if (freq_node && freq_node->GetText()) inventoryConfiguration_.setSchedule(ToInventoryFrequencyType(freq_node->GetText()));
109             }
110 
111             node = root->FirstChildElement("IncludedObjectVersions");
112             if (node && node->GetText()) inventoryConfiguration_.setIncludedObjectVersions(ToInventoryIncludedObjectVersionsType(node->GetText()));
113 
114             node = root->FirstChildElement("OptionalFields");
115             if (node) {
116                 InventoryOptionalFields field;
117                 XMLElement* field_node = node->FirstChildElement("Field");
118                 for (; field_node; field_node = field_node->NextSiblingElement()) {
119                     if (field_node->GetText())
120                         field.push_back(ToInventoryOptionalFieldType(field_node->GetText()));
121                 }
122                 inventoryConfiguration_.setOptionalFields(field);
123             }
124             parseDone_ = true;
125         }
126     }
127     return *this;
128 }
129