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.

179 lines
5.7 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __STATREG_H
  11. #define __STATREG_H
  12. #define E_ATL_REGISTRAR_DESC 0x0201
  13. #define E_ATL_NOT_IN_MAP 0x0202
  14. #define E_ATL_UNEXPECTED_EOS 0x0203
  15. #define E_ATL_VALUE_SET_FAILED 0x0204
  16. #define E_ATL_RECURSE_DELETE_FAILED 0x0205
  17. #define E_ATL_EXPECTING_EQUAL 0x0206
  18. #define E_ATL_CREATE_KEY_FAILED 0x0207
  19. #define E_ATL_DELETE_KEY_FAILED 0x0208
  20. #define E_ATL_OPEN_KEY_FAILED 0x0209
  21. #define E_ATL_CLOSE_KEY_FAILED 0x020A
  22. #define E_ATL_UNABLE_TO_COERCE 0x020B
  23. #define E_ATL_BAD_HKEY 0x020C
  24. #define E_ATL_MISSING_OPENKEY_TOKEN 0x020D
  25. #define E_ATL_CONVERT_FAILED 0x020E
  26. #define E_ATL_TYPE_NOT_SUPPORTED 0x020F
  27. #define E_ATL_COULD_NOT_CONCAT 0x0210
  28. #define E_ATL_COMPOUND_KEY 0x0211
  29. #define E_ATL_INVALID_MAPKEY 0x0212
  30. #define E_ATL_UNSUPPORTED_VT 0x0213
  31. #define E_ATL_VALUE_GET_FAILED 0x0214
  32. #define E_ATL_VALUE_TOO_LARGE 0x0215
  33. #define E_ATL_MISSING_VALUE_DELIMETER 0x0216
  34. #define E_ATL_DATA_NOT_BYTE_ALIGNED 0x0217
  35. #ifndef ATL_NO_NAMESPACE
  36. namespace ATL
  37. {
  38. #endif
  39. const TCHAR chSemiColon = _T(';');
  40. const TCHAR chDirSep = _T('\\');
  41. const TCHAR chEscape = _T('\\');
  42. const TCHAR chComma = _T(',');
  43. const TCHAR chDelete = _T('~');
  44. const TCHAR chEOS = _T('\0');
  45. const TCHAR chTab = _T('\t');
  46. const TCHAR chLF = _T('\n');
  47. const TCHAR chCR = _T('\r');
  48. const TCHAR chSpace = _T(' ');
  49. const TCHAR chRightBracket = _T('}');
  50. const TCHAR chLeftBracket = _T('{');
  51. const TCHAR chVarLead = _T('%');
  52. const TCHAR chQuote = _T('\'');
  53. const TCHAR chEquals = _T('=');
  54. //const LPCTSTR szRightBracket = _T("}");
  55. //const LPCTSTR szLeftBracket = _T("{");
  56. //const LPCTSTR szEquals = _T("=");
  57. //const LPCTSTR szDirSep = _T("\\");
  58. const LPCTSTR szStringVal = _T("S");
  59. const LPCTSTR szDwordVal = _T("D");
  60. const LPCTSTR szBinaryVal = _T("B");
  61. const LPCTSTR szValToken = _T("Val");
  62. const LPCTSTR szForceRemove = _T("ForceRemove");
  63. const LPCTSTR szNoRemove = _T("NoRemove");
  64. const LPCTSTR szDelete = _T("Delete");
  65. struct EXPANDER
  66. {
  67. LPOLESTR szKey;
  68. LPOLESTR szValue;
  69. };
  70. class CExpansionVector
  71. {
  72. public:
  73. CExpansionVector()
  74. {
  75. m_cEls = 0;
  76. m_nSize=10;
  77. m_p=(EXPANDER**)malloc(m_nSize*sizeof(EXPANDER*));
  78. }
  79. HRESULT Add(LPCOLESTR lpszKey, LPCOLESTR lpszValue);
  80. LPCOLESTR Find(LPTSTR lpszKey);
  81. HRESULT ClearReplacements();
  82. private:
  83. EXPANDER** m_p;
  84. int m_cEls;
  85. int m_nSize;
  86. };
  87. #if defined(_ATL_DLL) | defined(_ATL_DLL_IMPL)
  88. class ATL_NO_VTABLE CRegObject
  89. : public IRegistrar
  90. #else
  91. class CRegObject
  92. #endif
  93. {
  94. public:
  95. ~CRegObject(){ClearReplacements();}
  96. HRESULT FinalConstruct() {return S_OK;}
  97. void FinalRelease() {}
  98. // Map based methods
  99. HRESULT STDMETHODCALLTYPE AddReplacement(LPCOLESTR lpszKey, LPCOLESTR lpszItem);
  100. HRESULT STDMETHODCALLTYPE ClearReplacements();
  101. LPCOLESTR StrFromMap(LPTSTR lpszKey);
  102. // Register via a given mechanism
  103. HRESULT STDMETHODCALLTYPE ResourceRegister(LPCOLESTR pszFileName, UINT nID, LPCOLESTR pszType);
  104. HRESULT STDMETHODCALLTYPE ResourceRegisterSz(LPCOLESTR pszFileName, LPCOLESTR pszID, LPCOLESTR pszType);
  105. HRESULT STDMETHODCALLTYPE ResourceUnregister(LPCOLESTR pszFileName, UINT nID, LPCOLESTR pszType);
  106. HRESULT STDMETHODCALLTYPE ResourceUnregisterSz(LPCOLESTR pszFileName, LPCOLESTR pszID, LPCOLESTR pszType);
  107. HRESULT STDMETHODCALLTYPE FileRegister(LPCOLESTR pszFileName);
  108. HRESULT STDMETHODCALLTYPE FileUnregister(LPCOLESTR pszFileName);
  109. HRESULT STDMETHODCALLTYPE StringRegister(LPCOLESTR pszData);
  110. HRESULT STDMETHODCALLTYPE StringUnregister(LPCOLESTR pszData);
  111. protected:
  112. HRESULT MemMapAndRegister(LPCOLESTR pszFileName, BOOL bRegister);
  113. HRESULT RegisterFromResource(LPCOLESTR pszFileName, LPCTSTR pszID, LPCTSTR pszType, BOOL bRegister);
  114. HRESULT RegisterWithString(LPCOLESTR pszData, BOOL bRegister);
  115. static HRESULT GenerateError(UINT nID);
  116. CExpansionVector m_RepMap;
  117. CComObjectThreadModel::AutoCriticalSection m_csMap;
  118. };
  119. class CRegParser
  120. {
  121. public:
  122. CRegParser(CRegObject* pRegObj);
  123. HRESULT PreProcessBuffer(LPTSTR lpszReg, LPTSTR* ppszReg);
  124. HRESULT RegisterBuffer(LPTSTR szReg, BOOL bRegister);
  125. protected:
  126. void SkipWhiteSpace();
  127. HRESULT NextToken(LPTSTR szToken);
  128. HRESULT AddValue(CRegKey& rkParent,LPCTSTR szValueName, LPTSTR szToken);
  129. BOOL CanForceRemoveKey(LPCTSTR szKey);
  130. BOOL HasSubKeys(HKEY hkey);
  131. BOOL HasValues(HKEY hkey);
  132. HRESULT RegisterSubkeys(HKEY hkParent, BOOL bRegister, BOOL bInRecovery = FALSE);
  133. BOOL IsSpace(TCHAR ch);
  134. void IncrementLinePos();
  135. void IncrementLineCount(){m_cLines++;}
  136. LPTSTR m_pchCur;
  137. int m_cLines;
  138. CRegObject* m_pRegObj;
  139. HRESULT GenerateError(UINT nID);
  140. HRESULT HandleReplacements(LPTSTR& szToken);
  141. HRESULT SkipAssignment(LPTSTR szToken);
  142. BOOL EndOfVar() { return chQuote == *m_pchCur && chQuote != *CharNext(m_pchCur); }
  143. };
  144. #ifndef ATL_NO_NAMESPACE
  145. }; //namespace ATL
  146. #endif
  147. #endif //__STATREG_H