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 ), m_itemOperations( 0 ), m_subscription( false )
43 if( !event || event->
name() !=
"event" )
46 const TagList& events =
event->children();
47 TagList::const_iterator it = events.begin();
49 for( ; it != events.end(); ++it )
61 if( ( m_config = tag->
findChild(
"x" ) ) )
62 m_config = m_config->
clone();
72 m_config = m_config->
clone();
78 if( !m_itemOperations )
83 TagList::const_iterator itt = items.begin();
84 for( ; itt != items.end(); ++itt )
88 if( tag->
name() ==
"retract" )
96 m_itemOperations->push_back( op );
105 m_subscription = tag->
hasAttribute(
"subscription",
"subscribed" );
112 if( tag->
name() !=
"headers" || m_subscriptionIDs != 0 )
121 TagList::const_iterator ith = headers.begin();
122 for( ; ith != headers.end(); ++ith )
124 const std::string& name = (*ith)->findAttribute(
"name" );
125 if( name ==
"pubsub#subid" )
126 m_subscriptionIDs->push_back( (*ith)->cdata() );
127 else if( name ==
"pubsub#collection" )
128 m_collection = (*ith)->cdata();
143 m_node( node ), m_subscriptionIDs( 0 ), m_config( 0 ),
144 m_itemOperations( 0 )
152 delete m_subscriptionIDs;
154 if( m_itemOperations )
156 ItemOperationList::iterator it = m_itemOperations->begin();
157 for( ; it != m_itemOperations->end(); ++it )
159 delete (*it)->payload;
162 delete m_itemOperations;
168 if( !m_itemOperations )
171 m_itemOperations->push_back( op );
176 static const std::string filter =
"/message/event[@xmlns='" +
XMLNS_PUBSUB_EVENT +
"']";
186 Tag* child =
new Tag( event, util::lookup( m_type, eventTypeValues ) );
194 item =
new Tag( child,
"node",
"id", m_node );
211 if( m_itemOperations )
215 ItemOperationList::const_iterator itt = m_itemOperations->begin();
216 for( ; itt != m_itemOperations->end(); ++itt )
231 child->
addAttribute(
"subscription", m_subscription ?
"subscribed" :
"none" );
240 if( m_subscriptionIDs || !m_collection.empty() )
242 Tag* headers =
new Tag( event,
"headers",
XMLNS,
"http://jabber.org/protocol/shim" );
243 StringList::const_iterator it = m_subscriptionIDs->begin();
244 for( ; it != m_subscriptionIDs->end(); ++it )
246 (
new Tag( headers,
"header",
"name",
"pubsub#subid" ))->setCData( (*it) );
249 if( !m_collection.empty() )
250 (
new Tag( headers,
"header",
"name",
"pubsub#collection" ) )
251 ->setCData( m_collection );
260 e->m_subscriptionIDs = m_subscriptionIDs ?
new StringList( *m_subscriptionIDs ) : 0;
261 e->m_config = m_config ? m_config->
clone() : 0;
262 if( m_itemOperations )
265 ItemOperationList::const_iterator it = m_itemOperations->begin();
266 for( ; it != m_itemOperations->end(); ++it )
267 e->m_itemOperations->push_back(
new ItemOperation( *(*it) ) );
270 e->m_itemOperations = 0;
272 e->m_collection = m_collection;
const TagList & children() const
This is an implementation of a PubSub Notification as a StanzaExtension.
std::list< std::string > StringList
std::list< Tag * > TagList
const std::string XMLNS_PUBSUB_EVENT
bool setJID(const std::string &jid)
const std::string & filterString() const
The namespace for the gloox library.
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string & findAttribute(const std::string &name) const
bool hasAttribute(const std::string &name, const std::string &value=EmptyString) const
void addItem(ItemOperation *op)
ItemOperation(bool remove, const std::string &itemid, const Tag *pld=0)
const ItemOperationList & items() const
bool addAttribute(Attribute *attr)
PubSub::EventType type() const
const std::string & name() const
virtual StanzaExtension * clone() const
const std::string & full() const
std::list< ItemOperation * > ItemOperationList
Tag * findChild(const std::string &name) const
void addChildCopy(const Tag *child)
This is an abstraction of an XML element.