15 #include "adhochandler.h"
16 #include "adhoccommandprovider.h"
18 #include "discohandler.h"
65 item.
name =
"Ad-Hoc Commands";
70 StringMap::const_iterator it = m_items.begin();
71 for( ; it != m_items.end(); ++it )
74 item.
node = (*it).first;
76 item.
name = (*it).second;
85 StringMap::const_iterator it = m_items.find( node );
86 if( it != m_items.end() )
89 name =
"Ad-Hoc Commands";
93 ident[
"automation"] =
"command-list";
95 ident[
"automation"] =
"command-node";
108 AdhocCommandProviderMap::const_iterator it = m_adhocCommandProviders.find( node );
109 if( !node.empty() && ( it != m_adhocCommandProviders.end() ) )
111 (*it).second->handleAdhocCommand( node, c, stanza->
from(), stanza->
id() );
124 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
125 for( ; it != m_adhocTrackMap.end(); ++it )
127 if( (*it).second.context == context && (*it).second.remote == stanza->
from() )
148 else if( d ==
"prev" )
150 else if( d ==
"complete" )
166 if( s ==
"executing" )
168 else if( s ==
"completed" )
170 else if( s ==
"canceled" )
177 (*it).second.ah->handleAdhocExecutionResult( stanza->
from(), command, status, id, form,
178 actions, def, note, type );
181 m_adhocTrackMap.erase( it );
190 const std::string& name )
193 m_adhocCommandProviders[command] = acp;
194 m_items[command] = name;
199 if( context != CheckAdhocSupport )
202 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
203 for( ; it != m_adhocTrackMap.end(); ++it )
205 if( (*it).second.context == context && (*it).second.remote == stanza->
from() )
209 (*it).second.ah->handleAdhocSupport( (*it).second.remote,
211 m_adhocTrackMap.erase( it );
219 if( context != FetchAdhocCommands )
222 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
223 for( ; it != m_adhocTrackMap.end(); ++it )
225 if( (*it).second.context == context && (*it).second.remote == stanza->
from() )
232 Tag::TagList::const_iterator itt = l.begin();
233 for( ; itt != l.end(); ++itt )
235 const std::string& name = (*itt)->findAttribute(
"name" );
236 const std::string& node = (*itt)->findAttribute(
"node" );
237 if( (*itt)->name() ==
"item" && !name.empty() && !node.empty() )
239 commands[node] = name;
242 (*it).second.ah->handleAdhocCommands( (*it).second.remote, commands );
245 m_adhocTrackMap.erase( it );
253 AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
254 for( ; it != m_adhocTrackMap.end(); ++it )
256 if( (*it).second.context == context && (*it).second.remote == stanza->
from() )
258 (*it).second.ah->handleAdhocError( (*it).second.remote, stanza->
error() );
260 m_adhocTrackMap.erase( it );
271 track.remote = remote;
272 track.context = CheckAdhocSupport;
274 m_adhocTrackMap[m_parent->
getID()] = track;
284 track.remote = remote;
285 track.context = FetchAdhocCommands;
287 m_adhocTrackMap[m_parent->
getID()] = track;
292 const std::string& sessionid,
DataForm *form,
295 if( !remote || command.
empty() || !ah )
298 const std::string&
id = m_parent->
getID();
299 Tag *iq =
new Tag(
"iq" );
303 Tag *c =
new Tag( iq,
"command" );
307 if( !sessionid.empty() )
333 track.remote = remote;
334 track.context = ExecuteAdhocCommand;
336 m_adhocTrackMap[id] = track;
338 m_parent->
trackID(
this,
id, ExecuteAdhocCommand );
339 m_parent->
send( iq );
345 m_adhocCommandProviders.erase( command );
346 m_items.erase( command );