Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOAIStateMachineVerifierStage(Private) Category Reference

Instance Methods

(void) - validateAI:
 

Detailed Description

Definition at line 37 of file OOAIStateMachineVerifierStage.m.

Method Documentation

◆ validateAI:

- (void) validateAI: (NSString *) aiName

Extends class OOAIStateMachineVerifierStage.

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

123 :(NSString *)aiName
124{
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;
135 NSRange spaceRange;
136 NSString *selector = nil;
137 NSMutableSet *badSelectors = nil;
138 NSString *badSelectorDesc = nil;
139 NSUInteger index = 0;
140
141 OOLog(@"verifyOXP.verbose.validateAI", @"- Validating AI \"%@\".", aiName);
142 OOLogIndentIf(@"verifyOXP.verbose.validateAI");
143
144 // Attempt to load AI.
145 path = [[[self verifier] fileScannerStage] pathForFile:aiName inFolder:@"AIs" referencedFrom:@"AI list" checkBuiltIn:NO];
146 if (path == nil) return;
147
148 badSelectors = [NSMutableSet set];
149
150 aiStateMachine = OODictionaryFromFile(path);
151 if (aiStateMachine == nil)
152 {
153 OOLog(@"verifyOXP.validateAI.failed.notDictPlist", @"***** ERROR: could not interpret \"%@\" as a dictionary.", path);
154 return;
155 }
156
157 // Validate each state.
158 for (stateEnum = [aiStateMachine keyEnumerator]; (stateKey = [stateEnum nextObject]); )
159 {
160 stateHandlers = [aiStateMachine objectForKey:stateKey];
161 if (![stateHandlers isKindOfClass:[NSDictionary class]])
162 {
163 OOLog(@"verifyOXP.validateAI.failed.invalidFormat.state", @"***** ERROR: state \"%@\" in AI \"%@\" is not a dictionary.", stateKey, aiName);
164 continue;
165 }
166
167 // Verify handlers for this state.
168 for (handlerEnum = [stateHandlers keyEnumerator]; (handlerKey = [handlerEnum nextObject]); )
169 {
170 handlerActions = [stateHandlers objectForKey:handlerKey];
171 if (![handlerActions isKindOfClass:[NSArray class]])
172 {
173 OOLog(@"verifyOXP.validateAI.failed.invalidFormat.handler", @"***** ERROR: handler \"%@\" for state \"%@\" in AI \"%@\" is not an array, ignoring.", handlerKey, stateKey, aiName);
174 continue;
175 }
176
177 // Verify commands for this handler.
178 index = 0;
179 for (actionEnum = [handlerActions objectEnumerator]; (action = [actionEnum nextObject]); )
180 {
181 index++;
182 if (![action isKindOfClass:[NSString class]])
183 {
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);
185 continue;
186 }
187
188 // Trim spaces from beginning and end.
189 action = [action stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
190
191 // Cut off parameters.
192 spaceRange = [action rangeOfString:@" "];
193 if (spaceRange.location == NSNotFound) selector = action;
194 else selector = [action substringToIndex:spaceRange.location];
195
196 // Check against whitelist.
197 if (![_whitelist containsObject:selector])
198 {
199 [badSelectors addObject:selector];
200 }
201 }
202 }
203 }
204
205 if ([badSelectors count] != 0)
206 {
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);
209 }
210
211 OOLogOutdentIf(@"verifyOXP.verbose.validateAI");
212}
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLog(class, format,...)
Definition OOLogging.h:88
#define OOLogIndentIf(class)
Definition OOLogging.h:101
NSDictionary * OODictionaryFromFile(NSString *path)
unsigned count
return nil

The documentation for this category was generated from the following file: