Add content location methods.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19903 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-08-23 14:29:50 +00:00
parent 91cbfcec05
commit d3f69e8740
4 changed files with 69 additions and 8 deletions

View file

@ -1,3 +1,7 @@
2004-08-23 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSMime.m: Add content location methods.
2004-08-22 Richard Frith-Macdonald <rfm@gnu.org> 2004-08-22 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: Various minor optimisations ... uppercaseString * Source/NSString.m: Various minor optimisations ... uppercaseString

View file

@ -113,10 +113,12 @@
- (NSArray*) allHeaders; - (NSArray*) allHeaders;
- (id) content; - (id) content;
- (id) contentByID: (NSString*)key; - (id) contentByID: (NSString*)key;
- (id) contentByLocation: (NSString*)key;
- (id) contentByName: (NSString*)key; - (id) contentByName: (NSString*)key;
- (id) copyWithZone: (NSZone*)z; - (id) copyWithZone: (NSZone*)z;
- (NSString*) contentFile; - (NSString*) contentFile;
- (NSString*) contentID; - (NSString*) contentID;
- (NSString*) contentLocation;
- (NSString*) contentName; - (NSString*) contentName;
- (NSString*) contentSubtype; - (NSString*) contentSubtype;
- (NSString*) contentType; - (NSString*) contentType;

View file

