aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs272
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs1
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs7
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml3
4 files changed, 283 insertions, 0 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs
new file mode 100644
index 0000000..8d60aa6
--- /dev/null
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs
@@ -0,0 +1,272 @@
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.Net;
30using System.IO;
31using System.IO.Compression;
32using System.Xml;
33using System.Reflection;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Servers;
37using OpenSim.Region.CoreModules.World.Archiver;
38using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
39using log4net;
40
41namespace OpenSim.Grid.AssetInventoryServer.Plugins
42{
43 public class InventoryArchivePlugin : IAssetInventoryServerPlugin
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 private AssetInventoryServer m_server;
47
48 public InventoryArchivePlugin()
49 {
50 }
51
52 #region IPlugin implementation
53
54 public void Initialise(AssetInventoryServer server)
55 {
56 m_server = server;
57
58 m_server.HttpServer.AddStreamHandler(new GetInventoryArchive(server));
59
60 m_log.Info("[INVENTORYARCHIVE]: Inventory Archive loaded.");
61 }
62
63 /// <summary>
64 /// <para>Initialises asset interface</para>
65 /// </summary>
66 public void Initialise()
67 {
68 m_log.InfoFormat("[INVENTORYARCHIVE]: {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 "InventoryArchive"; }
85 }
86
87 #endregion IPlugin implementation
88
89 public class GetInventoryArchive : BaseStreamHandler
90 {
91 AssetInventoryServer m_server;
92
93 //public GetInventoryArchive(AssetInventoryServer server) : base("GET", @"^/inventoryarchive/")
94 public GetInventoryArchive(AssetInventoryServer server) : base("GET", "/inventoryarchive")
95 {
96 m_server = server;
97 }
98
99 public override string ContentType
100 {
101 get { return "application/x-compressed"; }
102 }
103
104 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
105 {
106 byte[] buffer = new byte[] {};
107 UUID ownerID;
108 // Split the URL up to get the asset ID out
109 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
110
111 if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out ownerID))
112 {
113 Uri owner = Utils.GetOpenSimUri(ownerID);
114 InventoryCollection inventory;
115 BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory);
116
117 if (storageResponse == BackendResponse.Success)
118 {
119 m_log.DebugFormat("[INVENTORYARCHIVE]: Archiving inventory for user UUID {0}", ownerID);
120 buffer = ArchiveInventoryCollection(inventory);
121 httpResponse.StatusCode = (int) HttpStatusCode.OK;
122 }
123 else
124 {
125 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
126 }
127 }
128 else
129 {
130 m_log.Warn("[INVENTORYARCHIVE]: Unrecognized inventory archive request: " + httpRequest.Url.PathAndQuery);
131 }
132
133 return buffer;
134 }
135 }
136
137 private static byte[] ArchiveInventoryCollection(InventoryCollection inventory)
138 {
139 byte[] buffer = new byte[] {};
140
141 // Fill in each folder's Children dictionary.
142 InventoryFolderWithChildren rootFolder = BuildInventoryHierarchy(ref inventory);
143
144 // TODO: It's probably a bad idea to tar to memory for large
145 // inventories.
146 MemoryStream ms = new MemoryStream();
147 GZipStream gzs = new GZipStream(ms, CompressionMode.Compress, true);
148 TarArchiveWriter archive = new TarArchiveWriter(gzs);
149 WriteInventoryFolderToArchive(archive, rootFolder, InventoryArchiveConstants.INVENTORY_PATH);
150
151 archive.Close();
152
153 ms.Seek(0, SeekOrigin.Begin);
154 buffer = ms.GetBuffer();
155 Array.Resize<byte>(ref buffer, (int) ms.Length);
156 ms.Close();
157 return buffer;
158 }
159
160 private static InventoryFolderWithChildren BuildInventoryHierarchy(ref InventoryCollection inventory)
161 {
162 m_log.DebugFormat("[INVENTORYARCHIVE]: Building inventory hierarchy");
163 InventoryFolderWithChildren rootFolder = null;
164
165 foreach (InventoryFolderWithChildren parentFolder in inventory.Folders.Values)
166 {
167 // Grab the root folder, it has no parents.
168 if (UUID.Zero == parentFolder.ParentID) rootFolder = parentFolder;
169
170 foreach (InventoryFolderWithChildren folder in inventory.Folders.Values)
171 if (parentFolder.ID == folder.ParentID)
172 parentFolder.Children.Add(folder.ID, folder);
173
174 foreach (InventoryItemBase item in inventory.Items.Values)
175 if (parentFolder.ID == item.Folder)
176 parentFolder.Children.Add(item.ID, item);
177 }
178
179 return rootFolder;
180 }
181
182 private static void WriteInventoryFolderToArchive(TarArchiveWriter archive, InventoryFolderWithChildren folder, string path)
183 {
184 path += string.Format("{0}{1}{2}/", folder.Name, InventoryArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folder.ID);
185 archive.WriteDir(path);
186
187 foreach (InventoryNodeBase inventoryNode in folder.Children.Values)
188 {
189 if (inventoryNode is InventoryFolderWithChildren)
190 {
191 WriteInventoryFolderToArchive(archive, (InventoryFolderWithChildren) inventoryNode, path);
192 }
193 else if (inventoryNode is InventoryItemBase)
194 {
195 WriteInventoryItemToArchive(archive, (InventoryItemBase) inventoryNode, path);
196 }
197 }
198 }
199
200 private static void WriteInventoryItemToArchive(TarArchiveWriter archive, InventoryItemBase item, string path)
201 {
202 string filename = string.Format("{0}{1}_{2}.xml", path, item.Name, item.ID);
203
204 StringWriter sw = new StringWriter();
205 XmlTextWriter writer = new XmlTextWriter(sw);
206 writer.Formatting = Formatting.Indented;
207
208 writer.WriteStartElement("InventoryItem");
209
210 writer.WriteStartElement("Name");
211 writer.WriteString(item.Name);
212 writer.WriteEndElement();
213 writer.WriteStartElement("ID");
214 writer.WriteString(item.ID.ToString());
215 writer.WriteEndElement();
216 writer.WriteStartElement("InvType");
217 writer.WriteString(item.InvType.ToString());
218 writer.WriteEndElement();
219 writer.WriteStartElement("CreatorUUID");
220 writer.WriteString(item.Creator.ToString());
221 writer.WriteEndElement();
222 writer.WriteStartElement("CreationDate");
223 writer.WriteString(item.CreationDate.ToString());
224 writer.WriteEndElement();
225 writer.WriteStartElement("Owner");
226 writer.WriteString(item.Owner.ToString());
227 writer.WriteEndElement();
228 writer.WriteStartElement("Description");
229 writer.WriteString(item.Description);
230 writer.WriteEndElement();
231 writer.WriteStartElement("AssetType");
232 writer.WriteString(item.AssetType.ToString());
233 writer.WriteEndElement();
234 writer.WriteStartElement("AssetID");
235 writer.WriteString(item.AssetID.ToString());
236 writer.WriteEndElement();
237 writer.WriteStartElement("SaleType");
238 writer.WriteString(item.SaleType.ToString());
239 writer.WriteEndElement();
240 writer.WriteStartElement("SalePrice");
241 writer.WriteString(item.SalePrice.ToString());
242 writer.WriteEndElement();
243 writer.WriteStartElement("BasePermissions");
244 writer.WriteString(item.BasePermissions.ToString());
245 writer.WriteEndElement();
246 writer.WriteStartElement("CurrentPermissions");
247 writer.WriteString(item.CurrentPermissions.ToString());
248 writer.WriteEndElement();
249 writer.WriteStartElement("EveryOnePermssions");
250 writer.WriteString(item.EveryOnePermissions.ToString());
251 writer.WriteEndElement();
252 writer.WriteStartElement("NextPermissions");
253 writer.WriteString(item.NextPermissions.ToString());
254 writer.WriteEndElement();
255 writer.WriteStartElement("Flags");
256 writer.WriteString(item.Flags.ToString());
257 writer.WriteEndElement();
258 writer.WriteStartElement("GroupID");
259 writer.WriteString(item.GroupID.ToString());
260 writer.WriteEndElement();
261 writer.WriteStartElement("GroupOwned");
262 writer.WriteString(item.GroupOwned.ToString());
263 writer.WriteEndElement();
264
265 writer.WriteEndElement();
266
267 archive.WriteFile(filename, sw.ToString());
268
269 //m_assetGatherer.GatherAssetUuids(item.AssetID, (AssetType) item.AssetType, assetUuids);
270 }
271 }
272}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
index b05e523..ee35ae2 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
@@ -122,6 +122,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
122 ms.Seek(0, SeekOrigin.Begin); 122 ms.Seek(0, SeekOrigin.Begin);
123 buffer = ms.GetBuffer(); 123 buffer = ms.GetBuffer();
124 Array.Resize<byte>(ref buffer, (int) ms.Length); 124 Array.Resize<byte>(ref buffer, (int) ms.Length);
125 ms.Close();
125 httpResponse.StatusCode = (int) HttpStatusCode.OK; 126 httpResponse.StatusCode = (int) HttpStatusCode.OK;
126 } 127 }
127 else 128 else
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
index d0388fb..c226a26 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
@@ -129,6 +129,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
129 ms.Seek(0, SeekOrigin.Begin); 129 ms.Seek(0, SeekOrigin.Begin);
130 buffer = ms.GetBuffer(); 130 buffer = ms.GetBuffer();
131 Array.Resize<byte>(ref buffer, (int) ms.Length); 131 Array.Resize<byte>(ref buffer, (int) ms.Length);
132 ms.Close();
132 httpResponse.StatusCode = (int) HttpStatusCode.OK; 133 httpResponse.StatusCode = (int) HttpStatusCode.OK;
133 } 134 }
134 else if (storageResponse == BackendResponse.NotFound) 135 else if (storageResponse == BackendResponse.NotFound)
@@ -145,6 +146,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
145 ms.Seek(0, SeekOrigin.Begin); 146 ms.Seek(0, SeekOrigin.Begin);
146 buffer = ms.GetBuffer(); 147 buffer = ms.GetBuffer();
147 Array.Resize<byte>(ref buffer, (int) ms.Length); 148 Array.Resize<byte>(ref buffer, (int) ms.Length);
149 ms.Close();
148 httpResponse.StatusCode = (int) HttpStatusCode.OK; 150 httpResponse.StatusCode = (int) HttpStatusCode.OK;
149 } 151 }
150 else 152 else
@@ -404,6 +406,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
404 ms.Seek(0, SeekOrigin.Begin); 406 ms.Seek(0, SeekOrigin.Begin);
405 buffer = ms.GetBuffer(); 407 buffer = ms.GetBuffer();
406 Array.Resize<byte>(ref buffer, (int) ms.Length); 408 Array.Resize<byte>(ref buffer, (int) ms.Length);
409 ms.Close();
407 httpResponse.StatusCode = (int) HttpStatusCode.OK; 410 httpResponse.StatusCode = (int) HttpStatusCode.OK;
408 } 411 }
409 else if (storageResponse == BackendResponse.NotFound) 412 else if (storageResponse == BackendResponse.NotFound)
@@ -415,6 +418,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
415 ms.Seek(0, SeekOrigin.Begin); 418 ms.Seek(0, SeekOrigin.Begin);
416 buffer = ms.GetBuffer(); 419 buffer = ms.GetBuffer();
417 Array.Resize<byte>(ref buffer, (int) ms.Length); 420 Array.Resize<byte>(ref buffer, (int) ms.Length);
421 ms.Close();
418 httpResponse.StatusCode = (int) HttpStatusCode.OK; 422 httpResponse.StatusCode = (int) HttpStatusCode.OK;
419 } 423 }
420 else 424 else
@@ -459,6 +463,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
459 ms.Seek(0, SeekOrigin.Begin); 463 ms.Seek(0, SeekOrigin.Begin);
460 buffer = ms.GetBuffer(); 464 buffer = ms.GetBuffer();
461 Array.Resize<byte>(ref buffer, (int) ms.Length); 465 Array.Resize<byte>(ref buffer, (int) ms.Length);
466 ms.Close();
462 httpResponse.StatusCode = (int) HttpStatusCode.OK; 467 httpResponse.StatusCode = (int) HttpStatusCode.OK;
463 } 468 }
464 else if (storageResponse == BackendResponse.NotFound) 469 else if (storageResponse == BackendResponse.NotFound)
@@ -469,6 +474,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
469 ms.Seek(0, SeekOrigin.Begin); 474 ms.Seek(0, SeekOrigin.Begin);
470 buffer = ms.GetBuffer(); 475 buffer = ms.GetBuffer();
471 Array.Resize<byte>(ref buffer, (int) ms.Length); 476 Array.Resize<byte>(ref buffer, (int) ms.Length);
477 ms.Close();
472 httpResponse.StatusCode = (int) HttpStatusCode.OK; 478 httpResponse.StatusCode = (int) HttpStatusCode.OK;
473 } 479 }
474 else 480 else
@@ -695,6 +701,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
695 ms.Seek(0, SeekOrigin.Begin); 701 ms.Seek(0, SeekOrigin.Begin);
696 buffer = ms.GetBuffer(); 702 buffer = ms.GetBuffer();
697 Array.Resize<byte>(ref buffer, (int) ms.Length); 703 Array.Resize<byte>(ref buffer, (int) ms.Length);
704 ms.Close();
698 705
699 return buffer; 706 return buffer;
700 } 707 }
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
index c1e5c4d..42a279d 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
@@ -22,4 +22,7 @@
22 <Extension path="/OpenSim/AssetInventoryServer/AuthorizationProvider"> 22 <Extension path="/OpenSim/AssetInventoryServer/AuthorizationProvider">
23 <Plugin id="AuthorizeAll" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.AuthorizeAllPlugin" /> 23 <Plugin id="AuthorizeAll" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.AuthorizeAllPlugin" />
24 </Extension> 24 </Extension>
25 <Extension path="/OpenSim/AssetInventoryServer/Frontend">
26 <Plugin id="InventoryArchive" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.InventoryArchivePlugin" />
27 </Extension>
25</Addin> 28</Addin>