Ad-Hoc Commands

If you want to implement your own adhoc command, just register your adhoc command module with module:add_item providing a descriptor for your command.

A descriptor can be created and added like this:

local adhoc_new = module:require "adhoc".new;
local descriptor = adhoc_new("Name", "node", handler);
module:add_item ("adhoc", descriptor)

A handler gets 2 parameters. A data table and a state.

The data table has 4 fields:

toThe to attribute of the stanza to be handled
fromThe from attribute of the stanza to be handled
actionThe action to be performed as specified in the stanza to be handled
formIf the to be handled stanza contains a form this will contain the form element

The handler should return two items. A data table and a state. The state will be saved and passed to the handler on invocation for any adhoc stanza with the same sessionid. If a session has ended the state returned should be nil.

The returned table can have the following fields:

Name Explanation Required?
statusStatus of the command (One of: "completed", "canceled", "error")yes
errorA table with the fields "type", "condition" and "message"when status is "error"
infoInformational text for display to the userno
warnA warning for the userno
actionsThe actions avaiable to the clientno
formA dataform to be filled out by the userno
resultA dataform of type result to be presented to the userno
otherAny other XML to be included in the response to the userno

For a simple module and details have a look at mod_ping.

doc/developers/modules/mod_adhoc.txt · Last modified: 2016/08/03 19:52 by Kim Alvefur