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

📄 sdp2session.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 3 页
字号:
                    while ((linecount != lines.end()) && ((*linecount)[0] == 'r'))                    {                        timeDescriptionLines.push_back ((*linecount));                        ++linecount;                    }                    try                    {                        SdpTime time (timeDescriptionLines);                        sdpTimeList.push_back (time);                    }                    catch (SdpExceptions& exp)                    {                        if (exp.value == FAILED)                        {                            return false;                        }                    }                }                if (linecount != lines.end())                {                    // adjust line position for the next description                    --linecount;                }            }	    else if((*linecount)[0] == 'z')	    {		cpLog(LOG_DEBUG, "Session: got the \"z=\" line");                s = (*linecount);		s.parse("=");//		s = (*linecount);//		s.erase(0,2);//                chomp (&s);                vector<Data> adjustmentList;		bool finished = false;		while(!finished)		{		    Data item = s.parse(" ", &finished);		    if(finished)		    {			item = s;		    }		    adjustmentList.push_back(item);		}		vector<Data>::iterator iter = adjustmentList.begin();		while(iter != adjustmentList.end())		{                    SdpZoneAdjustment sza;                    sza.setAdjustmentTime(*iter);                    ++iter;                    if (iter != adjustmentList.end())                    {			sza.setOffset((*iter));                        zoneAdjustmentList.push_back(sza);                        ++iter;                    }                    else    // <adjustment time> didn't followed by an <offset>                    {			sza.setOffset("0");                        zoneAdjustmentList.push_back(sza);                        break;                    }                }	    }            else if ((*linecount)[0] == 'b')            {                cpLog(LOG_DEBUG_STACK, "Session: got the \"b=\" line");                s = (*linecount);		s.parse("=");//                s = (*linecount);//                s.erase(0, 2);//                chomp (&s);                //create the bandwidth object, and store details there.                try                {                    if (!bandwidth)                    {                        bandwidth = new SdpBandwidth(s);                        assert (bandwidth);                    }                    else                    {                        SdpBandwidth bw (s);                        (*bandwidth) = bw;                    }                }                catch (SdpExceptions& )                {                    //bandwidth is optional. So do nothing if incorrect.                }            }	    else if((*linecount)[0] == 'k')	    {		cpLog(LOG_DEBUG, "Session: got the \"k=\" line: %s", 						(*linecount).logData());                s = (*linecount);		s.parse("=");//                chomp (&s);		//create the encrypttion key object, and store details there.		try		{		    if (!encryptkey)		    {			encryptkey = new SdpEncryptkey(s);			assert (encryptkey);		    }                    else                    {                        SdpEncryptkey key(s);                        (*encryptkey) = key;                    }		}		catch (SdpExceptions& )		{		    //Encryption key is optional. So do nothing if incorrect.		}            }            else if ((*linecount)[0] == 'a')            {                //this is the attribute line.                cpLog(LOG_DEBUG_STACK, "Session: got the a=line");                s = (*linecount);		s.parse("=");//                s.erase(0, 2);//                chomp (&s);                //create the attribute object, if not previously created.                if (!attribute)                {                    cpLog(LOG_DEBUG_STACK, "create a session attribute.");                    attribute = new SdpAttributes();                    assert(attribute);                }                try                {                    attribute->setAttribute(s);                }                catch (SdpExceptions& )                {                    //attribute is optional. So do nothing if incorrect.                }            }            else if ((*linecount)[0] == 'm')            {                Data tempstr;                //get all m lines until end of SDP msg.                while (linecount != lines.end())                {		    list<Data> mediaDetails;                    cpLog(LOG_DEBUG_STACK, "Session:got the m= line");                    cpLog(LOG_DEBUG_STACK, "Session: %s", (*linecount).logData());                                        if((*linecount)[0] == 'm')                    {                        (mediaDetails).push_back( (*linecount));  // subData copy.                    }                    ++linecount;                    while ( (linecount != lines.end() ) && 			    ((*linecount)[0] != 'm'))                    {                        cpLog(LOG_DEBUG_STACK, "%s", (*linecount).logData());                        (mediaDetails).push_back( (*linecount));                        ++linecount;                    }                    try                    {                        SdpMedia* mediaItm = new SdpMedia(mediaDetails);                        ostrstream ostr;                        mediaItm->encode(ostr);                        assert(mediaItm);                        addMedia(mediaItm);                    }                    catch (SdpExceptions& exp)                    {                        if (exp.value == FAILED)                            return false;                    }                } // end of processing of one m line            }// end of processing all m lines            else            {                cpLog(LOG_DEBUG, "got unknown line") ;                cpLog(LOG_DEBUG, "line: %s", (*linecount).logData());            }            // We might have reached the end in processing m field.            // In that case, we don't increment linecount            if ( linecount != lines.end() )            {                ++linecount;            }        }    }    isValid = true;    return true;}///voidSdpSession::flushMediaList(){    if (mediaList.empty())    {        return ;    }    list < SdpMedia* > ::iterator iter = mediaList.begin();    while (iter != mediaList.end())    {        if (*iter)        {            delete (*iter);        }        ++iter;    }    mediaList.clear();}    // SdpSession::flushMediaList///voidSdpSession::reset(){    protocolType = SdpProtocolTypeSDP;    protocolVersion = 0;    username = "-";    //TODO Use NTP time    sessionId = static_cast < unsigned int > (time(NULL));    //TODO Use NTP time    version = static_cast < unsigned int > (time(NULL));    networkType = NetworkTypeInternet;    addressType = AddressTypeIPV4;    address = "0.0.0.0";    sessionName = "-";    if ( 0 != connection )    {	delete connection;	connection = 0;    }    if ( 0 != attribute )    {	delete attribute;	attribute = 0;    }    if ( 0 != bandwidth )    {	delete bandwidth;	bandwidth = 0;    }    if ( 0 != encryptkey )    {	delete encryptkey;	encryptkey = 0;    }    SdpTime time;    sdpTimeList.clear();    sdpTimeList.push_back (time);    isValid = false;    flushMediaList();    // Take care of some of the new components added.    zoneAdjustmentList.clear();    phoneList.clear();    emailList.clear();    uriInfo = "";    sessionInfo = "";}    // SdpSession::SdpSession///boolSdpSession::conformToSdp (){    bool rc = true;    if (protocolVersion != 0)    {        cpLog (LOG_WARNING, "SdpSession::conformToSdp - protocol version %d",               protocolVersion);        rc = false;    }    if (networkType == NetworkTypeUnknown)    {        cpLog (LOG_WARNING, "SdpSession::conformToSdp - unknown network type");        rc = false;    }    if (addressType == AddressTypeUnknown)    {        cpLog (LOG_WARNING, "SdpSession::conformToSdp - unknown address type");        rc = false;    }    if (sdpTimeList.empty())    {        cpLog (LOG_WARNING, "SdpSession::conformToSdp - no time description");        rc = false;    }    else    {        cpLog (LOG_DEBUG_STACK, "SdpSession::conformToSdp - PASSED");    }    return rc;}    // SdpSession::conformToSdp///boolSdpSession::conformToNcs (){    bool rc = true;    if (protocolVersion != 0)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - protocol version %d",               protocolVersion);        rc = false;    }    if (username != "-")    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - username %s",               username.logData());        rc = false;    }    if (networkType != NetworkTypeInternet)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - network type %s",               networkTypeString().logData());        rc = false;    }    if (addressType != AddressTypeIPV4)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - address type %s",               addressTypeString().logData());        rc = false;    }    if (sessionName != "-")    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - sessionName %s",               sessionName.logData());        rc = false;    }    // No "i="    // No "u="    // No "e="    // No "p="    if (connection == 0)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - no connection");        rc = false;    }    else if (connection->getNetworkType() != NetworkTypeInternet)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - network type %d",               connection->getNetworkType());        rc = false;    }    else if (connection->getAddressType() != AddressTypeIPV4)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - address type %d",               connection->getAddressType());        rc = false;    }    else if (connection->getMulticast() != 0)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - not unicast");        rc = false;    }    if (bandwidth == 0)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - no bandwidth");        rc = false;    }    else if (bandwidth->getModifier() != BandwidthModifierTypeAS)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - bandwidth modifier %d",               bandwidth->getModifier());        rc = false;    }    if (sdpTimeList.empty())    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - no time description");        rc = false;    }    //TODO more time checking of stopTime == 0, no Repeat, no Time Zones    // No "k="    //TODO attribute("a=") lines like a=ptime:<value>    if (mediaList.empty())    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - no media");        rc = false;    }    else if ((*mediaList.begin())->getMediaType() != MediaTypeAudio)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - not audio media");        rc = false;    }    else if ((*mediaList.begin())->getTransportType() != TransportTypeRTP)    {        cpLog (LOG_WARNING, "SdpSession::conformToNcs - not RTP/AVP");        rc = false;    }    else    {        cpLog (LOG_DEBUG_STACK, "SdpSession::conformToNcs - PASSED");    }    return rc;}    // SdpSession::conformToNcs/// Verify if this a well formed SDP according to protocolboolSdpSession::verify (SdpProtocolType protocol /*Default Argument*/){    bool rc = true;    if (protocol == SdpProtocolTypeSDP)    {        rc = conformToSdp ();    }    else if (protocol == SdpProtocolTypeNCS)    {        rc = conformToNcs ();    }    //TODO verify other protocol types    if (!rc)    {        cpLog (LOG_WARNING, "SdpSession::verify - FAILED");    }    return rc;}    // SdpSession::verify///voidSdpSession::setHold (){    if (connection)    {        connection->setHold();    }    else    {        // TODO should we do something here        cpLog (LOG_ERR, "SdpSession::setHold: Session connection doesn't exist");    }    return ;}///boolSdpSession::isHold (){    if (connection)    {        return connection->isHold();    }    else    {        // TODO should we do something here        cpLog (LOG_ERR, "SdpSession::isHold: Session connection doesn't exist");        return false;    }}/* 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 + -