You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2011, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TALK_XMPP_PUBSUBTASKS_H_
  28. #define TALK_XMPP_PUBSUBTASKS_H_
  29. #include <vector>
  30. #include "talk/base/sigslot.h"
  31. #include "talk/xmpp/iqtask.h"
  32. #include "talk/xmpp/receivetask.h"
  33. namespace buzz {
  34. // A PubSub itemid + payload. Useful for signaling items.
  35. struct PubSubItem {
  36. std::string itemid;
  37. // The entire <item>, owned by the stanza handler. To keep a
  38. // reference after handling, make a copy.
  39. const XmlElement* elem;
  40. };
  41. // An IqTask which gets a <pubsub><items> for a particular jid and
  42. // node, parses the items in the response and signals the items.
  43. class PubSubRequestTask : public IqTask {
  44. public:
  45. PubSubRequestTask(XmppTaskParentInterface* parent,
  46. const Jid& pubsubjid,
  47. const std::string& node);
  48. sigslot::signal2<PubSubRequestTask*,
  49. const std::vector<PubSubItem>&> SignalResult;
  50. // SignalError inherited by IqTask.
  51. private:
  52. virtual void HandleResult(const XmlElement* stanza);
  53. };
  54. // A ReceiveTask which listens for <event><items> of a particular
  55. // pubsub JID and node and then signals them items.
  56. class PubSubReceiveTask : public ReceiveTask {
  57. public:
  58. PubSubReceiveTask(XmppTaskParentInterface* parent,
  59. const Jid& pubsubjid,
  60. const std::string& node)
  61. : ReceiveTask(parent),
  62. pubsubjid_(pubsubjid),
  63. node_(node) {
  64. }
  65. sigslot::signal2<PubSubReceiveTask*,
  66. const std::vector<PubSubItem>&> SignalUpdate;
  67. protected:
  68. virtual bool WantsStanza(const XmlElement* stanza);
  69. virtual void ReceiveStanza(const XmlElement* stanza);
  70. private:
  71. Jid pubsubjid_;
  72. std::string node_;
  73. };
  74. // An IqTask which publishes a <pubsub><publish><item> to a particular
  75. // pubsub jid and node.
  76. class PubSubPublishTask : public IqTask {
  77. public:
  78. // Takes ownership of children
  79. PubSubPublishTask(XmppTaskParentInterface* parent,
  80. const Jid& pubsubjid,
  81. const std::string& node,
  82. const std::string& itemid,
  83. const std::vector<XmlElement*>& children);
  84. const std::string& itemid() const { return itemid_; }
  85. sigslot::signal1<PubSubPublishTask*> SignalResult;
  86. private:
  87. // SignalError inherited by IqTask.
  88. virtual void HandleResult(const XmlElement* stanza);
  89. std::string itemid_;
  90. };
  91. // An IqTask which publishes a <pubsub><publish><retract> to a particular
  92. // pubsub jid and node.
  93. class PubSubRetractTask : public IqTask {
  94. public:
  95. PubSubRetractTask(XmppTaskParentInterface* parent,
  96. const Jid& pubsubjid,
  97. const std::string& node,
  98. const std::string& itemid);
  99. const std::string& itemid() const { return itemid_; }
  100. sigslot::signal1<PubSubRetractTask*> SignalResult;
  101. private:
  102. // SignalError inherited by IqTask.
  103. virtual void HandleResult(const XmlElement* stanza);
  104. std::string itemid_;
  105. };
  106. } // namespace buzz
  107. #endif // TALK_XMPP_PUBSUBTASKS_H_