adhoc.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 ADHOC_H__
#define ADHOC_H__
#include "adhocplugin.h"
#include "disco.h"
#include "disconodehandler.h"
#include "discohandler.h"
#include "iqhandler.h"
#include "stanzaextension.h"
#include "mutex.h"
#include <string>
#include <list>
#include <map>
namespace gloox
{
class ClientBase;
class Stanza;
class AdhocHandler;
class AdhocCommandProvider;
class GLOOX_API Adhoc : public DiscoNodeHandler, public DiscoHandler, public IqHandler
{
public:
class GLOOX_API Command : public StanzaExtension
{
friend class Adhoc;
public:
enum Action
{
Execute = 1,
Cancel = 2,
Previous = 4,
Next = 8,
Complete = 16,
InvalidAction = 32
};
enum Status
{
Executing,
Completed,
Canceled,
InvalidStatus
};
class GLOOX_API Note
{
friend class Command;
public:
enum Severity
{
Info,
Warning,
Error,
InvalidSeverity
};
Note( Severity sev, const std::string& note )
: m_severity( sev ), m_note( note ) {}
~Note() {}
Severity severity() const { return m_severity; }
const std::string& content() const { return m_note; }
Tag* tag() const;
private:
#ifdef ADHOC_COMMANDS_TEST
public:
#endif
Note( const Tag* tag );
Severity m_severity;
std::string m_note;
};
typedef std::list<const Note*> NoteList;
Command( const std::string& node, const std::string& sessionid, Action action,
AdhocPlugin* plugin = 0 );
Command( const std::string& node, const std::string& sessionid, Status status,
AdhocPlugin* plugin = 0 );
Command( const std::string& node, const std::string& sessionid, Status status,
Action executeAction, int allowedActions = Complete,
AdhocPlugin* plugin = 0 );
Command( const std::string& node, Action action,
AdhocPlugin* plugin = 0 );
Command( const Tag* tag = 0 );
virtual ~Command();
const std::string& node() const { return m_node; }
const std::string& sessionID() const { return m_sessionid; }
Status status() const { return m_status; }
Action action() const { return m_action; }
int actions() const { return m_actions; }
const NoteList& notes() const { return m_notes; }
void addNote( const Note* note ) { m_notes.push_back( note ); }
GLOOX_DEPRECATED const AdhocPlugin* form() const { return m_plugin; }
const AdhocPlugin* plugin() const { return m_plugin; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new Command( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
Command* c = new Command();
NoteList::const_iterator it = m_notes.begin();
for( ; it != m_notes.end(); ++it )
c->m_notes.push_back( new Note( *(*it) ) );
c->m_node = m_node;
c->m_sessionid = m_sessionid;
c->m_plugin = m_plugin ? static_cast<AdhocPlugin*>( m_plugin->clone() ) : 0;
c->m_action = m_action;
c->m_status = m_status;
c->m_actions = m_actions;
return c;
}
private:
#ifdef ADHOC_COMMANDS_TEST
public:
#endif
NoteList m_notes;
std::string m_node;
std::string m_sessionid;
AdhocPlugin* m_plugin;
Action m_action;
Status m_status;
int m_actions;
};
Adhoc( ClientBase* parent );
virtual ~Adhoc();
void checkSupport( const JID& remote, AdhocHandler* ah, int context = 0 );
void getCommands( const JID& remote, AdhocHandler* ah, int context = 0 );
void execute( const JID& remote, const Adhoc::Command* command, AdhocHandler* ah, int context = 0 );
void respond( const JID& remote, const Adhoc::Command* command, const Error* error = 0 );
void registerAdhocCommandProvider( AdhocCommandProvider* acp, const std::string& command,
const std::string& name );
void removeAdhocCommandProvider( const std::string& command );
// reimplemented from DiscoNodeHandler
virtual StringList handleDiscoNodeFeatures( const JID& from, const std::string& node );
// reimplemented from DiscoNodeHandler
virtual Disco::IdentityList handleDiscoNodeIdentities( const JID& from,
const std::string& node );
// reimplemented from DiscoNodeHandler
virtual Disco::ItemList handleDiscoNodeItems( const JID& from, const JID& to, const std::string& node );
// reimplemented from IqHandler
virtual bool handleIq( const IQ& iq );
// reimplemented from IqHandler
virtual void handleIqID( const IQ& iq, int context );
// reimplemented from DiscoHandler
virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );
// reimplemented from DiscoHandler
virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );
// reimplemented from DiscoHandler
virtual void handleDiscoError( const JID& from, const Error* error, int context );
private:
#ifdef ADHOC_TEST
public:
#endif
typedef std::map<const std::string, AdhocCommandProvider*> AdhocCommandProviderMap;
AdhocCommandProviderMap m_adhocCommandProviders;
enum AdhocContext
{
CheckAdhocSupport,
FetchAdhocCommands,
ExecuteAdhocCommand
};
struct TrackStruct
{
JID remote;
AdhocContext context;
std::string session;
AdhocHandler* ah;
int handlerContext;
};
typedef std::map<std::string, TrackStruct> AdhocTrackMap;
AdhocTrackMap m_adhocTrackMap;
util::Mutex m_adhocTrackMapMutex;
ClientBase* m_parent;
StringMap m_items;
StringMap m_activeSessions;
};
}
#endif // ADHOC_H__
gloox::AdhocCommandProvider
A virtual interface for an Ad-hoc Command Provider according to XEP-0050.
Definition adhoccommandprovider.h:37
gloox::AdhocHandler
A virtual interface for an Ad-hoc Command users according to XEP-0050.
Definition adhochandler.h:33
gloox::AdhocPlugin
A base class for Adhoc Command plugins (DataForm, IO Data, ...).
Definition adhocplugin.h:39
gloox::Adhoc::Command::Note
Definition adhoc.h:131
gloox::Adhoc::Command::Note::Severity
Severity
Definition adhoc.h:140
gloox::Adhoc::Command::Note::InvalidSeverity
@ InvalidSeverity
Definition adhoc.h:147
gloox::Adhoc::Command::Note::Info
@ Info
Definition adhoc.h:141
gloox::Adhoc::Command::Note::Warning
@ Warning
Definition adhoc.h:143
gloox::Adhoc::Command::Note::Error
@ Error
Definition adhoc.h:145
gloox::Adhoc::Command::Note::content
const std::string & content() const
Definition adhoc.h:173
gloox::Adhoc::Command::Note::severity
Severity severity() const
Definition adhoc.h:167
gloox::Adhoc::Command::Note::~Note
~Note()
Definition adhoc.h:161
gloox::Adhoc::Command::Note::Note
Note(Severity sev, const std::string &note)
Definition adhoc.h:155
gloox::Adhoc::Command
An abstraction of an Adhoc Command element (from Adhoc Commands, XEP-0050) as a StanzaExtension.
Definition adhoc.h:92
gloox::Adhoc::Command::node
const std::string & node() const
Definition adhoc.h:268
gloox::Adhoc::Command::Command
Command(const std::string &node, const std::string &sessionid, Action action, AdhocPlugin *plugin=0)
Definition adhoc.cpp:97
gloox::Adhoc::Command::addNote
void addNote(const Note *note)
Definition adhoc.h:307
gloox::Adhoc::Command::clone
virtual StanzaExtension * clone() const
Definition adhoc.h:335
gloox::Adhoc::Command::notes
const NoteList & notes() const
Definition adhoc.h:300
gloox::Adhoc::Command::Status
Status
Definition adhoc.h:117
gloox::Adhoc::Command::Executing
@ Executing
Definition adhoc.h:118
gloox::Adhoc::Command::Canceled
@ Canceled
Definition adhoc.h:120
gloox::Adhoc::Command::InvalidStatus
@ InvalidStatus
Definition adhoc.h:121
gloox::Adhoc::Command::Completed
@ Completed
Definition adhoc.h:119
gloox::Adhoc::Command::plugin
const AdhocPlugin * plugin() const
Definition adhoc.h:320
gloox::Adhoc::Command::form
GLOOX_DEPRECATED const AdhocPlugin * form() const
Definition adhoc.h:314
gloox::Adhoc::Command::Action
Action
Definition adhoc.h:101
gloox::Adhoc::Command::Execute
@ Execute
Definition adhoc.h:102
gloox::Adhoc::Command::InvalidAction
@ InvalidAction
Definition adhoc.h:110
gloox::Adhoc::Command::Previous
@ Previous
Definition adhoc.h:105
gloox::Adhoc::Command::Cancel
@ Cancel
Definition adhoc.h:104
gloox::Adhoc::Command::Complete
@ Complete
Definition adhoc.h:109
gloox::Adhoc::Command::Next
@ Next
Definition adhoc.h:107
gloox::Adhoc::Command::newInstance
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition adhoc.h:326
gloox::Adhoc::Command::actions
int actions() const
Definition adhoc.h:294
gloox::Adhoc::Command::status
Status status() const
Definition adhoc.h:281
gloox::Adhoc::Command::NoteList
std::list< const Note * > NoteList
Definition adhoc.h:198
gloox::Adhoc::Command::tag
virtual Tag * tag() const
Definition adhoc.cpp:168
gloox::Adhoc::Command::sessionID
const std::string & sessionID() const
Definition adhoc.h:274
gloox::Adhoc::Command::action
Action action() const
Definition adhoc.h:287
gloox::Adhoc
This class implements a provider for XEP-0050 (Ad-hoc Commands).
Definition adhoc.h:82
gloox::Adhoc::Adhoc
Adhoc(ClientBase *parent)
Definition adhoc.cpp:224
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
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::Info
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
Definition disco.h:66
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::IdentityList
std::list< Identity * > IdentityList
Definition disco.h:56
gloox::Disco::ItemList
std::list< Item * > ItemList
Definition disco.h:266
gloox::Error
A stanza error abstraction implemented as a StanzaExtension.
Definition error.h:35
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::Stanza
This is the base class for XMPP stanza abstractions.
Definition stanza.h:34
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::StringMap
std::map< std::string, std::string > StringMap
Definition gloox.h:1261