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.

142 lines
3.6 KiB

  1. /*++
  2. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. OBJPATH.H
  5. Abstract:
  6. object path parser
  7. History:
  8. --*/
  9. #ifndef _OBJPATH_H_
  10. #define _OBJPATH_H_
  11. #include <comdef.h>
  12. #include <wbemprov.h>
  13. #include <opathlex.h>
  14. #define DELETE_ME
  15. struct KeyRef
  16. {
  17. LPWSTR m_pName;
  18. VARIANT m_vValue;
  19. KeyRef();
  20. KeyRef(LPCWSTR wszKeyName, const VARIANT* pvValue);
  21. ~KeyRef();
  22. };
  23. struct ParsedObjectPath
  24. {
  25. LPWSTR m_pServer; // NULL if no server
  26. DWORD m_dwNumNamespaces; // 0 if no namespaces
  27. DWORD m_dwAllocNamespaces; // size of m_paNamespaces
  28. static const DWORD m_scdwAllocNamespaceChunkSize; // Grow m_paNamespaces in units of this quantity
  29. LPWSTR *m_paNamespaces; // NULL if no namespaces
  30. LPWSTR m_pClass; // Class name
  31. DWORD m_dwNumKeys; // 0 if no keys (just a class name)
  32. DWORD m_dwAllocKeys; // size of m_paKeys
  33. static const DWORD m_scdwAllocKeysChunkSize; // Grow m_paKeys in units of this quantity
  34. KeyRef **m_paKeys; // NULL if no keys specified
  35. BOOL m_bSingletonObj; // true if object of class with no keys
  36. ParsedObjectPath();
  37. ~ParsedObjectPath();
  38. public:
  39. BOOL SetClassName(LPCWSTR wszClassName);
  40. BOOL AddKeyRef(LPCWSTR wszKeyName, const VARIANT* pvValue);
  41. BOOL AddKeyRef(KeyRef* pAcquireRef);
  42. BOOL AddKeyRefEx(LPCWSTR wszKeyName, const VARIANT* pvValue);
  43. BOOL AddNamespace(LPCWSTR wszNamespace);
  44. LPWSTR GetKeyString();
  45. LPWSTR GetNamespacePart();
  46. LPWSTR GetParentNamespacePart();
  47. void ClearKeys () ;
  48. BOOL IsRelative(LPCWSTR wszMachine, LPCWSTR wszNamespace);
  49. BOOL IsLocal(LPCWSTR wszMachine);
  50. BOOL IsClass();
  51. BOOL IsInstance();
  52. BOOL IsObject();
  53. private:
  54. BOOL IncreaseNumAllocKeys();
  55. };
  56. // NOTE:
  57. // The m_vValue in the KeyRef may not be of the expected type, i.e., the parser
  58. // cannot distinguish 16 bit integers from 32 bit integers if they fall within the
  59. // legal subrange of a 16 bit value. Therefore, the parser only uses the following
  60. // types for keys:
  61. // VT_I4, VT_R8, VT_BSTR
  62. // If the underlying type is different, the user of this parser must do appropriate
  63. // type conversion.
  64. //
  65. typedef enum
  66. {
  67. e_ParserAcceptRelativeNamespace, // Allow a relative namespace
  68. e_ParserAbsoluteNamespaceOnly, // Require a full object path
  69. e_ParserAcceptAll // Accept any recognizable subset of a path
  70. } ObjectParserFlags;
  71. class CObjectPathParser
  72. {
  73. LPWSTR m_pInitialIdent;
  74. int m_nCurrentToken;
  75. CGenLexer *m_pLexer;
  76. ParsedObjectPath *m_pOutput;
  77. KeyRef *m_pTmpKeyRef;
  78. ObjectParserFlags m_eFlags;
  79. private:
  80. void Zero();
  81. void Empty();
  82. int begin_parse();
  83. int ns_or_server();
  84. int ns_or_class();
  85. int objref();
  86. int ns_list();
  87. int ident_becomes_ns();
  88. int ident_becomes_class();
  89. int objref_rest();
  90. int ns_list_rest();
  91. int key_const();
  92. int keyref_list();
  93. int keyref();
  94. int keyref_term();
  95. int propname();
  96. int optional_objref();
  97. int NextToken();
  98. public:
  99. enum { NoError, SyntaxError, InvalidParameter, OutOfMemory };
  100. CObjectPathParser(ObjectParserFlags eFlags = e_ParserAbsoluteNamespaceOnly);
  101. ~CObjectPathParser();
  102. int Parse(
  103. LPCWSTR RawPath,
  104. ParsedObjectPath **pOutput
  105. );
  106. static int WINAPI Unparse(
  107. ParsedObjectPath* pInput,
  108. DELETE_ME LPWSTR* pwszPath);
  109. static LPWSTR WINAPI GetRelativePath(LPWSTR wszFullPath);
  110. void Free(ParsedObjectPath *pOutput);
  111. void Free( LPWSTR wszUnparsedPath );
  112. };
  113. #endif