gloox  1.0.28
jinglesession.h
1 /*
2  Copyright (c) 2007-2023 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
287  Jingle( Action action, const JID& initiator, const JID& responder,
288  const PluginList& plugins, const std::string& sid );
289 
290 #ifdef JINGLE_TEST
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
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__
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:79
An abstraction of an IQ stanza.
Definition: iq.h:34
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:32
An abstraction of a JID.
Definition: jid.h:31
An abstraction of a Jingle Content Type. This is part of Jingle (XEP-0166).
Definition: jinglecontent.h:42
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.)
Definition: jingleplugin.h:68
A Jingle session handler.
The SessionManager is responsible for creating and destroying Jingle sessions, as well as for delegat...
This is an abstraction of Jingle's (XEP-0166) <jingle> element as a StanzaExtension.
const std::string & sid() const
virtual StanzaExtension * newInstance(const Tag *tag) const
void addPlugin(const Plugin *plugin)
const JID & responder() const
const PluginList & plugins() const
const JID & initiator() const
An abstraction of a Jingle (XEP-0166) session terminate reason.
const std::string & text() const
const std::string & sid() const
virtual Plugin * newInstance(const Tag *tag) const
This is an implementation of a Jingle Session (XEP-0166).
Definition: jinglesession.h:81
void setInitiator(const JID &initiator)
void setResponder(const JID &jid)
const std::string & sid() const
const JID & responder() const
void setHandler(SessionHandler *handler)
const JID & initiator() const
void setSID(const std::string &sid)
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
std::list< const Plugin * > PluginList
Definition: jingleplugin.h:52
The namespace for the gloox library.
Definition: adhoc.cpp:28
const std::string EmptyString
Definition: gloox.cpp:124