From 07ad051421bce8e72e39366d1e67e6f732bb7991 Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 29 Jun 2004 21:37:27 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@83 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/GNUmakefile | 3 +- OGoContentStore/GNUmakefile.preamble | 1 + OGoContentStore/OCSFolder.h | 2 + OGoContentStore/OCSFolder.m | 46 ++++++++++++ OGoContentStore/OCSFolderManager.m | 6 +- OGoContentStore/misc/icaltest.ical | 30 ++++++++ OGoContentStore/ocs_cat.m | 101 +++++++++++++++++++++++++++ OGoContentStore/sql/testapt-hh.psql | 63 +++++++++++++++++ 8 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 OGoContentStore/misc/icaltest.ical create mode 100644 OGoContentStore/ocs_cat.m create mode 100644 OGoContentStore/sql/testapt-hh.psql diff --git a/OGoContentStore/GNUmakefile b/OGoContentStore/GNUmakefile index dc7ed786..90983adb 100644 --- a/OGoContentStore/GNUmakefile +++ b/OGoContentStore/GNUmakefile @@ -4,7 +4,7 @@ include $(GNUSTEP_MAKEFILES)/common.make include ./Version LIBRARY_NAME = libOGoContentStore -TOOL_NAME = ocs_ls ocs_mkdir +TOOL_NAME = ocs_ls ocs_mkdir ocs_cat libOGoContentStore_HEADER_FILES += \ NSURL+OCS.h \ @@ -30,6 +30,7 @@ libOGoContentStore_OBJC_FILES += \ ocs_ls_OBJC_FILES += ocs_ls.m ocs_mkdir_OBJC_FILES += ocs_mkdir.m +ocs_cat_OBJC_FILES += ocs_cat.m -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/library.make diff --git a/OGoContentStore/GNUmakefile.preamble b/OGoContentStore/GNUmakefile.preamble index 176803b0..39f119fa 100644 --- a/OGoContentStore/GNUmakefile.preamble +++ b/OGoContentStore/GNUmakefile.preamble @@ -11,6 +11,7 @@ OCS_TOOL_LIBS += \ ocs_ls_TOOL_LIBS += $(OCS_TOOL_LIBS) ocs_mkdir_TOOL_LIBS += $(OCS_TOOL_LIBS) +ocs_cat_TOOL_LIBS += $(OCS_TOOL_LIBS) ADDITIONAL_INCLUDE_DIRS += -I. -I.. diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index db7c90a2..abf36143 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -76,6 +76,8 @@ - (NSArray *)subFolderNames; - (NSArray *)allSubFolderNames; +- (NSString *)fetchContentWithName:(NSString *)_name; + @end #endif /* __OGoContentStore_OCSFolder_H__ */ diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index 2bde8671..18795282 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -145,6 +145,52 @@ static BOOL debugOn = YES; recursive:YES]; } +- (NSString *)fetchContentWithName:(NSString *)_name { + EOAdaptorChannel *channel; + NSException *error; + NSDictionary *row; + NSArray *attrs; + NSString *result; + NSString *sql; + + if ((channel = [self acquireStoreChannel]) == nil) { + [self logWithFormat:@"ERROR(%s): could not open storage channel!"]; + return nil; + } + + /* generate SQL */ + + sql = @"SELECT \"c_content\" FROM "; + sql = [sql stringByAppendingString:[self storeTableName]]; + sql = [sql stringByAppendingString:@" WHERE \"c_name\" = '"]; + sql = [sql stringByAppendingString:_name]; + sql = [sql stringByAppendingString:@"'"]; + + /* run SQL */ + + if ((error = [channel evaluateExpressionX:sql]) != nil) { + [self logWithFormat:@"ERROR(%s): cannot execute blob-fetch SQL '%@': %@", + __PRETTY_FUNCTION__, sql, error]; + [self releaseChannel:channel]; + return nil; + } + + /* fetch results */ + + result = nil; + attrs = [channel describeResults]; + if ((row = [channel fetchAttributes:attrs withZone:NULL]) != nil) { + result = [[[row objectForKey:@"cContent"] copy] autorelease]; + if (![result isNotNull]) result = nil; + [channel cancelFetch]; + } + + /* release and return result */ + + [self releaseChannel:channel]; + return result; +} + /* description */ - (NSString *)description { diff --git a/OGoContentStore/OCSFolderManager.m b/OGoContentStore/OCSFolderManager.m index 27604255..cb1cb3ac 100644 --- a/OGoContentStore/OCSFolderManager.m +++ b/OGoContentStore/OCSFolderManager.m @@ -167,7 +167,9 @@ static const char *OCSPathColumnPattern = "c_path%i"; /* run SQL */ - if ((ex = [channel evaluateExpressionX:_sql])) { + if ((ex = [channel evaluateExpressionX:_sql]) != nil) { + [self logWithFormat:@"ERROR(%s): cannot execute SQL '%@': %@", + __PRETTY_FUNCTION__, _sql, ex]; [self releaseChannel:channel]; return nil; } @@ -176,7 +178,7 @@ static const char *OCSPathColumnPattern = "c_path%i"; attrs = [channel describeResults]; rows = [NSMutableArray arrayWithCapacity:16]; - while ((row = [channel fetchAttributes:attrs withZone:NULL])) + while ((row = [channel fetchAttributes:attrs withZone:NULL]) != nil) [rows addObject:row]; [self releaseChannel:channel]; diff --git a/OGoContentStore/misc/icaltest.ical b/OGoContentStore/misc/icaltest.ical new file mode 100644 index 00000000..d048821f --- /dev/null +++ b/OGoContentStore/misc/icaltest.ical @@ -0,0 +1,30 @@ +BEGIN:VEVENT +DURATION:PT1H +ATTENDEE;CN="Elke Bethke";DIR="addressbook://B156F3F0-9CFD-11D8-8561-000 + D93C1A604:ABPerson":mailto:E.Bethke@Sachsen-Anhalt-Lotto.de +ATTENDEE;CN="Erik Doernenburg";DIR="addressbook://B15FCB0F-9CFD-11D8-8561 + -000D93C1A604:ABPerson":mailto:erik@x101.net +ATTENDEE;CN="Christian Schnelle";DIR="addressbook://B1418D4E-9CFD-11D8-8 + 561-000D93C1A604:ABPerson":mailto:cs@enervation.de +ATTENDEE;CN="Chris Herrenberger";DIR="addressbook://B14A390C-9CFD-11D8-8 + 561-000D93C1A604:ABPerson":invalid:nomail +ATTENDEE;CN="Horst Parplies";DIR="addressbook://B19B47E5-9CFD-11D8-8561- + 000D93C1A604:ABPerson":mailto:horst.parplies@freenet.de +ATTENDEE;CN="Imdat Solak";DIR="addressbook://B19EDB62-9CFD-11D8-8561-000 + D93C1A604:ABPerson":mailto:imdat@solak.de +ATTENDEE;CN="Jens Enders";DIR="addressbook://B1B6819F-9CFD-11D8-8561-000 + D93C1A604:ABPerson":mailto:jens.enders@skyrix.com +ATTENDEE;CN="Jens Muenster";DIR="addressbook://B1BBA42E-9CFD-11D8-8561-00 + 0D93C1A604:ABPerson":mailto:jens.muenster@skyrix.com +ATTENDEE;CN="Laurent Pierre";DIR="addressbook://9337C270-A825-11D8-B930- + 000D93C1A604:ABPerson":mailto:laurent.pierre@linagora.com +ATTENDEE;CN="Marcel Weiher";DIR="addressbook://B1F9BB12-9CFD-11D8-8561-0 + 00D93C1A604:ABPerson":mailto:marcel@metaobject.co +DTSTAMP:20040520T140002Z +UID:BD91C454-AA65-11D8-84CA-000D93C1A604 +SEQUENCE:3 +STATUS:CONFIRMED +DTSTART;TZID=Europe/Berlin:20040618T160000 +SUMMARY:SIZE EVENT +X-WR-ITIPSTATUSML:UNCLEAN +END:VEVENT diff --git a/OGoContentStore/ocs_cat.m b/OGoContentStore/ocs_cat.m new file mode 100644 index 00000000..bdc11425 --- /dev/null +++ b/OGoContentStore/ocs_cat.m @@ -0,0 +1,101 @@ +// $Id$ + +#import + +@class NSUserDefaults; +@class OCSFolderManager; + +@interface Tool : NSObject +{ + NSUserDefaults *ud; + OCSFolderManager *folderManager; +} + ++ (int)run; + +@end + +#include +#include +#include "common.h" + +@implementation Tool + +- (id)init { + if ((self = [super init])) { + self->ud = [[NSUserDefaults standardUserDefaults] retain]; + self->folderManager = [[OCSFolderManager defaultFolderManager] retain]; + } + return self; +} +- (void)dealloc { + [self->ud release]; + [self->folderManager release]; + [super dealloc]; +} + +/* operation */ + +- (int)runOnPath:(NSString *)_path { + OCSFolder *folder; + NSString *dirname, *filename; + NSString *content; + + dirname = [_path stringByDeletingLastPathComponent]; + filename = [_path lastPathComponent]; + + if ((folder = [self->folderManager folderAtPath:dirname]) == nil) { + [self logWithFormat:@"did not find folder for file: '%@'", dirname]; + return 1; + } + + if ((content = [folder fetchContentWithName:filename]) == nil) { + [self logWithFormat:@"did not find file: '%@'", _path]; + return 1; + } + + printf("%s\n", [content cString]); + + return 0; +} + +- (int)run { + NSEnumerator *e; + NSString *path; + + [self logWithFormat:@"manager: %@", self->folderManager]; + + if (![self->folderManager canConnect]) { + [self logWithFormat:@"cannot connect folder-info database!"]; + return 1; + } + + e = [[[NSProcessInfo processInfo] argumentsWithoutDefaults] + objectEnumerator]; + [e nextObject]; // skip tool name + + while ((path = [e nextObject])) + [self runOnPath:path]; + + 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/testapt-hh.psql b/OGoContentStore/sql/testapt-hh.psql new file mode 100644 index 00000000..1ced1136 --- /dev/null +++ b/OGoContentStore/sql/testapt-hh.psql @@ -0,0 +1,63 @@ +-- $Id$ +-- +-- (C) 2004 SKYRIX Software AG +-- + +DELETE FROM SOGo_helge_privcal + WHERE c_name = 'BD91C454-AA65-11D8-84CA-000D93C1A604'; +DELETE FROM SOGo_helge_privcal_quick + WHERE c_name = 'BD91C454-AA65-11D8-84CA-000D93C1A604'; + + + +INSERT INTO SOGo_helge_privcal + ( c_name, c_creationdate, c_lastmodified, c_version, c_content ) +VALUES ( + 'BD91C454-AA65-11D8-84CA-000D93C1A604', + 928383, + 928383, + 1, + + 'BEGIN:VEVENT +DURATION:PT1H +ATTENDEE;CN="Elke Bethke";DIR="addressbook://B156F3F0-9CFD-11D8-8561-000 + D93C1A604:ABPerson":mailto:E.Bethke@Sachsen-Anhalt-Lotto.de +ATTENDEE;CN="Erik Doernenburg";DIR="addressbook://B15FCB0F-9CFD-11D8-8561 + -000D93C1A604:ABPerson":mailto:erik@x101.net +ATTENDEE;CN="Christian Schnelle";DIR="addressbook://B1418D4E-9CFD-11D8-8 + 561-000D93C1A604:ABPerson":mailto:cs@enervation.de +ATTENDEE;CN="Chris Herrenberger";DIR="addressbook://B14A390C-9CFD-11D8-8 + 561-000D93C1A604:ABPerson":invalid:nomail +ATTENDEE;CN="Horst Parplies";DIR="addressbook://B19B47E5-9CFD-11D8-8561- + 000D93C1A604:ABPerson":mailto:horst.parplies@freenet.de +ATTENDEE;CN="Imdat Solak";DIR="addressbook://B19EDB62-9CFD-11D8-8561-000 + D93C1A604:ABPerson":mailto:imdat@solak.de +ATTENDEE;CN="Jens Enders";DIR="addressbook://B1B6819F-9CFD-11D8-8561-000 + D93C1A604:ABPerson":mailto:jens.enders@skyrix.com +ATTENDEE;CN="Jens Muenster";DIR="addressbook://B1BBA42E-9CFD-11D8-8561-00 + 0D93C1A604:ABPerson":mailto:jens.muenster@skyrix.com +ATTENDEE;CN="Laurent Pierre";DIR="addressbook://9337C270-A825-11D8-B930- + 000D93C1A604:ABPerson":mailto:laurent.pierre@linagora.com +ATTENDEE;CN="Marcel Weiher";DIR="addressbook://B1F9BB12-9CFD-11D8-8561-0 + 00D93C1A604:ABPerson":mailto:marcel@metaobject.co +DTSTAMP:20040520T140002Z +UID:BD91C454-AA65-11D8-84CA-000D93C1A604 +SEQUENCE:3 +STATUS:CONFIRMED +DTSTART;TZID=Europe/Berlin:20040618T160000 +SUMMARY:SIZE EVENT +X-WR-ITIPSTATUSML:UNCLEAN +END:VEVENT +' +); + +INSERT INTO SOGo_helge_privcal_quick + ( c_name, uid, startdate, enddate, title, participants ) +VALUES ( + 'BD91C454-AA65-11D8-84CA-000D93C1A604', + 'BD91C454-AA65-11D8-84CA-000D93C1A604', + 8928837, + 8929000, + 'SIZE EVENT', + 'Elke Bethke, Erik Doernenburg, Christian Schnelle, Chris Herrenberger, Horst Parplies, Imdat Solak, Jens Enders, Jens Muenster, Laurent Pierre, Marcel Weiher' +); -- 2.39.5