Skip to content

Commit 31dae91

Browse files
committed
FEAT: added optional codec (decoder) for plist files
1 parent 7447dc0 commit 31dae91

File tree

4 files changed

+230
-0
lines changed

4 files changed

+230
-0
lines changed

make/rebol3.nest

+2
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ include-codec-ico: [
566566
include-codec-json: [mezz-lib-files: %mezz/codec-json.reb ]
567567
include-codec-xml: [mezz-lib-files: %mezz/codec-xml.reb ]
568568
include-codec-pdf: [mezz-lib-files: %mezz/codec-pdf.reb :include-png-filter-native] ; pdf may use special png pre-compression
569+
include-codec-plist: [mezz-lib-files: %mezz/codec-plist.reb ]
569570
include-codec-swf: [mezz-lib-files: %mezz/codec-swf.reb ]
570571
include-codec-wav: [mezz-lib-files: %mezz/codec-wav.reb ]
571572
include-codec-unixtime: [mezz-lib-files: %mezz/codec-unixtime.reb ]
@@ -636,6 +637,7 @@ include-rebol-bulk: [
636637
:include-codec-xml
637638
:include-codec-wav
638639
:include-codec-ico
640+
:include-codec-plist
639641

640642
:include-image-codecs ; use other optional image codecs before this include!
641643

src/mezz/codec-plist.reb

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
]

src/tests/units/codecs-test.r3

+10
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,16 @@ if find codecs 'html-entities [
539539
===end-group===
540540
]
541541

542+
try [import 'plist]
543+
if find codecs 'plist [
544+
===start-group=== "PLIST codec"
545+
--test-- "Load PLIST file (XML version)"
546+
--assert map? data: load %units/files/Some.plist
547+
--assert data/AppIDName = "Test Application"
548+
--assert data/UUID = "bba91992-3a72-46b3-bc5f-f7b59aa49236"
549+
===end-group===
550+
]
551+
542552
;@@ PDF codec test is in: codecs-test-pdf.r3
543553

544554
~~~end-file~~~

src/tests/units/files/Some.plist

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AppIDName</key>
6+
<string>Test Application</string>
7+
<key>ApplicationIdentifierPrefix</key>
8+
<array>
9+
<string>XXXXXXXXXX</string>
10+
</array>
11+
<key>CreationDate</key>
12+
<date>2022-03-25T11:00:04Z</date>
13+
<key>Platform</key>
14+
<array>
15+
<string>OSX</string>
16+
</array>
17+
<key>IsXcodeManaged</key>
18+
<true/>
19+
<key>DeveloperCertificates</key>
20+
<array>
21+
<data>UGxhY2Vob2xkZXI=</data>
22+
<data>Q2VydGlmaWNhdGU=</data>
23+
</array>
24+
25+
<key>DER-Encoded-Profile</key>
26+
<data>UGxhY2Vob2xkZXI=</data>
27+
28+
<key>Entitlements</key>
29+
<dict>
30+
31+
<key>com.apple.developer.arcade-operations</key>
32+
<true/>
33+
34+
<key>com.apple.application-identifier</key>
35+
<string>XXXXXXXXXX.application.test</string>
36+
37+
<key>keychain-access-groups</key>
38+
<array>
39+
<string>XXXXXXXXXX.*</string>
40+
</array>
41+
42+
<key>com.apple.developer.team-identifier</key>
43+
<string>XXXXXXXXXX</string>
44+
45+
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
46+
<string>XXXXXXXXXX.*</string>
47+
48+
<key>com.apple.developer.ubiquity-container-identifiers</key>
49+
<array>
50+
<string>XXXXXXXXXX.*</string>
51+
</array>
52+
53+
</dict>
54+
<key>ExpirationDate</key>
55+
<date>2023-03-25T11:00:04Z</date>
56+
<key>Name</key>
57+
<string>Mac Team Provisioning Profile: application.test</string>
58+
<key>ProvisionedDevices</key>
59+
<array>
60+
<string>DA3279C7-4CA2-5F13-AD90-7FC271175118</string>
61+
<string>94FAF6E4-BE34-5B0B-9533-78B245EF4174</string>
62+
</array>
63+
<key>TeamIdentifier</key>
64+
<array>
65+
<string>XXXXXXXXXX</string>
66+
</array>
67+
<key>TeamName</key>
68+
<string>Some Company s.r.o.</string>
69+
<key>TimeToLive</key>
70+
<integer>365</integer>
71+
<key>UUID</key>
72+
<string>bba91992-3a72-46b3-bc5f-f7b59aa49236</string>
73+
<key>Version</key>
74+
<integer>1</integer>
75+
</dict>
76+
</plist>

0 commit comments

Comments
 (0)