gloox  0.9.9.12
component.cpp
1 /*
2  Copyright (c) 2005-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #include "component.h"
16 
17 #include "disco.h"
18 #include "stanza.h"
19 #include "prep.h"
20 #include "sha.h"
21 
22 #include <cstdlib>
23 
24 namespace gloox
25 {
26 
27  Component::Component( const std::string& ns, const std::string& server,
28  const std::string& component, const std::string& password, int port )
29  : ClientBase( ns, password, server, port )
30  {
31  m_jid.setServer( component );
32  m_disco->setIdentity( "component", "generic" );
33  }
34 
35  void Component::handleStartNode()
36  {
37  if( m_sid.empty() )
38  return;
39 
40  notifyStreamEvent( StreamEventAuthentication );
41 
42  SHA sha;
43  sha.feed( m_sid + m_password );
44  sha.finalize();
45 
46  Tag *h = new Tag( "handshake", sha.hex() );
47  send( h );
48  }
49 
50  bool Component::handleNormalNode( Stanza *stanza )
51  {
52  if( stanza->name() != "handshake" )
53  return false;
54 
55  notifyStreamEvent( StreamEventFinished );
56  notifyOnConnect();
57 
58  return true;
59  }
60 
61 }