From 80f4473593800de22528e2ecc0ccd29de9756f9a Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 28 Jun 2004 11:18:04 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@66 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/GNUmakefile | 5 ++ OGoContentStore/GNUmakefile.preamble | 17 +++++++ OGoContentStore/OCSChannelManager.m | 22 +++++++- OGoContentStore/OCSFolderManager.h | 6 +++ OGoContentStore/OCSFolderManager.m | 75 ++++++++++++++++++++++++++++ OGoContentStore/README | 13 +++++ OGoContentStore/ocs_ls.m | 59 ++++++++++++++++++++++ OGoContentStore/sql/folderinfo.psql | 4 +- 8 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 OGoContentStore/GNUmakefile.preamble create mode 100644 OGoContentStore/ocs_ls.m diff --git a/OGoContentStore/GNUmakefile b/OGoContentStore/GNUmakefile index 348e1aec..c1fef708 100644 --- a/OGoContentStore/GNUmakefile +++ b/OGoContentStore/GNUmakefile @@ -3,6 +3,7 @@ include $(GNUSTEP_MAKEFILES)/common.make LIBRARY_NAME = libOGoContentStore +TOOL_NAME = ocs_ls libOGoContentStore_HEADER_FILES += \ NSURL+OCS.h \ @@ -24,6 +25,10 @@ libOGoContentStore_OBJC_FILES += \ OCSFolderType.m \ OCSChannelManager.m \ +ocs_ls_OBJC_FILES += \ + ocs_ls.m + -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/library.make +include $(GNUSTEP_MAKEFILES)/tool.make -include GNUmakefile.postamble diff --git a/OGoContentStore/GNUmakefile.preamble b/OGoContentStore/GNUmakefile.preamble new file mode 100644 index 00000000..d4882dd7 --- /dev/null +++ b/OGoContentStore/GNUmakefile.preamble @@ -0,0 +1,17 @@ +# $Id$ + +libOGoContentStore_LIBRARIES_DEPEND_UPON += \ + -lGDLAccess \ + -lEOControl + +ocs_ls_TOOL_LIBS += \ + -lOGoContentStore \ + -lGDLAccess \ + -lNGExtensions -lEOControl + +ADDITIONAL_INCLUDE_DIRS += -I. -I.. + +ifeq ($(FOUNDATION_LIB),apple) +libOGoContentStore_PREBIND_ADDR="0xC7700000" +libOGoContentStore_LDFLAGS += -seg1addr $(libOGoContentStore_PREBIND_ADDR) +endif diff --git a/OGoContentStore/OCSChannelManager.m b/OGoContentStore/OCSChannelManager.m index 6bf6f064..286d2bd2 100644 --- a/OGoContentStore/OCSChannelManager.m +++ b/OGoContentStore/OCSChannelManager.m @@ -73,8 +73,26 @@ static BOOL debugOn = YES; /* adaptors */ - (NSDictionary *)connectionDictionaryForURL:(NSURL *)_url { - [self debugWithFormat:@"build connection dictionary for URL: %@", _url]; - return nil; + NSMutableDictionary *md; + id tmp; + + md = [NSMutableDictionary dictionaryWithCapacity:4]; + + if ((tmp = [_url host]) != nil) + [md setObject:tmp forKey:@"hostName"]; + if ((tmp = [_url port]) != nil) + [md setObject:tmp forKey:@"port"]; + if ((tmp = [_url user]) != nil) + [md setObject:tmp forKey:@"userName"]; + if ((tmp = [_url password]) != nil) + [md setObject:tmp forKey:@"password"]; + + if ((tmp = [_url ocsDatabaseName]) != nil) + [md setObject:tmp forKey:@"databaseName"]; + + [self debugWithFormat:@"build connection dictionary for URL %@: %@", + [_url absoluteString], md]; + return md; } - (EOAdaptor *)adaptorForURL:(NSURL *)_url { diff --git a/OGoContentStore/OCSFolderManager.h b/OGoContentStore/OCSFolderManager.h index 90efca46..23a826bd 100644 --- a/OGoContentStore/OCSFolderManager.h +++ b/OGoContentStore/OCSFolderManager.h @@ -33,9 +33,11 @@ */ @class NSURL; +@class OCSChannelManager; @interface OCSFolderManager : NSObject { + OCSChannelManager *channelManager; NSURL *folderInfoLocation; } @@ -46,6 +48,10 @@ - (NSURL *)folderInfoLocation; +/* checking connection */ + +- (BOOL)canConnect; + @end #endif /* __OGoContentStore_OCSFolderManager_H__ */ diff --git a/OGoContentStore/OCSFolderManager.m b/OGoContentStore/OCSFolderManager.m index 8aeb19fa..15ba7ba9 100644 --- a/OGoContentStore/OCSFolderManager.m +++ b/OGoContentStore/OCSFolderManager.m @@ -21,11 +21,21 @@ // $Id$ #include "OCSFolderManager.h" +#include "OCSChannelManager.h" +#include "NSURL+OCS.h" #include "common.h" +#include @implementation OCSFolderManager static OCSFolderManager *fm = nil; +static BOOL debugOn = YES; + ++ (void)initialize { + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + + debugOn = [ud boolForKey:@"OCSFolderManagerDebugEnabled"]; +} + (id)defaultFolderManager { NSString *s; @@ -61,6 +71,7 @@ static OCSFolderManager *fm = nil; return nil; } if ((self = [super init])) { + self->channelManager = [[OCSChannelManager defaultChannelManager] retain]; self->folderInfoLocation = [_url retain]; } return self; @@ -68,6 +79,7 @@ static OCSFolderManager *fm = nil; - (void)dealloc { [self->folderInfoLocation release]; + [self->channelManager release]; [super dealloc]; } @@ -77,4 +89,67 @@ static OCSFolderManager *fm = nil; return self->folderInfoLocation; } +/* checking connection */ + +- (EOAdaptorChannel *)acquireOpenChannel { + EOAdaptorChannel *ch; + + ch = [self->channelManager acquireOpenChannelForURL: + [self folderInfoLocation]]; + return ch; +} +- (void)releaseChannel:(EOAdaptorChannel *)_channel { + [self->channelManager releaseChannel:_channel]; + if (debugOn) [self debugWithFormat:@"released channel: %@", _channel]; +} + +- (BOOL)canConnect { + EOAdaptorChannel *channel; + NSString *sql; + NSException *ex; + + /* check whether we can open a connection */ + + if ((channel = [self acquireOpenChannel]) == nil) { + if (debugOn) [self debugWithFormat:@"could not acquire channel!"]; + return NO; + } + if (debugOn) [self debugWithFormat:@"acquired channel: %@", channel]; + + /* check whether table exists */ + + sql = [@"SELECT COUNT(*) FROM " stringByAppendingString: + [[self folderInfoLocation] ocsTableName]]; + sql = [sql stringByAppendingString:@" WHERE 1=2"]; + + ex = [[[channel evaluateExpressionX:sql] retain] autorelease]; + [channel cancelFetch]; + [self releaseChannel:channel]; + + if (debugOn && ex != nil) [self debugWithFormat:@" folder-eval: %@", ex]; + + return ex != nil ? NO : YES; +} + +/* debugging */ + +- (BOOL)isDebuggingEnabled { + return debugOn; +} + +/* description */ + +- (NSString *)description { + NSMutableString *ms; + + ms = [NSMutableString stringWithCapacity:256]; + [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; + + [ms appendFormat:@" url=%@", [self->folderInfoLocation absoluteString]]; + [ms appendFormat:@" channel-manager=0x%08X", self->channelManager]; + + [ms appendString:@">"]; + return ms; +} + @end /* OCSFolderManager */ diff --git a/OGoContentStore/README b/OGoContentStore/README index c5c468c2..f04e2f61 100644 --- a/OGoContentStore/README +++ b/OGoContentStore/README @@ -42,6 +42,19 @@ Defaults ======== OCSFolderInfoURL - the DB URL where the folder-info table is located + eg: http://OGo:OGo@localhost/test/folder_info + + OCSFolderManagerDebugEnabled - enable folder-manager debug logs + + [PGDebugEnabled] - enable PostgreSQL adaptor debugging + +URLs +==== + + "Database URLs" + + We use the schema: + postgresql://[user]:[password]@[host]:[port]/[dbname]/[tablename] BLOB Formats ============ diff --git a/OGoContentStore/ocs_ls.m b/OGoContentStore/ocs_ls.m new file mode 100644 index 00000000..8c52ccb1 --- /dev/null +++ b/OGoContentStore/ocs_ls.m @@ -0,0 +1,59 @@ +// $Id$ + +#include +#include "common.h" + +@interface Tool : NSObject +{ + OCSFolderManager *folderManager; +} + ++ (int)run; + +@end + +@implementation Tool + +- (id)init { + if ((self = [super init])) { + self->folderManager = [[OCSFolderManager defaultFolderManager] retain]; + } + return self; +} +- (void)dealloc { + [self->folderManager release]; + [super dealloc]; +} + +/* operation */ + +- (int)run { + [self logWithFormat:@"manager: %@", self->folderManager]; + + if (![self->folderManager canConnect]) { + [self logWithFormat:@"cannot connect folder-info database!"]; + return 1; + } + + return 0; +} ++ (int)run { + return [(Tool *)[[[self alloc] init] autorelease] run]; +} + +@end /* Tool */ + +int main(int argc, char **argv, char **env) { + NSAutoreleasePool *pool; + int rc; + + pool = [[NSAutoreleasePool alloc] init]; +#if LIB_FOUNDATION_LIBRARY + [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; +#endif + + rc = [Tool run]; + + [pool release]; + return rc; +} diff --git a/OGoContentStore/sql/folderinfo.psql b/OGoContentStore/sql/folderinfo.psql index 8a6ece25..508d5e10 100644 --- a/OGoContentStore/sql/folderinfo.psql +++ b/OGoContentStore/sql/folderinfo.psql @@ -20,5 +20,5 @@ CREATE TABLE SOGo_folder_info ( INSERT INTO SOGo_folder_info ( path, rootname, foldername, location, foldertype ) VALUES - ( 'helge/Calendar', 'helge', 'Calendar', - 'http://OGo:OGo@localhost/OGo', 'Appointment' ); + ( '/Users/helge/Calendar', 'helge', 'Calendar', + 'http://OGo:OGo@localhost/test', 'Appointment' ); -- 2.39.5