aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General/Configuration/ConfigurationMember.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/General/Configuration/ConfigurationMember.cs')
-rw-r--r--OpenSim/Framework/General/Configuration/ConfigurationMember.cs758
1 files changed, 379 insertions, 379 deletions
diff --git a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs
index b8dfc0c..eb5465f 100644
--- a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs
+++ b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs
@@ -1,379 +1,379 @@
1using System; 1using System;
2using System.Reflection; 2using System.Reflection;
3using System.Collections; 3using System.Collections;
4using System.Collections.Generic; 4using System.Collections.Generic;
5using System.Text; 5using System.Text;
6using System.Net; 6using System.Net;
7 7
8using libsecondlife; 8using libsecondlife;
9 9
10using OpenSim.Framework.Console; 10using OpenSim.Framework.Console;
11using OpenSim.Framework.Configuration.Interfaces; 11using OpenSim.Framework.Configuration.Interfaces;
12 12
13namespace OpenSim.Framework.Configuration 13namespace OpenSim.Framework.Configuration
14{ 14{
15 public class ConfigurationMember 15 public class ConfigurationMember
16 { 16 {
17 public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result); 17 public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result);
18 public delegate void ConfigurationOptionsLoad(); 18 public delegate void ConfigurationOptionsLoad();
19 19
20 private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>(); 20 private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>();
21 private string configurationFilename = ""; 21 private string configurationFilename = "";
22 private string configurationDescription = ""; 22 private string configurationDescription = "";
23 23
24 private ConfigurationOptionsLoad loadFunction; 24 private ConfigurationOptionsLoad loadFunction;
25 private ConfigurationOptionResult resultFunction; 25 private ConfigurationOptionResult resultFunction;
26 26
27 private IGenericConfig configurationPlugin = null; 27 private IGenericConfig configurationPlugin = null;
28 /// <summary> 28 /// <summary>
29 /// This is the default configuration DLL loaded 29 /// This is the default configuration DLL loaded
30 /// </summary> 30 /// </summary>
31 private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll"; 31 private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll";
32 public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) 32 public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function)
33 { 33 {
34 this.configurationFilename = configuration_filename; 34 this.configurationFilename = configuration_filename;
35 this.configurationDescription = configuration_description; 35 this.configurationDescription = configuration_description;
36 this.loadFunction = load_function; 36 this.loadFunction = load_function;
37 this.resultFunction = result_function; 37 this.resultFunction = result_function;
38 } 38 }
39 39
40 public void setConfigurationFilename(string filename) 40 public void setConfigurationFilename(string filename)
41 { 41 {
42 configurationFilename = filename; 42 configurationFilename = filename;
43 } 43 }
44 public void setConfigurationDescription(string desc) 44 public void setConfigurationDescription(string desc)
45 { 45 {
46 configurationDescription = desc; 46 configurationDescription = desc;
47 } 47 }
48 48
49 public void setConfigurationResultFunction(ConfigurationOptionResult result) 49 public void setConfigurationResultFunction(ConfigurationOptionResult result)
50 { 50 {
51 resultFunction = result; 51 resultFunction = result;
52 } 52 }
53 53
54 public void forceConfigurationPluginLibrary(string dll_filename) 54 public void forceConfigurationPluginLibrary(string dll_filename)
55 { 55 {
56 configurationPluginFilename = dll_filename; 56 configurationPluginFilename = dll_filename;
57 } 57 }
58 public void addConfigurationOption(string configuration_key, ConfigurationOption.ConfigurationTypes configuration_type, string configuration_question, string configuration_default, bool use_default_no_prompt) 58 public void addConfigurationOption(string configuration_key, ConfigurationOption.ConfigurationTypes configuration_type, string configuration_question, string configuration_default, bool use_default_no_prompt)
59 { 59 {
60 ConfigurationOption configOption = new ConfigurationOption(); 60 ConfigurationOption configOption = new ConfigurationOption();
61 configOption.configurationKey = configuration_key; 61 configOption.configurationKey = configuration_key;
62 configOption.configurationQuestion = configuration_question; 62 configOption.configurationQuestion = configuration_question;
63 configOption.configurationDefault = configuration_default; 63 configOption.configurationDefault = configuration_default;
64 configOption.configurationType = configuration_type; 64 configOption.configurationType = configuration_type;
65 configOption.configurationUseDefaultNoPrompt = use_default_no_prompt; 65 configOption.configurationUseDefaultNoPrompt = use_default_no_prompt;
66 66
67 if (configuration_key != "" && configuration_question != "") 67 if (configuration_key != "" && configuration_question != "")
68 { 68 {
69 if (!configurationOptions.Contains(configOption)) 69 if (!configurationOptions.Contains(configOption))
70 { 70 {
71 configurationOptions.Add(configOption); 71 configurationOptions.Add(configOption);
72 } 72 }
73 } 73 }
74 else 74 else
75 { 75 {
76 MainLog.Instance.Notice("Required fields for adding a configuration option is invalid. Will not add this option (" + configuration_key + ")"); 76 MainLog.Instance.Notice("Required fields for adding a configuration option is invalid. Will not add this option (" + configuration_key + ")");
77 } 77 }
78 } 78 }
79 79
80 public void performConfigurationRetrieve() 80 public void performConfigurationRetrieve()
81 { 81 {
82 configurationPlugin = this.LoadConfigDll(configurationPluginFilename); 82 configurationPlugin = this.LoadConfigDll(configurationPluginFilename);
83 configurationOptions.Clear(); 83 configurationOptions.Clear();
84 if(loadFunction == null) 84 if(loadFunction == null)
85 { 85 {
86 MainLog.Instance.Error("Load Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); 86 MainLog.Instance.Error("Load Function for '" + this.configurationDescription + "' is null. Refusing to run configuration.");
87 return; 87 return;
88 } 88 }
89 89
90 if(resultFunction == null) 90 if(resultFunction == null)
91 { 91 {
92 MainLog.Instance.Error("Result Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); 92 MainLog.Instance.Error("Result Function for '" + this.configurationDescription + "' is null. Refusing to run configuration.");
93 return; 93 return;
94 } 94 }
95 95
96 MainLog.Instance.Verbose("Calling Configuration Load Function..."); 96 MainLog.Instance.Verbose("Calling Configuration Load Function...");
97 this.loadFunction(); 97 this.loadFunction();
98 98
99 if(configurationOptions.Count <= 0) 99 if(configurationOptions.Count <= 0)
100 { 100 {
101 MainLog.Instance.Error("No configuration options were specified for '" + this.configurationOptions + "'. Refusing to continue configuration."); 101 MainLog.Instance.Error("No configuration options were specified for '" + this.configurationOptions + "'. Refusing to continue configuration.");
102 return; 102 return;
103 } 103 }
104 104
105 bool useFile = true; 105 bool useFile = true;
106 if (configurationPlugin == null) 106 if (configurationPlugin == null)
107 { 107 {
108 MainLog.Instance.Error("Configuration Plugin NOT LOADED!"); 108 MainLog.Instance.Error("Configuration Plugin NOT LOADED!");
109 return; 109 return;
110 } 110 }
111 111
112 if (configurationFilename.Trim() != "") 112 if (configurationFilename.Trim() != "")
113 { 113 {
114 configurationPlugin.SetFileName(configurationFilename); 114 configurationPlugin.SetFileName(configurationFilename);
115 configurationPlugin.LoadData(); 115 configurationPlugin.LoadData();
116 useFile = true; 116 useFile = true;
117 } 117 }
118 118
119 else 119 else
120 { 120 {
121 MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file."); 121 MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file.");
122 useFile = false; 122 useFile = false;
123 } 123 }
124 124
125 foreach (ConfigurationOption configOption in configurationOptions) 125 foreach (ConfigurationOption configOption in configurationOptions)
126 { 126 {
127 bool convertSuccess = false; 127 bool convertSuccess = false;
128 object return_result = null; 128 object return_result = null;
129 string errorMessage = ""; 129 string errorMessage = "";
130 bool ignoreNextFromConfig = false; 130 bool ignoreNextFromConfig = false;
131 while (convertSuccess == false) 131 while (convertSuccess == false)
132 { 132 {
133 133
134 string console_result = ""; 134 string console_result = "";
135 string attribute = null; 135 string attribute = null;
136 if (useFile) 136 if (useFile)
137 { 137 {
138 if (!ignoreNextFromConfig) 138 if (!ignoreNextFromConfig)
139 { 139 {
140 attribute = configurationPlugin.GetAttribute(configOption.configurationKey); 140 attribute = configurationPlugin.GetAttribute(configOption.configurationKey);
141 } 141 }
142 else 142 else
143 { 143 {
144 ignoreNextFromConfig = false; 144 ignoreNextFromConfig = false;
145 } 145 }
146 } 146 }
147 147
148 if (attribute == null) 148 if (attribute == null)
149 { 149 {
150 if (configOption.configurationUseDefaultNoPrompt) 150 if (configOption.configurationUseDefaultNoPrompt)
151 { 151 {
152 console_result = configOption.configurationDefault; 152 console_result = configOption.configurationDefault;
153 } 153 }
154 else 154 else
155 { 155 {
156 156
157 if (configurationDescription.Trim() != "") 157 if (configurationDescription.Trim() != "")
158 { 158 {
159 console_result = MainLog.Instance.CmdPrompt(configurationDescription + ": " + configOption.configurationQuestion, configOption.configurationDefault); 159 console_result = MainLog.Instance.CmdPrompt(configurationDescription + ": " + configOption.configurationQuestion, configOption.configurationDefault);
160 } 160 }
161 else 161 else
162 { 162 {
163 console_result = MainLog.Instance.CmdPrompt(configOption.configurationQuestion, configOption.configurationDefault); 163 console_result = MainLog.Instance.CmdPrompt(configOption.configurationQuestion, configOption.configurationDefault);
164 } 164 }
165 } 165 }
166 } 166 }
167 else 167 else
168 { 168 {
169 console_result = attribute; 169 console_result = attribute;
170 } 170 }
171 171
172 switch (configOption.configurationType) 172 switch (configOption.configurationType)
173 { 173 {
174 case ConfigurationOption.ConfigurationTypes.TYPE_STRING: 174 case ConfigurationOption.ConfigurationTypes.TYPE_STRING:
175 return_result = console_result; 175 return_result = console_result;
176 convertSuccess = true; 176 convertSuccess = true;
177 break; 177 break;
178 case ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY: 178 case ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY:
179 if (console_result.Length > 0) 179 if (console_result.Length > 0)
180 { 180 {
181 return_result = console_result; 181 return_result = console_result;
182 convertSuccess = true; 182 convertSuccess = true;
183 } 183 }
184 errorMessage = "a string that is not empty"; 184 errorMessage = "a string that is not empty";
185 break; 185 break;
186 case ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN: 186 case ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN:
187 bool boolResult; 187 bool boolResult;
188 if (Boolean.TryParse(console_result, out boolResult)) 188 if (Boolean.TryParse(console_result, out boolResult))
189 { 189 {
190 convertSuccess = true; 190 convertSuccess = true;
191 return_result = boolResult; 191 return_result = boolResult;
192 } 192 }
193 errorMessage = "'true' or 'false' (Boolean)"; 193 errorMessage = "'true' or 'false' (Boolean)";
194 break; 194 break;
195 case ConfigurationOption.ConfigurationTypes.TYPE_BYTE: 195 case ConfigurationOption.ConfigurationTypes.TYPE_BYTE:
196 byte byteResult; 196 byte byteResult;
197 if (Byte.TryParse(console_result, out byteResult)) 197 if (Byte.TryParse(console_result, out byteResult))
198 { 198 {
199 convertSuccess = true; 199 convertSuccess = true;
200 return_result = byteResult; 200 return_result = byteResult;
201 } 201 }
202 errorMessage = "a byte (Byte)"; 202 errorMessage = "a byte (Byte)";
203 break; 203 break;
204 case ConfigurationOption.ConfigurationTypes.TYPE_CHARACTER: 204 case ConfigurationOption.ConfigurationTypes.TYPE_CHARACTER:
205 char charResult; 205 char charResult;
206 if (Char.TryParse(console_result, out charResult)) 206 if (Char.TryParse(console_result, out charResult))
207 { 207 {
208 convertSuccess = true; 208 convertSuccess = true;
209 return_result = charResult; 209 return_result = charResult;
210 } 210 }
211 errorMessage = "a character (Char)"; 211 errorMessage = "a character (Char)";
212 break; 212 break;
213 case ConfigurationOption.ConfigurationTypes.TYPE_INT16: 213 case ConfigurationOption.ConfigurationTypes.TYPE_INT16:
214 short shortResult; 214 short shortResult;
215 if (Int16.TryParse(console_result, out shortResult)) 215 if (Int16.TryParse(console_result, out shortResult))
216 { 216 {
217 convertSuccess = true; 217 convertSuccess = true;
218 return_result = shortResult; 218 return_result = shortResult;
219 } 219 }
220 errorMessage = "a signed 32 bit integer (short)"; 220 errorMessage = "a signed 32 bit integer (short)";
221 break; 221 break;
222 case ConfigurationOption.ConfigurationTypes.TYPE_INT32: 222 case ConfigurationOption.ConfigurationTypes.TYPE_INT32:
223 int intResult; 223 int intResult;
224 if (Int32.TryParse(console_result, out intResult)) 224 if (Int32.TryParse(console_result, out intResult))
225 { 225 {
226 convertSuccess = true; 226 convertSuccess = true;
227 return_result = intResult; 227 return_result = intResult;
228 228
229 } 229 }
230 errorMessage = "a signed 32 bit integer (int)"; 230 errorMessage = "a signed 32 bit integer (int)";
231 break; 231 break;
232 case ConfigurationOption.ConfigurationTypes.TYPE_INT64: 232 case ConfigurationOption.ConfigurationTypes.TYPE_INT64:
233 long longResult; 233 long longResult;
234 if (Int64.TryParse(console_result, out longResult)) 234 if (Int64.TryParse(console_result, out longResult))
235 { 235 {
236 convertSuccess = true; 236 convertSuccess = true;
237 return_result = longResult; 237 return_result = longResult;
238 } 238 }
239 errorMessage = "a signed 32 bit integer (long)"; 239 errorMessage = "a signed 32 bit integer (long)";
240 break; 240 break;
241 case ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS: 241 case ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS:
242 IPAddress ipAddressResult; 242 IPAddress ipAddressResult;
243 if (IPAddress.TryParse(console_result, out ipAddressResult)) 243 if (IPAddress.TryParse(console_result, out ipAddressResult))
244 { 244 {
245 convertSuccess = true; 245 convertSuccess = true;
246 return_result = ipAddressResult; 246 return_result = ipAddressResult;
247 } 247 }
248 errorMessage = "an IP Address (IPAddress)"; 248 errorMessage = "an IP Address (IPAddress)";
249 break; 249 break;
250 case ConfigurationOption.ConfigurationTypes.TYPE_LLUUID: 250 case ConfigurationOption.ConfigurationTypes.TYPE_LLUUID:
251 LLUUID uuidResult; 251 LLUUID uuidResult;
252 if (LLUUID.TryParse(console_result, out uuidResult)) 252 if (LLUUID.TryParse(console_result, out uuidResult))
253 { 253 {
254 convertSuccess = true; 254 convertSuccess = true;
255 return_result = uuidResult; 255 return_result = uuidResult;
256 } 256 }
257 errorMessage = "a UUID (LLUUID)"; 257 errorMessage = "a UUID (LLUUID)";
258 break; 258 break;
259 case ConfigurationOption.ConfigurationTypes.TYPE_LLVECTOR3: 259 case ConfigurationOption.ConfigurationTypes.TYPE_LLVECTOR3:
260 LLVector3 vectorResult; 260 LLVector3 vectorResult;
261 if (LLVector3.TryParse(console_result, out vectorResult)) 261 if (LLVector3.TryParse(console_result, out vectorResult))
262 { 262 {
263 convertSuccess = true; 263 convertSuccess = true;
264 return_result = vectorResult; 264 return_result = vectorResult;
265 } 265 }
266 errorMessage = "a vector (LLVector3)"; 266 errorMessage = "a vector (LLVector3)";
267 break; 267 break;
268 case ConfigurationOption.ConfigurationTypes.TYPE_UINT16: 268 case ConfigurationOption.ConfigurationTypes.TYPE_UINT16:
269 ushort ushortResult; 269 ushort ushortResult;
270 if (UInt16.TryParse(console_result, out ushortResult)) 270 if (UInt16.TryParse(console_result, out ushortResult))
271 { 271 {
272 convertSuccess = true; 272 convertSuccess = true;
273 return_result = ushortResult; 273 return_result = ushortResult;
274 } 274 }
275 errorMessage = "an unsigned 16 bit integer (ushort)"; 275 errorMessage = "an unsigned 16 bit integer (ushort)";
276 break; 276 break;
277 case ConfigurationOption.ConfigurationTypes.TYPE_UINT32: 277 case ConfigurationOption.ConfigurationTypes.TYPE_UINT32:
278 uint uintResult; 278 uint uintResult;
279 if (UInt32.TryParse(console_result, out uintResult)) 279 if (UInt32.TryParse(console_result, out uintResult))
280 { 280 {
281 convertSuccess = true; 281 convertSuccess = true;
282 return_result = uintResult; 282 return_result = uintResult;
283 283
284 } 284 }
285 errorMessage = "an unsigned 32 bit integer (uint)"; 285 errorMessage = "an unsigned 32 bit integer (uint)";
286 break; 286 break;
287 case ConfigurationOption.ConfigurationTypes.TYPE_UINT64: 287 case ConfigurationOption.ConfigurationTypes.TYPE_UINT64:
288 ulong ulongResult; 288 ulong ulongResult;
289 if (UInt64.TryParse(console_result, out ulongResult)) 289 if (UInt64.TryParse(console_result, out ulongResult))
290 { 290 {
291 convertSuccess = true; 291 convertSuccess = true;
292 return_result = ulongResult; 292 return_result = ulongResult;
293 } 293 }
294 errorMessage = "an unsigned 64 bit integer (ulong)"; 294 errorMessage = "an unsigned 64 bit integer (ulong)";
295 break; 295 break;
296 case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT: 296 case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT:
297 float floatResult; 297 float floatResult;
298 if (float.TryParse(console_result, out floatResult)) 298 if (float.TryParse(console_result, out floatResult))
299 { 299 {
300 convertSuccess = true; 300 convertSuccess = true;
301 return_result = floatResult; 301 return_result = floatResult;
302 } 302 }
303 errorMessage = "a single-precision floating point number (float)"; 303 errorMessage = "a single-precision floating point number (float)";
304 break; 304 break;
305 case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE: 305 case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE:
306 double doubleResult; 306 double doubleResult;
307 if (Double.TryParse(console_result, out doubleResult)) 307 if (Double.TryParse(console_result, out doubleResult))
308 { 308 {
309 convertSuccess = true; 309 convertSuccess = true;
310 return_result = doubleResult; 310 return_result = doubleResult;
311 } 311 }
312 errorMessage = "an double-precision floating point number (double)"; 312 errorMessage = "an double-precision floating point number (double)";
313 break; 313 break;
314 } 314 }
315 315
316 if (convertSuccess) 316 if (convertSuccess)
317 { 317 {
318 if (useFile) 318 if (useFile)
319 { 319 {
320 configurationPlugin.SetAttribute(configOption.configurationKey, console_result); 320 configurationPlugin.SetAttribute(configOption.configurationKey, console_result);
321 } 321 }
322 322
323 323
324 if (!this.resultFunction(configOption.configurationKey, return_result)) 324 if (!this.resultFunction(configOption.configurationKey, return_result))
325 { 325 {
326 Console.MainLog.Instance.Notice("The handler for the last configuration option denied that input, please try again."); 326 Console.MainLog.Instance.Notice("The handler for the last configuration option denied that input, please try again.");
327 convertSuccess = false; 327 convertSuccess = false;
328 ignoreNextFromConfig = true; 328 ignoreNextFromConfig = true;
329 } 329 }
330 } 330 }
331 else 331 else
332 { 332 {
333 if (configOption.configurationUseDefaultNoPrompt) 333 if (configOption.configurationUseDefaultNoPrompt)
334 { 334 {
335 MainLog.Instance.Error("Default given for '" + configOption.configurationKey + "' is not valid; the configuration result must be " + errorMessage + ". Will skip this option..."); 335 MainLog.Instance.Error("Default given for '" + configOption.configurationKey + "' is not valid; the configuration result must be " + errorMessage + ". Will skip this option...");
336 convertSuccess = true; 336 convertSuccess = true;
337 } 337 }
338 else 338 else
339 { 339 {
340 MainLog.Instance.Warn("configuration","Incorrect result given, the configuration option must be " + errorMessage + ". Prompting for same option..."); 340 MainLog.Instance.Warn("configuration","Incorrect result given, the configuration option must be " + errorMessage + ". Prompting for same option...");
341 ignoreNextFromConfig = true; 341 ignoreNextFromConfig = true;
342 } 342 }
343 } 343 }
344 } 344 }
345 } 345 }
346 346
347 if(useFile) 347 if(useFile)
348 { 348 {
349 configurationPlugin.Commit(); 349 configurationPlugin.Commit();
350 configurationPlugin.Close(); 350 configurationPlugin.Close();
351 } 351 }
352 } 352 }
353 353
354 private IGenericConfig LoadConfigDll(string dllName) 354 private IGenericConfig LoadConfigDll(string dllName)
355 { 355 {
356 Assembly pluginAssembly = Assembly.LoadFrom(dllName); 356 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
357 IGenericConfig plug = null; 357 IGenericConfig plug = null;
358 358
359 foreach (Type pluginType in pluginAssembly.GetTypes()) 359 foreach (Type pluginType in pluginAssembly.GetTypes())
360 { 360 {
361 if (pluginType.IsPublic) 361 if (pluginType.IsPublic)
362 { 362 {
363 if (!pluginType.IsAbstract) 363 if (!pluginType.IsAbstract)
364 { 364 {
365 Type typeInterface = pluginType.GetInterface("IGenericConfig", true); 365 Type typeInterface = pluginType.GetInterface("IGenericConfig", true);
366 366
367 if (typeInterface != null) 367 if (typeInterface != null)
368 { 368 {
369 plug = (IGenericConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 369 plug = (IGenericConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
370 } 370 }
371 } 371 }
372 } 372 }
373 } 373 }
374 374
375 pluginAssembly = null; 375 pluginAssembly = null;
376 return plug; 376 return plug;
377 } 377 }
378 } 378 }
379} 379}