aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Plugins
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs105
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs173
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs211
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs95
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs151
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs198
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs189
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs867
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs56
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs547
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml27
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs369
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml28
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml16
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs290
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs625
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs71
17 files changed, 0 insertions, 4018 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs
deleted file mode 100644
index 3d0a283..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs
+++ /dev/null
@@ -1,105 +0,0 @@
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.Reflection;
30using OpenMetaverse;
31using OpenSim.Framework;
32using log4net;
33
34namespace OpenSim.Grid.AssetInventoryServer.Plugins
35{
36 public class AuthorizeAllPlugin : IAuthorizationProvider
37 {
38 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
39 //private AssetInventoryServer m_server;
40
41 public AuthorizeAllPlugin()
42 {
43 }
44
45 #region IPlugin implementation
46
47 public void Initialise(AssetInventoryServer server)
48 {
49 //m_server = server;
50
51 m_log.Info("[AUTHORIZEALL]: Authorize All loaded.");
52 }
53
54 /// <summary>
55 /// <para>Initialises asset interface</para>
56 /// </summary>
57 public void Initialise()
58 {
59 m_log.InfoFormat("[AUTHORIZEALL]: {0} cannot be default-initialized!", Name);
60 throw new PluginNotInitialisedException(Name);
61 }
62
63 public void Dispose()
64 {
65 }
66
67 public string Version
68 {
69 // TODO: this should be something meaningful and not hardcoded?
70 get { return "0.1"; }
71 }
72
73 public string Name
74 {
75 get { return "AuthorizeAll"; }
76 }
77
78 #endregion IPlugin implementation
79
80 public bool IsMetadataAuthorized(UUID authToken, UUID assetID)
81 {
82 return true;
83 }
84
85 public bool IsDataAuthorized(UUID authToken, UUID assetID)
86 {
87 return true;
88 }
89
90 public bool IsCreateAuthorized(UUID authToken)
91 {
92 return true;
93 }
94
95 public bool IsInventoryReadAuthorized(UUID authToken, Uri owner)
96 {
97 return true;
98 }
99
100 public bool IsInventoryWriteAuthorized(UUID authToken, Uri owner)
101 {
102 return true;
103 }
104 }
105}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs
deleted file mode 100644
index 90ea2e0..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs
+++ /dev/null
@@ -1,173 +0,0 @@
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.IO;
30using System.Reflection;
31using System.Collections.Specialized;
32using System.Net;
33using System.Text;
34using System.Web;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Servers.HttpServer;
39using log4net;
40
41namespace OpenSim.Grid.AssetInventoryServer.Plugins
42{
43 public class BrowseFrontendPlugin : IAssetInventoryServerPlugin
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 private AssetInventoryServer m_server;
47
48 public BrowseFrontendPlugin()
49 {
50 }
51
52 #region IPlugin implementation
53
54 public void Initialise(AssetInventoryServer server)
55 {
56 m_server = server;
57
58 // Request for / or /?...
59 m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server));
60
61 m_log.Info("[BROWSEFRONTEND]: Browser Frontend loaded.");
62 }
63
64 /// <summary>
65 /// <para>Initialises asset interface</para>
66 /// </summary>
67 public void Initialise()
68 {
69 m_log.InfoFormat("[BROWSEFRONTEND]: {0} cannot be default-initialized!", Name);
70 throw new PluginNotInitialisedException(Name);
71 }
72
73 public void Dispose()
74 {
75 }
76
77 public string Version
78 {
79 // TODO: this should be something meaningful and not hardcoded?
80 get { return "0.1"; }
81 }
82
83 public string Name
84 {
85 get { return "BrowseFrontend"; }
86 }
87
88 #endregion IPlugin implementation
89
90 public class BrowseRequestHandler : BaseStreamHandler
91 {
92 AssetInventoryServer m_server;
93
94 //public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "(^/$|(^/\?.*)")
95 public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "/")
96 {
97 m_server = server;
98 }
99
100 public override string ContentType
101 {
102 get { return "text/html"; }
103 }
104
105 #region IStreamedRequestHandler implementation
106
107 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
108 {
109 const int ASSETS_PER_PAGE = 25;
110 const string HEADER = "<html><head><title>Asset Server</title></head><body>";
111 const string TABLE_HEADER =
112 "<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>";
113 const string TABLE_FOOTER = "</table>";
114 const string FOOTER = "</body></html>";
115
116 UUID authToken = Utils.GetAuthToken(httpRequest);
117
118 StringBuilder html = new StringBuilder();
119 int start = 0;
120 uint page = 0;
121
122 if (!String.IsNullOrEmpty(httpRequest.Url.Query))
123 {
124 NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
125 if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
126 start = (int)page * ASSETS_PER_PAGE;
127 }
128
129 html.AppendLine(HEADER);
130
131 html.AppendLine("<p>");
132 if (page > 0)
133 html.AppendFormat("<a href=\"{0}?page={1}\">&lt; Previous Page</a> | ", httpRequest.RawUrl, page - 1);
134 html.AppendFormat("<a href=\"{0}?page={1}\">Next Page &gt;</a>", httpRequest.RawUrl, page + 1);
135 html.AppendLine("</p>");
136
137 html.AppendLine(TABLE_HEADER);
138
139 m_server.StorageProvider.ForEach(
140 delegate(AssetMetadata data)
141 {
142 if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.FullID))
143 {
144 html.AppendLine(String.Format(
145 "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
146 data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
147 BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
148 }
149 else
150 {
151 html.AppendLine(String.Format(
152 "<tr><td>[Protected Asset]</td><td>&nbsp;</td><td>&nbsp;</td><td>{0}</td><td>{1}</td><td>&nbsp;</td></tr>",
153 data.ID, data.Temporary));
154 }
155 }, start, ASSETS_PER_PAGE
156 );
157
158 html.AppendLine(TABLE_FOOTER);
159
160 html.AppendLine(FOOTER);
161
162 byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
163
164 httpResponse.StatusCode = (int) HttpStatusCode.OK;
165 //httpResponse.Body.Write(responseData, 0, responseData.Length);
166 //httpResponse.Body.Flush();
167 return responseData;
168 }
169
170 #endregion IStreamedRequestHandler implementation
171 }
172 }
173}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs
deleted file mode 100644
index 8323450..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs
+++ /dev/null
@@ -1,211 +0,0 @@
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.Serialization;
37using OpenSim.Framework.Serialization.External;
38using OpenSim.Framework.Servers;
39using OpenSim.Framework.Servers.HttpServer;
40using log4net;
41
42namespace OpenSim.Grid.AssetInventoryServer.Plugins
43{
44 public class InventoryArchivePlugin : IAssetInventoryServerPlugin
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private AssetInventoryServer m_server;
48
49 public InventoryArchivePlugin()
50 {
51 }
52
53 #region IPlugin implementation
54
55 public void Initialise(AssetInventoryServer server)
56 {
57 m_server = server;
58
59 m_server.HttpServer.AddStreamHandler(new GetInventoryArchive(server));
60
61 m_log.Info("[INVENTORYARCHIVE]: Inventory Archive loaded.");
62 }
63
64 /// <summary>
65 /// <para>Initialises asset interface</para>
66 /// </summary>
67 public void Initialise()
68 {
69 m_log.InfoFormat("[INVENTORYARCHIVE]: {0} cannot be default-initialized!", Name);
70 throw new PluginNotInitialisedException(Name);
71 }
72
73 public void Dispose()
74 {
75 }
76
77 public string Version
78 {
79 // TODO: this should be something meaningful and not hardcoded?
80 get { return "0.1"; }
81 }
82
83 public string Name
84 {
85 get { return "InventoryArchive"; }
86 }
87
88 #endregion IPlugin implementation
89
90 public class GetInventoryArchive : BaseStreamHandler
91 {
92 AssetInventoryServer m_server;
93
94 //public GetInventoryArchive(AssetInventoryServer server) : base("GET", @"^/inventoryarchive/")
95 public GetInventoryArchive(AssetInventoryServer server) : base("GET", "/inventoryarchive")
96 {
97 m_server = server;
98 }
99
100 public override string ContentType
101 {
102 get { return "application/x-compressed"; }
103 }
104
105 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
106 {
107 byte[] buffer = new byte[] {};
108 UUID ownerID;
109 // Split the URL up to get the asset ID out
110 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
111
112 if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out ownerID))
113 {
114 Uri owner = Utils.GetOpenSimUri(ownerID);
115 InventoryCollection inventory;
116 BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory);
117
118 if (storageResponse == BackendResponse.Success)
119 {
120 m_log.DebugFormat("[INVENTORYARCHIVE]: Archiving inventory for user UUID {0}", ownerID);
121 buffer = ArchiveInventoryCollection(inventory);
122 httpResponse.StatusCode = (int) HttpStatusCode.OK;
123 }
124 else
125 {
126 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
127 }
128 }
129 else
130 {
131 m_log.Warn("[INVENTORYARCHIVE]: Unrecognized inventory archive request: " + httpRequest.Url.PathAndQuery);
132 }
133
134 return buffer;
135 }
136 }
137
138 private static byte[] ArchiveInventoryCollection(InventoryCollection inventory)
139 {
140 byte[] buffer = new byte[] {};
141
142 // Fill in each folder's Children dictionary.
143 InventoryFolderWithChildren rootFolder = BuildInventoryHierarchy(ref inventory);
144
145 // TODO: It's probably a bad idea to tar to memory for large
146 // inventories.
147 MemoryStream ms = new MemoryStream();
148 GZipStream gzs = new GZipStream(ms, CompressionMode.Compress, true);
149 TarArchiveWriter archive = new TarArchiveWriter(gzs);
150 WriteInventoryFolderToArchive(archive, rootFolder, ArchiveConstants.INVENTORY_PATH);
151
152 archive.Close();
153
154 ms.Seek(0, SeekOrigin.Begin);
155 buffer = ms.GetBuffer();
156 Array.Resize<byte>(ref buffer, (int) ms.Length);
157 ms.Close();
158 return buffer;
159 }
160
161 private static InventoryFolderWithChildren BuildInventoryHierarchy(ref InventoryCollection inventory)
162 {
163 m_log.DebugFormat("[INVENTORYARCHIVE]: Building inventory hierarchy");
164 InventoryFolderWithChildren rootFolder = null;
165
166 foreach (InventoryFolderWithChildren parentFolder in inventory.Folders.Values)
167 {
168 // Grab the root folder, it has no parents.
169 if (UUID.Zero == parentFolder.ParentID) rootFolder = parentFolder;
170
171 foreach (InventoryFolderWithChildren folder in inventory.Folders.Values)
172 if (parentFolder.ID == folder.ParentID)
173 parentFolder.Children.Add(folder.ID, folder);
174
175 foreach (InventoryItemBase item in inventory.Items.Values)
176 if (parentFolder.ID == item.Folder)
177 parentFolder.Children.Add(item.ID, item);
178 }
179
180 return rootFolder;
181 }
182
183 private static void WriteInventoryFolderToArchive(
184 TarArchiveWriter archive, InventoryFolderWithChildren folder, string path)
185 {
186 path += string.Format("{0}{1}{2}/", folder.Name, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folder.ID);
187 archive.WriteDir(path);
188
189 foreach (InventoryNodeBase inventoryNode in folder.Children.Values)
190 {
191 if (inventoryNode is InventoryFolderWithChildren)
192 {
193 WriteInventoryFolderToArchive(archive, (InventoryFolderWithChildren) inventoryNode, path);
194 }
195 else if (inventoryNode is InventoryItemBase)
196 {
197 WriteInventoryItemToArchive(archive, (InventoryItemBase) inventoryNode, path);
198 }
199 }
200 }
201
202 private static void WriteInventoryItemToArchive(TarArchiveWriter archive, InventoryItemBase item, string path)
203 {
204 string filename = string.Format("{0}{1}_{2}.xml", path, item.Name, item.ID);
205 string serialization = UserInventoryItemSerializer.Serialize(item);
206 archive.WriteFile(filename, serialization);
207
208 //m_assetGatherer.GatherAssetUuids(item.AssetID, (AssetType) item.AssetType, assetUuids);
209 }
210 }
211}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs
deleted file mode 100644
index 026b3c8..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs
+++ /dev/null
@@ -1,95 +0,0 @@
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.Reflection;
30using OpenMetaverse;
31using OpenSim.Framework;
32using log4net;
33
34namespace OpenSim.Grid.AssetInventoryServer.Plugins
35{
36 public class NullAuthenticationPlugin : IAuthenticationProvider
37 {
38 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
39 //private AssetInventoryServer m_server;
40
41 public NullAuthenticationPlugin()
42 {
43 }
44
45 #region IPlugin implementation
46
47 public void Initialise(AssetInventoryServer server)
48 {
49 //m_server = server;
50
51 m_log.Info("[NULLAUTHENTICATION]: Null Authentication loaded.");
52 }
53
54 /// <summary>
55 /// <para>Initialises asset interface</para>
56 /// </summary>
57 public void Initialise()
58 {
59 m_log.InfoFormat("[NULLAUTHENTICATION]: {0} cannot be default-initialized!", Name);
60 throw new PluginNotInitialisedException(Name);
61 }
62
63 public void Dispose()
64 {
65 }
66
67 public string Version
68 {
69 // TODO: this should be something meaningful and not hardcoded?
70 get { return "0.1"; }
71 }
72
73 public string Name
74 {
75 get { return "NullAuthentication"; }
76 }
77
78 #endregion IPlugin implementation
79
80 public void AddIdentifier(UUID authToken, Uri identifier)
81 {
82 }
83
84 public bool RemoveIdentifier(UUID authToken)
85 {
86 return true;
87 }
88
89 public bool TryGetIdentifier(UUID authToken, out Uri identifier)
90 {
91 identifier = null;
92 return true;
93 }
94 }
95}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs
deleted file mode 100644
index 8cde8f4..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs
+++ /dev/null
@@ -1,151 +0,0 @@
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.Reflection;
30using OpenMetaverse;
31using log4net;
32
33namespace OpenSim.Grid.AssetInventoryServer.Plugins
34{
35 public class NullMetricsPlugin : IMetricsProvider
36 {
37 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
38 //private AssetInventoryServer m_server;
39
40 public NullMetricsPlugin()
41 {
42 }
43
44 #region IMetricsProvider implementation
45
46 public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time)
47 {
48 m_log.DebugFormat("[{0}]: AssetMetadataFetch(): AssetID: {1}, Response: {2}", extension, assetID, response);
49 }
50
51 public void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time)
52 {
53 m_log.DebugFormat("[{0}]: AssetDataFetch(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID,
54 dataSize, response);
55 }
56
57 public void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time)
58 {
59 m_log.DebugFormat("[{0}]: AssetCreate(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID,
60 dataSize, response);
61 }
62
63 public void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time)
64 {
65 m_log.DebugFormat("[{0}]: InventoryFetch(): ObjID: {1}, Folder: {2}, OwnerID: {3}, Response: {4}", extension,
66 objID, folder, owner, response);
67 }
68
69 public void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
70 {
71 m_log.DebugFormat("[{0}]: InventoryFetchFolderContents(): FolderID: {1}, OwnerID: {2}, Response: {3}", extension,
72 folderID, owner, response);
73 }
74
75 public void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time)
76 {
77 m_log.DebugFormat("[{0}]: InventoryFetchFolderList(): OwnerID: {1}, Response: {2}", extension,
78 owner, response);
79 }
80
81 public void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time)
82 {
83 m_log.DebugFormat("[{0}]: InventoryFetchInventory(): OwnerID: {1}, Response: {2}", extension,
84 owner, response);
85 }
86
87 public void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time)
88 {
89 m_log.DebugFormat("[{0}]: InventoryFetchActiveGestures(): OwnerID: {1}, Response: {2}", extension,
90 owner, response);
91 }
92
93 public void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time)
94 {
95 m_log.DebugFormat("[{0}]: InventoryCreate(): OwnerID: {1}, Response: {2}", extension,
96 owner, response);
97 }
98
99 public void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time)
100 {
101 m_log.DebugFormat("[{0}]: InventoryCreateInventory(): Response: {1}", extension,
102 response);
103 }
104
105 public void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time)
106 {
107 m_log.DebugFormat("[{0}]: InventoryDelete(): OwnerID: {1}, Folder: {2}, Response: {3}", extension,
108 owner, folder, response);
109 }
110
111 public void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
112 {
113 m_log.DebugFormat("[{0}]: InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension,
114 owner, folderID, response);
115 }
116
117 #endregion IMetricsProvider implementation
118
119 #region IPlugin implementation
120
121 public void Initialise(AssetInventoryServer server)
122 {
123 //m_server = server;
124 }
125
126 /// <summary>
127 /// <para>Initialises metrics interface</para>
128 /// </summary>
129 public void Initialise()
130 {
131 m_log.Info("[NULLMETRICS]: Null metrics loaded.");
132 }
133
134 public void Dispose()
135 {
136 }
137
138 public string Version
139 {
140 // TODO: this should be something meaningful and not hardcoded?
141 get { return "0.1"; }
142 }
143
144 public string Name
145 {
146 get { return "NullMetrics"; }
147 }
148
149 #endregion IPlugin implementation
150 }
151}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
deleted file mode 100644
index e4be55e..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
+++ /dev/null
@@ -1,198 +0,0 @@
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.Reflection;
30using System.Net;
31using System.IO;
32using System.Text;
33using System.Xml;
34using System.Xml.Serialization;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Servers.HttpServer;
39using log4net;
40
41namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
42{
43 public class OpenSimAssetFrontendPlugin : IAssetInventoryServerPlugin
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 private AssetInventoryServer m_server;
47
48 public OpenSimAssetFrontendPlugin()
49 {
50 }
51
52 #region IPlugin implementation
53
54 public void Initialise(AssetInventoryServer server)
55 {
56 m_server = server;
57
58 // Asset request
59 m_server.HttpServer.AddStreamHandler(new AssetRequestHandler(server));
60
61 // Asset creation
62 m_server.HttpServer.AddStreamHandler(new AssetPostHandler(server));
63
64 m_log.Info("[OPENSIMASSETFRONTEND]: OpenSim Asset Frontend loaded.");
65 }
66
67 /// <summary>
68 /// <para>Initialises asset interface</para>
69 /// </summary>
70 public void Initialise()
71 {
72 m_log.InfoFormat("[OPENSIMASSETFRONTEND]: {0} cannot be default-initialized!", Name);
73 throw new PluginNotInitialisedException(Name);
74 }
75
76 public void Dispose()
77 {
78 }
79
80 public string Version
81 {
82 // TODO: this should be something meaningful and not hardcoded?
83 get { return "0.1"; }
84 }
85
86 public string Name
87 {
88 get { return "OpenSimAssetFrontend"; }
89 }
90
91 #endregion IPlugin implementation
92
93 public class AssetRequestHandler : BaseStreamHandler
94 {
95 AssetInventoryServer m_server;
96
97 //public AssetRequestHandler(AssetInventoryServer server) : base("GET", "^/assets")
98 public AssetRequestHandler(AssetInventoryServer server) : base("GET", "/assets")
99 {
100 m_server = server;
101 }
102
103 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
104 {
105 byte[] buffer = new byte[] {};
106 UUID assetID;
107 // Split the URL up to get the asset ID out
108 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
109
110 if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
111 {
112 BackendResponse dataResponse;
113
114 AssetBase asset = new AssetBase();
115 if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out asset)) == BackendResponse.Success)
116 {
117 if (rawUrl.Length >= 4 && rawUrl[3] == "data")
118 {
119 httpResponse.StatusCode = (int)HttpStatusCode.OK;
120 httpResponse.ContentType = Utils.SLAssetTypeToContentType(asset.Type);
121 buffer=asset.Data;
122 }
123 else
124 {
125 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
126 MemoryStream ms = new MemoryStream();
127 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
128 xs.Serialize(xw, asset);
129 xw.Flush();
130
131 ms.Seek(0, SeekOrigin.Begin);
132 buffer = ms.GetBuffer();
133 Array.Resize<byte>(ref buffer, (int)ms.Length);
134 ms.Close();
135 httpResponse.StatusCode = (int)HttpStatusCode.OK;
136 }
137 }
138 else
139 {
140 m_log.WarnFormat("[OPENSIMASSETFRONTEND]: Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
141 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
142 }
143 }
144 else
145 {
146 m_log.Warn("[OPENSIMASSETFRONTEND]: Unrecognized OpenSim asset request: " + httpRequest.Url.PathAndQuery);
147 }
148
149 return buffer;
150 }
151 }
152
153 public class AssetPostHandler : BaseStreamHandler
154 {
155 AssetInventoryServer m_server;
156
157 //public AssetPostHandler(AssetInventoryServer server) : base("POST", "/^assets")
158 public AssetPostHandler(AssetInventoryServer server) : base("POST", "/assets")
159 {
160 m_server = server;
161 }
162
163 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
164 {
165 AssetBase asset = null;
166
167 try
168 {
169 asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(httpRequest.InputStream);
170 }
171 catch (Exception ex)
172 {
173 m_log.Warn("[OPENSIMASSETFRONTEND]: Failed to parse POST data (expecting AssetBase): " + ex.Message);
174 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
175 }
176
177 if (asset != null && asset.Data != null && asset.Data.Length > 0)
178 {
179 BackendResponse storageResponse = m_server.StorageProvider.TryCreateAsset(asset);
180
181 if (storageResponse == BackendResponse.Success)
182 httpResponse.StatusCode = (int) HttpStatusCode.Created;
183 else if (storageResponse == BackendResponse.NotFound)
184 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
185 else
186 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
187 }
188 else
189 {
190 m_log.Warn("[OPENSIMASSETFRONTEND]: AssetPostHandler called with no asset data");
191 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
192 }
193
194 return new byte[] {};
195 }
196 }
197 }
198}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
deleted file mode 100644
index 0631ee7..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs
+++ /dev/null
@@ -1,189 +0,0 @@
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.Reflection;
30using System.Data;
31using System.Collections.Generic;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Data;
35using Nini.Config;
36using log4net;
37
38namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
39{
40 public class OpenSimAssetStoragePlugin : IAssetStorageProvider
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 const string EXTENSION_NAME = "OpenSimAssetStorage"; // Used in metrics reporting
44
45 private AssetInventoryServer m_server;
46 private IAssetDataPlugin m_assetProvider;
47 private IConfig m_openSimConfig;
48
49 public OpenSimAssetStoragePlugin()
50 {
51 }
52
53 #region IAssetStorageProvider implementation
54
55 public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata)
56 {
57 metadata = null;
58 BackendResponse ret;
59
60 AssetBase asset = m_assetProvider.FetchAsset(assetID);
61
62 if (asset == null) ret = BackendResponse.NotFound;
63 else
64 {
65 metadata = asset.Metadata;
66 ret = BackendResponse.Success;
67 }
68
69 m_server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
70 return ret;
71 }
72
73 public BackendResponse TryFetchData(UUID assetID, out byte[] assetData)
74 {
75 assetData = null;
76 BackendResponse ret;
77
78 AssetBase asset = m_assetProvider.FetchAsset(assetID);
79
80 if (asset == null) ret = BackendResponse.NotFound;
81 else
82 {
83 assetData = asset.Data;
84 ret = BackendResponse.Success;
85 }
86
87 m_server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
88 return ret;
89 }
90
91 public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset)
92 {
93 asset = m_assetProvider.FetchAsset(assetID);
94
95 if (asset == null) return BackendResponse.NotFound;
96
97 return BackendResponse.Success;
98 }
99
100 public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID)
101 {
102 assetID = asset.FullID = UUID.Random();
103 return TryCreateAsset(asset);
104 }
105
106 public BackendResponse TryCreateAsset(AssetBase asset)
107 {
108 BackendResponse ret;
109
110 m_assetProvider.CreateAsset(asset);
111 ret = BackendResponse.Success;
112
113 m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now);
114 return ret;
115 }
116
117 public int ForEach(Action<AssetMetadata> action, int start, int count)
118 {
119 int rowCount = 0;
120
121 foreach (AssetMetadata metadata in m_assetProvider.FetchAssetMetadataSet(start, count))
122 {
123 // We set the ContentType here because Utils is only in
124 // AssetInventoryServer. This should be moved to the DB
125 // backends when the equivalent of SLAssetTypeToContentType is
126 // in OpenSim.Framework or similar.
127 metadata.ContentType = Utils.SLAssetTypeToContentType(metadata.Type);
128
129 action(metadata);
130 ++rowCount;
131 }
132
133 return rowCount;
134 }
135
136 #endregion IAssetStorageProvider implementation
137
138 #region IPlugin implementation
139
140 public void Initialise(AssetInventoryServer server)
141 {
142 m_server = server;
143 m_openSimConfig = server.ConfigFile.Configs["OpenSim"];
144
145 try
146 {
147 m_assetProvider = DataPluginFactory.LoadDataPlugin<IAssetDataPlugin>(m_openSimConfig.GetString("asset_database_provider"),
148 m_openSimConfig.GetString("asset_database_connect"));
149 if (m_assetProvider == null)
150 {
151 m_log.Error("[OPENSIMASSETSTORAGE]: Failed to load a database plugin, server halting.");
152 Environment.Exit(-1);
153 }
154 else
155 m_log.InfoFormat("[OPENSIMASSETSTORAGE]: Loaded storage backend: {0}", Version);
156 }
157 catch (Exception e)
158 {
159 m_log.WarnFormat("[OPENSIMASSETSTORAGE]: Failure loading data plugin: {0}", e.ToString());
160 throw new PluginNotInitialisedException(Name);
161 }
162 }
163
164 /// <summary>
165 /// <para>Initialises asset interface</para>
166 /// </summary>
167 public void Initialise()
168 {
169 m_log.InfoFormat("[OPENSIMASSETSTORAGE]: {0} cannot be default-initialized!", Name);
170 throw new PluginNotInitialisedException(Name);
171 }
172
173 public void Dispose()
174 {
175 }
176
177 public string Version
178 {
179 get { return m_assetProvider.Version; }
180 }
181
182 public string Name
183 {
184 get { return "OpenSimAssetStorage"; }
185 }
186
187 #endregion IPlugin implementation
188 }
189}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
deleted file mode 100644
index c83e911..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
+++ /dev/null
@@ -1,867 +0,0 @@
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.Reflection;
31using System.Collections.Generic;
32using System.IO;
33using System.Xml;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Servers;
37using OpenSim.Framework.Servers.HttpServer;
38using log4net;
39
40namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
41{
42 public class OpenSimInventoryFrontendPlugin : IAssetInventoryServerPlugin
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 private AssetInventoryServer m_server;
46 private Utils.InventoryCollectionSerializer collectionSerializer = new Utils.InventoryCollectionSerializer();
47
48 public OpenSimInventoryFrontendPlugin()
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 GetInventoryHandler(server, collectionSerializer));
59 m_server.HttpServer.AddStreamHandler(new CreateInventoryHandler(server));
60 m_server.HttpServer.AddStreamHandler(new NewFolderHandler(server));
61 m_server.HttpServer.AddStreamHandler(new UpdateFolderHandler(server));
62 m_server.HttpServer.AddStreamHandler(new MoveFolderHandler(server));
63 m_server.HttpServer.AddStreamHandler(new PurgeFolderHandler(server));
64 m_server.HttpServer.AddStreamHandler(new NewItemHandler(server));
65 m_server.HttpServer.AddStreamHandler(new DeleteItemHandler(server));
66 m_server.HttpServer.AddStreamHandler(new RootFoldersHandler(server));
67 m_server.HttpServer.AddStreamHandler(new ActiveGesturesHandler(server));
68
69 m_log.Info("[OPENSIMINVENTORYFRONTEND]: OpenSim Inventory Frontend loaded.");
70 }
71
72 /// <summary>
73 /// <para>Initialises asset interface</para>
74 /// </summary>
75 public void Initialise()
76 {
77 m_log.InfoFormat("[OPENSIMINVENTORYFRONTEND]: {0} cannot be default-initialized!", Name);
78 throw new PluginNotInitialisedException(Name);
79 }
80
81 public void Dispose()
82 {
83 }
84
85 public string Version
86 {
87 // TODO: this should be something meaningful and not hardcoded?
88 get { return "0.1"; }
89 }
90
91 public string Name
92 {
93 get { return "OpenSimInventoryFrontend"; }
94 }
95
96 #endregion IPlugin implementation
97
98 public class GetInventoryHandler : BaseStreamHandler
99 {
100 AssetInventoryServer m_server;
101 Utils.InventoryCollectionSerializer m_collectionSerializer;
102
103 //public GetInventoryHandler(AssetInventoryServer server, Utils.InventoryCollectionSerializer collectionSerializer) : base("POST", @"^/GetInventory/")
104 public GetInventoryHandler(AssetInventoryServer server, Utils.InventoryCollectionSerializer collectionSerializer) : base("POST", "/GetInventory")
105 {
106 m_server = server;
107 m_collectionSerializer = collectionSerializer;
108 }
109
110 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
111 {
112 byte[] buffer = new byte[] {};
113 UUID sessionID, agentID;
114 UUID ownerID = DeserializeUUID(httpRequest.InputStream, out agentID, out sessionID);
115
116 if (ownerID != UUID.Zero)
117 {
118 m_log.Warn("[OPENSIMINVENTORYFRONTEND]: GetInventory is not scalable on some inventory backends, avoid calling it wherever possible");
119
120 Uri owner = Utils.GetOpenSimUri(ownerID);
121 InventoryCollection inventory;
122 BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory);
123
124 if (storageResponse == BackendResponse.Success)
125 {
126 //collectionSerializer.Serialize(httpResponse.Body, inventory);
127 //httpResponse.Body.Flush();
128 MemoryStream ms = new MemoryStream();
129 m_collectionSerializer.Serialize(ms, inventory);
130 ms.Seek(0, SeekOrigin.Begin);
131 buffer = ms.GetBuffer();
132 Array.Resize<byte>(ref buffer, (int) ms.Length);
133 ms.Close();
134 httpResponse.StatusCode = (int) HttpStatusCode.OK;
135 }
136 else if (storageResponse == BackendResponse.NotFound)
137 {
138 // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe
139 inventory = new InventoryCollection();
140 inventory.UserID = ownerID;
141 inventory.Folders = new Dictionary<UUID, InventoryFolderWithChildren>();
142 inventory.Items = new Dictionary<UUID, InventoryItemBase>();
143 //collectionSerializer.Serialize(httpResponse.Body, inventory);
144 //httpResponse.Body.Flush();
145 MemoryStream ms = new MemoryStream();
146 m_collectionSerializer.Serialize(ms, inventory);
147 ms.Seek(0, SeekOrigin.Begin);
148 buffer = ms.GetBuffer();
149 Array.Resize<byte>(ref buffer, (int) ms.Length);
150 ms.Close();
151 httpResponse.StatusCode = (int) HttpStatusCode.OK;
152 }
153 else
154 {
155 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
156 }
157 }
158 else
159 {
160 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
161 }
162
163 return buffer;
164 }
165 }
166
167 public class CreateInventoryHandler : BaseStreamHandler
168 {
169 AssetInventoryServer m_server;
170
171 //public CreateInventoryHandler(AssetInventoryServer server) : base("POST", @"^/CreateInventory/")
172 public CreateInventoryHandler(AssetInventoryServer server) : base("POST", "/CreateInventory")
173 {
174 m_server = server;
175 }
176
177 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
178 {
179 UUID ownerID = DeserializeUUID(httpRequest.InputStream);
180
181 if (ownerID != UUID.Zero)
182 {
183 Uri owner = Utils.GetOpenSimUri(ownerID);
184 m_log.DebugFormat("[OPENSIMINVENTORYFRONTEND]: Created URI {0} for inventory creation", owner);
185
186 InventoryFolderWithChildren rootFolder = new InventoryFolderWithChildren("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder);
187 BackendResponse storageResponse = m_server.InventoryProvider.TryCreateInventory(owner, rootFolder);
188 if (storageResponse == BackendResponse.Success)
189 {
190 // TODO: The CreateFolder calls need to be executed in SimpleStorage.
191 //CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation);
192 //CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart);
193 //CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard);
194 //CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing);
195 //CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture);
196 //CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark);
197 //CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder);
198 //CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard);
199 //CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object);
200 //CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder);
201 //CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText);
202 //CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound);
203 //CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture);
204 //CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder);
205
206 return SerializeBool(true);
207 }
208 }
209
210 return SerializeBool(false);
211 }
212 }
213
214 public class NewFolderHandler : BaseStreamHandler
215 {
216 AssetInventoryServer m_server;
217
218 //public NewFolderHandler(AssetInventoryServer server) : base("POST", @"^/NewFolder/")
219 public NewFolderHandler(AssetInventoryServer server) : base("POST", "/NewFolder")
220 {
221 m_server = server;
222 }
223
224 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
225 {
226 UUID agentID, sessionID;
227 InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID);
228
229 if (folder != null)
230 {
231 Uri owner = Utils.GetOpenSimUri(folder.Owner);
232
233 // Some calls that are moving or updating a folder instead
234 // of creating a new one will pass in an InventoryFolder
235 // without the name set and type set to 0. If this is the
236 // case we need to look up the name first and preserver
237 // it's type.
238 if (String.IsNullOrEmpty(folder.Name))
239 {
240 InventoryFolderWithChildren oldFolder;
241 if (m_server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success)
242 {
243 folder.Name = oldFolder.Name;
244 folder.Type = oldFolder.Type;
245 }
246 }
247
248 BackendResponse storageResponse = m_server.InventoryProvider.TryCreateFolder(owner, folder);
249
250 if (storageResponse == BackendResponse.Success)
251 {
252 return SerializeBool(true);
253 }
254 }
255
256 return SerializeBool(false);
257 }
258 }
259
260 public class UpdateFolderHandler : BaseStreamHandler
261 {
262 AssetInventoryServer m_server;
263
264 //public UpdateFolderHandler(AssetInventoryServer server) : base("POST", @"^/UpdateFolder/")
265 public UpdateFolderHandler(AssetInventoryServer server) : base("POST", "/UpdateFolder")
266 {
267 m_server = server;
268 }
269
270 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
271 {
272 return new NewFolderHandler(m_server).Handle(path, request, httpRequest, httpResponse);
273 }
274 }
275
276 public class MoveFolderHandler : BaseStreamHandler
277 {
278 AssetInventoryServer m_server;
279
280 //public MoveFolderHandler(AssetInventoryServer server) : base("POST", @"^/MoveFolder/")
281 public MoveFolderHandler(AssetInventoryServer server) : base("POST", "/MoveFolder")
282 {
283 m_server = server;
284 }
285
286 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
287 {
288 return new NewFolderHandler(m_server).Handle(path, request, httpRequest, httpResponse);
289 }
290 }
291
292 public class PurgeFolderHandler : BaseStreamHandler
293 {
294 AssetInventoryServer m_server;
295
296 //public PurgeFolderHandler(AssetInventoryServer server) : base("POST", @"^/PurgeFolder/")
297 public PurgeFolderHandler(AssetInventoryServer server) : base("POST", "/PurgeFolder")
298 {
299 m_server = server;
300 }
301
302 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
303 {
304 UUID agentID, sessionID;
305 InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID);
306
307 if (folder != null)
308 {
309 Uri owner = Utils.GetOpenSimUri(folder.Owner);
310 BackendResponse storageResponse = m_server.InventoryProvider.TryPurgeFolder(owner, folder.ID);
311
312 if (storageResponse == BackendResponse.Success)
313 {
314 return SerializeBool(true);
315 }
316 }
317
318 return SerializeBool(false);
319 }
320 }
321
322 public class NewItemHandler : BaseStreamHandler
323 {
324 AssetInventoryServer m_server;
325
326 //public NewItemHandler(AssetInventoryServer server) : base("POST", @"^/NewItem/")
327 public NewItemHandler(AssetInventoryServer server) : base("POST", "/NewItem")
328 {
329 m_server = server;
330 }
331
332 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
333 {
334 UUID agentID, sessionID;
335 InventoryItemBase item = DeserializeItem(httpRequest.InputStream, out agentID, out sessionID);
336
337 if (item != null)
338 {
339 Uri owner = Utils.GetOpenSimUri(agentID);
340 BackendResponse storageResponse = m_server.InventoryProvider.TryCreateItem(owner, item);
341
342 if (storageResponse == BackendResponse.Success)
343 {
344 return SerializeBool(true);
345 }
346 }
347
348 return SerializeBool(false);
349 }
350 }
351
352 public class DeleteItemHandler : BaseStreamHandler
353 {
354 AssetInventoryServer m_server;
355
356 //public DeleteItemHandler(AssetInventoryServer server) : base("POST", @"^/DeleteItem/")
357 public DeleteItemHandler(AssetInventoryServer server) : base("POST", "/DeleteItem")
358 {
359 m_server = server;
360 }
361
362 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
363 {
364 UUID agentID, sessionID;
365 InventoryItemBase item = DeserializeItem(httpRequest.InputStream, out agentID, out sessionID);
366
367 if (item != null)
368 {
369 Uri owner = Utils.GetOpenSimUri(item.Owner);
370 BackendResponse storageResponse = m_server.InventoryProvider.TryDeleteItem(owner, item.ID);
371
372 if (storageResponse == BackendResponse.Success)
373 {
374 return SerializeBool(true);
375 }
376 }
377
378 return SerializeBool(false);
379 }
380 }
381
382 public class RootFoldersHandler : BaseStreamHandler
383 {
384 AssetInventoryServer m_server;
385
386 //public RootFoldersHandler(AssetInventoryServer server) : base("POST", @"^/RootFolders/")
387 public RootFoldersHandler(AssetInventoryServer server) : base("POST", "/RootFolders")
388 {
389 m_server = server;
390 }
391
392 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
393 {
394 byte[] buffer = new byte[] {};
395 UUID ownerID = DeserializeUUID(httpRequest.InputStream);
396
397 if (ownerID != UUID.Zero)
398 {
399 Uri owner = Utils.GetOpenSimUri(ownerID);
400 List<InventoryFolderWithChildren> skeleton;
401 BackendResponse storageResponse = m_server.InventoryProvider.TryFetchFolderList(owner, out skeleton);
402
403 if (storageResponse == BackendResponse.Success)
404 {
405 MemoryStream ms = new MemoryStream();
406 SerializeFolderList(ms, skeleton);
407 ms.Seek(0, SeekOrigin.Begin);
408 buffer = ms.GetBuffer();
409 Array.Resize<byte>(ref buffer, (int) ms.Length);
410 ms.Close();
411 httpResponse.StatusCode = (int) HttpStatusCode.OK;
412 }
413 else if (storageResponse == BackendResponse.NotFound)
414 {
415 // Return an empty set of inventory so the requester knows that
416 // an inventory needs to be created for this agent
417 MemoryStream ms = new MemoryStream();
418 SerializeFolderList(ms, new List<InventoryFolderWithChildren>(0));
419 ms.Seek(0, SeekOrigin.Begin);
420 buffer = ms.GetBuffer();
421 Array.Resize<byte>(ref buffer, (int) ms.Length);
422 ms.Close();
423 httpResponse.StatusCode = (int) HttpStatusCode.OK;
424 }
425 else
426 {
427 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
428 }
429 }
430 else
431 {
432 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
433 }
434
435 return buffer;
436 }
437 }
438
439 public class ActiveGesturesHandler : BaseStreamHandler
440 {
441 AssetInventoryServer m_server;
442
443 //public ActiveGesturesHandler(AssetInventoryServer server) : base("POST", @"^/ActiveGestures/")
444 public ActiveGesturesHandler(AssetInventoryServer server) : base("POST", "/ActiveGestures")
445 {
446 m_server = server;
447 }
448
449 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
450 {
451 byte[] buffer = new byte[] {};
452 UUID ownerID = DeserializeUUID(httpRequest.InputStream);
453
454 if (ownerID != UUID.Zero)
455 {
456 Uri owner = Utils.GetOpenSimUri(ownerID);
457 List<InventoryItemBase> gestures;
458 BackendResponse storageResponse = m_server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);
459
460 if (storageResponse == BackendResponse.Success)
461 {
462 MemoryStream ms = new MemoryStream();
463 SerializeItemList(ms, gestures);
464 ms.Seek(0, SeekOrigin.Begin);
465 buffer = ms.GetBuffer();
466 Array.Resize<byte>(ref buffer, (int) ms.Length);
467 ms.Close();
468 httpResponse.StatusCode = (int) HttpStatusCode.OK;
469 }
470 else if (storageResponse == BackendResponse.NotFound)
471 {
472 // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior
473 MemoryStream ms = new MemoryStream();
474 SerializeItemList(ms, new List<InventoryItemBase>(0));
475 ms.Seek(0, SeekOrigin.Begin);
476 buffer = ms.GetBuffer();
477 Array.Resize<byte>(ref buffer, (int) ms.Length);
478 ms.Close();
479 httpResponse.StatusCode = (int) HttpStatusCode.OK;
480 }
481 else
482 {
483 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
484 }
485 }
486 else
487 {
488 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
489 }
490
491 return buffer;
492 }
493 }
494
495 //BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType)
496 //{
497 // InventoryFolder folder = new InventoryFolder(name, ownerID, parentID, (short)assetType);
498 // Uri owner = Utils.GetOpenSimUri(ownerID);
499 // return m_server.InventoryProvider.TryCreateFolder(owner, folder);
500 //}
501
502 private static UUID DeserializeUUID(Stream stream)
503 {
504 UUID id = UUID.Zero;
505
506 try
507 {
508 using (XmlReader reader = XmlReader.Create(stream))
509 {
510 reader.MoveToContent();
511 UUID.TryParse(reader.ReadElementContentAsString("guid", String.Empty), out id);
512 }
513 }
514 catch (Exception ex)
515 {
516 m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting guid): " + ex.Message);
517 }
518
519 return id;
520 }
521
522 private static UUID DeserializeUUID(Stream stream, out UUID agentID, out UUID sessionID)
523 {
524 UUID id;
525
526 try
527 {
528 using (XmlReader reader = XmlReader.Create(stream))
529 {
530 reader.MoveToContent();
531 reader.ReadStartElement("RestSessionObjectOfGuid");
532 UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID);
533 UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID);
534 UUID.TryParse(reader.ReadElementContentAsString("Body", String.Empty), out id);
535 reader.ReadEndElement();
536 }
537 }
538 catch (Exception ex)
539 {
540 m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse GetInventory POST data: " + ex.Message);
541 agentID = UUID.Zero;
542 sessionID = UUID.Zero;
543 return UUID.Zero;
544 }
545
546 return id;
547 }
548
549 private static InventoryFolderWithChildren DeserializeFolder(Stream stream, out UUID agentID, out UUID sessionID)
550 {
551 InventoryFolderWithChildren folder = new InventoryFolderWithChildren();
552
553 try
554 {
555 using (XmlReader reader = XmlReader.Create(stream))
556 {
557 reader.MoveToContent();
558 reader.ReadStartElement("RestSessionObjectOfInventoryFolderBase");
559 UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID);
560 UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID);
561 reader.ReadStartElement("Body");
562 if (reader.Name == "Name")
563 folder.Name = reader.ReadElementContentAsString("Name", String.Empty);
564 else
565 folder.Name = String.Empty;
566
567 UUID dummyUUID;
568 ReadUUID(reader, "ID", out dummyUUID);
569 folder.ID = dummyUUID;
570 ReadUUID(reader, "Owner", out dummyUUID);
571 folder.Owner = dummyUUID;
572 ReadUUID(reader, "ParentID", out dummyUUID);
573 folder.ParentID = dummyUUID;
574
575 short dummyType;
576 Int16.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out dummyType);
577 folder.Type = dummyType;
578
579 ushort dummyVersion;
580 UInt16.TryParse(reader.ReadElementContentAsString("Version", String.Empty), out dummyVersion);
581 folder.Version = dummyVersion;
582
583 reader.ReadEndElement();
584 reader.ReadEndElement();
585 }
586 }
587 catch (Exception ex)
588 {
589 m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryFolderBase): " + ex.Message);
590 agentID = UUID.Zero;
591 sessionID = UUID.Zero;
592 return null;
593 }
594
595 return folder;
596 }
597
598 private static InventoryItemBase DeserializeItem(Stream stream, out UUID agentID, out UUID sessionID)
599 {
600 InventoryItemBase item = new InventoryItemBase();
601
602 try
603 {
604 using (XmlReader reader = XmlReader.Create(stream))
605 {
606 reader.MoveToContent();
607 reader.ReadStartElement("RestSessionObjectOfInventoryItemBase");
608 UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID);
609 UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID);
610 reader.ReadStartElement("Body");
611
612 item.Name = reader.ReadElementContentAsString("Name", String.Empty);
613
614 UUID dummyUUID;
615 ReadUUID(reader, "ID", out dummyUUID);
616 item.ID = dummyUUID;
617
618 ReadUUID(reader, "Owner", out dummyUUID);
619 item.Owner = dummyUUID;
620
621 int dummyInt;
622 Int32.TryParse(reader.ReadElementContentAsString("InvType", String.Empty), out dummyInt);
623 item.InvType = dummyInt;
624
625 ReadUUID(reader, "Folder", out dummyUUID);
626 item.Folder = dummyUUID;
627
628 item.CreatorId = reader.ReadElementContentAsString("CreatorId", String.Empty);
629 item.Description = reader.ReadElementContentAsString("Description", String.Empty);
630
631 uint dummyUInt;
632 UInt32.TryParse(reader.ReadElementContentAsString("NextPermissions", String.Empty), out dummyUInt);
633 item.NextPermissions = dummyUInt;
634 UInt32.TryParse(reader.ReadElementContentAsString("CurrentPermissions", String.Empty), out dummyUInt);
635 item.CurrentPermissions = dummyUInt;
636 UInt32.TryParse(reader.ReadElementContentAsString("BasePermissions", String.Empty), out dummyUInt);
637 item.BasePermissions = dummyUInt;
638 UInt32.TryParse(reader.ReadElementContentAsString("EveryOnePermissions", String.Empty), out dummyUInt);
639 item.EveryOnePermissions = dummyUInt;
640 UInt32.TryParse(reader.ReadElementContentAsString("GroupPermissions", String.Empty), out dummyUInt);
641 item.GroupPermissions = dummyUInt;
642
643 Int32.TryParse(reader.ReadElementContentAsString("AssetType", String.Empty), out dummyInt);
644 item.AssetType = dummyInt;
645
646 ReadUUID(reader, "AssetID", out dummyUUID);
647 item.AssetID = dummyUUID;
648 ReadUUID(reader, "GroupID", out dummyUUID);
649 item.GroupID = dummyUUID;
650
651 bool dummyBool;
652 Boolean.TryParse(reader.ReadElementContentAsString("GroupOwned", String.Empty), out dummyBool);
653 item.GroupOwned = dummyBool;
654
655 Int32.TryParse(reader.ReadElementContentAsString("SalePrice", String.Empty), out dummyInt);
656 item.SalePrice = dummyInt;
657
658 byte dummyByte;
659 Byte.TryParse(reader.ReadElementContentAsString("SaleType", String.Empty), out dummyByte);
660 item.SaleType = dummyByte;
661
662 UInt32.TryParse(reader.ReadElementContentAsString("Flags", String.Empty), out dummyUInt);
663 item.Flags = dummyUInt;
664
665 Int32.TryParse(reader.ReadElementContentAsString("CreationDate", String.Empty), out dummyInt);
666 item.CreationDate = dummyInt;
667
668 reader.ReadEndElement();
669 reader.ReadEndElement();
670 }
671 }
672 catch (Exception ex)
673 {
674 m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryItemBase): " + ex.Message);
675 agentID = UUID.Zero;
676 sessionID = UUID.Zero;
677 return null;
678 }
679
680 return item;
681 }
682
683 private static byte[] SerializeBool(bool value)
684 {
685 byte[] buffer;
686 MemoryStream ms = new MemoryStream();
687
688 using (XmlWriter writer = XmlWriter.Create(ms))
689 {
690 writer.WriteStartDocument();
691 writer.WriteStartElement("boolean");
692 writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
693 writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
694 writer.WriteString(value.ToString().ToLower());
695 writer.WriteEndElement();
696 writer.WriteEndDocument();
697 writer.Flush();
698 }
699
700 ms.Seek(0, SeekOrigin.Begin);
701 buffer = ms.GetBuffer();
702 Array.Resize<byte>(ref buffer, (int) ms.Length);
703 ms.Close();
704
705 return buffer;
706 }
707
708 private static void SerializeFolderList(Stream stream, List<InventoryFolderWithChildren> folders)
709 {
710 using (XmlWriter writer = XmlWriter.Create(stream))
711 {
712 writer.WriteStartDocument();
713 writer.WriteStartElement("ArrayOfInventoryFolderBase");
714 writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
715 writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
716
717 if (folders != null)
718 {
719 foreach (InventoryFolderWithChildren folder in folders)
720 {
721 writer.WriteStartElement("InventoryFolderBase");
722 writer.WriteElementString("Name", folder.Name);
723 WriteUUID(writer, "Owner", folder.Owner);
724 WriteUUID(writer, "ParentID", folder.ParentID);
725 WriteUUID(writer, "ID", folder.ID);
726 writer.WriteElementString("Type", XmlConvert.ToString(folder.Type));
727 writer.WriteElementString("Version", XmlConvert.ToString(folder.Version));
728 writer.WriteEndElement();
729 }
730 }
731
732 writer.WriteEndElement();
733 writer.WriteEndDocument();
734
735 writer.Flush();
736 }
737
738 stream.Flush();
739 }
740
741 private static void SerializeItemList(Stream stream, List<InventoryItemBase> items)
742 {
743 using (XmlWriter writer = XmlWriter.Create(stream))
744 {
745 writer.WriteStartDocument();
746 writer.WriteStartElement("ArrayOfInventoryItemBase");
747 writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
748 writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
749
750 if (items != null)
751 {
752 foreach (InventoryItemBase item in items)
753 {
754 writer.WriteStartElement("InventoryItemBase");
755 WriteUUID(writer, "ID", item.ID);
756 writer.WriteElementString("InvType", XmlConvert.ToString(item.InvType));
757 WriteUUID(writer, "Folder", item.Folder);
758 WriteUUID(writer, "Owner", item.Owner);
759 writer.WriteElementString("Creator", item.CreatorId);
760 writer.WriteElementString("Name", item.Name);
761 writer.WriteElementString("Description", item.Description);
762 writer.WriteElementString("NextPermissions", XmlConvert.ToString(item.NextPermissions));
763 writer.WriteElementString("CurrentPermissions", XmlConvert.ToString(item.CurrentPermissions));
764 writer.WriteElementString("BasePermissions", XmlConvert.ToString(item.BasePermissions));
765 writer.WriteElementString("EveryOnePermissions", XmlConvert.ToString(item.EveryOnePermissions));
766 writer.WriteElementString("GroupPermissions", XmlConvert.ToString(item.GroupPermissions));
767 writer.WriteElementString("AssetType", XmlConvert.ToString(item.AssetType));
768 WriteUUID(writer, "AssetID", item.AssetID);
769 WriteUUID(writer, "GroupID", item.GroupID);
770 writer.WriteElementString("GroupOwned", XmlConvert.ToString(item.GroupOwned));
771 writer.WriteElementString("SalePrice", XmlConvert.ToString(item.SalePrice));
772 writer.WriteElementString("SaleType", XmlConvert.ToString(item.SaleType));
773 writer.WriteElementString("Flags", XmlConvert.ToString(item.Flags));
774 writer.WriteElementString("CreationDate", XmlConvert.ToString(item.CreationDate));
775 writer.WriteEndElement();
776 }
777 }
778
779 writer.WriteEndElement();
780 writer.WriteEndDocument();
781
782 writer.Flush();
783 }
784
785 stream.Flush();
786 }
787
788 private static void WriteUUID(XmlWriter writer, string name, UUID id)
789 {
790 writer.WriteStartElement(name);
791 writer.WriteElementString("Guid", XmlConvert.ToString(id.Guid));
792 writer.WriteEndElement();
793 }
794
795 private static void ReadUUID(XmlReader reader, string name, out UUID id)
796 {
797 reader.ReadStartElement(name);
798 UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out id);
799 reader.ReadEndElement();
800 }
801 }
802
803 #region OpenSim AssetType
804
805 /// <summary>
806 /// The different types of grid assets
807 /// </summary>
808 public enum AssetType : sbyte
809 {
810 /// <summary>Unknown asset type</summary>
811 Unknown = -1,
812 /// <summary>Texture asset, stores in JPEG2000 J2C stream format</summary>
813 Texture = 0,
814 /// <summary>Sound asset</summary>
815 Sound = 1,
816 /// <summary>Calling card for another avatar</summary>
817 CallingCard = 2,
818 /// <summary>Link to a location in world</summary>
819 Landmark = 3,
820 // <summary>Legacy script asset, you should never see one of these</summary>
821 //[Obsolete]
822 //Script = 4,
823 /// <summary>Collection of textures and parameters that can be
824 /// worn by an avatar</summary>
825 Clothing = 5,
826 /// <summary>Primitive that can contain textures, sounds,
827 /// scripts and more</summary>
828 Object = 6,
829 /// <summary>Notecard asset</summary>
830 Notecard = 7,
831 /// <summary>Holds a collection of inventory items</summary>
832 Folder = 8,
833 /// <summary>Root inventory folder</summary>
834 RootFolder = 9,
835 /// <summary>Linden scripting language script</summary>
836 LSLText = 10,
837 /// <summary>LSO bytecode for a script</summary>
838 LSLBytecode = 11,
839 /// <summary>Uncompressed TGA texture</summary>
840 TextureTGA = 12,
841 /// <summary>Collection of textures and shape parameters that can
842 /// be worn</summary>
843 Bodypart = 13,
844 /// <summary>Trash folder</summary>
845 TrashFolder = 14,
846 /// <summary>Snapshot folder</summary>
847 SnapshotFolder = 15,
848 /// <summary>Lost and found folder</summary>
849 LostAndFoundFolder = 16,
850 /// <summary>Uncompressed sound</summary>
851 SoundWAV = 17,
852 /// <summary>Uncompressed TGA non-square image, not to be used as a
853 /// texture</summary>
854 ImageTGA = 18,
855 /// <summary>Compressed JPEG non-square image, not to be used as a
856 /// texture</summary>
857 ImageJPEG = 19,
858 /// <summary>Animation</summary>
859 Animation = 20,
860 /// <summary>Sequence of animations, sounds, chat, and pauses</summary>
861 Gesture = 21,
862 /// <summary>Simstate file</summary>
863 Simstate = 22,
864 }
865
866 #endregion OpenSim AssetType
867}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs
deleted file mode 100644
index 0effa9f..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs
+++ /dev/null
@@ -1,56 +0,0 @@
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 OpenMetaverse;
29using OpenSim.Framework;
30using OpenSim.Framework.Communications;
31using OpenSim.Data;
32
33namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
34{
35 public class OpenSimInventoryService : InventoryServiceBase
36 {
37 public InventoryFolderWithChildren GetInventoryFolder(UUID folderID)
38 {
39 InventoryFolderBase baseFolder = null;
40 InventoryFolderWithChildren folder = null;
41
42 foreach (IInventoryDataPlugin plugin in m_plugins)
43 {
44 baseFolder = plugin.getInventoryFolder(folderID);
45 }
46
47 if (null != baseFolder)
48 {
49 folder = new InventoryFolderWithChildren(baseFolder);
50 folder.Children = null; // This call only returns data for the folder itself, no children data
51 }
52
53 return folder;
54 }
55 }
56}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs
deleted file mode 100644
index 2239b87..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs
+++ /dev/null
@@ -1,547 +0,0 @@
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.Reflection;
30using System.Collections.Generic;
31using System.Data;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Data;
35using Nini.Config;
36using log4net;
37
38namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
39{
40 public class OpenSimInventoryStoragePlugin : IInventoryStorageProvider
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 const string EXTENSION_NAME = "OpenSimInventoryStorage"; // Used in metrics reporting
44
45 private AssetInventoryServer m_server;
46 private IConfig m_openSimConfig;
47 private OpenSimInventoryService m_inventoryService;
48
49 public OpenSimInventoryStoragePlugin()
50 {
51 }
52
53 #region IInventoryStorageProvider implementation
54
55 public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItemBase item)
56 {
57 item = null;
58 //BackendResponse ret;
59
60 //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect")))
61 //{
62 // IDataReader reader;
63
64 // try
65 // {
66 // dbConnection.Open();
67
68 // IDbCommand command = dbConnection.CreateCommand();
69 // command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," +
70 // "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," +
71 // "creationDate,groupID,groupOwned,flags,avatarID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE inventoryID='{0}'",
72 // itemID.ToString());
73 // reader = command.ExecuteReader();
74
75 // if (reader.Read())
76 // {
77 // item = new InventoryItemBase();
78 // item.ID = itemID;
79 // item.AssetID = UUID.Parse(reader.GetString(0));
80 // item.AssetType = reader.GetInt32(1);
81 // item.Name = reader.GetString(2);
82 // item.Description = reader.GetString(3);
83 // item.NextPermissions = (uint)reader.GetInt32(4);
84 // item.CurrentPermissions = (uint)reader.GetInt32(5);
85 // item.InvType = reader.GetInt32(6);
86 // item.Creator = UUID.Parse(reader.GetString(7));
87 // item.BasePermissions = (uint)reader.GetInt32(8);
88 // item.EveryOnePermissions = (uint)reader.GetInt32(9);
89 // item.SalePrice = reader.GetInt32(10);
90 // item.SaleType = reader.GetByte(11);
91 // item.CreationDate = reader.GetInt32(12);
92 // item.GroupID = UUID.Parse(reader.GetString(13));
93 // item.GroupOwned = reader.GetBoolean(14);
94 // item.Flags = (uint)reader.GetInt32(15);
95 // item.Owner = UUID.Parse(reader.GetString(16));
96 // item.Folder = UUID.Parse(reader.GetString(17));
97 // item.GroupPermissions = (uint)reader.GetInt32(18);
98
99 // ret = BackendResponse.Success;
100 // }
101 // else
102 // {
103 // ret = BackendResponse.NotFound;
104 // }
105 // }
106 // catch (MySqlException ex)
107 // {
108 // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message);
109 // ret = BackendResponse.Failure;
110 // }
111 //}
112
113 //m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now);
114 //return ret;
115 m_log.Warn("[OPENSIMINVENTORYSTORAGE]: Called TryFetchItem which is not implemented.");
116 return BackendResponse.Success;
117 }
118
119 public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolderWithChildren folder)
120 {
121 BackendResponse ret;
122
123 // TODO: implement some logic for "folder not found"
124 folder = m_inventoryService.GetInventoryFolder(folderID);
125 ret = BackendResponse.Success;
126
127 m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now);
128 return ret;
129 }
130
131 public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents)
132 {
133 contents = null;
134 //BackendResponse ret;
135
136 //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect")))
137 //{
138 // IDataReader reader;
139
140 // try
141 // {
142 // dbConnection.Open();
143
144 // contents = new InventoryCollection();
145
146 // #region Folder retrieval
147
148 // IDbCommand command = dbConnection.CreateCommand();
149 // command.CommandText = String.Format("SELECT folderName,type,version,agentID,folderID FROM inventoryfolders WHERE parentFolderID='{0}'",
150 // folderID.ToString());
151 // reader = command.ExecuteReader();
152
153 // contents.Folders = new Dictionary<UUID, InventoryFolderWithChildren>();
154
155 // while (reader.Read())
156 // {
157 // InventoryFolderWithChildren folder = new InventoryFolderWithChildren();
158 // folder.ParentID = folderID;
159 // folder.Children = null; // This call doesn't do recursion
160 // folder.Name = reader.GetString(0);
161 // folder.Type = reader.GetInt16(1);
162 // folder.Version = (ushort)reader.GetInt16(2);
163 // folder.Owner = UUID.Parse(reader.GetString(3));
164 // folder.ID = UUID.Parse(reader.GetString(4));
165
166 // contents.Folders.Add(folder.ID, folder);
167 // contents.UserID = folder.Owner;
168 // }
169
170 // reader.Close();
171
172 // #endregion Folder retrieval
173
174 // #region Item retrieval
175
176 // command = dbConnection.CreateCommand();
177 // command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," +
178 // "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," +
179 // "creationDate,groupID,groupOwned,flags,avatarID,inventoryID,inventoryGroupPermissions FROM inventoryitems WHERE parentFolderID='{0}'",
180 // folderID.ToString());
181 // reader = command.ExecuteReader();
182
183 // contents.Items = new Dictionary<UUID, InventoryItemBase>();
184
185 // while (reader.Read())
186 // {
187 // InventoryItemBase item = new InventoryItemBase();
188 // item.Folder = folderID;
189 // item.AssetID = UUID.Parse(reader.GetString(0));
190 // item.AssetType = reader.GetInt32(1);
191 // item.Name = reader.GetString(2);
192 // item.Description = reader.GetString(3);
193 // item.NextPermissions = (uint)reader.GetInt32(4);
194 // item.CurrentPermissions = (uint)reader.GetInt32(5);
195 // item.InvType = reader.GetInt32(6);
196 // item.Creator = UUID.Parse(reader.GetString(7));
197 // item.BasePermissions = (uint)reader.GetInt32(8);
198 // item.EveryOnePermissions = (uint)reader.GetInt32(9);
199 // item.SalePrice = reader.GetInt32(10);
200 // item.SaleType = reader.GetByte(11);
201 // item.CreationDate = reader.GetInt32(12);
202 // item.GroupID = UUID.Parse(reader.GetString(13));
203 // item.GroupOwned = reader.GetBoolean(14);
204 // item.Flags = (uint)reader.GetInt32(15);
205 // item.Owner = UUID.Parse(reader.GetString(16));
206 // item.ID = UUID.Parse(reader.GetString(17));
207 // item.GroupPermissions = (uint)reader.GetInt32(18);
208
209 // contents.Items.Add(item.ID, item);
210 // contents.UserID = item.Owner;
211 // }
212
213 // #endregion Item retrieval
214
215 // ret = BackendResponse.Success;
216 // }
217 // catch (MySqlException ex)
218 // {
219 // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message);
220 // ret = BackendResponse.Failure;
221 // }
222 //}
223
224 //m_server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now);
225 //return ret;
226 m_log.Warn("[OPENSIMINVENTORYSTORAGE]: Called TryFetchFolderContents which is not implemented.");
227 return BackendResponse.Success;
228 }
229
230 public BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolderWithChildren> folders)
231 {
232 folders = new List<InventoryFolderWithChildren>();
233 BackendResponse ret;
234 UUID ownerID;
235
236 if (Utils.TryGetOpenSimUUID(owner, out ownerID))
237 {
238 List<InventoryFolderBase> baseFolders = m_inventoryService.GetInventorySkeleton(ownerID);
239 foreach (InventoryFolderBase baseFolder in baseFolders)
240 {
241 InventoryFolderWithChildren folder = new InventoryFolderWithChildren(baseFolder);
242 //folder.Children = null; // This call does not create a folder hierarchy
243 folders.Add(folder);
244 }
245
246 ret = BackendResponse.Success;
247 }
248 else
249 {
250 folders = null;
251 ret = BackendResponse.NotFound;
252 }
253
254 m_server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now);
255 return ret;
256 }
257
258 public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory)
259 {
260 inventory = null;
261 BackendResponse ret;
262 List<InventoryFolderWithChildren> folders;
263
264 ret = TryFetchFolderList(owner, out folders);
265
266 if (ret == BackendResponse.Success)
267 {
268 // Add the retrieved folders to the inventory collection
269 inventory = new InventoryCollection();
270 inventory.Folders = new Dictionary<UUID, InventoryFolderWithChildren>(folders.Count);
271 foreach (InventoryFolderWithChildren folder in folders)
272 inventory.Folders[folder.ID] = folder;
273
274 // Fetch inventory items
275 UUID ownerID;
276 if (Utils.TryGetOpenSimUUID(owner, out ownerID))
277 {
278 inventory.UserID = ownerID;
279 inventory.Items = new Dictionary<UUID, InventoryItemBase>();
280
281 foreach (InventoryFolderWithChildren folder in folders)
282 {
283 foreach (InventoryItemBase item in m_inventoryService.RequestFolderItems(folder.ID))
284 {
285 inventory.Items.Add(item.ID, item);
286 }
287 }
288
289 ret = BackendResponse.Success;
290
291 }
292 else
293 {
294 ret = BackendResponse.NotFound;
295 }
296 }
297
298 m_server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now);
299 return ret;
300 }
301
302 public BackendResponse TryFetchActiveGestures(Uri owner, out List<InventoryItemBase> gestures)
303 {
304 gestures = null;
305 BackendResponse ret;
306 UUID ownerID;
307
308 if (Utils.TryGetOpenSimUUID(owner, out ownerID))
309 {
310 gestures = m_inventoryService.GetActiveGestures(ownerID);
311 ret = BackendResponse.Success;
312 }
313 else
314 {
315 ret = BackendResponse.NotFound;
316 }
317
318 m_server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now);
319 return ret;
320 }
321
322 public BackendResponse TryCreateItem(Uri owner, InventoryItemBase item)
323 {
324 BackendResponse ret;
325
326 if (m_inventoryService.AddItem(item))
327 {
328 ret = BackendResponse.Success;
329 }
330 else
331 {
332 ret = BackendResponse.Failure;
333 }
334
335 m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now);
336 return ret;
337 }
338
339 public BackendResponse TryCreateFolder(Uri owner, InventoryFolderWithChildren folder)
340 {
341 BackendResponse ret;
342
343 if (m_inventoryService.AddFolder(folder))
344 {
345 ret = BackendResponse.Success;
346 }
347 else
348 {
349 ret = BackendResponse.Failure;
350 }
351
352 m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now);
353 return ret;
354 }
355
356 public BackendResponse TryCreateInventory(Uri owner, InventoryFolderWithChildren rootFolder)
357 {
358 BackendResponse ret;
359 UUID ownerID;
360
361 if (Utils.TryGetOpenSimUUID(owner, out ownerID))
362 {
363 if (m_inventoryService.CreateNewUserInventory(ownerID))
364 {
365 ret = BackendResponse.Success;
366 }
367 else
368 {
369 ret = BackendResponse.Failure;
370 }
371 }
372 else
373 {
374 ret = BackendResponse.Failure;
375 }
376
377 return ret;
378 }
379
380 public BackendResponse TryDeleteItem(Uri owner, UUID itemID)
381 {
382 BackendResponse ret;
383
384 if (m_inventoryService.DeleteItem(m_inventoryService.GetInventoryItem(itemID)))
385 {
386 ret = BackendResponse.Success;
387 }
388 else
389 {
390 ret = BackendResponse.Failure;
391 }
392
393 m_server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now);
394 return ret;
395 }
396
397 public BackendResponse TryDeleteFolder(Uri owner, UUID folderID)
398 {
399 //BackendResponse ret;
400 //UUID ownerID;
401
402 //if (Utils.TryGetOpenSimUUID(owner, out ownerID))
403 //{
404 // using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect")))
405 // {
406 // try
407 // {
408 // dbConnection.Open();
409
410 // MySqlCommand command = new MySqlCommand(
411 // "DELETE FROM inventoryfolders WHERE folderID=?folderID AND agentID=?agentID", dbConnection);
412
413 // command.Parameters.AddWithValue("?folderID", folderID.ToString());
414 // command.Parameters.AddWithValue("?agentID", ownerID.ToString());
415
416 // int rowsAffected = command.ExecuteNonQuery();
417 // if (rowsAffected == 1)
418 // {
419 // ret = BackendResponse.Success;
420 // }
421 // else
422 // {
423 // m_log.ErrorFormat("[OPENSIMINVENTORYSTORAGE]: MySQL DELETE query affected {0} rows", rowsAffected);
424 // ret = BackendResponse.NotFound;
425 // }
426 // }
427 // catch (MySqlException ex)
428 // {
429 // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message);
430 // ret = BackendResponse.Failure;
431 // }
432 // }
433 //}
434 //else
435 //{
436 // ret = BackendResponse.NotFound;
437 //}
438
439 //m_server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now);
440 //return ret;
441 m_log.Warn("[OPENSIMINVENTORYSTORAGE]: Called TryDeleteFolder which is not implemented.");
442 return BackendResponse.Success;
443 }
444
445 public BackendResponse TryPurgeFolder(Uri owner, UUID folderID)
446 {
447 BackendResponse ret;
448
449 if (m_inventoryService.PurgeFolder(m_inventoryService.GetInventoryFolder(folderID)))
450 {
451 ret = BackendResponse.Success;
452 }
453 else
454 {
455 ret = BackendResponse.Failure;
456 }
457
458 m_server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now);
459 return ret;
460 }
461
462 public int ForEach(Action<AssetMetadata> action, int start, int count)
463 {
464 int rowCount = 0;
465
466 //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect")))
467 //{
468 // MySqlDataReader reader;
469
470 // try
471 // {
472 // dbConnection.Open();
473
474 // MySqlCommand command = dbConnection.CreateCommand();
475 // command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}",
476 // start, count);
477 // reader = command.ExecuteReader();
478 // }
479 // catch (MySqlException ex)
480 // {
481 // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message);
482 // return 0;
483 // }
484
485 // while (reader.Read())
486 // {
487 // Metadata metadata = new Metadata();
488 // metadata.CreationDate = OpenMetaverse.Utils.Epoch;
489 // metadata.Description = reader.GetString(1);
490 // metadata.ID = UUID.Parse(reader.GetString(5));
491 // metadata.Name = reader.GetString(0);
492 // metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4));
493 // metadata.Temporary = reader.GetBoolean(3);
494 // metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
495
496 // action(metadata);
497 // ++rowCount;
498 // }
499
500 // reader.Close();
501 //}
502
503 return rowCount;
504 }
505
506 #endregion IInventoryStorageProvider implementation
507
508 #region IPlugin implementation
509
510 public void Initialise(AssetInventoryServer server)
511 {
512 m_server = server;
513 m_openSimConfig = server.ConfigFile.Configs["OpenSim"];
514
515 m_inventoryService = new OpenSimInventoryService();
516 m_inventoryService.AddPlugin(m_openSimConfig.GetString("inventory_database_provider"),
517 m_openSimConfig.GetString("inventory_database_connect"));
518 }
519
520 public void Stop()
521 {
522 }
523
524 public void Initialise()
525 {
526 m_log.InfoFormat("[OPENSIMINVENTORYSTORAGE]: {0} cannot be default-initialized!", Name);
527 throw new PluginNotInitialisedException(Name);
528 }
529
530 public void Dispose()
531 {
532 }
533
534 public string Version
535 {
536 // TODO: this should be something meaningful and not hardcoded?
537 get { return "0.1"; }
538 }
539
540 public string Name
541 {
542 get { return "OpenSimInventoryStorage"; }
543 }
544
545 #endregion IPlugin implementation
546 }
547}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml
deleted file mode 100644
index 8cd7585..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml
+++ /dev/null
@@ -1,27 +0,0 @@
1<Addin id="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim" version="0.1">
2 <Runtime>
3 <Import assembly="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" />
4 <Import assembly="OpenSim.Data.dll" />
5 </Runtime>
6
7 <Dependencies>
8 <Addin id="OpenSim.Grid.AssetInventoryServer" version="0.1" />
9 </Dependencies>
10
11 <ExtensionPoint path = "/OpenSim/AssetData">
12 <ExtensionNode name="Plugin" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.Data.IAssetDataPlugin" />
13 </ExtensionPoint>
14
15 <Extension path="/OpenSim/AssetInventoryServer/AssetStorageProvider">
16 <Plugin id="OpenSimAssetStorage" provider="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.OpenSimAssetStoragePlugin" />
17 </Extension>
18 <Extension path="/OpenSim/AssetInventoryServer/InventoryStorageProvider">
19 <Plugin id="OpenSimInventoryStorage" provider="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.OpenSimInventoryStoragePlugin" />
20 </Extension>
21 <Extension path="/OpenSim/AssetInventoryServer/Frontend">
22 <Plugin id="OpenSimAssetFrontend" provider="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.OpenSimAssetFrontendPlugin" />
23 </Extension>
24 <Extension path="/OpenSim/AssetInventoryServer/Frontend">
25 <Plugin id="OpenSimInventoryFrontend" provider="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.OpenSimInventoryFrontendPlugin" />
26 </Extension>
27</Addin>
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
deleted file mode 100644
index b5ad1a1..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
+++ /dev/null
@@ -1,369 +0,0 @@
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.IO;
30using System.Reflection;
31using System.Net;
32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers;
36using OpenSim.Framework.Servers.HttpServer;
37using log4net;
38
39namespace OpenSim.Grid.AssetInventoryServer.Plugins
40{
41 public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 AssetInventoryServer m_server;
45
46 public ReferenceFrontendPlugin()
47 {
48 }
49
50 #region IPlugin implementation
51
52 public void Initialise(AssetInventoryServer server)
53 {
54 m_server = server;
55
56 // Asset metadata request
57 //m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server));
58
59 // Asset data request
60 m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server));
61
62 // Asset creation
63 //m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server));
64
65 m_log.Info("[REFERENCEFRONTEND]: Reference Frontend loaded.");
66 }
67
68 /// <summary>
69 /// <para>Initialises asset interface</para>
70 /// </summary>
71 public void Initialise()
72 {
73 m_log.InfoFormat("[REFERENCEFRONTEND]: {0} cannot be default-initialized!", Name);
74 throw new PluginNotInitialisedException(Name);
75 }
76
77 public void Dispose()
78 {
79 }
80
81 public string Version
82 {
83 // TODO: this should be something meaningful and not hardcoded?
84 get { return "0.1"; }
85 }
86
87 public string Name
88 {
89 get { return "ReferenceFrontend"; }
90 }
91
92 #endregion IPlugin implementation
93
94 //public class MetadataRequestHandler : IStreamedRequestHandler
95 //{
96 // AssetInventoryServer m_server;
97 // string m_contentType;
98 // string m_httpMethod;
99 // string m_path;
100
101 // public MetadataRequestHandler(AssetInventoryServer server)
102 // {
103 // m_server = server;
104 // m_contentType = null;
105 // m_httpMethod = "GET";
106 // m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata";
107 // }
108
109 // #region IStreamedRequestHandler implementation
110
111 // public string ContentType
112 // {
113 // get { return m_contentType; }
114 // }
115
116 // public string HttpMethod
117 // {
118 // get { return m_httpMethod; }
119 // }
120
121 // public string Path
122 // {
123 // get { return m_path; }
124 // }
125
126 // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
127 // {
128 // byte[] serializedData = null;
129 // UUID assetID;
130 // // Split the URL up into an AssetID and a method
131 // string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
132
133 // if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
134 // {
135 // UUID authToken = Utils.GetAuthToken(httpRequest);
136
137 // if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
138 // {
139 // AssetMetadata metadata;
140 // BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata);
141
142 // if (storageResponse == BackendResponse.Success)
143 // {
144 // // If the asset data location wasn't specified in the metadata, specify it
145 // // manually here by pointing back to this asset server
146 // if (!metadata.Methods.ContainsKey("data"))
147 // {
148 // metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
149 // httpRequest.Url.Scheme, httpRequest.Url.Authority, assetID));
150 // }
151
152 // serializedData = metadata.SerializeToBytes();
153
154 // httpResponse.StatusCode = (int) HttpStatusCode.OK;
155 // httpResponse.ContentType = "application/json";
156 // httpResponse.ContentLength = serializedData.Length;
157 // httpResponse.Body.Write(serializedData, 0, serializedData.Length);
158 // }
159 // else if (storageResponse == BackendResponse.NotFound)
160 // {
161 // m_log.Warn("[REFERENCEFRONTEND]: Could not find metadata for asset " + assetID.ToString());
162 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
163 // }
164 // else
165 // {
166 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
167 // }
168 // }
169 // else
170 // {
171 // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
172 // }
173
174 // return serializedData;
175 // }
176
177 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
178 // return serializedData;
179 // }
180
181 // #endregion IStreamedRequestHandler implementation
182 //}
183
184 public class DataRequestHandler : IStreamedRequestHandler
185 {
186 AssetInventoryServer m_server;
187 string m_contentType;
188 string m_httpMethod;
189 string m_path;
190
191 public DataRequestHandler(AssetInventoryServer server)
192 {
193 m_server = server;
194 m_contentType = null;
195 m_httpMethod = "GET";
196 m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data";
197 }
198
199 #region IStreamedRequestHandler implementation
200
201 public string ContentType
202 {
203 get { return m_contentType; }
204 }
205
206 public string HttpMethod
207 {
208 get { return m_httpMethod; }
209 }
210
211 public string Path
212 {
213 get { return m_path; }
214 }
215
216 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
217 {
218 byte[] assetData = null;
219 UUID assetID;
220 // Split the URL up into an AssetID and a method
221 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
222
223 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
224 {
225 UUID authToken = Utils.GetAuthToken(httpRequest);
226
227 if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
228 {
229 BackendResponse storageResponse = m_server.StorageProvider.TryFetchData(assetID, out assetData);
230
231 if (storageResponse == BackendResponse.Success)
232 {
233 httpResponse.StatusCode = (int) HttpStatusCode.OK;
234 httpResponse.ContentType = "application/octet-stream";
235 httpResponse.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
236 httpResponse.ContentLength = assetData.Length;
237 httpResponse.Body.Write(assetData, 0, assetData.Length);
238 }
239 else if (storageResponse == BackendResponse.NotFound)
240 {
241 httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
242 }
243 else
244 {
245 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
246 }
247 }
248 else
249 {
250 httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
251 }
252
253 return assetData;
254 }
255
256 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
257 return assetData;
258 }
259
260 #endregion IStreamedRequestHandler implementation
261 }
262
263 //public class CreateRequestHandler : IStreamedRequestHandler
264 //{
265 // AssetInventoryServer m_server;
266 // string m_contentType;
267 // string m_httpMethod;
268 // string m_path;
269
270 // public CreateRequestHandler(AssetInventoryServer server)
271 // {
272 // m_server = server;
273 // m_contentType = null;
274 // m_httpMethod = "POST";
275 // m_path = "^/createasset";
276 // }
277
278 // #region IStreamedRequestHandler implementation
279
280 // public string ContentType
281 // {
282 // get { return m_contentType; }
283 // }
284
285 // public string HttpMethod
286 // {
287 // get { return m_httpMethod; }
288 // }
289
290 // public string Path
291 // {
292 // get { return m_path; }
293 // }
294
295 // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
296 // {
297 // byte[] responseData = null;
298 // UUID authToken = Utils.GetAuthToken(httpRequest);
299
300 // if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken))
301 // {
302 // try
303 // {
304 // OSD osdata = OSDParser.DeserializeJson(new StreamReader(httpRequest.InputStream).ReadToEnd());
305
306 // if (osdata.Type == OSDType.Map)
307 // {
308 // OSDMap map = (OSDMap)osdata;
309 // Metadata metadata = new Metadata();
310 // metadata.Deserialize(map);
311
312 // byte[] assetData = map["data"].AsBinary();
313
314 // if (assetData != null && assetData.Length > 0)
315 // {
316 // BackendResponse storageResponse;
317
318 // if (metadata.ID != UUID.Zero)
319 // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData);
320 // else
321 // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
322
323 // if (storageResponse == BackendResponse.Success)
324 // {
325 // httpResponse.StatusCode = (int) HttpStatusCode.Created;
326 // OSDMap responseMap = new OSDMap(1);
327 // responseMap["id"] = OSD.FromUUID(metadata.ID);
328 // LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
329 // responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
330 // httpResponse.Body.Write(responseData, 0, responseData.Length);
331 // httpResponse.Body.Flush();
332 // }
333 // else if (storageResponse == BackendResponse.NotFound)
334 // {
335 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
336 // }
337 // else
338 // {
339 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
340 // }
341 // }
342 // else
343 // {
344 // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
345 // }
346 // }
347 // else
348 // {
349 // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
350 // }
351 // }
352 // catch (Exception ex)
353 // {
354 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
355 // httpResponse.StatusDescription = ex.Message;
356 // }
357 // }
358 // else
359 // {
360 // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
361 // }
362
363 // return responseData;
364 // }
365
366 // #endregion IStreamedRequestHandler implementation
367 //}
368 }
369}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
deleted file mode 100644
index 42a279d..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml
+++ /dev/null
@@ -1,28 +0,0 @@
1<Addin id="OpenSim.Grid.AssetInventoryServer.Plugins" version="0.1">
2 <Runtime>
3 <Import assembly="OpenSim.Grid.AssetInventoryServer.Plugins.dll" />
4 </Runtime>
5
6 <Dependencies>
7 <Addin id="OpenSim.Grid.AssetInventoryServer" version="0.1" />
8 </Dependencies>
9
10 <Extension path="/OpenSim/AssetInventoryServer/MetricsProvider">
11 <Plugin id="NullMetrics" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.NullMetricsPlugin" />
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>
19 <Extension path="/OpenSim/AssetInventoryServer/AuthenticationProvider">
20 <Plugin id="NullAuthentication" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.NullAuthenticationPlugin" />
21 </Extension>
22 <Extension path="/OpenSim/AssetInventoryServer/AuthorizationProvider">
23 <Plugin id="AuthorizeAll" provider="OpenSim.Grid.AssetInventoryServer.Plugins.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.AuthorizeAllPlugin" />
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>
28</Addin>
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml
deleted file mode 100644
index cb6959e..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml
+++ /dev/null
@@ -1,16 +0,0 @@
1<Addin id="OpenSim.Grid.AssetInventoryServer.Plugins.Simple" version="0.1">
2 <Runtime>
3 <Import assembly="OpenSim.Grid.AssetInventoryServer.Plugins.Simple.dll" />
4 </Runtime>
5
6 <Dependencies>
7 <Addin id="OpenSim.Grid.AssetInventoryServer" version="0.1" />
8 </Dependencies>
9
10 <Extension path="/OpenSim/AssetInventoryServer/AssetStorageProvider">
11 <Plugin id="SimpleAssetStorage" provider="OpenSim.Grid.AssetInventoryServer.Plugins.Simple.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.Simple.SimpleAssetStoragePlugin" />
12 </Extension>
13 <Extension path="/OpenSim/AssetInventoryServer/InventoryStorageProvider">
14 <Plugin id="SimpleInventoryStorage" provider="OpenSim.Grid.AssetInventoryServer.Plugins.Simple.dll" type="OpenSim.Grid.AssetInventoryServer.Plugins.Simple.SimpleInventoryStoragePlugin" />
15 </Extension>
16</Addin>
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs
deleted file mode 100644
index 4ec2d96..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs
+++ /dev/null
@@ -1,290 +0,0 @@
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.Reflection;
30using System.Collections.Generic;
31using System.IO;
32using OpenMetaverse;
33using OpenSim.Framework;
34using log4net;
35
36namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
37{
38 public class SimpleAssetStoragePlugin : IAssetStorageProvider
39 {
40 const string EXTENSION_NAME = "SimpleAssetStorage"; // Used in metrics reporting
41 const string DEFAULT_DATA_DIR = "SimpleAssets";
42 const string TEMP_DATA_DIR = "SimpleAssetsTemp";
43
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 AssetInventoryServer server;
46 Dictionary<UUID, AssetMetadata> metadataStorage;
47 Dictionary<UUID, string> filenames;
48
49 public SimpleAssetStoragePlugin()
50 {
51 }
52
53 #region Required Interfaces
54
55 public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata)
56 {
57 metadata = null;
58 BackendResponse ret;
59
60 if (metadataStorage.TryGetValue(assetID, out metadata))
61 ret = BackendResponse.Success;
62 else
63 ret = BackendResponse.NotFound;
64
65 server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
66 return ret;
67 }
68
69 public BackendResponse TryFetchData(UUID assetID, out byte[] assetData)
70 {
71 assetData = null;
72 string filename;
73 BackendResponse ret;
74
75 if (filenames.TryGetValue(assetID, out filename))
76 {
77 try
78 {
79 assetData = File.ReadAllBytes(filename);
80 ret = BackendResponse.Success;
81 }
82 catch (Exception ex)
83 {
84 m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message);
85 ret = BackendResponse.Failure;
86 }
87 }
88 else
89 {
90 ret = BackendResponse.NotFound;
91 }
92
93 server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
94 return ret;
95 }
96
97 public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset)
98 {
99 asset = new AssetBase();
100 AssetMetadata metadata = asset.Metadata;
101
102 string filename;
103 BackendResponse ret;
104
105 if (metadataStorage.TryGetValue(assetID, out metadata) &&
106 filenames.TryGetValue(assetID, out filename))
107 {
108 try
109 {
110 asset.Data = File.ReadAllBytes(filename);
111 ret = BackendResponse.Success;
112 }
113 catch (Exception ex)
114 {
115 m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message);
116 ret = BackendResponse.Failure;
117 }
118
119 asset.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType);
120 asset.Local = false;
121 }
122 else
123 {
124 asset = null;
125 ret = BackendResponse.NotFound;
126 }
127
128 server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
129 server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (asset != null && asset.Data != null ? asset.Data.Length : 0), DateTime.Now);
130 return ret;
131 }
132
133 public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID)
134 {
135 assetID = asset.FullID = UUID.Random();
136 return TryCreateAsset(asset);
137 }
138
139 public BackendResponse TryCreateAsset(AssetBase asset)
140 {
141 BackendResponse ret;
142 AssetMetadata metadata = asset.Metadata;
143
144 string path;
145 string filename = String.Format("{0}.{1}", asset.FullID, Utils.ContentTypeToExtension(metadata.ContentType));
146
147 if (asset.Temporary)
148 path = Path.Combine(TEMP_DATA_DIR, filename);
149 else
150 path = Path.Combine(DEFAULT_DATA_DIR, filename);
151
152 try
153 {
154 File.WriteAllBytes(path, asset.Data);
155 lock (filenames) filenames[asset.FullID] = path;
156
157 // Set the creation date to right now
158 metadata.CreationDate = DateTime.Now;
159
160 lock (metadataStorage)
161 metadataStorage[asset.FullID] = metadata;
162
163 ret = BackendResponse.Success;
164 }
165 catch (Exception ex)
166 {
167 m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed writing data for asset {0} to {1}: {2}", asset.FullID, filename, ex.Message);
168 ret = BackendResponse.Failure;
169 }
170
171 server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now);
172 return ret;
173 }
174
175 public int ForEach(Action<AssetMetadata> action, int start, int count)
176 {
177 int rowCount = 0;
178
179 //lock (metadataStorage)
180 //{
181 // foreach (Metadata metadata in metadataStorage.Values)
182 // {
183 // action(metadata);
184 // ++rowCount;
185 // }
186 //}
187
188 return rowCount;
189 }
190
191 #endregion Required Interfaces
192
193 #region IPlugin implementation
194
195 public void Initialise(AssetInventoryServer server)
196 {
197 this.server = server;
198
199 metadataStorage = new Dictionary<UUID, AssetMetadata>();
200 filenames = new Dictionary<UUID, string>();
201
202 LoadFiles(DEFAULT_DATA_DIR, false);
203 LoadFiles(TEMP_DATA_DIR, true);
204
205 m_log.InfoFormat("[SIMPLEASSETSTORAGE]: Initialized the store index with metadata for {0} assets",
206 metadataStorage.Count);
207 }
208
209 /// <summary>
210 /// <para>Initialises asset interface</para>
211 /// </summary>
212 public void Initialise()
213 {
214 m_log.InfoFormat("[SIMPLEASSETSTORAGE]: {0} cannot be default-initialized!", Name);
215 throw new PluginNotInitialisedException(Name);
216 }
217
218 public void Dispose()
219 {
220 WipeTemporary();
221 }
222
223 public string Version
224 {
225 // TODO: this should be something meaningful and not hardcoded?
226 get { return "0.1"; }
227 }
228
229 public string Name
230 {
231 get { return "SimpleAssetStorage"; }
232 }
233
234 #endregion IPlugin implementation
235
236 public void WipeTemporary()
237 {
238 if (Directory.Exists(TEMP_DATA_DIR))
239 {
240 try { Directory.Delete(TEMP_DATA_DIR); }
241 catch (Exception ex) { m_log.Error("[SIMPLEASSETSTORAGE]: " + ex.Message); }
242 }
243 }
244
245 void LoadFiles(string folder, bool temporary)
246 {
247 // Try to create the directory if it doesn't already exist
248 if (!Directory.Exists(folder))
249 {
250 try { Directory.CreateDirectory(folder); }
251 catch (Exception ex)
252 {
253 m_log.Warn("[SIMPLEASSETSTORAGE]: " + ex.Message);
254 return;
255 }
256 }
257
258 lock (metadataStorage)
259 {
260 try
261 {
262 string[] assets = Directory.GetFiles(folder);
263
264 for (int i = 0; i < assets.Length; i++)
265 {
266 string filename = assets[i];
267 byte[] data = File.ReadAllBytes(filename);
268
269 AssetMetadata metadata = new AssetMetadata();
270 metadata.CreationDate = File.GetCreationTime(filename);
271 metadata.Description = String.Empty;
272 metadata.FullID = SimpleUtils.ParseUUIDFromFilename(filename);
273 metadata.Name = SimpleUtils.ParseNameFromFilename(filename);
274 metadata.SHA1 = OpenMetaverse.Utils.SHA1(data);
275 metadata.Temporary = false;
276 metadata.ContentType = Utils.ExtensionToContentType(Path.GetExtension(filename).TrimStart('.'));
277
278 // Store the loaded data
279 metadataStorage[metadata.FullID] = metadata;
280 filenames[metadata.FullID] = filename;
281 }
282 }
283 catch (Exception ex)
284 {
285 m_log.Warn("[SIMPLEASSETSTORAGE]: " + ex.Message);
286 }
287 }
288 }
289 }
290}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs
deleted file mode 100644
index 4010818..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs
+++ /dev/null
@@ -1,625 +0,0 @@
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.Reflection;
30using System.Collections.Generic;
31using System.IO;
32using System.Text;
33using OpenMetaverse;
34using OpenSim.Framework;
35using log4net;
36
37namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
38{
39 public class SimpleInventoryStoragePlugin : IInventoryStorageProvider
40 {
41 const string EXTENSION_NAME = "SimpleInventoryStorage"; // Used for metrics reporting
42 const string DEFAULT_INVENTORY_DIR = "SimpleInventory";
43
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 AssetInventoryServer server;
46 Dictionary<Uri, InventoryCollection> inventories = new Dictionary<Uri, InventoryCollection>();
47 Dictionary<Uri, List<InventoryItemBase>> activeGestures = new Dictionary<Uri, List<InventoryItemBase>>();
48 Utils.InventoryItemSerializer itemSerializer = new Utils.InventoryItemSerializer();
49 Utils.InventoryFolderSerializer folderSerializer = new Utils.InventoryFolderSerializer();
50
51 public SimpleInventoryStoragePlugin()
52 {
53 }
54
55 #region Required Interfaces
56
57 public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItemBase item)
58 {
59 item = null;
60 BackendResponse ret;
61
62 InventoryCollection collection;
63 if (inventories.TryGetValue(owner, out collection) && collection.Items.TryGetValue(itemID, out item))
64 ret = BackendResponse.Success;
65 else
66 ret = BackendResponse.NotFound;
67
68 server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now);
69 return ret;
70 }
71
72 public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolderWithChildren folder)
73 {
74 folder = null;
75 BackendResponse ret;
76
77 InventoryCollection collection;
78 if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder))
79 ret = BackendResponse.Success;
80 else
81 ret = BackendResponse.NotFound;
82
83 server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now);
84 return ret;
85 }
86
87 public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents)
88 {
89 contents = null;
90 BackendResponse ret;
91
92 InventoryCollection collection;
93 InventoryFolderWithChildren folder;
94
95 if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder))
96 {
97 contents = new InventoryCollection();
98 contents.UserID = collection.UserID;
99 contents.Folders = new Dictionary<UUID, InventoryFolderWithChildren>();
100 contents.Items = new Dictionary<UUID, InventoryItemBase>();
101
102 foreach (InventoryNodeBase invBase in folder.Children.Values)
103 {
104 if (invBase is InventoryItemBase)
105 {
106 InventoryItemBase invItem = invBase as InventoryItemBase;
107 contents.Items.Add(invItem.ID, invItem);
108 }
109 else
110 {
111 InventoryFolderWithChildren invFolder = invBase as InventoryFolderWithChildren;
112 contents.Folders.Add(invFolder.ID, invFolder);
113 }
114 }
115
116 ret = BackendResponse.Success;
117 }
118 else
119 {
120 ret = BackendResponse.NotFound;
121 }
122
123 server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now);
124 return ret;
125 }
126
127 public BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolderWithChildren> folders)
128 {
129 folders = null;
130 BackendResponse ret;
131
132 InventoryCollection collection;
133 if (inventories.TryGetValue(owner, out collection))
134 {
135 folders = new List<InventoryFolderWithChildren>(collection.Folders.Values);
136 return BackendResponse.Success;
137 }
138 else
139 {
140 ret = BackendResponse.NotFound;
141 }
142
143 server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now);
144 return ret;
145 }
146
147 public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory)
148 {
149 inventory = null;
150 BackendResponse ret;
151
152 if (inventories.TryGetValue(owner, out inventory))
153 ret = BackendResponse.Success;
154 else
155 ret = BackendResponse.NotFound;
156
157 server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now);
158 return ret;
159 }
160
161 public BackendResponse TryFetchActiveGestures(Uri owner, out List<InventoryItemBase> gestures)
162 {
163 gestures = null;
164 BackendResponse ret;
165
166 if (activeGestures.TryGetValue(owner, out gestures))
167 ret = BackendResponse.Success;
168 else
169 ret = BackendResponse.NotFound;
170
171 server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now);
172 return ret;
173 }
174
175 public BackendResponse TryCreateItem(Uri owner, InventoryItemBase item)
176 {
177 BackendResponse ret;
178
179 InventoryCollection collection;
180 if (inventories.TryGetValue(owner, out collection))
181 {
182 // Delete this item first if it already exists
183 InventoryItemBase oldItem;
184 if (collection.Items.TryGetValue(item.ID, out oldItem))
185 TryDeleteItem(owner, item.ID);
186
187 try
188 {
189 // Create the file
190 SaveItem(item);
191
192 // Add the item to the collection
193 lock (collection) collection.Items[item.ID] = item;
194
195 // Add the item to its parent folder
196 InventoryFolderWithChildren parent;
197 if (collection.Folders.TryGetValue(item.Folder, out parent))
198 lock (parent.Children) parent.Children.Add(item.ID, item);
199
200 // Add active gestures to our list
201 if (item.InvType == (int)InventoryType.Gesture && item.Flags == 1)
202 {
203 lock (activeGestures)
204 activeGestures[owner].Add(item);
205 }
206
207 ret = BackendResponse.Success;
208 }
209 catch (Exception ex)
210 {
211 m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message);
212 ret = BackendResponse.Failure;
213 }
214 }
215 else
216 {
217 return BackendResponse.NotFound;
218 }
219
220 server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now);
221 return ret;
222 }
223
224 public BackendResponse TryCreateFolder(Uri owner, InventoryFolderWithChildren folder)
225 {
226 BackendResponse ret;
227
228 InventoryCollection collection;
229 if (inventories.TryGetValue(owner, out collection))
230 {
231 // Delete this folder first if it already exists
232 InventoryFolderWithChildren oldFolder;
233 if (collection.Folders.TryGetValue(folder.ID, out oldFolder))
234 TryDeleteFolder(owner, folder.ID);
235
236 try
237 {
238 // Create the file
239 SaveFolder(folder);
240
241 // Add the folder to the collection
242 lock (collection) collection.Folders[folder.ID] = folder;
243
244 // Add the folder to its parent folder
245 InventoryFolderWithChildren parent;
246 if (collection.Folders.TryGetValue(folder.ParentID, out parent))
247 lock (parent.Children) parent.Children.Add(folder.ID, folder);
248
249 ret = BackendResponse.Success;
250 }
251 catch (Exception ex)
252 {
253 m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message);
254 ret = BackendResponse.Failure;
255 }
256 }
257 else
258 {
259 ret = BackendResponse.NotFound;
260 }
261
262 server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now);
263 return ret;
264 }
265
266 public BackendResponse TryCreateInventory(Uri owner, InventoryFolderWithChildren rootFolder)
267 {
268 BackendResponse ret;
269
270 lock (inventories)
271 {
272 if (!inventories.ContainsKey(owner))
273 {
274 InventoryCollection collection = new InventoryCollection();
275 collection.UserID = rootFolder.Owner;
276 collection.Folders = new Dictionary<UUID, InventoryFolderWithChildren>();
277 collection.Folders.Add(rootFolder.ID, rootFolder);
278 collection.Items = new Dictionary<UUID, InventoryItemBase>();
279
280 inventories.Add(owner, collection);
281
282 ret = BackendResponse.Success;
283 }
284 else
285 {
286 ret = BackendResponse.Failure;
287 }
288 }
289
290 if (ret == BackendResponse.Success)
291 {
292 string path = Path.Combine(DEFAULT_INVENTORY_DIR, rootFolder.Owner.ToString());
293 try
294 {
295 // Create the directory for this agent
296 Directory.CreateDirectory(path);
297
298 // Create an index.txt containing the UUID and URI for this agent
299 string[] index = new string[] { rootFolder.Owner.ToString(), owner.ToString() };
300 File.WriteAllLines(Path.Combine(path, "index.txt"), index);
301
302 // Create the root folder file
303 SaveFolder(rootFolder);
304 }
305 catch (Exception ex)
306 {
307 m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message);
308 ret = BackendResponse.Failure;
309 }
310 }
311
312 server.MetricsProvider.LogInventoryCreateInventory(EXTENSION_NAME, ret, DateTime.Now);
313 return ret;
314 }
315
316 public BackendResponse TryDeleteItem(Uri owner, UUID itemID)
317 {
318 BackendResponse ret;
319
320 InventoryCollection collection;
321 InventoryItemBase item;
322 if (inventories.TryGetValue(owner, out collection) && collection.Items.TryGetValue(itemID, out item))
323 {
324 // Remove the item from its parent folder
325 InventoryFolderWithChildren parent;
326 if (collection.Folders.TryGetValue(item.Folder, out parent))
327 lock (parent.Children) parent.Children.Remove(itemID);
328
329 // Remove the item from the collection
330 lock (collection) collection.Items.Remove(itemID);
331
332 // Remove from the active gestures list if applicable
333 if (item.InvType == (int)InventoryType.Gesture)
334 {
335 lock (activeGestures)
336 {
337 for (int i = 0; i < activeGestures[owner].Count; i++)
338 {
339 if (activeGestures[owner][i].ID == itemID)
340 {
341 activeGestures[owner].RemoveAt(i);
342 break;
343 }
344 }
345 }
346 }
347
348 // Delete the file. We don't know exactly what the file name is,
349 // so search for it
350 string path = PathFromURI(owner);
351 string[] matches = Directory.GetFiles(path, String.Format("*{0}.item", itemID), SearchOption.TopDirectoryOnly);
352 foreach (string match in matches)
353 {
354 try { File.Delete(match); }
355 catch (Exception ex) { m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed to delete file {0}: {1}", match, ex.Message); }
356 }
357
358 ret = BackendResponse.Success;
359 }
360 else
361 {
362 ret = BackendResponse.NotFound;
363 }
364
365 server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now);
366 return ret;
367 }
368
369 public BackendResponse TryDeleteFolder(Uri owner, UUID folderID)
370 {
371 BackendResponse ret;
372
373 InventoryCollection collection;
374 InventoryFolderWithChildren folder;
375 if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder))
376 {
377 // Remove the folder from its parent folder
378 InventoryFolderWithChildren parent;
379 if (collection.Folders.TryGetValue(folder.ParentID, out parent))
380 lock (parent.Children) parent.Children.Remove(folderID);
381
382 // Remove the folder from the collection
383 lock (collection) collection.Items.Remove(folderID);
384
385 // Delete the folder file. We don't know exactly what the file name is,
386 // so search for it
387 string path = PathFromURI(owner);
388 string[] matches = Directory.GetFiles(path, String.Format("*{0}.folder", folderID), SearchOption.TopDirectoryOnly);
389 foreach (string match in matches)
390 {
391 try { File.Delete(match); }
392 catch (Exception ex) { m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed to delete folder file {0}: {1}", match, ex.Message); }
393 }
394
395 ret = BackendResponse.Success;
396 }
397 else
398 {
399 ret = BackendResponse.NotFound;
400 }
401
402 server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now);
403 return ret;
404 }
405
406 public BackendResponse TryPurgeFolder(Uri owner, UUID folderID)
407 {
408 BackendResponse ret;
409
410 InventoryCollection collection;
411 InventoryFolderWithChildren folder;
412 if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder))
413 {
414 // Delete all of the folder children
415 foreach (InventoryNodeBase obj in new List<InventoryNodeBase>(folder.Children.Values))
416 {
417 if (obj is InventoryItemBase)
418 {
419 TryDeleteItem(owner, (obj as InventoryItemBase).ID);
420 }
421 else
422 {
423 InventoryFolderWithChildren childFolder = obj as InventoryFolderWithChildren;
424 TryPurgeFolder(owner, childFolder.ID);
425 TryDeleteFolder(owner, childFolder.ID);
426 }
427 }
428
429 ret = BackendResponse.Success;
430 }
431 else
432 {
433 ret = BackendResponse.NotFound;
434 }
435
436 server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now);
437 return ret;
438 }
439
440 #endregion Required Interfaces
441
442 void SaveItem(InventoryItemBase item)
443 {
444 string filename = String.Format("{0}-{1}.item", SanitizeFilename(item.Name), item.ID);
445
446 string path = Path.Combine(DEFAULT_INVENTORY_DIR, item.Owner.ToString());
447 path = Path.Combine(path, filename);
448
449 using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
450 {
451 itemSerializer.Serialize(stream, item);
452 stream.Flush();
453 }
454 }
455
456 void SaveFolder(InventoryFolderWithChildren folder)
457 {
458 string filename = String.Format("{0}-{1}.folder", SanitizeFilename(folder.Name), folder.ID);
459
460 string path = Path.Combine(DEFAULT_INVENTORY_DIR, folder.Owner.ToString());
461 path = Path.Combine(path, filename);
462
463 using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
464 {
465 folderSerializer.Serialize(stream, folder);
466 stream.Flush();
467 }
468 }
469
470 string SanitizeFilename(string filename)
471 {
472 string output = filename;
473
474 if (output.Length > 64)
475 output = output.Substring(0, 64);
476
477 foreach (char i in Path.GetInvalidFileNameChars())
478 output = output.Replace(i, '_');
479
480 return output;
481 }
482
483 static string PathFromURI(Uri uri)
484 {
485 byte[] hash = OpenMetaverse.Utils.SHA1(Encoding.UTF8.GetBytes(uri.ToString()));
486 StringBuilder digest = new StringBuilder(40);
487
488 // Convert the hash to a hex string
489 foreach (byte b in hash)
490 digest.AppendFormat(OpenMetaverse.Utils.EnUsCulture, "{0:x2}", b);
491
492 return Path.Combine(DEFAULT_INVENTORY_DIR, digest.ToString());
493 }
494
495 void LoadFiles(string folder)
496 {
497 // Try to create the directory if it doesn't already exist
498 if (!Directory.Exists(folder))
499 {
500 try { Directory.CreateDirectory(folder); }
501 catch (Exception ex)
502 {
503 m_log.Warn("[SIMPLEINVENTORYSTORAGE]: " + ex.Message);
504 return;
505 }
506 }
507
508 try
509 {
510 string[] agentFolders = Directory.GetDirectories(DEFAULT_INVENTORY_DIR);
511
512 for (int i = 0; i < agentFolders.Length; i++)
513 {
514 string foldername = agentFolders[i];
515 string indexPath = Path.Combine(foldername, "index.txt");
516 UUID ownerID = UUID.Zero;
517 Uri owner = null;
518
519 try
520 {
521 string[] index = File.ReadAllLines(indexPath);
522 ownerID = UUID.Parse(index[0]);
523 owner = new Uri(index[1]);
524 }
525 catch (Exception ex)
526 {
527 m_log.WarnFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading the index file {0}: {1}", indexPath, ex.Message);
528 }
529
530 if (ownerID != UUID.Zero && owner != null)
531 {
532 // Initialize the active gestures list for this agent
533 activeGestures.Add(owner, new List<InventoryItemBase>());
534
535 InventoryCollection collection = new InventoryCollection();
536 collection.UserID = ownerID;
537
538 // Load all of the folders for this agent
539 string[] folders = Directory.GetFiles(foldername, "*.folder", SearchOption.TopDirectoryOnly);
540 collection.Folders = new Dictionary<UUID,InventoryFolderWithChildren>(folders.Length);
541
542 for (int j = 0; j < folders.Length; j++)
543 {
544 InventoryFolderWithChildren invFolder = (InventoryFolderWithChildren)folderSerializer.Deserialize(
545 new FileStream(folders[j], FileMode.Open, FileAccess.Read));
546 collection.Folders[invFolder.ID] = invFolder;
547 }
548
549 // Iterate over the folders collection, adding children to their parents
550 foreach (InventoryFolderWithChildren invFolder in collection.Folders.Values)
551 {
552 InventoryFolderWithChildren parent;
553 if (collection.Folders.TryGetValue(invFolder.ParentID, out parent))
554 parent.Children[invFolder.ID] = invFolder;
555 }
556
557 // Load all of the items for this agent
558 string[] files = Directory.GetFiles(foldername, "*.item", SearchOption.TopDirectoryOnly);
559 collection.Items = new Dictionary<UUID, InventoryItemBase>(files.Length);
560
561 for (int j = 0; j < files.Length; j++)
562 {
563 InventoryItemBase invItem = (InventoryItemBase)itemSerializer.Deserialize(
564 new FileStream(files[j], FileMode.Open, FileAccess.Read));
565 collection.Items[invItem.ID] = invItem;
566
567 // Add items to their parent folders
568 InventoryFolderWithChildren parent;
569 if (collection.Folders.TryGetValue(invItem.Folder, out parent))
570 parent.Children[invItem.ID] = invItem;
571
572 // Add active gestures to our list
573 if (invItem.InvType == (int)InventoryType.Gesture && invItem.Flags != 0)
574 activeGestures[owner].Add(invItem);
575 }
576
577 inventories.Add(owner, collection);
578 }
579 }
580 }
581 catch (Exception ex)
582 {
583 m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading inventory from {0}: {1}", folder, ex.Message);
584 }
585 }
586
587 #region IPlugin implementation
588
589 public void Initialise(AssetInventoryServer server)
590 {
591 this.server = server;
592
593 LoadFiles(DEFAULT_INVENTORY_DIR);
594
595 m_log.InfoFormat("[SIMPLEINVENTORYSTORAGE]: Initialized the inventory index with data for {0} avatars",
596 inventories.Count);
597 }
598
599 /// <summary>
600 /// <para>Initialises asset interface</para>
601 /// </summary>
602 public void Initialise()
603 {
604 m_log.InfoFormat("[SIMPLEINVENTORYSTORAGE]: {0} cannot be default-initialized!", Name);
605 throw new PluginNotInitialisedException(Name);
606 }
607
608 public void Dispose()
609 {
610 }
611
612 public string Version
613 {
614 // TODO: this should be something meaningful and not hardcoded?
615 get { return "0.1"; }
616 }
617
618 public string Name
619 {
620 get { return "SimpleInventoryStorage"; }
621 }
622
623 #endregion IPlugin implementation
624 }
625}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs
deleted file mode 100644
index 0d5c53a..0000000
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs
+++ /dev/null
@@ -1,71 +0,0 @@
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.IO;
30using OpenMetaverse;
31
32namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
33{
34 public static class SimpleUtils
35 {
36 public static string ParseNameFromFilename(string filename)
37 {
38 filename = Path.GetFileName(filename);
39
40 int dot = filename.LastIndexOf('.');
41 int firstDash = filename.IndexOf('-');
42
43 if (dot - 37 > 0 && firstDash > 0)
44 return filename.Substring(0, firstDash);
45 else
46 return String.Empty;
47 }
48
49 public static UUID ParseUUIDFromFilename(string filename)
50 {
51 int dot = filename.LastIndexOf('.');
52
53 if (dot > 35)
54 {
55 // Grab the last 36 characters of the filename
56 string uuidString = filename.Substring(dot - 36, 36);
57 UUID uuid;
58 UUID.TryParse(uuidString, out uuid);
59 return uuid;
60 }
61 else
62 {
63 UUID uuid;
64 if (UUID.TryParse(Path.GetFileName(filename), out uuid))
65 return uuid;
66 else
67 return UUID.Zero;
68 }
69 }
70 }
71}