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