Source code of Windows XP (NT5)
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.

110 lines
3.0 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. // utils.cpp
  6. //
  7. // Purpose: utility functions
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #include <utillib.h>
  12. #include <utils.h>
  13. // see comments in header
  14. DWORD WINAPI NormalizePath(
  15. LPCWSTR lpwszInPath,
  16. LPCWSTR lpwszComputerName,
  17. LPCWSTR lpwszNamespace,
  18. DWORD dwFlags,
  19. CHString &sOutPath
  20. )
  21. {
  22. ParsedObjectPath *pParsedPath = NULL;
  23. CObjectPathParser objpathParser;
  24. GetValuesForPropResults eRet = e_OK;
  25. int nStatus = objpathParser.Parse( lpwszInPath, &pParsedPath );
  26. if ( 0 == nStatus )
  27. {
  28. try
  29. {
  30. // Check the machine name and namespace
  31. if (pParsedPath->IsRelative( lpwszComputerName, lpwszNamespace ))
  32. {
  33. // If there is only one key, null out the property name (easier than trying
  34. // to find the key name if it is missing).
  35. if (pParsedPath->m_dwNumKeys == 1)
  36. {
  37. if (pParsedPath->m_paKeys[0]->m_pName != NULL)
  38. {
  39. if (!(dwFlags & NORMALIZE_NULL))
  40. {
  41. }
  42. else
  43. {
  44. delete pParsedPath->m_paKeys[0]->m_pName;
  45. pParsedPath->m_paKeys[0]->m_pName = NULL;
  46. }
  47. }
  48. else
  49. {
  50. if (!(dwFlags & NORMALIZE_NULL))
  51. {
  52. eRet = e_NullName;
  53. }
  54. }
  55. }
  56. if (eRet == e_OK)
  57. {
  58. // Reform the object path, minus machine name and namespace name
  59. LPWSTR pPath = NULL;
  60. if (objpathParser.Unparse(pParsedPath, &pPath) == 0)
  61. {
  62. try
  63. {
  64. sOutPath = pPath;
  65. }
  66. catch ( ... )
  67. {
  68. delete pPath;
  69. throw;
  70. }
  71. delete pPath;
  72. }
  73. else
  74. {
  75. sOutPath.Empty();
  76. eRet = e_UnParseError;
  77. }
  78. }
  79. }
  80. else
  81. {
  82. sOutPath.Empty();
  83. eRet = e_NonLocalPath;
  84. }
  85. }
  86. catch (...)
  87. {
  88. objpathParser.Free( pParsedPath );
  89. throw;
  90. }
  91. objpathParser.Free( pParsedPath );
  92. }
  93. else
  94. {
  95. sOutPath.Empty();
  96. eRet = e_UnparsablePath;
  97. }
  98. return eRet;
  99. }