aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Configuration/HTTP
diff options
context:
space:
mode:
authormingchen2007-07-23 19:30:33 +0000
committermingchen2007-07-23 19:30:33 +0000
commit87bddd32dfdb6ab43ef21703053935d3cda69c51 (patch)
tree70d1beaf870770d9180756ae74bd77d3376ec9fb /OpenSim/Framework/Configuration/HTTP
parentApplied makomk 's patch from issue #219. (diff)
downloadopensim-SC_OLD-87bddd32dfdb6ab43ef21703053935d3cda69c51.zip
opensim-SC_OLD-87bddd32dfdb6ab43ef21703053935d3cda69c51.tar.gz
opensim-SC_OLD-87bddd32dfdb6ab43ef21703053935d3cda69c51.tar.bz2
opensim-SC_OLD-87bddd32dfdb6ab43ef21703053935d3cda69c51.tar.xz
*Added configuration plugin (OpenSim.Framework.Configuration.HTTP.dll) that fetches a file from a remote server
*Right now, values are not saved back to the remote server, but that will be changed *Removed some warnings from invalid references that were not used anyways
Diffstat (limited to 'OpenSim/Framework/Configuration/HTTP')
-rw-r--r--OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs89
-rw-r--r--OpenSim/Framework/Configuration/HTTP/RemoteConfigSettings.cs34
2 files changed, 123 insertions, 0 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 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.IO;
5using System.Text;
6
7using OpenSim.Framework.Configuration.Interfaces;
8
9namespace 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 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Framework.Configuration;
6
7namespace 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}