gloox  1.0.16
pubsubmanager.h
1 /*
2  Copyright (c) 2007-2015 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 #ifndef PUBSUBMANAGER_H__
14 #define PUBSUBMANAGER_H__
15 
16 #include "pubsub.h"
17 #include "dataform.h"
18 #include "iqhandler.h"
19 #include "mutex.h"
20 
21 #include <map>
22 #include <string>
23 
24 namespace gloox
25 {
26 
27  class ClientBase;
28 
29  namespace PubSub
30  {
31 
32  class ResultHandler;
33 
78  class GLOOX_API Manager : public IqHandler
79  {
80  public:
81 
86  Manager( ClientBase* parent );
87 
91  virtual ~Manager() {}
92 
108  const std::string subscribe( const JID& service, const std::string& node,
109  ResultHandler* handler, const JID& jid = JID(),
111  int depth = 1, const std::string& expire = EmptyString );
112 
130  const std::string subscribe( const JID& service, const std::string& node,
131  ResultHandler* handler, const JID& jid,
132  DataForm* options );
133 
147  const std::string unsubscribe( const JID& service,
148  const std::string& node,
149  const std::string& subid,
150  ResultHandler* handler,
151  const JID& jid = JID() );
152 
162  const std::string getSubscriptions( const JID& service,
163  ResultHandler* handler )
164  {
165  return getSubscriptionsOrAffiliations( service,
166  handler,
167  GetSubscriptionList );
168  }
169 
179  const std::string getAffiliations( const JID& service,
180  ResultHandler* handler )
181  {
182  return getSubscriptionsOrAffiliations( service,
183  handler,
184  GetAffiliationList );
185  }
186 
199  const std::string getSubscriptionOptions( const JID& service,
200  const JID& jid,
201  const std::string& node,
202  ResultHandler* handler,
203  const std::string& subid = EmptyString)
204  { return subscriptionOptions( GetSubscriptionOptions, service, jid, node, handler, 0, subid ); }
205 
219  const std::string setSubscriptionOptions( const JID& service,
220  const JID& jid,
221  const std::string& node,
222  DataForm* df,
223  ResultHandler* handler,
224  const std::string& subid = EmptyString )
225  { return subscriptionOptions( SetSubscriptionOptions, service, jid, node, handler, df, subid ); }
226 
236  void getAffiliations( const JID& service,
237  const std::string& node,
238  ResultHandler* handler );
239 
249  const std::string requestItems( const JID& service,
250  const std::string& node,
251  const std::string& subid,
252  int maxItems,
253  ResultHandler* handler);
254 
264  const std::string requestItems( const JID& service,
265  const std::string& node,
266  const std::string& subid,
267  const ItemList& items,
268  ResultHandler* handler);
269 
284  const std::string publishItem( const JID& service,
285  const std::string& node,
286  ItemList& items,
287  DataForm* options,
288  ResultHandler* handler );
289 
302  const std::string deleteItem( const JID& service,
303  const std::string& node,
304  const ItemList& items,
305  bool notify,
306  ResultHandler* handler );
307 
320  const std::string createNode( const JID& service,
321  const std::string& node,
322  DataForm* config,
323  ResultHandler* handler );
324 
335  const std::string deleteNode( const JID& service,
336  const std::string& node,
337  ResultHandler* handler );
338 
349  const std::string getDefaultNodeConfig( const JID& service,
350  NodeType type,
351  ResultHandler* handler );
352 
363  const std::string purgeNode( const JID& service,
364  const std::string& node,
365  ResultHandler* handler );
366 
377  const std::string getSubscribers( const JID& service,
378  const std::string& node,
379  ResultHandler* handler )
380  { return subscriberList( GetSubscriberList, service,
381  node, SubscriberList(),
382  handler ); }
383 
396  const std::string setSubscribers( const JID& service,
397  const std::string& node,
398  const SubscriberList& list,
399  ResultHandler* handler )
400  { return subscriberList( SetSubscriberList, service,
401  node, list, handler ); }
402 
413  const std::string getAffiliates( const JID& service,
414  const std::string& node,
415  ResultHandler* handler )
416  { return affiliateList( GetAffiliateList, service,
417  node, AffiliateList(),
418  handler ); }
419 
431  const std::string setAffiliates( const JID& service,
432  const std::string& node,
433  const AffiliateList& list,
434  ResultHandler* handler )
435  { return affiliateList( SetAffiliateList, service,
436  node, list, handler ); }
437 
448  const std::string getNodeConfig( const JID& service,
449  const std::string& node,
450  ResultHandler* handler )
451  { return nodeConfig( service, node, 0, handler ); }
452 
464  const std::string setNodeConfig( const JID& service,
465  const std::string& node,
466  DataForm* config,
467  ResultHandler* handler )
468  { return nodeConfig( service, node, config, handler ); }
469 
475  bool removeID( const std::string& id );
476 
477  // reimplemented from DiscoHandler
478  void handleDiscoInfoResult( IQ* iq, int context );
479 
480  // reimplemented from DiscoHandler
481  void handleDiscoItemsResult( IQ* iq, int context );
482 
483  // reimplemented from DiscoHandler
484  void handleDiscoError( IQ* iq, int context );
485 
486  // reimplemented from DiscoHandler
487  bool handleDiscoSet( IQ* ) { return 0; }
488 
489  // reimplemented from IqHandler.
490  virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
491 
492  // reimplemented from IqHandler.
493  virtual void handleIqID( const IQ& iq, int context );
494 
495  private:
496 #ifdef PUBSUBMANAGER_TEST
497  public:
498 #endif
499 
500  enum TrackContext
501  {
502  Subscription,
503  Unsubscription,
504  GetSubscriptionOptions,
505  SetSubscriptionOptions,
506  GetSubscriptionList,
507  GetSubscriberList,
508  SetSubscriberList,
509  GetAffiliationList,
510  GetAffiliateList,
511  SetAffiliateList,
512  GetNodeConfig,
513  SetNodeConfig,
514  DefaultNodeConfig,
515  GetItemList,
516  PublishItem,
517  DeleteItem,
518  CreateNode,
519  DeleteNode,
520  PurgeNodeItems,
521  NodeAssociation,
522  NodeDisassociation,
523  GetFeatureList,
524  DiscoServiceInfos,
525  DiscoNodeInfos,
526  DiscoNodeItems,
527  RequestItems,
528  InvalidContext
529  };
530 
531  class PubSubOwner : public StanzaExtension
532  {
533  public:
538  PubSubOwner( TrackContext context = InvalidContext );
539 
544  PubSubOwner( const Tag* tag );
545 
549  virtual ~PubSubOwner();
550 
555  void setNode( const std::string& node ) { m_node = node; }
556 
561  const std::string& node() const { return m_node; }
562 
567  void setConfig( DataForm* config )
568  { m_form = config; }
569 
574  const DataForm* config() const { return m_form; }
575 
580  void setSubscriberList( const SubscriberList& subList )
581  { m_subList = subList; }
582 
587  void setAffiliateList( const AffiliateList& affList )
588  { m_affList = affList; }
589 
594  const AffiliateList* affiliateList() const { return &m_affList; }
595 
596  // reimplemented from StanzaExtension
597  virtual const std::string& filterString() const;
598 
599  // reimplemented from StanzaExtension
600  virtual StanzaExtension* newInstance( const Tag* tag ) const
601  {
602  return new PubSubOwner( tag );
603  }
604 
605  // reimplemented from StanzaExtension
606  virtual Tag* tag() const;
607 
608  // reimplemented from StanzaExtension
609  virtual StanzaExtension* clone() const
610  {
611  PubSubOwner* p = new PubSubOwner();
612  p->m_node = m_node;
613  p->m_ctx = m_ctx;
614  p->m_form = m_form ? new DataForm( *m_form ) : 0;
615  p->m_subList = m_subList;
616  p->m_affList = m_affList;
617  return p;
618  }
619 
620  private:
621  std::string m_node;
622  TrackContext m_ctx;
623  DataForm* m_form;
624  SubscriberList m_subList;
625  AffiliateList m_affList;
626  };
627 
628  class PubSub : public StanzaExtension
629  {
630  public:
635  PubSub( TrackContext context = InvalidContext );
636 
641  PubSub( const Tag* tag );
642 
646  virtual ~PubSub();
647 
652  void setJID( const JID& jid ) { m_jid = jid; }
653 
658  const JID& jid() const { return m_jid; }
659 
664  void setNode( const std::string& node ) { m_node = node; }
665 
670  const std::string& node() const { return m_node; }
671 
676  void setSubscriptionID( const std::string& subid )
677  { m_subid = subid; }
678 
683  const std::string& subscriptionID() const { return m_subid; }
684 
691  void setOptions( const std::string& node, DataForm* df )
692  {
693  m_options.node = node;
694  if( m_options.df != 0 )
695  delete m_options.df;
696  m_options.df = df;
697  }
698 
703  const DataForm* options() const
704  { return m_options.df; }
705 
710  const ItemList& items() const { return m_items; }
711 
716  void setItems( const ItemList& items )
717  { m_items = items; }
718 
723  void setMaxItems( int maxItems )
724  { m_maxItems = maxItems; }
725 
730  const SubscriptionMap& subscriptions() const
731  { return m_subscriptionMap; }
732 
737  const AffiliationMap& affiliations() const
738  { return m_affiliationMap; }
739 
744  void setNotify( bool notify ) { m_notify = notify; }
745 
746  // reimplemented from StanzaExtension
747  virtual const std::string& filterString() const;
748 
749  // reimplemented from StanzaExtension
750  virtual StanzaExtension* newInstance( const Tag* tag ) const
751  {
752  return new PubSub( tag );
753  }
754 
755  // reimplemented from StanzaExtension
756  virtual Tag* tag() const;
757 
758  // reimplemented from StanzaExtension
759  virtual StanzaExtension* clone() const;
760 
761  private:
762  AffiliationMap m_affiliationMap;
763  SubscriptionMap m_subscriptionMap;
764  TrackContext m_ctx;
765 
766  struct Options
767  {
768  std::string node;
769  DataForm* df;
770  };
771  Options m_options;
772  JID m_jid;
773  std::string m_node;
774  std::string m_subid;
775  ItemList m_items;
776  int m_maxItems;
777  bool m_notify;
778  };
779 
791  const std::string nodeConfig( const JID& service,
792  const std::string& node,
793  DataForm* config,
794  ResultHandler* handler );
795 
809  const std::string subscriberList( TrackContext ctx,
810  const JID& service,
811  const std::string& node,
812  const SubscriberList& config,
813  ResultHandler* handler );
814 
828  const std::string affiliateList( TrackContext ctx,
829  const JID& service,
830  const std::string& node,
831  const AffiliateList& config,
832  ResultHandler* handler );
833 
834  const std::string subscriptionOptions( TrackContext context,
835  const JID& service,
836  const JID& jid,
837  const std::string& node,
838  ResultHandler* handler,
839  DataForm* df,
840  const std::string& subid = EmptyString );
841 
842  const std::string getSubscriptionsOrAffiliations( const JID& service,
843  ResultHandler* handler,
844  TrackContext context );
845 
846  typedef std::map < std::string, std::string > NodeOperationTrackMap;
847  typedef std::map < std::string, ResultHandler* > ResultHandlerTrackMap;
848 
849  ClientBase* m_parent;
850 
851  NodeOperationTrackMap m_nopTrackMap;
852  ResultHandlerTrackMap m_resultHandlerTrackMap;
853 
854  util::Mutex m_trackMapMutex;
855 
856  };
857 
858  }
859 
860 }
861 
862 #endif // PUBSUBMANAGER_H__
const std::string getSubscriptions(const JID &service, ResultHandler *handler)
An abstraction of an IQ stanza.
Definition: iq.h:33
An abstraction of a XEP-0004 Data Form.
Definition: dataform.h:56
const std::string getSubscribers(const JID &service, const std::string &node, ResultHandler *handler)
This manager is used to interact with PubSub services (XEP-0060).
Definition: pubsubmanager.h:78
SubscriptionObject
Definition: pubsub.h:96
const std::string getAffiliates(const JID &service, const std::string &node, ResultHandler *handler)
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string setAffiliates(const JID &service, const std::string &node, const AffiliateList &list, ResultHandler *handler)
const std::string getAffiliations(const JID &service, ResultHandler *handler)
A virtual interface to receive item related requests results.
const std::string setSubscriptionOptions(const JID &service, const JID &jid, const std::string &node, DataForm *df, ResultHandler *handler, const std::string &subid=EmptyString)
An abstraction of a JID.
Definition: jid.h:30
const std::string getSubscriptionOptions(const JID &service, const JID &jid, const std::string &node, ResultHandler *handler, const std::string &subid=EmptyString)
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:31
const std::string setNodeConfig(const JID &service, const std::string &node, DataForm *config, ResultHandler *handler)
An abstraction of a subscription stanza.
Definition: subscription.h:31
const std::string setSubscribers(const JID &service, const std::string &node, const SubscriberList &list, ResultHandler *handler)
virtual bool handleIq(const IQ &iq)
const std::string getNodeConfig(const JID &service, const std::string &node, ResultHandler *handler)
const std::string EmptyString
Definition: gloox.cpp:123
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