Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
2.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: tfc.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <pch.cpp>
  11. #pragma hdrstop
  12. #include "tfc.h"
  13. #include "multisz.h"
  14. #define __dwFILE__ __dwFILE_CERTLIB_MULTISZ_CPP__
  15. //////////////////////////////////////////////////////////////////////////////////
  16. //////////////////////////////////////////////////////////////////////////////////
  17. // CMultiSz
  18. //////////////////////////////////////////////////////////////////////////////////
  19. //////////////////////////////////////////////////////////////////////////////////
  20. //
  21. // Marshals the list into a multisz buffer. The function allocates space, caller
  22. // is responsible for LocalFree'ing rpBuffer.
  23. //
  24. // Also returns the buffer size in bytes.
  25. //
  26. HRESULT CMultiSz::Marshal(void *&rpBuffer, DWORD &rcbBuffer)
  27. {
  28. HRESULT hr;
  29. CMultiSzEnum Enum(*this);
  30. DWORD cbBuffer;
  31. void *pBuffer;
  32. WCHAR *pwszBuf;
  33. rcbBuffer = 0;
  34. rpBuffer = NULL;
  35. cbBuffer = 1; // trailing empty string
  36. for(CString *pStr=Enum.Next();
  37. pStr;
  38. pStr=Enum.Next())
  39. {
  40. cbBuffer += pStr->GetLength()+1;
  41. }
  42. cbBuffer *= sizeof(WCHAR);
  43. pBuffer = LocalAlloc(LMEM_FIXED, cbBuffer);
  44. _JumpIfAllocFailed(pBuffer, error);
  45. pwszBuf = (WCHAR*)pBuffer;
  46. Enum.Reset();
  47. for(CString *pStr=Enum.Next();
  48. pStr;
  49. pStr=Enum.Next())
  50. {
  51. wcscpy(pwszBuf, *pStr);
  52. pwszBuf += wcslen(*pStr)+1;
  53. }
  54. *pwszBuf = L'\0';
  55. rcbBuffer = cbBuffer;
  56. rpBuffer = pBuffer;
  57. hr = S_OK;
  58. error:
  59. return hr;
  60. }
  61. HRESULT CMultiSz::Unmarshal(void *pBuffer)
  62. {
  63. HRESULT hr;
  64. WCHAR *pchCrt;
  65. CSASSERT(IsEmpty()); // warn if used on a prepopulated CMultiSz
  66. for(pchCrt = (WCHAR*)pBuffer;
  67. L'\0' != *pchCrt;
  68. pchCrt += wcslen(pchCrt)+1)
  69. {
  70. CString *pStr = new CString(pchCrt);
  71. if(!pStr ||
  72. pStr->IsEmpty() ||
  73. !AddTail(pStr))
  74. {
  75. hr = E_OUTOFMEMORY;
  76. _JumpError(hr, error, "");
  77. }
  78. }
  79. hr = S_OK;
  80. error:
  81. return hr;
  82. }
  83. bool CMultiSz::Find(LPCWSTR pcwszValue, bool fCaseSensitive)
  84. {
  85. CMultiSzEnum ISAPIDependListEnum(*this);
  86. const CString *pStr;
  87. for(pStr = ISAPIDependListEnum.Next();
  88. pStr;
  89. pStr = ISAPIDependListEnum.Next())
  90. {
  91. if(0 == (fCaseSensitive?
  92. wcscmp(pcwszValue, *pStr):
  93. _wcsicmp(pcwszValue, *pStr)))
  94. return true;
  95. }
  96. return false;
  97. }