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

📄 rtspbase.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include "hxcom.h"
#include "hxtypes.h"
#include "hxstring.h"
#include "hxslist.h"
#include "hxengin.h"
#include "ihxpckts.h"
#include "chxpckts.h"
#include "safestring.h"
//#include "rtmlpars.h"
#include "mimehead.h"
#include "mimescan.h"
#include "timerep.h"
#include "rtspmsg.h"
#include "rtsppars.h"
#include "rtspmdsc.h"
#include "basepkt.h"
#include "servrsnd.h"
#include "rtspbase.h"
#include "dbcs.h" // for HXIsEqual

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE		
static const char HX_THIS_FILE[] = __FILE__;
#endif

// XXXHP: NEED TO MODIFY THE SAME STRUCTURE AT DLLMAIN.CPP!!!
struct RTSPError
{
    const char* pErrNo;
    const char* pErrMsg;
};

//
// XXXBAB - turn this into a dictionary
//
// XXXHP: NEED TO REGENERATE ON WIN16 EVERYTIME THIS ARRAY
//	  IS MODIFIED!!!
#ifdef _WIN16
extern RTSPError* RTSPErrorTable;
#else
static const RTSPError RTSPErrorTable[] =
{
    { "100", "Continue" },

    { "200", "OK" },
    { "201", "Created" },
    { "250", "Low On Storage Space" },

    { "300", "Multiple Choices" },
    { "301", "Moved Permanently" },
    { "302", "Moved Temporarily" },
    { "303", "See Other" },
    { "304", "Not Modified" },
    { "305", "Use Proxy" },

    { "400", "Bad Request" },
    { "401", "Unauthorized" },
    { "402", "Payment Required" },
    { "403", "Forbidden" },
    { "404", "Not Found" },
    { "405", "Method Not Allowed" },
    { "406", "Not Acceptable" },
    { "407", "Proxy Authentication Required" },
    { "408", "Request Time-out" },
    { "409", "Conflict" },
    { "410", "Gone" },
    { "411", "Length Required" },
    { "412", "Precondition Failed" },
    { "413", "Request Entity Too Large" },
    { "414", "Request-URI Too Large" },
    { "415", "Unsupported Media Type" },
    { "451", "Parameter Not Understood" },
    { "452", "Conference Not Found" },
    { "453", "Not Enough Bandwidth" },
    { "454", "Session Not Found" },
    { "455", "Method Not Valid In This State" },
    { "456", "Header Field Not Valid For Resource" },
    { "457", "Invalid Range" },
    { "458", "Parameter Is Read-Only" },
    { "459", "Aggregate Operation Not Allowed" },
    { "460", "Only Aggregate Operation Allowed" },
    { "461", "Unsupported Transport" },
    { "462", "Destination Unreachable" },
    { "500", "Internal Server Error" },
    { "501", "Not Implemented" },
    { "502", "Bad Gateway" },
    { "503", "Service Unavailable" },
    { "504", "Gateway Time-out" },
    { "505", "RTSP Version not supported" },
    { "551", "Option not supported" }
};
#endif

const RTSPRequireOptions RTSPBaseProtocol::RTSPRequireOptionsTable
    [RTSPBaseProtocol::m_NumRTSPRequireOptions] =
    {
        {"com.real.retain-entity-for-setup", "DESCRIBE", 8},
        {"com.real.load-test-password-enabled", "OPTIONS", 7}
    };

const RTSPAcceptEncodingOptions RTSPBaseProtocol::RTSPAcceptEncodingOptionsTable
    [RTSPBaseProtocol::m_NumRTSPAcceptEncodingOptions] =
    {
        {"mei", "DESCRIBE", 8},
        {"mei", "SETUP", 5}
    };

/*
 * RTSPBaseProtocol methods
 */

RTSPBaseProtocol::RTSPBaseProtocol():
    m_pContext(NULL),
    m_pCommonClassFactory(NULL),
    m_pSocket(0),
    m_pFastSocket(0),
    m_uControlBytesSent(0),
    m_pControlBuffer(0)
{
}

RTSPBaseProtocol::~RTSPBaseProtocol()
{
    clearMessages();

    HX_RELEASE(m_pControlBuffer);
    HX_RELEASE(m_pCommonClassFactory);
    HX_RELEASE(m_pContext);
}

HX_RESULT
RTSPBaseProtocol::enqueueMessage(RTSPMessage* pMsg)
{
    m_msgQueue.AddTail(pMsg);
    return HXR_OK;
}

RTSPMessage*
RTSPBaseProtocol::dequeueMessage(UINT32 seqNo)
{
    LISTPOSITION pos = m_msgQueue.GetHeadPosition();
    while(pos)
    {
        RTSPMessage* pMsg = (RTSPMessage*)m_msgQueue.GetAt(pos);
        if(pMsg->seqNo() == seqNo)
        {
            (void)m_msgQueue.RemoveAt(pos);
            return pMsg;
        }
        (void)m_msgQueue.GetNext(pos);
    }
    return 0;
}

