| 1 | /* |
| 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. 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 | * A copy of the License is located at |
| 7 | * |
| 8 | * http://aws.amazon.com/apache2.0 |
| 9 | * |
| 10 | * or in the "license" file accompanying this file. This file is distributed |
| 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | * express or implied. See the License for the specific language governing |
| 13 | * permissions and limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <aws/s3/model/GetObjectResult.h> |
| 17 | #include <aws/core/AmazonWebServiceResult.h> |
| 18 | #include <aws/core/utils/StringUtils.h> |
| 19 | #include <aws/core/utils/HashingUtils.h> |
| 20 | #include <aws/core/utils/memory/stl/AWSStringStream.h> |
| 21 | |
| 22 | #include <utility> |
| 23 | |
| 24 | using namespace Aws::S3::Model; |
| 25 | using namespace Aws::Utils::Stream; |
| 26 | using namespace Aws::Utils; |
| 27 | using namespace Aws; |
| 28 | |
| 29 | GetObjectResult::GetObjectResult() : |
| 30 | m_deleteMarker(false), |
| 31 | m_contentLength(0), |
| 32 | m_missingMeta(0), |
| 33 | m_serverSideEncryption(ServerSideEncryption::NOT_SET), |
| 34 | m_storageClass(StorageClass::NOT_SET), |
| 35 | m_requestCharged(RequestCharged::NOT_SET), |
| 36 | m_replicationStatus(ReplicationStatus::NOT_SET), |
| 37 | m_partsCount(0), |
| 38 | m_tagCount(0), |
| 39 | m_objectLockMode(ObjectLockMode::NOT_SET), |
| 40 | m_objectLockLegalHoldStatus(ObjectLockLegalHoldStatus::NOT_SET) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | GetObjectResult::GetObjectResult(GetObjectResult&& toMove) : |
| 45 | m_body(std::move(toMove.m_body)), |
| 46 | m_deleteMarker(toMove.m_deleteMarker), |
| 47 | m_acceptRanges(std::move(toMove.m_acceptRanges)), |
| 48 | m_expiration(std::move(toMove.m_expiration)), |
| 49 | m_restore(std::move(toMove.m_restore)), |
| 50 | m_lastModified(std::move(toMove.m_lastModified)), |
| 51 | m_contentLength(toMove.m_contentLength), |
| 52 | m_eTag(std::move(toMove.m_eTag)), |
| 53 | m_missingMeta(toMove.m_missingMeta), |
| 54 | m_versionId(std::move(toMove.m_versionId)), |
| 55 | m_cacheControl(std::move(toMove.m_cacheControl)), |
| 56 | m_contentDisposition(std::move(toMove.m_contentDisposition)), |
| 57 | m_contentEncoding(std::move(toMove.m_contentEncoding)), |
| 58 | m_contentLanguage(std::move(toMove.m_contentLanguage)), |
| 59 | m_contentRange(std::move(toMove.m_contentRange)), |
| 60 | m_contentType(std::move(toMove.m_contentType)), |
| 61 | m_expires(std::move(toMove.m_expires)), |
| 62 | m_websiteRedirectLocation(std::move(toMove.m_websiteRedirectLocation)), |
| 63 | m_serverSideEncryption(toMove.m_serverSideEncryption), |
| 64 | m_metadata(std::move(toMove.m_metadata)), |
| 65 | m_sSECustomerAlgorithm(std::move(toMove.m_sSECustomerAlgorithm)), |
| 66 | m_sSECustomerKeyMD5(std::move(toMove.m_sSECustomerKeyMD5)), |
| 67 | m_sSEKMSKeyId(std::move(toMove.m_sSEKMSKeyId)), |
| 68 | m_storageClass(toMove.m_storageClass), |
| 69 | m_requestCharged(toMove.m_requestCharged), |
| 70 | m_replicationStatus(toMove.m_replicationStatus), |
| 71 | m_partsCount(toMove.m_partsCount), |
| 72 | m_tagCount(toMove.m_tagCount), |
| 73 | m_objectLockMode(toMove.m_objectLockMode), |
| 74 | m_objectLockRetainUntilDate(std::move(toMove.m_objectLockRetainUntilDate)), |
| 75 | m_objectLockLegalHoldStatus(toMove.m_objectLockLegalHoldStatus), |
| 76 | m_id2(std::move(toMove.m_id2)), |
| 77 | m_requestId(std::move(toMove.m_requestId)) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | GetObjectResult& GetObjectResult::operator=(GetObjectResult&& toMove) |
| 82 | { |
| 83 | if(this == &toMove) |
| 84 | { |
| 85 | return *this; |
| 86 | } |
| 87 | |
| 88 | m_body = std::move(toMove.m_body); |
| 89 | m_deleteMarker = toMove.m_deleteMarker; |
| 90 | m_acceptRanges = std::move(toMove.m_acceptRanges); |
| 91 | m_expiration = std::move(toMove.m_expiration); |
| 92 | m_restore = std::move(toMove.m_restore); |
| 93 | m_lastModified = std::move(toMove.m_lastModified); |
| 94 | m_contentLength = toMove.m_contentLength; |
| 95 | m_eTag = std::move(toMove.m_eTag); |
| 96 | m_missingMeta = toMove.m_missingMeta; |
| 97 | m_versionId = std::move(toMove.m_versionId); |
| 98 | m_cacheControl = std::move(toMove.m_cacheControl); |
| 99 | m_contentDisposition = std::move(toMove.m_contentDisposition); |
| 100 | m_contentEncoding = std::move(toMove.m_contentEncoding); |
| 101 | m_contentLanguage = std::move(toMove.m_contentLanguage); |
| 102 | m_contentRange = std::move(toMove.m_contentRange); |
| 103 | m_contentType = std::move(toMove.m_contentType); |
| 104 | m_expires = std::move(toMove.m_expires); |
| 105 | m_websiteRedirectLocation = std::move(toMove.m_websiteRedirectLocation); |
| 106 | m_serverSideEncryption = toMove.m_serverSideEncryption; |
| 107 | m_metadata = std::move(toMove.m_metadata); |
| 108 | m_sSECustomerAlgorithm = std::move(toMove.m_sSECustomerAlgorithm); |
| 109 | m_sSECustomerKeyMD5 = std::move(toMove.m_sSECustomerKeyMD5); |
| 110 | m_sSEKMSKeyId = std::move(toMove.m_sSEKMSKeyId); |
| 111 | m_storageClass = toMove.m_storageClass; |
| 112 | m_requestCharged = toMove.m_requestCharged; |
| 113 | m_replicationStatus = toMove.m_replicationStatus; |
| 114 | m_partsCount = toMove.m_partsCount; |
| 115 | m_tagCount = toMove.m_tagCount; |
| 116 | m_objectLockMode = toMove.m_objectLockMode; |
| 117 | m_objectLockRetainUntilDate = std::move(toMove.m_objectLockRetainUntilDate); |
| 118 | m_objectLockLegalHoldStatus = toMove.m_objectLockLegalHoldStatus; |
| 119 | m_id2 = std::move(toMove.m_id2); |
| 120 | m_requestId = std::move(toMove.m_requestId); |
| 121 | |
| 122 | return *this; |
| 123 | } |
| 124 | |
| 125 | GetObjectResult::GetObjectResult(Aws::AmazonWebServiceResult<ResponseStream>&& result) : |
| 126 | m_deleteMarker(false), |
| 127 | m_contentLength(0), |
| 128 | m_missingMeta(0), |
| 129 | m_serverSideEncryption(ServerSideEncryption::NOT_SET), |
| 130 | m_storageClass(StorageClass::NOT_SET), |
| 131 | m_requestCharged(RequestCharged::NOT_SET), |
| 132 | m_replicationStatus(ReplicationStatus::NOT_SET), |
| 133 | m_partsCount(0), |
| 134 | m_tagCount(0), |
| 135 | m_objectLockMode(ObjectLockMode::NOT_SET), |
| 136 | m_objectLockLegalHoldStatus(ObjectLockLegalHoldStatus::NOT_SET) |
| 137 | { |
| 138 | *this = std::move(result); |
| 139 | } |
| 140 | |
| 141 | GetObjectResult& GetObjectResult::operator =(Aws::AmazonWebServiceResult<ResponseStream>&& result) |
| 142 | { |
| 143 | m_body = result.TakeOwnershipOfPayload(); |
| 144 | |
| 145 | const auto& = result.GetHeaderValueCollection(); |
| 146 | const auto& deleteMarkerIter = headers.find("x-amz-delete-marker" ); |
| 147 | if(deleteMarkerIter != headers.end()) |
| 148 | { |
| 149 | m_deleteMarker = StringUtils::ConvertToBool(deleteMarkerIter->second.c_str()); |
| 150 | } |
| 151 | |
| 152 | const auto& acceptRangesIter = headers.find("accept-ranges" ); |
| 153 | if(acceptRangesIter != headers.end()) |
| 154 | { |
| 155 | m_acceptRanges = acceptRangesIter->second; |
| 156 | } |
| 157 | |
| 158 | const auto& expirationIter = headers.find("x-amz-expiration" ); |
| 159 | if(expirationIter != headers.end()) |
| 160 | { |
| 161 | m_expiration = expirationIter->second; |
| 162 | } |
| 163 | |
| 164 | const auto& restoreIter = headers.find("x-amz-restore" ); |
| 165 | if(restoreIter != headers.end()) |
| 166 | { |
| 167 | m_restore = restoreIter->second; |
| 168 | } |
| 169 | |
| 170 | const auto& lastModifiedIter = headers.find("last-modified" ); |
| 171 | if(lastModifiedIter != headers.end()) |
| 172 | { |
| 173 | m_lastModified = DateTime(lastModifiedIter->second, DateFormat::RFC822); |
| 174 | } |
| 175 | |
| 176 | const auto& contentLengthIter = headers.find("content-length" ); |
| 177 | if(contentLengthIter != headers.end()) |
| 178 | { |
| 179 | m_contentLength = StringUtils::ConvertToInt64(contentLengthIter->second.c_str()); |
| 180 | } |
| 181 | |
| 182 | const auto& eTagIter = headers.find("etag" ); |
| 183 | if(eTagIter != headers.end()) |
| 184 | { |
| 185 | m_eTag = eTagIter->second; |
| 186 | } |
| 187 | |
| 188 | const auto& missingMetaIter = headers.find("x-amz-missing-meta" ); |
| 189 | if(missingMetaIter != headers.end()) |
| 190 | { |
| 191 | m_missingMeta = StringUtils::ConvertToInt32(missingMetaIter->second.c_str()); |
| 192 | } |
| 193 | |
| 194 | const auto& versionIdIter = headers.find("x-amz-version-id" ); |
| 195 | if(versionIdIter != headers.end()) |
| 196 | { |
| 197 | m_versionId = versionIdIter->second; |
| 198 | } |
| 199 | |
| 200 | const auto& cacheControlIter = headers.find("cache-control" ); |
| 201 | if(cacheControlIter != headers.end()) |
| 202 | { |
| 203 | m_cacheControl = cacheControlIter->second; |
| 204 | } |
| 205 | |
| 206 | const auto& contentDispositionIter = headers.find("content-disposition" ); |
| 207 | if(contentDispositionIter != headers.end()) |
| 208 | { |
| 209 | m_contentDisposition = contentDispositionIter->second; |
| 210 | } |
| 211 | |
| 212 | const auto& contentEncodingIter = headers.find("content-encoding" ); |
| 213 | if(contentEncodingIter != headers.end()) |
| 214 | { |
| 215 | m_contentEncoding = contentEncodingIter->second; |
| 216 | } |
| 217 | |
| 218 | const auto& contentLanguageIter = headers.find("content-language" ); |
| 219 | if(contentLanguageIter != headers.end()) |
| 220 | { |
| 221 | m_contentLanguage = contentLanguageIter->second; |
| 222 | } |
| 223 | |
| 224 | const auto& contentRangeIter = headers.find("content-range" ); |
| 225 | if(contentRangeIter != headers.end()) |
| 226 | { |
| 227 | m_contentRange = contentRangeIter->second; |
| 228 | } |
| 229 | |
| 230 | const auto& contentTypeIter = headers.find("content-type" ); |
| 231 | if(contentTypeIter != headers.end()) |
| 232 | { |
| 233 | m_contentType = contentTypeIter->second; |
| 234 | } |
| 235 | |
| 236 | const auto& expiresIter = headers.find("expires" ); |
| 237 | if(expiresIter != headers.end()) |
| 238 | { |
| 239 | m_expires = DateTime(expiresIter->second, DateFormat::RFC822); |
| 240 | } |
| 241 | |
| 242 | const auto& websiteRedirectLocationIter = headers.find("x-amz-website-redirect-location" ); |
| 243 | if(websiteRedirectLocationIter != headers.end()) |
| 244 | { |
| 245 | m_websiteRedirectLocation = websiteRedirectLocationIter->second; |
| 246 | } |
| 247 | |
| 248 | const auto& serverSideEncryptionIter = headers.find("x-amz-server-side-encryption" ); |
| 249 | if(serverSideEncryptionIter != headers.end()) |
| 250 | { |
| 251 | m_serverSideEncryption = ServerSideEncryptionMapper::GetServerSideEncryptionForName(serverSideEncryptionIter->second); |
| 252 | } |
| 253 | |
| 254 | std::size_t prefixSize = sizeof("x-amz-meta-" ) - 1; //subtract the NULL terminator out |
| 255 | for(const auto& item : headers) |
| 256 | { |
| 257 | std::size_t foundPrefix = item.first.find("x-amz-meta-" ); |
| 258 | |
| 259 | if(foundPrefix != std::string::npos) |
| 260 | { |
| 261 | m_metadata[item.first.substr(prefixSize)] = item.second; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | const auto& sSECustomerAlgorithmIter = headers.find("x-amz-server-side-encryption-customer-algorithm" ); |
| 266 | if(sSECustomerAlgorithmIter != headers.end()) |
| 267 | { |
| 268 | m_sSECustomerAlgorithm = sSECustomerAlgorithmIter->second; |
| 269 | } |
| 270 | |
| 271 | const auto& sSECustomerKeyMD5Iter = headers.find("x-amz-server-side-encryption-customer-key-md5" ); |
| 272 | if(sSECustomerKeyMD5Iter != headers.end()) |
| 273 | { |
| 274 | m_sSECustomerKeyMD5 = sSECustomerKeyMD5Iter->second; |
| 275 | } |
| 276 | |
| 277 | const auto& sSEKMSKeyIdIter = headers.find("x-amz-server-side-encryption-aws-kms-key-id" ); |
| 278 | if(sSEKMSKeyIdIter != headers.end()) |
| 279 | { |
| 280 | m_sSEKMSKeyId = sSEKMSKeyIdIter->second; |
| 281 | } |
| 282 | |
| 283 | const auto& storageClassIter = headers.find("x-amz-storage-class" ); |
| 284 | if(storageClassIter != headers.end()) |
| 285 | { |
| 286 | m_storageClass = StorageClassMapper::GetStorageClassForName(storageClassIter->second); |
| 287 | } |
| 288 | |
| 289 | const auto& requestChargedIter = headers.find("x-amz-request-charged" ); |
| 290 | if(requestChargedIter != headers.end()) |
| 291 | { |
| 292 | m_requestCharged = RequestChargedMapper::GetRequestChargedForName(requestChargedIter->second); |
| 293 | } |
| 294 | |
| 295 | const auto& replicationStatusIter = headers.find("x-amz-replication-status" ); |
| 296 | if(replicationStatusIter != headers.end()) |
| 297 | { |
| 298 | m_replicationStatus = ReplicationStatusMapper::GetReplicationStatusForName(replicationStatusIter->second); |
| 299 | } |
| 300 | |
| 301 | const auto& partsCountIter = headers.find("x-amz-mp-parts-count" ); |
| 302 | if(partsCountIter != headers.end()) |
| 303 | { |
| 304 | m_partsCount = StringUtils::ConvertToInt32(partsCountIter->second.c_str()); |
| 305 | } |
| 306 | |
| 307 | const auto& tagCountIter = headers.find("x-amz-tagging-count" ); |
| 308 | if(tagCountIter != headers.end()) |
| 309 | { |
| 310 | m_tagCount = StringUtils::ConvertToInt32(tagCountIter->second.c_str()); |
| 311 | } |
| 312 | |
| 313 | const auto& objectLockModeIter = headers.find("x-amz-object-lock-mode" ); |
| 314 | if(objectLockModeIter != headers.end()) |
| 315 | { |
| 316 | m_objectLockMode = ObjectLockModeMapper::GetObjectLockModeForName(objectLockModeIter->second); |
| 317 | } |
| 318 | |
| 319 | const auto& objectLockRetainUntilDateIter = headers.find("x-amz-object-lock-retain-until-date" ); |
| 320 | if(objectLockRetainUntilDateIter != headers.end()) |
| 321 | { |
| 322 | m_objectLockRetainUntilDate = DateTime(objectLockRetainUntilDateIter->second, DateFormat::RFC822); |
| 323 | } |
| 324 | |
| 325 | const auto& objectLockLegalHoldStatusIter = headers.find("x-amz-object-lock-legal-hold" ); |
| 326 | if(objectLockLegalHoldStatusIter != headers.end()) |
| 327 | { |
| 328 | m_objectLockLegalHoldStatus = ObjectLockLegalHoldStatusMapper::GetObjectLockLegalHoldStatusForName(objectLockLegalHoldStatusIter->second); |
| 329 | } |
| 330 | |
| 331 | const auto& id2Iter = headers.find("x-amz-id-2" ); |
| 332 | if(id2Iter != headers.end()) |
| 333 | { |
| 334 | m_id2 = id2Iter->second; |
| 335 | } |
| 336 | |
| 337 | const auto& requestIdIter = headers.find("x-amz-request-id" ); |
| 338 | if(requestIdIter != headers.end()) |
| 339 | { |
| 340 | m_requestId = requestIdIter->second; |
| 341 | } |
| 342 | |
| 343 | return *this; |
| 344 | } |
| 345 | |