From 9db47a54a87292d7e94dfc8aec902a1b4bd3d1ed Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 13 Jul 2005 13:53:52 +0000 Subject: [PATCH] improved behaviour with vCard content git-svn-id: http://svn.opengroupware.org/SOGo/trunk@737 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Contacts/ChangeLog | 2 + SOGo/SoObjects/Contacts/SOGoContactFolder.m | 10 +++-- SOGo/SoObjects/Contacts/SOGoContactObject.h | 7 +++- SOGo/SoObjects/Contacts/SOGoContactObject.m | 45 +++++++++++++++++++-- SOGo/SoObjects/Contacts/Version | 2 +- 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/SOGo/SoObjects/Contacts/ChangeLog b/SOGo/SoObjects/Contacts/ChangeLog index 8e33884a..19211722 100644 --- a/SOGo/SoObjects/Contacts/ChangeLog +++ b/SOGo/SoObjects/Contacts/ChangeLog @@ -1,5 +1,7 @@ 2005-07-13 Helge Hess + * SOGoContactObject.m: hardened against vCard content (v0.9.11) + * SOGoContactObject.m: removed special GET action, the redirect to 'view' seems to be handled by SOPE now. This also makes WebDAV GET work (v0.9.10) diff --git a/SOGo/SoObjects/Contacts/SOGoContactFolder.m b/SOGo/SoObjects/Contacts/SOGoContactFolder.m index 6a182911..608fcc86 100644 --- a/SOGo/SoObjects/Contacts/SOGoContactFolder.m +++ b/SOGo/SoObjects/Contacts/SOGoContactFolder.m @@ -86,8 +86,12 @@ if ((obj = [super lookupName:_key inContext:_ctx acquire:NO])) return obj; - if ([self isValidContactName:_key]) - return [self contactWithName:_key inContext:_ctx]; + if ([self isValidContactName:_key]) { +#if 0 + if ([[self ocsFolder] versionOfContentWithName:_key]) +#endif + return [self contactWithName:_key inContext:_ctx]; + } /* return 404 to stop acquisition */ return [NSException exceptionWithHTTPStatus:404 /* Not Found */]; @@ -113,7 +117,7 @@ return nil; } records = [self fixupRecords:records]; - [self debugWithFormat:@"fetched %i records.", [records count]]; + //[self debugWithFormat:@"fetched %i records.", [records count]]; return records; } diff --git a/SOGo/SoObjects/Contacts/SOGoContactObject.h b/SOGo/SoObjects/Contacts/SOGoContactObject.h index 1b45c7be..b2d71c95 100644 --- a/SOGo/SoObjects/Contacts/SOGoContactObject.h +++ b/SOGo/SoObjects/Contacts/SOGoContactObject.h @@ -36,15 +36,18 @@ */ @class NSDictionary; +@class NGVCard; @interface SOGoContactObject : SOGoContentObject { - NSDictionary *record; + id record; /* either an NSMutableDictionary or a NGVCard */ } /* accessors */ -- (NSDictionary *)record; +- (id)record; +- (BOOL)isVCardRecord; +- (NGVCard *)vCard; @end diff --git a/SOGo/SoObjects/Contacts/SOGoContactObject.m b/SOGo/SoObjects/Contacts/SOGoContactObject.m index 68d015d0..64ae6bd7 100644 --- a/SOGo/SoObjects/Contacts/SOGoContactObject.m +++ b/SOGo/SoObjects/Contacts/SOGoContactObject.m @@ -20,6 +20,7 @@ */ #include "SOGoContactObject.h" +#include #include "common.h" @implementation SOGoContactObject @@ -31,10 +32,35 @@ /* content */ -- (NSDictionary *)record { - if (self->record == nil) - self->record = [[[self contentAsString] propertyList] copy]; - return self->record; +- (id)record { + if (self->record == nil) { + NSString *s; + + s = [self contentAsString]; + + if ([s hasPrefix:@"BEGIN:VCARD"]) { + NSArray *v; + + v = [NGVCard parseVCardsFromSource:s]; + if ([v count] == 0) + return nil; + + self->record = [[v objectAtIndex:0] retain]; + } + else + self->record = [[s propertyList] copy]; + } + return [self->record isNotNull] ? self->record : nil; +} + +- (BOOL)isVCardRecord { + return [[self record] isKindOfClass:[NGVCard class]]; +} + +- (NGVCard *)vCard { + return [[self record] isKindOfClass:[NGVCard class]] + ? [self record] + : nil; } /* key value coding */ @@ -62,6 +88,12 @@ /* specialized actions */ - (NSException *)saveRecord:(id)_record { + if ([_record isKindOfClass:[NGVCard class]]) { + // TODO: implement a vCard generator + return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */ + reason:@"Saving vCards is not supported yet."]; + } + return [self saveContentString:[_record description]]; } @@ -69,6 +101,11 @@ inContext:(id)_ctx { NSMutableDictionary *md; + + if ([self isVCardRecord]) { + return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */ + reason:@"Changing vCards is not supported yet."]; + } if ([_fname length] == 0) { return [NSException exceptionWithHTTPStatus:400 /* Bad Request */ diff --git a/SOGo/SoObjects/Contacts/Version b/SOGo/SoObjects/Contacts/Version index d383fb7e..f941fe0f 100644 --- a/SOGo/SoObjects/Contacts/Version +++ b/SOGo/SoObjects/Contacts/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=10 +SUBMINOR_VERSION:=11 # v0.9.9 requires libGDLContentStore v4.5.26 # v0.9.5 requires libNGExtensions v4.5.136 -- 2.39.5