glooxd  0.3-svn
featuresession.cpp
1 /*
2  Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the glooxd library. http://camaya.net/glooxd
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 #include "featuresession.h"
14 #include "streambase.h"
15 
16 #include <gloox/gloox.h>
17 #include <gloox/iq.h>
18 
19 namespace glooxd
20 {
21 
23  : m_state( SessionCanceled )
24  {
25  }
26 
27  const std::string& FeatureSession::filterString() const
28  {
29  static const std::string filter = "/iq/session[@xmlns='" + gloox::XMLNS_STREAM_SESSION + "']";
30  return filter;
31  }
32 
33  gloox::Tag* FeatureSession::tag( int state, const std::string& /*domain*/ )
34  {
35  gloox::Tag* t = 0;
36 
37  if( ( state & StateAuthentication ) == StateAuthentication )
38  {
39  t = new gloox::Tag( "session" );
40  t->setXmlns( gloox::XMLNS_STREAM_SESSION );
41  m_state = SessionOffered;
42  }
43 
44  return t;
45  }
46 
47  void FeatureSession::handleTag( gloox::Tag* _tag )
48  {
49  if( !_tag )
50  return;
51 
52  if( m_state == SessionOffered )
53  {
54  m_state = SessionDone;
55  m_parent->finishStreamFeature( StateDone );
56  gloox::IQ re( gloox::IQ::Result, _tag->findAttribute( "from" ),
57  _tag->findAttribute( "id" ));
58  m_parent->send( re );
59  }
60  else
61  {
62  gloox::IQ re( gloox::IQ::Error, _tag->findAttribute( "from" ),
63  _tag->findAttribute( "id" ));
64  // FIXME add gloox::Error
65  m_parent->send( re );
66  }
67  }
68 
69 }