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 <ctime> 21 #include <iostream> 22 #include <alibabacloud/oss/Types.h> 23 24 namespace AlibabaCloud 25 { 26 namespace OSS 27 { 28 #define UNUSED_PARAM(x) ((void)(x)) 29 30 std::string ComputeContentMD5(const std::string& data); 31 std::string ComputeContentMD5(const char *data, size_t size); 32 std::string ComputeContentMD5(std::istream & stream); 33 34 std::string ComputeContentETag(const std::string& data); 35 std::string ComputeContentETag(const char *data, size_t size); 36 std::string ComputeContentETag(std::istream & stream); 37 38 std::string GenerateUuid(); 39 std::string UrlEncode(const std::string &src); 40 std::string UrlDecode(const std::string &src); 41 42 std::string Base64Encode(const std::string &src); 43 std::string Base64Encode(const ByteBuffer& buffer); 44 std::string Base64Encode(const char *src, int len); 45 std::string Base64EncodeUrlSafe(const std::string &src); 46 std::string Base64EncodeUrlSafe(const char *src, int len); 47 48 std::string XmlEscape(const std::string& value); 49 50 ByteBuffer Base64Decode(const char *src, int len); 51 ByteBuffer Base64Decode(const std::string &src); 52 53 void StringReplace(std::string &src, const std::string &s1, const std::string &s2); 54 std::string LeftTrim(const char* source); 55 std::string RightTrim(const char* source); 56 std::string Trim(const char* source); 57 std::string LeftTrimQuotes(const char* source); 58 std::string RightTrimQuotes(const char* source); 59 std::string TrimQuotes(const char* source); 60 std::string ToLower(const char* source); 61 std::string ToUpper(const char* source); 62 std::string ToGmtTime(std::time_t &t); 63 std::string ToUtcTime(std::time_t &t); 64 std::time_t UtcToUnixTime(const std::string &t); 65 66 bool IsIp(const std::string &host); 67 bool IsValidBucketName(const std::string &bucketName); 68 bool IsValidObjectKey(const std::string &key); 69 bool IsValidLoggingPrefix(const std::string &prefix); 70 bool IsValidChannelName(const std::string &channelName); 71 bool IsValidPlayListName(const std::string &playListName); 72 bool IsValidTagKey(const std::string &key); 73 bool IsValidTagValue(const std::string &value); 74 75 const std::string &LookupMimeType(const std::string& name); 76 std::string CombineHostString(const std::string &endpoint, const std::string &bucket, bool isCname); 77 std::string CombinePathString(const std::string &endpoint, const std::string &bucket, const std::string &key); 78 std::string CombineQueryString(const ParameterCollection ¶meters); 79 std::string CombineRTMPString(const std::string &endpoint, const std::string &bucket, bool isCname); 80 81 82 std::streampos GetIOStreamLength(std::iostream &stream); 83 84 const char *ToStorageClassName(StorageClass storageClass); 85 StorageClass ToStorageClassType(const char *name); 86 87 const char *ToAclName(CannedAccessControlList acl); 88 CannedAccessControlList ToAclType(const char *name); 89 90 const char * ToCopyActionName(CopyActionList action); 91 92 const char * ToRuleStatusName(RuleStatus status); 93 RuleStatus ToRuleStatusType(const char *name); 94 95 const char * ToLiveChannelStatusName(LiveChannelStatus status); 96 LiveChannelStatus ToLiveChannelStatusType(const char *name); 97 98 const char* ToRequestPayerName(RequestPayer payer); 99 RequestPayer ToRequestPayer(const char* name); 100 const char* ToSSEAlgorithmName(SSEAlgorithm sse); 101 SSEAlgorithm ToSSEAlgorithm(const char* name); 102 103 DataRedundancyType ToDataRedundancyType(const char* name); 104 const char* ToDataRedundancyTypeName(DataRedundancyType type); 105 106 const char * ToVersioningStatusName(VersioningStatus status); 107 VersioningStatus ToVersioningStatusType(const char *name); 108 109 const char* ToInventoryFormatName(InventoryFormat status); 110 InventoryFormat ToInventoryFormatType(const char* name); 111 112 const char* ToInventoryFrequencyName(InventoryFrequency status); 113 InventoryFrequency ToInventoryFrequencyType(const char* name); 114 115 const char* ToInventoryOptionalFieldName(InventoryOptionalField status); 116 InventoryOptionalField ToInventoryOptionalFieldType(const char* name); 117 118 const char* ToInventoryIncludedObjectVersionsName(InventoryIncludedObjectVersions status); 119 InventoryIncludedObjectVersions ToInventoryIncludedObjectVersionsType(const char* name); 120 121 std::string ToInventoryBucketFullName(const std::string& name); 122 std::string ToInventoryBucketShortName(const char* name); 123 124 const char * ToTierTypeName(TierType status); 125 TierType ToTierType(const char *name); 126 127 #if !defined(OSS_DISABLE_RESUAMABLE) || !defined(OSS_DISABLE_ENCRYPTION) 128 std::map<std::string, std::string> JsonStringToMap(const std::string& jsonStr); 129 std::string MapToJsonString(const std::map<std::string, std::string>& map); 130 #endif 131 } 132 } 133