MinIO C++ SDK
response.h
1 // MinIO C++ Library for Amazon S3 Compatible Cloud Storage
2 // Copyright 2022 MinIO, Inc.
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 #ifndef _MINIO_S3_RESPONSE_H
17 #define _MINIO_S3_RESPONSE_H
18 
19 #include <pugixml.hpp>
20 
21 #include "types.h"
22 
23 namespace minio {
24 namespace s3 {
25 struct Response {
26  std::string error;
27 
28  int status_code = 0;
29  utils::Multimap headers;
30  std::string data;
31 
32  std::string code;
33  std::string message;
34  std::string resource;
35  std::string request_id;
36  std::string host_id;
37  std::string bucket_name;
38  std::string object_name;
39 
40  Response();
42  Response(const Response& response);
43  operator bool() const {
44  return error.empty() && code.empty() && message.empty() &&
45  (status_code == 0 || status_code >= 200 && status_code <= 299);
46  }
47  std::string GetError();
48  static Response ParseXML(std::string_view data, int status_code,
49  utils::Multimap headers);
50 }; // struct Response
51 
52 struct GetRegionResponse : public Response {
53  std::string region;
54 
55  GetRegionResponse(std::string regionvalue);
57  GetRegionResponse(const Response& response);
58 }; // struct GetRegionResponse
59 
61 
62 struct ListBucketsResponse : public Response {
63  std::list<Bucket> buckets;
64 
65  ListBucketsResponse(std::list<Bucket> bucketlist);
67  ListBucketsResponse(const Response& response);
68  static ListBucketsResponse ParseXML(std::string_view data);
69 }; // struct ListBucketsResponse
70 
71 struct BucketExistsResponse : public Response {
72  bool exist = false;
73 
74  BucketExistsResponse(bool existflag);
76  BucketExistsResponse(const Response& response);
77 }; // struct BucketExistsResponse
78 
80 
82 
84  std::string location;
85  std::string etag;
86  std::string version_id;
87 
91  static CompleteMultipartUploadResponse ParseXML(std::string_view data,
92  std::string version_id);
93 }; // struct CompleteMultipartUploadResponse
94 
96  std::string upload_id;
97 
98  CreateMultipartUploadResponse(std::string uploadid);
100  CreateMultipartUploadResponse(const Response& response);
101 }; // struct CreateMultipartUploadResponse
102 
103 struct PutObjectResponse : public Response {
104  std::string etag;
105  std::string version_id;
106 
109  PutObjectResponse(const Response& response);
110 }; // struct PutObjectResponse
111 
113 
115 
116 struct StatObjectResponse : public Response {
117  std::string version_id;
118  std::string etag;
119  size_t size = 0;
120  utils::Time last_modified;
121  RetentionMode retention_mode;
122  utils::Time retention_retain_until_date;
123  LegalHold legal_hold;
124  bool delete_marker;
125  utils::Multimap user_metadata;
126 
129  StatObjectResponse(const Response& response);
130 }; // struct StatObjectResponse
131 
133 
135 
137 
138 struct Item : public Response {
139  std::string etag; // except DeleteMarker
140  std::string name;
141  utils::Time last_modified;
142  std::string owner_id;
143  std::string owner_name;
144  size_t size = 0; // except DeleteMarker
145  std::string storage_class;
146  bool is_latest = false; // except ListObjects V1/V2
147  std::string version_id; // except ListObjects V1/V2
148  std::map<std::string, std::string> user_metadata;
149  bool is_prefix = false;
150  bool is_delete_marker = false;
151  std::string encoding_type;
152 
153  Item();
154  Item(error::Error err);
155  Item(const Response& response);
156 }; // struct Item
157 
158 struct ListObjectsResponse : public Response {
159  // Common
160  std::string name;
161  std::string encoding_type;
162  std::string prefix;
163  std::string delimiter;
164  bool is_truncated;
165  unsigned int max_keys;
166  std::list<Item> contents;
167 
168  // ListObjectsV1
169  std::string marker;
170  std::string next_marker;
171 
172  // ListObjectsV2
173  unsigned int key_count;
174  std::string start_after;
175  std::string continuation_token;
176  std::string next_continuation_token;
177 
178  // ListObjectVersions
179  std::string key_marker;
180  std::string next_key_marker;
181  std::string version_id_marker;
182  std::string next_version_id_marker;
183 
186  ListObjectsResponse(const Response& response);
187  static ListObjectsResponse ParseXML(std::string_view data, bool version);
188 }; // struct ListObjectsResponse
189 
191 
193 
195 } // namespace s3
196 } // namespace minio
197 
198 #endif // #ifndef _MINIO_S3_RESPONSE_H
Definition: error.h:23
Definition: utils.h:119
Definition: utils.h:97
Definition: response.h:71
Definition: response.h:52
Definition: response.h:138
Definition: response.h:62
Definition: response.h:158
Definition: response.h:103
Definition: response.h:25
Definition: response.h:116