Added some property list parsing fixes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11834 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2001-12-19 11:43:06 +00:00
parent 70d9f361be
commit 6e5edd5259
10 changed files with 211 additions and 125 deletions

View file

@ -1,3 +1,10 @@
2001-12-19 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSXML.m: Check validation status at parse completion.
* Source/NSUserDefaults.m: Ensure flags are initialised.
* Source/GSCompatibility.m: Set GNUstep DTD for propertyLists.
* Tools/plist-0_9.dtd: GNUstep property list DTD.
Wed Dec 19 02:17:09 2001 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSThread.m (GSRegisterCurrentThread): Use @defs to

View file

@ -111,7 +111,6 @@
- (BOOL) scanPastSpace: (NSScanner*)scanner;
- (NSString*) scanSpecial: (NSScanner*)scanner;
- (NSString*) scanToken: (NSScanner*)scanner;
@end
#endif

View file

@ -57,11 +57,8 @@
#ifndef NO_GNUSTEP
@interface NSProcessInfo (GNUstep)
/* This method returns a set of debug levels set using the
* --GNU-Debug=... command line option. */
- (NSMutableSet*) debugSet;
/* When non using the other argument initialization hacks... */
+ (void) initializeWithArguments: (char**)argv
count: (int)argc
environment: (char**)env;

View file

@ -424,7 +424,8 @@ GSXMLPlMake(id obj, NSDictionary *loc)
dest = [NSMutableString stringWithCString:
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist "
"SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n"
"PUBLIC \"-//GNUstep//DTD plist 0.9//EN\" "
"\"http://www.gnustep.org/plist-0_9.xml\">\n"
"<plist version=\"0.9\">\n"];
XMLPlObject(dest, obj, loc, 0);

View file

@ -100,9 +100,11 @@ static void debugRead(NSData *data)
d = open(debugFile, O_WRONLY|O_CREAT|O_APPEND, 0644);
if (d >= 0)
{
s = [NSString stringWithFormat: @"\nRead %@ -\n", [NSDate date]];
s = [NSString stringWithFormat: @"\nRead %@ %u bytes - '",
[NSDate date], [data length]];
write(d, [s cString], [s cStringLength]);
write(d, [data bytes], [data length]);
write(d, "'", 1);
close(d);
}
[debugLock unlock];
@ -116,9 +118,11 @@ static void debugWrite(NSData *data)
d = open(debugFile, O_WRONLY|O_CREAT|O_APPEND, 0644);
if (d >= 0)
{
s = [NSString stringWithFormat: @"\nWrite %@ -\n", [NSDate date]];
s = [NSString stringWithFormat: @"\nWrite %@ %u bytes - '",
[NSDate date], [data length]];
write(d, [s cString], [s cStringLength]);
write(d, [data bytes], [data length]);
write(d, "'", 1);
close(d);
}
[debugLock unlock];

View file

