30#if OO_OXP_VERIFIER_ENABLED
37@interface OOAIStateMachineVerifierStage (Private)
39- (void) validateAI:(NSString *)aiName;
63 return [_usedAIs count] != 0;
69 NSArray *aiNames =
nil;
70 NSEnumerator *aiEnum =
nil;
71 NSString *aiName =
nil;
72 NSMutableSet *whitelist =
nil;
75 whitelist = [[NSMutableSet alloc] init];
79 _whitelist = [whitelist copy];
82 aiNames = [[_usedAIs allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
83 for (aiEnum = [aiNames objectEnumerator]; (aiName = [aiEnum nextObject]); )
85 [
self validateAI:aiName];
93+ (NSString *) nameForReverseDependencyForVerifier:(
OOOXPVerifier *)verifier
99- (void) stateMachineNamed:(NSString *)name usedByShip:(NSString *)shipName
103 if (name ==
nil)
return;
104 if ([_usedAIs containsObject:name])
return;
105 if (_usedAIs ==
nil) _usedAIs = [[NSMutableSet alloc] init];
106 [_usedAIs addObject:name];
108 fileScanner = [[
self verifier] fileScannerStage];
109 if (![fileScanner fileExists:name
111 referencedFrom:[NSString stringWithFormat:
@"shipdata.plist entry \"%@\
"", shipName]
114 OOLog(
@"verifyOXP.validateAI.notFound",
@"----- WARNING: AI state machine \"%@\
" referenced in shipdata.plist entry \"%@\" could not be found in %@ or in Oolite.", name, shipName, [[
self verifier] oxpDisplayName]);
121@implementation OOAIStateMachineVerifierStage (Private)
123- (void) validateAI:(NSString *)aiName
125 NSString *path =
nil;
126 NSDictionary *aiStateMachine =
nil;
127 NSEnumerator *stateEnum =
nil;
128 NSString *stateKey =
nil;
129 NSDictionary *stateHandlers =
nil;
130 NSEnumerator *handlerEnum =
nil;
131 NSString *handlerKey =
nil;
132 NSArray *handlerActions =
nil;
133 NSEnumerator *actionEnum =
nil;
134 NSString *action =
nil;
136 NSString *selector =
nil;
137 NSMutableSet *badSelectors =
nil;
138 NSString *badSelectorDesc =
nil;
139 NSUInteger index = 0;
141 OOLog(
@"verifyOXP.verbose.validateAI",
@"- Validating AI \"%@\
".", aiName);
145 path = [[[
self verifier] fileScannerStage] pathForFile:aiName inFolder:@"AIs" referencedFrom:@"AI list" checkBuiltIn:NO];
146 if (path ==
nil)
return;
148 badSelectors = [NSMutableSet set];
151 if (aiStateMachine ==
nil)
153 OOLog(
@"verifyOXP.validateAI.failed.notDictPlist",
@"***** ERROR: could not interpret \"%@\
" as a dictionary.", path);
158 for (stateEnum = [aiStateMachine keyEnumerator]; (stateKey = [stateEnum nextObject]); )
160 stateHandlers = [aiStateMachine objectForKey:stateKey];
161 if (![stateHandlers isKindOfClass:[NSDictionary
class]])
163 OOLog(
@"verifyOXP.validateAI.failed.invalidFormat.state",
@"***** ERROR: state \"%@\
" in AI \"%@\" is not a dictionary.", stateKey, aiName);
168 for (handlerEnum = [stateHandlers keyEnumerator]; (handlerKey = [handlerEnum nextObject]); )
170 handlerActions = [stateHandlers objectForKey:handlerKey];
171 if (![handlerActions isKindOfClass:[NSArray
class]])
173 OOLog(
@"verifyOXP.validateAI.failed.invalidFormat.handler",
@"***** ERROR: handler \"%@\
" for state \"%@\" in AI \"%@\" is not an array, ignoring.", handlerKey, stateKey, aiName);
179 for (actionEnum = [handlerActions objectEnumerator]; (action = [actionEnum nextObject]); )
182 if (![action isKindOfClass:[NSString
class]])
184 OOLog(
@"verifyOXP.validateAI.failed.invalidFormat.action",
@"***** ERROR: action %lu in handler \"%@\
" for state \"%@\" in AI \"%@\" is not a string, ignoring.", index - 1, handlerKey, stateKey, aiName);
189 action = [action stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
192 spaceRange = [action rangeOfString:@" "];
193 if (spaceRange.location == NSNotFound) selector = action;
194 else selector = [action substringToIndex:spaceRange.location];
197 if (![_whitelist containsObject:selector])
199 [badSelectors addObject:selector];
205 if ([badSelectors
count] != 0)
207 badSelectorDesc = [[[badSelectors allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@", "];
208 OOLog(
@"verifyOXP.validateAI.failed.badSelector",
@"***** ERROR: the AI \"%@\
" uses %lu unpermitted method%s: %@", aiName, [badSelectors
count], ([badSelectors
count] == 1) ?
"" :
"s", badSelectorDesc);
static NSString *const kStageName
#define OOLogOutdentIf(class)
#define OOLog(class, format,...)
#define OOLogIndentIf(class)
NSDictionary * OODictionaryFromFile(NSString *path)
NSDictionary * whitelistDictionary()