client.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CLIENT_H__
00015 #define CLIENT_H__
00016
00017 #include "clientbase.h"
00018 #include "presence.h"
00019
00020 #include <string>
00021
00022 namespace gloox
00023 {
00024
00025 class Capabilities;
00026 class RosterManager;
00027 class NonSaslAuth;
00028 class IQ;
00029
00098 class GLOOX_API Client : public ClientBase
00099 {
00100 public:
00101
00102 friend class NonSaslAuth;
00103 friend class Parser;
00104
00111 Client( const std::string& server );
00112
00123 Client( const JID& jid, const std::string& password, int port = -1 );
00124
00128 virtual ~Client();
00129
00145 bool bindResource( const std::string& resource )
00146 { return bindOperation( resource, true ); }
00147
00157 bool selectResource( const std::string& resource );
00158
00165 bool hasResourceBind() const { return ((m_streamFeatures & StreamFeatureUnbind) == StreamFeatureUnbind); }
00166
00175 bool unbindResource( const std::string& resource )
00176 { return bindOperation( resource, false ); }
00177
00182 const std::string& resource() const { return m_jid.resource(); }
00183
00188 int priority() const { return m_presence.priority(); }
00189
00194 void setUsername( const std::string &username );
00195
00200 void setResource( const std::string &resource ) { m_jid.setResource( resource ); }
00201
00212 void setPresence( const JID& to, Presence::PresenceType pres, int priority,
00213 const std::string& status = EmptyString );
00214
00228 void setPresence( Presence::PresenceType pres, int priority,
00229 const std::string& status = EmptyString );
00230
00242 void setPresence() { sendPresence( m_presence ); }
00243
00248 Presence& presence() { return m_presence; }
00249
00255 GLOOX_DEPRECATED void setForceNonSasl( bool force = true ) { m_forceNonSasl = force; }
00256
00262 void disableRoster();
00263
00268 RosterManager* rosterManager() { return m_rosterManager; }
00269
00273 void disconnect();
00274
00282 bool login();
00283
00284 protected:
00288 void nonSaslLogin();
00289
00290 private:
00297 class ResourceBind : public StanzaExtension
00298 {
00299
00300 public:
00307 ResourceBind( const std::string& resource, bool bind = true );
00308
00313 ResourceBind( const Tag* tag );
00314
00318 ~ResourceBind();
00319
00324 const std::string& resource() const { return m_resource; }
00325
00330 const JID& jid() const { return m_jid; }
00331
00337 bool unbind() const { return !m_bind; }
00338
00339
00340 virtual const std::string& filterString() const;
00341
00342
00343 virtual StanzaExtension* newInstance( const Tag* tag ) const
00344 {
00345 return new ResourceBind( tag );
00346 }
00347
00348
00349 virtual Tag* tag() const;
00350
00351
00352 virtual StanzaExtension* clone() const
00353 {
00354 return new ResourceBind( *this );
00355 }
00356
00357 private:
00358 std::string m_resource;
00359 JID m_jid;
00360 bool m_bind;
00361 };
00362
00369 class SessionCreation : public StanzaExtension
00370 {
00371
00372 public:
00376 SessionCreation() : StanzaExtension( ExtSessionCreation ) {}
00377
00381 ~SessionCreation() {}
00382
00383
00384 virtual const std::string& filterString() const { return EmptyString; }
00385
00386
00387 virtual StanzaExtension* newInstance( const Tag* tag ) const
00388 { (void)tag; return 0; }
00389
00390
00391 virtual Tag* tag() const;
00392
00393
00394 virtual StanzaExtension* clone() const
00395 { return 0; }
00396
00397 };
00398
00399 virtual void handleStartNode() {}
00400 virtual bool handleNormalNode( Tag* tag );
00401 virtual void disconnect( ConnectionError reason );
00402 virtual void handleIqIDForward( const IQ& iq, int context );
00403
00404 int getStreamFeatures( Tag* tag );
00405 int getSaslMechs( Tag* tag );
00406 int getCompressionMethods( Tag* tag );
00407 void processResourceBind( const IQ& iq );
00408 void processCreateSession( const IQ& iq );
00409 void sendPresence( Presence& pres );
00410 void createSession();
00411 void negotiateCompression( StreamFeature method );
00412 void connected();
00413 virtual void rosterFilled();
00414 virtual void cleanup();
00415 bool bindOperation( const std::string& resource, bool bind );
00416
00417 void init();
00418
00419 enum TrackContext
00420 {
00421 CtxResourceBind = 1000,
00422 CtxResourceUnbind,
00423 CtxSessionEstablishment
00424 };
00425
00426 RosterManager* m_rosterManager;
00427 NonSaslAuth* m_auth;
00428
00429 Presence m_presence;
00430
00431 bool m_resourceBound;
00432 bool m_forceNonSasl;
00433 bool m_manageRoster;
00434
00435 int m_streamFeatures;
00436
00437 };
00438
00439 }
00440
00441 #endif // CLIENT_H__