1
0

XInventoryInConnector.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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 == String.Empty)
  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 principal = UUID.Zero;
  429. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  430. List<InventoryItemBase> items = new List<InventoryItemBase>();
  431. int n = 0;
  432. try
  433. {
  434. foreach (string s in idlist)
  435. {
  436. UUID u = UUID.Zero;
  437. if (UUID.TryParse(s, out u))
  438. {
  439. UUID fid = UUID.Zero;
  440. if (UUID.TryParse(destlist[n++], out fid))
  441. {
  442. InventoryItemBase item = new InventoryItemBase(u, principal);
  443. item.Folder = fid;
  444. items.Add(item);
  445. }
  446. }
  447. }
  448. }
  449. catch (Exception e)
  450. {
  451. m_log.DebugFormat("[XINVENTORY IN CONNECTOR]: Exception in HandleMoveItems: {0}", e.Message);
  452. return FailureResult();
  453. }
  454. if (m_InventoryService.MoveItems(principal, items))
  455. return SuccessResult();
  456. else
  457. return FailureResult();
  458. }
  459. byte[] HandleDeleteItems(Dictionary<string,object> request)
  460. {
  461. UUID principal = UUID.Zero;
  462. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  463. List<string> slist = (List<string>)request["ITEMS"];
  464. List<UUID> uuids = new List<UUID>();
  465. foreach (string s in slist)
  466. {
  467. UUID u = UUID.Zero;
  468. if (UUID.TryParse(s, out u))
  469. uuids.Add(u);
  470. }
  471. if (m_InventoryService.DeleteItems(principal, uuids))
  472. return SuccessResult();
  473. else
  474. return
  475. FailureResult();
  476. }
  477. byte[] HandleGetItem(Dictionary<string,object> request)
  478. {
  479. Dictionary<string,object> result = new Dictionary<string,object>();
  480. UUID id = UUID.Zero;
  481. UUID.TryParse(request["ID"].ToString(), out id);
  482. UUID user = UUID.Zero;
  483. if (request.ContainsKey("PRINCIPAL"))
  484. UUID.TryParse(request["PRINCIPAL"].ToString(), out user);
  485. InventoryItemBase item = m_InventoryService.GetItem(user, id);
  486. if (item != null)
  487. result["item"] = EncodeItem(item);
  488. string xmlString = ServerUtils.BuildXmlResponse(result);
  489. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  490. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  491. }
  492. byte[] HandleGetMultipleItems(Dictionary<string, object> request)
  493. {
  494. Dictionary<string, object> resultSet = new Dictionary<string, object>();
  495. UUID principal = UUID.Zero;
  496. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  497. string itemIDstr = request["ITEMS"].ToString();
  498. int count = 0;
  499. Int32.TryParse(request["COUNT"].ToString(), out count);
  500. UUID[] fids = new UUID[count];
  501. string[] uuids = itemIDstr.Split(',');
  502. int i = 0;
  503. foreach (string id in uuids)
  504. {
  505. UUID fid = UUID.Zero;
  506. if (UUID.TryParse(id, out fid))
  507. fids[i] = fid;
  508. i += 1;
  509. }
  510. InventoryItemBase[] itemsList = m_InventoryService.GetMultipleItems(principal, fids);
  511. if (itemsList != null && itemsList.Length > 0)
  512. {
  513. count = 0;
  514. foreach (InventoryItemBase item in itemsList)
  515. resultSet["item_" + count++] = (item == null) ? (object)"NULL" : EncodeItem(item);
  516. }
  517. string xmlString = ServerUtils.BuildXmlResponse(resultSet);
  518. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  519. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  520. }
  521. byte[] HandleGetFolder(Dictionary<string,object> request)
  522. {
  523. Dictionary<string, object> result = new Dictionary<string, object>();
  524. UUID id = UUID.Zero;
  525. UUID.TryParse(request["ID"].ToString(), out id);
  526. UUID user = UUID.Zero;
  527. if (request.ContainsKey("PRINCIPAL"))
  528. UUID.TryParse(request["PRINCIPAL"].ToString(), out user);
  529. InventoryFolderBase folder = m_InventoryService.GetFolder(user, id);
  530. if (folder != null)
  531. result["folder"] = EncodeFolder(folder);
  532. string xmlString = ServerUtils.BuildXmlResponse(result);
  533. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  534. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  535. }
  536. byte[] HandleGetActiveGestures(Dictionary<string,object> request)
  537. {
  538. Dictionary<string,object> result = new Dictionary<string,object>();
  539. UUID principal = UUID.Zero;
  540. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  541. List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(principal);
  542. Dictionary<string, object> items = new Dictionary<string, object>();
  543. if (gestures != null)
  544. {
  545. int i = 0;
  546. foreach (InventoryItemBase item in gestures)
  547. {
  548. items["item_" + i.ToString()] = EncodeItem(item);
  549. i++;
  550. }
  551. }
  552. result["ITEMS"] = items;
  553. string xmlString = ServerUtils.BuildXmlResponse(result);
  554. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  555. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  556. }
  557. byte[] HandleGetAssetPermissions(Dictionary<string,object> request)
  558. {
  559. Dictionary<string,object> result = new Dictionary<string,object>();
  560. UUID principal = UUID.Zero;
  561. UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
  562. UUID assetID = UUID.Zero;
  563. UUID.TryParse(request["ASSET"].ToString(), out assetID);
  564. int perms = m_InventoryService.GetAssetPermissions(principal, assetID);
  565. result["RESULT"] = perms.ToString();
  566. string xmlString = ServerUtils.BuildXmlResponse(result);
  567. //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
  568. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  569. }
  570. private Dictionary<string, object> EncodeFolder(InventoryFolderBase f)
  571. {
  572. Dictionary<string, object> ret = new Dictionary<string, object>();
  573. ret["ParentID"] = f.ParentID.ToString();
  574. ret["Type"] = f.Type.ToString();
  575. ret["Version"] = f.Version.ToString();
  576. ret["Name"] = f.Name;
  577. ret["Owner"] = f.Owner.ToString();
  578. ret["ID"] = f.ID.ToString();
  579. return ret;
  580. }
  581. private Dictionary<string, object> EncodeItem(InventoryItemBase item)
  582. {
  583. Dictionary<string, object> ret = new Dictionary<string, object>();
  584. ret["AssetID"] = item.AssetID.ToString();
  585. ret["AssetType"] = item.AssetType.ToString();
  586. ret["BasePermissions"] = item.BasePermissions.ToString();
  587. ret["CreationDate"] = item.CreationDate.ToString();
  588. if (item.CreatorId != null)
  589. ret["CreatorId"] = item.CreatorId.ToString();
  590. else
  591. ret["CreatorId"] = String.Empty;
  592. if (item.CreatorData != null)
  593. ret["CreatorData"] = item.CreatorData;
  594. else
  595. ret["CreatorData"] = String.Empty;
  596. ret["CurrentPermissions"] = item.CurrentPermissions.ToString();
  597. ret["Description"] = item.Description.ToString();
  598. ret["EveryOnePermissions"] = item.EveryOnePermissions.ToString();
  599. ret["Flags"] = item.Flags.ToString();
  600. ret["Folder"] = item.Folder.ToString();
  601. ret["GroupID"] = item.GroupID.ToString();
  602. ret["GroupOwned"] = item.GroupOwned.ToString();
  603. ret["GroupPermissions"] = item.GroupPermissions.ToString();
  604. ret["ID"] = item.ID.ToString();
  605. ret["InvType"] = item.InvType.ToString();
  606. ret["Name"] = item.Name.ToString();
  607. ret["NextPermissions"] = item.NextPermissions.ToString();
  608. ret["Owner"] = item.Owner.ToString();
  609. ret["SalePrice"] = item.SalePrice.ToString();
  610. ret["SaleType"] = item.SaleType.ToString();
  611. return ret;
  612. }
  613. private InventoryFolderBase BuildFolder(Dictionary<string,object> data)
  614. {
  615. InventoryFolderBase folder = new InventoryFolderBase();
  616. folder.ParentID = new UUID(data["ParentID"].ToString());
  617. folder.Type = short.Parse(data["Type"].ToString());
  618. folder.Version = ushort.Parse(data["Version"].ToString());
  619. folder.Name = data["Name"].ToString();
  620. folder.Owner = new UUID(data["Owner"].ToString());
  621. folder.ID = new UUID(data["ID"].ToString());
  622. return folder;
  623. }
  624. private InventoryItemBase BuildItem(Dictionary<string,object> data)
  625. {
  626. InventoryItemBase item = new InventoryItemBase();
  627. item.AssetID = new UUID(data["AssetID"].ToString());
  628. item.AssetType = int.Parse(data["AssetType"].ToString());
  629. item.Name = data["Name"].ToString();
  630. item.Owner = new UUID(data["Owner"].ToString());
  631. item.ID = new UUID(data["ID"].ToString());
  632. item.InvType = int.Parse(data["InvType"].ToString());
  633. item.Folder = new UUID(data["Folder"].ToString());
  634. item.CreatorId = data["CreatorId"].ToString();
  635. item.CreatorData = data["CreatorData"].ToString();
  636. item.Description = data["Description"].ToString();
  637. item.NextPermissions = uint.Parse(data["NextPermissions"].ToString());
  638. item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString());
  639. item.BasePermissions = uint.Parse(data["BasePermissions"].ToString());
  640. item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString());
  641. item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString());
  642. item.GroupID = new UUID(data["GroupID"].ToString());
  643. item.GroupOwned = bool.Parse(data["GroupOwned"].ToString());
  644. item.SalePrice = int.Parse(data["SalePrice"].ToString());
  645. item.SaleType = byte.Parse(data["SaleType"].ToString());
  646. item.Flags = uint.Parse(data["Flags"].ToString());
  647. item.CreationDate = int.Parse(data["CreationDate"].ToString());
  648. return item;
  649. }
  650. }
  651. }