gloox  1.0.23
registration.h
1 /*
2  Copyright (c) 2005-2019 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 REGISTRATION_H__
15 #define REGISTRATION_H__
16 
17 #include "iqhandler.h"
18 #include "registrationhandler.h"
19 #include "dataform.h"
20 #include "jid.h"
21 #include "oob.h"
22 
23 #include <string>
24 #include <map>
25 
26 namespace gloox
27 {
28 
29  class ClientBase;
30  class Stanza;
31 
37  {
38  std::string username;
39  std::string nick;
40  std::string password;
41  std::string name;
42  std::string first;
43  std::string last;
44  std::string email;
45  std::string address;
46  std::string city;
47  std::string state;
48  std::string zip;
49  std::string phone;
50  std::string url;
51  std::string date;
52  std::string misc;
53  std::string text;
54  };
55 
92  class GLOOX_API Registration : public IqHandler
93  {
94  public:
95 
99  enum fieldEnum
100  {
101  FieldUsername = 1,
102  FieldNick = 2,
103  FieldPassword = 4,
104  FieldName = 8,
105  FieldFirst = 16,
106  FieldLast = 32,
107  FieldEmail = 64,
108  FieldAddress = 128,
109  FieldCity = 256,
110  FieldState = 512,
111  FieldZip = 1024,
112  FieldPhone = 2048,
113  FieldUrl = 4096,
114  FieldDate = 8192,
115  FieldMisc = 16384,
116  FieldText = 32768
117  };
118 
125  class Query : public StanzaExtension
126  {
127  public:
132  Query( DataForm* form );
133 
138  Query( bool del = false );
139 
146  Query( int fields, const RegistrationFields& values );
147 
152  Query( const Tag* tag );
153 
157  virtual ~Query();
158 
163  const DataForm* form() const { return m_form; }
164 
169  const std::string& instructions() const { return m_instructions; }
170 
175  int fields() const { return m_fields; }
176 
180  const RegistrationFields& values() const { return m_values; }
181 
186  bool registered() const { return m_reg; }
187 
192  bool remove() const { return m_del; }
193 
198  const OOB* oob() const { return m_oob; }
199 
200  // reimplemented from StanzaExtension
201  virtual const std::string& filterString() const;
202 
203  // reimplemented from StanzaExtension
204  virtual StanzaExtension* newInstance( const Tag* tag ) const
205  {
206  return new Query( tag );
207  }
208 
209  // reimplemented from StanzaExtension
210  virtual Tag* tag() const;
211 
212  // reimplemented from StanzaExtension
213  virtual StanzaExtension* clone() const
214  {
215  Query* q = new Query();
216  q->m_form = m_form ? new DataForm( *m_form ) : 0;
217  q->m_fields = m_fields;
218  q->m_values = m_values;
219  q->m_instructions = m_instructions;
220  q->m_oob = new OOB( *m_oob );
221  q->m_del = m_del;
222  q->m_reg = m_reg;
223  return q;
224  }
225 
226  private:
227  DataForm* m_form;
228  int m_fields;
229  RegistrationFields m_values;
230  std::string m_instructions;
231  OOB* m_oob;
232  bool m_del;
233  bool m_reg;
234  };
235 
242  Registration( ClientBase* parent, const JID& to );
243 
248  Registration( ClientBase* parent );
249 
253  virtual ~Registration();
254 
260  void fetchRegistrationFields();
261 
274  bool createAccount( int fields, const RegistrationFields& values );
275 
283  void createAccount( DataForm* form );
284 
288  void removeAccount();
289 
296  void changePassword( const std::string& username, const std::string& password );
297 
302  void registerRegistrationHandler( RegistrationHandler* rh );
303 
307  void removeRegistrationHandler();
308 
309  // reimplemented from IqHandler.
310  virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
311 
312  // reimplemented from IqHandler.
313  virtual void handleIqID( const IQ& iq, int context );
314 
315  private:
316 #ifdef REGISTRATION_TEST
317  public:
318 #endif
319 
320  enum IdType
321  {
322  FetchRegistrationFields,
323  CreateAccount,
324  RemoveAccount,
325  ChangePassword
326  };
327 
328  Registration operator=( const Registration& );
329 
330  void init();
331 
332  ClientBase* m_parent;
333  const JID m_to;
334  RegistrationHandler* m_registrationHandler;
335  };
336 
337 }
338 
339 #endif // REGISTRATION_H__
A virtual interface that receives events from an Registration object.
This class is an implementation of XEP-0077 (In-Band Registration).
Definition: registration.h:92
An abstraction of an IQ stanza.
Definition: iq.h:33
An abstraction of a XEP-0004 Data Form.
Definition: dataform.h:56
const std::string & instructions() const
Definition: registration.h:169
virtual bool handleIq(const IQ &iq)
Definition: registration.h:310
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
const OOB * oob() const
Definition: registration.h:198
An abstraction of a JID.
Definition: jid.h:30
This is an abstraction of a jabber:x:oob namespace element or a jabber:iq:oob namespace element as sp...
Definition: oob.h:35
A wrapping class for the XEP-0077 <query> element.
Definition: registration.h:125
virtual StanzaExtension * clone() const
Definition: registration.h:213
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:31
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition: registration.h:204
const DataForm * form() const
Definition: registration.h:163
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:76
This is an abstraction of an XML element.
Definition: tag.h:46