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.

141 lines
3.6 KiB

  1. /*++
  2. Copyright 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 <opathlex.h>
  12. #define DELETE_ME
  13. struct KeyRef
  14. {
  15. LPWSTR m_pName;
  16. VARIANT m_vValue;
  17. HRESULT m_hRes;
  18. KeyRef();
  19. KeyRef(LPCWSTR wszKeyName, const VARIANT* pvValue);
  20. ~KeyRef();
  21. BOOL IsValid(){ return (m_pName && (S_OK == m_hRes)); };
  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. LPWSTR *m_paNamespaces; // NULL if no namespaces
  29. LPWSTR m_pClass; // Class name
  30. DWORD m_dwNumKeys; // 0 if no keys (just a class name)
  31. DWORD m_dwAllocKeys; // size of m_paKeys
  32. KeyRef **m_paKeys; // NULL if no keys specified
  33. BOOL m_bSingletonObj; // true if object of class with no keys
  34. ParsedObjectPath();
  35. ~ParsedObjectPath();
  36. public:
  37. BOOL SetClassName(LPCWSTR wszClassName);
  38. BOOL AddKeyRef(LPCWSTR wszKeyName, const VARIANT* pvValue);
  39. BOOL AddKeyRef(KeyRef* pAcquireRef);
  40. BOOL AddKeyRefEx(LPCWSTR wszKeyName, const VARIANT* pvValue);
  41. BOOL AddNamespace(LPCWSTR wszNamespace);
  42. LPWSTR GetKeyString();
  43. LPWSTR GetNamespacePart();
  44. LPWSTR GetParentNamespacePart();
  45. void ClearKeys () ;
  46. BOOL IsRelative(LPCWSTR wszMachine, LPCWSTR wszNamespace);
  47. BOOL IsLocal(LPCWSTR wszMachine);
  48. BOOL IsClass();
  49. BOOL IsInstance();
  50. BOOL IsObject();
  51. BOOL IsValid()
  52. {
  53. return (m_paNamespaces && m_paKeys);
  54. };
  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