Mercurial > prosody-modules
comparison mod_server_contact_info/mod_server_contact_info.lua @ 414:074237d7820b
mod_server_contact_info: Add module that publishes contact information.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 03 Sep 2011 01:27:55 +0200 |
parents | |
children | 4fdcb5c35021 |
comparison
equal
deleted
inserted
replaced
412:8963f4026f3a | 414:074237d7820b |
---|---|
1 -- This plugin implements http://xmpp.org/extensions/xep-0157.html | |
2 local t_insert = table.insert; | |
3 local df_new = require "util.dataforms".new; | |
4 | |
5 local x_contact_info; | |
6 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo | |
7 local valid_types = { | |
8 abuse = true; | |
9 admin = true; | |
10 feedback = true; | |
11 sales = true; | |
12 security = true; | |
13 support = true; | |
14 } | |
15 | |
16 local function update_form_data() | |
17 if x_contact_info then | |
18 module:remove_item("extension", x_contact_info); | |
19 end | |
20 x_contact_info = nil; | |
21 | |
22 local contact_config = module:get_option("contact_info"); | |
23 if not contact_config then -- we'll use admins from the config as default | |
24 contact_config = { admin = {}; }; | |
25 local admins = module:get_option("admins"); | |
26 if not admins or #admins == 0 then | |
27 module:log("debug", "No contact_info or admins in config"); | |
28 return -- Nothing to attach, so we'll just skip it. | |
29 end | |
30 module:log("debug", "No contact_info in config, using admins as fallback"); | |
31 --TODO fetch global admins too? | |
32 for i = 1,#admins do | |
33 t_insert(contact_config.admin, "xmpp:" .. admins[i]) | |
34 module:log("debug", "Added %s to admin-addresses", admins[i]); | |
35 end | |
36 end | |
37 if not next(contact_config) then | |
38 module:log("debug", "No contacts, skipping"); | |
39 return -- No use in serving an empty form. | |
40 end | |
41 local form_layout = { | |
42 { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; }; | |
43 }; | |
44 local form_values = {}; | |
45 | |
46 for t,a in pairs(contact_config) do | |
47 if valid_types[t] and a then | |
48 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" }); | |
49 form_values[t .. "-addresses"] = type(a) == "table" and a or {a}; | |
50 end | |
51 end | |
52 | |
53 x_contact_info = df_new(form_layout):form(form_values, "result"); | |
54 module:add_extension(x_contact_info); | |
55 end | |
56 | |
57 module:hook_global("config-reloaded", update_form_data); | |
58 update_form_data(); |