initial commit
This commit is contained in:
@@ -0,0 +1,791 @@
|
||||
#ifndef COS_API_H
|
||||
#define COS_API_H
|
||||
|
||||
#include "op/bucket_op.h"
|
||||
#include "op/cos_result.h"
|
||||
#include "op/object_op.h"
|
||||
#include "op/service_op.h"
|
||||
#include "util/auth_tool.h"
|
||||
#include "util/codec_util.h"
|
||||
#include "trsf/transfer_handler.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class CosAPI {
|
||||
public:
|
||||
/// \brief CosAPI构造函数
|
||||
///
|
||||
/// \param config cos配置
|
||||
explicit CosAPI(CosConfig& config);
|
||||
|
||||
~CosAPI();
|
||||
|
||||
/// \brief 设置密钥
|
||||
void SetCredentail(const std::string& ak, const std::string& sk, const std::string& token);
|
||||
|
||||
/// \brief 获取 Bucket 所在的地域信息
|
||||
std::string GetBucketLocation(const std::string& bucket_name);
|
||||
|
||||
/// \brief 生成一个预签名链接
|
||||
std::string GeneratePresignedUrl(const GeneratePresignedUrlReq& request);
|
||||
|
||||
/// \brief 生成一个预签名链接
|
||||
std::string GeneratePresignedUrl(const std::string& bucket_name,
|
||||
const std::string& object_name,
|
||||
uint64_t start_time_in_s,
|
||||
uint64_t end_time_in_s,
|
||||
HTTP_METHOD http_method);
|
||||
|
||||
/// \brief 生成一个预签名的GET下载链接
|
||||
std::string GeneratePresignedUrl(const std::string& bucket_name,
|
||||
const std::string& object_name,
|
||||
uint64_t start_time_in_s,
|
||||
uint64_t end_time_in_s);
|
||||
|
||||
/// \brief 判断Bucket是否存在
|
||||
bool IsBucketExist(const std::string& bucket_name);
|
||||
|
||||
/// \brief 判断Object是否存在
|
||||
bool IsObjectExist(const std::string& bucket_name, const std::string& object_name);
|
||||
|
||||
/// \brief 创建一个Bucket
|
||||
/// 详见: https://cloud.tencent.com/document/api/436/8291
|
||||
///
|
||||
/// \param request GetService请求
|
||||
/// \param response GetService返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetService(const GetServiceReq& request, GetServiceResp* response);
|
||||
|
||||
/// \brief 创建一个Bucket
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7738
|
||||
///
|
||||
/// \param req PutBucket请求
|
||||
/// \param resp PutBucket返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucket(const PutBucketReq& request, PutBucketResp* response);
|
||||
|
||||
/// \brief 确认Bucket是否存在
|
||||
/// (详见:https://cloud.tencent.com/document/product/436/7735)
|
||||
///
|
||||
/// \param req HeadBucket请求
|
||||
/// \param resp HeadBucket返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult HeadBucket(const HeadBucketReq& request, HeadBucketResp* response);
|
||||
|
||||
/// \brief 列出该Bucket下的部分或者全部Object, 需要对Bucket有Read 权限
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7734
|
||||
///
|
||||
/// \param request GetBucket请求
|
||||
/// \param response GetBucket返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetBucket(const GetBucketReq& request, GetBucketResp* response);
|
||||
|
||||
CosResult ListMultipartUpload(const ListMultipartUploadReq& request,
|
||||
ListMultipartUploadResp* response);
|
||||
|
||||
/// \brief 删除Bucket
|
||||
/// 详见: https://cloud.tencent.com/document/product/436/7732
|
||||
///
|
||||
/// \param req DeleteBucket请求
|
||||
/// \param resp DeleteBucket返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucket(const DeleteBucketReq& request, DeleteBucketResp* response);
|
||||
|
||||
/// \brief 获得存储桶的版本控制信息
|
||||
/// (详见:https://cloud.tencent.com/document/product/436/8597)
|
||||
///
|
||||
/// \param req GetBucketVersioning请求
|
||||
/// \param resp GetBucketVersioning返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketVersioning(const GetBucketVersioningReq& req,
|
||||
GetBucketVersioningResp* resp);
|
||||
|
||||
/// \brief 启用或者暂停存储桶的版本控制功能
|
||||
/// (详见:https://cloud.tencent.com/document/product/436/8591)
|
||||
///
|
||||
/// \param req PutBucketVersioning请求
|
||||
/// \param resp PutBucketVersioning返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketVersioning(const PutBucketVersioningReq& req,
|
||||
PutBucketVersioningResp* resp);
|
||||
|
||||
/// \brief 列出Bucket下的跨域复制配置
|
||||
///
|
||||
/// \param req GetBucketReplication请求
|
||||
/// \param resp GetBucketReplication返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketReplication(const GetBucketReplicationReq& request,
|
||||
GetBucketReplicationResp* response);
|
||||
|
||||
/// \brief 增加/替换Bucket下的跨域复制配置
|
||||
///
|
||||
/// \param req PutBucketReplication请求
|
||||
/// \param resp PutBucketReplication返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketReplication(const PutBucketReplicationReq& request,
|
||||
PutBucketReplicationResp* response);
|
||||
|
||||
/// \brief 删除Bucket下的跨域复制配置
|
||||
///
|
||||
/// \param req DeleteBucketReplication请求
|
||||
/// \param resp DeleteBucketReplication返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketReplication(const DeleteBucketReplicationReq& request,
|
||||
DeleteBucketReplicationResp* response);
|
||||
|
||||
/// \brief 列出Bucket下的生命周期配置
|
||||
///
|
||||
/// \param req GetBucketLifecycle请求
|
||||
/// \param resp GetBucketLifecycle返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketLifecycle(const GetBucketLifecycleReq& request,
|
||||
GetBucketLifecycleResp* response);
|
||||
|
||||
/// \brief 增加/替换Bucket下的生命周期配置
|
||||
///
|
||||
/// \param req PutBucketLifecycle请求
|
||||
/// \param resp PutBucketLifecycle返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketLifecycle(const PutBucketLifecycleReq& request,
|
||||
PutBucketLifecycleResp* response);
|
||||
|
||||
/// \brief 删除Bucket下的生命周期配置
|
||||
///
|
||||
/// \param req DeleteBucketLifecycle请求
|
||||
/// \param resp DeleteBucketLifecycle返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketLifecycle(const DeleteBucketLifecycleReq& request,
|
||||
DeleteBucketLifecycleResp* response);
|
||||
|
||||
/// \brief 列出Bucket下的ACL
|
||||
///
|
||||
/// \param req GetBucketACL请求
|
||||
/// \param resp GetBucketACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketACL(const GetBucketACLReq& request,
|
||||
GetBucketACLResp* response);
|
||||
|
||||
/// \brief 增加/替换Bucket下的ACL, 可以通过Header或者Body传入ACL信息
|
||||
/// 注意Header 和 Body 只能选择其中一种,否则响应返回会冲突
|
||||
///
|
||||
/// \param req PutBucketACL请求
|
||||
/// \param resp PutBucketACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketACL(const PutBucketACLReq& request,
|
||||
PutBucketACLResp* response);
|
||||
|
||||
/// \brief 列出Bucket下的CORS
|
||||
///
|
||||
/// \param req GetBucketCORS请求
|
||||
/// \param resp GetBucketCORS返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketCORS(const GetBucketCORSReq& request,
|
||||
GetBucketCORSResp* response);
|
||||
|
||||
/// \brief 增加/替换Bucket下的CORS
|
||||
///
|
||||
/// \param req PutBucketCORS请求
|
||||
/// \param resp PutBucketCORS返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketCORS(const PutBucketCORSReq& request,
|
||||
PutBucketCORSResp* response);
|
||||
|
||||
/// \brief 删除Bucket下的CORS
|
||||
///
|
||||
/// \param req DeleteBucketCORS请求
|
||||
/// \param resp DeleteBucketCORS返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketCORS(const DeleteBucketCORSReq& request,
|
||||
DeleteBucketCORSResp* response);
|
||||
|
||||
/// \brief 获取对应Object的meta信息数据
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7745
|
||||
///
|
||||
/// \param request HeadObject请求
|
||||
/// \param response HeadObject返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult HeadObject(const HeadObjectReq& request, HeadObjectResp* response);
|
||||
|
||||
/// \brief 下载Bucket中的一个文件至流中
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7753
|
||||
///
|
||||
/// \param request GetObjectByStream请求
|
||||
/// \param response GetObjectByStream返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetObject(const GetObjectByStreamReq& request, GetObjectByStreamResp* response);
|
||||
|
||||
/// \brief 下载Bucket中的一个文件到本地
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7753
|
||||
///
|
||||
/// \param request GetObjectByFile请求
|
||||
/// \param response GetObjectByFile返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetObject(const GetObjectByFileReq& request, GetObjectByFileResp* response);
|
||||
|
||||
/// \brief 返回对象的URL
|
||||
///
|
||||
/// \param bucket 存储桶名
|
||||
/// \param object 对象名
|
||||
/// \param https 是否使用https
|
||||
/// \param region 地域名,默认使用配置文件中的地域名
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
std::string GetObjectUrl(const std::string& bucket, const std::string& object, bool https = true, const std::string& region = "");
|
||||
|
||||
/// \brief 将本地的文件上传至指定Bucket中
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7749
|
||||
///
|
||||
/// \param request PutObject请求
|
||||
/// \param response PutObject返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PutObject(const PutObjectByFileReq& request, PutObjectByFileResp* response);
|
||||
|
||||
/// \brief 将指定流上传至指定Bucket中
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7749
|
||||
///
|
||||
/// \param request PutObject请求
|
||||
/// \param response PutObject返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PutObject(const PutObjectByStreamReq& request, PutObjectByStreamResp* response);
|
||||
|
||||
/// \brief 删除Object
|
||||
/// 详见: https://cloud.tencent.com/document/product/436/7743
|
||||
///
|
||||
/// \param req DeleteObject请求
|
||||
/// \param resp DeleteObject返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteObject(const DeleteObjectReq& request, DeleteObjectResp* response);
|
||||
|
||||
/// \brief 批量删除Object
|
||||
///
|
||||
/// \param req DeleteObjects请求
|
||||
/// \param resp DeleteObjects返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteObjects(const DeleteObjectsReq& request, DeleteObjectsResp* response);
|
||||
|
||||
/// \brief 请求实现初始化分片上传,成功执行此请求以后会返回UploadId用于后续的Upload Part请求
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7746
|
||||
///
|
||||
/// \param request InitMultiUpload请求
|
||||
/// \param response InitMultiUpload返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult InitMultiUpload(const InitMultiUploadReq& request, InitMultiUploadResp* response);
|
||||
|
||||
/// \brief 初始化以后的分片上传,支持的分片的数量为1到10000,片的大小为1MB到5GB
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7750
|
||||
///
|
||||
/// \param request UploadPartData请求
|
||||
/// \param response UploadPartData返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult UploadPartData(const UploadPartDataReq& request, UploadPartDataResp* response);
|
||||
|
||||
/// \brief 初始化以后的分片上传复制,支持的片的数量为1到10000,片的大小为1MB到5GB
|
||||
/// 详见: https://cloud.tencent.com/document/product/436/8287
|
||||
///
|
||||
/// \param request UploadPartCopyData请求
|
||||
/// \param response UploadPartCopyData返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult UploadPartCopyData(const UploadPartCopyDataReq& request, UploadPartCopyDataResp* response);
|
||||
|
||||
/// \brief 完成整个分块上传。当使用 Upload Parts 上传完所有块以后,
|
||||
/// 必须调用该 API 来完成整个文件的分块上传
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7742
|
||||
///
|
||||
/// \param request CompleteMultiUpload请求
|
||||
/// \param response CompleteMultiUpload返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult CompleteMultiUpload(const CompleteMultiUploadReq& request,
|
||||
CompleteMultiUploadResp* response);
|
||||
|
||||
/// \brief 舍弃一个分块上传并删除已上传的块
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7740
|
||||
///
|
||||
/// \param request AbortMultiUpload请求
|
||||
/// \param response AbortMultiUpload返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult AbortMultiUpload(const AbortMultiUploadReq& request,
|
||||
AbortMultiUploadResp* response);
|
||||
|
||||
/// \brief 查询特定分块上传中的已上传的块
|
||||
///
|
||||
/// \param req ListParts请求
|
||||
/// \param resp ListParts返回
|
||||
///
|
||||
/// \return
|
||||
CosResult ListParts(const ListPartsReq& request, ListPartsResp* response);
|
||||
|
||||
/// \brief 列出Object下的ACL
|
||||
///
|
||||
/// \param req GetObjectACL请求
|
||||
/// \param resp GetObjectACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetObjectACL(const GetObjectACLReq& request,
|
||||
GetObjectACLResp* response);
|
||||
|
||||
/// \brief 增加/替换Object下的ACL, 可以通过Header或者Body传入ACL信息
|
||||
/// 注意Header 和 Body 只能选择其中一种,否则响应返回会冲突
|
||||
///
|
||||
/// \param req PutObjectACL请求
|
||||
/// \param resp PutObjectACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutObjectACL(const PutObjectACLReq& request,
|
||||
PutObjectACLResp* response);
|
||||
|
||||
/// \brief 复制Object, 适用于跨园区且Object小于5G
|
||||
///
|
||||
/// \param req PutObjectCopy请求
|
||||
/// \param resp PutObjectCopy返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutObjectCopy(const PutObjectCopyReq& request,
|
||||
PutObjectCopyResp* response);
|
||||
|
||||
/// \brief 复制Object, 自动判断源Object大小,调用PutObjectCopy/UploadPartCopyData
|
||||
///
|
||||
/// \param req Copy请求
|
||||
/// \param resp Copy返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult Copy(const CopyReq& request, CopyResp* response);
|
||||
|
||||
/// \brief 对一个通过 COS 归档为 archive 类型的对象进行恢复
|
||||
///
|
||||
/// \param request PostObjectRestore请求
|
||||
/// \param response PostObjectRestore返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PostObjectRestore(const PostObjectRestoreReq& request,
|
||||
PostObjectRestoreResp* response);
|
||||
|
||||
/// \brief 实现Object跨域访问请求的预请求,参考https://cloud.tencent.com/document/product/436/8288
|
||||
///
|
||||
/// \param req OptionsObjectReq 请求
|
||||
/// \param resp OptionsObjectResp 响应
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult OptionsObject(const OptionsObjectReq& request,
|
||||
OptionsObjectResp* response);
|
||||
|
||||
/// \brief 支持SELECT 接口,参考https://cloud.tencent.com/document/product/436/37641
|
||||
CosResult SelectObjectContent(const SelectObjectContentReq& request,
|
||||
SelectObjectContentResp* response);
|
||||
|
||||
/// \brief 列出Bucket下的部分或者全部Object(包括多版本)
|
||||
///
|
||||
/// \param req GetBucketObjectVersions请求
|
||||
/// \param resp GetBucketObjectVersions返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketObjectVersions(const GetBucketObjectVersionsReq& request,
|
||||
GetBucketObjectVersionsResp* response);
|
||||
|
||||
/// \brief 设置源存储桶的日志配置信息。
|
||||
///
|
||||
/// \param req PutBucketLogging请求
|
||||
/// \param resp PutBucketLogging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
|
||||
CosResult PutBucketLogging(const PutBucketLoggingReq& request,
|
||||
PutBucketLoggingResp* response);
|
||||
|
||||
/// \brief 获取源存储桶的日志配置信息。
|
||||
///
|
||||
/// \param req GetBucketLogging请求
|
||||
/// \param resp GetBucketLogging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketLogging(const GetBucketLoggingReq& request,
|
||||
GetBucketLoggingResp* response);
|
||||
|
||||
|
||||
/// \brief 设置存储桶自定义域名。
|
||||
///
|
||||
/// \param req PutBucketDomain请求
|
||||
/// \param resp PutBucketDomain返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketDomain(const PutBucketDomainReq& request,
|
||||
PutBucketDomainResp* response);
|
||||
|
||||
|
||||
/// \brief 获取存储桶自定义域名。
|
||||
///
|
||||
/// \param req GetBucketDomain请求
|
||||
/// \param resp GetBucketDomain返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketDomain(const GetBucketDomainReq& request,
|
||||
GetBucketDomainResp* response);
|
||||
|
||||
|
||||
/// \brief 为存储桶配置静态网站,可以通过传入 XML 格式的配置文件进行配置,文件大小限制为64KB.
|
||||
///
|
||||
/// \param req PutBucketWebsite请求
|
||||
/// \param resp PutBucketWebsite返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketWebsite(const PutBucketWebsiteReq& request,
|
||||
PutBucketWebsiteResp* response);
|
||||
|
||||
/// \brief 请求用于获取与存储桶关联的静态网站配置信息.
|
||||
///
|
||||
/// \param req GetBucketWebsite请求
|
||||
/// \param resp GetBucketWebsite返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketWebsite(const GetBucketWebsiteReq& request,
|
||||
GetBucketWebsiteResp* response);
|
||||
|
||||
/// \brief 删除存储桶中的静态网站配置.
|
||||
///
|
||||
/// \param req DeleteBucketWebsite请求
|
||||
/// \param resp DeleteBucketWebsite返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketWebsite(const DeleteBucketWebsiteReq& request,
|
||||
DeleteBucketWebsiteResp* response);
|
||||
|
||||
|
||||
/// \brief 已存在的Bucket设置标签.
|
||||
///
|
||||
/// \param req PutBucketTagging请求
|
||||
/// \param resp PutBucketTagging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketTagging(const PutBucketTaggingReq& request,
|
||||
PutBucketTaggingResp* response);
|
||||
|
||||
|
||||
/// \brief 查询指定存储桶下已有的存储桶标签.
|
||||
///
|
||||
/// \param req GetBucketTagging请求
|
||||
/// \param resp GetBucketTagging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketTagging(const GetBucketTaggingReq& request,
|
||||
GetBucketTaggingResp* response);
|
||||
|
||||
|
||||
/// \brief 删除指定存储桶下已有的存储桶标签.
|
||||
///
|
||||
/// \param req DeleteBucketTagging请求
|
||||
/// \param resp DeleteBucketTagging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketTagging(const DeleteBucketTaggingReq& request,
|
||||
DeleteBucketTaggingResp* response);
|
||||
|
||||
|
||||
/// \brief 在存储桶中创建清单任务.
|
||||
///
|
||||
/// \param req PutBucketInventory请求
|
||||
/// \param resp PutBucketInventory返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketInventory(const PutBucketInventoryReq& request,
|
||||
PutBucketInventoryResp* response);
|
||||
|
||||
/// \brief 用于查询存储桶中用户的清单任务信息.
|
||||
///
|
||||
/// \param req GetBucketInventory请求
|
||||
/// \param resp GetBucketInventory返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketInventory(const GetBucketInventoryReq& request,
|
||||
GetBucketInventoryResp* response);
|
||||
|
||||
/// \brief 用于请求返回一个存储桶中的所有清单任务.
|
||||
///
|
||||
/// \param req ListBucketInventoryConfigurations请求
|
||||
/// \param resp ListBucketInventoryConfigurations返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult ListBucketInventoryConfigurations(const ListBucketInventoryConfigurationsReq& request,
|
||||
ListBucketInventoryConfigurationsResp* response);
|
||||
|
||||
/// \brief 用于删除存储桶中指定的清单任务.
|
||||
///
|
||||
/// \param req DeleteBucketinventory请求
|
||||
/// \param resp DeleteBucketinventory返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketInventory(const DeleteBucketInventoryReq& request,
|
||||
DeleteBucketInventoryResp* response);
|
||||
|
||||
/// \brief 创建推流通道
|
||||
///
|
||||
/// \param req PutLiveChannelReq请求
|
||||
/// \param resp PutLiveChannelResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutLiveChannel(const PutLiveChannelReq& request,
|
||||
PutLiveChannelResp* response);
|
||||
|
||||
/// \brief 生成推流通道带签名的推流url
|
||||
///
|
||||
/// \param bucket 存储桶名称
|
||||
/// \param channel 通道名
|
||||
/// \param expire 签名过期时间
|
||||
/// \param url_params url参数
|
||||
///
|
||||
/// \return 带签名的推流url
|
||||
std::string GetRtmpSignedPublishUrl(const std::string& bucket, const std::string& channel,
|
||||
int expire, const std::map<std::string, std::string> url_params);
|
||||
|
||||
/// \brief 启用或者禁用直播通道
|
||||
///
|
||||
/// \param req PutLiveChannelSwitchReq请求
|
||||
/// \param resp PutLiveChannelSwitchResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutLiveChannelSwitch(const PutLiveChannelSwitchReq& request,
|
||||
PutLiveChannelSwitchResp* response);
|
||||
|
||||
/// \brief 获取直播通道配置信息
|
||||
///
|
||||
/// \param req GetLiveChannelReq请求
|
||||
/// \param resp GetLiveChannelResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetLiveChannel(const GetLiveChannelReq& request,
|
||||
GetLiveChannelResp* response);
|
||||
|
||||
/// \brief 获取直播通道推流历史
|
||||
///
|
||||
/// \param req GetLiveChannelHistoryReq请求
|
||||
/// \param resp GetLiveChannelHistoryResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetLiveChannelHistory(const GetLiveChannelHistoryReq& request,
|
||||
GetLiveChannelHistoryResp* response);
|
||||
|
||||
/// \brief 获取直播通道推流状态
|
||||
///
|
||||
/// \param req GetLiveChannelStatusReq请求
|
||||
/// \param resp GetLiveChannelStatusResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetLiveChannelStatus(const GetLiveChannelStatusReq& request,
|
||||
GetLiveChannelStatusResp* response);
|
||||
|
||||
/// \brief 删除直播通道
|
||||
///
|
||||
/// \param req GetLiveChannelStatusReq请求
|
||||
/// \param resp GetLiveChannelStatusResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteLiveChannel(const DeleteLiveChannelReq& request,
|
||||
DeleteLiveChannelResp* response);
|
||||
|
||||
/// \brief 查询指定通道在指定时间段推流生成的播放列表
|
||||
///
|
||||
/// \param req GetLiveChannelVodPlaylistReq请求
|
||||
/// \param resp GetLiveChannelVodPlaylistResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetLiveChannelVodPlaylist(const GetLiveChannelVodPlaylistReq& request,
|
||||
GetLiveChannelVodPlaylistResp* response);
|
||||
|
||||
/// \brief 为指定通道生成一个可供点播例用的播放列
|
||||
///
|
||||
/// \param req PostLiveChannelVodPlaylistReq请求
|
||||
/// \param resp PostLiveChannelVodPlaylistResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PostLiveChannelVodPlaylist(const PostLiveChannelVodPlaylistReq& request,
|
||||
PostLiveChannelVodPlaylistResp* response);
|
||||
|
||||
/// \brief 列举通道
|
||||
///
|
||||
/// \param req PostLiveChannelVodPlaylistReq请求
|
||||
/// \param resp PostLiveChannelVodPlaylistResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult ListLiveChannel(const ListLiveChannelReq& request,
|
||||
ListLiveChannelResp* response);
|
||||
|
||||
/// \brief 配置存储桶智能分层
|
||||
///
|
||||
/// \param req PutBucketIntelligentTiering请求
|
||||
/// \param resp PutBucketIntelligentTiering返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketIntelligentTiering(const PutBucketIntelligentTieringReq& request,
|
||||
PutBucketIntelligentTieringResp* response);
|
||||
|
||||
/// \brief 获取存储桶智能分层配置
|
||||
///
|
||||
/// \param req GetBucketIntelligentTiering请求
|
||||
/// \param resp GetBucketIntelligentTiering返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketIntelligentTiering(const GetBucketIntelligentTieringReq& request,
|
||||
GetBucketIntelligentTieringResp* response);
|
||||
|
||||
/*Multithread接口*/
|
||||
|
||||
/// \brief 封装了初始化分块上传、分块上传、完成分块上传三步,支持断点续传
|
||||
///
|
||||
/// \param request MultiUploadObject请求
|
||||
/// \param response MultiUploadObject返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult MultiUploadObject(const MultiUploadObjectReq& request,
|
||||
MultiUploadObjectResp* response);
|
||||
|
||||
/// \brief 多线程Range下载Bucket中的一个文件到本地
|
||||
/// 详见: https://www.qcloud.com/document/product/436/7753
|
||||
///
|
||||
/// \param request MultiGetObject请求
|
||||
/// \param response MultiGetObject返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetObject(const MultiGetObjectReq& request, MultiGetObjectResp* response);
|
||||
|
||||
/*Resumable接口*/
|
||||
|
||||
/// \brief 封装了初始化分块上传、分块上传、完成分块上传三步,支持断点续传
|
||||
// CosResult ResumablePutObject(const MultiUploadObjectReq& request, MultiUploadObjectResp* response);
|
||||
|
||||
/// \brief 支持断点下载
|
||||
CosResult ResumableGetObject(const MultiGetObjectReq& request, MultiGetObjectResp* response);
|
||||
|
||||
/*Async接口*/
|
||||
|
||||
/// \brief 异步上传对象,封装了初始化分块上传、分块上传、完成分块上传三步,支持断点续传
|
||||
/// \param request MultiUploadObject请求
|
||||
/// \param response MultiUploadObject返回
|
||||
/// \return 返回handler
|
||||
SharedTransferHandler PutObjectAsync(const MultiUploadObjectReq& request,
|
||||
MultiUploadObjectResp* response);
|
||||
|
||||
/// \brief 异步多线程下载对象,支持更新下载进度
|
||||
/// \param request MultiGetObject请求
|
||||
/// \param response MultiGetObject返回
|
||||
/// \return 返回handler
|
||||
SharedTransferHandler GetObjectAsync(const MultiGetObjectReq& request,
|
||||
MultiGetObjectResp* response);
|
||||
|
||||
/*批量及目录操作接口*/
|
||||
|
||||
/// \brief 批量上传对象
|
||||
/// \param request PutObjectsByDirectory请求
|
||||
/// \param response PutObjectByDirectoryResp返回
|
||||
/// \return 批量上传结果
|
||||
CosResult PutObjects(const PutObjectsByDirectoryReq& request, PutObjectsByDirectoryResp* response);
|
||||
|
||||
/// \brief 创建目录
|
||||
/// \param request PutObjectsByDirectory请求
|
||||
/// \param response PutObjectByDirectoryResp返回
|
||||
/// \return 创建目录结果
|
||||
CosResult PutDirectory(const PutDirectoryReq& request, PutDirectoryResp* response);
|
||||
|
||||
/// \brief 移动对象
|
||||
/// \param request MoveObjectReq请求
|
||||
/// \param response MoveObjectResp返回
|
||||
/// \return 移动对象结果
|
||||
CosResult MoveObject(const MoveObjectReq& request, MoveObjectResp* response);
|
||||
|
||||
/// \brief 按前缀删除Object
|
||||
/// \param req DeleteObjectsByPrefixReq请求
|
||||
/// \param resp DeleteObjectsByPrefixResp返回
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteObjects(const DeleteObjectsByPrefixReq& request, DeleteObjectsByPrefixResp* response);
|
||||
|
||||
/*数据处理接口*/
|
||||
|
||||
/**基础图片处理**/
|
||||
|
||||
/**图片持久化处理**/
|
||||
|
||||
/***上传时处理***/
|
||||
CosResult PutImage(const PutImageByFileReq& request, PutImageByFileResp* response);
|
||||
|
||||
/***云上数据处理***/
|
||||
CosResult CloudImageProcess(const CloudImageProcessReq& request, CloudImageProcessResp* response);
|
||||
|
||||
/***下载图片时识别二维码***/
|
||||
CosResult GetQRcode(const GetQRcodeReq& request, GetQRcodeResp* response);
|
||||
|
||||
|
||||
/*文档处理接口*/
|
||||
|
||||
/**查询已经开通文档预览功能的 Bucket**/
|
||||
// https://cloud.tencent.com/document/product/436/54057
|
||||
CosResult DescribeDocProcessBuckets(const DescribeDocProcessBucketsReq& request, DescribeDocProcessBucketsResp *response);
|
||||
|
||||
/**预览文档**/
|
||||
// https://cloud.tencent.com/document/product/436/54058
|
||||
CosResult DocPreview(const DocPreviewReq& request, DocPreviewResp *response);
|
||||
|
||||
/**提交一个文档预览任务**/
|
||||
// https://cloud.tencent.com/document/product/436/54056
|
||||
CosResult CreateDocProcessJobs(const CreateDocProcessJobsReq& request, CreateDocProcessJobsResp *response);
|
||||
|
||||
/**查询指定的文档预览任务**/
|
||||
// https://cloud.tencent.com/document/product/436/54095
|
||||
CosResult DescribeDocProcessJob(const DescribeDocProcessJobReq& request, DescribeDocProcessJobResp *response);
|
||||
|
||||
/**拉取符合条件的文档预览任务**/
|
||||
// https://cloud.tencent.com/document/product/436/54096
|
||||
CosResult DescribeDocProcessJobs(const DescribeDocProcessJobsReq& request, DescribeDocProcessJobsResp *response);
|
||||
|
||||
/**查询文档预览队列**/
|
||||
// https://cloud.tencent.com/document/product/436/54055
|
||||
CosResult DescribeDocProcessQueues(const DescribeDocProcessQueuesReq& request, DescribeDocProcessQueuesResp *response);
|
||||
|
||||
/**更新文档预览队列**/
|
||||
// https://cloud.tencent.com/document/product/436/54094
|
||||
CosResult UpdateDocProcessQueue(const UpdateDocProcessQueueReq& request, UpdateDocProcessQueueResp *response);
|
||||
|
||||
private:
|
||||
int CosInit();
|
||||
void CosUInit();
|
||||
|
||||
private:
|
||||
// Be careful with the m_config order
|
||||
SharedConfig m_config;
|
||||
ObjectOp m_object_op; // 内部封装object相关的操作
|
||||
BucketOp m_bucket_op; // 内部封装bucket相关的操作
|
||||
ServiceOp m_service_op; // 内部封装service相关的操作
|
||||
|
||||
static bool s_init;
|
||||
static bool s_poco_init;
|
||||
static int s_cos_obj_num;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif
|
||||
@@ -0,0 +1,151 @@
|
||||
#ifndef COS_CONFIG_H
|
||||
#define COS_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "util/log_util.h"
|
||||
|
||||
#include "Poco/JSON/Parser.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
class CosConfig{
|
||||
public:
|
||||
/// \brief CosConfig构造函数
|
||||
///
|
||||
/// \param config_file 配置文件所在路径
|
||||
explicit CosConfig(const std::string& config_file);
|
||||
|
||||
/// \brief CosConfig构造函数
|
||||
CosConfig() : m_app_id(0), m_access_key(""), m_secret_key(""), m_region(""), m_tmp_token(""), m_config_parsed(false) {}
|
||||
|
||||
/// \brief CosConfig构造函数
|
||||
///
|
||||
/// \param appid 开发者访问 COS 服务时拥有的用户维度唯一资源标识,用以标识资源
|
||||
/// \param access_key 开发者拥有的项目身份识别 ID,用以身份认证
|
||||
/// \param secret_key 开发者拥有的项目身份密钥
|
||||
CosConfig(uint64_t appid,
|
||||
const std::string& access_key,
|
||||
const std::string& secret_key,
|
||||
const std::string& region)
|
||||
: m_app_id(appid), m_access_key(access_key),
|
||||
m_secret_key(secret_key), m_region(region), m_tmp_token(""), m_config_parsed(false) {}
|
||||
|
||||
/// \brief CosConfig构造函数
|
||||
///
|
||||
/// \param appid 开发者访问 COS 服务时拥有的用户维度唯一资源标识,用以标识资源
|
||||
/// \param access_key 开发者拥有的项目身份识别 ID,用以身份认证
|
||||
/// \param secret_key 开发者拥有的项目身份密钥
|
||||
CosConfig(uint64_t appid,
|
||||
const std::string& access_key,
|
||||
const std::string& secret_key,
|
||||
const std::string& region,
|
||||
const std::string& tmp_token)
|
||||
: m_app_id(appid), m_access_key(access_key),
|
||||
m_secret_key(secret_key), m_region(region), m_tmp_token(tmp_token), m_config_parsed(false) {}
|
||||
|
||||
/// \brief CosConfig复制构造函数
|
||||
///
|
||||
/// \param config
|
||||
CosConfig(const CosConfig& config) {
|
||||
m_app_id = config.m_app_id;
|
||||
m_access_key = config.m_access_key;
|
||||
m_secret_key = config.m_secret_key;
|
||||
m_region = config.m_region;
|
||||
m_tmp_token = config.m_tmp_token;
|
||||
m_config_parsed = config.m_config_parsed;
|
||||
}
|
||||
|
||||
/// \brief CosConfig赋值构造函数
|
||||
///
|
||||
/// \param config
|
||||
CosConfig& operator=(const CosConfig& config) {
|
||||
m_app_id = config.m_app_id;
|
||||
m_access_key = config.m_access_key;
|
||||
m_secret_key = config.m_secret_key;
|
||||
m_region = config.m_region;
|
||||
m_tmp_token = config.m_tmp_token;
|
||||
m_config_parsed = config.m_config_parsed;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// \brief 根据配置文件进行初始化
|
||||
///
|
||||
/// \param config_file 配置文件所在路径
|
||||
///
|
||||
/// \return 初始化成功则返回true,否则返回false
|
||||
bool InitConf(const std::string& config_file);
|
||||
|
||||
/// \brief 获取AppID
|
||||
///
|
||||
/// \return appid
|
||||
uint64_t GetAppId() const;
|
||||
|
||||
/// \brief 获取AccessKey
|
||||
///
|
||||
/// \return access_key
|
||||
std::string GetAccessKey() const;
|
||||
|
||||
/// \brief 获取SecretKey
|
||||
///
|
||||
/// \return secret_key
|
||||
std::string GetSecretKey() const;
|
||||
|
||||
/// \brief 操作的Region
|
||||
/// region的有效值参见https://cloud.tencent.com/document/product/436/6224
|
||||
///
|
||||
/// \return region
|
||||
std::string GetRegion() const;
|
||||
|
||||
/// \brief 获取临时密钥
|
||||
std::string GetTmpToken() const;
|
||||
|
||||
/// \brief 设置AppID
|
||||
void SetAppId(uint64_t app_id) { m_app_id = app_id; }
|
||||
|
||||
/// \brief 设置AccessKey
|
||||
void SetAccessKey(const std::string& access_key) { m_access_key = access_key; }
|
||||
|
||||
/// \brief 设置SecreteKey
|
||||
void SetSecretKey(const std::string& secret_key) { m_secret_key = secret_key; }
|
||||
|
||||
/// \brief 设置操作的Region
|
||||
/// region的有效值参见https://cloud.tencent.com/document/product/436/6224
|
||||
void SetRegion(const std::string& region) { m_region = region; }
|
||||
|
||||
/// \brief 设置临时密钥
|
||||
void SetTmpToken(const std::string& tmp_token) { m_tmp_token = tmp_token; }
|
||||
|
||||
/// \brief 更新临时密钥
|
||||
void SetConfigCredentail(const std::string& access_key, const std::string& secret_key, const std::string& tmp_token);
|
||||
|
||||
/// \brief 设置是否使用自定义ip和端口号
|
||||
void SetIsUseIntranetAddr(bool is_use_intranet);
|
||||
|
||||
/// \berief 设置自定义ip和端口号
|
||||
void SetIntranetAddr(const std::string& intranet_addr);
|
||||
|
||||
/// \brief 设置日志回调
|
||||
void SetLogCallback(const LogCallback log_callback);
|
||||
|
||||
static bool JsonObjectGetStringValue(const Poco::JSON::Object::Ptr& json_object,
|
||||
const std::string& key, std::string *value);
|
||||
static bool JsonObjectGetIntegerValue(const Poco::JSON::Object::Ptr& json_object,
|
||||
const std::string& key, uint64_t *value);
|
||||
static bool JsonObjectGetBoolValue(const Poco::JSON::Object::Ptr& json_object,
|
||||
const std::string& key, bool *value);
|
||||
private:
|
||||
mutable std::mutex m_lock;
|
||||
uint64_t m_app_id;
|
||||
std::string m_access_key;
|
||||
std::string m_secret_key;
|
||||
std::string m_region;
|
||||
std::string m_tmp_token;
|
||||
bool m_config_parsed;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<CosConfig> SharedConfig;
|
||||
} // namespace qcloud_cos
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,149 @@
|
||||
#ifndef COS_PARAMS_H
|
||||
#define COS_PARAMS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace qcloud_cos{
|
||||
|
||||
/// http header中的Authorization字段
|
||||
const std::string kHttpHeaderAuthorization = "Authorization";
|
||||
|
||||
const std::string kParaCustomHeaders = "custom_headers";
|
||||
const std::string kParaCacheControl = "Cache-Control";
|
||||
const std::string kParaContentType = "Content-Type";
|
||||
const std::string kParaContentLength = "Content-Length";
|
||||
const std::string kParaContentDisposition = "Content-Disposition";
|
||||
const std::string kParaContentLanguage = "Content-Language";
|
||||
const std::string kParaContentEncoding = "Content-Encoding";
|
||||
const std::string kParaXCosMetaPrefix = "x-cos-meta-";
|
||||
|
||||
const std::string kParaMoveDstFileid = "dest_fileid";
|
||||
const std::string kParaMoveOverWrite = "to_over_write";
|
||||
|
||||
const std::string kParaListNum = "num";
|
||||
const std::string kParaListFlag = "list_flag";
|
||||
const std::string kParaListContext = "context";
|
||||
|
||||
const std::string kParaErrorDesc = "parameter error";
|
||||
const std::string kNetworkErrorDesc = "network error";
|
||||
const std::string kLocalFileNotExistDesc = "local file not exist";
|
||||
const std::string kParaPathIleagel = "path ileagel error";
|
||||
const std::string kCanNotOpRootPath = "can not operator root folder";
|
||||
|
||||
// x-cos-meta-前缀
|
||||
const std::string kXCosMetaPrefix = "x-cos-meta-";
|
||||
|
||||
// Request Header
|
||||
const std::string kReqHeaderEtag = "ETag";
|
||||
const std::string kReqHeaderLowerCaseEtag = "Etag";
|
||||
const std::string kReqHeaderContentLen = "Content-Length";
|
||||
const std::string kReqHeaderContentType = "Content-Type";
|
||||
const std::string kReqHeaderConnection = "Connection";
|
||||
const std::string kReqHeaderDate = "Date";
|
||||
const std::string kReqHeaderServer = "Server";
|
||||
const std::string kReqHeaderXCosReqId = "x-cos-request-id";
|
||||
const std::string kReqHeaderXCosTraceId = "x-cos-trace-id";
|
||||
|
||||
// Response Header
|
||||
const std::string kRespHeaderLastModified = "Last-Modified";
|
||||
const std::string kRespHeaderXCosObjectType = "x-cos-object-type";
|
||||
const std::string kRespHeaderXCosStorageClass = "x-cos-storage-class";
|
||||
const std::string kRespHeaderXCosHashCrc64Ecma = "x-cos-hash-crc64ecma";
|
||||
|
||||
// doc preive response header
|
||||
const std::string kRespHeaderXTotalPage = "X-Total-Page";
|
||||
const std::string kRespHeaderXErrNo = "X-ErrNo";
|
||||
const std::string kRespHeaderXTotalSheet = "X-Total-Sheet";
|
||||
const std::string kRespHeaderXSheetName = "X-Sheet-Name";
|
||||
|
||||
|
||||
// V5 返回错误信息的xml node名
|
||||
const std::string kErrorRoot = "Error";
|
||||
const std::string kErrorCode = "Code";
|
||||
const std::string kErrorMessage = "Message";
|
||||
const std::string kErrorResource = "Resource";
|
||||
const std::string kErrorTraceId = "TraceId";
|
||||
const std::string kErrorRequestId = "RequestId";
|
||||
const std::string kErrorServerTime = "ServerTime";
|
||||
|
||||
// GetBucketResponse XML node
|
||||
const std::string kGetBucketRoot = "ListBucketResult";
|
||||
const std::string kGetBucketName = "Name";
|
||||
const std::string kGetBucketDelimiter = "Delimiter";
|
||||
const std::string kGetBucketEncodingType = "EncodingType";
|
||||
const std::string kGetBucketNextMarker = "NextMarker";
|
||||
const std::string kGetBucketPrefix = "Prefix";
|
||||
const std::string kGetBucketMarker = "Marker";
|
||||
const std::string kGetBucketMaxKeys = "MaxKeys";
|
||||
const std::string kGetBucketIsTruncated = "IsTruncated";
|
||||
const std::string kGetBucketCommonPrefixes = "CommonPrefixes";
|
||||
const std::string kGetBucketContents = "Contents";
|
||||
const std::string kGetBucketContentsKey = "Key";
|
||||
const std::string kGetBucketContentsLastModified = "LastModified";
|
||||
const std::string kGetBucketContentsETag = "ETag";
|
||||
const std::string kGetBucketContentsSize = "Size";
|
||||
const std::string kGetBucketContentsStorageClass = "StorageClass";
|
||||
const std::string kGetBucketContentsOwner = "Owner";
|
||||
const std::string kGetBucketContentsOwnerID = "ID";
|
||||
|
||||
// ListMultipartUpload XML node
|
||||
const std::string kListMultipartUploadRoot = "ListMultipartUploadsResult";
|
||||
const std::string kListMultipartUploadBucket = "Bucket";
|
||||
const std::string kListMultipartUploadMarker = "KeyMarker";
|
||||
const std::string kListMultipartUploadIdMarker = "UploadIdMarker";
|
||||
const std::string kListMultipartUploadNextKeyMarker = "NextKeyMarker";
|
||||
const std::string kListMultipartUploadNextUploadIdMarker = "NextUploadIdMarker";
|
||||
const std::string kListMultipartUploadMaxUploads = "MaxUploads";
|
||||
const std::string kListMultipartUploadUpload = "Upload";
|
||||
const std::string kListMultipartUploadKey = "Key";
|
||||
const std::string kListMultipartUploadId = "UploadId";
|
||||
const std::string kListMultipartUploadStorageClass = "StorageClass";
|
||||
const std::string kListMultipartUploadInitiator = "Initiator";
|
||||
const std::string kListMultipartUploadOwner = "Owner";
|
||||
const std::string kListMultipartUploadInitiated = "Initiated";
|
||||
const std::string kListMultipartUploadID = "ID";
|
||||
const std::string kListMultipartUploadDisplayName = "DisplayName";
|
||||
|
||||
// BucketReplicationResponse XML node
|
||||
const std::string kBucketReplicationRoot = "ReplicationConfiguration";
|
||||
const std::string kBucketReplicationRule = "Rule";
|
||||
const std::string kBucketReplicationID = "ID";
|
||||
const std::string kBucketReplicationRole = "Role";
|
||||
const std::string kBucketReplicationPrefix = "Prefix";
|
||||
const std::string kBucketReplicationStatus = "Status";
|
||||
const std::string kBucketReplicationDestination = "Destination";
|
||||
const std::string kBucketReplicationBucket = "Bucket";
|
||||
const std::string kBucketReplicationStorageClass = "StorageClass";
|
||||
|
||||
// InitMultiUploadResp XML node
|
||||
const std::string kInitiateMultipartUploadRoot = "InitiateMultipartUploadResult";
|
||||
const std::string kInitiateMultipartUploadBucket = "Bucket";
|
||||
const std::string kInitiateMultipartUploadKey = "Key";
|
||||
const std::string kInitiateMultipartUploadId = "UploadId";
|
||||
|
||||
// CompleteMultiUploadResp XML node
|
||||
const std::string kCompleteMultiUploadRoot = "CompleteMultipartUploadResult";
|
||||
const std::string kCompleteMultiUploadLocation = "Location";
|
||||
const std::string kCompleteMultiUploadBucket = "Bucket";
|
||||
const std::string kCompleteMultiUploadKey = "Key";
|
||||
const std::string kCompleteMultiUploadETag = "ETag";
|
||||
|
||||
// StorageClass
|
||||
const std::string kStorageClassStandard = "STANDARD";
|
||||
const std::string kStorageClassStandardIA = "STANDARD_IA";
|
||||
const std::string kStorageClassMAZStandard = "MAZ_STANDARD";
|
||||
const std::string kStorageClassMAZStandardIA = "MAZ_STANDARD_IA";
|
||||
const std::string kStorageClassIntelligentTiering = "INTELLIGENT_TIERING";
|
||||
const std::string kStorageClassArchive = "ARCHIVE";
|
||||
const std::string kStorageClassDeepArchive = "DEEP_ARCHIVE";
|
||||
|
||||
// Resumable download
|
||||
const std::string kResumableDownloadTaskFileSuffix = ".cosresumabletask";
|
||||
const std::string kResumableDownloadFileName = "fileName";
|
||||
const std::string kResumableDownloadTaskLastModified = "lastModified";
|
||||
const std::string kResumableDownloadTaskContentLength = "contentLength";
|
||||
const std::string kResumableDownloadTaskEtag = "eTag";
|
||||
const std::string kResumableDownloadTaskCrc64ecma = "crc64ecma";
|
||||
const std::string kResumableDownloadResumeOffset = "resumeOffset";
|
||||
} // namespace qcloud_cos
|
||||
#endif
|
||||
@@ -0,0 +1,179 @@
|
||||
#ifndef COS_SYS_CONF_H
|
||||
#define COS_SYS_CONF_H
|
||||
#include <stdint.h>
|
||||
|
||||
#include "cos_defines.h"
|
||||
#include "util/log_util.h"
|
||||
|
||||
namespace qcloud_cos{
|
||||
|
||||
class CosSysConfig {
|
||||
public:
|
||||
/// \brief 设置签名超时时间,单位:秒
|
||||
static void SetAuthExpiredTime(uint64_t time);
|
||||
|
||||
/// \brief 设置本地时间与网络时间差值
|
||||
static void SetTimeStampDelta(int64_t dela);
|
||||
|
||||
/// \brief 设置连接超时时间,单位:毫秒
|
||||
static void SetConnTimeoutInms(uint64_t time);
|
||||
|
||||
/// \brief 设置接收超时时间,单位:毫秒
|
||||
static void SetRecvTimeoutInms(uint64_t time);
|
||||
|
||||
/// \brief 设置上传分片大小,单位:字节,默认:10M
|
||||
static void SetUploadPartSize(uint64_t part_size);
|
||||
|
||||
/// \brief 获取上传复制分片大小,单位:字节,默认: 20M
|
||||
static void SetUploadCopyPartSize(uint64_t part_size);
|
||||
|
||||
/// \brief 设置文件分片并发上传线程池大小,默认: 5
|
||||
static void SetUploadThreadPoolSize(unsigned size);
|
||||
|
||||
/// \brief 设置异步上传下载线程池大小,默认: 2
|
||||
static void SetAsynThreadPoolSize(unsigned size);
|
||||
|
||||
/// \brief 设置log输出,1:屏幕,2:syslog,3:不输出,默认:1
|
||||
static void SetLogOutType(LOG_OUT_TYPE log);
|
||||
|
||||
/// \brief 设置log输出等级,COS_LOG_ERR/WRAN/INFO/DBG
|
||||
static void SetLogLevel(LOG_LEVEL level);
|
||||
|
||||
/// \brief 设置下载线程池的大小
|
||||
static void SetDownThreadPoolSize(unsigned size);
|
||||
|
||||
/// \brief 设置下载分片的大小
|
||||
static void SetDownSliceSize(unsigned slice_size);
|
||||
|
||||
/// \brief 设置长连接的参数
|
||||
static void SetKeepAlive(bool keepalive);
|
||||
|
||||
/// \brief 设置长连接的参数
|
||||
static void SetKeepIdle(int64_t keepidle);
|
||||
|
||||
/// \brief 设置长连接的参数
|
||||
static void SetKeepIntvl(int64_t keepintvl);
|
||||
|
||||
static void SetDestDomain(const std::string& dest_domain);
|
||||
|
||||
/// \brief 获取签名超时时间,单位秒
|
||||
static uint64_t GetAuthExpiredTime();
|
||||
|
||||
/// \brief 获取本地时间与网络时间差值
|
||||
static int64_t GetTimeStampDelta();
|
||||
|
||||
/// \brief 获取连接超时时间,单位:毫秒
|
||||
static uint64_t GetConnTimeoutInms();
|
||||
|
||||
/// \brief 获取接收超时时间,单位:毫秒
|
||||
static uint64_t GetRecvTimeoutInms();
|
||||
|
||||
/// \brief 获取上传分片大小,单位:字节
|
||||
static uint64_t GetUploadPartSize();
|
||||
|
||||
/// \brief 获取上传复制分片大小,单位:字节
|
||||
static uint64_t GetUploadCopyPartSize();
|
||||
|
||||
/// \brief 获取上传线程池大小
|
||||
static unsigned GetUploadThreadPoolSize();
|
||||
|
||||
/// \brief 获取异步线程池大小
|
||||
static unsigned GetAsynThreadPoolSize();
|
||||
|
||||
/// \brief 获取日志输出类型,默认输出到屏幕
|
||||
static int GetLogOutType();
|
||||
|
||||
/// \brief 获取日志输出等级
|
||||
static int GetLogLevel();
|
||||
|
||||
/// \brief 打印CosSysConfig的配置详情
|
||||
static void PrintValue();
|
||||
|
||||
/// \brief 获取下载分片大小
|
||||
static unsigned GetDownSliceSize();
|
||||
|
||||
/// \brief 获取下载线程池大小
|
||||
static unsigned GetDownThreadPoolSize();
|
||||
|
||||
/// \brief 获取keepalive参数
|
||||
static bool GetKeepAlive();
|
||||
static int64_t GetKeepIdle();
|
||||
static int64_t GetKeepIntvl();
|
||||
|
||||
/// \brief 下载过程中是否检查MD5
|
||||
static bool IsCheckMd5();
|
||||
|
||||
/// \brief 设置下载过程中检查MD5
|
||||
static void SetCheckMd5(bool is_check_md5);
|
||||
|
||||
static bool IsDomainSameToHost();
|
||||
|
||||
static void SetDomainSameToHost(bool is_domain_same_to_host);
|
||||
|
||||
/// \brief 根据传入appid、region、bucket_name返回对应的hostname
|
||||
static std::string GetHost(uint64_t app_id, const std::string& region,
|
||||
const std::string& bucket_name);
|
||||
|
||||
static std::string GetDestDomain();
|
||||
|
||||
/// \brief 获取是否使用特定ip和端口号
|
||||
static bool IsUseIntranet();
|
||||
|
||||
static void SetIsUseIntranet(bool is_use_interanet);
|
||||
|
||||
static void SetIntranetAddr(const std::string& intranet_addr);
|
||||
|
||||
/// \brief 获取特定ip和端口号
|
||||
static std::string GetIntranetAddr();
|
||||
|
||||
/// \brief 日志回调
|
||||
static LogCallback GetLogCallback();
|
||||
|
||||
static void SetLogCallback(const LogCallback log_callback);
|
||||
private:
|
||||
// 打印日志:0,不打印,1:打印到屏幕,2:打印到syslog
|
||||
static LOG_OUT_TYPE m_log_outtype;
|
||||
// 日志级别:1: ERR, 2: WARN, 3:INFO, 4:DBG
|
||||
static LOG_LEVEL m_log_level;
|
||||
// 上传分片大小
|
||||
static uint64_t m_upload_part_size;
|
||||
// 上传分片大小
|
||||
static uint64_t m_upload_copy_part_size;
|
||||
// 本地时间戳与网络时间服务器时间戳的差值,计算方法:
|
||||
// delta = network_ts - local_ts
|
||||
static int64_t m_timestamp_delta;
|
||||
// 签名超时时间(秒)
|
||||
static uint64_t m_sign_expire_in_s;
|
||||
// Http连接超时时间(毫秒)
|
||||
static uint64_t m_conn_timeout_in_ms;
|
||||
// Http接收超时时间(毫秒)
|
||||
static uint64_t m_recv_timeout_in_ms;
|
||||
// 单文件分片并发上传线程池大小(每个文件一个)
|
||||
static unsigned m_threadpool_size;
|
||||
// 异步上传下载线程池大小(全局就一个)
|
||||
static unsigned m_asyn_threadpool_size;
|
||||
// 下载文件到本地线程池大小
|
||||
static unsigned m_down_thread_pool_size;
|
||||
// 下载文件到本地,每次下载字节数
|
||||
static unsigned m_down_slice_size;
|
||||
// 是否开启长连接
|
||||
static bool m_keep_alive;
|
||||
// 空闲多久后,发送keepalive探针,单位s
|
||||
static int64_t m_keep_idle;
|
||||
// 每个keepalive探针时间间隔,单位s
|
||||
static int64_t m_keep_intvl;
|
||||
// 下载时是否检查md5
|
||||
static bool m_is_check_md5;
|
||||
|
||||
static std::string m_dest_domain;
|
||||
|
||||
static bool m_is_domain_same_to_host;
|
||||
|
||||
static bool m_is_use_intranet;
|
||||
|
||||
static std::string m_intranet_addr;
|
||||
// 日志回调
|
||||
static LogCallback m_log_callback;
|
||||
};
|
||||
} // namespace qcloud_cos
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
#ifndef BASE_OP_H
|
||||
#define BASE_OP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "cos_config.h"
|
||||
#include "op/cos_result.h"
|
||||
|
||||
namespace qcloud_cos{
|
||||
|
||||
class BaseReq;
|
||||
class BaseResp;
|
||||
|
||||
class BaseOp {
|
||||
public:
|
||||
/// \brief BaseOp构造函数
|
||||
///
|
||||
/// \param cos_conf Cos配置
|
||||
explicit BaseOp(const SharedConfig& cos_conf)
|
||||
: m_config(cos_conf) {
|
||||
}
|
||||
|
||||
BaseOp() {}
|
||||
|
||||
/// \brief BaseOp析构函数
|
||||
~BaseOp() {}
|
||||
|
||||
/// \brief 获取Cos配置
|
||||
CosConfig GetCosConfig() const;
|
||||
|
||||
/// \brief 获取AppID
|
||||
uint64_t GetAppId() const;
|
||||
|
||||
/// \brief 获取AccessKey
|
||||
std::string GetAccessKey() const;
|
||||
|
||||
/// \brief 获取SecretKey
|
||||
std::string GetSecretKey() const;
|
||||
|
||||
/// \brief 获取Token
|
||||
std::string GetTmpToken() const;
|
||||
|
||||
/// \brief 封装了cos Service/Bucket/Object 相关接口的通用操作,
|
||||
/// 包括签名计算、请求发送、返回内容解析等
|
||||
///
|
||||
/// \param host 目标主机, 以http://开头
|
||||
/// \param path http path
|
||||
/// \param req http请求
|
||||
/// \param req_body http request的body
|
||||
/// \param resp http返回
|
||||
///
|
||||
/// \return http调用情况(状态码等)
|
||||
CosResult NormalAction(const std::string& host,
|
||||
const std::string& path,
|
||||
const BaseReq& req,
|
||||
const std::string& req_body,
|
||||
bool check_body,
|
||||
BaseResp* resp);
|
||||
|
||||
/// \brief 封装了cos Service/Bucket/Object相关接口的通用操作,
|
||||
/// 包括签名计算、请求发送、返回内容解析等
|
||||
///
|
||||
/// \param host 目标主机, 以http://开头
|
||||
/// \param path http path
|
||||
/// \param req http请求
|
||||
/// \param additional_headers http请求需要所需的额外header
|
||||
/// \param additional_params http请求需要所需的额外params
|
||||
/// \param req_body http request的body
|
||||
/// \param resp http返回
|
||||
///
|
||||
/// \return http调用情况(状态码等)
|
||||
CosResult NormalAction(const std::string& host,
|
||||
const std::string& path,
|
||||
const BaseReq& req,
|
||||
const std::map<std::string, std::string>& additional_headers,
|
||||
const std::map<std::string, std::string>& additional_params,
|
||||
const std::string& req_body,
|
||||
bool check_body,
|
||||
BaseResp* resp);
|
||||
|
||||
/// \brief 下载文件并输出到流中
|
||||
///
|
||||
/// \param host 目标主机, 以http://开头
|
||||
/// \param path http path
|
||||
/// \param req http请求
|
||||
/// \param resp http返回
|
||||
/// \param os 输出流
|
||||
///
|
||||
/// \return http调用情况(状态码等)
|
||||
CosResult DownloadAction(const std::string& host,
|
||||
const std::string& path,
|
||||
const BaseReq& req,
|
||||
BaseResp* resp,
|
||||
std::ostream& os);
|
||||
|
||||
/// \brief 支持从stream中读入数据并上传
|
||||
///
|
||||
/// \param host 目标主机, 以http://开头
|
||||
/// \param path http path
|
||||
/// \param req http请求
|
||||
/// \param additional_headers http请求需要所需的额外header
|
||||
/// \param additional_params http请求需要所需的额外params
|
||||
/// \param is http request的body
|
||||
/// \param resp http返回
|
||||
///
|
||||
/// \return http调用情况(状态码等)
|
||||
CosResult UploadAction(const std::string& host,
|
||||
const std::string& path,
|
||||
const BaseReq& req,
|
||||
const std::map<std::string, std::string>& additional_headers,
|
||||
const std::map<std::string, std::string>& additional_params,
|
||||
std::istream& is,
|
||||
BaseResp* resp);
|
||||
|
||||
std::string GetRealUrl(const std::string& host,
|
||||
const std::string& path,
|
||||
bool is_https);
|
||||
|
||||
|
||||
protected:
|
||||
SharedConfig m_config;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif
|
||||
@@ -0,0 +1,380 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/13/17
|
||||
// Description:
|
||||
|
||||
#ifndef BUCKETOP_H
|
||||
#define BUCKETOP_H
|
||||
#pragma once
|
||||
|
||||
#include "cos_sys_config.h"
|
||||
#include "op/base_op.h"
|
||||
#include "op/cos_result.h"
|
||||
#include "request/bucket_req.h"
|
||||
#include "response/bucket_resp.h"
|
||||
#include "request/data_process_req.h"
|
||||
#include "response/data_process_resp.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
/// \brief 封装了Bucket相关的操作
|
||||
class BucketOp : public BaseOp {
|
||||
public:
|
||||
/// \brief BucketOp构造函数
|
||||
///
|
||||
/// \param cos_conf Cos配置
|
||||
explicit BucketOp(const SharedConfig& config) : BaseOp(config) {}
|
||||
|
||||
/// \brief BucketOp析构函数
|
||||
virtual ~BucketOp() {}
|
||||
|
||||
/// \brief 判断bucket是否存在
|
||||
bool IsBucketExist(const std::string& bucket_name);
|
||||
|
||||
/// \brief 获取Bucket所在Location
|
||||
std::string GetBucketLocation(const std::string& bucket_name);
|
||||
|
||||
/// \brief 创建一个Bucket
|
||||
/// (详见:https://www.qcloud.com/document/product/436/7738)
|
||||
///
|
||||
/// \param req PutBucket请求
|
||||
/// \param resp PutBucket返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucket(const PutBucketReq& req, PutBucketResp* resp);
|
||||
|
||||
/// \brief 确认Bucket是否存在
|
||||
/// (详见:https://cloud.tencent.com/document/product/436/7735)
|
||||
///
|
||||
/// \param req HeadBucket请求
|
||||
/// \param resp HeadBucket返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult HeadBucket(const HeadBucketReq& req, HeadBucketResp* resp);
|
||||
|
||||
/// \brief 列出Bucket下的部分或者全部Object
|
||||
/// (详见:https://www.qcloud.com/document/product/436/7734)
|
||||
///
|
||||
/// \param req GetBucket请求
|
||||
/// \param resp GetBucket返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucket(const GetBucketReq& req, GetBucketResp* resp);
|
||||
|
||||
CosResult ListMultipartUpload(const ListMultipartUploadReq& req, ListMultipartUploadResp* resp);
|
||||
/// \brief 删除Bucket
|
||||
///
|
||||
/// \param req DeleteBucket请求
|
||||
/// \param resp DeleteBucket返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucket(const DeleteBucketReq& req, DeleteBucketResp* resp);
|
||||
|
||||
/// \brief 获得存储桶的版本控制信息
|
||||
/// (详见:https://cloud.tencent.com/document/product/436/8597)
|
||||
///
|
||||
/// \param req GetBucketVersioning请求
|
||||
/// \param resp GetBucketVersioning返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketVersioning(const GetBucketVersioningReq& req,
|
||||
GetBucketVersioningResp* resp);
|
||||
|
||||
/// \brief 启用或者暂停存储桶的版本控制功能
|
||||
/// (详见:https://cloud.tencent.com/document/product/436/8591)
|
||||
///
|
||||
/// \param req PutBucketVersioning请求
|
||||
/// \param resp PutBucketVersioning返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketVersioning(const PutBucketVersioningReq& req,
|
||||
PutBucketVersioningResp* resp);
|
||||
|
||||
/// \brief 列出Bucket下的跨域复制配置
|
||||
///
|
||||
/// \param req GetBucketReplication请求
|
||||
/// \param resp GetBucketReplication返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketReplication(const GetBucketReplicationReq& req,
|
||||
GetBucketReplicationResp* resp);
|
||||
|
||||
/// \brief 增加/替换Bucket下的跨域复制配置
|
||||
///
|
||||
/// \param req PutBucketReplication请求
|
||||
/// \param resp PutBucketReplication返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketReplication(const PutBucketReplicationReq& req,
|
||||
PutBucketReplicationResp* resp);
|
||||
|
||||
/// \brief 删除Bucket下的跨域复制配置
|
||||
///
|
||||
/// \param req DeleteBucketReplication请求
|
||||
/// \param resp DeleteBucketReplication返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketReplication(const DeleteBucketReplicationReq& req,
|
||||
DeleteBucketReplicationResp* resp);
|
||||
|
||||
/// \brief 列出Bucket下的生命周期配置
|
||||
///
|
||||
/// \param req GetBucketLifecycle请求
|
||||
/// \param resp GetBucketLifecycle返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketLifecycle(const GetBucketLifecycleReq& req,
|
||||
GetBucketLifecycleResp* resp);
|
||||
|
||||
/// \brief 增加/替换Bucket下的生命周期配置
|
||||
///
|
||||
/// \param req PutBucketLifecycle请求
|
||||
/// \param resp PutBucketLifecycle返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketLifecycle(const PutBucketLifecycleReq& req,
|
||||
PutBucketLifecycleResp* resp);
|
||||
|
||||
/// \brief 删除Bucket下的生命周期配置
|
||||
///
|
||||
/// \param req DeleteBucketLifecycle请求
|
||||
/// \param resp DeleteBucketLifecycle返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketLifecycle(const DeleteBucketLifecycleReq& req,
|
||||
DeleteBucketLifecycleResp* resp);
|
||||
|
||||
/// \brief 列出Bucket下的ACL
|
||||
///
|
||||
/// \param req GetBucketACL请求
|
||||
/// \param resp GetBucketACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketACL(const GetBucketACLReq& req,
|
||||
GetBucketACLResp* resp);
|
||||
|
||||
/// \brief 增加/替换Bucket下的ACL, 可以通过Header或者Body传入ACL信息
|
||||
/// 注意Header 和 Body 只能选择其中一种,否则响应返回会冲突
|
||||
///
|
||||
/// \param req PutBucketACL请求
|
||||
/// \param resp PutBucketACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketACL(const PutBucketACLReq& req,
|
||||
PutBucketACLResp* resp);
|
||||
|
||||
/// \brief 列出Bucket下的CORS
|
||||
///
|
||||
/// \param req GetBucketCORS请求
|
||||
/// \param resp GetBucketCORS返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketCORS(const GetBucketCORSReq& req,
|
||||
GetBucketCORSResp* resp);
|
||||
|
||||
/// \brief 增加/替换Bucket下的CORS
|
||||
///
|
||||
/// \param req PutBucketCORS请求
|
||||
/// \param resp PutBucketCORS返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketCORS(const PutBucketCORSReq& req,
|
||||
PutBucketCORSResp* resp);
|
||||
|
||||
/// \brief 删除Bucket下的CORS
|
||||
///
|
||||
/// \param req DeleteBucketCORS请求
|
||||
/// \param resp DeleteBucketCORS返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketCORS(const DeleteBucketCORSReq& req,
|
||||
DeleteBucketCORSResp* resp);
|
||||
|
||||
/// \brief 列出Bucket下的部分或者全部Object(包括多版本)
|
||||
///
|
||||
/// \param req GetBucketObjectVersions请求
|
||||
/// \param resp GetBucketObjectVersions返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketObjectVersions(const GetBucketObjectVersionsReq& req,
|
||||
GetBucketObjectVersionsResp* resp);
|
||||
|
||||
/// \brief 获取Bucket所在Location
|
||||
///
|
||||
/// \param req GetBucketLocation请求
|
||||
/// \param resp GetBucketLocation返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketLocation(const GetBucketLocationReq& req,
|
||||
GetBucketLocationResp* resp);
|
||||
// TODO(sevenyou)
|
||||
// std::string ListMultipartUploads();
|
||||
|
||||
|
||||
/// \brief 为源存储桶开启日志记录
|
||||
/// \brief https://cloud.tencent.com/document/product/436/17054
|
||||
/// \param req PutBucketLogging请求
|
||||
/// \param resp PutBucketLogging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketLogging(const PutBucketLoggingReq& req,
|
||||
PutBucketLoggingResp* resp);
|
||||
|
||||
/// \brief 用于获取源存储桶的日志配置信息
|
||||
/// \brief https://cloud.tencent.com/document/product/436/17053
|
||||
/// \param req GetBucketLogging请求
|
||||
/// \param resp GetBucketLogging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketLogging(const GetBucketLoggingReq& req,
|
||||
GetBucketLoggingResp* resp);
|
||||
|
||||
/// \brief 用于存储桶绑定自定义域名
|
||||
/// \brief
|
||||
/// \param req PutBucketDomain请求
|
||||
/// \param resp PutBucketDomain返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketDomain(const PutBucketDomainReq& req,
|
||||
PutBucketDomainResp* resp);
|
||||
|
||||
/// \brief 用于获取存储桶绑定自定义域名
|
||||
/// \brief
|
||||
/// \param req GetBucketDomain请求
|
||||
/// \param resp GetBucketDomain返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketDomain(const GetBucketDomainReq& req,
|
||||
GetBucketDomainResp* resp);
|
||||
|
||||
/// \brief 存储桶配置静态网站,通过传入 XML 格式的配置文件进行配置,文件大小限制为64KB
|
||||
/// \brief https://cloud.tencent.com/document/product/436/31930
|
||||
/// \param req PutBucketWebsite请求
|
||||
/// \param resp PutBucketWebsite返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketWebsite(const PutBucketWebsiteReq& req,
|
||||
PutBucketWebsiteResp* resp);
|
||||
|
||||
/// \brief 获取与存储桶关联的静态网站配置信息.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/31929
|
||||
/// \param req GetBucketWebsite请求
|
||||
/// \param resp GetBucketWebsite返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketWebsite(const GetBucketWebsiteReq& req,
|
||||
GetBucketWebsiteResp* resp);
|
||||
|
||||
/// \brief 删除存储桶中的静态网站配置.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/31928
|
||||
/// \param req DeleteBucketWebsite请求
|
||||
/// \param resp DeleteBucketWebsite返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketWebsite(const DeleteBucketWebsiteReq& req,
|
||||
DeleteBucketWebsiteResp* resp);
|
||||
|
||||
/// \brief 为已存在的Bucket设置标签.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/34838
|
||||
/// \param req PutBucketTagging请求
|
||||
/// \param resp PutBucketTagging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketTagging(const PutBucketTaggingReq& req,
|
||||
PutBucketTaggingResp* resp);
|
||||
|
||||
|
||||
/// \brief 查询指定存储桶下已有的存储桶标签.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/34837
|
||||
/// \param req GetBucketTagging请求
|
||||
/// \param resp GetBucketTagging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketTagging(const GetBucketTaggingReq& req,
|
||||
GetBucketTaggingResp* resp);
|
||||
|
||||
/// \brief 删除指定存储桶下已有的存储桶标签.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/34836
|
||||
/// \param req DeleteBucketTagging请求
|
||||
/// \param resp DeleteBucketTagging返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketTagging(const DeleteBucketTaggingReq& req,
|
||||
DeleteBucketTaggingResp* resp);
|
||||
|
||||
/// \brief 用于在存储桶中创建清单任务.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/33707
|
||||
/// \param req PutBucketinventory请求
|
||||
/// \param resp PutBucketinventory返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketInventory(const PutBucketInventoryReq& req,
|
||||
PutBucketInventoryResp* resp);
|
||||
|
||||
/// \brief 查询存储桶中用户的清单任务信息.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/33705
|
||||
/// \param req GetBucketinventory请求
|
||||
/// \param resp GetBucketinventory返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketInventory(const GetBucketInventoryReq& req,
|
||||
GetBucketInventoryResp* resp);
|
||||
|
||||
/// \brief 请求返回一个存储桶中的所有清单任务.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/33706
|
||||
/// \param req ListBucketInventoryConfigurations请求
|
||||
/// \param resp ListBucketInventoryConfigurations返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult ListBucketInventoryConfigurations(const ListBucketInventoryConfigurationsReq& req,
|
||||
ListBucketInventoryConfigurationsResp* resp);
|
||||
|
||||
/// \brief 用于删除存储桶中指定的清单任务.
|
||||
/// \brief https://cloud.tencent.com/document/product/436/33704
|
||||
/// \param req DeleteBucketinventory请求
|
||||
/// \param resp DeleteBucketinventory返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteBucketInventory(const DeleteBucketInventoryReq& req,
|
||||
DeleteBucketInventoryResp* resp);
|
||||
|
||||
/// \brief 列举直播通道
|
||||
/// \param req ListLiveChannelReq请求
|
||||
/// \param resp ListLiveChannelResp返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult ListLiveChannel(const ListLiveChannelReq& req, ListLiveChannelResp* resp);
|
||||
|
||||
/// \brief 配置存储桶智能分层
|
||||
///
|
||||
/// \param req PutBucketIntelligentTiering请求
|
||||
/// \param resp PutBucketIntelligentTiering返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutBucketIntelligentTiering(const PutBucketIntelligentTieringReq& req,
|
||||
PutBucketIntelligentTieringResp* resp);
|
||||
|
||||
/// \brief 获取存储桶智能分层配置
|
||||
///
|
||||
/// \param req GetBucketIntelligentTiering请求
|
||||
/// \param resp GetBucketIntelligentTiering返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetBucketIntelligentTiering(const GetBucketIntelligentTieringReq& req,
|
||||
GetBucketIntelligentTieringResp* resp);
|
||||
|
||||
CosResult CreateDocProcessJobs(const CreateDocProcessJobsReq& req, CreateDocProcessJobsResp* resp);
|
||||
|
||||
CosResult DescribeDocProcessJob(const DescribeDocProcessJobReq& req, DescribeDocProcessJobResp* resp);
|
||||
|
||||
CosResult DescribeDocProcessJobs(const DescribeDocProcessJobsReq& req, DescribeDocProcessJobsResp* resp);
|
||||
|
||||
CosResult DescribeDocProcessQueues(const DescribeDocProcessQueuesReq& req, DescribeDocProcessQueuesResp* resp);
|
||||
|
||||
CosResult UpdateDocProcessQueue(const UpdateDocProcessQueueReq& req, UpdateDocProcessQueueResp* resp);
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // BUCKETOP_H
|
||||
@@ -0,0 +1,131 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/25/17
|
||||
// Description:
|
||||
|
||||
#ifndef COS_RESULT_H
|
||||
#define COS_RESULT_H
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
// 封装HTTP状态码:3XX,4XX,5XX 的返回结果
|
||||
// 详见官网链接: https://www.qcloud.com/document/product/436/7730
|
||||
class CosResult {
|
||||
public:
|
||||
CosResult()
|
||||
: m_is_succ(false), m_http_status(-1), m_error_info(""), m_err_code(""),
|
||||
m_err_msg(""), m_resource_addr(""), m_x_cos_request_id(""), m_x_cos_trace_id("") {}
|
||||
|
||||
~CosResult() {}
|
||||
|
||||
CosResult(const CosResult& other) {
|
||||
m_is_succ = other.m_is_succ;
|
||||
m_http_status = other.m_http_status;
|
||||
m_error_info = other.m_error_info;
|
||||
m_err_code = other.m_err_code;
|
||||
m_err_msg = other.m_err_msg;
|
||||
m_resource_addr = other.m_resource_addr;
|
||||
m_x_cos_request_id = other.m_x_cos_request_id;
|
||||
m_x_cos_trace_id = other.m_x_cos_trace_id;
|
||||
m_real_byte = other.m_real_byte;
|
||||
}
|
||||
|
||||
CosResult& operator=(const CosResult& other) {
|
||||
if (this != &other) {
|
||||
m_is_succ = other.m_is_succ;
|
||||
m_http_status = other.m_http_status;
|
||||
m_error_info = other.m_error_info;
|
||||
m_err_code = other.m_err_code;
|
||||
m_err_msg = other.m_err_msg;
|
||||
m_resource_addr = other.m_resource_addr;
|
||||
m_x_cos_request_id = other.m_x_cos_request_id;
|
||||
m_x_cos_trace_id = other.m_x_cos_trace_id;
|
||||
m_real_byte = other.m_real_byte;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool IsSucc() const { return m_is_succ; }
|
||||
void SetSucc() { m_is_succ = true; }
|
||||
void SetFail() { m_is_succ = false; }
|
||||
void Clear() {
|
||||
m_is_succ = false;
|
||||
m_http_status = -1;
|
||||
m_error_info = "";
|
||||
m_err_code = "";
|
||||
m_err_msg = "";
|
||||
m_resource_addr = "";
|
||||
m_x_cos_request_id = "";
|
||||
m_x_cos_trace_id = "";
|
||||
}
|
||||
|
||||
// 解析xml string
|
||||
bool ParseFromHttpResponse(const std::map<std::string, std::string>& headers,
|
||||
const std::string& body);
|
||||
|
||||
// Getter
|
||||
std::string GetErrorInfo() const { return m_error_info; }
|
||||
int GetHttpStatus() const { return m_http_status; }
|
||||
std::string GetErrorCode() const { return m_err_code; }
|
||||
std::string GetErrorMsg() const { return m_err_msg; }
|
||||
std::string GetResourceAddr() const { return m_resource_addr; }
|
||||
std::string GetXCosRequestId() const { return m_x_cos_request_id; }
|
||||
std::string GetXCosTraceId() const { return m_x_cos_trace_id; }
|
||||
std::string GetXCosServerTime() const { return m_x_cos_server_time; }
|
||||
uint64_t GetRealByte() const { return m_real_byte; }
|
||||
|
||||
// Setter
|
||||
void SetErrorInfo(const std::string& result) { m_error_info = result; }
|
||||
void SetHttpStatus(int http_status) { m_http_status = http_status; }
|
||||
void SetErrorCode(const std::string& err_code) { m_err_code = err_code; }
|
||||
void SetErrorMsg(const std::string& err_msg) { m_err_msg = err_msg; }
|
||||
void SetResourceAddr(const std::string& resource_addr) {
|
||||
m_resource_addr = resource_addr;
|
||||
}
|
||||
void SetXCosRequestId(const std::string& x_cos_request_id) {
|
||||
m_x_cos_request_id = x_cos_request_id;
|
||||
}
|
||||
void SetXCosTraceId(const std::string& x_cos_trace_id) {
|
||||
m_x_cos_trace_id = x_cos_trace_id;
|
||||
}
|
||||
|
||||
void SetRealByte(uint64_t real_byte) {
|
||||
m_real_byte = real_byte;
|
||||
}
|
||||
/// \brief 输出Result的具体信息
|
||||
std::string DebugString() const;
|
||||
|
||||
std::string GetInitMpRequestId() const {
|
||||
return m_init_mp_request_id;
|
||||
}
|
||||
void SetInitMpRequestId(const std::string& request_id) {
|
||||
m_init_mp_request_id = request_id;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_is_succ; // 标识HTTP调用是否成功
|
||||
|
||||
int m_http_status; // http状态码
|
||||
std::string m_error_info; // 错误的具体信息, 存放sdk内部错误/调用失败时无法解析的返回信息
|
||||
|
||||
// COS返回的错误信息
|
||||
std::string m_err_code;
|
||||
std::string m_err_msg;
|
||||
std::string m_resource_addr;
|
||||
std::string m_x_cos_request_id;
|
||||
std::string m_x_cos_trace_id;
|
||||
std::string m_x_cos_server_time;
|
||||
uint64_t m_real_byte;
|
||||
// MultiUploadObject接口中封装了init mp/upload part/complete,该成员保存init mp的request id
|
||||
// 如果是断点续传,则该reqeust id为空
|
||||
std::string m_init_mp_request_id;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // COS_RESULT_H
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Runnable.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class FileCopyTask : public Poco::Runnable {
|
||||
public:
|
||||
FileCopyTask(const std::string& full_url,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms);
|
||||
|
||||
~FileCopyTask() {}
|
||||
|
||||
void run();
|
||||
|
||||
void CopyTask();
|
||||
|
||||
bool IsTaskSuccess() const;
|
||||
|
||||
int GetHttpStatus() const ;
|
||||
|
||||
std::string GetTaskResp() const;
|
||||
|
||||
std::map<std::string, std::string> GetRespHeaders() const;
|
||||
|
||||
void SetParams(const std::map<std::string, std::string>& params);
|
||||
|
||||
void SetHeaders(const std::map<std::string, std::string>& headers);
|
||||
|
||||
std::string GetErrMsg() const { return m_err_msg; }
|
||||
|
||||
std::string GetEtag() const { return m_etag; }
|
||||
|
||||
std::string GetLastModified() const { return m_last_modified; }
|
||||
|
||||
private:
|
||||
std::string m_full_url;
|
||||
std::map<std::string, std::string> m_headers;
|
||||
std::map<std::string, std::string> m_params;
|
||||
uint64_t m_conn_timeout_in_ms;
|
||||
uint64_t m_recv_timeout_in_ms;
|
||||
std::string m_resp;
|
||||
bool m_is_task_success;
|
||||
int m_http_status;
|
||||
std::map<std::string, std::string> m_resp_headers;
|
||||
std::string m_err_msg;
|
||||
std::string m_etag;
|
||||
std::string m_last_modified;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/25/17
|
||||
// Description:
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "trsf/transfer_handler.h"
|
||||
#include "cos_config.h"
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Runnable.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class FileDownTask : public Poco::Runnable {
|
||||
public:
|
||||
FileDownTask(const std::string& full_url,
|
||||
const std::map<std::string, std::string>& headers,
|
||||
const std::map<std::string, std::string>& params,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
const SharedTransferHandler& handler = nullptr,
|
||||
uint64_t offset = 0,
|
||||
unsigned char* pbuf = NULL,
|
||||
const size_t data_len = 0);
|
||||
|
||||
~FileDownTask() {}
|
||||
|
||||
void run();
|
||||
|
||||
void DownTask();
|
||||
|
||||
void SetDownParams(unsigned char* pdatabuf, size_t datalen, uint64_t offset);
|
||||
|
||||
std::string GetTaskResp();
|
||||
|
||||
size_t GetDownLoadLen();
|
||||
|
||||
bool IsTaskSuccess();
|
||||
|
||||
int GetHttpStatus();
|
||||
|
||||
std::map<std::string, std::string> GetRespHeaders();
|
||||
|
||||
std::string GetErrMsg() const { return m_err_msg; }
|
||||
|
||||
private:
|
||||
std::string m_full_url;
|
||||
std::map<std::string, std::string> m_headers;
|
||||
std::map<std::string, std::string> m_params;
|
||||
uint64_t m_conn_timeout_in_ms;
|
||||
uint64_t m_recv_timeout_in_ms;
|
||||
SharedTransferHandler m_handler;
|
||||
uint64_t m_offset;
|
||||
unsigned char* m_data_buf_ptr;
|
||||
size_t m_data_len;
|
||||
std::string m_resp;
|
||||
bool m_is_task_success;
|
||||
size_t m_real_down_len;
|
||||
int m_http_status;
|
||||
std::map<std::string, std::string> m_resp_headers;
|
||||
std::string m_err_msg;
|
||||
|
||||
SharedConfig m_config;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "request/object_req.h"
|
||||
#include "trsf/transfer_handler.h"
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Runnable.h"
|
||||
|
||||
namespace qcloud_cos{
|
||||
|
||||
class FileUploadTask : public Poco::Runnable {
|
||||
public:
|
||||
FileUploadTask(const std::string& full_url,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
unsigned char* pbuf = NULL,
|
||||
const size_t data_len = 0);
|
||||
|
||||
FileUploadTask(const std::string& full_url,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
const SharedTransferHandler& handler);
|
||||
|
||||
FileUploadTask(const std::string& full_url,
|
||||
const std::map<std::string, std::string>& headers,
|
||||
const std::map<std::string, std::string>& params,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
unsigned char* pbuf = NULL,
|
||||
const size_t data_len = 0);
|
||||
|
||||
~FileUploadTask() {}
|
||||
|
||||
void run();
|
||||
|
||||
void UploadTask();
|
||||
|
||||
void SetUploadBuf(unsigned char* pdatabuf, size_t data_len);
|
||||
|
||||
std::string GetTaskResp() const;
|
||||
|
||||
bool IsTaskSuccess() const;
|
||||
|
||||
void SetTaskSuccess() { m_is_task_success = true; }
|
||||
|
||||
int GetHttpStatus() const ;
|
||||
|
||||
std::map<std::string, std::string> GetRespHeaders() const;
|
||||
|
||||
void SetParams(const std::map<std::string, std::string>& params);
|
||||
|
||||
void SetHeaders(const std::map<std::string, std::string>& headers);
|
||||
|
||||
std::string GetErrMsg() const { return m_err_msg; }
|
||||
|
||||
void SetResume(const bool is_resume) { m_is_resume = is_resume; }
|
||||
|
||||
bool IsResume() const { return m_is_resume; }
|
||||
|
||||
void SetResumeEtag(const std::string& etag) { m_resume_etag = etag; }
|
||||
|
||||
std::string GetResumeEtag() const { return m_resume_etag; }
|
||||
|
||||
void SetPartNumber(uint64_t part_number);
|
||||
|
||||
uint64_t GetPartNumber() const { return m_part_number;}
|
||||
|
||||
private:
|
||||
std::string m_full_url;
|
||||
std::map<std::string, std::string> m_headers;
|
||||
std::map<std::string, std::string> m_params;
|
||||
uint64_t m_conn_timeout_in_ms;
|
||||
uint64_t m_recv_timeout_in_ms;
|
||||
unsigned char* m_data_buf_ptr;
|
||||
size_t m_data_len;
|
||||
std::string m_resp;
|
||||
bool m_is_task_success;
|
||||
int m_http_status;
|
||||
std::map<std::string, std::string> m_resp_headers;
|
||||
std::string m_err_msg;
|
||||
bool m_is_resume;
|
||||
std::string m_resume_etag;
|
||||
uint64_t m_part_number;
|
||||
SharedTransferHandler m_handler;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/21/17
|
||||
// Description:
|
||||
|
||||
#ifndef OBJECT_OP_H
|
||||
#define OBJECT_OP_H
|
||||
#pragma once
|
||||
|
||||
#include "op/base_op.h"
|
||||
#include "op/cos_result.h"
|
||||
#include "request/object_req.h"
|
||||
#include "request/data_process_req.h"
|
||||
#include "response/object_resp.h"
|
||||
#include "response/data_process_resp.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class FileUploadTask;
|
||||
class FileCopyTask;
|
||||
|
||||
/// \brief 封装了Object相关的操作
|
||||
class ObjectOp : public BaseOp {
|
||||
public:
|
||||
/// \brief BucketOp构造函数
|
||||
///
|
||||
/// \param cos_conf Cos配置
|
||||
explicit ObjectOp(const SharedConfig& config) : BaseOp(config) {}
|
||||
ObjectOp() {}
|
||||
|
||||
/// \brief ObjectOP析构函数
|
||||
virtual ~ObjectOp() {}
|
||||
|
||||
/// \brief 判断object是否存在
|
||||
bool IsObjectExist(const std::string& bucket_name, const std::string& object_name);
|
||||
|
||||
std::string GetResumableUploadID(const std::string& bucket_name, const std::string& object_name) ;
|
||||
|
||||
bool CheckUploadPart(const MultiUploadObjectReq& req, const std::string& bucket_name,
|
||||
const std::string& object_name, const std::string& uploadid,
|
||||
const std::string& localpath, std::vector<std::string>& already_exist);
|
||||
|
||||
bool CheckSinglePart(const std::string& local_file_path, uint64_t offset, uint64_t local_part_size,
|
||||
uint64_t size, const std::string& etag);
|
||||
|
||||
/// \brief 获取对应Object的meta信息数据
|
||||
///
|
||||
/// \param request HeadObject请求
|
||||
/// \param response HeadObject返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult HeadObject(const HeadObjectReq& req, HeadObjectResp* resp);
|
||||
|
||||
/// \brief 下载Bucket中的一个文件至流中
|
||||
///
|
||||
/// \param request GetObjectByStream请求
|
||||
/// \param response GetObjectByStream返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetObject(const GetObjectByStreamReq& req, GetObjectByStreamResp* resp);
|
||||
|
||||
/// \brief 下载Bucket中的一个文件到本地
|
||||
///
|
||||
/// \param request GetObjectByFile请求
|
||||
/// \param response GetObjectByFile返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetObject(const GetObjectByFileReq& req, GetObjectByFileResp* resp);
|
||||
|
||||
/// \brief 多线程下载Bucket中的一个文件到本地
|
||||
///
|
||||
/// \param request MultiGetObject请求
|
||||
/// \param response MultiGetObject返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetObject(const MultiGetObjectReq& req, MultiGetObjectResp* resp);
|
||||
|
||||
/// \brief 将本地的文件上传至指定Bucket中
|
||||
///
|
||||
/// \param request PutObjectByFile请求
|
||||
/// \param response PutObjectByFile返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PutObject(const PutObjectByFileReq& req, PutObjectByFileResp* resp);
|
||||
|
||||
/// \brief 将指定流上传至指定Bucket中
|
||||
///
|
||||
/// \param request PutObjectByStream请求
|
||||
/// \param response PutObjectByStream返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PutObject(const PutObjectByStreamReq& req, PutObjectByStreamResp* resp);
|
||||
|
||||
/// \brief 删除Object
|
||||
///
|
||||
/// \param req DeleteObject请求
|
||||
/// \param resp DeleteObject返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteObject(const DeleteObjectReq& req, DeleteObjectResp* resp);
|
||||
|
||||
/// \brief 批量删除Object
|
||||
///
|
||||
/// \param req DeleteObjects请求
|
||||
/// \param resp DeleteObjects返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult DeleteObjects(const DeleteObjectsReq& req, DeleteObjectsResp* resp);
|
||||
|
||||
/// \brief 请求实现初始化分片上传,成功执行此请求以后会返回UploadId用于后续的Upload Part请求
|
||||
///
|
||||
/// \param request InitMultiUpload请求
|
||||
/// \param response InitMultiUpload返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult InitMultiUpload(const InitMultiUploadReq& req, InitMultiUploadResp* resp);
|
||||
|
||||
/// \brief 初始化以后的分块上传,支持的块的数量为1到10000,块的大小为1MB到5GB
|
||||
///
|
||||
/// \param request UploadPartData请求
|
||||
/// \param response UploadPartData返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult UploadPartData(const UploadPartDataReq& req, UploadPartDataResp* resp);
|
||||
|
||||
/// \brief 初始化以后的分块复制,实现将一个文件的分块内容从源路径复制到目标路径。
|
||||
/// 通过指定 x-cos-copy-source 来指定源文件,x-cos-copy-source-range 指定字节范围。
|
||||
/// 允许分块的大小为 5 MB - 5 GB。
|
||||
///
|
||||
/// \param request UploadPartCopyData请求
|
||||
/// \param response UploadPartCopyData返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult UploadPartCopyData(const UploadPartCopyDataReq& req, UploadPartCopyDataResp* resp);
|
||||
|
||||
/// \brief 完成整个分块上传。当使用 Upload Parts 上传完所有块以后,
|
||||
/// 必须调用该 API 来完成整个文件的分块上传
|
||||
///
|
||||
/// \param request CompleteMultiUpload请求
|
||||
/// \param response CompleteMultiUpload返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult CompleteMultiUpload(const CompleteMultiUploadReq& req, CompleteMultiUploadResp* resp);
|
||||
|
||||
/// \brief 异步多线程上传
|
||||
/// \param request MultiUploadObject请求
|
||||
/// \param response MultiUploadObject返回
|
||||
/// \param handler TransferHandler
|
||||
///
|
||||
/// \return result
|
||||
CosResult MultiUploadObject(const MultiUploadObjectReq& req, MultiUploadObjectResp* resp,
|
||||
const SharedTransferHandler& handler = nullptr);
|
||||
|
||||
/// \brief 舍弃一个分块上传并删除已上传的块
|
||||
///
|
||||
/// \param req AbortMultiUpload请求
|
||||
/// \param resp AbortMultiUpload返回
|
||||
///
|
||||
/// \return
|
||||
CosResult AbortMultiUpload(const AbortMultiUploadReq& req, AbortMultiUploadResp* resp);
|
||||
|
||||
/// \brief 查询特定分块上传中的已上传的块
|
||||
///
|
||||
/// \param req ListParts请求
|
||||
/// \param resp ListParts返回
|
||||
///
|
||||
/// \return result
|
||||
CosResult ListParts(const ListPartsReq& req, ListPartsResp* resp);
|
||||
|
||||
/// \brief 列出Object下的ACL
|
||||
///
|
||||
/// \param req GetObjectACL请求
|
||||
/// \param resp GetObjectACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetObjectACL(const GetObjectACLReq& req,
|
||||
GetObjectACLResp* resp);
|
||||
|
||||
/// \brief 增加/替换Object下的ACL, 可以通过Header或者Body传入ACL信息
|
||||
/// 注意Header 和 Body 只能选择其中一种,否则响应返回会冲突
|
||||
///
|
||||
/// \param req PutObjectACL请求
|
||||
/// \param resp PutObjectACL返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutObjectACL(const PutObjectACLReq& req,
|
||||
PutObjectACLResp* resp);
|
||||
|
||||
/// \brief 复制Object
|
||||
///
|
||||
/// \param req PutObjectCopy请求
|
||||
/// \param resp PutObjectCopy返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult PutObjectCopy(const PutObjectCopyReq& req,
|
||||
PutObjectCopyResp* resp);
|
||||
|
||||
/// \brief 复制文件,实现将一个文件的分块内容从源路径复制到目标路径。
|
||||
/// 通过指定 x-cos-copy-source 来指定源文件,x-cos-copy-source-range 指定字节范围。
|
||||
///
|
||||
/// \param request Copy请求
|
||||
/// \param response Copy返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult Copy(const CopyReq& req, CopyResp* resp);
|
||||
|
||||
/// \brief 对一个通过 COS 归档为 archive 类型的对象进行恢复
|
||||
///
|
||||
/// \param request PostObjectRestore请求
|
||||
/// \param response PostObjectRestore返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PostObjectRestore(const PostObjectRestoreReq& req, PostObjectRestoreResp* resp);
|
||||
|
||||
std::string GeneratePresignedUrl(const GeneratePresignedUrlReq& req);
|
||||
|
||||
CosResult OptionsObject(const OptionsObjectReq& req, OptionsObjectResp* resp);
|
||||
|
||||
CosResult SelectObjectContent(const SelectObjectContentReq& req, SelectObjectContentResp* resp);
|
||||
|
||||
/// \brief 创建推流通道
|
||||
///
|
||||
/// \param request PutLiveChannelReq请求
|
||||
/// \param response PutLiveChannelResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PutLiveChannel(const PutLiveChannelReq& req, PutLiveChannelResp* resp);
|
||||
|
||||
/// \brief 启用或禁用通道
|
||||
///
|
||||
/// \param request PutLiveChannelSwitchReq请求
|
||||
/// \param response PutLiveChannelSwitchResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PutLiveChannelSwitch(const PutLiveChannelSwitchReq& req, PutLiveChannelSwitchResp* resp);
|
||||
|
||||
/// \brief 获取直播通道配置
|
||||
///
|
||||
/// \param request GetLiveChannelReq请求
|
||||
/// \param response GetLiveChannelResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetLiveChannel(const GetLiveChannelReq& req, GetLiveChannelResp* resp);
|
||||
|
||||
/// \brief 获取直播通道推流历史
|
||||
///
|
||||
/// \param request GetLiveChannelHistoryReq请求
|
||||
/// \param response GetLiveChannelHistoryResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetLiveChannelHistory(const GetLiveChannelHistoryReq& req, GetLiveChannelHistoryResp* resp);
|
||||
|
||||
/// \brief 获取直播通道推流状态
|
||||
///
|
||||
/// \param request GetLiveChannelStatusReq请求
|
||||
/// \param response GetLiveChannelStatusResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetLiveChannelStatus(const GetLiveChannelStatusReq& req, GetLiveChannelStatusResp* resp);
|
||||
|
||||
/// \brief 删除直播通
|
||||
///
|
||||
/// \param request DeleteLiveChannelReq请求
|
||||
/// \param response DeleteLiveChannelResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult DeleteLiveChannel(const DeleteLiveChannelReq& req, DeleteLiveChannelResp* resp);
|
||||
|
||||
/// \brief 查询指定通道在指定时间段推流生成的播放列表
|
||||
///
|
||||
/// \param request GetLiveChannelVodPlaylistReq请求
|
||||
/// \param response GetLiveChannelVodPlaylistResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult GetLiveChannelVodPlaylist(const GetLiveChannelVodPlaylistReq& req, GetLiveChannelVodPlaylistResp* resp);
|
||||
|
||||
/// \brief 指定通道生成一个可供点播例用的播放列表
|
||||
///
|
||||
/// \param request PostLiveChannelVodPlaylistReq请求
|
||||
/// \param response GetLiveChannelVodPlaylistResp返回
|
||||
///
|
||||
/// \return 返回HTTP请求的状态码及错误信息
|
||||
CosResult PostLiveChannelVodPlaylist(const PostLiveChannelVodPlaylistReq& req,
|
||||
PostLiveChannelVodPlaylistResp* resp);
|
||||
|
||||
/// \brief 异步多线程下载,handler处理回调
|
||||
CosResult MultiThreadDownload(const MultiGetObjectReq& req, MultiGetObjectResp* resp,
|
||||
const SharedTransferHandler& handler = nullptr);
|
||||
|
||||
/*Resumable接口*/
|
||||
|
||||
/// \brief 支持断点下载
|
||||
CosResult ResumableGetObject(const MultiGetObjectReq& req, MultiGetObjectResp* resp);
|
||||
|
||||
/*批量及目录操作接口*/
|
||||
CosResult PutObjects(const PutObjectsByDirectoryReq& req, PutObjectsByDirectoryResp* resp);
|
||||
|
||||
CosResult PutDirectory(const PutDirectoryReq& req, PutDirectoryResp* resp);
|
||||
|
||||
CosResult MoveObject(const MoveObjectReq& req, MoveObjectResp* resp);
|
||||
|
||||
|
||||
/*数据处理接口*/
|
||||
|
||||
/**基础图片处理**/
|
||||
|
||||
/**图片持久化处理**/
|
||||
|
||||
/***上传时处理***/
|
||||
CosResult PutImage(const PutImageByFileReq& req, PutImageByFileResp* resp);
|
||||
|
||||
/***云上数据处理***/
|
||||
CosResult CloudImageProcess(const CloudImageProcessReq& req, CloudImageProcessResp* resp);
|
||||
|
||||
/***下载图片时识别二维码***/
|
||||
CosResult GetQRcode(const GetQRcodeReq& req, GetQRcodeResp* resp);
|
||||
|
||||
/*文档处理接口*/
|
||||
|
||||
/**查询已经开通文档预览功能的 Bucket**/
|
||||
|
||||
CosResult DescribeDocProcessBuckets(const DescribeDocProcessBucketsReq& req, DescribeDocProcessBucketsResp *resp);
|
||||
|
||||
/**预览文档**/
|
||||
CosResult DocPreview(const DocPreviewReq& req, DocPreviewResp *resp);
|
||||
|
||||
private:
|
||||
// 生成request body所需的xml字符串
|
||||
bool GenerateCompleteMultiUploadReqBody(const CompleteMultiUploadReq& req,
|
||||
std::string* req_body);
|
||||
|
||||
/// \brief 多线程上传,handler处理回调
|
||||
CosResult MultiThreadUpload(const MultiUploadObjectReq& req,
|
||||
const std::string& upload_id,
|
||||
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);
|
||||
|
||||
/// \brief 读取文件内容, 并返回读取的长度
|
||||
uint64_t GetContent(const std::string& src, std::string* file_content) const;
|
||||
|
||||
void FillUploadTask(const std::string& upload_id, const std::string& host,
|
||||
const std::string& path, unsigned char* file_content_buf,
|
||||
uint64_t len, uint64_t part_number,
|
||||
FileUploadTask* task_ptr);
|
||||
|
||||
void FillCopyTask(const std::string& upload_id, const std::string& host,
|
||||
const std::string& path, uint64_t part_number,
|
||||
const std::string& range,
|
||||
const std::map<std::string, std::string>& headers,
|
||||
const std::map<std::string, std::string>& params,
|
||||
FileCopyTask* task);
|
||||
|
||||
/// \brief 检查是否可以走断点下载
|
||||
/// \param req MultiUploadObjectReq请求
|
||||
/// \param head_resp HeadObjectResp响应结果
|
||||
/// \param last_offset 返回的上一次下载偏移量
|
||||
/// \return true可以走断点下载,false表示不可以
|
||||
bool CheckResumableDownloadTask(const std::string& json_file,
|
||||
const std::map<std::string, std::string>& element_map,
|
||||
uint64_t *resume_offset);
|
||||
/// \brief 更新断点下载json文件
|
||||
/// \param json_file json文件名
|
||||
/// \param element_map 检查的元素映射
|
||||
/// \param last_offset 返回的上一次下载偏移量
|
||||
/// \return true文件检查成功, 否则失败
|
||||
void UpdateResumableDownloadTaskFile(const std::string& json_file,
|
||||
const std::map<std::string, std::string>& element_map,
|
||||
uint64_t resume_offset);
|
||||
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // OBJECT_OP_H
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 11/14/17
|
||||
// Description:
|
||||
|
||||
#ifndef SERVICEOP_H
|
||||
#define SERVICEOP_H
|
||||
#pragma once
|
||||
|
||||
#include "cos_sys_config.h"
|
||||
#include "op/base_op.h"
|
||||
#include "op/cos_result.h"
|
||||
#include "request/service_req.h"
|
||||
#include "response/service_resp.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
/// \brief 封装了Service相关的操作
|
||||
class ServiceOp : public BaseOp {
|
||||
public:
|
||||
/// \brief ServiceOp构造函数
|
||||
///
|
||||
/// \param cos_conf Cos配置
|
||||
explicit ServiceOp(const SharedConfig& config) : BaseOp(config) {}
|
||||
|
||||
/// \brief ServiceOp析构函数
|
||||
virtual ~ServiceOp() {}
|
||||
|
||||
/// \brief 获取请求者名下的所有存储空间列表Bucket list
|
||||
/// (详见:https://cloud.tencent.com/document/api/436/8291)
|
||||
///
|
||||
/// \param req GetService请求
|
||||
/// \param resp GetService返回
|
||||
///
|
||||
/// \return 本次请求的调用情况(如状态码等)
|
||||
CosResult GetService(const GetServiceReq& req, GetServiceResp* resp);
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // SERVICEOP_H
|
||||
@@ -0,0 +1,52 @@
|
||||
Use of this software is granted under one of the following two licenses,
|
||||
to be chosen freely by the user.
|
||||
|
||||
1. Boost Software License - Version 1.0 - August 17th, 2003
|
||||
===============================================================================
|
||||
|
||||
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
2. The MIT License
|
||||
===============================================================================
|
||||
|
||||
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,174 @@
|
||||
#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||
#define RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||
|
||||
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||
// Version 1.13
|
||||
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||
//! \file rapidxml_iterators.hpp This file contains rapidxml iterators
|
||||
|
||||
#include "rapidxml.hpp"
|
||||
|
||||
namespace rapidxml
|
||||
{
|
||||
|
||||
//! Iterator of child nodes of xml_node
|
||||
template<class Ch>
|
||||
class node_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef typename xml_node<Ch> value_type;
|
||||
typedef typename xml_node<Ch> &reference;
|
||||
typedef typename xml_node<Ch> *pointer;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
node_iterator()
|
||||
: m_node(0)
|
||||
{
|
||||
}
|
||||
|
||||
node_iterator(xml_node<Ch> *node)
|
||||
: m_node(node->first_node())
|
||||
{
|
||||
}
|
||||
|
||||
reference operator *() const
|
||||
{
|
||||
assert(m_node);
|
||||
return *m_node;
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
assert(m_node);
|
||||
return m_node;
|
||||
}
|
||||
|
||||
node_iterator& operator++()
|
||||
{
|
||||
assert(m_node);
|
||||
m_node = m_node->next_sibling();
|
||||
return *this;
|
||||
}
|
||||
|
||||
node_iterator operator++(int)
|
||||
{
|
||||
node_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
node_iterator& operator--()
|
||||
{
|
||||
assert(m_node && m_node->previous_sibling());
|
||||
m_node = m_node->previous_sibling();
|
||||
return *this;
|
||||
}
|
||||
|
||||
node_iterator operator--(int)
|
||||
{
|
||||
node_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator ==(const node_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_node == rhs.m_node;
|
||||
}
|
||||
|
||||
bool operator !=(const node_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_node != rhs.m_node;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
xml_node<Ch> *m_node;
|
||||
|
||||
};
|
||||
|
||||
//! Iterator of child attributes of xml_node
|
||||
template<class Ch>
|
||||
class attribute_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef typename xml_attribute<Ch> value_type;
|
||||
typedef typename xml_attribute<Ch> &reference;
|
||||
typedef typename xml_attribute<Ch> *pointer;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
attribute_iterator()
|
||||
: m_attribute(0)
|
||||
{
|
||||
}
|
||||
|
||||
attribute_iterator(xml_node<Ch> *node)
|
||||
: m_attribute(node->first_attribute())
|
||||
{
|
||||
}
|
||||
|
||||
reference operator *() const
|
||||
{
|
||||
assert(m_attribute);
|
||||
return *m_attribute;
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
assert(m_attribute);
|
||||
return m_attribute;
|
||||
}
|
||||
|
||||
attribute_iterator& operator++()
|
||||
{
|
||||
assert(m_attribute);
|
||||
m_attribute = m_attribute->next_attribute();
|
||||
return *this;
|
||||
}
|
||||
|
||||
attribute_iterator operator++(int)
|
||||
{
|
||||
attribute_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
attribute_iterator& operator--()
|
||||
{
|
||||
assert(m_attribute && m_attribute->previous_attribute());
|
||||
m_attribute = m_attribute->previous_attribute();
|
||||
return *this;
|
||||
}
|
||||
|
||||
attribute_iterator operator--(int)
|
||||
{
|
||||
attribute_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator ==(const attribute_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_attribute == rhs.m_attribute;
|
||||
}
|
||||
|
||||
bool operator !=(const attribute_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_attribute != rhs.m_attribute;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
xml_attribute<Ch> *m_attribute;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,448 @@
|
||||
#ifndef RAPIDXML_PRINT_HPP_INCLUDED
|
||||
#define RAPIDXML_PRINT_HPP_INCLUDED
|
||||
|
||||
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||
// Version 1.13
|
||||
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||
//! \file rapidxml_print.hpp This file contains rapidxml printer implementation
|
||||
|
||||
#include "rapidxml.hpp"
|
||||
|
||||
// Only include streams if not disabled
|
||||
#ifndef RAPIDXML_NO_STREAMS
|
||||
#include <ostream>
|
||||
#include <iterator>
|
||||
#endif
|
||||
|
||||
namespace rapidxml
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Printing flags
|
||||
|
||||
const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Internal
|
||||
|
||||
//! \cond internal
|
||||
namespace internal
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Internal character operations
|
||||
|
||||
// Copy characters from given range to given output iterator
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out)
|
||||
{
|
||||
while (begin != end)
|
||||
*out++ = *begin++;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Copy characters from given range to given output iterator and expand
|
||||
// characters into references (< > ' " &)
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out)
|
||||
{
|
||||
while (begin != end)
|
||||
{
|
||||
if (*begin == noexpand)
|
||||
{
|
||||
*out++ = *begin; // No expansion, copy character
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (*begin)
|
||||
{
|
||||
case Ch('<'):
|
||||
*out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||
break;
|
||||
case Ch('>'):
|
||||
*out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||
break;
|
||||
case Ch('\''):
|
||||
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';');
|
||||
break;
|
||||
case Ch('"'):
|
||||
*out++ = Ch('&'); *out++ = Ch('q'); *out++ = Ch('u'); *out++ = Ch('o'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||
break;
|
||||
case Ch('&'):
|
||||
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('m'); *out++ = Ch('p'); *out++ = Ch(';');
|
||||
break;
|
||||
default:
|
||||
*out++ = *begin; // No expansion, copy character
|
||||
}
|
||||
}
|
||||
++begin; // Step to next character
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Fill given output iterator with repetitions of the same character
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt fill_chars(OutIt out, int n, Ch ch)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
*out++ = ch;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Find character
|
||||
template<class Ch, Ch ch>
|
||||
inline bool find_char(const Ch *begin, const Ch *end)
|
||||
{
|
||||
while (begin != end)
|
||||
if (*begin++ == ch)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Internal printing operations
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
|
||||
|
||||
// Print node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
// Print proper node type
|
||||
switch (node->type())
|
||||
{
|
||||
|
||||
// Document
|
||||
case node_document:
|
||||
out = print_children(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// Element
|
||||
case node_element:
|
||||
out = print_element_node(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// Data
|
||||
case node_data:
|
||||
out = print_data_node(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// CDATA
|
||||
case node_cdata:
|
||||
out = print_cdata_node(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// Declaration
|
||||
case node_declaration:
|
||||
out = print_declaration_node(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// Comment
|
||||
case node_comment:
|
||||
out = print_comment_node(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// Doctype
|
||||
case node_doctype:
|
||||
out = print_doctype_node(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// Pi
|
||||
case node_pi:
|
||||
out = print_pi_node(out, node, flags, indent);
|
||||
break;
|
||||
|
||||
// Unknown
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
// If indenting not disabled, add line break after node
|
||||
if (!(flags & print_no_indenting))
|
||||
*out = Ch('\n'), ++out;
|
||||
|
||||
// Return modified iterator
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print children of the node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling())
|
||||
out = print_node(out, child, flags, indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print attributes of the node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags)
|
||||
{
|
||||
for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute())
|
||||
{
|
||||
if (attribute->name() && attribute->value())
|
||||
{
|
||||
// Print attribute name
|
||||
*out = Ch(' '), ++out;
|
||||
out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
|
||||
*out = Ch('='), ++out;
|
||||
// Print attribute value using appropriate quote type
|
||||
if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size()))
|
||||
{
|
||||
*out = Ch('\''), ++out;
|
||||
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out);
|
||||
*out = Ch('\''), ++out;
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = Ch('"'), ++out;
|
||||
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out);
|
||||
*out = Ch('"'), ++out;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print data node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
assert(node->type() == node_data);
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print data node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
assert(node->type() == node_cdata);
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
*out = Ch('<'); ++out;
|
||||
*out = Ch('!'); ++out;
|
||||
*out = Ch('['); ++out;
|
||||
*out = Ch('C'); ++out;
|
||||
*out = Ch('D'); ++out;
|
||||
*out = Ch('A'); ++out;
|
||||
*out = Ch('T'); ++out;
|
||||
*out = Ch('A'); ++out;
|
||||
*out = Ch('['); ++out;
|
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||
*out = Ch(']'); ++out;
|
||||
*out = Ch(']'); ++out;
|
||||
*out = Ch('>'); ++out;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print element node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
assert(node->type() == node_element);
|
||||
|
||||
// Print element name and attributes, if any
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
*out = Ch('<'), ++out;
|
||||
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||
out = print_attributes(out, node, flags);
|
||||
|
||||
// If node is childless
|
||||
if (node->value_size() == 0 && !node->first_node())
|
||||
{
|
||||
// Print childless node tag ending
|
||||
*out = Ch('/'), ++out;
|
||||
*out = Ch('>'), ++out;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print normal node tag ending
|
||||
*out = Ch('>'), ++out;
|
||||
|
||||
// Test if node contains a single data node only (and no other nodes)
|
||||
xml_node<Ch> *child = node->first_node();
|
||||
if (!child)
|
||||
{
|
||||
// If node has no children, only print its value without indenting
|
||||
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
|
||||
}
|
||||
else if (child->next_sibling() == 0 && child->type() == node_data)
|
||||
{
|
||||
// If node has a sole data child, only print its value without indenting
|
||||
out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print all children with full indenting
|
||||
if (!(flags & print_no_indenting))
|
||||
*out = Ch('\n'), ++out;
|
||||
out = print_children(out, node, flags, indent + 1);
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
}
|
||||
|
||||
// Print node end
|
||||
*out = Ch('<'), ++out;
|
||||
*out = Ch('/'), ++out;
|
||||
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||
*out = Ch('>'), ++out;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print declaration node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
// Print declaration start
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
*out = Ch('<'), ++out;
|
||||
*out = Ch('?'), ++out;
|
||||
*out = Ch('x'), ++out;
|
||||
*out = Ch('m'), ++out;
|
||||
*out = Ch('l'), ++out;
|
||||
|
||||
// Print attributes
|
||||
out = print_attributes(out, node, flags);
|
||||
|
||||
// Print declaration end
|
||||
*out = Ch('?'), ++out;
|
||||
*out = Ch('>'), ++out;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print comment node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
assert(node->type() == node_comment);
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
*out = Ch('<'), ++out;
|
||||
*out = Ch('!'), ++out;
|
||||
*out = Ch('-'), ++out;
|
||||
*out = Ch('-'), ++out;
|
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||
*out = Ch('-'), ++out;
|
||||
*out = Ch('-'), ++out;
|
||||
*out = Ch('>'), ++out;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print doctype node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
assert(node->type() == node_doctype);
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
*out = Ch('<'), ++out;
|
||||
*out = Ch('!'), ++out;
|
||||
*out = Ch('D'), ++out;
|
||||
*out = Ch('O'), ++out;
|
||||
*out = Ch('C'), ++out;
|
||||
*out = Ch('T'), ++out;
|
||||
*out = Ch('Y'), ++out;
|
||||
*out = Ch('P'), ++out;
|
||||
*out = Ch('E'), ++out;
|
||||
*out = Ch(' '), ++out;
|
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||
*out = Ch('>'), ++out;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Print pi node
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||
{
|
||||
assert(node->type() == node_pi);
|
||||
if (!(flags & print_no_indenting))
|
||||
out = fill_chars(out, indent, Ch('\t'));
|
||||
*out = Ch('<'), ++out;
|
||||
*out = Ch('?'), ++out;
|
||||
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||
*out = Ch(' '), ++out;
|
||||
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||
*out = Ch('?'), ++out;
|
||||
*out = Ch('>'), ++out;
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
//! \endcond
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Printing
|
||||
|
||||
//! Prints XML to given output iterator.
|
||||
//! \param out Output iterator to print to.
|
||||
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||
//! \param flags Flags controlling how XML is printed.
|
||||
//! \return Output iterator pointing to position immediately after last character of printed text.
|
||||
template<class OutIt, class Ch>
|
||||
inline OutIt print(OutIt out, const xml_node<Ch> &node, int flags = 0)
|
||||
{
|
||||
return internal::print_node(out, &node, flags, 0);
|
||||
}
|
||||
|
||||
#ifndef RAPIDXML_NO_STREAMS
|
||||
|
||||
//! Prints XML to given output stream.
|
||||
//! \param out Output stream to print to.
|
||||
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||
//! \param flags Flags controlling how XML is printed.
|
||||
//! \return Output stream.
|
||||
template<class Ch>
|
||||
inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out, const xml_node<Ch> &node, int flags = 0)
|
||||
{
|
||||
print(std::ostream_iterator<Ch>(out), node, flags);
|
||||
return out;
|
||||
}
|
||||
|
||||
//! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process.
|
||||
//! \param out Output stream to print to.
|
||||
//! \param node Node to be printed.
|
||||
//! \return Output stream.
|
||||
template<class Ch>
|
||||
inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out, const xml_node<Ch> &node)
|
||||
{
|
||||
return print(out, node);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
#ifndef RAPIDXML_UTILS_HPP_INCLUDED
|
||||
#define RAPIDXML_UTILS_HPP_INCLUDED
|
||||
|
||||
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||
// Version 1.13
|
||||
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||
//! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful
|
||||
//! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.
|
||||
|
||||
#include "rapidxml.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace rapidxml
|
||||
{
|
||||
|
||||
//! Represents data loaded from a file
|
||||
template<class Ch = char>
|
||||
class file
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Loads file into the memory. Data will be automatically destroyed by the destructor.
|
||||
//! \param filename Filename to load.
|
||||
file(const char *filename)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
// Open stream
|
||||
basic_ifstream<Ch> stream(filename, ios::binary);
|
||||
if (!stream)
|
||||
throw runtime_error(string("cannot open file ") + filename);
|
||||
stream.unsetf(ios::skipws);
|
||||
|
||||
// Determine stream size
|
||||
stream.seekg(0, ios::end);
|
||||
size_t size = stream.tellg();
|
||||
stream.seekg(0);
|
||||
|
||||
// Load data and add terminating 0
|
||||
m_data.resize(size + 1);
|
||||
stream.read(&m_data.front(), static_cast<streamsize>(size));
|
||||
m_data[size] = 0;
|
||||
}
|
||||
|
||||
//! Loads file into the memory. Data will be automatically destroyed by the destructor
|
||||
//! \param stream Stream to load from
|
||||
file(std::basic_istream<Ch> &stream)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
// Load data and add terminating 0
|
||||
stream.unsetf(ios::skipws);
|
||||
m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
|
||||
if (stream.fail() || stream.bad())
|
||||
throw runtime_error("error reading stream");
|
||||
m_data.push_back(0);
|
||||
}
|
||||
|
||||
//! Gets file data.
|
||||
//! \return Pointer to data of file.
|
||||
Ch *data()
|
||||
{
|
||||
return &m_data.front();
|
||||
}
|
||||
|
||||
//! Gets file data.
|
||||
//! \return Pointer to data of file.
|
||||
const Ch *data() const
|
||||
{
|
||||
return &m_data.front();
|
||||
}
|
||||
|
||||
//! Gets file data size.
|
||||
//! \return Size of file data, in characters.
|
||||
std::size_t size() const
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Ch> m_data; // File data
|
||||
|
||||
};
|
||||
|
||||
//! Counts children of node. Time complexity is O(n).
|
||||
//! \return Number of children of node
|
||||
template<class Ch>
|
||||
inline std::size_t count_children(xml_node<Ch> *node)
|
||||
{
|
||||
xml_node<Ch> *child = node->first_node();
|
||||
std::size_t count = 0;
|
||||
while (child)
|
||||
{
|
||||
++count;
|
||||
child = child->next_sibling();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
//! Counts attributes of node. Time complexity is O(n).
|
||||
//! \return Number of attributes of node
|
||||
template<class Ch>
|
||||
inline std::size_t count_attributes(xml_node<Ch> *node)
|
||||
{
|
||||
xml_attribute<Ch> *attr = node->first_attribute();
|
||||
std::size_t count = 0;
|
||||
while (attr)
|
||||
{
|
||||
++count;
|
||||
attr = attr->next_attribute();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/15/17
|
||||
// Description:
|
||||
|
||||
#ifndef BASEREQ_H
|
||||
#define BASEREQ_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "util/string_util.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
/// \brief 封装Http请求
|
||||
class BaseReq {
|
||||
public:
|
||||
typedef std::map<std::string, std::string> Str2StrMap;
|
||||
public:
|
||||
BaseReq();
|
||||
virtual ~BaseReq() {}
|
||||
|
||||
/// \brief 设置请求头部
|
||||
void AddHeader(const std::string& key, const std::string& value);
|
||||
void AddHeaders(const Str2StrMap& user_headers);
|
||||
|
||||
/// \brief 获取请求头部
|
||||
std::string GetHeader(const std::string& key) const;
|
||||
const Str2StrMap& GetHeaders() const { return m_headers_map; }
|
||||
|
||||
/// \brief 清空请求头部
|
||||
void ClearHeaders() { m_headers_map.clear(); }
|
||||
|
||||
/// \brief 设置请求参数
|
||||
void AddParam(const std::string& key, const std::string& value);
|
||||
void AddParams(const Str2StrMap& user_params);
|
||||
|
||||
/// \brief 获取请求参数
|
||||
std::string GetParam(const std::string& key) const;
|
||||
const Str2StrMap& GetParams() const { return m_params_map; };
|
||||
|
||||
/// \brief 清空请求参数
|
||||
void ClearParams() { m_params_map.clear(); }
|
||||
|
||||
/// \brief 获取请求的http方法
|
||||
std::string GetMethod() const { return m_method; }
|
||||
|
||||
/// \brief 设置请求的http方法
|
||||
void SetMethod(const std::string& method) {
|
||||
m_method = StringUtil::StringToUpper(method);
|
||||
}
|
||||
|
||||
/// \brief 获取请求的body
|
||||
std::string GetBody() const { return m_body; }
|
||||
|
||||
/// \brief 设置请求的body
|
||||
void SetBody(const std::string& body) { m_body = body; }
|
||||
|
||||
/// \brief 获取Path
|
||||
std::string GetPath() const { return m_path; }
|
||||
|
||||
/// \brief 设置Path
|
||||
void SetPath(const std::string& path) { m_path = path; }
|
||||
|
||||
void SetConnTimeoutInms(uint64_t conn_timeout_in_ms) {
|
||||
m_conn_timeout_in_ms = conn_timeout_in_ms;
|
||||
}
|
||||
|
||||
uint64_t GetConnTimeoutInms() const {
|
||||
return m_conn_timeout_in_ms;
|
||||
}
|
||||
|
||||
void SetRecvTimeoutInms(uint64_t recv_timeout_in_ms) {
|
||||
m_recv_timeout_in_ms = recv_timeout_in_ms;
|
||||
}
|
||||
|
||||
uint64_t GetRecvTimeoutInms() const {
|
||||
return m_recv_timeout_in_ms;
|
||||
}
|
||||
|
||||
/// \brief 设置当前请求是否使用https
|
||||
void SetHttps() { m_is_https = true; }
|
||||
bool IsHttps() const { return m_is_https; }
|
||||
|
||||
/// \brief set whether check content md5 each request, used for close range download check
|
||||
void SetCheckMD5(bool check_md5) { mb_check_md5 = check_md5; }
|
||||
bool CheckMD5() const { return mb_check_md5; }
|
||||
|
||||
void SetCheckCRC(bool check_crc) { mb_check_crc = check_crc; }
|
||||
bool CheckCRC() const { return mb_check_crc; }
|
||||
|
||||
/// \brief 输出请求的header和param信息
|
||||
std::string DebugString() const;
|
||||
|
||||
protected:
|
||||
// acl相关的请求,供PutObjectACL和PutBucketACL使用
|
||||
bool GenerateAclRequestBody(const Owner& owner,
|
||||
const std::vector<Grant>& acl,
|
||||
std::string* body) const;
|
||||
|
||||
protected:
|
||||
Str2StrMap m_headers_map;
|
||||
Str2StrMap m_params_map;
|
||||
std::string m_path;
|
||||
std::string m_method;
|
||||
std::string m_body;
|
||||
|
||||
uint64_t m_conn_timeout_in_ms;
|
||||
uint64_t m_recv_timeout_in_ms;
|
||||
bool m_is_https;
|
||||
bool mb_check_md5; // defaule is true
|
||||
bool mb_check_crc; // default is false
|
||||
};
|
||||
|
||||
} // namespaace qcloud_cos
|
||||
|
||||
#endif // BASEREQ_H
|
||||
@@ -0,0 +1,911 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/21/17
|
||||
// Description:
|
||||
|
||||
#ifndef BUCKET_REQ_H
|
||||
#define BUCKET_REQ_H
|
||||
#pragma once
|
||||
|
||||
#include "cos_defines.h"
|
||||
#include "request/base_req.h"
|
||||
#include "util/string_util.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class BucketReq : public BaseReq {
|
||||
public:
|
||||
BucketReq(const std::string& bucket_name) : m_bucket_name(bucket_name) { }
|
||||
virtual ~BucketReq() {}
|
||||
|
||||
// getter and setter
|
||||
std::string GetBucketName() const { return m_bucket_name; }
|
||||
void SetBucketName(const std::string& bucket_name) { m_bucket_name = bucket_name; }
|
||||
|
||||
private:
|
||||
std::string m_bucket_name;
|
||||
};
|
||||
|
||||
class HeadBucketReq : public BucketReq {
|
||||
public:
|
||||
HeadBucketReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
m_method = "HEAD";
|
||||
}
|
||||
|
||||
virtual ~HeadBucketReq() {}
|
||||
};
|
||||
|
||||
class PutBucketReq : public BucketReq {
|
||||
public:
|
||||
PutBucketReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
}
|
||||
|
||||
virtual ~PutBucketReq() {}
|
||||
|
||||
/// 定义Bucket的ACL属性,有效值:private,public-read-write,public-read
|
||||
/// 默认值:private
|
||||
void SetXCosAcl(const std::string& str) {
|
||||
AddHeader("x-cos-acl", str);
|
||||
}
|
||||
|
||||
/// 赋予被授权者读的权限.格式:x-cos-grant-read: id=" ",id=" ".
|
||||
/// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>"
|
||||
/// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
|
||||
void SetXCosGrantRead(const std::string& str) {
|
||||
AddHeader("x-cos-grant-read", str);
|
||||
}
|
||||
|
||||
/// 赋予被授权者写的权限,格式:x-cos-grant-write: id=" ",id=" "./
|
||||
/// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
|
||||
/// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
|
||||
void SetXCosGrantWrite(const std::string& str) {
|
||||
AddHeader("x-cos-grant-write", str);
|
||||
}
|
||||
|
||||
/// 赋予被授权者读写权限.格式:x-cos-grant-full-control: id=" ",id=" ".
|
||||
/// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
|
||||
/// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
|
||||
void SetXCosGrantFullControl(const std::string& str) {
|
||||
AddHeader("x-cos-grant-full-control", str);
|
||||
}
|
||||
};
|
||||
|
||||
class GetBucketReq : public BucketReq {
|
||||
public:
|
||||
GetBucketReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
}
|
||||
|
||||
virtual ~GetBucketReq() {}
|
||||
|
||||
/// \@brief 设置前缀,用来规定返回的文件前缀地址
|
||||
void SetPrefix(const std::string& prefix) {
|
||||
AddParam("prefix", prefix);
|
||||
}
|
||||
|
||||
/// \brief 设置定界符,如果有 Prefix,则将 Prefix 到 delimiter 之间的相同路径归为一类,
|
||||
/// 定义为 Common Prefix,然后列出所有 Common Prefix。如果没有 Prefix,则从路径起点开始
|
||||
void SetDelimiter(const std::string& delimiter) {
|
||||
AddParam("delimiter", delimiter);
|
||||
}
|
||||
|
||||
/// \brief 规定返回值的编码方式,可选值:url
|
||||
void SetEncodingType(const std::string& encoding_type) {
|
||||
AddParam("encoding-type", encoding_type);
|
||||
}
|
||||
|
||||
/// \brief 默认以 UTF-8 二进制顺序列出条目,所有列出条目从marker开始
|
||||
void SetMarker(const std::string& marker) {
|
||||
AddParam("marker", marker);
|
||||
}
|
||||
|
||||
/// \brief 单次返回最大的条目数量,默认1000
|
||||
void SetMaxKeys(uint64_t max_keys) {
|
||||
AddParam("max-keys", StringUtil::Uint64ToString(max_keys));
|
||||
}
|
||||
};
|
||||
|
||||
class ListMultipartUploadReq : public BucketReq {
|
||||
public:
|
||||
ListMultipartUploadReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("uploads", "");
|
||||
}
|
||||
|
||||
virtual ~ListMultipartUploadReq() {}
|
||||
|
||||
void SetPrefix(const std::string& prefix) {
|
||||
AddParam("prefix", prefix);
|
||||
}
|
||||
|
||||
void SetDelimiter(const std::string& delimiter) {
|
||||
AddParam("delimiter", delimiter);
|
||||
}
|
||||
|
||||
void SetEncodingType(const std::string& encoding_type) {
|
||||
AddParam("encoding-type", encoding_type);
|
||||
}
|
||||
|
||||
void SetKeyMarker(const std::string& marker) {
|
||||
AddParam("key-marker", marker);
|
||||
}
|
||||
|
||||
void SetMaxUploads(const std::string& max_uploads) {
|
||||
AddParam("max-uploads", max_uploads);
|
||||
}
|
||||
|
||||
void SetUploadIdMarker(const std::string& upload_id_marker) {
|
||||
AddParam("upload-id-marker", upload_id_marker);
|
||||
}
|
||||
};
|
||||
|
||||
class DeleteBucketReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("DELETE");
|
||||
}
|
||||
|
||||
~DeleteBucketReq() {}
|
||||
};
|
||||
|
||||
class GetBucketVersioningReq : public BucketReq {
|
||||
public:
|
||||
GetBucketVersioningReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("versioning", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketVersioningReq() {}
|
||||
};
|
||||
|
||||
class PutBucketVersioningReq : public BucketReq {
|
||||
public:
|
||||
PutBucketVersioningReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name), m_status(true) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("versioning", "");
|
||||
}
|
||||
|
||||
virtual ~PutBucketVersioningReq() {}
|
||||
|
||||
/// \brief 版本是否开启
|
||||
void SetStatus(bool is_enable) { m_status = is_enable; }
|
||||
|
||||
bool GetStatus() const { return m_status; }
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
bool m_status;
|
||||
};
|
||||
|
||||
class GetBucketReplicationReq : public BucketReq {
|
||||
public:
|
||||
GetBucketReplicationReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("replication", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketReplicationReq() {}
|
||||
};
|
||||
|
||||
class PutBucketReplicationReq : public BucketReq {
|
||||
public:
|
||||
PutBucketReplicationReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("replication", "");
|
||||
}
|
||||
|
||||
virtual ~PutBucketReplicationReq() {}
|
||||
|
||||
void SetRole(const std::string& role) { m_role = role; }
|
||||
|
||||
void AddReplicationRule(const ReplicationRule& rule) {
|
||||
m_rules.push_back(rule);
|
||||
}
|
||||
|
||||
void SetReplicationRule(const std::vector<ReplicationRule>& rules) {
|
||||
m_rules = rules;
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
std::string m_role;
|
||||
std::vector<ReplicationRule> m_rules;
|
||||
};
|
||||
|
||||
class DeleteBucketReplicationReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketReplicationReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("Delete");
|
||||
SetPath("/");
|
||||
AddParam("replication", "");
|
||||
}
|
||||
|
||||
virtual ~DeleteBucketReplicationReq() {}
|
||||
};
|
||||
|
||||
class GetBucketLifecycleReq : public BucketReq {
|
||||
public:
|
||||
GetBucketLifecycleReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("lifecycle", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketLifecycleReq() {}
|
||||
};
|
||||
|
||||
class PutBucketLifecycleReq : public BucketReq {
|
||||
public:
|
||||
PutBucketLifecycleReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("lifecycle", "");
|
||||
}
|
||||
|
||||
virtual ~PutBucketLifecycleReq() {}
|
||||
|
||||
void AddRule(const LifecycleRule& rule) {
|
||||
m_rules.push_back(rule);
|
||||
}
|
||||
|
||||
void SetRule(const std::vector<LifecycleRule>& rules) {
|
||||
m_rules = rules;
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
std::vector<LifecycleRule> m_rules;
|
||||
};
|
||||
|
||||
class DeleteBucketLifecycleReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketLifecycleReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("DELETE");
|
||||
SetPath("/");
|
||||
AddParam("lifecycle", "");
|
||||
}
|
||||
|
||||
virtual ~DeleteBucketLifecycleReq() {}
|
||||
};
|
||||
|
||||
class GetBucketACLReq : public BucketReq {
|
||||
public:
|
||||
GetBucketACLReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("acl", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketACLReq() {}
|
||||
};
|
||||
|
||||
class PutBucketACLReq : public BucketReq {
|
||||
public:
|
||||
PutBucketACLReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("acl", "");
|
||||
}
|
||||
|
||||
virtual ~PutBucketACLReq() {}
|
||||
|
||||
/// 定义Bucket的ACL属性,有效值:private,public-read-write,public-read
|
||||
/// 默认值:private
|
||||
void SetXCosAcl(const std::string& str) {
|
||||
AddHeader("x-cos-acl", str);
|
||||
}
|
||||
|
||||
/// 赋予被授权者读的权限.格式:x-cos-grant-read: id=" ",id=" ".
|
||||
/// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>"
|
||||
/// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
|
||||
void SetXCosGrantRead(const std::string& str) {
|
||||
AddHeader("x-cos-grant-read", str);
|
||||
}
|
||||
|
||||
/// 赋予被授权者写的权限,格式:x-cos-grant-write: id=" ",id=" "./
|
||||
/// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
|
||||
/// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
|
||||
void SetXCosGrantWrite(const std::string& str) {
|
||||
AddHeader("x-cos-grant-write", str);
|
||||
}
|
||||
|
||||
/// 赋予被授权者读写权限.格式:x-cos-grant-full-control: id=" ",id=" ".
|
||||
/// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
|
||||
/// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
|
||||
void SetXCosGrantFullControl(const std::string& str) {
|
||||
AddHeader("x-cos-grant-full-control", str);
|
||||
}
|
||||
|
||||
/// Bucket 持有者 ID
|
||||
void SetOwner(const Owner& owner) {
|
||||
m_owner = owner;
|
||||
}
|
||||
|
||||
/// 设置被授权者信息与权限信息
|
||||
void SetAccessControlList(const std::vector<Grant>& grants) {
|
||||
m_acl = grants;
|
||||
}
|
||||
|
||||
/// 添加单个 Bucket 的授权信息
|
||||
void AddAccessControlList(const Grant& grant) {
|
||||
m_acl.push_back(grant);
|
||||
}
|
||||
|
||||
/// 清空权限信息
|
||||
void ClearAccessControlList() {
|
||||
std::vector<Grant> tmp;
|
||||
m_acl.swap(tmp);
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
Owner m_owner;
|
||||
std::vector<Grant> m_acl;
|
||||
};
|
||||
|
||||
class DeleteBucketACLReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketACLReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("DELETE");
|
||||
}
|
||||
|
||||
virtual ~DeleteBucketACLReq() {}
|
||||
};
|
||||
|
||||
class GetBucketCORSReq : public BucketReq {
|
||||
public:
|
||||
GetBucketCORSReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("cors", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketCORSReq() {}
|
||||
};
|
||||
|
||||
class PutBucketCORSReq : public BucketReq {
|
||||
public:
|
||||
PutBucketCORSReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("cors", "");
|
||||
AddHeader("Content-Type", "application/xml");
|
||||
}
|
||||
|
||||
virtual ~PutBucketCORSReq() {}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
void AddRule(const CORSRule& rule) { m_rules.push_back(rule); }
|
||||
|
||||
void SetRules(const std::vector<CORSRule>& rules) { m_rules = rules; }
|
||||
|
||||
private:
|
||||
std::vector<CORSRule> m_rules;
|
||||
};
|
||||
|
||||
class DeleteBucketCORSReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketCORSReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("DELETE");
|
||||
SetPath("/");
|
||||
AddParam("cors", "");
|
||||
}
|
||||
|
||||
virtual ~DeleteBucketCORSReq() {}
|
||||
};
|
||||
|
||||
class GetBucketLocationReq : public BucketReq {
|
||||
public:
|
||||
GetBucketLocationReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("location", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketLocationReq() {}
|
||||
};
|
||||
|
||||
class GetBucketObjectVersionsReq : public BucketReq {
|
||||
public:
|
||||
GetBucketObjectVersionsReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("versions", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketObjectVersionsReq() {}
|
||||
|
||||
/// \@brief 设置前缀,用来规定返回的文件前缀地址
|
||||
void SetPrefix(const std::string& prefix) {
|
||||
AddParam("prefix", prefix);
|
||||
}
|
||||
|
||||
/// \brief 设置定界符,如果有 Prefix,则将 Prefix 到 delimiter 之间的相同路径归为一类,
|
||||
/// 定义为 Common Prefix,然后列出所有 Common Prefix。如果没有 Prefix,则从路径起点开始
|
||||
void SetDelimiter(const std::string& delimiter) {
|
||||
AddParam("delimiter", delimiter);
|
||||
}
|
||||
|
||||
/// \brief 规定返回值的编码方式,可选值:url
|
||||
void SetEncodingType(const std::string& encoding_type) {
|
||||
AddParam("encoding-type", encoding_type);
|
||||
}
|
||||
|
||||
/// \brief 默认以 UTF-8 二进制顺序列出条目,所有列出条目从marker开始
|
||||
void SetKeyMarker(const std::string& marker) {
|
||||
AddParam("key-marker", marker);
|
||||
}
|
||||
|
||||
/// \brief 单次返回最大的条目数量,默认1000
|
||||
void SetMaxKeys(uint64_t max_keys) {
|
||||
AddParam("max-keys", StringUtil::Uint64ToString(max_keys));
|
||||
}
|
||||
|
||||
void SetVersionIdMarker(const std::string& version_id_marker) {
|
||||
AddParam("version-id-marker", version_id_marker);
|
||||
}
|
||||
};
|
||||
|
||||
class PutBucketLoggingReq : public BucketReq {
|
||||
public:
|
||||
PutBucketLoggingReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name), m_mask(0x00000000u) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("logging", "");
|
||||
}
|
||||
virtual ~PutBucketLoggingReq() {}
|
||||
|
||||
void SetLoggingEnabled(const LoggingEnabled& rules) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_rules = rules;
|
||||
}
|
||||
bool HasLoggingEnabled() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
private:
|
||||
uint64_t m_mask;
|
||||
LoggingEnabled m_rules;
|
||||
};
|
||||
|
||||
class GetBucketLoggingReq : public BucketReq {
|
||||
public:
|
||||
GetBucketLoggingReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("logging", "");
|
||||
}
|
||||
virtual ~GetBucketLoggingReq() {}
|
||||
};
|
||||
|
||||
class PutBucketDomainReq : public BucketReq {
|
||||
public:
|
||||
PutBucketDomainReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("domain", "");
|
||||
}
|
||||
virtual ~PutBucketDomainReq() {}
|
||||
|
||||
void SetDomainRule(const DomainRule& rules) {
|
||||
m_rules = rules;
|
||||
}
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
DomainRule m_rules;
|
||||
};
|
||||
|
||||
class GetBucketDomainReq : public BucketReq {
|
||||
public:
|
||||
GetBucketDomainReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("domain", "");
|
||||
}
|
||||
virtual ~GetBucketDomainReq() {}
|
||||
};
|
||||
|
||||
class PutBucketWebsiteReq : public BucketReq {
|
||||
public:
|
||||
PutBucketWebsiteReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name), m_mask(0x00000000u),
|
||||
m_suffix(""), m_protocol(""), m_key(""){
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("website", "");
|
||||
}
|
||||
|
||||
virtual ~PutBucketWebsiteReq() {}
|
||||
|
||||
void SetSuffix(const std::string& suffix) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_suffix = suffix;
|
||||
}
|
||||
|
||||
void SetProtocol(const std::string& protocol) {
|
||||
m_mask = m_mask | 0x00000002u;
|
||||
m_protocol = protocol;
|
||||
}
|
||||
|
||||
void SetKey(const std::string& key) {
|
||||
m_mask = m_mask | 0x00000004u;
|
||||
m_key = key;
|
||||
}
|
||||
|
||||
std::string GetSuffix() const {
|
||||
return m_suffix;
|
||||
}
|
||||
|
||||
std::string GetProtocol() const {
|
||||
return m_protocol;
|
||||
}
|
||||
|
||||
std::string GetKey() const {
|
||||
return m_key;
|
||||
}
|
||||
|
||||
bool HasSuffix() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
bool HasProtocol() const {
|
||||
return (m_mask & 0x00000002u) != 0;
|
||||
}
|
||||
|
||||
bool HasKey() const {
|
||||
return (m_mask & 0x00000004u) != 0;
|
||||
}
|
||||
|
||||
bool HasRoutingRules() const {
|
||||
return !m_routingrules.empty();
|
||||
}
|
||||
|
||||
/// 设置重定向规则
|
||||
void SetRoutingRules(const std::vector<RoutingRule>& routingrules) {
|
||||
m_routingrules = routingrules;
|
||||
}
|
||||
|
||||
/// 添加单个rule
|
||||
void AddRoutingRule(const RoutingRule& routingrule) {
|
||||
m_routingrules.push_back(routingrule);
|
||||
}
|
||||
|
||||
/// 清空重定向规则
|
||||
void ClearRoutingRules() {
|
||||
std::vector<RoutingRule> tmp;
|
||||
m_routingrules.swap(tmp);
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
uint64_t m_mask;
|
||||
std::string m_suffix;
|
||||
std::string m_protocol;
|
||||
std::string m_key;
|
||||
std::vector<RoutingRule> m_routingrules;
|
||||
};
|
||||
|
||||
class GetBucketWebsiteReq : public BucketReq {
|
||||
public:
|
||||
GetBucketWebsiteReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("Get");
|
||||
SetPath("/");
|
||||
AddParam("website", "");
|
||||
}
|
||||
|
||||
virtual ~GetBucketWebsiteReq() {}
|
||||
};
|
||||
|
||||
class DeleteBucketWebsiteReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketWebsiteReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("DELETE");
|
||||
SetPath("/");
|
||||
AddParam("website", "");
|
||||
}
|
||||
|
||||
virtual ~DeleteBucketWebsiteReq() {}
|
||||
};
|
||||
|
||||
class PutBucketTaggingReq : public BucketReq {
|
||||
public:
|
||||
PutBucketTaggingReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("tagging", "");
|
||||
}
|
||||
|
||||
void SetTagSet(std::vector<Tag>& tagset) {
|
||||
m_tagset = tagset;
|
||||
}
|
||||
|
||||
std::vector<Tag> GetTagSet() {
|
||||
return m_tagset;
|
||||
}
|
||||
|
||||
//清除tag规则.
|
||||
void ClearTagSet() {
|
||||
std::vector<Tag> temp;
|
||||
m_tagset.swap(temp);
|
||||
}
|
||||
|
||||
/// 添加单个tag.
|
||||
void AddTag(const Tag& tag) {
|
||||
m_tagset.push_back(tag);
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
virtual ~PutBucketTaggingReq() {}
|
||||
private:
|
||||
std::vector<Tag> m_tagset;
|
||||
};
|
||||
|
||||
|
||||
class GetBucketTaggingReq : public BucketReq {
|
||||
public:
|
||||
GetBucketTaggingReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("tagging", "");
|
||||
}
|
||||
virtual ~GetBucketTaggingReq() {}
|
||||
};
|
||||
|
||||
class DeleteBucketTaggingReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketTaggingReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("DELETE");
|
||||
SetPath("/");
|
||||
AddParam("tagging", "");
|
||||
}
|
||||
|
||||
virtual ~DeleteBucketTaggingReq() {}
|
||||
};
|
||||
|
||||
|
||||
class PutBucketInventoryReq : public BucketReq {
|
||||
public:
|
||||
PutBucketInventoryReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name), m_mask(0x00000000u) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("inventory", "");
|
||||
}
|
||||
|
||||
void SetInventory(Inventory& inventory) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_inventory = inventory;
|
||||
}
|
||||
|
||||
bool HasInventory() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
const Inventory& GetInventory() const {
|
||||
return m_inventory;
|
||||
}
|
||||
|
||||
void SetId(const std::string id) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_id = id;
|
||||
AddParam("id", m_id);
|
||||
}
|
||||
|
||||
std::string GetId() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool HasId() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
virtual ~PutBucketInventoryReq() {}
|
||||
|
||||
private:
|
||||
uint64_t m_mask;
|
||||
std::string m_id;
|
||||
Inventory m_inventory;
|
||||
};
|
||||
|
||||
|
||||
class GetBucketInventoryReq : public BucketReq {
|
||||
public:
|
||||
GetBucketInventoryReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name), m_mask(0x00000000u) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("inventory", "");
|
||||
}
|
||||
|
||||
void SetId(const std::string id) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_id = id;
|
||||
AddParam("id", m_id);
|
||||
}
|
||||
|
||||
std::string GetId() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool HasId() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
virtual ~GetBucketInventoryReq() {}
|
||||
|
||||
private:
|
||||
uint64_t m_mask;
|
||||
std::string m_id;
|
||||
};
|
||||
|
||||
class ListBucketInventoryConfigurationsReq : public BucketReq {
|
||||
public:
|
||||
ListBucketInventoryConfigurationsReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name), m_mask(0x00000000u) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("inventory", "");
|
||||
}
|
||||
|
||||
void SetContinuationToken(const std::string continuation_token) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_continuation_token = continuation_token;
|
||||
AddParam("continuation-token", m_continuation_token);
|
||||
}
|
||||
|
||||
std::string GetContinuationToken() const {
|
||||
return m_continuation_token;
|
||||
}
|
||||
|
||||
bool HasContinuationToken() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
virtual ~ListBucketInventoryConfigurationsReq() {}
|
||||
|
||||
private:
|
||||
uint64_t m_mask;
|
||||
std::string m_continuation_token;
|
||||
};
|
||||
|
||||
class DeleteBucketInventoryReq : public BucketReq {
|
||||
public:
|
||||
DeleteBucketInventoryReq (const std::string& bucket_name)
|
||||
:BucketReq(bucket_name), m_mask(0x00000000u), m_id("") {
|
||||
SetMethod("DELETE");
|
||||
SetPath("/");
|
||||
AddParam("inventory", "");
|
||||
}
|
||||
|
||||
void SetId(const std::string id) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_id = id;
|
||||
AddParam("id", m_id);
|
||||
}
|
||||
|
||||
std::string GetId() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool HasId() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
virtual ~DeleteBucketInventoryReq() {}
|
||||
|
||||
private:
|
||||
uint64_t m_mask;
|
||||
std::string m_id;
|
||||
};
|
||||
|
||||
/// \brief: 列举直播通道请求
|
||||
class ListLiveChannelReq : public BucketReq {
|
||||
public:
|
||||
ListLiveChannelReq(const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("live", "");
|
||||
}
|
||||
void SetMaxKeys(uint32_t max_keys) {
|
||||
AddParam("max-keys", StringUtil::IntToString(max_keys));
|
||||
}
|
||||
void SetMarker(const std::string& marker) {
|
||||
AddParam("marker", marker);
|
||||
}
|
||||
void SetPrefix(const std::string& prefix) {
|
||||
AddParam("prefix", prefix);
|
||||
}
|
||||
virtual ~ListLiveChannelReq() {}
|
||||
};
|
||||
|
||||
/// \brief: 配置存储桶智能分层特性
|
||||
class PutBucketIntelligentTieringReq : public BucketReq {
|
||||
public:
|
||||
PutBucketIntelligentTieringReq(const std::string& bucket_name)
|
||||
:BucketReq(bucket_name), m_status(false), m_days(30) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/");
|
||||
AddParam("intelligenttiering", "");
|
||||
}
|
||||
virtual ~PutBucketIntelligentTieringReq() {}
|
||||
|
||||
/// \brief 设置智能分层的状态,true表示Enabled,false表示Suspended
|
||||
void SetStatus(bool is_enable) { m_status = is_enable; }
|
||||
|
||||
/// \brief 指定智能分层存储配置中标准层数据转换为低频层数据的天数限制,默认值为30天
|
||||
void SetDays(uint32_t days) {
|
||||
m_days = days;
|
||||
}
|
||||
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
bool m_status;
|
||||
uint32_t m_days;
|
||||
};
|
||||
|
||||
/// \brief: 获取存储桶智能分层配置
|
||||
class GetBucketIntelligentTieringReq : public BucketReq {
|
||||
public:
|
||||
GetBucketIntelligentTieringReq(const std::string& bucket_name)
|
||||
:BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
AddParam("intelligenttiering", "");
|
||||
}
|
||||
virtual ~GetBucketIntelligentTieringReq() {}
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
|
||||
#endif // BUCKET_REQ_H
|
||||
@@ -0,0 +1,704 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Poco/Dynamic/Struct.h"
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "request/bucket_req.h"
|
||||
#include "request/object_req.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
struct Input {
|
||||
Input() : object("") {}
|
||||
|
||||
std::string object; // 文件在 COS 上的文件路径,Bucket 由 Host 指定
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "object: " << object;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct Output {
|
||||
Output() : region(""), bucket(""), object("") {}
|
||||
std::string region; // 存储桶的地域
|
||||
std::string bucket; // 存储结果的存储桶
|
||||
std::string object; // 输出文件路径
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "region: " << region << ", bucket: " << bucket
|
||||
<< ", object: " << object;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct DocProcess {
|
||||
DocProcess()
|
||||
: src_type(""),
|
||||
tgt_type(""),
|
||||
sheet_id(1),
|
||||
start_page(1),
|
||||
end_page(-1),
|
||||
image_params(""),
|
||||
doc_passwd(""),
|
||||
comments(0),
|
||||
paper_direction(0),
|
||||
quality(100),
|
||||
zoom(100) {}
|
||||
std::string src_type; // 源数据的后缀类型
|
||||
std::string tgt_type; // 转换输出目标文件类型
|
||||
int sheet_id; // 表格文件参数
|
||||
int start_page; // 从第 X 页开始转换
|
||||
int end_page; // 转换至第 X 页
|
||||
int page_size; //
|
||||
std::string image_params; // 转换后的图片处理参数
|
||||
std::string doc_passwd; // Office 文档的打开密码
|
||||
int comments; // 是否隐藏批注和应用修订,默认为0
|
||||
int paper_direction; // 表格文件转换纸张方向,0代表垂直方向,非0代表水平方向,默认为0
|
||||
int quality; // 生成预览图的图片质量,取值范围 [1-100],默认值100。
|
||||
// 例:值为100,代表生成图片质量为100%
|
||||
int zoom; // 预览图片的缩放参数
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "src_type: " << src_type << ", tgt_type: " << tgt_type
|
||||
<< ", sheet_id: " << sheet_id << ", start_page: " << start_page
|
||||
<< ", end_page: " << end_page << ", page_size: " << page_size
|
||||
<< ", image_params: " << image_params << ", doc_passwd: " << doc_passwd
|
||||
<< ", comments: " << comments << ", paper_direction: " << paper_direction
|
||||
<< ", quality: " << quality << ", zoom: " << zoom;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct PageInfo {
|
||||
PageInfo()
|
||||
: page_no(0), tgt_uri(""), x_sheet_pics(0), pic_index(0), pic_num(0) {}
|
||||
int page_no; // 预览产物页码,源文件为 Excel 格式时表示 SheetId
|
||||
std::string tgt_uri; // 预览产物生成的 cos 桶路径
|
||||
int x_sheet_pics; // 当前 Sheet 生成的图片总数(源文件为 Excel 特有参数)
|
||||
int pic_index; // 当前预览产物在整个源文件中的序号(源文件为 Excel 特有参数)
|
||||
int pic_num; // 当前预览产物在 Sheet 中的序号(源文件为 Excel 特有参数)
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "page_no: " << page_no << ", tgt_uri: " << tgt_uri
|
||||
<< ", x_sheet_pics: " << x_sheet_pics << ", pic_index: " << pic_index
|
||||
<< ", pic_num: " << pic_num;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct DocProcessResult {
|
||||
DocProcessResult()
|
||||
: tgt_type(""),
|
||||
total_pageount(0),
|
||||
succ_pagecount(0),
|
||||
fail_pagecount(0),
|
||||
total_sheetcount(0) {}
|
||||
std::vector<PageInfo> page_infos; // 预览任务产物详情
|
||||
std::string tgt_type; // 预览产物目标格式
|
||||
std::string task_id; //
|
||||
int total_pageount; // 预览任务产物的总数
|
||||
int succ_pagecount; // 预览任务产物的成功数
|
||||
int fail_pagecount; // 预览任务产物的失败数
|
||||
int total_sheetcount; // 预览任务的 Sheet 总数(源文件为 Excel 特有参数)
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
for (auto& page_info : page_infos) {
|
||||
ss << ", page_info: " << page_info.to_string();
|
||||
}
|
||||
ss << ", tgt_type: " << tgt_type << ", task_id: " << task_id
|
||||
<< ", total_pageount: " << total_pageount
|
||||
<< ", succ_pagecount: " << succ_pagecount
|
||||
<< ", fail_pagecount: " << fail_pagecount
|
||||
<< ", total_sheetcount: " << total_sheetcount;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct Operation {
|
||||
Output output; // 当 Tag 为 DocProcess 时有效,指定该任务的参数
|
||||
DocProcess doc_process; // 结果输出地址
|
||||
DocProcessResult
|
||||
doc_process_result; // 在 job 的类型为 DocProcess 且 job 状态为 success
|
||||
// 时,返回文档预览任务结果详情
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "output: " << output.to_string()
|
||||
<< ", doc_process: " << doc_process.to_string()
|
||||
<< ", doc_process_result: " << doc_process_result.to_string();
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct CodeLocation {
|
||||
std::vector<std::string> points; // 二维码坐标点
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
for (auto& point : points) {
|
||||
ss << ", point: " << point;
|
||||
}
|
||||
ss << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct QRcodeInfo {
|
||||
std::string code_url; // 二维码的内容。可能识别不出
|
||||
CodeLocation code_location; // 图中识别到的二维码位置坐标
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "code_url: " << code_url
|
||||
<< ", code_location: " << code_location.to_string() << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct GetQRcodeResult {
|
||||
int code_status; // 二维码识别结果。0表示未识别到二维码,1表示识别到二维码
|
||||
std::vector<QRcodeInfo> qr_code_info; // 二维码识别结果,可能有多个
|
||||
std::string
|
||||
result_image; // 处理后的图片 base64数据,请求参数 cover 为1时返回
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "code_status: " << code_status;
|
||||
for (auto& qr_code : qr_code_info) {
|
||||
ss << "qr_code: " << qr_code.to_string();
|
||||
}
|
||||
ss << "result_image: " << result_image << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct Object {
|
||||
std::string key; // 文件名
|
||||
std::string location; // 图片路径
|
||||
std::string format; // 图片格式
|
||||
int width; // 图片宽度
|
||||
int height; // 图片高度
|
||||
int size; // 图片大小
|
||||
int quality; // 图片质量
|
||||
std::string etag; // 处理结果图 ETag 信息
|
||||
int code_status; // 二维码识别结果。0表示未识别到二维码,1表示识别到二维码
|
||||
int watermark_status; // 当 type
|
||||
// 为2时返回该字段,表示提取到全盲水印的可信度。
|
||||
// 具体为0-100的数字,75分以上表示确定有盲水印,60-75表示疑似有盲水印,60以下可认为未提取到盲水印
|
||||
std::vector<QRcodeInfo> qr_code_info; // 二维码识别结果,可能有多个
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "key: " << key << ", location: " << location << ", format: " << format
|
||||
<< ", width: " << width << ", heihth: " << height << ", size: " << size
|
||||
<< ", quality: " << quality << ", etag: " << etag
|
||||
<< ", watermark_status: " << watermark_status;
|
||||
for (auto& qr_code : qr_code_info) {
|
||||
ss << "qr_code: " << qr_code.to_string();
|
||||
}
|
||||
ss << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct ProcessResults {
|
||||
std::vector<Object> objects; // 可能有多个对象
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
for (auto& object : objects) {
|
||||
ss << "object: " << object.to_string();
|
||||
}
|
||||
ss << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct ImageInfo {
|
||||
std::string format; // 格式
|
||||
int width; // 图片宽度
|
||||
int height; // 图片高度
|
||||
int quality; // 图片质量
|
||||
std::string ave; // 图片主色调
|
||||
int orientation; // 图片旋转角度
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "format: " << format << ", width: " << width << ", heihth: " << height
|
||||
<< ", quality: " << quality << ", ave: " << ave
|
||||
<< ", orientation: " << orientation << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct OriginalInfo {
|
||||
std::string key; // 原图文件名
|
||||
std::string location; // 图片路径
|
||||
ImageInfo image_info; // 原图图片信息
|
||||
std::string etag; // 原图 ETag 信息
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "key: " << key << ", location: " << location
|
||||
<< ", image_info: " << image_info.to_string() << ", etag: " << etag
|
||||
<< std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct UploadResult {
|
||||
OriginalInfo original_info; // 原图信息
|
||||
ProcessResults process_result; // 图片处理结果
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "original_info: " << original_info.to_string()
|
||||
<< ", process_result: " << process_result.to_string() << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct PicRules {
|
||||
std::string bucket; // 存储结果的目标存储桶名称,格式为
|
||||
// BucketName-APPID,如果不指定的话默认保存到当前存储桶
|
||||
std::string
|
||||
fileid; // 处理结果的文件路径名称,如以/开头,则存入指定文件夹中,否则,存入原图文件存储的同目录
|
||||
std::string
|
||||
rule; // 处理参数,参见对象存储图片处理
|
||||
// API。若按指定样式处理,则以style/开头,后加样式名,如样式名为test,则
|
||||
// rule 字段为style/test
|
||||
};
|
||||
|
||||
class PicOperation {
|
||||
public:
|
||||
PicOperation() : is_pic_info(true) {}
|
||||
virtual ~PicOperation() {}
|
||||
|
||||
void AddRule(const PicRules& rule) { rules.push_back(rule); }
|
||||
|
||||
void TurnOffPicInfo() { is_pic_info = false; }
|
||||
|
||||
std::string GenerateJsonString() const {
|
||||
Poco::JSON::Object::Ptr json_root = new Poco::JSON::Object();
|
||||
if (is_pic_info) {
|
||||
json_root->set("is_pic_info", 1);
|
||||
} else {
|
||||
json_root->set("is_pic_info", 0);
|
||||
}
|
||||
|
||||
Poco::JSON::Array rules_array;
|
||||
for (auto& it : rules) {
|
||||
Poco::JSON::Object::Ptr rule = new Poco::JSON::Object();
|
||||
if (!it.bucket.empty()) {
|
||||
rule->set("bucket", it.bucket);
|
||||
}
|
||||
rule->set("fileid", it.fileid);
|
||||
rule->set("rule", it.rule);
|
||||
rules_array.add(rule);
|
||||
}
|
||||
|
||||
json_root->set("rules", rules_array);
|
||||
std::ostringstream oss;
|
||||
Poco::JSON::Stringifier::stringify(json_root, oss);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
private:
|
||||
bool
|
||||
is_pic_info; // 是否返回原图信息,0不返回原图信息,1返回原图信息,默认为0
|
||||
std::vector<PicRules>
|
||||
rules; //处理规则,一条规则对应一个处理结果(目前支持五条规则),不填则不进行图片处理
|
||||
};
|
||||
|
||||
struct DocBucketList {
|
||||
std::string bucket_id; //存储桶 ID
|
||||
std::string name; // 存储桶名称,同 BucketId
|
||||
std::string region; //所在的地域
|
||||
std::string create_time; // 创建时间
|
||||
std::string alias_bucket_id; // 存储桶别名
|
||||
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "bucket_id: " << bucket_id << ", name: " << name
|
||||
<< ", region: " << region << ", create_time: " << create_time
|
||||
<< ", alias_bucket_id: " << alias_bucket_id;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct DocBucketResponse {
|
||||
std::string request_id; // 请求的唯一 ID
|
||||
int total_count; // 文档预览 Bucket 总数
|
||||
int page_number; // 当前页数,同请求中的 pageNumber
|
||||
int page_size; // 每页个数,同请求中的 pageSize
|
||||
std::vector<DocBucketList> doc_bucket_list; // 文档预览 Bucket 列表
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "request_id: " << request_id << ", total_count: " << total_count
|
||||
<< ", page_number: " << page_number << ", page_size: " << page_size;
|
||||
for (auto& bucket : doc_bucket_list) {
|
||||
ss << ", bucket: " << bucket.to_string();
|
||||
}
|
||||
ss << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct JobsDetail {
|
||||
JobsDetail() {}
|
||||
std::string code; // 错误码,只有 State 为 Failed 时有意义
|
||||
std::string message; // 错误描述,只有 State 为 Failed 时有意义
|
||||
std::string job_id; // 新创建任务的 ID
|
||||
std::string tag; // 新创建任务的 Tag:DocProcess
|
||||
std::string
|
||||
state; // 任务的状态,为
|
||||
// Submitted、Running、Success、Failed、Pause、Cancel 其中一个
|
||||
std::string create_time; // 任务的创建时间
|
||||
std::string end_time; //
|
||||
std::string queue_id; // 任务所属的队列 ID
|
||||
Input input; // 该任务的输入文件路径
|
||||
Operation operation; // 该任务的规则
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "code: " << code << ", message: " << message << ", job_id: " << job_id
|
||||
<< ", tag: " << tag << ", state: " << state
|
||||
<< ", create_time: " << create_time << ", end_time: " << end_time
|
||||
<< ", queue_id: " << queue_id << ". input: " << input.to_string()
|
||||
<< ", operation: " << operation.to_string();
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct NotifyConfig {
|
||||
std::string url; // 回调地址
|
||||
std::string state; // 开关状态,On 或者 Off
|
||||
std::string type; // 回调类型,Url
|
||||
std::string event; // 触发回调的事件
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "url: " << url << ", state: " << state << ", type: " << type
|
||||
<< ", event: " << event;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct NonExistPIDs {
|
||||
std::vector<std::string> queue_id; // NonExistPIDs
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
for (auto& q : queue_id) {
|
||||
ss << ", queue_id: " << q;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct QueueList {
|
||||
std::string queue_id; //队列 ID
|
||||
std::string name; // 队列名字
|
||||
std::string state; // 当前状态,Active 或者 Paused
|
||||
NotifyConfig notify_config; // 回调配置
|
||||
int max_size; // 队列最大长度
|
||||
int max_concurrent; // 当前队列最大并行执行的任务数
|
||||
std::string update_time; // 更新时间
|
||||
std::string create_time; // 创建时间
|
||||
std::string bucket_id; //
|
||||
std::string category; //
|
||||
std::string to_string() const {
|
||||
std::stringstream ss;
|
||||
ss << "queue_id: " << queue_id << ", name: " << name << ", state: " << state
|
||||
<< ", notify_config: " << notify_config.to_string()
|
||||
<< ", max_size: " << max_size << ", max_concurrent: " << max_concurrent
|
||||
<< ", update_time: " << update_time << ", create_time: " << create_time
|
||||
<< ". bucket_id: " << bucket_id << ", category: " << category;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
class PutImageByFileReq : public PutObjectByFileReq {
|
||||
public:
|
||||
PutImageByFileReq(const std::string& bucket_name,
|
||||
const std::string& object_name,
|
||||
const std::string& local_image)
|
||||
: PutObjectByFileReq(bucket_name, object_name, local_image) {}
|
||||
|
||||
virtual ~PutImageByFileReq() {}
|
||||
|
||||
void SetPicOperation(const PicOperation& pic_operation) {
|
||||
m_pic_operation = pic_operation;
|
||||
AddHeader("Pic-Operations", m_pic_operation.GenerateJsonString());
|
||||
}
|
||||
|
||||
private:
|
||||
PicOperation m_pic_operation;
|
||||
};
|
||||
|
||||
class CloudImageProcessReq : public ObjectReq {
|
||||
public:
|
||||
CloudImageProcessReq(const std::string& bucket_name,
|
||||
const std::string& object_name)
|
||||
: ObjectReq(bucket_name, object_name) {
|
||||
m_method = "POST";
|
||||
}
|
||||
virtual ~CloudImageProcessReq() {}
|
||||
|
||||
void SetPicOperation(const PicOperation& pic_operation) {
|
||||
m_pic_operation = pic_operation;
|
||||
AddHeader("Pic-Operations", m_pic_operation.GenerateJsonString());
|
||||
AddParam("image_process", "");
|
||||
}
|
||||
|
||||
private:
|
||||
PicOperation m_pic_operation;
|
||||
};
|
||||
|
||||
class GetQRcodeReq : public ObjectReq {
|
||||
public:
|
||||
GetQRcodeReq(const std::string& bucket_name, const std::string& object_name)
|
||||
: ObjectReq(bucket_name, object_name) {
|
||||
AddParam("ci-process", "QRcode");
|
||||
AddParam("cover", "0");
|
||||
|
||||
m_method = "GET";
|
||||
}
|
||||
|
||||
virtual ~GetQRcodeReq() {}
|
||||
|
||||
// 二维码覆盖功能,将对识别出的二维码覆盖上马赛克。取值为0或1。0表示不开启二维码覆盖,1表示开启二维码覆盖,默认值0
|
||||
void EnableCover() { AddParam("cover", "1"); }
|
||||
};
|
||||
|
||||
class DescribeDocProcessBucketsReq : public BaseReq {
|
||||
public:
|
||||
DescribeDocProcessBucketsReq() {
|
||||
m_method = "GET";
|
||||
|
||||
m_path = "/docbucket";
|
||||
|
||||
// 该接口只支持https
|
||||
SetHttps();
|
||||
}
|
||||
virtual ~DescribeDocProcessBucketsReq() {}
|
||||
|
||||
void SetRegions(const std::string& regions) { AddParam("regions", regions); }
|
||||
|
||||
void SetBucketNames(const std::string& bucket_names) {
|
||||
AddParam("bucketNames", bucket_names);
|
||||
}
|
||||
|
||||
void SetBucketName(const std::string& bucket_name) {
|
||||
AddParam("bucketName", bucket_name);
|
||||
}
|
||||
|
||||
void SetPageNumber(const std::string& page_number) {
|
||||
AddParam("pageNumber", page_number);
|
||||
}
|
||||
|
||||
void SetPageSize(const std::string& page_size) {
|
||||
AddParam("PageSize", page_size);
|
||||
}
|
||||
};
|
||||
|
||||
class DocPreviewReq : public GetObjectByFileReq {
|
||||
public:
|
||||
DocPreviewReq(const std::string& bucket_name, const std::string& object_name,
|
||||
const std::string& local_file)
|
||||
: GetObjectByFileReq(bucket_name, object_name, local_file) {
|
||||
AddParam("ci-process", "doc-preview");
|
||||
|
||||
AddParam("page", "1");
|
||||
|
||||
AddParam("sheet", "1");
|
||||
|
||||
AddParam("dstType", "jpg");
|
||||
|
||||
AddParam("comment", "0");
|
||||
|
||||
AddParam("excelPaperDirection", "0");
|
||||
|
||||
AddParam("quality", "100");
|
||||
|
||||
AddParam("scale", "100");
|
||||
}
|
||||
|
||||
virtual ~DocPreviewReq() {}
|
||||
|
||||
// 源数据的后缀类型,当前文档转换根据 COS 对象的后缀名来确定源数据类型。当 COS
|
||||
// 对象没有后缀名时,可以设置该值
|
||||
void SetSrcType(const std::string& src_type) {
|
||||
AddParam("srcType", src_type);
|
||||
}
|
||||
|
||||
// 需转换的文档页码,默认从1开始计数;表格文件中 page 表示转换的第 X 个 sheet
|
||||
// 的第 X 张图
|
||||
void SetPage(const int page) { AddParam("page", std::to_string(page)); }
|
||||
// 转换后的图片处理参数,支持 基础图片处理 所有处理参数,多个处理参数可通过
|
||||
// 管道操作符 分隔,从而实现在一次访问中按顺序对图片进行不同处理
|
||||
void SetImageParams(const std::string& image_param) {
|
||||
AddParam("ImageParams", image_param);
|
||||
}
|
||||
|
||||
// 表格文件参数,转换第 X 个表,默认为1
|
||||
void SetSheet(const int sheet) {
|
||||
AddParam("ImageParams", std::to_string(sheet));
|
||||
}
|
||||
|
||||
// 转换输出目标文件类型
|
||||
void SetDstType(const std::string& dst_type) {
|
||||
AddParam("dstType", dst_type);
|
||||
}
|
||||
|
||||
// Office 文档的打开密码,如果需要转换有密码的文档,请设置该字段
|
||||
void SetPasswd(const std::string& passwd) { AddParam("password", passwd); }
|
||||
// 是否隐藏批注和应用修订,默认为
|
||||
void SetComment(const int comment) {
|
||||
AddParam("comment", std::to_string(comment));
|
||||
}
|
||||
|
||||
// 表格文件转换纸张方向,0代表垂直方向,非0代表水平方向,默认为0
|
||||
void SetExcelPaperDirection(const int direction) {
|
||||
AddParam("excelPaperDirection", std::to_string(direction));
|
||||
}
|
||||
|
||||
// 生成预览图的图片质量,取值范围 [1-100],默认值100。
|
||||
// 例:值为100,代表生成图片质量为100%
|
||||
void SetQuality(const int quality) {
|
||||
AddParam("quality", std::to_string(quality));
|
||||
}
|
||||
|
||||
// 预览图片的缩放参数,取值范围[10-200], 默认值100。
|
||||
// 例:值为200,代表图片缩放比例为200% 即放大两倍
|
||||
void SetScale(const int scale) { AddParam("scale", std::to_string(scale)); }
|
||||
};
|
||||
|
||||
class CreateDocProcessJobsReq : public BucketReq {
|
||||
public:
|
||||
CreateDocProcessJobsReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("POST");
|
||||
SetPath("/doc_jobs");
|
||||
SetHttps();
|
||||
AddHeader("Content-Type", "application/xml");
|
||||
m_tag = "DocProcess";
|
||||
}
|
||||
|
||||
virtual ~CreateDocProcessJobsReq() {}
|
||||
|
||||
void SetTag(const std::string& tag) { m_tag = tag; }
|
||||
void SetOperation(const Operation& operation) { m_operation = operation; }
|
||||
void SetInput(const Input& input) { m_input = input; }
|
||||
void SetQueueId(const std::string& queue_id) { m_queue_id = queue_id; }
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
std::string m_tag; // 创建任务的 Tag,目前仅支持:DocProcess
|
||||
Input m_input; // 待操作的文件对象
|
||||
Operation m_operation; // 操作规则
|
||||
std::string m_queue_id; // 任务所在的队列 ID
|
||||
};
|
||||
|
||||
class DescribeDocProcessJobReq : public BucketReq {
|
||||
public:
|
||||
DescribeDocProcessJobReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/doc_jobs");
|
||||
SetHttps();
|
||||
}
|
||||
virtual ~DescribeDocProcessJobReq() {}
|
||||
void SetJobId(const std::string& job_id) { m_path += "/" + job_id; }
|
||||
};
|
||||
|
||||
class DescribeDocProcessJobsReq : public BucketReq {
|
||||
public:
|
||||
DescribeDocProcessJobsReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/doc_jobs");
|
||||
SetHttps();
|
||||
AddParam("tag", "DocProcess");
|
||||
|
||||
AddParam("orderByTime", "Desc");
|
||||
AddParam("size", "10");
|
||||
AddParam("states", "All");
|
||||
}
|
||||
virtual ~DescribeDocProcessJobsReq() {}
|
||||
void SetQueueId(const std::string& queue_id) {
|
||||
AddParam("queueId", queue_id);
|
||||
}
|
||||
void SetOrderByTime(const std::string& order) {
|
||||
AddParam("orderByTime", order);
|
||||
}
|
||||
|
||||
void SetNextToken(const std::string& next_token) {
|
||||
AddParam("nextToken", next_token);
|
||||
}
|
||||
|
||||
void SetSize(const int size) {
|
||||
AddParam("size", StringUtil::IntToString(size));
|
||||
}
|
||||
void SetStates(const std::string& states) { AddParam("states", states); }
|
||||
void SetStartCreationTime(const std::string& start_time) {
|
||||
AddParam("startCreationTime", start_time);
|
||||
}
|
||||
|
||||
void SetEndCreationTime(const std::string& end_time) {
|
||||
AddParam("endCreationTime", end_time);
|
||||
}
|
||||
};
|
||||
|
||||
class DescribeDocProcessQueuesReq : public BucketReq {
|
||||
public:
|
||||
DescribeDocProcessQueuesReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("GET");
|
||||
SetPath("/docqueue");
|
||||
SetHttps();
|
||||
}
|
||||
virtual ~DescribeDocProcessQueuesReq() {}
|
||||
void SetQueueIds(const std::string& queue_ids) {
|
||||
AddParam("queueIds", queue_ids);
|
||||
}
|
||||
void SetState(const std::string& state) { AddParam("state", state); }
|
||||
void SetPageNumber(const std::string& page_number) {
|
||||
AddParam("pageNumber", page_number);
|
||||
}
|
||||
|
||||
void SetPageSize(const std::string& page_size) {
|
||||
AddParam("pageSize", page_size);
|
||||
}
|
||||
};
|
||||
|
||||
class UpdateDocProcessQueueReq : public BucketReq {
|
||||
public:
|
||||
UpdateDocProcessQueueReq(const std::string& bucket_name)
|
||||
: BucketReq(bucket_name) {
|
||||
SetMethod("PUT");
|
||||
SetPath("/docqueue");
|
||||
AddHeader("Content-Type", "application/xml");
|
||||
SetHttps();
|
||||
}
|
||||
virtual ~UpdateDocProcessQueueReq() {}
|
||||
void SetQueueId(const std::string& queue_id) {
|
||||
m_queue_id = queue_id;
|
||||
m_path.append("/" + queue_id);
|
||||
}
|
||||
|
||||
void SetName(const std::string& name) { m_name = name; }
|
||||
void SetState(const std::string& state) { m_state = state; }
|
||||
void SetNotifyConfig(const NotifyConfig& notify_config) {
|
||||
m_notify_config = notify_config;
|
||||
}
|
||||
bool GenerateRequestBody(std::string* body) const;
|
||||
|
||||
private:
|
||||
std::string m_name; // 队列名称
|
||||
std::string m_queue_id; // 队列 ID
|
||||
std::string m_state; // 队列状态
|
||||
NotifyConfig m_notify_config; // 通知渠道
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 11/14/17
|
||||
// Description:
|
||||
|
||||
#ifndef SERVICE_REQ_H
|
||||
#define SERVICE_REQ_H
|
||||
#pragma once
|
||||
|
||||
#include "cos_defines.h"
|
||||
#include "request/base_req.h"
|
||||
#include "util/string_util.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class GetServiceReq : public BaseReq {
|
||||
public:
|
||||
GetServiceReq() {
|
||||
SetMethod("GET");
|
||||
SetPath("/");
|
||||
}
|
||||
|
||||
virtual ~GetServiceReq() {}
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
|
||||
#endif // SERVICE_REQ_H
|
||||
@@ -0,0 +1,102 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/18/17
|
||||
// Description:
|
||||
|
||||
#ifndef BASERESP_H
|
||||
#define BASERESP_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cos_defines.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
// 封装HTTP调用成功时的返回信息, 包括header和body
|
||||
// CosResult::IsSucc返回true时, 调用其子类的Get方法获取具体字段
|
||||
class BaseResp {
|
||||
public:
|
||||
BaseResp() {}
|
||||
virtual ~BaseResp() {}
|
||||
|
||||
// debug使用
|
||||
virtual std::string DebugString() const {
|
||||
std::string ret;
|
||||
for (std::map<std::string, std::string>::const_iterator c_itr = m_headers.begin();
|
||||
c_itr != m_headers.end(); ++c_itr) {
|
||||
ret += c_itr->first + " = " + c_itr->second + "\n";
|
||||
}
|
||||
ret += m_body_str;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetHeader(const std::string& key) const;
|
||||
std::map<std::string, std::string> GetHeaders() const { return m_headers; }
|
||||
std::map<std::string, std::string>* GetHeadersPtr() { return &m_headers; }
|
||||
void SetHeaders(const std::map<std::string, std::string>& headers) { m_headers = headers; }
|
||||
|
||||
// ==========================头部相关==============================
|
||||
//TODO 头部可以不需要解析
|
||||
virtual void ParseFromHeaders(const std::map<std::string, std::string>& headers);
|
||||
uint64_t GetContentLength() const { return m_content_length; }
|
||||
std::string GetContentType() const { return m_content_type; }
|
||||
std::string GetEtag() const { return m_etag; }
|
||||
std::string GetCrc64Ecma() const { return m_crc64ecma; }
|
||||
std::string GetConnection() const { return m_connection; }
|
||||
std::string GetDate() const { return m_date; }
|
||||
std::string GetServer() const { return m_server; }
|
||||
std::string GetXCosRequestId() const { return m_x_cos_request_id; }
|
||||
std::string GetXCosTraceId() const { return m_x_cos_trace_id; }
|
||||
|
||||
void SetContentLength(uint64_t content_length) { m_content_length = content_length; }
|
||||
void SetContentType(const std::string& content_type) { m_content_type = content_type; }
|
||||
void SetEtag(const std::string& etag);
|
||||
void SetConnection(const std::string& conn) { m_connection = conn; }
|
||||
void SetDate(const std::string& date) { m_date = date; }
|
||||
void SetServer(const std::string& server) { m_server = server; }
|
||||
void SetXCosRequestId(const std::string& id) { m_x_cos_request_id = id; }
|
||||
void SetXCosTraceId(const std::string& id) { m_x_cos_trace_id = id; }
|
||||
|
||||
// ==========================响应体================================
|
||||
// 解析响应体的XML字符串
|
||||
virtual bool ParseFromXmlString(const std::string& body) { return true; }
|
||||
void SetBody(const std::string& body) { m_body_str = body; }
|
||||
const std::string& GetBody() const { return m_body_str; }
|
||||
std::string* GetBodyPtr() { return &m_body_str; }
|
||||
|
||||
void CopyFrom(const BaseResp& resp) { InternalCopyFrom(resp);}
|
||||
|
||||
protected:
|
||||
bool ParseFromACLXMLString(const std::string& body,
|
||||
std::string* owner_id,
|
||||
std::string* owner_display_name,
|
||||
std::vector<Grant>* acl);
|
||||
|
||||
void InternalCopyFrom(const BaseResp& resp);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> m_headers;
|
||||
std::string m_body_str;
|
||||
|
||||
// 公共头部字段
|
||||
uint64_t m_content_length;
|
||||
std::string m_content_type;
|
||||
std::string m_etag;
|
||||
std::string m_crc64ecma;
|
||||
std::string m_connection;
|
||||
std::string m_date;
|
||||
std::string m_server;
|
||||
std::string m_x_cos_request_id;
|
||||
std::string m_x_cos_trace_id;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
|
||||
#endif // BASERESP_H
|
||||
@@ -0,0 +1,647 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/21/17
|
||||
// Description:
|
||||
|
||||
#ifndef BUCKET_RESP_H
|
||||
#define BUCKET_RESP_H
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "cos_config.h"
|
||||
#include "cos_defines.h"
|
||||
#include "response/base_resp.h"
|
||||
|
||||
#include "rapidxml/1.13/rapidxml.hpp"
|
||||
#include "rapidxml/1.13/rapidxml_print.hpp"
|
||||
#include "rapidxml/1.13/rapidxml_utils.hpp"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class PutBucketResp : public BaseResp {
|
||||
public:
|
||||
PutBucketResp() {}
|
||||
virtual ~PutBucketResp() {}
|
||||
};
|
||||
|
||||
class HeadBucketResp : public BaseResp {
|
||||
public:
|
||||
HeadBucketResp() {}
|
||||
virtual ~HeadBucketResp() {}
|
||||
};
|
||||
|
||||
class GetBucketResp : public BaseResp {
|
||||
public:
|
||||
GetBucketResp() {}
|
||||
virtual ~GetBucketResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
/// \brief 获取Bucket中Object对应的元信息
|
||||
std::vector<Content> GetContents() const { return m_contents; }
|
||||
|
||||
/// \brief Bucket名称
|
||||
std::string GetName() const { return m_name; }
|
||||
|
||||
/// \brief 获取定界符
|
||||
std::string GetDelimiter() const { return m_delimiter; }
|
||||
|
||||
/// \brief 编码格式
|
||||
std::string GetEncodingType() const { return m_encoding_type; }
|
||||
|
||||
/// \brief 返回的文件前缀
|
||||
std::string GetPrefix() const { return m_prefix; }
|
||||
|
||||
/// \brief 默认以UTF-8二进制顺序列出条目,所有列出条目从marker开始
|
||||
std::string GetMarker() const { return m_marker; }
|
||||
|
||||
/// \brief 单次响应请求内返回结果的最大的条目数量
|
||||
uint64_t GetMaxKeys() const { return m_max_keys; }
|
||||
|
||||
/// \brief 响应请求条目是否被截断,布尔值:true,false
|
||||
bool IsTruncated() const { return m_is_truncated; }
|
||||
|
||||
/// \brief 假如返回条目被截断,则返回 NextMarker 就是下一个条目的起点
|
||||
std::string GetNextMarker() const { return m_next_marker; }
|
||||
|
||||
/// \brief 将 Prefix 到 delimiter 之间的相同路径归为一类,定义为 Common Prefix
|
||||
std::vector<std::string> GetCommonPrefixes() const { return m_common_prefixes; }
|
||||
|
||||
private:
|
||||
std::vector<Content> m_contents;
|
||||
std::string m_name;
|
||||
std::string m_encoding_type;
|
||||
std::string m_delimiter;
|
||||
std::string m_prefix;
|
||||
std::string m_marker;
|
||||
uint64_t m_max_keys;
|
||||
bool m_is_truncated;
|
||||
std::string m_next_marker;
|
||||
std::vector<std::string> m_common_prefixes;
|
||||
};
|
||||
|
||||
class DeleteBucketResp : public BaseResp {
|
||||
public:
|
||||
DeleteBucketResp() {}
|
||||
virtual ~DeleteBucketResp() {}
|
||||
};
|
||||
|
||||
class GetBucketVersioningResp : public BaseResp {
|
||||
public:
|
||||
GetBucketVersioningResp() : m_status(0) {}
|
||||
virtual ~GetBucketVersioningResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
/// \brief 返回bucket的版本状态,0: 从未开启版本管理, 1: 版本管理生效中, 2: 暂停
|
||||
/// 区别于PutBucketVersioning, 一个Bucket可能处于三种状态
|
||||
int GetStatus() const { return m_status; }
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
};
|
||||
|
||||
class PutBucketVersioningResp : public BaseResp {
|
||||
public:
|
||||
PutBucketVersioningResp() {}
|
||||
virtual ~PutBucketVersioningResp() {}
|
||||
};
|
||||
|
||||
class GetBucketReplicationResp : public BaseResp {
|
||||
public:
|
||||
GetBucketReplicationResp() {}
|
||||
virtual ~GetBucketReplicationResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetRole() const { return m_role; }
|
||||
|
||||
std::vector<ReplicationRule> GetRules() const { return m_rules; }
|
||||
|
||||
private:
|
||||
std::string m_role;
|
||||
std::vector<ReplicationRule> m_rules;
|
||||
};
|
||||
|
||||
class PutBucketReplicationResp : public BaseResp {
|
||||
public:
|
||||
PutBucketReplicationResp() {}
|
||||
virtual ~PutBucketReplicationResp() {}
|
||||
};
|
||||
|
||||
class DeleteBucketReplicationResp : public BaseResp {
|
||||
public:
|
||||
DeleteBucketReplicationResp() {}
|
||||
virtual ~DeleteBucketReplicationResp() {}
|
||||
};
|
||||
|
||||
class GetBucketLifecycleResp : public BaseResp {
|
||||
public:
|
||||
GetBucketLifecycleResp() {}
|
||||
virtual ~GetBucketLifecycleResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::vector<LifecycleRule> GetRules() const { return m_rules; }
|
||||
|
||||
private:
|
||||
std::vector<LifecycleRule> m_rules;
|
||||
};
|
||||
|
||||
class PutBucketLifecycleResp : public BaseResp {
|
||||
public:
|
||||
PutBucketLifecycleResp() {}
|
||||
virtual ~PutBucketLifecycleResp() {}
|
||||
};
|
||||
|
||||
class DeleteBucketLifecycleResp : public BaseResp {
|
||||
public:
|
||||
DeleteBucketLifecycleResp() {}
|
||||
virtual ~DeleteBucketLifecycleResp() {}
|
||||
};
|
||||
|
||||
class GetBucketACLResp : public BaseResp {
|
||||
public:
|
||||
GetBucketACLResp() {}
|
||||
virtual ~GetBucketACLResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetOwnerID() const { return m_owner_id; }
|
||||
std::string GetOwnerDisplayName() const { return m_owner_display_name; }
|
||||
std::vector<Grant> GetAccessControlList() const { return m_acl; }
|
||||
|
||||
private:
|
||||
std::string m_owner_id;
|
||||
std::string m_owner_display_name;
|
||||
std::vector<Grant> m_acl;
|
||||
};
|
||||
|
||||
// TODO
|
||||
class ListMultipartUploadResp : public BaseResp {
|
||||
public:
|
||||
ListMultipartUploadResp() {}
|
||||
virtual ~ListMultipartUploadResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
/// \brief 获取Bucket中Object对应的元信息
|
||||
std::vector<Upload> GetUpload() const { return m_upload; }
|
||||
|
||||
/// \brief Bucket名称
|
||||
std::string GetName() const { return m_name; }
|
||||
|
||||
/// \brief 编码格式
|
||||
std::string GetEncodingType() const { return m_encoding_type; }
|
||||
|
||||
/// \brief 默认以UTF-8二进制顺序列出条目,所有列出条目从marker开始
|
||||
std::string GetMarker() const { return m_marker; }
|
||||
|
||||
std::string GetUploadIdMarker() const { return m_uploadid_marker; }
|
||||
|
||||
std::string GetNextKeyMarker() const { return m_nextkey_marker; }
|
||||
|
||||
std::string GetNextUploadIdMarker() const { return m_nextuploadid_marker; }
|
||||
|
||||
std::string GetMaxUploads () const { return m_max_uploads; }
|
||||
|
||||
/// \brief 响应请求条目是否被截断,布尔值:true,false
|
||||
bool IsTruncated() const { return m_is_truncated; }
|
||||
|
||||
/// \brief 返回的文件前缀
|
||||
std::string GetPrefix() const { return m_prefix; }
|
||||
|
||||
/// \brief 获取定界符
|
||||
std::string GetDelimiter() const { return m_delimiter; }
|
||||
|
||||
/// \brief 将 Prefix 到 delimiter 之间的相同路径归为一类,定义为 Common Prefix
|
||||
std::vector<std::string> GetCommonPrefixes() const { return m_common_prefixes; }
|
||||
|
||||
private:
|
||||
std::vector<Upload> m_upload;
|
||||
std::string m_name;
|
||||
std::string m_encoding_type;
|
||||
std::string m_delimiter;
|
||||
std::string m_prefix;
|
||||
std::string m_marker;
|
||||
std::string m_uploadid_marker;
|
||||
std::string m_nextkey_marker;
|
||||
std::string m_nextuploadid_marker;
|
||||
std::string m_max_uploads;
|
||||
bool m_is_truncated;
|
||||
std::vector<std::string> m_common_prefixes;
|
||||
|
||||
};
|
||||
|
||||
class PutBucketACLResp : public BaseResp {
|
||||
public:
|
||||
PutBucketACLResp() {}
|
||||
virtual ~PutBucketACLResp() {}
|
||||
};
|
||||
|
||||
class GetBucketCORSResp : public BaseResp {
|
||||
public:
|
||||
GetBucketCORSResp() {}
|
||||
virtual ~GetBucketCORSResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::vector<CORSRule> GetCORSRules() const { return m_rules; }
|
||||
|
||||
private:
|
||||
std::vector<CORSRule> m_rules;
|
||||
};
|
||||
|
||||
class PutBucketCORSResp : public BaseResp {
|
||||
public:
|
||||
PutBucketCORSResp() {}
|
||||
virtual ~PutBucketCORSResp() {}
|
||||
};
|
||||
|
||||
class DeleteBucketCORSResp : public BaseResp {
|
||||
public:
|
||||
DeleteBucketCORSResp() {}
|
||||
virtual ~DeleteBucketCORSResp() {}
|
||||
};
|
||||
|
||||
class GetBucketLocationResp : public BaseResp {
|
||||
public:
|
||||
GetBucketLocationResp() {}
|
||||
virtual ~GetBucketLocationResp() {}
|
||||
|
||||
std::string GetLocation() const { return m_location; }
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
private:
|
||||
std::string m_location;
|
||||
};
|
||||
|
||||
class GetBucketObjectVersionsResp : public BaseResp {
|
||||
public:
|
||||
GetBucketObjectVersionsResp() {}
|
||||
virtual ~GetBucketObjectVersionsResp() {}
|
||||
|
||||
/// \brief 编码格式
|
||||
std::string GetEncodingType() const { return m_encoding_type; }
|
||||
|
||||
/// \brief 返回的文件前缀
|
||||
std::string GetPrefix() const { return m_prefix; }
|
||||
|
||||
/// \brief 单次响应请求内返回结果的最大的条目数量
|
||||
uint64_t GetMaxKeys() const { return m_max_keys; }
|
||||
|
||||
/// \brief 响应请求条目是否被截断,布尔值:true,false
|
||||
bool IsTruncated() const { return m_is_truncated; }
|
||||
|
||||
/// \brief 假如返回条目被截断,则返回 NextKeyMarker 就是下一个条目的起点
|
||||
std::string GetNextKeyMarker() const { return m_next_key_marker; }
|
||||
|
||||
std::string GetKeyMarker() const { return m_key_marker; }
|
||||
|
||||
std::string GetBucketName() const { return m_bucket_name; }
|
||||
|
||||
std::string GetVersionIdMarker() const { return m_version_id_marker; }
|
||||
|
||||
std::vector<COSVersionSummary> GetVersionSummary() const { return m_summaries; }
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
private:
|
||||
std::vector<COSVersionSummary> m_summaries;
|
||||
std::string m_encoding_type;
|
||||
bool m_is_truncated;
|
||||
uint64_t m_max_keys;
|
||||
std::string m_bucket_name;
|
||||
std::string m_key_marker;
|
||||
std::string m_prefix;
|
||||
std::string m_version_id_marker;
|
||||
std::string m_next_key_marker;
|
||||
std::string m_next_version_id_marker;
|
||||
};
|
||||
|
||||
class PutBucketLoggingResp : public BaseResp {
|
||||
public:
|
||||
PutBucketLoggingResp() {}
|
||||
virtual ~PutBucketLoggingResp() {}
|
||||
};
|
||||
|
||||
class GetBucketLoggingResp : public BaseResp {
|
||||
public:
|
||||
GetBucketLoggingResp() {}
|
||||
virtual ~GetBucketLoggingResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
LoggingEnabled GetLoggingEnabled() const {
|
||||
return m_rules;
|
||||
}
|
||||
|
||||
private:
|
||||
LoggingEnabled m_rules;
|
||||
};
|
||||
|
||||
class PutBucketDomainResp : public BaseResp {
|
||||
public:
|
||||
PutBucketDomainResp() {}
|
||||
virtual ~PutBucketDomainResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
DomainErrorMsg GetDomainErrorMsg() const {
|
||||
return m_rules;
|
||||
}
|
||||
private:
|
||||
DomainErrorMsg m_rules;
|
||||
};
|
||||
|
||||
class GetBucketDomainResp : public BaseResp {
|
||||
public:
|
||||
GetBucketDomainResp() {}
|
||||
virtual ~GetBucketDomainResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetStatus() const {
|
||||
return m_status;
|
||||
}
|
||||
|
||||
std::string GetName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
std::string GetType() const {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
void SetStatus(const std::string& status) {
|
||||
m_status = status;
|
||||
}
|
||||
|
||||
void SetName(const std::string& name) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
void SetType(const std::string& type) {
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_status;
|
||||
std::string m_name;
|
||||
std::string m_type;
|
||||
};
|
||||
|
||||
class PutBucketWebsiteResp : public BaseResp {
|
||||
public:
|
||||
PutBucketWebsiteResp() {}
|
||||
virtual ~PutBucketWebsiteResp() {}
|
||||
};
|
||||
|
||||
|
||||
class GetBucketWebsiteResp : public BaseResp {
|
||||
public:
|
||||
GetBucketWebsiteResp() {}
|
||||
virtual ~GetBucketWebsiteResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
bool ParseFromXmlRoutingRule(rapidxml::xml_node<>* node, RoutingRule& tmp_routingrule);
|
||||
|
||||
void SetSuffix(const std::string& suffix) {
|
||||
m_suffix = suffix;
|
||||
}
|
||||
|
||||
void SetProtocol(const std::string& protocol) {
|
||||
m_protocol = protocol;
|
||||
}
|
||||
|
||||
void SetKey(const std::string& key) {
|
||||
m_key = key;
|
||||
}
|
||||
|
||||
std::string GetSuffix() const {
|
||||
return m_suffix;
|
||||
}
|
||||
|
||||
std::string GetProtocol() const {
|
||||
return m_protocol;
|
||||
}
|
||||
|
||||
std::string GetKey() const {
|
||||
return m_key;
|
||||
}
|
||||
|
||||
/// 设置重定向规则
|
||||
void SetRoutingRules(const std::vector<RoutingRule>& routingrules) {
|
||||
m_routingrules = routingrules;
|
||||
}
|
||||
|
||||
std::vector<RoutingRule> GetRoutingRules() const {
|
||||
return m_routingrules;
|
||||
}
|
||||
|
||||
/// 添加单个rule
|
||||
void AddRoutingRule(const RoutingRule& routingrule) {
|
||||
m_routingrules.push_back(routingrule);
|
||||
}
|
||||
|
||||
/// 清空重定向规则
|
||||
void ClearRoutingRule() {
|
||||
std::vector<RoutingRule> tmp;
|
||||
m_routingrules.swap(tmp);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_suffix;
|
||||
std::string m_protocol;
|
||||
std::string m_key;
|
||||
std::vector<RoutingRule> m_routingrules;
|
||||
};
|
||||
|
||||
class DeleteBucketWebsiteResp : public BaseResp {
|
||||
public:
|
||||
DeleteBucketWebsiteResp() {}
|
||||
virtual ~DeleteBucketWebsiteResp() {}
|
||||
};
|
||||
|
||||
class PutBucketTaggingResp : public BaseResp {
|
||||
public:
|
||||
PutBucketTaggingResp() {}
|
||||
virtual ~PutBucketTaggingResp() {}
|
||||
};
|
||||
|
||||
class GetBucketTaggingResp : public BaseResp {
|
||||
public:
|
||||
GetBucketTaggingResp() {}
|
||||
|
||||
void SetTagSet(std::vector<Tag>& tagset) {
|
||||
m_tagset = tagset;
|
||||
}
|
||||
|
||||
std::vector<Tag> GetTagSet() const {
|
||||
return m_tagset;
|
||||
}
|
||||
|
||||
//清除tag规则.
|
||||
void ClearTagSet() {
|
||||
std::vector<Tag> temp;
|
||||
m_tagset.swap(temp);
|
||||
}
|
||||
|
||||
/// 添加单个tag.
|
||||
void AddTag(const Tag& tag) {
|
||||
m_tagset.push_back(tag);
|
||||
}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
virtual ~GetBucketTaggingResp() {}
|
||||
private:
|
||||
std::vector<Tag> m_tagset;
|
||||
};
|
||||
|
||||
class DeleteBucketTaggingResp : public BaseResp {
|
||||
public:
|
||||
DeleteBucketTaggingResp() {}
|
||||
virtual ~DeleteBucketTaggingResp() {}
|
||||
};
|
||||
|
||||
class PutBucketInventoryResp : public BaseResp {
|
||||
public:
|
||||
PutBucketInventoryResp() {}
|
||||
virtual ~PutBucketInventoryResp() {}
|
||||
};
|
||||
|
||||
class GetBucketInventoryResp : public BaseResp {
|
||||
public:
|
||||
GetBucketInventoryResp(): m_mask(0x00000001u) {}
|
||||
|
||||
void SetInventory(const Inventory& inventory) {
|
||||
m_mask = m_mask | 0x00000001u;
|
||||
m_inventory = inventory;
|
||||
}
|
||||
|
||||
bool HasInventory() const {
|
||||
return (m_mask & 0x00000001u) != 0;
|
||||
}
|
||||
|
||||
const Inventory& GetInventory() const {
|
||||
return m_inventory;
|
||||
}
|
||||
|
||||
bool ParseFromXmlOptionalFields(rapidxml::xml_node<>*node, Inventory &temp_inventory);
|
||||
bool ParseFromXmlCOSBucketDestination(rapidxml::xml_node<>* node, Inventory &temp_inventory);
|
||||
bool ParseFromXmlInventoryConfiguration(rapidxml::xml_node<>* node, Inventory &temp_inventory);
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
virtual ~GetBucketInventoryResp() {}
|
||||
|
||||
private:
|
||||
uint64_t m_mask;
|
||||
Inventory m_inventory;
|
||||
};
|
||||
|
||||
|
||||
class ListBucketInventoryConfigurationsResp : public GetBucketInventoryResp {
|
||||
public:
|
||||
ListBucketInventoryConfigurationsResp(): m_is_truncated(false),
|
||||
m_continuation_token(""), m_next_continuation_token("") {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
virtual ~ListBucketInventoryConfigurationsResp() {}
|
||||
|
||||
/// 添加单个Inventory.
|
||||
void AddInventory(const Inventory& inventory) {
|
||||
m_inventory_vec.push_back(inventory);
|
||||
}
|
||||
|
||||
void SetInventoryVec(std::vector<Inventory>& inventory_vec) {
|
||||
m_inventory_vec = inventory_vec;
|
||||
}
|
||||
|
||||
void SetIsTruncated(bool is_truncated) {
|
||||
m_is_truncated = is_truncated;
|
||||
}
|
||||
|
||||
void SetContinuationToken(std::string continuation_token) {
|
||||
m_continuation_token = continuation_token;
|
||||
}
|
||||
|
||||
void SetNextContinuationToken(std::string next_continuation_token) {
|
||||
m_next_continuation_token = next_continuation_token;
|
||||
}
|
||||
|
||||
std::vector<Inventory> GetInventory() const {
|
||||
return m_inventory_vec;
|
||||
}
|
||||
|
||||
bool GetIsTruncated() const {
|
||||
return m_is_truncated;
|
||||
}
|
||||
|
||||
std::string GetContinuationToken() const {
|
||||
return m_continuation_token;
|
||||
}
|
||||
|
||||
std::string GetNextContinuationToken() const {
|
||||
return m_next_continuation_token;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Inventory> m_inventory_vec;
|
||||
bool m_is_truncated;
|
||||
std::string m_continuation_token;
|
||||
std::string m_next_continuation_token;
|
||||
};
|
||||
|
||||
class DeleteBucketInventoryResp : public BaseResp {
|
||||
public:
|
||||
DeleteBucketInventoryResp() {}
|
||||
virtual ~DeleteBucketInventoryResp() {}
|
||||
};
|
||||
|
||||
/// \brief: 列举直播通道响应
|
||||
class ListLiveChannelResp : public BaseResp {
|
||||
public:
|
||||
ListLiveChannelResp() {}
|
||||
virtual ~ListLiveChannelResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
const ListLiveChannelResult &GetListResult() const {
|
||||
return result;
|
||||
}
|
||||
void ClearResult() {
|
||||
result.Clear();
|
||||
}
|
||||
private:
|
||||
ListLiveChannelResult result;
|
||||
};
|
||||
|
||||
/// \brief: 配置存储桶智能分层的响应
|
||||
class PutBucketIntelligentTieringResp : public BaseResp {
|
||||
public:
|
||||
PutBucketIntelligentTieringResp() {}
|
||||
virtual ~PutBucketIntelligentTieringResp() {}
|
||||
};
|
||||
|
||||
/// \brief: 获取配置存储桶智能分层配置的响应
|
||||
class GetBucketIntelligentTieringResp : public BaseResp {
|
||||
public:
|
||||
GetBucketIntelligentTieringResp() {}
|
||||
virtual ~GetBucketIntelligentTieringResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
std::string GetStatus() const {
|
||||
return m_status;
|
||||
}
|
||||
uint32_t GetDays() const {
|
||||
return m_days;
|
||||
}
|
||||
uint32_t GetRequestFrequent() const {
|
||||
return m_freq;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_status;
|
||||
int m_days;
|
||||
int m_freq;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // BUCKET_RESP_H
|
||||
@@ -0,0 +1,189 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "rapidxml/1.13/rapidxml.hpp"
|
||||
#include "rapidxml/1.13/rapidxml_print.hpp"
|
||||
#include "rapidxml/1.13/rapidxml_utils.hpp"
|
||||
#include "request/data_process_req.h"
|
||||
#include "response/object_resp.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class ImageRespBase : virtual public BaseResp {
|
||||
public:
|
||||
ImageRespBase() {}
|
||||
|
||||
virtual ~ImageRespBase() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
UploadResult GetUploadResult() const { return m_upload_result; }
|
||||
|
||||
static bool ParseObject(rapidxml::xml_node<>* root, Object& object);
|
||||
static bool ParseQRcodeInfo(rapidxml::xml_node<>* root, QRcodeInfo& qr_code);
|
||||
|
||||
protected:
|
||||
bool ParseOriginalInfo(rapidxml::xml_node<>* root);
|
||||
UploadResult m_upload_result;
|
||||
};
|
||||
|
||||
class PutImageByFileResp : public ImageRespBase, public PutObjectByFileResp {
|
||||
public:
|
||||
PutImageByFileResp() {}
|
||||
virtual ~PutImageByFileResp() {}
|
||||
};
|
||||
|
||||
class CloudImageProcessResp : public ImageRespBase {
|
||||
public:
|
||||
CloudImageProcessResp() {}
|
||||
virtual ~CloudImageProcessResp() {}
|
||||
};
|
||||
|
||||
class GetQRcodeResp : public BaseResp {
|
||||
public:
|
||||
GetQRcodeResp() {}
|
||||
virtual ~GetQRcodeResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
GetQRcodeResult GetResult() const { return m_result; }
|
||||
|
||||
private:
|
||||
GetQRcodeResult m_result;
|
||||
};
|
||||
|
||||
class DescribeDocProcessBucketsResp : public BaseResp {
|
||||
public:
|
||||
DescribeDocProcessBucketsResp() {}
|
||||
virtual ~DescribeDocProcessBucketsResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
DocBucketResponse GetResult() const { return m_result; }
|
||||
|
||||
private:
|
||||
bool ParseDocBucketList(rapidxml::xml_node<>* root,
|
||||
DocBucketList& bucket_list);
|
||||
DocBucketResponse m_result;
|
||||
};
|
||||
|
||||
class DocPreviewResp : public GetObjectByFileResp {
|
||||
public:
|
||||
DocPreviewResp() {}
|
||||
virtual ~DocPreviewResp() {}
|
||||
|
||||
void ParseFromHeaders(const std::map<std::string, std::string>& headers);
|
||||
|
||||
// 返回文档总页数(表格文件表示当前 sheet 转换后的总图片数),异常时为空
|
||||
int GetTotalPage() const { return m_x_total_page; }
|
||||
// 当异常时返回错误码
|
||||
std::string GetErrNo() const { return m_x_errno; }
|
||||
// 返回文档中总表数
|
||||
int GetTotalSheet() const { return m_x_total_sheet; }
|
||||
// 返回当前 sheet 名
|
||||
std::string GetSheetName() const { return m_sheet_name; }
|
||||
|
||||
private:
|
||||
int m_x_total_page;
|
||||
std::string m_x_errno;
|
||||
int m_x_total_sheet;
|
||||
std::string m_sheet_name;
|
||||
};
|
||||
|
||||
class DocProcessJobBase : public BaseResp {
|
||||
public:
|
||||
DocProcessJobBase() {}
|
||||
virtual ~DocProcessJobBase() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
JobsDetail GetJobsDetail() const { return m_jobs_detail; }
|
||||
|
||||
protected:
|
||||
bool ParseJobsDetail(rapidxml::xml_node<>* root, JobsDetail& jobs_detail);
|
||||
bool ParseOperation(rapidxml::xml_node<>* root, Operation& operation);
|
||||
bool ParseDocProcess(rapidxml::xml_node<>* root, DocProcess& doc_process);
|
||||
bool ParseDocProcessResult(rapidxml::xml_node<>* root,
|
||||
DocProcessResult& doc_process_result);
|
||||
|
||||
private:
|
||||
JobsDetail m_jobs_detail;
|
||||
};
|
||||
|
||||
class CreateDocProcessJobsResp : public DocProcessJobBase {
|
||||
public:
|
||||
CreateDocProcessJobsResp() {}
|
||||
virtual ~CreateDocProcessJobsResp() {}
|
||||
};
|
||||
|
||||
class DescribeDocProcessJobResp : public DocProcessJobBase {
|
||||
public:
|
||||
DescribeDocProcessJobResp() {}
|
||||
virtual ~DescribeDocProcessJobResp() {}
|
||||
};
|
||||
|
||||
class DescribeDocProcessJobsResp : public DocProcessJobBase {
|
||||
public:
|
||||
DescribeDocProcessJobsResp() {}
|
||||
virtual ~DescribeDocProcessJobsResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::vector<JobsDetail> GetJobsDetails() const { return m_jobs_details; }
|
||||
|
||||
std::string GetNextToken() const { return m_next_token; }
|
||||
|
||||
private:
|
||||
std::vector<JobsDetail> m_jobs_details;
|
||||
std::string m_next_token;
|
||||
};
|
||||
|
||||
class DocProcessQueueBase : public BaseResp {
|
||||
public:
|
||||
DocProcessQueueBase() {}
|
||||
virtual ~DocProcessQueueBase() {}
|
||||
|
||||
protected:
|
||||
bool ParseNonExistPIDs(rapidxml::xml_node<>* root,
|
||||
NonExistPIDs& non_exist_pids);
|
||||
bool ParseQueueList(rapidxml::xml_node<>* root, QueueList& queue_list);
|
||||
};
|
||||
|
||||
class DescribeDocProcessQueuesResp : public DocProcessQueueBase {
|
||||
public:
|
||||
DescribeDocProcessQueuesResp() {}
|
||||
virtual ~DescribeDocProcessQueuesResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
int GetTotalCount() const { return m_total_count; }
|
||||
std::string GetRequestId() const { return m_request_id; }
|
||||
int GetPageNumber() const { return m_page_number; }
|
||||
int GetPageSize() const { return m_page_size; }
|
||||
QueueList GetQueueList() const { return m_queue_list; }
|
||||
NonExistPIDs GetNonExistPIDs() const { return m_non_exist_pids; }
|
||||
|
||||
private:
|
||||
int m_total_count;
|
||||
std::string m_request_id;
|
||||
int m_page_number;
|
||||
int m_page_size;
|
||||
QueueList m_queue_list;
|
||||
NonExistPIDs m_non_exist_pids;
|
||||
};
|
||||
|
||||
class UpdateDocProcessQueueResp : public DocProcessQueueBase {
|
||||
public:
|
||||
UpdateDocProcessQueueResp() {}
|
||||
virtual ~UpdateDocProcessQueueResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetRequestId() const { return m_request_id; }
|
||||
QueueList GetQueueList() const { return m_queue; }
|
||||
|
||||
private:
|
||||
std::string m_request_id;
|
||||
QueueList m_queue;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
@@ -0,0 +1,685 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/21/17
|
||||
// Description:
|
||||
|
||||
#ifndef OBJECT_RESP_H
|
||||
#define OBJECT_RESP_H
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "cos_config.h"
|
||||
#include "cos_params.h"
|
||||
#include "response/base_resp.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class GetObjectResp : public BaseResp {
|
||||
public:
|
||||
/// \brief 获取object最后被修改的时间, 字符串格式Date, 类似"Wed, 28 Oct 2014 20:30:00 GMT"
|
||||
std::string GetLastModified() const { return m_last_modified; }
|
||||
void SetLastModified(const std::string& last_modified) {
|
||||
m_last_modified = last_modified;
|
||||
}
|
||||
|
||||
/// \brief 获取object type, 表示object是否可以被追加上传,枚举值:normal 或者 appendable
|
||||
std::string GetXCosObjectType() const { return m_x_cos_object_type; }
|
||||
void SetXCosObjectType(const std::string& x_cos_object_type) {
|
||||
m_x_cos_object_type = x_cos_object_type;
|
||||
}
|
||||
|
||||
/// \brief 获取Object 的存储级别,枚举值:STANDARD,STANDARD_IA
|
||||
std::string GetXCosStorageClass() const { return m_x_cos_storage_class; }
|
||||
void SetXCosStorageClass(const std::string& x_cos_storage_class) {
|
||||
m_x_cos_storage_class = x_cos_storage_class;
|
||||
}
|
||||
|
||||
/// \brief 获取自定义的元数据
|
||||
std::map<std::string, std::string> GetXCosMetas() const { return m_x_cos_metas; }
|
||||
/// \brief 获取自定义的元数据
|
||||
std::string GetXCosMeta(const std::string& key) const {
|
||||
std::map<std::string, std::string>::const_iterator itr = m_x_cos_metas.find(key);
|
||||
if (itr != m_x_cos_metas.end()) {
|
||||
return itr->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
void SetXCosMeta(const std::string& key, const std::string& value) {
|
||||
m_x_cos_metas[key] = value;
|
||||
}
|
||||
|
||||
/// \brief Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
|
||||
void ParseFromHeaders(const std::map<std::string, std::string>& headers);
|
||||
|
||||
protected:
|
||||
GetObjectResp() {}
|
||||
virtual ~GetObjectResp() {}
|
||||
|
||||
private:
|
||||
std::string m_last_modified;
|
||||
std::string m_x_cos_object_type;
|
||||
std::string m_x_cos_storage_class;
|
||||
std::map<std::string, std::string> m_x_cos_metas;
|
||||
};
|
||||
|
||||
class GetObjectByStreamResp : public GetObjectResp {
|
||||
public:
|
||||
GetObjectByStreamResp() {}
|
||||
virtual ~GetObjectByStreamResp() {}
|
||||
};
|
||||
|
||||
class GetObjectByFileResp : public GetObjectResp {
|
||||
public:
|
||||
GetObjectByFileResp() {}
|
||||
virtual ~GetObjectByFileResp() {}
|
||||
};
|
||||
|
||||
class MultiGetObjectResp : public GetObjectResp {
|
||||
public:
|
||||
MultiGetObjectResp() {}
|
||||
virtual ~MultiGetObjectResp() {}
|
||||
|
||||
/// Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
};
|
||||
|
||||
class PutObjectResp : virtual public BaseResp {
|
||||
protected:
|
||||
PutObjectResp() {}
|
||||
virtual ~PutObjectResp() {}
|
||||
|
||||
public:
|
||||
/// 获取Object的版本号, 如果Bucket未开启多版本, 返回空字符串
|
||||
std::string GetVersionId() const { return GetHeader("x-cos-version-id"); }
|
||||
|
||||
/// Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
};
|
||||
|
||||
class PutObjectByStreamResp : public PutObjectResp {
|
||||
public:
|
||||
PutObjectByStreamResp() {}
|
||||
virtual ~PutObjectByStreamResp() {}
|
||||
};
|
||||
|
||||
class PutObjectByFileResp : public PutObjectResp {
|
||||
public:
|
||||
PutObjectByFileResp() {}
|
||||
virtual ~PutObjectByFileResp() {}
|
||||
};
|
||||
|
||||
class DeleteObjectResp : public BaseResp {
|
||||
public:
|
||||
DeleteObjectResp() {}
|
||||
virtual ~DeleteObjectResp() {}
|
||||
};
|
||||
|
||||
class DeleteObjectsResp : public BaseResp {
|
||||
public:
|
||||
DeleteObjectsResp() {}
|
||||
virtual ~DeleteObjectsResp() {}
|
||||
|
||||
std::vector<DeletedInfo> GetDeletedInfos() const {
|
||||
return m_deleted_infos;
|
||||
}
|
||||
|
||||
std::vector<ErrorInfo> GetErrorinfos() const {
|
||||
return m_error_infos;
|
||||
}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
private:
|
||||
std::vector<DeletedInfo> m_deleted_infos;
|
||||
std::vector<ErrorInfo> m_error_infos;
|
||||
};
|
||||
|
||||
class HeadObjectResp : public BaseResp {
|
||||
public:
|
||||
HeadObjectResp() : m_x_cos_storage_class(kStorageClassStandard) {}
|
||||
virtual ~HeadObjectResp() {}
|
||||
|
||||
/// \brief 获取object最后被修改的时间, 字符串格式Date, 类似"Wed, 28 Oct 2014 20:30:00 GMT"
|
||||
std::string GetLastModified() const { return m_last_modified; }
|
||||
void SetLastModified(const std::string& last_modified) {
|
||||
m_last_modified = last_modified;
|
||||
}
|
||||
|
||||
/// \brief 获取object type, 表示object是否可以被追加上传,枚举值:normal 或者 appendable
|
||||
std::string GetXCosObjectType() const { return m_x_cos_object_type; }
|
||||
void SetXCosObjectType(const std::string& x_cos_object_type) {
|
||||
m_x_cos_object_type = x_cos_object_type;
|
||||
}
|
||||
|
||||
/// \brief 获取Object 的存储级别,枚举值:STANDARD,STANDARD_IA
|
||||
std::string GetXCosStorageClass() const { return m_x_cos_storage_class; }
|
||||
void SetXCosStorageClass(const std::string& x_cos_storage_class) {
|
||||
m_x_cos_storage_class = x_cos_storage_class;
|
||||
}
|
||||
|
||||
/// \brief 获取自定义的元数据
|
||||
std::map<std::string, std::string> GetXCosMetas() const { return m_x_cos_metas; }
|
||||
/// \brief 获取自定义的元数据
|
||||
std::string GetXCosMeta(const std::string& key) const {
|
||||
std::map<std::string, std::string>::const_iterator itr = m_x_cos_metas.find(key);
|
||||
if (itr != m_x_cos_metas.end()) {
|
||||
return itr->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
void SetXCosMeta(const std::string& key, const std::string& value) {
|
||||
m_x_cos_metas[key] = value;
|
||||
}
|
||||
|
||||
/// \brief 获得 archive 类型对象的当前恢复状态
|
||||
std::string GetXCosRestore() const {
|
||||
return GetHeader("x-cos-restore");
|
||||
}
|
||||
|
||||
/// \brief Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
|
||||
/// \brief 获取Content-Encoding
|
||||
std::string GetContentEncoding() const {
|
||||
return GetHeader("Content-Encoding");
|
||||
}
|
||||
|
||||
/// \brief 获取Cache-Control
|
||||
std::string GetCacheControl() const {
|
||||
return GetHeader("Cache-Control");
|
||||
}
|
||||
|
||||
/// \brief 获取Content-Disposition
|
||||
std::string GetContentDisposition() const {
|
||||
return GetHeader("Content-Disposition");
|
||||
}
|
||||
|
||||
/// \brief 获取Expires
|
||||
std::string GetExpires() const {
|
||||
return GetHeader("Expires");
|
||||
}
|
||||
|
||||
void ParseFromHeaders(const std::map<std::string, std::string>& headers);
|
||||
|
||||
private:
|
||||
std::string m_last_modified;// TODO last_modified属于common header
|
||||
std::string m_x_cos_object_type;
|
||||
std::string m_x_cos_storage_class;
|
||||
std::map<std::string, std::string> m_x_cos_metas;
|
||||
};
|
||||
|
||||
class InitMultiUploadResp : public BaseResp {
|
||||
public:
|
||||
InitMultiUploadResp() {}
|
||||
virtual ~InitMultiUploadResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
/// \brief 获取uploadId, 用于后续上传
|
||||
std::string GetUploadId() const { return m_upload_id; }
|
||||
|
||||
/// \brief 获取Object的名称
|
||||
std::string GetKey() const { return m_key; }
|
||||
|
||||
/// \brief 分片上传的目标Bucket
|
||||
std::string GetBucket() const { return m_bucket; }
|
||||
|
||||
/// \brief Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_bucket;
|
||||
std::string m_key; // object名称
|
||||
std::string m_upload_id;
|
||||
};
|
||||
|
||||
class UploadPartDataResp : public BaseResp {
|
||||
public:
|
||||
UploadPartDataResp() {}
|
||||
virtual ~UploadPartDataResp() {}
|
||||
|
||||
/// \brief Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
};
|
||||
|
||||
class UploadPartCopyDataResp : public BaseResp {
|
||||
public:
|
||||
UploadPartCopyDataResp() {}
|
||||
virtual ~UploadPartCopyDataResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
/// \brief 获取返回文件的MD5算法校验值。
|
||||
/// ETag 的值可以用于检查 Object 的内容是否发生变化。
|
||||
std::string GetEtag() const { return m_etag; }
|
||||
|
||||
/// \brief 返回文件最后修改时间,GMT 格式
|
||||
std::string GetLastModified() const { return m_last_modified; }
|
||||
|
||||
/// \brief Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_etag;
|
||||
std::string m_last_modified;
|
||||
};
|
||||
|
||||
class CompleteMultiUploadResp : public BaseResp {
|
||||
public:
|
||||
CompleteMultiUploadResp() {}
|
||||
virtual ~CompleteMultiUploadResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetLocation() const { return m_location; }
|
||||
std::string GetKey() const { return m_key; }
|
||||
std::string GetBucket() const { return m_bucket; }
|
||||
std::string GetVersionId() const { return GetHeader("x-cos-version-id"); }
|
||||
|
||||
/// \brief Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_location; // Object的外网访问域名
|
||||
std::string m_bucket;
|
||||
std::string m_key;
|
||||
};
|
||||
|
||||
class MultiUploadObjectResp : public BaseResp {
|
||||
public:
|
||||
MultiUploadObjectResp() {}
|
||||
|
||||
virtual ~MultiUploadObjectResp() {}
|
||||
|
||||
std::string GetRespTag() { return m_resp_tag; }
|
||||
|
||||
std::string GetLocation() const { return m_location; }
|
||||
|
||||
std::string GetKey() const { return m_key; }
|
||||
|
||||
std::string GetBucket() const { return m_bucket; }
|
||||
|
||||
void SetLocation(const std::string& location) { m_location = location; }
|
||||
|
||||
void SetKey(const std::string& key) { m_key = key; }
|
||||
|
||||
void SetBucket(const std::string& bucket) { m_bucket = bucket; }
|
||||
|
||||
void CopyFrom(const InitMultiUploadResp& resp);
|
||||
|
||||
void CopyFrom(const UploadPartDataResp& resp);
|
||||
|
||||
void CopyFrom(const CompleteMultiUploadResp& resp);
|
||||
|
||||
/// \brief Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_location; // Object的外网访问域名
|
||||
std::string m_bucket;
|
||||
std::string m_key;
|
||||
std::string m_upload_id;
|
||||
|
||||
// FIXME(sevenyou) 先这么搞吧
|
||||
std::string m_resp_tag; // 用于区分是哪一种response
|
||||
};
|
||||
|
||||
class AbortMultiUploadResp : public BaseResp {
|
||||
public:
|
||||
AbortMultiUploadResp() {}
|
||||
virtual ~AbortMultiUploadResp() {}
|
||||
};
|
||||
|
||||
class ListPartsResp : public BaseResp {
|
||||
public:
|
||||
ListPartsResp() : m_bucket(""), m_encoding_type(""), m_key(""), m_upload_id(""),
|
||||
m_part_number_marker(0), m_parts(0), m_next_part_number_marker(0),
|
||||
m_storage_class(""), m_max_parts(1000), m_is_truncated(false) {}
|
||||
virtual ~ListPartsResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetBucket() const { return m_bucket; }
|
||||
|
||||
std::string GetEncodingType() const { return m_encoding_type; }
|
||||
|
||||
std::string GetKey() const { return m_key; }
|
||||
|
||||
std::string GetUploadId() const { return m_upload_id; }
|
||||
|
||||
Initiator GetInitiator() const { return m_initiator; }
|
||||
|
||||
Owner GetOwner() const { return m_owner; }
|
||||
|
||||
uint64_t GetPartNumberMarker() const { return m_part_number_marker; }
|
||||
|
||||
std::vector<Part> GetParts() const { return m_parts; }
|
||||
|
||||
uint64_t GetNextPartNumberMarker() const { return m_next_part_number_marker; }
|
||||
|
||||
std::string GetStorageClass() const { return m_storage_class; }
|
||||
|
||||
uint64_t GetMaxParts() const { return m_max_parts; }
|
||||
|
||||
bool IsTruncated() const { return m_is_truncated; }
|
||||
|
||||
private:
|
||||
std::string m_bucket;
|
||||
std::string m_encoding_type;
|
||||
std::string m_key;
|
||||
std::string m_upload_id;
|
||||
Initiator m_initiator;
|
||||
Owner m_owner;
|
||||
uint64_t m_part_number_marker;
|
||||
std::vector<Part> m_parts;
|
||||
uint64_t m_next_part_number_marker;
|
||||
std::string m_storage_class;
|
||||
uint64_t m_max_parts;
|
||||
bool m_is_truncated;
|
||||
};
|
||||
|
||||
class GetObjectACLResp : public BaseResp {
|
||||
public:
|
||||
GetObjectACLResp() {}
|
||||
virtual ~GetObjectACLResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetOwnerID() const { return m_owner_id; }
|
||||
std::string GetOwnerDisplayName() const { return m_owner_display_name; }
|
||||
std::vector<Grant> GetAccessControlList() const { return m_acl; }
|
||||
|
||||
private:
|
||||
std::string m_owner_id;
|
||||
std::string m_owner_display_name;
|
||||
std::vector<Grant> m_acl;
|
||||
};
|
||||
|
||||
class PutObjectACLResp : public BaseResp {
|
||||
public:
|
||||
PutObjectACLResp() {}
|
||||
virtual ~PutObjectACLResp() {}
|
||||
};
|
||||
|
||||
class PutObjectCopyResp : public BaseResp {
|
||||
public:
|
||||
PutObjectCopyResp() {}
|
||||
virtual ~PutObjectCopyResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
std::string GetEtag() const { return m_etag; }
|
||||
std::string GetLastModified() const { return m_last_modified; }
|
||||
std::string GetVersionId() const { return m_version_id; }
|
||||
std::string GetCrc64() const { return m_crc64; }
|
||||
|
||||
/// Server端加密使用的算法
|
||||
std::string GetXCosServerSideEncryption() const {
|
||||
return GetHeader("x-cos-server-side-encryption");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_etag;
|
||||
std::string m_last_modified;
|
||||
std::string m_version_id;
|
||||
std::string m_crc64;
|
||||
};
|
||||
|
||||
class CopyResp : public BaseResp {
|
||||
public:
|
||||
CopyResp() : m_location(""), m_bucket(""), m_key(""),
|
||||
m_etag(""), m_last_modified(""), m_version_id(""), m_resp_tag("") {}
|
||||
virtual ~CopyResp() {}
|
||||
|
||||
void CopyFrom(const PutObjectCopyResp& resp);
|
||||
|
||||
void CopyFrom(const CompleteMultiUploadResp& resp);
|
||||
|
||||
void Clear() {
|
||||
m_location = "";
|
||||
m_bucket = "";
|
||||
m_key = "";
|
||||
m_etag = "";
|
||||
m_last_modified = "";
|
||||
m_version_id = "";
|
||||
m_resp_tag = "";
|
||||
}
|
||||
|
||||
std::string GetLocation() const { return m_location; }
|
||||
std::string GetKey() const { return m_key; }
|
||||
std::string GetBucket() const { return m_bucket; }
|
||||
std::string GetEtag() const { return m_etag; }
|
||||
std::string GetLastModified() const { return m_last_modified; }
|
||||
std::string GetVersionId() const { return m_version_id; }
|
||||
std::string GetRespTag() { return m_resp_tag; }
|
||||
|
||||
private:
|
||||
std::string m_location; // Object的外网访问域名
|
||||
std::string m_bucket;
|
||||
std::string m_key;
|
||||
std::string m_etag;
|
||||
std::string m_last_modified;
|
||||
std::string m_version_id;
|
||||
|
||||
std::string m_resp_tag; // 用于区分是哪一种response
|
||||
};
|
||||
|
||||
class PostObjectRestoreResp : public BaseResp {
|
||||
public:
|
||||
PostObjectRestoreResp() {}
|
||||
~PostObjectRestoreResp() {}
|
||||
};
|
||||
|
||||
class OptionsObjectResp : public BaseResp {
|
||||
public:
|
||||
OptionsObjectResp() {}
|
||||
~OptionsObjectResp() {}
|
||||
|
||||
/// \brief 获取模拟跨域访问的请求来源域名,当来源不允许的时候,此Header不返回
|
||||
std::string GetAccessControAllowOrigin() const {
|
||||
return GetHeader("Access-Control-Allow-Origin");
|
||||
}
|
||||
|
||||
/// \brief 获取模拟跨域访问的请求 HTTP 方法,当请求方法不允许的时候,此Header不返回
|
||||
std::string GetAccessControlAllowMethods() const {
|
||||
return GetHeader("Access-Control-Allow-Methods");
|
||||
}
|
||||
|
||||
/// \brief 获取模拟跨域访问的请求头部,当模拟任何请求头部不允许的时候,此Header不返回该请求头部
|
||||
std::string GetAccessControlAllowHeaders() const {
|
||||
return GetHeader("Access-Control-Allow-Headers");
|
||||
}
|
||||
|
||||
/// \brief 获取模拟跨域访问的请求 HTTP 方法,当请求方法不允许的时候,此Header不返回
|
||||
std::string GetAccessControlExposeHeaders() const {
|
||||
return GetHeader("Access-Control-Expose-Headers");
|
||||
}
|
||||
|
||||
/// \brief 获取OPTIONS请求得到结果的有效期
|
||||
std::string GetAccessControlMaxAge() const {
|
||||
return GetHeader("Access-Control-Max-Age");
|
||||
}
|
||||
};
|
||||
|
||||
class SelectObjectContentResp : public BaseResp {
|
||||
public:
|
||||
SelectObjectContentResp() {
|
||||
resp_data.reserve(10);
|
||||
}
|
||||
~SelectObjectContentResp() {}
|
||||
|
||||
/// \brief 将响应结果写入本地文件
|
||||
int WriteResultToLocalFile(const std::string& file);
|
||||
|
||||
bool ParseFromXmlString(const std::string& body);
|
||||
//bool ParseFromStringStream(const std::ostringstream& os);
|
||||
|
||||
/// \brief 打印最终结果至终端
|
||||
void PrintResult() const;
|
||||
|
||||
private:
|
||||
//void ParseStatsEvent(const std::string& stat_str);
|
||||
//void ParseProgressEvent(const std::string& prog_str);
|
||||
std::vector<SelectMessage> resp_data;
|
||||
std::string error_message;
|
||||
std::string error_code;
|
||||
};
|
||||
|
||||
/// \brief: 创建直播通道的响应
|
||||
class PutLiveChannelResp : public BaseResp {
|
||||
public:
|
||||
PutLiveChannelResp() {}
|
||||
virtual ~PutLiveChannelResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
const std::string GetPublishUrl() const {
|
||||
return m_publish_url;
|
||||
}
|
||||
|
||||
std::string& GetPublishUrl() {
|
||||
return m_publish_url;
|
||||
}
|
||||
|
||||
std::string GetPlayUrl() const {
|
||||
return m_play_url;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_publish_url; // 推流url
|
||||
std::string m_play_url; // 观流url
|
||||
};
|
||||
|
||||
/// \brief: 启用或者禁用直播通道的响应
|
||||
class PutLiveChannelSwitchResp : public BaseResp {
|
||||
public:
|
||||
PutLiveChannelSwitchResp() {}
|
||||
virtual ~PutLiveChannelSwitchResp() {}
|
||||
};
|
||||
|
||||
/// \brief: 获取直播通道配置的响应
|
||||
class GetLiveChannelResp : public BaseResp {
|
||||
public:
|
||||
GetLiveChannelResp() {}
|
||||
virtual ~GetLiveChannelResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
const LiveChannelConfiguration& GetLiveChannelConf() const {
|
||||
return m_chan_conf;
|
||||
}
|
||||
private:
|
||||
LiveChannelConfiguration m_chan_conf;
|
||||
};
|
||||
|
||||
/// \brief: 获取直播通道推流历史的响应
|
||||
class GetLiveChannelHistoryResp : public BaseResp {
|
||||
public:
|
||||
GetLiveChannelHistoryResp() {}
|
||||
virtual ~GetLiveChannelHistoryResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
const std::vector<LiveRecord>& GetChanHistory() const {
|
||||
return m_history;
|
||||
}
|
||||
private:
|
||||
std::vector<LiveRecord> m_history;
|
||||
};
|
||||
|
||||
/// \brief: 获取直播通道推流状态的响应
|
||||
class GetLiveChannelStatusResp : public BaseResp {
|
||||
public:
|
||||
GetLiveChannelStatusResp() {}
|
||||
virtual ~GetLiveChannelStatusResp() {}
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
const LiveChannelStatus& GetLiveChannelStatus() const {
|
||||
return m_livechan_status;
|
||||
}
|
||||
private:
|
||||
LiveChannelStatus m_livechan_status;
|
||||
};
|
||||
|
||||
/// \brief: 删除直播通道的响应
|
||||
class DeleteLiveChannelResp : public BaseResp {
|
||||
public:
|
||||
DeleteLiveChannelResp() {}
|
||||
virtual ~DeleteLiveChannelResp() {}
|
||||
};
|
||||
|
||||
/// \brief: 查询指定通道在指定时间段推流生成的播放列表的响应
|
||||
class GetLiveChannelVodPlaylistResp : public BaseResp {
|
||||
public:
|
||||
GetLiveChannelVodPlaylistResp() {}
|
||||
virtual ~GetLiveChannelVodPlaylistResp() {}
|
||||
int WriteResultToFile(const std::string& file);
|
||||
};
|
||||
|
||||
/// \brief: 为指定通道生成一个可供点播例用的播放列表的响应
|
||||
class PostLiveChannelVodPlaylistResp : public BaseResp {
|
||||
public:
|
||||
PostLiveChannelVodPlaylistResp() {}
|
||||
virtual ~PostLiveChannelVodPlaylistResp() {}
|
||||
};
|
||||
|
||||
/*批量及目录操作接口*/
|
||||
|
||||
class PutObjectsByDirectoryResp {
|
||||
public:
|
||||
PutObjectsByDirectoryResp() {}
|
||||
virtual ~PutObjectsByDirectoryResp() {}
|
||||
|
||||
public:
|
||||
class PutResp {
|
||||
public:
|
||||
PutResp() {}
|
||||
virtual ~PutResp() {}
|
||||
std::string m_file_name; // 本地文件名
|
||||
std::string m_object_name; // 对象名
|
||||
BaseResp m_cos_resp; //cos返回的响应
|
||||
};
|
||||
// 成功上传的对象
|
||||
std::vector<PutResp> m_succ_put_objs;
|
||||
};
|
||||
|
||||
class PutDirectoryResp : public PutObjectResp {
|
||||
public:
|
||||
PutDirectoryResp() {}
|
||||
virtual ~PutDirectoryResp() {}
|
||||
};
|
||||
|
||||
class MoveObjectResp {
|
||||
public:
|
||||
MoveObjectResp() {}
|
||||
virtual ~MoveObjectResp() {}
|
||||
};
|
||||
|
||||
class DeleteObjectsByPrefixResp {
|
||||
public:
|
||||
DeleteObjectsByPrefixResp() {}
|
||||
virtual ~DeleteObjectsByPrefixResp() {}
|
||||
std::vector<std::string> m_succ_del_objs; // 成功删除的对象
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // OBJECT_RESP_H
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 11/14/17
|
||||
// Description:
|
||||
|
||||
#ifndef SERVICE_RESP_H
|
||||
#define SERVICE_RESP_H
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "cos_config.h"
|
||||
#include "cos_defines.h"
|
||||
#include "response/base_resp.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class GetServiceResp : public BaseResp {
|
||||
public:
|
||||
GetServiceResp() {}
|
||||
virtual ~GetServiceResp() {}
|
||||
|
||||
virtual bool ParseFromXmlString(const std::string& body);
|
||||
|
||||
/// \brief 获取 Bucket 持有者的信息
|
||||
///
|
||||
/// \return Owner 持有者的信息
|
||||
Owner GetOwner() const { return m_owner; }
|
||||
|
||||
/// \brief 获取所有 Bucket 列表信息
|
||||
std::vector<Bucket> GetBuckets() const { return m_buckets; }
|
||||
|
||||
private:
|
||||
Owner m_owner;
|
||||
std::vector<Bucket> m_buckets;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // SERVICE_RESP_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "Poco/TaskManager.h"
|
||||
#include "Poco/Task.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
using TaskFunc = std::function<void()>;
|
||||
|
||||
class AsyncTask : public Poco::Task {
|
||||
public:
|
||||
AsyncTask(TaskFunc &&f) : Task("AsyncTask"), _f(f) {}
|
||||
~AsyncTask() {}
|
||||
|
||||
void runTask() {
|
||||
_f();
|
||||
}
|
||||
|
||||
private:
|
||||
TaskFunc _f;
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
@@ -0,0 +1,176 @@
|
||||
#ifndef __TRSF_HANDLER_H__
|
||||
#define __TRSF_HANDLER_H__
|
||||
|
||||
#include <map>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include "op/cos_result.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
/// @brief 进度回调函数
|
||||
typedef void (*TransferProgressCallback)(uint64_t transferred_size, uint64_t total_size, void *user_data);
|
||||
|
||||
/// @brief 状态回调函数
|
||||
typedef void (*TransferStatusCallback)(const std::string& status, void *user_data);
|
||||
|
||||
class PartState {
|
||||
public:
|
||||
PartState();
|
||||
PartState(int part_num, std::string& etag, size_t size, bool last_part = false);
|
||||
|
||||
void SetPartNum(int number) { m_part_num = number; }
|
||||
int GetPartNum() const { return m_part_num; }
|
||||
|
||||
void SetEtag(const std::string& etag) { m_etag = etag; }
|
||||
std::string GetEtag() const { return m_etag; }
|
||||
|
||||
void SetSize(size_t size) { m_size_inbytes = size; }
|
||||
size_t GetSize() const { return m_size_inbytes; }
|
||||
|
||||
void SetLastPart(bool lastpart) { m_lastpart = lastpart; }
|
||||
bool IsLastPart() { return m_lastpart; }
|
||||
|
||||
private:
|
||||
int m_part_num;
|
||||
// current use the md5
|
||||
std::string m_etag;
|
||||
|
||||
size_t m_size_inbytes;
|
||||
|
||||
// TODO for now just care about the whole progress
|
||||
/* size_t m_current_progress_inbytes; */
|
||||
/* size_t m_range_begin; */
|
||||
|
||||
bool m_lastpart;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<PartState> PartPointer;
|
||||
// Key is partnumber
|
||||
typedef std::map<int, PartPointer> PartStateMap;
|
||||
|
||||
enum class TransferStatus
|
||||
{
|
||||
NOT_START,
|
||||
//Operation is now running
|
||||
IN_PROGRESS,
|
||||
//Operation was canceled.
|
||||
CANCELED,
|
||||
//Operation failed
|
||||
FAILED,
|
||||
//Operation was successful
|
||||
COMPLETED,
|
||||
//Operation either failed or was canceled and a user deleted the multi-part upload .
|
||||
ABORTED
|
||||
};
|
||||
|
||||
// For now support the multiupload
|
||||
class TransferHandler {
|
||||
public:
|
||||
// Upload
|
||||
TransferHandler(const std::string& bucket_name, const std::string& object_name,
|
||||
uint64_t total_size, const std::string& file_path="");
|
||||
|
||||
void SetBucketName(const std::string& bucket_name) { m_bucket_name = bucket_name; }
|
||||
std::string GetBucketName() const { return m_bucket_name; }
|
||||
|
||||
void SetObjectName(const std::string& object_name) { m_object_name = object_name; }
|
||||
std::string GetObjectName() const { return m_object_name; }
|
||||
|
||||
void SetLocalFilePath(const std::string& local_file_path) { m_local_file_path = local_file_path; }
|
||||
std::string GetLocalFilePath() const { return m_local_file_path; }
|
||||
|
||||
void SetTotalSize(uint64_t total_size) { m_total_size = total_size; }
|
||||
uint64_t GetTotalSize() const { return m_total_size; }
|
||||
|
||||
// Notice there can not backwards
|
||||
void UpdateProgress(uint64_t update_prog);
|
||||
// Get the current upload size(B).
|
||||
uint64_t GetProgress() const;
|
||||
|
||||
void UpdateStatus(const TransferStatus& status);
|
||||
|
||||
void UpdateStatus(const TransferStatus& status, const CosResult& result);
|
||||
// Get the current status of process, detail see the enum TransferStatus.
|
||||
TransferStatus GetStatus() const;
|
||||
|
||||
std::string GetStatusString() const;
|
||||
|
||||
void SetUploadID(const std::string& uploadid) { m_uploadid = uploadid; }
|
||||
// Get the init or resumed uploadid.
|
||||
std::string GetUploadID() const { return m_uploadid; }
|
||||
|
||||
// Cancel the process of interface the uploadid can reuse.
|
||||
void Cancel();
|
||||
|
||||
bool ShouldContinue() const;
|
||||
|
||||
bool IsFinishStatus(TransferStatus status) const;
|
||||
|
||||
bool IsAllowTransition(TransferStatus org, TransferStatus dst) const;
|
||||
|
||||
// Block until finish.
|
||||
void WaitUntilFinish();
|
||||
|
||||
/// @brief 设置进度回调函数
|
||||
void SetTransferProgressCallback(TransferProgressCallback callback) {
|
||||
m_progress_cb = callback;
|
||||
}
|
||||
/// @brief 设置状态回调函数
|
||||
void SetTransferStatusCallback(TransferStatusCallback callback) {
|
||||
m_status_cb = callback;
|
||||
}
|
||||
/// @brief 设置回调私有数据
|
||||
void SetTransferCallbackUserData(void *user_data) {
|
||||
m_user_data = user_data;
|
||||
}
|
||||
|
||||
public:
|
||||
// Origin result
|
||||
CosResult m_result;
|
||||
|
||||
private:
|
||||
std::string m_bucket_name;
|
||||
std::string m_object_name;
|
||||
std::string m_local_file_path;
|
||||
uint64_t m_total_size;
|
||||
// The m_current_progress best to use the atomic. but can not support c11 for now, so use the mutex.
|
||||
uint64_t m_current_progress;
|
||||
TransferStatus m_status;
|
||||
std::string m_uploadid;
|
||||
// Is cancel
|
||||
bool m_cancel;
|
||||
|
||||
PartStateMap m_part_map;
|
||||
|
||||
// Mutex lock for the progress
|
||||
mutable std::mutex m_lock_prog;
|
||||
// Mutex lock for the status
|
||||
mutable std::mutex m_lock_stat;
|
||||
// Condition
|
||||
mutable std::condition_variable m_cond;
|
||||
|
||||
// callback function
|
||||
TransferProgressCallback m_progress_cb;
|
||||
TransferStatusCallback m_status_cb;
|
||||
void *m_user_data;
|
||||
|
||||
// Mutex lock for the part map
|
||||
// mutable boost::mutex m_lock_parts;
|
||||
};
|
||||
|
||||
/// @异步回调Hanlder
|
||||
typedef std::shared_ptr<TransferHandler> SharedTransferHandler;
|
||||
|
||||
class HandleStreamCopier {
|
||||
public:
|
||||
static std::streamsize handleCopyStream(const SharedTransferHandler& handler, std::istream& istr, std::ostream& ostr,
|
||||
std::size_t bufferSize = 8192);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifndef UTIL_AUTHTOOl_H
|
||||
#define UTIL_AUTHTOOl_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "request/base_req.h"
|
||||
#include "util/noncopyable.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class AuthTool : private NonCopyable {
|
||||
public:
|
||||
/// \brief 返回签名,可以在指定的有效期内(通过CosSysConfig设置, 默认60s)使用
|
||||
///
|
||||
/// \param secret_id 开发者拥有的项目身份识别 ID,用以身份认证
|
||||
/// \param secret_key 开发者拥有的项目身份密钥
|
||||
/// \param http_method http方法,如POST/GET/HEAD/PUT等, 传入大小写不敏感
|
||||
/// \param in_uri http uri
|
||||
/// \param headers http header的键值对
|
||||
/// \param params http params的键值对
|
||||
///
|
||||
/// \return 字符串形式的签名,返回空串代表失败
|
||||
static std::string Sign(const std::string& secret_id,
|
||||
const std::string& secret_key,
|
||||
const std::string& http_method,
|
||||
const std::string& in_uri,
|
||||
const std::map<std::string, std::string>& headers,
|
||||
const std::map<std::string, std::string>& params);
|
||||
|
||||
/// \brief 返回签名,可以在指定的有效期内使用
|
||||
///
|
||||
/// \param secret_id 开发者拥有的项目身份识别 ID,用以身份认证
|
||||
/// \param secret_key 开发者拥有的项目身份密钥
|
||||
/// \param http_method http方法,如POST/GET/HEAD/PUT等, 传入大小写不敏感
|
||||
/// \param in_uri http uri
|
||||
/// \param headers http header的键值对
|
||||
/// \param params http params的键值对
|
||||
///
|
||||
/// \return 字符串形式的签名,返回空串代表失败
|
||||
static std::string Sign(const std::string& secret_id,
|
||||
const std::string& secret_key,
|
||||
const std::string& http_method,
|
||||
const std::string& in_uri,
|
||||
const std::map<std::string, std::string>& headers,
|
||||
const std::map<std::string, std::string>& params,
|
||||
uint64_t start_time_in_s,
|
||||
uint64_t end_time_in_s);
|
||||
|
||||
/// \brief get rtmp signature
|
||||
static std::string RtmpSign(const std::string& secret_id,
|
||||
const std::string& secret_key,
|
||||
const std::string& token,
|
||||
const std::string& bucket,
|
||||
const std::string& channel,
|
||||
const std::map<std::string, std::string>& params,
|
||||
uint64_t expire);
|
||||
private:
|
||||
/// \brief 把params中的数据,转小写,正排,key放在param_list key=value放param_value_list
|
||||
/// \param params 参数
|
||||
/// \param key_encode key是否进行uri编码
|
||||
/// \param value_encode value是否进行uri编码
|
||||
/// \param value_lower value是否小写
|
||||
/// \param param_list 参数名列表,以;分隔
|
||||
/// \param param_value_list 参数键值对列表,以&分隔
|
||||
/// \retval 无
|
||||
static void FillMap(const std::map<std::string,std::string> ¶ms,
|
||||
bool key_encode,
|
||||
bool value_encode,
|
||||
bool value_lower,
|
||||
std::string* param_list,
|
||||
std::string* param_value_list);
|
||||
|
||||
/// \brief 找出需要鉴权的头部,并设置,目前host conent-type 还有x开头的都要鉴权
|
||||
/// \param hedaers 头部的kv对
|
||||
/// \param filted_req_headers 需要鉴权的头部
|
||||
/// \retval 无
|
||||
static void FilterAndSetSignHeader(const std::map<std::string,std::string>& headers,
|
||||
std::map<std::string, std::string>* filted_req_headers);
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
|
||||
#endif // AUTHTOOL_H
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef CODEC_UTIL_H
|
||||
#define CODEC_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class CodecUtil {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief 将字符x转成十六进制 (x的值[0, 15])
|
||||
*
|
||||
* @param x
|
||||
*
|
||||
* @return 十六进制字符
|
||||
*/
|
||||
static unsigned char ToHex(const unsigned char& x);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将二进制数据转成十六进制 (x的值[0, 15]),上层调用保证hex的大小足够
|
||||
*
|
||||
* @param bin
|
||||
*
|
||||
* @param binLen
|
||||
*
|
||||
* @param hex 存放结果的数据块
|
||||
*
|
||||
* @return 无
|
||||
*/
|
||||
static void BinToHex(const unsigned char *bin,unsigned int binLen, char *hex);
|
||||
|
||||
|
||||
static std::string EncodeKey(const std::string& key);
|
||||
|
||||
/**
|
||||
* @brief 对字符串进行URL编码
|
||||
*
|
||||
* @param str 带编码的字符串
|
||||
*
|
||||
* @return 经过URL编码的字符串
|
||||
*/
|
||||
static std::string UrlEncode(const std::string& str);
|
||||
|
||||
/**
|
||||
* @brief 对字符串进行base64编码
|
||||
*
|
||||
* @param plainText 待编码的字符串
|
||||
*
|
||||
* @return 编码后的字符串
|
||||
*/
|
||||
static std::string Base64Encode(const std::string& plainText);
|
||||
|
||||
/**
|
||||
* @brief 获取hmacSha1值
|
||||
*
|
||||
* @param plainText 明文
|
||||
* @param key 秘钥
|
||||
*
|
||||
* @return 获取的hmacsha1值
|
||||
*/
|
||||
static std::string HmacSha1(const std::string& plainText,
|
||||
const std::string& key);
|
||||
|
||||
/**
|
||||
* @brief 获取hmacSha1的16进制值
|
||||
*
|
||||
* @param plainText 明文
|
||||
* @param key 秘钥
|
||||
*
|
||||
* @return 获取的hmacsha1的16进制值
|
||||
*/
|
||||
static std::string HmacSha1Hex(const std::string& plainText,
|
||||
const std::string& key);
|
||||
|
||||
static std::string RawMd5(const std::string& plainText);
|
||||
|
||||
static std::string RawMd51(const std::string& plainText);
|
||||
|
||||
static std::string HexToBin(const std::string &strHex);
|
||||
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <cstddef>
|
||||
|
||||
namespace qcloud_cos {
|
||||
class CRC64
|
||||
{
|
||||
public:
|
||||
static uint64_t CalcCRC(uint64_t crc, void *buf, size_t len);
|
||||
static uint64_t CombineCRC(uint64_t crc1, uint64_t crc2, uintmax_t len2);
|
||||
static uint64_t CalcCRC(uint64_t crc, void *buf, size_t len, bool little);
|
||||
};
|
||||
} // namespace qcloud_cos
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef FILE_UTIL_H
|
||||
#define FILE_UTIL_H
|
||||
#include <stdint.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class FileUtil {
|
||||
public:
|
||||
//获取文件内容
|
||||
static std::string GetFileContent(const std::string& path);
|
||||
|
||||
//返回文件大小
|
||||
static uint64_t GetFileLen(const std::string& path);
|
||||
|
||||
static bool IsDirectoryExists(const std::string& path);
|
||||
|
||||
static bool IsDirectory(const std::string& path);
|
||||
|
||||
static std::string GetDirectory(const std::string& path);
|
||||
|
||||
static uint64_t GetFileCrc64(const std::string& file);
|
||||
};
|
||||
} // namespace qcloud_cos
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 07/18/17
|
||||
// Description:
|
||||
|
||||
#ifndef HTTP_SENDER_H
|
||||
#define HTTP_SENDER_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "trsf/transfer_handler.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class HttpSender {
|
||||
public:
|
||||
static int SendRequest(const std::string& http_method,
|
||||
const std::string& url_str,
|
||||
const std::map<std::string, std::string>& req_params,
|
||||
const std::map<std::string, std::string>& req_headers,
|
||||
const std::string& req_body,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
std::map<std::string, std::string>* resp_headers,
|
||||
std::string* resp_body,
|
||||
std::string* err_msg,
|
||||
bool is_check_md5 = false);
|
||||
|
||||
static int SendRequest(const std::string& http_method,
|
||||
const std::string& url_str,
|
||||
const std::map<std::string, std::string>& req_params,
|
||||
const std::map<std::string, std::string>& req_headers,
|
||||
const std::string& req_body,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
std::map<std::string, std::string>* resp_headers,
|
||||
std::ostream& resp_stream,
|
||||
std::string* err_msg,
|
||||
bool is_check_md5 = false);
|
||||
|
||||
static int SendRequest(const std::string& http_method,
|
||||
const std::string& url_str,
|
||||
const std::map<std::string, std::string>& req_params,
|
||||
const std::map<std::string, std::string>& req_headers,
|
||||
std::istream& is,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
std::map<std::string, std::string>* resp_headers,
|
||||
std::string* resp_body,
|
||||
std::string* err_msg,
|
||||
bool is_check_md5 = false);
|
||||
|
||||
static int SendRequest(const std::string& http_method,
|
||||
const std::string& url_str,
|
||||
const std::map<std::string, std::string>& req_params,
|
||||
const std::map<std::string, std::string>& req_headers,
|
||||
std::istream& is,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
std::map<std::string, std::string>* resp_headers,
|
||||
std::ostream& resp_stream,
|
||||
std::string* err_msg,
|
||||
bool is_check_md5 = false);
|
||||
|
||||
static int SendRequest(const std::string& http_method,
|
||||
const std::string& url_str,
|
||||
const std::map<std::string, std::string>& req_params,
|
||||
const std::map<std::string, std::string>& req_headers,
|
||||
const std::string& req_body,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
std::map<std::string, std::string>* resp_headers,
|
||||
std::string* xml_err_str,
|
||||
std::ostream& resp_stream,
|
||||
std::string* err_msg,
|
||||
uint64_t* real_byte,
|
||||
bool is_check_md5 = false);
|
||||
/// \brief 支持更新进度
|
||||
static int TransferSendRequest(const SharedTransferHandler& handler,
|
||||
const std::string& http_method,
|
||||
const std::string& url_str,
|
||||
const std::map<std::string, std::string>& req_params,
|
||||
const std::map<std::string, std::string>& req_headers,
|
||||
std::istream& is,
|
||||
uint64_t conn_timeout_in_ms,
|
||||
uint64_t recv_timeout_in_ms,
|
||||
std::map<std::string, std::string>* resp_headers,
|
||||
std::ostream& resp_stream,
|
||||
std::string* err_msg,
|
||||
bool is_check_md5 = false);
|
||||
};
|
||||
|
||||
} // namespace qcloud_cos
|
||||
#endif // HTTP_SENDER_H
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef LOG_UTIL_H
|
||||
#define LOG_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include "cos_defines.h"
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
typedef void (*LogCallback)(const std::string& logstr);
|
||||
|
||||
class LogUtil {
|
||||
public:
|
||||
static std::string GetLogPrefix(int level);
|
||||
static std::string FormatLog(int level, const char* fmt, ...);
|
||||
static void Syslog(int level, const char* fmt, ...);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2017, Tencent Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Author: sevenyou <sevenyou@tencent.com>
|
||||
// Created: 08/03/17
|
||||
// Description:
|
||||
|
||||
#ifndef NONCOPYABLE_H
|
||||
#define NONCOPYABLE_H
|
||||
#pragma once
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
class NonCopyable {
|
||||
protected:
|
||||
NonCopyable() {}
|
||||
~NonCopyable() {}
|
||||
private: // emphasize the following members are private
|
||||
NonCopyable(const NonCopyable&);
|
||||
const NonCopyable& operator=(const NonCopyable&);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NONCOPYABLE_H
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef SHA_H
|
||||
#define SHA_H
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace qcloud_cos {
|
||||
|
||||
/* Useful defines & typedefs */
|
||||
typedef unsigned char SHA_BYTE; /* 8-bit quantity */
|
||||
|
||||
// SHA_LONG already defined in openssl/sha.h
|
||||
typedef unsigned int SHA_LONG; /* 32-or-more-bit quantity */
|
||||
#define SHA_BYTE_ORDER 1234
|
||||
#define SHA_VERSION 1
|
||||
|
||||
#define SHA_BLOCKSIZE 64
|
||||
#define SHA_DIGESTSIZE 20
|
||||
|
||||
typedef struct {
|
||||
SHA_LONG digest[5]; /* message digest */
|
||||
SHA_LONG count_lo, count_hi; /* 64-bit bit count */
|
||||
SHA_BYTE data[SHA_BLOCKSIZE]; /* SHA data buffer */
|
||||
int local; /* unprocessed amount in data */
|
||||
} SHA_INFO;
|
||||
|
||||
|
||||
void ShaInit(SHA_INFO *);
|
||||
void ShaUpdate(SHA_INFO *, SHA_BYTE *, int);
|
||||
void ShaFinal(unsigned char [20], SHA_INFO *);
|
||||
|
||||
void ShaOutput(unsigned char [20],unsigned char [40]);
|
||||
const char* ShaVersion(void);
|
||||
|
||||
class Sha1 {
|
||||
public:
|
||||
Sha1();
|
||||
~Sha1();
|
||||
|
||||
void Append(const char* data, unsigned int size);
|
||||
std::string Final();
|
||||
|
||||
private:
|
||||
SHA_INFO m_sha;
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* SHA_H */
|
||||
@@ -0,0 +1,246 @@
|
||||
#ifndef STRING_UTIL_H
|
||||
#define STRING_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rapidxml/1.13/rapidxml.hpp"
|
||||
#include "rapidxml/1.13/rapidxml_utils.hpp"
|
||||
#include "rapidxml/1.13/rapidxml_print.hpp"
|
||||
|
||||
#include "cos_defines.h"
|
||||
|
||||
namespace qcloud_cos{
|
||||
|
||||
class StringUtil {
|
||||
public:
|
||||
/**
|
||||
* @brief 去除string两端的空格
|
||||
*
|
||||
* @param s: 待去除空格的字符串,是入参也是出参
|
||||
*
|
||||
* @return 返回去除空格后的字符串,即s
|
||||
*/
|
||||
static std::string& Trim(std::string& s);
|
||||
|
||||
/**
|
||||
* @brief 去除string两端指定的字符串
|
||||
*
|
||||
* @param s: 待去除的字符串,入参
|
||||
* @param trim_value: 删除的字符串
|
||||
*
|
||||
* @return 返回Trim后的字符串
|
||||
*/
|
||||
static std::string Trim(const std::string& s, const std::string& trim_value);
|
||||
|
||||
/**
|
||||
* @brief 将xml转为string
|
||||
*
|
||||
* @param xmlObject 需要转换xml对象
|
||||
*
|
||||
* @return 返回转换后的string
|
||||
*/
|
||||
static std::string XmlToString(const rapidxml::xml_document<>& xml_doc);
|
||||
|
||||
/**
|
||||
* @brief 将string转换为xml
|
||||
*
|
||||
* @param xmlStr 待转换的string对象
|
||||
* @param doc 待返回的xml对象[out]
|
||||
*
|
||||
* @return 转换成功返回true,否则返回false
|
||||
*/
|
||||
static bool StringToXml(char* xml_str, rapidxml::xml_document<>* doc);
|
||||
|
||||
/**
|
||||
* @brief 把uint64_t类型的num转换成std::string,长度为8个字节
|
||||
*
|
||||
* @param num uint64_t类型
|
||||
*
|
||||
* @return 转换后的string
|
||||
*/
|
||||
static std::string Uint64ToString(uint64_t num);
|
||||
|
||||
/**
|
||||
* @brief 将int转为string
|
||||
*
|
||||
* @param num int类型
|
||||
*
|
||||
* @return 转换后的string
|
||||
*/
|
||||
static std::string IntToString(int num);
|
||||
|
||||
/**
|
||||
* @brief 字符串就地转成全大写
|
||||
*
|
||||
* @param s 指向string类型的指针
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static void StringToUpper(std::string* s);
|
||||
|
||||
/**
|
||||
* @brief 字符串转成全大写
|
||||
*
|
||||
* @param s string类型的常引用
|
||||
*
|
||||
* @return 全大写字符串
|
||||
*/
|
||||
static std::string StringToUpper(const std::string& s);
|
||||
|
||||
/**
|
||||
* @brief 字符串就地转成全小写
|
||||
*
|
||||
* @param s 指向string类型的指针
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static void StringToLower(std::string* s);
|
||||
|
||||
/**
|
||||
* @brief 字符串转成全小写
|
||||
*
|
||||
* @param s string类型的常引用
|
||||
*
|
||||
* @return 全大写字符串
|
||||
*/
|
||||
static std::string StringToLower(const std::string& s);
|
||||
|
||||
/**
|
||||
* @brief 字符串连接
|
||||
*
|
||||
* @param str_vec 字符串vector
|
||||
* @param delimiter 分隔符
|
||||
*
|
||||
* @return 字符串
|
||||
*/
|
||||
static std::string JoinStrings(const std::vector<std::string>& str_vec,
|
||||
const std::string& delimiter);
|
||||
|
||||
/**
|
||||
* @brief 将string转为uint64_t
|
||||
*
|
||||
* @param str string类型
|
||||
*
|
||||
* @return 转换后的uint64_t
|
||||
*/
|
||||
static uint64_t StringToUint64(const std::string& str);
|
||||
|
||||
/**
|
||||
* @brief 将string转为int
|
||||
*
|
||||
* @param str string类型
|
||||
*
|
||||
* @return 转换后的int
|
||||
*/
|
||||
static int StringToInt(const std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 判断字符串是否以指定前缀开头
|
||||
*
|
||||
* @param str string类型
|
||||
* @param prefix string类型
|
||||
*
|
||||
* @return str的前缀为prefix,则返回true;反之,返回false
|
||||
*/
|
||||
static bool StringStartsWith(const std::string& str, const std::string& prefix);
|
||||
|
||||
/**
|
||||
* @brief 判断字符串是否以指定前缀开头(忽略大小写)
|
||||
*
|
||||
* @param str string类型
|
||||
* @param prefix string类型
|
||||
*
|
||||
* @return str的前缀为prefix,则返回true;反之,返回false
|
||||
*/
|
||||
static bool StringStartsWithIgnoreCase(const std::string& str, const std::string& prefix);
|
||||
|
||||
/**
|
||||
* @brief 移除前缀
|
||||
*
|
||||
* @param str string类型
|
||||
* @param prefix string类型
|
||||
*
|
||||
* @return 返回移除了prefix前缀的字符串
|
||||
*/
|
||||
static std::string StringRemovePrefix(const std::string& str, const std::string& prefix);
|
||||
|
||||
/**
|
||||
* @brief 判断字符串是否以指定后缀结尾
|
||||
*
|
||||
* @param str string类型
|
||||
* @param suffix string类型
|
||||
*
|
||||
* @return str的后缀为suffix,则返回true;反之,返回false
|
||||
*/
|
||||
static bool StringEndsWith(const std::string& str, const std::string& suffix);
|
||||
|
||||
/**
|
||||
* @brief 判断字符串是否以指定后缀结尾(忽略大小写)
|
||||
*
|
||||
* @param str string类型
|
||||
* @param suffix string类型
|
||||
*
|
||||
* @return str的后缀为suffix,则返回true;反之,返回false
|
||||
*/
|
||||
static bool StringEndsWithIgnoreCase(const std::string& str, const std::string& suffix);
|
||||
|
||||
/**
|
||||
* @brief 移除后缀
|
||||
*
|
||||
* @param str string类型
|
||||
* @param suffix string类型
|
||||
*
|
||||
* @return 返回移除了suffix前缀的字符串
|
||||
*/
|
||||
static std::string StringRemoveSuffix(const std::string& str, const std::string& suffix);
|
||||
|
||||
/**
|
||||
* @brief 分割字符串
|
||||
*
|
||||
* @param str string类型,待分割字符串
|
||||
* @param delim char类型,分割符
|
||||
* @param vec std::vector类型,分割结果
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static void SplitString(const std::string& str, char delim, std::vector<std::string>* vec);
|
||||
|
||||
/**
|
||||
* @brief 分割字符串
|
||||
*
|
||||
* @param str string类型,待分割字符串
|
||||
* @param sep string类型,分割字符串
|
||||
* @param vec std::vector类型,分割结果
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static void SplitString(const std::string& str, const std::string& sep, std::vector<std::string>* vec);
|
||||
|
||||
/**
|
||||
* @brief 将HTTP_METHOD转成对应的字符串格式
|
||||
*
|
||||
* @param method HTTP_METHOD
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static std::string HttpMethodToString(HTTP_METHOD method);
|
||||
|
||||
static bool IsV4ETag(const std::string& etag);
|
||||
static bool IsMultipartUploadETag(const std::string& etag);
|
||||
|
||||
/**
|
||||
* @brief 从字符串中获取uint32整型
|
||||
*/
|
||||
static uint32_t GetUint32FromStrWithBigEndian(const char *str);
|
||||
|
||||
/**
|
||||
* @brief 从字符串中获取uint16整型
|
||||
*/
|
||||
static uint16_t GetUint16FromStrWithBigEndian(const char * str);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user