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 = (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 )
213 c->
addChild( m_plugin->tag()->clone() );
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 );
void checkSupport(const JID &remote, AdhocHandler *ah, int context=0)
void addFeature(const std::string &feature)
An abstraction of a Disco query element (from Service Discovery, XEP-0030) in the disco::items namesp...
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
std::list< Item * > ItemList
A simple implementation of a mutex guard.
const ItemList & items() const
void removeIDHandler(IqHandler *ih)
std::list< std::string > StringList
void clearList(std::list< T * > &L)
An abstraction of an IQ stanza.
void removeIqHandler(IqHandler *ih, int exttype)
void getDiscoItems(const JID &to, const std::string &node, DiscoHandler *dh, int context, const std::string &tid=EmptyString)
void registerIqHandler(IqHandler *ih, int exttype)
void addExtension(const StanzaExtension *se)
std::list< Identity * > IdentityList
const std::string & node() const
void respond(const JID &remote, const Adhoc::Command *command, const Error *error=0)
void registerStanzaExtension(StanzaExtension *ext)
void execute(const JID &remote, const Adhoc::Command *command, AdhocHandler *ah, int context=0)
void removeAdhocCommandProvider(const std::string &command)
Command(const std::string &node, const std::string &sessionid, Action action, AdhocPlugin *plugin=0)
void removeNodeHandler(DiscoNodeHandler *nh, const std::string &node)
Note(Severity sev, const std::string ¬e)
virtual Disco::ItemList handleDiscoNodeItems(const JID &from, const JID &to, const std::string &node)
std::list< const Tag * > ConstTagList
virtual Disco::IdentityList handleDiscoNodeIdentities(const JID &from, const std::string &node)
A virtual interface for an Ad-hoc Command users according to XEP-0050.
A stanza error abstraction implemented as a StanzaExtension.
Adhoc(ClientBase *parent)
void getCommands(const JID &remote, AdhocHandler *ah, int context=0)
bool removeStanzaExtension(int ext)
An abstraction of an Adhoc Command element (from Adhoc Commands, XEP-0050) as a StanzaExtension.
const std::string & sessionID() const
void addChild(Tag *child)
const std::string XMLNS_X_DATA
This is an abstraction of the IO Data specification XEP-0244.
void registerNodeHandler(DiscoNodeHandler *nh, const std::string &node)
The namespace for the gloox library.
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string XMLNS_ADHOC_COMMANDS
const std::string & xmlns() const
virtual void handleDiscoItems(const JID &from, const Disco::Items &items, int context)
virtual Disco * disco() const
const std::string & findAttribute(const std::string &name) const
const std::string XMLNS_IODATA
std::map< std::string, std::string > StringMap
virtual const std::string & filterString() const
const std::string cdata() const
virtual void handleDiscoError(const JID &from, const Error *error, int context)
bool addAttribute(Attribute *attr)
An abstraction of a Disco Info element (from Service Discovery, XEP-0030) as a StanzaExtension.
bool hasChild(const std::string &name, const std::string &attr=EmptyString, const std::string &value=EmptyString) const
const AdhocPlugin * plugin() const
virtual Tag * tag() const
const std::string & name() const
virtual void handleIqID(const IQ &iq, int context)
An abstraction of a Disco item (Service Discovery, XEP-0030).
void getDiscoInfo(const JID &to, const std::string &node, DiscoHandler *dh, int context, const std::string &tid=EmptyString)
const std::string getID()
const Error * error() const
bool hasFeature(const std::string &feature) const
virtual void handleDiscoInfo(const JID &from, const Disco::Info &info, int context)
A virtual interface for an Ad-hoc Command Provider according to XEP-0050.
virtual StringList handleDiscoNodeFeatures(const JID &from, const std::string &node)
void removeFeature(const std::string &feature)
Tag * findChild(const std::string &name) const
const std::string & id() const
ConstTagList findTagList(const std::string &expression) const
const std::string EmptyString
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const StanzaExtension * findExtension(int type) const
This is an abstraction of an XML element.
void registerAdhocCommandProvider(AdhocCommandProvider *acp, const std::string &command, const std::string &name)
An abstraction of a Disco identity (Service Discovery, XEP-0030).
virtual bool handleIq(const IQ &iq)
A base class for Adhoc Command plugins (DataForm, IO Data, ...).