Software /
code /
prosody
Comparison
core/configmanager.lua @ 6716:2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 18 May 2015 19:06:34 +0100 |
parent | 6715:03a283aa679e |
child | 6717:4fecfc81dac1 |
comparison
equal
deleted
inserted
replaced
6715:03a283aa679e | 6716:2b78754b0f1c |
---|---|
119 | 119 |
120 -- Built-in Lua parser | 120 -- Built-in Lua parser |
121 do | 121 do |
122 local pcall = _G.pcall; | 122 local pcall = _G.pcall; |
123 parsers.lua = {}; | 123 parsers.lua = {}; |
124 function parsers.lua.load(data, config_file, config) | 124 function parsers.lua.load(data, config_file, config_table) |
125 local env; | 125 local env; |
126 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below | 126 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
127 env = setmetatable({ | 127 env = setmetatable({ |
128 Host = true, host = true, VirtualHost = true, | 128 Host = true, host = true, VirtualHost = true, |
129 Component = true, component = true, | 129 Component = true, component = true, |
137 }); | 137 }); |
138 | 138 |
139 rawset(env, "__currenthost", "*") -- Default is global | 139 rawset(env, "__currenthost", "*") -- Default is global |
140 function env.VirtualHost(name) | 140 function env.VirtualHost(name) |
141 name = nameprep(name); | 141 name = nameprep(name); |
142 if rawget(config, name) and rawget(config[name], "component_module") then | 142 if rawget(config_table, name) and rawget(config_table[name], "component_module") then |
143 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", | 143 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", |
144 name, config[name].component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); | 144 name, config_table[name].component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); |
145 end | 145 end |
146 rawset(env, "__currenthost", name); | 146 rawset(env, "__currenthost", name); |
147 -- Needs at least one setting to logically exist :) | 147 -- Needs at least one setting to logically exist :) |
148 set(config, name or "*", "defined", true); | 148 set(config_table, name or "*", "defined", true); |
149 return function (config_options) | 149 return function (config_options) |
150 rawset(env, "__currenthost", "*"); -- Return to global scope | 150 rawset(env, "__currenthost", "*"); -- Return to global scope |
151 for option_name, option_value in pairs(config_options) do | 151 for option_name, option_value in pairs(config_options) do |
152 set(config, name or "*", option_name, option_value); | 152 set(config_table, name or "*", option_name, option_value); |
153 end | 153 end |
154 end; | 154 end; |
155 end | 155 end |
156 env.Host, env.host = env.VirtualHost, env.VirtualHost; | 156 env.Host, env.host = env.VirtualHost, env.VirtualHost; |
157 | 157 |
158 function env.Component(name) | 158 function env.Component(name) |
159 name = nameprep(name); | 159 name = nameprep(name); |
160 if rawget(config, name) and rawget(config[name], "defined") and not rawget(config[name], "component_module") then | 160 if rawget(config_table, name) and rawget(config_table[name], "defined") and not rawget(config_table[name], "component_module") then |
161 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", | 161 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", |
162 name, name, name), 0); | 162 name, name, name), 0); |
163 end | 163 end |
164 set(config, name, "component_module", "component"); | 164 set(config_table, name, "component_module", "component"); |
165 -- Don't load the global modules by default | 165 -- Don't load the global modules by default |
166 set(config, name, "load_global_modules", false); | 166 set(config_table, name, "load_global_modules", false); |
167 rawset(env, "__currenthost", name); | 167 rawset(env, "__currenthost", name); |
168 local function handle_config_options(config_options) | 168 local function handle_config_options(config_options) |
169 rawset(env, "__currenthost", "*"); -- Return to global scope | 169 rawset(env, "__currenthost", "*"); -- Return to global scope |
170 for option_name, option_value in pairs(config_options) do | 170 for option_name, option_value in pairs(config_options) do |
171 set(config, name or "*", option_name, option_value); | 171 set(config_table, name or "*", option_name, option_value); |
172 end | 172 end |
173 end | 173 end |
174 | 174 |
175 return function (module) | 175 return function (module) |
176 if type(module) == "string" then | 176 if type(module) == "string" then |
177 set(config, name, "component_module", module); | 177 set(config_table, name, "component_module", module); |
178 return handle_config_options; | 178 return handle_config_options; |
179 end | 179 end |
180 return handle_config_options(module); | 180 return handle_config_options(module); |
181 end | 181 end |
182 end | 182 end |