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/ListLiveChannelResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include <alibabacloud/oss/model/Bucket.h>
21 #include <alibabacloud/oss/model/Owner.h>
22 #include <sstream>
23 #include "utils/Utils.h"
24 using namespace AlibabaCloud::OSS;
25 using namespace tinyxml2;
26 
ListLiveChannelResult()27 ListLiveChannelResult::ListLiveChannelResult():
28     OssResult(),maxKeys_(0)
29 {
30 }
31 
ListLiveChannelResult(const std::string & result)32 ListLiveChannelResult::ListLiveChannelResult(const std::string& result):
33     ListLiveChannelResult()
34 {
35     *this = result;
36 }
37 
ListLiveChannelResult(const std::shared_ptr<std::iostream> & result)38 ListLiveChannelResult::ListLiveChannelResult(const std::shared_ptr<std::iostream>& result):
39     ListLiveChannelResult()
40 {
41     std::istreambuf_iterator<char> isb(*result.get()), end;
42     std::string str(isb, end);
43     *this = str;
44 }
45 
operator =(const std::string & result)46 ListLiveChannelResult& ListLiveChannelResult::operator =(const std::string& result)
47 {
48     XMLDocument doc;
49     XMLError xml_err;
50     if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
51         XMLElement* root =doc.RootElement();
52         if (root && !std::strncmp("ListLiveChannelResult", root->Name(), 21)) {
53             XMLElement *node;
54             node = root->FirstChildElement("Prefix");
55             if(node && node->GetText())
56             {
57                 prefix_ = node->GetText();
58             }
59 
60             node = root->FirstChildElement("Marker");
61             if(node && node->GetText())
62             {
63                 marker_ = node->GetText();
64             }
65 
66             node = root->FirstChildElement("MaxKeys");
67             if(node && node->GetText())
68             {
69                 maxKeys_ = std::strtoul(node->GetText(), nullptr, 10);
70             }
71 
72             node = root->FirstChildElement("IsTruncated");
73             if(node && node->GetText())
74             {
75                 isTruncated_ = node->BoolText();
76             }
77 
78             node = root->FirstChildElement("NextMarker");
79             if(node && node->GetText())
80             {
81                 nextMarker_ = node->GetText();
82             }
83 
84             XMLNode *livechannelNode = root->FirstChildElement("LiveChannel");
85             for(; livechannelNode; livechannelNode = livechannelNode->NextSiblingElement("LiveChannel"))
86             {
87                 LiveChannelInfo info;
88                 node = livechannelNode->FirstChildElement("Name");
89                 if(node && node->GetText())
90                 {
91                     info.name = node->GetText();
92                 }
93 
94                 node = livechannelNode->FirstChildElement("Description");
95                 if(node && node->GetText())
96                 {
97                     info.description = node->GetText();
98                 }
99 
100                 node = livechannelNode->FirstChildElement("Status");
101                 if(node && node->GetText())
102                 {
103                     info.status = node->GetText();
104                 }
105 
106                 node = livechannelNode->FirstChildElement("LastModified");
107                 if(node && node->GetText())
108                 {
109                     info.lastModified = node->GetText();
110                 }
111 
112                 XMLNode *publishNode = livechannelNode->FirstChildElement("PublishUrls");
113                 if(publishNode)
114                 {
115                     node = publishNode->FirstChildElement("Url");
116                     if(node && node->GetText())
117                     {
118                         info.publishUrl = node->GetText();
119                     }
120                 }
121 
122                 XMLNode *playNode = livechannelNode->FirstChildElement("PlayUrls");
123                 if(playNode)
124                 {
125                     node = playNode->FirstChildElement("Url");
126                     if(node && node->GetText())
127                     {
128                         info.playUrl = node->GetText();
129                     }
130                 }
131                 liveChannelList_.push_back(info);
132             }
133             parseDone_ = true;
134         }
135     }
136     return *this;
137 }
138 
Marker() const139 const std::string& ListLiveChannelResult::Marker() const
140 {
141     return marker_;
142 }
143 
MaxKeys() const144 uint32_t ListLiveChannelResult::MaxKeys() const
145 {
146     return maxKeys_;
147 }
148 
Prefix() const149 const std::string& ListLiveChannelResult::Prefix() const
150 {
151     return prefix_;
152 }
153 
NextMarker() const154 const std::string& ListLiveChannelResult::NextMarker() const
155 {
156     return nextMarker_;
157 }
158 
IsTruncated() const159 bool ListLiveChannelResult::IsTruncated() const
160 {
161     return isTruncated_;
162 }
163 
LiveChannelList() const164 const LiveChannelListInfo& ListLiveChannelResult::LiveChannelList() const
165 {
166     return liveChannelList_;
167 }
168 
169 
170 
171