diff options
author | mingchen | 2007-07-18 23:15:08 +0000 |
---|---|---|
committer | mingchen | 2007-07-18 23:15:08 +0000 |
commit | 222becc8795d8abd8263c8abf8212de91faa4748 (patch) | |
tree | ac0eb1b420c2f60975b759296c94813f41925798 /OpenSim/Framework/General/Configuration | |
parent | * Reverting 1371 (diff) | |
download | opensim-SC_OLD-222becc8795d8abd8263c8abf8212de91faa4748.zip opensim-SC_OLD-222becc8795d8abd8263c8abf8212de91faa4748.tar.gz opensim-SC_OLD-222becc8795d8abd8263c8abf8212de91faa4748.tar.bz2 opensim-SC_OLD-222becc8795d8abd8263c8abf8212de91faa4748.tar.xz |
*New Configuration System, much easier and less buggy compared to the original system in place
*View RegionInfo.cs for an example on how it works!
*This hopefully copies all the files over, but who knows :)
Diffstat (limited to 'OpenSim/Framework/General/Configuration')
6 files changed, 639 insertions, 0 deletions
diff --git a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs new file mode 100644 index 0000000..2d945b5 --- /dev/null +++ b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs | |||
@@ -0,0 +1,311 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Text; | ||
5 | using System.Net; | ||
6 | |||
7 | using libsecondlife; | ||
8 | |||
9 | using OpenSim.Framework.Console; | ||
10 | |||
11 | namespace OpenSim.Framework.Configuration | ||
12 | { | ||
13 | public class ConfigurationMember | ||
14 | { | ||
15 | public delegate void ConfigurationOptionResult(string configuration_key, object configuration_result); | ||
16 | public delegate void ConfigurationOptionsLoad(); | ||
17 | |||
18 | private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>(); | ||
19 | private string configurationFilename = ""; | ||
20 | private string configurationDescription = ""; | ||
21 | |||
22 | private ConfigurationOptionsLoad loadFunction; | ||
23 | private ConfigurationOptionResult resultFunction; | ||
24 | |||
25 | public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) | ||
26 | { | ||
27 | this.configurationFilename = configuration_filename; | ||
28 | this.configurationDescription = configuration_description; | ||
29 | this.loadFunction = load_function; | ||
30 | this.resultFunction = result_function; | ||
31 | } | ||
32 | |||
33 | public void setConfigurationFilename(string filename) | ||
34 | { | ||
35 | configurationFilename = filename; | ||
36 | } | ||
37 | public void setConfigurationDescription(string desc) | ||
38 | { | ||
39 | configurationDescription = desc; | ||
40 | } | ||
41 | |||
42 | public void setConfigurationResultFunction(ConfigurationOptionResult result) | ||
43 | { | ||
44 | resultFunction = result; | ||
45 | } | ||
46 | |||
47 | public void addConfigurationOption(string configuration_key, ConfigurationOption.ConfigurationTypes configuration_type, string configuration_question, string configuration_default) | ||
48 | { | ||
49 | ConfigurationOption configOption = new ConfigurationOption(); | ||
50 | configOption.configurationKey = configuration_key; | ||
51 | configOption.configurationQuestion = configuration_question; | ||
52 | configOption.configurationDefault = configuration_default; | ||
53 | configOption.configurationType = configuration_type; | ||
54 | |||
55 | if (configuration_key != "" && configuration_question != "" && configuration_type != null) | ||
56 | { | ||
57 | if (!configurationOptions.Contains(configOption)) | ||
58 | { | ||
59 | configurationOptions.Add(configOption); | ||
60 | } | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | MainLog.Instance.Notice("Required fields for adding a configuration option is invalid. Will not add this option (" + configuration_key + ")"); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | public void performConfigurationRetrieve() | ||
69 | { | ||
70 | configurationOptions.Clear(); | ||
71 | if(loadFunction == null) | ||
72 | { | ||
73 | MainLog.Instance.Error("Load Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); | ||
74 | return; | ||
75 | } | ||
76 | |||
77 | if(resultFunction == null) | ||
78 | { | ||
79 | MainLog.Instance.Error("Result Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | MainLog.Instance.Verbose("Calling Configuration Load Function..."); | ||
84 | this.loadFunction(); | ||
85 | |||
86 | if(configurationOptions.Count <= 0) | ||
87 | { | ||
88 | MainLog.Instance.Error("No configuration options were specified for '" + this.configurationOptions + "'. Refusing to continue configuration."); | ||
89 | return; | ||
90 | } | ||
91 | |||
92 | bool useFile = true; | ||
93 | XmlConfiguration xmlConfig = null; | ||
94 | if (configurationFilename.Trim() != "") | ||
95 | { | ||
96 | xmlConfig = new XmlConfiguration(configurationFilename); | ||
97 | |||
98 | } | ||
99 | |||
100 | if(xmlConfig != null) | ||
101 | { | ||
102 | xmlConfig.LoadData(); | ||
103 | useFile = true; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file."); | ||
108 | useFile = false; | ||
109 | } | ||
110 | |||
111 | foreach (ConfigurationOption configOption in configurationOptions) | ||
112 | { | ||
113 | bool convertSuccess = false; | ||
114 | object return_result = null; | ||
115 | string errorMessage = ""; | ||
116 | bool ignoreNextFromConfig = false; | ||
117 | while (convertSuccess == false) | ||
118 | { | ||
119 | |||
120 | string attribute = null; | ||
121 | if (useFile) | ||
122 | { | ||
123 | if (!ignoreNextFromConfig) | ||
124 | { | ||
125 | attribute = xmlConfig.GetAttribute(configOption.configurationKey); | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | ignoreNextFromConfig = false; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | string console_result = ""; | ||
134 | if (attribute == null) | ||
135 | { | ||
136 | if (configurationDescription.Trim() != "") | ||
137 | { | ||
138 | console_result = MainLog.Instance.CmdPrompt(configurationDescription + ": " + configOption.configurationQuestion, configOption.configurationDefault); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | console_result = MainLog.Instance.CmdPrompt(configOption.configurationQuestion, configOption.configurationDefault); | ||
143 | } | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | console_result = attribute; | ||
148 | } | ||
149 | |||
150 | switch (configOption.configurationType) | ||
151 | { | ||
152 | case ConfigurationOption.ConfigurationTypes.TYPE_STRING: | ||
153 | return_result = console_result; | ||
154 | convertSuccess = true; | ||
155 | break; | ||
156 | case ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN: | ||
157 | bool boolResult; | ||
158 | if (Boolean.TryParse(console_result, out boolResult)) | ||
159 | { | ||
160 | convertSuccess = true; | ||
161 | return_result = boolResult; | ||
162 | } | ||
163 | errorMessage = "'true' or 'false' (Boolean)"; | ||
164 | break; | ||
165 | case ConfigurationOption.ConfigurationTypes.TYPE_BYTE: | ||
166 | byte byteResult; | ||
167 | if (Byte.TryParse(console_result, out byteResult)) | ||
168 | { | ||
169 | convertSuccess = true; | ||
170 | return_result = byteResult; | ||
171 | } | ||
172 | errorMessage = "a byte (Byte)"; | ||
173 | break; | ||
174 | case ConfigurationOption.ConfigurationTypes.TYPE_CHARACTER: | ||
175 | char charResult; | ||
176 | if (Char.TryParse(console_result, out charResult)) | ||
177 | { | ||
178 | convertSuccess = true; | ||
179 | return_result = charResult; | ||
180 | } | ||
181 | errorMessage = "a character (Char)"; | ||
182 | break; | ||
183 | case ConfigurationOption.ConfigurationTypes.TYPE_INT16: | ||
184 | short shortResult; | ||
185 | if (Int16.TryParse(console_result, out shortResult)) | ||
186 | { | ||
187 | convertSuccess = true; | ||
188 | return_result = shortResult; | ||
189 | } | ||
190 | errorMessage = "a signed 32 bit integer (short)"; | ||
191 | break; | ||
192 | case ConfigurationOption.ConfigurationTypes.TYPE_INT32: | ||
193 | int intResult; | ||
194 | if (Int32.TryParse(console_result, out intResult)) | ||
195 | { | ||
196 | convertSuccess = true; | ||
197 | return_result = intResult; | ||
198 | |||
199 | } | ||
200 | errorMessage = "a signed 32 bit integer (int)"; | ||
201 | break; | ||
202 | case ConfigurationOption.ConfigurationTypes.TYPE_INT64: | ||
203 | long longResult; | ||
204 | if (Int64.TryParse(console_result, out longResult)) | ||
205 | { | ||
206 | convertSuccess = true; | ||
207 | return_result = longResult; | ||
208 | } | ||
209 | errorMessage = "a signed 32 bit integer (long)"; | ||
210 | break; | ||
211 | case ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS: | ||
212 | IPAddress ipAddressResult; | ||
213 | if (IPAddress.TryParse(console_result, out ipAddressResult)) | ||
214 | { | ||
215 | convertSuccess = true; | ||
216 | return_result = ipAddressResult; | ||
217 | } | ||
218 | errorMessage = "an IP Address (IPAddress)"; | ||
219 | break; | ||
220 | case ConfigurationOption.ConfigurationTypes.TYPE_LLUUID: | ||
221 | LLUUID uuidResult; | ||
222 | if (LLUUID.TryParse(console_result, out uuidResult)) | ||
223 | { | ||
224 | convertSuccess = true; | ||
225 | return_result = uuidResult; | ||
226 | } | ||
227 | errorMessage = "a UUID (LLUUID)"; | ||
228 | break; | ||
229 | case ConfigurationOption.ConfigurationTypes.TYPE_LLVECTOR3: | ||
230 | LLVector3 vectorResult; | ||
231 | if (LLVector3.TryParse(console_result, out vectorResult)) | ||
232 | { | ||
233 | convertSuccess = true; | ||
234 | return_result = vectorResult; | ||
235 | } | ||
236 | errorMessage = "a vector (LLVector3)"; | ||
237 | break; | ||
238 | case ConfigurationOption.ConfigurationTypes.TYPE_UINT16: | ||
239 | ushort ushortResult; | ||
240 | if (UInt16.TryParse(console_result, out ushortResult)) | ||
241 | { | ||
242 | convertSuccess = true; | ||
243 | return_result = ushortResult; | ||
244 | } | ||
245 | errorMessage = "an unsigned 16 bit integer (ushort)"; | ||
246 | break; | ||
247 | case ConfigurationOption.ConfigurationTypes.TYPE_UINT32: | ||
248 | uint uintResult; | ||
249 | if (UInt32.TryParse(console_result, out uintResult)) | ||
250 | { | ||
251 | convertSuccess = true; | ||
252 | return_result = uintResult; | ||
253 | |||
254 | } | ||
255 | errorMessage = "an unsigned 32 bit integer (uint)"; | ||
256 | break; | ||
257 | case ConfigurationOption.ConfigurationTypes.TYPE_UINT64: | ||
258 | ulong ulongResult; | ||
259 | if (UInt64.TryParse(console_result, out ulongResult)) | ||
260 | { | ||
261 | convertSuccess = true; | ||
262 | return_result = ulongResult; | ||
263 | } | ||
264 | errorMessage = "an unsigned 64 bit integer (ulong)"; | ||
265 | break; | ||
266 | case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT: | ||
267 | float floatResult; | ||
268 | if (float.TryParse(console_result, out floatResult)) | ||
269 | { | ||
270 | convertSuccess = true; | ||
271 | return_result = floatResult; | ||
272 | } | ||
273 | errorMessage = "a single-precision floating point number (float)"; | ||
274 | break; | ||
275 | case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE: | ||
276 | double doubleResult; | ||
277 | if (Double.TryParse(console_result, out doubleResult)) | ||
278 | { | ||
279 | convertSuccess = true; | ||
280 | return_result = doubleResult; | ||
281 | } | ||
282 | errorMessage = "an double-precision floating point number (double)"; | ||
283 | break; | ||
284 | } | ||
285 | |||
286 | if (convertSuccess) | ||
287 | { | ||
288 | if (useFile) | ||
289 | { | ||
290 | xmlConfig.SetAttribute(configOption.configurationKey, console_result); | ||
291 | } | ||
292 | |||
293 | |||
294 | this.resultFunction(configOption.configurationKey, return_result); | ||
295 | } | ||
296 | else | ||
297 | { | ||
298 | MainLog.Instance.Warn("Incorrect result given, the configuration option must be " + errorMessage + ". Prompting for same option..."); | ||
299 | ignoreNextFromConfig = true; | ||
300 | } | ||
301 | } | ||
302 | } | ||
303 | |||
304 | if(useFile) | ||
305 | { | ||
306 | xmlConfig.Commit(); | ||
307 | xmlConfig.Close(); | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | } | ||
diff --git a/OpenSim/Framework/General/Configuration/ConfigurationOption.cs b/OpenSim/Framework/General/Configuration/ConfigurationOption.cs new file mode 100644 index 0000000..15da1aa --- /dev/null +++ b/OpenSim/Framework/General/Configuration/ConfigurationOption.cs | |||
@@ -0,0 +1,34 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Framework.Configuration | ||
6 | { | ||
7 | public class ConfigurationOption | ||
8 | { | ||
9 | public enum ConfigurationTypes | ||
10 | { | ||
11 | TYPE_STRING, | ||
12 | TYPE_UINT16, | ||
13 | TYPE_UINT32, | ||
14 | TYPE_UINT64, | ||
15 | TYPE_INT16, | ||
16 | TYPE_INT32, | ||
17 | TYPE_INT64, | ||
18 | TYPE_IP_ADDRESS, | ||
19 | TYPE_CHARACTER, | ||
20 | TYPE_BOOLEAN, | ||
21 | TYPE_BYTE, | ||
22 | TYPE_LLUUID, | ||
23 | TYPE_LLVECTOR3, | ||
24 | TYPE_FLOAT, | ||
25 | TYPE_DOUBLE | ||
26 | }; | ||
27 | |||
28 | public string configurationKey = ""; | ||
29 | public string configurationQuestion = ""; | ||
30 | public string configurationDefault = ""; | ||
31 | |||
32 | public ConfigurationTypes configurationType = ConfigurationTypes.TYPE_STRING; | ||
33 | } | ||
34 | } | ||
diff --git a/OpenSim/Framework/General/Configuration/GridConfig.cs b/OpenSim/Framework/General/Configuration/GridConfig.cs new file mode 100644 index 0000000..97dd699 --- /dev/null +++ b/OpenSim/Framework/General/Configuration/GridConfig.cs | |||
@@ -0,0 +1,78 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Framework.Configuration | ||
6 | { | ||
7 | public class GridConfig | ||
8 | { | ||
9 | public string GridOwner = ""; | ||
10 | public string DefaultAssetServer = ""; | ||
11 | public string AssetSendKey = ""; | ||
12 | public string AssetRecvKey = ""; | ||
13 | |||
14 | public string DefaultUserServer = ""; | ||
15 | public string UserSendKey = ""; | ||
16 | public string UserRecvKey = ""; | ||
17 | |||
18 | public string SimSendKey = ""; | ||
19 | public string SimRecvKey = ""; | ||
20 | |||
21 | private ConfigurationMember configMember; | ||
22 | public GridConfig(string description, string filename) | ||
23 | { | ||
24 | configMember = new ConfigurationMember(filename, description, this.loadConfigurationOptions, this.handleIncomingConfiguration); | ||
25 | configMember.performConfigurationRetrieve(); | ||
26 | } | ||
27 | |||
28 | public void loadConfigurationOptions() | ||
29 | { | ||
30 | configMember.addConfigurationOption("grid_owner",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"OGS Grid Owner","OGS development team"); | ||
31 | configMember.addConfigurationOption("default_asset_server",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Default Asset Server URI","http://127.0.0.1:8003/"); | ||
32 | configMember.addConfigurationOption("asset_send_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to send to asset server","null"); | ||
33 | configMember.addConfigurationOption("asset_recv_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to expect from asset server","null"); | ||
34 | |||
35 | configMember.addConfigurationOption("default_user_server",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Default User Server URI","http://127.0.0.1:8002/"); | ||
36 | configMember.addConfigurationOption("user_send_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to send to user server","null"); | ||
37 | configMember.addConfigurationOption("user_recv_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to expect from user server","null"); | ||
38 | |||
39 | configMember.addConfigurationOption("sim_send_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to send to a simulator","null"); | ||
40 | configMember.addConfigurationOption("sim_recv_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to expect from a simulator","null"); | ||
41 | |||
42 | } | ||
43 | |||
44 | public void handleIncomingConfiguration(string configuration_key, object configuration_result) | ||
45 | { | ||
46 | switch (configuration_key) | ||
47 | { | ||
48 | case "grid_owner": | ||
49 | this.GridOwner = (string)configuration_result; | ||
50 | break; | ||
51 | case "default_asset_server": | ||
52 | this.DefaultAssetServer = (string)configuration_result; | ||
53 | break; | ||
54 | case "asset_send_key": | ||
55 | this.AssetSendKey = (string)configuration_result; | ||
56 | break; | ||
57 | case "asset_recv_key": | ||
58 | this.AssetRecvKey = (string)configuration_result; | ||
59 | break; | ||
60 | case "default_user_server": | ||
61 | this.DefaultUserServer = (string)configuration_result; | ||
62 | break; | ||
63 | case "user_send_key": | ||
64 | this.UserSendKey = (string)configuration_result; | ||
65 | break; | ||
66 | case "user_recv_key": | ||
67 | this.UserRecvKey = (string)configuration_result; | ||
68 | break; | ||
69 | case "sim_send_key": | ||
70 | this.SimSendKey = (string)configuration_result; | ||
71 | break; | ||
72 | case "sim_recv_key": | ||
73 | this.SimRecvKey = (string)configuration_result; | ||
74 | break; | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
diff --git a/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs b/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs new file mode 100644 index 0000000..2c379dd --- /dev/null +++ b/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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 | namespace OpenSim.Framework.Interfaces | ||
29 | { | ||
30 | public interface IGenericConfig | ||
31 | { | ||
32 | void LoadData(); | ||
33 | string GetAttribute(string attributeName); | ||
34 | bool SetAttribute(string attributeName, string attributeValue); | ||
35 | void Commit(); | ||
36 | void Close(); | ||
37 | } | ||
38 | } | ||
diff --git a/OpenSim/Framework/General/Configuration/UserConfig.cs b/OpenSim/Framework/General/Configuration/UserConfig.cs new file mode 100644 index 0000000..9d607b3 --- /dev/null +++ b/OpenSim/Framework/General/Configuration/UserConfig.cs | |||
@@ -0,0 +1,55 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Framework.Configuration | ||
6 | { | ||
7 | /// <summary> | ||
8 | /// UserConfig -- For User Server Configuration | ||
9 | /// </summary> | ||
10 | public class UserConfig | ||
11 | { | ||
12 | public string DefaultStartupMsg = ""; | ||
13 | public string GridServerURL = ""; | ||
14 | public string GridSendKey = ""; | ||
15 | public string GridRecvKey = ""; | ||
16 | |||
17 | private ConfigurationMember configMember; | ||
18 | |||
19 | public UserConfig(string description, string filename) | ||
20 | { | ||
21 | configMember = new ConfigurationMember(filename, description, this.loadConfigurationOptions, this.handleIncomingConfiguration); | ||
22 | configMember.performConfigurationRetrieve(); | ||
23 | } | ||
24 | |||
25 | public void loadConfigurationOptions() | ||
26 | { | ||
27 | configMember.addConfigurationOption("default_startup_message",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Default Startup Message","Welcome to OGS"); | ||
28 | |||
29 | configMember.addConfigurationOption("default_grid_server",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Default Grid Server URI","http://127.0.0.1:8001/"); | ||
30 | configMember.addConfigurationOption("grid_send_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to send to grid server","null"); | ||
31 | configMember.addConfigurationOption("grid_recv_key",ConfigurationOption.ConfigurationTypes.TYPE_STRING,"Key to expect from grid server","null"); | ||
32 | |||
33 | |||
34 | } | ||
35 | |||
36 | public void handleIncomingConfiguration(string configuration_key, object configuration_result) | ||
37 | { | ||
38 | switch (configuration_key) | ||
39 | { | ||
40 | case "default_startup_message": | ||
41 | this.DefaultStartupMsg = (string)configuration_result; | ||
42 | break; | ||
43 | case "default_grid_server": | ||
44 | this.GridServerURL = (string)configuration_result; | ||
45 | break; | ||
46 | case "grid_send_key": | ||
47 | this.GridSendKey = (string)configuration_result; | ||
48 | break; | ||
49 | case "grid_recv_key": | ||
50 | this.GridRecvKey = (string)configuration_result; | ||
51 | break; | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | } | ||
diff --git a/OpenSim/Framework/General/Configuration/XmlConfiguration.cs b/OpenSim/Framework/General/Configuration/XmlConfiguration.cs new file mode 100644 index 0000000..e1f3816 --- /dev/null +++ b/OpenSim/Framework/General/Configuration/XmlConfiguration.cs | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.IO; | ||
30 | using System.Xml; | ||
31 | |||
32 | using OpenSim.Framework.Interfaces; | ||
33 | |||
34 | namespace OpenSim.Framework.Configuration | ||
35 | { | ||
36 | public class XmlConfiguration : IGenericConfig | ||
37 | { | ||
38 | private XmlDocument doc; | ||
39 | private XmlNode rootNode; | ||
40 | private XmlNode configNode; | ||
41 | private string fileName; | ||
42 | private bool createdFile = false; | ||
43 | |||
44 | public XmlConfiguration(string filename) | ||
45 | { | ||
46 | fileName = filename; | ||
47 | } | ||
48 | |||
49 | public void LoadData() | ||
50 | { | ||
51 | doc = new XmlDocument(); | ||
52 | |||
53 | if (File.Exists(fileName)) | ||
54 | { | ||
55 | XmlTextReader reader = new XmlTextReader(fileName); | ||
56 | reader.WhitespaceHandling = WhitespaceHandling.None; | ||
57 | doc.Load(reader); | ||
58 | reader.Close(); | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | createdFile = true; | ||
63 | rootNode = doc.CreateNode(XmlNodeType.Element, "Root", ""); | ||
64 | doc.AppendChild(rootNode); | ||
65 | configNode = doc.CreateNode(XmlNodeType.Element, "Config", ""); | ||
66 | rootNode.AppendChild(configNode); | ||
67 | } | ||
68 | |||
69 | |||
70 | rootNode = doc.FirstChild; | ||
71 | if (rootNode.Name != "Root") | ||
72 | throw new Exception("Error: Invalid .xml File. Missing <Root>"); | ||
73 | |||
74 | configNode = rootNode.FirstChild; | ||
75 | if (configNode.Name != "Config") | ||
76 | throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>"); | ||
77 | |||
78 | if (createdFile) | ||
79 | { | ||
80 | this.Commit(); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | public string GetAttribute(string attributeName) | ||
85 | { | ||
86 | string result = null; | ||
87 | if (configNode.Attributes[attributeName] != null) | ||
88 | { | ||
89 | result = ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value; | ||
90 | } | ||
91 | return result; | ||
92 | } | ||
93 | |||
94 | public bool SetAttribute(string attributeName, string attributeValue) | ||
95 | { | ||
96 | if (configNode.Attributes[attributeName] != null) | ||
97 | { | ||
98 | ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value = attributeValue; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | XmlAttribute attri; | ||
103 | attri = doc.CreateAttribute(attributeName); | ||
104 | attri.Value = attributeValue; | ||
105 | configNode.Attributes.Append(attri); | ||
106 | } | ||
107 | return true; | ||
108 | } | ||
109 | |||
110 | public void Commit() | ||
111 | { | ||
112 | doc.Save(fileName); | ||
113 | } | ||
114 | |||
115 | public void Close() | ||
116 | { | ||
117 | configNode = null; | ||
118 | rootNode = null; | ||
119 | doc = null; | ||
120 | } | ||
121 | |||
122 | } | ||
123 | } | ||