cos_defines.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. #ifndef COS_CPP_SDK_V5_INCLUDE_COS_DEFINES_H_
  2. #define COS_CPP_SDK_V5_INCLUDE_COS_DEFINES_H_
  3. #include <inttypes.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <string>
  7. #include <vector>
  8. #include <functional>
  9. #include "util/log_util.h"
  10. namespace qcloud_cos {
  11. #define COS_CPP_SDK_VERSON "v5.5.20"
  12. /// 路径分隔符
  13. const char kPathDelimiter[] = "/";
  14. /// 路径分隔符
  15. const unsigned char kPathDelimiterChar = '/';
  16. /// 分块上传时,失败的最大重试次数
  17. const int kMaxRetryTimes = 3;
  18. /// 默认线程池大小
  19. const int kDefaultPoolSize = 2;
  20. /// 分块上传的线程池默认大小
  21. const int kDefaultThreadPoolSizeUploadPart = 5;
  22. /// 分块上传的线程池最大数目
  23. const int kMaxThreadPoolSizeUploadPart = 100;
  24. /// 分块上传的线程池最小数目
  25. const int kMinThreadPoolSizeUploadPart = 1;
  26. /// 最大分开数量
  27. const int kMaxPartNumbers = 10000;
  28. /// 分块大小1M
  29. const uint64_t kPartSize1M = 1 * 1024 * 1024;
  30. /// 分块大小5G
  31. const uint64_t kPartSize5G = (uint64_t)5 * 1024 * 1024 * 1024;
  32. using SSLCtxCallback = std::function<int(void *ssl_ctx, void* user_data)>;
  33. const bool COS_CHANGE_BACKUP_DOMAIN = true;
  34. typedef enum log_out_type {
  35. COS_LOG_NULL = 0,
  36. COS_LOG_STDOUT,
  37. COS_LOG_SYSLOG
  38. } LOG_OUT_TYPE;
  39. typedef enum {
  40. HTTP_HEAD,
  41. HTTP_GET,
  42. HTTP_PUT,
  43. HTTP_POST,
  44. HTTP_DELETE,
  45. HTTP_OPTIONS
  46. } HTTP_METHOD;
  47. typedef enum cos_log_level {
  48. COS_LOG_ERR = 1, // LOG_ERR
  49. COS_LOG_WARN = 2, // LOG_WARNING
  50. COS_LOG_INFO = 3, // LOG_INFO
  51. COS_LOG_DBG = 4 // LOG_DEBUG
  52. } LOG_LEVEL;
  53. typedef enum file_type { CSV = 0, JSON } SELECT_FILE_TYPE;
  54. typedef enum compress_type {
  55. COMPRESS_NONE = 0,
  56. COMPRESS_GZIP,
  57. COMPRESS_BZIP2
  58. } SELECT_COMPRESS_TYPE;
  59. #define LOG_LEVEL_STRING(level) \
  60. ((level == COS_LOG_DBG) ? "[DBG] " \
  61. : (level == COS_LOG_INFO) ? "[INFO] " \
  62. : (level == COS_LOG_WARN) ? "[WARN] " \
  63. : (level == COS_LOG_ERR) ? "[ERR] " \
  64. : "[CRIT]")
  65. #define COS_LOW_LOGPRN(level, fmt, ...) \
  66. if (level <= CosSysConfig::GetLogLevel()) { \
  67. if (CosSysConfig::GetLogOutType() == COS_LOG_STDOUT) { \
  68. fprintf(stdout, "%s:%s(%d) " fmt "\n", LOG_LEVEL_STRING(level), \
  69. __func__, __LINE__, ##__VA_ARGS__); \
  70. } else if (CosSysConfig::GetLogOutType() == COS_LOG_SYSLOG) { \
  71. LogUtil::Syslog(level, "%s:%s(%d) " fmt "\n", LOG_LEVEL_STRING(level), \
  72. __func__, __LINE__, ##__VA_ARGS__); \
  73. } else { \
  74. } \
  75. } else { \
  76. } \
  77. { \
  78. auto log_callback = CosSysConfig::GetLogCallback(); \
  79. if (log_callback && level <= CosSysConfig::GetLogLevel()) { \
  80. std::string logstr = \
  81. LogUtil::FormatLog(level, "%s:%s(%d) " fmt "\n", __FILE__, __func__, \
  82. __LINE__, ##__VA_ARGS__); \
  83. log_callback(logstr); \
  84. } \
  85. }
  86. #define SDK_LOG_DBG(fmt, ...) COS_LOW_LOGPRN(COS_LOG_DBG, fmt, ##__VA_ARGS__)
  87. #define SDK_LOG_INFO(fmt, ...) COS_LOW_LOGPRN(COS_LOG_INFO, fmt, ##__VA_ARGS__)
  88. #define SDK_LOG_WARN(fmt, ...) COS_LOW_LOGPRN(COS_LOG_WARN, fmt, ##__VA_ARGS__)
  89. #define SDK_LOG_ERR(fmt, ...) COS_LOW_LOGPRN(COS_LOG_ERR, fmt, ##__VA_ARGS__)
  90. #define SDK_LOG_COS(level, fmt, ...) COS_LOW_LOGPRN(level, fmt, ##__VA_ARGS__)
  91. #define UNUSED_PARAM(x) (void)x;
  92. struct Content {
  93. std::string m_key; // Object 的 Key
  94. std::string m_last_modified; // Object 最后被修改时间
  95. std::string m_etag; // 文件的 MD-5 算法校验值
  96. std::string m_size; // 文件大小,单位是 Byte
  97. std::vector<std::string> m_owner_ids; // Bucket 持有者信息
  98. std::string
  99. m_storage_class; // Object 的存储级别,枚举值:STANDARD,STANDARD_IA
  100. };
  101. struct ReplicationRule {
  102. bool m_is_enable;
  103. std::string m_id; // 非必须
  104. std::string m_prefix;
  105. std::string m_dest_bucket;
  106. std::string m_dest_storage_class; // 非必须
  107. ReplicationRule() {}
  108. ReplicationRule(const std::string& prefix, const std::string& dest_bucket,
  109. const std::string& storage_class = "",
  110. const std::string& id = "", bool is_enable = true) {
  111. m_is_enable = is_enable;
  112. m_id = id;
  113. m_prefix = prefix;
  114. m_dest_bucket = dest_bucket;
  115. m_dest_storage_class = storage_class;
  116. }
  117. };
  118. struct LifecycleTag {
  119. std::string key;
  120. std::string value;
  121. };
  122. class LifecycleFilter {
  123. public:
  124. LifecycleFilter() : m_mask(0x00000000u), m_prefix("") {}
  125. std::string GetPrefix() const { return m_prefix; }
  126. std::vector<LifecycleTag> GetTags() const { return m_tags; }
  127. void SetPrefix(const std::string& prefix) {
  128. m_mask |= 0x00000001u;
  129. m_prefix = prefix;
  130. }
  131. void SetTags(const std::vector<LifecycleTag>& tags) {
  132. m_mask |= 0x00000002u;
  133. m_tags = tags;
  134. }
  135. void AddTag(const LifecycleTag& tag) {
  136. m_mask |= 0x00000002u;
  137. m_tags.push_back(tag);
  138. }
  139. bool HasPrefix() const { return (m_mask & 0x00000001u) != 0; }
  140. bool HasTags() const { return (m_mask & 0x00000002u) != 0; }
  141. private:
  142. uint64_t m_mask;
  143. std::string m_prefix;
  144. std::vector<LifecycleTag> m_tags;
  145. };
  146. class LifecycleTransition {
  147. public:
  148. LifecycleTransition()
  149. : m_mask(0x00000000u), m_days(0), m_date(""), m_storage_class("") {}
  150. uint64_t GetDays() const { return m_days; }
  151. std::string GetDate() const { return m_date; }
  152. std::string GetStorageClass() const { return m_storage_class; }
  153. void SetDays(uint64_t days) {
  154. m_mask |= 0x00000001u;
  155. m_days = days;
  156. }
  157. void SetDate(const std::string& date) {
  158. m_mask |= 0x00000002u;
  159. m_date = date;
  160. }
  161. void SetStorageClass(const std::string& storage_class) {
  162. m_mask |= 0x00000004u;
  163. m_storage_class = storage_class;
  164. }
  165. bool HasDays() const { return (m_mask & 0x00000001u) != 0; }
  166. bool HasDate() const { return (m_mask & 0x00000002u) != 0; }
  167. bool HasStorageClass() const { return (m_mask & 0x00000004u) != 0; }
  168. private:
  169. uint64_t m_mask;
  170. // 不能在同一规则中同时使用Days和Date
  171. uint64_t m_days; // 有效值是非负整数
  172. std::string m_date;
  173. std::string m_storage_class;
  174. };
  175. class LifecycleExpiration {
  176. public:
  177. LifecycleExpiration()
  178. : m_mask(0x00000000u),
  179. m_days(0),
  180. m_date(""),
  181. m_expired_obj_del_marker(false) {}
  182. uint64_t GetDays() const { return m_days; }
  183. std::string GetDate() const { return m_date; }
  184. bool IsExpiredObjDelMarker() const { return m_expired_obj_del_marker; }
  185. void SetDays(uint64_t days) {
  186. m_mask |= 0x00000001u;
  187. m_days = days;
  188. }
  189. void SetDate(const std::string& date) {
  190. m_mask |= 0x00000002u;
  191. m_date = date;
  192. }
  193. void SetExpiredObjDelMarker(bool marker) {
  194. m_mask |= 0x00000004u;
  195. m_expired_obj_del_marker = marker;
  196. }
  197. bool HasDays() const { return (m_mask & 0x00000001u) != 0; }
  198. bool HasDate() const { return (m_mask & 0x00000002u) != 0; }
  199. bool HasExpiredObjDelMarker() const { return (m_mask & 0x00000004u) != 0; }
  200. private:
  201. uint64_t m_mask;
  202. // 不能在同一规则中同时使用Days和Date
  203. uint64_t m_days; // 有效值为正整数
  204. std::string m_date;
  205. bool m_expired_obj_del_marker;
  206. };
  207. class LifecycleNonCurrTransition {
  208. public:
  209. LifecycleNonCurrTransition()
  210. : m_mask(0x00000000u), m_days(0), m_storage_class("") {}
  211. uint64_t GetDays() const { return m_days; }
  212. std::string GetStorageClass() const { return m_storage_class; }
  213. void SetDays(uint64_t days) {
  214. m_mask |= 0x00000001u;
  215. m_days = days;
  216. }
  217. void SetStorageClass(const std::string& storage_class) {
  218. m_mask |= 0x00000002u;
  219. m_storage_class = storage_class;
  220. }
  221. bool HasDays() const { return (m_mask & 0x00000001u) != 0; }
  222. bool HasStorageClass() const { return (m_mask & 0x00000002u) != 0; }
  223. private:
  224. uint64_t m_mask;
  225. uint64_t m_days;
  226. std::string m_storage_class;
  227. };
  228. class LifecycleNonCurrExpiration {
  229. public:
  230. LifecycleNonCurrExpiration() : m_mask(0x00000000u), m_days(0) {}
  231. uint64_t GetDays() const { return m_days; }
  232. void SetDays(uint64_t days) {
  233. m_mask |= 0x00000001u;
  234. m_days = days;
  235. }
  236. bool HasDays() const { return (m_mask & 0x00000001u) != 0; }
  237. private:
  238. uint64_t m_mask;
  239. uint64_t m_days;
  240. };
  241. struct AbortIncompleteMultipartUpload {
  242. uint64_t m_days_after_init;
  243. };
  244. class LifecycleRule {
  245. public:
  246. LifecycleRule() : m_mask(0x00000000u), m_is_enable(false), m_id("") {}
  247. void SetIsEnable(bool is_enable) {
  248. m_mask |= 0x00000001u;
  249. m_is_enable = is_enable;
  250. }
  251. void SetId(const std::string& id) {
  252. m_mask |= 0x00000002u;
  253. m_id = id;
  254. }
  255. void SetFilter(const LifecycleFilter& filter) {
  256. m_mask |= 0x00000004u;
  257. m_filter = filter;
  258. }
  259. void AddTransition(const LifecycleTransition& rh) {
  260. m_mask |= 0x00000008u;
  261. m_transitions.push_back(rh);
  262. }
  263. void SetExpiration(const LifecycleExpiration& rh) {
  264. m_mask |= 0x00000010u;
  265. m_expiration = rh;
  266. }
  267. void SetNonCurrTransition(const LifecycleNonCurrTransition& rh) {
  268. m_mask |= 0x00000020u;
  269. m_non_curr_transition = rh;
  270. }
  271. void SetNonCurrExpiration(const LifecycleNonCurrExpiration& rh) {
  272. m_mask |= 0x00000040u;
  273. m_non_curr_expiration = rh;
  274. }
  275. void SetAbortIncompleteMultiUpload(const AbortIncompleteMultipartUpload& rh) {
  276. m_mask |= 0x00000080u;
  277. m_abort_multi_upload = rh;
  278. }
  279. bool IsEnable() const { return m_is_enable; }
  280. std::string GetId() const { return m_id; }
  281. LifecycleFilter GetFilter() const { return m_filter; }
  282. std::vector<LifecycleTransition> GetTransitions() const {
  283. return m_transitions;
  284. }
  285. LifecycleExpiration GetExpiration() const { return m_expiration; }
  286. LifecycleNonCurrTransition GetNonCurrTransition() const {
  287. return m_non_curr_transition;
  288. }
  289. LifecycleNonCurrExpiration GetNonCurrExpiration() const {
  290. return m_non_curr_expiration;
  291. }
  292. AbortIncompleteMultipartUpload GetAbortIncompleteMultiUpload() const {
  293. return m_abort_multi_upload;
  294. }
  295. bool HasIsEnable() const { return (m_mask & 0x00000001u) != 0; }
  296. bool HasId() const { return (m_mask & 0x00000002u) != 0; }
  297. bool HasFilter() const { return (m_mask & 0x00000004u) != 0; }
  298. bool HasTransition() const { return (m_mask & 0x00000008u) != 0; }
  299. bool HasExpiration() const { return (m_mask & 0x00000010u) != 0; }
  300. bool HasNonCurrTransition() const { return (m_mask & 0x00000020u) != 0; }
  301. bool HasNonCurrExpiration() const { return (m_mask & 0x00000040u) != 0; }
  302. bool HasAbortIncomMultiUpload() const { return (m_mask & 0x00000080u) != 0; }
  303. private:
  304. uint64_t m_mask;
  305. bool m_is_enable;
  306. std::string m_id;
  307. LifecycleFilter m_filter;
  308. std::vector<LifecycleTransition> m_transitions;
  309. LifecycleExpiration m_expiration;
  310. LifecycleNonCurrTransition m_non_curr_transition;
  311. LifecycleNonCurrExpiration m_non_curr_expiration;
  312. AbortIncompleteMultipartUpload m_abort_multi_upload;
  313. };
  314. struct Grantee {
  315. std::string m_type;
  316. std::string m_id;
  317. std::string m_display_name;
  318. std::string m_uri;
  319. };
  320. struct Grant {
  321. Grantee m_grantee;
  322. std::string m_perm;
  323. };
  324. struct CORSRule {
  325. std::string m_id;
  326. std::string m_max_age_secs;
  327. std::vector<std::string> m_allowed_headers;
  328. std::vector<std::string> m_allowed_methods;
  329. std::vector<std::string> m_allowed_origins;
  330. std::vector<std::string> m_expose_headers;
  331. };
  332. struct Initiator {
  333. std::string m_id;
  334. std::string m_display_name;
  335. };
  336. struct Owner {
  337. std::string m_id;
  338. std::string m_display_name;
  339. };
  340. // The result of the listmultiparts
  341. struct Upload {
  342. std::string m_key;
  343. std::string m_uploadid;
  344. std::string m_storage_class;
  345. std::vector<Owner> m_initator;
  346. std::vector<Owner> m_owner;
  347. std::string m_initiated;
  348. };
  349. struct Part {
  350. uint64_t m_part_num;
  351. uint64_t m_size;
  352. std::string m_etag;
  353. std::string m_last_modified;
  354. };
  355. // 描述单个 Bucket 的信息
  356. struct Bucket {
  357. std::string m_name; // Bucket 名称
  358. std::string m_location; // Bucket 所在地域
  359. std::string m_create_date; // Bucket 创建时间。ISO8601 格式,例如
  360. // 2016-11-09T08:46:32.000Z
  361. };
  362. struct ObjectVersionPair {
  363. std::string m_object_name;
  364. std::string m_version_id;
  365. ObjectVersionPair() {
  366. m_object_name = "";
  367. m_version_id = "";
  368. }
  369. ObjectVersionPair(const std::string& obj_name,
  370. const std::string& version_id) {
  371. m_object_name = obj_name;
  372. m_version_id = version_id;
  373. }
  374. };
  375. struct DeletedInfo {
  376. DeletedInfo()
  377. : m_key(""),
  378. m_version_id(""),
  379. m_delete_marker(false),
  380. m_delete_marker_version_id("") {}
  381. std::string m_key;
  382. std::string m_version_id;
  383. bool m_delete_marker;
  384. std::string m_delete_marker_version_id;
  385. };
  386. struct ErrorInfo {
  387. ErrorInfo() : m_key(""), m_code(""), m_message(""), m_version_id("") {}
  388. std::string m_key;
  389. std::string m_code;
  390. std::string m_message;
  391. std::string m_version_id;
  392. };
  393. struct COSVersionSummary {
  394. bool m_is_delete_marker;
  395. std::string m_etag;
  396. uint64_t m_size;
  397. std::string m_storage_class;
  398. bool m_is_latest;
  399. std::string m_key;
  400. std::string m_last_modified;
  401. Owner m_owner;
  402. std::string m_version_id;
  403. };
  404. class LoggingEnabled {
  405. public:
  406. LoggingEnabled()
  407. : m_mask(0x00000000u), m_targetbucket(""), m_targetprefix("") {}
  408. LoggingEnabled& operator=(const LoggingEnabled& obj) {
  409. if (this == &obj) {
  410. return *this;
  411. } else {
  412. m_mask = obj.GetMask();
  413. m_targetbucket = obj.GetTargetBucket();
  414. m_targetprefix = obj.GetTargetPrefix();
  415. return *this;
  416. }
  417. }
  418. void SetTargetBucket(const std::string& targetbucket) {
  419. m_mask = m_mask | 0x00000001u;
  420. m_targetbucket = targetbucket;
  421. }
  422. void SetTargetPrefix(const std::string& targetprefix) {
  423. m_mask = m_mask | 0x00000002u;
  424. m_targetprefix = targetprefix;
  425. }
  426. uint64_t GetMask() const { return m_mask; }
  427. std::string GetTargetBucket() const { return m_targetbucket; }
  428. std::string GetTargetPrefix() const { return m_targetprefix; }
  429. bool HasTargetBucket() const { return (m_mask & 0x00000001u) != 0; }
  430. bool HasTargetPrefix() const { return (m_mask & 0x00000002u) != 0; }
  431. virtual ~LoggingEnabled() {}
  432. private:
  433. uint64_t m_mask;
  434. std::string m_targetbucket;
  435. std::string m_targetprefix;
  436. };
  437. class DomainRule {
  438. public:
  439. DomainRule()
  440. : m_mask(0x00000000u),
  441. m_status(""),
  442. m_name(""),
  443. m_type(""),
  444. m_forcedreplacement("") {}
  445. DomainRule& operator=(const DomainRule& obj) {
  446. if (this == &obj) {
  447. return *this;
  448. } else {
  449. m_name = obj.GetName();
  450. m_type = obj.GetType();
  451. m_status = obj.GetStatus();
  452. m_mask = obj.GetMask();
  453. m_forcedreplacement = obj.GetForcedReplacement();
  454. return *this;
  455. }
  456. }
  457. virtual ~DomainRule() {}
  458. void SetStatus(const std::string& status) {
  459. m_mask = m_mask | 0x00000001u;
  460. m_status = status;
  461. }
  462. void SetName(const std::string& name) {
  463. m_mask = m_mask | 0x00000002u;
  464. m_name = name;
  465. }
  466. void SetType(const std::string& type) {
  467. m_mask = m_mask | 0x00000004u;
  468. m_type = type;
  469. }
  470. void SetForcedReplacement(const std::string& forcedreplacement) {
  471. m_mask = m_mask | 0x00000008u;
  472. m_forcedreplacement = forcedreplacement;
  473. }
  474. std::string GetStatus() const { return m_status; }
  475. std::string GetName() const { return m_name; }
  476. std::string GetType() const { return m_type; }
  477. std::string GetForcedReplacement() const { return m_forcedreplacement; }
  478. uint64_t GetMask() const { return m_mask; }
  479. bool HasStatus() const { return (m_mask & 0x00000001u) != 0; }
  480. bool HasName() const { return (m_mask & 0x00000002u) != 0; }
  481. bool HasType() const { return (m_mask & 0x00000004u) != 0; }
  482. bool HasForcedrePlacement() const { return (m_mask & 0x00000008u) != 0; }
  483. private:
  484. uint64_t m_mask;
  485. std::string m_status;
  486. std::string m_name;
  487. std::string m_type;
  488. std::string m_forcedreplacement;
  489. };
  490. class DomainErrorMsg {
  491. public:
  492. DomainErrorMsg() : m_code(""), m_message(""), m_resource(""), m_traceid("") {}
  493. virtual ~DomainErrorMsg() {}
  494. void SetCode(const std::string& code) { m_code = code; }
  495. void SetMessage(const std::string& message) { m_message = message; }
  496. void SetResource(const std::string& resource) { m_resource = resource; }
  497. void SetRequestid(const std::string& requestid) { m_requestid = requestid; }
  498. void SetTraceid(const std::string& traceid) { m_traceid = traceid; }
  499. std::string GetCode() const { return m_code; }
  500. std::string GetMessage() const { return m_message; }
  501. std::string GetResource() const { return m_resource; }
  502. std::string GetRequestid() const { return m_requestid; }
  503. std::string GetTraceid() const { return m_traceid; }
  504. private:
  505. std::string m_code;
  506. std::string m_message;
  507. std::string m_resource;
  508. std::string m_requestid;
  509. std::string m_traceid;
  510. };
  511. class Condition {
  512. public:
  513. Condition()
  514. : m_mask(0x00000000u),
  515. m_httperrorcodereturnedequals(404),
  516. m_keyprefixequals("") {}
  517. Condition& operator=(const Condition& obj) {
  518. if (this == &obj) {
  519. return *this;
  520. } else {
  521. m_mask = obj.GetMask();
  522. m_keyprefixequals = obj.GetKeyPrefixEquals();
  523. m_httperrorcodereturnedequals = obj.GetHttpErrorCodeReturnedEquals();
  524. return *this;
  525. }
  526. }
  527. void SetHttpErrorCodeReturnedEquals(const int& httpcode) {
  528. m_mask = m_mask | 0x00000001u;
  529. m_httperrorcodereturnedequals = httpcode;
  530. }
  531. void SetKeyPrefixEquals(const std::string& keyprefixequals) {
  532. m_mask = m_mask | 0x00000002u;
  533. m_keyprefixequals = keyprefixequals;
  534. }
  535. bool HasHttpErrorCodeReturnedEquals() const {
  536. return (m_mask & 0x00000001u) != 0;
  537. }
  538. bool HasKeyPrefixEquals() const { return (m_mask & 0x00000002u) != 0; }
  539. uint64_t GetMask() const { return m_mask; }
  540. int GetHttpErrorCodeReturnedEquals() const {
  541. return m_httperrorcodereturnedequals;
  542. }
  543. std::string GetKeyPrefixEquals() const { return m_keyprefixequals; }
  544. virtual ~Condition() {}
  545. private:
  546. uint64_t m_mask;
  547. int m_httperrorcodereturnedequals;
  548. std::string m_keyprefixequals;
  549. };
  550. class Redirect {
  551. public:
  552. Redirect()
  553. : m_mask(0x00000000u),
  554. m_protocol(""),
  555. m_replacekeywith(""),
  556. m_replacekeyprefixwith("") {}
  557. Redirect& operator=(const Redirect& obj) {
  558. if (this == &obj) {
  559. return *this;
  560. } else {
  561. m_mask = obj.GetMask();
  562. m_protocol = obj.GetProtocol();
  563. m_replacekeywith = obj.GetReplaceKeyWith();
  564. m_replacekeyprefixwith = obj.GetReplaceKeyPrefixWith();
  565. return *this;
  566. }
  567. }
  568. void SetProtocol(const std::string protocol) {
  569. m_mask = m_mask | 0x00000001u;
  570. m_protocol = protocol;
  571. }
  572. void SetReplaceKeyWith(const std::string replacekeywith) {
  573. m_mask = m_mask | 0x00000002u;
  574. m_replacekeywith = replacekeywith;
  575. }
  576. void SetReplaceKeyPrefixWith(const std::string replacekeyprefixwith) {
  577. m_mask = m_mask | 0x00000004u;
  578. m_replacekeyprefixwith = replacekeyprefixwith;
  579. }
  580. uint64_t GetMask() const { return m_mask; }
  581. std::string GetProtocol() const { return m_protocol; }
  582. std::string GetReplaceKeyWith() const { return m_replacekeywith; }
  583. std::string GetReplaceKeyPrefixWith() const { return m_replacekeyprefixwith; }
  584. bool HasProtocol() const { return (m_mask & 0x00000001u) != 0; }
  585. bool HasReplaceKeyWith() const { return (m_mask & 0x00000002u) != 0; }
  586. bool HasReplaceKeyPrefixWith() const { return (m_mask & 0x00000004u) != 0; }
  587. virtual ~Redirect() {}
  588. private:
  589. uint64_t m_mask;
  590. std::string m_protocol;
  591. std::string m_replacekeywith;
  592. std::string m_replacekeyprefixwith;
  593. };
  594. class RoutingRule {
  595. public:
  596. RoutingRule() : m_mask(0x00000000u), m_condition(), m_redirect() {}
  597. RoutingRule(const RoutingRule& obj) {
  598. m_mask = obj.m_mask;
  599. m_condition = obj.GetCondition();
  600. m_redirect = obj.GetRedirect();
  601. }
  602. RoutingRule& operator=(const RoutingRule& obj) {
  603. if (this == &obj) {
  604. return *this;
  605. } else {
  606. m_mask = obj.GetMask();
  607. m_condition = obj.GetCondition();
  608. m_redirect = obj.GetRedirect();
  609. return *this;
  610. }
  611. }
  612. void SetCondition(const Condition& condition) {
  613. m_mask = m_mask | 0x00000001u;
  614. m_condition = condition;
  615. }
  616. void SetRedirect(const Redirect& redirect) {
  617. m_mask = m_mask | 0x00000002u;
  618. m_redirect = redirect;
  619. }
  620. uint64_t GetMask() const { return m_mask; }
  621. const Condition& GetCondition() const { return m_condition; }
  622. const Redirect& GetRedirect() const { return m_redirect; }
  623. bool HasCondition() const { return (m_mask & 0x00000001u) != 0; }
  624. bool HasRedirect() const { return (m_mask & 0x00000002u) != 0; }
  625. virtual ~RoutingRule() {}
  626. private:
  627. uint64_t m_mask;
  628. Condition m_condition;
  629. Redirect m_redirect;
  630. };
  631. class Tag {
  632. public:
  633. Tag() : m_mask(0x00000000u), m_key(""), m_value("") {}
  634. void SetKey(const std::string key) {
  635. m_mask = m_mask | 0x00000001u;
  636. m_key = key;
  637. }
  638. void SetValue(const std::string value) {
  639. m_mask = m_mask | 0x00000002u;
  640. m_value = value;
  641. }
  642. uint64_t GetMask() const { return m_mask; }
  643. std::string GetKey() const { return m_key; }
  644. std::string GetValue() const { return m_value; }
  645. bool HasKey() const { return (m_mask & 0x00000001u) != 0; }
  646. bool HasValue() const { return (m_mask & 0x00000002u) != 0; }
  647. private:
  648. uint64_t m_mask;
  649. std::string m_key;
  650. std::string m_value;
  651. };
  652. class COSBucketDestination {
  653. public:
  654. COSBucketDestination()
  655. : m_mask(0x00000000u),
  656. m_format(""),
  657. m_accountId(""),
  658. m_bucket(""),
  659. m_prefix(""),
  660. m_encryption(false) {}
  661. void SetFormat(const std::string& format) {
  662. m_mask = m_mask | 0x00000001u;
  663. m_format = format;
  664. }
  665. void SetAccountId(const std::string& accountId) {
  666. m_mask = m_mask | 0x00000002u;
  667. m_accountId = accountId;
  668. }
  669. void SetBucket(const std::string& bucket) {
  670. m_mask = m_mask | 0x00000004u;
  671. m_bucket = bucket;
  672. }
  673. void SetPrefix(const std::string& prefix) {
  674. m_mask = m_mask | 0x00000008u;
  675. m_prefix = prefix;
  676. }
  677. void SetEncryption(const bool encryption) {
  678. m_mask = m_mask | 0x000000010u;
  679. m_encryption = encryption;
  680. }
  681. uint64_t GetMask() const { return m_mask; }
  682. std::string GetFormat() const { return m_format; }
  683. std::string GetAccountId() const { return m_accountId; }
  684. std::string GetBucket() const { return m_bucket; }
  685. std::string GetPrefix() const { return m_prefix; }
  686. bool GetEncryption() const { return m_encryption; }
  687. bool HasFormat() const { return (m_mask & 0x00000001u) != 0; }
  688. bool HasAccountId() const { return (m_mask & 0x00000002u) != 0; }
  689. bool HasBucket() const { return (m_mask & 0x00000004u) != 0; }
  690. bool HasPrefix() const { return (m_mask & 0x00000008u) != 0; }
  691. bool HasEncryption() const { return (m_mask & 0x00000010u) != 0; }
  692. private:
  693. uint64_t m_mask;
  694. std::string m_format;
  695. std::string m_accountId;
  696. std::string m_bucket;
  697. std::string m_prefix;
  698. bool m_encryption;
  699. };
  700. class OptionalFields {
  701. public:
  702. OptionalFields()
  703. : m_mask(0x00000000u),
  704. m_is_size(false),
  705. m_is_etag(false),
  706. m_is_last_modified(false),
  707. m_is_storage_class(false),
  708. m_is_replication_status(false),
  709. m_is_multipart_uploaded(false) {}
  710. void SetIsSize(const bool size) {
  711. m_mask = m_mask | 0x00000001u;
  712. m_is_size = size;
  713. }
  714. void SetIsLastModified(const bool last_modified) {
  715. m_mask = m_mask | 0x00000002u;
  716. m_is_last_modified = last_modified;
  717. }
  718. void SetIsStorageClass(const bool storage_class) {
  719. m_mask = m_mask | 0x00000004u;
  720. m_is_storage_class = storage_class;
  721. }
  722. void SetIsMultipartUploaded(const bool ismultipart_uploaded) {
  723. m_mask = m_mask | 0x00000008u;
  724. m_is_multipart_uploaded = ismultipart_uploaded;
  725. }
  726. void SetIsReplicationStatus(const bool replication_status) {
  727. m_mask = m_mask | 0x000000010u;
  728. m_is_replication_status = replication_status;
  729. }
  730. void SetIsEtag(const bool is_etag) {
  731. m_mask = m_mask | 0x000000020u;
  732. m_is_etag = is_etag;
  733. }
  734. uint64_t GetMask() const { return m_mask; }
  735. bool GetIsSize() const { return m_is_size; }
  736. bool GetIsLastModified() const { return m_is_last_modified; }
  737. bool GetIsStorageClass() const { return m_is_storage_class; }
  738. bool GetIsReplicationStatus() const { return m_is_replication_status; }
  739. bool GetIsMultipartUploaded() const { return m_is_multipart_uploaded; }
  740. bool GetIsETag() const { return m_is_etag; }
  741. bool HasIsSize() const { return (m_mask & 0x00000001u) != 0; }
  742. bool HasIsLastModified() const { return (m_mask & 0x00000002u) != 0; }
  743. bool HasIsStorageClass() const { return (m_mask & 0x00000004u) != 0; }
  744. bool HasIsReplicationStatus() const { return (m_mask & 0x00000008u) != 0; }
  745. bool HasIsMultipartUploaded() const { return (m_mask & 0x00000010u) != 0; }
  746. bool HasIsETag() const { return (m_mask & 0x00000020u) != 0; }
  747. private:
  748. uint64_t m_mask;
  749. bool m_is_size;
  750. bool m_is_etag;
  751. bool m_is_last_modified;
  752. bool m_is_storage_class;
  753. bool m_is_replication_status;
  754. bool m_is_multipart_uploaded;
  755. };
  756. class Inventory {
  757. public:
  758. Inventory()
  759. : m_mask(0x00000000u),
  760. m_id(""),
  761. m_included_objectversions(""),
  762. m_filter(""),
  763. m_frequency(""),
  764. m_is_enabled(true) {}
  765. Inventory& operator=(const Inventory& obj) {
  766. if (this == &obj) {
  767. return *this;
  768. } else {
  769. m_mask = obj.GetMask();
  770. m_id = obj.GetId();
  771. m_included_objectversions = obj.GetIncludedObjectVersions();
  772. m_filter = obj.GetFilter();
  773. m_is_enabled = obj.GetIsEnable();
  774. m_destination = obj.GetCOSBucketDestination();
  775. m_fields = obj.GetOptionalFields();
  776. m_frequency = obj.GetFrequency();
  777. return *this;
  778. }
  779. }
  780. void SetId(const std::string& id) {
  781. m_mask = m_mask | 0x00000001u;
  782. m_id = id;
  783. }
  784. void SetIsEnable(bool is_enabled) {
  785. m_mask = m_mask | 0x00000002u;
  786. m_is_enabled = is_enabled;
  787. }
  788. void SetIncludedObjectVersions(const std::string& included_objectversions) {
  789. m_mask = m_mask | 0x00000004u;
  790. m_included_objectversions = included_objectversions;
  791. }
  792. void SetFilter(const std::string& filter) {
  793. m_mask = m_mask | 0x00000008u;
  794. m_filter = filter;
  795. }
  796. void SetCOSBucketDestination(const COSBucketDestination& destination) {
  797. m_mask = m_mask | 0x00000010u;
  798. m_destination = destination;
  799. }
  800. void SetOptionalFields(const OptionalFields& fields) {
  801. m_mask = m_mask | 0x00000020u;
  802. m_fields = fields;
  803. }
  804. void SetFrequency(const std::string& frequency) {
  805. if (frequency == "Daily" || frequency == "Weekly") {
  806. m_mask = m_mask | 0x00000040u;
  807. m_frequency = frequency;
  808. } else {
  809. m_frequency = "";
  810. }
  811. }
  812. uint64_t GetMask() const { return m_mask; }
  813. std::string GetId() const { return m_id; }
  814. bool GetIsEnable() const { return m_is_enabled; }
  815. std::string GetIncludedObjectVersions() const {
  816. return m_included_objectversions;
  817. }
  818. std::string GetFilter() const { return m_filter; }
  819. const COSBucketDestination& GetCOSBucketDestination() const {
  820. return m_destination;
  821. }
  822. const OptionalFields& GetOptionalFields() const { return m_fields; }
  823. std::string GetFrequency() const { return m_frequency; }
  824. bool HasId() const { return (m_mask & 0x00000001u) != 0; }
  825. bool HasIsEnable() const { return (m_mask & 0x00000002u) != 0; }
  826. bool HasIncludedObjectVersions() const { return (m_mask & 0x00000004u) != 0; }
  827. bool HasFilter() const { return (m_mask & 0x00000008u) != 0; }
  828. bool HasCOSBucketDestination() const { return (m_mask & 0x000000010u) != 0; }
  829. bool HasOptionalFields() const { return (m_mask & 0x00000020u) != 0; }
  830. bool HasFrequency() const { return (m_mask & 0x00000040u) != 0; }
  831. private:
  832. uint64_t m_mask;
  833. std::string m_id;
  834. std::string m_included_objectversions;
  835. std::string m_filter;
  836. std::string m_frequency;
  837. bool m_is_enabled;
  838. COSBucketDestination m_destination;
  839. OptionalFields m_fields;
  840. };
  841. struct SelectMessage {
  842. std::string m_event_type;
  843. std::string m_content_type;
  844. // bool m_has_payload;
  845. std::string payload;
  846. // uint32_t m_payload_offset; // offset in body
  847. // uint32_t m_payload_len; // length
  848. };
  849. class LiveChannelConfiguration {
  850. public:
  851. LiveChannelConfiguration() {}
  852. LiveChannelConfiguration(const std::string& desc,
  853. const std::string& switch_info,
  854. const std::string& type, int frag_duartion,
  855. int frag_count, const std::string& playlist_name)
  856. : m_desc(desc),
  857. m_switch(switch_info),
  858. m_type(type),
  859. m_frag_duartion(frag_duartion),
  860. m_frag_count(frag_count),
  861. m_playlist_name(playlist_name) {}
  862. ~LiveChannelConfiguration() {}
  863. void SetDescription(const std::string& desc) { m_desc = desc; }
  864. std::string GetDescription() const { return m_desc; }
  865. /// brief: "Enabled" or "Disabled"
  866. void SetSwitch(const std::string& switch_info) { m_switch = switch_info; }
  867. std::string GetSwitch() const { return m_switch; }
  868. /// brief: only support "HLS" for now
  869. void SetType(const std::string& type) { m_type = type; }
  870. std::string GetType() const { return m_type; }
  871. void SetFragDuration(const int frag_duartion) {
  872. m_frag_duartion = frag_duartion;
  873. }
  874. int GetFragDuration() const { return m_frag_duartion; }
  875. void SetFragCount(const int frag_count) { m_frag_count = frag_count; }
  876. int GetFragCount() const { return m_frag_count; }
  877. void SetPlaylistName(const std::string& playlist_name) {
  878. m_playlist_name = playlist_name;
  879. }
  880. std::string GetPlaylistName() const { return m_playlist_name; }
  881. void SetPublishUrl(const std::string& url) { m_publish_url = url; }
  882. std::string GetPublishUrl() const { return m_publish_url; }
  883. void SetPlayUrl(const std::string& url) { m_play_url = url; }
  884. std::string GetPlayUrl() const { return m_play_url; }
  885. private:
  886. std::string m_desc; // 通道描述信息
  887. std::string m_switch; // "Enabled" or "Disabled"
  888. std::string m_type; // 目前仅支持"HLS"
  889. int m_frag_duartion; // [1, 100]
  890. int m_frag_count; // [1, 100]
  891. std::string m_playlist_name;
  892. std::string m_publish_url;
  893. std::string m_play_url;
  894. };
  895. /// @brief 直播通道推流历史记录
  896. struct LiveRecord {
  897. std::string m_start_time; // 推流开始时间
  898. std::string m_end_time; // 推流结束时间
  899. std::string m_remote_addr; // 客户端ip地址和端口
  900. std::string m_request_id; // 请求ID
  901. };
  902. /// @brief 直播通道推流的视频信息
  903. struct LiveChannelVideoInfo {
  904. std::string m_width;
  905. std::string m_heigh;
  906. std::string m_framerate;
  907. std::string m_bandwidth;
  908. std::string m_codec;
  909. };
  910. /// @brief 直播通道推流的音频信息
  911. struct LiveChannelAudioInfo {
  912. std::string m_bandwidth;
  913. std::string m_samplerate;
  914. std::string m_codec;
  915. };
  916. /// @brief 直播通道推流的状态
  917. struct LiveChannelStatus {
  918. LiveChannelStatus() : m_has_video(false), m_has_audio(false) {}
  919. std::string m_status; // 流当前状态
  920. std::string m_connected_time; // 推流开始时间
  921. std::string m_remote_addr; // 客户端ip地址和端口
  922. std::string m_request_id; // 请求ID
  923. bool m_has_video;
  924. LiveChannelVideoInfo m_video;
  925. bool m_has_audio;
  926. LiveChannelAudioInfo m_audio;
  927. };
  928. /// @brief 列举得到的通道信息
  929. struct LiveChannel {
  930. std::string m_name; // 通道名
  931. std::string m_last_modified; // 上次修改时间
  932. };
  933. /// @brief 列举通道结果
  934. struct ListLiveChannelResult {
  935. std::string
  936. m_max_keys; // 单次响应返回结果的最大条目数量,对应请求中的 max-keys 参数
  937. std::string m_marker; // 起始通道标记,从该标记之后(不含)按照 UTF-8
  938. // 字典序返回通道,对应请求中的marker参数
  939. std::string m_prefix; // 通道名匹配前缀,限定响应中只包含指定前缀的通道名
  940. std::string m_is_truncated; // 响应条目是否被截断,布尔值,例如 true 或 false
  941. std::string
  942. m_next_marker; // 仅当响应条目有截断(IsTruncated 为
  943. // true)才会返回该节点,
  944. // 该节点的值为当前响应条目中的最后一个通道名,当需要继续请求后续条目时,
  945. // 将该节点的值作为下一次请求的 marker 参数传入
  946. std::vector<LiveChannel> m_channels;
  947. void Clear() {
  948. m_max_keys = "";
  949. m_marker = "";
  950. m_prefix = "";
  951. m_is_truncated = "";
  952. m_next_marker = "";
  953. m_channels.clear();
  954. }
  955. };
  956. } // namespace qcloud_cos
  957. #endif // COS_CPP_SDK_V5_INCLUDE_COS_DEFINES_H_