@ -60,6 +60,7 @@
static NSCharacterSet *whitespace = nil; static NSCharacterSet *whitespace = nil;
static NSCharacterSet *rfc822Specials = nil; static NSCharacterSet *rfc822Specials = nil;
static NSCharacterSet *rfc2045Specials = nil; static NSCharacterSet *rfc2045Specials = nil;
static Class NSArrayClass = 0;
/* /*
* Name - decodebase64() * Name - decodebase64()
@ -652,6 +653,14 @@ wordData(NSString *word)
return AUTORELEASE(newDocument); return AUTORELEASE(newDocument);
} }
+ (void) initialize
{
if (NSArrayClass == 0)
{
NSArrayClass = [NSArray class];
}
}
/** /**
* Create and return a parser. * Create and return a parser.
*/ */
@ -2635,6 +2644,10 @@ static NSCharacterSet *tokenSet = nil;
tokenSet = [ms copy]; tokenSet = [ms copy];
RELEASE(ms); RELEASE(ms);
nonToken = RETAIN([tokenSet invertedSet]); nonToken = RETAIN([tokenSet invertedSet]);
if (NSArrayClass == 0)
{
NSArrayClass = [NSArray class];
}
} }
} }
@ -3379,6 +3392,10 @@ static NSCharacterSet *tokenSet = nil;
[m removeCharactersInString: @"."]; [m removeCharactersInString: @"."];
rfc2045Specials = [m copy]; rfc2045Specials = [m copy];
whitespace = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]); whitespace = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]);
if (NSArrayClass == 0)
{
NSArrayClass = [NSArray class];
}
} }
} }
@ -3543,7 +3560,7 @@ static NSCharacterSet *tokenSet = nil;
{ {
key = [NSString stringWithFormat: @"<%@>", key]; key = [NSString stringWithFormat: @"<%@>", key];
} }
if ([content isKindOfClass: [NSArray class]] == YES) if ([content isKindOfClass: NSArrayClass] == YES)
{ {
NSEnumerator *e = [content objectEnumerator]; NSEnumerator *e = [content objectEnumerator];
GSMimeDocument *d; GSMimeDocument *d;
@ -3564,6 +3581,35 @@ static NSCharacterSet *tokenSet = nil;
return nil; return nil;
} }
/**
* Search the content of this document to locate a part whose content ID
* matches the specified key. Recursively descend into other documents.<br />
* Wraps the supplied key in angle brackets if they are not present.<br />
* Return nil if no match is found, the matching GSMimeDocument otherwise.
*/
- (id) contentByLocation: (NSString*)key
{
if ([content isKindOfClass: NSArrayClass] == YES)
{
NSEnumerator *e = [content objectEnumerator];
GSMimeDocument *d;
while ((d = [e nextObject]) != nil)
{
if ([[d contentLocation] isEqualToString: key] == YES)
{
return d;
}
d = [d contentByLocation: key];
if (d != nil)
{
return d;
}
}
}
return nil;
}
/** /**
* Search the content of this document to locate a part whose content-type * Search the content of this document to locate a part whose content-type
* name or content-disposition name matches the specified key. * name or content-disposition name matches the specified key.
@ -3573,7 +3619,7 @@ static NSCharacterSet *tokenSet = nil;
- (id) contentByName: (NSString*)key - (id) contentByName: (NSString*)key
{ {
if ([content isKindOfClass: [NSArray class]] == YES) if ([content isKindOfClass: NSArrayClass] == YES)
{ {
NSEnumerator *e = [content objectEnumerator]; NSEnumerator *e = [content objectEnumerator];
GSMimeDocument *d; GSMimeDocument *d;
@ -3622,6 +3668,16 @@ static NSCharacterSet *tokenSet = nil;
return [hdr value]; return [hdr value];
} }
/**
* Convenience method to fetch the content location from the header.
*/
- (NSString*) contentLocation
{
GSMimeHeader *hdr = [self headerNamed: @"content-location"];
return [hdr value];
}
/** /**
* Convenience method to fetch the content name from the header. * Convenience method to fetch the content name from the header.
*/ */
@ -3716,7 +3772,7 @@ static NSCharacterSet *tokenSet = nil;
{ {
NSMutableArray *a = nil; NSMutableArray *a = nil;
if ([content isKindOfClass: [NSArray class]] == YES) if ([content isKindOfClass: NSArrayClass] == YES)
{ {
NSEnumerator *e = [content objectEnumerator]; NSEnumerator *e = [content objectEnumerator];
GSMimeDocument *d; GSMimeDocument *d;
@ -3816,7 +3872,7 @@ static NSCharacterSet *tokenSet = nil;
c->headers = [[NSMutableArray allocWithZone: z] initWithArray: headers c->headers = [[NSMutableArray allocWithZone: z] initWithArray: headers
copyItems: YES]; copyItems: YES];
if ([content isKindOfClass: [NSArray class]] == YES) if ([content isKindOfClass: NSArrayClass] == YES)
{ {
c->content = [[NSMutableArray allocWithZone: z] initWithArray: content c->content = [[NSMutableArray allocWithZone: z] initWithArray: content
copyItems: YES]; copyItems: YES];
@ -4123,7 +4179,7 @@ static NSCharacterSet *tokenSet = nil;
} }
} }
if ([content isKindOfClass: [NSArray class]] == YES) if ([content isKindOfClass: NSArrayClass] == YES)
{ {
count = [content count]; count = [content count];
partData = [NSMutableArray arrayWithCapacity: count]; partData = [NSMutableArray arrayWithCapacity: count];
@ -4540,7 +4596,7 @@ static NSCharacterSet *tokenSet = nil;
ASSIGNCOPY(content, newContent); ASSIGNCOPY(content, newContent);
} }
} }
else if ([newContent isKindOfClass: [NSArray class]] == YES) else if ([newContent isKindOfClass: NSArrayClass] == YES)
{ {
if (newContent != content) if (newContent != content)
{ {
@ -4670,7 +4726,7 @@ static NSCharacterSet *tokenSet = nil;
if ([type isEqualToString: @"multipart"] == NO if ([type isEqualToString: @"multipart"] == NO
&& [type isEqualToString: @"application"] == NO && [type isEqualToString: @"application"] == NO
&& [content isKindOfClass: [NSArray class]] == YES) && [content isKindOfClass: NSArrayClass] == YES)
{ {
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"[%@ -%@] content doesn't match content-type", format: @"[%@ -%@] content doesn't match content-type",

View file

@ -1027,7 +1027,6 @@ GSPropertyListFromStringsFormat(NSString *string)
NSMutableDictionary *dict; NSMutableDictionary *dict;
pldata _pld; pldata _pld;
pldata *pld = &_pld; pldata *pld = &_pld;
unsigned length;
NSData *d; NSData *d;
/* /*