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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: metautil.cpp,v 1.4.28.1 2004/07/09 01:55:14 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 "hlxclib/string.h"
  50. #include "hxtypes.h"
  51. #include "hxcom.h"
  52. #include "ihxpckts.h"
  53. #include "hxfiles.h"
  54. #include "hxccf.h"
  55. HX_RESULT CheckMetaInfoRequest(IHXRequest*            pRequest,
  56.                                IHXCommonClassFactory* pFactory,
  57.                                REF(BOOL)              rbAcceptMetaInfoPresent,
  58.                                REF(BOOL)              rbAllMetaInfoRequested,
  59.                                REF(IHXValues*)        rpRequestedMetaInfo)
  60. {
  61.     HX_RESULT retVal = HXR_FAIL;
  62.     if (pRequest && pFactory)
  63.     {
  64.         IHXValues* pReqHdrs = NULL;
  65.         retVal = pRequest->GetRequestHeaders(pReqHdrs);
  66.         if (SUCCEEDED(retVal) && pReqHdrs)
  67.         {
  68.             IHXBuffer* pBuffer = NULL;
  69.             pReqHdrs->GetPropertyCString("AcceptMetaInfo", pBuffer);
  70.             if (pBuffer)
  71.             {
  72.                 // "AcceptMetaInfo" is present
  73.                 rbAcceptMetaInfoPresent = TRUE;
  74.                 // Get the string to examine
  75.                 const char* pszStr = (const char*) pBuffer->GetBuffer();
  76.                 // Check if it's "*"
  77.                 if (!strcmp(pszStr, "*"))
  78.                 {
  79.                     // All meta info is requested
  80.                     rbAllMetaInfoRequested = TRUE;
  81.                     rpRequestedMetaInfo    = NULL;
  82.                 }
  83.                 else
  84.                 {
  85.                     // We must parse the string
  86.                     IHXValues* pInfo = NULL;
  87.                     // We're going to use strtok() which is
  88.                     // destructive, so copy the string first
  89.                     char* pszCopy = new char [strlen(pszStr) + 1];
  90.                     if (pszCopy)
  91.                     {
  92.                         const char* pszSep = " trn,;";
  93.                         char* pszTok = strtok(pszCopy, pszSep);
  94.                         while (pszTok)
  95.                         {
  96.                             if (!pInfo)
  97.                             {
  98.                                 pFactory->CreateInstance(CLSID_IHXValues,
  99.                                                          (void**) &pInfo);
  100.                             }
  101.                             if (pInfo)
  102.                             {
  103.                                 pInfo->SetPropertyULONG32(pszTok, 1);
  104.                             }
  105.                             pszTok = strtok(NULL, pszSep);
  106.                         }
  107.                     }
  108.                     HX_VECTOR_DELETE(pszCopy);
  109.                     // Did we get any valid parsed strings?
  110.                     if (pInfo)
  111.                     {
  112.                         rbAllMetaInfoRequested = FALSE;
  113.                         HX_RELEASE(rpRequestedMetaInfo);
  114.                         rpRequestedMetaInfo = pInfo;
  115.                         rpRequestedMetaInfo->AddRef();
  116.                     }
  117.                     else
  118.                     {
  119.                         // AcceptMetaInfo was present, but there
  120.                         // weren't any valid strings in it, so we fail
  121.                         retVal = HXR_FAIL;
  122.                     }
  123.                     // Release the values
  124.                     HX_RELEASE(pInfo);
  125.                 }
  126.             }
  127.             else
  128.             {
  129.                 // "AcceptMetaInfo" is not present in
  130.                 // the request headers
  131.                 rbAcceptMetaInfoPresent = FALSE;
  132.             }
  133.             HX_RELEASE(pBuffer);
  134.         }
  135.         else
  136.         {
  137.             // No request headers
  138.             rbAcceptMetaInfoPresent = FALSE;
  139.         }
  140.         HX_RELEASE(pReqHdrs);
  141.     }
  142.     return retVal;
  143. }