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 NSString *aiName =
nil;
71 NSMutableSet *whitelist =
nil;
74 whitelist = [[NSMutableSet alloc] init];
78 _whitelist = [whitelist copy];
81 aiNames = [[_usedAIs allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
82 foreach (aiName, aiNames)
84 [
self validateAI:aiName];
92+ (NSString *) nameForReverseDependencyForVerifier:(
OOOXPVerifier *)verifier
98- (void) stateMachineNamed:(NSString *)name usedByShip:(NSString *)shipName
102 if (name ==
nil)
return;
103 if ([_usedAIs containsObject:name]) return;
104 if (_usedAIs ==
nil) _usedAIs = [[NSMutableSet alloc] init];
105 [_usedAIs addObject:name];
107 fileScanner = [[
self verifier] fileScannerStage];
108 if (![fileScanner fileExists:name
110 referencedFrom:[NSString stringWithFormat:
@"shipdata.plist entry \"%@\
"", shipName]
113 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]);
120@implementation OOAIStateMachineVerifierStage (Private)
122- (void) validateAI:(NSString *)aiName
124 NSString *path =
nil;
125 NSDictionary *aiStateMachine =
nil;
126 NSString *stateKey =
nil;
127 NSDictionary *stateHandlers =
nil;
128 NSString *handlerKey =
nil;
129 NSArray *handlerActions =
nil;
130 NSString *action =
nil;
132 NSString *selector =
nil;
133 NSMutableSet *badSelectors =
nil;
134 NSString *badSelectorDesc =
nil;
135 NSUInteger index = 0;
137 OOLog(
@"verifyOXP.verbose.validateAI",
@"- Validating AI \"%@\
".", aiName);
141 path = [[[
self verifier] fileScannerStage] pathForFile:aiName inFolder:@"AIs" referencedFrom:@"AI list" checkBuiltIn:NO];
142 if (path ==
nil)
return;
144 badSelectors = [NSMutableSet set];
147 if (aiStateMachine ==
nil)
149 OOLog(
@"verifyOXP.validateAI.failed.notDictPlist",
@"***** ERROR: could not interpret \"%@\
" as a dictionary.", path);
156 stateHandlers = [aiStateMachine objectForKey:stateKey];
157 if (![stateHandlers isKindOfClass:[NSDictionary class]])
159 OOLog(
@"verifyOXP.validateAI.failed.invalidFormat.state",
@"***** ERROR: state \"%@\
" in AI \"%@\" is not a dictionary.", stateKey, aiName);
166 handlerActions = [stateHandlers objectForKey:handlerKey];
167 if (![handlerActions isKindOfClass:[NSArray class]])
169 OOLog(
@"verifyOXP.validateAI.failed.invalidFormat.handler",
@"***** ERROR: handler \"%@\
" for state \"%@\" in AI \"%@\" is not an array, ignoring.", handlerKey, stateKey, aiName);
175 foreach (action, handlerActions)
178 if (![action isKindOfClass:[NSString class]])
180 OOLog(
@"verifyOXP.validateAI.failed.invalidFormat.action",
@"***** ERROR: action %llu in handler \"%@\
" for state \"%@\" in AI \"%@\" is not a string, ignoring.", index - 1, handlerKey, stateKey, aiName);
185 action = [action stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
188 spaceRange = [action rangeOfString:@" "];
189 if (spaceRange.location == NSNotFound) selector = action;
190 else selector = [action substringToIndex:spaceRange.location];
193 if (![_whitelist containsObject:selector])
195 [badSelectors addObject:selector];
201 if ([badSelectors
count] != 0)
203 badSelectorDesc = [[[badSelectors allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@", "];
204 OOLog(
@"verifyOXP.validateAI.failed.badSelector",
@"***** ERROR: the AI \"%@\
" uses %llu unpermitted method%s: %@", aiName, [badSelectors
count], ([badSelectors
count] == 1) ?
"" :
"s", badSelectorDesc);
static NSString *const kStageName
#define foreachkey(VAR, DICT)
#define OOLogOutdentIf(class)
#define OOLog(class, format,...)
#define OOLogIndentIf(class)
NSDictionary * OODictionaryFromFile(NSString *path)
NSDictionary * whitelistDictionary()