comparison mod_service_directories/mod_service_directories.lua @ 927:a9dfa7232d88

Merge
author Matthew Wild <mwild1@gmail.com>
date Tue, 12 Mar 2013 12:10:25 +0000
parents 7648ee2d59d1
children 42625801d15a
comparison
equal deleted inserted replaced
926:f88381a39c56 927:a9dfa7232d88
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);