component.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "component.h"
00016
00017 #include "disco.h"
00018 #include "stanza.h"
00019 #include "prep.h"
00020 #include "sha.h"
00021
00022 #include <cstdlib>
00023
00024 namespace gloox
00025 {
00026
00027 Component::Component( const std::string& ns, const std::string& server,
00028 const std::string& component, const std::string& password, int port )
00029 : ClientBase( ns, password, server, port )
00030 {
00031 m_jid.setServer( component );
00032 m_disco->setIdentity( "component", "generic" );
00033 }
00034
00035 void Component::handleStartNode()
00036 {
00037 if( m_sid.empty() )
00038 return;
00039
00040 notifyStreamEvent( StreamEventAuthentication );
00041
00042 SHA sha;
00043 sha.feed( m_sid + m_password );
00044 sha.finalize();
00045
00046 Tag *h = new Tag( "handshake", sha.hex() );
00047 send( h );
00048 }
00049
00050 bool Component::handleNormalNode( Stanza *stanza )
00051 {
00052 if( stanza->name() != "handshake" )
00053 return false;
00054
00055 notifyStreamEvent( StreamEventFinished );
00056 notifyOnConnect();
00057
00058 return true;
00059 }
00060
00061 }