Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOLegacyScriptWhitelist.h
Go to the documentation of this file.
1/*
2
3OOLegacyScriptWhitelist.h
4
5Functions to apply method whitelist and basic tokenization to legacy scripts.
6
7
8A sanitized script is an array of zero or more sanitized statements.
9
10A sanitized statement is an array whose first element is a boolean indicating
11whether it's a conditional statement (true) or an action statement (false).
12
13A conditional statement has three additional elements. The first is an array
14of sanitized conditions (see below). The second is a sanitized script to
15execute if the condition evaluates to true. The third is a sanitized script to
16execute if the condition evaluates to false.
17
18An action statement has one or two additional elements, both strings. The
19first is a selector. If the selector ends with a colon (i.e., takes an
20argument), the second is the argument.
21
22
23A sanitized condition is an array of the form:
24 (opType, rawString, selector, comparisonType, operandArray).
25
26opType and comparisonType are NSNumbers containing OOOperationType and
27OOComparisonType enumerators, respectively.
28
29rawString is the original textual representation of the condition for
30display purposes.
31
32selector is a string, either a method selector or a mission/local
33variable name.
34
35operandArray is an array of operands. Each operand is itself an array
36of two items: a boolean indicating whether it's a method selector
37(true) or a string (false), and a string.
38
39The special opType OP_FALSE doesn't require any other elements in the
40array. All other valid opTypes require the array to have five elements.
41
42
43A complete example: given the following script (the Cloaking Device mission
44script from Oolite 1.65):
45 (
46 {
47 conditions = (
48 "galaxy_number equal 4",
49 "status_string equal STATUS_EXITING_WITCHSPACE",
50 "mission_cloak undefined"
51 );
52 do = (
53 {
54 conditions = ("mission_cloakcounter undefined");
55 do = ("set: mission_cloakcounter 0");
56 },
57 "increment: mission_cloakcounter",
58 "checkForShips: asp-cloaked",
59 {
60 conditions = ("shipsFound_number equal 0", "mission_cloakcounter greaterthan 6");
61 do = ("addShips: asp-cloaked 1", "addShips: asp-pirate 2");
62 }
63 );
64 }
65 )
66the sanitized form (with rawString values replaced with "..." for simplicity) is:
67 (
68 (
69 true, // This is a conditonal statement
70 ( // conditions
71 (OP_NUMBER, "...", "galaxy_number", COMPARISON_EQUAL, ((false, "4"))),
72 (OP_STRING, "...", "status_string", COMPARISON_EQUAL, ((false, "STATUS_EXITING_WITCHSPACE"))),
73 (OP_MISSION_VAR, "...", "mission_cloak", COMPARISON_UNDEFINED, ())
74 ),
75 ( // do
76 (
77 true,
78 ( (OP_MISSION_VAR, "...", "mission_cloakcounter", COMPARISON_UNDEFINED, ()) ),
79 ( (false, "set:", "mission_cloakcounter 0") ),
80 ()
81 ),
82 (false, "increment:", "mission_cloakcounter"),
83 (false, "checkForShips:", "asp-cloaked"),
84 (true,
85 (
86 (OP_NUMBER, "...", "shipsFound_number", COMPARISON_EQUAL, ((false, "0"))),
87 (OP_MISSION_VAR, "...", "mission_cloakcounter, COMPARISON_GREATERTHAN, ((false, "6"))),
88 ),
89 (
90 (false, "addShips:", "asp-cloaked 1"),
91 (false, "addShips:", "asp-pirate 2"),
92 ),
93 ()
94 )
95 ),
96 () // else
97 )
98 )
99
100
101Oolite
102Copyright (C) 2004-2013 Giles C Williams and contributors
103
104This program is free software; you can redistribute it and/or
105modify it under the terms of the GNU General Public License
106as published by the Free Software Foundation; either version 2
107of the License, or (at your option) any later version.
108
109This program is distributed in the hope that it will be useful,
110but WITHOUT ANY WARRANTY; without even the implied warranty of
111MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
112GNU General Public License for more details.
113
114You should have received a copy of the GNU General Public License
115along with this program; if not, write to the Free Software
116Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
117MA 02110-1301, USA.
118
119*/
120
121#import "OOCocoa.h"
122
123
124// context is used for error messages.
125NSArray *OOSanitizeLegacyScript(NSArray *script, NSString *context, BOOL allowAIMethods);
126NSArray *OOSanitizeLegacyScriptConditions(NSArray *conditions, NSString *context);
127
128
129/* Quick test of whether a conditions array is sanitized. It is assumed that
130 this will only be passed fully-sanitized or fully-unsanitized conditions
131 arrays, so the test doesn't need to be exhaustive.
132
133 Note that OOLegacyConditionsAreSanitized() is *not* called by
134 OOSanitizeLegacyScript(), so that it is not possible to sneak an
135 unwhitelisted "pre-compiled" condition past it.
136*/
137BOOL OOLegacyConditionsAreSanitized(NSArray *conditions);
NSArray * OOSanitizeLegacyScriptConditions(NSArray *conditions, NSString *context)
NSArray * OOSanitizeLegacyScript(NSArray *script, NSString *context, BOOL allowAIMethods)
BOOL OOLegacyConditionsAreSanitized(NSArray *conditions)