aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
diff options
context:
space:
mode:
authorTeravus Ovares (Dan Olivares)2009-08-20 19:25:52 -0400
committerTeravus Ovares (Dan Olivares)2009-08-20 19:25:52 -0400
commit181b992b4a8dab3423b52f705e20dcb63e7fdb47 (patch)
tree309f2255464873944a5478472596cbc24b130b27 /OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
parent* Deal with git thinking that file was changed even though it wasn't and it's... (diff)
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-181b992b4a8dab3423b52f705e20dcb63e7fdb47.zip
opensim-SC-181b992b4a8dab3423b52f705e20dcb63e7fdb47.tar.gz
opensim-SC-181b992b4a8dab3423b52f705e20dcb63e7fdb47.tar.bz2
opensim-SC-181b992b4a8dab3423b52f705e20dcb63e7fdb47.tar.xz
Merge branch 'master' of ssh://MyConnection/var/git/opensim
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs369
1 files changed, 0 insertions, 369 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
deleted file mode 100644
index b5ad1a1..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
+++ /dev/null
@@ -1,369 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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
28using System;
29using System.IO;
30using System.Reflection;
31using System.Net;
32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers;
36using OpenSim.Framework.Servers.HttpServer;
37using log4net;
38
39namespace OpenSim.Grid.AssetInventoryServer.Plugins
40{
41 public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 AssetInventoryServer m_server;
45
46 public ReferenceFrontendPlugin()
47 {
48 }
49
50 #region IPlugin implementation
51
52 public void Initialise(AssetInventoryServer server)
53 {
54 m_server = server;
55
56 // Asset metadata request
57 //m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server));
58
59 // Asset data request
60 m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server));
61
62 // Asset creation
63 //m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server));
64
65 m_log.Info("[REFERENCEFRONTEND]: Reference Frontend loaded.");
66 }
67
68 /// <summary>
69 /// <para>Initialises asset interface</para>
70 /// </summary>
71 public void Initialise()
72 {
73 m_log.InfoFormat("[REFERENCEFRONTEND]: {0} cannot be default-initialized!", Name);
74 throw new PluginNotInitialisedException(Name);
75 }
76
77 public void Dispose()
78 {
79 }
80
81 public string Version
82 {
83 // TODO: this should be something meaningful and not hardcoded?
84 get { return "0.1"; }
85 }
86
87 public string Name
88 {
89 get { return "ReferenceFrontend"; }
90 }
91
92 #endregion IPlugin implementation
93
94 //public class MetadataRequestHandler : IStreamedRequestHandler
95 //{
96 // AssetInventoryServer m_server;
97 // string m_contentType;
98 // string m_httpMethod;
99 // string m_path;
100
101 // public MetadataRequestHandler(AssetInventoryServer server)
102 // {
103 // m_server = server;
104 // m_contentType = null;
105 // m_httpMethod = "GET";
106 // m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata";
107 // }
108
109 // #region IStreamedRequestHandler implementation
110
111 // public string ContentType
112 // {
113 // get { return m_contentType; }
114 // }
115
116 // public string HttpMethod
117 // {
118 // get { return m_httpMethod; }
119 // }
120
121 // public string Path
122 // {
123 // get { return m_path; }
124 // }
125
126 // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
127 // {
128 // byte[] serializedData = null;
129 // UUID assetID;
130 // // Split the URL up into an AssetID and a method
131 // string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
132
133 // if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
134 // {
135 // UUID authToken = Utils.GetAuthToken(httpRequest);
136
137 // if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
138 // {
139 // AssetMetadata metadata;
140 // BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata);
141
142 // if (storageResponse == BackendResponse.Success)
143 // {
144 // // If the asset data location wasn't specified in the metadata, specify it
145 // // manually here by pointing back to this asset server
146 // if (!metadata.Methods.ContainsKey("data"))
147 // {
148 // metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
149 // httpRequest.Url.Scheme, httpRequest.Url.Authority, assetID));
150 // }
151
152 // serializedData = metadata.SerializeToBytes();
153
154 // httpResponse.StatusCode = (int) HttpStatusCode.OK;
155 // httpResponse.ContentType = "application/json";
156 // httpResponse.ContentLength = serializedData.Length;
157 // httpResponse.Body.Write(serializedData, 0, serializedData.Length);
158 // }
159 // else if (storageResponse == BackendResponse.NotFound)
160 // {
161 // m_log.Warn("[REFERENCEFRONTEND]: Could not find metadata for asset " + assetID.ToString());
162 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
163 // }
164 // else
165 // {
166 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
167 // }
168 // }
169 // else
170 // {
171 // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
172 // }
173
174 // return serializedData;
175 // }
176
177 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
178 // return serializedData;
179 // }
180
181 // #endregion IStreamedRequestHandler implementation
182 //}
183
184 public class DataRequestHandler : IStreamedRequestHandler
185 {
186 AssetInventoryServer m_server;
187 string m_contentType;
188 string m_httpMethod;
189 string m_path;
190
191 public DataRequestHandler(AssetInventoryServer server)
192 {
193 m_server = server;
194 m_contentType = null;
195 m_httpMethod = "GET";
196 m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data";
197 }
198
199 #region IStreamedRequestHandler implementation
200
201 public string ContentType
202 {
203 get { return m_contentType; }
204 }
205
206 public string HttpMethod
207 {
208 get { return m_httpMethod; }
209 }
210
211 public string Path
212 {
213 get { return m_path; }
214 }
215
216 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
217 {
218 byte[] assetData = null;
219 UUID assetID;
220 // Split the URL up into an AssetID and a method
221 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
222
223 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
224 {
225 UUID authToken = Utils.GetAuthToken(httpRequest);
226
227 if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
228 {
229 BackendResponse storageResponse = m_server.StorageProvider.TryFetchData(assetID, out assetData);
230
231 if (storageResponse == BackendResponse.Success)
232 {
233 httpResponse.StatusCode = (int) HttpStatusCode.OK;
234 httpResponse.ContentType = "application/octet-stream";
235 httpResponse.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
236 httpResponse.ContentLength = assetData.Length;
237 httpResponse.Body.Write(assetData, 0, assetData.Length);
238 }
239 else if (storageResponse == BackendResponse.NotFound)
240 {
241 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
242 }
243 else
244 {
245 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
246 }
247 }
248 else
249 {
250 httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
251 }
252
253 return assetData;
254 }
255
256 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
257 return assetData;
258 }
259
260 #endregion IStreamedRequestHandler implementation
261 }
262
263 //public class CreateRequestHandler : IStreamedRequestHandler
264 //{
265 // AssetInventoryServer m_server;
266 // string m_contentType;
267 // string m_httpMethod;
268 // string m_path;
269
270 // public CreateRequestHandler(AssetInventoryServer server)
271 // {
272 // m_server = server;
273 // m_contentType = null;
274 // m_httpMethod = "POST";
275 // m_path = "^/createasset";
276 // }
277
278 // #region IStreamedRequestHandler implementation
279
280 // public string ContentType
281 // {
282 // get { return m_contentType; }
283 // }
284
285 // public string HttpMethod
286 // {
287 // get { return m_httpMethod; }
288 // }
289
290 // public string Path
291 // {
292 // get { return m_path; }
293 // }
294
295 // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
296 // {
297 // byte[] responseData = null;
298 // UUID authToken = Utils.GetAuthToken(httpRequest);
299
300 // if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken))
301 // {
302 // try
303 // {
304 // OSD osdata = OSDParser.DeserializeJson(new StreamReader(httpRequest.InputStream).ReadToEnd());
305
306 // if (osdata.Type == OSDType.Map)
307 // {
308 // OSDMap map = (OSDMap)osdata;
309 // Metadata metadata = new Metadata();
310 // metadata.Deserialize(map);
311
312 // byte[] assetData = map["data"].AsBinary();
313
314 // if (assetData != null && assetData.Length > 0)
315 // {
316 // BackendResponse storageResponse;
317
318 // if (metadata.ID != UUID.Zero)
319 // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData);
320 // else
321 // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
322
323 // if (storageResponse == BackendResponse.Success)
324 // {
325 // httpResponse.StatusCode = (int) HttpStatusCode.Created;
326 // OSDMap responseMap = new OSDMap(1);
327 // responseMap["id"] = OSD.FromUUID(metadata.ID);
328 // LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
329 // responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
330 // httpResponse.Body.Write(responseData, 0, responseData.Length);
331 // httpResponse.Body.Flush();
332 // }
333 // else if (storageResponse == BackendResponse.NotFound)
334 // {
335 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
336 // }
337 // else
338 // {
339 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
340 // }
341 // }
342 // else
343 // {
344 // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
345 // }
346 // }
347 // else
348 // {
349 // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
350 // }
351 // }
352 // catch (Exception ex)
353 // {
354 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
355 // httpResponse.StatusDescription = ex.Message;
356 // }
357 // }
358 // else
359 // {
360 // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
361 // }
362
363 // return responseData;
364 // }
365
366 // #endregion IStreamedRequestHandler implementation
367 //}
368 }
369}