mns_protocol.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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