gloox
1.0
|
00001 /* 00002 Copyright (c) 2005-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 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 // reimplemented from StanzaExtension 00201 virtual const std::string& filterString() const; 00202 00203 // reimplemented from StanzaExtension 00204 virtual StanzaExtension* newInstance( const Tag* tag ) const 00205 { 00206 return new Query( tag ); 00207 } 00208 00209 // reimplemented from StanzaExtension 00210 virtual Tag* tag() const; 00211 00212 // reimplemented from StanzaExtension 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 // reimplemented from IqHandler. 00310 virtual bool handleIq( const IQ& iq ) { (void)iq; return false; } 00311 00312 // reimplemented from IqHandler. 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__