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/GetObjectAclResult.h>
19 #include <alibabacloud/oss/model/Owner.h>
20 #include <external/tinyxml2/tinyxml2.h>
21 #include "utils/Utils.h"
22 using namespace AlibabaCloud::OSS;
23 using namespace tinyxml2;
24 
GetObjectAclResult()25 GetObjectAclResult::GetObjectAclResult() :
26     OssObjectResult()
27 {
28 }
29 
GetObjectAclResult(const std::string & result)30 GetObjectAclResult::GetObjectAclResult(const std::string& result):
31     GetObjectAclResult()
32 {
33     *this = result;
34 }
35 
GetObjectAclResult(const std::shared_ptr<std::iostream> & result)36 GetObjectAclResult::GetObjectAclResult(const std::shared_ptr<std::iostream>& result):
37     GetObjectAclResult()
38 {
39     std::istreambuf_iterator<char> isb(*result.get()), end;
40     std::string str(isb, end);
41     *this = str;
42 }
43 
GetObjectAclResult(const HeaderCollection & headers,const std::shared_ptr<std::iostream> & result)44 GetObjectAclResult::GetObjectAclResult(const HeaderCollection& headers, const std::shared_ptr<std::iostream>& result) :
45     OssObjectResult(headers)
46 {
47     std::istreambuf_iterator<char> isb(*result.get()), end;
48     std::string str(isb, end);
49     *this = str;
50 }
51 
operator =(const std::string & result)52 GetObjectAclResult& GetObjectAclResult::operator =(const std::string& result)
53 {
54     XMLDocument doc;
55     XMLError xml_err;
56     if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
57         XMLElement* root =doc.RootElement();
58         if (root && !std::strncmp("AccessControlPolicy", root->Name(), 19)) {
59             XMLElement *node;
60 
61             node = root->FirstChildElement("Owner");
62             std::string owner_ID, owner_DisplayName;
63             if (node) {
64                 XMLElement *sub_node;
65                 sub_node = node->FirstChildElement("ID");
66                 if (sub_node && sub_node->GetText()) owner_ID = sub_node->GetText();
67 
68                 sub_node = node->FirstChildElement("DisplayName");
69                 if (sub_node && sub_node->GetText()) owner_DisplayName = sub_node->GetText();
70             }
71 
72             node = root->FirstChildElement("AccessControlList");
73             if (node) {
74                 XMLElement *sub_node;
75                 sub_node = node->FirstChildElement("Grant");
76                 if (sub_node && sub_node->GetText()) acl_ = ToAclType(sub_node->GetText());
77             }
78 
79             owner_ = AlibabaCloud::OSS::Owner(owner_ID, owner_DisplayName);
80 
81             //TODO check the result and the parse flag;
82             parseDone_ = true;
83         }
84     }
85     return *this;
86 }
87 
88