Minor incremental parsing fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18200 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-11-25 13:19:41 +00:00
parent e74bcf1b96
commit c4119b882c
3 changed files with 39 additions and 5 deletions

View file

@ -1,3 +1,9 @@
2003-11-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSMime.m: fix for incremental parsing so that
the parser insists on the crlf after the last boundary in a message
(hold a flag to say we are still expecting the crlf).
2003-11-23 S.J.Chun <chunsj@embian.com> 2003-11-23 S.J.Chun <chunsj@embian.com>
* Headers/Additions/GNUstepBase/GSCategories.h: Change * Headers/Additions/GNUstepBase/GSCategories.h: Change

View file

@ -160,6 +160,7 @@
unsigned int complete:1; unsigned int complete:1;
unsigned int hadErrors:1; unsigned int hadErrors:1;
unsigned int buggyQuotes:1; unsigned int buggyQuotes:1;
unsigned int wantEndOfLine:1;
} flags; } flags;
NSData *boundary; NSData *boundary;
GSMimeDocument *document; GSMimeDocument *document;

View file

@ -1212,7 +1212,8 @@ wordData(NSString *word)
* This is an intermediary response ... so we have * This is an intermediary response ... so we have
* to restart the parsing operation! * to restart the parsing operation!
*/ */
NSDebugMLLog(@"GSMime", @"Parsed http continuation", ""); NSDebugMLLog(@"GSMime",
@"Parsed http continuation", "");
flags.inBody = 0; flags.inBody = 0;
} }
} }
@ -1242,7 +1243,11 @@ wordData(NSString *word)
{ {
BOOL result; BOOL result;
if (flags.inBody == 1) if (flags.wantEndOfLine == 1)
{
result = [self parse: [NSData dataWithBytes: @"\r\n" length: 2]];
}
else if (flags.inBody == 1)
{ {
result = [self _decodeBody: d]; result = [self _decodeBody: d];
} }
@ -1254,6 +1259,7 @@ wordData(NSString *word)
*/ */
result = [self parse: [NSData dataWithBytes: @"\r\n\r\n" length: 4]]; result = [self parse: [NSData dataWithBytes: @"\r\n\r\n" length: 4]];
} }
flags.wantEndOfLine = 0;
flags.inBody = 0; flags.inBody = 0;
flags.complete = 1; /* Finished parsing */ flags.complete = 1; /* Finished parsing */
return result; return result;
@ -2201,6 +2207,8 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info);
while (done == NO) while (done == NO)
{ {
BOOL found = NO;
/* /*
* Search our data for the next boundary. * Search our data for the next boundary.
*/ */
@ -2212,18 +2220,37 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info);
if (lineStart == 0 || bytes[lineStart-1] == '\r' if (lineStart == 0 || bytes[lineStart-1] == '\r'
|| bytes[lineStart-1] == '\n') || bytes[lineStart-1] == '\n')
{ {
BOOL lastPart = NO;
unsigned eol;
lineEnd = lineStart + bLength; lineEnd = lineStart + bLength;
if (lineEnd + 2 < dataEnd && bytes[lineEnd] == '-' eol = lineEnd;
if (lineEnd + 2 <= dataEnd && bytes[lineEnd] == '-'
&& bytes[lineEnd+1] == '-') && bytes[lineEnd+1] == '-')
{ {
endedFinalPart = YES; eol += 2;
lastPart = YES;
}
if (eol < dataEnd && bytes[eol] == '\r')
{
eol++;
}
if (eol < dataEnd && bytes[eol] == '\n')
{
flags.wantEndOfLine = 0;
found = YES;
endedFinalPart = lastPart;
}
else
{
flags.wantEndOfLine = 1;
} }
break; break;
} }
} }
lineStart++; lineStart++;
} }
if (dataEnd - lineStart < bLength) if (found == NO)
{ {
done = YES; /* Needs more data. */ done = YES; /* Needs more data. */
} }