13 #include "pubsubevent.h"
23 static const char* eventTypeValues[] = {
34 : retract( right.retract ), item( right.item ),
35 payload( right.payload ? right.payload->clone() : 0 )
41 m_subscriptionIDs( 0 ), m_config( 0 ),
48 m_subscriptionIDs( 0 ), m_config( 0 ), m_itemOperations( 0 ), m_subscription( false )
50 if( !event || event->
name() !=
"event" )
53 const TagList& events =
event->children();
54 TagList::const_iterator it = events.begin();
56 for( ; it != events.end(); ++it )
69 m_config = m_config->
clone();
79 m_config = m_config->
clone();
85 if( !m_itemOperations )
90 TagList::const_iterator itt =
items.begin();
91 for( ; itt !=
items.end(); ++itt )
103 m_itemOperations->push_back( op );
119 if(
tag->
name() !=
"headers" || m_subscriptionIDs != 0 )
128 TagList::const_iterator ith = headers.begin();
129 for( ; ith != headers.end(); ++ith )
131 const std::string& name = (*ith)->findAttribute(
"name" );
132 if( name ==
"pubsub#subid" )
133 m_subscriptionIDs->push_back( (*ith)->cdata() );
134 else if( name ==
"pubsub#collection" )
135 m_collection = (*ith)->cdata();
150 m_node( node ), m_subscriptionIDs( 0 ), m_config( 0 ),
151 m_itemOperations( 0 )
159 delete m_subscriptionIDs;
161 if( m_itemOperations )
163 ItemOperationList::iterator it = m_itemOperations->begin();
164 for( ; it != m_itemOperations->end(); ++it )
166 delete (*it)->payload;
169 delete m_itemOperations;
175 if( !m_itemOperations )
178 m_itemOperations->push_back( op );
183 static const std::string filter =
"/message/event[@xmlns='" +
XMLNS_PUBSUB_EVENT +
"']";
193 Tag* child =
new Tag( event, util::lookup( m_type, eventTypeValues ) );
201 item =
new Tag( child,
"node",
"id", m_node );
218 if( m_itemOperations )
222 ItemOperationList::const_iterator itt = m_itemOperations->begin();
223 for( ; itt != m_itemOperations->end(); ++itt )
238 child->
addAttribute(
"subscription", m_subscription ?
"subscribed" :
"none" );
247 if( m_subscriptionIDs || !m_collection.empty() )
249 Tag* headers =
new Tag( event,
"headers",
XMLNS,
"http://jabber.org/protocol/shim" );
251 if( m_subscriptionIDs )
253 StringList::const_iterator it = m_subscriptionIDs->begin();
254 for( ; it != m_subscriptionIDs->end(); ++it )
255 (
new Tag( headers,
"header",
"name",
"pubsub#subid" ))->setCData( (*it) );
258 if( !m_collection.empty() )
259 (
new Tag( headers,
"header",
"name",
"pubsub#collection" ))->setCData( m_collection );
268 e->m_subscriptionIDs = m_subscriptionIDs ?
new StringList( *m_subscriptionIDs ) : 0;
269 e->m_config = m_config ? m_config->
clone() : 0;
270 if( m_itemOperations )
273 ItemOperationList::const_iterator it = m_itemOperations->begin();
274 for( ; it != m_itemOperations->end(); ++it )
275 e->m_itemOperations->push_back(
new ItemOperation( *(*it) ) );
278 e->m_itemOperations = 0;
280 e->m_collection = m_collection;
bool setJID(const std::string &jid)
const std::string & full() const
This is an implementation of a PubSub Notification as a StanzaExtension.
PubSub::EventType type() const
std::list< ItemOperation * > ItemOperationList
virtual StanzaExtension * clone() const
const ItemOperationList & items() const
const std::string & filterString() const
void addItem(ItemOperation *op)
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Tag * findChild(const std::string &name) const
void addChildCopy(const Tag *child)
bool addAttribute(Attribute *attr)
bool hasAttribute(const std::string &name, const std::string &value=EmptyString) const
const std::string & findAttribute(const std::string &name) const
const std::string & name() const
const TagList & children() const
The namespace for the gloox library.
std::list< Tag * > TagList
std::list< std::string > StringList
const std::string XMLNS_PUBSUB_EVENT
ItemOperation(bool remove, const std::string &itemid, const Tag *pld=0)