aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs623
1 files changed, 623 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs
new file mode 100644
index 0000000..9d96703
--- /dev/null
+++ b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs
@@ -0,0 +1,623 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Communications;
37using OpenSim.Services.Interfaces;
38using OpenSim.Server.Base;
39using OpenMetaverse;
40
41namespace OpenSim.Services.Connectors
42{
43 public class XInventoryServicesConnector : IInventoryService
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48
49 private string m_ServerURI = String.Empty;
50
51 private object m_Lock = new object();
52
53 public XInventoryServicesConnector()
54 {
55 }
56
57 public XInventoryServicesConnector(string serverURI)
58 {
59 m_ServerURI = serverURI.TrimEnd('/');
60 }
61
62 public XInventoryServicesConnector(IConfigSource source)
63 {
64 Initialise(source);
65 }
66
67 public virtual void Initialise(IConfigSource source)
68 {
69 IConfig assetConfig = source.Configs["InventoryService"];
70 if (assetConfig == null)
71 {
72 m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
73 throw new Exception("Inventory connector init error");
74 }
75
76 string serviceURI = assetConfig.GetString("InventoryServerURI",
77 String.Empty);
78
79 if (serviceURI == String.Empty)
80 {
81 m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService");
82 throw new Exception("Inventory connector init error");
83 }
84 m_ServerURI = serviceURI;
85 }
86
87 public bool CreateUserInventory(UUID principalID)
88 {
89 Dictionary<string,object> ret = MakeRequest("CREATEUSERINVENTORY",
90 new Dictionary<string,object> {
91 { "PRINCIPAL", principalID.ToString() }
92 });
93
94 if (ret == null)
95 return false;
96 if (ret.Count == 0)
97 return false;
98
99 return bool.Parse(ret["RESULT"].ToString());
100 }
101
102 public List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
103 {
104 Dictionary<string,object> ret = MakeRequest("GETINVENTORYSKELETON",
105 new Dictionary<string,object> {
106 { "PRINCIPAL", principalID.ToString() }
107 });
108
109 if (ret == null)
110 return null;
111 if (ret.Count == 0)
112 return null;
113
114 Dictionary<string, object> folders = (Dictionary<string, object>)ret["FOLDERS"];
115
116 List<InventoryFolderBase> fldrs = new List<InventoryFolderBase>();
117
118 try
119 {
120 foreach (Object o in folders.Values)
121 fldrs.Add(BuildFolder((Dictionary<string, object>)o));
122 }
123 catch (Exception e)
124 {
125 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message);
126 }
127
128 return fldrs;
129 }
130
131 public InventoryFolderBase GetRootFolder(UUID principalID)
132 {
133 Dictionary<string,object> ret = MakeRequest("GETROOTFOLDER",
134 new Dictionary<string,object> {
135 { "PRINCIPAL", principalID.ToString() }
136 });
137
138 if (ret == null)
139 return null;
140 if (ret.Count == 0)
141 return null;
142
143 return BuildFolder((Dictionary<string, object>)ret["folder"]);
144 }
145
146 public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
147 {
148 Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE",
149 new Dictionary<string,object> {
150 { "PRINCIPAL", principalID.ToString() },
151 { "TYPE", ((int)type).ToString() }
152 });
153
154 if (ret == null)
155 return null;
156 if (ret.Count == 0)
157 return null;
158
159 return BuildFolder((Dictionary<string, object>)ret["folder"]);
160 }
161
162 public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
163 {
164 InventoryCollection inventory = new InventoryCollection();
165 inventory.Folders = new List<InventoryFolderBase>();
166 inventory.Items = new List<InventoryItemBase>();
167 inventory.UserID = principalID;
168
169 try
170 {
171 Dictionary<string,object> ret = MakeRequest("GETFOLDERCONTENT",
172 new Dictionary<string,object> {
173 { "PRINCIPAL", principalID.ToString() },
174 { "FOLDER", folderID.ToString() }
175 });
176
177 if (ret == null)
178 return null;
179 if (ret.Count == 0)
180 return null;
181
182 Dictionary<string,object> folders =
183 (Dictionary<string,object>)ret["FOLDERS"];
184 Dictionary<string,object> items =
185 (Dictionary<string,object>)ret["ITEMS"];
186
187 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
188 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
189 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
190 inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
191 }
192 catch (Exception e)
193 {
194 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetFolderContent: {0}", e.Message);
195 }
196
197 return inventory;
198 }
199
200 public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
201 {
202 Dictionary<string,object> ret = MakeRequest("GETFOLDERITEMS",
203 new Dictionary<string,object> {
204 { "PRINCIPAL", principalID.ToString() },
205 { "FOLDER", folderID.ToString() }
206 });
207
208 if (ret == null)
209 return null;
210 if (ret.Count == 0)
211 return null;
212
213 Dictionary<string, object> items = (Dictionary<string, object>)ret["ITEMS"];
214 List<InventoryItemBase> fitems = new List<InventoryItemBase>();
215 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
216 fitems.Add(BuildItem((Dictionary<string, object>)o));
217
218 return fitems;
219 }
220
221 public bool AddFolder(InventoryFolderBase folder)
222 {
223 Dictionary<string,object> ret = MakeRequest("ADDFOLDER",
224 new Dictionary<string,object> {
225 { "ParentID", folder.ParentID.ToString() },
226 { "Type", folder.Type.ToString() },
227 { "Version", folder.Version.ToString() },
228 { "Name", folder.Name.ToString() },
229 { "Owner", folder.Owner.ToString() },
230 { "ID", folder.ID.ToString() }
231 });
232
233 if (ret == null)
234 return false;
235
236 return bool.Parse(ret["RESULT"].ToString());
237 }
238
239 public bool UpdateFolder(InventoryFolderBase folder)
240 {
241 Dictionary<string,object> ret = MakeRequest("UPDATEFOLDER",
242 new Dictionary<string,object> {
243 { "ParentID", folder.ParentID.ToString() },
244 { "Type", folder.Type.ToString() },
245 { "Version", folder.Version.ToString() },
246 { "Name", folder.Name.ToString() },
247 { "Owner", folder.Owner.ToString() },
248 { "ID", folder.ID.ToString() }
249 });
250
251 if (ret == null)
252 return false;
253
254 return bool.Parse(ret["RESULT"].ToString());
255 }
256
257 public bool MoveFolder(InventoryFolderBase folder)
258 {
259 Dictionary<string,object> ret = MakeRequest("MOVEFOLDER",
260 new Dictionary<string,object> {
261 { "ParentID", folder.ParentID.ToString() },
262 { "ID", folder.ID.ToString() },
263 { "PRINCIPAL", folder.Owner.ToString() }
264 });
265
266 if (ret == null)
267 return false;
268
269 return bool.Parse(ret["RESULT"].ToString());
270 }
271
272 public bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
273 {
274 List<string> slist = new List<string>();
275
276 foreach (UUID f in folderIDs)
277 slist.Add(f.ToString());
278
279 Dictionary<string,object> ret = MakeRequest("DELETEFOLDERS",
280 new Dictionary<string,object> {
281 { "PRINCIPAL", principalID.ToString() },
282 { "FOLDERS", slist }
283 });
284
285 if (ret == null)
286 return false;
287
288 return bool.Parse(ret["RESULT"].ToString());
289 }
290
291 public bool PurgeFolder(InventoryFolderBase folder)
292 {
293 Dictionary<string,object> ret = MakeRequest("PURGEFOLDER",
294 new Dictionary<string,object> {
295 { "ID", folder.ID.ToString() }
296 });
297
298 if (ret == null)
299 return false;
300
301 return bool.Parse(ret["RESULT"].ToString());
302 }
303
304 public bool AddItem(InventoryItemBase item)
305 {
306 if (item.CreatorData == null)
307 item.CreatorData = String.Empty;
308 Dictionary<string,object> ret = MakeRequest("ADDITEM",
309 new Dictionary<string,object> {
310 { "AssetID", item.AssetID.ToString() },
311 { "AssetType", item.AssetType.ToString() },
312 { "Name", item.Name.ToString() },
313 { "Owner", item.Owner.ToString() },
314 { "ID", item.ID.ToString() },
315 { "InvType", item.InvType.ToString() },
316 { "Folder", item.Folder.ToString() },
317 { "CreatorId", item.CreatorId.ToString() },
318 { "CreatorData", item.CreatorData.ToString() },
319 { "Description", item.Description.ToString() },
320 { "NextPermissions", item.NextPermissions.ToString() },
321 { "CurrentPermissions", item.CurrentPermissions.ToString() },
322 { "BasePermissions", item.BasePermissions.ToString() },
323 { "EveryOnePermissions", item.EveryOnePermissions.ToString() },
324 { "GroupPermissions", item.GroupPermissions.ToString() },
325 { "GroupID", item.GroupID.ToString() },
326 { "GroupOwned", item.GroupOwned.ToString() },
327 { "SalePrice", item.SalePrice.ToString() },
328 { "SaleType", item.SaleType.ToString() },
329 { "Flags", item.Flags.ToString() },
330 { "CreationDate", item.CreationDate.ToString() }
331 });
332
333 if (ret == null)
334 return false;
335
336 return bool.Parse(ret["RESULT"].ToString());
337 }
338
339 public bool UpdateItem(InventoryItemBase item)
340 {
341 if (item.CreatorData == null)
342 item.CreatorData = String.Empty;
343 Dictionary<string,object> ret = MakeRequest("UPDATEITEM",
344 new Dictionary<string,object> {
345 { "AssetID", item.AssetID.ToString() },
346 { "AssetType", item.AssetType.ToString() },
347 { "Name", item.Name.ToString() },
348 { "Owner", item.Owner.ToString() },
349 { "ID", item.ID.ToString() },
350 { "InvType", item.InvType.ToString() },
351 { "Folder", item.Folder.ToString() },
352 { "CreatorId", item.CreatorId.ToString() },
353 { "CreatorData", item.CreatorData.ToString() },
354 { "Description", item.Description.ToString() },
355 { "NextPermissions", item.NextPermissions.ToString() },
356 { "CurrentPermissions", item.CurrentPermissions.ToString() },
357 { "BasePermissions", item.BasePermissions.ToString() },
358 { "EveryOnePermissions", item.EveryOnePermissions.ToString() },
359 { "GroupPermissions", item.GroupPermissions.ToString() },
360 { "GroupID", item.GroupID.ToString() },
361 { "GroupOwned", item.GroupOwned.ToString() },
362 { "SalePrice", item.SalePrice.ToString() },
363 { "SaleType", item.SaleType.ToString() },
364 { "Flags", item.Flags.ToString() },
365 { "CreationDate", item.CreationDate.ToString() }
366 });
367
368 if (ret == null)
369 return false;
370
371 return bool.Parse(ret["RESULT"].ToString());
372 }
373
374 public bool MoveItems(UUID principalID, List<InventoryItemBase> items)
375 {
376 List<string> idlist = new List<string>();
377 List<string> destlist = new List<string>();
378
379 foreach (InventoryItemBase item in items)
380 {
381 idlist.Add(item.ID.ToString());
382 destlist.Add(item.Folder.ToString());
383 }
384
385 Dictionary<string,object> ret = MakeRequest("MOVEITEMS",
386 new Dictionary<string,object> {
387 { "PRINCIPAL", principalID.ToString() },
388 { "IDLIST", idlist },
389 { "DESTLIST", destlist }
390 });
391
392 if (ret == null)
393 return false;
394
395 return bool.Parse(ret["RESULT"].ToString());
396 }
397
398 public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
399 {
400 List<string> slist = new List<string>();
401
402 foreach (UUID f in itemIDs)
403 slist.Add(f.ToString());
404
405 Dictionary<string,object> ret = MakeRequest("DELETEITEMS",
406 new Dictionary<string,object> {
407 { "PRINCIPAL", principalID.ToString() },
408 { "ITEMS", slist }
409 });
410
411 if (ret == null)
412 return false;
413
414 return bool.Parse(ret["RESULT"].ToString());
415 }
416
417 public InventoryItemBase GetItem(InventoryItemBase item)
418 {
419 try
420 {
421 Dictionary<string, object> ret = MakeRequest("GETITEM",
422 new Dictionary<string, object> {
423 { "ID", item.ID.ToString() }
424 });
425
426 if (ret == null)
427 return null;
428 if (ret.Count == 0)
429 return null;
430
431 return BuildItem((Dictionary<string, object>)ret["item"]);
432 }
433 catch (Exception e)
434 {
435 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetItem: {0}", e.Message);
436 }
437
438 return null;
439 }
440
441 public InventoryFolderBase GetFolder(InventoryFolderBase folder)
442 {
443 try
444 {
445 Dictionary<string, object> ret = MakeRequest("GETFOLDER",
446 new Dictionary<string, object> {
447 { "ID", folder.ID.ToString() }
448 });
449
450 if (ret == null)
451 return null;
452 if (ret.Count == 0)
453 return null;
454
455 return BuildFolder((Dictionary<string, object>)ret["folder"]);
456 }
457 catch (Exception e)
458 {
459 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetFolder: {0}", e.Message);
460 }
461
462 return null;
463 }
464
465 public List<InventoryItemBase> GetActiveGestures(UUID principalID)
466 {
467 Dictionary<string,object> ret = MakeRequest("GETACTIVEGESTURES",
468 new Dictionary<string,object> {
469 { "PRINCIPAL", principalID.ToString() }
470 });
471
472 if (ret == null)
473 return null;
474
475 List<InventoryItemBase> items = new List<InventoryItemBase>();
476
477 foreach (Object o in ret.Values) // getting the values directly, we don't care about the keys item_i
478 items.Add(BuildItem((Dictionary<string, object>)o));
479
480 return items;
481 }
482
483 public int GetAssetPermissions(UUID principalID, UUID assetID)
484 {
485 Dictionary<string,object> ret = MakeRequest("GETASSETPERMISSIONS",
486 new Dictionary<string,object> {
487 { "PRINCIPAL", principalID.ToString() },
488 { "ASSET", assetID.ToString() }
489 });
490
491 if (ret == null)
492 return 0;
493
494 return int.Parse(ret["RESULT"].ToString());
495 }
496
497 public InventoryCollection GetUserInventory(UUID principalID)
498 {
499 InventoryCollection inventory = new InventoryCollection();
500 inventory.Folders = new List<InventoryFolderBase>();
501 inventory.Items = new List<InventoryItemBase>();
502 inventory.UserID = principalID;
503
504 try
505 {
506 Dictionary<string, object> ret = MakeRequest("GETUSERINVENTORY",
507 new Dictionary<string, object> {
508 { "PRINCIPAL", principalID.ToString() }
509 });
510
511 if (ret == null)
512 return null;
513 if (ret.Count == 0)
514 return null;
515
516 Dictionary<string, object> folders =
517 (Dictionary<string, object>)ret["FOLDERS"];
518 Dictionary<string, object> items =
519 (Dictionary<string, object>)ret["ITEMS"];
520
521 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
522 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
523 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
524 inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
525 }
526 catch (Exception e)
527 {
528 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetUserInventory: {0}", e.Message);
529 }
530
531 return inventory;
532 }
533
534 public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback)
535 {
536 }
537
538 public bool HasInventoryForUser(UUID principalID)
539 {
540 return false;
541 }
542
543 // Helpers
544 //
545 private Dictionary<string,object> MakeRequest(string method,
546 Dictionary<string,object> sendData)
547 {
548 sendData["METHOD"] = method;
549
550 string reply = string.Empty;
551 lock (m_Lock)
552 reply = SynchronousRestFormsRequester.MakeRequest("POST",
553 m_ServerURI + "/xinventory",
554 ServerUtils.BuildQueryString(sendData));
555
556 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
557 reply);
558
559 return replyData;
560 }
561
562 private InventoryFolderBase BuildFolder(Dictionary<string,object> data)
563 {
564 InventoryFolderBase folder = new InventoryFolderBase();
565
566 try
567 {
568 folder.ParentID = new UUID(data["ParentID"].ToString());
569 folder.Type = short.Parse(data["Type"].ToString());
570 folder.Version = ushort.Parse(data["Version"].ToString());
571 folder.Name = data["Name"].ToString();
572 folder.Owner = new UUID(data["Owner"].ToString());
573 folder.ID = new UUID(data["ID"].ToString());
574 }
575 catch (Exception e)
576 {
577 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception building folder: {0}", e.Message);
578 }
579
580 return folder;
581 }
582
583 private InventoryItemBase BuildItem(Dictionary<string,object> data)
584 {
585 InventoryItemBase item = new InventoryItemBase();
586
587 try
588 {
589 item.AssetID = new UUID(data["AssetID"].ToString());
590 item.AssetType = int.Parse(data["AssetType"].ToString());
591 item.Name = data["Name"].ToString();
592 item.Owner = new UUID(data["Owner"].ToString());
593 item.ID = new UUID(data["ID"].ToString());
594 item.InvType = int.Parse(data["InvType"].ToString());
595 item.Folder = new UUID(data["Folder"].ToString());
596 item.CreatorId = data["CreatorId"].ToString();
597 if (data.ContainsKey("CreatorData"))
598 item.CreatorData = data["CreatorData"].ToString();
599 else
600 item.CreatorData = String.Empty;
601 item.Description = data["Description"].ToString();
602 item.NextPermissions = uint.Parse(data["NextPermissions"].ToString());
603 item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString());
604 item.BasePermissions = uint.Parse(data["BasePermissions"].ToString());
605 item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString());
606 item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString());
607 item.GroupID = new UUID(data["GroupID"].ToString());
608 item.GroupOwned = bool.Parse(data["GroupOwned"].ToString());
609 item.SalePrice = int.Parse(data["SalePrice"].ToString());
610 item.SaleType = byte.Parse(data["SaleType"].ToString());
611 item.Flags = uint.Parse(data["Flags"].ToString());
612 item.CreationDate = int.Parse(data["CreationDate"].ToString());
613 }
614 catch (Exception e)
615 {
616 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception building item: {0}", e.Message);
617 }
618
619 return item;
620 }
621
622 }
623}