2005-07-13 Helge Hess <helge.hess@opengroupware.org>
+ * 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)
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 */];
return nil;
}
records = [self fixupRecords:records];
- [self debugWithFormat:@"fetched %i records.", [records count]];
+ //[self debugWithFormat:@"fetched %i records.", [records count]];
return records;
}
*/
#include "SOGoContactObject.h"
+#include <NGiCal/NGVCard.h>
#include "common.h"
@implementation SOGoContactObject
/* 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 */
/* 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]];
}
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 */