Utils.cs 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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.Globalization;
  29. using System.Xml;
  30. using System.Xml.Serialization;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Servers;
  34. using OpenSim.Framework.Servers.HttpServer;
  35. namespace OpenSim.Grid.AssetInventoryServer
  36. {
  37. public static class Utils
  38. {
  39. public static UUID GetAuthToken(OSHttpRequest request)
  40. {
  41. UUID authToken = UUID.Zero;
  42. string[] authHeader = request.Headers.GetValues("Authorization");
  43. if (authHeader != null && authHeader.Length == 1)
  44. {
  45. // Example header:
  46. // Authorization: OpenGrid 65fda0b5-4446-42f5-b828-aaf644293646
  47. string[] authHeaderParts = authHeader[0].Split(' ');
  48. if (authHeaderParts.Length == 2 && authHeaderParts[0] == "OpenGrid")
  49. UUID.TryParse(authHeaderParts[1], out authToken);
  50. }
  51. //if (authToken == UUID.Zero && request.Cookies != null)
  52. //{
  53. // // Check for an authToken cookie to make logins browser-compatible
  54. // RequestCookie authCookie = request.Cookies["authToken"];
  55. // if (authCookie != null)
  56. // UUID.TryParse(authCookie.Value, out authToken);
  57. //}
  58. return authToken;
  59. }
  60. public static Uri GetOpenSimUri(UUID avatarID)
  61. {
  62. return new Uri("http://opensim/" + avatarID.ToString());
  63. }
  64. public static bool TryGetOpenSimUUID(Uri avatarUri, out UUID avatarID)
  65. {
  66. string[] parts = avatarUri.Segments;
  67. return UUID.TryParse(parts[parts.Length - 1], out avatarID);
  68. }
  69. #region SL / file extension / content-type conversions
  70. public static string SLAssetTypeToContentType(int assetType)
  71. {
  72. switch (assetType)
  73. {
  74. case 0:
  75. return "image/jp2";
  76. case 1:
  77. return "application/ogg";
  78. case 2:
  79. return "application/x-metaverse-callingcard";
  80. case 3:
  81. return "application/x-metaverse-landmark";
  82. case 5:
  83. return "application/x-metaverse-clothing";
  84. case 6:
  85. return "application/x-metaverse-primitive";
  86. case 7:
  87. return "application/x-metaverse-notecard";
  88. case 8:
  89. return "application/x-metaverse-folder";
  90. case 10:
  91. return "application/x-metaverse-lsl";
  92. case 11:
  93. return "application/x-metaverse-lso";
  94. case 12:
  95. return "image/tga";
  96. case 13:
  97. return "application/x-metaverse-bodypart";
  98. case 17:
  99. return "audio/x-wav";
  100. case 19:
  101. return "image/jpeg";
  102. case 20:
  103. return "application/x-metaverse-animation";
  104. case 21:
  105. return "application/x-metaverse-gesture";
  106. case 22:
  107. return "application/x-metaverse-simstate";
  108. default:
  109. return "application/octet-stream";
  110. }
  111. }
  112. public static int ContentTypeToSLAssetType(string contentType)
  113. {
  114. switch (contentType)
  115. {
  116. case "image/jp2":
  117. return 0;
  118. case "application/ogg":
  119. return 1;
  120. case "application/x-metaverse-callingcard":
  121. return 2;
  122. case "application/x-metaverse-landmark":
  123. return 3;
  124. case "application/x-metaverse-clothing":
  125. return 5;
  126. case "application/x-metaverse-primitive":
  127. return 6;
  128. case "application/x-metaverse-notecard":
  129. return 7;
  130. case "application/x-metaverse-lsl":
  131. return 10;
  132. case "application/x-metaverse-lso":
  133. return 11;
  134. case "image/tga":
  135. return 12;
  136. case "application/x-metaverse-bodypart":
  137. return 13;
  138. case "audio/x-wav":
  139. return 17;
  140. case "image/jpeg":
  141. return 19;
  142. case "application/x-metaverse-animation":
  143. return 20;
  144. case "application/x-metaverse-gesture":
  145. return 21;
  146. case "application/x-metaverse-simstate":
  147. return 22;
  148. default:
  149. return -1;
  150. }
  151. }
  152. public static string ContentTypeToExtension(string contentType)
  153. {
  154. switch (contentType)
  155. {
  156. case "image/jp2":
  157. return "texture";
  158. case "application/ogg":
  159. return "ogg";
  160. case "application/x-metaverse-callingcard":
  161. return "callingcard";
  162. case "application/x-metaverse-landmark":
  163. return "landmark";
  164. case "application/x-metaverse-clothing":
  165. return "clothing";
  166. case "application/x-metaverse-primitive":
  167. return "primitive";
  168. case "application/x-metaverse-notecard":
  169. return "notecard";
  170. case "application/x-metaverse-lsl":
  171. return "lsl";
  172. case "application/x-metaverse-lso":
  173. return "lso";
  174. case "image/tga":
  175. return "tga";
  176. case "application/x-metaverse-bodypart":
  177. return "bodypart";
  178. case "audio/x-wav":
  179. return "wav";
  180. case "image/jpeg":
  181. return "jpg";
  182. case "application/x-metaverse-animation":
  183. return "animation";
  184. case "application/x-metaverse-gesture":
  185. return "gesture";
  186. case "application/x-metaverse-simstate":
  187. return "simstate";
  188. default:
  189. return "bin";
  190. }
  191. }
  192. public static string ExtensionToContentType(string extension)
  193. {
  194. switch (extension)
  195. {
  196. case "texture":
  197. case "jp2":
  198. case "j2c":
  199. return "image/jp2";
  200. case "sound":
  201. case "ogg":
  202. return "application/ogg";
  203. case "callingcard":
  204. return "application/x-metaverse-callingcard";
  205. case "landmark":
  206. return "application/x-metaverse-landmark";
  207. case "clothing":
  208. return "application/x-metaverse-clothing";
  209. case "primitive":
  210. return "application/x-metaverse-primitive";
  211. case "notecard":
  212. return "application/x-metaverse-notecard";
  213. case "lsl":
  214. return "application/x-metaverse-lsl";
  215. case "lso":
  216. return "application/x-metaverse-lso";
  217. case "tga":
  218. return "image/tga";
  219. case "bodypart":
  220. return "application/x-metaverse-bodypart";
  221. case "wav":
  222. return "audio/x-wav";
  223. case "jpg":
  224. case "jpeg":
  225. return "image/jpeg";
  226. case "animation":
  227. return "application/x-metaverse-animation";
  228. case "gesture":
  229. return "application/x-metaverse-gesture";
  230. case "simstate":
  231. return "application/x-metaverse-simstate";
  232. case "txt":
  233. return "text/plain";
  234. case "xml":
  235. return "application/xml";
  236. default:
  237. return "application/octet-stream";
  238. }
  239. }
  240. #endregion SL / file extension / content-type conversions
  241. #region XML Serialization
  242. public class GeneratedReader : XmlSerializationReader
  243. {
  244. public object ReadRoot_InventoryFolderBase()
  245. {
  246. Reader.MoveToContent();
  247. if (Reader.LocalName != "InventoryFolderBase" || Reader.NamespaceURI != "")
  248. throw CreateUnknownNodeException();
  249. return ReadObject_InventoryFolder(true, true);
  250. }
  251. public object ReadRoot_InventoryItemBase()
  252. {
  253. Reader.MoveToContent();
  254. if (Reader.LocalName != "InventoryItemBase" || Reader.NamespaceURI != "")
  255. throw CreateUnknownNodeException();
  256. return ReadObject_InventoryItem(true, true);
  257. }
  258. public object ReadRoot_InventoryCollection()
  259. {
  260. Reader.MoveToContent();
  261. if (Reader.LocalName != "InventoryCollection" || Reader.NamespaceURI != "")
  262. throw CreateUnknownNodeException();
  263. return ReadObject_InventoryCollection(true, true);
  264. }
  265. public InventoryFolderWithChildren ReadObject_InventoryFolder(bool isNullable, bool checkType)
  266. {
  267. InventoryFolderWithChildren ob = null;
  268. if (isNullable && ReadNull()) return null;
  269. if (checkType)
  270. {
  271. System.Xml.XmlQualifiedName t = GetXsiType();
  272. if (t == null)
  273. { }
  274. else if (t.Name != "InventoryFolderBase" || t.Namespace != "")
  275. throw CreateUnknownTypeException(t);
  276. }
  277. ob = (InventoryFolderWithChildren)Activator.CreateInstance(typeof(InventoryFolderWithChildren), true);
  278. Reader.MoveToElement();
  279. while (Reader.MoveToNextAttribute())
  280. {
  281. if (IsXmlnsAttribute(Reader.Name))
  282. {
  283. }
  284. else
  285. {
  286. UnknownNode(ob);
  287. }
  288. }
  289. Reader.MoveToElement();
  290. Reader.MoveToElement();
  291. if (Reader.IsEmptyElement)
  292. {
  293. Reader.Skip();
  294. return ob;
  295. }
  296. Reader.ReadStartElement();
  297. Reader.MoveToContent();
  298. bool b0 = false, b1 = false, b2 = false, b3 = false, b4 = false, b5 = false;
  299. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  300. {
  301. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  302. {
  303. if (Reader.LocalName == "Owner" && Reader.NamespaceURI == "" && !b1)
  304. {
  305. b1 = true;
  306. ob.@Owner = ReadObject_UUID(false, true);
  307. }
  308. else if (Reader.LocalName == "Version" && Reader.NamespaceURI == "" && !b5)
  309. {
  310. b5 = true;
  311. string s6 = Reader.ReadElementString();
  312. ob.@Version = UInt16.Parse(s6, CultureInfo.InvariantCulture);
  313. }
  314. else if (Reader.LocalName == "ID" && Reader.NamespaceURI == "" && !b3)
  315. {
  316. b3 = true;
  317. ob.@ID = ReadObject_UUID(false, true);
  318. }
  319. else if (Reader.LocalName == "Type" && Reader.NamespaceURI == "" && !b4)
  320. {
  321. b4 = true;
  322. string s7 = Reader.ReadElementString();
  323. ob.@Type = Int16.Parse(s7, CultureInfo.InvariantCulture);
  324. }
  325. else if (Reader.LocalName == "Name" && Reader.NamespaceURI == "" && !b0)
  326. {
  327. b0 = true;
  328. string s8 = Reader.ReadElementString();
  329. ob.@Name = s8;
  330. }
  331. else if (Reader.LocalName == "ParentID" && Reader.NamespaceURI == "" && !b2)
  332. {
  333. b2 = true;
  334. ob.@ParentID = ReadObject_UUID(false, true);
  335. }
  336. else
  337. {
  338. UnknownNode(ob);
  339. }
  340. }
  341. else
  342. UnknownNode(ob);
  343. Reader.MoveToContent();
  344. }
  345. ReadEndElement();
  346. return ob;
  347. }
  348. public InventoryItemBase ReadObject_InventoryItem(bool isNullable, bool checkType)
  349. {
  350. InventoryItemBase ob = null;
  351. if (isNullable && ReadNull()) return null;
  352. if (checkType)
  353. {
  354. System.Xml.XmlQualifiedName t = GetXsiType();
  355. if (t == null)
  356. { }
  357. else if (t.Name != "InventoryItemBase" || t.Namespace != "")
  358. throw CreateUnknownTypeException(t);
  359. }
  360. ob = (InventoryItemBase)Activator.CreateInstance(typeof(InventoryItemBase), true);
  361. Reader.MoveToElement();
  362. while (Reader.MoveToNextAttribute())
  363. {
  364. if (IsXmlnsAttribute(Reader.Name))
  365. {
  366. }
  367. else
  368. {
  369. UnknownNode(ob);
  370. }
  371. }
  372. Reader.MoveToElement();
  373. Reader.MoveToElement();
  374. if (Reader.IsEmptyElement)
  375. {
  376. Reader.Skip();
  377. return ob;
  378. }
  379. Reader.ReadStartElement();
  380. Reader.MoveToContent();
  381. bool b9 = false, b10 = false, b11 = false, b12 = false, b13 = false, b14 = false, b15 = false, b16 = false, b17 = false, b18 = false, b19 = false, b20 = false, b21 = false, b22 = false, b23 = false, b24 = false, b25 = false, b26 = false, b27 = false, b28 = false;
  382. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  383. {
  384. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  385. {
  386. if (Reader.LocalName == "GroupPermissions" && Reader.NamespaceURI == "" && !b20)
  387. {
  388. b20 = true;
  389. string s29 = Reader.ReadElementString();
  390. ob.@GroupPermissions = UInt32.Parse(s29, CultureInfo.InvariantCulture);
  391. }
  392. else if (Reader.LocalName == "AssetType" && Reader.NamespaceURI == "" && !b21)
  393. {
  394. b21 = true;
  395. string s30 = Reader.ReadElementString();
  396. ob.@AssetType = Int32.Parse(s30, CultureInfo.InvariantCulture);
  397. }
  398. else if (Reader.LocalName == "SalePrice" && Reader.NamespaceURI == "" && !b25)
  399. {
  400. b25 = true;
  401. string s31 = Reader.ReadElementString();
  402. ob.@SalePrice = Int32.Parse(s31, CultureInfo.InvariantCulture);
  403. }
  404. else if (Reader.LocalName == "AssetID" && Reader.NamespaceURI == "" && !b22)
  405. {
  406. b22 = true;
  407. ob.@AssetID = ReadObject_UUID(false, true);
  408. }
  409. else if (Reader.LocalName == "Folder" && Reader.NamespaceURI == "" && !b11)
  410. {
  411. b11 = true;
  412. ob.@Folder = ReadObject_UUID(false, true);
  413. }
  414. else if (Reader.LocalName == "Name" && Reader.NamespaceURI == "" && !b14)
  415. {
  416. b14 = true;
  417. string s32 = Reader.ReadElementString();
  418. ob.@Name = s32;
  419. }
  420. else if (Reader.LocalName == "NextPermissions" && Reader.NamespaceURI == "" && !b16)
  421. {
  422. b16 = true;
  423. string s33 = Reader.ReadElementString();
  424. ob.@NextPermissions = UInt32.Parse(s33, CultureInfo.InvariantCulture);
  425. }
  426. else if (Reader.LocalName == "BasePermissions" && Reader.NamespaceURI == "" && !b18)
  427. {
  428. b18 = true;
  429. string s34 = Reader.ReadElementString();
  430. ob.@BasePermissions = UInt32.Parse(s34, CultureInfo.InvariantCulture);
  431. }
  432. else if (Reader.LocalName == "ID" && Reader.NamespaceURI == "" && !b9)
  433. {
  434. b9 = true;
  435. ob.@ID = ReadObject_UUID(false, true);
  436. }
  437. else if (Reader.LocalName == "Flags" && Reader.NamespaceURI == "" && !b27)
  438. {
  439. b27 = true;
  440. string s35 = Reader.ReadElementString();
  441. ob.@Flags = UInt32.Parse(s35, CultureInfo.InvariantCulture);
  442. }
  443. else if (Reader.LocalName == "GroupOwned" && Reader.NamespaceURI == "" && !b24)
  444. {
  445. b24 = true;
  446. string s36 = Reader.ReadElementString();
  447. ob.@GroupOwned = XmlConvert.ToBoolean(s36);
  448. }
  449. else if (Reader.LocalName == "InvType" && Reader.NamespaceURI == "" && !b10)
  450. {
  451. b10 = true;
  452. string s37 = Reader.ReadElementString();
  453. ob.@InvType = Int32.Parse(s37, CultureInfo.InvariantCulture);
  454. }
  455. else if (Reader.LocalName == "GroupID" && Reader.NamespaceURI == "" && !b23)
  456. {
  457. b23 = true;
  458. ob.@GroupID = ReadObject_UUID(false, true);
  459. }
  460. else if (Reader.LocalName == "Description" && Reader.NamespaceURI == "" && !b15)
  461. {
  462. b15 = true;
  463. string s38 = Reader.ReadElementString();
  464. ob.@Description = s38;
  465. }
  466. else if (Reader.LocalName == "CreationDate" && Reader.NamespaceURI == "" && !b28)
  467. {
  468. b28 = true;
  469. string s39 = Reader.ReadElementString();
  470. ob.@CreationDate = Int32.Parse(s39, CultureInfo.InvariantCulture);
  471. }
  472. else if (Reader.LocalName == "EveryOnePermissions" && Reader.NamespaceURI == "" && !b19)
  473. {
  474. b19 = true;
  475. string s40 = Reader.ReadElementString();
  476. ob.@EveryOnePermissions = UInt32.Parse(s40, CultureInfo.InvariantCulture);
  477. }
  478. else if (Reader.LocalName == "Creator" && Reader.NamespaceURI == "" && !b13)
  479. {
  480. b13 = true;
  481. ob.@CreatorId = Reader.ReadElementString();
  482. }
  483. else if (Reader.LocalName == "Owner" && Reader.NamespaceURI == "" && !b12)
  484. {
  485. b12 = true;
  486. ob.@Owner = ReadObject_UUID(false, true);
  487. }
  488. else if (Reader.LocalName == "SaleType" && Reader.NamespaceURI == "" && !b26)
  489. {
  490. b26 = true;
  491. string s41 = Reader.ReadElementString();
  492. ob.@SaleType = byte.Parse(s41, CultureInfo.InvariantCulture);
  493. }
  494. else if (Reader.LocalName == "CurrentPermissions" && Reader.NamespaceURI == "" && !b17)
  495. {
  496. b17 = true;
  497. string s42 = Reader.ReadElementString();
  498. ob.@CurrentPermissions = UInt32.Parse(s42, CultureInfo.InvariantCulture);
  499. }
  500. else
  501. {
  502. UnknownNode(ob);
  503. }
  504. }
  505. else
  506. UnknownNode(ob);
  507. Reader.MoveToContent();
  508. }
  509. ReadEndElement();
  510. return ob;
  511. }
  512. public InventoryCollection ReadObject_InventoryCollection(bool isNullable, bool checkType)
  513. {
  514. InventoryCollection ob = null;
  515. if (isNullable && ReadNull()) return null;
  516. if (checkType)
  517. {
  518. System.Xml.XmlQualifiedName t = GetXsiType();
  519. if (t == null)
  520. { }
  521. else if (t.Name != "InventoryCollection" || t.Namespace != "")
  522. throw CreateUnknownTypeException(t);
  523. }
  524. ob = (InventoryCollection)Activator.CreateInstance(typeof(InventoryCollection), true);
  525. Reader.MoveToElement();
  526. while (Reader.MoveToNextAttribute())
  527. {
  528. if (IsXmlnsAttribute(Reader.Name))
  529. {
  530. }
  531. else
  532. {
  533. UnknownNode(ob);
  534. }
  535. }
  536. Reader.MoveToElement();
  537. Reader.MoveToElement();
  538. if (Reader.IsEmptyElement)
  539. {
  540. Reader.Skip();
  541. if (ob.@Folders == null)
  542. {
  543. ob.@Folders = new System.Collections.Generic.Dictionary<UUID, InventoryFolderWithChildren>();
  544. }
  545. if (ob.@Items == null)
  546. {
  547. ob.@Items = new System.Collections.Generic.Dictionary<UUID, InventoryItemBase>();
  548. }
  549. return ob;
  550. }
  551. Reader.ReadStartElement();
  552. Reader.MoveToContent();
  553. bool b43 = false, b44 = false, b45 = false;
  554. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  555. {
  556. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  557. {
  558. if (Reader.LocalName == "UserID" && Reader.NamespaceURI == "" && !b45)
  559. {
  560. b45 = true;
  561. ob.@UserID = ReadObject_UUID(false, true);
  562. }
  563. else if (Reader.LocalName == "Items" && Reader.NamespaceURI == "" && !b44)
  564. {
  565. System.Collections.Generic.Dictionary<UUID, InventoryItemBase> o46 = ob.@Items;
  566. if (((object)o46) == null)
  567. {
  568. o46 = new System.Collections.Generic.Dictionary<UUID, InventoryItemBase>();
  569. ob.@Items = o46;
  570. }
  571. if (Reader.IsEmptyElement)
  572. {
  573. Reader.Skip();
  574. }
  575. else
  576. {
  577. int n47 = 0;
  578. Reader.ReadStartElement();
  579. Reader.MoveToContent();
  580. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  581. {
  582. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  583. {
  584. if (Reader.LocalName == "InventoryItemBase" && Reader.NamespaceURI == "")
  585. {
  586. if (((object)o46) == null)
  587. throw CreateReadOnlyCollectionException("System.Collections.Generic.List<InventoryItemBase>");
  588. InventoryItemBase item = ReadObject_InventoryItem(true, true);
  589. o46.Add(item.ID, item);
  590. n47++;
  591. }
  592. else UnknownNode(null);
  593. }
  594. else UnknownNode(null);
  595. Reader.MoveToContent();
  596. }
  597. ReadEndElement();
  598. }
  599. b44 = true;
  600. }
  601. else if (Reader.LocalName == "Folders" && Reader.NamespaceURI == "" && !b43)
  602. {
  603. System.Collections.Generic.Dictionary<UUID, InventoryFolderWithChildren> o48 = ob.@Folders;
  604. if (((object)o48) == null)
  605. {
  606. o48 = new System.Collections.Generic.Dictionary<UUID, InventoryFolderWithChildren>();
  607. ob.@Folders = o48;
  608. }
  609. if (Reader.IsEmptyElement)
  610. {
  611. Reader.Skip();
  612. }
  613. else
  614. {
  615. int n49 = 0;
  616. Reader.ReadStartElement();
  617. Reader.MoveToContent();
  618. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  619. {
  620. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  621. {
  622. if (Reader.LocalName == "InventoryFolderBase" && Reader.NamespaceURI == "")
  623. {
  624. if (((object)o48) == null)
  625. throw CreateReadOnlyCollectionException("System.Collections.Generic.List<InventoryFolderBase>");
  626. InventoryFolderWithChildren folder = ReadObject_InventoryFolder(true, true);
  627. o48.Add(folder.ID, folder);
  628. n49++;
  629. }
  630. else UnknownNode(null);
  631. }
  632. else UnknownNode(null);
  633. Reader.MoveToContent();
  634. }
  635. ReadEndElement();
  636. }
  637. b43 = true;
  638. }
  639. else
  640. {
  641. UnknownNode(ob);
  642. }
  643. }
  644. else
  645. UnknownNode(ob);
  646. Reader.MoveToContent();
  647. }
  648. if (ob.@Folders == null)
  649. {
  650. ob.@Folders = new System.Collections.Generic.Dictionary<UUID, InventoryFolderWithChildren>();
  651. }
  652. if (ob.@Items == null)
  653. {
  654. ob.@Items = new System.Collections.Generic.Dictionary<UUID, InventoryItemBase>();
  655. }
  656. ReadEndElement();
  657. return ob;
  658. }
  659. public OpenMetaverse.UUID ReadObject_UUID(bool isNullable, bool checkType)
  660. {
  661. OpenMetaverse.UUID ob = (OpenMetaverse.UUID)Activator.CreateInstance(typeof(OpenMetaverse.UUID), true);
  662. System.Xml.XmlQualifiedName t = GetXsiType();
  663. if (t == null)
  664. { }
  665. else if (t.Name != "UUID" || t.Namespace != "")
  666. throw CreateUnknownTypeException(t);
  667. Reader.MoveToElement();
  668. while (Reader.MoveToNextAttribute())
  669. {
  670. if (IsXmlnsAttribute(Reader.Name))
  671. {
  672. }
  673. else
  674. {
  675. UnknownNode(ob);
  676. }
  677. }
  678. Reader.MoveToElement();
  679. Reader.MoveToElement();
  680. if (Reader.IsEmptyElement)
  681. {
  682. Reader.Skip();
  683. return ob;
  684. }
  685. Reader.ReadStartElement();
  686. Reader.MoveToContent();
  687. bool b52 = false;
  688. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  689. {
  690. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  691. {
  692. if (Reader.LocalName == "Guid" && Reader.NamespaceURI == "" && !b52)
  693. {
  694. b52 = true;
  695. string s53 = Reader.ReadElementString();
  696. ob.@Guid = XmlConvert.ToGuid(s53);
  697. }
  698. else
  699. {
  700. UnknownNode(ob);
  701. }
  702. }
  703. else
  704. UnknownNode(ob);
  705. Reader.MoveToContent();
  706. }
  707. ReadEndElement();
  708. return ob;
  709. }
  710. protected override void InitCallbacks()
  711. {
  712. }
  713. protected override void InitIDs()
  714. {
  715. }
  716. }
  717. public class GeneratedWriter : XmlSerializationWriter
  718. {
  719. const string xmlNamespace = "http://www.w3.org/2000/xmlns/";
  720. //static readonly System.Reflection.MethodInfo toBinHexStringMethod = typeof(XmlConvert).GetMethod("ToBinHexString", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic, null, new Type[] { typeof(byte[]) }, null);
  721. //static string ToBinHexString(byte[] input)
  722. //{
  723. // return input == null ? null : (string)toBinHexStringMethod.Invoke(null, new object[] { input });
  724. //}
  725. public void WriteRoot_InventoryFolder(object o)
  726. {
  727. WriteStartDocument();
  728. InventoryFolderWithChildren ob = (InventoryFolderWithChildren)o;
  729. TopLevelElement();
  730. WriteObject_InventoryFolder(ob, "InventoryFolderBase", "", true, false, true);
  731. }
  732. public void WriteRoot_InventoryItem(object o)
  733. {
  734. WriteStartDocument();
  735. InventoryItemBase ob = (InventoryItemBase)o;
  736. TopLevelElement();
  737. WriteObject_InventoryItem(ob, "InventoryItemBase", "", true, false, true);
  738. }
  739. public void WriteRoot_InventoryCollection(object o)
  740. {
  741. WriteStartDocument();
  742. InventoryCollection ob = (InventoryCollection)o;
  743. TopLevelElement();
  744. WriteObject_InventoryCollection(ob, "InventoryCollection", "", true, false, true);
  745. }
  746. void WriteObject_InventoryFolder(InventoryFolderWithChildren ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  747. {
  748. if (((object)ob) == null)
  749. {
  750. if (isNullable)
  751. WriteNullTagLiteral(element, namesp);
  752. return;
  753. }
  754. System.Type type = ob.GetType();
  755. if (type == typeof(InventoryFolderWithChildren))
  756. { }
  757. else
  758. {
  759. throw CreateUnknownTypeException(ob);
  760. }
  761. if (writeWrappingElem)
  762. {
  763. WriteStartElement(element, namesp, ob);
  764. }
  765. if (needType) WriteXsiType("InventoryFolderBase", "");
  766. WriteElementString("Name", "", ob.@Name);
  767. WriteObject_UUID(ob.@Owner, "Owner", "", false, false, true);
  768. WriteObject_UUID(ob.@ParentID, "ParentID", "", false, false, true);
  769. WriteObject_UUID(ob.@ID, "ID", "", false, false, true);
  770. WriteElementString("Type", "", [email protected](CultureInfo.InvariantCulture));
  771. WriteElementString("Version", "", [email protected](CultureInfo.InvariantCulture));
  772. if (writeWrappingElem) WriteEndElement(ob);
  773. }
  774. void WriteObject_InventoryItem(InventoryItemBase ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  775. {
  776. if (((object)ob) == null)
  777. {
  778. if (isNullable)
  779. WriteNullTagLiteral(element, namesp);
  780. return;
  781. }
  782. System.Type type = ob.GetType();
  783. if (type == typeof(InventoryItemBase))
  784. { }
  785. else
  786. {
  787. throw CreateUnknownTypeException(ob);
  788. }
  789. if (writeWrappingElem)
  790. {
  791. WriteStartElement(element, namesp, ob);
  792. }
  793. if (needType) WriteXsiType("InventoryItemBase", "");
  794. WriteObject_UUID(ob.@ID, "ID", "", false, false, true);
  795. WriteElementString("InvType", "", [email protected](CultureInfo.InvariantCulture));
  796. WriteObject_UUID(ob.@Folder, "Folder", "", false, false, true);
  797. WriteObject_UUID(ob.@Owner, "Owner", "", false, false, true);
  798. WriteElementString("Creator", "", ob.@CreatorId);
  799. WriteElementString("Name", "", ob.@Name);
  800. WriteElementString("Description", "", ob.@Description);
  801. WriteElementString("NextPermissions", "", [email protected](CultureInfo.InvariantCulture));
  802. WriteElementString("CurrentPermissions", "", [email protected](CultureInfo.InvariantCulture));
  803. WriteElementString("BasePermissions", "", [email protected](CultureInfo.InvariantCulture));
  804. WriteElementString("EveryOnePermissions", "", [email protected](CultureInfo.InvariantCulture));
  805. WriteElementString("GroupPermissions", "", [email protected](CultureInfo.InvariantCulture));
  806. WriteElementString("AssetType", "", [email protected](CultureInfo.InvariantCulture));
  807. WriteObject_UUID(ob.@AssetID, "AssetID", "", false, false, true);
  808. WriteObject_UUID(ob.@GroupID, "GroupID", "", false, false, true);
  809. WriteElementString("GroupOwned", "", (ob.@GroupOwned ? "true" : "false"));
  810. WriteElementString("SalePrice", "", [email protected](CultureInfo.InvariantCulture));
  811. WriteElementString("SaleType", "", [email protected](CultureInfo.InvariantCulture));
  812. WriteElementString("Flags", "", [email protected](CultureInfo.InvariantCulture));
  813. WriteElementString("CreationDate", "", [email protected](CultureInfo.InvariantCulture));
  814. if (writeWrappingElem) WriteEndElement(ob);
  815. }
  816. void WriteObject_InventoryCollection(InventoryCollection ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  817. {
  818. if (((object)ob) == null)
  819. {
  820. if (isNullable)
  821. WriteNullTagLiteral(element, namesp);
  822. return;
  823. }
  824. System.Type type = ob.GetType();
  825. if (type == typeof(InventoryCollection))
  826. { }
  827. else
  828. {
  829. throw CreateUnknownTypeException(ob);
  830. }
  831. if (writeWrappingElem)
  832. {
  833. WriteStartElement(element, namesp, ob);
  834. }
  835. if (needType) WriteXsiType("InventoryCollection", "");
  836. if (ob.@Folders != null)
  837. {
  838. WriteStartElement("Folders", "", ob.@Folders);
  839. foreach (InventoryFolderWithChildren folder in ob.Folders.Values)
  840. {
  841. WriteObject_InventoryFolder(folder, "InventoryFolderBase", "", true, false, true);
  842. }
  843. WriteEndElement(ob.@Folders);
  844. }
  845. if (ob.@Items != null)
  846. {
  847. WriteStartElement("Items", "", ob.@Items);
  848. foreach (InventoryItemBase item in ob.Items.Values)
  849. {
  850. WriteObject_InventoryItem(item, "InventoryItemBase", "", true, false, true);
  851. }
  852. WriteEndElement(ob.@Items);
  853. }
  854. WriteObject_UUID(ob.@UserID, "UserID", "", false, false, true);
  855. if (writeWrappingElem) WriteEndElement(ob);
  856. }
  857. void WriteObject_UUID(OpenMetaverse.UUID ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  858. {
  859. System.Type type = ob.GetType();
  860. if (type == typeof(OpenMetaverse.UUID))
  861. { }
  862. else
  863. {
  864. throw CreateUnknownTypeException(ob);
  865. }
  866. if (writeWrappingElem)
  867. {
  868. WriteStartElement(element, namesp, ob);
  869. }
  870. if (needType) WriteXsiType("UUID", "");
  871. WriteElementString("Guid", "", XmlConvert.ToString(ob.@Guid));
  872. if (writeWrappingElem) WriteEndElement(ob);
  873. }
  874. protected override void InitCallbacks()
  875. {
  876. }
  877. }
  878. public class BaseXmlSerializer : System.Xml.Serialization.XmlSerializer
  879. {
  880. protected override System.Xml.Serialization.XmlSerializationReader CreateReader()
  881. {
  882. return new GeneratedReader();
  883. }
  884. protected override System.Xml.Serialization.XmlSerializationWriter CreateWriter()
  885. {
  886. return new GeneratedWriter();
  887. }
  888. public override bool CanDeserialize(System.Xml.XmlReader xmlReader)
  889. {
  890. return true;
  891. }
  892. }
  893. public sealed class InventoryFolderSerializer : BaseXmlSerializer
  894. {
  895. protected override void Serialize(object obj, System.Xml.Serialization.XmlSerializationWriter writer)
  896. {
  897. ((GeneratedWriter)writer).WriteRoot_InventoryFolder(obj);
  898. }
  899. protected override object Deserialize(System.Xml.Serialization.XmlSerializationReader reader)
  900. {
  901. return ((GeneratedReader)reader).ReadRoot_InventoryFolderBase();
  902. }
  903. }
  904. public sealed class InventoryItemSerializer : BaseXmlSerializer
  905. {
  906. protected override void Serialize(object obj, System.Xml.Serialization.XmlSerializationWriter writer)
  907. {
  908. ((GeneratedWriter)writer).WriteRoot_InventoryItem(obj);
  909. }
  910. protected override object Deserialize(System.Xml.Serialization.XmlSerializationReader reader)
  911. {
  912. return ((GeneratedReader)reader).ReadRoot_InventoryItemBase();
  913. }
  914. }
  915. public sealed class InventoryCollectionSerializer : BaseXmlSerializer
  916. {
  917. protected override void Serialize(object obj, System.Xml.Serialization.XmlSerializationWriter writer)
  918. {
  919. ((GeneratedWriter)writer).WriteRoot_InventoryCollection(obj);
  920. }
  921. protected override object Deserialize(System.Xml.Serialization.XmlSerializationReader reader)
  922. {
  923. return ((GeneratedReader)reader).ReadRoot_InventoryCollection();
  924. }
  925. }
  926. #endregion XML Serialization
  927. }
  928. }