void
RTSPBaseProtocol::clearMessages()
{
    LISTPOSITION pos = m_msgQueue.GetHeadPosition();
    while(pos)
    {
        RTSPMessage* pMsg = (RTSPMessage*)m_msgQueue.GetNext(pos);
        delete pMsg;
    }
}

const char*
RTSPBaseProtocol::getErrorText(const char* pErrNo)
{
    int tabSize = sizeof(RTSPErrorTable) / sizeof(RTSPErrorTable[0]);
    for (int i = 0; i < tabSize; ++i)
    {
        if (strcmp(pErrNo, RTSPErrorTable[i].pErrNo) == 0)
        {
            return RTSPErrorTable[i].pErrMsg;
        }
    }
    return "";
}

HX_RESULT
RTSPBaseProtocol::sendRequest(RTSPRequestMessage* pMsg,
    const char* pContent, const char* pMimeType, UINT32 seqNo)
{
    if(pContent)
    {
        char tmpBuf[32];
        pMsg->addHeader("Content-type", pMimeType);
        SafeSprintf(tmpBuf, 32,"%d", strlen(pContent)); 
        pMsg->addHeader("Content-length", tmpBuf);
        pMsg->setContent(pContent);
    }
    return sendRequest(pMsg, seqNo);
}

HX_RESULT
RTSPBaseProtocol::sendRequest(RTSPRequestMessage* pMsg, UINT32 seqNo)
{
    // set sequence number
    char seqBuf[32]; 
    SafeSprintf(seqBuf, 32, "%ld", seqNo); 
    pMsg->addHeader("CSeq", seqBuf, TRUE);	// add to head of list
    pMsg->setSeqNo(seqNo);
    enqueueMessage(pMsg);
    CHXString msgStr = pMsg->asString();

    CHXBuffer* pBuffer = new CHXBuffer;
    pBuffer->AddRef();
    pBuffer->Set((BYTE*)(const char*)msgStr, msgStr.GetLength());
    HX_RESULT rc = sendControlMessage(pBuffer);
    handleSendEvent(pMsg);
    pBuffer->Release();
    return HXR_OK;
}

void
RTSPBaseProtocol::handleDebug(IHXBuffer* pMsgBuf, BOOL bInbound)
{
    // Only implemented by subclasses in server modules
}

void
RTSPBaseProtocol::handleTiming(IHXBuffer* pMsgBuf, BOOL bInbound)
{
    // Only implemented by subclasses in server modules
}

void 
RTSPBaseProtocol::handleSendEvent(RTSPRequestMessage* pMsg)
{
    // Only implemented by subclasses in server modules
}

RTSPResponseMessage*
RTSPBaseProtocol::makeResponseMessage(UINT32 seqNo, const char* pErrNo)
{
    RTSPResponseMessage* pMsg = new RTSPResponseMessage;

    // set sequence number
    char seqBuf[32]; 
    SafeSprintf(seqBuf,32,"%ld", seqNo);
    pMsg->addHeader("CSeq", seqBuf, TRUE);	// add to head of list
    pMsg->setSeqNo(seqNo);

    pMsg->setErrorCode(pErrNo);
    pMsg->setErrorMsg(getErrorText(pErrNo));
    UTCTimeRep utcNow;
    pMsg->addHeader("Date", utcNow.asRFC1123String());
    return pMsg;
}

HX_RESULT
RTSPBaseProtocol::sendResponse(UINT32 seqNo, const char* pErrNo)
{
    RTSPResponseMessage* pMsg = makeResponseMessage(seqNo, pErrNo);
    HX_RESULT err = sendResponse(pMsg);
    delete pMsg;
    return err;
}

HX_RESULT
RTSPBaseProtocol::sendResponse(
    RTSPResponseMessage* pMsg, const char* pContent, const char* pMimeType)
{
    if (pContent != NULL)
    {
        char tmpBuf[32]; 
        pMsg->addHeader("Content-type", pMimeType);
        SafeSprintf(tmpBuf,32, "%d", strlen(pContent));  // only for strings 
        pMsg->addHeader("Content-length", tmpBuf);
        pMsg->setContent(pContent);
    }

    CHXString msgStr = pMsg->asString();

    CHXBuffer* pBuffer = new CHXBuffer;
    pBuffer->AddRef();
    pBuffer->Set((BYTE*)(const char*)msgStr, msgStr.GetLength());
    sendControlMessage(pBuffer);
    handleSendEvent(pMsg);
    pBuffer->Release();
    return HXR_OK;
}

void 
RTSPBaseProtocol::handleSendEvent(RTSPResponseMessage* pMsg)
{
    // Only implmented by subclasses in server modules
}

void
RTSPBaseProtocol::addRFC822Headers(RTSPMessage* pMsg,
				   IHXValues* pRFC822Headers)
{
    HX_RESULT         res;

⌨️ 快捷键说明

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