From 791aa03c09bba353ce87faefef4fa81e3bcb84dc Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 2 Jul 2004 17:42:35 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@138 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGoLogic/SOGoAppointment.m | 128 ++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 55 deletions(-) diff --git a/SOGoLogic/SOGoAppointment.m b/SOGoLogic/SOGoAppointment.m index 3dec7fcf..da48bd4b 100644 --- a/SOGoLogic/SOGoAppointment.m +++ b/SOGoLogic/SOGoAppointment.m @@ -54,6 +54,11 @@ static SaxObjectDecoder *sax = nil; } - (id)initWithICalString:(NSString *)_iCal { + if ([_iCal length] == 0) { + [self logWithFormat:@"ERROR: tried to init SOGoAppointment without iCal"]; + [self release]; + return nil; + } if ((self = [self init])) { id root; @@ -64,9 +69,13 @@ static SaxObjectDecoder *sax = nil; /* parse */ - [parser parseFromSource:_iCal]; - root = [[sax rootObject] retain]; - [sax reset]; + if ([_iCal length] > 0) { + [parser parseFromSource:_iCal]; + root = [[sax rootObject] retain]; + [sax reset]; + } + else + root = nil; /* fill */ @@ -75,6 +84,14 @@ static SaxObjectDecoder *sax = nil; if ([root isKindOfClass:[iCalEvent class]]) { self->event = root; } + else if ([root isKindOfClass:[NSDictionary class]]) { + /* multiple vevents in the calendar */ + [self logWithFormat: + @"ERROR(%s): tried to initialize with multiple records: %@", + __PRETTY_FUNCTION__, root]; + [self release]; + return nil; + } else { self->calendar = root; self->event = [[[self->calendar events] lastObject] retain]; @@ -101,52 +118,53 @@ static SaxObjectDecoder *sax = nil; /* TODO: REMOVE THIS HACK ASAP */ - (NSString *)iCalString { - NSMutableString *s; - NSArray *persons; - unsigned i, count; - iCalPerson *p; - - /* assume length of 1K - reasonable ? */ - s = [[NSMutableString alloc] initWithCapacity:1024]; - [s appendString:@"BEGIN:VCALENDAR\nMETHOD:REQUEST\nPRODID:"]; - if (self->calendar == nil) - [s appendString:@"SOGo/0.9"]; - else - [s appendString:[self->calendar prodId]]; - [s appendString:@"\nVERSION:"]; - if (self->calendar == nil) - [s appendString:@"2.0"]; - else - [s appendString:[(iCalCalendar *)self->calendar version]]; - [s appendString:@"\nBEGIN:VEVENT"]; - [s appendString:@"\nSUMMARY:"]; - [s appendString:[self summary]]; - if([self hasLocation]) { + NSMutableString *s; + NSArray *persons; + unsigned i, count; + iCalPerson *p; + + /* assume length of 1K - reasonable ? */ + s = [NSMutableString stringWithCapacity:1024]; + + [s appendString:@"BEGIN:VCALENDAR\nMETHOD:REQUEST\nPRODID:"]; + if (self->calendar == nil) + [s appendString:@"SOGo/0.9"]; + else + [s appendString:[self->calendar prodId]]; + [s appendString:@"\nVERSION:"]; + if (self->calendar == nil) + [s appendString:@"2.0"]; + else + [s appendString:[(iCalCalendar *)self->calendar version]]; + [s appendString:@"\nBEGIN:VEVENT"]; + [s appendString:@"\nSUMMARY:"]; + [s appendString:[self summary]]; + if([self hasLocation]) { [s appendString:@"\nLOCATION:"]; [s appendString:[self location]]; - } - [s appendString:@"\nUID:"]; - [s appendString:[self uid]]; - [s appendString:@"\nDTSTART:"]; - [s appendString:[[self startDate] icalString]]; - if([self hasEndDate]) { + } + [s appendString:@"\nUID:"]; + [s appendString:[self uid]]; + [s appendString:@"\nDTSTART:"]; + [s appendString:[[self startDate] icalString]]; + if([self hasEndDate]) { [s appendString:@"\nDTEND:"]; [s appendString:[[self endDate] icalString]]; - } - if([self hasDuration]) { + } + if([self hasDuration]) { [s appendString:@"\nDURATION:"]; [s appendString:[(iCalEvent *)self->event duration]]; - } - [s appendString:@"\nSTATUS:"]; - [s appendString:[self status]]; + } + [s appendString:@"\nSTATUS:"]; + [s appendString:[self status]]; - /* what's all this? */ - [s appendString:@"\nTRANSP:OPAQUE"]; - [s appendString:@"\nCLASS:PRIVATE"]; + /* what's all this? */ + [s appendString:@"\nTRANSP:OPAQUE"]; /* transparency */ + [s appendString:@"\nCLASS:PRIVATE"]; /* classification [like 'top secret'] */ - /* organizer */ - p = [self organizer]; - if(p) { + /* organizer */ + p = [self organizer]; + if(p) { NSString *x; [s appendString:@"\nORGANIZER;CN=\""]; @@ -158,12 +176,12 @@ static SaxObjectDecoder *sax = nil; [s appendString:@":"]; /* sic! */ [s appendString:x]; } - } + } - /* attendees */ - persons = [self attendees]; - count = [persons count]; - for(i = 0; i < count; i++) { + /* attendees */ + persons = [self attendees]; + count = [persons count]; + for (i = 0; i < count; i++) { NSString *x; p = [persons objectAtIndex:i]; @@ -176,11 +194,11 @@ static SaxObjectDecoder *sax = nil; [s appendString:@":"]; /* sic! */ [s appendString:x]; } - } - - /* postamble */ - [s appendString:@"\nEND:VEVENT\nEND:VCALENDAR"]; - return [s autorelease]; + } + + /* postamble */ + [s appendString:@"\nEND:VEVENT\nEND:VCALENDAR"]; + return s; } @@ -188,17 +206,17 @@ static SaxObjectDecoder *sax = nil; - (void)setUid:(NSString *)_value { - [self->event setUid:_value]; + [self->event setUid:_value]; } - (NSString *)uid { - return [self->event uid]; + return [self->event uid]; } - (void)setSummary:(NSString *)_value { - [self->event setSummary:_value]; + [self->event setSummary:_value]; } - (NSString *)summary { - return [self->event summary]; + return [self->event summary]; } - (void)setLocation:(NSString *)_value { -- 2.39.5