@ -63,6 +63,7 @@
#include <Foundation/NSValue.h>
#include <Foundation/NSURL.h>
#include <Foundation/NSURLHandle.h>
#include <Foundation/NSDebug.h>
#include <Foundation/GSMime.h>
#include <string.h>
#include <ctype.h>
@ -223,17 +224,31 @@ parseCharacterSet(NSString *token)
return NSASCIIStringEncoding;
}
/**
* The most rudimentary context ... this is used for decoding plain
* text and binary dat (ie data which is not really decoded at all)
* and all other decoding work is done by a subclass.
*/
@implementation GSMimeCodingContext
/**
* Returns the current value of the 'atEnd' flag.
*/
- (BOOL) atEnd
{
return atEnd;
}
/**
* Copying is implemented as a simple retain.
*/
- (id) copyWithZone: (NSZone*)z
{
return RETAIN(self);
}
/**
* Sets the current value of the 'atEnd' flag.
*/
- (void) setAtEnd: (BOOL)flag
{
atEnd = flag;
@ -297,33 +312,6 @@ parseCharacterSet(NSString *token)
@interface GSMimeBinaryDecoderContext : GSMimeCodingContext
@end
@implementation GSMimeBinaryDecoderContext
- (id) autorelease
{
return self;
}
- (id) copyWithZone: (NSZone*)z
{
return self;
}
- (void) dealloc
{
NSLog(@"Error - attempt to deallocate GSMimeBinaryDecoderContext");
}
- (id) retain
{
return self;
}
- (void) release
{
}
@end
@interface GSMimeParser (Private)
- (BOOL) _decodeBody: (NSData*)data;
- (NSString*) _decodeHeader;
@ -369,9 +357,9 @@ parseCharacterSet(NSString *token)
* <list>
* <item>base64</item>
* <item>quoted-printable</item>
* <item>binary</item>
* <item>7bit</item>
* <item>8bit</item>
* <item>binary (no coding actually performed)</item>
* <item>7bit (no coding actually performed)</item>
* <item>8bit (no coding actually performed)</item>
* <item>chunked (for HTTP/1.1)</item>
* </list>
*/
@ -382,7 +370,7 @@ parseCharacterSet(NSString *token)
if (info == nil)
{
return AUTORELEASE([GSMimeBinaryDecoderContext new]);
return AUTORELEASE([GSMimeCodingContext new]);
}
name = [info objectForKey: @"Name"];
@ -393,7 +381,7 @@ parseCharacterSet(NSString *token)
if ([value length] == 0)
{
NSLog(@"Bad value for %@ header - assume binary encoding", name);
return AUTORELEASE([GSMimeBinaryDecoderContext new]);
return AUTORELEASE([GSMimeCodingContext new]);
}
if ([value isEqualToString: @"base64"] == YES)
{
@ -405,15 +393,15 @@ parseCharacterSet(NSString *token)
}
else if ([value isEqualToString: @"binary"] == YES)
{
return AUTORELEASE([GSMimeBinaryDecoderContext new]);
return AUTORELEASE([GSMimeCodingContext new]);
}
else if ([value characterAtIndex: 0] == '7')
{
return AUTORELEASE([GSMimeBinaryDecoderContext new]);
return AUTORELEASE([GSMimeCodingContext new]);
}
else if ([value characterAtIndex: 0] == '8')
{
return AUTORELEASE([GSMimeBinaryDecoderContext new]);
return AUTORELEASE([GSMimeCodingContext new]);
}
else if ([value isEqualToString: @"chunked"] == YES)
{
@ -422,7 +410,7 @@ parseCharacterSet(NSString *token)
}
NSLog(@"contextFor: - unknown header (%@) ... assumed binary encoding", name);
return AUTORELEASE([GSMimeBinaryDecoderContext new]);
return AUTORELEASE([GSMimeCodingContext new]);
}
/**
@ -828,7 +816,7 @@ parseCharacterSet(NSString *token)
}
}
/*
* Append any data.
* Correct size of output buffer.
*/
[dData setLength: size + dst - beg];
}
@ -840,7 +828,6 @@ parseCharacterSet(NSString *token)
[dData setLength: size + (end - src)];
dst = (unsigned char*)[dData mutableBytes];
memcpy(&dst[size], src, (end - src));
[dData setLength: size + end - src];
}
/*
@ -923,19 +910,22 @@ parseCharacterSet(NSString *token)
* <p>
* Since it is not always possible to determine if the end of a
* MIME document has been reached from its content, the method
* may need to be called with a nil argument after you have
* may need to be called with a nil or empty argument after you have
* passed all the data to it ... this tells it that the data
* is complete.
* </p>
*/
- (BOOL) parse: (NSData*)d
{
unsigned l = [d length];
if (complete == YES)
{
return NO; /* Already completely parsed! */
}
if ([d length] > 0)
if (l > 0)
{
NSDebugMLLog(@"GSMime", @"Parse %u bytes - '%*.*s'", l, l, l, [d bytes]);
if (inBody == NO)
{
[data appendBytes: [d bytes] length: [d length]];
@ -961,6 +951,11 @@ parseCharacterSet(NSString *token)
{
return NO; /* Header not parsed properly. */
}
NSDebugMLLog(@"GSMime", @"Parsed header '%@'", header);
}
else
{
NSDebugMLLog(@"GSMime", @"Parsed end of headers");
}
}
/*
@ -996,6 +991,7 @@ parseCharacterSet(NSString *token)
* This is an intermediary response ... so we have
* to restart the parsing operation!
*/
NSDebugMLLog(@"GSMime", @"Parsed http continuation");
inBody = NO;
}
}
@ -1007,13 +1003,18 @@ parseCharacterSet(NSString *token)
{
if (inBody == YES)
{
[self _decodeBody: d];
/*
* We can't just re-call -parse: ...
* that would lead to recursion.
*/
return [self _decodeBody: d];
}
else
{
return [self parse: d];
}
}
return YES; /* Want more data for body */
}
else
@ -1277,7 +1278,6 @@ parseCharacterSet(NSString *token)
* work generally -
* </p>
* <deflist>
*
* <term>content-disposition</term>
* <desc>
* <deflist>
@ -1309,7 +1309,6 @@ parseCharacterSet(NSString *token)
* <desc>The full MIME type (xxx/yyy) in lowercase</desc>
* </deflist>
* </desc>
*
* <term>content-transfer-encoding</term>
* <desc>
* <deflist>
@ -1317,7 +1316,6 @@ parseCharacterSet(NSString *token)
* <desc>The transfer encoding type in lowercase</desc>
* </deflist>
* </desc>
*
* <term>http</term>
* <desc>
* <deflist>
@ -1833,9 +1831,10 @@ parseCharacterSet(NSString *token)
- (BOOL) _decodeBody: (NSData*)d
{
unsigned l = [d length];
BOOL result = NO;
rawBodyLength += [d length];
rawBodyLength += l;
if (context == nil)
{
@ -1868,8 +1867,11 @@ parseCharacterSet(NSString *token)
}
context = [self contextFor: hdr];
RETAIN(context);
NSDebugMLLog(@"GSMime", @"Parse body expects %u bytes", expect);
}
NSDebugMLLog(@"GSMime", @"Parse %u bytes - '%*.*s'", l, l, l, [d bytes]);
if ([context atEnd] == YES)
{
inBody = NO;
@ -1908,6 +1910,7 @@ parseCharacterSet(NSString *token)
inBody = NO;
complete = YES;
NSDebugMLLog(@"GSMime", @"Parse body complete");
/*
* If no content type is supplied, we assume text.
*/
@ -2162,7 +2165,6 @@ parseCharacterSet(NSString *token)
}
return unwrappingComplete;
}
@end

