disco.h
/*
Copyright (c) 2004-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 DISCO_H__
#define DISCO_H__
#include "gloox.h"
#include "iqhandler.h"
#include "jid.h"
#include <string>
#include <list>
#include <map>
namespace gloox
{
class ClientBase;
class DataForm;
class DiscoHandler;
class DiscoNodeHandler;
class IQ;
class GLOOX_API Disco : public IqHandler
{
friend class ClientBase;
public:
class Identity; // declared below class Info
typedef std::list<Identity*> IdentityList;
class GLOOX_API Info : public StanzaExtension
{
friend class Disco;
public:
const std::string& node() const { return m_node; }
const StringList& features() const { return m_features; }
bool hasFeature( const std::string& feature ) const;
const IdentityList& identities() const { return m_identities; }
const DataForm* form() const { return m_form; }
void setForm( DataForm* form );
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new Info( tag );
}
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
return new Info( *this );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
private:
#ifdef DISCO_INFO_TEST
public:
#endif
Info( const std::string& node = EmptyString, bool defaultFeatures = false );
Info( const Tag* tag );
Info( const Info& info );
virtual ~Info();
void setNode( const std::string& node ) { m_node = node; }
void setFeatures( const StringList& features )
{
StringList fl( features );
fl.sort(); // needed on win32
m_features.merge( fl );
}
void setIdentities( const IdentityList& identities ) { m_identities = identities; }
std::string m_node;
StringList m_features;
IdentityList m_identities;
DataForm* m_form;
};
class GLOOX_API Identity
{
friend class Info;
friend class Disco;
public:
Identity( const std::string& category,
const std::string& type,
const std::string& name );
Identity( const Identity& id );
~Identity();
const std::string& category() const { return m_category; }
const std::string& type() const { return m_type; }
const std::string& name() const { return m_name; }
Tag* tag() const;
private:
Identity( const Tag* tag );
std::string m_category;
std::string m_type;
std::string m_name;
};
class Item; // declared below class Items
typedef std::list<Item*> ItemList;
class GLOOX_API Items : public StanzaExtension
{
friend class Disco;
public:
// This needs to be public so one can proactively send a list of adhoc commands
// see @xep{0050}
Items( const std::string& node = EmptyString );
virtual ~Items();
void setItems( const ItemList& items );
const std::string& node() const { return m_node; }
const ItemList& items() const { return m_items; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new Items( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
return new Items( *this );
}
private:
#ifdef DISCO_ITEMS_TEST
public:
#endif
Items( const Tag* tag );
std::string m_node;
ItemList m_items;
};
class GLOOX_API Item
{
friend class Items;
public:
Item( const JID& jid,
const std::string& node,
const std::string& name )
: m_jid( jid ), m_node( node ), m_name( name ) {}
~Item() {}
const JID& jid() const { return m_jid; }
const std::string& node() const { return m_node; }
const std::string& name() const { return m_name; }
Tag* tag() const;
private:
Item( const Tag* tag );
JID m_jid;
std::string m_node;
std::string m_name;
};
void addFeature( const std::string& feature )
{ m_features.push_back( feature ); }
void removeFeature( const std::string& feature )
{ m_features.remove( feature ); }
const StringList features( bool defaultFeatures = false ) const;
void getDiscoInfo( const JID& to, const std::string& node, DiscoHandler* dh, int context,
const std::string& tid = EmptyString )
{ getDisco( to, node, dh, context, GetDiscoInfo, tid ); }
void getDiscoItems( const JID& to, const std::string& node, DiscoHandler* dh, int context,
const std::string& tid = EmptyString )
{ getDisco( to, node, dh, context, GetDiscoItems, tid ); }
void setVersion( const std::string& name, const std::string& version,
const std::string& os = EmptyString );
const std::string& name() const { return m_versionName; }
const std::string& version() const { return m_versionVersion; }
const std::string& os() const { return m_versionOs; }
void setIdentity( const std::string& category, const std::string& type,
const std::string& name = EmptyString );
void addIdentity( const std::string& category, const std::string& type,
const std::string& name = EmptyString )
{ m_identities.push_back( new Identity( category, type, name ) ); }
const IdentityList& identities() const { return m_identities; }
void setForm( DataForm* form );
const DataForm* form() const { return m_form; }
void registerDiscoHandler( DiscoHandler* dh )
{ m_discoHandlers.push_back( dh ); }
void removeDiscoHandler( DiscoHandler* dh );
void registerNodeHandler( DiscoNodeHandler* nh, const std::string& node );
void removeNodeHandler( DiscoNodeHandler* nh, const std::string& node );
void removeNodeHandlers( DiscoNodeHandler* nh );
// reimplemented from IqHandler.
virtual bool handleIq( const IQ& iq );
// reimplemented from IqHandler.
virtual void handleIqID( const IQ& iq, int context );
private:
#ifdef DISCO_TEST
public:
#endif
Disco( ClientBase* parent );
virtual ~Disco();
enum IdType
{
GetDiscoInfo,
GetDiscoItems
};
void getDisco( const JID& to, const std::string& node, DiscoHandler* dh,
int context, IdType idType, const std::string& tid );
struct DiscoHandlerContext
{
DiscoHandler* dh;
int context;
};
ClientBase* m_parent;
typedef std::list<DiscoHandler*> DiscoHandlerList;
typedef std::list<DiscoNodeHandler*> DiscoNodeHandlerList;
typedef std::map<std::string, DiscoNodeHandlerList> DiscoNodeHandlerMap;
typedef std::map<std::string, DiscoHandlerContext> DiscoHandlerMap;
DiscoHandlerList m_discoHandlers;
DiscoNodeHandlerMap m_nodeHandlers;
DiscoHandlerMap m_track;
IdentityList m_identities;
StringList m_features;
StringMap m_queryIDs;
DataForm* m_form;
std::string m_versionName;
std::string m_versionVersion;
std::string m_versionOs;
};
}
#endif // DISCO_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::DiscoHandler
A virtual interface that enables objects to receive Service Discovery (XEP-0030) events.
Definition discohandler.h:35
gloox::DiscoNodeHandler
Derived classes can be registered as NodeHandlers for certain nodes with the Disco object.
Definition disconodehandler.h:36
gloox::Disco::Identity
An abstraction of a Disco identity (Service Discovery, XEP-0030).
Definition disco.h:197
gloox::Disco::Identity::category
const std::string & category() const
Definition disco.h:228
gloox::Disco::Identity::name
const std::string & name() const
Definition disco.h:240
gloox::Disco::Identity::type
const std::string & type() const
Definition disco.h:234
gloox::Disco::Identity::Identity
Identity(const std::string &category, const std::string &type, const std::string &name)
Definition disco.cpp:28
gloox::Disco::Info
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
Definition disco.h:66
gloox::Disco::Info::node
const std::string & node() const
Definition disco.h:74
gloox::Disco::Info::clone
virtual StanzaExtension * clone() const
Definition disco.h:120
gloox::Disco::Info::form
const DataForm * form() const
Definition disco.h:99
gloox::Disco::Info::identities
const IdentityList & identities() const
Definition disco.h:93
gloox::Disco::Info::newInstance
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition disco.h:114
gloox::Disco::Info::features
const StringList & features() const
Definition disco.h:80
gloox::Disco::Info::tag
virtual Tag * tag() const
Definition disco.cpp:135
gloox::Disco::Item
An abstraction of a Disco item (Service Discovery, XEP-0030).
Definition disco.h:353
gloox::Disco::Item::node
const std::string & node() const
Definition disco.h:383
gloox::Disco::Item::name
const std::string & name() const
Definition disco.h:389
gloox::Disco::Item::Item
Item(const JID &jid, const std::string &node, const std::string &name)
Definition disco.h:363
gloox::Disco::Item::~Item
~Item()
Definition disco.h:371
gloox::Disco::Item::jid
const JID & jid() const
Definition disco.h:377
gloox::Disco::Items
An abstraction of a Disco query element (from Service Discovery, XEP-0030) in the disco::items namesp...
Definition disco.h:276
gloox::Disco::Items::node
const std::string & node() const
Definition disco.h:305
gloox::Disco::Items::clone
virtual StanzaExtension * clone() const
Definition disco.h:326
gloox::Disco::Items::items
const ItemList & items() const
Definition disco.h:311
gloox::Disco::Items::newInstance
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition disco.h:317
gloox::Disco::Items::Items
Items(const std::string &node=EmptyString)
Definition disco.cpp:186
gloox::Disco::Items::tag
virtual Tag * tag() const
Definition disco.cpp:227
gloox::Disco::Items::setItems
void setItems(const ItemList &items)
Definition disco.cpp:214
gloox::Disco
This class implements XEP-0030 (Service Discovery) and XEP-0092 (Software Version).
Definition disco.h:46
gloox::Disco::name
const std::string & name() const
Definition disco.h:485
gloox::Disco::form
const DataForm * form() const
Definition disco.h:544
gloox::Disco::setForm
void setForm(DataForm *form)
Definition disco.cpp:277
gloox::Disco::version
const std::string & version() const
Definition disco.h:491
gloox::Disco::identities
const IdentityList & identities() const
Definition disco.h:529
gloox::Disco::getDiscoInfo
void getDiscoInfo(const JID &to, const std::string &node, DiscoHandler *dh, int context, const std::string &tid=EmptyString)
Definition disco.h:451
gloox::Disco::os
const std::string & os() const
Definition disco.h:497
gloox::Disco::removeFeature
void removeFeature(const std::string &feature)
Definition disco.h:430
gloox::Disco::registerDiscoHandler
void registerDiscoHandler(DiscoHandler *dh)
Definition disco.h:552
gloox::Disco::addFeature
void addFeature(const std::string &feature)
Definition disco.h:422
gloox::Disco::IdentityList
std::list< Identity * > IdentityList
Definition disco.h:56
gloox::Disco::addIdentity
void addIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
Definition disco.h:521
gloox::Disco::getDiscoItems
void getDiscoItems(const JID &to, const std::string &node, DiscoHandler *dh, int context, const std::string &tid=EmptyString)
Definition disco.h:466
gloox::Disco::ItemList
std::list< Item * > ItemList
Definition disco.h:266
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::StanzaExtension::StanzaExtension
StanzaExtension(int type)
Definition stanzaextension.h:211
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::StringMap
std::map< std::string, std::string > StringMap
Definition gloox.h:1261