Software /
code /
prosody
Comparison
core/configmanager.lua @ 6323:5926f01e5cd2
configmanager: nameprep VirtualHost and Component names
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 31 Jul 2014 06:56:21 +0100 |
parent | 6166:46cb87d531a7 |
child | 6326:a3b9496673ee |
comparison
equal
deleted
inserted
replaced
6314:8029b8a5f37a | 6323:5926f01e5cd2 |
---|---|
14 local fire_event = prosody and prosody.events.fire_event or function () end; | 14 local fire_event = prosody and prosody.events.fire_event or function () end; |
15 | 15 |
16 local envload = require"util.envload".envload; | 16 local envload = require"util.envload".envload; |
17 local deps = require"util.dependencies"; | 17 local deps = require"util.dependencies"; |
18 local path_sep = package.config:sub(1,1); | 18 local path_sep = package.config:sub(1,1); |
19 | |
20 local have_encodings, encodings = pcall(require, "util.encodings"); | |
21 local nameprep = have_encodings and encodings.stringprep.nameprep or function (host) return host:lower(); end | |
19 | 22 |
20 module "configmanager" | 23 module "configmanager" |
21 | 24 |
22 local parsers = {}; | 25 local parsers = {}; |
23 | 26 |
168 end | 171 end |
169 }); | 172 }); |
170 | 173 |
171 rawset(env, "__currenthost", "*") -- Default is global | 174 rawset(env, "__currenthost", "*") -- Default is global |
172 function env.VirtualHost(name) | 175 function env.VirtualHost(name) |
176 name = nameprep(name); | |
173 if rawget(config, name) and rawget(config[name], "component_module") then | 177 if rawget(config, name) and rawget(config[name], "component_module") then |
174 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", | 178 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", |
175 name, config[name].component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); | 179 name, config[name].component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); |
176 end | 180 end |
177 rawset(env, "__currenthost", name); | 181 rawset(env, "__currenthost", name); |
185 end; | 189 end; |
186 end | 190 end |
187 env.Host, env.host = env.VirtualHost, env.VirtualHost; | 191 env.Host, env.host = env.VirtualHost, env.VirtualHost; |
188 | 192 |
189 function env.Component(name) | 193 function env.Component(name) |
194 name = nameprep(name); | |
190 if rawget(config, name) and rawget(config[name], "defined") and not rawget(config[name], "component_module") then | 195 if rawget(config, name) and rawget(config[name], "defined") and not rawget(config[name], "component_module") then |
191 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", | 196 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", |
192 name, name, name), 0); | 197 name, name, name), 0); |
193 end | 198 end |
194 set(config, name, "component_module", "component"); | 199 set(config, name, "component_module", "component"); |