diff --git a/apps/sbc/SBCCallLeg.cpp b/apps/sbc/SBCCallLeg.cpp index 6f90e4e7..e1a09a28 100644 --- a/apps/sbc/SBCCallLeg.cpp +++ b/apps/sbc/SBCCallLeg.cpp @@ -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 diff --git a/core/AmMimeBody.cpp b/core/AmMimeBody.cpp index 65c456a0..b66cd107 100644 --- a/core/AmMimeBody.cpp +++ b/core/AmMimeBody.cpp @@ -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 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; diff --git a/core/AmMimeBody.h b/core/AmMimeBody.h index 26c9a41a..cb814875 100644 --- a/core/AmMimeBody.h +++ b/core/AmMimeBody.h @@ -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; }