Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

jinglesession.cpp

00001 /*
00002   Copyright (c) 2007-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 #include "jinglesession.h"
00015 
00016 #include "clientbase.h"
00017 #include "jinglecontent.h"
00018 #include "jingledescription.h"
00019 #include "jingletransport.h"
00020 #include "jinglesessionhandler.h"
00021 #include "tag.h"
00022 #include "util.h"
00023 
00024 namespace gloox
00025 {
00026 
00027   namespace Jingle
00028   {
00029 
00030     static const char* actionValues [] = {
00031       "content-accept",
00032       "content-add",
00033       "content-modify",
00034       "content-remove",
00035       "content-replace",
00036       "session-accept",
00037       "session-info",
00038       "session-initiate",
00039       "session-terminate",
00040       "transport-info"
00041     };
00042 
00043     static inline Action actionType( const std::string& type )
00044     {
00045       return (Action)util::lookup( type, actionValues );
00046     }
00047 
00048     // ---- Session::Jingle ----
00049     Session::Jingle::Jingle( Action action, const ContentList& contents, const std::string& sid )
00050       : StanzaExtension( ExtJingle ), m_action( action ), m_sid( sid ), m_contents( contents )
00051     {
00052     }
00053 
00054     Session::Jingle::Jingle( Action action, const Content* content, const std::string& sid )
00055       : StanzaExtension( ExtJingle ), m_action( action ), m_sid( sid )
00056     {
00057       if( content )
00058         m_contents.push_back( content );
00059     }
00060 
00061     Session::Jingle::Jingle( const Tag* tag )
00062       : StanzaExtension( ExtJingle ), m_action( InvalidAction )
00063     {
00064     }
00065 
00066       Session::Jingle::~Jingle()
00067     {
00068     }
00069 
00070     const std::string& Session::Jingle::filterString() const
00071     {
00072       static const std::string filter = "/iq/jingle[@xmlns='" + XMLNS_JINGLE + "']";
00073       return filter;
00074     }
00075 
00076     Tag* Session::Jingle::tag() const
00077     {
00078       if( m_action == InvalidAction || m_sid.empty() || m_initiator.empty() )
00079         return 0;
00080 
00081       Tag* t = new Tag( "jingle" );
00082       t->setXmlns( XMLNS_JINGLE );
00083       t->addAttribute( "action", util::lookup( m_action, actionValues ) );
00084       t->addAttribute( "initiator", m_initiator );
00085       if( !m_responder.empty() )
00086         t->addAttribute( "responder", m_responder );
00087       t->addAttribute( "sid", m_sid );
00088 
00089       return t;
00090     }
00091     // ---- ~Session::Jingle ----
00092 
00093     // ---- Session ----
00094     Session::Session( ClientBase* parent, const JID& callee, SessionHandler* jsh )
00095       : m_parent( parent ), m_state( Ended ), m_handler( jsh ), m_valid( false )
00096     {
00097       if( !m_parent || !m_handler )
00098         return;
00099 
00100       m_parent->registerStanzaExtension( new Jingle() );
00101 
00102       m_valid = true;
00103     }
00104 
00105     Session::~Session()
00106     {
00107       if( m_parent )
00108         m_parent->removeIDHandler( this );
00109 
00110       util::clearList( m_contents );
00111     }
00112 
00113     bool Session::initiate()
00114     {
00115       if( !m_valid || !m_parent || !m_contents.empty() )
00116         return false;
00117 
00118       m_state = Pending;
00119       IQ init( IQ::Set, m_callee, m_parent->getID() );
00120       init.addExtension( new Jingle( SessionInitiate, m_contents, m_sid ) );
00121       m_parent->send( init, this, SessionInitiate );
00122 
00123       ContentList::const_iterator it = m_contents.begin();
00124       for( ; it != m_contents.end(); ++it )
00125       {
00126         IQ t( IQ::Set, m_callee, m_parent->getID() );
00127         t.addExtension( new Jingle( TransportInfo, (*it), m_sid ) );
00128         m_parent->send( t, this, TransportInfo );
00129       }
00130 
00131       return true;
00132     }
00133 
00134     bool Session::terminate()
00135     {
00136       if( !m_valid )
00137         return false;
00138 
00139       m_state = Ended;
00140 
00141       return true;
00142     }
00143 
00144     bool Session::handleIq( const IQ& iq )
00145     {
00146       const Jingle* j = iq.findExtension<Jingle>( ExtJingle );
00147       if( !j || j->sid() != m_sid )
00148         return false;
00149 
00150       switch( j->action() )
00151       {
00152         default:
00153           break;
00154       }
00155 
00156       return true;
00157     }
00158 
00159     void Session::handleIqID( const IQ& iq, int context )
00160     {
00161       if( iq.subtype() == IQ::Result )
00162       {
00163         switch( context )
00164         {
00165           default:
00166             break;
00167         }
00168       }
00169       else if( iq.subtype() == IQ::Error )
00170       {
00171       }
00172     }
00173 
00174   }
00175 
00176 }

Generated on Sun Dec 28 22:10:16 2008 for gloox by  doxygen 1.4.1