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

Generated on Wed Dec 20 18:25:28 2006 for gloox by  doxygen 1.5.1