| 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 |  | 
|---|
| 31 | #ifndef MACOS_PLIST_H | 
|---|
| 32 | #define MACOS_PLIST_H | 
|---|
| 33 |  | 
|---|
| 34 | // Property list file format (application/x-plist) parser, property list ASN-1 serialization. | 
|---|
| 35 |  | 
|---|
| 36 | #include "core/crypto/crypto_core.h" | 
|---|
| 37 | #include "core/io/file_access.h" | 
|---|
| 38 | #include "core/os/time.h" | 
|---|
| 39 |  | 
|---|
| 40 | class PListNode; | 
|---|
| 41 |  | 
|---|
| 42 | class PList : public RefCounted { | 
|---|
| 43 | friend class PListNode; | 
|---|
| 44 |  | 
|---|
| 45 | public: | 
|---|
| 46 | enum PLNodeType { | 
|---|
| 47 | PL_NODE_TYPE_NIL, | 
|---|
| 48 | PL_NODE_TYPE_STRING, | 
|---|
| 49 | PL_NODE_TYPE_ARRAY, | 
|---|
| 50 | PL_NODE_TYPE_DICT, | 
|---|
| 51 | PL_NODE_TYPE_BOOLEAN, | 
|---|
| 52 | PL_NODE_TYPE_INTEGER, | 
|---|
| 53 | PL_NODE_TYPE_REAL, | 
|---|
| 54 | PL_NODE_TYPE_DATA, | 
|---|
| 55 | PL_NODE_TYPE_DATE, | 
|---|
| 56 | }; | 
|---|
| 57 |  | 
|---|
| 58 | private: | 
|---|
| 59 | struct PListTrailer { | 
|---|
| 60 | uint8_t offset_size; | 
|---|
| 61 | uint8_t ref_size; | 
|---|
| 62 | uint64_t object_num; | 
|---|
| 63 | uint64_t root_offset_idx; | 
|---|
| 64 | uint64_t offset_table_start; | 
|---|
| 65 | }; | 
|---|
| 66 |  | 
|---|
| 67 | PListTrailer trailer; | 
|---|
| 68 | Ref<PListNode> root; | 
|---|
| 69 |  | 
|---|
| 70 | uint64_t read_bplist_var_size_int(Ref<FileAccess> p_file, uint8_t p_size); | 
|---|
| 71 | Ref<PListNode> read_bplist_obj(Ref<FileAccess> p_file, uint64_t p_offset_idx); | 
|---|
| 72 |  | 
|---|
| 73 | public: | 
|---|
| 74 | PList(); | 
|---|
| 75 | PList(const String &p_string); | 
|---|
| 76 |  | 
|---|
| 77 | bool load_file(const String &p_filename); | 
|---|
| 78 | bool load_string(const String &p_string); | 
|---|
| 79 |  | 
|---|
| 80 | PackedByteArray save_asn1() const; | 
|---|
| 81 | String save_text() const; | 
|---|
| 82 |  | 
|---|
| 83 | Ref<PListNode> get_root(); | 
|---|
| 84 | }; | 
|---|
| 85 |  | 
|---|
| 86 | /*************************************************************************/ | 
|---|
| 87 |  | 
|---|
| 88 | class PListNode : public RefCounted { | 
|---|
| 89 | static int _asn1_size_len(uint8_t p_len_octets); | 
|---|
| 90 |  | 
|---|
| 91 | public: | 
|---|
| 92 | PList::PLNodeType data_type = PList::PLNodeType::PL_NODE_TYPE_NIL; | 
|---|
| 93 |  | 
|---|
| 94 | CharString data_string; | 
|---|
| 95 | Vector<Ref<PListNode>> data_array; | 
|---|
| 96 | HashMap<String, Ref<PListNode>> data_dict; | 
|---|
| 97 | union { | 
|---|
| 98 | int64_t data_int; | 
|---|
| 99 | bool data_bool; | 
|---|
| 100 | double data_real; | 
|---|
| 101 | }; | 
|---|
| 102 |  | 
|---|
| 103 | PList::PLNodeType get_type() const; | 
|---|
| 104 | Variant get_value() const; | 
|---|
| 105 |  | 
|---|
| 106 | static Ref<PListNode> new_node(const Variant &p_value); | 
|---|
| 107 | static Ref<PListNode> new_array(); | 
|---|
| 108 | static Ref<PListNode> new_dict(); | 
|---|
| 109 | static Ref<PListNode> new_string(const String &p_string); | 
|---|
| 110 | static Ref<PListNode> new_data(const String &p_string); | 
|---|
| 111 | static Ref<PListNode> new_date(const String &p_string); | 
|---|
| 112 | static Ref<PListNode> new_bool(bool p_bool); | 
|---|
| 113 | static Ref<PListNode> new_int(int64_t p_int); | 
|---|
| 114 | static Ref<PListNode> new_real(double p_real); | 
|---|
| 115 |  | 
|---|
| 116 | bool push_subnode(const Ref<PListNode> &p_node, const String &p_key = ""); | 
|---|
| 117 |  | 
|---|
| 118 | size_t get_asn1_size(uint8_t p_len_octets) const; | 
|---|
| 119 |  | 
|---|
| 120 | void store_asn1_size(PackedByteArray &p_stream, uint8_t p_len_octets) const; | 
|---|
| 121 | bool store_asn1(PackedByteArray &p_stream, uint8_t p_len_octets) const; | 
|---|
| 122 | void store_text(String &p_stream, uint8_t p_indent) const; | 
|---|
| 123 |  | 
|---|
| 124 | PListNode() {} | 
|---|
| 125 | ~PListNode() {} | 
|---|
| 126 | }; | 
|---|
| 127 |  | 
|---|
| 128 | #endif // MACOS_PLIST_H | 
|---|
| 129 |  | 
|---|