Source code of Windows XP (NT5)
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.

1541 lines
32 KiB

  1. /***********************************************************************
  2. *
  3. * ABCTBL3.C
  4. *
  5. * Contents Table - Part 3.
  6. *
  7. *
  8. * The following routines are implemented in this file.
  9. *
  10. *
  11. * IVTABC_QueryInterface
  12. * IVTABC_Release
  13. * IVTABC_SortTable
  14. * IVTABC_QuerySortOrder
  15. * IVTABC_CreateBookmark
  16. * IVTABC_FreeBookmark
  17. * IVTABC_ExpandRow
  18. * IVTABC_ColapseRow
  19. * IVTABC_WaitForCompletion
  20. * IVTABC_Abort
  21. * IVTABC_Advise
  22. * IVTABC_Unadvise
  23. * IVTABC_GetStatus
  24. * IVTABC_SetColumns
  25. * IVTABC_QueryColumns
  26. * IVTABC_GetCollapseState,
  27. * IVTABC_SetCollapseState,
  28. *
  29. * Copyright 1992, 1993, 1994 Microsoft Corporation. All Rights Reserved.
  30. *
  31. ***********************************************************************/
  32. #include "faxab.h"
  33. /*
  34. * Default sort order set
  35. */
  36. static const SizedSSortOrderSet(1, sosIVTABC) =
  37. {
  38. 1,
  39. 0,
  40. 0,
  41. {
  42. {
  43. PR_DISPLAY_NAME, TABLE_SORT_ASCEND
  44. }
  45. }
  46. };
  47. /*************************************************************************
  48. *
  49. *
  50. - AVTABC_QueryInterface
  51. -
  52. *
  53. *
  54. *
  55. */
  56. STDMETHODIMP
  57. IVTABC_QueryInterface( LPIVTABC lpIVTAbc,
  58. REFIID lpiid,
  59. LPVOID FAR * lppNewObj
  60. )
  61. {
  62. HRESULT hResult = hrSuccess;
  63. /* Minimally validate the lpIVTAbc parameter */
  64. /*
  65. * Check to see if it's big enough to be this object
  66. */
  67. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  68. {
  69. /*
  70. * Not big enough
  71. */
  72. hResult = ResultFromScode(E_INVALIDARG);
  73. goto out;
  74. }
  75. /*
  76. * Check to see that it's the correct vtbl
  77. */
  78. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  79. {
  80. /*
  81. * Not my vtbl
  82. */
  83. hResult = ResultFromScode(E_INVALIDARG);
  84. goto out;
  85. }
  86. /* Check other parameters */
  87. if ( IsBadReadPtr( lpiid, (UINT) SIZEOF(IID)) ||
  88. IsBadWritePtr( lppNewObj, (UINT) SIZEOF(LPVOID))
  89. )
  90. {
  91. DebugTraceSc(IVTABC_QueryInterface, E_INVALIDARG);
  92. return ResultFromScode(E_INVALIDARG);
  93. }
  94. /* See if the requested interface is one of ours */
  95. if (memcmp(lpiid, &IID_IUnknown, SIZEOF(IID)) &&
  96. memcmp(lpiid, &IID_IMAPITable, SIZEOF(IID)))
  97. {
  98. *lppNewObj = NULL; /* OLE requires zeroing the [out] parameter */
  99. DebugTraceSc(IVTABC_QueryInterface, E_NOINTERFACE);
  100. return ResultFromScode(E_NOINTERFACE);
  101. }
  102. /* We'll do this one. Bump the usage count and return a new pointer. */
  103. EnterCriticalSection(&lpIVTAbc->cs);
  104. ++lpIVTAbc->lcInit;
  105. LeaveCriticalSection(&lpIVTAbc->cs);
  106. *lppNewObj = lpIVTAbc;
  107. out:
  108. DebugTraceResult(IVTABC_QueryInterface,hResult);
  109. return hResult;
  110. }
  111. /*************************************************************************
  112. *
  113. - IVTABC_Release
  114. -
  115. *
  116. * Decrement the reference count on this object and free it if
  117. * the reference count is zero.
  118. * Returns the reference count.
  119. */
  120. STDMETHODIMP_(ULONG)
  121. IVTABC_Release(LPIVTABC lpIVTAbc)
  122. {
  123. ULONG ulBK;
  124. long lcInit;
  125. /*
  126. * Check to see if it's big enough to hold this object
  127. */
  128. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  129. {
  130. /*
  131. * Not large enough
  132. */
  133. return 1;
  134. }
  135. /*
  136. * Check to see that it's the correct vtbl
  137. */
  138. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  139. {
  140. /*
  141. * Not my vtbl
  142. */
  143. return 1;
  144. }
  145. EnterCriticalSection(&lpIVTAbc->cs);
  146. lcInit = --lpIVTAbc->lcInit;
  147. LeaveCriticalSection(&lpIVTAbc->cs);
  148. if (lcInit == 0)
  149. {
  150. /*
  151. * Free up the current column set
  152. */
  153. if (lpIVTAbc->lpPTAColSet != ptagaivtabcColSet)
  154. {
  155. lpIVTAbc->lpFreeBuff (lpIVTAbc->lpPTAColSet);
  156. }
  157. /*
  158. * Close up the file
  159. */
  160. if (lpIVTAbc->hFile != INVALID_HANDLE_VALUE)
  161. {
  162. CloseHandle(lpIVTAbc->hFile);
  163. lpIVTAbc->hFile = INVALID_HANDLE_VALUE;
  164. }
  165. /*
  166. * Free up the file name
  167. */
  168. lpIVTAbc->lpFreeBuff(lpIVTAbc->lpszFileName);
  169. /*
  170. * Rip through the bookmarks and free up any that are there
  171. */
  172. for (ulBK = 0; ulBK < MAX_BOOKMARKS; ulBK++)
  173. if (lpIVTAbc->rglpABCBK[ulBK])
  174. {
  175. (*(lpIVTAbc->lpFreeBuff)) (lpIVTAbc->rglpABCBK[ulBK]);
  176. lpIVTAbc->rglpABCBK[ulBK] = NULL;
  177. }
  178. /*
  179. * Free up the ANR stuff, if used
  180. */
  181. lpIVTAbc->lpFreeBuff (lpIVTAbc->lpszPartialName);
  182. FreeANRBitmaps(lpIVTAbc);
  183. /*
  184. * Free up the advise list, if used
  185. */
  186. if (lpIVTAbc->parglpAdvise)
  187. lpIVTAbc->lpMalloc->lpVtbl->Free(lpIVTAbc->lpMalloc, lpIVTAbc->parglpAdvise);
  188. /* Delete critical section for this object */
  189. DeleteCriticalSection(&lpIVTAbc->cs);
  190. /* Deregister the idle routine */
  191. DeregisterIdleRoutine(lpIVTAbc->ftg);
  192. /*
  193. * Set the vtbl to NULL. This way the client will find out
  194. * real fast if it's calling a method on a released object. That is,
  195. * the client will crash. Hopefully, this will happen during the
  196. * development stage of the client.
  197. */
  198. lpIVTAbc->lpVtbl = NULL;
  199. /*
  200. * Need to free the object
  201. */
  202. lpIVTAbc->lpFreeBuff(lpIVTAbc);
  203. return 0;
  204. }
  205. return lcInit;
  206. }
  207. /*
  208. - IVTABC_SortTable
  209. -
  210. * The Microsoft At Work Fax Address Book does not resort it's views.
  211. *
  212. */
  213. STDMETHODIMP
  214. IVTABC_SortTable( LPIVTABC lpIVTAbc,
  215. LPSSortOrderSet lpSortCriteria,
  216. ULONG ulFlags
  217. )
  218. {
  219. HRESULT hResult;
  220. /*
  221. * Validate parameters
  222. */
  223. /*
  224. * Check to see if it's big enough to hold this object
  225. */
  226. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  227. {
  228. /*
  229. * Not large enough
  230. */
  231. hResult = ResultFromScode(E_INVALIDARG);
  232. goto out;
  233. }
  234. /*
  235. * Check to see that it's the correct vtbl
  236. */
  237. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  238. {
  239. /*
  240. * Not my vtbl
  241. */
  242. hResult = ResultFromScode(E_INVALIDARG);
  243. goto out;
  244. }
  245. /*
  246. * Check for bad sort order set. This is from the mapi utilities DLL.
  247. */
  248. if (FBadSortOrderSet(lpSortCriteria))
  249. {
  250. hResult = ResultFromScode(MAPI_E_UNKNOWN_FLAGS);
  251. goto out;
  252. }
  253. /*
  254. * Check flags
  255. */
  256. if (ulFlags & ~(TBL_ASYNC|TBL_BATCH))
  257. {
  258. hResult = ResultFromScode(MAPI_E_UNKNOWN_FLAGS);
  259. goto out;
  260. }
  261. /*
  262. * We don't support sorting this table
  263. */
  264. hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  265. out:
  266. DebugTraceResult(IVTABC_SortTable, hResult);
  267. return hResult;
  268. }
  269. /*
  270. - IVTABC_QuerySortOrder
  271. -
  272. *
  273. * For this implementation there is only one sort order
  274. */
  275. STDMETHODIMP
  276. IVTABC_QuerySortOrder( LPIVTABC lpIVTAbc,
  277. LPSSortOrderSet * lppSortCriteria
  278. )
  279. {
  280. SCODE scode;
  281. HRESULT hResult = hrSuccess;
  282. int cbSize;
  283. /*
  284. * Validate parameters
  285. */
  286. /*
  287. * Check to see if it's large enough to hold this object
  288. */
  289. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  290. {
  291. /*
  292. * Not large enough
  293. */
  294. hResult = ResultFromScode(E_INVALIDARG);
  295. goto out;
  296. }
  297. /*
  298. * Check to see that it's the correct vtbl
  299. */
  300. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  301. {
  302. /*
  303. * Not my vtbl
  304. */
  305. hResult = ResultFromScode(E_INVALIDARG);
  306. goto out;
  307. }
  308. /*
  309. * Check the out parameter for writability
  310. */
  311. if (IsBadWritePtr(lppSortCriteria, sizeof(LPSSortOrderSet)))
  312. {
  313. hResult = ResultFromScode(E_INVALIDARG);
  314. goto out;
  315. }
  316. /* Calculate size of the structure we're gonna copy */
  317. cbSize = CbNewSSortOrderSet((int)sosIVTABC.cSorts);
  318. scode = lpIVTAbc->lpAllocBuff(cbSize, (LPVOID *) lppSortCriteria);
  319. if (FAILED(scode))
  320. {
  321. hResult = ResultFromScode(scode);
  322. goto out;
  323. }
  324. /*
  325. * Copy the column set in
  326. */
  327. if (cbSize)
  328. memcpy(*lppSortCriteria, &sosIVTABC, cbSize);
  329. out:
  330. DebugTraceResult(IVTABC_QuerySortOrder, hResult);
  331. return hResult;
  332. }
  333. /*
  334. - IVTABC_CreateBookmark
  335. -
  336. * Creates a bookmark associated with a row in a table
  337. *
  338. */
  339. STDMETHODIMP
  340. IVTABC_CreateBookmark( LPIVTABC lpIVTAbc,
  341. BOOKMARK * lpbkPosition
  342. )
  343. {
  344. SCODE scode;
  345. HRESULT hResult = hrSuccess;
  346. ULONG ulBK;
  347. LPABCBK lpABCBK = NULL;
  348. ULONG cbRead = 0;
  349. /*
  350. * Validate parameters
  351. */
  352. /*
  353. * Check to see if it's large enough to hold this object
  354. */
  355. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  356. {
  357. /*
  358. * Not large enough
  359. */
  360. hResult = ResultFromScode(E_INVALIDARG);
  361. DebugTraceResult(IVTABC_CreateBookmark, hResult);
  362. return hResult;
  363. }
  364. /*
  365. * Check to see that it's the correct vtbl
  366. */
  367. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  368. {
  369. /*
  370. * Not my vtbl
  371. */
  372. hResult = ResultFromScode(E_INVALIDARG);
  373. DebugTraceResult(IVTABC_CreateBookmark, hResult);
  374. return hResult;
  375. }
  376. /*
  377. * Check the out parameter for writability
  378. */
  379. if (IsBadWritePtr(lpbkPosition, SIZEOF(BOOKMARK)))
  380. {
  381. hResult = ResultFromScode(E_INVALIDARG);
  382. DebugTraceResult(IVTABC_CreateBookmark, hResult);
  383. return hResult;
  384. }
  385. EnterCriticalSection(&lpIVTAbc->cs);
  386. /*
  387. * Open the file
  388. */
  389. hResult = HrOpenFile(lpIVTAbc);
  390. if (HR_FAILED(hResult))
  391. {
  392. goto out;
  393. }
  394. /*
  395. * Shortcuts first
  396. */
  397. if (lpIVTAbc->ulPosition == lpIVTAbc->ulMaxPos)
  398. {
  399. *lpbkPosition = BOOKMARK_END;
  400. return hrSuccess;
  401. }
  402. /*
  403. * search for a blank bookmark
  404. */
  405. for (ulBK = 0; lpIVTAbc->rglpABCBK[ulBK] && ulBK < MAX_BOOKMARKS; ulBK++);
  406. /* did we find any?? */
  407. if (ulBK == MAX_BOOKMARKS)
  408. {
  409. hResult = ResultFromScode(MAPI_E_UNABLE_TO_COMPLETE);
  410. goto out;
  411. }
  412. scode = lpIVTAbc->lpAllocBuff (SIZEOF(ABCBK),(LPVOID *) &lpABCBK);
  413. if (FAILED(scode))
  414. {
  415. hResult = ResultFromScode(scode);
  416. goto out;
  417. }
  418. /*
  419. * Fill in new bookmark
  420. */
  421. lpABCBK->filetime = lpIVTAbc->filetime;
  422. lpABCBK->ulPosition = lpIVTAbc->ulPosition;
  423. /* Seek to position in file */
  424. (void) SetFilePointer(lpIVTAbc->hFile, lpABCBK->ulPosition, NULL, FILE_BEGIN);
  425. /* Read in the record at that location */
  426. if (!ReadFile(lpIVTAbc->hFile,
  427. (LPVOID) &(lpABCBK->abcrec), SIZEOF(ABCREC), &cbRead, NULL))
  428. {
  429. goto readerror;
  430. }
  431. /* Second check */
  432. if (cbRead != sizeof(ABCREC))
  433. {
  434. goto readerror;
  435. }
  436. /*
  437. * Put this in the bookmark structure
  438. */
  439. lpIVTAbc->rglpABCBK[ulBK] = lpABCBK;
  440. /* Return the bookmark */
  441. *lpbkPosition = ulBK + 3;
  442. out:
  443. LeaveCriticalSection(&lpIVTAbc->cs);
  444. DebugTraceResult(IVTABC_CreateBookmark, hResult);
  445. return hResult;
  446. readerror:
  447. /*
  448. * Didn't get the record.
  449. */
  450. /* Restore back to original position */
  451. (void) SetFilePointer(lpIVTAbc->hFile, lpIVTAbc->ulPosition, NULL, FILE_BEGIN);
  452. /* Free up the new bookmark */
  453. lpIVTAbc->lpFreeBuff(lpABCBK);
  454. hResult = ResultFromScode(MAPI_E_UNABLE_TO_COMPLETE);
  455. SetErrorIDS(lpIVTAbc, hResult, IDS_FAB_NO_READ);
  456. goto out;
  457. }
  458. /*************************************************************************
  459. *
  460. - IVTABC_FreeBookmark
  461. -
  462. * Frees up the given bookmark
  463. *
  464. *
  465. *
  466. */
  467. STDMETHODIMP
  468. IVTABC_FreeBookmark( LPIVTABC lpIVTAbc,
  469. BOOKMARK bkPosition
  470. )
  471. {
  472. HRESULT hResult = hrSuccess;
  473. /*
  474. * Validate parameters
  475. */
  476. /*
  477. * Check to see if it's large enough to hold this object
  478. */
  479. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  480. {
  481. /*
  482. * Not large enough
  483. */
  484. hResult = ResultFromScode(E_INVALIDARG);
  485. DebugTraceResult(IVTABC_FreeBookmark, hResult);
  486. return hResult;
  487. }
  488. /*
  489. * Check to see that it's the correct vtbl
  490. */
  491. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  492. {
  493. /*
  494. * Not my vtbl
  495. */
  496. hResult = ResultFromScode(E_INVALIDARG);
  497. DebugTraceResult(IVTABC_FreeBookmark, hResult);
  498. return hResult;
  499. }
  500. EnterCriticalSection(&lpIVTAbc->cs);
  501. /*
  502. * Don't try and free up any of the standard bookmarks
  503. */
  504. if ((bkPosition != BOOKMARK_BEGINNING) &&
  505. (bkPosition != BOOKMARK_CURRENT) &&
  506. (bkPosition != BOOKMARK_END))
  507. {
  508. ULONG ulBK = (ULONG) bkPosition - 3;
  509. /*
  510. * See if it's in range
  511. */
  512. if (ulBK >= 0 && ulBK < MAX_BOOKMARKS)
  513. {
  514. LPABCBK lpABCBK = NULL;
  515. /* If it's valid... */
  516. if (lpABCBK = lpIVTAbc->rglpABCBK[ulBK]) /* '=' on purpose */
  517. {
  518. /* ...free it up. */
  519. lpIVTAbc->lpFreeBuff(lpABCBK);
  520. lpIVTAbc->rglpABCBK[ulBK] = NULL;
  521. }
  522. }
  523. else
  524. {
  525. /*
  526. * It's an error
  527. */
  528. hResult = ResultFromScode(E_INVALIDARG);
  529. }
  530. }
  531. LeaveCriticalSection(&lpIVTAbc->cs);
  532. DebugTraceResult(IVTABC_FreeBookmark, hResult);
  533. return hResult;
  534. }
  535. /*************************************************************************
  536. *
  537. - IVTABC_ExpandRow
  538. -
  539. * Stubbed out. This table doesn't implement catagorization.
  540. *
  541. *
  542. *
  543. */
  544. STDMETHODIMP
  545. IVTABC_ExpandRow( LPIVTABC lpIVTAbc,
  546. ULONG cbIKey,
  547. LPBYTE pbIKey,
  548. ULONG ulRowCount,
  549. ULONG ulFlags,
  550. LPSRowSet FAR * lppRows,
  551. ULONG FAR * lpulMoreRows
  552. )
  553. {
  554. HRESULT hResult;
  555. /*
  556. * Validate parameters
  557. */
  558. /*
  559. * Check to see if it's large enough to hold this object
  560. */
  561. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  562. {
  563. /*
  564. * Not large enough
  565. */
  566. hResult = ResultFromScode(E_INVALIDARG);
  567. DebugTraceResult(IVTABC_ExpandRow, hResult);
  568. return hResult;
  569. }
  570. /*
  571. * Check to see that it's the correct vtbl
  572. */
  573. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  574. {
  575. /*
  576. * Not my vtbl
  577. */
  578. hResult = ResultFromScode(E_INVALIDARG);
  579. DebugTraceResult(IVTABC_ExpandRow, hResult);
  580. return hResult;
  581. }
  582. hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  583. DebugTraceResult(IVTABC_ExpandRow, hResult);
  584. return hResult;
  585. }
  586. /*************************************************************************
  587. *
  588. - IVTABC_CollapseRow
  589. -
  590. * Stubbed out. This table doesn't implement catagorization.
  591. *
  592. *
  593. *
  594. */
  595. STDMETHODIMP
  596. IVTABC_CollapseRow( LPIVTABC lpIVTAbc,
  597. ULONG cbIKey,
  598. LPBYTE pbIKey,
  599. ULONG ulFlags,
  600. ULONG FAR * lpulRowCount
  601. )
  602. {
  603. HRESULT hResult;
  604. /*
  605. * Validate parameters
  606. */
  607. /*
  608. * Check to see if it's large enough to hold this object
  609. */
  610. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  611. {
  612. /*
  613. * Not large enough
  614. */
  615. hResult = ResultFromScode(E_INVALIDARG);
  616. DebugTraceResult(IVTABC_CollapseRow, hResult);
  617. return hResult;
  618. }
  619. /*
  620. * Check to see that it's the correct vtbl
  621. */
  622. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  623. {
  624. /*
  625. * Not my vtbl
  626. */
  627. hResult = ResultFromScode(E_INVALIDARG);
  628. DebugTraceResult(IVTABC_CollapseRow, hResult);
  629. return hResult;
  630. }
  631. hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  632. DebugTraceResult(IVTABC_CollapseRow, hResult);
  633. return hResult;
  634. }
  635. /*************************************************************************
  636. *
  637. - IVTABC_WaitForCompletion
  638. -
  639. * Stubbed out.
  640. *
  641. *
  642. *
  643. */
  644. STDMETHODIMP
  645. IVTABC_WaitForCompletion( LPIVTABC lpIVTAbc,
  646. ULONG ulFlags,
  647. ULONG ulTimeout,
  648. ULONG FAR * lpulTableStatus
  649. )
  650. {
  651. HRESULT hResult;
  652. /*
  653. * Validate parameters
  654. */
  655. /*
  656. * Check to see if it's large enough to hold this object
  657. */
  658. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  659. {
  660. /*
  661. * Not large enough
  662. */
  663. hResult = ResultFromScode(E_INVALIDARG);
  664. DebugTraceResult(IVTABC_WaitForCompletion, hResult);
  665. return hResult;
  666. }
  667. /*
  668. * Check to see that it's the correct vtbl
  669. */
  670. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  671. {
  672. /*
  673. * Not my vtbl
  674. */
  675. hResult = ResultFromScode(E_INVALIDARG);
  676. DebugTraceResult(IVTABC_WaitForCompletion, hResult);
  677. return hResult;
  678. }
  679. hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  680. DebugTraceResult(IVTABC_WaitForCompletion, hResult);
  681. return hResult;
  682. }
  683. /*************************************************************************
  684. *
  685. - IVTABC_Abort
  686. -
  687. * Nothing ever to abort...
  688. *
  689. *
  690. *
  691. */
  692. STDMETHODIMP
  693. IVTABC_Abort(LPIVTABC lpIVTAbc)
  694. {
  695. HRESULT hResult;
  696. /*
  697. * Validate parameters
  698. */
  699. /*
  700. * Check to see if it's large enough to hold this object
  701. */
  702. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  703. {
  704. /*
  705. * Not large enough
  706. */
  707. hResult = ResultFromScode(E_INVALIDARG);
  708. DebugTraceResult(IVTABC_Abort, hResult);
  709. return hResult;
  710. }
  711. /*
  712. * Check to see that it's the correct vtbl
  713. */
  714. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  715. {
  716. /*
  717. * Not my vtbl
  718. */
  719. hResult = ResultFromScode(E_INVALIDARG);
  720. DebugTraceResult(IVTABC_Abort, hResult);
  721. return hResult;
  722. }
  723. return hrSuccess;
  724. }
  725. /*************************************************************************
  726. *
  727. *
  728. - IVTABC_Advise
  729. -
  730. *
  731. *
  732. *
  733. */
  734. STDMETHODIMP
  735. IVTABC_Advise( LPIVTABC lpIVTAbc,
  736. ULONG ulEventmask,
  737. LPMAPIADVISESINK lpAdviseSink,
  738. ULONG FAR * lpulConnection
  739. )
  740. {
  741. HRESULT hResult = hrSuccess;
  742. UINT iAdvise;
  743. /*
  744. * Check to see if it's large enough to hold this object
  745. */
  746. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  747. {
  748. /*
  749. * Not large enough
  750. */
  751. DebugTraceSc(IVTABC_Advise, E_INVALIDARG);
  752. return ResultFromScode(E_INVALIDARG);
  753. }
  754. /*
  755. * Check to see that it's the correct vtbl
  756. */
  757. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  758. {
  759. /*
  760. * Not my vtbl
  761. */
  762. hResult = ResultFromScode(E_INVALIDARG);
  763. DebugTraceResult(IVTABC_Advise, hResult);
  764. return hResult;
  765. }
  766. /*
  767. * Validate the parameters
  768. */
  769. if ((ulEventmask & ~(ULONG) fnevTableModified) ||
  770. IsBadReadPtr(lpAdviseSink, SIZEOF(LPVOID)) ||
  771. IsBadReadPtr(lpAdviseSink->lpVtbl, 3 * SIZEOF(LPVOID)) ||
  772. IsBadWritePtr(lpulConnection, SIZEOF(ULONG)))
  773. {
  774. DebugTraceSc(IVTABC_Advise, E_INVALIDARG);
  775. return ResultFromScode(E_INVALIDARG);
  776. }
  777. /* Get the Critical Section */
  778. EnterCriticalSection(&lpIVTAbc->cs);
  779. for (iAdvise = 0;
  780. lpIVTAbc->parglpAdvise && iAdvise < lpIVTAbc->cAdvise;
  781. ++iAdvise)
  782. {
  783. if (lpIVTAbc->parglpAdvise[iAdvise] == NULL)
  784. break;
  785. }
  786. if (iAdvise >= lpIVTAbc->cAdvise)
  787. {
  788. /*
  789. * Realloc the array if it exists
  790. */
  791. if (lpIVTAbc->parglpAdvise)
  792. {
  793. lpIVTAbc->parglpAdvise = lpIVTAbc->lpMalloc->lpVtbl->Realloc(
  794. lpIVTAbc->lpMalloc,
  795. lpIVTAbc->parglpAdvise,
  796. (lpIVTAbc->cAdvise + 1) * SIZEOF(LPMAPIADVISESINK));
  797. }
  798. else
  799. {
  800. lpIVTAbc->parglpAdvise = lpIVTAbc->lpMalloc->lpVtbl->Alloc(
  801. lpIVTAbc->lpMalloc,
  802. (lpIVTAbc->cAdvise + 1) * SIZEOF(LPMAPIADVISESINK));
  803. }
  804. /*
  805. * Could we get the desired memory?
  806. */
  807. if (lpIVTAbc->parglpAdvise == NULL)
  808. {
  809. hResult = MakeResult(E_OUTOFMEMORY);
  810. goto ret;
  811. }
  812. }
  813. lpIVTAbc->cAdvise++;
  814. *lpulConnection = lpIVTAbc->ulConnectMic + iAdvise;
  815. lpIVTAbc->parglpAdvise[iAdvise] = lpAdviseSink;
  816. lpAdviseSink->lpVtbl->AddRef(lpAdviseSink);
  817. ret:
  818. /* leave critical section */
  819. LeaveCriticalSection(&lpIVTAbc->cs);
  820. DebugTraceResult(IVTABC_Advise, hResult);
  821. return hResult;
  822. }
  823. /*************************************************************************
  824. *
  825. *
  826. - IVTABC_Unadvise
  827. -
  828. *
  829. *
  830. *
  831. */
  832. STDMETHODIMP
  833. IVTABC_Unadvise(LPIVTABC lpIVTAbc, ULONG ulConnection)
  834. {
  835. LPMAPIADVISESINK padvise;
  836. UINT iAdvise;
  837. HRESULT hResult = hrSuccess;
  838. /*
  839. * Check to see if it's large enough to hold this object
  840. */
  841. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  842. {
  843. /*
  844. * Not large enough
  845. */
  846. DebugTraceSc(IVTABC_Unadvise, E_INVALIDARG);
  847. return ResultFromScode(E_INVALIDARG);
  848. }
  849. /*
  850. * Check to see that it's the correct vtbl
  851. */
  852. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  853. {
  854. /*
  855. * Not my vtbl
  856. */
  857. hResult = ResultFromScode(E_INVALIDARG);
  858. DebugTraceResult(IVTABC_Unadvise, hResult);
  859. return hResult;
  860. }
  861. if (ulConnection - lpIVTAbc->ulConnectMic > (ULONG) lpIVTAbc->cAdvise)
  862. {
  863. DebugTraceSc(IVTABC_Unadvise, E_INVALIDARG);
  864. return ResultFromScode(E_INVALIDARG);
  865. }
  866. /* Get the Critical Section */
  867. EnterCriticalSection(&lpIVTAbc->cs);
  868. iAdvise = (UINT) (ulConnection - lpIVTAbc->ulConnectMic);
  869. padvise = lpIVTAbc->parglpAdvise[iAdvise];
  870. padvise->lpVtbl->Release(padvise);
  871. lpIVTAbc->parglpAdvise[iAdvise] = NULL;
  872. lpIVTAbc->cAdvise--;
  873. /* leave critical section */
  874. LeaveCriticalSection(&lpIVTAbc->cs);
  875. DebugTraceResult(IVTABC_Unadvise, hResult);
  876. return hResult;
  877. }
  878. /*************************************************************************
  879. *
  880. - IVTABC_GetStatus
  881. -
  882. * Returns the status of this table. This table really isn't
  883. * dynamic yet, but it could be...
  884. *
  885. *
  886. */
  887. STDMETHODIMP
  888. IVTABC_GetStatus( LPIVTABC lpIVTAbc,
  889. ULONG * lpulTableStatus,
  890. ULONG * lpulTableType
  891. )
  892. {
  893. HRESULT hResult;
  894. /*
  895. * Parameter checking
  896. */
  897. /*
  898. * Check to see if it's large enough to hold this object
  899. */
  900. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  901. {
  902. /*
  903. * Not large enough
  904. */
  905. hResult = ResultFromScode(E_INVALIDARG);
  906. DebugTraceResult(IVTABC_GetStatus, hResult);
  907. return hResult;
  908. }
  909. /*
  910. * Check to see that it's the correct vtbl
  911. */
  912. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  913. {
  914. /*
  915. * Not my vtbl
  916. */
  917. hResult = ResultFromScode(E_INVALIDARG);
  918. DebugTraceResult(IVTABC_GetStatus, hResult);
  919. return hResult;
  920. }
  921. /*
  922. * Check the out parameters for writability
  923. */
  924. if (IsBadWritePtr(lpulTableStatus, SIZEOF(ULONG))
  925. || IsBadWritePtr(lpulTableType, SIZEOF(ULONG)))
  926. {
  927. /*
  928. * Bad out parameters
  929. */
  930. hResult = ResultFromScode(E_INVALIDARG);
  931. DebugTraceResult(IVTABC_GetStatus, hResult);
  932. return hResult;
  933. }
  934. *lpulTableStatus = TBLSTAT_COMPLETE;
  935. *lpulTableType = TBLTYPE_DYNAMIC;
  936. return hrSuccess;
  937. }
  938. /*************************************************************************
  939. *
  940. - IVTABC_SetColumns
  941. -
  942. *
  943. * SetColumns for contents table.
  944. *
  945. */
  946. STDMETHODIMP
  947. IVTABC_SetColumns( LPIVTABC lpIVTAbc,
  948. LPSPropTagArray lpPTAColSet,
  949. ULONG ulFlags
  950. )
  951. {
  952. SCODE scode;
  953. HRESULT hResult = hrSuccess;
  954. int cbSizeOfColSet;
  955. LPSPropTagArray lpPTAColSetT;
  956. ULONG uliCol;
  957. /*
  958. * Check parameters
  959. */
  960. /*
  961. * Check to see if it's large enough to hold this object
  962. */
  963. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  964. {
  965. /*
  966. * Not large enough
  967. */
  968. hResult = ResultFromScode(E_INVALIDARG);
  969. DebugTraceResult(IVTABC_SetColumns, hResult);
  970. return hResult;
  971. }
  972. /*
  973. * Check to see that it's the correct vtbl
  974. */
  975. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  976. {
  977. /*
  978. * Not my vtbl
  979. */
  980. hResult = ResultFromScode(E_INVALIDARG);
  981. DebugTraceResult(IVTABC_GetStatus, hResult);
  982. return hResult;
  983. }
  984. /*
  985. * Check flags
  986. */
  987. if (ulFlags & ~TBL_NOWAIT)
  988. {
  989. hResult = ResultFromScode(MAPI_E_UNKNOWN_FLAGS);
  990. DebugTraceResult(IVTABC_GetStatus, hResult);
  991. return hResult;
  992. }
  993. /*
  994. * The first element of the structure
  995. */
  996. if (IsBadReadPtr(lpPTAColSet, offsetof(SPropTagArray, aulPropTag)))
  997. {
  998. hResult = ResultFromScode(E_INVALIDARG);
  999. DebugTraceResult(IVTABC_GetStatus, hResult);
  1000. return hResult;
  1001. }
  1002. cbSizeOfColSet = CbSPropTagArray(lpPTAColSet);
  1003. /*
  1004. * The rest of the structure
  1005. */
  1006. if (IsBadReadPtr(lpPTAColSet, cbSizeOfColSet))
  1007. {
  1008. hResult = ResultFromScode(E_INVALIDARG);
  1009. DebugTraceResult(IVTABC_GetStatus, hResult);
  1010. return hResult;
  1011. }
  1012. /*
  1013. * Verify that there are no PT_ERRORs here...
  1014. */
  1015. for (uliCol = 0; uliCol < lpPTAColSet->cValues; uliCol++)
  1016. {
  1017. if (PROP_TYPE(lpPTAColSet->aulPropTag[uliCol]) == PT_ERROR)
  1018. {
  1019. hResult = ResultFromScode(E_INVALIDARG);
  1020. DebugTraceResult(IVTABC_GetStatus, hResult);
  1021. return hResult;
  1022. }
  1023. }
  1024. /*
  1025. * Allocate a new column set.
  1026. */
  1027. scode = lpIVTAbc->lpAllocBuff(cbSizeOfColSet,(LPVOID *) &lpPTAColSetT);
  1028. if (FAILED(scode))
  1029. {
  1030. hResult = ResultFromScode(scode);
  1031. DebugTraceResult(IVTABC_GetStatus, hResult);
  1032. return hResult;
  1033. }
  1034. /*
  1035. * Copy the column set in
  1036. */
  1037. if (cbSizeOfColSet)
  1038. memcpy(lpPTAColSetT, lpPTAColSet, cbSizeOfColSet);
  1039. EnterCriticalSection(&lpIVTAbc->cs);
  1040. if (lpIVTAbc->lpPTAColSet != ptagaivtabcColSet)
  1041. {
  1042. /*
  1043. * Free up the old column set
  1044. */
  1045. lpIVTAbc->lpFreeBuff(lpIVTAbc->lpPTAColSet);
  1046. }
  1047. lpIVTAbc->lpPTAColSet = lpPTAColSetT;
  1048. LeaveCriticalSection(&lpIVTAbc->cs);
  1049. return hrSuccess;
  1050. }
  1051. /*************************************************************************
  1052. *
  1053. - IVTABC_QueryColumns
  1054. -
  1055. *
  1056. *
  1057. * I always have all my columns available... and active.
  1058. */
  1059. STDMETHODIMP
  1060. IVTABC_QueryColumns( LPIVTABC lpIVTAbc,
  1061. ULONG ulFlags,
  1062. LPSPropTagArray FAR * lppColumns
  1063. )
  1064. {
  1065. SCODE scode;
  1066. HRESULT hResult = hrSuccess;
  1067. int cbSizeOfColSet;
  1068. /*
  1069. * Check parameters
  1070. */
  1071. /*
  1072. * Check to see if it's large enough to hold this object
  1073. */
  1074. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  1075. {
  1076. /*
  1077. * Not large enough
  1078. */
  1079. hResult = ResultFromScode(E_INVALIDARG);
  1080. DebugTraceResult(IVTABC_QueryColumns, hResult);
  1081. return hResult;
  1082. }
  1083. /*
  1084. * Check to see that it's the correct vtbl
  1085. */
  1086. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  1087. {
  1088. /*
  1089. * Not my vtbl
  1090. */
  1091. hResult = ResultFromScode(E_INVALIDARG);
  1092. DebugTraceResult(IVTABC_QueryColumns, hResult);
  1093. return hResult;
  1094. }
  1095. /*
  1096. * Check the out parameters for writability
  1097. */
  1098. if (IsBadWritePtr(lppColumns, SIZEOF(LPSPropTagArray)))
  1099. {
  1100. hResult = ResultFromScode(E_INVALIDARG);
  1101. DebugTraceResult(IVTABC_QueryColumns, hResult);
  1102. return hResult;
  1103. }
  1104. /*
  1105. * Check flags
  1106. */
  1107. if (ulFlags & ~TBL_ALL_COLUMNS)
  1108. {
  1109. hResult = ResultFromScode(MAPI_E_UNKNOWN_FLAGS);
  1110. DebugTraceResult(IVTABC_QueryColumns, hResult);
  1111. return hResult;
  1112. }
  1113. EnterCriticalSection(&lpIVTAbc->cs);
  1114. /*
  1115. * Allocate enough memory for the column set
  1116. */
  1117. if (ulFlags & TBL_ALL_COLUMNS)
  1118. cbSizeOfColSet = sizeof(ULONG) +
  1119. (int)(ptagaivtabcColSet->cValues) * SIZEOF(ULONG);
  1120. else
  1121. cbSizeOfColSet = sizeof(ULONG) +
  1122. (int)lpIVTAbc->lpPTAColSet->cValues * SIZEOF(ULONG);
  1123. scode = lpIVTAbc->lpAllocBuff (cbSizeOfColSet,(LPVOID *) lppColumns);
  1124. if (FAILED(scode))
  1125. {
  1126. hResult = ResultFromScode(scode);
  1127. goto out;
  1128. }
  1129. /*
  1130. * Copy the column set in
  1131. */
  1132. if (ulFlags & TBL_ALL_COLUMNS)
  1133. memcpy(*lppColumns, ptagaivtabcColSet, cbSizeOfColSet);
  1134. else
  1135. memcpy(*lppColumns, lpIVTAbc->lpPTAColSet, cbSizeOfColSet);
  1136. out:
  1137. LeaveCriticalSection(&lpIVTAbc->cs);
  1138. DebugTraceResult(IVTABC_QueryColumns, hResult);
  1139. return hResult;
  1140. }
  1141. /*************************************************************************
  1142. *
  1143. - IVTABC_GetCollapseState
  1144. -
  1145. * Stubbed out. Only necessary if this table were to support categorization.
  1146. *
  1147. *
  1148. *
  1149. */
  1150. STDMETHODIMP
  1151. IVTABC_GetCollapseState( LPIVTABC lpIVTAbc,
  1152. ULONG ulFlags,
  1153. ULONG cbInstanceKey,
  1154. LPBYTE pbInstanceKey,
  1155. ULONG FAR * lpcbCollapseState,
  1156. LPBYTE FAR * lppbCollapseState
  1157. )
  1158. {
  1159. SCODE sc = MAPI_E_NO_SUPPORT;
  1160. HRESULT hResult;
  1161. /*
  1162. * Check parameters
  1163. */
  1164. /*
  1165. * Check to see if it's large enough to hold this object
  1166. */
  1167. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  1168. {
  1169. /*
  1170. * Not large enough
  1171. */
  1172. sc = E_INVALIDARG;
  1173. goto out;
  1174. }
  1175. /*
  1176. * Check to see that it's the correct vtbl
  1177. */
  1178. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  1179. {
  1180. /*
  1181. * Not my vtbl
  1182. */
  1183. sc = E_INVALIDARG;
  1184. goto out;
  1185. }
  1186. if ( IsBadReadPtr(pbInstanceKey, (UINT) cbInstanceKey))
  1187. {
  1188. sc = MAPI_E_INVALID_PARAMETER;
  1189. goto out;
  1190. }
  1191. if ( IsBadWritePtr(lpcbCollapseState, SIZEOF(ULONG)))
  1192. {
  1193. sc = MAPI_E_INVALID_PARAMETER;
  1194. goto out;
  1195. }
  1196. if ( IsBadWritePtr(lppbCollapseState, SIZEOF(LPBYTE)))
  1197. {
  1198. sc = MAPI_E_INVALID_PARAMETER;
  1199. goto out;
  1200. }
  1201. if ( ulFlags )
  1202. {
  1203. sc = MAPI_E_UNKNOWN_FLAGS;
  1204. }
  1205. out:
  1206. hResult = ResultFromScode(sc);
  1207. DebugTraceResult(IVTABC_GetCollapseState, hResult);
  1208. return hResult;
  1209. }
  1210. /*************************************************************************
  1211. *
  1212. - IVTABC_SetCollapseState
  1213. -
  1214. * Stubbed out. Only necessary if this table were to support categorization.
  1215. *
  1216. *
  1217. *
  1218. */
  1219. STDMETHODIMP
  1220. IVTABC_SetCollapseState( LPIVTABC lpIVTAbc,
  1221. ULONG ulFlags,
  1222. ULONG cbCollapseState,
  1223. LPBYTE pbCollapseState,
  1224. BOOKMARK FAR * lpbkLocation
  1225. )
  1226. {
  1227. SCODE sc = MAPI_E_NO_SUPPORT;
  1228. HRESULT hResult;
  1229. /*
  1230. * Check parameters
  1231. */
  1232. /*
  1233. * Check to see if it's large enough to hold this object
  1234. */
  1235. if (IsBadReadPtr(lpIVTAbc, SIZEOF(IVTABC)))
  1236. {
  1237. /*
  1238. * Not large enough
  1239. */
  1240. sc = E_INVALIDARG;
  1241. goto out;
  1242. }
  1243. /*
  1244. * Check to see that it's the correct vtbl
  1245. */
  1246. if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  1247. {
  1248. /*
  1249. * Not my vtbl
  1250. */
  1251. sc = E_INVALIDARG;
  1252. goto out;
  1253. }
  1254. if ( IsBadReadPtr(pbCollapseState, (UINT) cbCollapseState))
  1255. {
  1256. sc = MAPI_E_INVALID_PARAMETER;
  1257. goto out;
  1258. }
  1259. if (IsBadWritePtr(lpbkLocation, SIZEOF(BOOKMARK)))
  1260. {
  1261. sc = MAPI_E_INVALID_PARAMETER;
  1262. goto out;
  1263. }
  1264. if ( ulFlags )
  1265. {
  1266. sc = MAPI_E_UNKNOWN_FLAGS;
  1267. }
  1268. out:
  1269. hResult = ResultFromScode(sc);
  1270. DebugTraceResult(IVTABC_SetCollapseState, hResult);
  1271. return hResult;
  1272. }