Add methods to get/set whether a parser is parsing an HTTP document.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13714 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-05-27 08:28:28 +00:00
parent 5f7646186e
commit 4a42e431f2
2 changed files with 65 additions and 4 deletions

View file

@ -125,6 +125,7 @@
unsigned expect;
unsigned rawBodyLength;
BOOL inBody;
BOOL isHttp;
BOOL complete;
NSData *boundary;
GSMimeDocument *document;
@ -141,17 +142,19 @@
fromRange: (NSRange)aRange
intoData: (NSMutableData*)dData
withContext: (GSMimeCodingContext*)con;
- (GSMimeDocument*) document;
- (void) expectNoHeaders;
- (BOOL) isComplete;
- (BOOL) isHttp;
- (BOOL) isInBody;
- (BOOL) isInHeaders;
- (GSMimeDocument*) mimeDocument;
- (BOOL) parse: (NSData*)d;
- (BOOL) parseHeader: (NSString*)aHeader;
- (BOOL) scanHeaderBody: (NSScanner*)scanner into: (GSMimeHeader*)info;
- (BOOL) scanPastSpace: (NSScanner*)scanner;
- (NSString*) scanSpecial: (NSScanner*)scanner;
- (NSString*) scanToken: (NSScanner*)scanner;
- (void) setIsHttp;
@end
#endif

View file

@ -864,9 +864,10 @@ parseCharacterSet(NSString *token)
}
/**
* <deprecated />
* Returns the object into which raw mime data is being parsed.
*/
- (GSMimeDocument*) document
- (id) document
{
return document;
}
@ -888,6 +889,7 @@ parseCharacterSet(NSString *token)
inBody = YES;
}
}
/**
* Returns YES if the document parsing is known to be completed.
*/
@ -896,6 +898,15 @@ parseCharacterSet(NSString *token)
return complete;
}
/**
* Returns YES if the parser is parsing an HTTP document rather than
* a true MIME document.
*/
- (BOOL) isHttp
{
return isHttp;
}
/**
* Returns YES if all the document headers have been parsed but
* the document body parsing may not yet be complete.
@ -929,6 +940,15 @@ parseCharacterSet(NSString *token)
return self;
}
/**
* Returns the GSMimeDocument instance into which data is being parsed
* or has been parsed.
*/
- (GSMimeDocument*) mimeDocument
{
return document;
}
/**
* <p>
* This method is called repeatedly to pass raw mime data into
@ -1383,6 +1403,10 @@ parseCharacterSet(NSString *token)
[document deleteHeader: h];
}
/*
* Mark to say we are parsing HTTP content
*/
[self setIsHttp];
}
else if ([name isEqualToString: @"content-transfer-encoding"] == YES
|| [name isEqualToString: @"transfer-encoding"] == YES)
@ -1590,8 +1614,28 @@ parseCharacterSet(NSString *token)
}
if ([string characterAtIndex: r.location - 1] == '\\')
{
r.location++;
r.length = length - r.location;
int p;
/*
* Count number of escape ('\') characters ... if it's odd
* then the quote has been escaped and is not a closing
* quote.
*/
p = r.location;
while (p > 0 && [string characterAtIndex: p - 1] == '\\')
{
p--;
}
p = r.location - p;
if (p % 2 == 1)
{
r.location++;
r.length = length - r.location;
}
else
{
done = YES;
}
}
else
{
@ -1648,11 +1692,25 @@ parseCharacterSet(NSString *token)
}
}
/**
* Method to inform the parser that the data it is parsing is an HTTP
* document rather than true MIME. This method is called internally
* if the parser detects an HTTP response line at the start of the
* headers it is parsing.
*/
- (void) setIsHttp
{
isHttp = YES;
}
@end
@implementation GSMimeParser (Private)
/*
* This method takes the raw data of an unfolded header line, and handles
* Method to inform the parser that the data it is parsing is an HTTP
* document rather than true MIME. This method is called internally
* if the parser detects an HTTP response line at the start of the
* headers it is parsing.
* RFC2047 word encoding in the header by creating a string containing the
* decoded words.
*/