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 28 #ifndef TALK_XMPP_PUBSUBTASKS_H_ 29 #define TALK_XMPP_PUBSUBTASKS_H_ 30 31 #include <vector> 32 33 #include "talk/xmpp/iqtask.h" 34 #include "talk/xmpp/receivetask.h" 35 #include "webrtc/base/sigslot.h" 36 37 namespace buzz { 38 39 // A PubSub itemid + payload. Useful for signaling items. 40 struct PubSubItem { 41 std::string itemid; 42 // The entire <item>, owned by the stanza handler. To keep a 43 // reference after handling, make a copy. 44 const XmlElement* elem; 45 }; 46 47 // An IqTask which gets a <pubsub><items> for a particular jid and 48 // node, parses the items in the response and signals the items. 49 class PubSubRequestTask : public IqTask { 50 public: 51 PubSubRequestTask(XmppTaskParentInterface* parent, 52 const Jid& pubsubjid, 53 const std::string& node); 54 55 sigslot::signal2<PubSubRequestTask*, 56 const std::vector<PubSubItem>&> SignalResult; 57 // SignalError inherited by IqTask. 58 private: 59 virtual void HandleResult(const XmlElement* stanza); 60 }; 61 62 // A ReceiveTask which listens for <event><items> of a particular 63 // pubsub JID and node and then signals them items. 64 class PubSubReceiveTask : public ReceiveTask { 65 public: PubSubReceiveTask(XmppTaskParentInterface * parent,const Jid & pubsubjid,const std::string & node)66 PubSubReceiveTask(XmppTaskParentInterface* parent, 67 const Jid& pubsubjid, 68 const std::string& node) 69 : ReceiveTask(parent), 70 pubsubjid_(pubsubjid), 71 node_(node) { 72 } 73 74 virtual int ProcessStart(); 75 sigslot::signal2<PubSubReceiveTask*, 76 const std::vector<PubSubItem>&> SignalUpdate; 77 78 protected: 79 virtual bool WantsStanza(const XmlElement* stanza); 80 virtual void ReceiveStanza(const XmlElement* stanza); 81 82 private: 83 Jid pubsubjid_; 84 std::string node_; 85 }; 86 87 // An IqTask which publishes a <pubsub><publish><item> to a particular 88 // pubsub jid and node. 89 class PubSubPublishTask : public IqTask { 90 public: 91 // Takes ownership of children 92 PubSubPublishTask(XmppTaskParentInterface* parent, 93 const Jid& pubsubjid, 94 const std::string& node, 95 const std::string& itemid, 96 const std::vector<XmlElement*>& children); 97 itemid()98 const std::string& itemid() const { return itemid_; } 99 100 sigslot::signal1<PubSubPublishTask*> SignalResult; 101 102 private: 103 // SignalError inherited by IqTask. 104 virtual void HandleResult(const XmlElement* stanza); 105 106 std::string itemid_; 107 }; 108 109 // An IqTask which publishes a <pubsub><publish><retract> to a particular 110 // pubsub jid and node. 111 class PubSubRetractTask : public IqTask { 112 public: 113 PubSubRetractTask(XmppTaskParentInterface* parent, 114 const Jid& pubsubjid, 115 const std::string& node, 116 const std::string& itemid); 117 itemid()118 const std::string& itemid() const { return itemid_; } 119 120 sigslot::signal1<PubSubRetractTask*> SignalResult; 121 122 private: 123 // SignalError inherited by IqTask. 124 virtual void HandleResult(const XmlElement* stanza); 125 126 std::string itemid_; 127 }; 128 129 } // namespace buzz 130 131 #endif // TALK_XMPP_PUBSUBTASKS_H_ 132