⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipcontentdatacontainer.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0  *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted providd that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", *    and "Vovida Open Communication Application Library (VOCAL)" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor *    may "VOCAL" appear in their name, without prior written *    permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const SipContentDataContainer_cxx_version =    "$Id: SipContentDataContainer.cxx,v 1.27.2.1 2003/01/21 02:36:11 sprajpat Exp $";#include "global.h"#include "SipContentDataContainer.hxx"#include "SipOsp.hxx"#include "SipIsup.hxx"#include "SipSdp.hxx"#include "SipHeader.hxx"#include "SipUnknownContentData.hxx"#include "SipContentData.hxx"using namespace Vocal;SipContentDataContainer::SipContentDataContainer()        : contentType(new SipContentType),	  contentLength(new SipContentLength),	  contentDisposition(new SipContentDisposition),	  mimeDataList(),	  mimeData(),	  isParsed(false),	  actualBoundary(){    assert(mimeDataList.begin() == mimeDataList.end());}SipContentDataContainer::~SipContentDataContainer(){}SipContentDataContainer::SipContentDataContainer( const SipContentDataContainer& rhs ){    copyRhs2This( rhs );}SipContentDataContainer&SipContentDataContainer::operator=( const SipContentDataContainer& rhs ){    if ( &rhs != this )    {        copyRhs2This( rhs );    }    return *this;}voidSipContentDataContainer::copyRhs2This( const SipContentDataContainer& rhs ){    if( rhs.contentType != 0 )    {        contentType = new SipContentType( *rhs.contentType );    }    if( rhs.contentLength != 0 )    {        contentLength = new SipContentLength( *rhs.contentLength );    }    if( rhs.contentDisposition != 0 )    {        contentDisposition = new SipContentDisposition( *rhs.contentDisposition );    }    cpLog( LOG_DEBUG_STACK, "rhs mimeDataList size is %d",                            rhs.mimeDataList.size() );    mimeDataList.clear();    for( vector< Sptr <SipContentData> >::const_iterator i = rhs.mimeDataList.begin();         i != rhs.mimeDataList.end();         ++i )    {        //TODO?: assert( *i != 0 ); and remove else part        if( 0 != i->getPtr() )        {            mimeDataList.push_back( (*i)->duplicate() );        }        else        {            cpLog( LOG_ERR, "Null entry in mimeDataList" );            // mimeDataList.push_back( 0 );        }    }    mimeData = rhs.mimeData;    isParsed = rhs.isParsed;    actualBoundary = rhs.actualBoundary;}voidSipContentDataContainer::encode(Data* data) const{        Data tempData;        if ( (isParsed) || (mimeDataList.size() > 0) )    {	Data parsedData;	// call encode of SipContentData list	vector< Sptr <SipContentData> >::const_iterator iter;     	int len = 0;    	int numOfContentData = mimeDataList.size();	if (numOfContentData > 1)	{	    iter = mimeDataList.begin(); 	    int singleMimeLen;    	    while (iter != mimeDataList.end())	    {		singleMimeLen = 0;    		if  ((*iter) != 0)		{		    //add the boundary.		    parsedData+= "--";                    parsedData+= actualBoundary;		    parsedData+= CRLF;		    //this is a SipContentData item. call encode functions of SipContentData.		    parsedData+= (*iter)->encodeHeaders();		    parsedData+= CRLF;		    parsedData+= (*iter)->encodeBody(singleMimeLen);    		    len+= singleMimeLen;		    		}		++iter;                                            	    }	    if (mimeDataList.size() > 1)	    {		//end with the boundary.				parsedData+= "--";		parsedData+= actualBoundary;		parsedData+= CRLF;	    }	}	else	{	    if(!mimeDataList.empty() && (mimeDataList[0] != 0))	    {		parsedData+= mimeDataList[0]->encodeBody(len);	    }	}	tempData = parsedData;	assert(contentLength != 0);	//this needs to be called by the SipMsg, while encoding content length.	contentLength->setLength(len);     }    else    {	tempData = mimeData;    }    if (tempData.length())    {	//there is mime defined here.	(*data) += CRLF;	(*data) += tempData;    }    else    {	(*data) += CRLF;    }}       voidSipContentDataContainer::decode(const Data& data, 				Sptr <SipContentLength> contLength, 				Sptr <SipContentType> contType, 				Sptr <SipContentDisposition> contDisp){    contentLength = contLength;    contentType = contType;    contentDisposition = contDisp;        //maintain string here.    mimeData = data;}        boolSipContentDataContainer::parse() {    bool success = false;    //construct the SipContentData objects here.    // xxx fixme    if (contentType != 0)    {        // this is a multipart MIME (RFC 2046)	if(contentType->getType() == "multipart") 	{	    //this is a multi-MIME.	    Data boundary = contentType->getAttributeValue("boundary");	    if (boundary.length())	    {		actualBoundary = "--";		actualBoundary += boundary;		success = parseMultiMime(actualBoundary);	    }	}	else	{	    success = parseSingleMime(mimeData,                                       contentLength,                                       contentType,                                       contentDisposition);	}    }    if(!success)    {	cpLog(LOG_DEBUG, "failed to parse MIME data when asked to");    }    isParsed = true;        return success;}        boolSipContentDataContainer::parseSingleMime(Data singleMimeData, 					 Sptr<SipContentLength> len, 					 Sptr<SipContentType> type, 					 Sptr<SipContentDisposition> disp){    cpLog( LOG_DEBUG_STACK, "parseSingleMime %s", singleMimeData.logData() );    Data subType;    //get contentType. Defaults to text/plain.    if (type != 0)    {	subType = type->getSubType();    }    else    {	subType = "plain";    }    Sptr <SipContentData> contentData;        //parse singleMimeData, and add into ContentData object.    if ( isEqualNoCase(subType, "SDP") )    {	contentData  = new SipSdp(singleMimeData);    }    else if (isEqualNoCase(subType, "ISUP") )    {	//this is ISUP	contentData = new SipIsup(singleMimeData);    }    else if (isEqualNoCase(subType, "OSP") )    {	//this is OSP token	contentData = new SipOsp(singleMimeData);    }    else if (singleMimeData.length() > 0) // if length is 0, ignore    {        contentData = new SipUnknownContentData(singleMimeData);    }    if(contentData != 0)    {	if (len != 0)	{	    contentData->setContentLength(len);	}	if (type != 0)	{	    contentData->setContentType(type);	}	if (disp != 0)	{	    contentData->setContentDisposition(disp);	}	//set this into the map.	mimeDataList.push_back(contentData);    }    else    {	// xxx this is not an error if there is a null-bodied object	// passed here ?    }        return true;  //need to find out error condition here.}        boolSipContentDataContainer::parseMultiMime(Data boundary){    bool success = true;        bool matchFail = true;    Data mimeBoundary = mimeData.getLine(&matchFail);    if ( (mimeBoundary.operator!=(boundary)) || ( matchFail ) )    {	success = false;	return success;    }    else  //continue    {	while (mimeData.length())        {	    //get the string between this and the next boundary line.	    Data singleMimeData;            	    //form the line that we need to search for.	    Data boundaryLine = boundary;	    boundaryLine+= CRLF;            LocalScopeAllocator lo; 	    int found = mimeData.match(boundaryLine.getData(lo), &singleMimeData, true);    	    if ( (found == NOT_FOUND) || (found == FIRST) )	    {                // this is the epilogue boundary, which is mandatory		success = false; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -