From f67bb974bff000b920b5eca00d5d79519582d256 Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 28 Jun 2004 23:37:48 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@70 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/OCSFolder.m | 6 +++ OGoContentStore/OCSFolderManager.h | 4 +- OGoContentStore/OCSFolderManager.m | 72 +++++++++++++++++++++++++++++ OGoContentStore/ocs_ls.m | 3 ++ OGoContentStore/sql/folderinfo.psql | 22 +++++++++ 5 files changed, 106 insertions(+), 1 deletion(-) diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index 25ddec0c..da120631 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -26,6 +26,12 @@ @implementation OCSFolder - (void)dealloc { + [self->folderId release]; + [self->folderName release]; + [self->rootName release]; + [self->path release]; + [self->location release]; + [self->folderType release]; [super dealloc]; } diff --git a/OGoContentStore/OCSFolderManager.h b/OGoContentStore/OCSFolderManager.h index af9db959..2c83471b 100644 --- a/OGoContentStore/OCSFolderManager.h +++ b/OGoContentStore/OCSFolderManager.h @@ -33,7 +33,7 @@ */ @class NSString, NSArray, NSURL; -@class OCSChannelManager; +@class OCSChannelManager, OCSFolder; @interface OCSFolderManager : NSObject { @@ -63,6 +63,8 @@ - (BOOL)folderExistsAtPath:(NSString *)_path; - (NSArray *)listSubFoldersAtPath:(NSString *)_path recursive:(BOOL)_flag; +- (OCSFolder *)folderAtPath:(NSString *)_path; + /* cache management */ - (void)reset; diff --git a/OGoContentStore/OCSFolderManager.m b/OGoContentStore/OCSFolderManager.m index a0c9fb80..31d46067 100644 --- a/OGoContentStore/OCSFolderManager.m +++ b/OGoContentStore/OCSFolderManager.m @@ -321,6 +321,24 @@ static NSArray *emptyArray = nil; return _name; } +- (NSDictionary *)filterRecords:(NSArray *)_records forPath:(NSString *)_path { + unsigned i, count; + NSString *name; + + if (_records == nil) return nil; + if ((name = [self internalNameFromPath:_path]) == nil) return nil; + + for (i = 0, count = [_records count]; i < count; i++) { + NSString *recName; + + recName = [[_records objectAtIndex:i] objectForKey:@"path"]; + [self logWithFormat:@"check '%@' vs '%@' ...", name, recName]; + if ([name isEqualToString:recName]) + return [_records objectAtIndex:i]; + } + return nil; +} + - (BOOL)folderExistsAtPath:(NSString *)_path { NSString *fname; NSArray *fnames, *records; @@ -417,6 +435,60 @@ static NSArray *emptyArray = nil; return result; } +- (OCSFolder *)folderAtPath:(NSString *)_path { + NSMutableString *sql; + NSArray *fnames, *records; + NSString *ws; + NSDictionary *record; + + if ((fnames = [self internalNamesFromPath:_path]) == nil) { + [self debugWithFormat:@"got no internal names for path: '%@'", _path]; + return nil; + } + + /* generate SQL to fetch folder attributes */ + + ws = [self generateSQLWhereForInternalNames:fnames + exactMatch:YES orDirectSubfolderMatch:NO]; + + sql = [NSMutableString stringWithCapacity:256]; + [sql appendString:@"SELECT "]; + [sql appendString:@"\"folderid\", \"path\", \"location\", \"foldertype\""]; + [sql appendString:@" FROM "]; + [sql appendString:[self folderInfoTableName]]; + [sql appendString:@" WHERE "]; + [sql appendString:ws]; + + /* fetching */ + + if ((records = [self performSQL:sql]) == nil) { + [self logWithFormat:@"ERROR(%s): executing SQL failed: '%@'", + __PRETTY_FUNCTION__, sql]; + return nil; + } + + // TODO: need to filter on path + + if ([records count] != 1) { + if ([records count] == 0) { + [self debugWithFormat:@"found no records for path: '%@'", _path]; + return nil; + } + + [self logWithFormat:@"ERROR(%s): more than one row for path: '%@'", + __PRETTY_FUNCTION__, _path]; + return nil; + } + + if ((record = [self filterRecords:records forPath:_path]) == nil) { + [self debugWithFormat:@"found no record for path: '%@'", _path]; + return nil; + } + + [self logWithFormat:@"record: %@", record]; + return nil; +} + /* cache management */ - (void)reset { diff --git a/OGoContentStore/ocs_ls.m b/OGoContentStore/ocs_ls.m index bd5d7309..dba6ac37 100644 --- a/OGoContentStore/ocs_ls.m +++ b/OGoContentStore/ocs_ls.m @@ -55,6 +55,9 @@ for (i = 0, count = [subfolders count]; i < count; i++) { printf("%s\n", [[subfolders objectAtIndex:i] cString]); } + + NSLog(@"folder: %@", [self->folderManager folderAtPath:_path]); + return 0; } diff --git a/OGoContentStore/sql/folderinfo.psql b/OGoContentStore/sql/folderinfo.psql index 4aa12d85..9b358f0a 100644 --- a/OGoContentStore/sql/folderinfo.psql +++ b/OGoContentStore/sql/folderinfo.psql @@ -22,6 +22,28 @@ CREATE TABLE SOGo_folder_info ( folderType VARCHAR(255) NOT NULL -- the folder type ... ); +INSERT INTO SOGo_folder_info + ( path, path1, path2, path3, path4, foldername, location, foldertype ) +VALUES + ( '/Users', + 'Users', + NULL, + NULL, + NULL, + 'Calendar', + 'http://OGo:OGo@localhost/test', 'Container' ); + +INSERT INTO SOGo_folder_info + ( path, path1, path2, path3, path4, foldername, location, foldertype ) +VALUES + ( '/Users/helge', + 'Users', + 'helge', + NULL, + NULL, + 'Calendar', + 'http://OGo:OGo@localhost/test', 'Container' ); + INSERT INTO SOGo_folder_info ( path, path1, path2, path3, path4, foldername, location, foldertype ) VALUES -- 2.39.5