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.

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