Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/cos_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ class CosAPI {
/// \param req AsyncResumableGetObject
/// \return 返回context
SharedAsyncContext AsyncResumableGetObject(const AsyncGetObjectReq& req);
SharedAsyncContext AsyncResumableGetObject(const AsyncGetObjectReq& req, Poco::TaskManager*& taskManager);;
SharedAsyncContext AsyncResumableGetObject(const AsyncGetObjectReq& req, Poco::TaskManager*& taskManager);

/// \brief 异步多线程下载对象到本地
/// \param req MultiGetObjectAsync请求
Expand Down
1 change: 1 addition & 0 deletions include/cos_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const uint64_t kPartSize1M = 1 * 1024 * 1024;
/// 分块大小5G
const uint64_t kPartSize5G = (uint64_t)5 * 1024 * 1024 * 1024;

const bool COS_CHANGE_BACKUP_DOMAIN = true;
typedef enum log_out_type {
COS_LOG_NULL = 0,
COS_LOG_STDOUT,
Expand Down
9 changes: 8 additions & 1 deletion include/cos_sys_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class CosSysConfig {

/// \brief 根据传入appid、region、bucket_name返回对应的hostname
static std::string GetHost(uint64_t app_id, const std::string& region,
const std::string& bucket_name);
const std::string& bucket_name,
bool change_backup_domain = false);

/// \brief 获取CI域名
static std::string GetCIHost(const std::string& bucket_name,
Expand Down Expand Up @@ -158,6 +159,10 @@ class CosSysConfig {
/// \brief 获取dns cache大小
static unsigned GetDnsCacheSize();

static void SetRetryChangeDomain(bool retry_change_domain);

static bool GetRetryChangeDomain();

private:
// 打印日志:0,不打印,1:打印到屏幕,2:打印到syslog
static LOG_OUT_TYPE m_log_outtype;
Expand Down Expand Up @@ -208,6 +213,8 @@ class CosSysConfig {
static unsigned m_dns_cache_expire_seconds;
// dns cache大小
static unsigned m_dns_cache_size;

static bool m_retry_change_domain;
};

} // namespace qcloud_cos
Expand Down
6 changes: 6 additions & 0 deletions include/op/base_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class BaseOp {

bool IsDomainSameToHost() const;

bool UseDefaultDomain() const;

bool IsDefaultHost(const std::string &host) const;

std::string ChangeHostSuffix(const std::string &host);

/// \brief 封装了cos Service/Bucket/Object 相关接口的通用操作,
/// 包括签名计算、请求发送、返回内容解析等
///
Expand Down
126 changes: 84 additions & 42 deletions include/op/bucket_op.h

Large diffs are not rendered by default.

95 changes: 58 additions & 37 deletions include/op/object_op.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017, Tencent Inc.
// Copyright (c) 2017, Tencent Inc.
// All rights reserved.
//
// Author: sevenyou <[email protected]>
Expand Down Expand Up @@ -41,7 +41,8 @@ class ObjectOp : public BaseOp {

std::string GetResumableUploadID(const PutObjectByFileReq& originReq,
const std::string& bucket_name,
const std::string& object_name);
const std::string& object_name,
bool change_backup_domain = false);

bool CheckUploadPart(const PutObjectByFileReq& req,
const std::string& bucket_name,
Expand All @@ -59,7 +60,7 @@ class ObjectOp : public BaseOp {
/// \param response HeadObject返回
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult HeadObject(const HeadObjectReq& req, HeadObjectResp* resp);
CosResult HeadObject(const HeadObjectReq& req, HeadObjectResp* resp, bool change_backup_domain = false);

/// \brief 下载Bucket中的一个文件至流中
///
Expand All @@ -68,7 +69,7 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult GetObject(const GetObjectByStreamReq& req,
GetObjectByStreamResp* resp);
GetObjectByStreamResp* resp, bool change_backup_domain = false);

/// \brief 下载Bucket中的一个文件到本地
///
Expand All @@ -77,7 +78,7 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult GetObject(const GetObjectByFileReq& req, GetObjectByFileResp* resp,
const SharedTransferHandler& handler = nullptr);
const SharedTransferHandler& handler = nullptr, bool change_backup_domain = false);

/// \brief 多线程下载Bucket中的一个文件到本地
///
Expand All @@ -95,7 +96,7 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult PutObject(const PutObjectByFileReq& req, PutObjectByFileResp* resp,
const SharedTransferHandler& handler = nullptr);
const SharedTransferHandler& handler = nullptr, bool change_backup_domain = false);

/// \brief 将指定流上传至指定Bucket中
///
Expand All @@ -104,23 +105,23 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult PutObject(const PutObjectByStreamReq& req,
PutObjectByStreamResp* resp, const SharedTransferHandler& handler=nullptr);
PutObjectByStreamResp* resp, const SharedTransferHandler& handler=nullptr, bool change_backup_domain = false);

/// \brief 删除Object
///
/// \param req DeleteObject请求
/// \param resp DeleteObject返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult DeleteObject(const DeleteObjectReq& req, DeleteObjectResp* resp);
CosResult DeleteObject(const DeleteObjectReq& req, DeleteObjectResp* resp, bool change_backup_domain = false);

/// \brief 批量删除Object
///
/// \param req DeleteObjects请求
/// \param resp DeleteObjects返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult DeleteObjects(const DeleteObjectsReq& req, DeleteObjectsResp* resp);
CosResult DeleteObjects(const DeleteObjectsReq& req, DeleteObjectsResp* resp, bool change_backup_domain = false);

/// \brief
/// 请求实现初始化分片上传,成功执行此请求以后会返回UploadId用于后续的Upload
Expand All @@ -131,7 +132,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult InitMultiUpload(const InitMultiUploadReq& req,
InitMultiUploadResp* resp);
InitMultiUploadResp* resp,
bool change_backup_domain = false);

/// \brief 初始化以后的分块上传,支持的块的数量为1到10000,块的大小为1MB到5GB
///
Expand All @@ -140,7 +142,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult UploadPartData(const UploadPartDataReq& req,
UploadPartDataResp* resp);
UploadPartDataResp* resp,
bool change_backup_domain = false);

