diff options
author | Mike Mazur | 2009-03-05 08:30:08 +0000 |
---|---|---|
committer | Mike Mazur | 2009-03-05 08:30:08 +0000 |
commit | 56158443b39193f968d1c3f18e8c71b26adb8e38 (patch) | |
tree | b59a40d3a242b9a1ffd538c798642fe5d857e552 /OpenSim | |
parent | Implementing more inventory storage methods. (diff) | |
download | opensim-SC_OLD-56158443b39193f968d1c3f18e8c71b26adb8e38.zip opensim-SC_OLD-56158443b39193f968d1c3f18e8c71b26adb8e38.tar.gz opensim-SC_OLD-56158443b39193f968d1c3f18e8c71b26adb8e38.tar.bz2 opensim-SC_OLD-56158443b39193f968d1c3f18e8c71b26adb8e38.tar.xz |
Implemented all Inventory frontend handlers.
This doesn't mean they all work as expected, though. More changes to
come as testing unveils bugs.
Diffstat (limited to 'OpenSim')
3 files changed, 719 insertions, 512 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs b/OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs index 5fa4274..4f42a20 100644 --- a/OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs +++ b/OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs | |||
@@ -99,6 +99,33 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
99 | 99 | ||
100 | public class InventoryFolderWithChildren : InventoryFolderBase | 100 | public class InventoryFolderWithChildren : InventoryFolderBase |
101 | { | 101 | { |
102 | public InventoryFolderWithChildren() | ||
103 | { | ||
104 | } | ||
105 | |||
106 | public InventoryFolderWithChildren(InventoryFolderBase folder) | ||
107 | { | ||
108 | // from InventoryNodeBase | ||
109 | Name = folder.Name; | ||
110 | ID = folder.ID; | ||
111 | Owner = folder.Owner; | ||
112 | |||
113 | // from InventoryFolderBase | ||
114 | ParentID = folder.ParentID; | ||
115 | Type = folder.Type; | ||
116 | Version = folder.Version; | ||
117 | } | ||
118 | |||
119 | public InventoryFolderWithChildren(string name, UUID ownerID, UUID parentID, short assetType) | ||
120 | { | ||
121 | ID = UUID.Random(); | ||
122 | Name = name; | ||
123 | Owner = ownerID; | ||
124 | ParentID = parentID; | ||
125 | Type = assetType; | ||
126 | Version = 1; | ||
127 | } | ||
128 | |||
102 | [NonSerialized] | 129 | [NonSerialized] |
103 | public Dictionary<UUID, InventoryNodeBase> Children = new Dictionary<UUID, InventoryNodeBase>(); | 130 | public Dictionary<UUID, InventoryNodeBase> Children = new Dictionary<UUID, InventoryNodeBase>(); |
104 | } | 131 | } |
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs index 2ed6d59..fabc5f6 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs | |||
@@ -26,12 +26,14 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Net; | ||
29 | using System.Reflection; | 30 | using System.Reflection; |
30 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
31 | using System.IO; | 32 | using System.IO; |
32 | using System.Xml; | 33 | using System.Xml; |
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Framework.Servers; | ||
35 | using log4net; | 37 | using log4net; |
36 | 38 | ||
37 | namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | 39 | namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim |
@@ -39,10 +41,8 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
39 | public class OpenSimInventoryFrontendPlugin : IAssetInventoryServerPlugin | 41 | public class OpenSimInventoryFrontendPlugin : IAssetInventoryServerPlugin |
40 | { | 42 | { |
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | //private AssetInventoryServer m_server; | 44 | private AssetInventoryServer m_server; |
43 | //private Utils.InventoryItemSerializer itemSerializer = new Utils.InventoryItemSerializer(); | 45 | private Utils.InventoryCollectionSerializer collectionSerializer = new Utils.InventoryCollectionSerializer(); |
44 | //private Utils.InventoryFolderSerializer folderSerializer = new Utils.InventoryFolderSerializer(); | ||
45 | //private Utils.InventoryCollectionSerializer collectionSerializer = new Utils.InventoryCollectionSerializer(); | ||
46 | 46 | ||
47 | public OpenSimInventoryFrontendPlugin() | 47 | public OpenSimInventoryFrontendPlugin() |
48 | { | 48 | { |
@@ -52,18 +52,18 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
52 | 52 | ||
53 | public void Initialise(AssetInventoryServer server) | 53 | public void Initialise(AssetInventoryServer server) |
54 | { | 54 | { |
55 | //m_server = server; | 55 | m_server = server; |
56 | 56 | ||
57 | //m_server.HttpServer.AddHandler("post", null, @"^/GetInventory/", GetInventoryHandler); | 57 | m_server.HttpServer.AddStreamHandler(new GetInventoryHandler(server, collectionSerializer)); |
58 | //m_server.HttpServer.AddHandler("post", null, @"^/CreateInventory/", CreateInventoryHandler); | 58 | m_server.HttpServer.AddStreamHandler(new CreateInventoryHandler(server)); |
59 | //m_server.HttpServer.AddHandler("post", null, @"^/NewFolder/", NewFolderHandler); | 59 | m_server.HttpServer.AddStreamHandler(new NewFolderHandler(server)); |
60 | //m_server.HttpServer.AddHandler("post", null, @"^/UpdateFolder/", UpdateFolderHandler); | 60 | m_server.HttpServer.AddStreamHandler(new UpdateFolderHandler(server)); |
61 | //m_server.HttpServer.AddHandler("post", null, @"^/MoveFolder/", MoveFolderHandler); | 61 | m_server.HttpServer.AddStreamHandler(new MoveFolderHandler(server)); |
62 | //m_server.HttpServer.AddHandler("post", null, @"^/PurgeFolder/", PurgeFolderHandler); | 62 | m_server.HttpServer.AddStreamHandler(new PurgeFolderHandler(server)); |
63 | //m_server.HttpServer.AddHandler("post", null, @"^/NewItem/", NewItemHandler); | 63 | m_server.HttpServer.AddStreamHandler(new NewItemHandler(server)); |
64 | //m_server.HttpServer.AddHandler("post", null, @"^/DeleteItem/", DeleteItemHandler); | 64 | m_server.HttpServer.AddStreamHandler(new DeleteItemHandler(server)); |
65 | //m_server.HttpServer.AddHandler("post", null, @"^/RootFolders/", RootFoldersHandler); | 65 | m_server.HttpServer.AddStreamHandler(new RootFoldersHandler(server)); |
66 | //m_server.HttpServer.AddHandler("post", null, @"^/ActiveGestures/", ActiveGesturesHandler); | 66 | m_server.HttpServer.AddStreamHandler(new ActiveGesturesHandler(server)); |
67 | 67 | ||
68 | m_log.Info("[OPENSIMINVENTORYFRONTEND]: OpenSim Inventory Frontend loaded."); | 68 | m_log.Info("[OPENSIMINVENTORYFRONTEND]: OpenSim Inventory Frontend loaded."); |
69 | } | 69 | } |
@@ -94,253 +94,391 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
94 | 94 | ||
95 | #endregion IPlugin implementation | 95 | #endregion IPlugin implementation |
96 | 96 | ||
97 | //bool GetInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 97 | public class GetInventoryHandler : BaseStreamHandler |
98 | //{ | 98 | { |
99 | // UUID sessionID, agentID; | 99 | AssetInventoryServer m_server; |
100 | // UUID ownerID = DeserializeUUID(request.Body, out agentID, out sessionID); | 100 | Utils.InventoryCollectionSerializer m_collectionSerializer; |
101 | 101 | ||
102 | // if (ownerID != UUID.Zero) | 102 | //public GetInventoryHandler(AssetInventoryServer server, Utils.InventoryCollectionSerializer collectionSerializer) : base("POST", @"^/GetInventory/") |
103 | // { | 103 | public GetInventoryHandler(AssetInventoryServer server, Utils.InventoryCollectionSerializer collectionSerializer) : base("POST", "/GetInventory") |
104 | // m_log.Warn("[OPENSIMINVENTORYFRONTEND]: GetInventory is not scalable on some inventory backends, avoid calling it wherever possible"); | 104 | { |
105 | 105 | m_server = server; | |
106 | // Uri owner = Utils.GetOpenSimUri(ownerID); | 106 | m_collectionSerializer = collectionSerializer; |
107 | // InventoryCollection inventory; | 107 | } |
108 | // BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory); | 108 | |
109 | 109 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | |
110 | // if (storageResponse == BackendResponse.Success) | 110 | { |
111 | // { | 111 | byte[] buffer = new byte[] {}; |
112 | // collectionSerializer.Serialize(response.Body, inventory); | 112 | UUID sessionID, agentID; |
113 | // response.Body.Flush(); | 113 | UUID ownerID = DeserializeUUID(httpRequest.InputStream, out agentID, out sessionID); |
114 | // } | 114 | |
115 | // else if (storageResponse == BackendResponse.NotFound) | 115 | if (ownerID != UUID.Zero) |
116 | // { | 116 | { |
117 | // // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe | 117 | m_log.Warn("[OPENSIMINVENTORYFRONTEND]: GetInventory is not scalable on some inventory backends, avoid calling it wherever possible"); |
118 | // inventory = new InventoryCollection(); | 118 | |
119 | // inventory.UserID = ownerID; | 119 | Uri owner = Utils.GetOpenSimUri(ownerID); |
120 | // inventory.Folders = new Dictionary<UUID, InventoryFolder>(); | 120 | InventoryCollection inventory; |
121 | // inventory.Items = new Dictionary<UUID, InventoryItem>(); | 121 | BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory); |
122 | // collectionSerializer.Serialize(response.Body, inventory); | 122 | |
123 | // response.Body.Flush(); | 123 | if (storageResponse == BackendResponse.Success) |
124 | // } | 124 | { |
125 | // else | 125 | //collectionSerializer.Serialize(httpResponse.Body, inventory); |
126 | // { | 126 | //httpResponse.Body.Flush(); |
127 | // response.Status = HttpStatusCode.InternalServerError; | 127 | MemoryStream ms = new MemoryStream(); |
128 | // } | 128 | m_collectionSerializer.Serialize(ms, inventory); |
129 | // } | 129 | ms.Seek(0, SeekOrigin.Begin); |
130 | // else | 130 | buffer = ms.GetBuffer(); |
131 | // { | 131 | Array.Resize<byte>(ref buffer, (int) ms.Length); |
132 | // response.Status = HttpStatusCode.BadRequest; | 132 | httpResponse.StatusCode = (int) HttpStatusCode.OK; |
133 | // } | 133 | } |
134 | 134 | else if (storageResponse == BackendResponse.NotFound) | |
135 | // return true; | 135 | { |
136 | //} | 136 | // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe |
137 | inventory = new InventoryCollection(); | ||
138 | inventory.UserID = ownerID; | ||
139 | inventory.Folders = new Dictionary<UUID, InventoryFolderWithChildren>(); | ||
140 | inventory.Items = new Dictionary<UUID, InventoryItemBase>(); | ||
141 | //collectionSerializer.Serialize(httpResponse.Body, inventory); | ||
142 | //httpResponse.Body.Flush(); | ||
143 | MemoryStream ms = new MemoryStream(); | ||
144 | m_collectionSerializer.Serialize(ms, inventory); | ||
145 | ms.Seek(0, SeekOrigin.Begin); | ||
146 | buffer = ms.GetBuffer(); | ||
147 | Array.Resize<byte>(ref buffer, (int) ms.Length); | ||
148 | httpResponse.StatusCode = (int) HttpStatusCode.OK; | ||
149 | } | ||
150 | else | ||
151 | { | ||
152 | httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; | ||
153 | } | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; | ||
158 | } | ||
159 | |||
160 | return buffer; | ||
161 | } | ||
162 | } | ||
137 | 163 | ||
138 | //bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 164 | public class CreateInventoryHandler : BaseStreamHandler |
139 | //{ | 165 | { |
140 | // UUID ownerID = DeserializeUUID(request.Body); | 166 | AssetInventoryServer m_server; |
141 | 167 | ||
142 | // if (ownerID != UUID.Zero) | 168 | //public CreateInventoryHandler(AssetInventoryServer server) : base("POST", @"^/CreateInventory/") |
143 | // { | 169 | public CreateInventoryHandler(AssetInventoryServer server) : base("POST", "/CreateInventory") |
144 | // Uri owner = Utils.GetOpenSimUri(ownerID); | 170 | { |
145 | // m_log.DebugFormat("[OPENSIMINVENTORYFRONTEND]: Created URI {0} for inventory creation", owner); | 171 | m_server = server; |
146 | 172 | } | |
147 | // InventoryFolder rootFolder = new InventoryFolder("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder); | 173 | |
148 | // BackendResponse storageResponse = m_server.InventoryProvider.TryCreateInventory(owner, rootFolder); | 174 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
149 | // if (storageResponse == BackendResponse.Success) | 175 | { |
150 | // { | 176 | UUID ownerID = DeserializeUUID(httpRequest.InputStream); |
151 | // CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation); | 177 | |
152 | // CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart); | 178 | if (ownerID != UUID.Zero) |
153 | // CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard); | 179 | { |
154 | // CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing); | 180 | Uri owner = Utils.GetOpenSimUri(ownerID); |
155 | // CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture); | 181 | m_log.DebugFormat("[OPENSIMINVENTORYFRONTEND]: Created URI {0} for inventory creation", owner); |
156 | // CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark); | 182 | |
157 | // CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder); | 183 | InventoryFolderWithChildren rootFolder = new InventoryFolderWithChildren("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder); |
158 | // CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard); | 184 | BackendResponse storageResponse = m_server.InventoryProvider.TryCreateInventory(owner, rootFolder); |
159 | // CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object); | 185 | if (storageResponse == BackendResponse.Success) |
160 | // CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder); | 186 | { |
161 | // CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText); | 187 | // TODO: The CreateFolder calls need to be executed in SimpleStorage. |
162 | // CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound); | 188 | //CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation); |
163 | // CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture); | 189 | //CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart); |
164 | // CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder); | 190 | //CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard); |
165 | 191 | //CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing); | |
166 | // SerializeBool(response.Body, true); | 192 | //CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture); |
167 | // return true; | 193 | //CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark); |
168 | // } | 194 | //CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder); |
169 | // } | 195 | //CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard); |
170 | 196 | //CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object); | |
171 | // SerializeBool(response.Body, false); | 197 | //CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder); |
172 | // return true; | 198 | //CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText); |
173 | //} | 199 | //CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound); |
200 | //CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture); | ||
201 | //CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder); | ||
202 | |||
203 | return SerializeBool(true); | ||
204 | } | ||
205 | } | ||
206 | |||
207 | return SerializeBool(false); | ||
208 | } | ||
209 | } | ||
174 | 210 | ||
175 | //bool NewFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 211 | public class NewFolderHandler : BaseStreamHandler |
176 | //{ | 212 | { |
177 | // UUID agentID, sessionID; | 213 | AssetInventoryServer m_server; |
178 | // InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID); | 214 | |
179 | 215 | //public NewFolderHandler(AssetInventoryServer server) : base("POST", @"^/NewFolder/") | |
180 | // if (folder != null) | 216 | public NewFolderHandler(AssetInventoryServer server) : base("POST", "/NewFolder") |
181 | // { | 217 | { |
182 | // Uri owner = Utils.GetOpenSimUri(folder.Owner); | 218 | m_server = server; |
183 | 219 | } | |
184 | // // Some calls that are moving or updating a folder instead of creating a new one | 220 | |
185 | // // will pass in an InventoryFolder without the name set. If this is the case we | 221 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
186 | // // need to look up the name first | 222 | { |
187 | // if (String.IsNullOrEmpty(folder.Name)) | 223 | UUID agentID, sessionID; |
188 | // { | 224 | InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID); |
189 | // InventoryFolder oldFolder; | 225 | |
190 | // if (m_server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success) | 226 | if (folder != null) |
191 | // folder.Name = oldFolder.Name; | 227 | { |
192 | // } | 228 | Uri owner = Utils.GetOpenSimUri(folder.Owner); |
193 | 229 | ||
194 | // BackendResponse storageResponse = m_server.InventoryProvider.TryCreateFolder(owner, folder); | 230 | // Some calls that are moving or updating a folder instead of creating a new one |
195 | 231 | // will pass in an InventoryFolder without the name set. If this is the case we | |
196 | // if (storageResponse == BackendResponse.Success) | 232 | // need to look up the name first |
197 | // { | 233 | if (String.IsNullOrEmpty(folder.Name)) |
198 | // SerializeBool(response.Body, true); | 234 | { |
199 | // return true; | 235 | InventoryFolderWithChildren oldFolder; |
200 | // } | 236 | if (m_server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success) |
201 | // } | 237 | folder.Name = oldFolder.Name; |
202 | 238 | } | |
203 | // SerializeBool(response.Body, false); | 239 | |
204 | // return true; | 240 | BackendResponse storageResponse = m_server.InventoryProvider.TryCreateFolder(owner, folder); |
205 | //} | 241 | |
242 | if (storageResponse == BackendResponse.Success) | ||
243 | { | ||
244 | return SerializeBool(true); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | return SerializeBool(false); | ||
249 | } | ||
250 | } | ||
206 | 251 | ||
207 | //bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 252 | public class UpdateFolderHandler : BaseStreamHandler |
208 | //{ | 253 | { |
209 | // return NewFolderHandler(client, request, response); | 254 | AssetInventoryServer m_server; |
210 | //} | 255 | |
256 | //public UpdateFolderHandler(AssetInventoryServer server) : base("POST", @"^/UpdateFolder/") | ||
257 | public UpdateFolderHandler(AssetInventoryServer server) : base("POST", "/UpdateFolder") | ||
258 | { | ||
259 | m_server = server; | ||
260 | } | ||
261 | |||
262 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
263 | { | ||
264 | return new NewFolderHandler(m_server).Handle(path, request, httpRequest, httpResponse); | ||
265 | } | ||
266 | } | ||
211 | 267 | ||
212 | //bool MoveFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 268 | public class MoveFolderHandler : BaseStreamHandler |
213 | //{ | 269 | { |
214 | // return NewFolderHandler(client, request, response); | 270 | AssetInventoryServer m_server; |
215 | //} | 271 | |
272 | //public MoveFolderHandler(AssetInventoryServer server) : base("POST", @"^/MoveFolder/") | ||
273 | public MoveFolderHandler(AssetInventoryServer server) : base("POST", "/MoveFolder") | ||
274 | { | ||
275 | m_server = server; | ||
276 | } | ||
277 | |||
278 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
279 | { | ||
280 | return new NewFolderHandler(m_server).Handle(path, request, httpRequest, httpResponse); | ||
281 | } | ||
282 | } | ||
216 | 283 | ||
217 | //bool PurgeFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 284 | public class PurgeFolderHandler : BaseStreamHandler |
218 | //{ | 285 | { |
219 | // UUID agentID, sessionID; | 286 | AssetInventoryServer m_server; |
220 | // InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID); | 287 | |
221 | 288 | //public PurgeFolderHandler(AssetInventoryServer server) : base("POST", @"^/PurgeFolder/") | |
222 | // if (folder != null) | 289 | public PurgeFolderHandler(AssetInventoryServer server) : base("POST", "/PurgeFolder") |
223 | // { | 290 | { |
224 | // Uri owner = Utils.GetOpenSimUri(folder.Owner); | 291 | m_server = server; |
225 | // BackendResponse storageResponse = m_server.InventoryProvider.TryPurgeFolder(owner, folder.ID); | 292 | } |
226 | 293 | ||
227 | // if (storageResponse == BackendResponse.Success) | 294 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
228 | // { | 295 | { |
229 | // SerializeBool(response.Body, true); | 296 | UUID agentID, sessionID; |
230 | // return true; | 297 | InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID); |
231 | // } | 298 | |
232 | // } | 299 | if (folder != null) |
233 | 300 | { | |
234 | // SerializeBool(response.Body, false); | 301 | Uri owner = Utils.GetOpenSimUri(folder.Owner); |
235 | // return true; | 302 | BackendResponse storageResponse = m_server.InventoryProvider.TryPurgeFolder(owner, folder.ID); |
236 | //} | 303 | |
304 | if (storageResponse == BackendResponse.Success) | ||
305 | { | ||
306 | return SerializeBool(true); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | return SerializeBool(false); | ||
311 | } | ||
312 | } | ||
237 | 313 | ||
238 | //bool NewItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 314 | public class NewItemHandler : BaseStreamHandler |
239 | //{ | 315 | { |
240 | // UUID agentID, sessionID; | 316 | AssetInventoryServer m_server; |
241 | // InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID); | 317 | |
242 | 318 | //public NewItemHandler(AssetInventoryServer server) : base("POST", @"^/NewItem/") | |
243 | // if (item != null) | 319 | public NewItemHandler(AssetInventoryServer server) : base("POST", "/NewItem") |
244 | // { | 320 | { |
245 | // Uri owner = Utils.GetOpenSimUri(agentID); | 321 | m_server = server; |
246 | // BackendResponse storageResponse = m_server.InventoryProvider.TryCreateItem(owner, item); | 322 | } |
247 | 323 | ||
248 | // if (storageResponse == BackendResponse.Success) | 324 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
249 | // { | 325 | { |
250 | // SerializeBool(response.Body, true); | 326 | UUID agentID, sessionID; |
251 | // return true; | 327 | InventoryItemBase item = DeserializeItem(httpRequest.InputStream, out agentID, out sessionID); |
252 | // } | 328 | |
253 | // } | 329 | if (item != null) |
254 | 330 | { | |
255 | // SerializeBool(response.Body, false); | 331 | Uri owner = Utils.GetOpenSimUri(agentID); |
256 | // return true; | 332 | BackendResponse storageResponse = m_server.InventoryProvider.TryCreateItem(owner, item); |
257 | //} | 333 | |
334 | if (storageResponse == BackendResponse.Success) | ||
335 | { | ||
336 | return SerializeBool(true); | ||
337 | } | ||
338 | } | ||
339 | |||
340 | return SerializeBool(false); | ||
341 | } | ||
342 | } | ||
258 | 343 | ||
259 | //bool DeleteItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 344 | public class DeleteItemHandler : BaseStreamHandler |
260 | //{ | 345 | { |
261 | // UUID agentID, sessionID; | 346 | AssetInventoryServer m_server; |
262 | // InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID); | 347 | |
263 | 348 | //public DeleteItemHandler(AssetInventoryServer server) : base("POST", @"^/DeleteItem/") | |
264 | // if (item != null) | 349 | public DeleteItemHandler(AssetInventoryServer server) : base("POST", "/DeleteItem") |
265 | // { | 350 | { |
266 | // Uri owner = Utils.GetOpenSimUri(item.Owner); | 351 | m_server = server; |
267 | // BackendResponse storageResponse = m_server.InventoryProvider.TryDeleteItem(owner, item.ID); | 352 | } |
268 | 353 | ||
269 | // if (storageResponse == BackendResponse.Success) | 354 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
270 | // { | 355 | { |
271 | // SerializeBool(response.Body, true); | 356 | UUID agentID, sessionID; |
272 | // return true; | 357 | InventoryItemBase item = DeserializeItem(httpRequest.InputStream, out agentID, out sessionID); |
273 | // } | 358 | |
274 | // } | 359 | if (item != null) |
275 | 360 | { | |
276 | // SerializeBool(response.Body, false); | 361 | Uri owner = Utils.GetOpenSimUri(item.Owner); |
277 | // return true; | 362 | BackendResponse storageResponse = m_server.InventoryProvider.TryDeleteItem(owner, item.ID); |
278 | //} | 363 | |
364 | if (storageResponse == BackendResponse.Success) | ||
365 | { | ||
366 | return SerializeBool(true); | ||
367 | } | ||
368 | } | ||
369 | |||
370 | return SerializeBool(false); | ||
371 | } | ||
372 | } | ||
279 | 373 | ||
280 | //bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 374 | public class RootFoldersHandler : BaseStreamHandler |
281 | //{ | 375 | { |
282 | // UUID ownerID = DeserializeUUID(request.Body); | 376 | AssetInventoryServer m_server; |
283 | 377 | ||
284 | // if (ownerID != UUID.Zero) | 378 | //public RootFoldersHandler(AssetInventoryServer server) : base("POST", @"^/RootFolders/") |
285 | // { | 379 | public RootFoldersHandler(AssetInventoryServer server) : base("POST", "/RootFolders") |
286 | // Uri owner = Utils.GetOpenSimUri(ownerID); | 380 | { |
287 | // List<InventoryFolder> skeleton; | 381 | m_server = server; |
288 | // BackendResponse storageResponse = m_server.InventoryProvider.TryFetchFolderList(owner, out skeleton); | 382 | } |
289 | 383 | ||
290 | // if (storageResponse == BackendResponse.Success) | 384 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
291 | // { | 385 | { |
292 | // SerializeFolderList(response.Body, skeleton); | 386 | byte[] buffer = new byte[] {}; |
293 | // } | 387 | UUID ownerID = DeserializeUUID(httpRequest.InputStream); |
294 | // else if (storageResponse == BackendResponse.NotFound) | 388 | |
295 | // { | 389 | if (ownerID != UUID.Zero) |
296 | // // Return an empty set of inventory so the requester knows that | 390 | { |
297 | // // an inventory needs to be created for this agent | 391 | Uri owner = Utils.GetOpenSimUri(ownerID); |
298 | // SerializeFolderList(response.Body, new List<InventoryFolder>(0)); | 392 | List<InventoryFolderWithChildren> skeleton; |
299 | // } | 393 | BackendResponse storageResponse = m_server.InventoryProvider.TryFetchFolderList(owner, out skeleton); |
300 | // else | 394 | |
301 | // { | 395 | if (storageResponse == BackendResponse.Success) |
302 | // response.Status = HttpStatusCode.InternalServerError; | 396 | { |
303 | // } | 397 | MemoryStream ms = new MemoryStream(); |
304 | // } | 398 | SerializeFolderList(ms, skeleton); |
305 | // else | 399 | ms.Seek(0, SeekOrigin.Begin); |
306 | // { | 400 | buffer = ms.GetBuffer(); |
307 | // response.Status = HttpStatusCode.BadRequest; | 401 | Array.Resize<byte>(ref buffer, (int) ms.Length); |
308 | // } | 402 | httpResponse.StatusCode = (int) HttpStatusCode.OK; |
309 | 403 | } | |
310 | // return true; | 404 | else if (storageResponse == BackendResponse.NotFound) |
311 | //} | 405 | { |
406 | // Return an empty set of inventory so the requester knows that | ||
407 | // an inventory needs to be created for this agent | ||
408 | MemoryStream ms = new MemoryStream(); | ||
409 | SerializeFolderList(ms, new List<InventoryFolderWithChildren>(0)); | ||
410 | ms.Seek(0, SeekOrigin.Begin); | ||
411 | buffer = ms.GetBuffer(); | ||
412 | Array.Resize<byte>(ref buffer, (int) ms.Length); | ||
413 | httpResponse.StatusCode = (int) HttpStatusCode.OK; | ||
414 | } | ||
415 | else | ||
416 | { | ||
417 | httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; | ||
418 | } | ||
419 | } | ||
420 | else | ||
421 | { | ||
422 | httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; | ||
423 | } | ||
424 | |||
425 | return buffer; | ||
426 | } | ||
427 | } | ||
312 | 428 | ||
313 | //bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | 429 | public class ActiveGesturesHandler : BaseStreamHandler |
314 | //{ | 430 | { |
315 | // UUID ownerID = DeserializeUUID(request.Body); | 431 | AssetInventoryServer m_server; |
316 | 432 | ||
317 | // if (ownerID != UUID.Zero) | 433 | //public ActiveGesturesHandler(AssetInventoryServer server) : base("POST", @"^/ActiveGestures/") |
318 | // { | 434 | public ActiveGesturesHandler(AssetInventoryServer server) : base("POST", "/ActiveGestures") |
319 | // Uri owner = Utils.GetOpenSimUri(ownerID); | 435 | { |
320 | // List<InventoryItem> gestures; | 436 | m_server = server; |
321 | // BackendResponse storageResponse = m_server.InventoryProvider.TryFetchActiveGestures(owner, out gestures); | 437 | } |
322 | 438 | ||
323 | // if (storageResponse == BackendResponse.Success) | 439 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
324 | // { | 440 | { |
325 | // SerializeItemList(response.Body, gestures); | 441 | byte[] buffer = new byte[] {}; |
326 | // } | 442 | UUID ownerID = DeserializeUUID(httpRequest.InputStream); |
327 | // else if (storageResponse == BackendResponse.NotFound) | 443 | |
328 | // { | 444 | if (ownerID != UUID.Zero) |
329 | // // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior | 445 | { |
330 | // SerializeItemList(response.Body, new List<InventoryItem>(0)); | 446 | Uri owner = Utils.GetOpenSimUri(ownerID); |
331 | // } | 447 | List<InventoryItemBase> gestures; |
332 | // else | 448 | BackendResponse storageResponse = m_server.InventoryProvider.TryFetchActiveGestures(owner, out gestures); |
333 | // { | 449 | |
334 | // response.Status = HttpStatusCode.InternalServerError; | 450 | if (storageResponse == BackendResponse.Success) |
335 | // } | 451 | { |
336 | // } | 452 | MemoryStream ms = new MemoryStream(); |
337 | // else | 453 | SerializeItemList(ms, gestures); |
338 | // { | 454 | ms.Seek(0, SeekOrigin.Begin); |
339 | // response.Status = HttpStatusCode.BadRequest; | 455 | buffer = ms.GetBuffer(); |
340 | // } | 456 | Array.Resize<byte>(ref buffer, (int) ms.Length); |
341 | 457 | httpResponse.StatusCode = (int) HttpStatusCode.OK; | |
342 | // return true; | 458 | } |
343 | //} | 459 | else if (storageResponse == BackendResponse.NotFound) |
460 | { | ||
461 | // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior | ||
462 | MemoryStream ms = new MemoryStream(); | ||
463 | SerializeItemList(ms, new List<InventoryItemBase>(0)); | ||
464 | ms.Seek(0, SeekOrigin.Begin); | ||
465 | buffer = ms.GetBuffer(); | ||
466 | Array.Resize<byte>(ref buffer, (int) ms.Length); | ||
467 | httpResponse.StatusCode = (int) HttpStatusCode.OK; | ||
468 | } | ||
469 | else | ||
470 | { | ||
471 | httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; | ||
472 | } | ||
473 | } | ||
474 | else | ||
475 | { | ||
476 | httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; | ||
477 | } | ||
478 | |||
479 | return buffer; | ||
480 | } | ||
481 | } | ||
344 | 482 | ||
345 | //BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType) | 483 | //BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType) |
346 | //{ | 484 | //{ |
@@ -349,248 +487,303 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
349 | // return m_server.InventoryProvider.TryCreateFolder(owner, folder); | 487 | // return m_server.InventoryProvider.TryCreateFolder(owner, folder); |
350 | //} | 488 | //} |
351 | 489 | ||
352 | //UUID DeserializeUUID(Stream stream) | 490 | UUID DeserializeUUID(Stream stream) |
353 | //{ | 491 | { |
354 | // UUID id = UUID.Zero; | 492 | UUID id = UUID.Zero; |
355 | 493 | ||
356 | // try | 494 | try |
357 | // { | 495 | { |
358 | // using (XmlReader reader = XmlReader.Create(stream)) | 496 | using (XmlReader reader = XmlReader.Create(stream)) |
359 | // { | 497 | { |
360 | // reader.MoveToContent(); | 498 | reader.MoveToContent(); |
361 | // UUID.TryParse(reader.ReadElementContentAsString("guid", String.Empty), out id); | 499 | UUID.TryParse(reader.ReadElementContentAsString("guid", String.Empty), out id); |
362 | // } | 500 | } |
363 | // } | 501 | } |
364 | // catch (Exception ex) | 502 | catch (Exception ex) |
365 | // { | 503 | { |
366 | // m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting guid): " + ex.Message); | 504 | m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting guid): " + ex.Message); |
367 | // } | 505 | } |
368 | 506 | ||
369 | // return id; | 507 | return id; |
370 | //} | 508 | } |
371 | 509 | ||
372 | //UUID DeserializeUUID(Stream stream, out UUID agentID, out UUID sessionID) | 510 | private static UUID DeserializeUUID(Stream stream, out UUID agentID, out UUID sessionID) |
373 | //{ | 511 | { |
374 | // UUID id; | 512 | UUID id; |
375 | 513 | ||
376 | // try | 514 | try |
377 | // { | 515 | { |
378 | // using (XmlReader reader = XmlReader.Create(stream)) | 516 | using (XmlReader reader = XmlReader.Create(stream)) |
379 | // { | 517 | { |
380 | // reader.MoveToContent(); | 518 | reader.MoveToContent(); |
381 | // reader.ReadStartElement("RestSessionObjectOfGuid"); | 519 | reader.ReadStartElement("RestSessionObjectOfGuid"); |
382 | // UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); | 520 | UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); |
383 | // UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); | 521 | UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); |
384 | // UUID.TryParse(reader.ReadElementContentAsString("Body", String.Empty), out id); | 522 | UUID.TryParse(reader.ReadElementContentAsString("Body", String.Empty), out id); |
385 | // reader.ReadEndElement(); | 523 | reader.ReadEndElement(); |
386 | // } | 524 | } |
387 | // } | 525 | } |
388 | // catch (Exception ex) | 526 | catch (Exception ex) |
389 | // { | 527 | { |
390 | // m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse GetInventory POST data: " + ex.Message); | 528 | m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse GetInventory POST data: " + ex.Message); |
391 | // agentID = UUID.Zero; | 529 | agentID = UUID.Zero; |
392 | // sessionID = UUID.Zero; | 530 | sessionID = UUID.Zero; |
393 | // return UUID.Zero; | 531 | return UUID.Zero; |
394 | // } | 532 | } |
395 | 533 | ||
396 | // return id; | 534 | return id; |
397 | //} | 535 | } |
398 | 536 | ||
399 | //InventoryFolder DeserializeFolder(Stream stream, out UUID agentID, out UUID sessionID) | 537 | private static InventoryFolderWithChildren DeserializeFolder(Stream stream, out UUID agentID, out UUID sessionID) |
400 | //{ | 538 | { |
401 | // InventoryFolder folder = new InventoryFolder(); | 539 | InventoryFolderWithChildren folder = new InventoryFolderWithChildren(); |
402 | 540 | ||
403 | // try | 541 | try |
404 | // { | 542 | { |
405 | // using (XmlReader reader = XmlReader.Create(stream)) | 543 | using (XmlReader reader = XmlReader.Create(stream)) |
406 | // { | 544 | { |
407 | // reader.MoveToContent(); | 545 | reader.MoveToContent(); |
408 | // reader.ReadStartElement("RestSessionObjectOfInventoryFolderBase"); | 546 | reader.ReadStartElement("RestSessionObjectOfInventoryFolderBase"); |
409 | // UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); | 547 | UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); |
410 | // UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); | 548 | UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); |
411 | // reader.ReadStartElement("Body"); | 549 | reader.ReadStartElement("Body"); |
412 | // if (reader.Name == "Name") | 550 | if (reader.Name == "Name") |
413 | // folder.Name = reader.ReadElementContentAsString("Name", String.Empty); | 551 | folder.Name = reader.ReadElementContentAsString("Name", String.Empty); |
414 | // else | 552 | else |
415 | // folder.Name = String.Empty; | 553 | folder.Name = String.Empty; |
416 | // ReadUUID(reader, "Owner", out folder.Owner); | 554 | |
417 | // ReadUUID(reader, "ParentID", out folder.ParentID); | 555 | UUID dummyUUID; |
418 | // ReadUUID(reader, "ID", out folder.ID); | 556 | ReadUUID(reader, "Owner", out dummyUUID); |
419 | // Int16.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out folder.Type); | 557 | folder.Owner = dummyUUID; |
420 | // UInt16.TryParse(reader.ReadElementContentAsString("Version", String.Empty), out folder.Version); | 558 | ReadUUID(reader, "ParentID", out dummyUUID); |
421 | // reader.ReadEndElement(); | 559 | folder.ParentID = dummyUUID; |
422 | // reader.ReadEndElement(); | 560 | ReadUUID(reader, "ID", out dummyUUID); |
423 | // } | 561 | folder.ID = dummyUUID; |
424 | // } | 562 | |
425 | // catch (Exception ex) | 563 | short dummyType; |
426 | // { | 564 | Int16.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out dummyType); |
427 | // m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryFolderBase): " + ex.Message); | 565 | folder.Type = dummyType; |
428 | // agentID = UUID.Zero; | 566 | |
429 | // sessionID = UUID.Zero; | 567 | ushort dummyVersion; |
430 | // return null; | 568 | UInt16.TryParse(reader.ReadElementContentAsString("Version", String.Empty), out dummyVersion); |
431 | // } | 569 | folder.Version = dummyVersion; |
432 | 570 | ||
433 | // return folder; | 571 | reader.ReadEndElement(); |
434 | //} | 572 | reader.ReadEndElement(); |
573 | } | ||
574 | } | ||
575 | catch (Exception ex) | ||
576 | { | ||
577 | m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryFolderBase): " + ex.Message); | ||
578 | agentID = UUID.Zero; | ||
579 | sessionID = UUID.Zero; | ||
580 | return null; | ||
581 | } | ||
582 | |||
583 | return folder; | ||
584 | } | ||
435 | 585 | ||
436 | //InventoryItem DeserializeItem(Stream stream, out UUID agentID, out UUID sessionID) | 586 | private static InventoryItemBase DeserializeItem(Stream stream, out UUID agentID, out UUID sessionID) |
437 | //{ | 587 | { |
438 | // InventoryItem item = new InventoryItem(); | 588 | InventoryItemBase item = new InventoryItemBase(); |
439 | 589 | ||
440 | // try | 590 | try |
441 | // { | 591 | { |
442 | // using (XmlReader reader = XmlReader.Create(stream)) | 592 | using (XmlReader reader = XmlReader.Create(stream)) |
443 | // { | 593 | { |
444 | // reader.MoveToContent(); | 594 | reader.MoveToContent(); |
445 | // reader.ReadStartElement("RestSessionObjectOfInventoryItemBase"); | 595 | reader.ReadStartElement("RestSessionObjectOfInventoryItemBase"); |
446 | // UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); | 596 | UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); |
447 | // UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); | 597 | UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); |
448 | // reader.ReadStartElement("Body"); | 598 | reader.ReadStartElement("Body"); |
449 | // ReadUUID(reader, "ID", out item.ID); | 599 | |
450 | // Int32.TryParse(reader.ReadElementContentAsString("InvType", String.Empty), out item.InvType); | 600 | UUID dummyUUID; |
451 | // ReadUUID(reader, "Folder", out item.Folder); | 601 | ReadUUID(reader, "ID", out dummyUUID); |
452 | // ReadUUID(reader, "Owner", out item.Owner); | 602 | item.ID = dummyUUID; |
453 | // ReadUUID(reader, "Creator", out item.Creator); | 603 | |
454 | // item.Name = reader.ReadElementContentAsString("Name", String.Empty); | 604 | int dummyInt; |
455 | // item.Description = reader.ReadElementContentAsString("Description", String.Empty); | 605 | Int32.TryParse(reader.ReadElementContentAsString("InvType", String.Empty), out dummyInt); |
456 | // UInt32.TryParse(reader.ReadElementContentAsString("NextPermissions", String.Empty), out item.NextPermissions); | 606 | item.InvType = dummyInt; |
457 | // UInt32.TryParse(reader.ReadElementContentAsString("CurrentPermissions", String.Empty), out item.CurrentPermissions); | 607 | |
458 | // UInt32.TryParse(reader.ReadElementContentAsString("BasePermissions", String.Empty), out item.BasePermissions); | 608 | ReadUUID(reader, "Folder", out dummyUUID); |
459 | // UInt32.TryParse(reader.ReadElementContentAsString("EveryOnePermissions", String.Empty), out item.EveryOnePermissions); | 609 | item.Folder = dummyUUID; |
460 | // UInt32.TryParse(reader.ReadElementContentAsString("GroupPermissions", String.Empty), out item.GroupPermissions); | 610 | ReadUUID(reader, "Owner", out dummyUUID); |
461 | // Int32.TryParse(reader.ReadElementContentAsString("AssetType", String.Empty), out item.AssetType); | 611 | item.Owner = dummyUUID; |
462 | // ReadUUID(reader, "AssetID", out item.AssetID); | 612 | ReadUUID(reader, "Creator", out dummyUUID); |
463 | // ReadUUID(reader, "GroupID", out item.GroupID); | 613 | item.Creator = dummyUUID; |
464 | // Boolean.TryParse(reader.ReadElementContentAsString("GroupOwned", String.Empty), out item.GroupOwned); | 614 | |
465 | // Int32.TryParse(reader.ReadElementContentAsString("SalePrice", String.Empty), out item.SalePrice); | 615 | item.Name = reader.ReadElementContentAsString("Name", String.Empty); |
466 | // Byte.TryParse(reader.ReadElementContentAsString("SaleType", String.Empty), out item.SaleType); | 616 | item.Description = reader.ReadElementContentAsString("Description", String.Empty); |
467 | // UInt32.TryParse(reader.ReadElementContentAsString("Flags", String.Empty), out item.Flags); | 617 | |
468 | // Int32.TryParse(reader.ReadElementContentAsString("CreationDate", String.Empty), out item.CreationDate); | 618 | uint dummyUInt; |
469 | // reader.ReadEndElement(); | 619 | UInt32.TryParse(reader.ReadElementContentAsString("NextPermissions", String.Empty), out dummyUInt); |
470 | // reader.ReadEndElement(); | 620 | item.NextPermissions = dummyUInt; |
471 | // } | 621 | UInt32.TryParse(reader.ReadElementContentAsString("CurrentPermissions", String.Empty), out dummyUInt); |
472 | // } | 622 | item.CurrentPermissions = dummyUInt; |
473 | // catch (Exception ex) | 623 | UInt32.TryParse(reader.ReadElementContentAsString("BasePermissions", String.Empty), out dummyUInt); |
474 | // { | 624 | item.BasePermissions = dummyUInt; |
475 | // m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryItemBase): " + ex.Message); | 625 | UInt32.TryParse(reader.ReadElementContentAsString("EveryOnePermissions", String.Empty), out dummyUInt); |
476 | // agentID = UUID.Zero; | 626 | item.EveryOnePermissions = dummyUInt; |
477 | // sessionID = UUID.Zero; | 627 | UInt32.TryParse(reader.ReadElementContentAsString("GroupPermissions", String.Empty), out dummyUInt); |
478 | // return null; | 628 | item.GroupPermissions = dummyUInt; |
479 | // } | 629 | |
480 | 630 | Int32.TryParse(reader.ReadElementContentAsString("AssetType", String.Empty), out dummyInt); | |
481 | // return item; | 631 | item.AssetType = dummyInt; |
482 | //} | 632 | |
633 | ReadUUID(reader, "AssetID", out dummyUUID); | ||
634 | item.AssetID = dummyUUID; | ||
635 | ReadUUID(reader, "GroupID", out dummyUUID); | ||
636 | item.GroupID = dummyUUID; | ||
637 | |||
638 | bool dummyBool; | ||
639 | Boolean.TryParse(reader.ReadElementContentAsString("GroupOwned", String.Empty), out dummyBool); | ||
640 | item.GroupOwned = dummyBool; | ||
641 | |||
642 | Int32.TryParse(reader.ReadElementContentAsString("SalePrice", String.Empty), out dummyInt); | ||
643 | item.SalePrice = dummyInt; | ||
644 | |||
645 | byte dummyByte; | ||
646 | Byte.TryParse(reader.ReadElementContentAsString("SaleType", String.Empty), out dummyByte); | ||
647 | item.SaleType = dummyByte; | ||
648 | |||
649 | UInt32.TryParse(reader.ReadElementContentAsString("Flags", String.Empty), out dummyUInt); | ||
650 | item.Flags = dummyUInt; | ||
651 | |||
652 | Int32.TryParse(reader.ReadElementContentAsString("CreationDate", String.Empty), out dummyInt); | ||
653 | item.CreationDate = dummyInt; | ||
654 | |||
655 | reader.ReadEndElement(); | ||
656 | reader.ReadEndElement(); | ||
657 | } | ||
658 | } | ||
659 | catch (Exception ex) | ||
660 | { | ||
661 | m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryItemBase): " + ex.Message); | ||
662 | agentID = UUID.Zero; | ||
663 | sessionID = UUID.Zero; | ||
664 | return null; | ||
665 | } | ||
666 | |||
667 | return item; | ||
668 | } | ||
483 | 669 | ||
484 | //void SerializeBool(Stream stream, bool value) | 670 | private static byte[] SerializeBool(bool value) |
485 | //{ | 671 | { |
486 | // using (XmlWriter writer = XmlWriter.Create(stream)) | 672 | byte[] buffer; |
487 | // { | 673 | MemoryStream ms = new MemoryStream(); |
488 | // writer.WriteStartDocument(); | 674 | |
489 | // writer.WriteStartElement("boolean"); | 675 | using (XmlWriter writer = XmlWriter.Create(ms)) |
490 | // writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); | 676 | { |
491 | // writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); | 677 | writer.WriteStartDocument(); |
492 | // writer.WriteString(value.ToString().ToLower()); | 678 | writer.WriteStartElement("boolean"); |
493 | // writer.WriteEndElement(); | 679 | writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); |
494 | // writer.WriteEndDocument(); | 680 | writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); |
495 | // writer.Flush(); | 681 | writer.WriteString(value.ToString().ToLower()); |
496 | // } | 682 | writer.WriteEndElement(); |
497 | 683 | writer.WriteEndDocument(); | |
498 | // stream.Flush(); | 684 | writer.Flush(); |
499 | //} | 685 | } |
686 | |||
687 | ms.Seek(0, SeekOrigin.Begin); | ||
688 | buffer = ms.GetBuffer(); | ||
689 | Array.Resize<byte>(ref buffer, (int) ms.Length); | ||
690 | |||
691 | return buffer; | ||
692 | } | ||
500 | 693 | ||
501 | //void SerializeFolderList(Stream stream, List<InventoryFolder> folders) | 694 | private static void SerializeFolderList(Stream stream, List<InventoryFolderWithChildren> folders) |
502 | //{ | 695 | { |
503 | // using (XmlWriter writer = XmlWriter.Create(stream)) | 696 | using (XmlWriter writer = XmlWriter.Create(stream)) |
504 | // { | 697 | { |
505 | // writer.WriteStartDocument(); | 698 | writer.WriteStartDocument(); |
506 | // writer.WriteStartElement("ArrayOfInventoryFolderBase"); | 699 | writer.WriteStartElement("ArrayOfInventoryFolderBase"); |
507 | // writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); | 700 | writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); |
508 | // writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); | 701 | writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); |
509 | 702 | ||
510 | // if (folders != null) | 703 | if (folders != null) |
511 | // { | 704 | { |
512 | // foreach (InventoryFolder folder in folders) | 705 | foreach (InventoryFolderWithChildren folder in folders) |
513 | // { | 706 | { |
514 | // writer.WriteStartElement("InventoryFolderBase"); | 707 | writer.WriteStartElement("InventoryFolderBase"); |
515 | // writer.WriteElementString("Name", folder.Name); | 708 | writer.WriteElementString("Name", folder.Name); |
516 | // WriteUUID(writer, "Owner", folder.Owner); | 709 | WriteUUID(writer, "Owner", folder.Owner); |
517 | // WriteUUID(writer, "ParentID", folder.ParentID); | 710 | WriteUUID(writer, "ParentID", folder.ParentID); |
518 | // WriteUUID(writer, "ID", folder.ID); | 711 | WriteUUID(writer, "ID", folder.ID); |
519 | // writer.WriteElementString("Type", XmlConvert.ToString(folder.Type)); | 712 | writer.WriteElementString("Type", XmlConvert.ToString(folder.Type)); |
520 | // writer.WriteElementString("Version", XmlConvert.ToString(folder.Version)); | 713 | writer.WriteElementString("Version", XmlConvert.ToString(folder.Version)); |
521 | // writer.WriteEndElement(); | 714 | writer.WriteEndElement(); |
522 | // } | 715 | } |
523 | // } | 716 | } |
524 | 717 | ||
525 | // writer.WriteEndElement(); | 718 | writer.WriteEndElement(); |
526 | // writer.WriteEndDocument(); | 719 | writer.WriteEndDocument(); |
527 | 720 | ||
528 | // writer.Flush(); | 721 | writer.Flush(); |
529 | // } | 722 | } |
530 | 723 | ||
531 | // stream.Flush(); | 724 | stream.Flush(); |
532 | //} | 725 | } |
533 | 726 | ||
534 | //void SerializeItemList(Stream stream, List<InventoryItem> items) | 727 | private static void SerializeItemList(Stream stream, List<InventoryItemBase> items) |
535 | //{ | 728 | { |
536 | // using (XmlWriter writer = XmlWriter.Create(stream)) | 729 | using (XmlWriter writer = XmlWriter.Create(stream)) |
537 | // { | 730 | { |
538 | // writer.WriteStartDocument(); | 731 | writer.WriteStartDocument(); |
539 | // writer.WriteStartElement("ArrayOfInventoryItemBase"); | 732 | writer.WriteStartElement("ArrayOfInventoryItemBase"); |
540 | // writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); | 733 | writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); |
541 | // writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); | 734 | writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); |
542 | 735 | ||
543 | // if (items != null) | 736 | if (items != null) |
544 | // { | 737 | { |
545 | // foreach (InventoryItem item in items) | 738 | foreach (InventoryItemBase item in items) |
546 | // { | 739 | { |
547 | // writer.WriteStartElement("InventoryItemBase"); | 740 | writer.WriteStartElement("InventoryItemBase"); |
548 | // WriteUUID(writer, "ID", item.ID); | 741 | WriteUUID(writer, "ID", item.ID); |
549 | // writer.WriteElementString("InvType", XmlConvert.ToString(item.InvType)); | 742 | writer.WriteElementString("InvType", XmlConvert.ToString(item.InvType)); |
550 | // WriteUUID(writer, "Folder", item.Folder); | 743 | WriteUUID(writer, "Folder", item.Folder); |
551 | // WriteUUID(writer, "Owner", item.Owner); | 744 | WriteUUID(writer, "Owner", item.Owner); |
552 | // WriteUUID(writer, "Creator", item.Creator); | 745 | WriteUUID(writer, "Creator", item.Creator); |
553 | // writer.WriteElementString("Name", item.Name); | 746 | writer.WriteElementString("Name", item.Name); |
554 | // writer.WriteElementString("Description", item.Description); | 747 | writer.WriteElementString("Description", item.Description); |
555 | // writer.WriteElementString("NextPermissions", XmlConvert.ToString(item.NextPermissions)); | 748 | writer.WriteElementString("NextPermissions", XmlConvert.ToString(item.NextPermissions)); |
556 | // writer.WriteElementString("CurrentPermissions", XmlConvert.ToString(item.CurrentPermissions)); | 749 | writer.WriteElementString("CurrentPermissions", XmlConvert.ToString(item.CurrentPermissions)); |
557 | // writer.WriteElementString("BasePermissions", XmlConvert.ToString(item.BasePermissions)); | 750 | writer.WriteElementString("BasePermissions", XmlConvert.ToString(item.BasePermissions)); |
558 | // writer.WriteElementString("EveryOnePermissions", XmlConvert.ToString(item.EveryOnePermissions)); | 751 | writer.WriteElementString("EveryOnePermissions", XmlConvert.ToString(item.EveryOnePermissions)); |
559 | // writer.WriteElementString("GroupPermissions", XmlConvert.ToString(item.GroupPermissions)); | 752 | writer.WriteElementString("GroupPermissions", XmlConvert.ToString(item.GroupPermissions)); |
560 | // writer.WriteElementString("AssetType", XmlConvert.ToString(item.AssetType)); | 753 | writer.WriteElementString("AssetType", XmlConvert.ToString(item.AssetType)); |
561 | // WriteUUID(writer, "AssetID", item.AssetID); | 754 | WriteUUID(writer, "AssetID", item.AssetID); |
562 | // WriteUUID(writer, "GroupID", item.GroupID); | 755 | WriteUUID(writer, "GroupID", item.GroupID); |
563 | // writer.WriteElementString("GroupOwned", XmlConvert.ToString(item.GroupOwned)); | 756 | writer.WriteElementString("GroupOwned", XmlConvert.ToString(item.GroupOwned)); |
564 | // writer.WriteElementString("SalePrice", XmlConvert.ToString(item.SalePrice)); | 757 | writer.WriteElementString("SalePrice", XmlConvert.ToString(item.SalePrice)); |
565 | // writer.WriteElementString("SaleType", XmlConvert.ToString(item.SaleType)); | 758 | writer.WriteElementString("SaleType", XmlConvert.ToString(item.SaleType)); |
566 | // writer.WriteElementString("Flags", XmlConvert.ToString(item.Flags)); | 759 | writer.WriteElementString("Flags", XmlConvert.ToString(item.Flags)); |
567 | // writer.WriteElementString("CreationDate", XmlConvert.ToString(item.CreationDate)); | 760 | writer.WriteElementString("CreationDate", XmlConvert.ToString(item.CreationDate)); |
568 | // writer.WriteEndElement(); | 761 | writer.WriteEndElement(); |
569 | // } | 762 | } |
570 | // } | 763 | } |
571 | 764 | ||
572 | // writer.WriteEndElement(); | 765 | writer.WriteEndElement(); |
573 | // writer.WriteEndDocument(); | 766 | writer.WriteEndDocument(); |
574 | 767 | ||
575 | // writer.Flush(); | 768 | writer.Flush(); |
576 | // } | 769 | } |
577 | 770 | ||
578 | // stream.Flush(); | 771 | stream.Flush(); |
579 | //} | 772 | } |
580 | 773 | ||
581 | //void WriteUUID(XmlWriter writer, string name, UUID id) | 774 | private static void WriteUUID(XmlWriter writer, string name, UUID id) |
582 | //{ | 775 | { |
583 | // writer.WriteStartElement(name); | 776 | writer.WriteStartElement(name); |
584 | // writer.WriteElementString("Guid", XmlConvert.ToString(id.Guid)); | 777 | writer.WriteElementString("Guid", XmlConvert.ToString(id.Guid)); |
585 | // writer.WriteEndElement(); | 778 | writer.WriteEndElement(); |
586 | //} | 779 | } |
587 | 780 | ||
588 | //void ReadUUID(XmlReader reader, string name, out UUID id) | 781 | private static void ReadUUID(XmlReader reader, string name, out UUID id) |
589 | //{ | 782 | { |
590 | // reader.ReadStartElement(name); | 783 | reader.ReadStartElement(name); |
591 | // UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out id); | 784 | UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out id); |
592 | // reader.ReadEndElement(); | 785 | reader.ReadEndElement(); |
593 | //} | 786 | } |
594 | } | 787 | } |
595 | 788 | ||
596 | #region OpenSim AssetType | 789 | #region OpenSim AssetType |
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs index e53462e..930e4f6 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs | |||
@@ -43,13 +43,11 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
43 | const string EXTENSION_NAME = "OpenSimInventoryStorage"; // Used in metrics reporting | 43 | const string EXTENSION_NAME = "OpenSimInventoryStorage"; // Used in metrics reporting |
44 | 44 | ||
45 | private AssetInventoryServer m_server; | 45 | private AssetInventoryServer m_server; |
46 | private IInventoryDataPlugin m_inventoryProvider; | ||
47 | private IConfig m_openSimConfig; | 46 | private IConfig m_openSimConfig; |
48 | private OpenSimInventoryService m_inventoryService; | 47 | private OpenSimInventoryService m_inventoryService; |
49 | 48 | ||
50 | public OpenSimInventoryStoragePlugin() | 49 | public OpenSimInventoryStoragePlugin() |
51 | { | 50 | { |
52 | m_inventoryService = new OpenSimInventoryService(); | ||
53 | } | 51 | } |
54 | 52 | ||
55 | #region IInventoryStorageProvider implementation | 53 | #region IInventoryStorageProvider implementation |
@@ -231,16 +229,17 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
231 | 229 | ||
232 | public BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolderWithChildren> folders) | 230 | public BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolderWithChildren> folders) |
233 | { | 231 | { |
234 | folders = null; | 232 | folders = new List<InventoryFolderWithChildren>(); |
235 | BackendResponse ret; | 233 | BackendResponse ret; |
236 | UUID ownerID; | 234 | UUID ownerID; |
237 | 235 | ||
238 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) | 236 | if (Utils.TryGetOpenSimUUID(owner, out ownerID)) |
239 | { | 237 | { |
240 | foreach (InventoryFolderWithChildren baseFolder in m_inventoryService.GetInventorySkeleton(ownerID)) | 238 | List<InventoryFolderBase> baseFolders = m_inventoryService.GetInventorySkeleton(ownerID); |
239 | foreach (InventoryFolderBase baseFolder in baseFolders) | ||
241 | { | 240 | { |
242 | InventoryFolderWithChildren folder = (InventoryFolderWithChildren) baseFolder; | 241 | InventoryFolderWithChildren folder = new InventoryFolderWithChildren(baseFolder); |
243 | folder.Children = null; // This call does not create a folder hierarchy | 242 | //folder.Children = null; // This call does not create a folder hierarchy |
244 | folders.Add(folder); | 243 | folders.Add(folder); |
245 | } | 244 | } |
246 | 245 | ||
@@ -248,6 +247,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
248 | } | 247 | } |
249 | else | 248 | else |
250 | { | 249 | { |
250 | folders = null; | ||
251 | ret = BackendResponse.NotFound; | 251 | ret = BackendResponse.NotFound; |
252 | } | 252 | } |
253 | 253 | ||
@@ -512,23 +512,9 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
512 | m_server = server; | 512 | m_server = server; |
513 | m_openSimConfig = server.ConfigFile.Configs["OpenSim"]; | 513 | m_openSimConfig = server.ConfigFile.Configs["OpenSim"]; |
514 | 514 | ||
515 | try | 515 | m_inventoryService = new OpenSimInventoryService(); |
516 | { | 516 | m_inventoryService.AddPlugin(m_openSimConfig.GetString("inventory_database_provider"), |
517 | m_inventoryProvider = DataPluginFactory.LoadDataPlugin<IInventoryDataPlugin>(m_openSimConfig.GetString("inventory_database_provider"), | 517 | m_openSimConfig.GetString("inventory_database_connect")); |
518 | m_openSimConfig.GetString("inventory_database_connect")); | ||
519 | if (m_inventoryProvider == null) | ||
520 | { | ||
521 | m_log.Error("[OPENSIMINVENTORYSTORAGE]: Failed to load a database plugin, server halting."); | ||
522 | Environment.Exit(-1); | ||
523 | } | ||
524 | else | ||
525 | m_log.InfoFormat("[OPENSIMINVENTORYSTORAGE]: Loaded storage backend: {0}", Version); | ||
526 | } | ||
527 | catch (Exception e) | ||
528 | { | ||
529 | m_log.WarnFormat("[OPENSIMINVENTORYSTORAGE]: Failure loading data plugin: {0}", e.ToString()); | ||
530 | throw new PluginNotInitialisedException(Name); | ||
531 | } | ||
532 | } | 518 | } |
533 | 519 | ||
534 | public void Stop() | 520 | public void Stop() |
@@ -547,7 +533,8 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
547 | 533 | ||
548 | public string Version | 534 | public string Version |
549 | { | 535 | { |
550 | get { return m_inventoryProvider.Version; } | 536 | // TODO: this should be something meaningful and not hardcoded? |
537 | get { return "0.1"; } | ||
551 | } | 538 | } |
552 | 539 | ||
553 | public string Name | 540 | public string Name |