14 #include "jinglesession.h"
16 #include "clientbase.h"
18 #include "jinglecontent.h"
19 #include "jinglesessionhandler.h"
29 static const char* actionValues [] = {
47 static inline Action actionType(
const std::string& type )
49 return (
Action)util::lookup( type, actionValues );
53 static const char* reasonValues [] = {
54 "alternative-session",
64 "incompatible-parameters",
69 "unsupported-applications",
70 "unsupported-transports"
79 const std::string& sid,
80 const std::string& text)
81 : m_reason( reason ), m_sid( sid ), m_text( text )
87 if( !tag || tag->
name() !=
"reason" )
91 TagList::const_iterator it = l.begin();
92 for( ; it != l.end(); ++it )
94 if( (*it)->name() ==
"text" )
95 m_text = (*it)->cdata();
97 m_reason = reasonType( (*it)->name() );
103 static const std::string filter =
"jingle/reason";
109 if( m_reason == InvalidReason )
112 Tag* t =
new Tag(
"reason" );
113 Tag* r =
new Tag( t, util::lookup( m_reason, reasonValues ) );
114 if( m_reason == AlternativeSession && !m_sid.empty() )
115 new Tag( r,
"sid", m_sid );
117 if( !m_text.empty() )
118 new Tag( t,
"text", m_text );
125 return new Reason( *
this );
130 Session::Jingle::Jingle(
Action action,
const JID& initiator,
133 m_initiator( initiator ), m_plugins( plugins ), m_tag( 0 )
137 Session::Jingle::Jingle(
Action action,
const JID& initiator,
138 const Plugin* plugin,
const std::string&
sid )
140 m_initiator( initiator ), m_tag( 0 )
143 m_plugins.push_back( plugin );
146 Session::Jingle::Jingle(
const Tag* tag )
149 if( !tag || tag->
name() !=
"jingle" )
166 m_tag = tag->
clone();
179 Session::Jingle::~Jingle()
184 const std::string& Session::Jingle::filterString()
const
186 static const std::string filter =
"/iq/jingle[@xmlns='" +
XMLNS_JINGLE +
"']";
190 Tag* Session::Jingle::tag()
const
195 Tag* t =
new Tag(
"jingle" );
197 t->
addAttribute(
"action", util::lookup( m_action, actionValues ) );
207 PluginList::const_iterator it = m_plugins.begin();
208 for( ; it != m_plugins.end(); ++it )
216 return new Jingle( *
this );
222 : m_parent( parent ), m_state(
Ended ), m_callee( callee ),
223 m_handler( jsh ), m_valid( false )
225 if( !m_parent || !m_handler || !m_callee )
228 m_initiator = m_parent->jid();
229 m_sid = m_parent->getID();
237 : m_parent( parent ), m_state(
Ended ), m_handler( jsh ), m_valid( false )
239 if( !m_parent || !m_handler )
243 m_callee = m_parent->jid();
246 m_sid = jingle->
sid();
323 if( !content || m_state >
Pending )
340 if( !content || !m_initiator || m_state >=
Pending )
349 if( plugins.empty() || !m_initiator || m_state >=
Pending )
398 bool Session::doAction(
Action action,
const Plugin* plugin )
401 pl.push_back( plugin );
402 return doAction( action, pl );
407 if( !m_valid || !m_parent )
411 init.
addExtension(
new Jingle( action, m_initiator, plugins, m_sid ) );
412 m_parent->
send( init,
this, action );
420 if( !j || j->sid() != m_sid || !m_handler )
423 switch( j->action() )
430 m_initiator = j->initiator();
442 m_parent->
send( re );