*/
@class NSString, NSArray, NSURL;
-@class OCSChannelManager;
+@class OCSChannelManager, OCSFolder;
@interface OCSFolderManager : NSObject
{
- (BOOL)folderExistsAtPath:(NSString *)_path;
- (NSArray *)listSubFoldersAtPath:(NSString *)_path recursive:(BOOL)_flag;
+- (OCSFolder *)folderAtPath:(NSString *)_path;
+
/* cache management */
- (void)reset;
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;
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 {
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