aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Application
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-21 23:06:10 +0000
committerMelanie Thielker2009-05-21 23:06:10 +0000
commite5f3337c3fd4266d06e6e75ad3bf7cbcd68163ca (patch)
tree8c5b310195e071ff6c51ca657e28e5cb19a7985f /OpenSim/Region/Application
parent* Upgraded LLStandaloneLoginModule, LLProxyLoginModule and LLClientStackModul... (diff)
downloadopensim-SC_OLD-e5f3337c3fd4266d06e6e75ad3bf7cbcd68163ca.zip
opensim-SC_OLD-e5f3337c3fd4266d06e6e75ad3bf7cbcd68163ca.tar.gz
opensim-SC_OLD-e5f3337c3fd4266d06e6e75ad3bf7cbcd68163ca.tar.bz2
opensim-SC_OLD-e5f3337c3fd4266d06e6e75ad3bf7cbcd68163ca.tar.xz
Implement .ini file includes. Anything that begins with "Include-" will be
treated as another ini source to load. For example: Include-Asset = AssetSetup.ini will load AssetSetup.ini after all other ini files are done. This works recursively, too
Diffstat (limited to 'OpenSim/Region/Application')
-rw-r--r--OpenSim/Region/Application/ConfigurationLoader.cs208
-rw-r--r--OpenSim/Region/Application/OpenSim.cs5
2 files changed, 132 insertions, 81 deletions
diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs
index 467b099..b317db5 100644
--- a/OpenSim/Region/Application/ConfigurationLoader.cs
+++ b/OpenSim/Region/Application/ConfigurationLoader.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.IO; 30using System.IO;
30using System.Reflection; 31using System.Reflection;
31using System.Threading; 32using System.Threading;
@@ -42,100 +43,120 @@ namespace OpenSim
42 protected OpenSimConfigSource m_config; 43 protected OpenSimConfigSource m_config;
43 protected NetworkServersInfo m_networkServersInfo; 44 protected NetworkServersInfo m_networkServersInfo;
44 45
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
46 49
47 public ConfigurationLoader() 50 public ConfigurationLoader()
48 { 51 {
49 } 52 }
50 53
51 public OpenSimConfigSource LoadConfigSettings(IConfigSource configSource, out ConfigSettings configSettings, 54 public OpenSimConfigSource LoadConfigSettings(
52 out NetworkServersInfo networkInfo) 55 IConfigSource argvSource, out ConfigSettings configSettings,
56 out NetworkServersInfo networkInfo)
53 { 57 {
54 m_configSettings = configSettings = new ConfigSettings(); 58 m_configSettings = configSettings = new ConfigSettings();
55 m_networkServersInfo = networkInfo = new NetworkServersInfo(); 59 m_networkServersInfo = networkInfo = new NetworkServersInfo();
60
56 bool iniFileExists = false; 61 bool iniFileExists = false;
57 62
58 IConfig startupConfig = configSource.Configs["Startup"]; 63 IConfig startupConfig = argvSource.Configs["Startup"];
59 64
60 string iniFileName = startupConfig.GetString("inifile", "OpenSim.ini"); 65 List<string> sources = new List<string>();
61 Application.iniFilePath = Path.Combine(Util.configDir(), iniFileName);
62 66
63 string masterFileName = startupConfig.GetString("inimaster", ""); 67 string masterFileName =
64 string masterfilePath = Path.Combine(Util.configDir(), masterFileName); 68 startupConfig.GetString("inimaster", String.Empty);
65 69
66 string iniDirName = startupConfig.GetString("inidirectory", "config"); 70 if (IsUri(masterFileName))
67 //string iniDirPath = Path.Combine(Util.configDir(), iniDirName); 71 {
72 if (!sources.Contains(masterFileName))
73 sources.Add(masterFileName);
74 }
75 else
76 {
77 string masterFilePath = Path.GetFullPath(
78 Path.Combine(Util.configDir(), masterFileName));
68 79
69 m_config = new OpenSimConfigSource(); 80 if (masterFileName != String.Empty &&
70 m_config.Source = new IniConfigSource(); 81 File.Exists(masterFilePath) &&
71 m_config.Source.Merge(DefaultConfig()); 82 (!sources.Contains(masterFilePath)))
83 sources.Add(masterFilePath);
84 }
72 85
73 m_log.Info("[CONFIG] Reading configuration settings");
74 86
75 Uri configUri; 87 string iniFileName =
76 String xmlPath = Path.Combine(Util.configDir(), "OpenSim.xml"); 88 startupConfig.GetString("inifile", "OpenSim.ini");
77 89
78 //check for master .INI file (name passed in command line, no default), or XML over http 90 if (IsUri(iniFileName))
79 if (masterFileName.Length > 0) // If a master file name is given ...
80 { 91 {
81 m_log.InfoFormat("[CONFIG] Reading config master file {0}", masterfilePath); 92 if (!sources.Contains(iniFileName))
93 sources.Add(iniFileName);
94 Application.iniFilePath = iniFileName;
95 }
96 else
97 {
98 Application.iniFilePath = Path.GetFullPath(
99 Path.Combine(Util.configDir(), iniFileName));
82 100
83 bool isMasterUri = Uri.TryCreate(masterFileName, UriKind.Absolute, out configUri) && 101 if (!File.Exists(Application.iniFilePath))
84 configUri.Scheme == Uri.UriSchemeHttp; 102 {
103 iniFileName = "OpenSim.xml";
104 Application.iniFilePath = Path.GetFullPath(
105 Path.Combine(Util.configDir(), iniFileName));
106 }
85 107
86 if (!ReadConfig(masterFileName, masterfilePath, m_config, isMasterUri)) 108 if (File.Exists(Application.iniFilePath))
87 { 109 {
88 m_log.FatalFormat("[CONFIG] Could not open master config file {0}", masterfilePath); 110 if (!sources.Contains(Application.iniFilePath))
111 sources.Add(Application.iniFilePath);
89 } 112 }
90 } 113 }
91 114
92 if (Directory.Exists(iniDirName)) 115 string iniDirName =
116 startupConfig.GetString("inidirectory", "config");
117 string iniDirPath =
118 Path.Combine(Util.configDir(), iniDirName);
119
120 if (Directory.Exists(iniDirPath))
93 { 121 {
94 m_log.InfoFormat("Searching folder: {0} , for config ini files", iniDirName); 122 m_log.InfoFormat("Searching folder {0} for config ini files",
123 iniDirPath);
124
95 string[] fileEntries = Directory.GetFiles(iniDirName); 125 string[] fileEntries = Directory.GetFiles(iniDirName);
96 foreach (string filePath in fileEntries) 126 foreach (string filePath in fileEntries)
97 { 127 {
98 if (Path.GetExtension(filePath).ToLower() == ".ini") 128 if (Path.GetExtension(filePath).ToLower() == ".ini")
99 { 129 {
100 // m_log.InfoFormat("reading ini file < {0} > from config dir", filePath); 130 if (!sources.Contains(Path.GetFullPath(filePath)))
101 ReadConfig(Path.GetFileName(filePath), filePath, m_config, false); 131 sources.Add(Path.GetFullPath(filePath));
102 } 132 }
103 } 133 }
104 } 134 }
105 135
106 // Check for .INI file (either default or name passed on command 136 m_config = new OpenSimConfigSource();
107 // line) or XML config source over http 137 m_config.Source = new IniConfigSource();
108 bool isIniUri = Uri.TryCreate(iniFileName, UriKind.Absolute, out configUri) && 138 m_config.Source.Merge(DefaultConfig());
109 configUri.Scheme == Uri.UriSchemeHttp;
110 iniFileExists = ReadConfig(iniFileName, Application.iniFilePath, m_config, isIniUri);
111 139
112 if (!iniFileExists) 140 m_log.Info("[CONFIG] Reading configuration settings");
141
142 if (sources.Count == 0)
113 { 143 {
114 // check for a xml config file 144 m_log.FatalFormat("[CONFIG] Could not load any configuration");
115 if (File.Exists(xmlPath)) 145 m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
116 { 146 Environment.Exit(1);
117 Application.iniFilePath = xmlPath; 147 }
118 148
119 m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath)); 149 for (int i = 0 ; i < sources.Count ; i++)
150 {
151 if (ReadConfig(sources[i]))
120 iniFileExists = true; 152 iniFileExists = true;
121 153 AddIncludes(sources);
122 m_config.Source = new XmlConfigSource();
123 m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath));
124 }
125 } 154 }
126 155
127 m_config.Source.Merge(configSource);
128
129 if (!iniFileExists) 156 if (!iniFileExists)
130 { 157 {
131 m_log.FatalFormat("[CONFIG] Could not load any configuration"); 158 m_log.FatalFormat("[CONFIG] Could not load any configuration");
132 if (!isIniUri) 159 m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!");
133 m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(Application.iniFilePath));
134 else
135 m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", iniFileName);
136 m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath));
137
138 m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
139 Environment.Exit(1); 160 Environment.Exit(1);
140 } 161 }
141 162
@@ -144,48 +165,81 @@ namespace OpenSim
144 return m_config; 165 return m_config;
145 } 166 }
146 167
168 private void AddIncludes(List<string> sources)
169 {
170 foreach (IConfig config in m_config.Source.Configs)
171 {
172 string[] keys = config.GetKeys();
173 foreach (string k in keys)
174 {
175 if (k.StartsWith("Include-"))
176 {
177 string file = config.GetString(k);
178 if (IsUri(file))
179 {
180 if (!sources.Contains(file))
181 sources.Add(file);
182 }
183 else
184 {
185 string path = Path.GetFullPath(
186 Path.Combine(Util.configDir(), file));
187 if (File.Exists(path))
188 {
189 if (!sources.Contains(path))
190 sources.Add(path);
191 }
192 }
193 }
194 }
195 }
196 }
197
198 bool IsUri(string file)
199 {
200 Uri configUri;
201
202 return Uri.TryCreate(file, UriKind.Absolute,
203 out configUri) && configUri.Scheme == Uri.UriSchemeHttp;
204 }
205
147 /// <summary> 206 /// <summary>
148 /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http 207 /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
149 /// </summary> 208 /// </summary>
150 /// <param name="iniName">The name of the ini to load</param>
151 /// <param name="iniPath">Full path to the ini</param> 209 /// <param name="iniPath">Full path to the ini</param>
152 /// <param name="m_config">The current configuration source</param>
153 /// <param name="isUri">Boolean representing whether the ini source is a URI path over http or a file on the system</param>
154 /// <returns></returns> 210 /// <returns></returns>
155 private bool ReadConfig(string iniName, string iniPath, OpenSimConfigSource m_config, bool isUri) 211 private bool ReadConfig(string iniPath)
156 { 212 {
157 bool success = false; 213 bool success = false;
158 214
159 if (!isUri && File.Exists(iniPath)) 215 if (!IsUri(iniPath))
160 { 216 {
161 m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(iniPath)); 217 m_log.InfoFormat("[CONFIG] Reading configuration file {0}",
218 Path.GetFullPath(iniPath));
162 219
163 // From reading Nini's code, it seems that later merged keys replace earlier ones.
164 m_config.Source.Merge(new IniConfigSource(iniPath)); 220 m_config.Source.Merge(new IniConfigSource(iniPath));
165 success = true; 221 success = true;
166 } 222 }
167 else 223 else
168 { 224 {
169 if (isUri) 225 m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...",
170 { 226 iniPath);
171 m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", iniName);
172 227
173 // The ini file path is a http URI 228 // The ini file path is a http URI
174 // Try to read it 229 // Try to read it
175 try 230 //
176 { 231 try
177 XmlReader r = XmlReader.Create(iniName); 232 {
178 XmlConfigSource cs = new XmlConfigSource(r); 233 XmlReader r = XmlReader.Create(iniPath);
179 m_config.Source.Merge(cs); 234 XmlConfigSource cs = new XmlConfigSource(r);
235 m_config.Source.Merge(cs);
180 236
181 success = true; 237 success = true;
182 m_log.InfoFormat("[CONFIG] Loaded config from {0}", iniName); 238 }
183 } 239 catch (Exception e)
184 catch (Exception e) 240 {
185 { 241 m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath);
186 m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniName); 242 Environment.Exit(1);
187 Environment.Exit(1);
188 }
189 } 243 }
190 } 244 }
191 return success; 245 return success;
@@ -195,7 +249,7 @@ namespace OpenSim
195 /// Setup a default config values in case they aren't present in the ini file 249 /// Setup a default config values in case they aren't present in the ini file
196 /// </summary> 250 /// </summary>
197 /// <returns></returns> 251 /// <returns></returns>
198 public static IConfigSource DefaultConfig() 252 private static IConfigSource DefaultConfig()
199 { 253 {
200 IConfigSource defaultConfig = new IniConfigSource(); 254 IConfigSource defaultConfig = new IniConfigSource();
201 255
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 6c1fee5..1084174 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -490,9 +490,6 @@ namespace OpenSim
490 } 490 }
491 else 491 else
492 { 492 {
493 // IConfig c = DefaultConfig().Configs[cmdparams[1]];
494 // if (c == null)
495 // c = DefaultConfig().AddConfig(cmdparams[1]);
496 IConfig c; 493 IConfig c;
497 IConfigSource source = new IniConfigSource(); 494 IConfigSource source = new IniConfigSource();
498 c = source.AddConfig(cmdparams[1]); 495 c = source.AddConfig(cmdparams[1]);
@@ -516,7 +513,7 @@ namespace OpenSim
516 } 513 }
517 else 514 else
518 { 515 {
519 IConfig c = m_config.Source.Configs[cmdparams[1]]; // DefaultConfig().Configs[cmdparams[1]]; 516 IConfig c = m_config.Source.Configs[cmdparams[1]];
520 if (c == null) 517 if (c == null)
521 { 518 {
522 m_log.Info("Section \"" + cmdparams[1] + "\" does not exist."); 519 m_log.Info("Section \"" + cmdparams[1] + "\" does not exist.");