Fixed parsing bounds for header fields and values.

This commit is contained in:
Vincent Richard 2005-03-15 17:31:26 +00:00
parent e0aabf8c72
commit 4493a7f801
3 changed files with 12 additions and 15 deletions

View File

@ -178,6 +178,8 @@ address* address::parseNext(const string& buffer, const string::size_type positi
try try
{ {
parsedAddress->parse(buffer, start, pos, NULL); parsedAddress->parse(buffer, start, pos, NULL);
parsedAddress->setParsedBounds(start, pos);
return (parsedAddress); return (parsedAddress);
} }
catch (std::exception&) catch (std::exception&)

View File

@ -134,9 +134,10 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ
while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t'))
++pos; ++pos;
// Extract the field value const string::size_type contentsStart = pos;
string contents; string::size_type contentsEnd = 0;
// Extract the field value
while (pos < end) while (pos < end)
{ {
c = buffer[pos]; c = buffer[pos];
@ -144,18 +145,17 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ
// Check for end of contents // Check for end of contents
if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n') if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n')
{ {
contentsEnd = pos;
pos += 2; pos += 2;
break; break;
} }
else if (c == '\n') else if (c == '\n')
{ {
contentsEnd = pos;
++pos; ++pos;
break; break;
} }
const string::size_type ctsStart = pos;
string::size_type ctsEnd = pos;
while (pos < end) while (pos < end)
{ {
c = buffer[pos]; c = buffer[pos];
@ -163,13 +163,13 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ
// Check for end of line // Check for end of line
if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n') if (c == '\r' && pos + 1 < end && buffer[pos + 1] == '\n')
{ {
ctsEnd = pos; contentsEnd = pos;
pos += 2; pos += 2;
break; break;
} }
else if (c == '\n') else if (c == '\n')
{ {
ctsEnd = pos; contentsEnd = pos;
++pos; ++pos;
break; break;
} }
@ -177,13 +177,6 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ
++pos; ++pos;
} }
if (ctsEnd != ctsStart)
{
// Append this line to contents
contents.append(buffer.begin() + ctsStart,
buffer.begin() + ctsEnd);
}
// Handle the case of folded lines // Handle the case of folded lines
if (buffer[pos] == ' ' || buffer[pos] == '\t') if (buffer[pos] == ' ' || buffer[pos] == '\t')
{ {
@ -200,7 +193,7 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ
// Return a new field // Return a new field
headerField* field = headerFieldFactory::getInstance()->create(name); headerField* field = headerFieldFactory::getInstance()->create(name);
field->parse(contents); // TODO: fix incorrect parsed bounds... field->parse(buffer, contentsStart, contentsEnd, NULL);
field->setParsedBounds(nameStart, pos); field->setParsedBounds(nameStart, pos);
if (newPosition) if (newPosition)

View File

@ -66,6 +66,8 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
delete (parsedAddress); delete (parsedAddress);
getValue().setParsedBounds(position, end);
setParsedBounds(position, end); setParsedBounds(position, end);
if (newPosition) if (newPosition)