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/GetBucketInfoResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23
24
GetBucketInfoResult()25 GetBucketInfoResult::GetBucketInfoResult() :
26 OssResult(),
27 dataRedundancyType_(AlibabaCloud::OSS::DataRedundancyType::NotSet),
28 sseAlgorithm_(AlibabaCloud::OSS::SSEAlgorithm::NotSet),
29 versioningStatus_(AlibabaCloud::OSS::VersioningStatus::NotSet)
30 {
31 }
32
GetBucketInfoResult(const std::string & result)33 GetBucketInfoResult::GetBucketInfoResult(const std::string& result):
34 GetBucketInfoResult()
35 {
36 *this = result;
37 }
38
GetBucketInfoResult(const std::shared_ptr<std::iostream> & result)39 GetBucketInfoResult::GetBucketInfoResult(const std::shared_ptr<std::iostream>& result):
40 GetBucketInfoResult()
41 {
42 std::istreambuf_iterator<char> isb(*result.get()), end;
43 std::string str(isb, end);
44 *this = str;
45 }
46
operator =(const std::string & result)47 GetBucketInfoResult& GetBucketInfoResult::operator =(const std::string& result)
48 {
49 XMLDocument doc;
50 XMLError xml_err;
51 if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
52 XMLElement* root =doc.RootElement();
53 if (root && !std::strncmp("BucketInfo", root->Name(), 10)) {
54 XMLElement *node;
55 XMLElement *bucket_node;
56 bucket_node = root->FirstChildElement("Bucket");
57 if (bucket_node) {
58 node = bucket_node->FirstChildElement("CreationDate");
59 if (node && node->GetText()) creationDate_ = node->GetText();
60
61 node = bucket_node->FirstChildElement("ExtranetEndpoint");
62 if (node && node->GetText()) extranetEndpoint_ = node->GetText();
63
64 node = bucket_node->FirstChildElement("IntranetEndpoint");
65 if (node && node->GetText()) intranetEndpoint_ = node->GetText();
66
67 node = bucket_node->FirstChildElement("Location");
68 if (node && node->GetText()) location_ = node->GetText();
69
70 node = bucket_node->FirstChildElement("Name");
71 if (node && node->GetText()) name_ = node->GetText();
72
73 node = bucket_node->FirstChildElement("StorageClass");
74 if (node && node->GetText()) storageClass_ = ToStorageClassType(node->GetText());
75
76 node = bucket_node->FirstChildElement("Owner");
77 std::string owner_ID, owner_DisplayName;
78 if (node) {
79 XMLElement *sub_node;
80 sub_node = node->FirstChildElement("ID");
81 if (sub_node && sub_node->GetText()) owner_ID = sub_node->GetText();
82
83 sub_node = node->FirstChildElement("DisplayName");
84 if (sub_node && sub_node->GetText()) owner_DisplayName = sub_node->GetText();
85 }
86 owner_ = AlibabaCloud::OSS::Owner(owner_ID, owner_DisplayName);
87
88 node = bucket_node->FirstChildElement("AccessControlList");
89 if (node) {
90 XMLElement *sub_node;
91 sub_node = node->FirstChildElement("Grant");
92 if (sub_node && sub_node->GetText()) acl_ = ToAclType(sub_node->GetText());
93 }
94
95 node = bucket_node->FirstChildElement("DataRedundancyType");
96 if (node && node->GetText()) dataRedundancyType_ = ToDataRedundancyType(node->GetText());
97
98 node = bucket_node->FirstChildElement("Comment");
99 if (node && node->GetText()) comment_ = node->GetText();
100
101 node = bucket_node->FirstChildElement("ServerSideEncryptionRule");
102 if (node) {
103 XMLElement *sub_node;
104 sub_node = node->FirstChildElement("SSEAlgorithm");
105 if (sub_node && sub_node->GetText()) sseAlgorithm_ = ToSSEAlgorithm(sub_node->GetText());
106
107 sub_node = node->FirstChildElement("KMSMasterKeyID");
108 if (sub_node && sub_node->GetText()) kmsMasterKeyID_ = sub_node->GetText();
109 }
110
111 node = bucket_node->FirstChildElement("Versioning");
112 if (node && node->GetText()) versioningStatus_ = ToVersioningStatusType(node->GetText());
113 }
114 //TODO check the result and the parse flag;
115 parseDone_ = true;
116 }
117 }
118 return *this;
119 }
120