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.

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