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.

207 lines
7.4 KiB

  1. /*++ /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. pcm.h
  5. Abstract:
  6. Define common data structure for precompiled-manifest Writer and Reader
  7. and class definition of PrecompiledManifetWriter and
  8. PrecompiledManifestReader
  9. Author:
  10. Xiaoyu Wu (xiaoyuw) June 2000
  11. Revision History:
  12. --*/
  13. #if !defined(_FUSION_SXS_PCM_H_INCLUDED_)
  14. #define _FUSION_SXS_PCM_H_INCLUDED_
  15. #pragma once
  16. #include <ole2.h>
  17. #include <xmlparser.h>
  18. #include "nodefactory.h"
  19. #include "pcmwriterstream.h"
  20. // pcm structure shared between PCMWriter and PCMReader
  21. typedef enum _RECORD_TYPE_PRECOMP_MANIFEST{
  22. CREATENODE_PRECOMP_MANIFEST = 1,
  23. BEGINCHILDREN_PRECOMP_MANIFEST = CREATENODE_PRECOMP_MANIFEST + 1,
  24. ENDCHILDREN_PRECOMP_MANIFEST = BEGINCHILDREN_PRECOMP_MANIFEST + 1
  25. } RECORD_TYPE_PRECOMP_MANIFEST;
  26. typedef struct _PCM_Header{
  27. int iVersion;
  28. ULONG ulRecordCount;
  29. USHORT usMaxNodeCount;
  30. }PCMHeader;
  31. typedef struct _PCM_RecordHeader{
  32. int typeID ;
  33. ULONG RecordSize;
  34. ULONG NodeCount;
  35. }PCM_RecordHeader;
  36. typedef struct _PCM_XML_NODE_INFO{
  37. DWORD dwSize;
  38. DWORD dwType;
  39. DWORD dwSubType;
  40. BOOL fTerminal;
  41. ULONG offset;
  42. ULONG ulLen;
  43. ULONG ulNsPrefixLen;
  44. }PCM_XML_NODE_INFO;
  45. class __declspec(uuid("6745d578-5d84-4890-aa6a-bd794ea50421"))
  46. CPrecompiledManifestReader : public IXMLNodeSource, public IStream {
  47. public :
  48. // IUnknown methods:
  49. STDMETHODIMP_(ULONG) AddRef();
  50. STDMETHODIMP_(ULONG) Release();
  51. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  52. // IXMLNodeSource methods, only GetLineNumber is implemented got PCM purpose
  53. STDMETHODIMP SetFactory(IXMLNodeFactory __RPC_FAR *pNodeFactory);
  54. STDMETHODIMP GetFactory(IXMLNodeFactory** ppNodeFactory);
  55. STDMETHODIMP Abort(BSTR bstrErrorInfo);
  56. STDMETHODIMP_(ULONG) GetLineNumber(void);
  57. STDMETHODIMP_(ULONG) GetLinePosition(void);
  58. STDMETHODIMP_(ULONG) GetAbsolutePosition(void);
  59. STDMETHODIMP GetLineBuffer(const WCHAR **ppwcBuf, ULONG *pulLen, ULONG *pulStartPos);
  60. STDMETHODIMP GetLastError(void);
  61. STDMETHODIMP GetErrorInfo(BSTR *pbstrErrorInfo);
  62. STDMETHODIMP_(ULONG) GetFlags();
  63. STDMETHODIMP GetURL(const WCHAR **ppwcBuf);
  64. // IStream methods:
  65. STDMETHODIMP Read(void *pv, ULONG cb, ULONG *pcbRead);
  66. STDMETHODIMP Write(void const *pv, ULONG cb, ULONG *pcbWritten);
  67. STDMETHODIMP Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
  68. STDMETHODIMP SetSize(ULARGE_INTEGER libNewSize);
  69. STDMETHODIMP CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten);
  70. STDMETHODIMP Commit(DWORD grfCommitFlags);
  71. STDMETHODIMP Revert();
  72. STDMETHODIMP LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  73. STDMETHODIMP UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  74. STDMETHODIMP Stat(STATSTG *pstatstg, DWORD grfStatFlag);
  75. STDMETHODIMP Clone(IStream **ppIStream);
  76. CPrecompiledManifestReader():m_hFile(INVALID_HANDLE_VALUE),
  77. m_hFileMapping(INVALID_HANDLE_VALUE), m_lpMapAddress(NULL),
  78. m_ulLineNumberFromCreateNodeRecord(ULONG(-1)),
  79. m_dwFilePointer(0), m_dwFileSize(0),
  80. m_cRef(0) { }
  81. ~CPrecompiledManifestReader() { CSxsPreserveLastError ple; this->Close(); ple.Restore(); }
  82. HRESULT InvokeNodeFactory(PCWSTR pcmFileName, IXMLNodeFactory *pNodeFactory);
  83. VOID Reset();
  84. protected:
  85. HANDLE m_hFile;
  86. HANDLE m_hFileMapping;
  87. LPVOID m_lpMapAddress;
  88. ULONG m_ulLineNumberFromCreateNodeRecord;
  89. DWORD m_dwFilePointer; // should we limit the size of pcm file? Since manifest file is not very huge...
  90. DWORD m_dwFileSize;
  91. ULONG m_cRef;
  92. HRESULT Close(
  93. );
  94. HRESULT OpenForRead(
  95. IN PCWSTR pszPCMFileName,
  96. IN DWORD dwShareMode = FILE_SHARE_READ, // share mode
  97. IN DWORD dwCreationDisposition = OPEN_EXISTING, // how to create
  98. IN DWORD dwFlagsAndAttributes = FILE_FLAG_SEQUENTIAL_SCAN // file attributes
  99. );
  100. HRESULT ReadPCMHeader(
  101. OUT PCMHeader* pHeader
  102. );
  103. HRESULT ReadPCMRecordHeader(
  104. OUT PCM_RecordHeader * pHeader
  105. );
  106. HRESULT ReadPCMRecord(
  107. OUT XML_NODE_INFO ** ppNodes,
  108. OUT PCM_RecordHeader * pRecordHeader,
  109. OUT PVOID param
  110. );
  111. };
  112. class __declspec(uuid("1b345c93-eb16-4d07-b366-81e8a2b88414"))
  113. CPrecompiledManifestWriter : public IXMLNodeFactory {
  114. public :
  115. // IUnknown methods:
  116. STDMETHODIMP_(ULONG) AddRef();
  117. STDMETHODIMP_(ULONG) Release();
  118. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  119. // IXMLNodeFactory methods:
  120. STDMETHODIMP NotifyEvent(IXMLNodeSource *pSource, XML_NODEFACTORY_EVENT iEvt);
  121. STDMETHODIMP BeginChildren(IXMLNodeSource *pSource, XML_NODE_INFO *pNodeInfo);
  122. STDMETHODIMP EndChildren(IXMLNodeSource *pSource, BOOL fEmpty, XML_NODE_INFO *pNodeInfo);
  123. STDMETHODIMP Error(IXMLNodeSource *pSource, HRESULT hrErrorCode, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  124. STDMETHODIMP CreateNode(IXMLNodeSource *pSource, PVOID pNodeParent, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  125. // constructor and destructor
  126. CPrecompiledManifestWriter() : m_cRef(0), m_ulRecordCount(0), m_usMaxNodeCount(0) { }
  127. ~CPrecompiledManifestWriter() { }
  128. // write APIs
  129. HRESULT Initialize(
  130. PACTCTXGENCTX ActCtxGenCtx,
  131. PASSEMBLY Assembly,
  132. PACTCTXCTB_ASSEMBLY_CONTEXT AssemblyContext);
  133. HRESULT SetWriterStream(CPrecompiledManifestWriterStream * pSinkedStream); // usually, filename of PCM is not available when
  134. // the stream is opened. and stream is inited by caller
  135. HRESULT Initialize(PCWSTR pcmFileName);
  136. HRESULT WritePrecompiledManifestRecord(
  137. IN RECORD_TYPE_PRECOMP_MANIFEST typeID,
  138. IN PVOID pData,
  139. IN USHORT NodeCount,
  140. IN PVOID param = NULL
  141. );
  142. HRESULT SetFactory(IXMLNodeFactory *pNodeFactory);
  143. HRESULT Close();
  144. protected:
  145. CSmartRef<IXMLNodeFactory> m_pNodeFactory;
  146. CSmartRef<CPrecompiledManifestWriterStream> m_pFileStream;
  147. ULONG m_ulRecordCount;
  148. USHORT m_usMaxNodeCount;
  149. ULONG m_cRef;
  150. HRESULT GetPCMRecordSize(
  151. IN XML_NODE_INFO ** ppNodeInfo,
  152. IN USHORT iNodeCount,
  153. IN ULONG * pSize
  154. );
  155. HRESULT WritePCMHeader( // version is forced to be 1, and the recordCount is forced to be 0;
  156. );
  157. HRESULT WritePCMRecordHeader(
  158. IN PCM_RecordHeader * pHeader
  159. );
  160. HRESULT WritePCMXmlNodeInfo(
  161. IN XML_NODE_INFO ** ppNodeInfo,
  162. IN USHORT iNodeCount,
  163. IN RECORD_TYPE_PRECOMP_MANIFEST typeID,
  164. IN PVOID param
  165. );
  166. };
  167. #endif // _FUSION_SXS_PRECOMPILED_MANIFEST_H_INCLUDED_