diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Server/Handlers/Inventory | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Server/Handlers/Inventory')
3 files changed, 1178 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs new file mode 100644 index 0000000..b295446 --- /dev/null +++ b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs | |||
@@ -0,0 +1,330 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using Nwc.XmlRpc; | ||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Server.Handlers.Base; | ||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Server.Handlers.Inventory | ||
44 | { | ||
45 | public class InventoryServiceInConnector : ServiceConnector | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected IInventoryService m_InventoryService; | ||
50 | |||
51 | private bool m_doLookup = false; | ||
52 | |||
53 | //private static readonly int INVENTORY_DEFAULT_SESSION_TIME = 30; // secs | ||
54 | //private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); | ||
55 | |||
56 | private string m_userserver_url; | ||
57 | protected string m_ConfigName = "InventoryService"; | ||
58 | |||
59 | public InventoryServiceInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
60 | base(config, server, configName) | ||
61 | { | ||
62 | if (configName != string.Empty) | ||
63 | m_ConfigName = configName; | ||
64 | |||
65 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
66 | if (serverConfig == null) | ||
67 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
68 | |||
69 | string inventoryService = serverConfig.GetString("LocalServiceModule", | ||
70 | String.Empty); | ||
71 | |||
72 | if (inventoryService == String.Empty) | ||
73 | throw new Exception("No LocalServiceModule in config file"); | ||
74 | |||
75 | Object[] args = new Object[] { config }; | ||
76 | m_InventoryService = | ||
77 | ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args); | ||
78 | |||
79 | m_userserver_url = serverConfig.GetString("UserServerURI", String.Empty); | ||
80 | m_doLookup = serverConfig.GetBoolean("SessionAuthentication", false); | ||
81 | |||
82 | AddHttpHandlers(server); | ||
83 | m_log.Debug("[INVENTORY HANDLER]: handlers initialized"); | ||
84 | } | ||
85 | |||
86 | protected virtual void AddHttpHandlers(IHttpServer m_httpServer) | ||
87 | { | ||
88 | m_httpServer.AddStreamHandler( | ||
89 | new RestDeserialiseSecureHandler<Guid, List<InventoryFolderBase>>( | ||
90 | "POST", "/SystemFolders/", GetSystemFolders, CheckAuthSession)); | ||
91 | |||
92 | m_httpServer.AddStreamHandler( | ||
93 | new RestDeserialiseSecureHandler<Guid, InventoryCollection>( | ||
94 | "POST", "/GetFolderContent/", GetFolderContent, CheckAuthSession)); | ||
95 | |||
96 | m_httpServer.AddStreamHandler( | ||
97 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
98 | "POST", "/UpdateFolder/", m_InventoryService.UpdateFolder, CheckAuthSession)); | ||
99 | |||
100 | m_httpServer.AddStreamHandler( | ||
101 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
102 | "POST", "/MoveFolder/", m_InventoryService.MoveFolder, CheckAuthSession)); | ||
103 | |||
104 | m_httpServer.AddStreamHandler( | ||
105 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
106 | "POST", "/PurgeFolder/", m_InventoryService.PurgeFolder, CheckAuthSession)); | ||
107 | |||
108 | m_httpServer.AddStreamHandler( | ||
109 | new RestDeserialiseSecureHandler<List<Guid>, bool>( | ||
110 | "POST", "/DeleteFolders/", DeleteFolders, CheckAuthSession)); | ||
111 | |||
112 | m_httpServer.AddStreamHandler( | ||
113 | new RestDeserialiseSecureHandler<List<Guid>, bool>( | ||
114 | "POST", "/DeleteItem/", DeleteItems, CheckAuthSession)); | ||
115 | |||
116 | m_httpServer.AddStreamHandler( | ||
117 | new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( | ||
118 | "POST", "/QueryItem/", m_InventoryService.GetItem, CheckAuthSession)); | ||
119 | |||
120 | m_httpServer.AddStreamHandler( | ||
121 | new RestDeserialiseSecureHandler<InventoryFolderBase, InventoryFolderBase>( | ||
122 | "POST", "/QueryFolder/", m_InventoryService.GetFolder, CheckAuthSession)); | ||
123 | |||
124 | m_httpServer.AddStreamHandler( | ||
125 | new RestDeserialiseTrustedHandler<Guid, bool>( | ||
126 | "POST", "/CreateInventory/", CreateUsersInventory, CheckTrustSource)); | ||
127 | |||
128 | m_httpServer.AddStreamHandler( | ||
129 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
130 | "POST", "/NewFolder/", m_InventoryService.AddFolder, CheckAuthSession)); | ||
131 | |||
132 | m_httpServer.AddStreamHandler( | ||
133 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
134 | "POST", "/CreateFolder/", m_InventoryService.AddFolder, CheckAuthSession)); | ||
135 | |||
136 | m_httpServer.AddStreamHandler( | ||
137 | new RestDeserialiseSecureHandler<InventoryItemBase, bool>( | ||
138 | "POST", "/NewItem/", m_InventoryService.AddItem, CheckAuthSession)); | ||
139 | |||
140 | m_httpServer.AddStreamHandler( | ||
141 | new RestDeserialiseTrustedHandler<InventoryItemBase, bool>( | ||
142 | "POST", "/AddNewItem/", m_InventoryService.AddItem, CheckTrustSource)); | ||
143 | |||
144 | m_httpServer.AddStreamHandler( | ||
145 | new RestDeserialiseSecureHandler<Guid, List<InventoryItemBase>>( | ||
146 | "POST", "/GetItems/", GetFolderItems, CheckAuthSession)); | ||
147 | |||
148 | m_httpServer.AddStreamHandler( | ||
149 | new RestDeserialiseSecureHandler<List<InventoryItemBase>, bool>( | ||
150 | "POST", "/MoveItems/", MoveItems, CheckAuthSession)); | ||
151 | |||
152 | m_httpServer.AddStreamHandler(new InventoryServerMoveItemsHandler(m_InventoryService)); | ||
153 | |||
154 | |||
155 | // for persistent active gestures | ||
156 | m_httpServer.AddStreamHandler( | ||
157 | new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>> | ||
158 | ("POST", "/ActiveGestures/", GetActiveGestures, CheckTrustSource)); | ||
159 | |||
160 | // WARNING: Root folders no longer just delivers the root and immediate child folders (e.g | ||
161 | // system folders such as Objects, Textures), but it now returns the entire inventory skeleton. | ||
162 | // It would have been better to rename this request, but complexities in the BaseHttpServer | ||
163 | // (e.g. any http request not found is automatically treated as an xmlrpc request) make it easier | ||
164 | // to do this for now. | ||
165 | m_httpServer.AddStreamHandler( | ||
166 | new RestDeserialiseTrustedHandler<Guid, List<InventoryFolderBase>> | ||
167 | ("POST", "/RootFolders/", GetInventorySkeleton, CheckTrustSource)); | ||
168 | |||
169 | m_httpServer.AddStreamHandler( | ||
170 | new RestDeserialiseTrustedHandler<InventoryItemBase, int> | ||
171 | ("POST", "/AssetPermissions/", GetAssetPermissions, CheckTrustSource)); | ||
172 | |||
173 | } | ||
174 | |||
175 | #region Wrappers for converting the Guid parameter | ||
176 | |||
177 | public List<InventoryFolderBase> GetSystemFolders(Guid guid) | ||
178 | { | ||
179 | UUID userID = new UUID(guid); | ||
180 | return new List<InventoryFolderBase>(GetSystemFolders(userID).Values); | ||
181 | } | ||
182 | |||
183 | // This shouldn't be here, it should be in the inventory service. | ||
184 | // But I don't want to deal with types and dependencies for now. | ||
185 | private Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID) | ||
186 | { | ||
187 | InventoryFolderBase root = m_InventoryService.GetRootFolder(userID); | ||
188 | if (root != null) | ||
189 | { | ||
190 | InventoryCollection content = m_InventoryService.GetFolderContent(userID, root.ID); | ||
191 | if (content != null) | ||
192 | { | ||
193 | Dictionary<AssetType, InventoryFolderBase> folders = new Dictionary<AssetType, InventoryFolderBase>(); | ||
194 | foreach (InventoryFolderBase folder in content.Folders) | ||
195 | { | ||
196 | if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) | ||
197 | folders[(AssetType)folder.Type] = folder; | ||
198 | } | ||
199 | // Put the root folder there, as type Folder | ||
200 | folders[AssetType.Folder] = root; | ||
201 | return folders; | ||
202 | } | ||
203 | } | ||
204 | m_log.WarnFormat("[INVENTORY SERVICE]: System folders for {0} not found", userID); | ||
205 | return new Dictionary<AssetType, InventoryFolderBase>(); | ||
206 | } | ||
207 | |||
208 | public InventoryCollection GetFolderContent(Guid guid) | ||
209 | { | ||
210 | return m_InventoryService.GetFolderContent(UUID.Zero, new UUID(guid)); | ||
211 | } | ||
212 | |||
213 | public List<InventoryItemBase> GetFolderItems(Guid folderID) | ||
214 | { | ||
215 | List<InventoryItemBase> allItems = new List<InventoryItemBase>(); | ||
216 | |||
217 | // TODO: UUID.Zero is passed as the userID here, making the old assumption that the OpenSim | ||
218 | // inventory server only has a single inventory database and not per-user inventory databases. | ||
219 | // This could be changed but it requirs a bit of hackery to pass another parameter into this | ||
220 | // callback | ||
221 | List<InventoryItemBase> items = m_InventoryService.GetFolderItems(UUID.Zero, new UUID(folderID)); | ||
222 | |||
223 | if (items != null) | ||
224 | { | ||
225 | allItems.InsertRange(0, items); | ||
226 | } | ||
227 | return allItems; | ||
228 | } | ||
229 | |||
230 | public bool CreateUsersInventory(Guid rawUserID) | ||
231 | { | ||
232 | UUID userID = new UUID(rawUserID); | ||
233 | |||
234 | |||
235 | return m_InventoryService.CreateUserInventory(userID); | ||
236 | } | ||
237 | |||
238 | public List<InventoryItemBase> GetActiveGestures(Guid rawUserID) | ||
239 | { | ||
240 | UUID userID = new UUID(rawUserID); | ||
241 | |||
242 | return m_InventoryService.GetActiveGestures(userID); | ||
243 | } | ||
244 | |||
245 | public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID) | ||
246 | { | ||
247 | UUID userID = new UUID(rawUserID); | ||
248 | return m_InventoryService.GetInventorySkeleton(userID); | ||
249 | } | ||
250 | |||
251 | public int GetAssetPermissions(InventoryItemBase item) | ||
252 | { | ||
253 | return m_InventoryService.GetAssetPermissions(item.Owner, item.AssetID); | ||
254 | } | ||
255 | |||
256 | public bool DeleteFolders(List<Guid> items) | ||
257 | { | ||
258 | List<UUID> uuids = new List<UUID>(); | ||
259 | foreach (Guid g in items) | ||
260 | uuids.Add(new UUID(g)); | ||
261 | // oops we lost the user info here. Bad bad handlers | ||
262 | return m_InventoryService.DeleteFolders(UUID.Zero, uuids); | ||
263 | } | ||
264 | |||
265 | public bool DeleteItems(List<Guid> items) | ||
266 | { | ||
267 | List<UUID> uuids = new List<UUID>(); | ||
268 | foreach (Guid g in items) | ||
269 | uuids.Add(new UUID(g)); | ||
270 | // oops we lost the user info here. Bad bad handlers | ||
271 | return m_InventoryService.DeleteItems(UUID.Zero, uuids); | ||
272 | } | ||
273 | |||
274 | public bool MoveItems(List<InventoryItemBase> items) | ||
275 | { | ||
276 | // oops we lost the user info here. Bad bad handlers | ||
277 | // let's peek at one item | ||
278 | UUID ownerID = UUID.Zero; | ||
279 | if (items.Count > 0) | ||
280 | ownerID = items[0].Owner; | ||
281 | return m_InventoryService.MoveItems(ownerID, items); | ||
282 | } | ||
283 | #endregion | ||
284 | |||
285 | /// <summary> | ||
286 | /// Check that the source of an inventory request is one that we trust. | ||
287 | /// </summary> | ||
288 | /// <param name="peer"></param> | ||
289 | /// <returns></returns> | ||
290 | public bool CheckTrustSource(IPEndPoint peer) | ||
291 | { | ||
292 | if (m_doLookup) | ||
293 | { | ||
294 | m_log.InfoFormat("[INVENTORY IN CONNECTOR]: Checking trusted source {0}", peer); | ||
295 | UriBuilder ub = new UriBuilder(m_userserver_url); | ||
296 | IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host); | ||
297 | foreach (IPAddress uaddr in uaddrs) | ||
298 | { | ||
299 | if (uaddr.Equals(peer.Address)) | ||
300 | { | ||
301 | return true; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | m_log.WarnFormat( | ||
306 | "[INVENTORY IN CONNECTOR]: Rejecting request since source {0} was not in the list of trusted sources", | ||
307 | peer); | ||
308 | |||
309 | return false; | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | return true; | ||
314 | } | ||
315 | } | ||
316 | |||
317 | /// <summary> | ||
318 | /// Check that the source of an inventory request for a particular agent is a current session belonging to | ||
319 | /// that agent. | ||
320 | /// </summary> | ||
321 | /// <param name="session_id"></param> | ||
322 | /// <param name="avatar_id"></param> | ||
323 | /// <returns></returns> | ||
324 | public virtual bool CheckAuthSession(string session_id, string avatar_id) | ||
325 | { | ||
326 | return true; | ||
327 | } | ||
328 | |||
329 | } | ||
330 | } | ||
diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs new file mode 100644 index 0000000..e2c50fe --- /dev/null +++ b/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs | |||
@@ -0,0 +1,81 @@ | |||
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 | |||
28 | using Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using System.IO; | ||
34 | using System.Net; | ||
35 | using System.Text; | ||
36 | using System.Text.RegularExpressions; | ||
37 | using System.Xml; | ||
38 | using System.Xml.Serialization; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | using OpenMetaverse; | ||
44 | |||
45 | namespace OpenSim.Server.Handlers.Inventory | ||
46 | { | ||
47 | public class InventoryServerMoveItemsHandler : BaseStreamHandler | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IInventoryService m_InventoryService; | ||
52 | |||
53 | public InventoryServerMoveItemsHandler(IInventoryService service) : | ||
54 | base("PUT", "/inventory") | ||
55 | { | ||
56 | m_InventoryService = service; | ||
57 | } | ||
58 | |||
59 | protected override byte[] ProcessRequest(string path, Stream request, | ||
60 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
61 | { | ||
62 | XmlSerializer xs = new XmlSerializer(typeof (List<InventoryItemBase>)); | ||
63 | List<InventoryItemBase> items = (List<InventoryItemBase>)xs.Deserialize(request); | ||
64 | |||
65 | bool result = false; | ||
66 | string[] p = SplitParams(path); | ||
67 | |||
68 | if (p.Length > 0) | ||
69 | { | ||
70 | UUID ownerID = UUID.Zero; | ||
71 | UUID.TryParse(p[0], out ownerID); | ||
72 | result = m_InventoryService.MoveItems(ownerID, items); | ||
73 | } | ||
74 | else | ||
75 | m_log.WarnFormat("[MOVEITEMS HANDLER]: ownerID not provided in request. Unable to serve."); | ||
76 | |||
77 | xs = new XmlSerializer(typeof(bool)); | ||
78 | return ServerUtils.SerializeResult(xs, result); | ||
79 | } | ||
80 | } | ||
81 | } | ||
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs new file mode 100644 index 0000000..5c4e7a9 --- /dev/null +++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs | |||
@@ -0,0 +1,767 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Text; | ||
31 | using System.Xml; | ||
32 | using System.Collections.Generic; | ||
33 | using System.IO; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.ServiceAuth; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Server.Handlers.Base; | ||
41 | using log4net; | ||
42 | using OpenMetaverse; | ||
43 | |||
44 | using System.Threading; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Inventory | ||
47 | { | ||
48 | public class XInventoryInConnector : ServiceConnector | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IInventoryService m_InventoryService; | ||
53 | private string m_ConfigName = "InventoryService"; | ||
54 | |||
55 | public XInventoryInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
56 | base(config, server, configName) | ||
57 | { | ||
58 | if (configName != String.Empty) | ||
59 | m_ConfigName = configName; | ||
60 | |||
61 | m_log.DebugFormat("[XInventoryInConnector]: Starting with config name {0}", m_ConfigName); | ||
62 | |||
63 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
64 | if (serverConfig == null) | ||
65 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
66 | |||
67 | string inventoryService = serverConfig.GetString("LocalServiceModule", | ||
68 | String.Empty); | ||
69 | |||
70 | if (inventoryService == String.Empty) | ||
71 | throw new Exception("No InventoryService in config file"); | ||
72 | |||
73 | Object[] args = new Object[] { config, m_ConfigName }; | ||
74 | m_InventoryService = | ||
75 | ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args); | ||
76 | |||
77 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
78 | |||
79 | server.AddStreamHandler(new XInventoryConnectorPostHandler(m_InventoryService, auth)); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public class XInventoryConnectorPostHandler : BaseStreamHandler | ||
84 | { | ||
85 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
86 | |||
87 | private IInventoryService m_InventoryService; | ||
88 | |||
89 | public XInventoryConnectorPostHandler(IInventoryService service, IServiceAuth auth) : | ||
90 | base("POST", "/xinventory", auth) | ||
91 | { | ||
92 | m_InventoryService = service; | ||
93 | } | ||
94 | |||
95 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
96 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
97 | { | ||
98 | StreamReader sr = new StreamReader(requestData); | ||
99 | string body = sr.ReadToEnd(); | ||
100 | sr.Close(); | ||
101 | body = body.Trim(); | ||
102 | |||
103 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
104 | |||
105 | try | ||
106 | { | ||
107 | Dictionary<string, object> request = | ||
108 | ServerUtils.ParseQueryString(body); | ||
109 | |||
110 | if (!request.ContainsKey("METHOD")) | ||
111 | return FailureResult(); | ||
112 | |||
113 | string method = request["METHOD"].ToString(); | ||
114 | request.Remove("METHOD"); | ||
115 | |||
116 | switch (method) | ||
117 | { | ||
118 | case "CREATEUSERINVENTORY": | ||
119 | return HandleCreateUserInventory(request); | ||
120 | case "GETINVENTORYSKELETON": | ||
121 | return HandleGetInventorySkeleton(request); | ||
122 | case "GETROOTFOLDER": | ||
123 | return HandleGetRootFolder(request); | ||
124 | case "GETFOLDERFORTYPE": | ||
125 | return HandleGetFolderForType(request); | ||
126 | case "GETFOLDERCONTENT": | ||
127 | return HandleGetFolderContent(request); | ||
128 | case "GETMULTIPLEFOLDERSCONTENT": | ||
129 | return HandleGetMultipleFoldersContent(request); | ||
130 | case "GETFOLDERITEMS": | ||
131 | return HandleGetFolderItems(request); | ||
132 | case "ADDFOLDER": | ||
133 | return HandleAddFolder(request); | ||
134 | case "UPDATEFOLDER": | ||
135 | return HandleUpdateFolder(request); | ||
136 | case "MOVEFOLDER": | ||
137 | return HandleMoveFolder(request); | ||
138 | case "DELETEFOLDERS": | ||
139 | return HandleDeleteFolders(request); | ||
140 | case "PURGEFOLDER": | ||
141 | return HandlePurgeFolder(request); | ||
142 | case "ADDITEM": | ||
143 | return HandleAddItem(request); | ||
144 | case "UPDATEITEM": | ||
145 | return HandleUpdateItem(request); | ||
146 | case "MOVEITEMS": | ||
147 | return HandleMoveItems(request); | ||
148 | case "DELETEITEMS": | ||
149 | return HandleDeleteItems(request); | ||
150 | case "GETITEM": | ||
151 | return HandleGetItem(request); | ||
152 | case "GETMULTIPLEITEMS": | ||
153 | return HandleGetMultipleItems(request); | ||
154 | case "GETFOLDER": | ||
155 | return HandleGetFolder(request); | ||
156 | case "GETACTIVEGESTURES": | ||
157 | return HandleGetActiveGestures(request); | ||
158 | case "GETASSETPERMISSIONS": | ||
159 | return HandleGetAssetPermissions(request); | ||
160 | } | ||
161 | m_log.DebugFormat("[XINVENTORY HANDLER]: unknown method request: {0}", method); | ||
162 | } | ||
163 | catch (Exception e) | ||
164 | { | ||
165 | m_log.Error(string.Format("[XINVENTORY HANDLER]: Exception {0} ", e.Message), e); | ||
166 | } | ||
167 | |||
168 | return FailureResult(); | ||
169 | } | ||
170 | |||
171 | private byte[] FailureResult() | ||
172 | { | ||
173 | return BoolResult(false); | ||
174 | } | ||
175 | |||
176 | private byte[] SuccessResult() | ||
177 | { | ||
178 | return BoolResult(true); | ||
179 | } | ||
180 | |||
181 | private byte[] BoolResult(bool value) | ||
182 | { | ||
183 | XmlDocument doc = new XmlDocument(); | ||
184 | |||
185 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
186 | "", ""); | ||
187 | |||
188 | doc.AppendChild(xmlnode); | ||
189 | |||
190 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
191 | ""); | ||
192 | |||
193 | doc.AppendChild(rootElement); | ||
194 | |||
195 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
196 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
197 | |||
198 | rootElement.AppendChild(result); | ||
199 | |||
200 | return Util.DocToBytes(doc); | ||
201 | } | ||
202 | |||
203 | byte[] HandleCreateUserInventory(Dictionary<string,object> request) | ||
204 | { | ||
205 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
206 | |||
207 | if (!request.ContainsKey("PRINCIPAL")) | ||
208 | return FailureResult(); | ||
209 | |||
210 | if (m_InventoryService.CreateUserInventory(new UUID(request["PRINCIPAL"].ToString()))) | ||
211 | result["RESULT"] = "True"; | ||
212 | else | ||
213 | result["RESULT"] = "False"; | ||
214 | |||
215 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
216 | |||
217 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
218 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
219 | } | ||
220 | |||
221 | byte[] HandleGetInventorySkeleton(Dictionary<string,object> request) | ||
222 | { | ||
223 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
224 | |||
225 | if (!request.ContainsKey("PRINCIPAL")) | ||
226 | return FailureResult(); | ||
227 | |||
228 | |||
229 | List<InventoryFolderBase> folders = m_InventoryService.GetInventorySkeleton(new UUID(request["PRINCIPAL"].ToString())); | ||
230 | |||
231 | Dictionary<string, object> sfolders = new Dictionary<string, object>(); | ||
232 | if (folders != null) | ||
233 | { | ||
234 | int i = 0; | ||
235 | foreach (InventoryFolderBase f in folders) | ||
236 | { | ||
237 | sfolders["folder_" + i.ToString()] = EncodeFolder(f); | ||
238 | i++; | ||
239 | } | ||
240 | } | ||
241 | result["FOLDERS"] = sfolders; | ||
242 | |||
243 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
244 | |||
245 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
246 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
247 | } | ||
248 | |||
249 | byte[] HandleGetRootFolder(Dictionary<string,object> request) | ||
250 | { | ||
251 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
252 | |||
253 | UUID principal = UUID.Zero; | ||
254 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
255 | InventoryFolderBase rfolder = m_InventoryService.GetRootFolder(principal); | ||
256 | if (rfolder != null) | ||
257 | result["folder"] = EncodeFolder(rfolder); | ||
258 | |||
259 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
260 | |||
261 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
262 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
263 | } | ||
264 | |||
265 | byte[] HandleGetFolderForType(Dictionary<string,object> request) | ||
266 | { | ||
267 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
268 | UUID principal = UUID.Zero; | ||
269 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
270 | int type = 0; | ||
271 | Int32.TryParse(request["TYPE"].ToString(), out type); | ||
272 | InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (FolderType)type); | ||
273 | if (folder != null) | ||
274 | result["folder"] = EncodeFolder(folder); | ||
275 | |||
276 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
277 | |||
278 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
279 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
280 | } | ||
281 | |||
282 | byte[] HandleGetFolderContent(Dictionary<string,object> request) | ||
283 | { | ||
284 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
285 | UUID principal = UUID.Zero; | ||
286 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
287 | UUID folderID = UUID.Zero; | ||
288 | UUID.TryParse(request["FOLDER"].ToString(), out folderID); | ||
289 | |||
290 | InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID); | ||
291 | if (icoll != null) | ||
292 | { | ||
293 | result["FID"] = icoll.FolderID.ToString(); | ||
294 | result["VERSION"] = icoll.Version.ToString(); | ||
295 | Dictionary<string, object> folders = new Dictionary<string, object>(); | ||
296 | int i = 0; | ||
297 | if (icoll.Folders != null) | ||
298 | { | ||
299 | foreach (InventoryFolderBase f in icoll.Folders) | ||
300 | { | ||
301 | folders["folder_" + i.ToString()] = EncodeFolder(f); | ||
302 | i++; | ||
303 | } | ||
304 | result["FOLDERS"] = folders; | ||
305 | } | ||
306 | if (icoll.Items != null) | ||
307 | { | ||
308 | i = 0; | ||
309 | Dictionary<string, object> items = new Dictionary<string, object>(); | ||
310 | foreach (InventoryItemBase it in icoll.Items) | ||
311 | { | ||
312 | items["item_" + i.ToString()] = EncodeItem(it); | ||
313 | i++; | ||
314 | } | ||
315 | result["ITEMS"] = items; | ||
316 | } | ||
317 | } | ||
318 | |||
319 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
320 | |||
321 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
322 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
323 | } | ||
324 | |||
325 | byte[] HandleGetMultipleFoldersContent(Dictionary<string, object> request) | ||
326 | { | ||
327 | Dictionary<string, object> resultSet = new Dictionary<string, object>(); | ||
328 | UUID principal = UUID.Zero; | ||
329 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
330 | string folderIDstr = request["FOLDERS"].ToString(); | ||
331 | int count = 0; | ||
332 | Int32.TryParse(request["COUNT"].ToString(), out count); | ||
333 | |||
334 | UUID[] fids = new UUID[count]; | ||
335 | string[] uuids = folderIDstr.Split(','); | ||
336 | int i = 0; | ||
337 | foreach (string id in uuids) | ||
338 | { | ||
339 | UUID fid = UUID.Zero; | ||
340 | if (UUID.TryParse(id, out fid)) | ||
341 | fids[i] = fid; | ||
342 | i += 1; | ||
343 | } | ||
344 | |||
345 | count = 0; | ||
346 | InventoryCollection[] icollList = m_InventoryService.GetMultipleFoldersContent(principal, fids); | ||
347 | if (icollList != null && icollList.Length > 0) | ||
348 | { | ||
349 | foreach (InventoryCollection icoll in icollList) | ||
350 | { | ||
351 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
352 | result["FID"] = icoll.FolderID.ToString(); | ||
353 | result["VERSION"] = icoll.Version.ToString(); | ||
354 | result["OWNER"] = icoll.OwnerID.ToString(); | ||
355 | Dictionary<string, object> folders = new Dictionary<string, object>(); | ||
356 | i = 0; | ||
357 | if (icoll.Folders != null) | ||
358 | { | ||
359 | foreach (InventoryFolderBase f in icoll.Folders) | ||
360 | { | ||
361 | folders["folder_" + i.ToString()] = EncodeFolder(f); | ||
362 | i++; | ||
363 | } | ||
364 | result["FOLDERS"] = folders; | ||
365 | } | ||
366 | i = 0; | ||
367 | if (icoll.Items != null) | ||
368 | { | ||
369 | Dictionary<string, object> items = new Dictionary<string, object>(); | ||
370 | foreach (InventoryItemBase it in icoll.Items) | ||
371 | { | ||
372 | items["item_" + i.ToString()] = EncodeItem(it); | ||
373 | i++; | ||
374 | } | ||
375 | result["ITEMS"] = items; | ||
376 | } | ||
377 | |||
378 | resultSet["F_" + fids[count++]] = result; | ||
379 | //m_log.DebugFormat("[XXX]: Sending {0} {1}", fids[count-1], icoll.FolderID); | ||
380 | } | ||
381 | } | ||
382 | |||
383 | string xmlString = ServerUtils.BuildXmlResponse(resultSet); | ||
384 | |||
385 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
386 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
387 | } | ||
388 | |||
389 | byte[] HandleGetFolderItems(Dictionary<string, object> request) | ||
390 | { | ||
391 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
392 | UUID principal = UUID.Zero; | ||
393 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
394 | UUID folderID = UUID.Zero; | ||
395 | UUID.TryParse(request["FOLDER"].ToString(), out folderID); | ||
396 | |||
397 | List<InventoryItemBase> items = m_InventoryService.GetFolderItems(principal, folderID); | ||
398 | Dictionary<string, object> sitems = new Dictionary<string, object>(); | ||
399 | |||
400 | if (items != null) | ||
401 | { | ||
402 | int i = 0; | ||
403 | foreach (InventoryItemBase item in items) | ||
404 | { | ||
405 | sitems["item_" + i.ToString()] = EncodeItem(item); | ||
406 | i++; | ||
407 | } | ||
408 | } | ||
409 | result["ITEMS"] = sitems; | ||
410 | |||
411 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
412 | |||
413 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
414 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
415 | } | ||
416 | |||
417 | byte[] HandleAddFolder(Dictionary<string,object> request) | ||
418 | { | ||
419 | InventoryFolderBase folder = BuildFolder(request); | ||
420 | |||
421 | if (m_InventoryService.AddFolder(folder)) | ||
422 | return SuccessResult(); | ||
423 | else | ||
424 | return FailureResult(); | ||
425 | } | ||
426 | |||
427 | byte[] HandleUpdateFolder(Dictionary<string,object> request) | ||
428 | { | ||
429 | InventoryFolderBase folder = BuildFolder(request); | ||
430 | |||
431 | if (m_InventoryService.UpdateFolder(folder)) | ||
432 | return SuccessResult(); | ||
433 | else | ||
434 | return FailureResult(); | ||
435 | } | ||
436 | |||
437 | byte[] HandleMoveFolder(Dictionary<string,object> request) | ||
438 | { | ||
439 | UUID parentID = UUID.Zero; | ||
440 | UUID.TryParse(request["ParentID"].ToString(), out parentID); | ||
441 | UUID folderID = UUID.Zero; | ||
442 | UUID.TryParse(request["ID"].ToString(), out folderID); | ||
443 | UUID principal = UUID.Zero; | ||
444 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
445 | |||
446 | InventoryFolderBase folder = new InventoryFolderBase(folderID, "", principal, parentID); | ||
447 | if (m_InventoryService.MoveFolder(folder)) | ||
448 | return SuccessResult(); | ||
449 | else | ||
450 | return FailureResult(); | ||
451 | |||
452 | } | ||
453 | |||
454 | byte[] HandleDeleteFolders(Dictionary<string,object> request) | ||
455 | { | ||
456 | UUID principal = UUID.Zero; | ||
457 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
458 | List<string> slist = (List<string>)request["FOLDERS"]; | ||
459 | List<UUID> uuids = new List<UUID>(); | ||
460 | foreach (string s in slist) | ||
461 | { | ||
462 | UUID u = UUID.Zero; | ||
463 | if (UUID.TryParse(s, out u)) | ||
464 | uuids.Add(u); | ||
465 | } | ||
466 | |||
467 | if (m_InventoryService.DeleteFolders(principal, uuids)) | ||
468 | return SuccessResult(); | ||
469 | else | ||
470 | return | ||
471 | FailureResult(); | ||
472 | } | ||
473 | |||
474 | byte[] HandlePurgeFolder(Dictionary<string,object> request) | ||
475 | { | ||
476 | UUID folderID = UUID.Zero; | ||
477 | UUID.TryParse(request["ID"].ToString(), out folderID); | ||
478 | |||
479 | InventoryFolderBase folder = new InventoryFolderBase(folderID); | ||
480 | if (m_InventoryService.PurgeFolder(folder)) | ||
481 | return SuccessResult(); | ||
482 | else | ||
483 | return FailureResult(); | ||
484 | } | ||
485 | |||
486 | byte[] HandleAddItem(Dictionary<string,object> request) | ||
487 | { | ||
488 | InventoryItemBase item = BuildItem(request); | ||
489 | |||
490 | if (m_InventoryService.AddItem(item)) | ||
491 | return SuccessResult(); | ||
492 | else | ||
493 | return FailureResult(); | ||
494 | } | ||
495 | |||
496 | byte[] HandleUpdateItem(Dictionary<string,object> request) | ||
497 | { | ||
498 | InventoryItemBase item = BuildItem(request); | ||
499 | |||
500 | if (m_InventoryService.UpdateItem(item)) | ||
501 | return SuccessResult(); | ||
502 | else | ||
503 | return FailureResult(); | ||
504 | } | ||
505 | |||
506 | byte[] HandleMoveItems(Dictionary<string,object> request) | ||
507 | { | ||
508 | List<string> idlist = (List<string>)request["IDLIST"]; | ||
509 | List<string> destlist = (List<string>)request["DESTLIST"]; | ||
510 | UUID principal = UUID.Zero; | ||
511 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
512 | |||
513 | List<InventoryItemBase> items = new List<InventoryItemBase>(); | ||
514 | int n = 0; | ||
515 | try | ||
516 | { | ||
517 | foreach (string s in idlist) | ||
518 | { | ||
519 | UUID u = UUID.Zero; | ||
520 | if (UUID.TryParse(s, out u)) | ||
521 | { | ||
522 | UUID fid = UUID.Zero; | ||
523 | if (UUID.TryParse(destlist[n++], out fid)) | ||
524 | { | ||
525 | InventoryItemBase item = new InventoryItemBase(u, principal); | ||
526 | item.Folder = fid; | ||
527 | items.Add(item); | ||
528 | } | ||
529 | } | ||
530 | } | ||
531 | } | ||
532 | catch (Exception e) | ||
533 | { | ||
534 | m_log.DebugFormat("[XINVENTORY IN CONNECTOR]: Exception in HandleMoveItems: {0}", e.Message); | ||
535 | return FailureResult(); | ||
536 | } | ||
537 | |||
538 | if (m_InventoryService.MoveItems(principal, items)) | ||
539 | return SuccessResult(); | ||
540 | else | ||
541 | return FailureResult(); | ||
542 | } | ||
543 | |||
544 | byte[] HandleDeleteItems(Dictionary<string,object> request) | ||
545 | { | ||
546 | UUID principal = UUID.Zero; | ||
547 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
548 | List<string> slist = (List<string>)request["ITEMS"]; | ||
549 | List<UUID> uuids = new List<UUID>(); | ||
550 | foreach (string s in slist) | ||
551 | { | ||
552 | UUID u = UUID.Zero; | ||
553 | if (UUID.TryParse(s, out u)) | ||
554 | uuids.Add(u); | ||
555 | } | ||
556 | |||
557 | if (m_InventoryService.DeleteItems(principal, uuids)) | ||
558 | return SuccessResult(); | ||
559 | else | ||
560 | return | ||
561 | FailureResult(); | ||
562 | } | ||
563 | |||
564 | byte[] HandleGetItem(Dictionary<string,object> request) | ||
565 | { | ||
566 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
567 | UUID id = UUID.Zero; | ||
568 | UUID.TryParse(request["ID"].ToString(), out id); | ||
569 | |||
570 | InventoryItemBase item = new InventoryItemBase(id); | ||
571 | item = m_InventoryService.GetItem(item); | ||
572 | if (item != null) | ||
573 | result["item"] = EncodeItem(item); | ||
574 | |||
575 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
576 | |||
577 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
578 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
579 | } | ||
580 | |||
581 | byte[] HandleGetMultipleItems(Dictionary<string, object> request) | ||
582 | { | ||
583 | Dictionary<string, object> resultSet = new Dictionary<string, object>(); | ||
584 | UUID principal = UUID.Zero; | ||
585 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
586 | string itemIDstr = request["ITEMS"].ToString(); | ||
587 | int count = 0; | ||
588 | Int32.TryParse(request["COUNT"].ToString(), out count); | ||
589 | |||
590 | UUID[] fids = new UUID[count]; | ||
591 | string[] uuids = itemIDstr.Split(','); | ||
592 | int i = 0; | ||
593 | foreach (string id in uuids) | ||
594 | { | ||
595 | UUID fid = UUID.Zero; | ||
596 | if (UUID.TryParse(id, out fid)) | ||
597 | fids[i] = fid; | ||
598 | i += 1; | ||
599 | } | ||
600 | |||
601 | InventoryItemBase[] itemsList = m_InventoryService.GetMultipleItems(principal, fids); | ||
602 | if (itemsList != null && itemsList.Length > 0) | ||
603 | { | ||
604 | count = 0; | ||
605 | foreach (InventoryItemBase item in itemsList) | ||
606 | resultSet["item_" + count++] = (item == null) ? (object)"NULL" : EncodeItem(item); | ||
607 | } | ||
608 | |||
609 | string xmlString = ServerUtils.BuildXmlResponse(resultSet); | ||
610 | |||
611 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
612 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
613 | } | ||
614 | |||
615 | byte[] HandleGetFolder(Dictionary<string,object> request) | ||
616 | { | ||
617 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
618 | UUID id = UUID.Zero; | ||
619 | UUID.TryParse(request["ID"].ToString(), out id); | ||
620 | |||
621 | InventoryFolderBase folder = new InventoryFolderBase(id); | ||
622 | folder = m_InventoryService.GetFolder(folder); | ||
623 | if (folder != null) | ||
624 | result["folder"] = EncodeFolder(folder); | ||
625 | |||
626 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
627 | |||
628 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
629 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
630 | } | ||
631 | |||
632 | byte[] HandleGetActiveGestures(Dictionary<string,object> request) | ||
633 | { | ||
634 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
635 | UUID principal = UUID.Zero; | ||
636 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
637 | |||
638 | List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(principal); | ||
639 | Dictionary<string, object> items = new Dictionary<string, object>(); | ||
640 | if (gestures != null) | ||
641 | { | ||
642 | int i = 0; | ||
643 | foreach (InventoryItemBase item in gestures) | ||
644 | { | ||
645 | items["item_" + i.ToString()] = EncodeItem(item); | ||
646 | i++; | ||
647 | } | ||
648 | } | ||
649 | result["ITEMS"] = items; | ||
650 | |||
651 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
652 | |||
653 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
654 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
655 | } | ||
656 | |||
657 | byte[] HandleGetAssetPermissions(Dictionary<string,object> request) | ||
658 | { | ||
659 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
660 | UUID principal = UUID.Zero; | ||
661 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
662 | UUID assetID = UUID.Zero; | ||
663 | UUID.TryParse(request["ASSET"].ToString(), out assetID); | ||
664 | |||
665 | int perms = m_InventoryService.GetAssetPermissions(principal, assetID); | ||
666 | |||
667 | result["RESULT"] = perms.ToString(); | ||
668 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
669 | |||
670 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
671 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
672 | } | ||
673 | |||
674 | private Dictionary<string, object> EncodeFolder(InventoryFolderBase f) | ||
675 | { | ||
676 | Dictionary<string, object> ret = new Dictionary<string, object>(); | ||
677 | |||
678 | ret["ParentID"] = f.ParentID.ToString(); | ||
679 | ret["Type"] = f.Type.ToString(); | ||
680 | ret["Version"] = f.Version.ToString(); | ||
681 | ret["Name"] = f.Name; | ||
682 | ret["Owner"] = f.Owner.ToString(); | ||
683 | ret["ID"] = f.ID.ToString(); | ||
684 | |||
685 | return ret; | ||
686 | } | ||
687 | |||
688 | private Dictionary<string, object> EncodeItem(InventoryItemBase item) | ||
689 | { | ||
690 | Dictionary<string, object> ret = new Dictionary<string, object>(); | ||
691 | |||
692 | ret["AssetID"] = item.AssetID.ToString(); | ||
693 | ret["AssetType"] = item.AssetType.ToString(); | ||
694 | ret["BasePermissions"] = item.BasePermissions.ToString(); | ||
695 | ret["CreationDate"] = item.CreationDate.ToString(); | ||
696 | if (item.CreatorId != null) | ||
697 | ret["CreatorId"] = item.CreatorId.ToString(); | ||
698 | else | ||
699 | ret["CreatorId"] = String.Empty; | ||
700 | if (item.CreatorData != null) | ||
701 | ret["CreatorData"] = item.CreatorData; | ||
702 | else | ||
703 | ret["CreatorData"] = String.Empty; | ||
704 | ret["CurrentPermissions"] = item.CurrentPermissions.ToString(); | ||
705 | ret["Description"] = item.Description.ToString(); | ||
706 | ret["EveryOnePermissions"] = item.EveryOnePermissions.ToString(); | ||
707 | ret["Flags"] = item.Flags.ToString(); | ||
708 | ret["Folder"] = item.Folder.ToString(); | ||
709 | ret["GroupID"] = item.GroupID.ToString(); | ||
710 | ret["GroupOwned"] = item.GroupOwned.ToString(); | ||
711 | ret["GroupPermissions"] = item.GroupPermissions.ToString(); | ||
712 | ret["ID"] = item.ID.ToString(); | ||
713 | ret["InvType"] = item.InvType.ToString(); | ||
714 | ret["Name"] = item.Name.ToString(); | ||
715 | ret["NextPermissions"] = item.NextPermissions.ToString(); | ||
716 | ret["Owner"] = item.Owner.ToString(); | ||
717 | ret["SalePrice"] = item.SalePrice.ToString(); | ||
718 | ret["SaleType"] = item.SaleType.ToString(); | ||
719 | |||
720 | return ret; | ||
721 | } | ||
722 | |||
723 | private InventoryFolderBase BuildFolder(Dictionary<string,object> data) | ||
724 | { | ||
725 | InventoryFolderBase folder = new InventoryFolderBase(); | ||
726 | |||
727 | folder.ParentID = new UUID(data["ParentID"].ToString()); | ||
728 | folder.Type = short.Parse(data["Type"].ToString()); | ||
729 | folder.Version = ushort.Parse(data["Version"].ToString()); | ||
730 | folder.Name = data["Name"].ToString(); | ||
731 | folder.Owner = new UUID(data["Owner"].ToString()); | ||
732 | folder.ID = new UUID(data["ID"].ToString()); | ||
733 | |||
734 | return folder; | ||
735 | } | ||
736 | |||
737 | private InventoryItemBase BuildItem(Dictionary<string,object> data) | ||
738 | { | ||
739 | InventoryItemBase item = new InventoryItemBase(); | ||
740 | |||
741 | item.AssetID = new UUID(data["AssetID"].ToString()); | ||
742 | item.AssetType = int.Parse(data["AssetType"].ToString()); | ||
743 | item.Name = data["Name"].ToString(); | ||
744 | item.Owner = new UUID(data["Owner"].ToString()); | ||
745 | item.ID = new UUID(data["ID"].ToString()); | ||
746 | item.InvType = int.Parse(data["InvType"].ToString()); | ||
747 | item.Folder = new UUID(data["Folder"].ToString()); | ||
748 | item.CreatorId = data["CreatorId"].ToString(); | ||
749 | item.CreatorData = data["CreatorData"].ToString(); | ||
750 | item.Description = data["Description"].ToString(); | ||
751 | item.NextPermissions = uint.Parse(data["NextPermissions"].ToString()); | ||
752 | item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString()); | ||
753 | item.BasePermissions = uint.Parse(data["BasePermissions"].ToString()); | ||
754 | item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString()); | ||
755 | item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString()); | ||
756 | item.GroupID = new UUID(data["GroupID"].ToString()); | ||
757 | item.GroupOwned = bool.Parse(data["GroupOwned"].ToString()); | ||
758 | item.SalePrice = int.Parse(data["SalePrice"].ToString()); | ||
759 | item.SaleType = byte.Parse(data["SaleType"].ToString()); | ||
760 | item.Flags = uint.Parse(data["Flags"].ToString()); | ||
761 | item.CreationDate = int.Parse(data["CreationDate"].ToString()); | ||
762 | |||
763 | return item; | ||
764 | } | ||
765 | |||
766 | } | ||
767 | } | ||