metautil.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:5k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hlxclib/string.h"
  36. #include "hxtypes.h"
  37. #include "hxcom.h"
  38. #include "ihxpckts.h"
  39. #include "hxfiles.h"
  40. #include "hxccf.h"
  41. HX_RESULT CheckMetaInfoRequest(IHXRequest*            pRequest,
  42.                                IHXCommonClassFactory* pFactory,
  43.                                REF(BOOL)              rbAcceptMetaInfoPresent,
  44.                                REF(BOOL)              rbAllMetaInfoRequested,
  45.                                REF(IHXValues*)        rpRequestedMetaInfo)
  46. {
  47.     HX_RESULT retVal = HXR_FAIL;
  48.     if (pRequest && pFactory)
  49.     {
  50.         IHXValues* pReqHdrs = NULL;
  51.         retVal = pRequest->GetRequestHeaders(pReqHdrs);
  52.         if (SUCCEEDED(retVal) && pReqHdrs)
  53.         {
  54.             IHXBuffer* pBuffer = NULL;
  55.             pReqHdrs->GetPropertyCString("AcceptMetaInfo", pBuffer);
  56.             if (pBuffer)
  57.             {
  58.                 // "AcceptMetaInfo" is present
  59.                 rbAcceptMetaInfoPresent = TRUE;
  60.                 // Get the string to examine
  61.                 const char* pszStr = (const char*) pBuffer->GetBuffer();
  62.                 // Check if it's "*"
  63.                 if (!strcmp(pszStr, "*"))
  64.                 {
  65.                     // All meta info is requested
  66.                     rbAllMetaInfoRequested = TRUE;
  67.                     rpRequestedMetaInfo    = NULL;
  68.                 }
  69.                 else
  70.                 {
  71.                     // We must parse the string
  72.                     IHXValues* pInfo = NULL;
  73.                     // We're going to use strtok() which is
  74.                     // destructive, so copy the string first
  75.                     char* pszCopy = new char [strlen(pszStr) + 1];
  76.                     if (pszCopy)
  77.                     {
  78.                         const char* pszSep = " trn,;";
  79.                         char* pszTok = strtok(pszCopy, pszSep);
  80.                         while (pszTok)
  81.                         {
  82.                             if (!pInfo)
  83.                             {
  84.                                 pFactory->CreateInstance(CLSID_IHXValues,
  85.                                                          (void**) &pInfo);
  86.                             }
  87.                             if (pInfo)
  88.                             {
  89.                                 pInfo->SetPropertyULONG32(pszTok, 1);
  90.                             }
  91.                             pszTok = strtok(NULL, pszSep);
  92.                         }
  93.                     }
  94.                     HX_VECTOR_DELETE(pszCopy);
  95.                     // Did we get any valid parsed strings?
  96.                     if (pInfo)
  97.                     {
  98.                         rbAllMetaInfoRequested = FALSE;
  99.                         HX_RELEASE(rpRequestedMetaInfo);
  100.                         rpRequestedMetaInfo = pInfo;
  101.                         rpRequestedMetaInfo->AddRef();
  102.                     }
  103.                     else
  104.                     {
  105.                         // AcceptMetaInfo was present, but there
  106.                         // weren't any valid strings in it, so we fail
  107.                         retVal = HXR_FAIL;
  108.                     }
  109.                     // Release the values
  110.                     HX_RELEASE(pInfo);
  111.                 }
  112.             }
  113.             else
  114.             {
  115.                 // "AcceptMetaInfo" is not present in
  116.                 // the request headers
  117.                 rbAcceptMetaInfoPresent = FALSE;
  118.             }
  119.             HX_RELEASE(pBuffer);
  120.         }
  121.         else
  122.         {
  123.             // No request headers
  124.             rbAcceptMetaInfoPresent = FALSE;
  125.         }
  126.         HX_RELEASE(pReqHdrs);
  127.     }
  128.     return retVal;
  129. }