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/GetBucketCorsResult.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
GetBucketCorsResult()25 GetBucketCorsResult::GetBucketCorsResult() :
26 OssResult()
27 {
28 }
29
GetBucketCorsResult(const std::string & result)30 GetBucketCorsResult::GetBucketCorsResult(const std::string& result):
31 GetBucketCorsResult()
32 {
33 *this = result;
34 }
35
GetBucketCorsResult(const std::shared_ptr<std::iostream> & result)36 GetBucketCorsResult::GetBucketCorsResult(const std::shared_ptr<std::iostream>& result):
37 GetBucketCorsResult()
38 {
39 std::istreambuf_iterator<char> isb(*result.get()), end;
40 std::string str(isb, end);
41 *this = str;
42 }
43
operator =(const std::string & result)44 GetBucketCorsResult& GetBucketCorsResult::operator =(const std::string& result)
45 {
46 XMLDocument doc;
47 XMLError xml_err;
48 if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
49 XMLElement* root =doc.RootElement();
50 if (root && !std::strncmp("CORSConfiguration", root->Name(), 17)) {
51 XMLElement *rule_node = root->FirstChildElement("CORSRule");
52 for (; rule_node; rule_node = rule_node->NextSiblingElement("CORSRule")) {
53 XMLElement *node = rule_node->FirstChildElement();
54 CORSRule rule;
55 for (; node; node = node->NextSiblingElement()) {
56
57 if (!strncmp(node->Name(), "AllowedOrigin", 13))
58 if (node->GetText()) rule.addAllowedOrigin(node->GetText());
59
60 if (!strncmp(node->Name(), "AllowedMethod", 13))
61 if (node->GetText()) rule.addAllowedMethod(node->GetText());
62
63 if (!strncmp(node->Name(), "AllowedHeader", 13))
64 if (node->GetText()) rule.addAllowedHeader(node->GetText());
65
66 if (!strncmp(node->Name(), "ExposeHeader", 12))
67 if (node->GetText()) rule.addExposeHeader(node->GetText());
68
69 if (!strncmp(node->Name(), "MaxAgeSeconds", 13))
70 if (node->GetText()) rule.setMaxAgeSeconds(std::atoi(node->GetText()));
71 }
72 ruleList_.push_back(rule);
73 }
74 parseDone_ = true;
75 }
76 }
77 return *this;
78 }
79