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.

154 lines
3.1 KiB

  1. #include "precomp.h"
  2. #include "mcinc.h"
  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. {
  14. for(int i = 0; i<_Count(); i++)
  15. {
  16. SERVICE_ITEM *psi = _Item( i );
  17. if(psi)
  18. {
  19. IUnknown_Set((IUnknown **)&psi->psp, NULL);
  20. }
  21. }
  22. DSA_Destroy(_hdsa);
  23. }
  24. HRESULT IProfferServiceImpl::ProfferService(REFGUID rguidService, IServiceProvider *psp, DWORD *pdwCookie)
  25. {
  26. HRESULT hr;
  27. if (!_hdsa)
  28. _hdsa = DSA_Create(sizeof(SERVICE_ITEM), 4);
  29. SERVICE_ITEM si;
  30. si.psp = psp;
  31. si.guidService = rguidService;
  32. si.dwCookie = ++_dwNextCookie; // start at 1
  33. if (_hdsa && (-1 != DSA_AppendItem(_hdsa, &si)))
  34. {
  35. psp->AddRef();
  36. *pdwCookie = si.dwCookie;
  37. hr = S_OK;
  38. }
  39. else
  40. {
  41. hr = E_OUTOFMEMORY;
  42. }
  43. return hr;
  44. }
  45. HRESULT IProfferServiceImpl::RevokeService(DWORD dwCookie)
  46. {
  47. HRESULT hr = E_INVALIDARG; // not found
  48. for(int i = 0; i<_Count(); i++)
  49. {
  50. SERVICE_ITEM *psi = _Item( i );
  51. if(psi)
  52. {
  53. if(psi->dwCookie == dwCookie)
  54. {
  55. IUnknown_Set((IUnknown **)&psi->psp, NULL);
  56. DSA_DeleteItem(_hdsa, i);
  57. hr = S_OK; // successful revoke
  58. break;
  59. }
  60. }
  61. }
  62. return hr;
  63. }
  64. HRESULT IProfferServiceImpl::QueryService(REFGUID guidService, REFIID riid, void **ppv)
  65. {
  66. HRESULT hr = E_FAIL; // did not find the service object
  67. *ppv = NULL;
  68. for(int i = 0; i<_Count(); i++)
  69. {
  70. SERVICE_ITEM *psi = _Item( i );
  71. if(psi)
  72. {
  73. if(IsEqualGUID(psi->guidService, guidService))
  74. {
  75. hr = psi->psp->QueryService(guidService, riid, ppv);
  76. break;
  77. }
  78. }
  79. }
  80. return hr;
  81. }
  82. #if 0
  83. // trident implementation
  84. HRESULT CProfferService::ProfferService(REFGUID rguidService, IServiceProvider * pSP, DWORD * pdwCookie)
  85. {
  86. HRESULT hr;
  87. CProfferServiceItem *pItem = new CProfferServiceItem(rguidService, pSP);
  88. if (!pItem)
  89. {
  90. hr = E_OUTOFMEMORY;
  91. goto Cleanup;
  92. }
  93. hr = THR(_aryItems.Append(pItem));
  94. if (hr)
  95. goto Cleanup;
  96. if (!pdwCookie)
  97. {
  98. hr = E_INVALIDARG;
  99. goto Cleanup;
  100. }
  101. *pdwCookie = _aryItems.Size() - 1;
  102. Cleanup:
  103. RRETURN (hr);
  104. }
  105. HRESULT CProfferService::RevokeService(DWORD dwCookie)
  106. {
  107. if ((DWORD)_aryItems.Size() <= dwCookie)
  108. {
  109. RRETURN (E_INVALIDARG);
  110. }
  111. delete _aryItems[dwCookie];
  112. _aryItems[dwCookie] = NULL;
  113. RRETURN (S_OK);
  114. }
  115. HRESULT CProfferService::QueryService(REFGUID rguidService, REFIID riid, void ** ppv)
  116. {
  117. for (int i = 0, int c = _aryItems.Size(); i < c; i++)
  118. {
  119. CProfferServiceItem *pItem = _aryItems[i];
  120. if (pItem && IsEqualGUID(pItem->_guidService, rguidService))
  121. {
  122. RRETURN (pItem->_pSP->QueryService(rguidService, riid, ppv));
  123. }
  124. }
  125. RRETURN (E_NOTIMPL);
  126. }
  127. #endif