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