2014-05-14 03:06:59 +02:00
|
|
|
/* EOQualifier+SOGoCacheObject.m - this file is part of SOGo
|
2010-12-13 18:15:54 +01:00
|
|
|
*
|
2014-05-14 03:06:59 +02:00
|
|
|
* Copyright (C) 2010-2014 Inverse inc
|
2010-12-13 18:15:54 +01:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
2011-08-12 00:56:04 +02:00
|
|
|
#import <Foundation/NSCharacterSet.h>
|
2010-12-13 18:15:54 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2011-08-12 00:56:04 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2010-12-13 18:15:54 +01:00
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
#import "EOBitmaskQualifier.h"
|
2014-05-14 03:06:59 +02:00
|
|
|
#import "SOGoCacheGCSObject.h"
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
#import "EOQualifier+SOGoCacheObject.h"
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
@implementation EOQualifier (SOGoCacheObjectRestrictions)
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (BOOL) _evaluateSOGoMAPIDBObject: (NSDictionary *) properties
|
2010-12-13 18:15:54 +01:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
- (BOOL) evaluateSOGoMAPIDBObject: (SOGoCacheGCSObject *) object
|
2010-12-13 18:15:54 +01:00
|
|
|
{
|
|
|
|
NSDictionary *properties;
|
2010-12-30 15:43:08 +01:00
|
|
|
BOOL rc;
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2013-03-13 20:04:11 +01:00
|
|
|
//[self logWithFormat: @"evaluating object '%@'", object];
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
properties = [object properties];
|
|
|
|
rc = [self _evaluateSOGoMAPIDBObject: properties];
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2013-03-13 20:04:11 +01:00
|
|
|
//[self logWithFormat: @" evaluation result: %d", rc];
|
2010-12-30 15:43:08 +01:00
|
|
|
|
|
|
|
return rc;
|
2010-12-13 18:15:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
@implementation EOAndQualifier (SOGoCacheRestrictionsPrivate)
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (BOOL) _evaluateSOGoMAPIDBObject: (NSDictionary *) properties
|
2010-12-13 18:15:54 +01:00
|
|
|
{
|
|
|
|
NSUInteger i;
|
|
|
|
BOOL rc;
|
|
|
|
|
|
|
|
rc = YES;
|
|
|
|
|
|
|
|
for (i = 0; rc && i < count; i++)
|
|
|
|
rc = [[qualifiers objectAtIndex: i]
|
2012-06-29 19:59:38 +02:00
|
|
|
_evaluateSOGoMAPIDBObject: properties];
|
2010-12-13 18:15:54 +01:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
@implementation EOOrQualifier (SOGoCacheObjectRestrictionsPrivate)
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (BOOL) _evaluateSOGoMAPIDBObject: (NSDictionary *) properties
|
2010-12-13 18:15:54 +01:00
|
|
|
{
|
|
|
|
NSUInteger i;
|
|
|
|
BOOL rc;
|
|
|
|
|
|
|
|
rc = NO;
|
|
|
|
|
|
|
|
for (i = 0; !rc && i < count; i++)
|
|
|
|
rc = [[qualifiers objectAtIndex: i]
|
2012-06-29 19:59:38 +02:00
|
|
|
_evaluateSOGoMAPIDBObject: properties];
|
2010-12-13 18:15:54 +01:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
@implementation EONotQualifier (SOGoCacheObjectRestrictionsPrivate)
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (BOOL) _evaluateSOGoMAPIDBObject: (NSDictionary *) properties
|
2010-12-13 18:15:54 +01:00
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
return ![qualifier _evaluateSOGoMAPIDBObject: properties];
|
2010-12-13 18:15:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
@implementation EOKeyValueQualifier (SOGoCacheObjectRestrictionsPrivate)
|
2010-12-13 18:15:54 +01:00
|
|
|
|
2011-08-12 00:56:04 +02:00
|
|
|
typedef BOOL (*EOComparator) (id, SEL, id);
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (BOOL) _evaluateSOGoMAPIDBObject: (NSDictionary *) properties
|
2010-12-13 18:15:54 +01:00
|
|
|
{
|
2011-08-12 00:56:04 +02:00
|
|
|
id finalKey;
|
2010-12-13 18:15:54 +01:00
|
|
|
id propValue;
|
2011-08-12 00:56:04 +02:00
|
|
|
EOComparator comparator;
|
|
|
|
|
|
|
|
if ([key isKindOfClass: [NSNumber class]])
|
|
|
|
finalKey = key;
|
|
|
|
else if ([key isKindOfClass: [NSString class]])
|
|
|
|
{
|
|
|
|
finalKey = [key stringByTrimmingCharactersInSet: [NSCharacterSet decimalDigitCharacterSet]];
|
|
|
|
if ([finalKey length] > 0)
|
|
|
|
finalKey = key;
|
|
|
|
else
|
|
|
|
finalKey = [NSNumber numberWithInt: [key intValue]];
|
|
|
|
}
|
2011-09-30 21:46:23 +02:00
|
|
|
else
|
|
|
|
finalKey = @"";
|
|
|
|
|
2011-08-12 00:56:04 +02:00
|
|
|
propValue = [properties objectForKey: finalKey];
|
|
|
|
comparator = (EOComparator) [propValue methodForSelector: operator];
|
|
|
|
|
|
|
|
return (comparator ? comparator (propValue, operator, value) : NO);
|
2010-12-13 18:15:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2010-12-14 21:54:07 +01:00
|
|
|
|
2014-05-14 03:06:59 +02:00
|
|
|
@implementation EOBitmaskQualifier (SOGoCacheObjectRestrictionsPrivate)
|
2010-12-14 21:54:07 +01:00
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (BOOL) _evaluateSOGoMAPIDBObject: (NSDictionary *) properties
|
2010-12-14 21:54:07 +01:00
|
|
|
{
|
|
|
|
NSNumber *propTag;
|
|
|
|
id propValue;
|
|
|
|
uint32_t intValue;
|
|
|
|
BOOL rc;
|
|
|
|
|
|
|
|
propTag = [NSNumber numberWithInt: [key intValue]];
|
|
|
|
propValue = [properties objectForKey: propTag];
|
|
|
|
intValue = [propValue unsignedIntValue];
|
|
|
|
|
|
|
|
rc = ((isZero && (intValue & mask) == 0)
|
|
|
|
|| (!isZero && (intValue & mask) != 0));
|
|
|
|
|
2013-03-13 20:04:11 +01:00
|
|
|
//[self logWithFormat: @"evaluation of bitmask qualifier:"
|
|
|
|
// @" (%.8x & %.8x) %s 0: %d",
|
|
|
|
// intValue, mask, (isZero ? "==" : "!="), rc];
|
2010-12-14 21:54:07 +01:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|