annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 local st = require "util.stanza";
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 local xmlns_cmd = "http://jabber.org/protocol/commands";
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 local _M = {};
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7 function _cmdtag(desc, status, sessionid, action)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8 local cmd = st.stanza("command", { xmlns = xmlns_cmd, node = desc.node, status = status });
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
9 if sessionid then cmd.attr.sessionid = sessionid; end
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
10 if action then cmd.attr.action = action; end
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 return cmd;
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 end
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14
43
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
15 function _M.new(name, node, handler, permission)
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
16 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") };
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17 end
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
19 function _M.handle_cmd(command, origin, stanza)
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
20 local sessionid = stanza.tags[1].attr.sessionid or nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
21 local dataIn = {};
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
22 dataIn.to = stanza.attr.to;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
23 dataIn.from = stanza.attr.from;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
24 dataIn.action = stanza.tags[1].attr.action or nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
25 dataIn.form = stanza.tags[1]:child_with_ns("jabber:x:data");
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
26
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
27 local data, sessid = command:handler(dataIn, sessionid);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
28 local stanza = st.reply(stanza);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
29 if data.status == "completed" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
30 cmdtag = command:cmdtag("completed", sessid);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
31 elseif data.status == "canceled" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
32 cmdtag = command:cmdtag("canceled", sessid);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
33 elseif data.status == "error" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
34 stanza = st.error_reply(stanza, data.error.type, data.error.condition, data.error.message);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
35 cmdtag = command:cmdtag("canceled", sessid);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
36 else
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
37 cmdtag = command:cmdtag("executing", sessid);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
38 end
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
39
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
40 for name, content in pairs(data) do
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
41 if name == "info" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
42 cmdtag:tag("note", {type="info"}):text(content);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
43 elseif name == "error" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
44 cmdtag:tag("note", {type="error"}):text(content.message);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
45 elseif name == "form" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
46 cmdtag:add_child(data.form:form());
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
47 elseif name == "other" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
48 cmdtag:add_child(content);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
49 end
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
50 end
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
51 stanza:add_child(cmdtag);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
52 origin.send(stanza);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
53
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
54 return true;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
55 end
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
56
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 return _M;