gloox
1.0
|
00001 /* 00002 Copyright (c) 2004-2009 by Jakob Schroeter <js@camaya.net> 00003 This file is part of the gloox library. http://camaya.net/gloox 00004 00005 This software is distributed under a license. The full license 00006 agreement can be found in the file LICENSE in this distribution. 00007 This software may not be copied, modified, sold or distributed 00008 other than expressed in the named license agreement. 00009 00010 This software is distributed without any warranty. 00011 */ 00012 00013 00014 #ifndef ROSTERMANAGER_H__ 00015 #define ROSTERMANAGER_H__ 00016 00017 #include "subscriptionhandler.h" 00018 #include "privatexmlhandler.h" 00019 #include "iqhandler.h" 00020 #include "presencehandler.h" 00021 #include "rosterlistener.h" 00022 00023 #include <map> 00024 #include <string> 00025 #include <list> 00026 00027 namespace gloox 00028 { 00029 00030 class ClientBase; 00031 class Stanza; 00032 class PrivateXML; 00033 class RosterItem; 00034 00047 class GLOOX_API RosterManager : public IqHandler, public PresenceHandler, public SubscriptionHandler, 00048 public PrivateXMLHandler 00049 { 00050 public: 00055 RosterManager( ClientBase* parent ); 00056 00060 virtual ~RosterManager(); 00061 00066 void fill(); 00067 00072 Roster* roster(); 00073 00082 void subscribe( const JID& jid, const std::string& name = EmptyString, 00083 const StringList& groups = StringList(), 00084 const std::string& msg = EmptyString ); 00085 00089 void synchronize(); 00090 00098 void add( const JID& jid, const std::string& name, const StringList& groups ); 00099 00108 void unsubscribe( const JID& jid, const std::string& msg = EmptyString ); 00109 00118 void cancel( const JID& jid, const std::string& msg = EmptyString ); 00119 00126 void remove( const JID& jid ); 00127 00134 void ackSubscriptionRequest( const JID& to, bool ack ); 00135 00141 const std::string& delimiter() const { return m_delimiter; } 00142 00148 void setDelimiter( const std::string& delimiter ); 00149 00154 RosterItem* getRosterItem( const JID& jid ); 00155 00165 void registerRosterListener( RosterListener* rl, bool syncSubscribeReq = true ); 00166 00171 void removeRosterListener(); 00172 00173 // reimplemented from IqHandler. 00174 virtual bool handleIq( const IQ& iq ); 00175 00176 // reimplemented from IqHandler. 00177 virtual void handleIqID( const IQ& iq, int context ); 00178 00179 // reimplemented from PresenceHandler. 00180 virtual void handlePresence( const Presence& presence ); 00181 00182 // reimplemented from SubscriptionHandler. 00183 virtual void handleSubscription( const Subscription& subscription ); 00184 00185 // reimplemented from PrivateXMLHandler 00186 virtual void handlePrivateXML( const Tag* xml ); 00187 00188 // reimplemented from PrivateXMLHandler 00189 virtual void handlePrivateXMLResult( const std::string& uid, PrivateXMLResult pxResult ); 00190 00191 private: 00192 #ifdef ROSTERMANAGER_TEST 00193 public: 00194 #endif 00195 typedef std::list<RosterItemData*> RosterData; 00196 00203 class Query : public StanzaExtension 00204 { 00205 public: 00212 Query( const JID& jid, const std::string& name, const StringList& groups ); 00213 00218 Query( const JID& jid ); 00219 00224 Query( const Tag* tag = 0 ); 00225 00229 ~Query(); 00230 00237 const RosterData& roster() const { return m_roster; } 00238 00239 // reimplemented from StanzaExtension 00240 virtual const std::string& filterString() const; 00241 00242 // reimplemented from StanzaExtension 00243 virtual StanzaExtension* newInstance( const Tag* tag ) const 00244 { 00245 return new Query( tag ); 00246 } 00247 00248 // reimplemented from StanzaExtension 00249 virtual Tag* tag() const; 00250 00251 // reimplemented from StanzaExtension 00252 virtual StanzaExtension* clone() const; 00253 00254 private: 00255 RosterData m_roster; 00256 00257 }; 00258 00259 void mergePush( const RosterData& data ); 00260 void mergeRoster( const RosterData& data ); 00261 00262 RosterListener* m_rosterListener; 00263 Roster m_roster; 00264 ClientBase* m_parent; 00265 PrivateXML* m_privateXML; 00266 RosterItem* m_self; 00267 00268 std::string m_delimiter; 00269 bool m_syncSubscribeReq; 00270 00271 enum RosterContext 00272 { 00273 RequestRoster, 00274 AddRosterItem, 00275 RemoveRosterItem, 00276 SynchronizeRoster 00277 }; 00278 00279 }; 00280 00281 } 00282 00283 #endif // ROSTER_H__