Software / code / prosody
Annotate
plugins/adhoc/adhoc.lib.lua @ 8706:e2919978673e
net.http: Fix parameter order to http request callbacks
Commit e3b9dc9dd940 changed the parameter order in 2013, but did not update the names of the parameters in the callback function. Due to this inconsistency, 12df41a5a4b1 accidentally reversed the order when fixing the variable names without fixing where they are used.
Additionally the documentation was incorrect (since 2013), and this has also now been fixed.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 04 Apr 2018 18:27:44 +0100 |
| parent | 7951:2b91da49285a |
| child | 8459:84c117cdd048 |
| rev | line source |
|---|---|
|
3230
a5c3a82d677e
mod_adhoc/adhoc.lib: Add copyright header
Matthew Wild <mwild1@gmail.com>
parents:
3229
diff
changeset
|
1 -- Copyright (C) 2009-2010 Florian Zeitz |
|
a5c3a82d677e
mod_adhoc/adhoc.lib: Add copyright header
Matthew Wild <mwild1@gmail.com>
parents:
3229
diff
changeset
|
2 -- |
|
a5c3a82d677e
mod_adhoc/adhoc.lib: Add copyright header
Matthew Wild <mwild1@gmail.com>
parents:
3229
diff
changeset
|
3 -- This file is MIT/X11 licensed. Please see the |
|
a5c3a82d677e
mod_adhoc/adhoc.lib: Add copyright header
Matthew Wild <mwild1@gmail.com>
parents:
3229
diff
changeset
|
4 -- COPYING file in the source package for more information. |
|
a5c3a82d677e
mod_adhoc/adhoc.lib: Add copyright header
Matthew Wild <mwild1@gmail.com>
parents:
3229
diff
changeset
|
5 -- |
|
a5c3a82d677e
mod_adhoc/adhoc.lib: Add copyright header
Matthew Wild <mwild1@gmail.com>
parents:
3229
diff
changeset
|
6 |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local st, uuid = require "util.stanza", require "util.uuid"; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local xmlns_cmd = "http://jabber.org/protocol/commands"; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local states = {} |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local _M = {}; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
|
4975
6f689c155186
adhoc.lib: Make some globals local
Kim Alvefur <zash@zash.se>
parents:
4860
diff
changeset
|
15 local function _cmdtag(desc, status, sessionid, action) |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local cmd = st.stanza("command", { xmlns = xmlns_cmd, node = desc.node, status = status }); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 if sessionid then cmd.attr.sessionid = sessionid; end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 if action then cmd.attr.action = action; end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 return cmd; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 function _M.new(name, node, handler, permission) |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") }; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 function _M.handle_cmd(command, origin, stanza) |
|
6302
76699a0ae4c4
mod_lastactivity, mod_legacyauth, mod_presence, mod_saslauth, mod_tls: Use the newer stanza:get_child APIs and optimize away some table lookups
Kim Alvefur <zash@zash.se>
parents:
5758
diff
changeset
|
28 local cmdtag = stanza.tags[1] |
|
76699a0ae4c4
mod_lastactivity, mod_legacyauth, mod_presence, mod_saslauth, mod_tls: Use the newer stanza:get_child APIs and optimize away some table lookups
Kim Alvefur <zash@zash.se>
parents:
5758
diff
changeset
|
29 local sessionid = cmdtag.attr.sessionid or uuid.generate(); |
|
7951
2b91da49285a
mod_adhoc/adhoc.lib: instantiate table with all fields
Kim Alvefur <zash@zash.se>
parents:
6302
diff
changeset
|
30 local dataIn = { |
|
2b91da49285a
mod_adhoc/adhoc.lib: instantiate table with all fields
Kim Alvefur <zash@zash.se>
parents:
6302
diff
changeset
|
31 to = stanza.attr.to; |
|
2b91da49285a
mod_adhoc/adhoc.lib: instantiate table with all fields
Kim Alvefur <zash@zash.se>
parents:
6302
diff
changeset
|
32 from = stanza.attr.from; |
|
2b91da49285a
mod_adhoc/adhoc.lib: instantiate table with all fields
Kim Alvefur <zash@zash.se>
parents:
6302
diff
changeset
|
33 action = cmdtag.attr.action or "execute"; |
|
2b91da49285a
mod_adhoc/adhoc.lib: instantiate table with all fields
Kim Alvefur <zash@zash.se>
parents:
6302
diff
changeset
|
34 form = cmdtag:get_child("x", "jabber:x:data"); |
|
2b91da49285a
mod_adhoc/adhoc.lib: instantiate table with all fields
Kim Alvefur <zash@zash.se>
parents:
6302
diff
changeset
|
35 }; |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local data, state = command:handler(dataIn, states[sessionid]); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 states[sessionid] = state; |
|
4975
6f689c155186
adhoc.lib: Make some globals local
Kim Alvefur <zash@zash.se>
parents:
4860
diff
changeset
|
39 local cmdtag; |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 if data.status == "completed" then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 states[sessionid] = nil; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 cmdtag = command:cmdtag("completed", sessionid); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 elseif data.status == "canceled" then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 states[sessionid] = nil; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 cmdtag = command:cmdtag("canceled", sessionid); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 elseif data.status == "error" then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 states[sessionid] = nil; |
|
5758
ebc074918173
adhoc.lib: Don't build error reply from reply stanza
Kim Alvefur <zash@zash.se>
parents:
5075
diff
changeset
|
48 local reply = st.error_reply(stanza, data.error.type, data.error.condition, data.error.message); |
|
ebc074918173
adhoc.lib: Don't build error reply from reply stanza
Kim Alvefur <zash@zash.se>
parents:
5075
diff
changeset
|
49 origin.send(reply); |
|
3229
0abb73c43bc8
mod_adhoc/adhoc.lib: Handle errors according to XEP
Matthew Wild <mwild1@gmail.com>
parents:
3220
diff
changeset
|
50 return true; |
|
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3484
diff
changeset
|
51 else |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 cmdtag = command:cmdtag("executing", sessionid); |
|
4860
b66e73793cb7
adhoc.lib: Default actions to 'complete' (replacement for rev 52b6901cabb0)
Kim Alvefur <zash@zash.se>
parents:
4858
diff
changeset
|
53 data.actions = data.actions or { "complete" }; |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 for name, content in pairs(data) do |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 if name == "info" then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 cmdtag:tag("note", {type="info"}):text(content):up(); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 elseif name == "warn" then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 cmdtag:tag("note", {type="warn"}):text(content):up(); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 elseif name == "error" then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 cmdtag:tag("note", {type="error"}):text(content.message):up(); |
|
5075
4d939d2b1574
mod_adhoc: Add support for specifying a default action
Florian Zeitz <florob@babelmonkeys.de>
parents:
4993
diff
changeset
|
63 elseif name == "actions" then |
|
4d939d2b1574
mod_adhoc: Add support for specifying a default action
Florian Zeitz <florob@babelmonkeys.de>
parents:
4993
diff
changeset
|
64 local actions = st.stanza("actions", { execute = content.default }); |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 for _, action in ipairs(content) do |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if (action == "prev") or (action == "next") or (action == "complete") then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 actions:tag(action):up(); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 else |
|
4993
5243b74a4cbb
Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents:
4975
diff
changeset
|
69 module:log("error", "Command %q at node %q provided an invalid action %q", |
|
5243b74a4cbb
Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents:
4975
diff
changeset
|
70 command.name, command.node, action); |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 end |
|
4858
33458e1d84c8
Backed out changeset 52b6901cabb0 (to be replaced)
Matthew Wild <mwild1@gmail.com>
parents:
4632
diff
changeset
|
73 cmdtag:add_child(actions); |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 elseif name == "form" then |
|
3484
66910810a9f7
mod_adhoc: Fix passing data to util.dataforms
Florian Zeitz <florob@babelmonkeys.de>
parents:
3346
diff
changeset
|
75 cmdtag:add_child((content.layout or content):form(content.values)); |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 elseif name == "result" then |
|
3484
66910810a9f7
mod_adhoc: Fix passing data to util.dataforms
Florian Zeitz <florob@babelmonkeys.de>
parents:
3346
diff
changeset
|
77 cmdtag:add_child((content.layout or content):form(content.values, "result")); |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 elseif name == "other" then |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 cmdtag:add_child(content); |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 end |
|
5758
ebc074918173
adhoc.lib: Don't build error reply from reply stanza
Kim Alvefur <zash@zash.se>
parents:
5075
diff
changeset
|
82 local reply = st.reply(stanza); |
|
ebc074918173
adhoc.lib: Don't build error reply from reply stanza
Kim Alvefur <zash@zash.se>
parents:
5075
diff
changeset
|
83 reply:add_child(cmdtag); |
|
ebc074918173
adhoc.lib: Don't build error reply from reply stanza
Kim Alvefur <zash@zash.se>
parents:
5075
diff
changeset
|
84 origin.send(reply); |
|
3220
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 return true; |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 end |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 |
|
b3772f9bc359
mod_adhoc: Imported from prosody-modules, thanks Florob!
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 return _M; |