gloox  1.0.20
jinglesession.h
1 /*
2  Copyright (c) 2007-2017 by Jakob Schröter <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  const JID& initiator() const { return m_initiator; }
226 
231  const JID& responder() const { return m_responder; }
232 
237  Action action() const { return m_action; }
238 
243  void addPlugin( const Plugin* plugin ) { if( plugin ) m_plugins.push_back( plugin ); }
244 
249  const PluginList& plugins() const { return m_plugins; }
250 
255  Tag* embeddedTag() const { return m_tag; }
256 
257  // reimplemented from StanzaExtension
258  virtual const std::string& filterString() const;
259 
260  // reimplemented from StanzaExtension
261  virtual StanzaExtension* newInstance( const Tag* tag ) const
262  {
263  return new Jingle( tag );
264  }
265 
266  // reimplemented from StanzaExtension
267  virtual Tag* tag() const;
268 
269  // reimplemented from StanzaExtension
270  virtual StanzaExtension* clone() const;
271 
272 #ifdef JINGLE_TEST
273  public:
274 #else
275  private:
276 #endif
277 
287  Jingle( Action action, const JID& initiator, const JID& responder,
288  const PluginList& plugins, const std::string& sid );
289 
290 #ifdef JINGLE_TEST
291 
301  Jingle( Action action, const JID& initiator, const JID& responder,
302  const Plugin* plugin, const std::string& sid );
303  #endif
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  void setInitiator( const JID& initiator ) { m_initiator = initiator; }
331 
336  const JID& initiator() const { return m_initiator; }
337 
343  const JID& responder() const { return m_responder; }
344 
352  void setResponder( const JID& jid ) { m_responder = jid; }
353 
358  void setHandler( SessionHandler* handler ) { m_handler = handler; }
359 
366  bool contentAccept( const Content* content );
367 
374  bool contentAdd( const Content* content );
375 
382  bool contentAdd( const PluginList& contents );
383 
390  bool contentModify( const Content* content );
391 
398  bool contentReject( const Content* content );
399 
406  bool contentRemove( const Content* content );
407 
414  bool descriptionInfo( const Plugin* info );
415 
422  bool securityInfo( const Plugin* info );
423 
431  bool sessionAccept( const Content* content );
432 
439  bool sessionAccept( const PluginList& plugins );
440 
447  bool sessionInfo( const Plugin* info );
448 
455  bool sessionInitiate( const Content* content );
456 
465  bool sessionInitiate( const PluginList& plugins );
466 
474  bool sessionTerminate( Session::Reason* reason );
475 
482  bool transportAccept( const Content* content );
483 
490  bool transportInfo( const Plugin* info );
491 
498  bool transportReject( const Content* content );
499 
506  bool transportReplace( const Content* content );
507 
512  State state() const { return m_state; }
513 
519  void setSID( const std::string& sid ) { m_sid = sid; }
520 
525  const std::string& sid() const { return m_sid; }
526 
527  // reimplemented from IqHandler
528  virtual bool handleIq( const IQ& iq );
529 
530  // reimplemented from IqHandler
531  virtual void handleIqID( const IQ& iq, int context );
532 
533 #ifdef JINGLE_TEST
534  public:
535 #else
536  private:
537 #endif
538 
544  Session( ClientBase* parent, const JID& callee, SessionHandler* jsh );
545 
554  Session( ClientBase* parent, const JID& callee, const Session::Jingle* jingle,
555  SessionHandler* jsh );
556 
557  bool doAction( Action action, const Plugin* plugin );
558  bool doAction( Action action, const PluginList& plugin );
559 
560  ClientBase* m_parent;
561  State m_state;
562  JID m_remote;
563  JID m_initiator;
564  JID m_responder;
565  SessionHandler* m_handler;
566  std::string m_sid;
567  bool m_valid;
568 
569  };
570 
571  }
572 
573 }
574 
575 #endif // JINGLESESSION_H__
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.)
Definition: jingleplugin.h:67
const std::string & text() const
An abstraction of an IQ stanza.
Definition: iq.h:33
virtual StanzaExtension * newInstance(const Tag *tag) const
const JID & responder() const
void setResponder(const JID &jid)
void addPlugin(const Plugin *plugin)
An abstraction of a Jingle (XEP-0166) session terminate reason.
const JID & responder() const
const std::string & sid() const
const std::string & sid() const
This is an implementation of a Jingle Session (XEP-0166).
Definition: jinglesession.h:80
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
void setHandler(SessionHandler *handler)
void setSID(const std::string &sid)
An abstraction of a JID.
Definition: jid.h:30
A Jingle session handler.
This is an abstraction of Jingle&#39;s (XEP-0166) <jingle> element as a StanzaExtension.
const PluginList & plugins() const
virtual Plugin * newInstance(const Tag *tag) const
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:31
const JID & initiator() const
The SessionManager is responsible for creating and destroying Jingle sessions, as well as for delegat...
const std::string & sid() const
const JID & initiator() const
void setInitiator(const JID &initiator)
std::list< const Plugin * > PluginList
Definition: jingleplugin.h:52
const std::string EmptyString
Definition: gloox.cpp:124
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:76
This is an abstraction of an XML element.
Definition: tag.h:46
An abstraction of a Jingle Content Type. This is part of Jingle (XEP-0166).
Definition: jinglecontent.h:41