29 using System.Reflection;
32 using System.Collections.Generic;
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;
44 using System.Threading;
46 namespace OpenSim.Server.Handlers.Inventory
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 private string m_ConfigName =
"InventoryService";
56 base(config, server, configName)
58 if (configName != String.Empty)
59 m_ConfigName = configName;
61 m_log.DebugFormat(
"[XInventoryInConnector]: Starting with config name {0}", m_ConfigName);
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));
67 string inventoryService = serverConfig.GetString(
"LocalServiceModule",
70 if (inventoryService == String.Empty)
71 throw new Exception(
"No InventoryService in config file");
73 Object[] args =
new Object[] { config, m_ConfigName };
77 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
85 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
90 base(
"POST",
"/xinventory", auth)
92 m_InventoryService = service;
98 StreamReader sr =
new StreamReader(requestData);
99 string body = sr.ReadToEnd();
107 Dictionary<string, object> request =
108 ServerUtils.ParseQueryString(body);
110 if (!request.ContainsKey(
"METHOD"))
111 return FailureResult();
113 string method = request[
"METHOD"].ToString();
114 request.Remove(
"METHOD");
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);
133 return HandleAddFolder(request);
135 return HandleUpdateFolder(request);
137 return HandleMoveFolder(request);
138 case "DELETEFOLDERS":
139 return HandleDeleteFolders(request);
141 return HandlePurgeFolder(request);
143 return HandleAddItem(request);
145 return HandleUpdateItem(request);
147 return HandleMoveItems(request);
149 return HandleDeleteItems(request);
151 return HandleGetItem(request);
152 case "GETMULTIPLEITEMS":
153 return HandleGetMultipleItems(request);
155 return HandleGetFolder(request);
156 case "GETACTIVEGESTURES":
157 return HandleGetActiveGestures(request);
158 case "GETASSETPERMISSIONS":
159 return HandleGetAssetPermissions(request);
161 m_log.DebugFormat(
"[XINVENTORY HANDLER]: unknown method request: {0}", method);
165 m_log.Error(string.Format(
"[XINVENTORY HANDLER]: Exception {0} ", e.Message), e);
168 return FailureResult();
171 private byte[] FailureResult()
173 return BoolResult(
false);
176 private byte[] SuccessResult()
178 return BoolResult(
true);
181 private byte[] BoolResult(
bool value)
183 XmlDocument doc =
new XmlDocument();
185 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
188 doc.AppendChild(xmlnode);
190 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
193 doc.AppendChild(rootElement);
195 XmlElement result = doc.CreateElement(
"",
"RESULT",
"");
196 result.AppendChild(doc.CreateTextNode(value.ToString()));
198 rootElement.AppendChild(result);
200 return Util.DocToBytes(doc);
203 byte[] HandleCreateUserInventory(Dictionary<string,object> request)
205 Dictionary<string,object> result =
new Dictionary<string,object>();
207 if (!request.ContainsKey(
"PRINCIPAL"))
208 return FailureResult();
210 if (m_InventoryService.CreateUserInventory(
new UUID(request[
"PRINCIPAL"].ToString())))
211 result[
"RESULT"] =
"True";
213 result[
"RESULT"] =
"False";
215 string xmlString = ServerUtils.BuildXmlResponse(result);
218 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
221 byte[] HandleGetInventorySkeleton(Dictionary<string,object> request)
223 Dictionary<string,object> result =
new Dictionary<string,object>();
225 if (!request.ContainsKey(
"PRINCIPAL"))
226 return FailureResult();
229 List<InventoryFolderBase> folders = m_InventoryService.GetInventorySkeleton(
new UUID(request[
"PRINCIPAL"].ToString()));
231 Dictionary<string, object> sfolders =
new Dictionary<string, object>();
237 sfolders[
"folder_" + i.ToString()] = EncodeFolder(f);
241 result[
"FOLDERS"] = sfolders;
243 string xmlString = ServerUtils.BuildXmlResponse(result);
246 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
249 byte[] HandleGetRootFolder(Dictionary<string,object> request)
251 Dictionary<string,object> result =
new Dictionary<string,object>();
253 UUID principal = UUID.Zero;
254 UUID.TryParse(request[
"PRINCIPAL"].ToString(), out principal);
257 result[
"folder"] = EncodeFolder(rfolder);
259 string xmlString = ServerUtils.BuildXmlResponse(result);
262 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
265 byte[] HandleGetFolderForType(Dictionary<string,object> request)
267 Dictionary<string,object> result =
new Dictionary<string,object>();
268 UUID principal = UUID.Zero;
269 UUID.TryParse(request[
"PRINCIPAL"].ToString(), out principal);
271 Int32.TryParse(request[
"TYPE"].ToString(), out type);
272 InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (FolderType)type);
274 result[
"folder"] = EncodeFolder(folder);
276 string xmlString = ServerUtils.BuildXmlResponse(result);
279 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
282 byte[] HandleGetFolderContent(Dictionary<string,object> request)
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);
293 result[
"FID"] = icoll.FolderID.ToString();
294 result[
"VERSION"] = icoll.Version.ToString();
295 Dictionary<string, object> folders =
new Dictionary<string, object>();
301 folders[
"folder_" + i.ToString()] = EncodeFolder(f);
304 result[
"FOLDERS"] = folders;
306 if (icoll.
Items != null)
309 Dictionary<string, object> items =
new Dictionary<string, object>();
312 items[
"item_" + i.ToString()] = EncodeItem(it);
315 result[
"ITEMS"] = items;
319 string xmlString = ServerUtils.BuildXmlResponse(result);
322 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
325 byte[] HandleGetMultipleFoldersContent(Dictionary<string, object> request)
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();
332 Int32.TryParse(request[
"COUNT"].ToString(), out count);
335 string[] uuids = folderIDstr.Split(
',');
337 foreach (
string id in uuids)
339 UUID fid = UUID.Zero;
340 if (
UUID.TryParse(
id, out fid))
346 InventoryCollection[] icollList = m_InventoryService.GetMultipleFoldersContent(principal, fids);
347 if (icollList != null && icollList.Length > 0)
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>();
361 folders[
"folder_" + i.ToString()] = EncodeFolder(f);
364 result[
"FOLDERS"] = folders;
367 if (icoll.
Items != null)
369 Dictionary<string, object> items =
new Dictionary<string, object>();
372 items[
"item_" + i.ToString()] = EncodeItem(it);
375 result[
"ITEMS"] = items;
378 resultSet[
"F_" + fids[count++]] = result;
383 string xmlString = ServerUtils.BuildXmlResponse(resultSet);
386 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
389 byte[] HandleGetFolderItems(Dictionary<string, object> request)
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);
397 List<InventoryItemBase> items = m_InventoryService.GetFolderItems(principal, folderID);
398 Dictionary<string, object> sitems =
new Dictionary<string, object>();
405 sitems[
"item_" + i.ToString()] = EncodeItem(item);
409 result[
"ITEMS"] = sitems;
411 string xmlString = ServerUtils.BuildXmlResponse(result);
414 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
417 byte[] HandleAddFolder(Dictionary<string,object> request)
421 if (m_InventoryService.AddFolder(folder))
422 return SuccessResult();
424 return FailureResult();
427 byte[] HandleUpdateFolder(Dictionary<string,object> request)
431 if (m_InventoryService.UpdateFolder(folder))
432 return SuccessResult();
434 return FailureResult();
437 byte[] HandleMoveFolder(Dictionary<string,object> request)
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);
447 if (m_InventoryService.MoveFolder(folder))
448 return SuccessResult();
450 return FailureResult();
454 byte[] HandleDeleteFolders(Dictionary<string,object> request)
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)
463 if (
UUID.TryParse(s, out u))
467 if (m_InventoryService.DeleteFolders(principal, uuids))
468 return SuccessResult();
474 byte[] HandlePurgeFolder(Dictionary<string,object> request)
476 UUID folderID = UUID.Zero;
477 UUID.TryParse(request[
"ID"].ToString(), out folderID);
480 if (m_InventoryService.PurgeFolder(folder))
481 return SuccessResult();
483 return FailureResult();
486 byte[] HandleAddItem(Dictionary<string,object> request)
490 if (m_InventoryService.AddItem(item))
491 return SuccessResult();
493 return FailureResult();
496 byte[] HandleUpdateItem(Dictionary<string,object> request)
500 if (m_InventoryService.UpdateItem(item))
501 return SuccessResult();
503 return FailureResult();
506 byte[] HandleMoveItems(Dictionary<string,object> request)
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);
513 List<InventoryItemBase> items =
new List<InventoryItemBase>();
517 foreach (
string s
in idlist)
520 if (
UUID.TryParse(s, out u))
522 UUID fid = UUID.Zero;
523 if (
UUID.TryParse(destlist[n++], out fid))
534 m_log.DebugFormat(
"[XINVENTORY IN CONNECTOR]: Exception in HandleMoveItems: {0}", e.Message);
535 return FailureResult();
538 if (m_InventoryService.MoveItems(principal, items))
539 return SuccessResult();
541 return FailureResult();
544 byte[] HandleDeleteItems(Dictionary<string,object> request)
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)
553 if (
UUID.TryParse(s, out u))
557 if (m_InventoryService.DeleteItems(principal, uuids))
558 return SuccessResult();
564 byte[] HandleGetItem(Dictionary<string,object> request)
566 Dictionary<string,object> result =
new Dictionary<string,object>();
568 UUID.TryParse(request[
"ID"].ToString(), out
id);
571 item = m_InventoryService.GetItem(item);
573 result[
"item"] = EncodeItem(item);
575 string xmlString = ServerUtils.BuildXmlResponse(result);
578 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
581 byte[] HandleGetMultipleItems(Dictionary<string, object> request)
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();
588 Int32.TryParse(request[
"COUNT"].ToString(), out count);
591 string[] uuids = itemIDstr.Split(
',');
593 foreach (
string id in uuids)
595 UUID fid = UUID.Zero;
596 if (
UUID.TryParse(
id, out fid))
601 InventoryItemBase[] itemsList = m_InventoryService.GetMultipleItems(principal, fids);
602 if (itemsList != null && itemsList.Length > 0)
606 resultSet[
"item_" + count++] = (item == null) ? (
object)
"NULL" : EncodeItem(item);
609 string xmlString = ServerUtils.BuildXmlResponse(resultSet);
612 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
615 byte[] HandleGetFolder(Dictionary<string,object> request)
617 Dictionary<string, object> result =
new Dictionary<string, object>();
619 UUID.TryParse(request[
"ID"].ToString(), out
id);
622 folder = m_InventoryService.GetFolder(folder);
624 result[
"folder"] = EncodeFolder(folder);
626 string xmlString = ServerUtils.BuildXmlResponse(result);
629 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
632 byte[] HandleGetActiveGestures(Dictionary<string,object> request)
634 Dictionary<string,object> result =
new Dictionary<string,object>();
635 UUID principal = UUID.Zero;
636 UUID.TryParse(request[
"PRINCIPAL"].ToString(), out principal);
638 List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(principal);
639 Dictionary<string, object> items =
new Dictionary<string, object>();
640 if (gestures != null)
645 items[
"item_" + i.ToString()] = EncodeItem(item);
649 result[
"ITEMS"] = items;
651 string xmlString = ServerUtils.BuildXmlResponse(result);
654 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
657 byte[] HandleGetAssetPermissions(Dictionary<string,object> request)
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);
665 int perms = m_InventoryService.GetAssetPermissions(principal, assetID);
667 result[
"RESULT"] = perms.ToString();
668 string xmlString = ServerUtils.BuildXmlResponse(result);
671 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
676 Dictionary<string, object> ret =
new Dictionary<string, object>();
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();
690 Dictionary<string, object> ret =
new Dictionary<string, object>();
692 ret[
"AssetID"] = item.AssetID.ToString();
693 ret[
"AssetType"] = item.AssetType.ToString();
694 ret[
"BasePermissions"] = item.BasePermissions.ToString();
695 ret[
"CreationDate"] = item.CreationDate.ToString();
697 ret[
"CreatorId"] = item.CreatorId.ToString();
699 ret[
"CreatorId"] = String.Empty;
701 ret[
"CreatorData"] = item.CreatorData;
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();
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());
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());
Base streamed request handler.
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
List< InventoryItemBase > Items
Inventory Item - contains all the properties associated with an individual inventory piece...
string CreatorData
Extended creator information of the form <profile url>="">;<name>
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
XInventoryConnectorPostHandler(IInventoryService service, IServiceAuth auth)
XInventoryInConnector(IConfigSource config, IHttpServer server, string configName)
List< InventoryFolderBase > Folders
Used to serialize a whole inventory for transfer over the network.