include $(GNUSTEP_MAKEFILES)/common.make
LIBRARY_NAME = libOGoContentStore
+TOOL_NAME = ocs_ls
libOGoContentStore_HEADER_FILES += \
NSURL+OCS.h \
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
--- /dev/null
+# $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
/* 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 {
*/
@class NSURL;
+@class OCSChannelManager;
@interface OCSFolderManager : NSObject
{
+ OCSChannelManager *channelManager;
NSURL *folderInfoLocation;
}
- (NSURL *)folderInfoLocation;
+/* checking connection */
+
+- (BOOL)canConnect;
+
@end
#endif /* __OGoContentStore_OCSFolderManager_H__ */
// $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;
return nil;
}
if ((self = [super init])) {
+ self->channelManager = [[OCSChannelManager defaultChannelManager] retain];
self->folderInfoLocation = [_url retain];
}
return self;
- (void)dealloc {
[self->folderInfoLocation release];
+ [self->channelManager release];
[super dealloc];
}
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 */
========
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
============
--- /dev/null
+// $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;
+}
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' );