Added flag to know when a multipart last boundary was found.
git-svn-id: http://yate.null.ro/svn/yate/trunk@1622 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
d6d9ceda8f
commit
5c670eeee4
|
@ -601,17 +601,20 @@ void MimeMultipartBody::parse(const char* buf, int len)
|
||||||
if (!(buf && len > 0 && getBoundary(boundary)))
|
if (!(buf && len > 0 && getBoundary(boundary)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool endBody;
|
||||||
// Find first boundary: ignore the data before it
|
// Find first boundary: ignore the data before it
|
||||||
findBoundary(buf,len,boundary.c_str(),boundary.length());
|
findBoundary(buf,len,boundary.c_str(),boundary.length(),endBody);
|
||||||
|
|
||||||
// Parse for bodies
|
// Parse for bodies
|
||||||
XDebug(DebugInfo,"Start parsing boundary=%s len=%d [%p]",
|
XDebug(DebugInfo,"Start parsing boundary=%s len=%d [%p]",
|
||||||
boundary.c_str() + 4,len,this);
|
boundary.c_str() + 4,len,this);
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
if (endBody)
|
||||||
|
break;
|
||||||
// Find next boundary. Get the length of data before it
|
// Find next boundary. Get the length of data before it
|
||||||
// 'start' will point to the beginning of an enclosed body
|
// 'start' will point to the beginning of an enclosed body
|
||||||
const char* start = buf;
|
const char* start = buf;
|
||||||
int l = findBoundary(buf,len,boundary.c_str(),boundary.length());
|
int l = findBoundary(buf,len,boundary.c_str(),boundary.length(),endBody);
|
||||||
XDebug(DebugInfo,"Found %d length body (remain=%d) [%p]",l,len,this);
|
XDebug(DebugInfo,"Found %d length body (remain=%d) [%p]",l,len,this);
|
||||||
if (l <= 0)
|
if (l <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -671,7 +674,8 @@ void MimeMultipartBody::parse(const char* buf, int len)
|
||||||
XDebug(DebugInfo,"Added ('%s',%p) with %u additional headers [%p]",
|
XDebug(DebugInfo,"Added ('%s',%p) with %u additional headers [%p]",
|
||||||
cType->c_str(),body,body->headers().count(),this);
|
cType->c_str(),body,body->headers().count(),this);
|
||||||
}
|
}
|
||||||
XDebug(DebugInfo,"End parsing boundary=%s [%p]",boundary.c_str() + 4,this);
|
XDebug(DebugInfo,"End parsing boundary=%s%s [%p]",boundary.c_str() + 4,
|
||||||
|
(endBody && len > 0)?" .Found garbage after body":"",this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse input buffer for first body boundary or data end
|
// Parse input buffer for first body boundary or data end
|
||||||
|
@ -680,11 +684,14 @@ void MimeMultipartBody::parse(const char* buf, int len)
|
||||||
// buffer was reached
|
// buffer was reached
|
||||||
// Return the length of data before the found boundary
|
// Return the length of data before the found boundary
|
||||||
int MimeMultipartBody::findBoundary(const char*& buf, int& len,
|
int MimeMultipartBody::findBoundary(const char*& buf, int& len,
|
||||||
const char* boundary, unsigned int bLen)
|
const char* boundary, unsigned int bLen, bool& endBody)
|
||||||
{
|
{
|
||||||
if (len <= 0)
|
if (len <= 0) {
|
||||||
|
endBody = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
endBody = false;
|
||||||
unsigned int l = len;
|
unsigned int l = len;
|
||||||
int bodyLen = 0;
|
int bodyLen = 0;
|
||||||
|
|
||||||
|
@ -713,6 +720,7 @@ int MimeMultipartBody::findBoundary(const char*& buf, int& len,
|
||||||
if (l > 2 && buf[0] == '-' && buf[1] == '-') {
|
if (l > 2 && buf[0] == '-' && buf[1] == '-') {
|
||||||
buf += 2;
|
buf += 2;
|
||||||
l -= 2;
|
l -= 2;
|
||||||
|
endBody = true;
|
||||||
}
|
}
|
||||||
// Skip until the end of line or data
|
// Skip until the end of line or data
|
||||||
for (; l; buf++, l--)
|
for (; l; buf++, l--)
|
||||||
|
@ -725,6 +733,8 @@ int MimeMultipartBody::findBoundary(const char*& buf, int& len,
|
||||||
}
|
}
|
||||||
|
|
||||||
len = l;
|
len = l;
|
||||||
|
if (!len)
|
||||||
|
endBody = true;
|
||||||
return bodyLen;
|
return bodyLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -513,9 +513,10 @@ protected:
|
||||||
private:
|
private:
|
||||||
// Parse input buffer for first body boundary or data end
|
// Parse input buffer for first body boundary or data end
|
||||||
// Advance buffer pass the boundary line and decrease the buffer length
|
// Advance buffer pass the boundary line and decrease the buffer length
|
||||||
|
// Set endBody to true if the last boundary was found
|
||||||
// Return the length of data before the found boundary
|
// Return the length of data before the found boundary
|
||||||
int findBoundary(const char*& buf, int& len,
|
int findBoundary(const char*& buf, int& len,
|
||||||
const char* boundary, unsigned int bLen);
|
const char* boundary, unsigned int bLen, bool& endBody);
|
||||||
// Build a boundary string to be used when parsing or building body
|
// Build a boundary string to be used when parsing or building body
|
||||||
// Remove quotes if present. Remove trailing blanks
|
// Remove quotes if present. Remove trailing blanks
|
||||||
// Insert CRLF and boundary marks ('--') before parameter
|
// Insert CRLF and boundary marks ('--') before parameter
|
||||||
|
|
Loading…
Reference in New Issue