/// \brief
/// 初始化以后的分块复制,实现将一个文件的分块内容从源路径复制到目标路径。
Expand All @@ -152,7 +155,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult UploadPartCopyData(const UploadPartCopyDataReq& req,
UploadPartCopyDataResp* resp);
UploadPartCopyDataResp* resp,
bool change_backup_domain = false);

/// \brief 完成整个分块上传。当使用 Upload Parts 上传完所有块以后,
/// 必须调用该 API 来完成整个文件的分块上传
Expand All @@ -162,7 +166,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult CompleteMultiUpload(const CompleteMultiUploadReq& req,
CompleteMultiUploadResp* resp);
CompleteMultiUploadResp* resp,
bool change_backup_domain = false);

/// \brief 异步多线程上传
/// \param request MultiUploadObject请求
Expand All @@ -172,7 +177,8 @@ class ObjectOp : public BaseOp {
/// \return result
CosResult MultiUploadObject(const PutObjectByFileReq& req,
MultiPutObjectResp* resp,
const SharedTransferHandler& handler = nullptr);
const SharedTransferHandler& handler = nullptr,
bool change_backup_domain = false);

/// \brief 舍弃一个分块上传并删除已上传的块
///
Expand All @@ -181,23 +187,24 @@ class ObjectOp : public BaseOp {
///
/// \return
CosResult AbortMultiUpload(const AbortMultiUploadReq& req,
AbortMultiUploadResp* resp);
AbortMultiUploadResp* resp,
bool change_backup_domain = false);

/// \brief 查询特定分块上传中的已上传的块
///
/// \param req ListParts请求
/// \param resp ListParts返回
///
/// \return result
CosResult ListParts(const ListPartsReq& req, ListPartsResp* resp);
CosResult ListParts(const ListPartsReq& req, ListPartsResp* resp, bool change_backup_domain = false);

/// \brief 列出Object下的ACL
///
/// \param req GetObjectACL请求
/// \param resp GetObjectACL返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult GetObjectACL(const GetObjectACLReq& req, GetObjectACLResp* resp);
CosResult GetObjectACL(const GetObjectACLReq& req, GetObjectACLResp* resp, bool change_backup_domain = false);

/// \brief 增加/替换Object下的ACL, 可以通过Header或者Body传入ACL信息
/// 注意Header 和 Body 只能选择其中一种,否则响应返回会冲突
Expand All @@ -206,7 +213,7 @@ class ObjectOp : public BaseOp {
/// \param resp PutObjectACL返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult PutObjectACL(const PutObjectACLReq& req, PutObjectACLResp* resp);
CosResult PutObjectACL(const PutObjectACLReq& req, PutObjectACLResp* resp, bool change_backup_domain = false);

/// \brief 已存在的Object设置标签.
///
Expand Down Expand Up @@ -241,7 +248,7 @@ class ObjectOp : public BaseOp {
/// \param resp PutObjectCopy返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult PutObjectCopy(const PutObjectCopyReq& req, PutObjectCopyResp* resp);
CosResult PutObjectCopy(const PutObjectCopyReq& req, PutObjectCopyResp* resp, bool change_backup_domain = false);

/// \brief 复制文件,实现将一个文件的分块内容从源路径复制到目标路径。
/// 通过指定 x-cos-copy-source 来指定源文件,x-cos-copy-source-range
Expand All @@ -251,7 +258,7 @@ class ObjectOp : public BaseOp {
/// \param response Copy返回
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult Copy(const CopyReq& req, CopyResp* resp);
CosResult Copy(const CopyReq& req, CopyResp* resp, bool change_backup_domain = false);

/// \brief 对一个通过 COS 归档为 archive 类型的对象进行恢复
///
Expand All @@ -260,14 +267,16 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult PostObjectRestore(const PostObjectRestoreReq& req,
PostObjectRestoreResp* resp);
PostObjectRestoreResp* resp,
bool change_backup_domain = false);

std::string GeneratePresignedUrl(const GeneratePresignedUrlReq& req);

CosResult OptionsObject(const OptionsObjectReq& req, OptionsObjectResp* resp);
CosResult OptionsObject(const OptionsObjectReq& req, OptionsObjectResp* resp, bool change_backup_domain = false);

CosResult SelectObjectContent(const SelectObjectContentReq& req,
SelectObjectContentResp* resp);
SelectObjectContentResp* resp,
bool change_backup_domain = false);

CosResult AppendObject(const AppendObjectReq& req, AppendObjectResp* resp);

Expand All @@ -278,7 +287,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult PutLiveChannel(const PutLiveChannelReq& req,
PutLiveChannelResp* resp);
PutLiveChannelResp* resp,
bool change_backup_domain = false);

