component.cpp
/*
Copyright (c) 2005-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.
*/
#include "component.h"
#include "disco.h"
#include "stanza.h"
#include "prep.h"
#include "sha.h"
#include <cstdlib>
namespace gloox
{
Component::Component( const std::string& ns, const std::string& server,
const std::string& component, const std::string& password, int port )
: ClientBase( ns, password, server, port )
{
m_jid.setServer( component );
m_disco->setIdentity( "component", "generic" );
}
void Component::handleStartNode( const Tag* /*start*/ )
{
if( m_sid.empty() )
return;
notifyStreamEvent( StreamEventAuthentication );
SHA sha;
sha.feed( m_sid + m_password );
sha.finalize();
Tag* h = new Tag( "handshake", sha.hex() );
send( h );
}
bool Component::handleNormalNode( Tag* tag )
{
if( tag->name() != "handshake" )
return false;
m_authed = true;
notifyStreamEvent( StreamEventFinished );
notifyOnConnect();
return true;
}
}
gloox::ClientBase::m_sid
std::string m_sid
Definition clientbase.h:890
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::notifyOnConnect
void notifyOnConnect()
Definition clientbase.cpp:1527
gloox::ClientBase::m_authed
bool m_authed
Definition clientbase.h:897
gloox::ClientBase::m_disco
Disco * m_disco
Definition clientbase.h:874
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::m_password
std::string m_password
Definition clientbase.h:886
gloox::ClientBase::send
void send(Tag *tag)
Definition clientbase.cpp:1004
gloox::ClientBase::notifyStreamEvent
void notifyStreamEvent(StreamEvent event)
Definition clientbase.cpp:1561
gloox::Component::Component
Component(const std::string &ns, const std::string &server, const std::string &component, const std::string &password, int port=5347)
Definition component.cpp:27
gloox::Component::handleNormalNode
virtual bool handleNormalNode(Tag *tag)
Definition component.cpp:50
gloox::Component::handleStartNode
virtual void handleStartNode(const Tag *start)
Definition component.cpp:35
gloox::SHA
An implementation of SHA1.
Definition sha.h:30
gloox::SHA::finalize
void finalize()
Definition sha.cpp:80
gloox::SHA::feed
void feed(const unsigned char *data, unsigned length)
Definition sha.cpp:89
gloox::SHA::hex
const std::string hex()
Definition sha.cpp:53
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::name
const std::string & name() const
Definition tag.h:394
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StreamEventAuthentication
@ StreamEventAuthentication
Definition gloox.h:657
gloox::StreamEventFinished
@ StreamEventFinished
Definition gloox.h:677