From d4d1e648d4639f98b60470550500c617f09c9032 Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 5 Dec 2005 14:20:31 +0000 Subject: [PATCH] improved error handling git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1192 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-ical/data/kde-vcard-bug1594.vcf | 9 +++ sope-ical/versitSaxDriver/ChangeLog | 9 +++ sope-ical/versitSaxDriver/VSSaxDriver.m | 48 ++++++++++++--- sope-ical/versitSaxDriver/VSvCardSaxDriver.h | 2 +- sope-ical/versitSaxDriver/VSvCardSaxDriver.m | 65 +++++++++----------- sope-ical/versitSaxDriver/Version | 2 +- 6 files changed, 91 insertions(+), 44 deletions(-) create mode 100644 sope-ical/data/kde-vcard-bug1594.vcf diff --git a/sope-ical/data/kde-vcard-bug1594.vcf b/sope-ical/data/kde-vcard-bug1594.vcf new file mode 100644 index 00000000..deb68576 --- /dev/null +++ b/sope-ical/data/kde-vcard-bug1594.vcf @@ -0,0 +1,9 @@ +BEGIN:VCARD +CLASS:PUBLIC +FN:NEW USER +N:USER;NEW;;; +NAME:NEW USER +TEL;TYPE=HOME:1234 567890 +UID:bH0Q5UMsyb +VERSION:3.0 +END:VCARD diff --git a/sope-ical/versitSaxDriver/ChangeLog b/sope-ical/versitSaxDriver/ChangeLog index c23a6fd2..0b0dd0ea 100644 --- a/sope-ical/versitSaxDriver/ChangeLog +++ b/sope-ical/versitSaxDriver/ChangeLog @@ -1,3 +1,12 @@ +2005-12-05 Helge Hess + + * v4.5.21 + + * VSSaxDriver.m: added some debug logs, throw an error if a tagline + starts with a colon/semicolon (tagname missing) + + * VSvCardSaxDriver.m: minor code cleanups + 2005-11-17 Helge Hess * VSSaxDriver.m: renamed internal -error: method to -reportError: to diff --git a/sope-ical/versitSaxDriver/VSSaxDriver.m b/sope-ical/versitSaxDriver/VSSaxDriver.m index 2e1f6262..0866c87a 100644 --- a/sope-ical/versitSaxDriver/VSSaxDriver.m +++ b/sope-ical/versitSaxDriver/VSSaxDriver.m @@ -679,6 +679,11 @@ static VSStringFormatter *stringFormatter = nil; NSMutableArray *tagAttributes; NSRange r, todoRange; unsigned length; + +#if 0 + if (debugOn) + NSLog(@"%s: parse line: '%@'", __PRETTY_FUNCTION__, _line); +#endif length = [_line length]; todoRange = NSMakeRange(0, length); @@ -686,9 +691,15 @@ static VSStringFormatter *stringFormatter = nil; options:0 range:todoRange]; /* is line well-formed? */ - if (r.length == 0) { - [self reportError:[@"got an improper content line! ->\n" - stringByAppendingString:_line]]; + if (r.length == 0 || r.location == 0) { + NSLog(@"todo-range: %i-%i, range: %i-%i, length %i, str-class %@", + todoRange.location, todoRange.length, + r.location, r.length, + length, NSStringFromClass([_line class])); + + [self reportError: + [@"got an improper content line! (did not find colon) ->\n" + stringByAppendingString:_line]]; return; } @@ -696,6 +707,12 @@ static VSStringFormatter *stringFormatter = nil; tagName = [[_line substringToIndex:r.location] uppercaseString]; tagAttributes = [[NSMutableArray alloc] initWithCapacity:16]; + if (debugOn && ([tagName length] == 0)) { + [self reportError:[@"got an improper content line! ->\n" + stringByAppendingString:_line]]; + return; + } + /* possible shortcut: if we spotted a ':', we don't have to do "expensive" argument scanning/processing. @@ -759,12 +776,23 @@ static VSStringFormatter *stringFormatter = nil; } tagValue = [_line substringFromIndex:NSMaxRange(r)]; + if (debugOn && ([tagName length] == 0)) { + NSLog(@"%s: missing tagname in line: '%@'", + __PRETTY_FUNCTION__, _line); + } + /* At this point we have: - name: 'BEGIN', 'TEL', 'EMAIL', 'ITEM1.ADR' etc - value: ';;;Magdeburg;;;Germany' - atributes: ("type=INTERNET", "type=HOME", "type=pref") + name: 'BEGIN', 'TEL', 'EMAIL', 'ITEM1.ADR' etc + value: ';;;Magdeburg;;;Germany' + attributes: ("type=INTERNET", "type=HOME", "type=pref") */ + +#if 0 +# warning DEBUG LOG ENABLED + NSLog(@"TAG: %@, value %@ attrs %@", + tagName, tagValue, tagAttributes); +#endif /* process tag */ @@ -779,7 +807,13 @@ static VSStringFormatter *stringFormatter = nil; [self _endComponent:tagName value:tagValue]; } else { - // TODO: make this more generic, this one is used with Outlook vCards + /* a regular content tag */ + + /* + check whether the tga value is encoded in quoted printable, + this one is used with Outlook vCards (see data/ for examples) + */ + // TODO: make the encoding check more generic if ([tagAttributes containsObject:@"ENCODING=QUOTED-PRINTABLE"]) { // TODO: QP is charset specific! The one below decodes in Unicode! tagValue = [tagValue stringByDecodingQuotedPrintable]; diff --git a/sope-ical/versitSaxDriver/VSvCardSaxDriver.h b/sope-ical/versitSaxDriver/VSvCardSaxDriver.h index cf93a84b..4e532521 100644 --- a/sope-ical/versitSaxDriver/VSvCardSaxDriver.h +++ b/sope-ical/versitSaxDriver/VSvCardSaxDriver.h @@ -1,6 +1,6 @@ /* Copyright (C) 2003-2004 Max Berger - Copyright (C) 2004 OpenGroupware.org + Copyright (C) 2004-2005 OpenGroupware.org This file is part of versitSaxDriver, written for the OpenGroupware.org project (OGo). diff --git a/sope-ical/versitSaxDriver/VSvCardSaxDriver.m b/sope-ical/versitSaxDriver/VSvCardSaxDriver.m index 39431e4e..14928117 100644 --- a/sope-ical/versitSaxDriver/VSvCardSaxDriver.m +++ b/sope-ical/versitSaxDriver/VSvCardSaxDriver.m @@ -1,25 +1,25 @@ /* - Copyright (C) 2003-2004 Max Berger - Copyright (C) 2004 OpenGroupware.org - - This file is part of versitSaxDriver, written for the OpenGroupware.org - project (OGo). - - SOPE is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - SOPE is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with SOPE; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. - */ + Copyright (C) 2003-2004 Max Berger + Copyright (C) 2004-2005 OpenGroupware.org + + This file is part of versitSaxDriver, written for the OpenGroupware.org + project (OGo). + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ #include "VSvCardSaxDriver.h" #include "common.h" @@ -39,12 +39,7 @@ static NSSet *defElementNames = nil; didInit = YES; defElementNames = [[NSSet alloc] initWithObjects: - @"class", - @"prodid", - @"rev", - @"uid", - @"version", - nil]; + @"class", @"prodid", @"rev", @"uid", @"version", nil]; } + (NSDictionary *)xcardMapping { @@ -68,10 +63,10 @@ static NSSet *defElementNames = nil; | VERSION | version | CDATA | IMPLIED | +----------------+------------+------------+----------------+ */ - [xcard setObject:@"class" forKey:@"CLASS"]; - [xcard setObject:@"prodid" forKey:@"PRODID"]; - [xcard setObject:@"rev" forKey:@"REV"]; - [xcard setObject:@"uid" forKey:@"UID"]; + [xcard setObject:@"class" forKey:@"CLASS"]; + [xcard setObject:@"prodid" forKey:@"PRODID"]; + [xcard setObject:@"rev" forKey:@"REV"]; + [xcard setObject:@"uid" forKey:@"UID"]; [xcard setObject:@"version" forKey:@"VERSION"]; @@ -96,11 +91,11 @@ static NSSet *defElementNames = nil; | BDAY | bday | PCDATA | +----------------+------------+-----------------------------+ */ - [xcard setObject:@"fn" forKey:@"FN"]; - [xcard setObject:@"n" forKey:@"N"]; + [xcard setObject:@"fn" forKey:@"FN"]; + [xcard setObject:@"n" forKey:@"N"]; [xcard setObject:@"nickname" forKey:@"NICKNAME"]; - [xcard setObject:@"photo" forKey:@"PHOTO"]; - [xcard setObject:@"bday" forKey:@"BDAY"]; + [xcard setObject:@"photo" forKey:@"PHOTO"]; + [xcard setObject:@"bday" forKey:@"BDAY"]; /* diff --git a/sope-ical/versitSaxDriver/Version b/sope-ical/versitSaxDriver/Version index 161b0af2..c4b3e0d5 100644 --- a/sope-ical/versitSaxDriver/Version +++ b/sope-ical/versitSaxDriver/Version @@ -1,3 +1,3 @@ # Version file -SUBMINOR_VERSION:=20 +SUBMINOR_VERSION:=21 -- 2.39.5