XInventoryInConnector.cs 28 KB

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