aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:25:44 +0000
committerMike Mazur2009-02-16 02:25:44 +0000
commit16fa7f516a484e9f21fac34262214b3d9d761823 (patch)
tree925c10831c04d053b707857ffa785482316d4dcb /OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs
parentAdded OpenSim asset frontend plugin. (diff)
downloadopensim-SC-16fa7f516a484e9f21fac34262214b3d9d761823.zip
opensim-SC-16fa7f516a484e9f21fac34262214b3d9d761823.tar.gz
opensim-SC-16fa7f516a484e9f21fac34262214b3d9d761823.tar.bz2
opensim-SC-16fa7f516a484e9f21fac34262214b3d9d761823.tar.xz
Converted to Linux newlines.
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs478
1 files changed, 239 insertions, 239 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs b/OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs
index 454984e..df6bd95 100644
--- a/OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Extensions/ReferenceFrontend.cs
@@ -1,239 +1,239 @@
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
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Net; 32using System.Net;
33using System.Xml; 33using System.Xml;
34using ExtensionLoader; 34using ExtensionLoader;
35using OpenMetaverse; 35using OpenMetaverse;
36using OpenMetaverse.StructuredData; 36using OpenMetaverse.StructuredData;
37using HttpServer; 37using HttpServer;
38 38
39namespace OpenSim.Grid.AssetInventoryServer.Extensions 39namespace OpenSim.Grid.AssetInventoryServer.Extensions
40{ 40{
41 public class ReferenceFrontend : IExtension<AssetInventoryServer> 41 public class ReferenceFrontend : IExtension<AssetInventoryServer>
42 { 42 {
43 AssetInventoryServer server; 43 AssetInventoryServer server;
44 44
45 public ReferenceFrontend() 45 public ReferenceFrontend()
46 { 46 {
47 } 47 }
48 48
49 public void Start(AssetInventoryServer server) 49 public void Start(AssetInventoryServer server)
50 { 50 {
51 this.server = server; 51 this.server = server;
52 52
53 // Asset metadata request 53 // Asset metadata request
54 server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata", 54 server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata",
55 MetadataRequestHandler); 55 MetadataRequestHandler);
56 56
57 // Asset data request 57 // Asset data request
58 server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data", 58 server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data",
59 DataRequestHandler); 59 DataRequestHandler);
60 60
61 // Asset creation 61 // Asset creation
62 server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler); 62 server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler);
63 } 63 }
64 64
65 public void Stop() 65 public void Stop()
66 { 66 {
67 } 67 }
68 68
69 bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 69 bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
70 { 70 {
71 UUID assetID; 71 UUID assetID;
72 // Split the URL up into an AssetID and a method 72 // Split the URL up into an AssetID and a method
73 string[] rawUrl = request.Uri.PathAndQuery.Split('/'); 73 string[] rawUrl = request.Uri.PathAndQuery.Split('/');
74 74
75 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) 75 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
76 { 76 {
77 UUID authToken = Utils.GetAuthToken(request); 77 UUID authToken = Utils.GetAuthToken(request);
78 78
79 if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID)) 79 if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
80 { 80 {
81 Metadata metadata; 81 Metadata metadata;
82 BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata); 82 BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata);
83 83
84 if (storageResponse == BackendResponse.Success) 84 if (storageResponse == BackendResponse.Success)
85 { 85 {
86 // If the asset data location wasn't specified in the metadata, specify it 86 // If the asset data location wasn't specified in the metadata, specify it
87 // manually here by pointing back to this asset server 87 // manually here by pointing back to this asset server
88 if (!metadata.Methods.ContainsKey("data")) 88 if (!metadata.Methods.ContainsKey("data"))
89 { 89 {
90 metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data", 90 metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
91 request.Uri.Scheme, request.Uri.Authority, assetID)); 91 request.Uri.Scheme, request.Uri.Authority, assetID));
92 } 92 }
93 93
94 byte[] serializedData = metadata.SerializeToBytes(); 94 byte[] serializedData = metadata.SerializeToBytes();
95 95
96 response.Status = HttpStatusCode.OK; 96 response.Status = HttpStatusCode.OK;
97 response.ContentType = "application/json"; 97 response.ContentType = "application/json";
98 response.ContentLength = serializedData.Length; 98 response.ContentLength = serializedData.Length;
99 response.Body.Write(serializedData, 0, serializedData.Length); 99 response.Body.Write(serializedData, 0, serializedData.Length);
100 100
101 } 101 }
102 else if (storageResponse == BackendResponse.NotFound) 102 else if (storageResponse == BackendResponse.NotFound)
103 { 103 {
104 Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString()); 104 Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
105 response.Status = HttpStatusCode.NotFound; 105 response.Status = HttpStatusCode.NotFound;
106 } 106 }
107 else 107 else
108 { 108 {
109 response.Status = HttpStatusCode.InternalServerError; 109 response.Status = HttpStatusCode.InternalServerError;
110 } 110 }
111 } 111 }
112 else 112 else
113 { 113 {
114 response.Status = HttpStatusCode.Forbidden; 114 response.Status = HttpStatusCode.Forbidden;
115 } 115 }
116 116
117 return true; 117 return true;
118 } 118 }
119 119
120 response.Status = HttpStatusCode.NotFound; 120 response.Status = HttpStatusCode.NotFound;
121 return true; 121 return true;
122 } 122 }
123 123
124 bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 124 bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
125 { 125 {
126 UUID assetID; 126 UUID assetID;
127 // Split the URL up into an AssetID and a method 127 // Split the URL up into an AssetID and a method
128 string[] rawUrl = request.Uri.PathAndQuery.Split('/'); 128 string[] rawUrl = request.Uri.PathAndQuery.Split('/');
129 129
130 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) 130 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
131 { 131 {
132 UUID authToken = Utils.GetAuthToken(request); 132 UUID authToken = Utils.GetAuthToken(request);
133 133
134 if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID)) 134 if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
135 { 135 {
136 byte[] assetData; 136 byte[] assetData;
137 BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData); 137 BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData);
138 138
139 if (storageResponse == BackendResponse.Success) 139 if (storageResponse == BackendResponse.Success)
140 { 140 {
141 response.Status = HttpStatusCode.OK; 141 response.Status = HttpStatusCode.OK;
142 response.Status = HttpStatusCode.OK; 142 response.Status = HttpStatusCode.OK;
143 response.ContentType = "application/octet-stream"; 143 response.ContentType = "application/octet-stream";
144 response.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString()); 144 response.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
145 response.ContentLength = assetData.Length; 145 response.ContentLength = assetData.Length;
146 response.Body.Write(assetData, 0, assetData.Length); 146 response.Body.Write(assetData, 0, assetData.Length);
147 } 147 }
148 else if (storageResponse == BackendResponse.NotFound) 148 else if (storageResponse == BackendResponse.NotFound)
149 { 149 {
150 response.Status = HttpStatusCode.NotFound; 150 response.Status = HttpStatusCode.NotFound;
151 } 151 }
152 else 152 else
153 { 153 {
154 response.Status = HttpStatusCode.InternalServerError; 154 response.Status = HttpStatusCode.InternalServerError;
155 } 155 }
156 } 156 }
157 else 157 else
158 { 158 {
159 response.Status = HttpStatusCode.Forbidden; 159 response.Status = HttpStatusCode.Forbidden;
160 } 160 }
161 161
162 return true; 162 return true;
163 } 163 }
164 164
165 response.Status = HttpStatusCode.BadRequest; 165 response.Status = HttpStatusCode.BadRequest;
166 return true; 166 return true;
167 } 167 }
168 168
169 bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) 169 bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
170 { 170 {
171 UUID authToken = Utils.GetAuthToken(request); 171 UUID authToken = Utils.GetAuthToken(request);
172 172
173 if (server.AuthorizationProvider.IsCreateAuthorized(authToken)) 173 if (server.AuthorizationProvider.IsCreateAuthorized(authToken))
174 { 174 {
175 try 175 try
176 { 176 {
177 OSD osdata = OSDParser.DeserializeJson(request.Body); 177 OSD osdata = OSDParser.DeserializeJson(request.Body);
178 178
179 if (osdata.Type == OSDType.Map) 179 if (osdata.Type == OSDType.Map)
180 { 180 {
181 OSDMap map = (OSDMap)osdata; 181 OSDMap map = (OSDMap)osdata;
182 Metadata metadata = new Metadata(); 182 Metadata metadata = new Metadata();
183 metadata.Deserialize(map); 183 metadata.Deserialize(map);
184 184
185 byte[] assetData = map["data"].AsBinary(); 185 byte[] assetData = map["data"].AsBinary();
186 186
187 if (assetData != null && assetData.Length > 0) 187 if (assetData != null && assetData.Length > 0)
188 { 188 {
189 BackendResponse storageResponse; 189 BackendResponse storageResponse;
190 190
191 if (metadata.ID != UUID.Zero) 191 if (metadata.ID != UUID.Zero)
192 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData); 192 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
193 else 193 else
194 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID); 194 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
195 195
196 if (storageResponse == BackendResponse.Success) 196 if (storageResponse == BackendResponse.Success)
197 { 197 {
198 response.Status = HttpStatusCode.Created; 198 response.Status = HttpStatusCode.Created;
199 OSDMap responseMap = new OSDMap(1); 199 OSDMap responseMap = new OSDMap(1);
200 responseMap["id"] = OSD.FromUUID(metadata.ID); 200 responseMap["id"] = OSD.FromUUID(metadata.ID);
201 LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap); 201 LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
202 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson()); 202 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
203 response.Body.Write(responseData, 0, responseData.Length); 203 response.Body.Write(responseData, 0, responseData.Length);
204 response.Body.Flush(); 204 response.Body.Flush();
205 } 205 }
206 else if (storageResponse == BackendResponse.NotFound) 206 else if (storageResponse == BackendResponse.NotFound)
207 { 207 {
208 response.Status = HttpStatusCode.NotFound; 208 response.Status = HttpStatusCode.NotFound;
209 } 209 }
210 else 210 else
211 { 211 {
212 response.Status = HttpStatusCode.InternalServerError; 212 response.Status = HttpStatusCode.InternalServerError;
213 } 213 }
214 } 214 }
215 else 215 else
216 { 216 {
217 response.Status = HttpStatusCode.BadRequest; 217 response.Status = HttpStatusCode.BadRequest;
218 } 218 }
219 } 219 }
220 else 220 else
221 { 221 {
222 response.Status = HttpStatusCode.BadRequest; 222 response.Status = HttpStatusCode.BadRequest;
223 } 223 }
224 } 224 }
225 catch (Exception ex) 225 catch (Exception ex)
226 { 226 {
227 response.Status = HttpStatusCode.InternalServerError; 227 response.Status = HttpStatusCode.InternalServerError;
228 response.Reason = ex.Message; 228 response.Reason = ex.Message;
229 } 229 }
230 } 230 }
231 else 231 else
232 { 232 {
233 response.Status = HttpStatusCode.Forbidden; 233 response.Status = HttpStatusCode.Forbidden;
234 } 234 }
235 235
236 return true; 236 return true;
237 } 237 }
238 } 238 }
239} 239}