MT#59962 AmMimeBody: add Content-Length parsing

Add parsing of Content-Length, for cases
were this length matters (e.g. ct length > 0,
but suddenly there is no SDP body).

Also add a getter for the AmContentType's length.

Change-Id: I92cdd19319c6f4a4edcfbaeec7bad1be12c8a0b1
mr13.5
Donat Zenichev 11 months ago
parent 1bf5c7e60b
commit f9ea22fcc7

@ -437,7 +437,6 @@ int SBCCallLeg::relayEvent(AmEvent* ev)
ILOG_DLG(L_DBG, "filtering body for request '%s' (c/t '%s')\n",
req_ev->req.method.c_str(), req_ev->req.body.getCTStr().c_str());
// todo: handle filtering errors
int res = filterSdp(req_ev->req.body, req_ev->req.method);
if (res < 0) {
delete ev; // failed relayEvent should destroy the event

@ -58,14 +58,15 @@ const AmMimeBody& AmMimeBody::operator = (const AmMimeBody& r_body)
}
AmContentType::AmContentType()
: mp_boundary(NULL)
: mp_boundary(NULL), length(-1)
{
}
AmContentType::AmContentType(const AmContentType& ct)
: type(ct.type),
subtype(ct.subtype),
mp_boundary(NULL)
mp_boundary(NULL),
length(ct.length)
{
for(Params::const_iterator it = ct.params.begin();
it != ct.params.end(); ++it) {
@ -277,6 +278,16 @@ int AmContentType::parse(const string& ct)
return 0;
}
int AmContentType::parse(const string& ct, unsigned int _length)
{
if (!length) {
DBG("Cannot parse Content-Type of zero-length body\n");
return -1;
}
length = _length;
return parse(ct);
}
int AmContentType::parseParams(const char* c, const char* end)
{
list<sip_avp*> avp_params;
@ -568,7 +579,7 @@ int AmMimeBody::parse(const string& content_type,
const char* buf,
unsigned int len)
{
if(ct.parse(content_type) < 0)
if(ct.parse(content_type, len) < 0)
return -1;
if(ct.isType(MULTIPART)) {
@ -587,6 +598,7 @@ int AmMimeBody::parse(const string& content_type,
void AmMimeBody::convertToMultipart()
{
AmContentType n_ct;
/* TODO: should we somehow predict the length of multipart body? */
n_ct.parse(MULTIPART_MIXED); // never fails
n_ct.resetBoundary();
@ -652,7 +664,11 @@ AmMimeBody* AmMimeBody::addPart(const string& content_type)
AmMimeBody* body = NULL;
if(ct.type.empty() && ct.subtype.empty()) {
// fill *this* body
if(ct.parse(content_type)) {
string sdp_body;
body->print(sdp_body);
unsigned int len = sdp_body.length(); /* the number of bytes represented by SDP body as a string */
if(ct.parse(content_type, len)) {
DBG("could not parse content-type\n");
return NULL;
}
@ -663,6 +679,7 @@ AmMimeBody* AmMimeBody::addPart(const string& content_type)
// convert to multipart
convertToMultipart();
body = new AmMimeBody();
/* TODO: should we somehow predict multipart body's length? */
if(body->ct.parse(content_type)) {
DBG("parsing new content-type failed\n");
delete body;

@ -39,13 +39,18 @@ struct AmContentType
Params params;
Param* mp_boundary;
int length; /* -1 is unparsed; >= 0 is valid value; */
AmContentType();
AmContentType(const AmContentType& ct);
~AmContentType();
const AmContentType& operator = (const AmContentType& r_ct);
/* parse content-type */
int parse(const string& ct);
/* parse content-type with length */
int parse(const string& ct, unsigned int _length);
int parseParams(const char* c, const char* end);
void setType(const string& t);
@ -138,6 +143,8 @@ public:
/** Get content-type with parameters */
string getCTHdr() const { return ct.getHdr(); }
int getCTLength() const { return ct.length; }
/** @return the list of sub-parts */
const Parts& getParts() const { return parts; }

Loading…
Cancel
Save