15 #include "adhochandler.h"
16 #include "adhoccommandprovider.h"
19 #include "discohandler.h"
20 #include "clientbase.h"
27 static const char* cmdActionStringValues[] =
29 "execute",
"cancel",
"prev",
"next",
"complete"
34 return util::lookup2( action, cmdActionStringValues );
37 static const char* cmdStatusStringValues[] =
39 "executing",
"completed",
"canceled"
44 return util::lookup( status, cmdStatusStringValues );
47 static const char* cmdNoteStringValues[] =
49 "info",
"warn",
"error"
54 return util::lookup( sev, cmdNoteStringValues );
59 : m_severity( InvalidSeverity )
61 if( !tag || tag->
name() !=
"note" )
64 m_severity = (Severity)util::deflookup( tag->
findAttribute(
"type" ), cmdNoteStringValues, Info );
65 m_note = tag->
cdata();
73 Tag* n =
new Tag(
"note", m_note );
90 m_form( form ), m_action( InvalidAction ), m_status( status ), m_actions( 0 )
98 m_form( form ), m_action( action ), m_actions( 0 )
103 Action executeAction,
int allowedActions,
106 m_form( form ), m_action( executeAction ), m_status( status ), m_actions( allowedActions )
138 ConstTagList::const_iterator it = l.begin();
139 for( ; it != l.end(); ++it )
140 m_notes.push_back(
new Note( (*it) ) );
164 Tag* c =
new Tag(
"command" );
171 if( m_status != InvalidStatus )
176 Tag* actions =
new Tag( c,
"actions" );
178 if( m_action != InvalidAction )
183 if( ( m_actions & Previous ) == Previous )
184 new Tag( actions,
"prev" );
185 if( ( m_actions & Next ) == Next )
186 new Tag( actions,
"next" );
187 if( ( m_actions & Complete ) == Complete )
188 new Tag( actions,
"complete" );
194 if( m_action != InvalidAction )
196 if( m_status != InvalidStatus )
200 if ( !m_sessionid.empty() )
203 if( m_form && *m_form )
206 NoteList::const_iterator it = m_notes.begin();
207 for( ; it != m_notes.end(); ++it )
218 if( !m_parent || !m_parent->
disco() )
230 if( !m_parent || !m_parent->
disco() )
258 StringMap::const_iterator it = m_items.begin();
259 for( ; it != m_items.end(); ++it )
261 AdhocCommandProviderMap::const_iterator itp = m_adhocCommandProviders.find( (*it).first );
262 if( itp != m_adhocCommandProviders.end()
264 && (*itp).second->handleAdhocAccessRequest( from, (*it).first ) )
266 l.push_back(
new Disco::Item( m_parent->
jid(), (*it).first, (*it).second ) );
276 StringMap::const_iterator it = m_items.find( node );
279 it == m_items.end() ?
"Ad-Hoc Commands" : (*it).second ) );
289 if( !ac || ac->
node().empty())
292 AdhocCommandProviderMap::const_iterator it = m_adhocCommandProviders.find( ac->
node() );
293 if( it != m_adhocCommandProviders.end() )
296 m_activeSessions[sess] = iq.
id();
297 (*it).second->handleAdhocCommand( iq.
from(), *ac, sess );
306 if( context != ExecuteAdhocCommand )
309 AdhocTrackMap::iterator it = m_adhocTrackMap.find( iq.
id() );
310 if( it == m_adhocTrackMap.end() || (*it).second.context != context
311 || (*it).second.remote != iq.
from() )
317 (*it).second.ah->handleAdhocError( iq.
from(), iq.
error() );
323 (*it).second.ah->handleAdhocExecutionResult( iq.
from(), *ac );
329 m_adhocTrackMap.erase( it );
333 const std::string& name )
335 if( !m_parent || !m_parent->
disco() )
339 m_adhocCommandProviders[command] = acp;
340 m_items[command] = name;
345 if( context != CheckAdhocSupport )
348 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
349 for( ; it != m_adhocTrackMap.end() && (*it).second.context != context
350 && (*it).second.remote != from; ++it )
352 if( it == m_adhocTrackMap.end() )
356 m_adhocTrackMap.erase( it );
361 if( context != FetchAdhocCommands )
364 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
365 for( ; it != m_adhocTrackMap.end(); ++it )
367 if( (*it).second.context == context && (*it).second.remote == from )
371 Disco::ItemList::const_iterator it2 = l.begin();
372 for( ; it2 != l.end(); ++it2 )
374 commands[(*it2)->node()] = (*it2)->name();
376 (*it).second.ah->handleAdhocCommands( from, commands );
378 m_adhocTrackMap.erase( it );
386 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
387 for( ; it != m_adhocTrackMap.end(); ++it )
389 if( (*it).second.context == context && (*it).second.remote == from )
391 (*it).second.ah->handleAdhocError( from, error );
393 m_adhocTrackMap.erase( it );
400 if( !remote || !ah || !m_parent || !m_parent->
disco() )
404 track.remote = remote;
405 track.context = CheckAdhocSupport;
407 const std::string&
id = m_parent->
getID();
408 m_adhocTrackMap[id] = track;
414 if( !remote || !ah || !m_parent || !m_parent->
disco() )
418 track.remote = remote;
419 track.context = FetchAdhocCommands;
421 const std::string&
id = m_parent->
getID();
422 m_adhocTrackMap[id] = track;
428 if( !remote || !command || !m_parent || !ah )
431 const std::string&
id = m_parent->
getID();
436 track.remote = remote;
437 track.context = ExecuteAdhocCommand;
440 m_adhocTrackMap[id] = track;
442 m_parent->
send( iq,
this, ExecuteAdhocCommand );
447 if( !remote || !command || !m_parent )
450 StringMap::iterator it = m_activeSessions.find( command->
sessionID() );
451 if( it == m_activeSessions.end() )
458 m_parent->
send( re );
459 m_activeSessions.erase( it );
464 if( !m_parent || !m_parent->
disco() )
468 m_adhocCommandProviders.erase( command );
469 m_items.erase( command );
void checkSupport(const JID &remote, AdhocHandler *ah)
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
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 removeAdhocCommandProvider(const std::string &command)
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)
void getCommands(const JID &remote, AdhocHandler *ah)
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)
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
void registerNodeHandler(DiscoNodeHandler *nh, const std::string &node)
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 DataForm * form() const
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)
Command(const std::string &node, const std::string &sessionid, Action action, DataForm *form=0)
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
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
void execute(const JID &remote, const Adhoc::Command *command, AdhocHandler *ah)
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)