diff options
author | Melanie Thielker | 2016-12-22 18:23:04 +0000 |
---|---|---|
committer | Melanie Thielker | 2016-12-22 18:23:04 +0000 |
commit | 0ae2b5ac8134230fd5f1bcd668647afb5b345baf (patch) | |
tree | 50c3eb9c697ed86a5a2729e0a4cccb7324bd92c3 /OpenSim | |
parent | Merge branch 'master' of opensimulator.org:/var/git/opensim (diff) | |
download | opensim-SC-0ae2b5ac8134230fd5f1bcd668647afb5b345baf.zip opensim-SC-0ae2b5ac8134230fd5f1bcd668647afb5b345baf.tar.gz opensim-SC-0ae2b5ac8134230fd5f1bcd668647afb5b345baf.tar.bz2 opensim-SC-0ae2b5ac8134230fd5f1bcd668647afb5b345baf.tar.xz |
Allow the use of modular configs with Robust as we already can with OpenSim
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 148 |
1 files changed, 123 insertions, 25 deletions
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index a7cffd7..e18594f 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs | |||
@@ -55,11 +55,7 @@ namespace OpenSim.Server.Base | |||
55 | // | 55 | // |
56 | protected string[] m_Arguments; | 56 | protected string[] m_Arguments; |
57 | 57 | ||
58 | public string ConfigDirectory | 58 | protected string m_configDirectory = "."; |
59 | { | ||
60 | get; | ||
61 | private set; | ||
62 | } | ||
63 | 59 | ||
64 | // Run flag | 60 | // Run flag |
65 | // | 61 | // |
@@ -101,31 +97,24 @@ namespace OpenSim.Server.Base | |||
101 | logConfig =startupConfig.GetString("logconfig", logConfig); | 97 | logConfig =startupConfig.GetString("logconfig", logConfig); |
102 | } | 98 | } |
103 | 99 | ||
104 | // Find out of the file name is a URI and remote load it if possible. | 100 | Config = ReadConfigSource(iniFile); |
105 | // Load it as a local file otherwise. | ||
106 | Uri configUri; | ||
107 | 101 | ||
108 | try | 102 | List<string> sources = new List<string>(); |
103 | sources.Add(iniFile); | ||
104 | |||
105 | int sourceIndex = 1; | ||
106 | |||
107 | while (AddIncludes(Config, sources)) | ||
109 | { | 108 | { |
110 | if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && | 109 | for ( ; sourceIndex < sources.Count ; ++sourceIndex) |
111 | configUri.Scheme == Uri.UriSchemeHttp) | ||
112 | { | 110 | { |
113 | XmlReader r = XmlReader.Create(iniFile); | 111 | IConfigSource s = ReadConfigSource(sources[sourceIndex]); |
114 | Config = new XmlConfigSource(r); | 112 | Config.Merge(s); |
115 | } | ||
116 | else | ||
117 | { | ||
118 | Config = new IniConfigSource(iniFile); | ||
119 | } | 113 | } |
120 | } | 114 | } |
121 | catch (Exception e) | ||
122 | { | ||
123 | System.Console.WriteLine("Error reading from config source. {0}", e.Message); | ||
124 | Environment.Exit(1); | ||
125 | } | ||
126 | 115 | ||
127 | // Merge OpSys env vars | 116 | // Merge OpSys env vars |
128 | m_log.Info("[CONFIG]: Loading environment variables for Config"); | 117 | Console.WriteLine("[CONFIG]: Loading environment variables for Config"); |
129 | Util.MergeEnvironmentToConfig(Config); | 118 | Util.MergeEnvironmentToConfig(Config); |
130 | 119 | ||
131 | // Merge the configuration from the command line into the loaded file | 120 | // Merge the configuration from the command line into the loaded file |
@@ -141,7 +130,7 @@ namespace OpenSim.Server.Base | |||
141 | 130 | ||
142 | if (startupConfig != null) | 131 | if (startupConfig != null) |
143 | { | 132 | { |
144 | ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); | 133 | m_configDirectory = startupConfig.GetString("ConfigDirectory", m_configDirectory); |
145 | 134 | ||
146 | prompt = startupConfig.GetString("Prompt", prompt); | 135 | prompt = startupConfig.GetString("Prompt", prompt); |
147 | } | 136 | } |
@@ -241,5 +230,114 @@ namespace OpenSim.Server.Base | |||
241 | protected virtual void Initialise() | 230 | protected virtual void Initialise() |
242 | { | 231 | { |
243 | } | 232 | } |
233 | |||
234 | /// <summary> | ||
235 | /// Adds the included files as ini configuration files | ||
236 | /// </summary> | ||
237 | /// <param name="sources">List of URL strings or filename strings</param> | ||
238 | private bool AddIncludes(IConfigSource configSource, List<string> sources) | ||
239 | { | ||
240 | bool sourcesAdded = false; | ||
241 | |||
242 | //loop over config sources | ||
243 | foreach (IConfig config in configSource.Configs) | ||
244 | { | ||
245 | // Look for Include-* in the key name | ||
246 | string[] keys = config.GetKeys(); | ||
247 | foreach (string k in keys) | ||
248 | { | ||
249 | if (k.StartsWith("Include-")) | ||
250 | { | ||
251 | // read the config file to be included. | ||
252 | string file = config.GetString(k); | ||
253 | if (IsUri(file)) | ||
254 | { | ||
255 | if (!sources.Contains(file)) | ||
256 | { | ||
257 | sourcesAdded = true; | ||
258 | sources.Add(file); | ||
259 | } | ||
260 | } | ||
261 | else | ||
262 | { | ||
263 | string basepath = Path.GetFullPath(m_configDirectory); | ||
264 | // Resolve relative paths with wildcards | ||
265 | string chunkWithoutWildcards = file; | ||
266 | string chunkWithWildcards = string.Empty; | ||
267 | int wildcardIndex = file.IndexOfAny(new char[] { '*', '?' }); | ||
268 | if (wildcardIndex != -1) | ||
269 | { | ||
270 | chunkWithoutWildcards = file.Substring(0, wildcardIndex); | ||
271 | chunkWithWildcards = file.Substring(wildcardIndex); | ||
272 | } | ||
273 | string path = Path.Combine(basepath, chunkWithoutWildcards); | ||
274 | path = Path.GetFullPath(path) + chunkWithWildcards; | ||
275 | string[] paths = Util.Glob(path); | ||
276 | |||
277 | // If the include path contains no wildcards, then warn the user that it wasn't found. | ||
278 | if (wildcardIndex == -1 && paths.Length == 0) | ||
279 | { | ||
280 | Console.WriteLine("[CONFIG]: Could not find include file {0}", path); | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | foreach (string p in paths) | ||
285 | { | ||
286 | if (!sources.Contains(p)) | ||
287 | { | ||
288 | sourcesAdded = true; | ||
289 | sources.Add(p); | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | } | ||
295 | } | ||
296 | } | ||
297 | |||
298 | return sourcesAdded; | ||
299 | } | ||
300 | |||
301 | /// <summary> | ||
302 | /// Check if we can convert the string to a URI | ||
303 | /// </summary> | ||
304 | /// <param name="file">String uri to the remote resource</param> | ||
305 | /// <returns>true if we can convert the string to a Uri object</returns> | ||
306 | bool IsUri(string file) | ||
307 | { | ||
308 | Uri configUri; | ||
309 | |||
310 | return Uri.TryCreate(file, UriKind.Absolute, | ||
311 | out configUri) && configUri.Scheme == Uri.UriSchemeHttp; | ||
312 | } | ||
313 | |||
314 | IConfigSource ReadConfigSource(string iniFile) | ||
315 | { | ||
316 | // Find out of the file name is a URI and remote load it if possible. | ||
317 | // Load it as a local file otherwise. | ||
318 | Uri configUri; | ||
319 | IConfigSource s = null; | ||
320 | |||
321 | try | ||
322 | { | ||
323 | if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && | ||
324 | configUri.Scheme == Uri.UriSchemeHttp) | ||
325 | { | ||
326 | XmlReader r = XmlReader.Create(iniFile); | ||
327 | s = new XmlConfigSource(r); | ||
328 | } | ||
329 | else | ||
330 | { | ||
331 | s = new IniConfigSource(iniFile); | ||
332 | } | ||
333 | } | ||
334 | catch (Exception e) | ||
335 | { | ||
336 | System.Console.WriteLine("Error reading from config source. {0}", e.Message); | ||
337 | Environment.Exit(1); | ||
338 | } | ||
339 | |||
340 | return s; | ||
341 | } | ||
244 | } | 342 | } |
245 | } \ No newline at end of file | 343 | } |