gloox 1.0.28
component.cpp
1/*
2 Copyright (c) 2005-2023 by Jakob Schröter <js@camaya.net>
3 This file is part of the gloox library. http://camaya.net/gloox
4
5 This software is distributed under a license. The full license
6 agreement can be found in the file LICENSE in this distribution.
7 This software may not be copied, modified, sold or distributed
8 other than expressed in the named license agreement.
9
10 This software is distributed without any warranty.
11*/
12
13
14
15#include "component.h"
16
17#include "disco.h"
18#include "stanza.h"
19#include "prep.h"
20#include "sha.h"
21
22#include <cstdlib>
23
24namespace gloox
25{
26
27 Component::Component( const std::string& ns, const std::string& server,
28 const std::string& component, const std::string& password, int port )
29 : ClientBase( ns, password, server, port )
30 {
31 m_jid.setServer( component );
32 m_disco->setIdentity( "component", "generic" );
33 }
34
35 void Component::handleStartNode( const Tag* /*start*/ )
36 {
37 if( m_sid.empty() )
38 return;
39
41
42 SHA sha;
43 sha.feed( m_sid + m_password );
44 sha.finalize();
45
46 Tag* h = new Tag( "handshake", sha.hex() );
47 send( h );
48 }
49
51 {
52 if( tag->name() != "handshake" )
53 return false;
54
55 m_authed = true;
58
59 return true;
60 }
61
62}
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
std::string m_sid
Definition clientbase.h:890
std::string m_password
Definition clientbase.h:886
void send(Tag *tag)
void notifyStreamEvent(StreamEvent event)
Component(const std::string &ns, const std::string &server, const std::string &component, const std::string &password, int port=5347)
Definition component.cpp:27
virtual bool handleNormalNode(Tag *tag)
Definition component.cpp:50
virtual void handleStartNode(const Tag *start)
Definition component.cpp:35
void setIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
Definition disco.cpp:474
bool setServer(const std::string &server)
Definition jid.cpp:56
An implementation of SHA1.
Definition sha.h:30
void finalize()
Definition sha.cpp:80
void feed(const unsigned char *data, unsigned length)
Definition sha.cpp:89
const std::string hex()
Definition sha.cpp:53
This is an abstraction of an XML element.
Definition tag.h:47
const std::string & name() const
Definition tag.h:394
The namespace for the gloox library.
Definition adhoc.cpp:28
@ StreamEventAuthentication
Definition gloox.h:657
@ StreamEventFinished
Definition gloox.h:677