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.

449 lines
12 KiB

  1. //+------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1991-1997 Microsoft Corporation.
  4. //
  5. // File: notifdoc.cxx
  6. //
  7. // Contents: Notification opened document interface
  8. //
  9. // Classes: CINOpenedDoc
  10. //
  11. // History: 24-Feb-97 SitaramR Created
  12. //
  13. //-------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include "notifdoc.hxx"
  17. #include "notprop.hxx"
  18. #include "infilter.hxx"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CINOpenedDoc::CINOpenedDoc
  22. //
  23. // Synopsis: Constructor
  24. //
  25. // Arguments: [xNotifTable] -- Notification table
  26. //
  27. // History: 24-Feb-97 SitaramR Created
  28. //
  29. //----------------------------------------------------------------------------
  30. CINOpenedDoc::CINOpenedDoc( XInterface<CIndexNotificationTable> & xNotifTable )
  31. : _widOpened( widInvalid ),
  32. _xNotifTable( xNotifTable.Acquire() ),
  33. _cRefs( 1 )
  34. {
  35. }
  36. //+-------------------------------------------------------------------------
  37. //
  38. // Method: CINOpenedDoc::AddRef
  39. //
  40. // Synopsis: Increments refcount
  41. //
  42. // History: 24-Feb-1997 SitaramR Created
  43. //
  44. //--------------------------------------------------------------------------
  45. ULONG STDMETHODCALLTYPE CINOpenedDoc::AddRef()
  46. {
  47. return InterlockedIncrement( (long *) &_cRefs );
  48. }
  49. //+-------------------------------------------------------------------------
  50. //
  51. // Method: CINOpenedDoc::Release
  52. //
  53. // Synopsis: Decrement refcount. Delete if necessary.
  54. //
  55. // History: 24-Feb-1997 SitaramR Created
  56. //
  57. //--------------------------------------------------------------------------
  58. ULONG STDMETHODCALLTYPE CINOpenedDoc::Release()
  59. {
  60. Win4Assert( _cRefs > 0 );
  61. ULONG uTmp = InterlockedDecrement( (long *) &_cRefs );
  62. if ( 0 == uTmp )
  63. delete this;
  64. return(uTmp);
  65. }
  66. //+-------------------------------------------------------------------------
  67. //
  68. // Method: CINOpenedDoc::QueryInterface
  69. //
  70. // Synopsis: Rebind to other interface
  71. //
  72. // Arguments: [riid] -- IID of new interface
  73. // [ppvObject] -- New interface * returned here
  74. //
  75. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  76. //
  77. // History: 24-Feb-1997 SitaramR Created
  78. //
  79. //--------------------------------------------------------------------------
  80. SCODE STDMETHODCALLTYPE CINOpenedDoc::QueryInterface( REFIID riid,
  81. void ** ppvObject)
  82. {
  83. Win4Assert( 0 != ppvObject );
  84. if ( riid == IID_ICiCOpenedDoc )
  85. *ppvObject = (void *)(ICiCOpenedDoc *) this;
  86. else if ( riid == IID_IUnknown )
  87. *ppvObject = (void *)(IUnknown *) this;
  88. else
  89. {
  90. *ppvObject = 0;
  91. return E_NOINTERFACE;
  92. }
  93. AddRef();
  94. return S_OK;
  95. }
  96. //+---------------------------------------------------------------------------
  97. //
  98. // Member: CINOpenedDoc::Open
  99. //
  100. // Synopsis: Opens the specified file
  101. //
  102. // Arguments: [pbDocName] - Pointer to the name
  103. // [cbDocName] - Length in BYTES of the name
  104. //
  105. // History: 24-Feb-97 SitaramR Created
  106. //
  107. //----------------------------------------------------------------------------
  108. SCODE CINOpenedDoc::Open ( BYTE const * pbDocName, ULONG cbDocName )
  109. {
  110. if ( _widOpened != widInvalid )
  111. return FILTER_E_ALREADY_OPEN;
  112. if ( cbDocName != sizeof( WORKID ) + sizeof( WCHAR ) )
  113. {
  114. //
  115. // Size should be serialized form of wid + null terminator
  116. //
  117. return E_INVALIDARG;
  118. }
  119. SCODE sc = S_OK;
  120. TRY
  121. {
  122. RtlCopyMemory( &_widOpened, pbDocName, sizeof(WORKID) );
  123. Win4Assert( _widOpened != widInvalid );
  124. if ( _widOpened == widInvalid )
  125. sc = E_INVALIDARG;
  126. else
  127. {
  128. CIndexNotificationEntry *pNotifEntry;
  129. BOOL fFound = _xNotifTable->Lookup( _widOpened, pNotifEntry );
  130. if ( fFound )
  131. _xName.Set( new CCiCDocName( (WCHAR *)pbDocName, sizeof(WORKID)/sizeof(WCHAR) ) );
  132. else
  133. {
  134. //
  135. // In push filtering model, wids are never refiled, and so the case of
  136. // a delete being refiled as a add cannot occur. Hence we shouldn't be
  137. // asked to open an unkwown wid. Hence the assert.
  138. //
  139. Win4Assert( !"Open: object not found" );
  140. sc = STATUS_OBJECT_NAME_NOT_FOUND;
  141. }
  142. }
  143. }
  144. CATCH( CException, e )
  145. {
  146. sc = e.GetErrorCode();
  147. ciDebugOut(( DEB_ERROR,
  148. "CINOpenedDoc::Open - Exception caught 0x%x\n",
  149. sc ));
  150. }
  151. END_CATCH;
  152. return sc;
  153. }
  154. //+---------------------------------------------------------------------------
  155. //
  156. // Member: CINOpenedDoc::Close
  157. //
  158. // Synopsis: Closes the opened file
  159. //
  160. // History: 24-Feb-97 SitaramR Created
  161. //
  162. //----------------------------------------------------------------------------
  163. SCODE STDMETHODCALLTYPE CINOpenedDoc::Close()
  164. {
  165. if ( _widOpened == widInvalid )
  166. return FILTER_E_NOT_OPEN;
  167. SCODE sc = S_OK;
  168. TRY
  169. {
  170. _widOpened = widInvalid;
  171. _xName.Free();
  172. }
  173. CATCH( CException, e )
  174. {
  175. sc = e.GetErrorCode();
  176. ciDebugOut(( DEB_ERROR,
  177. "CINOpenedDoc::Close - Exception caught 0x%x\n",
  178. sc ));
  179. }
  180. END_CATCH;
  181. return sc;
  182. }
  183. //+---------------------------------------------------------------------------
  184. //
  185. // Member: CINOpenedDoc::GetDocumentName
  186. //
  187. // Synopsis: Returns the interface to the document name
  188. //
  189. // Arguments: [ppIDocName] - Pointer to the returned document name
  190. //
  191. // History: 24-Feb-97 SitaramR Created
  192. //
  193. //----------------------------------------------------------------------------
  194. SCODE STDMETHODCALLTYPE CINOpenedDoc::GetDocumentName( ICiCDocName ** ppIDocName )
  195. {
  196. if ( _widOpened == widInvalid )
  197. return FILTER_E_NOT_OPEN;
  198. *ppIDocName = _xName.GetPointer();
  199. (*ppIDocName)->AddRef();
  200. return S_OK;
  201. }
  202. //+---------------------------------------------------------------------------
  203. //
  204. // Member: CINOpenedDoc::GetStatPropertyEnum
  205. //
  206. // Synopsis: Return property storage for the "stat" property set. This
  207. // property set is not really stored but is faked.
  208. //
  209. // Arguments: [ppIStatPropEnum] - Pointer to the returned IPropertyStorage
  210. // interface
  211. //
  212. // History: 24-Feb-97 SitaramR Created
  213. //
  214. //----------------------------------------------------------------------------
  215. SCODE STDMETHODCALLTYPE CINOpenedDoc::GetStatPropertyEnum( IPropertyStorage ** ppIStatPropEnum )
  216. {
  217. if ( _widOpened == widInvalid )
  218. return FILTER_E_NOT_OPEN;
  219. SCODE sc = S_OK;
  220. TRY
  221. {
  222. CINStatPropertyStorage *pStorage = new CINStatPropertyStorage;
  223. sc = pStorage->QueryInterface( IID_IPropertyStorage,
  224. (void **) ppIStatPropEnum );
  225. pStorage->Release(); // QI does an AddRef
  226. }
  227. CATCH( CException, e )
  228. {
  229. sc = e.GetErrorCode();
  230. ciDebugOut(( DEB_ERROR,
  231. "CINOpenedDoc::GetStatPropertyEnum - Exception caught 0x%x\n",
  232. sc ));
  233. }
  234. END_CATCH;
  235. return sc;
  236. }
  237. //+---------------------------------------------------------------------------
  238. //
  239. // Member: CINOpenedDoc::GetPropertySetEnum
  240. //
  241. // Synopsis: Returns the docfile property set storage interface on the
  242. // current doc.
  243. //
  244. // Arguments: [ppIPropSetEnum] - Returned pointer to the Docfile property
  245. // set storage
  246. //
  247. // History: 24-Feb-97 SitaramR Created
  248. //
  249. //----------------------------------------------------------------------------
  250. SCODE STDMETHODCALLTYPE CINOpenedDoc::GetPropertySetEnum( IPropertySetStorage ** ppIPropSetEnum )
  251. {
  252. if ( _widOpened == widInvalid )
  253. return FILTER_E_NOT_OPEN;
  254. //
  255. // No docfiles in push filtering model
  256. //
  257. *ppIPropSetEnum = 0;
  258. return FILTER_S_NO_PROPSETS;
  259. }
  260. //+---------------------------------------------------------------------------
  261. //
  262. // Member: CINOpenedDoc::GetPropertyEnum
  263. //
  264. // Synopsis: Return the property storage for a particular property set
  265. //
  266. // Arguments: [GuidPropSet] - GUID of the property set whose property
  267. // storage is being requested
  268. // [ppIPropEnum] - Returned pointer to property storage
  269. //
  270. // History: 24-Feb-97 SitaramR Created
  271. //
  272. //----------------------------------------------------------------------------
  273. SCODE STDMETHODCALLTYPE CINOpenedDoc::GetPropertyEnum( REFFMTID refGuidPropSet,
  274. IPropertyStorage **ppIPropEnum )
  275. {
  276. if ( _widOpened == widInvalid )
  277. return FILTER_E_NOT_OPEN;
  278. //
  279. // No property sets in push filtering
  280. //
  281. *ppIPropEnum = 0;
  282. return FILTER_E_NO_SUCH_PROPERTY;
  283. }
  284. //+---------------------------------------------------------------------------
  285. //
  286. // Member: CINOpenedDoc::GetIFilter
  287. //
  288. // Synopsis: Return the appropriate filter bound to the document
  289. //
  290. // Arguments: [ppIFilter] - Returned IFilter
  291. //
  292. // History: 24-Feb-97 SitaramR Created
  293. //
  294. //----------------------------------------------------------------------------
  295. SCODE STDMETHODCALLTYPE CINOpenedDoc::GetIFilter( IFilter ** ppIFilter )
  296. {
  297. if ( _widOpened == widInvalid )
  298. return FILTER_E_NOT_OPEN;
  299. SCODE sc = S_OK;
  300. TRY
  301. {
  302. CIndexNotificationEntry *pIndexEntry;
  303. BOOL fFound = _xNotifTable->Lookup( _widOpened, pIndexEntry );
  304. //
  305. // We checked this in the Open method
  306. //
  307. Win4Assert( fFound );
  308. pIndexEntry->AddRef();
  309. XInterface<CIndexNotificationEntry> xNotifEntry( pIndexEntry );
  310. CINFilter *pFilter = new CINFilter( xNotifEntry );
  311. sc = pFilter->QueryInterface( IID_IFilter, (void **)ppIFilter );
  312. pFilter->Release(); // QI does an AddRef
  313. }
  314. CATCH( CException, e )
  315. {
  316. sc = e.GetErrorCode();
  317. ciDebugOut(( DEB_ERROR,
  318. "CINOpenedDoc::GetIFilter - Exception caught 0x%x\n",
  319. sc ));
  320. }
  321. END_CATCH;
  322. return sc;
  323. }
  324. //+---------------------------------------------------------------------------
  325. //
  326. // Member: CINOpenedDoc::GetSecurity
  327. //
  328. // Synopsis: Retrieves security
  329. //
  330. // Arguments: [pbData] - Pointer to returned buffer containing security descriptor
  331. // [pcbData] - Input: size of buffer
  332. // Output: amount of buffer used, if successful, size needed
  333. // otherwise
  334. //
  335. // History: 24-Feb-97 SitaramR Created
  336. //
  337. //----------------------------------------------------------------------------
  338. SCODE STDMETHODCALLTYPE CINOpenedDoc::GetSecurity( BYTE * pbData, ULONG *pcbData )
  339. {
  340. if ( _widOpened == widInvalid )
  341. return FILTER_E_NOT_OPEN;
  342. //
  343. // Allow security access always
  344. //
  345. *pbData = 0;
  346. *pcbData = 0;
  347. return S_OK;
  348. }
  349. //+---------------------------------------------------------------------------
  350. //
  351. // Member: CINOpenedDoc::IsInUseByAnotherProcess
  352. //
  353. // Synopsis: Tests to see if the document is wanted by another process
  354. //
  355. // Arguments: [pfInUse] - Returned flag, TRUE => someone wants this document
  356. //
  357. // History: 24-Feb-97 SitaramR Created
  358. //
  359. //----------------------------------------------------------------------------
  360. SCODE STDMETHODCALLTYPE CINOpenedDoc::IsInUseByAnotherProcess( BOOL *pfInUse )
  361. {
  362. if ( _widOpened == widInvalid )
  363. return FILTER_E_NOT_OPEN;
  364. //
  365. // No oplocks in push filtering model
  366. //
  367. *pfInUse = FALSE;
  368. return S_OK;
  369. }