registration.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef REGISTRATION_H__
00015 #define REGISTRATION_H__
00016
00017 #include "iqhandler.h"
00018 #include "registrationhandler.h"
00019 #include "dataform.h"
00020 #include "jid.h"
00021 #include "oob.h"
00022
00023 #include <string>
00024 #include <map>
00025
00026 namespace gloox
00027 {
00028
00029 class ClientBase;
00030 class Stanza;
00031
00036 struct RegistrationFields
00037 {
00038 std::string username;
00039 std::string nick;
00040 std::string password;
00041 std::string name;
00042 std::string first;
00043 std::string last;
00044 std::string email;
00045 std::string address;
00046 std::string city;
00047 std::string state;
00048 std::string zip;
00049 std::string phone;
00050 std::string url;
00051 std::string date;
00052 std::string misc;
00053 std::string text;
00054 };
00055
00092 class GLOOX_API Registration : public IqHandler
00093 {
00094 public:
00095
00099 enum fieldEnum
00100 {
00101 FieldUsername = 1,
00102 FieldNick = 2,
00103 FieldPassword = 4,
00104 FieldName = 8,
00105 FieldFirst = 16,
00106 FieldLast = 32,
00107 FieldEmail = 64,
00108 FieldAddress = 128,
00109 FieldCity = 256,
00110 FieldState = 512,
00111 FieldZip = 1024,
00112 FieldPhone = 2048,
00113 FieldUrl = 4096,
00114 FieldDate = 8192,
00115 FieldMisc = 16384,
00116 FieldText = 32768
00117 };
00118
00125 class Query : public StanzaExtension
00126 {
00127 public:
00132 Query( DataForm* form );
00133
00138 Query( bool del = false );
00139
00146 Query( int fields, const RegistrationFields& values );
00147
00152 Query( const Tag* tag );
00153
00157 virtual ~Query();
00158
00163 const DataForm* form() const { return m_form; }
00164
00169 const std::string& instructions() const { return m_instructions; }
00170
00175 int fields() const { return m_fields; }
00176
00180 const RegistrationFields& values() const { return m_values; }
00181
00186 bool registered() const { return m_reg; }
00187
00192 bool remove() const { return m_del; }
00193
00198 const OOB* oob() const { return m_oob; }
00199
00200
00201 virtual const std::string& filterString() const;
00202
00203
00204 virtual StanzaExtension* newInstance( const Tag* tag ) const
00205 {
00206 return new Query( tag );
00207 }
00208
00209
00210 virtual Tag* tag() const;
00211
00212
00213 virtual StanzaExtension* clone() const
00214 {
00215 Query* q = new Query();
00216 q->m_form = m_form ? new DataForm( *m_form ) : 0;
00217 q->m_fields = m_fields;
00218 q->m_values = m_values;
00219 q->m_instructions = m_instructions;
00220 q->m_oob = new OOB( *m_oob );
00221 q->m_del = m_del;
00222 q->m_reg = m_reg;
00223 return q;
00224 }
00225
00226 private:
00227 DataForm* m_form;
00228 int m_fields;
00229 RegistrationFields m_values;
00230 std::string m_instructions;
00231 OOB* m_oob;
00232 bool m_del;
00233 bool m_reg;
00234 };
00235
00242 Registration( ClientBase* parent, const JID& to );
00243
00248 Registration( ClientBase* parent );
00249
00253 virtual ~Registration();
00254
00260 void fetchRegistrationFields();
00261
00274 bool createAccount( int fields, const RegistrationFields& values );
00275
00283 void createAccount( DataForm* form );
00284
00288 void removeAccount();
00289
00296 void changePassword( const std::string& username, const std::string& password );
00297
00302 void registerRegistrationHandler( RegistrationHandler* rh );
00303
00307 void removeRegistrationHandler();
00308
00309
00310 virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
00311
00312
00313 virtual void handleIqID( const IQ& iq, int context );
00314
00315 private:
00316 #ifdef REGISTRATION_TEST
00317 public:
00318 #endif
00319
00320 enum IdType
00321 {
00322 FetchRegistrationFields,
00323 CreateAccount,
00324 RemoveAccount,
00325 ChangePassword
00326 };
00327
00328 Registration operator=( const Registration& );
00329
00330 void init();
00331
00332 ClientBase* m_parent;
00333 const JID m_to;
00334 RegistrationHandler* m_registrationHandler;
00335 };
00336
00337 }
00338
00339 #endif // REGISTRATION_H__