source: trunk/PrefsPane/src/Rule.m @ 1046

Revision 978, 1.5 KB checked in by speck, 17 months ago (diff)

Support for running transformers for non-OK http statuses, e.g. redirects and server errors.

Line 
1/* Copyright (C) 2008-2009 Peter Speck
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#import "Rule.h"
18#import "Xml.h"
19
20@implementation Rule
21
22+ (RuleType)getRuleType:(NSXMLElement*)ruleE
23{
24    NSString* type = [Xml getAttribute:ruleE withName:@"type"];
25    if ([type isEqualToString:@"block"])
26        return BlockRuleType;
27    if ([type isEqualToString:@"modify"]) {
28        if ([[Xml getAttribute:ruleE withName:@"content-type"] isEqual:@"*not-ok*"])
29            return ModifyErrorStatusRuleType;
30        else
31            return ModifyContentRuleType;
32    }
33    if ([type isEqualToString:@"whitelist"])
34        return WhitelistRuleType;
35    if ([type isEqualToString:@"keyword"])
36        return KeywordRuleType;
37    if ([type isEqualToString:@"request"])
38        return RequestRuleType;
39    return UnknownRuleType;
40}
41
42+ (BOOL)ruleIsSafe:(NSXMLElement*)ruleE
43{
44    switch ([Rule getRuleType:ruleE]) {
45        case WhitelistRuleType:
46        case BlockRuleType:
47            return YES;
48        default:
49            return NO;
50    }
51}
52
53@end
Note: See TracBrowser for help on using the repository browser.