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/GetBucketRefererResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23 
24 
GetBucketRefererResult()25 GetBucketRefererResult::GetBucketRefererResult() :
26     OssResult()
27 {
28 }
29 
GetBucketRefererResult(const std::string & result)30 GetBucketRefererResult::GetBucketRefererResult(const std::string& result):
31     GetBucketRefererResult()
32 {
33     *this = result;
34 }
35 
GetBucketRefererResult(const std::shared_ptr<std::iostream> & result)36 GetBucketRefererResult::GetBucketRefererResult(const std::shared_ptr<std::iostream>& result):
37     GetBucketRefererResult()
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 GetBucketRefererResult& GetBucketRefererResult::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("RefererConfiguration", root->Name(), 20)) {
51             XMLElement *node;
52             node = root->FirstChildElement("AllowEmptyReferer");
53             if (node && node->GetText()) allowEmptyReferer_ = (std::strncmp(node->GetText(), "true", 4)? false:true);
54 
55             node = root->FirstChildElement("RefererList");
56             if (node) {
57                 XMLElement *referer_node = node->FirstChildElement("Referer");
58                 for (; referer_node; referer_node = referer_node->NextSiblingElement()) {
59                     if (referer_node->GetText())
60                         refererList_.push_back(referer_node->GetText());
61                 }
62             }
63 		    parseDone_ = true;
64 		}
65     }
66     return *this;
67 }
68