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 );