diff options
6 files changed, 174 insertions, 12 deletions
diff --git a/OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs b/OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs new file mode 100644 index 0000000..c7d2c9c --- /dev/null +++ b/OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs | |||
@@ -0,0 +1,89 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Net; | ||
4 | using System.IO; | ||
5 | using System.Text; | ||
6 | |||
7 | using OpenSim.Framework.Configuration.Interfaces; | ||
8 | |||
9 | namespace OpenSim.Framework.Configuration.HTTP | ||
10 | { | ||
11 | public class HTTPConfiguration : IGenericConfig | ||
12 | { | ||
13 | RemoteConfigSettings remoteConfigSettings; | ||
14 | |||
15 | XmlConfiguration xmlConfig; | ||
16 | |||
17 | private string configFileName = ""; | ||
18 | |||
19 | public HTTPConfiguration() | ||
20 | { | ||
21 | remoteConfigSettings = new RemoteConfigSettings("remoteconfig.xml"); | ||
22 | xmlConfig = new XmlConfiguration(); | ||
23 | } | ||
24 | |||
25 | public void SetFileName(string fileName) | ||
26 | { | ||
27 | configFileName = fileName; | ||
28 | } | ||
29 | |||
30 | public void LoadData() | ||
31 | { | ||
32 | try | ||
33 | { | ||
34 | StringBuilder sb = new StringBuilder(); | ||
35 | |||
36 | byte[] buf = new byte[8192]; | ||
37 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.remoteConfigSettings.baseConfigURL + this.configFileName); | ||
38 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | ||
39 | |||
40 | Stream resStream = response.GetResponseStream(); | ||
41 | |||
42 | string tempString = null; | ||
43 | int count = 0; | ||
44 | |||
45 | do | ||
46 | { | ||
47 | count = resStream.Read(buf, 0, buf.Length); | ||
48 | if (count != 0) | ||
49 | { | ||
50 | tempString = Encoding.ASCII.GetString(buf, 0, count); | ||
51 | sb.Append(tempString); | ||
52 | } | ||
53 | } | ||
54 | while (count > 0); | ||
55 | LoadDataFromString(sb.ToString()); | ||
56 | } | ||
57 | catch (Exception e) | ||
58 | { | ||
59 | Console.MainLog.Instance.Warn("Unable to connect to remote configuration file (" + remoteConfigSettings.baseConfigURL + configFileName + "). Creating local file instead."); | ||
60 | xmlConfig.SetFileName(configFileName); | ||
61 | xmlConfig.LoadData(); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | public void LoadDataFromString(string data) | ||
66 | { | ||
67 | xmlConfig.LoadDataFromString(data); | ||
68 | |||
69 | } | ||
70 | |||
71 | public string GetAttribute(string attributeName) | ||
72 | { | ||
73 | return xmlConfig.GetAttribute(attributeName); | ||
74 | } | ||
75 | |||
76 | public bool SetAttribute(string attributeName, string attributeValue) | ||
77 | { | ||
78 | return true; | ||
79 | } | ||
80 | |||
81 | public void Commit() | ||
82 | { | ||
83 | } | ||
84 | |||
85 | public void Close() | ||
86 | { | ||
87 | } | ||
88 | } | ||
89 | } | ||
diff --git a/OpenSim/Framework/Configuration/HTTP/RemoteConfigSettings.cs b/OpenSim/Framework/Configuration/HTTP/RemoteConfigSettings.cs new file mode 100644 index 0000000..e3cfac7 --- /dev/null +++ b/OpenSim/Framework/Configuration/HTTP/RemoteConfigSettings.cs | |||
@@ -0,0 +1,34 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | using OpenSim.Framework.Configuration; | ||
6 | |||
7 | namespace OpenSim.Framework.Configuration.HTTP | ||
8 | { | ||
9 | public class RemoteConfigSettings | ||
10 | { | ||
11 | private ConfigurationMember configMember; | ||
12 | |||
13 | public string baseConfigURL = ""; | ||
14 | public RemoteConfigSettings(string filename) | ||
15 | { | ||
16 | configMember = new ConfigurationMember(filename, "REMOTE CONFIG SETTINGS", loadConfigurationOptions, handleIncomingConfiguration); | ||
17 | configMember.forceConfigurationPluginLibrary("OpenSim.Framework.Configuration.XML.dll"); | ||
18 | configMember.performConfigurationRetrieve(); | ||
19 | } | ||
20 | |||
21 | public void loadConfigurationOptions() | ||
22 | { | ||
23 | configMember.addConfigurationOption("base_config_url", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "URL Containing Configuration Files", "http://localhost/", false); | ||
24 | } | ||
25 | public bool handleIncomingConfiguration(string configuration_key, object configuration_result) | ||
26 | { | ||
27 | if (configuration_key == "base_config_url") | ||
28 | { | ||
29 | baseConfigURL = (string)configuration_result; | ||
30 | } | ||
31 | return true; | ||
32 | } | ||
33 | } | ||
34 | } | ||
diff --git a/OpenSim/Framework/Configuration/XML/XmlConfiguration.cs b/OpenSim/Framework/Configuration/XML/XmlConfiguration.cs index e56c657..5b66035 100644 --- a/OpenSim/Framework/Configuration/XML/XmlConfiguration.cs +++ b/OpenSim/Framework/Configuration/XML/XmlConfiguration.cs | |||
@@ -47,10 +47,19 @@ namespace OpenSim.Framework.Configuration | |||
47 | fileName = file; | 47 | fileName = file; |
48 | } | 48 | } |
49 | 49 | ||
50 | private void LoadDataToClass() | ||
51 | { | ||
52 | rootNode = doc.FirstChild; | ||
53 | if (rootNode.Name != "Root") | ||
54 | throw new Exception("Error: Invalid .xml File. Missing <Root>"); | ||
55 | |||
56 | configNode = rootNode.FirstChild; | ||
57 | if (configNode.Name != "Config") | ||
58 | throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>"); | ||
59 | } | ||
50 | public void LoadData() | 60 | public void LoadData() |
51 | { | 61 | { |
52 | doc = new XmlDocument(); | 62 | doc = new XmlDocument(); |
53 | |||
54 | if (File.Exists(fileName)) | 63 | if (File.Exists(fileName)) |
55 | { | 64 | { |
56 | XmlTextReader reader = new XmlTextReader(fileName); | 65 | XmlTextReader reader = new XmlTextReader(fileName); |
@@ -67,14 +76,7 @@ namespace OpenSim.Framework.Configuration | |||
67 | rootNode.AppendChild(configNode); | 76 | rootNode.AppendChild(configNode); |
68 | } | 77 | } |
69 | 78 | ||
70 | 79 | LoadDataToClass(); | |
71 | rootNode = doc.FirstChild; | ||
72 | if (rootNode.Name != "Root") | ||
73 | throw new Exception("Error: Invalid .xml File. Missing <Root>"); | ||
74 | |||
75 | configNode = rootNode.FirstChild; | ||
76 | if (configNode.Name != "Config") | ||
77 | throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>"); | ||
78 | 80 | ||
79 | if (createdFile) | 81 | if (createdFile) |
80 | { | 82 | { |
@@ -82,6 +84,13 @@ namespace OpenSim.Framework.Configuration | |||
82 | } | 84 | } |
83 | } | 85 | } |
84 | 86 | ||
87 | public void LoadDataFromString(string data) | ||
88 | { | ||
89 | doc = new XmlDocument(); | ||
90 | doc.LoadXml(data); | ||
91 | |||
92 | LoadDataToClass(); | ||
93 | } | ||
85 | public string GetAttribute(string attributeName) | 94 | public string GetAttribute(string attributeName) |
86 | { | 95 | { |
87 | string result = null; | 96 | string result = null; |
diff --git a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs index 4a6e0cc..b8dfc0c 100644 --- a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs +++ b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs | |||
@@ -25,13 +25,16 @@ namespace OpenSim.Framework.Configuration | |||
25 | private ConfigurationOptionResult resultFunction; | 25 | private ConfigurationOptionResult resultFunction; |
26 | 26 | ||
27 | private IGenericConfig configurationPlugin = null; | 27 | private IGenericConfig configurationPlugin = null; |
28 | /// <summary> | ||
29 | /// This is the default configuration DLL loaded | ||
30 | /// </summary> | ||
31 | private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll"; | ||
28 | 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) |
29 | { | 33 | { |
30 | this.configurationFilename = configuration_filename; | 34 | this.configurationFilename = configuration_filename; |
31 | this.configurationDescription = configuration_description; | 35 | this.configurationDescription = configuration_description; |
32 | this.loadFunction = load_function; | 36 | this.loadFunction = load_function; |
33 | this.resultFunction = result_function; | 37 | this.resultFunction = result_function; |
34 | this.configurationPlugin = this.LoadConfigDll("OpenSim.Framework.Configuration.XML.dll"); | ||
35 | } | 38 | } |
36 | 39 | ||
37 | public void setConfigurationFilename(string filename) | 40 | public void setConfigurationFilename(string filename) |
@@ -50,7 +53,7 @@ namespace OpenSim.Framework.Configuration | |||
50 | 53 | ||
51 | public void forceConfigurationPluginLibrary(string dll_filename) | 54 | public void forceConfigurationPluginLibrary(string dll_filename) |
52 | { | 55 | { |
53 | configurationPlugin = this.LoadConfigDll(dll_filename); | 56 | configurationPluginFilename = dll_filename; |
54 | } | 57 | } |
55 | 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) |
56 | { | 59 | { |
@@ -76,6 +79,7 @@ namespace OpenSim.Framework.Configuration | |||
76 | 79 | ||
77 | public void performConfigurationRetrieve() | 80 | public void performConfigurationRetrieve() |
78 | { | 81 | { |
82 | configurationPlugin = this.LoadConfigDll(configurationPluginFilename); | ||
79 | configurationOptions.Clear(); | 83 | configurationOptions.Clear(); |
80 | if(loadFunction == null) | 84 | if(loadFunction == null) |
81 | { | 85 | { |
diff --git a/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs b/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs index 5a5a20e..ceccd04 100644 --- a/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs +++ b/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs | |||
@@ -31,6 +31,7 @@ namespace OpenSim.Framework.Configuration.Interfaces | |||
31 | { | 31 | { |
32 | void SetFileName(string fileName); | 32 | void SetFileName(string fileName); |
33 | void LoadData(); | 33 | void LoadData(); |
34 | void LoadDataFromString(string data); | ||
34 | string GetAttribute(string attributeName); | 35 | string GetAttribute(string attributeName); |
35 | bool SetAttribute(string attributeName, string attributeValue); | 36 | bool SetAttribute(string attributeName, string attributeValue); |
36 | void Commit(); | 37 | void Commit(); |
diff --git a/prebuild.xml b/prebuild.xml index 83c5142..d57eaf8 100644 --- a/prebuild.xml +++ b/prebuild.xml | |||
@@ -124,13 +124,38 @@ | |||
124 | <Reference name="XMLRPC.dll"/> | 124 | <Reference name="XMLRPC.dll"/> |
125 | <Reference name="OpenSim.Framework"/> | 125 | <Reference name="OpenSim.Framework"/> |
126 | <Reference name="OpenSim.Framework.Console"/> | 126 | <Reference name="OpenSim.Framework.Console"/> |
127 | <Reference name="OpenSim.Framework.Configuration"/> | ||
128 | <Reference name="OpenSim.Framework.Data"/> | 127 | <Reference name="OpenSim.Framework.Data"/> |
129 | <Files> | 128 | <Files> |
130 | <Match pattern="*.cs" recurse="true"/> | 129 | <Match pattern="*.cs" recurse="true"/> |
131 | </Files> | 130 | </Files> |
132 | </Project> | 131 | </Project> |
133 | 132 | ||
133 | <Project name="OpenSim.Framework.Configuration.HTTP" path="OpenSim/Framework/Configuration/HTTP" type="Library"> | ||
134 | <Configuration name="Debug"> | ||
135 | <Options> | ||
136 | <OutputPath>../../../../bin/</OutputPath> | ||
137 | </Options> | ||
138 | </Configuration> | ||
139 | <Configuration name="Release"> | ||
140 | <Options> | ||
141 | <OutputPath>../../../../bin/</OutputPath> | ||
142 | </Options> | ||
143 | </Configuration> | ||
144 | |||
145 | <ReferencePath>../../../../bin/</ReferencePath> | ||
146 | <Reference name="System"/> | ||
147 | <Reference name="System.Xml"/> | ||
148 | <Reference name="libsecondlife.dll"/> | ||
149 | <Reference name="Db4objects.Db4o.dll"/> | ||
150 | <Reference name="XMLRPC.dll"/> | ||
151 | <Reference name="OpenSim.Framework"/> | ||
152 | <Reference name="OpenSim.Framework.Console"/> | ||
153 | <Reference name="OpenSim.Framework.Configuration.XML"/> | ||
154 | <Reference name="OpenSim.Framework.Data"/> | ||
155 | <Files> | ||
156 | <Match pattern="*.cs" recurse="true"/> | ||
157 | </Files> | ||
158 | </Project> | ||
134 | 159 | ||
135 | <Project name="OpenSim.Framework.Servers" path="OpenSim/Framework/Servers" type="Library"> | 160 | <Project name="OpenSim.Framework.Servers" path="OpenSim/Framework/Servers" type="Library"> |
136 | <Configuration name="Debug"> | 161 | <Configuration name="Debug"> |