/// \brief 启用或禁用通道
///
Expand All @@ -287,7 +297,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult PutLiveChannelSwitch(const PutLiveChannelSwitchReq& req,
PutLiveChannelSwitchResp* resp);
PutLiveChannelSwitchResp* resp,
bool change_backup_domain = false);

/// \brief 获取直播通道配置
///
Expand All @@ -296,7 +307,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult GetLiveChannel(const GetLiveChannelReq& req,
GetLiveChannelResp* resp);
GetLiveChannelResp* resp,
bool change_backup_domain = false);

/// \brief 获取直播通道推流历史
///
Expand All @@ -305,7 +317,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult GetLiveChannelHistory(const GetLiveChannelHistoryReq& req,
GetLiveChannelHistoryResp* resp);
GetLiveChannelHistoryResp* resp,
bool change_backup_domain = false);

/// \brief 获取直播通道推流状态
///
Expand All @@ -314,7 +327,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult GetLiveChannelStatus(const GetLiveChannelStatusReq& req,
GetLiveChannelStatusResp* resp);
GetLiveChannelStatusResp* resp,
bool change_backup_domain = false);

/// \brief 删除直播通
///
Expand All @@ -323,7 +337,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult DeleteLiveChannel(const DeleteLiveChannelReq& req,
DeleteLiveChannelResp* resp);
DeleteLiveChannelResp* resp,
bool change_backup_domain = false);

/// \brief 查询指定通道在指定时间段推流生成的播放列表
///
Expand All @@ -332,7 +347,8 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult GetLiveChannelVodPlaylist(const GetLiveChannelVodPlaylistReq& req,
GetLiveChannelVodPlaylistResp* resp);
GetLiveChannelVodPlaylistResp* resp,
bool change_backup_domain = false);

/// \brief 指定通道生成一个可供点播例用的播放列表
///
Expand All @@ -341,27 +357,31 @@ class ObjectOp : public BaseOp {
///
/// \return 返回HTTP请求的状态码及错误信息
CosResult PostLiveChannelVodPlaylist(const PostLiveChannelVodPlaylistReq& req,
PostLiveChannelVodPlaylistResp* resp);
PostLiveChannelVodPlaylistResp* resp,
bool change_backup_domain = false);

/// \brief 异步多线程下载,handler处理回调
CosResult MultiThreadDownload(const GetObjectByFileReq& req,
GetObjectByFileResp* resp,
const SharedTransferHandler& handler = nullptr);
const SharedTransferHandler& handler = nullptr,
bool change_backup_domain = false);

/* Resumable接口 */

/// \brief 支持断点下载
CosResult ResumableGetObject(const GetObjectByFileReq& req,
GetObjectByFileResp* resp,
const SharedTransferHandler& handler = nullptr);
const SharedTransferHandler& handler = nullptr,
bool change_backup_domain = false);

/*批量及目录操作接口*/
CosResult PutObjects(const PutObjectsByDirectoryReq& req,
PutObjectsByDirectoryResp* resp);
PutObjectsByDirectoryResp* resp,
bool change_backup_domain = false);

CosResult PutDirectory(const PutDirectoryReq& req, PutDirectoryResp* resp);
CosResult PutDirectory(const PutDirectoryReq& req, PutDirectoryResp* resp, bool change_backup_domain = false);

CosResult MoveObject(const MoveObjectReq& req);
CosResult MoveObject(const MoveObjectReq& req, bool change_backup_domain = false);

/*数据处理接口*/

Expand Down Expand Up @@ -404,7 +424,8 @@ class ObjectOp : public BaseOp {
const std::vector<std::string>& already_exist_parts,
bool resume_flag, std::vector<std::string>* etags_ptr,
std::vector<uint64_t>* part_numbers_ptr,
const SharedTransferHandler& handler = nullptr);
const SharedTransferHandler& handler = nullptr,
bool change_backup_domain = false);

/// \brief 读取文件内容, 并返回读取的长度
// uint64_t GetContent(const std::string& src, std::string* file_content) const;
Expand Down
1 change: 1 addition & 0 deletions include/trsf/transfer_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ enum class TransferStatus {
COMPLETED,
// Operation either failed or was canceled and a user deleted the multi-part
// upload .
RETRY,
ABORTED
};

Expand Down
Loading