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
00021 #include <iksemel.h>
00022
00023 #include <cstdlib>
00024
00025 namespace gloox
00026 {
00027
00028 Component::Component( const std::string& ns, const std::string& server,
00029 const std::string& component, const std::string& password, int port )
00030 : ClientBase( ns, password, server, port ),
00031 m_disco( 0 )
00032 {
00033 m_jid.setServer( component );
00034 m_disco = new Disco( this );
00035 m_disco->setVersion( "based on gloox", GLOOX_VERSION );
00036 m_disco->setIdentity( "component", "generic" );
00037 }
00038
00039 Component::~Component()
00040 {
00041 delete m_disco;
00042 }
00043
00044 void Component::handleStartNode()
00045 {
00046 if( m_sid.empty() )
00047 return;
00048
00049 const std::string data = m_sid + m_password;
00050 char *hash = (char*)calloc( 41, sizeof( char ) );
00051 iks_sha( data.c_str(), hash );
00052
00053 Tag *h = new Tag( "handshake", hash );
00054 send( h );
00055
00056 free( hash );
00057 }
00058
00059 bool Component::handleNormalNode( Stanza *stanza )
00060 {
00061 if( stanza->name() == "handshake" )
00062 notifyOnConnect();
00063 else
00064 return false;
00065
00066 return true;
00067 }
00068
00069 void Component::disconnect()
00070 {
00071 disconnect( ConnUserDisconnected );
00072 }
00073
00074 void Component::disconnect( ConnectionError reason )
00075 {
00076 ClientBase::disconnect( reason );
00077 }
00078 }