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 )