14 #include "jinglesession.h"
16 #include "clientbase.h"
18 #include "jinglecontent.h"
19 #include "jingledescription.h"
20 #include "jingledtmf.h"
21 #include "jingletransport.h"
22 #include "jinglesessionhandler.h"
32 static const char* actionValues [] = {
49 static inline Action actionType(
const std::string& type )
51 return (
Action)util::lookup( type, actionValues );
55 static const char* reasonValues [] = {
56 "alternative-session",
68 "unsupported-applications",
69 "unsupported-transports"
78 const std::string& sid,
79 const std::string& text)
80 : m_reason( reason ), m_sid( sid ), m_text( text )
86 if( !tag || tag->
name() !=
"reason" )
90 TagList::const_iterator it = l.begin();
91 for( ; it != l.end(); ++it )
93 if( (*it)->name() ==
"text" )
94 m_text = (*it)->cdata();
96 m_reason = reasonType( (*it)->name() );
102 static const std::string filter =
"reason";
108 if( m_reason == InvalidReason )
111 Tag* t =
new Tag(
"reason" );
112 Tag* r =
new Tag( t, util::lookup( m_reason, reasonValues ) );
113 if( m_reason == AlternativeSession && !m_sid.empty() )
114 new Tag( r,
"sid", m_sid );
116 if( !m_text.empty() )
117 new Tag( t,
"text", m_text );
124 return new Reason( *
this );
129 Session::Jingle::Jingle(
Action action,
const JID& initiator,
132 m_initiator( initiator ), m_plugins( plugins )
136 Session::Jingle::Jingle(
Action action,
const JID& initiator,
137 const Plugin* plugin,
const std::string&
sid )
139 m_initiator( initiator )
142 m_plugins.push_back( plugin );
145 Session::Jingle::Jingle(
const Tag* tag )
148 if( !tag || tag->
name() !=
"jingle" )
157 TagList::const_iterator it = l.begin();
158 for( ; it != l.end(); ++it )
160 const std::string& name = (*it)->name();
161 if( name ==
"content" )
162 m_plugins.push_back(
new Content( (*it) ) );
164 m_plugins.push_back(
new DTMF( (*it) ) );
168 Session::Jingle::Jingle(
const Jingle& right )
170 m_sid( right.m_sid ), m_initiator( right.m_initiator ),
171 m_responder( right.m_responder )
173 PluginList::const_iterator it = right.m_plugins.begin();
174 for( ; it != right.m_plugins.end(); ++it )
175 m_plugins.push_back( (*it)->clone() );
178 Session::Jingle::~Jingle()
183 const std::string& Session::Jingle::filterString()
const
185 static const std::string filter =
"/iq/jingle[@xmlns='" +
XMLNS_JINGLE +
"']";
189 Tag* Session::Jingle::tag()
const
191 if( m_action ==
InvalidAction || m_sid.empty() || !m_initiator )
194 Tag* t =
new Tag(
"jingle" );
196 t->
addAttribute(
"action", util::lookup( m_action, actionValues ) );
202 PluginList::const_iterator it = m_plugins.begin();
203 for( ; it != m_plugins.end(); ++it )
211 return new Jingle( *
this );
217 : m_parent( parent ), m_state(
Ended ), m_callee( callee ),
218 m_handler( jsh ), m_valid( false )
220 if( !m_parent || !m_handler || !m_callee )
223 m_initiator = m_parent->
jid();
231 : m_parent( parent ), m_state( Ended ), m_handler( jsh ), m_valid( false )
233 if( !m_parent || !m_handler || !jingle || jingle->action() !=
SessionInitiate )
236 m_callee = m_parent->
jid();
239 m_sid = jingle->
sid();
252 if( !m_valid || !m_parent || !plugins.empty() || !m_initiator
266 if( !m_valid || !m_parent || !content || !m_initiator
280 if( !m_valid || !m_parent || m_state <
Pending || !m_initiator
287 m_parent->
send( init,
this, action );
294 if( !m_valid || !m_parent || m_state <
Pending || !m_initiator )
309 if( !j || j->sid() != m_sid || !m_handler )
312 switch( j->action() )
329 m_handler->handleSessionStateChange(
this, j );
331 m_parent->
send( re );
336 m_handler->handleSessionInfo(
this, j );
338 m_parent->
send( re );
344 Tag* e =
new Tag(
"unknown-session" );
347 m_parent->
send( re );
353 m_handler->handleSessionStateChange(
this, j );
355 m_parent->
send( re );
362 m_handler->handleTransportInfo(
this, j );
364 m_parent->
send( re );