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.

189 lines
5.1 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. // This function checks if a given URL already has a subscription.
  4. // Returns TRUE: if it aleady has a subscription
  5. // FALSE: Otherwise.
  6. //
  7. BOOL CheckForExistingSubscription(LPCTSTR lpcszURL)
  8. {
  9. HRESULT hr;
  10. ISubscriptionMgr *psm;
  11. BOOL fRet = FALSE; //Assume failure.
  12. //Create the subscription Manager.
  13. hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  14. CLSCTX_INPROC_SERVER,
  15. IID_ISubscriptionMgr,
  16. (void**)&psm);
  17. if (SUCCEEDED(hr))
  18. {
  19. BSTR bstrURL = SysAllocStringT(lpcszURL);
  20. if (bstrURL)
  21. {
  22. psm->IsSubscribed(bstrURL, &fRet);
  23. SysFreeString(bstrURL);
  24. }
  25. psm->Release();
  26. }
  27. return(fRet);
  28. }
  29. BOOL DeleteFromSubscriptionList(LPCTSTR pszURL)
  30. {
  31. BOOL fRet = FALSE;
  32. HRESULT hr;
  33. ISubscriptionMgr *psm;
  34. hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  35. CLSCTX_INPROC_SERVER,
  36. IID_ISubscriptionMgr,
  37. (void**)&psm);
  38. if (SUCCEEDED(hr))
  39. {
  40. BSTR bstrURL = SysAllocStringT(pszURL); // Call TSTR version
  41. if (bstrURL)
  42. {
  43. // Looks like all code paths going through this has already
  44. // put up some UI.
  45. if (SUCCEEDED(psm->DeleteSubscription(bstrURL, NULL)))
  46. {
  47. fRet = TRUE;
  48. }
  49. SysFreeString(bstrURL);
  50. }
  51. psm->Release();
  52. }
  53. return(fRet);
  54. }
  55. BOOL UpdateSubscription(LPCTSTR pszURL)
  56. {
  57. BOOL fRet = FALSE;
  58. HRESULT hr;
  59. ISubscriptionMgr *psm;
  60. hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  61. CLSCTX_INPROC_SERVER,
  62. IID_ISubscriptionMgr,
  63. (void**)&psm);
  64. if (SUCCEEDED(hr))
  65. {
  66. BSTR bstrURL = SysAllocStringT(pszURL); // Call TSTR version
  67. if (bstrURL)
  68. {
  69. if (SUCCEEDED(psm->UpdateSubscription(bstrURL)))
  70. {
  71. fRet = TRUE;
  72. }
  73. SysFreeString(bstrURL);
  74. }
  75. psm->Release();
  76. }
  77. return(fRet);
  78. }
  79. //
  80. //
  81. // This function enumerates the URLs of all the desktop components and then
  82. // calls webcheck to see if they are subcribed to and if so asks webcheck to
  83. // deliver those subscriptions right now.
  84. //
  85. //
  86. BOOL UpdateAllDesktopSubscriptions(IADesktopP2 *padp2)
  87. {
  88. IActiveDesktop *pActiveDesktop;
  89. ISubscriptionMgr *psm;
  90. int iCount; //Count of components.
  91. HRESULT hres;
  92. BOOL fRet = TRUE; //Assume success!
  93. if(padp2 == NULL) //Are we provided a pointer already?
  94. {
  95. if(FAILED(hres = CActiveDesktop_InternalCreateInstance((LPUNKNOWN *)&pActiveDesktop, IID_IActiveDesktop)))
  96. {
  97. TraceMsg(TF_WARNING, "Could not instantiate CActiveDesktop COM object");
  98. return FALSE;
  99. }
  100. }
  101. else
  102. {
  103. if(FAILED(hres = (padp2->QueryInterface(IID_PPV_ARG(IActiveDesktop, &pActiveDesktop)))))
  104. {
  105. TraceMsg(TF_WARNING, "Could not get IActiveDesktop * from IADesktopP2 *");
  106. return FALSE;
  107. }
  108. }
  109. pActiveDesktop->GetDesktopItemCount(&iCount, 0);
  110. if(iCount <= 0)
  111. {
  112. TraceMsg(DM_TRACE, "No desktop components to update!");
  113. return TRUE; //No components to enumerate!
  114. }
  115. //Create the subscription Manager.
  116. hres = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  117. CLSCTX_INPROC_SERVER,
  118. IID_ISubscriptionMgr,
  119. (void**)&psm);
  120. if(SUCCEEDED(hres))
  121. {
  122. int iIndex;
  123. BSTR bstrURL;
  124. //Enumerate the desktop components one by one.
  125. for(iIndex = 0; iIndex < iCount; iIndex++)
  126. {
  127. COMPONENT Comp; //We are using the public structure here.
  128. Comp.dwSize = sizeof(COMPONENT);
  129. if(SUCCEEDED(pActiveDesktop->GetDesktopItem(iIndex, &Comp, 0)) &&
  130. Comp.fChecked) //Is this component enabled?
  131. {
  132. BOOL fSubscribed;
  133. fSubscribed = FALSE; //Assume that it is NOT subscribed!
  134. bstrURL = SysAllocString(Comp.wszSubscribedURL);
  135. if(!bstrURL)
  136. {
  137. fRet = FALSE;
  138. break; //Out of memory!
  139. }
  140. psm->IsSubscribed(bstrURL, &fSubscribed);
  141. if(fSubscribed)
  142. psm->UpdateSubscription(bstrURL);
  143. SysFreeString(bstrURL);
  144. }
  145. else
  146. TraceMsg(TF_WARNING, "Component# %d either failed or not enabled!", iIndex);
  147. }
  148. psm->Release();
  149. }
  150. else
  151. {
  152. TraceMsg(TF_WARNING, "Could not create CLSID_SubscriptionMgr");
  153. }
  154. pActiveDesktop->Release();
  155. return fRet;
  156. }