15 #include "adhochandler.h"
16 #include "adhoccommandprovider.h"
21 #include "discohandler.h"
22 #include "clientbase.h"
23 #include "adhocplugin.h"
25 #include "mutexguard.h"
30 static const char* cmdActionStringValues[] =
32 "execute",
"cancel",
"prev",
"next",
"complete"
37 return util::lookup2( action, cmdActionStringValues );
40 static const char* cmdStatusStringValues[] =
42 "executing",
"completed",
"canceled"
47 return util::lookup( status, cmdStatusStringValues );
50 static const char* cmdNoteStringValues[] =
52 "info",
"warn",
"error"
57 return util::lookup( sev, cmdNoteStringValues );
62 : m_severity( InvalidSeverity )
64 if( !tag || tag->
name() !=
"note" )
67 m_severity =
static_cast<Severity
>( util::deflookup( tag->
findAttribute(
"type" ), cmdNoteStringValues, Info ) );
68 m_note = tag->
cdata();
76 Tag* n =
new Tag(
"note", m_note );
93 m_plugin( plugin ), m_action( InvalidAction ), m_status( status ), m_actions( 0 )
101 m_plugin( plugin ), m_action( action ), m_actions( 0 )
106 Action executeAction,
int allowedActions,
109 m_plugin( plugin ), m_action( executeAction ), m_status( status ), m_actions( allowedActions )
141 ConstTagList::const_iterator it = l.begin();
142 for( ; it != l.end(); ++it )
143 m_notes.push_back(
new Note( (*it) ) );
152 m_plugin =
new IOData( x );
173 Tag* c =
new Tag(
"command" );
180 if( m_status != InvalidStatus )
185 Tag* actions =
new Tag( c,
"actions" );
187 if( m_action != InvalidAction )
192 if( ( m_actions & Previous ) == Previous )
193 new Tag( actions,
"prev" );
194 if( ( m_actions & Next ) == Next )
195 new Tag( actions,
"next" );
196 if( ( m_actions & Complete ) == Complete )
197 new Tag( actions,
"complete" );
203 if( m_action != InvalidAction )
205 if( m_status != InvalidStatus )
209 if ( !m_sessionid.empty() )
212 if( m_plugin && *m_plugin )
215 NoteList::const_iterator it = m_notes.begin();
216 for( ; it != m_notes.end(); ++it )
227 if( !m_parent || !m_parent->
disco() )
239 m_adhocTrackMapMutex.
lock();
240 m_adhocTrackMap.clear();
241 m_adhocTrackMapMutex.
unlock();
243 if( !m_parent || !m_parent->
disco() )
271 StringMap::const_iterator it = m_items.begin();
272 for( ; it != m_items.end(); ++it )
274 AdhocCommandProviderMap::const_iterator itp = m_adhocCommandProviders.find( (*it).first );
275 if( itp != m_adhocCommandProviders.end()
277 && (*itp).second->handleAdhocAccessRequest( from, (*it).first ) )
279 l.push_back(
new Disco::Item( m_parent->
jid(), (*it).first, (*it).second ) );
289 StringMap::const_iterator it = m_items.find( node );
292 it == m_items.end() ?
"Ad-Hoc Commands" : (*it).second ) );
302 if( !ac || ac->
node().empty())
305 AdhocCommandProviderMap::const_iterator it = m_adhocCommandProviders.find( ac->
node() );
306 if( it != m_adhocCommandProviders.end() )
309 m_activeSessions[sess] = iq.
id();
310 (*it).second->handleAdhocCommand( iq.
from(), *ac, sess );
319 if( context != ExecuteAdhocCommand )
322 m_adhocTrackMapMutex.
lock();
323 AdhocTrackMap::iterator it = m_adhocTrackMap.find( iq.
id() );
324 bool haveIdHandler = ( it != m_adhocTrackMap.end() );
325 m_adhocTrackMapMutex.
unlock();
326 if( !haveIdHandler || (*it).second.context != context
327 || (*it).second.remote != iq.
from() )
333 (*it).second.ah->handleAdhocError( iq.
from(), iq.
error(), (*it).second.handlerContext );
339 (*it).second.ah->handleAdhocExecutionResult( iq.
from(), *ac, (*it).second.handlerContext );
345 m_adhocTrackMapMutex.
lock();
346 m_adhocTrackMap.erase( it );
347 m_adhocTrackMapMutex.
unlock();
351 const std::string& name )
353 if( !m_parent || !m_parent->
disco() )
357 m_adhocCommandProviders[command] = acp;
358 m_items[command] = name;
363 if( context != CheckAdhocSupport )
368 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
369 for( ; it != m_adhocTrackMap.end() && (*it).second.context != context
370 && (*it).second.remote != from; ++it )
372 if( it == m_adhocTrackMap.end() )
376 m_adhocTrackMap.erase( it );
381 if( context != FetchAdhocCommands )
386 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
387 for( ; it != m_adhocTrackMap.end(); ++it )
389 if( (*it).second.context == context && (*it).second.remote == from )
393 Disco::ItemList::const_iterator it2 = l.begin();
394 for( ; it2 != l.end(); ++it2 )
396 commands[(*it2)->node()] = (*it2)->name();
398 (*it).second.ah->handleAdhocCommands( from, commands, (*it).second.handlerContext );
400 m_adhocTrackMap.erase( it );
409 for( AdhocTrackMap::iterator it = m_adhocTrackMap.begin(); it != m_adhocTrackMap.end(); )
411 if( (*it).second.context == context && (*it).second.remote == from )
413 (*it).second.ah->handleAdhocError( from, error, (*it).second.handlerContext );
420 m_adhocTrackMap.erase( it++ );
431 if( !remote || !ah || !m_parent || !m_parent->
disco() )
435 track.remote = remote;
436 track.context = CheckAdhocSupport;
438 track.handlerContext = context;
439 const std::string&
id = m_parent->
getID();
440 m_adhocTrackMapMutex.
lock();
441 m_adhocTrackMap[id] = track;
442 m_adhocTrackMapMutex.
unlock();
448 if( !remote || !ah || !m_parent || !m_parent->
disco() )
452 track.remote = remote;
453 track.context = FetchAdhocCommands;
455 track.handlerContext = context;
456 const std::string&
id = m_parent->
getID();
457 m_adhocTrackMapMutex.
lock();
458 m_adhocTrackMap[id] = track;
459 m_adhocTrackMapMutex.
unlock();
465 if( !remote || !command || !m_parent || !ah )
468 const std::string&
id = m_parent->
getID();
473 track.remote = remote;
474 track.context = ExecuteAdhocCommand;
477 track.handlerContext = context;
478 m_adhocTrackMapMutex.
lock();
479 m_adhocTrackMap[id] = track;
480 m_adhocTrackMapMutex.
unlock();
482 m_parent->
send( iq,
this, ExecuteAdhocCommand );
487 if( !remote || !command || !m_parent )
490 StringMap::iterator it = m_activeSessions.find( command->
sessionID() );
491 if( it == m_activeSessions.end() )
498 m_parent->
send( re );
499 m_activeSessions.erase( it );
504 if( !m_parent || !m_parent->
disco() )
508 m_adhocCommandProviders.erase( command );
509 m_items.erase( command );
A virtual interface for an Ad-hoc Command Provider according to XEP-0050.
A virtual interface for an Ad-hoc Command users according to XEP-0050.
A base class for Adhoc Command plugins (DataForm, IO Data, ...).
Note(Severity sev, const std::string ¬e)
An abstraction of an Adhoc Command element (from Adhoc Commands, XEP-0050) as a StanzaExtension.
const AdhocPlugin * plugin() const
Command(const std::string &node, const std::string &sessionid, Action action, AdhocPlugin *plugin=0)
const std::string & node() const
const std::string & sessionID() const
virtual const std::string & filterString() const
virtual Tag * tag() const
virtual Disco::ItemList handleDiscoNodeItems(const JID &from, const JID &to, const std::string &node)
virtual void handleIqID(const IQ &iq, int context)
virtual bool handleIq(const IQ &iq)
virtual void handleDiscoInfo(const JID &from, const Disco::Info &info, int context)
void registerAdhocCommandProvider(AdhocCommandProvider *acp, const std::string &command, const std::string &name)
void respond(const JID &remote, const Adhoc::Command *command, const Error *error=0)
virtual void handleDiscoError(const JID &from, const Error *error, int context)
void getCommands(const JID &remote, AdhocHandler *ah, int context=0)
void removeAdhocCommandProvider(const std::string &command)
virtual void handleDiscoItems(const JID &from, const Disco::Items &items, int context)
void checkSupport(const JID &remote, AdhocHandler *ah, int context=0)
void execute(const JID &remote, const Adhoc::Command *command, AdhocHandler *ah, int context=0)
virtual Disco::IdentityList handleDiscoNodeIdentities(const JID &from, const std::string &node)
virtual StringList handleDiscoNodeFeatures(const JID &from, const std::string &node)
Adhoc(ClientBase *parent)
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const std::string getID()
virtual Disco * disco() const
void removeIqHandler(IqHandler *ih, int exttype)
void removeIDHandler(IqHandler *ih)
bool removeStanzaExtension(int ext)
void registerIqHandler(IqHandler *ih, int exttype)
void registerStanzaExtension(StanzaExtension *ext)
An abstraction of a Disco identity (Service Discovery, XEP-0030).
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
bool hasFeature(const std::string &feature) const
An abstraction of a Disco item (Service Discovery, XEP-0030).
An abstraction of a Disco query element (from Service Discovery, XEP-0030) in the disco::items namesp...
const ItemList & items() const
void removeNodeHandler(DiscoNodeHandler *nh, const std::string &node)
void getDiscoInfo(const JID &to, const std::string &node, DiscoHandler *dh, int context, const std::string &tid=EmptyString)
void registerNodeHandler(DiscoNodeHandler *nh, const std::string &node)
void removeFeature(const std::string &feature)
void addFeature(const std::string &feature)
std::list< Identity * > IdentityList
void getDiscoItems(const JID &to, const std::string &node, DiscoHandler *dh, int context, const std::string &tid=EmptyString)
std::list< Item * > ItemList
A stanza error abstraction implemented as a StanzaExtension.
This is an abstraction of the IO Data specification XEP-0244.
An abstraction of an IQ stanza.
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
void addExtension(const StanzaExtension *se)
const Error * error() const
const std::string & id() const
const StanzaExtension * findExtension(int type) const
This is an abstraction of an XML element.
Tag * findChild(const std::string &name) const
const std::string xmlns() const
bool addAttribute(Attribute *attr)
bool hasChild(const std::string &name, const std::string &attr=EmptyString, const std::string &value=EmptyString) const
ConstTagList findTagList(const std::string &expression) const
void addChild(Tag *child)
const std::string cdata() const
const std::string & findAttribute(const std::string &name) const
const std::string & name() const
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
A simple implementation of a mutex guard.
void clearList(std::list< T * > &L)
The namespace for the gloox library.
std::list< std::string > StringList
const std::string XMLNS_X_DATA
const std::string EmptyString
std::list< const Tag * > ConstTagList
const std::string XMLNS_IODATA
const std::string XMLNS_ADHOC_COMMANDS
std::map< std::string, std::string > StringMap