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 )
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" ) );
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() );
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 )
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 );
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 );
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 )
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const std::string getID()
void removeIqHandler(IqHandler *ih, int exttype)
void removeIDHandler(IqHandler *ih)
bool removeStanzaExtension(int ext)
A virtual interface that enables objects to receive Service Discovery (XEP-0030) events.
Derived classes can be registered as NodeHandlers for certain nodes with the Disco object.
An abstraction of a Disco identity (Service Discovery, XEP-0030).
Identity(const std::string &category, const std::string &type, const std::string &name)
const std::string & name() const
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
const std::string & node() const
void setForm(DataForm *form)
virtual const std::string & filterString() const
bool hasFeature(const std::string &feature) const
virtual Tag * tag() const
An abstraction of a Disco item (Service Discovery, XEP-0030).
Item(const JID &jid, const std::string &node, const std::string &name)
An abstraction of a Disco query element (from Service Discovery, XEP-0030) in the disco::items namesp...
const std::string & node() const
virtual const std::string & filterString() const
Items(const std::string &node=EmptyString)
virtual Tag * tag() const
void setItems(const ItemList &items)
const std::string & version() const
void removeDiscoHandler(DiscoHandler *dh)
void setForm(DataForm *form)
void removeNodeHandler(DiscoNodeHandler *nh, const std::string &node)
const DataForm * form() const
virtual void handleIqID(const IQ &iq, int context)
virtual bool handleIq(const IQ &iq)
void removeNodeHandlers(DiscoNodeHandler *nh)
void registerNodeHandler(DiscoNodeHandler *nh, const std::string &node)
void setIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
void addFeature(const std::string &feature)
void setVersion(const std::string &name, const std::string &version, const std::string &os=EmptyString)
const StringList features(bool defaultFeatures=false) const
std::list< Identity * > IdentityList
const std::string & name() const
const IdentityList & identities() const
void addIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
const std::string & os() const
std::list< Item * > ItemList
A stanza error abstraction implemented as a StanzaExtension.
An abstraction of an IQ stanza.
This is an implementation of XEP-0092 as a StanzaExtension.
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
void addExtension(const StanzaExtension *se)
void setFrom(const JID &from)
const Error * error() const
const std::string & id() const
const StanzaExtension * findExtension(int type) const
This is an abstraction of an XML element.
const std::string xmlns() const
bool addAttribute(Attribute *attr)
void addChild(Tag *child)
const std::string & findAttribute(const std::string &name) const
const std::string & name() const
const TagList & children() const
void clearList(std::list< T * > &L)
The namespace for the gloox library.
std::list< Tag * > TagList
const std::string XMLNS_VERSION
std::list< std::string > StringList
const std::string XMLNS_DISCO_ITEMS
const std::string XMLNS_X_DATA
const std::string XMLNS_DISCO_INFO
const std::string EmptyString
@ StanzaErrorItemNotFound