chxpckts.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:26k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: chxpckts.cpp,v 1.8.18.3 2004/07/09 01:45:59 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "hxcppflags.h"
  50. #ifndef HX_CPP_BASIC_TEMPLATES
  51. #include "old_hxpckts.cpp"
  52. #else
  53. /************************************************************************
  54.  *  Defines
  55.  */
  56. #define EXTREME_RTP_TIME    0xFFFFFFFF
  57. #include "hxtypes.h"
  58. #include "hxresult.h"
  59. #include "hxcom.h"
  60. #include "ihxpckts.h"
  61. #include "chxpckts.h"
  62. #include "hlxclib/string.h"
  63. #include "hxheap.h"
  64. #ifdef _DEBUG
  65. #undef HX_THIS_FILE
  66. static const char HX_THIS_FILE[] = __FILE__;
  67. #endif
  68. /////////////////////////////////////////////////////////////////////////
  69. // CHXPacket
  70. /////////////////////////////////////////////////////////////////////////
  71. // Method:
  72. // IUnknown::QueryInterface
  73. // Purpose:
  74. // Implement this to export the interfaces supported by your 
  75. // object.
  76. //
  77. STDMETHODIMP
  78. CHXPacket::QueryInterface(REFIID riid, void** ppvObj)
  79. {
  80.     if (IsEqualIID(riid, IID_IUnknown))
  81.     {
  82.         AddRef();
  83.         *ppvObj = this;
  84.         return HXR_OK;
  85.     }
  86.     else if (IsEqualIID(riid, IID_IHXPacket))
  87.     {
  88.         AddRef();
  89.         *ppvObj = (IHXPacket*)this;
  90.         return HXR_OK;
  91.     }
  92.     *ppvObj = NULL;
  93.     return HXR_NOINTERFACE;
  94. }
  95. /////////////////////////////////////////////////////////////////////////
  96. // Method:
  97. // IUnknown::AddRef
  98. // Purpose:
  99. // Everyone usually implements this the same... feel free to use
  100. // this implementation.
  101. //
  102. STDMETHODIMP_(ULONG32)
  103. CHXPacket::AddRef()
  104. {
  105.     return InterlockedIncrement(&m_lRefCount);
  106. }
  107. /////////////////////////////////////////////////////////////////////////
  108. // Method:
  109. // IUnknown::Release
  110. // Purpose:
  111. // Everyone usually implements this the same... feel free to use
  112. // this implementation.
  113. //
  114. STDMETHODIMP_(ULONG32)
  115. CHXPacket::Release()
  116. {
  117.     if (InterlockedDecrement(&m_lRefCount) > 0)
  118.     {
  119.         return m_lRefCount;
  120.     }
  121.     delete this;
  122.     return 0;
  123. }
  124. /************************************************************************
  125.  * Method:
  126.  * IHXPacket::Get
  127.  * Purpose:
  128.  * TBD
  129.  */
  130. STDMETHODIMP
  131. CHXPacket::Get(REF(IHXBuffer*)  pBuffer, 
  132.                REF(ULONG32)     ulTime,
  133.                REF(UINT16)      uStreamNumber,
  134.                REF(UINT8)       unASMFlags,
  135.                REF(UINT16)      unASMRuleNumber)
  136. {
  137.     return _Get(pBuffer,
  138.                 ulTime,
  139.                 uStreamNumber,
  140.                 unASMFlags,
  141.                 unASMRuleNumber);
  142. }
  143. /************************************************************************
  144.  * Method:
  145.  * IHXPacket::GetBuffer
  146.  * Purpose:
  147.  * TBD
  148.  */
  149. STDMETHODIMP_(IHXBuffer*)
  150. CHXPacket::GetBuffer()
  151. {
  152.     // Whenever a COM object is returned out of an
  153.     // interface, it should be AddRef()'d.
  154.     if (m_pBuffer) m_pBuffer->AddRef();
  155.     return m_pBuffer; 
  156. }
  157. /************************************************************************
  158.  * Method:
  159.  * IHXPacket::GetTime
  160.  * Purpose:
  161.  * TBD
  162.  */
  163. STDMETHODIMP_(ULONG32)
  164. CHXPacket::GetTime()
  165. {
  166.     return m_ulTime;
  167. }
  168. /************************************************************************
  169.  * Method:
  170.  * IHXPacket::GetFlags
  171.  * Purpose:
  172.  * TBD
  173.  */
  174. STDMETHODIMP_(UINT8)
  175. CHXPacket::GetASMFlags()
  176. {
  177.     return m_unASMFlags;
  178. }
  179. /************************************************************************
  180.  * Method:
  181.  * IHXPacket::GetStreamNumber
  182.  * Purpose:
  183.  * TBD
  184.  */
  185. STDMETHODIMP_(UINT16)
  186. CHXPacket::GetStreamNumber()
  187. {
  188.     return m_uStreamNumber;
  189. }
  190. /************************************************************************
  191.  * Method:
  192.  * IHXPacket::GetASMRuleNumber
  193.  * Purpose:
  194.  * TBD
  195.  */
  196. STDMETHODIMP_(UINT16)
  197. CHXPacket::GetASMRuleNumber()
  198. {
  199.     return m_unASMRuleNumber;
  200. }
  201. /************************************************************************
  202.  * Method:
  203.  * IHXPacket::IsLost
  204.  * Purpose:
  205.  * TBD
  206.  */
  207. STDMETHODIMP_(BOOL)
  208. CHXPacket::IsLost()
  209.     return m_bIsLost;
  210. }
  211. /************************************************************************
  212.  * Method:
  213.  * IHXPacket::SetAsLost
  214.  * Purpose:
  215.  * TBD
  216.  */
  217. STDMETHODIMP
  218. CHXPacket::SetAsLost()
  219. {
  220.     HX_ASSERT(m_pBuffer == NULL);
  221.     // Dropped packets are allowed to have a non-zero timestamp
  222.     if (!(m_unASMFlags & HX_ASM_DROPPED_PKT))
  223.     {
  224. HX_ASSERT(m_ulTime == 0);
  225.     }
  226.     if (m_pBuffer)
  227.     {
  228.         return HXR_UNEXPECTED;
  229.     }
  230.     m_bIsLost = TRUE;
  231.     return HXR_OK; 
  232. }
  233. /************************************************************************
  234.  * Method:
  235.  * IHXPacket::Set
  236.  * Purpose:
  237.  * TBD
  238.  */
  239. STDMETHODIMP
  240. CHXPacket::Set (IHXBuffer*  pBuffer, 
  241.                 ULONG32     ulTime,
  242.                 UINT16      uStreamNumber,
  243.                 UINT8       unASMFlags,
  244.                 UINT16      unASMRuleNumber
  245. )
  246. {
  247.     return _Set(pBuffer, 
  248.                 ulTime,
  249.                 uStreamNumber,
  250.                 unASMFlags,
  251.                 unASMRuleNumber);
  252. }
  253. /************************************************************************
  254.  * Method:
  255.  * IHXRTPPacket::GetRTP
  256.  */
  257. STDMETHODIMP
  258. CHXPacket::GetRTP(REF(IHXBuffer*) pBuffer, 
  259.                   REF(ULONG32)    ulTime,
  260.                   REF(ULONG32)    ulRTPTime,
  261.                   REF(UINT16)     uStreamNumber,
  262.                   REF(UINT8)      unASMFlags,
  263.                   REF(UINT16)     unASMRuleNumber)
  264. {
  265.     HX_ASSERT(HXR_UNEXPECTED == HXR_OK);
  266.     return HXR_UNEXPECTED;
  267. }
  268. /************************************************************************
  269.  * Method:
  270.  * IHXRTPPacket::GetRTPTime
  271.  */
  272. STDMETHODIMP_(ULONG32)
  273. CHXPacket::GetRTPTime()
  274. {
  275.     HX_ASSERT(HXR_UNEXPECTED == HXR_OK);
  276.     return EXTREME_RTP_TIME;
  277. }
  278. /************************************************************************
  279.  * Method:
  280.  * IHXRTPPacket::SetRTP
  281.  */
  282. STDMETHODIMP
  283. CHXPacket::SetRTP (IHXBuffer* pBuffer, 
  284.                    ULONG32    ulTime,
  285.                    ULONG32    ulRTPTime,
  286.                    UINT16     uStreamNumber,
  287.                    UINT8      unASMFlags,
  288.                    UINT16     unASMRuleNumber)
  289. {
  290.     HX_ASSERT(HXR_UNEXPECTED == HXR_OK);
  291.     return HXR_UNEXPECTED;
  292. }
  293. inline HX_RESULT
  294. CHXPacket::_Get(IHXBuffer*  &pBuffer,
  295.                 ULONG32     &ulTime,
  296.                 UINT16      &uStreamNumber,
  297.                 UINT8       &unASMFlags,
  298.                 UINT16      &unASMRuleNumber)
  299. {
  300.     pBuffer         = m_pBuffer;
  301.     ulTime          = m_ulTime;
  302.     uStreamNumber   = m_uStreamNumber;
  303.     unASMFlags      = m_unASMFlags;
  304.     unASMRuleNumber = m_unASMRuleNumber;
  305.     // Whenever a COM object is returned out of an
  306.     // interface, it should be AddRef()'d.
  307.     if (m_pBuffer) m_pBuffer->AddRef();
  308.     return HXR_OK;
  309. }
  310. inline HX_RESULT
  311. CHXPacket::_Set(IHXBuffer*  pBuffer, 
  312.                 ULONG32     ulTime,
  313.                 UINT16      uStreamNumber,
  314.                 UINT8       unASMFlags,
  315.                 UINT16      unASMRuleNumber)
  316. {
  317.     /* We allow changing the packet info when it is owned
  318.      * by atmost one user.
  319.      */
  320.     if (m_lRefCount > 1)
  321.     {
  322.         HX_ASSERT(FALSE);
  323.         return HXR_UNEXPECTED;
  324.     }
  325.     if (m_pBuffer)
  326.     {
  327.         m_pBuffer->Release();
  328.     }
  329.     m_pBuffer = pBuffer;
  330.     if (m_pBuffer)
  331.     {
  332.         m_pBuffer->AddRef();
  333.     }
  334.     m_ulTime            = ulTime;
  335.     m_uStreamNumber     = uStreamNumber;
  336.     m_unASMFlags        = unASMFlags;
  337.     m_unASMRuleNumber   = unASMRuleNumber;
  338.     return HXR_OK;
  339. }
  340. // serialization method
  341. void
  342. CHXPacket::Pack(IHXPacket* pPacket, char* pData, UINT32& ulSize)
  343. {
  344.     UINT16      uValue = 0;
  345.     UINT32      ulValue = 0;
  346.     UINT32      ulBufferSize = 0;
  347.     IHXBuffer*  pBuffer = NULL;
  348.     if (!pPacket)
  349.     {
  350.         goto cleanup;
  351.     }
  352.     pBuffer = pPacket->GetBuffer();
  353.     if (pBuffer)
  354.     {
  355.         ulBufferSize = pBuffer->GetSize();
  356.     }
  357.     // figure out the size 
  358.     if (!pData)
  359.     {
  360.         ulSize = sizeof(HXPacketInfo) + ulBufferSize;
  361.     }
  362.     // pack the data
  363.     else
  364.     {
  365.         *pData++ = (BYTE)pPacket->IsLost(); ulSize++;
  366.         *pData++ = (BYTE)pPacket->GetASMFlags(); ulSize++;
  367.         uValue = pPacket->GetASMRuleNumber();
  368.         *pData++ = (BYTE)uValue; *pData++ = (BYTE)(uValue >> 8);  ulSize += 2;
  369.         uValue = pPacket->GetStreamNumber();
  370.         *pData++ = (BYTE)uValue; *pData++ = (BYTE)(uValue >> 8);  ulSize += 2;
  371.         ulValue = pPacket->GetTime();
  372.         *pData++ = (BYTE)ulValue; *pData++ = (BYTE)(ulValue >> 8);
  373.         *pData++ = (BYTE)(ulValue >> 16); *pData++ = (BYTE)(ulValue >> 24); ulSize += 4;
  374.         if (pBuffer)
  375.         {
  376.             memcpy(pData, (char*)pBuffer->GetBuffer(), ulBufferSize); /* Flawfinder: ignore */
  377.             pData += ulBufferSize; ulSize += ulBufferSize;
  378.         }
  379.     }
  380. cleanup:
  381.     HX_RELEASE(pBuffer);
  382.     return;
  383. }   
  384. void
  385. CHXPacket::UnPack(IHXPacket*& pPacket, char* pData, UINT32 ulSize)
  386. {
  387.     UINT16          uValue = 0;
  388.     UINT32          ulValue = 0;
  389.     IHXBuffer*      pBuffer = NULL;
  390.     HXPacketInfo   packetInfo;
  391.     pPacket = NULL;
  392.     if (!pData || !ulSize)
  393.     {
  394.         goto cleanup;
  395.     }
  396.     HX_ASSERT(ulSize >= sizeof(HXPacketInfo));
  397.     packetInfo.lost = (BYTE)*pData++;     ulSize--;
  398.     packetInfo.ASMFlags = (BYTE)*pData++;   ulSize--;
  399.     uValue = (BYTE)*pData++; uValue |= (((BYTE)*pData++) << 8);
  400.     packetInfo.ASMRuleNumber = uValue;     ulSize -= 2;
  401.     uValue = (BYTE)*pData++; uValue |= (((BYTE)*pData++) << 8);
  402.     packetInfo.streamNum = uValue;     ulSize -= 2;
  403.     ulValue = (BYTE)*pData++; ulValue |= (((BYTE)*pData++) << 8);
  404.     ulValue |= (((BYTE)*pData++) << 16); ulValue |= (((BYTE)*pData++) << 24);
  405.     packetInfo.time = ulValue;     ulSize -= 4;
  406.     if (ulSize)
  407.     {
  408.         pBuffer = new CHXBuffer();
  409.         pBuffer->AddRef();
  410.         pBuffer->Set((const UCHAR*)pData, ulSize);
  411.     }
  412.         
  413.     pPacket = new CHXPacket();
  414.     pPacket->AddRef();
  415.     pPacket->Set(pBuffer, 
  416.                  packetInfo.time, 
  417.                  packetInfo.streamNum,
  418.                  packetInfo.ASMFlags,
  419.                  packetInfo.ASMRuleNumber);
  420.     if (packetInfo.lost)
  421.     {
  422.         pPacket->SetAsLost();
  423.     }
  424. cleanup:
  425.     HX_RELEASE(pBuffer);
  426.     return;
  427. }
  428. /////////////////////////////////////////////////////////////////////////
  429. // CHXRTPPacket
  430. /////////////////////////////////////////////////////////////////////////
  431. // Method:
  432. // IUnknown::QueryInterface
  433. // Purpose:
  434. // Implement this to export the interfaces supported by your 
  435. // object.
  436. //
  437. STDMETHODIMP
  438. CHXRTPPacket::QueryInterface(REFIID riid, void** ppvObj)
  439. {
  440. QInterfaceList qiList[] =
  441. {
  442. { GET_IIDHANDLE(IID_IUnknown), this },
  443. { GET_IIDHANDLE(IID_IHXRTPPacket), (IHXRTPPacket*) this },
  444. { GET_IIDHANDLE(IID_IHXPacket), (IHXPacket*) this },
  445. };
  446.     return QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);   
  447. }
  448. /////////////////////////////////////////////////////////////////////////
  449. // Method:
  450. // IUnknown::Release
  451. // Purpose:
  452. // Everyone usually implements this the same... feel free to use
  453. // this implementation.
  454. //
  455. STDMETHODIMP_(ULONG32)
  456. CHXRTPPacket::Release()
  457. {
  458.     if (InterlockedDecrement(&m_lRefCount) > 0)
  459.     {
  460.         return m_lRefCount;
  461.     }
  462.     delete this;
  463.     return 0;
  464. }
  465. /************************************************************************
  466.  * Method:
  467.  * IHXPacket::Set
  468.  */
  469. STDMETHODIMP
  470. CHXRTPPacket::Set(IHXBuffer*  pBuffer, 
  471.                   ULONG32     ulTime,
  472.                   UINT16      uStreamNumber,
  473.                   UINT8       unASMFlags,
  474.                   UINT16      unASMRuleNumber)
  475. {
  476.     m_ulRTPTime = ulTime;
  477.     return _Set(pBuffer, 
  478.                 ulTime,
  479.                 uStreamNumber,
  480.                 unASMFlags,
  481.                 unASMRuleNumber);
  482. }
  483. /************************************************************************
  484.  * Method:
  485.  * IHXRTPPacket::GetRTP
  486.  */
  487. STDMETHODIMP
  488. CHXRTPPacket::GetRTP(REF(IHXBuffer*)  pBuffer, 
  489.                      REF(ULONG32)     ulTime,
  490.                      REF(ULONG32)     ulRTPTime,
  491.                      REF(UINT16)      uStreamNumber,
  492.                      REF(UINT8)       unASMFlags,
  493.                      REF(UINT16)      unASMRuleNumber)
  494. {
  495.     ulRTPTime = m_ulRTPTime;
  496.     return _Get(pBuffer,
  497.                 ulTime,
  498.                 uStreamNumber,
  499.                 unASMFlags,
  500.                 unASMRuleNumber);
  501. }
  502. /************************************************************************
  503.  * Method:
  504.  * IHXRTPPacket::GetRTPTime
  505.  */
  506. STDMETHODIMP_(ULONG32)
  507. CHXRTPPacket::GetRTPTime()
  508. {
  509.     return m_ulRTPTime;
  510. }
  511. /************************************************************************
  512.  * Method:
  513.  * IHXRTPPacket::SetRTP
  514.  */
  515. STDMETHODIMP
  516. CHXRTPPacket::SetRTP(IHXBuffer*  pBuffer, 
  517.                      ULONG32     ulTime,
  518.                      ULONG32     ulRTPTime,
  519.                      UINT16      uStreamNumber,
  520.                      UINT8       unASMFlags,
  521.                      UINT16      unASMRuleNumber)
  522. {
  523.     m_ulRTPTime = ulRTPTime;
  524.     return _Set(pBuffer, 
  525.                 ulTime,
  526.                 uStreamNumber,
  527.                 unASMFlags,
  528.                 unASMRuleNumber);
  529. }
  530. /////////////////////////////////////////////////////////////////////////
  531. // CHXHeader
  532. //
  533. /////////////////////////////////////////////////////////////////////////
  534. // Method:
  535. // IUnknown::QueryInterface
  536. // Purpose:
  537. // Implement this to export the interfaces supported by your 
  538. // object.
  539. //
  540. STDMETHODIMP
  541. CHXHeader::QueryInterface(REFIID riid, void** ppvObj)
  542. {
  543.     if (IsEqualIID(riid, IID_IUnknown))
  544.     {
  545.         AddRef();
  546.         *ppvObj = this;
  547.         return HXR_OK;
  548.     }
  549.     else if (IsEqualIID(riid, IID_IHXValues))
  550.     {
  551.         AddRef();
  552.         *ppvObj = (IHXValues*)this;
  553.         return HXR_OK;
  554.     }
  555.     *ppvObj = NULL;
  556.     return HXR_NOINTERFACE;
  557. }
  558. /////////////////////////////////////////////////////////////////////////
  559. // Method:
  560. // IUnknown::AddRef
  561. // Purpose:
  562. // Everyone usually implements this the same... feel free to use
  563. // this implementation.
  564. //
  565. STDMETHODIMP_(ULONG32)
  566. CHXHeader::AddRef()
  567. {
  568.     return InterlockedIncrement(&m_lRefCount);
  569. }
  570. /////////////////////////////////////////////////////////////////////////
  571. // Method:
  572. // IUnknown::Release
  573. // Purpose:
  574. // Everyone usually implements this the same... feel free to use
  575. // this implementation.
  576. //
  577. STDMETHODIMP_(ULONG32)
  578. CHXHeader::Release()
  579. {
  580.     if (InterlockedDecrement(&m_lRefCount) > 0)
  581.     {
  582.         return m_lRefCount;
  583.     }
  584.     delete this;
  585.     return 0;
  586. }
  587. CHXHeader::CValue&
  588. CHXHeader::CValue::operator= (CHXHeader::CValue const& rhs)
  589. {
  590.     CValue(rhs).Swap(*this);
  591.     return *this;
  592. }
  593. CHXHeader::~CHXHeader()
  594. {
  595.     for (Map::iterator i = m_Map.begin(); i != m_Map.end(); ++i)
  596.     {
  597.         delete[] (char*)i->first;
  598.     }
  599. }
  600. CHXHeader::CValue::~CValue()
  601. {
  602.     HX_RELEASE(m_pIBuffer);
  603.     HX_RELEASE(m_pIString);
  604. }
  605. bool
  606. CHXHeader::MyCompare::operator()(const char* p1, const char* p2) const
  607. {
  608.     return (m_PreserveCase ? strcmp(p1, p2) : strcmpi(p1, p2)) < 0;
  609. }
  610. STDMETHODIMP
  611. CHXHeader::SetPropertyULONG32(const char* pPropertyName,
  612.                               ULONG32     uPropertyValue)
  613. {
  614.     return SetProperty(pPropertyName, &CValue::m_lVal, uPropertyValue);
  615. }
  616. STDMETHODIMP
  617. CHXHeader::GetPropertyULONG32(const char*  pPropertyName,
  618.                               REF(ULONG32) uPropertyValue)
  619. {
  620.     return GetProperty(pPropertyName, &CValue::m_lVal, uPropertyValue);
  621. }
  622. STDMETHODIMP
  623. CHXHeader::GetFirstPropertyULONG32(REF(const char*) pPropertyName,
  624.                                    REF(ULONG32)     uPropertyValue)
  625. {
  626.     m_ULONG32Position = m_Map.begin();
  627.     return GetNextProperty(
  628.                 pPropertyName,
  629.                 &CValue::m_lVal,
  630.                 uPropertyValue,
  631.                 m_ULONG32Position);
  632. }
  633. STDMETHODIMP
  634. CHXHeader::GetNextPropertyULONG32(REF(const char*) pPropertyName,
  635.                                   REF(ULONG32)     uPropertyValue)
  636. {
  637.     if (m_ULONG32Position == m_Map.end())
  638.     {
  639.         return HXR_FAIL;
  640.     }
  641.     return GetNextProperty(
  642.                 pPropertyName,
  643.                 &CValue::m_lVal,
  644.                 uPropertyValue,
  645.                 ++m_ULONG32Position);
  646. }
  647. STDMETHODIMP
  648. CHXHeader::SetPropertyBuffer(const char* pPropertyName,
  649.                              IHXBuffer*  pPropertyValue)
  650. {
  651.     if (!pPropertyValue)
  652.     {
  653.         return HXR_FAIL;
  654.     }
  655.     return SetProperty(pPropertyName, &CValue::m_pIBuffer, pPropertyValue);
  656. }
  657. STDMETHODIMP
  658. CHXHeader::GetPropertyBuffer(const char*     pPropertyName,
  659.                              REF(IHXBuffer*) pPropertyValue)
  660. {
  661.     return GetProperty(pPropertyName, &CValue::m_pIBuffer, pPropertyValue);
  662. }
  663. STDMETHODIMP
  664. CHXHeader::GetFirstPropertyBuffer(REF(const char*) pPropertyName,
  665.                                   REF(IHXBuffer*)  pPropertyValue)
  666. {
  667.     m_BufferPosition = m_Map.begin();
  668.     return GetNextProperty(
  669.                 pPropertyName,
  670.                 &CValue::m_pIBuffer,
  671.                 pPropertyValue,
  672.                 m_BufferPosition);
  673. }
  674. STDMETHODIMP
  675. CHXHeader::GetNextPropertyBuffer(REF(const char*) pPropertyName,
  676.                                  REF(IHXBuffer*)  pPropertyValue)
  677. {
  678.     if (m_BufferPosition == m_Map.end())
  679.     {
  680.         return HXR_FAIL;
  681.     }
  682.     return GetNextProperty(
  683.                pPropertyName,
  684.                &CValue::m_pIBuffer,
  685.                pPropertyValue,
  686.                ++m_BufferPosition);
  687. }
  688. STDMETHODIMP
  689. CHXHeader::SetPropertyCString(const char* pPropertyName,
  690.                               IHXBuffer*  pPropertyValue)
  691. {
  692.     if (!pPropertyValue)
  693.     {
  694.         return HXR_FAIL;
  695.     }
  696.     return SetProperty(pPropertyName, &CValue::m_pIString, pPropertyValue);
  697. }
  698. STDMETHODIMP
  699. CHXHeader::GetPropertyCString(const char*     pPropertyName,
  700.                               REF(IHXBuffer*) pPropertyValue)
  701. {
  702.         return GetProperty(pPropertyName, &CValue::m_pIString, pPropertyValue);
  703. }
  704. STDMETHODIMP
  705. CHXHeader::GetFirstPropertyCString(REF(const char*) pPropertyName,
  706.                                    REF(IHXBuffer*)  pPropertyValue)
  707. {
  708.     m_CStringPosition = m_Map.begin();
  709.     return GetNextProperty(
  710.                pPropertyName,
  711.                &CValue::m_pIString,
  712.                pPropertyValue,
  713.                m_CStringPosition);
  714. }
  715. STDMETHODIMP
  716. CHXHeader::GetNextPropertyCString(REF(const char*) pPropertyName,
  717.                                   REF(IHXBuffer*)  pPropertyValue)
  718. {
  719.     if (m_CStringPosition == m_Map.end())
  720.     {
  721.         return HXR_FAIL;
  722.     }
  723.     return GetNextProperty(
  724.                pPropertyName,
  725.                &CValue::m_pIString,
  726.                pPropertyValue,
  727.                ++m_CStringPosition);
  728. }
  729. void
  730. CHXHeader::PreserveCase(BOOL bPreserve)
  731. {
  732.     HX_ASSERT(m_Map.empty());
  733.     Map(MyCompare(bPreserve)).swap(m_Map);
  734. }
  735. void
  736. CHXHeader::mergeHeaders(IHXValues* pDestHeaders, 
  737.                         IHXValues* pSrcHeaders)
  738. {
  739. #if 0
  740.     if (!pDestHeaders || !pSrcHeaders) return;
  741.     // XXXHP - caveat emptor
  742.     CHXHeader& sourceHeader = *((CHXHeader*) pSrcHeaders);
  743.     CHXHeader& destHeader = *((CHXHeader*) pDestHeaders);
  744.     for (Map::const_iterator i = sourceHeader.m_Map.begin (); i != sourceHeader.m_Map.end (); ++i)
  745.     {
  746.         Map::iterator j = destHeader.m_Map.find(i->first);
  747.         if (j != destHeader.m_Map.end())
  748.         {
  749.             CValue& lhs = j->second;
  750.             const CValue& rhs = i->second;
  751.             if (rhs.m_lValValid) lhs.Set(&CValue::m_lVal, rhs.m_lVal);
  752.             if (rhs.m_pIBuffer) lhs.Set(&CValue::m_pIBuffer, rhs.m_pIBuffer);
  753.             if (rhs.m_pIString) lhs.Set(&CValue::m_pIString, rhs.m_pIString);
  754.         }
  755.         else
  756.         {
  757.             char* pTmp = new char[strlen(i->first) + 1];
  758.             strcpy(pTmp, i->first); /* Flawfinder: ignore */
  759.             Map::value_type newVal(pTmp, i->second);
  760.             newVal.second.m_Key = newVal.first;
  761.             destHeader.m_Map.insert(newVal);
  762.         }
  763.     }
  764. #else
  765.     if (pSrcHeaders && pDestHeaders)
  766.     {
  767.         // add these headers to the existing ones
  768.         //
  769.         const char* pPropName = NULL;
  770.         UINT32 ulPropValue = 0;
  771.         HX_RESULT rc =
  772.             pSrcHeaders->GetFirstPropertyULONG32(pPropName, ulPropValue);
  773.         while (SUCCEEDED(rc))
  774.         {
  775.             pDestHeaders->SetPropertyULONG32(pPropName, ulPropValue);
  776.             rc = pSrcHeaders->GetNextPropertyULONG32(pPropName, ulPropValue);
  777.         }
  778.         IHXBuffer* pBuffer = NULL;
  779.         rc = pSrcHeaders->GetFirstPropertyBuffer(pPropName, pBuffer);
  780.         while (SUCCEEDED(rc))
  781.         {
  782.             pDestHeaders->SetPropertyBuffer(pPropName, pBuffer);
  783.             pBuffer->Release();
  784.             rc = pSrcHeaders->GetNextPropertyBuffer(pPropName, pBuffer);
  785.         }
  786.         rc = pSrcHeaders->GetFirstPropertyCString(pPropName, pBuffer);
  787.         while (SUCCEEDED(rc))
  788.         {
  789.             pDestHeaders->SetPropertyCString(pPropName, pBuffer);
  790.             pBuffer->Release();
  791.             rc = pSrcHeaders->GetNextPropertyCString(pPropName, pBuffer);
  792.         }
  793.     }
  794. #endif
  795. }
  796. _CStoreName::_CStoreName() : m_strName()
  797. {
  798. }
  799. _CStoreName::~_CStoreName()
  800. {
  801. }
  802. const
  803. CHXString& _CStoreName::GetName() const
  804. {
  805.     return m_strName;
  806. }
  807. void
  808. _CStoreName::SetName(const char* szName)
  809. {
  810.     m_strName = szName;
  811. }
  812. _CStoreNameUINT32Pair::_CStoreNameUINT32Pair() : m_ulValue(0)
  813. {
  814. }
  815. _CStoreNameUINT32Pair::~_CStoreNameUINT32Pair()
  816. {
  817. }
  818. UINT32
  819. _CStoreNameUINT32Pair::GetValue()
  820. {
  821.     return m_ulValue;
  822. }
  823. void
  824. _CStoreNameUINT32Pair::SetValue(UINT32 ulValue)
  825. {
  826.     m_ulValue = ulValue;
  827. }
  828. _CStoreNameBufferPair::_CStoreNameBufferPair() : m_pbufValue(NULL)
  829. {
  830. }
  831. _CStoreNameBufferPair::~_CStoreNameBufferPair()
  832. {
  833.     HX_RELEASE(m_pbufValue);
  834. }
  835. IHXBuffer*
  836. _CStoreNameBufferPair::GetValue()
  837. {
  838.     if (m_pbufValue)
  839.     {
  840.         m_pbufValue->AddRef();
  841.     }
  842.     return m_pbufValue;
  843. }
  844. void
  845. _CStoreNameBufferPair::SetValue(IHXBuffer* pbufValue)
  846. {
  847.     HX_RELEASE(m_pbufValue);
  848.     m_pbufValue = pbufValue;
  849.     if (m_pbufValue)
  850.     {
  851.         m_pbufValue->AddRef();
  852.     }
  853. }
  854. #if 0
  855. IHXBuffer*
  856. CHXHeader::encodeBuffer(IHXBuffer* pBuffer)
  857. {
  858.     //XXXBAB - come back to this soon...
  859.     CHXBuffer* pEncodedBuffer = new CHXBuffer;
  860.     pEncodedBuffer->AddRef();
  861.     pEncodedBuffer->Set(pBuffer->GetBuffer(), pBuffer->GetSize());
  862.     return pEncodedBuffer;
  863. }
  864. IHXBuffer*
  865. CHXHeader::encodeCString(IHXBuffer* pBuffer)
  866. {
  867.     CHXString tmp;
  868.     const char* pStr = (const char*)pBuffer->GetBuffer();
  869.     BOOL inEscape = FALSE;
  870.     for(size_t i=0;i<strlen(pStr);++i)
  871.     {
  872.         switch(pStr[i])
  873.         {
  874.             case 'n':
  875.             {
  876.                 tmp += "\n";
  877.             }
  878.             break;
  879.             case 't':
  880.             {
  881.                 tmp += "\t";
  882.             }
  883.             break;
  884.             case 'r':
  885.             {
  886.                 tmp += "\r";
  887.             }
  888.             break;
  889.             case '"':
  890.             {
  891.                 tmp += "\"";
  892.             }
  893.             break;
  894.             case '\':
  895.             {
  896.                 tmp += "\\";
  897.             }
  898.             break;
  899.             default:
  900.             {
  901.                 tmp += pStr[i];
  902.             }
  903.         }
  904.     }
  905.     CHXBuffer* pEncodedBuffer = new CHXBuffer;
  906.     pEncodedBuffer->AddRef();
  907.     pEncodedBuffer->Set((const BYTE*)(const char*)tmp, tmp.GetLength()+1);
  908.     return pEncodedBuffer;
  909. }
  910. #endif
  911. #endif