aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/NewAssetServer/AssetServer.cs
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:24:57 +0000
committerMike Mazur2009-02-16 02:24:57 +0000
commit0e09b4a08beddb3b0239a3f088ab9a230b8f3979 (patch)
tree481d1cb9a60062dea6e646e0e6c5d9d87ce40b6e /OpenSim/Grid/NewAssetServer/AssetServer.cs
parentThank you, cmickeyb, for a patch to ass two string functions (diff)
downloadopensim-SC_OLD-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.zip
opensim-SC_OLD-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.tar.gz
opensim-SC_OLD-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.tar.bz2
opensim-SC_OLD-0e09b4a08beddb3b0239a3f088ab9a230b8f3979.tar.xz
Adding
- NewAssetServer code - NewAssetServer addin manifest - example AssetServer.ini file
Diffstat (limited to 'OpenSim/Grid/NewAssetServer/AssetServer.cs')
-rw-r--r--OpenSim/Grid/NewAssetServer/AssetServer.cs262
1 files changed, 262 insertions, 0 deletions
diff --git a/OpenSim/Grid/NewAssetServer/AssetServer.cs b/OpenSim/Grid/NewAssetServer/AssetServer.cs
new file mode 100644
index 0000000..c6864e7
--- /dev/null
+++ b/OpenSim/Grid/NewAssetServer/AssetServer.cs
@@ -0,0 +1,262 @@
1/*
2 * Copyright (c) 2008 Intel Corporation
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * -- Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * -- Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * -- Neither the name of the Intel Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30using System;
31using System.Collections.Generic;
32using System.IO;
33using System.Net;
34using System.Reflection;
35using System.Security.Cryptography.X509Certificates;
36using System.ServiceProcess;
37using ExtensionLoader;
38using ExtensionLoader.Config;
39using HttpServer;
40using log4net;
41using OpenSim.Framework;
42
43namespace AssetServer
44{
45 public class AssetServer : ServiceBase
46 {
47 public const string CONFIG_FILE = "AssetServer.ini";
48
49 public WebServer HttpServer;
50 public IniConfigSource ConfigFile;
51
52 public IAssetStorageProvider StorageProvider;
53 public IInventoryProvider InventoryProvider;
54 public IAuthenticationProvider AuthenticationProvider;
55 public IAuthorizationProvider AuthorizationProvider;
56 public IMetricsProvider MetricsProvider;
57
58 public AssetServer()
59 {
60 this.ServiceName = "OpenSimAssetServer";
61 }
62
63 public bool Start()
64 {
65 Logger.Log.Info("Starting Asset Server");
66 List<string> extensionList = null;
67 int port = 0;
68 X509Certificate2 serverCert = null;
69
70 try { ConfigFile = new IniConfigSource(CONFIG_FILE); }
71 catch (Exception)
72 {
73 Logger.Log.Error("Failed to load the config file " + CONFIG_FILE);
74 return false;
75 }
76
77 try
78 {
79 IConfig extensionConfig = ConfigFile.Configs["Config"];
80
81 // Load the port number to listen on
82 port = extensionConfig.GetInt("ListenPort");
83
84 // Load the server certificate file
85 string certFile = extensionConfig.GetString("SSLCertFile");
86 if (!String.IsNullOrEmpty(certFile))
87 serverCert = new X509Certificate2(certFile);
88 }
89 catch (Exception)
90 {
91 Logger.Log.Error("Failed to load [Config] section from " + CONFIG_FILE);
92 return false;
93 }
94
95 try
96 {
97 // Load the extension list (and ordering) from our config file
98 IConfig extensionConfig = ConfigFile.Configs["Extensions"];
99 extensionList = new List<string>(extensionConfig.GetKeys());
100 }
101 catch (Exception)
102 {
103 Logger.Log.Error("Failed to load [Extensions] section from " + CONFIG_FILE);
104 return false;
105 }
106
107 //try
108 //{
109 // // Create a reference list for C# extensions compiled at runtime
110 // List<string> references = new List<string>();
111 // references.Add("OpenMetaverseTypes.dll");
112 // references.Add("OpenMetaverse.dll");
113 // references.Add("OpenMetaverse.StructuredData.dll");
114 // references.Add("OpenMetaverse.Http.dll");
115 // references.Add("ExtensionLoader.dll");
116 // references.Add("AssetServer.exe");
117
118 // // Get a list of all of the members of AssetServer that are interfaces
119 // List<FieldInfo> assignables = ExtensionLoader<AssetServer>.GetInterfaces(this);
120
121 // // Load all of the extensions
122 // ExtensionLoader<AssetServer>.LoadAllExtensions(
123 // Assembly.GetExecutingAssembly(),
124 // Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
125 // extensionList,
126 // references,
127 // "AssetServer.*.dll",
128 // "AssetServer.*.cs",
129 // this,
130 // assignables);
131 //}
132 //catch (ExtensionException ex)
133 //{
134 // Logger.Log.Error("Interface loading failed, shutting down: " + ex.Message);
135 // if (ex.InnerException != null)
136 // Logger.Log.Error(ex.InnerException.Message, ex.InnerException);
137 // Stop();
138 // return false;
139 //}
140
141 StorageProvider = LoadAssetServerPlugin() as IAssetStorageProvider;
142
143 try
144 {
145 InitHttpServer(port, serverCert);
146 }
147 catch (Exception ex)
148 {
149 Logger.Log.Error("Initializing the HTTP server failed, shutting down: " + ex.Message);
150 Stop();
151 return false;
152 }
153
154 // Start all of the extensions
155 //foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
156 //{
157 // Logger.Log.Info("Starting extension " + extension.GetType().Name);
158 // extension.Start(this);
159 //}
160
161 return true;
162 }
163
164 public void Shutdown()
165 {
166 foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
167 {
168 Logger.Log.Debug("Disposing extension " + extension.GetType().Name);
169 try { extension.Stop(); }
170 catch (Exception ex)
171 { Logger.Log.ErrorFormat("Failure shutting down extension {0}: {1}", extension.GetType().Name, ex.Message); }
172 }
173
174 if (HttpServer != null)
175 HttpServer.Stop();
176 }
177
178 void InitHttpServer(int port, X509Certificate serverCert)
179 {
180 if (serverCert != null)
181 HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false);
182 else
183 HttpServer = new WebServer(IPAddress.Any, port);
184
185 HttpServer.LogWriter = new log4netLogWriter(Logger.Log);
186
187 HttpServer.Set404Handler(
188 delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
189 {
190 Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery);
191
192 string notFoundString = "<html><head><title>Page Not Found</title></head><body>The requested page or method was not found</body></html>";
193 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString);
194 response.Body.Write(buffer, 0, buffer.Length);
195 response.Status = HttpStatusCode.NotFound;
196 return true;
197 }
198 );
199
200 HttpServer.Start();
201
202 Logger.Log.Info("Asset server is listening on port " + port);
203 }
204
205 #region ServiceBase Overrides
206
207 protected override void OnStart(string[] args)
208 {
209 Start();
210 }
211 protected override void OnStop()
212 {
213 Shutdown();
214 }
215
216 #endregion
217
218 private IAssetServerPlugin LoadAssetServerPlugin()
219 {
220 PluginLoader<IAssetServerPlugin> loader = new PluginLoader<IAssetServerPlugin>(new AssetServerPluginInitialiser(this));
221
222 //loader.Add ("/OpenSim/AssetServer/StorageProvider", new PluginProviderFilter (provider));
223 loader.Add("/OpenSim/AssetServer/StorageProvider", new PluginCountConstraint(1));
224 loader.Load();
225
226 return loader.Plugin;
227 }
228 }
229
230 public class log4netLogWriter : ILogWriter
231 {
232 ILog Log;
233
234 public log4netLogWriter(ILog log)
235 {
236 Log = log;
237 }
238
239 public void Write(object source, LogPrio prio, string message)
240 {
241 switch (prio)
242 {
243 case LogPrio.Trace:
244 case LogPrio.Debug:
245 Log.DebugFormat("{0}: {1}", source, message);
246 break;
247 case LogPrio.Info:
248 Log.InfoFormat("{0}: {1}", source, message);
249 break;
250 case LogPrio.Warning:
251 Log.WarnFormat("{0}: {1}", source, message);
252 break;
253 case LogPrio.Error:
254 Log.ErrorFormat("{0}: {1}", source, message);
255 break;
256 case LogPrio.Fatal:
257 Log.FatalFormat("{0}: {1}", source, message);
258 break;
259 }
260 }
261 }
262}