pubsubmanager.h
/*
Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef PUBSUBMANAGER_H__
#define PUBSUBMANAGER_H__
#include "pubsub.h"
#include "dataform.h"
#include "iqhandler.h"
#include "mutex.h"
#include <map>
#include <string>
namespace gloox
{
class ClientBase;
namespace PubSub
{
class ResultHandler;
class GLOOX_API Manager : public IqHandler
{
public:
Manager( ClientBase* parent );
virtual ~Manager() {}
const std::string subscribe( const JID& service, const std::string& node,
ResultHandler* handler, const JID& jid = JID(),
SubscriptionObject type = SubscriptionNodes,
int depth = 1, const std::string& expire = EmptyString );
const std::string subscribe( const JID& service, const std::string& node,
ResultHandler* handler, const JID& jid,
DataForm* options );
const std::string unsubscribe( const JID& service,
const std::string& node,
const std::string& subid,
ResultHandler* handler,
const JID& jid = JID() );
const std::string getSubscriptions( const JID& service,
ResultHandler* handler )
{
return getSubscriptionsOrAffiliations( service,
handler,
GetSubscriptionList );
}
const std::string getAffiliations( const JID& service,
ResultHandler* handler )
{
return getSubscriptionsOrAffiliations( service,
handler,
GetAffiliationList );
}
const std::string getSubscriptionOptions( const JID& service,
const JID& jid,
const std::string& node,
ResultHandler* handler,
const std::string& subid = EmptyString)
{ return subscriptionOptions( GetSubscriptionOptions, service, jid, node, handler, 0, subid ); }
const std::string setSubscriptionOptions( const JID& service,
const JID& jid,
const std::string& node,
DataForm* df,
ResultHandler* handler,
const std::string& subid = EmptyString )
{ return subscriptionOptions( SetSubscriptionOptions, service, jid, node, handler, df, subid ); }
void getAffiliations( const JID& service,
const std::string& node,
ResultHandler* handler );
const std::string requestItems( const JID& service,
const std::string& node,
const std::string& subid,
int maxItems,
ResultHandler* handler);
const std::string requestItems( const JID& service,
const std::string& node,
const std::string& subid,
const ItemList& items,
ResultHandler* handler);
const std::string publishItem( const JID& service,
const std::string& node,
ItemList& items,
DataForm* options,
ResultHandler* handler );
const std::string deleteItem( const JID& service,
const std::string& node,
const ItemList& items,
bool notify,
ResultHandler* handler );
const std::string createNode( const JID& service,
const std::string& node,
DataForm* config,
ResultHandler* handler );
const std::string deleteNode( const JID& service,
const std::string& node,
ResultHandler* handler );
const std::string getDefaultNodeConfig( const JID& service,
NodeType type,
ResultHandler* handler );
const std::string purgeNode( const JID& service,
const std::string& node,
ResultHandler* handler );
const std::string getSubscribers( const JID& service,
const std::string& node,
ResultHandler* handler )
{ return subscriberList( GetSubscriberList, service,
node, SubscriberList(),
handler ); }
const std::string setSubscribers( const JID& service,
const std::string& node,
const SubscriberList& list,
ResultHandler* handler )
{ return subscriberList( SetSubscriberList, service,
node, list, handler ); }
const std::string getAffiliates( const JID& service,
const std::string& node,
ResultHandler* handler )
{ return affiliateList( GetAffiliateList, service,
node, AffiliateList(),
handler ); }
const std::string setAffiliates( const JID& service,
const std::string& node,
const AffiliateList& list,
ResultHandler* handler )
{ return affiliateList( SetAffiliateList, service,
node, list, handler ); }
const std::string getNodeConfig( const JID& service,
const std::string& node,
ResultHandler* handler )
{ return nodeConfig( service, node, 0, handler ); }
const std::string setNodeConfig( const JID& service,
const std::string& node,
DataForm* config,
ResultHandler* handler )
{ return nodeConfig( service, node, config, handler ); }
bool removeID( const std::string& id );
// reimplemented from DiscoHandler
void handleDiscoInfoResult( IQ* iq, int context );
// reimplemented from DiscoHandler
void handleDiscoItemsResult( IQ* iq, int context );
// reimplemented from DiscoHandler
void handleDiscoError( IQ* iq, int context );
// reimplemented from DiscoHandler
bool handleDiscoSet( IQ* ) { return 0; }
// reimplemented from IqHandler.
virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
// reimplemented from IqHandler.
virtual void handleIqID( const IQ& iq, int context );
private:
#ifdef PUBSUBMANAGER_TEST
public:
#endif
enum TrackContext
{
Subscription,
Unsubscription,
GetSubscriptionOptions,
SetSubscriptionOptions,
GetSubscriptionList,
GetSubscriberList,
SetSubscriberList,
GetAffiliationList,
GetAffiliateList,
SetAffiliateList,
GetNodeConfig,
SetNodeConfig,
DefaultNodeConfig,
GetItemList,
PublishItem,
DeleteItem,
CreateNode,
DeleteNode,
PurgeNodeItems,
NodeAssociation,
NodeDisassociation,
GetFeatureList,
DiscoServiceInfos,
DiscoNodeInfos,
DiscoNodeItems,
RequestItems,
InvalidContext
};
class PubSubOwner : public StanzaExtension
{
public:
PubSubOwner( TrackContext context = InvalidContext );
PubSubOwner( const Tag* tag );
virtual ~PubSubOwner();
void setNode( const std::string& node ) { m_node = node; }
const std::string& node() const { return m_node; }
void setConfig( DataForm* config )
{ m_form = config; }
const DataForm* config() const { return m_form; }
void setSubscriberList( const SubscriberList& subList )
{ m_subList = subList; }
void setAffiliateList( const AffiliateList& affList )
{ m_affList = affList; }
const AffiliateList* affiliateList() const { return &m_affList; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new PubSubOwner( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
PubSubOwner* p = new PubSubOwner();
p->m_node = m_node;
p->m_ctx = m_ctx;
p->m_form = m_form ? new DataForm( *m_form ) : 0;
p->m_subList = m_subList;
p->m_affList = m_affList;
return p;
}
private:
std::string m_node;
TrackContext m_ctx;
DataForm* m_form;
SubscriberList m_subList;
AffiliateList m_affList;
};
class PubSub : public StanzaExtension
{
public:
PubSub( TrackContext context = InvalidContext );
PubSub( const Tag* tag );
virtual ~PubSub();
void setJID( const JID& jid ) { m_jid = jid; }
const JID& jid() const { return m_jid; }
void setNode( const std::string& node ) { m_node = node; }
const std::string& node() const { return m_node; }
TrackContext context() const { return m_ctx; }
void setSubscriptionID( const std::string& subid )
{ m_subid = subid; }
const std::string& subscriptionID() const { return m_subid; }
void setOptions( const std::string& node, DataForm* df )
{
m_options.node = node;
if( m_options.df != 0 )
delete m_options.df;
m_options.df = df;
}
const DataForm* options() const
{ return m_options.df; }
const ItemList& items() const { return m_items; }
void setItems( const ItemList& items )
{ m_items = items; }
void setMaxItems( int maxItems )
{ m_maxItems = maxItems; }
const SubscriptionMap& subscriptions() const
{ return m_subscriptionMap; }
const AffiliationMap& affiliations() const
{ return m_affiliationMap; }
void setNotify( bool notify ) { m_notify = notify; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new PubSub( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const;
private:
AffiliationMap m_affiliationMap;
SubscriptionMap m_subscriptionMap;
TrackContext m_ctx;
struct Options
{
std::string node;
DataForm* df;
};
Options m_options;
JID m_jid;
std::string m_node;
std::string m_subid;
ItemList m_items;
int m_maxItems;
bool m_notify;
};
const std::string nodeConfig( const JID& service,
const std::string& node,
DataForm* config,
ResultHandler* handler );
const std::string subscriberList( TrackContext ctx,
const JID& service,
const std::string& node,
const SubscriberList& config,
ResultHandler* handler );
const std::string affiliateList( TrackContext ctx,
const JID& service,
const std::string& node,
const AffiliateList& config,
ResultHandler* handler );
const std::string subscriptionOptions( TrackContext context,
const JID& service,
const JID& jid,
const std::string& node,
ResultHandler* handler,
DataForm* df,
const std::string& subid = EmptyString );
const std::string getSubscriptionsOrAffiliations( const JID& service,
ResultHandler* handler,
TrackContext context );
typedef std::map < std::string, std::string > NodeOperationTrackMap;
typedef std::map < std::string, ResultHandler* > ResultHandlerTrackMap;
ClientBase* m_parent;
NodeOperationTrackMap m_nopTrackMap;
ResultHandlerTrackMap m_resultHandlerTrackMap;
util::Mutex m_trackMapMutex;
};
}
}
#endif // PUBSUBMANAGER_H__
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::DataForm
An abstraction of a XEP-0004 Data Form.
Definition dataform.h:57
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::IqHandler
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition iqhandler.h:32
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::PubSub::Manager::setSubscribers
const std::string setSubscribers(const JID &service, const std::string &node, const SubscriberList &list, ResultHandler *handler)
Definition pubsubmanager.h:396
gloox::PubSub::Manager::handleIq
virtual bool handleIq(const IQ &iq)
Definition pubsubmanager.h:490
gloox::PubSub::Manager::createNode
const std::string createNode(const JID &service, const std::string &node, DataForm *config, ResultHandler *handler)
Definition pubsubmanager.cpp:829
gloox::PubSub::Manager::getSubscriptionOptions
const std::string getSubscriptionOptions(const JID &service, const JID &jid, const std::string &node, ResultHandler *handler, const std::string &subid=EmptyString)
Definition pubsubmanager.h:199
gloox::PubSub::Manager::~Manager
virtual ~Manager()
Definition pubsubmanager.h:91
gloox::PubSub::Manager::requestItems
const std::string requestItems(const JID &service, const std::string &node, const std::string &subid, int maxItems, ResultHandler *handler)
Definition pubsubmanager.cpp:730
gloox::PubSub::Manager::deleteItem
const std::string deleteItem(const JID &service, const std::string &node, const ItemList &items, bool notify, ResultHandler *handler)
Definition pubsubmanager.cpp:805
gloox::PubSub::Manager::getAffiliates
const std::string getAffiliates(const JID &service, const std::string &node, ResultHandler *handler)
Definition pubsubmanager.h:413
gloox::PubSub::Manager::getSubscriptions
const std::string getSubscriptions(const JID &service, ResultHandler *handler)
Definition pubsubmanager.h:162
gloox::PubSub::Manager::getDefaultNodeConfig
const std::string getDefaultNodeConfig(const JID &service, NodeType type, ResultHandler *handler)
Definition pubsubmanager.cpp:874
gloox::PubSub::Manager::getSubscribers
const std::string getSubscribers(const JID &service, const std::string &node, ResultHandler *handler)
Definition pubsubmanager.h:377
gloox::PubSub::Manager::purgeNode
const std::string purgeNode(const JID &service, const std::string &node, ResultHandler *handler)
Definition pubsubmanager.cpp:972
gloox::PubSub::Manager::setSubscriptionOptions
const std::string setSubscriptionOptions(const JID &service, const JID &jid, const std::string &node, DataForm *df, ResultHandler *handler, const std::string &subid=EmptyString)
Definition pubsubmanager.h:219
gloox::PubSub::Manager::setNodeConfig
const std::string setNodeConfig(const JID &service, const std::string &node, DataForm *config, ResultHandler *handler)
Definition pubsubmanager.h:464
gloox::PubSub::Manager::Manager
Manager(ClientBase *parent)
Definition pubsubmanager.cpp:582
gloox::PubSub::Manager::getAffiliations
const std::string getAffiliations(const JID &service, ResultHandler *handler)
Definition pubsubmanager.h:179
gloox::PubSub::Manager::publishItem
const std::string publishItem(const JID &service, const std::string &node, ItemList &items, DataForm *options, ResultHandler *handler)
Definition pubsubmanager.cpp:778
gloox::PubSub::Manager::deleteNode
const std::string deleteNode(const JID &service, const std::string &node, ResultHandler *handler)
Definition pubsubmanager.cpp:853
gloox::PubSub::Manager::getAffiliations
void getAffiliations(const JID &service, const std::string &node, ResultHandler *handler)
gloox::PubSub::Manager::setAffiliates
const std::string setAffiliates(const JID &service, const std::string &node, const AffiliateList &list, ResultHandler *handler)
Definition pubsubmanager.h:431
gloox::PubSub::Manager::getNodeConfig
const std::string getNodeConfig(const JID &service, const std::string &node, ResultHandler *handler)
Definition pubsubmanager.h:448
gloox::PubSub::ResultHandler
A virtual interface to receive item related requests results.
Definition pubsubresulthandler.h:50
gloox::StanzaExtension
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
Definition stanzaextension.h:204
gloox::Subscription
An abstraction of a subscription stanza.
Definition subscription.h:32
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::PubSub
Namespace holding all the Pubsub-related structures and definitions.
Definition pubsub.h:28
gloox::PubSub::SubscriptionObject
SubscriptionObject
Definition pubsub.h:97
gloox::PubSub::SubscriptionNodes
@ SubscriptionNodes
Definition pubsub.h:98
gloox::PubSub::NodeType
NodeType
Definition pubsub.h:36
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124