aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Inventory
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Services/Connectors/Inventory
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Services/Connectors/Inventory')
-rw-r--r--OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs405
1 files changed, 277 insertions, 128 deletions
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs
index 44f5e01..7cecd93 100644
--- a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs
@@ -33,22 +33,37 @@ using System.Reflection;
33using Nini.Config; 33using Nini.Config;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Framework.Communications; 36
37using OpenSim.Framework.Monitoring;
37using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
38using OpenSim.Server.Base; 39using OpenSim.Server.Base;
39using OpenMetaverse; 40using OpenMetaverse;
40 41
41namespace OpenSim.Services.Connectors 42namespace OpenSim.Services.Connectors
42{ 43{
43 public class XInventoryServicesConnector : IInventoryService 44 public class XInventoryServicesConnector : BaseServiceConnector, IInventoryService
44 { 45 {
45 private static readonly ILog m_log = 46 private static readonly ILog m_log =
46 LogManager.GetLogger( 47 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType); 48 MethodBase.GetCurrentMethod().DeclaringType);
48 49
50 /// <summary>
51 /// Number of requests made to the remote inventory service.
52 /// </summary>
53 public int RequestsMade { get; private set; }
54
49 private string m_ServerURI = String.Empty; 55 private string m_ServerURI = String.Empty;
50 56
51 private object m_Lock = new object(); 57 /// <summary>
58 /// Timeout for remote requests.
59 /// </summary>
60 /// <remarks>
61 /// In this case, -1 is default timeout (100 seconds), not infinite.
62 /// </remarks>
63 private int m_requestTimeoutSecs = -1;
64
65 private const double CACHE_EXPIRATION_SECONDS = 20.0;
66 private static ExpiringCache<UUID, InventoryItemBase> m_ItemCache = new ExpiringCache<UUID,InventoryItemBase>();
52 67
53 public XInventoryServicesConnector() 68 public XInventoryServicesConnector()
54 { 69 {
@@ -60,20 +75,21 @@ namespace OpenSim.Services.Connectors
60 } 75 }
61 76
62 public XInventoryServicesConnector(IConfigSource source) 77 public XInventoryServicesConnector(IConfigSource source)
78 : base(source, "InventoryService")
63 { 79 {
64 Initialise(source); 80 Initialise(source);
65 } 81 }
66 82
67 public virtual void Initialise(IConfigSource source) 83 public virtual void Initialise(IConfigSource source)
68 { 84 {
69 IConfig assetConfig = source.Configs["InventoryService"]; 85 IConfig config = source.Configs["InventoryService"];
70 if (assetConfig == null) 86 if (config == null)
71 { 87 {
72 m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); 88 m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
73 throw new Exception("Inventory connector init error"); 89 throw new Exception("Inventory connector init error");
74 } 90 }
75 91
76 string serviceURI = assetConfig.GetString("InventoryServerURI", 92 string serviceURI = config.GetString("InventoryServerURI",
77 String.Empty); 93 String.Empty);
78 94
79 if (serviceURI == String.Empty) 95 if (serviceURI == String.Empty)
@@ -82,6 +98,45 @@ namespace OpenSim.Services.Connectors
82 throw new Exception("Inventory connector init error"); 98 throw new Exception("Inventory connector init error");
83 } 99 }
84 m_ServerURI = serviceURI; 100 m_ServerURI = serviceURI;
101
102 m_requestTimeoutSecs = config.GetInt("RemoteRequestTimeout", m_requestTimeoutSecs);
103
104 StatsManager.RegisterStat(
105 new Stat(
106 "RequestsMade",
107 "Requests made",
108 "Number of requests made to the remove inventory service",
109 "requests",
110 "inventory",
111 serviceURI,
112 StatType.Pull,
113 MeasuresOfInterest.AverageChangeOverTime,
114 s => s.Value = RequestsMade,
115 StatVerbosity.Debug));
116 }
117
118 private bool CheckReturn(Dictionary<string, object> ret)
119 {
120 if (ret == null)
121 return false;
122
123 if (ret.Count == 0)
124 return false;
125
126 if (ret.ContainsKey("RESULT"))
127 {
128 if (ret["RESULT"] is string)
129 {
130 bool result;
131
132 if (bool.TryParse((string)ret["RESULT"], out result))
133 return result;
134
135 return false;
136 }
137 }
138
139 return true;
85 } 140 }
86 141
87 public bool CreateUserInventory(UUID principalID) 142 public bool CreateUserInventory(UUID principalID)
@@ -91,12 +146,7 @@ namespace OpenSim.Services.Connectors
91 { "PRINCIPAL", principalID.ToString() } 146 { "PRINCIPAL", principalID.ToString() }
92 }); 147 });
93 148
94 if (ret == null) 149 return CheckReturn(ret);
95 return false;
96 if (ret.Count == 0)
97 return false;
98
99 return bool.Parse(ret["RESULT"].ToString());
100 } 150 }
101 151
102 public List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) 152 public List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
@@ -106,9 +156,7 @@ namespace OpenSim.Services.Connectors
106 { "PRINCIPAL", principalID.ToString() } 156 { "PRINCIPAL", principalID.ToString() }
107 }); 157 });
108 158
109 if (ret == null) 159 if (!CheckReturn(ret))
110 return null;
111 if (ret.Count == 0)
112 return null; 160 return null;
113 161
114 Dictionary<string, object> folders = (Dictionary<string, object>)ret["FOLDERS"]; 162 Dictionary<string, object> folders = (Dictionary<string, object>)ret["FOLDERS"];
@@ -135,15 +183,13 @@ namespace OpenSim.Services.Connectors
135 { "PRINCIPAL", principalID.ToString() } 183 { "PRINCIPAL", principalID.ToString() }
136 }); 184 });
137 185
138 if (ret == null) 186 if (!CheckReturn(ret))
139 return null;
140 if (ret.Count == 0)
141 return null; 187 return null;
142 188
143 return BuildFolder((Dictionary<string, object>)ret["folder"]); 189 return BuildFolder((Dictionary<string, object>)ret["folder"]);
144 } 190 }
145 191
146 public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) 192 public InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
147 { 193 {
148 Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE", 194 Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE",
149 new Dictionary<string,object> { 195 new Dictionary<string,object> {
@@ -151,9 +197,7 @@ namespace OpenSim.Services.Connectors
151 { "TYPE", ((int)type).ToString() } 197 { "TYPE", ((int)type).ToString() }
152 }); 198 });
153 199
154 if (ret == null) 200 if (!CheckReturn(ret))
155 return null;
156 if (ret.Count == 0)
157 return null; 201 return null;
158 202
159 return BuildFolder((Dictionary<string, object>)ret["folder"]); 203 return BuildFolder((Dictionary<string, object>)ret["folder"]);
@@ -164,7 +208,7 @@ namespace OpenSim.Services.Connectors
164 InventoryCollection inventory = new InventoryCollection(); 208 InventoryCollection inventory = new InventoryCollection();
165 inventory.Folders = new List<InventoryFolderBase>(); 209 inventory.Folders = new List<InventoryFolderBase>();
166 inventory.Items = new List<InventoryItemBase>(); 210 inventory.Items = new List<InventoryItemBase>();
167 inventory.UserID = principalID; 211 inventory.OwnerID = principalID;
168 212
169 try 213 try
170 { 214 {
@@ -174,20 +218,20 @@ namespace OpenSim.Services.Connectors
174 { "FOLDER", folderID.ToString() } 218 { "FOLDER", folderID.ToString() }
175 }); 219 });
176 220
177 if (ret == null) 221 if (!CheckReturn(ret))
178 return null;
179 if (ret.Count == 0)
180 return null; 222 return null;
181 223
182 Dictionary<string,object> folders = 224 Dictionary<string,object> folders = ret.ContainsKey("FOLDERS") ?
183 (Dictionary<string,object>)ret["FOLDERS"]; 225 (Dictionary<string,object>)ret["FOLDERS"] : null;
184 Dictionary<string,object> items = 226 Dictionary<string,object> items = ret.ContainsKey("ITEMS") ?
185 (Dictionary<string,object>)ret["ITEMS"]; 227 (Dictionary<string, object>)ret["ITEMS"] : null;
186 228
187 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i 229 if (folders != null)
188 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o)); 230 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
189 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i 231 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
190 inventory.Items.Add(BuildItem((Dictionary<string, object>)o)); 232 if (items != null)
233 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
234 inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
191 } 235 }
192 catch (Exception e) 236 catch (Exception e)
193 { 237 {
@@ -196,6 +240,87 @@ namespace OpenSim.Services.Connectors
196 240
197 return inventory; 241 return inventory;
198 } 242 }
243
244 public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
245 {
246 InventoryCollection[] inventoryArr = new InventoryCollection[folderIDs.Length];
247 // m_log.DebugFormat("[XXX]: In GetMultipleFoldersContent {0}", String.Join(",", folderIDs));
248 try
249 {
250 Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEFOLDERSCONTENT",
251 new Dictionary<string, object> {
252 { "PRINCIPAL", principalID.ToString() },
253 { "FOLDERS", String.Join(",", folderIDs) },
254 { "COUNT", folderIDs.Length.ToString() }
255 });
256
257 if (!CheckReturn(resultSet))
258 return null;
259
260 int i = 0;
261 foreach (KeyValuePair<string, object> kvp in resultSet)
262 {
263 InventoryCollection inventory = new InventoryCollection();
264 if (kvp.Key.StartsWith("F_"))
265 {
266 UUID fid = UUID.Zero;
267 if (UUID.TryParse(kvp.Key.Substring(2), out fid) && fid == folderIDs[i])
268 {
269 inventory.Folders = new List<InventoryFolderBase>();
270 inventory.Items = new List<InventoryItemBase>();
271
272 Dictionary<string, object> ret = (Dictionary<string, object>)kvp.Value;
273
274 if (ret.ContainsKey("FID"))
275 {
276 if (!UUID.TryParse(ret["FID"].ToString(), out inventory.FolderID))
277 m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Could not parse folder id {0}", ret["FID"].ToString());
278 }
279 else
280 m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: FID key not present in response");
281
282 inventory.Version = -1;
283 if (ret.ContainsKey("VERSION"))
284 Int32.TryParse(ret["VERSION"].ToString(), out inventory.Version);
285 if (ret.ContainsKey("OWNER"))
286 UUID.TryParse(ret["OWNER"].ToString(), out inventory.OwnerID);
287
288 //m_log.DebugFormat("[XXX]: Received {0} ({1}) {2} {3}", inventory.FolderID, fid, inventory.Version, inventory.OwnerID);
289
290 Dictionary<string, object> folders =
291 (Dictionary<string, object>)ret["FOLDERS"];
292 Dictionary<string, object> items =
293 (Dictionary<string, object>)ret["ITEMS"];
294
295 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
296 {
297 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
298 }
299 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
300 {
301 inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
302 }
303
304 inventoryArr[i] = inventory;
305 }
306 else
307 {
308 m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Folder id does not match. Expected {0} got {1}",
309 folderIDs[i], fid);
310 m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: {0} {1}", String.Join(",", folderIDs), String.Join(",", resultSet.Keys));
311 }
312
313 i += 1;
314 }
315 }
316 }
317 catch (Exception e)
318 {
319 m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleFoldersContent: {0}", e.Message);
320 }
321
322 return inventoryArr;
323 }
199 324
200 public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) 325 public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
201 { 326 {
@@ -205,9 +330,7 @@ namespace OpenSim.Services.Connectors
205 { "FOLDER", folderID.ToString() } 330 { "FOLDER", folderID.ToString() }
206 }); 331 });
207 332
208 if (ret == null) 333 if (!CheckReturn(ret))
209 return null;
210 if (ret.Count == 0)
211 return null; 334 return null;
212 335
213 Dictionary<string, object> items = (Dictionary<string, object>)ret["ITEMS"]; 336 Dictionary<string, object> items = (Dictionary<string, object>)ret["ITEMS"];
@@ -230,10 +353,7 @@ namespace OpenSim.Services.Connectors
230 { "ID", folder.ID.ToString() } 353 { "ID", folder.ID.ToString() }
231 }); 354 });
232 355
233 if (ret == null) 356 return CheckReturn(ret);
234 return false;
235
236 return bool.Parse(ret["RESULT"].ToString());
237 } 357 }
238 358
239 public bool UpdateFolder(InventoryFolderBase folder) 359 public bool UpdateFolder(InventoryFolderBase folder)
@@ -248,10 +368,7 @@ namespace OpenSim.Services.Connectors
248 { "ID", folder.ID.ToString() } 368 { "ID", folder.ID.ToString() }
249 }); 369 });
250 370
251 if (ret == null) 371 return CheckReturn(ret);
252 return false;
253
254 return bool.Parse(ret["RESULT"].ToString());
255 } 372 }
256 373
257 public bool MoveFolder(InventoryFolderBase folder) 374 public bool MoveFolder(InventoryFolderBase folder)
@@ -263,10 +380,7 @@ namespace OpenSim.Services.Connectors
263 { "PRINCIPAL", folder.Owner.ToString() } 380 { "PRINCIPAL", folder.Owner.ToString() }
264 }); 381 });
265 382
266 if (ret == null) 383 return CheckReturn(ret);
267 return false;
268
269 return bool.Parse(ret["RESULT"].ToString());
270 } 384 }
271 385
272 public bool DeleteFolders(UUID principalID, List<UUID> folderIDs) 386 public bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
@@ -282,10 +396,7 @@ namespace OpenSim.Services.Connectors
282 { "FOLDERS", slist } 396 { "FOLDERS", slist }
283 }); 397 });
284 398
285 if (ret == null) 399 return CheckReturn(ret);
286 return false;
287
288 return bool.Parse(ret["RESULT"].ToString());
289 } 400 }
290 401
291 public bool PurgeFolder(InventoryFolderBase folder) 402 public bool PurgeFolder(InventoryFolderBase folder)
@@ -295,17 +406,18 @@ namespace OpenSim.Services.Connectors
295 { "ID", folder.ID.ToString() } 406 { "ID", folder.ID.ToString() }
296 }); 407 });
297 408
298 if (ret == null) 409 return CheckReturn(ret);
299 return false;
300
301 return bool.Parse(ret["RESULT"].ToString());
302 } 410 }
303 411
304 public bool AddItem(InventoryItemBase item) 412 public bool AddItem(InventoryItemBase item)
305 { 413 {
414 if (item.Description == null)
415 item.Description = String.Empty;
306 if (item.CreatorData == null) 416 if (item.CreatorData == null)
307 item.CreatorData = String.Empty; 417 item.CreatorData = String.Empty;
308 Dictionary<string,object> ret = MakeRequest("ADDITEM", 418 if (item.CreatorId == null)
419 item.CreatorId = String.Empty;
420 Dictionary<string, object> ret = MakeRequest("ADDITEM",
309 new Dictionary<string,object> { 421 new Dictionary<string,object> {
310 { "AssetID", item.AssetID.ToString() }, 422 { "AssetID", item.AssetID.ToString() },
311 { "AssetType", item.AssetType.ToString() }, 423 { "AssetType", item.AssetType.ToString() },
@@ -330,10 +442,7 @@ namespace OpenSim.Services.Connectors
330 { "CreationDate", item.CreationDate.ToString() } 442 { "CreationDate", item.CreationDate.ToString() }
331 }); 443 });
332 444
333 if (ret == null) 445 return CheckReturn(ret);
334 return false;
335
336 return bool.Parse(ret["RESULT"].ToString());
337 } 446 }
338 447
339 public bool UpdateItem(InventoryItemBase item) 448 public bool UpdateItem(InventoryItemBase item)
@@ -365,10 +474,13 @@ namespace OpenSim.Services.Connectors
365 { "CreationDate", item.CreationDate.ToString() } 474 { "CreationDate", item.CreationDate.ToString() }
366 }); 475 });
367 476
368 if (ret == null) 477 bool result = CheckReturn(ret);
369 return false; 478 if (result)
479 {
480 m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS);
481 }
370 482
371 return bool.Parse(ret["RESULT"].ToString()); 483 return result;
372 } 484 }
373 485
374 public bool MoveItems(UUID principalID, List<InventoryItemBase> items) 486 public bool MoveItems(UUID principalID, List<InventoryItemBase> items)
@@ -389,10 +501,7 @@ namespace OpenSim.Services.Connectors
389 { "DESTLIST", destlist } 501 { "DESTLIST", destlist }
390 }); 502 });
391 503
392 if (ret == null) 504 return CheckReturn(ret);
393 return false;
394
395 return bool.Parse(ret["RESULT"].ToString());
396 } 505 }
397 506
398 public bool DeleteItems(UUID principalID, List<UUID> itemIDs) 507 public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
@@ -408,14 +517,17 @@ namespace OpenSim.Services.Connectors
408 { "ITEMS", slist } 517 { "ITEMS", slist }
409 }); 518 });
410 519
411 if (ret == null) 520 return CheckReturn(ret);
412 return false;
413
414 return bool.Parse(ret["RESULT"].ToString());
415 } 521 }
416 522
417 public InventoryItemBase GetItem(InventoryItemBase item) 523 public InventoryItemBase GetItem(InventoryItemBase item)
418 { 524 {
525 InventoryItemBase retrieved = null;
526 if (m_ItemCache.TryGetValue(item.ID, out retrieved))
527 {
528 return retrieved;
529 }
530
419 try 531 try
420 { 532 {
421 Dictionary<string, object> ret = MakeRequest("GETITEM", 533 Dictionary<string, object> ret = MakeRequest("GETITEM",
@@ -423,19 +535,81 @@ namespace OpenSim.Services.Connectors
423 { "ID", item.ID.ToString() } 535 { "ID", item.ID.ToString() }
424 }); 536 });
425 537
426 if (ret == null) 538 if (!CheckReturn(ret))
427 return null;
428 if (ret.Count == 0)
429 return null; 539 return null;
430 540
431 return BuildItem((Dictionary<string, object>)ret["item"]); 541 retrieved = BuildItem((Dictionary<string, object>)ret["item"]);
432 } 542 }
433 catch (Exception e) 543 catch (Exception e)
434 { 544 {
435 m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); 545 m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e);
436 } 546 }
437 547
438 return null; 548 m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS);
549
550 return retrieved;
551 }
552
553 public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
554 {
555 //m_log.DebugFormat("[XXX]: In GetMultipleItems {0}", String.Join(",", itemIDs));
556
557 InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length];
558 // Try to get them from the cache
559 List<UUID> pending = new List<UUID>();
560 InventoryItemBase item = null;
561 int i = 0;
562 foreach (UUID id in itemIDs)
563 {
564 if (m_ItemCache.TryGetValue(id, out item))
565 itemArr[i++] = item;
566 else
567 pending.Add(id);
568 }
569
570 if (pending.Count == 0) // we're done, everything was in the cache
571 return itemArr;
572
573 try
574 {
575 Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS",
576 new Dictionary<string, object> {
577 { "PRINCIPAL", principalID.ToString() },
578 { "ITEMS", String.Join(",", pending.ToArray()) },
579 { "COUNT", pending.Count.ToString() }
580 });
581
582 if (!CheckReturn(resultSet))
583 {
584 if (i == 0)
585 return null;
586 else
587 return itemArr;
588 }
589
590 // carry over index i where we left above
591 foreach (KeyValuePair<string, object> kvp in resultSet)
592 {
593 InventoryCollection inventory = new InventoryCollection();
594 if (kvp.Key.StartsWith("item_"))
595 {
596 if (kvp.Value is Dictionary<string, object>)
597 {
598 item = BuildItem((Dictionary<string, object>)kvp.Value);
599 m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS);
600 itemArr[i++] = item;
601 }
602 else
603 itemArr[i++] = null;
604 }
605 }
606 }
607 catch (Exception e)
608 {
609 m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleItems: {0}", e.Message);
610 }
611
612 return itemArr;
439 } 613 }
440 614
441 public InventoryFolderBase GetFolder(InventoryFolderBase folder) 615 public InventoryFolderBase GetFolder(InventoryFolderBase folder)
@@ -447,9 +621,7 @@ namespace OpenSim.Services.Connectors
447 { "ID", folder.ID.ToString() } 621 { "ID", folder.ID.ToString() }
448 }); 622 });
449 623
450 if (ret == null) 624 if (!CheckReturn(ret))
451 return null;
452 if (ret.Count == 0)
453 return null; 625 return null;
454 626
455 return BuildFolder((Dictionary<string, object>)ret["folder"]); 627 return BuildFolder((Dictionary<string, object>)ret["folder"]);
@@ -469,7 +641,7 @@ namespace OpenSim.Services.Connectors
469 { "PRINCIPAL", principalID.ToString() } 641 { "PRINCIPAL", principalID.ToString() }
470 }); 642 });
471 643
472 if (ret == null) 644 if (!CheckReturn(ret))
473 return null; 645 return null;
474 646
475 List<InventoryItemBase> items = new List<InventoryItemBase>(); 647 List<InventoryItemBase> items = new List<InventoryItemBase>();
@@ -488,51 +660,22 @@ namespace OpenSim.Services.Connectors
488 { "ASSET", assetID.ToString() } 660 { "ASSET", assetID.ToString() }
489 }); 661 });
490 662
663 // We cannot use CheckReturn() here because valid values for RESULT are "false" (in the case of request failure) or an int
491 if (ret == null) 664 if (ret == null)
492 return 0; 665 return 0;
493 666
494 return int.Parse(ret["RESULT"].ToString()); 667 if (ret.ContainsKey("RESULT"))
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 { 668 {
506 Dictionary<string, object> ret = MakeRequest("GETUSERINVENTORY", 669 if (ret["RESULT"] is string)
507 new Dictionary<string, object> { 670 {
508 { "PRINCIPAL", principalID.ToString() } 671 int intResult;
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 672
521 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i 673 if (int.TryParse ((string)ret["RESULT"], out intResult))
522 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o)); 674 return intResult;
523 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i 675 }
524 inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
525 } 676 }
526 catch (Exception e)
527 {
528 m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetUserInventory: ", e);
529 }
530
531 return inventory;
532 }
533 677
534 public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback) 678 return 0;
535 {
536 } 679 }
537 680
538 public bool HasInventoryForUser(UUID principalID) 681 public bool HasInventoryForUser(UUID principalID)
@@ -545,13 +688,19 @@ namespace OpenSim.Services.Connectors
545 private Dictionary<string,object> MakeRequest(string method, 688 private Dictionary<string,object> MakeRequest(string method,
546 Dictionary<string,object> sendData) 689 Dictionary<string,object> sendData)
547 { 690 {
548 sendData["METHOD"] = method; 691 // Add "METHOD" as the first key in the dictionary. This ensures that it will be
692 // visible even when using partial logging ("debug http all 5").
693 Dictionary<string, object> temp = sendData;
694 sendData = new Dictionary<string,object>{ { "METHOD", method } };
695 foreach (KeyValuePair<string, object> kvp in temp)
696 sendData.Add(kvp.Key, kvp.Value);
697
698 RequestsMade++;
549 699
550 string reply = string.Empty; 700 string reply
551 lock (m_Lock) 701 = SynchronousRestFormsRequester.MakeRequest(
552 reply = SynchronousRestFormsRequester.MakeRequest("POST", 702 "POST", m_ServerURI + "/xinventory",
553 m_ServerURI + "/xinventory", 703 ServerUtils.BuildQueryString(sendData), m_requestTimeoutSecs, m_Auth);
554 ServerUtils.BuildQueryString(sendData));
555 704
556 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( 705 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
557 reply); 706 reply);
@@ -619,4 +768,4 @@ namespace OpenSim.Services.Connectors
619 return item; 768 return item;
620 } 769 }
621 } 770 }
622} \ No newline at end of file 771}