gloox  1.0.28
privacymanager.h
1 /*
2  Copyright (c) 2005-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 PRIVACYMANAGER_H__
15 #define PRIVACYMANAGER_H__
16 
17 #include "iqhandler.h"
18 #include "privacylisthandler.h"
19 #include "stanzaextension.h"
20 
21 #include <string>
22 
23 namespace gloox
24 {
25 
26  class ClientBase;
27 
34  class GLOOX_API PrivacyManager : public IqHandler
35  {
36  public:
41  PrivacyManager( ClientBase* parent );
42 
46  virtual ~PrivacyManager();
47 
54  std::string store( const std::string& name, const PrivacyListHandler::PrivacyList& list );
55 
59  std::string requestListNames()
60  { return operation( PLRequestNames, EmptyString ); }
61 
66  std::string requestList( const std::string& name )
67  { return operation( PLRequestList, name ); }
68 
73  std::string removeList( const std::string& name )
74  { return operation( PLRemove, name ); }
75 
80  std::string setDefault( const std::string& name )
81  { return operation( PLDefault, name ); }
82 
86  std::string unsetDefault()
87  { return operation( PLUnsetDefault, EmptyString ); }
88 
93  std::string setActive( const std::string& name )
94  { return operation( PLActivate, name ); }
95 
99  std::string unsetActive()
100  { return operation( PLUnsetActivate, EmptyString ); }
101 
108  { m_privacyListHandler = plh; }
109 
114  { m_privacyListHandler = 0; }
115 
116  // reimplemented from IqHandler.
117  virtual bool handleIq( const IQ& iq );
118 
119  // reimplemented from IqHandler.
120  virtual void handleIqID( const IQ& iq, int context );
121 
122  private:
123  enum IdType
124  {
125  PLRequestNames,
126  PLRequestList,
127  PLActivate,
128  PLDefault,
129  PLUnsetActivate,
130  PLUnsetDefault,
131  PLRemove,
132  PLStore
133  };
134 
135  class Query : public StanzaExtension
136  {
137  public:
145  Query( IdType context, const std::string& name,
147 
152  Query( const Tag* tag = 0 );
153 
157  virtual ~Query();
158 
163  const std::string& active() const { return m_active; }
164 
169  const std::string& def() const { return m_default; }
170 
175  const PrivacyListHandler::PrivacyList& items() const
176  { return m_items; }
177 
182  const StringList& names() const { return m_names; }
183 
189  const std::string& name() const
190  {
191  if( m_names.empty())
192  return EmptyString;
193  else
194  return (*m_names.begin());
195  }
196 
197  // reimplemented from StanzaExtension
198  virtual const std::string& filterString() const;
199 
200  // reimplemented from StanzaExtension
201  virtual StanzaExtension* newInstance( const Tag* tag ) const
202  {
203  return new Query( tag );
204  }
205 
206  // reimplemented from StanzaExtension
207  virtual Tag* tag() const;
208 
209  // reimplemented from StanzaExtension
210  virtual StanzaExtension* clone() const
211  {
212  return new Query( *this );
213  }
214 
215  private:
216  IdType m_context;
217  StringList m_names;
218  std::string m_default;
219  std::string m_active;
221  };
222 
223  std::string operation( IdType context, const std::string& name );
224 
225  ClientBase* m_parent;
226  PrivacyListHandler* m_privacyListHandler;
227  };
228 
229 }
230 
231 #endif // PRIVACYMANAGER_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
A virtual interface that allows to retrieve Privacy Lists.
std::list< PrivacyItem > PrivacyList
This class implements a manager for privacy lists as defined in section 10 of RFC 3921.
std::string requestListNames()
std::string removeList(const std::string &name)
std::string setDefault(const std::string &name)
std::string unsetActive()
std::string setActive(const std::string &name)
void registerPrivacyListHandler(PrivacyListHandler *plh)
std::string unsetDefault()
std::string requestList(const std::string &name)
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