component.cpp

00001 /*
00002   Copyright (c) 2005-2008 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 #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 }

Generated on Sun Apr 27 11:08:13 2008 for gloox by  doxygen 1.5.5