component.cpp

00001 /*
00002   Copyright (c) 2005-2006 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
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 }

Generated on Tue May 1 14:20:20 2007 for gloox by  doxygen 1.5.1