bucket_resp.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. // Copyright (c) 2017, Tencent Inc.
  2. // All rights reserved.
  3. //
  4. // Author: sevenyou <sevenyou@tencent.com>
  5. // Created: 07/21/17
  6. // Description:
  7. #ifndef BUCKET_RESP_H
  8. #define BUCKET_RESP_H
  9. #pragma once
  10. #include <vector>
  11. #include "cos_config.h"
  12. #include "cos_defines.h"
  13. #include "rapidxml/1.13/rapidxml.hpp"
  14. #include "rapidxml/1.13/rapidxml_print.hpp"
  15. #include "rapidxml/1.13/rapidxml_utils.hpp"
  16. #include "response/base_resp.h"
  17. namespace qcloud_cos {
  18. class PutBucketResp : public BaseResp {
  19. public:
  20. PutBucketResp() {}
  21. virtual ~PutBucketResp() {}
  22. };
  23. class HeadBucketResp : public BaseResp {
  24. public:
  25. HeadBucketResp() {}
  26. virtual ~HeadBucketResp() {}
  27. };
  28. class GetBucketResp : public BaseResp {
  29. public:
  30. GetBucketResp() {}
  31. virtual ~GetBucketResp() {}
  32. virtual bool ParseFromXmlString(const std::string& body);
  33. /// \brief 获取Bucket中Object对应的元信息
  34. std::vector<Content> GetContents() const { return m_contents; }
  35. /// \brief Bucket名称
  36. std::string GetName() const { return m_name; }
  37. /// \brief 获取定界符
  38. std::string GetDelimiter() const { return m_delimiter; }
  39. /// \brief 编码格式
  40. std::string GetEncodingType() const { return m_encoding_type; }
  41. /// \brief 返回的文件前缀
  42. std::string GetPrefix() const { return m_prefix; }
  43. /// \brief 默认以UTF-8二进制顺序列出条目,所有列出条目从marker开始
  44. std::string GetMarker() const { return m_marker; }
  45. /// \brief 单次响应请求内返回结果的最大的条目数量
  46. uint64_t GetMaxKeys() const { return m_max_keys; }
  47. /// \brief 响应请求条目是否被截断,布尔值:true,false
  48. bool IsTruncated() const { return m_is_truncated; }
  49. /// \brief 假如返回条目被截断,则返回 NextMarker 就是下一个条目的起点
  50. std::string GetNextMarker() const { return m_next_marker; }
  51. /// \brief 将 Prefix 到 delimiter 之间的相同路径归为一类,定义为 Common Prefix
  52. std::vector<std::string> GetCommonPrefixes() const {
  53. return m_common_prefixes;
  54. }
  55. private:
  56. std::vector<Content> m_contents;
  57. std::string m_name;
  58. std::string m_encoding_type;
  59. std::string m_delimiter;
  60. std::string m_prefix;
  61. std::string m_marker;
  62. uint64_t m_max_keys;
  63. bool m_is_truncated;
  64. std::string m_next_marker;
  65. std::vector<std::string> m_common_prefixes;
  66. };
  67. class DeleteBucketResp : public BaseResp {
  68. public:
  69. DeleteBucketResp() {}
  70. virtual ~DeleteBucketResp() {}
  71. };
  72. class GetBucketVersioningResp : public BaseResp {
  73. public:
  74. GetBucketVersioningResp() : m_status(0) {}
  75. virtual ~GetBucketVersioningResp() {}
  76. virtual bool ParseFromXmlString(const std::string& body);
  77. /// \brief 返回bucket的版本状态,0: 从未开启版本管理, 1: 版本管理生效中, 2:
  78. /// 暂停 区别于PutBucketVersioning, 一个Bucket可能处于三种状态
  79. int GetStatus() const { return m_status; }
  80. private:
  81. int m_status;
  82. };
  83. class PutBucketVersioningResp : public BaseResp {
  84. public:
  85. PutBucketVersioningResp() {}
  86. virtual ~PutBucketVersioningResp() {}
  87. };
  88. class GetBucketReplicationResp : public BaseResp {
  89. public:
  90. GetBucketReplicationResp() {}
  91. virtual ~GetBucketReplicationResp() {}
  92. virtual bool ParseFromXmlString(const std::string& body);
  93. std::string GetRole() const { return m_role; }
  94. std::vector<ReplicationRule> GetRules() const { return m_rules; }
  95. private:
  96. std::string m_role;
  97. std::vector<ReplicationRule> m_rules;
  98. };
  99. class PutBucketReplicationResp : public BaseResp {
  100. public:
  101. PutBucketReplicationResp() {}
  102. virtual ~PutBucketReplicationResp() {}
  103. };
  104. class DeleteBucketReplicationResp : public BaseResp {
  105. public:
  106. DeleteBucketReplicationResp() {}
  107. virtual ~DeleteBucketReplicationResp() {}
  108. };
  109. class GetBucketLifecycleResp : public BaseResp {
  110. public:
  111. GetBucketLifecycleResp() {}
  112. virtual ~GetBucketLifecycleResp() {}
  113. virtual bool ParseFromXmlString(const std::string& body);
  114. std::vector<LifecycleRule> GetRules() const { return m_rules; }
  115. private:
  116. std::vector<LifecycleRule> m_rules;
  117. };
  118. class PutBucketLifecycleResp : public BaseResp {
  119. public:
  120. PutBucketLifecycleResp() {}
  121. virtual ~PutBucketLifecycleResp() {}
  122. };
  123. class DeleteBucketLifecycleResp : public BaseResp {
  124. public:
  125. DeleteBucketLifecycleResp() {}
  126. virtual ~DeleteBucketLifecycleResp() {}
  127. };
  128. class GetBucketACLResp : public BaseResp {
  129. public:
  130. GetBucketACLResp() {}
  131. virtual ~GetBucketACLResp() {}
  132. virtual bool ParseFromXmlString(const std::string& body);
  133. std::string GetOwnerID() const { return m_owner_id; }
  134. std::string GetOwnerDisplayName() const { return m_owner_display_name; }
  135. std::vector<Grant> GetAccessControlList() const { return m_acl; }
  136. private:
  137. std::string m_owner_id;
  138. std::string m_owner_display_name;
  139. std::vector<Grant> m_acl;
  140. };
  141. // TODO
  142. class ListMultipartUploadResp : public BaseResp {
  143. public:
  144. ListMultipartUploadResp() {}
  145. virtual ~ListMultipartUploadResp() {}
  146. virtual bool ParseFromXmlString(const std::string& body);
  147. /// \brief 获取Bucket中Object对应的元信息
  148. std::vector<Upload> GetUpload() const { return m_upload; }
  149. /// \brief Bucket名称
  150. std::string GetName() const { return m_name; }
  151. /// \brief 编码格式
  152. std::string GetEncodingType() const { return m_encoding_type; }
  153. /// \brief 默认以UTF-8二进制顺序列出条目,所有列出条目从marker开始
  154. std::string GetMarker() const { return m_marker; }
  155. std::string GetUploadIdMarker() const { return m_uploadid_marker; }
  156. std::string GetNextKeyMarker() const { return m_nextkey_marker; }
  157. std::string GetNextUploadIdMarker() const { return m_nextuploadid_marker; }
  158. std::string GetMaxUploads() const { return m_max_uploads; }
  159. /// \brief 响应请求条目是否被截断,布尔值:true,false
  160. bool IsTruncated() const { return m_is_truncated; }
  161. /// \brief 返回的文件前缀
  162. std::string GetPrefix() const { return m_prefix; }
  163. /// \brief 获取定界符
  164. std::string GetDelimiter() const { return m_delimiter; }
  165. /// \brief 将 Prefix 到 delimiter 之间的相同路径归为一类,定义为 Common Prefix
  166. std::vector<std::string> GetCommonPrefixes() const {
  167. return m_common_prefixes;
  168. }
  169. private:
  170. std::vector<Upload> m_upload;
  171. std::string m_name;
  172. std::string m_encoding_type;
  173. std::string m_delimiter;
  174. std::string m_prefix;
  175. std::string m_marker;
  176. std::string m_uploadid_marker;
  177. std::string m_nextkey_marker;
  178. std::string m_nextuploadid_marker;
  179. std::string m_max_uploads;
  180. bool m_is_truncated;
  181. std::vector<std::string> m_common_prefixes;
  182. };
  183. class PutBucketACLResp : public BaseResp {
  184. public:
  185. PutBucketACLResp() {}
  186. virtual ~PutBucketACLResp() {}
  187. };
  188. class GetBucketPolicyResp : public BaseResp {
  189. public:
  190. GetBucketPolicyResp() {}
  191. virtual ~GetBucketPolicyResp() {}
  192. std::string GetPolicy() const { return GetBody(); }
  193. };
  194. class PutBucketPolicyResp : public BaseResp {
  195. public:
  196. PutBucketPolicyResp() {}
  197. virtual ~PutBucketPolicyResp() {}
  198. };
  199. class DeleteBucketPolicyResp : public BaseResp {
  200. public:
  201. DeleteBucketPolicyResp() {}
  202. virtual ~DeleteBucketPolicyResp() {}
  203. };
  204. class GetBucketCORSResp : public BaseResp {
  205. public:
  206. GetBucketCORSResp() {}
  207. virtual ~GetBucketCORSResp() {}
  208. virtual bool ParseFromXmlString(const std::string& body);
  209. std::vector<CORSRule> GetCORSRules() const { return m_rules; }
  210. private:
  211. std::vector<CORSRule> m_rules;
  212. };
  213. class PutBucketCORSResp : public BaseResp {
  214. public:
  215. PutBucketCORSResp() {}
  216. virtual ~PutBucketCORSResp() {}
  217. };
  218. class DeleteBucketCORSResp : public BaseResp {
  219. public:
  220. DeleteBucketCORSResp() {}
  221. virtual ~DeleteBucketCORSResp() {}
  222. };
  223. class GetBucketLocationResp : public BaseResp {
  224. public:
  225. GetBucketLocationResp() {}
  226. virtual ~GetBucketLocationResp() {}
  227. std::string GetLocation() const { return m_location; }
  228. virtual bool ParseFromXmlString(const std::string& body);
  229. private:
  230. std::string m_location;
  231. };
  232. class GetBucketObjectVersionsResp : public BaseResp {
  233. public:
  234. GetBucketObjectVersionsResp() {}
  235. virtual ~GetBucketObjectVersionsResp() {}
  236. /// \brief 编码格式
  237. std::string GetEncodingType() const { return m_encoding_type; }
  238. /// \brief 返回的文件前缀
  239. std::string GetPrefix() const { return m_prefix; }
  240. /// \brief 单次响应请求内返回结果的最大的条目数量
  241. uint64_t GetMaxKeys() const { return m_max_keys; }
  242. /// \brief 响应请求条目是否被截断,布尔值:true,false
  243. bool IsTruncated() const { return m_is_truncated; }
  244. /// \brief 假如返回条目被截断,则返回 NextKeyMarker 就是下一个条目的起点
  245. std::string GetNextKeyMarker() const { return m_next_key_marker; }
  246. std::string GetKeyMarker() const { return m_key_marker; }
  247. std::string GetBucketName() const { return m_bucket_name; }
  248. std::string GetVersionIdMarker() const { return m_version_id_marker; }
  249. std::vector<COSVersionSummary> GetVersionSummary() const {
  250. return m_summaries;
  251. }
  252. virtual bool ParseFromXmlString(const std::string& body);
  253. private:
  254. std::vector<COSVersionSummary> m_summaries;
  255. std::string m_encoding_type;
  256. bool m_is_truncated;
  257. uint64_t m_max_keys;
  258. std::string m_bucket_name;
  259. std::string m_key_marker;
  260. std::string m_prefix;
  261. std::string m_version_id_marker;
  262. std::string m_next_key_marker;
  263. std::string m_next_version_id_marker;
  264. };
  265. class PutBucketLoggingResp : public BaseResp {
  266. public:
  267. PutBucketLoggingResp() {}
  268. virtual ~PutBucketLoggingResp() {}
  269. };
  270. class GetBucketLoggingResp : public BaseResp {
  271. public:
  272. GetBucketLoggingResp() {}
  273. virtual ~GetBucketLoggingResp() {}
  274. virtual bool ParseFromXmlString(const std::string& body);
  275. LoggingEnabled GetLoggingEnabled() const { return m_rules; }
  276. private:
  277. LoggingEnabled m_rules;
  278. };
  279. class PutBucketDomainResp : public BaseResp {
  280. public:
  281. PutBucketDomainResp() {}
  282. virtual ~PutBucketDomainResp() {}
  283. virtual bool ParseFromXmlString(const std::string& body);
  284. DomainErrorMsg GetDomainErrorMsg() const { return m_rules; }
  285. private:
  286. DomainErrorMsg m_rules;
  287. };
  288. class GetBucketDomainResp : public BaseResp {
  289. public:
  290. GetBucketDomainResp() {}
  291. virtual ~GetBucketDomainResp() {}
  292. virtual bool ParseFromXmlString(const std::string& body);
  293. std::string GetStatus() const { return m_status; }
  294. std::string GetName() const { return m_name; }
  295. std::string GetType() const { return m_type; }
  296. void SetStatus(const std::string& status) { m_status = status; }
  297. void SetName(const std::string& name) { m_name = name; }
  298. void SetType(const std::string& type) { m_type = type; }
  299. private:
  300. std::string m_status;
  301. std::string m_name;
  302. std::string m_type;
  303. };
  304. class PutBucketWebsiteResp : public BaseResp {
  305. public:
  306. PutBucketWebsiteResp() {}
  307. virtual ~PutBucketWebsiteResp() {}
  308. };
  309. class GetBucketWebsiteResp : public BaseResp {
  310. public:
  311. GetBucketWebsiteResp() {}
  312. virtual ~GetBucketWebsiteResp() {}
  313. virtual bool ParseFromXmlString(const std::string& body);
  314. bool ParseFromXmlRoutingRule(rapidxml::xml_node<>* node,
  315. RoutingRule& tmp_routingrule);
  316. void SetSuffix(const std::string& suffix) { m_suffix = suffix; }
  317. void SetProtocol(const std::string& protocol) { m_protocol = protocol; }
  318. void SetKey(const std::string& key) { m_key = key; }
  319. std::string GetSuffix() const { return m_suffix; }
  320. std::string GetProtocol() const { return m_protocol; }
  321. std::string GetKey() const { return m_key; }
  322. /// 设置重定向规则
  323. void SetRoutingRules(const std::vector<RoutingRule>& routingrules) {
  324. m_routingrules = routingrules;
  325. }
  326. std::vector<RoutingRule> GetRoutingRules() const { return m_routingrules; }
  327. /// 添加单个rule
  328. void AddRoutingRule(const RoutingRule& routingrule) {
  329. m_routingrules.push_back(routingrule);
  330. }
  331. /// 清空重定向规则
  332. void ClearRoutingRule() {
  333. std::vector<RoutingRule> tmp;
  334. m_routingrules.swap(tmp);
  335. }
  336. private:
  337. std::string m_suffix;
  338. std::string m_protocol;
  339. std::string m_key;
  340. std::vector<RoutingRule> m_routingrules;
  341. };
  342. class DeleteBucketWebsiteResp : public BaseResp {
  343. public:
  344. DeleteBucketWebsiteResp() {}
  345. virtual ~DeleteBucketWebsiteResp() {}
  346. };
  347. class PutBucketTaggingResp : public BaseResp {
  348. public:
  349. PutBucketTaggingResp() {}
  350. virtual ~PutBucketTaggingResp() {}
  351. };
  352. class GetBucketTaggingResp : public BaseResp {
  353. public:
  354. GetBucketTaggingResp() {}
  355. void SetTagSet(std::vector<Tag>& tagset) { m_tagset = tagset; }
  356. std::vector<Tag> GetTagSet() const { return m_tagset; }
  357. //清除tag规则.
  358. void ClearTagSet() {
  359. std::vector<Tag> temp;
  360. m_tagset.swap(temp);
  361. }
  362. /// 添加单个tag.
  363. void AddTag(const Tag& tag) { m_tagset.push_back(tag); }
  364. virtual bool ParseFromXmlString(const std::string& body);
  365. virtual ~GetBucketTaggingResp() {}
  366. private:
  367. std::vector<Tag> m_tagset;
  368. };
  369. class DeleteBucketTaggingResp : public BaseResp {
  370. public:
  371. DeleteBucketTaggingResp() {}
  372. virtual ~DeleteBucketTaggingResp() {}
  373. };
  374. class PutBucketInventoryResp : public BaseResp {
  375. public:
  376. PutBucketInventoryResp() {}
  377. virtual ~PutBucketInventoryResp() {}
  378. };
  379. class GetBucketInventoryResp : public BaseResp {
  380. public:
  381. GetBucketInventoryResp() : m_mask(0x00000001u) {}
  382. void SetInventory(const Inventory& inventory) {
  383. m_mask = m_mask | 0x00000001u;
  384. m_inventory = inventory;
  385. }
  386. bool HasInventory() const { return (m_mask & 0x00000001u) != 0; }
  387. const Inventory& GetInventory() const { return m_inventory; }
  388. bool ParseFromXmlOptionalFields(rapidxml::xml_node<>* node,
  389. Inventory& temp_inventory);
  390. bool ParseFromXmlCOSBucketDestination(rapidxml::xml_node<>* node,
  391. Inventory& temp_inventory);
  392. bool ParseFromXmlInventoryConfiguration(rapidxml::xml_node<>* node,
  393. Inventory& temp_inventory);
  394. virtual bool ParseFromXmlString(const std::string& body);
  395. virtual ~GetBucketInventoryResp() {}
  396. private:
  397. uint64_t m_mask;
  398. Inventory m_inventory;
  399. };
  400. class ListBucketInventoryConfigurationsResp : public GetBucketInventoryResp {
  401. public:
  402. ListBucketInventoryConfigurationsResp()
  403. : m_is_truncated(false),
  404. m_continuation_token(""),
  405. m_next_continuation_token("") {}
  406. virtual bool ParseFromXmlString(const std::string& body);
  407. virtual ~ListBucketInventoryConfigurationsResp() {}
  408. /// 添加单个Inventory.
  409. void AddInventory(const Inventory& inventory) {
  410. m_inventory_vec.push_back(inventory);
  411. }
  412. void SetInventoryVec(std::vector<Inventory>& inventory_vec) {
  413. m_inventory_vec = inventory_vec;
  414. }
  415. void SetIsTruncated(bool is_truncated) { m_is_truncated = is_truncated; }
  416. void SetContinuationToken(std::string continuation_token) {
  417. m_continuation_token = continuation_token;
  418. }
  419. void SetNextContinuationToken(std::string next_continuation_token) {
  420. m_next_continuation_token = next_continuation_token;
  421. }
  422. std::vector<Inventory> GetInventory() const { return m_inventory_vec; }
  423. bool GetIsTruncated() const { return m_is_truncated; }
  424. std::string GetContinuationToken() const { return m_continuation_token; }
  425. std::string GetNextContinuationToken() const {
  426. return m_next_continuation_token;
  427. }
  428. private:
  429. std::vector<Inventory> m_inventory_vec;
  430. bool m_is_truncated;
  431. std::string m_continuation_token;
  432. std::string m_next_continuation_token;
  433. };
  434. class DeleteBucketInventoryResp : public BaseResp {
  435. public:
  436. DeleteBucketInventoryResp() {}
  437. virtual ~DeleteBucketInventoryResp() {}
  438. };
  439. /// \brief: 列举直播通道响应
  440. class ListLiveChannelResp : public BaseResp {
  441. public:
  442. ListLiveChannelResp() {}
  443. virtual ~ListLiveChannelResp() {}
  444. virtual bool ParseFromXmlString(const std::string& body);
  445. const ListLiveChannelResult& GetListResult() const { return result; }
  446. void ClearResult() { result.Clear(); }
  447. private:
  448. ListLiveChannelResult result;
  449. };
  450. /// \brief: 配置存储桶智能分层的响应
  451. class PutBucketIntelligentTieringResp : public BaseResp {
  452. public:
  453. PutBucketIntelligentTieringResp() {}
  454. virtual ~PutBucketIntelligentTieringResp() {}
  455. };
  456. /// \brief: 获取配置存储桶智能分层配置的响应
  457. class GetBucketIntelligentTieringResp : public BaseResp {
  458. public:
  459. GetBucketIntelligentTieringResp() {}
  460. virtual ~GetBucketIntelligentTieringResp() {}
  461. virtual bool ParseFromXmlString(const std::string& body);
  462. std::string GetStatus() const { return m_status; }
  463. uint32_t GetDays() const { return m_days; }
  464. uint32_t GetRequestFrequent() const { return m_freq; }
  465. private:
  466. std::string m_status;
  467. int m_days;
  468. int m_freq;
  469. };
  470. /// \brief: 配置存储桶Referer响应
  471. class PutBucketRefererResp : public BaseResp {
  472. public:
  473. PutBucketRefererResp() {}
  474. virtual ~PutBucketRefererResp() {}
  475. };
  476. /// \brief: 获取存储桶Referer响应
  477. class GetBucketRefererResp : public BaseResp {
  478. public:
  479. GetBucketRefererResp() {}
  480. virtual ~GetBucketRefererResp() {}
  481. virtual bool ParseFromXmlString(const std::string& body);
  482. std::string GetStatus() const { return m_status; }
  483. std::string GetRefererType() const { return m_referer_type; }
  484. std::vector<std::string> GetDomainList() const { return m_domain_list; }
  485. std::string GetEmptyReferConf() const { return m_empty_refer_conf; }
  486. std::string GetVerifySignatureUrl() const {return m_verify_signature_url; }
  487. private:
  488. std::string m_status;
  489. std::string m_referer_type;
  490. std::vector<std::string> m_domain_list;
  491. std::string m_empty_refer_conf;
  492. std::string m_verify_signature_url;
  493. };
  494. } // namespace qcloud_cos
  495. #endif // BUCKET_RESP_H