//-----------------------------------------------------------------------
      ISDPTypes::SDPPtr SDPParser::parse(const char *blob)
      {
        if (!blob) return SDPPtr();

        SDPPtr sdp(make_shared<SDP>());

        sdp->mOriginal = String(blob);
        std::unique_ptr<char[]> rawBuffer(new char[sdp->mOriginal.length()+1]);
        sdp->mRawBuffer = std::move(rawBuffer);

        memset(sdp->mRawBuffer.get(), 0, sizeof(char)*(sdp->mOriginal.length()+1));
        memcpy(sdp->mRawBuffer.get(), blob, sizeof(char)*(sdp->mOriginal.length()));

        try {
          parseLines(*sdp);
          parseAttributes(*sdp);
          validateAttributeLevels(*sdp);
          parseLinesDetails(*sdp);
          processFlagAttributes(*sdp);
          processSessionLevelValues(*sdp);
          processMediaLevelValues(*sdp);
          processSourceLevelValues(*sdp);
        } catch (const SafeIntException &e) {
          ORTC_THROW_INVALID_PARAMETERS("value found out of legal value range" + string(e.m_code));
        }

        return sdp;
      }
Ejemplo n.º 2
0
char *DOMString::transcode(MemoryManager* const manager) const
{
    if (!fHandle || fHandle->fLength == 0)
    {
        char* retP = (char*) manager->allocate(sizeof(char));//new char[1];
        *retP = 0;
        return retP;
    }

    // We've got some data
    const XMLCh* srcP = rawBuffer();

    //
    //  Find out how many output chars we need and allocate a buffer big enough
    //  for that plus a null.
    //
    //  The charsNeeded normally is same as fHandle->fLength.  To enhance performance,
    //  we start with this estimate, and if overflow, then call calcRequiredSize for actual size
    unsigned int charsNeeded = fHandle->fLength;
    char* retP = (char*) manager->allocate((charsNeeded + 1) * sizeof(char));//new char[charsNeeded + 1];

    if (!getDomConverter()->transcode(srcP, retP, charsNeeded) || (XMLString::stringLen(retP) != charsNeeded))
    {
        manager->deallocate(retP);//delete [] retP;
        charsNeeded = getDomConverter()->calcRequiredSize(srcP);
        retP = (char*) manager->allocate((charsNeeded + 1) * sizeof(char));//new char[charsNeeded + 1];
        if (!getDomConverter()->transcode(srcP, retP, charsNeeded))
        {
            // <TBD> We should throw something here?
        }
    }

    // Cap it off and return it
    retP[charsNeeded] = 0;
    return retP;
}