cos_defines.h 32 KB

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