14 #include "clientbase.h"
15 #include "rostermanager.h"
17 #include "rosteritem.h"
18 #include "rosterlistener.h"
19 #include "privatexml.h"
26 : m_rosterListener( 0 ), m_parent( parent ), m_privateXML( 0 ),
27 m_syncSubscribeReq( false )
53 Roster::iterator it = m_roster.begin();
54 for( ; it != m_roster.end(); ++it )
67 Roster::iterator it = m_roster.begin();
68 while( it != m_roster.end() )
72 m_roster.erase( it2 );
80 Tag *q =
new Tag( iq,
"query" );
89 extractItems( stanza,
false );
91 if( m_rosterListener )
94 m_parent->rosterFilled();
100 extractItems( stanza,
true );
102 Tag *iq =
new Tag(
"iq" );
105 m_parent->
send( iq );
111 if( m_rosterListener )
130 Tag::TagList::const_iterator it_c = l.begin();
131 for( ; it_c != l.end(); ++it_c )
133 if( (*it_c)->name() ==
"c" )
136 cap.append( (*it_c)->findAttribute(
"node" ).c_str() );
138 cap.append( (*it_c)->findAttribute(
"ver" ).c_str() );
139 if( (*it_c)->findAttribute(
"ext" ).size ())
142 cap.append( (*it_c)->findAttribute(
"ext" ).c_str() );
144 caps.push_back( cap );
148 Roster::iterator it = m_roster.find( stanza->
from().
bare() );
149 if( it != m_roster.end() )
152 (*it).second->removeResource( stanza->
from().
resource() );
161 if( m_rosterListener )
177 if( m_rosterListener )
183 if( m_rosterListener )
189 const StringList& groups,
const std::string& msg )
194 add( jid, name, groups );
196 Tag *s =
new Tag(
"presence" );
201 new Tag( s,
"status", msg );
212 const std::string&
id = m_parent->
getID();
214 Tag *iq =
new Tag(
"iq" );
217 Tag *q =
new Tag( iq,
"query" );
219 Tag *i =
new Tag( q,
"item" );
224 if( groups.size() != 0 )
226 StringList::const_iterator it = groups.begin();
227 for( ; it != groups.end(); ++it )
228 new Tag( i,
"group", (*it) );
231 m_parent->
send( iq );
236 Tag *s =
new Tag(
"presence" );
240 new Tag( s,
"status", msg );
248 Tag *s =
new Tag(
"presence" );
252 new Tag( s,
"status", msg );
260 const std::string&
id = m_parent->
getID();
262 Tag *iq =
new Tag(
"iq" );
265 Tag *q =
new Tag( iq,
"query" );
267 Tag *i =
new Tag( q,
"item" );
271 m_parent->
send( iq );
276 Roster::const_iterator it = m_roster.begin();
277 for( ; it != m_roster.end(); ++it )
279 if( (*it).second->changed() )
281 const std::string&
id = m_parent->
getID();
283 Tag *iq =
new Tag(
"iq" );
286 Tag *q =
new Tag( iq,
"query" );
288 Tag *i =
new Tag( q,
"item" );
290 if( !(*it).second->name().empty() )
293 if( (*it).second->groups().size() != 0 )
295 StringList::const_iterator g_it = (*it).second->groups().begin();
296 for( ; g_it != (*it).second->groups().end(); ++g_it )
297 new Tag( i,
"group", (*g_it) );
300 m_parent->
send( iq );
307 Tag *p =
new Tag(
"presence" );
319 if( !m_rosterListener )
327 if( m_syncSubscribeReq )
346 Tag *p =
new Tag(
"presence" );
352 if( m_syncSubscribeReq && answer )
375 m_syncSubscribeReq = syncSubscribeReq;
376 m_rosterListener = rl;
381 m_syncSubscribeReq =
false;
382 m_rosterListener = 0;
385 void RosterManager::extractItems(
Tag *tag,
bool isPush )
389 Tag::TagList::const_iterator it = l.begin();
390 for( ; it != l.end(); ++it )
392 if( (*it)->name() ==
"item" )
395 if( (*it)->hasChild(
"group" ) )
398 Tag::TagList::const_iterator it_g = g.begin();
399 for( ; it_g != g.end(); ++it_g )
401 gl.push_back( (*it_g)->cdata() );
405 const JID& jid = (*it)->findAttribute(
"jid" );
406 Roster::iterator it_d = m_roster.find( jid.bare() );
407 if( it_d != m_roster.end() )
409 (*it_d).second->setName( (*it)->findAttribute(
"name" ) );
410 const std::string& sub = (*it)->findAttribute(
"subscription" );
411 if( sub ==
"remove" )
413 delete (*it_d).second;
414 m_roster.erase( it_d );
415 if( m_rosterListener )
419 const std::string& ask = (*it)->findAttribute(
"ask" );
423 (*it_d).second->setSubscription( sub, a );
424 (*it_d).second->setGroups( gl );
425 (*it_d).second->setSynchronized();
427 if( isPush && m_rosterListener )
432 const std::string& sub = (*it)->findAttribute(
"subscription" );
433 if( sub ==
"remove" )
435 const std::string& name = (*it)->findAttribute(
"name" );
436 const std::string& ask = (*it)->findAttribute(
"ask" );
442 add( jid.bare(), name, gl, caps, sub, a );
443 if( isPush && m_rosterListener )
452 const std::string& sub,
bool ask )
454 if( m_roster.find( jid ) == m_roster.end() )
455 m_roster[jid] =
new RosterItem( jid, name );
457 m_roster[jid]->setSubscription( sub, ask );
458 m_roster[jid]->setGroups( groups );
460 m_roster[jid]->setSynchronized();
466 Tag *t =
new Tag(
"roster", m_delimiter );
473 m_delimiter = xml->
cdata();
482 Roster::const_iterator it = m_roster.find( jid.
bare() );
483 if( it != m_roster.end() )