]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@66 d1b88da0-ebda-0310-925b-ed51d8...
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 28 Jun 2004 11:18:04 +0000 (11:18 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 28 Jun 2004 11:18:04 +0000 (11:18 +0000)
OGoContentStore/GNUmakefile
OGoContentStore/GNUmakefile.preamble [new file with mode: 0644]
OGoContentStore/OCSChannelManager.m
OGoContentStore/OCSFolderManager.h
OGoContentStore/OCSFolderManager.m
OGoContentStore/README
OGoContentStore/ocs_ls.m [new file with mode: 0644]
OGoContentStore/sql/folderinfo.psql

index 348e1aecc0062584ec5285e4b9d61ecf1f164e5d..c1fef708d3ee5601a92588fe66767bd458294625 100644 (file)
@@ -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 (file)
index 0000000..d4882dd
--- /dev/null
@@ -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
index 6bf6f064277dd8e38cc2822564cb7778eed2ce84..286d2bd2d53aa8945e30aaf9fb9c8439c8def0a3 100644 (file)
@@ -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 {
index 90efca46dacf67f516841acbbaa0a690c711f2eb..23a826bda45e0c8531c3255618015b05da483290 100644 (file)
 */
 
 @class NSURL;
+@class OCSChannelManager;
 
 @interface OCSFolderManager : NSObject
 {
+  OCSChannelManager *channelManager;
   NSURL *folderInfoLocation;
 }
 
 
 - (NSURL *)folderInfoLocation;
 
+/* checking connection */
+
+- (BOOL)canConnect;
+
 @end
 
 #endif /* __OGoContentStore_OCSFolderManager_H__ */
index 8aeb19fabcc42cbb62eacf1bd3ebb9155675e57d..15ba7ba9742eb48d29f2b58678b3677d64ce241f 100644 (file)
 // $Id$
 
 #include "OCSFolderManager.h"
+#include "OCSChannelManager.h"
+#include "NSURL+OCS.h"
 #include "common.h"
+#include <GDLAccess/EOAdaptorChannel.h>
 
 @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 */
index c5c468c231d7397540adf7d0433707df9b5d5db2..f04e2f61fecdab4d08687b15a6ded090a45559cb 100644 (file)
@@ -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 (file)
index 0000000..8c52ccb
--- /dev/null
@@ -0,0 +1,59 @@
+// $Id$
+
+#include <OGoContentStore/OCSFolderManager.h>
+#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;
+}
index 8a6ece25173cdf920f25ef206510cdfc5c8e9e12..508d5e1017f50925c53871c1c97b5a4de68b096a 100644 (file)
@@ -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' );