client.h
/*
Copyright (c) 2004-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef CLIENT_H__
#define CLIENT_H__
#include "clientbase.h"
#include "presence.h"
#include <string>
namespace gloox
{
class Capabilities;
class RosterManager;
class NonSaslAuth;
class IQ;
class GLOOX_API Client : public ClientBase
{
public:
friend class NonSaslAuth;
friend class Parser;
Client( const std::string& server );
Client( const JID& jid, const std::string& password, int port = -1 );
virtual ~Client();
bool bindResource( const std::string& resource )
{ return bindOperation( resource, true ); }
bool selectResource( const std::string& resource );
bool hasResourceBind() const { return ((m_streamFeatures & StreamFeatureUnbind) == StreamFeatureUnbind); }
bool unbindResource( const std::string& resource )
{ return bindOperation( resource, false ); }
const std::string& resource() const { return m_jid.resource(); }
void setStreamManagement( bool enable = true, bool resume = true );
void ackStreamManagement();
void reqStreamManagement();
int priority() const { return m_presence.priority(); }
void setUsername( const std::string &username );
void setResource( const std::string &resource ) { m_jid.setResource( resource ); }
void setPresence( const JID& to, Presence::PresenceType pres, int priority,
const std::string& status = EmptyString );
void setPresence( Presence::PresenceType pres, int priority,
const std::string& status = EmptyString );
void setPresence() { sendPresence( m_presence ); }
void setActive() { if( hasClientStateIndication() )
send( new Tag( "active", XMLNS, XMLNS_CLIENT_STATE_INDICATION ) ); }
void setInactive() { if( hasClientStateIndication() )
send( new Tag( "inactive", XMLNS, XMLNS_CLIENT_STATE_INDICATION ) ); }
bool hasClientStateIndication() const {
return ((m_streamFeatures & StreamFeatureClientStateIndication) == StreamFeatureClientStateIndication); }
Presence& presence() { return m_presence; }
GLOOX_DEPRECATED void setForceNonSasl( bool force = true ) { m_forceNonSasl = force; }
void disableRoster();
RosterManager* rosterManager() { return m_rosterManager; }
void disconnect();
bool login();
protected:
void nonSaslLogin();
private:
#ifdef CLIENT_TEST
public:
#endif
class ResourceBind : public StanzaExtension
{
public:
ResourceBind( const std::string& resource, bool bind = true );
ResourceBind( const Tag* tag );
~ResourceBind();
const std::string& resource() const { return m_resource; }
const JID& jid() const { return m_jid; }
bool unbind() const { return !m_bind; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new ResourceBind( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
return new ResourceBind( *this );
}
private:
std::string m_resource;
JID m_jid;
bool m_bind;
};
class SessionCreation : public StanzaExtension
{
public:
SessionCreation() : StanzaExtension( ExtSessionCreation ) {}
~SessionCreation() {}
// reimplemented from StanzaExtension
virtual const std::string& filterString() const { return EmptyString; }
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{ (void)tag; return 0; }
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{ return 0; }
};
virtual void handleStartNode( const Tag* /*start*/ ) {}
virtual bool handleNormalNode( Tag* tag );
virtual void disconnect( ConnectionError reason );
virtual void handleIqIDForward( const IQ& iq, int context );
int getStreamFeatures( Tag* tag );
int getSaslMechs( Tag* tag );
int getCompressionMethods( Tag* tag );
void processResourceBind( const IQ& iq );
void processCreateSession( const IQ& iq );
void sendPresence( Presence& pres );
void createSession();
void negotiateCompression( StreamFeature method );
void connected();
virtual void rosterFilled();
virtual void cleanup();
bool bindOperation( const std::string& resource, bool bind );
void sendStreamManagement();
void init();
enum TrackContext
{
CtxResourceBind = 1000, // must be higher than the last element in ClientBase's TrackContext
CtxResourceUnbind,
CtxSessionEstablishment
};
RosterManager* m_rosterManager;
NonSaslAuth* m_auth;
Presence m_presence;
bool m_forceNonSasl;
bool m_manageRoster;
std::string m_smId;
std::string m_smLocation;
bool m_smResume;
bool m_smWanted;
int m_smMax;
int m_streamFeatures;
};
}
#endif // CLIENT_H__
gloox::Capabilities
This is an implementation of XEP-0115 (Entity Capabilities).
Definition capabilities.h:37
gloox::ClientBase::port
int port() const
Definition clientbase.h:221
gloox::ClientBase::server
const std::string & server() const
Definition clientbase.h:196
gloox::ClientBase::m_jid
JID m_jid
Definition clientbase.h:868
gloox::ClientBase::password
virtual const std::string & password() const
Definition clientbase.h:227
gloox::ClientBase::ClientBase
ClientBase(const std::string &ns, const std::string &server, int port=-1)
Definition clientbase.cpp:94
gloox::ClientBase::send
void send(Tag *tag)
Definition clientbase.cpp:1004
gloox::ClientBase::jid
const JID & jid()
Definition clientbase.h:147
gloox::Client::presence
Presence & presence()
Definition client.h:328
gloox::Client::Client
Client(const std::string &server)
Definition client.cpp:103
gloox::Client::setForceNonSasl
GLOOX_DEPRECATED void setForceNonSasl(bool force=true)
Definition client.h:335
gloox::Client::setActive
void setActive()
Definition client.h:302
gloox::Client::priority
int priority() const
Definition client.h:239
gloox::Client::setInactive
void setInactive()
Definition client.h:312
gloox::Client::bindResource
bool bindResource(const std::string &resource)
Definition client.h:163
gloox::Client::unbindResource
bool unbindResource(const std::string &resource)
Definition client.h:193
gloox::Client::resource
const std::string & resource() const
Definition client.h:200
gloox::Client::rosterManager
RosterManager * rosterManager()
Definition client.h:348
gloox::Client::setPresence
void setPresence()
Definition client.h:293
gloox::Client::setResource
void setResource(const std::string &resource)
Definition client.h:251
gloox::Client::hasClientStateIndication
bool hasClientStateIndication() const
Definition client.h:321
gloox::Client::hasResourceBind
bool hasResourceBind() const
Definition client.h:183
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::NonSaslAuth
This class is an implementation of XEP-0078 (Non-SASL Authentication).
Definition nonsaslauth.h:40
gloox::Presence
An abstraction of a presence stanza.
Definition presence.h:33
gloox::Presence::PresenceType
PresenceType
Definition presence.h:43
gloox::RosterManager
This class implements Jabber/XMPP roster handling in the jabber:iq:roster namespace.
Definition rostermanager.h:49
gloox::StanzaExtension
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
Definition stanzaextension.h:204
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StreamFeatureClientStateIndication
@ StreamFeatureClientStateIndication
Definition gloox.h:748
gloox::StreamFeatureUnbind
@ StreamFeatureUnbind
Definition gloox.h:736
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::XMLNS_CLIENT_STATE_INDICATION
const std::string XMLNS_CLIENT_STATE_INDICATION
Definition gloox.cpp:115
gloox::ExtSessionCreation
@ ExtSessionCreation
Definition stanzaextension.h:55