aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Plugins
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:26:44 +0000
committerMike Mazur2009-02-16 02:26:44 +0000
commit02cf9f7e9f879642b1a1b84373b51429e263d532 (patch)
tree8f71f112207b73adbcadd0f634ab7d0a41086551 /OpenSim/Grid/AssetInventoryServer/Plugins
parentMigrate OpenSim inventory frontend to load with Mono.Addins. Everything (diff)
downloadopensim-SC_OLD-02cf9f7e9f879642b1a1b84373b51429e263d532.zip
opensim-SC_OLD-02cf9f7e9f879642b1a1b84373b51429e263d532.tar.gz
opensim-SC_OLD-02cf9f7e9f879642b1a1b84373b51429e263d532.tar.bz2
opensim-SC_OLD-02cf9f7e9f879642b1a1b84373b51429e263d532.tar.xz
Move BrowseFrontend and ReferenceFrontend to
OpenSim/Grid/AssetInventoryServer/Plugins.
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs151
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs265
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml6
3 files changed, 422 insertions, 0 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs
new file mode 100644
index 0000000..f445b97
--- /dev/null
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs
@@ -0,0 +1,151 @@
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.Collections.Specialized;
33using System.Net;
34using System.Text;
35using System.Web;
36using OpenMetaverse;
37using HttpServer;
38using OpenSim.Framework;
39
40namespace OpenSim.Grid.AssetInventoryServer.Plugins
41{
42 public class BrowseFrontendPlugin : IAssetInventoryServerPlugin
43 {
44 AssetInventoryServer server;
45
46 public BrowseFrontendPlugin()
47 {
48 }
49
50 #region IPlugin implementation
51
52 public void Initialise(AssetInventoryServer server)
53 {
54 this.server = server;
55
56 // Request for / or /?...
57 server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler);
58
59 Logger.Log.Info("[ASSET] Browser Frontend loaded.");
60 }
61
62 /// <summary>
63 /// <para>Initialises asset interface</para>
64 /// </summary>
65 public void Initialise()
66 {
67 Logger.Log.InfoFormat("[ASSET]: {0} cannot be default-initialized!", Name);
68 throw new PluginNotInitialisedException(Name);
69 }
70
71 public void Dispose()
72 {
73 }
74
75 public string Version
76 {
77 // TODO: this should be something meaningful and not hardcoded?
78 get { return "0.1"; }
79 }
80
81 public string Name
82 {
83 get { return "AssetInventoryServer Browse asset frontend"; }
84 }
85
86 #endregion IPlugin implementation
87
88 bool BrowseRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
89 {
90 const int ASSETS_PER_PAGE = 25;
91 const string HEADER = "<html><head><title>Asset Server</title></head><body>";
92 const string TABLE_HEADER =
93 "<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>";
94 const string TABLE_FOOTER = "</table>";
95 const string FOOTER = "</body></html>";
96
97 UUID authToken = Utils.GetAuthToken(request);
98
99 StringBuilder html = new StringBuilder();
100 int start = 0;
101 uint page = 0;
102
103 if (!String.IsNullOrEmpty(request.Uri.Query))
104 {
105 NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query);
106 if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
107 start = (int)page * ASSETS_PER_PAGE;
108 }
109
110 html.AppendLine(HEADER);
111
112 html.AppendLine("<p>");
113 if (page > 0)
114 html.AppendFormat("<a href=\"{0}?page={1}\">&lt; Previous Page</a> | ", request.Uri.AbsolutePath, page - 1);
115 html.AppendFormat("<a href=\"{0}?page={1}\">Next Page &gt;</a>", request.Uri.AbsolutePath, page + 1);
116 html.AppendLine("</p>");
117
118 html.AppendLine(TABLE_HEADER);
119
120 server.StorageProvider.ForEach(
121 delegate(Metadata data)
122 {
123 if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
124 {
125 html.AppendLine(String.Format(
126 "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
127 data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
128 BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
129 }
130 else
131 {
132 html.AppendLine(String.Format(
133 "<tr><td>[Protected Asset]</td><td>&nbsp;</td><td>&nbsp;</td><td>{0}</td><td>{1}</td><td>&nbsp;</td></tr>",
134 data.ID, data.Temporary));
135 }
136 }, start, ASSETS_PER_PAGE
137 );
138
139 html.AppendLine(TABLE_FOOTER);
140
141 html.AppendLine(FOOTER);
142
143 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
144
145 response.Status = HttpStatusCode.OK;
146 response.Body.Write(responseData, 0, responseData.Length);
147 response.Body.Flush();
148 return true;
149 }
150 }
151}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
new file mode 100644
index 0000000..fddc385
--- /dev/null
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
@@ -0,0 +1,265 @@
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.Net;
33using System.Xml;
34using OpenMetaverse;
35using OpenMetaverse.StructuredData;
36using HttpServer;
37using OpenSim.Framework;
38
39namespace OpenSim.Grid.AssetInventoryServer.Plugins
40{
41 public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin
42 {
43 AssetInventoryServer server;
44
45 public ReferenceFrontendPlugin()
46 {
47 }
48
49 #region IPlugin implementation
50
51 public void Initialise(AssetInventoryServer server)
52 {
53 this.server = server;
54
55 // Asset metadata request
56 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",
57 MetadataRequestHandler);
58
59 // Asset data request
60 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",
61 DataRequestHandler);
62
63 // Asset creation
64 server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler);
65
66 Logger.Log.Info("[ASSET] Reference Frontend loaded.");
67 }
68
69 /// <summary>
70 /// <para>Initialises asset interface</para>
71 /// </summary>
72 public void Initialise()
73 {
74 Logger.Log.InfoFormat("[ASSET]: {0} cannot be default-initialized!", Name);
75 throw new PluginNotInitialisedException(Name);
76 }
77
78 public void Dispose()
79 {
80 }
81
82 public string Version
83 {
84 // TODO: this should be something meaningful and not hardcoded?
85 get { return "0.1"; }
86 }
87
88 public string Name
89 {
90 get { return "AssetInventoryServer Reference asset frontend"; }
91 }
92
93 #endregion IPlugin implementation
94
95 bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
96 {
97 UUID assetID;
98 // Split the URL up into an AssetID and a method
99 string[] rawUrl = request.Uri.PathAndQuery.Split('/');
100
101 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
102 {
103 UUID authToken = Utils.GetAuthToken(request);
104
105 if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
106 {
107 Metadata metadata;
108 BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata);
109
110 if (storageResponse == BackendResponse.Success)
111 {
112 // If the asset data location wasn't specified in the metadata, specify it
113 // manually here by pointing back to this asset server
114 if (!metadata.Methods.ContainsKey("data"))
115 {
116 metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
117 request.Uri.Scheme, request.Uri.Authority, assetID));
118 }
119
120 byte[] serializedData = metadata.SerializeToBytes();
121
122 response.Status = HttpStatusCode.OK;
123 response.ContentType = "application/json";
124 response.ContentLength = serializedData.Length;
125 response.Body.Write(serializedData, 0, serializedData.Length);
126
127 }
128 else if (storageResponse == BackendResponse.NotFound)
129 {
130 Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
131 response.Status = HttpStatusCode.NotFound;
132 }
133 else
134 {
135 response.Status = HttpStatusCode.InternalServerError;
136 }
137 }
138 else
139 {
140 response.Status = HttpStatusCode.Forbidden;
141 }
142
143 return true;
144 }
145
146 response.Status = HttpStatusCode.NotFound;
147 return true;
148 }
149
150 bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
151 {
152 UUID assetID;
153 // Split the URL up into an AssetID and a method
154 string[] rawUrl = request.Uri.PathAndQuery.Split('/');
155
156 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
157 {
158 UUID authToken = Utils.GetAuthToken(request);
159
160 if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
161 {
162 byte[] assetData;
163 BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData);
164
165 if (storageResponse == BackendResponse.Success)
166 {
167 response.Status = HttpStatusCode.OK;
168 response.Status = HttpStatusCode.OK;
169 response.ContentType = "application/octet-stream";
170 response.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
171 response.ContentLength = assetData.Length;
172 response.Body.Write(assetData, 0, assetData.Length);
173 }
174 else if (storageResponse == BackendResponse.NotFound)
175 {
176 response.Status = HttpStatusCode.NotFound;
177 }
178 else
179 {
180 response.Status = HttpStatusCode.InternalServerError;
181 }
182 }
183 else
184 {
185 response.Status = HttpStatusCode.Forbidden;
186 }
187
188 return true;
189 }
190
191 response.Status = HttpStatusCode.BadRequest;
192 return true;
193 }
194
195 bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
196 {
197 UUID authToken = Utils.GetAuthToken(request);
198
199 if (server.AuthorizationProvider.IsCreateAuthorized(authToken))
200 {
201 try
202 {
203 OSD osdata = OSDParser.DeserializeJson(request.Body);
204
205 if (osdata.Type == OSDType.Map)
206 {
207 OSDMap map = (OSDMap)osdata;
208 Metadata metadata = new Metadata();
209 metadata.Deserialize(map);
210
211 byte[] assetData = map["data"].AsBinary();
212
213 if (assetData != null && assetData.Length > 0)
214 {
215 BackendResponse storageResponse;
216
217 if (metadata.ID != UUID.Zero)
218 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
219 else
220 storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
221
222 if (storageResponse == BackendResponse.Success)
223 {
224 response.Status = HttpStatusCode.Created;
225 OSDMap responseMap = new OSDMap(1);
226 responseMap["id"] = OSD.FromUUID(metadata.ID);
227 LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
228 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
229 response.Body.Write(responseData, 0, responseData.Length);
230 response.Body.Flush();
231 }
232 else if (storageResponse == BackendResponse.NotFound)
233 {
234 response.Status = HttpStatusCode.NotFound;
235 }
236 else
237 {
238 response.Status = HttpStatusCode.InternalServerError;
239 }
240 }
241 else
242 {
243 response.Status = HttpStatusCode.BadRequest;
244 }
245 }
246 else
247 {
248 response.Status = HttpStatusCode.BadRequest;
249 }
250 }
251 catch (Exception ex)
252 {
253 response.Status = HttpStatusCode.InternalServerError;
254 response.Reason = ex.Message;
255 }
256 }
257 else
258 {
259 response.Status = HttpStatusCode.Forbidden;
260 }
261
262 return true;
263 }
264 }
265}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
index 089c6a2..0ec28de 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
@@ -10,4 +10,10 @@
10 <Extension path="/OpenSim/AssetInventoryServer/MetricsProvider"> 10 <Extension path="/OpenSim/AssetInventoryServer/MetricsProvider">
11 <Plugin id="AssetInventoryMetrics" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.NullMetricsPlugin" /> 11 <Plugin id="AssetInventoryMetrics" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.NullMetricsPlugin" />
12 </Extension> 12 </Extension>
13 <Extension path="/OpenSim/AssetInventoryServer/Frontend">
14 <Plugin id="BrowseFrontend" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.BrowseFrontendPlugin" />
15 </Extension>
16 <Extension path="/OpenSim/AssetInventoryServer/Frontend">
17 <Plugin id="ReferenceFrontend" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.ReferenceFrontendPlugin" />
18 </Extension>
13</Addin> 19</Addin>