XInventoryInConnector.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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. using System;
  28. using System.Reflection;
  29. using System.Text;
  30. using System.Xml;
  31. using System.Collections.Generic;
  32. using System.IO;
  33. using Nini.Config;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.ServiceAuth;
  36. using OpenSim.Server.Base;
  37. using OpenSim.Services.Interfaces;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Server.Handlers.Base;
  40. using log4net;
  41. using OpenMetaverse;
  42. using System.Threading;
  43. namespace OpenSim.Server.Handlers.Inventory
  44. {
  45. public class XInventoryInConnector : ServiceConnector
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private IInventoryService m_InventoryService;
  49. private string m_ConfigName = "InventoryService";
  50. public XInventoryInConnector(IConfigSource config, IHttpServer server, string configName) :
  51. base(config, server, configName)
  52. {
  53. if (configName != String.Empty)
  54. m_ConfigName = configName;
  55. m_log.DebugFormat("[XInventoryInConnector]: Starting with config name {0}", m_ConfigName);
  56. IConfig serverConfig = config.Configs[m_ConfigName];
  57. if (serverConfig == null)
  58. throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
  59. string inventoryService = serverConfig.GetString("LocalServiceModule",
  60. String.Empty);
  61. if (inventoryService.Length == 0)
  62. throw new Exception("No InventoryService in config file");
  63. Object[] args = new Object[] { config, m_ConfigName };
  64. m_InventoryService =
  65. ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args);
  66. IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
  67. server.AddStreamHandler(new XInventoryConnectorPostHandler(m_InventoryService, auth));
  68. }
  69. }
  70. public class XInventoryConnectorPostHandler : BaseStreamHandler
  71. {
  72. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  73. private IInventoryService m_InventoryService;
  74. public XInventoryConnectorPostHandler(IInventoryService service, IServiceAuth auth) :
  75. base("POST", "/xinventory", auth)
  76. {
  77. m_InventoryService = service;
  78. }
  79. protected override byte[] ProcessRequest(string path, Stream requestData,
  80. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  81. {
  82. string body;
  83. using(StreamReader sr = new StreamReader(requestData))
  84. body = sr.ReadToEnd();
  85. body = body.Trim();
  86. //m_log.DebugFormat("[XXX]: query String: {0}", body);
  87. try
  88. {
  89. Dictionary<string, object> request =
  90. ServerUtils.ParseQueryString(body);
  91. if (!request.ContainsKey("METHOD"))
  92. return FailureResult();
  93. string method = request["METHOD"].ToString();
  94. request.Remove("METHOD");
  95. switch (method)
  96. {
  97. case "CREATEUSERINVENTORY":
  98. return HandleCreateUserInventory(request);
  99. case "GETINVENTORYSKELETON":
  100. return HandleGetInventorySkeleton(request);
  101. case "GETROOTFOLDER":
  102. return HandleGetRootFolder(request);
  103. case "GETFOLDERFORTYPE":
  104. return HandleGetFolderForType(request);
  105. case "GETFOLDERCONTENT":
  106. return HandleGetFolderContent(request);
  107. case "GETMULTIPLEFOLDERSCONTENT":
  108. return HandleGetMultipleFoldersContent(request);
  109. case "GETFOLDERITEMS":
  110. return HandleGetFolderItems(request);
  111. case "ADDFOLDER":
  112. return HandleAddFolder(request);
  113. case "UPDATEFOLDER":
  114. return HandleUpdateFolder(request);
  115. case "MOVEFOLDER":
  116. return HandleMoveFolder(request);
  117. case "DELETEFOLDERS":
  118. return HandleDeleteFolders(request);
  119. case "PURGEFOLDER":
  120. return HandlePurgeFolder(request);
  121. case "ADDITEM":
  122. return HandleAddItem(request);
  123. case "UPDATEITEM":
  124. return HandleUpdateItem(request);
  125. case "MOVEITEMS":
  126. return HandleMoveItems(request);
  127. case "DELETEITEMS":
  128. return HandleDeleteItems(request);
  129. case "GETITEM":
  130. return HandleGetItem(request);
  131. case "GETMULTIPLEITEMS":
  132. return HandleGetMultipleItems(request);
  133. case "GETFOLDER":
  134. return HandleGetFolder(request);
  135. case "GETACTIVEGESTURES":
  136. return HandleGetActiveGestures(request);
  137. case "GETASSETPERMISSIONS":
  138. return HandleGetAssetPermissions(request);
  139. }
  140. m_log.DebugFormat("[XINVENTORY HANDLER]: unknown method request: {0}", method);
  141. }
  142. catch (Exception e)
  143. {
  144. m_log.Error(string.Format("[XINVENTORY HANDLER]: Exception {0} ", e.Message), e);
  145. }
  146. return FailureResult();
  147. }
  148. private byte[] FailureResult()
  149. {
  150. return BoolResult(false);
  151. }
  152. private byte[] SuccessResult()
  153. {
  154. return BoolResult(true);
  155. }
  156. private byte[] BoolResult(bool value)
  157. {
  158. XmlDocument doc = new XmlDocument();
  159. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  160. "", "");
  161. doc.AppendChild(xmlnode);
  162. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  163. "");
  164. doc.AppendChild(rootElement);
  165. XmlElement result = doc.CreateElement("", "RESULT", "");
  166. result.AppendChild(doc.CreateTextNode(value.ToString()));
  167. rootElement.AppendChild(result);
  168. return Util.DocToBytes(doc);
  169. }
  170. byte[] HandleCreateUserInventory(Dictionary<string,object> request)
  171. {
  172. Dictionary<string,object> result = new Dictionary<string,object>();
  173. if (!request.ContainsKey("PRINCIPAL"))
  174. return FailureResult();
  175. if (m_InventoryService.CreateUserInventory(new UUID(request["PRINCIPAL"].ToString())))
  176. result["RESULT"] = "True";
  177. else
  178. result["RESULT"] = "False";
  179. string xmlString = ServerUtils.BuildXmlResponse(result);
  180. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  181. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  182. }
  183. byte[] HandleGetInventorySkeleton(Dictionary<string,object> request)
  184. {
  185. Dictionary<string,object> result = new Dictionary<string,object>();
  186. if (!request.ContainsKey("PRINCIPAL"))
  187. return FailureResult();
  188. List<InventoryFolderBase> folders = m_InventoryService.GetInventorySkeleton(new UUID(request["PRINCIPAL"].ToString()));
  189. Dictionary<string, object> sfolders = new Dictionary<string, object>();
  190. if (folders != null)
  191. {
  192. int i = 0;
  193. foreach (InventoryFolderBase f in folders)
  194. {
  195. sfolders["folder_" + i.ToString()] = EncodeFolder(f);
  196. i++;
  197. }
  198. }
  199. result["FOLDERS"] = sfolders;
  200. string xmlString = ServerUtils.BuildXmlResponse(result);
  201. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  202. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  203. }
  204. byte[] HandleGetRootFolder(Dictionary<string,object> request)
  205. {
  206. Dictionary<string,object> result = new Dictionary<string,object>();
  207. UUID principal = UUID.Zero;
  208. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  209. InventoryFolderBase rfolder = m_InventoryService.GetRootFolder(principal);
  210. if (rfolder != null)
  211. result["folder"] = EncodeFolder(rfolder);
  212. string xmlString = ServerUtils.BuildXmlResponse(result);
  213. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  214. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  215. }
  216. byte[] HandleGetFolderForType(Dictionary<string,object> request)
  217. {
  218. Dictionary<string,object> result = new Dictionary<string,object>();
  219. UUID principal = UUID.Zero;
  220. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  221. int type = 0;
  222. Int32.TryParse(request["TYPE"].ToString(), out type);
  223. InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (FolderType)type);
  224. if (folder != null)
  225. result["folder"] = EncodeFolder(folder);
  226. string xmlString = ServerUtils.BuildXmlResponse(result);
  227. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  228. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  229. }
  230. byte[] HandleGetFolderContent(Dictionary<string,object> request)
  231. {
  232. Dictionary<string,object> result = new Dictionary<string,object>();
  233. UUID principal = UUID.Zero;
  234. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  235. UUID folderID = UUID.Zero;
  236. UUID.TryParse(request["FOLDER"].ToString(), out folderID);
  237. InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID);
  238. if (icoll != null)
  239. {
  240. result["FID"] = icoll.FolderID.ToString();
  241. result["VERSION"] = icoll.Version.ToString();
  242. Dictionary<string, object> folders = new Dictionary<string, object>();
  243. int i = 0;
  244. if (icoll.Folders != null)
  245. {
  246. foreach (InventoryFolderBase f in icoll.Folders)
  247. {
  248. folders["folder_" + i.ToString()] = EncodeFolder(f);
  249. i++;
  250. }
  251. result["FOLDERS"] = folders;
  252. }
  253. if (icoll.Items != null)
  254. {
  255. i = 0;
  256. Dictionary<string, object> items = new Dictionary<string, object>();
  257. foreach (InventoryItemBase it in icoll.Items)
  258. {
  259. items["item_" + i.ToString()] = EncodeItem(it);
  260. i++;
  261. }
  262. result["ITEMS"] = items;
  263. }
  264. }
  265. string xmlString = ServerUtils.BuildXmlResponse(result);
  266. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  267. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  268. }
  269. byte[] HandleGetMultipleFoldersContent(Dictionary<string, object> request)
  270. {
  271. Dictionary<string, object> resultSet = new Dictionary<string, object>();
  272. UUID principal = UUID.Zero;
  273. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  274. string folderIDstr = request["FOLDERS"].ToString();
  275. int count = 0;
  276. Int32.TryParse(request["COUNT"].ToString(), out count);
  277. UUID[] fids = new UUID[count];
  278. string[] uuids = folderIDstr.Split(',');
  279. int i = 0;
  280. foreach (string id in uuids)
  281. {
  282. UUID fid = UUID.Zero;
  283. if (UUID.TryParse(id, out fid))
  284. fids[i] = fid;
  285. i += 1;
  286. }
  287. count = 0;
  288. InventoryCollection[] icollList = m_InventoryService.GetMultipleFoldersContent(principal, fids);
  289. if (icollList != null && icollList.Length > 0)
  290. {
  291. foreach (InventoryCollection icoll in icollList)
  292. {
  293. Dictionary<string, object> result = new Dictionary<string, object>();
  294. result["FID"] = icoll.FolderID.ToString();
  295. result["VERSION"] = icoll.Version.ToString();
  296. result["OWNER"] = icoll.OwnerID.ToString();
  297. Dictionary<string, object> folders = new Dictionary<string, object>();
  298. i = 0;
  299. if (icoll.Folders != null)
  300. {
  301. foreach (InventoryFolderBase f in icoll.Folders)
  302. {
  303. folders["folder_" + i.ToString()] = EncodeFolder(f);
  304. i++;
  305. }
  306. result["FOLDERS"] = folders;
  307. }
  308. i = 0;
  309. if (icoll.Items != null)
  310. {
  311. Dictionary<string, object> items = new Dictionary<string, object>();
  312. foreach (InventoryItemBase it in icoll.Items)
  313. {
  314. items["item_" + i.ToString()] = EncodeItem(it);
  315. i++;
  316. }
  317. result["ITEMS"] = items;
  318. }
  319. resultSet["F_" + fids[count++]] = result;
  320. //m_log.DebugFormat("[XXX]: Sending {0} {1}", fids[count-1], icoll.FolderID);
  321. }
  322. }
  323. string xmlString = ServerUtils.BuildXmlResponse(resultSet);
  324. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  325. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  326. }
  327. byte[] HandleGetFolderItems(Dictionary<string, object> request)
  328. {
  329. Dictionary<string,object> result = new Dictionary<string,object>();
  330. UUID principal = UUID.Zero;
  331. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  332. UUID folderID = UUID.Zero;
  333. UUID.TryParse(request["FOLDER"].ToString(), out folderID);
  334. List<InventoryItemBase> items = m_InventoryService.GetFolderItems(principal, folderID);
  335. Dictionary<string, object> sitems = new Dictionary<string, object>();
  336. if (items != null)
  337. {
  338. int i = 0;
  339. foreach (InventoryItemBase item in items)
  340. {
  341. sitems["item_" + i.ToString()] = EncodeItem(item);
  342. i++;
  343. }
  344. }
  345. result["ITEMS"] = sitems;
  346. string xmlString = ServerUtils.BuildXmlResponse(result);
  347. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  348. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  349. }
  350. byte[] HandleAddFolder(Dictionary<string,object> request)
  351. {
  352. InventoryFolderBase folder = BuildFolder(request);
  353. if (m_InventoryService.AddFolder(folder))
  354. return SuccessResult();
  355. else
  356. return FailureResult();
  357. }
  358. byte[] HandleUpdateFolder(Dictionary<string,object> request)
  359. {
  360. InventoryFolderBase folder = BuildFolder(request);
  361. if (m_InventoryService.UpdateFolder(folder))
  362. return SuccessResult();
  363. else
  364. return FailureResult();
  365. }
  366. byte[] HandleMoveFolder(Dictionary<string,object> request)
  367. {
  368. UUID parentID = UUID.Zero;
  369. UUID.TryParse(request["ParentID"].ToString(), out parentID);
  370. UUID folderID = UUID.Zero;
  371. UUID.TryParse(request["ID"].ToString(), out folderID);
  372. UUID principal = UUID.Zero;
  373. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  374. InventoryFolderBase folder = new InventoryFolderBase(folderID, "", principal, parentID);
  375. if (m_InventoryService.MoveFolder(folder))
  376. return SuccessResult();
  377. else
  378. return FailureResult();
  379. }
  380. byte[] HandleDeleteFolders(Dictionary<string,object> request)
  381. {
  382. UUID principal = UUID.Zero;
  383. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  384. List<string> slist = (List<string>)request["FOLDERS"];
  385. List<UUID> uuids = new List<UUID>();
  386. foreach (string s in slist)
  387. {
  388. UUID u = UUID.Zero;
  389. if (UUID.TryParse(s, out u))
  390. uuids.Add(u);
  391. }
  392. if (m_InventoryService.DeleteFolders(principal, uuids))
  393. return SuccessResult();
  394. else
  395. return
  396. FailureResult();
  397. }
  398. byte[] HandlePurgeFolder(Dictionary<string,object> request)
  399. {
  400. UUID folderID = UUID.Zero;
  401. UUID.TryParse(request["ID"].ToString(), out folderID);
  402. InventoryFolderBase folder = new InventoryFolderBase(folderID);
  403. if (m_InventoryService.PurgeFolder(folder))
  404. return SuccessResult();
  405. else
  406. return FailureResult();
  407. }
  408. byte[] HandleAddItem(Dictionary<string,object> request)
  409. {
  410. InventoryItemBase item = BuildItem(request);
  411. if (m_InventoryService.AddItem(item))
  412. return SuccessResult();
  413. else
  414. return FailureResult();
  415. }
  416. byte[] HandleUpdateItem(Dictionary<string,object> request)
  417. {
  418. InventoryItemBase item = BuildItem(request);
  419. if (m_InventoryService.UpdateItem(item))
  420. return SuccessResult();
  421. else
  422. return FailureResult();
  423. }
  424. byte[] HandleMoveItems(Dictionary<string,object> request)
  425. {
  426. List<string> idlist = (List<string>)request["IDLIST"];
  427. List<string> destlist = (List<string>)request["DESTLIST"];
  428. UUID.TryParse(request["PRINCIPAL"].ToString(), out UUID principal);
  429. List<InventoryItemBase> items = new List<InventoryItemBase>();
  430. int n = 0;
  431. try
  432. {
  433. foreach (string s in idlist)
  434. {
  435. UUID u = UUID.Zero;
  436. if (UUID.TryParse(s, out u))
  437. {
  438. UUID fid = UUID.Zero;
  439. if (UUID.TryParse(destlist[n++], out fid))
  440. {
  441. InventoryItemBase item = new InventoryItemBase(u, principal);
  442. item.Folder = fid;
  443. items.Add(item);
  444. }
  445. }
  446. }
  447. }
  448. catch (Exception e)
  449. {
  450. m_log.DebugFormat("[XINVENTORY IN CONNECTOR]: Exception in HandleMoveItems: {0}", e.Message);
  451. return FailureResult();
  452. }
  453. if (m_InventoryService.MoveItems(principal, items))
  454. return SuccessResult();
  455. else
  456. return FailureResult();
  457. }
  458. byte[] HandleDeleteItems(Dictionary<string,object> request)
  459. {
  460. UUID principal = UUID.Zero;
  461. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  462. List<string> slist = (List<string>)request["ITEMS"];
  463. List<UUID> uuids = new List<UUID>();
  464. foreach (string s in slist)
  465. {
  466. UUID u = UUID.Zero;
  467. if (UUID.TryParse(s, out u))
  468. uuids.Add(u);
  469. }
  470. if (m_InventoryService.DeleteItems(principal, uuids))
  471. return SuccessResult();
  472. else
  473. return
  474. FailureResult();
  475. }
  476. byte[] HandleGetItem(Dictionary<string,object> request)
  477. {
  478. Dictionary<string,object> result = new Dictionary<string,object>();
  479. UUID id = UUID.Zero;
  480. UUID.TryParse(request["ID"].ToString(), out id);
  481. UUID user = UUID.Zero;
  482. if (request.ContainsKey("PRINCIPAL"))
  483. UUID.TryParse(request["PRINCIPAL"].ToString(), out user);
  484. InventoryItemBase item = m_InventoryService.GetItem(user, id);
  485. if (item != null)
  486. result["item"] = EncodeItem(item);
  487. string xmlString = ServerUtils.BuildXmlResponse(result);
  488. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  489. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  490. }
  491. byte[] HandleGetMultipleItems(Dictionary<string, object> request)
  492. {
  493. Dictionary<string, object> resultSet = new Dictionary<string, object>();
  494. if(!UUID.TryParse(request["PRINCIPAL"].ToString(), out UUID principal))
  495. return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(resultSet));
  496. string itemIDstr = request["ITEMS"].ToString();
  497. if(string.IsNullOrEmpty(itemIDstr))
  498. return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(resultSet));
  499. string[] uuids = itemIDstr.Split(',');
  500. if(uuids.Length == 0)
  501. return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(resultSet));
  502. UUID[] fids = new UUID[uuids.Length];
  503. int i = 0;
  504. foreach (string id in uuids)
  505. {
  506. UUID fid = UUID.Zero;
  507. if (UUID.TryParse(id, out fid))
  508. fids[i] = fid;
  509. i += 1;
  510. }
  511. InventoryItemBase[] itemsList = m_InventoryService.GetMultipleItems(principal, fids);
  512. if (itemsList != null && itemsList.Length > 0)
  513. {
  514. int count = 0;
  515. foreach (InventoryItemBase item in itemsList)
  516. resultSet["item_" + count++] = (item == null) ? "NULL" : EncodeItem(item);
  517. }
  518. string xmlString = ServerUtils.BuildXmlResponse(resultSet);
  519. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  520. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  521. }
  522. byte[] HandleGetFolder(Dictionary<string,object> request)
  523. {
  524. Dictionary<string, object> result = new Dictionary<string, object>();
  525. UUID id = UUID.Zero;
  526. UUID.TryParse(request["ID"].ToString(), out id);
  527. UUID user = UUID.Zero;
  528. if (request.ContainsKey("PRINCIPAL"))
  529. UUID.TryParse(request["PRINCIPAL"].ToString(), out user);
  530. InventoryFolderBase folder = m_InventoryService.GetFolder(user, id);
  531. if (folder != null)
  532. result["folder"] = EncodeFolder(folder);
  533. string xmlString = ServerUtils.BuildXmlResponse(result);
  534. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  535. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  536. }
  537. byte[] HandleGetActiveGestures(Dictionary<string,object> request)
  538. {
  539. Dictionary<string,object> result = new Dictionary<string,object>();
  540. UUID principal = UUID.Zero;
  541. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  542. List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(principal);
  543. Dictionary<string, object> items = new Dictionary<string, object>();
  544. if (gestures != null)
  545. {
  546. int i = 0;
  547. foreach (InventoryItemBase item in gestures)
  548. {
  549. items["item_" + i.ToString()] = EncodeItem(item);
  550. i++;
  551. }
  552. }
  553. result["ITEMS"] = items;
  554. string xmlString = ServerUtils.BuildXmlResponse(result);
  555. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  556. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  557. }
  558. byte[] HandleGetAssetPermissions(Dictionary<string,object> request)
  559. {
  560. Dictionary<string,object> result = new Dictionary<string,object>();
  561. UUID principal = UUID.Zero;
  562. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  563. UUID assetID = UUID.Zero;
  564. UUID.TryParse(request["ASSET"].ToString(), out assetID);
  565. int perms = m_InventoryService.GetAssetPermissions(principal, assetID);
  566. result["RESULT"] = perms.ToString();
  567. string xmlString = ServerUtils.BuildXmlResponse(result);
  568. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  569. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  570. }
  571. private Dictionary<string, object> EncodeFolder(InventoryFolderBase f)
  572. {
  573. Dictionary<string, object> ret = new Dictionary<string, object>();
  574. ret["ParentID"] = f.ParentID.ToString();
  575. ret["Type"] = f.Type.ToString();
  576. ret["Version"] = f.Version.ToString();
  577. ret["Name"] = f.Name;
  578. ret["Owner"] = f.Owner.ToString();
  579. ret["ID"] = f.ID.ToString();
  580. return ret;
  581. }
  582. private Dictionary<string, object> EncodeItem(InventoryItemBase item)
  583. {
  584. Dictionary<string, object> ret = new Dictionary<string, object>();
  585. ret["AssetID"] = item.AssetID.ToString();
  586. ret["AssetType"] = item.AssetType.ToString();
  587. ret["BasePermissions"] = item.BasePermissions.ToString();
  588. ret["CreationDate"] = item.CreationDate.ToString();
  589. if (item.CreatorId != null)
  590. ret["CreatorId"] = item.CreatorId.ToString();
  591. else
  592. ret["CreatorId"] = String.Empty;
  593. if (item.CreatorData != null)
  594. ret["CreatorData"] = item.CreatorData;
  595. else
  596. ret["CreatorData"] = String.Empty;
  597. ret["CurrentPermissions"] = item.CurrentPermissions.ToString();
  598. ret["Description"] = item.Description.ToString();
  599. ret["EveryOnePermissions"] = item.EveryOnePermissions.ToString();
  600. ret["Flags"] = item.Flags.ToString();
  601. ret["Folder"] = item.Folder.ToString();
  602. ret["GroupID"] = item.GroupID.ToString();
  603. ret["GroupOwned"] = item.GroupOwned.ToString();
  604. ret["GroupPermissions"] = item.GroupPermissions.ToString();
  605. ret["ID"] = item.ID.ToString();
  606. ret["InvType"] = item.InvType.ToString();
  607. ret["Name"] = item.Name.ToString();
  608. ret["NextPermissions"] = item.NextPermissions.ToString();
  609. ret["Owner"] = item.Owner.ToString();
  610. ret["SalePrice"] = item.SalePrice.ToString();
  611. ret["SaleType"] = item.SaleType.ToString();
  612. return ret;
  613. }
  614. private InventoryFolderBase BuildFolder(Dictionary<string,object> data)
  615. {
  616. InventoryFolderBase folder = new InventoryFolderBase();
  617. folder.ParentID = new UUID(data["ParentID"].ToString());
  618. folder.Type = short.Parse(data["Type"].ToString());
  619. folder.Version = ushort.Parse(data["Version"].ToString());
  620. folder.Name = data["Name"].ToString();
  621. folder.Owner = new UUID(data["Owner"].ToString());
  622. folder.ID = new UUID(data["ID"].ToString());
  623. return folder;
  624. }
  625. private InventoryItemBase BuildItem(Dictionary<string,object> data)
  626. {
  627. InventoryItemBase item = new InventoryItemBase();
  628. item.AssetID = new UUID(data["AssetID"].ToString());
  629. item.AssetType = int.Parse(data["AssetType"].ToString());
  630. item.Name = data["Name"].ToString();
  631. item.Owner = new UUID(data["Owner"].ToString());
  632. item.ID = new UUID(data["ID"].ToString());
  633. item.InvType = int.Parse(data["InvType"].ToString());
  634. item.Folder = new UUID(data["Folder"].ToString());
  635. item.CreatorId = data["CreatorId"].ToString();
  636. item.CreatorData = data["CreatorData"].ToString();
  637. item.Description = data["Description"].ToString();
  638. item.NextPermissions = uint.Parse(data["NextPermissions"].ToString());
  639. item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString());
  640. item.BasePermissions = uint.Parse(data["BasePermissions"].ToString());
  641. item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString());
  642. item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString());
  643. item.GroupID = new UUID(data["GroupID"].ToString());
  644. item.GroupOwned = bool.Parse(data["GroupOwned"].ToString());
  645. item.SalePrice = int.Parse(data["SalePrice"].ToString());
  646. item.SaleType = byte.Parse(data["SaleType"].ToString());
  647. item.Flags = uint.Parse(data["Flags"].ToString());
  648. item.CreationDate = int.Parse(data["CreationDate"].ToString());
  649. return item;
  650. }
  651. }
  652. }