gloox 1.0.24
pubsubmanager.h
1/*
2 Copyright (c) 2007-2019 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
24namespace 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 {
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 TrackContext context() const { return m_ctx; }
677
682 void setSubscriptionID( const std::string& subid )
683 { m_subid = subid; }
684
689 const std::string& subscriptionID() const { return m_subid; }
690
697 void setOptions( const std::string& node, DataForm* df )
698 {
699 m_options.node = node;
700 if( m_options.df != 0 )
701 delete m_options.df;
702 m_options.df = df;
703 }
704
709 const DataForm* options() const
710 { return m_options.df; }
711
716 const ItemList& items() const { return m_items; }
717
722 void setItems( const ItemList& items )
723 { m_items = items; }
724
729 void setMaxItems( int maxItems )
730 { m_maxItems = maxItems; }
731
736 const SubscriptionMap& subscriptions() const
737 { return m_subscriptionMap; }
738
743 const AffiliationMap& affiliations() const
744 { return m_affiliationMap; }
745
750 void setNotify( bool notify ) { m_notify = notify; }
751
752 // reimplemented from StanzaExtension
753 virtual const std::string& filterString() const;
754
755 // reimplemented from StanzaExtension
756 virtual StanzaExtension* newInstance( const Tag* tag ) const
757 {
758 return new PubSub( tag );
759 }
760
761 // reimplemented from StanzaExtension
762 virtual Tag* tag() const;
763
764 // reimplemented from StanzaExtension
765 virtual StanzaExtension* clone() const;
766
767 private:
768 AffiliationMap m_affiliationMap;
769 SubscriptionMap m_subscriptionMap;
770 TrackContext m_ctx;
771
772 struct Options
773 {
774 std::string node;
775 DataForm* df;
776 };
777 Options m_options;
778 JID m_jid;
779 std::string m_node;
780 std::string m_subid;
781 ItemList m_items;
782 int m_maxItems;
783 bool m_notify;
784 };
785
797 const std::string nodeConfig( const JID& service,
798 const std::string& node,
799 DataForm* config,
800 ResultHandler* handler );
801
815 const std::string subscriberList( TrackContext ctx,
816 const JID& service,
817 const std::string& node,
818 const SubscriberList& config,
819 ResultHandler* handler );
820
834 const std::string affiliateList( TrackContext ctx,
835 const JID& service,
836 const std::string& node,
837 const AffiliateList& config,
838 ResultHandler* handler );
839
840 const std::string subscriptionOptions( TrackContext context,
841 const JID& service,
842 const JID& jid,
843 const std::string& node,
844 ResultHandler* handler,
845 DataForm* df,
846 const std::string& subid = EmptyString );
847
848 const std::string getSubscriptionsOrAffiliations( const JID& service,
849 ResultHandler* handler,
850 TrackContext context );
851
852 typedef std::map < std::string, std::string > NodeOperationTrackMap;
853 typedef std::map < std::string, ResultHandler* > ResultHandlerTrackMap;
854
855 ClientBase* m_parent;
856
857 NodeOperationTrackMap m_nopTrackMap;
858 ResultHandlerTrackMap m_resultHandlerTrackMap;
859
860 util::Mutex m_trackMapMutex;
861
862 };
863
864 }
865
866}
867
868#endif // PUBSUBMANAGER_H__
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:79
An abstraction of a XEP-0004 Data Form.
Definition: dataform.h:57
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
This manager is used to interact with PubSub services (XEP-0060).
Definition: pubsubmanager.h:79
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 getSubscriptionOptions(const JID &service, const JID &jid, const std::string &node, ResultHandler *handler, const std::string &subid=EmptyString)
const std::string getAffiliates(const JID &service, const std::string &node, ResultHandler *handler)
const std::string getSubscriptions(const JID &service, ResultHandler *handler)
const std::string getSubscribers(const JID &service, const std::string &node, ResultHandler *handler)
const std::string setSubscriptionOptions(const JID &service, const JID &jid, const std::string &node, DataForm *df, ResultHandler *handler, const std::string &subid=EmptyString)
const std::string setNodeConfig(const JID &service, const std::string &node, DataForm *config, ResultHandler *handler)
const std::string getAffiliations(const JID &service, ResultHandler *handler)
void getAffiliations(const JID &service, const std::string &node, ResultHandler *handler)
const std::string setAffiliates(const JID &service, const std::string &node, const AffiliateList &list, ResultHandler *handler)
const std::string getNodeConfig(const JID &service, const std::string &node, ResultHandler *handler)
A virtual interface to receive item related requests results.
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
An abstraction of a subscription stanza.
Definition: subscription.h:32
This is an abstraction of an XML element.
Definition: tag.h:47
SubscriptionObject
Definition: pubsub.h:97
@ SubscriptionNodes
Definition: pubsub.h:98
The namespace for the gloox library.
Definition: adhoc.cpp:28
const std::string EmptyString
Definition: gloox.cpp:124