View file

@ -3,7 +3,6 @@
Written by: Georg Tuparev <Tuparev@EMBL-Heidelberg.de>
Heidelberg, Germany
Tuparev@EMBL-Heidelberg.de
Modified by: Richard Frith-Macdonald <rfm@gnu.org>
This file is part of the GNUstep Base Library.
@ -522,8 +521,10 @@ int main(int argc, char *argv[], char *env[])
#endif /* HAS_LOAD_METHOD && HAS_PROCFS */
/* Fallback method. User must call this method if none of the other
above hacks is being used
/**
* Fallback method. The developer must call this method to initialize
* the |NSProcessInfo system if none of the system-specific hacks to
* auto initiailise it are working.
*/
+ (void) initializeWithArguments: (char**)argv
count: (int)argc
@ -563,6 +564,13 @@ int main(int argc, char *argv[], char *env[])
return _gnu_arguments;
}
/**
* This method returns a set of debug levels set using the
* --GNU-Debug=... command line option.<br />
* You can modify this set to change the debug logging under
* your programs control ... but such modifications are not
* thread-safe.
*/
- (NSMutableSet*) debugSet
{
return _debug_set;

View file

@ -349,6 +349,7 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
[sharedDefaults registerDefaults: [self _unlocalizedDefaults]];
}
RETAIN(sharedDefaults);
updateCache(sharedDefaults);
[classLock unlock];
return AUTORELEASE(sharedDefaults);
}

View file

@ -33,7 +33,7 @@ include ../config.mak
# DTDs to install
dtddir = $(GNUSTEP_RESOURCES)/DTDs
DTD_FILES = gsdoc-0_6_5.dtd gsdoc-0_6_6.dtd gsdoc-0_6_7.dtd
DTD_FILES = plist-0_9.dtd gsdoc-0_6_5.dtd gsdoc-0_6_6.dtd gsdoc-0_6_7.dtd
# DocTemplates to install
doctemplatesdir = $(GNUSTEP_RESOURCES)/DocTemplates

67
Tools/plist-0_9.dtd Normal file
View file

@ -0,0 +1,67 @@
<!--
XML Document Type Definition for GNUstep property list (plist).
This is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This document 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 General Public License for more details.
You should have received a copy of the GNU General
Public License along with this software; if not, write to the
Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
02139, USA.
-->
<!--
plist is an XML language - Typical usage:
<?xml version="1.0" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC "-//GNUstep//DTD plist 0.9//EN"
"http://www.gnustep.org/plist-0_9.xml">
<plist>
</plist>
-->
<!ENTITY % item "(array | data | date | dict | false | integer | real | string | true)">
<!ELEMENT plist %item;>
<!ATTLIST plist version CDATA "0.9" >
<!-- An array containing zero or more items -->
<!ELEMENT array (%item;)*>
<!-- A chunk of base-64 encoded data -->
<!ELEMENT data (#PCDATA)>
<!-- A date YYYY-MM-DD hh:mm:ss Z -->
<!ELEMENT date (#PCDATA)>
<!-- A dictionary of keys and items -->
<!ELEMENT dict (key, %item;)*>
<!-- A boolean constant -->
<!ELEMENT false EMPTY>
<!-- An integer in base ten, with an optional sign -->
<!ELEMENT integer (#PCDATA)>
<!-- A key ... treated just like a string -->
<!ELEMENT key (#PCDATA)>
<!-- A string of characters. -->
<!ELEMENT string (#PCDATA)>
<!-- A real number [+/-]n.p[E[+/-]m] -->
<!ELEMENT real (#PCDATA)>
<!-- A boolean constant -->
<!ELEMENT true EMPTY>