Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

client.h

00001 /*
00002   Copyright (c) 2004-2008 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 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; }
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_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 
00275     protected:
00279       void nonSaslLogin();
00280 
00281     private:
00288       class ResourceBind : public StanzaExtension
00289       {
00290 
00291         public:
00298           ResourceBind( const std::string& resource, bool bind = true );
00299 
00304           ResourceBind( const Tag* tag );
00305 
00309           ~ResourceBind();
00310 
00315           const std::string& resource() const { return m_resource; }
00316 
00321           const JID& jid() const { return m_jid; }
00322 
00328           bool unbind() const { return !m_bind; }
00329 
00330           // reimplemented from StanzaExtension
00331           virtual const std::string& filterString() const;
00332 
00333          // reimplemented from StanzaExtension
00334           virtual StanzaExtension* newInstance( const Tag* tag ) const
00335           {
00336             return new ResourceBind( tag );
00337           }
00338 
00339           // reimplemented from StanzaExtension
00340           virtual Tag* tag() const;
00341 
00342         private:
00343           std::string m_resource;
00344           JID m_jid;
00345           bool m_bind;
00346       };
00347 
00354       class SessionCreation : public StanzaExtension
00355       {
00356 
00357         public:
00361           SessionCreation() : StanzaExtension( ExtSessionCreation ) {}
00362 
00366           ~SessionCreation() {}
00367 
00368           // reimplemented from StanzaExtension
00369           virtual const std::string& filterString() const { return EmptyString; }
00370 
00371           // reimplemented from StanzaExtension
00372           virtual StanzaExtension* newInstance( const Tag* tag ) const
00373             { (void)tag; return 0; }
00374 
00375           // reimplemented from StanzaExtension
00376           virtual Tag* tag() const;
00377 
00378       };
00379 
00380       virtual void handleStartNode() {}
00381       virtual bool handleNormalNode( Tag* tag );
00382       virtual void disconnect( ConnectionError reason );
00383       virtual void handleIqIDForward( const IQ& iq, int context );
00384 
00385       int getStreamFeatures( Tag* tag );
00386       int getSaslMechs( Tag* tag );
00387       int getCompressionMethods( Tag* tag );
00388       void processResourceBind( const IQ& iq );
00389       void processCreateSession( const IQ& iq );
00390       void sendPresence( const Presence& pres );
00391       void createSession();
00392       void negotiateCompression( StreamFeature method );
00393       void connected();
00394       virtual void rosterFilled();
00395       virtual void cleanup();
00396       bool bindOperation( const std::string& resource, bool bind );
00397 
00398       void init();
00399 
00400       enum TrackContext
00401       {
00402         CtxResourceBind = 1000,  // must be higher than the last element in ClientBase's TrackContext
00403         CtxResourceUnbind,
00404         CtxSessionEstablishment
00405       };
00406 
00407       RosterManager* m_rosterManager;
00408       NonSaslAuth* m_auth;
00409 
00410       Presence m_presence;
00411 
00412       bool m_resourceBound;
00413       bool m_forceNonSasl;
00414       bool m_manageRoster;
00415       bool m_doAuth;
00416 
00417       int m_streamFeatures;
00418       int m_priority;
00419 
00420   };
00421 
00422 }
00423 
00424 #endif // CLIENT_H__

Generated on Tue Apr 22 15:10:10 2008 for gloox by  doxygen 1.4.1