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.

232 lines
6.6 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: rpubdf.cxx
  7. //
  8. // Contents: CRootPubDocFile implementation
  9. //
  10. //---------------------------------------------------------------
  11. #include "dfhead.cxx"
  12. #include "h/header.hxx"
  13. #include "h/rexpdf.hxx"
  14. #include "dfbasis.hxx"
  15. #include "h/tchar.h"
  16. // Priority mode lock permissions
  17. #define PRIORITY_PERMS DF_READ
  18. //+--------------------------------------------------------------
  19. //
  20. // Member: CRootExposedDocFile::CRootExposedDocFile, public
  21. //
  22. // Synopsis: Ctor - Initializes empty object
  23. //
  24. //---------------------------------------------------------------
  25. CRootExposedDocFile::CRootExposedDocFile(CDFBasis *pdfb) :
  26. CExposedDocFile(NULL, NULL, 0, ROOT_LUID, NULL, NULL, NULL, pdfb)
  27. {
  28. olDebugOut((DEB_ITRACE, "CRootExposedDocFile constructor called\n"));
  29. }
  30. //+--------------------------------------------------------------
  31. //
  32. // Member: CRootExposedDocFile::Init, private
  33. //
  34. // Synopsis: Dependent root initialization
  35. //
  36. // Arguments: [plstBase] - Base
  37. // [snbExclude] - Limited instantiation exclusions
  38. // [dwStartFlags] - Startup flags
  39. //
  40. // Returns: Appropriate status code
  41. //
  42. //---------------------------------------------------------------
  43. SCODE CRootExposedDocFile::Init( ILockBytes *plstBase,
  44. SNBW snbExclude,
  45. DWORD const dwStartFlags)
  46. {
  47. CDocFile *pdf;
  48. SCODE sc;
  49. CMStream *pms;
  50. olDebugOut((DEB_ITRACE, "In CRootExposedDocFile::Init()\n"));
  51. if (snbExclude)
  52. {
  53. olChk(DllMultiStreamFromStream(&pms, &plstBase, dwStartFlags));
  54. olMemTo(EH_pms,
  55. pdf = new CDocFile(pms, SIDROOT, ROOT_LUID, _pilbBase));
  56. pdf->AddRef();
  57. olChkTo(EH_pdf, pdf->ExcludeEntries(pdf, snbExclude));
  58. olChkTo(EH_pdf, pms->Flush(0));
  59. pdf->Release();
  60. }
  61. plstBase->AddRef();
  62. _pilbBase = plstBase;
  63. olDebugOut((DEB_ITRACE, "Out CRootExposedDocFile::Init()\n"));
  64. return S_OK;
  65. EH_pdf:
  66. pdf->Release();
  67. EH_pms:
  68. DllReleaseMultiStream(pms);
  69. EH_Err:
  70. return sc;
  71. }
  72. //+--------------------------------------------------------------
  73. //
  74. // Member: CRootExposedDocFile::InitRoot, public
  75. //
  76. // Synopsis: Initialising a root storage
  77. //
  78. // Arguments: [plstBase] - Base LStream
  79. // [dwStartFlags] - How to start things
  80. // [df] - Transactioning flags
  81. // [snbExclude] - Parital instantiation list
  82. // [ppdfb] - Basis pointer return
  83. //
  84. // Returns: Appropriate status code
  85. //
  86. // Modifies: [ppdfb]
  87. //
  88. //---------------------------------------------------------------
  89. SCODE CRootExposedDocFile::InitRoot( ILockBytes *plstBase,
  90. DWORD const dwStartFlags,
  91. DFLAGS const df,
  92. SNBW snbExclude)
  93. {
  94. CDocFile *pdfBase;
  95. SCODE sc, scConv = S_OK;
  96. STATSTG statstg;
  97. olDebugOut((DEB_ITRACE, "In CRootExposedDocFile::InitRoot("
  98. "%p, %lX, %lX, %p)\n",
  99. plstBase, dwStartFlags, df, snbExclude));
  100. // Exclusion only works with a plain open
  101. olAssert(snbExclude == NULL ||
  102. (dwStartFlags & (RSF_CREATEFLAGS | RSF_CONVERT)) == 0);
  103. olHChk(plstBase->Stat(&statstg, STATFLAG_NONAME));
  104. olChkTo(EH_GetPriority,
  105. Init(plstBase, snbExclude, dwStartFlags));
  106. scConv = DllMultiStreamFromStream(&_pmsBase, &_pilbBase,
  107. dwStartFlags);
  108. if (scConv == STG_E_INVALIDHEADER)
  109. scConv = STG_E_FILEALREADYEXISTS;
  110. olChkTo(EH_pfstScratchInit, scConv);
  111. olMemTo(EH_pmsBase,
  112. pdfBase = new CDocFile(_pmsBase, SIDROOT, ROOT_LUID, _pilbBase));
  113. pdfBase->AddRef();
  114. _pdf = pdfBase;
  115. _df = df;
  116. olDebugOut((DEB_ITRACE, "Out CRootExposedDocFile::InitRoot\n"));
  117. return scConv;
  118. EH_pmsBase:
  119. DllReleaseMultiStream(_pmsBase);
  120. EH_pfstScratchInit:
  121. EH_GetPriority:
  122. EH_Err:
  123. return sc;
  124. }
  125. //+--------------------------------------------------------------
  126. //
  127. // Member: CRootExposedDocFile::~CRootExposedDocFile,
  128. // public virutal
  129. //
  130. // Synopsis: dtor (virtual)
  131. //
  132. //---------------------------------------------------------------
  133. CRootExposedDocFile::~CRootExposedDocFile(void)
  134. {
  135. olDebugOut((DEB_TRACE, "In CRootExposedDocFile::~CRootExposedDocFile\n"));
  136. olAssert(_cReferences == 0);
  137. if (SUCCEEDED(CheckReverted()))
  138. {
  139. if (_pilbBase) {
  140. _pilbBase->Release();
  141. _pilbBase = NULL;
  142. }
  143. }
  144. olDebugOut((DEB_TRACE, "Out CRootExposedDocFile::~CRootExposedDocFile\n"));
  145. }
  146. //+-------------------------------------------------------------------
  147. //
  148. // Member: CRootExposedDocFile::Stat, public
  149. // virtual fr. CExposedDocFile
  150. //
  151. // Synopsis: Fills in a stat buffer from the base LStream
  152. //
  153. // Arguments: [pstatstg] - Stat buffer
  154. // [grfStatFlag] - Stat flags
  155. //
  156. // Returns: Appropriate status code
  157. //
  158. // Modifies: [pstatstg]
  159. //
  160. //--------------------------------------------------------------------
  161. SCODE CRootExposedDocFile::Stat(STATSTGW *pstatstgw, DWORD grfStatFlag)
  162. {
  163. SCODE sc;
  164. STATSTG *pstatstg= (STATSTG*)pstatstgw;
  165. olDebugOut((DEB_ITRACE, "In CRootExposedDocFile::Stat(%p, %lu)\n",
  166. pstatstg, grfStatFlag));
  167. olChk(ValidateOutBuffer(pstatstg, sizeof(STATSTGW)));
  168. olChk(VerifyStatFlag(grfStatFlag));
  169. olChk(CheckReverted());
  170. olHChk(_pilbBase->Stat(pstatstg, grfStatFlag));
  171. pstatstg->type = STGTY_STORAGE;
  172. ULISet32(pstatstg->cbSize, 0); // size undefined for storage obj
  173. pstatstg->grfLocksSupported = 0;
  174. pstatstg->reserved = 0;
  175. if (pstatstg->pwcsName)
  176. {
  177. // pilbBase returns either wide or ansi names depending on
  178. // system type, so we have to convert to ANSI char if neccessay
  179. WCHAR *pwcs;
  180. olChkTo(EH_pwcsName,
  181. DfAllocWC(_tcslen(pstatstg->pwcsName)+1, &pwcs));
  182. TTOW(pstatstg->pwcsName, pwcs, _tcslen(pstatstg->pwcsName)+1);
  183. delete[] pstatstg->pwcsName;
  184. pstatstgw->pwcsName = pwcs;
  185. }
  186. pstatstg->grfMode = DFlagsToMode(_df);
  187. olChkTo(EH_pwcsName, _pdf->GetClass(&pstatstg->clsid));
  188. olChkTo(EH_pwcsName, _pdf->GetStateBits(&pstatstg->grfStateBits));
  189. olDebugOut((DEB_ITRACE, "Out CRootExposedDocFile::Stat\n"));
  190. return S_OK;
  191. EH_pwcsName:
  192. if (pstatstg->pwcsName)
  193. delete[] pstatstg->pwcsName;
  194. EH_Err:
  195. return sc;
  196. }