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.

413 lines
13 KiB

  1. #ifndef _CDFAGENT_H
  2. #define _CDFAGENT_H
  3. #include "msxml.h"
  4. class CProcessElement;
  5. class CProcessRoot;
  6. class CUrlTrackingCache;
  7. class CRunDeliveryAgentSink
  8. {
  9. public:
  10. // OnAgentProgress not currently called
  11. virtual HRESULT OnAgentProgress()
  12. { return E_NOTIMPL; }
  13. // OnAgentEnd called when agent is complete. fSynchronous means that StartAgent call
  14. // has not yet returned; hrResult will be returned from StartAgent
  15. virtual HRESULT OnAgentEnd(const SUBSCRIPTIONCOOKIE *pSubscriptionCookie,
  16. long lSizeDownloaded, HRESULT hrResult, LPCWSTR wszResult,
  17. BOOL fSynchronous)
  18. { return E_NOTIMPL; }
  19. };
  20. class CProcessElementSink
  21. {
  22. public:
  23. virtual HRESULT OnChildDone(CProcessElement *pChild, HRESULT hr) = 0;
  24. virtual LPCWSTR GetBaseUrl() = 0; // Returned pointer doesn't need to get freed
  25. virtual BOOL IsGlobalLog() = 0;
  26. };
  27. typedef struct CDF_TIME
  28. {
  29. WORD wDay;
  30. WORD wHour;
  31. WORD wMin;
  32. WORD wReserved;
  33. DWORD dwConvertedMinutes; // Day/Hour/Min in Minutes
  34. } CDF_TIME;
  35. //////////////////////////////////////////////////////////////////////////
  36. //
  37. // Channel Agent object
  38. //
  39. //////////////////////////////////////////////////////////////////////////
  40. class CChannelAgent : public CDeliveryAgent,
  41. public CUrlDownloadSink,
  42. public CProcessElementSink
  43. {
  44. friend CProcessElement; // for SendUpdateProgress
  45. friend CProcessRoot; // for laziness
  46. protected:
  47. // properties
  48. LPWSTR m_pwszURL;
  49. DWORD m_dwChannelFlags;
  50. // used during updating
  51. CUrlDownload *m_pCurDownload;
  52. IExtractIcon *m_pChannelIconHelper;
  53. BOOL m_fHasInitCookie; // One time deal, don't try again.
  54. VARIANT m_varChange;
  55. GROUPID m_llCacheGroupID;
  56. GROUPID m_llOldCacheGroupID;
  57. // other agent flags
  58. enum {
  59. FLAG_CDFCHANGED = 0x80000000 // did the CDF change?
  60. };
  61. private:
  62. ~CChannelAgent(void);
  63. public:
  64. CChannelAgent(void);
  65. // CUrlDownloadSink
  66. HRESULT OnAuthenticate(HWND *phwnd, LPWSTR *ppszUsername, LPWSTR *ppszPassword);
  67. HRESULT OnDownloadComplete(UINT iID, int iError);
  68. // CProcessElementSink
  69. HRESULT OnChildDone(CProcessElement *pChild, HRESULT hr);
  70. LPCWSTR GetBaseUrl() { return GetUrl(); }
  71. BOOL IsGlobalLog() { return FALSE; }
  72. // virtual functions overriding CDeliveryAgent
  73. HRESULT AgentPause(DWORD dwFlags);
  74. HRESULT AgentResume(DWORD dwFlags);
  75. HRESULT AgentAbort(DWORD dwFlags);
  76. STDMETHODIMP GetIconLocation(UINT, LPTSTR, UINT, int *, UINT *);
  77. STDMETHODIMP Extract(LPCTSTR, UINT, HICON *, HICON *, UINT);
  78. LPCWSTR GetUrl() { return m_pwszURL; }
  79. ISubscriptionItem *GetStartItem() { return m_pSubscriptionItem; }
  80. BOOL IsChannelFlagSet(DWORD dwFlag) { return dwFlag & m_dwChannelFlags; }
  81. protected:
  82. // CDeliveryAgent overrides
  83. HRESULT ModifyUpdateEnd(ISubscriptionItem *pEndItem, UINT *puiRes);
  84. HRESULT StartOperation();
  85. HRESULT StartDownload();
  86. void CleanUp();
  87. // Used during updates
  88. CProcessRoot *m_pProcess;
  89. public:
  90. DWORD m_dwMaxSizeKB;
  91. };
  92. //////////////////////////////////////////////////////////////////////////
  93. //
  94. // CRunDeliveryAgent object
  95. // Will run a delivery agent and host it for you
  96. // Create, call Init, then call StartAgent
  97. // Use static function SafeRelease to safely release this class.
  98. //
  99. //////////////////////////////////////////////////////////////////////////
  100. class CRunDeliveryAgent : public ISubscriptionAgentEvents
  101. {
  102. protected:
  103. virtual ~CRunDeliveryAgent();
  104. CRunDeliveryAgentSink *m_pParent;
  105. ULONG m_cRef;
  106. ISubscriptionItem *m_pItem;
  107. ISubscriptionAgentControl *m_pAgent;
  108. HRESULT m_hrResult;
  109. BOOL m_fInStartAgent;
  110. CLSID m_clsidDest;
  111. void CleanUp();
  112. public:
  113. CRunDeliveryAgent();
  114. HRESULT Init(CRunDeliveryAgentSink *pParent, ISubscriptionItem *pItem, REFCLSID rclsidDest);
  115. void LeaveMeAlone() { m_pParent = NULL; }
  116. inline static void SafeRelease(CRunDeliveryAgent * &pThis)
  117. { if (pThis) { pThis->m_pParent=NULL; pThis->Release(); pThis=NULL; } }
  118. static HRESULT CreateNewItem(ISubscriptionItem **ppItem, REFCLSID rclsidAgent);
  119. // StartAgent will return E_PENDING if agent is running. Otherwise it will return
  120. // synchronous result code from agent.
  121. HRESULT StartAgent();
  122. HRESULT AgentPause(DWORD dwFlags);
  123. HRESULT AgentResume(DWORD dwFlags);
  124. HRESULT AgentAbort(DWORD dwFlags);
  125. // IUnknown members
  126. STDMETHODIMP QueryInterface(REFIID riid, void **ppunk);
  127. STDMETHODIMP_(ULONG) AddRef();
  128. STDMETHODIMP_(ULONG) Release();
  129. // ISubscriptionAgentEvents members
  130. STDMETHODIMP UpdateBegin(const SUBSCRIPTIONCOOKIE *pSubscriptionCookie);
  131. STDMETHODIMP UpdateProgress(const SUBSCRIPTIONCOOKIE *pSubscriptionCookie,
  132. long lSizeDownloaded, long lProgressCurrent, long lProgressMax,
  133. HRESULT hrStatus, LPCWSTR wszStatus);
  134. STDMETHODIMP UpdateEnd(const SUBSCRIPTIONCOOKIE *pSubscriptionCookie,
  135. long lSizeDownloaded,
  136. HRESULT hrResult, LPCWSTR wszResult);
  137. STDMETHODIMP ReportError(const SUBSCRIPTIONCOOKIE *pSubscriptionCookie,
  138. HRESULT hrError, LPCWSTR wszError);
  139. };
  140. class CChannelAgentHolder : public CRunDeliveryAgent,
  141. public IServiceProvider
  142. {
  143. protected:
  144. ~CChannelAgentHolder();
  145. public:
  146. CChannelAgentHolder(CChannelAgent *pChannelAgent, CProcessElement *pProcess);
  147. // IUnknown
  148. STDMETHODIMP QueryInterface(REFIID riid, void **ppunk);
  149. STDMETHODIMP_(ULONG) AddRef();
  150. STDMETHODIMP_(ULONG) Release();
  151. // ServiceProvider
  152. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppvObject);
  153. protected:
  154. CChannelAgent *m_pChannelAgent;
  155. CProcessElement *m_pProcess;
  156. };
  157. //////////////////////////////////////////////////////////////////////////
  158. //
  159. // Process Element objects
  160. //
  161. // User of this class
  162. // 1) Creates & passes in self & element
  163. // 2) Calls Run
  164. // 3) If E_PENDING, will receive call back "OnChildDone"
  165. //
  166. // The purpose of this class is simply to allow us to save our state of
  167. // walking the XML OM, so that we can host another deliver agent
  168. // (webcrawler). This requires us to return out to the thread's message
  169. // pump after sending the "agent start" to the web crawler.
  170. // The if a webcrawl is initiated the class creates its own sink. Classes
  171. // also keep references to their spawned enumerations in case of an
  172. // abort, which comes from the root element (CProcessRoot instance)
  173. //
  174. //////////////////////////////////////////////////////////////////////////
  175. class CProcessElement : public CProcessElementSink, public CRunDeliveryAgentSink
  176. {
  177. public:
  178. CProcessElement(CProcessElementSink *pParent, CProcessRoot *pRoot, IXMLElement *pEle);
  179. ~CProcessElement();
  180. // From CRunDeliveryAgent
  181. HRESULT OnAgentEnd(const SUBSCRIPTIONCOOKIE *pSubscriptionCookie,
  182. long lSizeDownloaded, HRESULT hrResult, LPCWSTR wszResult,
  183. BOOL fSynchronous);
  184. typedef HRESULT (CChannelAgent::*PFNHANDLETAG)(LPCWSTR pwszTagName, IXMLElement *pEle);
  185. typedef struct
  186. {
  187. LPCWSTR pwszTagName;
  188. PFNHANDLETAG pfnHandleTag;
  189. } TAGTABLE;
  190. // E_FAIL, E_PENDING, or S_OK
  191. virtual HRESULT Run();
  192. // Called when E_PENDING DoChild returns (from m_pCurChild)
  193. HRESULT OnChildDone(CProcessElement *pChild, HRESULT hr);
  194. HRESULT Pause(DWORD dwFlags);
  195. HRESULT Resume(DWORD dwFlags);
  196. HRESULT Abort(DWORD dwFlags);
  197. IXMLElement *GetCurrentElement() { return m_pChildElement; }
  198. protected:
  199. // Returns E_PENDING, or S_OK if enumeration complete
  200. HRESULT DoEnumeration();
  201. // E_PENDING if webcrawl pending
  202. HRESULT DoChild(CProcessElement *pChild);
  203. // Should return E_PENDING, or S_OK if processing done
  204. // Can return E_ABORT to abort entire CDF processing
  205. virtual HRESULT ProcessItemInEnum(LPCWSTR pwszTagName, IXMLElement *pItem) = 0;
  206. // Called by DoEnumeration when it's done. Return value ignored.
  207. virtual HRESULT EnumerationComplete() { return S_OK; }
  208. // E_PENDING, or E_FAIL
  209. HRESULT DoDeliveryAgent(ISubscriptionItem *pItem, REFCLSID rclsid, LPCWSTR pwszURL=NULL);
  210. HRESULT DoWebCrawl(IXMLElement *pItem, LPCWSTR pwszURL=NULL);
  211. HRESULT DoSoftDist(IXMLElement *pItem);
  212. BOOL ShouldDownloadLogo(IXMLElement *pLogo);
  213. // If relative url, will combine with most recent base URL
  214. // *ppwszRetUrl should be NULL & will be LocalAlloced if needed
  215. HRESULT CombineWithBaseUrl(LPCWSTR pwszUrl, LPWSTR *ppwszRetUrl);
  216. // Returned pointer doesn't need to get freed
  217. LPCWSTR GetBaseUrl() { return m_pParent->GetBaseUrl(); }
  218. BOOL IsGlobalLog() { return m_pParent->IsGlobalLog(); }
  219. CProcessRoot *m_pRoot;
  220. CProcessElement *m_pCurChild;
  221. IXMLElementCollection *m_pCollection;
  222. long m_lIndex;
  223. long m_lMax;
  224. BOOL m_fStartedEnumeration;
  225. BOOL m_fSentEnumerationComplete;
  226. IXMLElement *m_pElement;
  227. IXMLElement *m_pChildElement;
  228. CProcessElementSink *m_pParent;
  229. CRunDeliveryAgent *m_pRunAgent;
  230. };
  231. class CProcessRoot : public CProcessElement
  232. {
  233. public:
  234. CProcessRoot(CChannelAgent *pParent, IXMLElement *pRoot);
  235. ~CProcessRoot();
  236. CChannelAgent *m_pChannelAgent;
  237. DWORD m_dwCurSizeKB;
  238. int m_iTotalStarted;
  239. BOOL m_fMaxSizeExceeded;
  240. protected:
  241. ISubscriptionItem *m_pDefaultStartItem;
  242. CUrlTrackingCache *m_pTracking;
  243. public:
  244. HRESULT CreateStartItem(ISubscriptionItem **ppItem);
  245. IUnknown *DefaultStartItem() { return m_pDefaultStartItem; }
  246. HRESULT Run();
  247. // Called when E_PENDING DoChild returns (from m_pCurChild, a CProcessChannel)
  248. HRESULT OnChildDone(CProcessElement *pChild, HRESULT hr);
  249. HRESULT OnAgentEnd(const SUBSCRIPTIONCOOKIE *, long, HRESULT, LPCWSTR, BOOL);
  250. BOOL IsPaused() { return m_pChannelAgent->IsPaused(); }
  251. BOOL IsChannelFlagSet(DWORD dw) { return m_pChannelAgent->IsChannelFlagSet(dw); }
  252. // HRESULT ProcessLogin(IXMLElement *pElement);
  253. HRESULT DoTrackingFromItem(IXMLElement *pItem, LPCWSTR pwszUrl, BOOL fForceLog);
  254. HRESULT DoTrackingFromLog(IXMLElement *pItem);
  255. protected:
  256. HRESULT ProcessItemInEnum(LPCWSTR pwszTagName, IXMLElement *pItem);
  257. LPCWSTR GetBaseUrl() { return m_pChannelAgent->GetUrl(); }
  258. };
  259. class CProcessChannel : public CProcessElement
  260. {
  261. public:
  262. CProcessChannel(CProcessElementSink *pParent, CProcessRoot *pRoot, IXMLElement *pItem);
  263. ~CProcessChannel();
  264. HRESULT Run();
  265. void SetGlobalLogFlag(BOOL flag) { m_fglobalLog = flag; }
  266. protected:
  267. HRESULT ProcessItemInEnum(LPCWSTR pwszTagName, IXMLElement *pItem);
  268. LPCWSTR GetBaseUrl() { if (m_bstrBaseUrl) return m_bstrBaseUrl; return m_pParent->GetBaseUrl(); }
  269. BOOL IsGlobalLog() { return m_fglobalLog; }
  270. HRESULT CheckPreCache();
  271. BOOL m_fDownloadedHREF;
  272. BSTR m_bstrBaseUrl;
  273. BOOL m_fglobalLog;
  274. };
  275. class CProcessItem : public CProcessElement
  276. {
  277. public:
  278. CProcessItem(CProcessElementSink *pParent, CProcessRoot *pRoot, IXMLElement *pItem);
  279. ~CProcessItem();
  280. protected:
  281. HRESULT ProcessItemInEnum(LPCWSTR pwszTagName, IXMLElement *pItem);
  282. HRESULT EnumerationComplete();
  283. BSTR m_bstrAnchorURL;
  284. BOOL m_fDesktop;
  285. BOOL m_fEmail;
  286. };
  287. class CProcessSchedule : public CProcessElement
  288. {
  289. public:
  290. CProcessSchedule(CProcessElementSink *pParent, CProcessRoot *pRoot, IXMLElement *pItem);
  291. HRESULT Run();
  292. protected:
  293. HRESULT ProcessItemInEnum(LPCWSTR pwszTagName, IXMLElement *pItem);
  294. HRESULT EnumerationComplete();
  295. CDF_TIME m_timeInterval;
  296. CDF_TIME m_timeEarliest;
  297. CDF_TIME m_timeLatest;
  298. SYSTEMTIME m_stStartDate;
  299. SYSTEMTIME m_stEndDate;
  300. public:
  301. TASK_TRIGGER m_tt;
  302. };
  303. class CExtractSchedule : public CProcessElement
  304. {
  305. public:
  306. CExtractSchedule(IXMLElement *pEle, CExtractSchedule *m_pExtractRoot);
  307. HRESULT ProcessItemInEnum(LPCWSTR pwszTagName, IXMLElement *pItem);
  308. HRESULT GetTaskTrigger(TASK_TRIGGER *ptt);
  309. virtual HRESULT Run();
  310. TASK_TRIGGER m_tt;
  311. CExtractSchedule *m_pExtractRoot;
  312. protected:
  313. LPCWSTR GetBaseUrl() { return NULL; }
  314. };
  315. #endif // _CDFAGENT_H