15 #include "discohandler.h"
18 #include "clientbase.h"
19 #include "disconodehandler.h"
20 #include "softwareversion.h"
29 const std::string& type,
30 const std::string& name )
31 : m_category( category ), m_type( type ), m_name( name )
37 if( !tag || tag->
name() !=
"identity" )
46 : m_category( id.m_category ), m_type( id.m_type ), m_name( id.m_name )
56 if( m_category.empty() || m_type.empty() )
59 Tag* i =
new Tag(
"identity" );
71 Disco::Info::Info(
const std::string& node,
bool defaultFeatures )
81 Disco::Info::Info(
const Tag* tag )
87 m_node = tag->findAttribute(
"node" );
89 const TagList& l = tag->children();
90 TagList::const_iterator it = l.begin();
91 for( ; it != l.end(); ++it )
93 const std::string&
name = (*it)->name();
94 if( name ==
"identity" )
95 m_identities.push_back(
new Identity( (*it) ) );
96 else if( name ==
"feature" && (*it)->hasAttribute(
"var" ) )
97 m_features.push_back( (*it)->findAttribute(
"var" ) );
98 else if( !m_form && name ==
"x" && (*it)->xmlns() ==
XMLNS_X_DATA )
99 m_form =
new DataForm( (*it) );
103 Disco::Info::Info(
const Info& info )
104 : StanzaExtension(
ExtDiscoInfo ), m_node( info.m_node ), m_features( info.m_features ),
105 m_identities( info.m_identities ), m_form( info.m_form ? new DataForm( *(info.m_form) ) : 0 )
123 StringList::const_iterator it = m_features.begin();
124 for( ; it != m_features.end() && (*it) != feature; ++it )
126 return it != m_features.end();
131 static const std::string filter =
"/iq/query[@xmlns='" +
XMLNS_DISCO_INFO +
"']";
139 if( !m_node.empty() )
142 IdentityList::const_iterator it_i = m_identities.begin();
143 for( ; it_i != m_identities.end(); ++it_i )
146 StringList::const_iterator it_f = m_features.begin();
147 for( ; it_f != m_features.end(); ++it_f )
148 new Tag( t,
"feature",
"var", (*it_f) );
160 if( !tag || tag->
name() !=
"item" )
173 Tag* i =
new Tag(
"item" );
176 if( !m_node.empty() )
178 if( !m_name.empty() )
200 TagList::const_iterator it = l.begin();
201 for( ; it != l.end(); ++it )
203 const std::string& name = (*it)->name();
205 m_items.push_back(
new Item( (*it) ) );
223 static const std::string filter =
"/iq/query[@xmlns='" +
XMLNS_DISCO_ITEMS +
"']";
231 if( !m_node.empty() )
234 ItemList::const_iterator it_i = m_items.begin();
235 for( ; it_i != m_items.end(); ++it_i )
244 : m_parent( parent ), m_form( 0 )
253 m_parent->registerIqHandler(
this,
ExtVersion );
254 m_parent->registerStanzaExtension(
new Disco::Info() );
255 m_parent->registerStanzaExtension(
new Disco::Items() );
295 re.addExtension(
new SoftwareVersion( m_versionName, m_versionVersion, m_versionOs ) );
296 m_parent->
send( re );
304 if( !info->
node().empty() )
306 i->setNode( info->
node() );
309 DiscoNodeHandlerMap::const_iterator it = m_nodeHandlers.find( info->
node() );
310 if( it == m_nodeHandlers.end() )
315 m_parent->
send( re );
320 DiscoNodeHandlerList::const_iterator in = (*it).second.begin();
321 for( ; in != (*it).second.end(); ++in )
325 identities.merge( il );
328 features.merge( fl );
331 i->setIdentities( identities );
332 i->setFeatures( features );
337 IdentityList::const_iterator it = m_identities.begin();
338 for( ; it != m_identities.end(); ++it )
340 il.push_back(
new Identity( *(*it) ) );
342 i->setIdentities( il );
343 i->setFeatures( m_features );
348 re.addExtension( i );
349 m_parent->
send( re );
357 if( !items->
node().empty() )
359 DiscoNodeHandlerMap::const_iterator it = m_nodeHandlers.find( items->
node() );
360 if( it == m_nodeHandlers.end() )
365 m_parent->
send( re );
371 DiscoNodeHandlerList::const_iterator in = (*it).second.begin();
372 for( ; in != (*it).second.end(); ++in )
376 itemlist.merge( il );
382 re.addExtension( i );
383 m_parent->
send( re );
392 DiscoHandlerList::const_iterator it = m_discoHandlers.begin();
393 for( ; it != m_discoHandlers.end(); ++it )
395 if( (*it)->handleDiscoSet( iq ) )
410 DiscoHandlerMap::iterator it = m_track.find( iq.
id() );
411 if( it != m_track.end() && (*it).second.dh )
422 (*it).second.dh->handleDiscoInfo( iq.
from(), *di, (*it).second.context );
429 (*it).second.dh->handleDiscoItems( iq.
from(), *di, (*it).second.context );
437 (*it).second.dh->handleDiscoError( iq.
from(), iq.
error(), (*it).second.context );
449 void Disco::getDisco(
const JID& to,
const std::string& node,
DiscoHandler* dh,
int context,
450 IdType idType,
const std::string& tid )
452 const std::string&
id = tid.empty() ? m_parent->
getID() : tid;
455 if( idType == GetDiscoInfo )
456 iq.addExtension(
new Info( node ) );
458 iq.addExtension(
new Items( node ) );
460 DiscoHandlerContext ct;
462 ct.context = context;
464 m_parent->
send( iq,
this, idType );
469 m_versionName =
name;
475 const std::string& name )
483 m_discoHandlers.remove( dh );
484 DiscoHandlerMap::iterator t;
485 DiscoHandlerMap::iterator it = m_track.begin();
486 while( it != m_track.end() )
490 if( dh == (*t).second.dh )
499 m_nodeHandlers[node].push_back( nh );
504 DiscoNodeHandlerMap::iterator it = m_nodeHandlers.find( node );
505 if( it != m_nodeHandlers.end() )
507 (*it).second.remove( nh );
508 if( (*it).second.empty() )
509 m_nodeHandlers.erase( it );
515 DiscoNodeHandlerMap::iterator it = m_nodeHandlers.begin();
516 DiscoNodeHandlerMap::iterator it2;
517 while( it != m_nodeHandlers.end() )
527 if( defaultFeatures )
const TagList & children() const
virtual Tag * tag() const
Items(const std::string &node=EmptyString)
void addFeature(const std::string &feature)
An abstraction of a Disco query element (from Service Discovery, XEP-0030) in the disco::items namesp...
void removeNodeHandlers(DiscoNodeHandler *nh)
std::list< Item * > ItemList
void removeIDHandler(IqHandler *ih)
virtual const std::string & filterString() const
const std::string & name() const
std::list< std::string > StringList
void clearList(std::list< T * > &L)
An abstraction of an IQ stanza.
void removeIqHandler(IqHandler *ih, int exttype)
const DataForm * form() const
void addExtension(const StanzaExtension *se)
void removeDiscoHandler(DiscoHandler *dh)
std::list< Identity * > IdentityList
const std::string & name() const
const StringList features(bool defaultFeatures=false) const
const std::string & node() const
std::list< Tag * > TagList
void removeNodeHandler(DiscoNodeHandler *nh, const std::string &node)
This is an implementation of XEP-0092 as a StanzaExtension.
A stanza error abstraction implemented as a StanzaExtension.
bool removeStanzaExtension(int ext)
void setForm(DataForm *form)
void setFrom(const JID &from)
virtual bool handleIq(const IQ &iq)
const std::string XMLNS_DISCO_INFO
Derived classes can be registered as NodeHandlers for certain nodes with the Disco object...
const std::string & version() const
void addChild(Tag *child)
const std::string XMLNS_X_DATA
Item(const JID &jid, const std::string &node, const std::string &name)
void registerNodeHandler(DiscoNodeHandler *nh, const std::string &node)
const std::string XMLNS_DISCO_ITEMS
The namespace for the gloox library.
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string & xmlns() const
Identity(const std::string &category, const std::string &type, const std::string &name)
virtual const std::string & filterString() const
const std::string & findAttribute(const std::string &name) const
const std::string & os() const
virtual Tag * tag() const
void setIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
void setVersion(const std::string &name, const std::string &version, const std::string &os=EmptyString)
bool addAttribute(Attribute *attr)
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
void setForm(DataForm *form)
const std::string & name() const
const std::string XMLNS_VERSION
An abstraction of a Disco item (Service Discovery, XEP-0030).
A virtual interface that enables objects to receive Service Discovery (XEP-0030) events.
const std::string getID()
const Error * error() const
bool hasFeature(const std::string &feature) const
void addIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
virtual void handleIqID(const IQ &iq, int context)
const IdentityList & identities() const
const std::string & id() const
const std::string EmptyString
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const StanzaExtension * findExtension(int type) const
This is an abstraction of an XML element.
void setItems(const ItemList &items)
An abstraction of a Disco identity (Service Discovery, XEP-0030).
const std::string & node() const