/*
- Copyright (C) 2004-2005 SKYRIX Software AG
+ Copyright (C) 2004-2007 SKYRIX Software AG
+ Copyright (C) 2007 Helge Hess
This file is part of OpenGroupware.org.
NSString *path;
NSURL *location;
NSURL *quickLocation;
+ NSURL *aclLocation;
NSString *folderTypeName;
struct {
- (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId
folderTypeName:(NSString *)_ftname folderType:(GCSFolderType *)_ftype
location:(NSURL *)_loc quickLocation:(NSURL *)_qloc
+ aclLocation: (NSURL *)_aloc
folderManager:(GCSFolderManager *)_fm;
/* accessors */
- (NSString *)path;
- (NSURL *)location;
- (NSURL *)quickLocation;
+- (NSURL *)aclLocation;
- (NSString *)folderTypeName;
- (GCSFolderManager *)folderManager;
- (NSString *)storeTableName;
- (NSString *)quickTableName;
+- (NSString *)aclTableName;
- (BOOL)isQuickInfoStoredInContentTable;
/* connection */
- (EOAdaptorChannel *)acquireStoreChannel;
- (EOAdaptorChannel *)acquireQuickChannel;
+- (EOAdaptorChannel *)acquireAclChannel;
- (void)releaseChannel:(EOAdaptorChannel *)_channel;
- (BOOL)canConnectStore;
- (NSArray *)fetchFields:(NSArray *)_flds
fetchSpecification:(EOFetchSpecification *)_fs;
- (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q;
+- (NSArray *)fetchAclMatchingQualifier:(EOQualifier *)_q;
@end
/*
- Copyright (C) 2004-2005 SKYRIX Software AG
+ Copyright (C) 2004-2007 SKYRIX Software AG
+ Copyright (C) 2007 Helge Hess
This file is part of OpenGroupware.org.
- (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId
folderTypeName:(NSString *)_ftname folderType:(GCSFolderType *)_ftype
location:(NSURL *)_loc quickLocation:(NSURL *)_qloc
+ aclLocation:(NSURL *)_aloc
folderManager:(GCSFolderManager *)_fm
{
if (![_loc isNotNull]) {
self->path = [_path copy];
self->location = [_loc retain];
self->quickLocation = _qloc ? [_qloc retain] : [_loc retain];
+ self->aclLocation = [_aloc retain];
self->folderTypeName = [_ftname copy];
-
+
self->ofFlags.requiresFolderSelect = 0;
self->ofFlags.sameTableForQuick =
[self->location isEqualTo:self->quickLocation] ? 1 : 0;
return [self initWithPath:nil primaryKey:nil
folderTypeName:nil folderType:nil
location:nil quickLocation:nil
+ aclLocation:nil
folderManager:nil];
}
+- (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId
+ folderTypeName:(NSString *)_ftname folderType:(GCSFolderType *)_ftype
+ location:(NSURL *)_loc quickLocation:(NSURL *)_qloc
+ folderManager:(GCSFolderManager *)_fm
+{
+ return [self initWithPath:_path primaryKey:_folderId folderTypeName:_ftname
+ folderType:_ftype location:_loc quickLocation:_qloc
+ aclLocation:nil
+ folderManager:_fm];
+}
- (void)dealloc {
[self->folderManager release];
[self->path release];
[self->location release];
[self->quickLocation release];
+ [self->aclLocation release];
[self->folderTypeName release];
[super dealloc];
}
- (NSURL *)quickLocation {
return self->quickLocation;
}
+- (NSURL *)aclLocation {
+ return self->aclLocation;
+}
- (NSString *)folderTypeName {
return self->folderTypeName;
- (NSString *)quickTableName {
return [[self quickLocation] gcsTableName];
}
+- (NSString *)aclTableName {
+ return [[self aclLocation] gcsTableName];
+}
- (BOOL)isQuickInfoStoredInContentTable {
return self->ofFlags.sameTableForQuick ? YES : NO;
- (EOAdaptorChannel *)acquireQuickChannel {
return [[self channelManager] acquireOpenChannelForURL:[self quickLocation]];
}
+- (EOAdaptorChannel *)acquireAclChannel {
+ return [[self channelManager] acquireOpenChannelForURL:[self aclLocation]];
+}
- (void)releaseChannel:(EOAdaptorChannel *)_channel {
[[self channelManager] releaseChannel:_channel];
- (BOOL)canConnectQuick {
return [[self channelManager] canConnect:[self quickLocation]];
}
+- (BOOL)canConnectAcl {
+ return [[self channelManager] canConnect:[self quickLocation]];
+}
/* errors */
return [self fetchFields:_flds fetchSpecification:fs];
}
+- (NSArray *)fetchAclWithSpecification:(EOFetchSpecification *)_fs
+{
+ EOQualifier *qualifier;
+ NSArray *sortOrderings;
+ EOAdaptorChannel *channel;
+ NSException *error;
+ NSMutableString *sql;
+ NSArray *attrs;
+ NSMutableArray *results;
+ NSDictionary *row;
+
+ qualifier = [_fs qualifier];
+ sortOrderings = [_fs sortOrderings];
+
+#if 0
+ [self logWithFormat:@"FETCH: %@", _flds];
+ [self logWithFormat:@" MATCH: %@", _q];
+#endif
+
+ /* generate SQL */
+
+ sql = [NSMutableString stringWithCapacity:256];
+ [sql appendString:@"SELECT c_uid, c_object, c_role"];
+ [sql appendString:@" FROM "];
+ [sql appendString:[self aclTableName]];
+
+ if (qualifier != nil) {
+ [sql appendString:@" WHERE "];
+ [sql appendString:[self generateSQLForQualifier:qualifier]];
+ }
+ if ([sortOrderings count] > 0) {
+ [sql appendString:@" ORDER BY "];
+ [sql appendString:[self generateSQLForSortOrderings:sortOrderings]];
+ }
+#if 0
+ /* limit */
+ [sql appendString:@" LIMIT "]; // count
+ [sql appendString:@" OFFSET "]; // index from 0
+#endif
+
+ /* open channel */
+
+ if ((channel = [self acquireAclChannel]) == nil) {
+ [self logWithFormat:@"ERROR(%s): could not open acl channel!"];
+ return nil;
+ }
+
+ /* run SQL */
+
+ if ((error = [channel evaluateExpressionX:sql]) != nil) {
+ [self logWithFormat:@"ERROR(%s): cannot execute acl-fetch SQL '%@': %@",
+ __PRETTY_FUNCTION__, sql, error];
+ [self releaseChannel:channel];
+ return nil;
+ }
+
+ /* fetch results */
+
+ results = [NSMutableArray arrayWithCapacity:64];
+ attrs = [channel describeResults:NO /* do not beautify names */];
+ while ((row = [channel fetchAttributes:attrs withZone:NULL]) != nil)
+ [results addObject:row];
+
+ /* release channels */
+
+ [self releaseChannel:channel];
+
+ return results;
+}
+- (NSArray *) fetchAclMatchingQualifier:(EOQualifier *)_q {
+ EOFetchSpecification *fs;
+
+ if (_q == nil)
+ fs = nil;
+ else {
+ fs = [EOFetchSpecification fetchSpecificationWithEntityName:
+ [self folderName]
+ qualifier:_q
+ sortOrderings:nil];
+ }
+ return [self fetchAclWithSpecification:fs];
+}
+
/* description */
- (NSString *)description {
GCSFolderType *folderType;
NSString *folderTypeName, *locationString, *folderName, *path;
NSNumber *folderId;
- NSURL *location, *quickLocation;
+ NSURL *location, *quickLocation, *aclLocation;
if (_record == nil) return nil;
[self logWithFormat:@"WARNING(%s): missing quick location in record: %@",
__PRETTY_FUNCTION__, _record];
}
+
+ locationString = [_record objectForKey:@"c_acl_location"];
+ aclLocation = [locationString isNotNull]
+ ? [NSURL URLWithString:locationString]
+ : nil;
folder = [[GCSFolder alloc] initWithPath:path primaryKey:folderId
folderTypeName:folderTypeName
folderType:folderType
location:location quickLocation:quickLocation
+ aclLocation:aclLocation
folderManager:self];
return [folder autorelease];
}
[sql appendString:@"SELECT "];
[sql appendString:@"c_folder_id, "];
[sql appendString:@"c_path, "];
- [sql appendString:@"c_location, c_quick_location, "];
- [sql appendString:@"c_folder_type"];
+ [sql appendString:@"c_location, c_quick_location, c_acl_location,"];
+ [sql appendString:@" c_folder_type"];
[sql appendString:@" FROM "];
[sql appendString:[self folderInfoTableName]];
[sql appendString:@" WHERE "];