clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using System.IO;
31 using System.Reflection;
32 using System.Threading;
33 using System.Xml;
34 using log4net;
35 using Nini.Config;
36  
37 namespace OpenSim.Tools.Configger
38 {
39 /// <summary>
40 /// Loads the Configuration files into nIni
41 /// </summary>
42 public class ConfigurationLoader
43 {
44 /// <summary>
45 /// A source of Configuration data
46 /// </summary>
47 protected IConfigSource m_config;
48  
49 /// <summary>
50 /// Console logger
51 /// </summary>
52 private static readonly ILog m_log =
53 LogManager.GetLogger(
54 MethodBase.GetCurrentMethod().DeclaringType);
55  
56 public ConfigurationLoader()
57 {
58 }
59  
60 /// <summary>
61 /// Loads the region configuration
62 /// </summary>
63 /// <param name="argvSource">Parameters passed into the process when started</param>
64 /// <param name="configSettings"></param>
65 /// <param name="networkInfo"></param>
66 /// <returns>A configuration that gets passed to modules</returns>
67 public IConfigSource LoadConfigSettings(IConfig startupConfig)
68 {
69 bool iniFileExists = false;
70  
71 List<string> sources = new List<string>();
72  
73 string iniFileName = startupConfig.GetString("inifile", Path.Combine(".", "OpenSim.ini"));
74  
75 if (IsUri(iniFileName))
76 {
77 if (!sources.Contains(iniFileName))
78 sources.Add(iniFileName);
79 }
80 else
81 {
82 if (File.Exists(iniFileName))
83 {
84 if (!sources.Contains(iniFileName))
85 sources.Add(iniFileName);
86 }
87 }
88  
89 m_config = new IniConfigSource();
90 m_config.Merge(DefaultConfig());
91  
92 m_log.Info("[CONFIG] Reading configuration settings");
93  
94 if (sources.Count == 0)
95 {
96 m_log.FatalFormat("[CONFIG] Could not load any configuration");
97 m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
98 Environment.Exit(1);
99 }
100  
101 for (int i = 0 ; i < sources.Count ; i++)
102 {
103 if (ReadConfig(sources[i]))
104 iniFileExists = true;
105 AddIncludes(sources);
106 }
107  
108 if (!iniFileExists)
109 {
110 m_log.FatalFormat("[CONFIG] Could not load any configuration");
111 m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!");
112 Environment.Exit(1);
113 }
114  
115 return m_config;
116 }
117  
118 /// <summary>
119 /// Adds the included files as ini configuration files
120 /// </summary>
121 /// <param name="sources">List of URL strings or filename strings</param>
122 private void AddIncludes(List<string> sources)
123 {
124 //loop over config sources
125 foreach (IConfig config in m_config.Configs)
126 {
127 // Look for Include-* in the key name
128 string[] keys = config.GetKeys();
129 foreach (string k in keys)
130 {
131 if (k.StartsWith("Include-"))
132 {
133 // read the config file to be included.
134 string file = config.GetString(k);
135 if (IsUri(file))
136 {
137 if (!sources.Contains(file))
138 sources.Add(file);
139 }
140 else
141 {
142 string basepath = Path.GetFullPath(".");
143 // Resolve relative paths with wildcards
144 string chunkWithoutWildcards = file;
145 string chunkWithWildcards = string.Empty;
146 int wildcardIndex = file.IndexOfAny(new char[] { '*', '?' });
147 if (wildcardIndex != -1)
148 {
149 chunkWithoutWildcards = file.Substring(0, wildcardIndex);
150 chunkWithWildcards = file.Substring(wildcardIndex);
151 }
152 string path = Path.Combine(basepath, chunkWithoutWildcards);
153 path = Path.GetFullPath(path) + chunkWithWildcards;
154 string[] paths = Util.Glob(path);
155 foreach (string p in paths)
156 {
157 if (!sources.Contains(p))
158 sources.Add(p);
159 }
160 }
161 }
162 }
163 }
164 }
165 /// <summary>
166 /// Check if we can convert the string to a URI
167 /// </summary>
168 /// <param name="file">String uri to the remote resource</param>
169 /// <returns>true if we can convert the string to a Uri object</returns>
170 bool IsUri(string file)
171 {
172 Uri configUri;
173  
174 return Uri.TryCreate(file, UriKind.Absolute,
175 out configUri) && configUri.Scheme == Uri.UriSchemeHttp;
176 }
177  
178 /// <summary>
179 /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
180 /// </summary>
181 /// <param name="iniPath">Full path to the ini</param>
182 /// <returns></returns>
183 private bool ReadConfig(string iniPath)
184 {
185 bool success = false;
186  
187 if (!IsUri(iniPath))
188 {
189 m_log.InfoFormat("[CONFIG] Reading configuration file {0}",
190 Path.GetFullPath(iniPath));
191  
192 m_config.Merge(new IniConfigSource(iniPath));
193 success = true;
194 }
195 else
196 {
197 m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...",
198 iniPath);
199  
200 // The ini file path is a http URI
201 // Try to read it
202 //
203 try
204 {
205 XmlReader r = XmlReader.Create(iniPath);
206 XmlConfigSource cs = new XmlConfigSource(r);
207 m_config.Merge(cs);
208  
209 success = true;
210 }
211 catch (Exception e)
212 {
213 m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath);
214 Environment.Exit(1);
215 }
216 }
217 return success;
218 }
219  
220 /// <summary>
221 /// Setup a default config values in case they aren't present in the ini file
222 /// </summary>
223 /// <returns>A Configuration source containing the default configuration</returns>
224 private static IConfigSource DefaultConfig()
225 {
226 IConfigSource defaultConfig = new IniConfigSource();
227  
228 {
229 IConfig config = defaultConfig.Configs["Startup"];
230  
231 if (null == config)
232 config = defaultConfig.AddConfig("Startup");
233  
234 config.Set("region_info_source", "filesystem");
235 config.Set("allow_regionless", false);
236  
237 config.Set("gridmode", false);
238 config.Set("physics", "OpenDynamicsEngine");
239 config.Set("meshing", "Meshmerizer");
240 config.Set("physical_prim", true);
241 config.Set("serverside_object_permissions", true);
242 config.Set("storage_prim_inventories", true);
243 config.Set("startup_console_commands_file", String.Empty);
244 config.Set("shutdown_console_commands_file", String.Empty);
245 config.Set("DefaultScriptEngine", "XEngine");
246 config.Set("clientstack_plugin", "OpenSim.Region.ClientStack.LindenUDP.dll");
247 // life doesn't really work without this
248 config.Set("EventQueue", true);
249 }
250  
251 return defaultConfig;
252 }
253 }
254 }