Comparison

mod_service_directories/mod_service_directories.lua @ 904:7648ee2d59d1

mod_service_directories: Use dataforms correctly
author Kim Alvefur <zash@zash.se>
date Mon, 04 Feb 2013 01:36:41 +0100
parent 759:6531a029fce5
child 1280:42625801d15a
comparison
equal deleted inserted replaced
903:8a1beff848c1 904:7648ee2d59d1
12 local st = require "util.stanza"; 12 local st = require "util.stanza";
13 local jid_split = require "util.jid".split; 13 local jid_split = require "util.jid".split;
14 local adhoc_new = module:require "adhoc".new; 14 local adhoc_new = module:require "adhoc".new;
15 local to_ascii = require "util.encodings".idna.to_ascii; 15 local to_ascii = require "util.encodings".idna.to_ascii;
16 local nameprep = require "util.encodings".stringprep.nameprep; 16 local nameprep = require "util.encodings".stringprep.nameprep;
17 local dataforms_new = require "util.dataforms".new;
17 local pairs, ipairs = pairs, ipairs; 18 local pairs, ipairs = pairs, ipairs;
18 local module = module; 19 local module = module;
19 local hosts = hosts; 20 local hosts = hosts;
20 21
21 local subscription_from = {}; 22 local subscription_from = {};
77 end 78 end
78 79
79 -- Admin ad-hoc command to subscribe 80 -- Admin ad-hoc command to subscribe
80 81
81 local function add_contact_handler(self, data, state) 82 local function add_contact_handler(self, data, state)
82 local layout = { 83 local layout = dataforms_new{
83 title = "Adding a Server Buddy"; 84 title = "Adding a Server Buddy";
84 instructions = "Fill out this form to add a \"server buddy\"."; 85 instructions = "Fill out this form to add a \"server buddy\".";
85 86
86 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; 87 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
87 { name = "peerjid", type = "jid-single", required = true, label = "The server to add" }; 88 { name = "peerjid", type = "jid-single", required = true, label = "The server to add" };
90 if not state then 91 if not state then
91 return { status = "executing", form = layout }, "executing"; 92 return { status = "executing", form = layout }, "executing";
92 elseif data.action == "canceled" then 93 elseif data.action == "canceled" then
93 return { status = "canceled" }; 94 return { status = "canceled" };
94 else 95 else
95 local fields = layout:data(data); 96 local fields = layout:data(data.form);
96 local peerjid = nameprep(fields.peerjid); 97 local peerjid = nameprep(fields.peerjid);
97 if not peerjid or peerjid == "" or #peerjid > 1023 or not to_ascii(peerjid) then 98 if not peerjid or peerjid == "" or #peerjid > 1023 or not to_ascii(peerjid) then
98 return { status = "completed", error = { message = "Invalid JID" } }; 99 return { status = "completed", error = { message = "Invalid JID" } };
99 end 100 end
100 add_contact(peerjid); 101 add_contact(peerjid);