23 function _M.new(name, node, handler, permission) |
23 function _M.new(name, node, handler, permission) |
24 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") }; |
24 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") }; |
25 end |
25 end |
26 |
26 |
27 function _M.handle_cmd(command, origin, stanza) |
27 function _M.handle_cmd(command, origin, stanza) |
28 local sessionid = stanza.tags[1].attr.sessionid or uuid.generate(); |
28 local cmdtag = stanza.tags[1] |
|
29 local sessionid = cmdtag.attr.sessionid or uuid.generate(); |
29 local dataIn = {}; |
30 local dataIn = {}; |
30 dataIn.to = stanza.attr.to; |
31 dataIn.to = stanza.attr.to; |
31 dataIn.from = stanza.attr.from; |
32 dataIn.from = stanza.attr.from; |
32 dataIn.action = stanza.tags[1].attr.action or "execute"; |
33 dataIn.action = cmdtag.attr.action or "execute"; |
33 dataIn.form = stanza.tags[1]:child_with_ns("jabber:x:data"); |
34 dataIn.form = cmdtag:get_child("x", "jabber:x:data"); |
34 |
35 |
35 local data, state = command:handler(dataIn, states[sessionid]); |
36 local data, state = command:handler(dataIn, states[sessionid]); |
36 states[sessionid] = state; |
37 states[sessionid] = state; |
37 local cmdtag; |
38 local cmdtag; |
38 if data.status == "completed" then |
39 if data.status == "completed" then |