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

📄 sipcontentdatacontainer.cxx

📁 Vovida 社区开源的 SIP 协议源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
		break;  //break out of while loop.	    }	    // else continue	    {	        //get headers if any in the MIME section		bool matchFailHeaders = true;    		Data nextLine = singleMimeData.getLine(&matchFailHeaders);    		Sptr <SipContentType> singleMimeContentType;		Sptr <SipContentLength> singleMimeContentLength;		Sptr <SipContentDisposition> singleMimeContentDisposition;		bool dummyFlag;    		while  ( (nextLine.length()) && (!matchFailHeaders) )		{		    		    Data headerValue = nextLine;		    // decode this line of the message		    Data headerName = headerValue.parse(": \t", &dummyFlag);		    //we dont check for match failing, since these fields are not mandatory here.		    headerName.lowercase();		    		    SipHeaderType  headerType = headerTypeDecode(headerName);		    switch(headerType)		    {			case SIP_CONTENT_TYPE_HDR:			{			    singleMimeContentType                                 = new SipContentType(headerValue);			}			break;			case SIP_CONTENT_LENGTH_HDR:			{			    singleMimeContentLength                                 = new SipContentLength(headerValue);			}			break;			case SIP_CONTENT_DISPOSITION_HDR:			{			    singleMimeContentDisposition                                 = new SipContentDisposition(headerValue);			}			break;			default:			{			}			break;		    } //end switch		    //get the next line.                    nextLine = singleMimeData.getLine(&matchFailHeaders);		} //end while headers found		//CRLF found now.		//the remaining is content data.		success                     = success && parseSingleMime(singleMimeData,                                                  singleMimeContentLength,                                                  singleMimeContentType,                                                  singleMimeContentDisposition);	    }//else	}// while mimeData.length()	//parse based on boundary,        //if you get contentlength, type, or disposition,        //set in SipCOntentData.    }//else found boundary.    return success;}   intSipContentDataContainer::getNumContentData() {    if (!isParsed)    {        //parse here	parse();    }    return static_cast<int>(mimeDataList.size());}voidSipContentDataContainer::setNumContentData(int index){    // precondition    assert(index >= 0);    if (!isParsed)    {        parse();    }    while(index < static_cast<int>(mimeDataList.size()) )    {        // reduce the number by trimming from the end        mimeDataList.pop_back();    }    // postcondition    assert(index >= static_cast<int>(mimeDataList.size()) );}Sptr <SipContentData>SipContentDataContainer::getContentData(int index){    if (!isParsed)    {        //parse here	parse();    }        //return from list    if (index >=  static_cast<int>(mimeDataList.size() ) ||         (mimeDataList.size() == 0))    {	return 0;    }    else if (index < 0)    {	return mimeDataList[mimeDataList.size()-1];    }    else    {	return mimeDataList[index];    }}    // xxx there are two known bugs in this function:// 1.  from an API perspective, this should have more consistent// behavior if you pass an index that's out of range.  Either //     (a) you need to know what the range is, and you should assert//     if you try to set something out of range//     (b) you can use a big index, and it will either expand w/ null//     items or append// either is better than the current behavior (silently fail, unless// the index is 0, in which case insert).// 2.  the boundaries are not uniquely generated.  they need to be to// work correctly.voidSipContentDataContainer::setContentData(Sptr<SipContentData> contData, 					int index){    assert( contData != 0 );    cpLog( LOG_DEBUG_STACK, "setContentData %d: %s",                            index,                            contData->encodeHeaders().logData() );    int bodyLength;    cpLog( LOG_DEBUG_STACK, "\n%s",                            contData->encodeBody(bodyLength).logData() );    cpLog( LOG_DEBUG_STACK, "mimeDataList size before parse is %d", mimeDataList.size() );    //if the existing mimeData is not parsed yet, parse now.    if  (!isParsed)    {	parse();    }    //set at index.    int size = mimeDataList.size();        cpLog( LOG_DEBUG_STACK, "mimeDataList size after parse is %d", size );    if ( (index >= -1) && (index <= size) )    {        if (index == -1)        {            mimeDataList.push_back(contData);        }        else if ( index <= size )        {            vector< Sptr <SipContentData> >::iterator iter;	                iter = mimeDataList.begin();	                iter+=index;            //insert it at index.            mimeDataList.insert(iter, contData);      	}    }    if ( (mimeDataList.size() == 2) && ( !actualBoundary.length()) ) //more than one item in mime list    {	//give a boundary if none exists before.	actualBoundary = "unique-boundary-1"; // xxx need to generate this some how.    }}        voidSipContentDataContainer::removeContentData(int index){    if (!isParsed)    {	parse();    }    if (index == -1)    {	mimeDataList.pop_back();    }    else if ( index <= static_cast<int>(mimeDataList.size())  && (index > -1) )    {	vector<Sptr <SipContentData> >::iterator iter;         iter = mimeDataList.begin();        iter+=index;        if(iter != mimeDataList.end())        {            mimeDataList.erase(iter);        }    }    if (mimeDataList.size() == 0)    {          	mimeDataList.clear();    }    if (mimeDataList.size() ==1)    {	//set boundary to ""	actualBoundary = "";    }}             Sptr <SipContentType>SipContentDataContainer::getContentType(){    if (isParsed)    {        if(actualBoundary.length())        {            contentType->setTokenDetails("boundary", actualBoundary);        }    	if ( (actualBoundary.length()) && 	     (contentType->getType() != "multipart"))	{	    //set the content type.	    contentType->setType("multipart");	    contentType->setSubType("mixed");	   	}#if 0	else if ( (!actualBoundary.length()) &&		  (contentType->getType() != "multipart"))#endif	else if ( (!actualBoundary.length()) )	{	    //get the type of object.            if(mimeDataList.empty())            {                // there is nothing here -- so there is no contenttype                contentType->setType("");                contentType->setSubType("");            }            else            {                contentType->setType(mimeDataList[0]->getContentType()->getType());                contentType->setSubType(mimeDataList[0]->getContentType()->getSubType());            }            contentType->clearToken("boundary");	}    }    return contentType;}    void SipContentDataContainer::setContentType(Sptr <SipContentType> content){    contentType = content;}    Sptr <SipContentLength> SipContentDataContainer::getContentLength(){    return contentLength;}    void SipContentDataContainer::setContentLength(Sptr <SipContentLength>  content){    contentLength = content;}    void SipContentDataContainer::setContentDisposition(Sptr <SipContentDisposition> disp){    contentDisposition = disp;}        Sptr <SipContentDisposition> SipContentDataContainer::getContentDisposition(){    return contentDisposition;}    boolSipContentDataContainer::operator ==(const SipContentDataContainer& src){    if (  (!src.isParsed) && (!isParsed) )    {	return (src.mimeData == mimeData);    }    else if ( ( src.isParsed ) && (!isParsed) )    {	//encode src	Data srcEncodedBody;	src.encode(&srcEncodedBody);    	//should we maintain a flag again, to say that the mimeData is 	//here	return (srcEncodedBody == mimeData);    }    else if ( (!src.isParsed) && (isParsed) )    {	//encode this.	Data thisEncodedBody;	encode(&thisEncodedBody);    	return (src.mimeData == thisEncodedBody);    }    else //both are parsed, run through list and compare.    {        SipContentDataContainer cData(src);	int srcContentDatasize = cData.getNumContentData(); 	if ( srcContentDatasize != getNumContentData())	{	    return false;	}	else	{	    //encode both and compare.	    //optionally, we could also go over each in the list and	    //call the == operator on that.    	    //encode this.	    Data thisEncodedBody;	    encode(&thisEncodedBody);    	    //encode src	    Data srcEncodedBody;	    src.encode(&srcEncodedBody);    	    return (thisEncodedBody == srcEncodedBody);	}    }         }void SipContentDataContainer::forceParse(){    parse();}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */

⌨️ 快捷键说明

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