14 #include "clientbase.h"
15 #include "rostermanager.h"
17 #include "rosteritem.h"
18 #include "rosteritemdata.h"
19 #include "rosterlistener.h"
20 #include "privatexml.h"
22 #include "stanzaextension.h"
23 #include "capabilities.h"
30 RosterManager::Query::Query(
const JID& jid,
const std::string& name,
const StringList& groups )
33 m_roster.push_back(
new RosterItemData( jid, name, groups ) );
36 RosterManager::Query::Query(
const JID& jid )
39 m_roster.push_back(
new RosterItemData( jid ) );
42 RosterManager::Query::Query(
const Tag* tag )
45 if( !tag || tag->name() !=
"query" || tag->xmlns() != XMLNS_ROSTER )
48 const ConstTagList& l = tag->findTagList(
"query/item" );
49 ConstTagList::const_iterator it = l.begin();
50 for( ; it != l.end(); ++it )
53 const ConstTagList& g = (*it)->findTagList(
"item/group" );
54 ConstTagList::const_iterator it_g = g.begin();
55 for( ; it_g != g.end(); ++it_g )
56 groups.push_back( (*it_g)->cdata() );
58 const std::string sub = (*it)->findAttribute(
"subscription" );
60 m_roster.push_back(
new RosterItemData( JID( (*it)->findAttribute(
"jid" ) ) ) );
63 RosterItemData* rid =
new RosterItemData( JID( (*it)->findAttribute(
"jid" ) ),
64 (*it)->findAttribute(
"name" ),
66 rid->setSubscription( sub, (*it)->findAttribute(
"ask" ) );
67 m_roster.push_back( rid );
72 RosterManager::Query::~Query()
74 util::clearList( m_roster );
77 const std::string& RosterManager::Query::filterString()
const
79 static const std::string filter =
"/iq/query[@xmlns='" +
XMLNS_ROSTER +
"']";
83 Tag* RosterManager::Query::tag()
const
85 Tag* t =
new Tag(
"query" );
86 t->setXmlns( XMLNS_ROSTER );
88 RosterData::const_iterator it = m_roster.begin();
89 for( ; it != m_roster.end(); ++it )
90 t->addChild( (*it)->tag() );
95 StanzaExtension* RosterManager::Query::clone()
const
97 Query* q =
new Query();
98 RosterData::const_iterator it = m_roster.begin();
99 for( ; it != m_roster.end(); ++it )
101 q->m_roster.push_back(
new RosterItemData( *(*it) ) );
109 : m_rosterListener( 0 ), m_parent( parent ), m_privateXML( 0 ),
110 m_syncSubscribeReq( false )
154 m_parent->
send( iq,
this, RequestRoster );
164 if( q && q->roster().size() )
165 mergePush( q->roster() );
168 m_parent->
send( re );
178 mergeRoster( q->roster() );
180 if( context == RequestRoster )
183 m_parent->rosterFilled();
185 if( m_rosterListener )
191 if( context == RequestRoster && m_parent )
192 m_parent->rosterFilled();
194 if( m_rosterListener )
205 Roster::iterator it = m_roster.find( presence.
from().
bare() );
206 if( it != m_roster.end() || (
self = ( presence.
from().
bareJID() == m_self->
jidJID() ) ) )
208 RosterItem* ri =
self ? m_self : (*it).second;
209 const std::string& resource = presence.
from().
resource();
221 if( m_rosterListener && !
self )
224 else if( m_rosterListener &&
self )
230 if( m_rosterListener )
236 const StringList& groups,
const std::string& msg )
241 add( jid, name, groups );
256 m_parent->
send( iq,
this, AddRosterItem );
279 m_parent->
send( iq,
this, RemoveRosterItem );
284 Roster::const_iterator it = m_roster.begin();
285 for( ; it != m_roster.end(); ++it )
287 if( !(*it).second->changed() )
291 iq.
addExtension(
new Query( (*it).second->jidJID(), (*it).second->name(), (*it).second->groups() ) );
292 m_parent->
send( iq,
this, SynchronizeRoster );
305 if( !m_rosterListener )
313 if( m_syncSubscribeReq )
331 if( m_syncSubscribeReq && answer )
349 m_syncSubscribeReq = syncSubscribeReq;
350 m_rosterListener = rl;
355 m_syncSubscribeReq =
false;
356 m_rosterListener = 0;
362 Tag* t =
new Tag(
"roster", m_delimiter );
370 m_delimiter = xml->
cdata();
379 Roster::const_iterator it = m_roster.find( jid.
bare() );
380 return it != m_roster.end() ? (*it).second : 0;
383 void RosterManager::mergePush(
const RosterData& data )
385 RosterData::const_iterator it = data.begin();
386 for( ; it != data.end(); ++it )
388 Roster::iterator itr = m_roster.find( (*it)->jidJID().full() );
389 if( itr != m_roster.end() )
391 if( (*it)->remove() )
393 if( m_rosterListener )
395 delete (*itr).second;
396 m_roster.erase( itr );
400 (*itr).second->setData( *(*it) );
401 if( m_rosterListener )
405 else if( !(*it)->remove() )
407 m_roster.insert( std::make_pair( (*it)->jidJID().full(),
new RosterItem( *(*it) ) ) );
408 if( m_rosterListener )
414 void RosterManager::mergeRoster(
const RosterData& data )
416 RosterData::const_iterator it = data.begin();
417 for( ; it != data.end(); ++it )
418 m_roster.insert( std::make_pair( (*it)->jidJID().full(),
new RosterItem( *(*it) ) ) );
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const std::string getID()
void registerPresenceHandler(PresenceHandler *ph)
void removeSubscriptionHandler(SubscriptionHandler *sh)
void removeIqHandler(IqHandler *ih, int exttype)
void registerSubscriptionHandler(SubscriptionHandler *sh)
void removeIDHandler(IqHandler *ih)
bool removeStanzaExtension(int ext)
void registerIqHandler(IqHandler *ih, int exttype)
void registerStanzaExtension(StanzaExtension *ext)
void removePresenceHandler(PresenceHandler *ph)
An abstraction of an IQ stanza.
const std::string & resource() const
const std::string & bare() const
An abstraction of a presence stanza.
PresenceType presence() const
PresenceType subtype() const
const std::string status(const std::string &lang="default") const
This class implements XEP-0049 (Private XML Storage).
std::string requestXML(const std::string &tag, const std::string &xmlns, PrivateXMLHandler *pxh)
std::string storeXML(const Tag *tag, PrivateXMLHandler *pxh)
An abstraction of a roster item.
void setPriority(const std::string &resource, int priority)
const JID & jidJID() const
void removeResource(const std::string &resource)
void setStatus(const std::string &resource, const std::string &msg)
void setExtensions(const std::string &resource, const StanzaExtensionList &exts)
void setPresence(const std::string &resource, Presence::PresenceType presence)
A virtual interface which can be reimplemented to receive roster updates.
virtual bool handleSubscriptionRequest(const JID &jid, const std::string &msg)=0
virtual void handleItemUnsubscribed(const JID &jid)=0
virtual void handleItemRemoved(const JID &jid)=0
virtual void handleRoster(const Roster &roster)=0
virtual void handleItemSubscribed(const JID &jid)=0
virtual void handleNonrosterPresence(const Presence &presence)=0
virtual void handleItemAdded(const JID &jid)=0
virtual void handleItemUpdated(const JID &jid)=0
virtual void handleRosterPresence(const RosterItem &item, const std::string &resource, Presence::PresenceType presence, const std::string &msg)=0
virtual void handleSelfPresence(const RosterItem &item, const std::string &resource, Presence::PresenceType presence, const std::string &msg)=0
virtual bool handleUnsubscriptionRequest(const JID &jid, const std::string &msg)=0
virtual void handleRosterError(const IQ &iq)=0
void add(const JID &jid, const std::string &name, const StringList &groups)
const std::string & delimiter() const
void subscribe(const JID &jid, const std::string &name=EmptyString, const StringList &groups=StringList(), const std::string &msg=EmptyString)
void unsubscribe(const JID &jid, const std::string &msg=EmptyString)
virtual void handleSubscription(const Subscription &subscription)
virtual void handleIqID(const IQ &iq, int context)
virtual bool handleIq(const IQ &iq)
void setDelimiter(const std::string &delimiter)
virtual void handlePrivateXML(const Tag *xml)
virtual void handlePresence(const Presence &presence)
void cancel(const JID &jid, const std::string &msg=EmptyString)
RosterItem * getRosterItem(const JID &jid)
virtual void handlePrivateXMLResult(const std::string &uid, PrivateXMLResult pxResult)
void ackSubscriptionRequest(const JID &to, bool ack)
void remove(const JID &jid)
void registerRosterListener(RosterListener *rl, bool syncSubscribeReq=true)
void removeRosterListener()
void addExtension(const StanzaExtension *se)
const StanzaExtensionList & extensions() const
const std::string & id() const
const StanzaExtension * findExtension(int type) const
An abstraction of a subscription stanza.
const std::string status(const std::string &lang="default") const
This is an abstraction of an XML element.
bool addAttribute(Attribute *attr)
const std::string cdata() const
void clearMap(std::map< Key, T * > &M)
The namespace for the gloox library.
std::list< std::string > StringList
std::list< const Tag * > ConstTagList
const std::string XMLNS_ROSTER
std::map< const std::string, RosterItem * > Roster
const std::string XMLNS_ROSTER_DELIMITER