gloox  1.0.28
rostermanager.h
1 /*
2  Copyright (c) 2004-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef ROSTERMANAGER_H__
15 #define ROSTERMANAGER_H__
16 
17 #include "subscriptionhandler.h"
18 #include "privatexmlhandler.h"
19 #include "iqhandler.h"
20 #include "presencehandler.h"
21 #include "rosterlistener.h"
22 
23 #include <map>
24 #include <string>
25 #include <list>
26 
27 namespace gloox
28 {
29 
30  class ClientBase;
31  class Stanza;
32  class PrivateXML;
33  class RosterItem;
34 
47  class GLOOX_API RosterManager : public IqHandler, public PresenceHandler, public SubscriptionHandler,
48  public PrivateXMLHandler
49  {
50  public:
55  RosterManager( ClientBase* parent );
56 
60  virtual ~RosterManager();
61 
66  void fill();
67 
72  Roster* roster();
73 
82  void subscribe( const JID& jid, const std::string& name = EmptyString,
83  const StringList& groups = StringList(),
84  const std::string& msg = EmptyString );
85 
89  void synchronize();
90 
98  void add( const JID& jid, const std::string& name, const StringList& groups );
99 
108  void unsubscribe( const JID& jid, const std::string& msg = EmptyString );
109 
118  void cancel( const JID& jid, const std::string& msg = EmptyString );
119 
126  void remove( const JID& jid );
127 
134  void ackSubscriptionRequest( const JID& to, bool ack );
135 
141  const std::string& delimiter() const { return m_delimiter; }
142 
148  void setDelimiter( const std::string& delimiter );
149 
154  RosterItem* getRosterItem( const JID& jid );
155 
165  void registerRosterListener( RosterListener* rl, bool syncSubscribeReq = true );
166 
171  void removeRosterListener();
172 
173  // reimplemented from IqHandler.
174  virtual bool handleIq( const IQ& iq );
175 
176  // reimplemented from IqHandler.
177  virtual void handleIqID( const IQ& iq, int context );
178 
179  // reimplemented from PresenceHandler.
180  virtual void handlePresence( const Presence& presence );
181 
182  // reimplemented from SubscriptionHandler.
183  virtual void handleSubscription( const Subscription& subscription );
184 
185  // reimplemented from PrivateXMLHandler
186  virtual void handlePrivateXML( const Tag* xml );
187 
188  // reimplemented from PrivateXMLHandler
189  virtual void handlePrivateXMLResult( const std::string& uid, PrivateXMLResult pxResult );
190 
191  private:
192 #ifdef ROSTERMANAGER_TEST
193  public:
194 #endif
195  typedef std::list<RosterItemData*> RosterData;
196 
203  class Query : public StanzaExtension
204  {
205  public:
212  Query( const JID& jid, const std::string& name, const StringList& groups );
213 
218  Query( const JID& jid );
219 
224  Query( const Tag* tag = 0 );
225 
229  ~Query();
230 
237  const RosterData& roster() const { return m_roster; }
238 
239  // reimplemented from StanzaExtension
240  virtual const std::string& filterString() const;
241 
242  // reimplemented from StanzaExtension
243  virtual StanzaExtension* newInstance( const Tag* tag ) const
244  {
245  return new Query( tag );
246  }
247 
248  // reimplemented from StanzaExtension
249  virtual Tag* tag() const;
250 
251  // reimplemented from StanzaExtension
252  virtual StanzaExtension* clone() const;
253 
254  private:
255  RosterData m_roster;
256 
257  };
258 
259  void mergePush( const RosterData& data );
260  void mergeRoster( const RosterData& data );
261 
262  RosterListener* m_rosterListener;
263  Roster m_roster;
264  ClientBase* m_parent;
265  PrivateXML* m_privateXML;
266  RosterItem* m_self;
267 
268  std::string m_delimiter;
269  bool m_syncSubscribeReq;
270 
271  enum RosterContext
272  {
273  RequestRoster,
274  AddRosterItem,
275  RemoveRosterItem,
276  SynchronizeRoster
277  };
278 
279  };
280 
281 }
282 
283 #endif // ROSTER_H__
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:79
An abstraction of an IQ stanza.
Definition: iq.h:34
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:32
An abstraction of a JID.
Definition: jid.h:31
A virtual interface which can be reimplemented to receive presence stanzas.
An abstraction of a presence stanza.
Definition: presence.h:33
A virtual interface which can be reimplemented to store and receive private XML data.
An abstraction of a roster item.
Definition: rosteritem.h:41
A virtual interface which can be reimplemented to receive roster updates.
This class implements Jabber/XMPP roster handling in the jabber:iq:roster namespace.
Definition: rostermanager.h:49
const std::string & delimiter() const
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
A virtual interface which can be reimplemented to receive incoming subscription stanzas.
An abstraction of a subscription stanza.
Definition: subscription.h:32
This is an abstraction of an XML element.
Definition: tag.h:47
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< std::string > StringList
Definition: gloox.h:1251
const std::string EmptyString
Definition: gloox.cpp:124
std::map< const std::string, RosterItem * > Roster