Mercurial > prosody-modules
comparison mod_adhoc/adhoc/adhoc.lib.lua @ 121:a9898f13c89e
mod_adhoc: Major refactoring. Actuall data exchange happens here now
mod_adhoc_cmd_*: Update to work with aforementioned change
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 22 Jan 2010 04:25:58 +0100 |
| parents | adc9eff8adb2 |
| children | c3a874eec712 |
comparison
equal
deleted
inserted
replaced
| 120:7a2d33e8ad1f | 121:a9898f13c89e |
|---|---|
| 14 | 14 |
| 15 function _M.new(name, node, handler, permission) | 15 function _M.new(name, node, handler, permission) |
| 16 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") }; | 16 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") }; |
| 17 end | 17 end |
| 18 | 18 |
| 19 function _M.handle_cmd(command, origin, stanza) | |
| 20 local sessionid = stanza.tags[1].attr.sessionid or nil; | |
| 21 local dataIn = {}; | |
| 22 dataIn.to = stanza.attr.to; | |
| 23 dataIn.from = stanza.attr.from; | |
| 24 dataIn.action = stanza.tags[1].attr.action or nil; | |
| 25 dataIn.form = stanza.tags[1]:child_with_ns("jabber:x:data"); | |
| 26 | |
| 27 local data, sessid = command:handler(dataIn, sessionid); | |
| 28 local stanza = st.reply(stanza); | |
| 29 if data.status == "completed" then | |
| 30 cmdtag = command:cmdtag("completed", sessid); | |
| 31 elseif data.status == "canceled" then | |
| 32 cmdtag = command:cmdtag("canceled", sessid); | |
| 33 elseif data.status == "error" then | |
| 34 stanza = st.error_reply(stanza, data.error.type, data.error.condition, data.error.message); | |
| 35 cmdtag = command:cmdtag("canceled", sessid); | |
| 36 else | |
| 37 cmdtag = command:cmdtag("executing", sessid); | |
| 38 end | |
| 39 | |
| 40 for name, content in pairs(data) do | |
| 41 if name == "info" then | |
| 42 cmdtag:tag("note", {type="info"}):text(content); | |
| 43 elseif name == "error" then | |
| 44 cmdtag:tag("note", {type="error"}):text(content.message); | |
| 45 elseif name == "form" then | |
| 46 cmdtag:add_child(data.form:form()); | |
| 47 elseif name == "other" then | |
| 48 cmdtag:add_child(content); | |
| 49 end | |
| 50 end | |
| 51 stanza:add_child(cmdtag); | |
| 52 origin.send(stanza); | |
| 53 | |
| 54 return true; | |
| 55 end | |
| 56 | |
| 19 return _M; | 57 return _M; |
