plist.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**************************************************************************/
  2. /* plist.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef MACOS_PLIST_H
  31. #define MACOS_PLIST_H
  32. // Property list file format (application/x-plist) parser, property list ASN-1 serialization.
  33. #include "core/crypto/crypto_core.h"
  34. #include "core/io/file_access.h"
  35. #include "core/os/time.h"
  36. class PListNode;
  37. class PList : public RefCounted {
  38. friend class PListNode;
  39. public:
  40. enum PLNodeType {
  41. PL_NODE_TYPE_NIL,
  42. PL_NODE_TYPE_STRING,
  43. PL_NODE_TYPE_ARRAY,
  44. PL_NODE_TYPE_DICT,
  45. PL_NODE_TYPE_BOOLEAN,
  46. PL_NODE_TYPE_INTEGER,
  47. PL_NODE_TYPE_REAL,
  48. PL_NODE_TYPE_DATA,
  49. PL_NODE_TYPE_DATE,
  50. };
  51. private:
  52. struct PListTrailer {
  53. uint8_t offset_size;
  54. uint8_t ref_size;
  55. uint64_t object_num;
  56. uint64_t root_offset_idx;
  57. uint64_t offset_table_start;
  58. };
  59. PListTrailer trailer;
  60. Ref<PListNode> root;
  61. uint64_t read_bplist_var_size_int(Ref<FileAccess> p_file, uint8_t p_size);
  62. Ref<PListNode> read_bplist_obj(Ref<FileAccess> p_file, uint64_t p_offset_idx);
  63. public:
  64. PList();
  65. PList(const String &p_string);
  66. bool load_file(const String &p_filename);
  67. bool load_string(const String &p_string);
  68. PackedByteArray save_asn1() const;
  69. String save_text() const;
  70. Ref<PListNode> get_root();
  71. };
  72. /*************************************************************************/
  73. class PListNode : public RefCounted {
  74. static int _asn1_size_len(uint8_t p_len_octets);
  75. public:
  76. PList::PLNodeType data_type = PList::PLNodeType::PL_NODE_TYPE_NIL;
  77. CharString data_string;
  78. Vector<Ref<PListNode>> data_array;
  79. HashMap<String, Ref<PListNode>> data_dict;
  80. union {
  81. int64_t data_int;
  82. bool data_bool;
  83. double data_real;
  84. };
  85. PList::PLNodeType get_type() const;
  86. Variant get_value() const;
  87. static Ref<PListNode> new_node(const Variant &p_value);
  88. static Ref<PListNode> new_array();
  89. static Ref<PListNode> new_dict();
  90. static Ref<PListNode> new_string(const String &p_string);
  91. static Ref<PListNode> new_data(const String &p_string);
  92. static Ref<PListNode> new_date(const String &p_string);
  93. static Ref<PListNode> new_bool(bool p_bool);
  94. static Ref<PListNode> new_int(int64_t p_int);
  95. static Ref<PListNode> new_real(double p_real);
  96. bool push_subnode(const Ref<PListNode> &p_node, const String &p_key = "");
  97. size_t get_asn1_size(uint8_t p_len_octets) const;
  98. void store_asn1_size(PackedByteArray &p_stream, uint8_t p_len_octets) const;
  99. bool store_asn1(PackedByteArray &p_stream, uint8_t p_len_octets) const;
  100. void store_text(String &p_stream, uint8_t p_indent) const;
  101. PListNode() {}
  102. ~PListNode() {}
  103. };
  104. #endif // MACOS_PLIST_H