|
| 1 | +REBOL [ |
| 2 | + name: plist |
| 3 | + type: module |
| 4 | + options: [delay] |
| 5 | + version: 0.0.1 |
| 6 | + title: "REBOL 3 codec for PLIST files" |
| 7 | + file: https://raw.githubusercontent.com/Oldes/Rebol3/master/src/mezz/codec-plist.reb |
| 8 | + author: "Oldes" |
| 9 | + history: [ |
| 10 | + 07-Apr-2022 "Oldes" {Initial version of the PLIST decoder} |
| 11 | + ] |
| 12 | + References: [ |
| 13 | + https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html |
| 14 | + https://medium.com/@karaiskc/understanding-apples-binary-property-list-format-281e6da00dbd |
| 15 | + ] |
| 16 | + todo: { |
| 17 | + * Support binary PLIST version |
| 18 | + * PLIST encoder |
| 19 | + } |
| 20 | +] |
| 21 | + |
| 22 | +system/options/log/plist: 1 |
| 23 | + |
| 24 | +stack: copy [] |
| 25 | +key: value: none |
| 26 | + |
| 27 | +~spnl: system/catalog/bitsets/whitespace |
| 28 | + |
| 29 | +~dict: [ |
| 30 | + any ~spnl |
| 31 | + <dict> |
| 32 | + ( |
| 33 | + append append stack :key make map! 8 |
| 34 | + ) |
| 35 | + any [ |
| 36 | + ~key |
| 37 | + ~value |
| 38 | + ( |
| 39 | + put last stack :key :value |
| 40 | + ) |
| 41 | + | any ~spnl |
| 42 | + ] |
| 43 | + any ~comment |
| 44 | + </dict> |
| 45 | + ( |
| 46 | + value: take/last stack |
| 47 | + key: take/last stack |
| 48 | + ) |
| 49 | +] |
| 50 | +~key: [<key> any ~spnl copy key: to </key> thru #">" (try [key: to word! key])] |
| 51 | +~string: [<string> any ~spnl copy value: to </string> thru #">" ] |
| 52 | +~data: [<data> any ~spnl copy value: to </data> thru #">" (value: debase value 64)] |
| 53 | +~date: [<date> any ~spnl copy value: to </date> thru #">" (value: to-date value)] |
| 54 | +~integer: [<integer> any ~spnl copy value: to </integer> thru #">" (value: to integer! value)] |
| 55 | +~real: [<real> any ~spnl copy value: to </real> thru #">" (value: to decimal! value)] |
| 56 | +~true: [<true/> (value: true )] |
| 57 | +~false: [<false/> (value: false)] |
| 58 | +~array: [ |
| 59 | + <array> |
| 60 | + (append/only stack copy []) |
| 61 | + any [~value (append/only last stack :value) any ~spnl] |
| 62 | + </array> |
| 63 | + (value: take/last stack) |
| 64 | +] |
| 65 | +~comment: [any ~spnl opt ["<!--" thru "-->"]] |
| 66 | + |
| 67 | +~value: [ |
| 68 | + any ~comment [ |
| 69 | + ~string |
| 70 | + | ~true |
| 71 | + | ~false |
| 72 | + | ~array |
| 73 | + | ~dict |
| 74 | + | ~date |
| 75 | + | ~data |
| 76 | + | ~integer |
| 77 | + | ~real |
| 78 | + ] |
| 79 | +] |
| 80 | + |
| 81 | +register-codec [ |
| 82 | + name: 'plist |
| 83 | + type: 'text |
| 84 | + title: "Property List File Format" |
| 85 | + suffixes: [%.plist] |
| 86 | + |
| 87 | + decode: function [ |
| 88 | + {Extract content of the PLIST file} |
| 89 | + data [binary! file! url!] |
| 90 | + ;return: [map!] |
| 91 | + ] [ |
| 92 | + verbose: system/options/log/plist |
| 93 | + unless binary? data [ data: read data ] |
| 94 | + if verbose > 0 [ |
| 95 | + sys/log/info 'PLIST ["^[[1;32mDecode PLIST data^[[m (^[[1m" length? data "^[[mbytes )"] |
| 96 | + ] |
| 97 | + unless parse to string! data [ |
| 98 | + thru "<plist " thru #">" |
| 99 | + ~dict |
| 100 | + any ~comment |
| 101 | + </plist> |
| 102 | + to end |
| 103 | + ][ return none ] |
| 104 | + |
| 105 | + if verbose: system/options/log/plist > 0 [ |
| 106 | + foreach [k v] value [ |
| 107 | + switch to word! k [ |
| 108 | + DeveloperCertificates [ |
| 109 | + v: copy v |
| 110 | + forall v [ |
| 111 | + try [ |
| 112 | + crt: codecs/crt/decode v/1 |
| 113 | + change/only v compose [ |
| 114 | + commonName: (crt/subject/commonName) |
| 115 | + valid-to: (crt/valid-to) |
| 116 | + fingerprint: (crt/fingerprint) |
| 117 | + ] |
| 118 | + ] |
| 119 | + ] |
| 120 | + ] |
| 121 | + DER-Encoded-Profile [ |
| 122 | + sys/log/more 'PLIST ajoin [as-green k ": " mold v] |
| 123 | + continue |
| 124 | + ] |
| 125 | + ] |
| 126 | + sys/log 'PLIST ajoin [as-green k ": " mold v] |
| 127 | + ] |
| 128 | + ] |
| 129 | + |
| 130 | + value |
| 131 | + ] |
| 132 | + |
| 133 | + ;encode: function [data [binary!]][ ] |
| 134 | + |
| 135 | + identify: function [data [binary!]][ |
| 136 | + ; just a simple test if there are key parts... |
| 137 | + parse data [ |
| 138 | + thru "<!DOCTYPE plist" |
| 139 | + thru "<plist " to end |
| 140 | + ] |
| 141 | + ] |
| 142 | +] |
0 commit comments