aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:25:36 +0000
committerMike Mazur2009-02-16 02:25:36 +0000
commit617016fa6870765d1799ba4c73731fcca30920ad (patch)
tree4173a7b3d3d52c63196439d678bd6d67abbf47d6 /OpenSim
parentRename NewAssetServer AssetInventoryServer and fully qualify with (diff)
downloadopensim-SC_OLD-617016fa6870765d1799ba4c73731fcca30920ad.zip
opensim-SC_OLD-617016fa6870765d1799ba4c73731fcca30920ad.tar.gz
opensim-SC_OLD-617016fa6870765d1799ba4c73731fcca30920ad.tar.bz2
opensim-SC_OLD-617016fa6870765d1799ba4c73731fcca30920ad.tar.xz
Added OpenSim asset frontend plugin.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs10
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs240
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs102
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml7
4 files changed, 312 insertions, 47 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
index 2c588f5..a769448 100644
--- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
+++ b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
@@ -55,6 +55,8 @@ namespace OpenSim.Grid.AssetInventoryServer
55 public IAuthorizationProvider AuthorizationProvider; 55 public IAuthorizationProvider AuthorizationProvider;
56 public IMetricsProvider MetricsProvider; 56 public IMetricsProvider MetricsProvider;
57 57
58 private IAssetInventoryServerPlugin frontend;
59
58 public AssetInventoryServer() 60 public AssetInventoryServer()
59 { 61 {
60 this.ServiceName = "OpenSimAssetInventoryServer"; 62 this.ServiceName = "OpenSimAssetInventoryServer";
@@ -138,7 +140,7 @@ namespace OpenSim.Grid.AssetInventoryServer
138 // return false; 140 // return false;
139 //} 141 //}
140 142
141 StorageProvider = LoadAssetInventoryServerPlugin() as IAssetStorageProvider; 143 StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider") as IAssetStorageProvider;
142 144
143 try 145 try
144 { 146 {
@@ -151,6 +153,8 @@ namespace OpenSim.Grid.AssetInventoryServer
151 return false; 153 return false;
152 } 154 }
153 155
156 frontend = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/Frontend");
157
154 // Start all of the extensions 158 // Start all of the extensions
155 //foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions) 159 //foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
156 //{ 160 //{
@@ -215,13 +219,13 @@ namespace OpenSim.Grid.AssetInventoryServer
215 219
216 #endregion 220 #endregion
217 221
218 private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin() 222 private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin(string addinPath)
219 { 223 {
220 PluginLoader<IAssetInventoryServerPlugin> loader = new PluginLoader<IAssetInventoryServerPlugin>(new AssetInventoryServerPluginInitialiser(this)); 224 PluginLoader<IAssetInventoryServerPlugin> loader = new PluginLoader<IAssetInventoryServerPlugin>(new AssetInventoryServerPluginInitialiser(this));
221 225
222 //loader.Add ("/OpenSim/AssetInventoryServer/StorageProvider", new PluginProviderFilter (provider)); 226 //loader.Add ("/OpenSim/AssetInventoryServer/StorageProvider", new PluginProviderFilter (provider));
223 //loader.Add("/OpenSim/AssetInventoryServer/StorageProvider", new PluginCountConstraint(1)); 227 //loader.Add("/OpenSim/AssetInventoryServer/StorageProvider", new PluginCountConstraint(1));
224 loader.Add("/OpenSim/AssetInventoryServer/StorageProvider"); 228 loader.Add(addinPath);
225 loader.Load(); 229 loader.Load();
226 230
227 return loader.Plugin; 231 return loader.Plugin;
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
new file mode 100644
index 0000000..e76c8ee
--- /dev/null
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
@@ -0,0 +1,240 @@
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.IO;
34using System.Xml;
35using ExtensionLoader;
36using OpenMetaverse;
37using HttpServer;
38using OpenSim.Framework;
39
40namespace OpenSim.Grid.AssetInventoryServer.Plugins
41{
42 public class OpenSimAssetFrontendPlugin : IAssetInventoryServerPlugin
43 {
44 AssetInventoryServer server;
45
46 public OpenSimAssetFrontendPlugin()
47 {
48 }
49
50 #region IPlugin implementation
51
52 public void Initialise(AssetInventoryServer server)
53 {
54 this.server = server;
55
56 // Asset request
57 server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler);
58
59 // Asset creation
60 server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler);
61 }
62
63 /// <summary>
64 /// <para>Initialises asset interface</para>
65 /// </summary>
66 public void Initialise()
67 {
68 Logger.Log.InfoFormat("[ASSET]: {0} cannot be default-initialized!", Name);
69 throw new PluginNotInitialisedException(Name);
70 }
71
72 public void Dispose()
73 {
74 }
75
76 public string Version
77 {
78 // TODO: this should be something meaningful and not hardcoded?
79 get { return "0.1"; }
80 }
81
82 public string Name
83 {
84 get { return "AssetInventoryServer OpenSim asset frontend"; }
85 }
86
87 #endregion IPlugin implementation
88
89 bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
90 {
91 UUID assetID;
92 // Split the URL up to get the asset ID out
93 string[] rawUrl = request.Uri.PathAndQuery.Split('/');
94
95 if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
96 {
97 Metadata metadata;
98 byte[] assetData;
99 BackendResponse dataResponse;
100
101 if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
102 {
103 MemoryStream stream = new MemoryStream();
104
105 XmlWriterSettings settings = new XmlWriterSettings();
106 settings.Indent = true;
107 XmlWriter writer = XmlWriter.Create(stream, settings);
108
109 writer.WriteStartDocument();
110 writer.WriteStartElement("AssetBase");
111 writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
112 writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
113 writer.WriteStartElement("FullID");
114 writer.WriteStartElement("Guid");
115 writer.WriteString(assetID.ToString());
116 writer.WriteEndElement();
117 writer.WriteEndElement();
118 writer.WriteStartElement("ID");
119 writer.WriteString(assetID.ToString());
120 writer.WriteEndElement();
121 writer.WriteStartElement("Data");
122 writer.WriteBase64(assetData, 0, assetData.Length);
123 writer.WriteEndElement();
124 writer.WriteStartElement("Type");
125 writer.WriteValue(Utils.ContentTypeToSLAssetType(metadata.ContentType));
126 writer.WriteEndElement();
127 writer.WriteStartElement("Name");
128 writer.WriteString(metadata.Name);
129 writer.WriteEndElement();
130 writer.WriteStartElement("Description");
131 writer.WriteString(metadata.Description);
132 writer.WriteEndElement();
133 writer.WriteStartElement("Local");
134 writer.WriteValue(false);
135 writer.WriteEndElement();
136 writer.WriteStartElement("Temporary");
137 writer.WriteValue(metadata.Temporary);
138 writer.WriteEndElement();
139 writer.WriteEndElement();
140 writer.WriteEndDocument();
141
142 writer.Flush();
143 byte[] buffer = stream.GetBuffer();
144
145 response.Status = HttpStatusCode.OK;
146 response.ContentType = "application/xml";
147 response.ContentLength = stream.Length;
148 response.Body.Write(buffer, 0, (int)stream.Length);
149 response.Body.Flush();
150 }
151 else
152 {
153 Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
154 response.Status = HttpStatusCode.NotFound;
155 }
156 }
157 else
158 {
159 Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery);
160 }
161
162 return true;
163 }
164
165 bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
166 {
167 byte[] assetData = null;
168 Metadata metadata = new Metadata();
169
170 Logger.Log.Debug("Handling OpenSim asset upload");
171
172 try
173 {
174 using (XmlReader reader = XmlReader.Create(request.Body))
175 {
176 reader.MoveToContent();
177 reader.ReadStartElement("AssetBase");
178
179 reader.ReadStartElement("FullID");
180 UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out metadata.ID);
181 reader.ReadEndElement();
182 reader.ReadStartElement("ID");
183 reader.Skip();
184 reader.ReadEndElement();
185
186 // HACK: Broken on Mono. https://bugzilla.novell.com/show_bug.cgi?id=464229
187 //int readBytes = 0;
188 //byte[] buffer = new byte[1024];
189 //MemoryStream stream = new MemoryStream();
190 //BinaryWriter writer = new BinaryWriter(stream);
191 //while ((readBytes = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length)) > 0)
192 // writer.Write(buffer, 0, readBytes);
193 //writer.Flush();
194 //assetData = stream.GetBuffer();
195 //Array.Resize<byte>(ref assetData, (int)stream.Length);
196
197 assetData = Convert.FromBase64String(reader.ReadElementContentAsString());
198
199 int type;
200 Int32.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out type);
201 metadata.ContentType = Utils.SLAssetTypeToContentType(type);
202 metadata.Name = reader.ReadElementContentAsString("Name", String.Empty);
203 metadata.Description = reader.ReadElementContentAsString("Description", String.Empty);
204 Boolean.TryParse(reader.ReadElementContentAsString("Local", String.Empty), out metadata.Temporary);
205 Boolean.TryParse(reader.ReadElementContentAsString("Temporary", String.Empty), out metadata.Temporary);
206
207 reader.ReadEndElement();
208 }
209
210 if (assetData != null && assetData.Length > 0)
211 {
212 metadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData);
213 metadata.CreationDate = DateTime.Now;
214
215 BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
216
217 if (storageResponse == BackendResponse.Success)
218 response.Status = HttpStatusCode.Created;
219 else if (storageResponse == BackendResponse.NotFound)
220 response.Status = HttpStatusCode.NotFound;
221 else
222 response.Status = HttpStatusCode.InternalServerError;
223 }
224 else
225 {
226 Logger.Log.Warn("AssetPostHandler called with no asset data");
227 response.Status = HttpStatusCode.BadRequest;
228 }
229 }
230 catch (Exception ex)
231 {
232 Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
233 response.Status = HttpStatusCode.BadRequest;
234 }
235
236 Logger.Log.Debug("Finished handling OpenSim asset upload, Status: " + response.Status.ToString());
237 return true;
238 }
239 }
240}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
index 7f5f85a..148b401 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
@@ -142,50 +142,68 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
142 { 142 {
143 metadata = null; 143 metadata = null;
144 assetData = null; 144 assetData = null;
145 BackendResponse ret; 145 //BackendResponse ret;
146
147 using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
148 {
149 IDataReader reader;
150
151 try
152 {
153 dbConnection.Open();
154
155 IDbCommand command = dbConnection.CreateCommand();
156 command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString());
157 reader = command.ExecuteReader();
158
159 if (reader.Read())
160 {
161 metadata = new Metadata();
162 metadata.CreationDate = OpenMetaverse.Utils.Epoch;
163 metadata.SHA1 = null;
164 metadata.ID = assetID;
165 metadata.Name = reader.GetString(0);
166 metadata.Description = reader.GetString(1);
167 metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
168 metadata.Temporary = reader.GetBoolean(3);
169 146
170 assetData = (byte[])reader.GetValue(4); 147 AssetBase asset_base = m_assetProvider.FetchAsset(assetID);
171 148
172 ret = BackendResponse.Success; 149 if (asset_base != null)
173 } 150 {
174 else 151 metadata = new Metadata();
175 { 152 metadata.CreationDate = OpenMetaverse.Utils.Epoch;
176 ret = BackendResponse.NotFound; 153 metadata.SHA1 = null;
177 } 154 metadata.Name = asset_base.Name;
178 } 155 metadata.Description = asset_base.Description;
179 catch (MySqlException ex) 156 metadata.ContentType = Utils.SLAssetTypeToContentType(asset_base.Type);
180 { 157 metadata.Temporary = asset_base.Temporary;
181 Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); 158
182 ret = BackendResponse.Failure; 159 assetData = asset_base.Data;
183 }
184 } 160 }
185 161 else return BackendResponse.NotFound;
186 server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); 162
187 server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); 163 return BackendResponse.Success;
188 return ret; 164
165 //using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
166 //{
167 // IDataReader reader;
168
169 // try
170 // {
171 // dbConnection.Open();
172
173 // IDbCommand command = dbConnection.CreateCommand();
174 // command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString());
175 // reader = command.ExecuteReader();
176
177 // if (reader.Read())
178 // {
179 // metadata = new Metadata();
180 // metadata.CreationDate = OpenMetaverse.Utils.Epoch;
181 // metadata.SHA1 = null;
182 // metadata.ID = assetID;
183 // metadata.Name = reader.GetString(0);
184 // metadata.Description = reader.GetString(1);
185 // metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
186 // metadata.Temporary = reader.GetBoolean(3);
187
188 // assetData = (byte[])reader.GetValue(4);
189
190 // ret = BackendResponse.Success;
191 // }
192 // else
193 // {
194 // ret = BackendResponse.NotFound;
195 // }
196 // }
197 // catch (MySqlException ex)
198 // {
199 // Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
200 // ret = BackendResponse.Failure;
201 // }
202 //}
203
204 //server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
205 //server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
206 //return ret;
189 } 207 }
190 208
191 public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) 209 public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID)
@@ -332,7 +350,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
332 350
333 public string Name 351 public string Name
334 { 352 {
335 get { return "AssetInventoryServer storage provider"; } 353 get { return "AssetInventoryServer OpenSim asset storage provider"; }
336 } 354 }
337 355
338 #endregion IPlugin implementation 356 #endregion IPlugin implementation
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml
index eeda54a..a7e5dec 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml
@@ -1,14 +1,17 @@
1<Addin id="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim" version="0.1"> 1<Addin id="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim" version="0.1">
2 <Runtime> 2 <Runtime>
3 <Import assembly="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll"/> 3 <Import assembly="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" />
4 </Runtime> 4 </Runtime>
5 <Dependencies> 5 <Dependencies>
6 <Addin id="OpenSim.Grid.AssetInventoryServer" version="0.1" /> 6 <Addin id="OpenSim.Grid.AssetInventoryServer" version="0.1" />
7 </Dependencies> 7 </Dependencies>
8 <ExtensionPoint path = "/OpenSim/AssetData"> 8 <ExtensionPoint path = "/OpenSim/AssetData">
9 <ExtensionNode name="Plugin" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.Framework.IAssetProviderPlugin"/> 9 <ExtensionNode name="Plugin" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.Framework.IAssetProviderPlugin" />
10 </ExtensionPoint> 10 </ExtensionPoint>
11 <Extension path="/OpenSim/AssetInventoryServer/StorageProvider"> 11 <Extension path="/OpenSim/AssetInventoryServer/StorageProvider">
12 <Plugin id="OpenSimAssetStorage" provider="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSimAssetStoragePlugin" /> 12 <Plugin id="OpenSimAssetStorage" provider="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSimAssetStoragePlugin" />
13 </Extension> 13 </Extension>
14 <Extension path="/OpenSim/AssetInventoryServer/Frontend">
15 <Plugin id="OpenSimAssetFrontend" provider="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSimAssetFrontendPlugin" />
16 </Extension>
14</Addin> 17</Addin>