mns_protocol.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. // Copyright (C) 2015, Alibaba Cloud Computing
  2. #ifndef MNS_PROTOCOL_H
  3. #define MNS_PROTOCOL_H
  4. #include <iostream>
  5. #include <fstream>
  6. #include <map>
  7. #include <vector>
  8. #include <string>
  9. #include <stdint.h>
  10. #include "pugixml.hpp"
  11. #include "mns_utils.h"
  12. namespace mns
  13. {
  14. namespace sdk
  15. {
  16. enum NotifyStrategy
  17. {
  18. UNKNOWN_STRATEGY, // do not specify the strategy and use default value
  19. BACKOFF_RETRY,
  20. EXPONENTIAL_DECAY_RETRY
  21. };
  22. class NotifyStrategyHelper
  23. {
  24. public:
  25. static std::string NotifyStrategyToString(const NotifyStrategy notifyStrategy)
  26. {
  27. if (notifyStrategy == BACKOFF_RETRY)
  28. {
  29. return "BACKOFF_RETRY";
  30. }
  31. if (notifyStrategy == EXPONENTIAL_DECAY_RETRY)
  32. {
  33. return "EXPONENTIAL_DECAY_RETRY";
  34. }
  35. return "UNKNOWN_STRATEGY";
  36. }
  37. static NotifyStrategy StringToNotifyStrategy(const std::string& notifyStrategyStr)
  38. {
  39. if (notifyStrategyStr == "BACKOFF_RETRY")
  40. {
  41. return BACKOFF_RETRY;
  42. }
  43. if (notifyStrategyStr == "EXPONENTIAL_DECAY_RETRY")
  44. {
  45. return EXPONENTIAL_DECAY_RETRY;
  46. }
  47. return UNKNOWN_STRATEGY;
  48. }
  49. };
  50. enum ContentFormat
  51. {
  52. UNKNOWN_FORMAT, // do not specify the format and use default value
  53. XML,
  54. SIMPLIFIED,
  55. JSON
  56. };
  57. class ContentFormatHelper
  58. {
  59. public:
  60. static std::string ContentFormatToString(const ContentFormat contentFormat)
  61. {
  62. switch (contentFormat)
  63. {
  64. case XML:
  65. return "XML";
  66. case SIMPLIFIED:
  67. return "SIMPLIFIED";
  68. case JSON:
  69. return "JSON";
  70. default:
  71. return "UNKNOWN_FORMAT";
  72. }
  73. }
  74. static ContentFormat StringToContentFormat(const std::string& contentFormatStr)
  75. {
  76. if (contentFormatStr == "XML")
  77. {
  78. return XML;
  79. }
  80. if (contentFormatStr == "SIMPLIFIED")
  81. {
  82. return SIMPLIFIED;
  83. }
  84. if (contentFormatStr == "JSON")
  85. {
  86. return JSON;
  87. }
  88. return UNKNOWN_FORMAT;
  89. }
  90. };
  91. enum SMSType
  92. {
  93. SINGLE_SMS,
  94. BATCH_SMS
  95. };
  96. struct SendMessageItem
  97. {
  98. SendMessageItem(const std::string& body = "",
  99. const int32_t delaySec = -1,
  100. const int32_t prio = -1)
  101. : messageBody(body)
  102. , delaySeconds(delaySec)
  103. , priority(prio)
  104. {
  105. }
  106. std::string messageBody;
  107. int32_t delaySeconds;
  108. int32_t priority;
  109. };
  110. struct SendMessageSucceedItem
  111. {
  112. SendMessageSucceedItem()
  113. : messageId(""), messageBodyMD5("")
  114. {
  115. }
  116. std::string messageId;
  117. std::string messageBodyMD5;
  118. };
  119. struct DeleteMessageFailedItem
  120. {
  121. DeleteMessageFailedItem()
  122. : errorCode("")
  123. , errorMessage("")
  124. , receiptHandle("")
  125. {
  126. }
  127. std::string errorCode;
  128. std::string errorMessage;
  129. std::string receiptHandle;
  130. };
  131. struct SendMessageFailedItem
  132. {
  133. SendMessageFailedItem()
  134. : errorCode("")
  135. , errorMessage("")
  136. {
  137. }
  138. std::string errorCode;
  139. std::string errorMessage;
  140. };
  141. class MessageAttributes;
  142. class MailAttributes
  143. {
  144. public:
  145. const std::string& getSubject();
  146. void setSubject(const std::string& subject);
  147. const std::string& getAccountName();
  148. void setAccountName(const std::string& accountName);
  149. int getAddressType();
  150. void setAddressType(int addressType);
  151. bool getReplyToAddress();
  152. void setReplyToAddress(bool replyToAddress);
  153. bool getIsHtml();
  154. void setIsHtml(bool isHtml);
  155. std::string toJson();
  156. friend class MessageAttributes;
  157. protected:
  158. MailAttributes();
  159. protected:
  160. /*
  161. * Please Refer to https://help.aliyun.com/document_detail/directmail/api-reference/sendmail-related/SingleSendMail.html
  162. */
  163. std::string mSubject;
  164. std::string mAccountName;
  165. int mAddressType;
  166. bool mReplyToAddress;
  167. bool mIsHtml;
  168. };
  169. class SMSAttributes
  170. {
  171. public:
  172. std::string toJson();
  173. SMSType getType();
  174. std::string getSignName();
  175. void setSignName(const std::string& signName);
  176. std::string getTemplateCode();
  177. void setTemplateCode(const std::string& templateCode);
  178. std::string getReceiver();
  179. void setReceiver(const std::string& receiver);
  180. std::string getSingleParam(const std::string& key);
  181. void setSingleParam(const std::string& key, const std::string& value);
  182. std::map<std::string, std::string> getBatchParam(const std::string& phone);
  183. std::string getBatchParam(const std::string& phone, const std::string& key);
  184. void setBatchParam(const std::string& phone, const std::string& key, const std::string& value);
  185. void setBatchParam(const std::string& phone, const std::map<std::string, std::string>& params);
  186. friend class MessageAttributes;
  187. protected:
  188. SMSAttributes(const SMSType type);
  189. private:
  190. SMSType mType;
  191. std::string mSignName;
  192. std::string mTemplateCode;
  193. std::string mReceiver;
  194. std::map<std::string, std::string> mSingleParams;
  195. std::map<std::string, std::map<std::string, std::string> > mBatchParams;
  196. };
  197. class PublishMessageRequest;
  198. class MessageAttributes
  199. {
  200. public:
  201. MessageAttributes()
  202. : mpMailAttributes(NULL)
  203. , mpSMSAttributes(NULL)
  204. {}
  205. virtual ~MessageAttributes()
  206. {
  207. if (mpMailAttributes != NULL)
  208. {
  209. delete mpMailAttributes;
  210. }
  211. if (mpSMSAttributes != NULL)
  212. {
  213. delete mpSMSAttributes;
  214. }
  215. }
  216. /** Get MailAttributes Ptr
  217. *
  218. * @param isCreate: if isCreate is true and mailAttributes does not exist,
  219. * the mailAttributes will be created.
  220. */
  221. MailAttributes* getMailAttributesPtr(bool isCreate = true)
  222. {
  223. if (mpMailAttributes == NULL && isCreate)
  224. {
  225. PTScopedLock lock(mMutex);
  226. mpMailAttributes = new MailAttributes();
  227. }
  228. return mpMailAttributes;
  229. }
  230. SMSAttributes* getSMSAttributesPtr(const SMSType smsType = BATCH_SMS, bool isCreate = true)
  231. {
  232. if (mpSMSAttributes == NULL && isCreate)
  233. {
  234. PTScopedLock lock(mMutex);
  235. mpSMSAttributes = new SMSAttributes(smsType);
  236. }
  237. return mpSMSAttributes;
  238. }
  239. friend class PublishMessageRequest;
  240. protected:
  241. MailAttributes* getMailAttributesPtrNoCreate() const
  242. {
  243. return mpMailAttributes;
  244. }
  245. SMSAttributes* getSMSAttributesPtrNoCreate() const
  246. {
  247. return mpSMSAttributes;
  248. }
  249. protected:
  250. MailAttributes* mpMailAttributes;
  251. SMSAttributes* mpSMSAttributes;
  252. PTMutex mMutex;
  253. };
  254. class ReceiveMessageResponse;
  255. class BatchReceiveMessageResponse;
  256. class Message
  257. {
  258. public:
  259. Message()
  260. : mMessageId("")
  261. , mReceiptHandle("")
  262. , mMessageBody("")
  263. , mMessageBodyMD5("")
  264. , mEnqueueTime(-1)
  265. , mNextVisibleTime(-1)
  266. , mFirstDequeueTime(-1)
  267. , mDequeueCount(-1)
  268. , mPriority(-1)
  269. {
  270. }
  271. const std::string& getMessageId()
  272. {
  273. return mMessageId;
  274. }
  275. const std::string& getReceiptHandle()
  276. {
  277. return mReceiptHandle;
  278. }
  279. const std::string& getMessageBody()
  280. {
  281. return mMessageBody;
  282. }
  283. const std::string& getMessageBodyMD5()
  284. {
  285. return mMessageBodyMD5;
  286. }
  287. int64_t getEnqueueTime()
  288. {
  289. return mEnqueueTime;
  290. }
  291. int64_t getFirstDequeueTime()
  292. {
  293. return mFirstDequeueTime;
  294. }
  295. int64_t getNextVisibleTime()
  296. {
  297. return mNextVisibleTime;
  298. }
  299. int32_t getDequeueCount()
  300. {
  301. return mDequeueCount;
  302. }
  303. int32_t getPriority()
  304. {
  305. return mPriority;
  306. }
  307. friend class ReceiveMessageResponse;
  308. friend class BatchReceiveMessageResponse;
  309. friend class PeekMessageResponse;
  310. friend class BatchPeekMessageResponse;
  311. protected:
  312. void initFromXml(const pugi::xml_node& messageNode);
  313. protected:
  314. std::string mMessageId;
  315. std::string mReceiptHandle;
  316. std::string mMessageBody;
  317. std::string mMessageBodyMD5;
  318. int64_t mEnqueueTime;
  319. int64_t mNextVisibleTime;
  320. int64_t mFirstDequeueTime;
  321. int32_t mDequeueCount;
  322. int32_t mPriority;
  323. };
  324. class GetAccountAttributesResponse;
  325. class SetAccountAttributesRequest;
  326. class AccountAttributes
  327. {
  328. public:
  329. AccountAttributes()
  330. : mLoggingBucket("")
  331. , mLoggingBucketSet(false)
  332. {
  333. }
  334. void clear()
  335. {
  336. mLoggingBucket = "";
  337. mLoggingBucketSet = false;
  338. }
  339. void setLoggingBucket(const std::string& loggingBucket)
  340. {
  341. mLoggingBucket = loggingBucket;
  342. mLoggingBucketSet = true;
  343. }
  344. std::string getLoggingBucket() const
  345. {
  346. return mLoggingBucket;
  347. }
  348. friend class GetAccountAttributesResponse;
  349. friend class SetAccountAttributesRequest;
  350. protected:
  351. bool isLoggingBucketSet() const
  352. {
  353. return mLoggingBucketSet;
  354. }
  355. protected:
  356. std::string mLoggingBucket;
  357. bool mLoggingBucketSet;
  358. };
  359. class GetQueueAttributesResponse;
  360. class SetQueueAttributesRequest;
  361. class CreateQueueRequest;
  362. class QueueAttributes
  363. {
  364. public:
  365. QueueAttributes();
  366. void clear();
  367. void setVisibilityTimeout(int64_t visibilityTimeout);
  368. void setDelaySeconds(int64_t delaySeconds);
  369. void setMaximumMessageSize(int64_t maximumMessageSize);
  370. void setMessageRetentionPeriod(int64_t messageRetentionPeriod);
  371. void setPollingWaitSeconds(int32_t pollingWaitSeconds);
  372. void setLoggingEnabled(bool loggingEnabled);
  373. std::string getQueueName() const;
  374. int32_t getPollingWaitSeconds() const;
  375. int64_t getVisibilityTimeout() const;
  376. int64_t getDelaySeconds() const;
  377. int64_t getMaximumMessageSize() const;
  378. int64_t getMessageRetentionPeriod() const;
  379. int64_t getActiveMessages() const;
  380. int64_t getInactiveMessages() const;
  381. int64_t getDelayMessages() const;
  382. int64_t getCreateTime() const;
  383. int64_t getLastModifyTime() const;
  384. bool isLoggingEnabled() const;
  385. friend class GetQueueAttributesResponse;
  386. friend class SetQueueAttributesRequest;
  387. friend class CreateQueueRequest;
  388. protected:
  389. bool isLoggingEnabledSet() const;
  390. protected:
  391. std::string mQueueName;
  392. int64_t mVisibilityTimeout;
  393. int64_t mDelaySeconds;
  394. int64_t mMaximumMessageSize;
  395. int64_t mMessageRetentionPeriod;
  396. int64_t mActiveMessages;
  397. int64_t mInactiveMessages;
  398. int64_t mDelayMessages;
  399. int64_t mCreateTime;
  400. int64_t mLastModifyTime;
  401. int32_t mPollingWaitSeconds;
  402. bool mLoggingEnabled;
  403. bool mLoggingEnabledSet;
  404. };
  405. class GetTopicAttributesResponse;
  406. class SetTopicAttributesRequest;
  407. class CreateTopicRequest;
  408. class TopicAttributes
  409. {
  410. public:
  411. TopicAttributes();
  412. void clear();
  413. void setMaximumMessageSize(int64_t maximumMessageSize);
  414. void setLoggingEnabled(bool loggingEnabled);
  415. std::string getTopicName();
  416. int64_t getCreateTime() const;
  417. int64_t getLastModifyTime() const;
  418. int64_t getMaximumMessageSize() const;
  419. int64_t getMessageRetentionPeriod() const;
  420. int64_t getMessages() const;
  421. bool isLoggingEnabled() const;
  422. friend class GetTopicAttributesResponse;
  423. friend class SetTopicAttributesRequest;
  424. friend class CreateTopicRequest;
  425. protected:
  426. bool isLoggingEnabledSet() const;
  427. protected:
  428. std::string mTopicName;
  429. int64_t mCreateTime;
  430. int64_t mLastModifyTime;
  431. int64_t mMaximumMessageSize;
  432. int64_t mMessageRetentionPeriod;
  433. int64_t mMessages; // count of messages in topic
  434. bool mLoggingEnabled;
  435. bool mLoggingEnabledSet;
  436. };
  437. class GetSubscriptionAttributesResponse;
  438. class SubscriptionAttributes
  439. {
  440. public:
  441. SubscriptionAttributes();
  442. void setNotifyStrategy(NotifyStrategy notifyStrategy);
  443. void setContentFormat(ContentFormat contentFormat);
  444. std::string getSubscriptionName() const;
  445. std::string getTopicOwner() const;
  446. std::string getTopicName() const;
  447. std::string getFilterTag() const;
  448. std::string getEndPoint() const;
  449. NotifyStrategy getNotifyStrategy() const;
  450. ContentFormat getContentFormat() const;
  451. int64_t getCreateTime() const;
  452. int64_t getLastModifyTime() const;
  453. friend class GetSubscriptionAttributesResponse;
  454. protected:
  455. std::string mSubscriptionName;
  456. std::string mTopicOwner;
  457. std::string mTopicName;
  458. std::string mEndPoint;
  459. std::string mFilterTag;
  460. NotifyStrategy mNotifyStrategy;
  461. ContentFormat mContentFormat;
  462. int64_t mCreateTime;
  463. int64_t mLastModifyTime;
  464. };
  465. class Request
  466. {
  467. public:
  468. Request(const std::string& method)
  469. : mMethod(method), mCanonicalizedResource(""), mRequestBody("")
  470. {}
  471. virtual ~Request() {};
  472. const std::string& getMethod() const
  473. {
  474. return mMethod;
  475. }
  476. const std::string& getCanonicalizedResource()
  477. {
  478. if (mCanonicalizedResource == "")
  479. {
  480. return generateCanonicalizedResource();
  481. }
  482. return mCanonicalizedResource;
  483. }
  484. const std::string& generateCanonicalizedResource()
  485. {
  486. mCanonicalizedResource = getResourcePath();
  487. if (getQueryString() != "")
  488. {
  489. mCanonicalizedResource += "?" + getQueryString();
  490. }
  491. return mCanonicalizedResource;
  492. }
  493. const std::string& getRequestBody()
  494. {
  495. if (mRequestBody == "")
  496. {
  497. return generateRequestBody();
  498. }
  499. return mRequestBody;
  500. }
  501. virtual std::string getQueryString() = 0;
  502. virtual std::string getResourcePath() = 0;
  503. virtual const std::string& generateRequestBody() = 0;
  504. const std::map<std::string, std::string>& getHeaders()
  505. {
  506. return mHeaders;
  507. }
  508. std::string getHeader(const std::string& key)
  509. {
  510. std::map<std::string, std::string>::iterator iter = mHeaders.find(key);
  511. if (iter != mHeaders.end())
  512. {
  513. return iter->second;
  514. }
  515. return "";
  516. }
  517. void setHeader(std::string key, std::string value)
  518. {
  519. mHeaders[key] = value;
  520. }
  521. protected:
  522. std::string mMethod;
  523. std::string mCanonicalizedResource;
  524. std::string mRequestBody;
  525. std::map<std::string, std::string> mHeaders;
  526. };
  527. class Response
  528. {
  529. public:
  530. Response();
  531. virtual ~Response() {};
  532. int getStatus()
  533. {
  534. return mStatus;
  535. }
  536. void setStatus(int32_t status)
  537. {
  538. mStatus = status;
  539. }
  540. const std::map<std::string, std::string>& getHeaders()
  541. {
  542. return mHeaders;
  543. }
  544. void setHeader(std::string key, std::string value)
  545. {
  546. mHeaders[key] = value;
  547. }
  548. std::string getHeader(std::string key)
  549. {
  550. std::map<std::string, std::string>::iterator iter = mHeaders.find(key);
  551. if (iter != mHeaders.end())
  552. {
  553. return iter->second;
  554. }
  555. return NULL;
  556. }
  557. std::string* getRawDataPtr()
  558. {
  559. return &mRawData;
  560. }
  561. void clearRawData()
  562. {
  563. mRawData.clear();
  564. }
  565. virtual bool isSuccess() = 0;
  566. virtual void parseResponse() = 0;
  567. protected:
  568. pugi::xml_node toXML();
  569. void parseCommonError(const pugi::xml_node& rootNode);
  570. bool isCommonError(const pugi::xml_node& rootNode);
  571. protected:
  572. pugi::xml_document mDoc;
  573. std::map<std::string, std::string> mHeaders;
  574. std::string mRawData;
  575. int32_t mStatus;
  576. };
  577. class MessageRequest : public Request
  578. {
  579. public:
  580. MessageRequest(const std::string& method)
  581. : Request(method), mQueueName(NULL)
  582. {
  583. }
  584. virtual ~MessageRequest() {}
  585. std::string getResourcePath()
  586. {
  587. if (mQueueName == NULL)
  588. return "";
  589. return "/queues/" + *mQueueName + "/messages";
  590. }
  591. /* QueueName will be automatically set when sending request. */
  592. void setQueueName(const std::string& queueName)
  593. {
  594. mQueueName = &queueName;
  595. }
  596. protected:
  597. const std::string* mQueueName;
  598. };
  599. class SubscriptionRequest : public Request
  600. {
  601. public:
  602. SubscriptionRequest(const std::string& method,
  603. const std::string& topicName,
  604. const std::string& subscriptionName)
  605. : Request(method)
  606. , mTopicName(&topicName)
  607. , mSubscriptionName(&subscriptionName)
  608. {
  609. }
  610. virtual ~SubscriptionRequest() {}
  611. std::string getResourcePath()
  612. {
  613. if (mTopicName == NULL || mSubscriptionName == NULL)
  614. return "";
  615. return "/topics/" + *mTopicName + "/subscriptions/" + *mSubscriptionName;
  616. }
  617. protected:
  618. const std::string* mTopicName;
  619. const std::string* mSubscriptionName;
  620. };
  621. class GetAccountAttributesRequest : public Request
  622. {
  623. public:
  624. GetAccountAttributesRequest();
  625. virtual ~GetAccountAttributesRequest() {}
  626. std::string getQueryString();
  627. std::string getResourcePath();
  628. const std::string& generateRequestBody();
  629. };
  630. class GetAccountAttributesResponse : public Response
  631. {
  632. public:
  633. GetAccountAttributesResponse(AccountAttributes& attributes);
  634. virtual ~GetAccountAttributesResponse() {}
  635. void parseResponse();
  636. bool isSuccess();
  637. protected:
  638. AccountAttributes* mAccountAttributes;
  639. };
  640. class SetAccountAttributesRequest : public Request
  641. {
  642. public:
  643. SetAccountAttributesRequest(const AccountAttributes& accountAttributes);
  644. virtual ~SetAccountAttributesRequest() {}
  645. std::string getQueryString();
  646. std::string getResourcePath();
  647. const std::string& generateRequestBody();
  648. protected:
  649. const AccountAttributes* mAccountAttributes;
  650. };
  651. class SetAccountAttributesResponse : public Response
  652. {
  653. public:
  654. bool isSuccess();
  655. void parseResponse();
  656. };
  657. class CreateQueueRequest : public Request
  658. {
  659. public:
  660. CreateQueueRequest(const std::string& queueName);
  661. CreateQueueRequest(const std::string& queueName,
  662. const QueueAttributes& attributes);
  663. std::string getQueryString();
  664. std::string getResourcePath();
  665. const std::string& generateRequestBody();
  666. protected:
  667. const std::string* mQueueName;
  668. const QueueAttributes* mAttributes;
  669. };
  670. class CreateQueueResponse : public Response
  671. {
  672. public:
  673. void parseResponse();
  674. bool isSuccess();
  675. };
  676. class DeleteQueueRequest : public Request
  677. {
  678. public:
  679. DeleteQueueRequest(const std::string& queueName);
  680. virtual ~DeleteQueueRequest() {}
  681. std::string getQueryString();
  682. std::string getResourcePath();
  683. const std::string& generateRequestBody();
  684. protected:
  685. const std::string* mQueueName;
  686. };
  687. class DeleteQueueResponse : public Response
  688. {
  689. public:
  690. void parseResponse();
  691. bool isSuccess();
  692. };
  693. class ListQueueRequest : public Request
  694. {
  695. public:
  696. ListQueueRequest(const std::string& prefix = "",
  697. const std::string& marker = "",
  698. const int32_t retNum = -1);
  699. virtual ~ListQueueRequest() {}
  700. void setMarker(const std::string& marker);
  701. void setPrefix(const std::string& prefix);
  702. void setRetNum(const int32_t retNum);
  703. std::string getQueryString();
  704. std::string getResourcePath();
  705. const std::string& generateRequestBody();
  706. protected:
  707. std::string mPrefix;
  708. std::string mMarker;
  709. int32_t mRetNum;
  710. };
  711. class ListQueueResponse : public Response
  712. {
  713. public:
  714. ListQueueResponse(std::vector<std::string>& queueNames,
  715. std::string& nextMarker);
  716. virtual ~ListQueueResponse() {}
  717. void parseResponse();
  718. bool isSuccess();
  719. protected:
  720. std::vector<std::string>* mQueueNames;
  721. std::string* mNextMarker;
  722. };
  723. class GetQueueAttributesRequest : public Request
  724. {
  725. public:
  726. GetQueueAttributesRequest(const std::string& queueName);
  727. virtual ~GetQueueAttributesRequest() {}
  728. std::string getQueryString();
  729. std::string getResourcePath();
  730. const std::string& generateRequestBody();
  731. protected:
  732. const std::string* mQueueName;
  733. };
  734. class GetQueueAttributesResponse : public Response
  735. {
  736. public:
  737. GetQueueAttributesResponse(QueueAttributes& attributes);
  738. virtual ~GetQueueAttributesResponse() {}
  739. void parseResponse();
  740. bool isSuccess();
  741. protected:
  742. QueueAttributes* mQueueAttributes;
  743. };
  744. class SetQueueAttributesRequest : public Request
  745. {
  746. public:
  747. SetQueueAttributesRequest(const std::string& queueName,
  748. const QueueAttributes& queueAttributes);
  749. virtual ~SetQueueAttributesRequest() {}
  750. std::string getQueryString();
  751. std::string getResourcePath();
  752. const std::string& generateRequestBody();
  753. protected:
  754. const std::string* mQueueName;
  755. const QueueAttributes* mQueueAttributes;
  756. };
  757. class SetQueueAttributesResponse : public Response
  758. {
  759. public:
  760. bool isSuccess();
  761. void parseResponse();
  762. };
  763. class SendMessageRequest : public MessageRequest
  764. {
  765. public:
  766. SendMessageRequest(const std::string& messageBody,
  767. const int32_t delaySeconds = -1, const int32_t priority = -1);
  768. virtual ~SendMessageRequest() {}
  769. std::string getQueryString();
  770. const std::string& generateRequestBody();
  771. protected:
  772. const std::string* mMessageBody;
  773. int32_t mDelaySeconds;
  774. int32_t mPriority;
  775. };
  776. class SendMessageResponse : public Response
  777. {
  778. public:
  779. SendMessageResponse();
  780. virtual ~SendMessageResponse() {}
  781. void parseResponse();
  782. bool isSuccess();
  783. std::string getMessageId()
  784. {
  785. return mMessageId;
  786. }
  787. std::string getMessageBodyMD5()
  788. {
  789. return mMessageBodyMD5;
  790. }
  791. protected:
  792. std::string mMessageId;
  793. std::string mMessageBodyMD5;
  794. };
  795. class BatchSendMessageRequest : public MessageRequest
  796. {
  797. public:
  798. BatchSendMessageRequest(
  799. const std::vector<SendMessageItem>& sendMessageItems);
  800. virtual ~BatchSendMessageRequest() {}
  801. std::string getQueryString();
  802. const std::string& generateRequestBody();
  803. protected:
  804. const std::vector<SendMessageItem>* mSendMessageItems;
  805. };
  806. class BatchSendMessageResponse : public Response
  807. {
  808. public:
  809. void parseResponse();
  810. bool isSuccess();
  811. const std::vector<SendMessageSucceedItem>& getSendMessageSucceedItems()
  812. {
  813. return mSendMessageSucceedItems;
  814. }
  815. const std::vector<SendMessageFailedItem>& getSendMessageFailedItems()
  816. {
  817. return mSendMessageFailedItems;
  818. }
  819. protected:
  820. void parseBatchSendResponse(pugi::xml_node& rootNode);
  821. protected:
  822. std::vector<SendMessageSucceedItem> mSendMessageSucceedItems;
  823. std::vector<SendMessageFailedItem> mSendMessageFailedItems;
  824. };
  825. class ReceiveMessageRequest : public MessageRequest
  826. {
  827. public:
  828. ReceiveMessageRequest(const int32_t waitSeconds = -1);
  829. virtual ~ReceiveMessageRequest() {}
  830. std::string getQueryString();
  831. const std::string& generateRequestBody();
  832. protected:
  833. int32_t mWaitSeconds;
  834. };
  835. class ReceiveMessageResponse : public Response
  836. {
  837. public:
  838. ReceiveMessageResponse(Message& message);
  839. virtual ~ReceiveMessageResponse() {}
  840. void parseResponse();
  841. bool isSuccess();
  842. protected:
  843. Message* mMessage;
  844. };
  845. class BatchReceiveMessageRequest : public MessageRequest
  846. {
  847. public:
  848. BatchReceiveMessageRequest(const int32_t numOfMessages,
  849. const int32_t waitSeconds = -1);
  850. virtual ~BatchReceiveMessageRequest() {}
  851. std::string getQueryString();
  852. const std::string& generateRequestBody();
  853. protected:
  854. int32_t mNumOfMessages;
  855. int32_t mWaitSeconds;
  856. };
  857. class BatchReceiveMessageResponse : public Response
  858. {
  859. public:
  860. BatchReceiveMessageResponse(std::vector<Message>& messages);
  861. virtual ~BatchReceiveMessageResponse() {}
  862. void parseResponse();
  863. bool isSuccess();
  864. protected:
  865. std::vector<Message>* mMessages;
  866. };
  867. class DeleteMessageRequest : public MessageRequest
  868. {
  869. public:
  870. DeleteMessageRequest(const std::string& receiptHandle);
  871. virtual ~DeleteMessageRequest() {}
  872. std::string getQueryString();
  873. const std::string& generateRequestBody();
  874. protected:
  875. const std::string* mReceiptHandle;
  876. };
  877. class DeleteMessageResponse : public Response
  878. {
  879. public:
  880. void parseResponse();
  881. bool isSuccess();
  882. };
  883. class BatchDeleteMessageRequest : public MessageRequest
  884. {
  885. public:
  886. BatchDeleteMessageRequest(const std::vector<std::string>& receiptHandles);
  887. virtual ~BatchDeleteMessageRequest() {}
  888. std::string getQueryString();
  889. const std::string& generateRequestBody();
  890. protected:
  891. const std::vector<std::string>* mReceiptHandles;
  892. };
  893. class BatchDeleteMessageResponse : public Response
  894. {
  895. public:
  896. void parseResponse();
  897. bool isSuccess();
  898. const std::vector<DeleteMessageFailedItem>& getDeleteMessageFailedItem()
  899. {
  900. return mDeleteMessageFailedItems;
  901. }
  902. protected:
  903. std::vector<DeleteMessageFailedItem> mDeleteMessageFailedItems;
  904. };
  905. class PeekMessageRequest : public MessageRequest
  906. {
  907. public:
  908. PeekMessageRequest();
  909. virtual ~PeekMessageRequest() {}
  910. std::string getQueryString();
  911. const std::string& generateRequestBody();
  912. };
  913. class PeekMessageResponse : public Response
  914. {
  915. public:
  916. PeekMessageResponse(Message& message);
  917. virtual ~PeekMessageResponse() {}
  918. void parseResponse();
  919. bool isSuccess();
  920. protected:
  921. Message* mMessage;
  922. };
  923. class BatchPeekMessageRequest : public MessageRequest
  924. {
  925. public:
  926. BatchPeekMessageRequest(const int32_t numOfMessages);
  927. virtual ~BatchPeekMessageRequest() {}
  928. std::string getQueryString();
  929. const std::string& generateRequestBody();
  930. protected:
  931. int32_t mNumOfMessages;
  932. };
  933. class BatchPeekMessageResponse : public Response
  934. {
  935. public:
  936. BatchPeekMessageResponse(std::vector<Message>& mMessages);
  937. virtual ~BatchPeekMessageResponse() {}
  938. void parseResponse();
  939. bool isSuccess();
  940. protected:
  941. std::vector<Message>* mMessages;
  942. };
  943. class ChangeMessageVisibilityRequest : public MessageRequest
  944. {
  945. public:
  946. ChangeMessageVisibilityRequest(const std::string& receiptHandle,
  947. const int32_t visibilityTimeout);
  948. virtual ~ChangeMessageVisibilityRequest() {}
  949. std::string getQueryString();
  950. const std::string& generateRequestBody();
  951. protected:
  952. const std::string* mReceiptHandle;
  953. int32_t mVisibilityTimeout;
  954. };
  955. class ChangeMessageVisibilityResponse : public Response
  956. {
  957. public:
  958. void parseResponse();
  959. bool isSuccess();
  960. const std::string& getReceiptHandle()
  961. {
  962. return mReceiptHandle;
  963. }
  964. int64_t getNextVisibleTime()
  965. {
  966. return mNextVisibleTime;
  967. }
  968. protected:
  969. std::string mReceiptHandle;
  970. int64_t mNextVisibleTime;
  971. };
  972. class CreateTopicRequest : public Request
  973. {
  974. public:
  975. CreateTopicRequest(const std::string& topicName);
  976. CreateTopicRequest(const std::string& topicName,
  977. const TopicAttributes& attributes);
  978. std::string getQueryString();
  979. std::string getResourcePath();
  980. const std::string& generateRequestBody();
  981. protected:
  982. const std::string* mTopicName;
  983. const TopicAttributes* mAttributes;
  984. };
  985. class CreateTopicResponse : public Response
  986. {
  987. public:
  988. CreateTopicResponse();
  989. virtual ~CreateTopicResponse() {};
  990. std::string getTopicURL() const
  991. {
  992. return mTopicURL;
  993. }
  994. void setTopicURL(const std::string& topicURL)
  995. {
  996. mTopicURL = topicURL;
  997. }
  998. void parseResponse();
  999. bool isSuccess();
  1000. protected:
  1001. std::string mTopicURL;
  1002. };
  1003. class DeleteTopicRequest : public Request
  1004. {
  1005. public:
  1006. DeleteTopicRequest(const std::string& queueName);
  1007. virtual ~DeleteTopicRequest() {}
  1008. std::string getQueryString();
  1009. std::string getResourcePath();
  1010. const std::string& generateRequestBody();
  1011. protected:
  1012. const std::string* mTopicName;
  1013. };
  1014. class DeleteTopicResponse : public Response
  1015. {
  1016. public:
  1017. void parseResponse();
  1018. bool isSuccess();
  1019. };
  1020. class ListTopicRequest : public Request
  1021. {
  1022. public:
  1023. ListTopicRequest(const std::string& prefix = "",
  1024. const std::string& marker = "",
  1025. const int32_t retNum = -1);
  1026. virtual ~ListTopicRequest() {}
  1027. void setMarker(const std::string& marker);
  1028. void setPrefix(const std::string& prefix);
  1029. void setRetNum(const int32_t retNum);
  1030. std::string getQueryString();
  1031. std::string getResourcePath();
  1032. const std::string& generateRequestBody();
  1033. protected:
  1034. std::string mPrefix;
  1035. std::string mMarker;
  1036. int32_t mRetNum;
  1037. };
  1038. class ListTopicResponse : public Response
  1039. {
  1040. public:
  1041. ListTopicResponse(std::vector<std::string>& queueNames,
  1042. std::string& nextMarker);
  1043. virtual ~ListTopicResponse() {}
  1044. void parseResponse();
  1045. bool isSuccess();
  1046. protected:
  1047. std::vector<std::string>* mTopicNames;
  1048. std::string* mNextMarker;
  1049. };
  1050. class GetTopicAttributesRequest : public Request
  1051. {
  1052. public:
  1053. GetTopicAttributesRequest(const std::string& topicName);
  1054. virtual ~GetTopicAttributesRequest() {}
  1055. std::string getQueryString();
  1056. std::string getResourcePath();
  1057. const std::string& generateRequestBody();
  1058. protected:
  1059. const std::string* mTopicName;
  1060. };
  1061. class GetTopicAttributesResponse : public Response
  1062. {
  1063. public:
  1064. GetTopicAttributesResponse(TopicAttributes& attributes);
  1065. virtual ~GetTopicAttributesResponse() {}
  1066. void parseResponse();
  1067. bool isSuccess();
  1068. protected:
  1069. TopicAttributes* mAttributes;
  1070. };
  1071. class SetTopicAttributesRequest : public Request
  1072. {
  1073. public:
  1074. SetTopicAttributesRequest(const std::string& topicName,
  1075. const TopicAttributes& attributes);
  1076. virtual ~SetTopicAttributesRequest() {}
  1077. std::string getQueryString();
  1078. std::string getResourcePath();
  1079. const std::string& generateRequestBody();
  1080. protected:
  1081. const std::string* mTopicName;
  1082. const TopicAttributes* mAttributes;
  1083. };
  1084. class SetTopicAttributesResponse : public Response
  1085. {
  1086. public:
  1087. bool isSuccess();
  1088. void parseResponse();
  1089. };
  1090. class PublishMessageRequest : public Request
  1091. {
  1092. public:
  1093. PublishMessageRequest(const std::string& topicName,
  1094. const std::string& messageBody);
  1095. PublishMessageRequest(const std::string& topicName,
  1096. const std::string& messageBody,
  1097. const MessageAttributes& messageAttributes);
  1098. PublishMessageRequest(const std::string& topicName,
  1099. const std::string& messageBody,
  1100. const std::string& messageTag);
  1101. PublishMessageRequest(const std::string& topicName,
  1102. const std::string& messageBody,
  1103. const std::string& messageTag,
  1104. const MessageAttributes& messageAttributes);
  1105. virtual ~PublishMessageRequest() {}
  1106. std::string getQueryString();
  1107. std::string getResourcePath();
  1108. const std::string& generateRequestBody();
  1109. protected:
  1110. const std::string* mTopicName;
  1111. const std::string* mMessageBody;
  1112. const std::string* mMessageTag;
  1113. const MessageAttributes* mpMessageAttributes;
  1114. };
  1115. class PublishMessageResponse : public Response
  1116. {
  1117. public:
  1118. PublishMessageResponse();
  1119. virtual ~PublishMessageResponse() {}
  1120. void parseResponse();
  1121. bool isSuccess();
  1122. std::string getMessageId()
  1123. {
  1124. return mMessageId;
  1125. }
  1126. std::string getMessageBodyMD5()
  1127. {
  1128. return mMessageBodyMD5;
  1129. }
  1130. protected:
  1131. std::string mMessageId;
  1132. std::string mMessageBodyMD5;
  1133. };
  1134. class SubscribeRequest : public SubscriptionRequest
  1135. {
  1136. public:
  1137. SubscribeRequest(const std::string& topicName,
  1138. const std::string& subscriptionName,
  1139. const std::string& endPoint);
  1140. SubscribeRequest(const std::string& topicName,
  1141. const std::string& subscriptionName,
  1142. const std::string& endPoint,
  1143. const SubscriptionAttributes& attributes);
  1144. SubscribeRequest(const std::string& topicName,
  1145. const std::string& subscriptionName,
  1146. const std::string& filterTag,
  1147. const std::string& endPoint);
  1148. SubscribeRequest(const std::string& topicName,
  1149. const std::string& subscriptionName,
  1150. const std::string& filterTag,
  1151. const std::string& endPoint,
  1152. const SubscriptionAttributes& attributes);
  1153. virtual ~SubscribeRequest();
  1154. std::string getQueryString();
  1155. const std::string& generateRequestBody();
  1156. protected:
  1157. const std::string* mEndPoint;
  1158. const std::string* mFilterTag;
  1159. const SubscriptionAttributes* mAttributes;
  1160. };
  1161. class SubscribeResponse : public Response
  1162. {
  1163. public:
  1164. bool isSuccess();
  1165. void parseResponse();
  1166. };
  1167. class SetSubscriptionAttributesRequest : public SubscriptionRequest
  1168. {
  1169. public:
  1170. SetSubscriptionAttributesRequest(const std::string& topicName,
  1171. const std::string& subscriptionName,
  1172. const SubscriptionAttributes& attributes);
  1173. virtual ~SetSubscriptionAttributesRequest();
  1174. std::string getQueryString();
  1175. const std::string& generateRequestBody();
  1176. protected:
  1177. const SubscriptionAttributes* mAttributes;
  1178. };
  1179. class SetSubscriptionAttributesResponse : public Response
  1180. {
  1181. public:
  1182. bool isSuccess();
  1183. void parseResponse();
  1184. };
  1185. class GetSubscriptionAttributesRequest : public SubscriptionRequest
  1186. {
  1187. public:
  1188. GetSubscriptionAttributesRequest(const std::string& topicName,
  1189. const std::string& subscriptionName);
  1190. virtual ~GetSubscriptionAttributesRequest() {}
  1191. std::string getQueryString();
  1192. const std::string& generateRequestBody();
  1193. };
  1194. class GetSubscriptionAttributesResponse : public Response
  1195. {
  1196. public:
  1197. GetSubscriptionAttributesResponse(SubscriptionAttributes& attributes);
  1198. virtual ~GetSubscriptionAttributesResponse() {}
  1199. bool isSuccess();
  1200. void parseResponse();
  1201. protected:
  1202. SubscriptionAttributes* mAttributes;
  1203. };
  1204. class UnsubscribeRequest : public SubscriptionRequest
  1205. {
  1206. public:
  1207. UnsubscribeRequest(const std::string& topicName,
  1208. const std::string& subscriptionName);
  1209. virtual ~UnsubscribeRequest() {}
  1210. std::string getQueryString();
  1211. const std::string& generateRequestBody();
  1212. };
  1213. class UnsubscribeResponse : public Response
  1214. {
  1215. public:
  1216. bool isSuccess();
  1217. void parseResponse();
  1218. };
  1219. class ListSubscriptionRequest : public Request
  1220. {
  1221. public:
  1222. ListSubscriptionRequest(const std::string& prefix = "",
  1223. const std::string& marker = "",
  1224. const int32_t retNum = -1);
  1225. virtual ~ListSubscriptionRequest() {}
  1226. void setMarker(const std::string& marker);
  1227. void setPrefix(const std::string& prefix);
  1228. void setRetNum(const int32_t retNum);
  1229. // this is automatically set
  1230. void setTopicName(const std::string& topicName);
  1231. std::string getQueryString();
  1232. std::string getResourcePath();
  1233. const std::string& generateRequestBody();
  1234. protected:
  1235. std::string mPrefix;
  1236. std::string mMarker;
  1237. int32_t mRetNum;
  1238. const std::string* mTopicName;
  1239. };
  1240. class ListSubscriptionResponse : public Response
  1241. {
  1242. public:
  1243. ListSubscriptionResponse(std::vector<std::string>& subscriptionNames,
  1244. std::string& nextMarker);
  1245. virtual ~ListSubscriptionResponse() {}
  1246. void parseResponse();
  1247. bool isSuccess();
  1248. protected:
  1249. std::vector<std::string>* mSubscriptionNames;
  1250. std::string* mNextMarker;
  1251. };
  1252. }
  1253. }
  1254. #endif