gloox  1.0.9
jinglesession.h
1 /*
2  Copyright (c) 2007-2013 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 #ifndef JINGLESESSION_H__
15 #define JINGLESESSION_H__
16 
17 #include "stanzaextension.h"
18 #include "tag.h"
19 #include "iqhandler.h"
20 #include "jingleplugin.h"
21 
22 #include <string>
23 
24 namespace gloox
25 {
26 
27  class ClientBase;
28 
38  namespace Jingle
39  {
40 
41  class Description;
42  class Transport;
43  class SessionHandler;
44  class Content;
45 
49  enum Action
50  {
67  };
68 
80  class GLOOX_API Session : public IqHandler
81  {
82 
83  friend class SessionManager;
84 
85  public:
89  enum State
90  {
93  Active
94  };
95 
104  class GLOOX_API Reason : public Plugin
105  {
106  public:
110  enum Reasons
111  {
129  InvalidReason
130  };
131 
138  Reason( Reasons reason, const std::string& sid = EmptyString,
139  const std::string& text = EmptyString );
140 
145  Reason( const Tag* tag = 0 );
146 
150  virtual ~Reason() {}
151 
156  Reasons reason() const { return m_reason; }
157 
163  const std::string& sid() const { return m_sid; }
164 
170  const std::string& text() const { return m_text; }
171 
172  // reimplemented from Plugin
173  virtual const std::string& filterString() const;
174 
175  // reimplemented from Plugin
176  virtual Tag* tag() const;
177 
178  // reimplemented from Plugin
179  virtual Plugin* newInstance( const Tag* tag ) const { return new Reason( tag ); }
180 
181  // reimplemented from Plugin
182  virtual Plugin* clone() const;
183 
184  private:
185  Reasons m_reason;
186  std::string m_sid;
187  std::string m_text;
188 
189  };
190 
198  class Jingle : public StanzaExtension
199  {
200 
201  friend class Session;
202 
203  public:
208  Jingle( const Tag* tag = 0 );
209 
213  virtual ~Jingle();
214 
219  const std::string& sid() const { return m_sid; }
220 
225  void setInitiator( const JID& jid ) { m_initiator = jid; }
226 
231  const JID& initiator() const { return m_initiator; }
232 
237  void setResponder( const JID& jid ) { m_responder = jid; }
238 
243  Action action() const { return m_action; }
244 
249  void addPlugin( const Plugin* plugin ) { if( plugin ) m_plugins.push_back( plugin ); }
250 
255  const PluginList& plugins() const { return m_plugins; }
256 
261  Tag* embeddedTag() const { return m_tag; }
262 
263  // reimplemented from StanzaExtension
264  virtual const std::string& filterString() const;
265 
266  // reimplemented from StanzaExtension
267  virtual StanzaExtension* newInstance( const Tag* tag ) const
268  {
269  return new Jingle( tag );
270  }
271 
272  // reimplemented from StanzaExtension
273  virtual Tag* tag() const;
274 
275  // reimplemented from StanzaExtension
276  virtual StanzaExtension* clone() const;
277 
278 #ifdef JINGLE_TEST
279  public:
280 #else
281  private:
282 #endif
283 
291  Jingle( Action action, const JID& initiator,
292  const PluginList& plugins, const std::string& sid );
293 
302  Jingle( Action action, const JID& initiator,
303  const Plugin* plugin, const std::string& sid );
304 
305 // /**
306 // * Copy constructor.
307 // * @param right The instance to copy.
308 // */
309 // Jingle( const Jingle& right );
310 
311  Action m_action;
312  std::string m_sid;
313  JID m_initiator;
314  JID m_responder;
315  PluginList m_plugins;
316  Tag* m_tag;
317 
318  };
319 
323  virtual ~Session();
324 
330  bool contentAccept( const Content* content );
331 
337  bool contentAdd( const Content* content );
338 
344  bool contentAdd( const PluginList& contents );
345 
351  bool contentModify( const Content* content );
352 
358  bool contentReject( const Content* content );
359 
365  bool contentRemove( const Content* content );
366 
372  bool descriptionInfo( const Plugin* info );
373 
379  bool securityInfo( const Plugin* info );
380 
387  bool sessionAccept( const Content* content );
388 
394  bool sessionInfo( const Plugin* info );
395 
401  bool sessionInitiate( const Content* content );
402 
410  bool sessionInitiate( const PluginList& plugins );
411 
418  bool sessionTerminate( Session::Reason* reason );
419 
425  bool transportAccept( const Content* content );
426 
432  bool transportInfo( const Plugin* info );
433 
439  bool transportReject( const Content* content );
440 
446  bool transportReplace( const Content* content );
447 
452  State state() const { return m_state; }
453 
458  void setSID( const std::string& sid ) { m_sid = sid; }
459 
464  const std::string& sid() const { return m_sid; }
465 
466  // reimplemented from IqHandler
467  virtual bool handleIq( const IQ& iq );
468 
469  // reimplemented from IqHandler
470  virtual void handleIqID( const IQ& iq, int context );
471 
472 #ifdef JINGLE_TEST
473  public:
474 #else
475  private:
476 #endif
477 
483  Session( ClientBase* parent, const JID& callee, SessionHandler* jsh );
484 
492  Session( ClientBase* parent, const Session::Jingle* jingle,
493  SessionHandler* jsh );
494 
495  bool doAction( Action action, const Plugin* plugin );
496  bool doAction( Action action, const PluginList& plugin );
497 
498  ClientBase* m_parent;
499  State m_state;
500  JID m_callee;
501  JID m_initiator;
502  SessionHandler* m_handler;
503  std::string m_sid;
504  bool m_valid;
505 
506  };
507 
508  }
509 
510 }
511 
512 #endif // JINGLESESSION_H__