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 #pragma once
18 
19 #include <string>
20 #include <alibabacloud/oss/ServiceRequest.h>
21 
22 namespace AlibabaCloud
23 {
24 namespace OSS
25 {
26     class OssClientImpl;
27     class OssEncryptionClient;
28     class  ALIBABACLOUD_OSS_EXPORT OssRequest : public ServiceRequest
29     {
30     public:
31         OssRequest();
32         virtual ~ OssRequest() = default;
33         virtual HeaderCollection Headers() const;
34         virtual ParameterCollection Parameters() const;
35         virtual std::shared_ptr<std::iostream> Body() const;
36     protected:
37         OssRequest(const std::string& bucket, const std::string& key);
38         friend class OssClientImpl;
39         friend class OssEncryptionClient;
40 
41         virtual int validate() const;
42         const char *validateMessage(int code) const;
43 
44         virtual std::string payload() const;
45         virtual HeaderCollection specialHeaders() const;
46         virtual ParameterCollection specialParameters() const;
47 
48         const std::string& bucket() const;
49         const std::string& key()  const;
50     protected:
51         std::string bucket_;
52         std::string key_;
53     };
54 
55     class ALIBABACLOUD_OSS_EXPORT OssBucketRequest : public OssRequest
56     {
57     public:
OssBucketRequest(const std::string & bucket)58         OssBucketRequest(const std::string& bucket):
59             OssRequest(bucket, "")
60         {}
61         void setBucket(const std::string& bucket);
62         const std::string& Bucket() const;
63     protected:
64         virtual int validate() const;
65     };
66 
67     class ALIBABACLOUD_OSS_EXPORT OssObjectRequest : public OssRequest
68     {
69     public:
OssObjectRequest(const std::string & bucket,const std::string & key)70         OssObjectRequest(const std::string& bucket, const std::string& key) :
71             OssRequest(bucket, key),
72             requestPayer_(AlibabaCloud::OSS::RequestPayer::NotSet),
73             versionId_()
74         {}
75         void setBucket(const std::string& bucket);
76         const std::string& Bucket() const;
77 
78         void setKey(const std::string& key);
79         const std::string& Key() const;
80 
81         void setRequestPayer(AlibabaCloud::OSS::RequestPayer value);
82         AlibabaCloud::OSS::RequestPayer RequestPayer() const;
83         void setVersionId(const std::string& versionId);
84         const std::string& VersionId() const;
85     protected:
86         virtual int validate() const;
87         virtual HeaderCollection specialHeaders() const;
88         virtual ParameterCollection specialParameters() const;
89         AlibabaCloud::OSS::RequestPayer requestPayer_;
90         std::string versionId_;
91     };
92 
93     class ALIBABACLOUD_OSS_EXPORT OssResumableBaseRequest : public OssRequest
94     {
95     public:
OssResumableBaseRequest(const std::string & bucket,const std::string & key,const std::string & checkpointDir,const uint64_t partSize,const uint32_t threadNum)96         OssResumableBaseRequest(const std::string& bucket, const std::string& key,
97             const std::string& checkpointDir, const uint64_t partSize, const uint32_t threadNum) :
98             OssRequest(bucket, key),
99             partSize_(partSize),
100             checkpointDir_(checkpointDir),
101             requestPayer_(AlibabaCloud::OSS::RequestPayer::NotSet),
102             trafficLimit_(0),
103             versionId_()
104         {
105             threadNum_ = threadNum == 0 ? 1 : threadNum;
106         }
107 
OssResumableBaseRequest(const std::string & bucket,const std::string & key,const std::wstring & checkpointDir,const uint64_t partSize,const uint32_t threadNum)108         OssResumableBaseRequest(const std::string& bucket, const std::string& key,
109             const std::wstring& checkpointDir, const uint64_t partSize, const uint32_t threadNum) :
110             OssRequest(bucket, key),
111             partSize_(partSize),
112             checkpointDirW_(checkpointDir),
113             requestPayer_(AlibabaCloud::OSS::RequestPayer::NotSet),
114             trafficLimit_(0),
115             versionId_()
116         {
117             threadNum_ = threadNum == 0 ? 1 : threadNum;
118         }
119 
120         void setBucket(const std::string& bucket);
121         const std::string& Bucket() const;
122 
123         void setKey(const std::string& key);
124         const std::string& Key() const;
125 
126         void setPartSize(uint64_t partSize);
127         uint64_t PartSize() const;
128 
129         void setObjectSize(uint64_t objectSize);
130         uint64_t ObjectSize() const;
131 
132         void setThreadNum(uint32_t threadNum);
133         uint32_t ThreadNum() const;
134 
135         void setCheckpointDir(const std::string& checkpointDir);
136         const std::string& CheckpointDir() const;
137 
138         void setCheckpointDir(const std::wstring& checkpointDir);
139         const std::wstring& CheckpointDirW() const;
140 
141         bool hasCheckpointDir() const;
142 
143         void setObjectMtime(const std::string& mtime);
144         const std::string& ObjectMtime() const;
145 
146         void setRequestPayer(RequestPayer value);
147         AlibabaCloud::OSS::RequestPayer RequestPayer() const;
148 
149         void setTrafficLimit(uint64_t value);
150         uint64_t TrafficLimit() const;
151 
152         void setVersionId(const std::string& versionId);
153         const std::string& VersionId() const;
154 
155     protected:
156         friend class OssClientImpl;
157         friend class OssEncryptionClient;
158         virtual int validate() const;
159         const char *validateMessage(int code) const;
160 
161     protected:
162         uint64_t partSize_;
163         uint64_t objectSize_;
164         uint32_t threadNum_;
165         std::string checkpointDir_;
166         std::wstring checkpointDirW_;
167         std::string mtime_;
168         AlibabaCloud::OSS::RequestPayer requestPayer_;
169         uint64_t trafficLimit_;
170         std::string versionId_;
171     };
172 
173     class ALIBABACLOUD_OSS_EXPORT LiveChannelRequest : public OssRequest
174     {
175     public:
LiveChannelRequest(const std::string & bucket,const std::string & channelName)176         LiveChannelRequest(const std::string &bucket, const std::string &channelName) :
177             OssRequest(bucket, channelName),
178             channelName_(channelName)
179         {}
180         void setBucket(const std::string &bucket);
181         const std::string& Bucket() const;
182 
183         void setChannelName(const std::string &channelName);
184         const std::string& ChannelName() const;
185     protected:
186         virtual int validate() const;
187     protected:
188         std::string channelName_;
189     };
190 }
191 }
192