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.

98 lines
2.1 KiB

  1. #include "stock.h"
  2. #pragma hdrstop
  3. #include <profsvc.h>
  4. typedef struct
  5. {
  6. IServiceProvider *psp;
  7. GUID guidService;
  8. DWORD dwCookie;
  9. } SERVICE_ITEM;
  10. #define _Item(i) (_hdsa ? (SERVICE_ITEM *)DSA_GetItemPtr(_hdsa, i) : NULL)
  11. #define _Count() (_hdsa ? DSA_GetItemCount(_hdsa) : 0)
  12. IProfferServiceImpl::IProfferServiceImpl() :
  13. _hdsa(NULL),
  14. _dwNextCookie(0)
  15. {
  16. }
  17. IProfferServiceImpl::~IProfferServiceImpl()
  18. {
  19. for (int i = 0; i < _Count(); i++)
  20. {
  21. SERVICE_ITEM *psi = _Item(i);
  22. if (psi)
  23. {
  24. IUnknown_Set((IUnknown **)&psi->psp, NULL);
  25. }
  26. }
  27. DSA_Destroy(_hdsa);
  28. }
  29. HRESULT IProfferServiceImpl::ProfferService(REFGUID rguidService, IServiceProvider *psp, DWORD *pdwCookie)
  30. {
  31. HRESULT hr;
  32. if (!_hdsa)
  33. {
  34. _hdsa = DSA_Create(sizeof(SERVICE_ITEM), 4);
  35. }
  36. SERVICE_ITEM si;
  37. si.psp = psp;
  38. si.guidService = rguidService;
  39. si.dwCookie = ++_dwNextCookie; // start at 1
  40. if (_hdsa && (-1 != DSA_AppendItem(_hdsa, &si)))
  41. {
  42. psp->AddRef();
  43. *pdwCookie = si.dwCookie;
  44. hr = S_OK;
  45. }
  46. else
  47. {
  48. hr = E_OUTOFMEMORY;
  49. }
  50. return hr;
  51. }
  52. HRESULT IProfferServiceImpl::RevokeService(DWORD dwCookie)
  53. {
  54. HRESULT hr = E_INVALIDARG; // not found
  55. for (int i = 0; i < _Count(); i++)
  56. {
  57. SERVICE_ITEM *psi = _Item(i);
  58. if (psi && (psi->dwCookie == dwCookie))
  59. {
  60. IUnknown_Set((IUnknown **)&psi->psp, NULL);
  61. DSA_DeleteItem(_hdsa, i);
  62. hr = S_OK; // successful revoke
  63. break;
  64. }
  65. }
  66. return hr;
  67. }
  68. HRESULT IProfferServiceImpl::QueryService(REFGUID guidService, REFIID riid, void **ppv)
  69. {
  70. HRESULT hr = E_FAIL; // did not find the service object
  71. *ppv = NULL;
  72. for (int i = 0; i < _Count(); i++)
  73. {
  74. SERVICE_ITEM *psi = _Item(i);
  75. if (psi && IsEqualGUID(psi->guidService, guidService))
  76. {
  77. hr = psi->psp->QueryService(guidService, riid, ppv);
  78. break;
  79. }
  80. }
  81. return hr;
  82. }