XInventoryInConnector.cs 27 KB

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