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.

205 lines
8.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 1993-1998 Microsoft Corporation. All Rights Reserved.
  3. //
  4. // MODULE: newstask.h
  5. //
  6. // PURPOSE: Implements a task object to take care of news downloads.
  7. //
  8. #ifndef __NEWSTASK_H__
  9. #define __NEWSTASK_H__
  10. #include "spoolapi.h"
  11. #include "newsstor.h"
  12. #include "StorUtil.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Types of events we support
  15. #define HUNDRED_NANOSECONDS 10000000
  16. typedef enum tagEVENTTYPE
  17. {
  18. EVENT_OUTBOX,
  19. EVENT_NEWMSGS,
  20. EVENT_IMAPUPLOAD
  21. } EVENTTYPE;
  22. typedef struct tagEVENTINFO
  23. {
  24. TCHAR szGroup[256];
  25. EVENTTYPE type;
  26. } EVENTINFO;
  27. typedef enum tagNEWSTASKSTATE
  28. {
  29. NTS_IDLE = 0,
  30. NTS_CONNECTING,
  31. NTS_POST_INIT,
  32. NTS_POST_NEXT, // Posting states
  33. NTS_POST_RESP,
  34. NTS_POST_DISPOSE,
  35. NTS_POST_END,
  36. NTS_NEWMSG_INIT,
  37. NTS_NEWMSG_NEXTGROUP, // Check for new messages
  38. NTS_NEWMSG_RESP,
  39. NTS_NEWMSG_HTTPSYNCSTORE,
  40. NTS_NEWMSG_HTTPRESP,
  41. NTS_NEWMSG_END,
  42. NTS_MAX
  43. } NEWSTASKSTATE;
  44. typedef struct tagSPLITMSGINFO
  45. {
  46. FOLDERID idFolder;
  47. LPMIMEMESSAGEPARTS pMsgParts;
  48. LPMIMEENUMMESSAGEPARTS pEnumParts;
  49. } SPLITMSGINFO;
  50. class CNewsTask;
  51. typedef HRESULT (CNewsTask::*PFNSTATEFUNC)(THIS_ void);
  52. /////////////////////////////////////////////////////////////////////////////
  53. // class CNewsTask
  54. //
  55. // Overview:
  56. // This object defines and implements the ISpoolerTask interface to handle
  57. // uploading and downloading information from a news server.
  58. //
  59. class CNewsTask : public ISpoolerTask, public IStoreCallback, public ITimeoutCallback
  60. {
  61. public:
  62. /////////////////////////////////////////////////////////////////////////
  63. // Constructor, destructor, initialization
  64. CNewsTask();
  65. ~CNewsTask();
  66. /////////////////////////////////////////////////////////////////////////
  67. // IUnknown Interface
  68. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj);
  69. STDMETHOD_(ULONG, AddRef)(THIS);
  70. STDMETHOD_(ULONG, Release)(THIS);
  71. /////////////////////////////////////////////////////////////////////////
  72. // ISpoolerTask Interface
  73. STDMETHOD(Init)(THIS_ DWORD dwFlags, ISpoolerBindContext *pBindCtx);
  74. STDMETHOD(BuildEvents)(THIS_ ISpoolerUI *pSpoolerUI, IImnAccount *pAccount, FOLDERID idFolder);
  75. STDMETHOD(Execute)(THIS_ EVENTID eid, DWORD_PTR dwTwinkie);
  76. STDMETHOD(CancelEvent)(THIS_ EVENTID eid, DWORD_PTR dwTwinkie);
  77. STDMETHOD(ShowProperties)(THIS_ HWND hwndParent, EVENTID eid, DWORD_PTR dwTwinkie);
  78. STDMETHOD(GetExtendedDetails)(THIS_ EVENTID eid, DWORD_PTR dwTwinkie, LPSTR *ppszDetails);
  79. STDMETHOD(Cancel)(THIS);
  80. STDMETHOD(IsDialogMessage)(THIS_ LPMSG pMsg);
  81. STDMETHOD(OnFlagsChanged)(THIS_ DWORD dwFlags);
  82. /////////////////////////////////////////////////////////////////////////
  83. // IStoreCallback Interface
  84. STDMETHODIMP OnBegin(STOREOPERATIONTYPE tyOperation, STOREOPERATIONINFO *pOpInfo, IOperationCancel *pCancel);
  85. STDMETHODIMP OnProgress(STOREOPERATIONTYPE tyOperation, DWORD dwCurrent, DWORD dwMax, LPCSTR pszStatus);
  86. STDMETHODIMP OnTimeout(LPINETSERVER pServer, LPDWORD pdwTimeout, IXPTYPE ixpServerType);
  87. STDMETHODIMP CanConnect(LPCSTR pszAccountId, DWORD dwFlags);
  88. STDMETHODIMP OnLogonPrompt(LPINETSERVER pServer, IXPTYPE ixpServerType);
  89. STDMETHODIMP OnComplete(STOREOPERATIONTYPE tyOperation, HRESULT hrComplete, LPSTOREOPERATIONINFO pOpInfo, LPSTOREERROR pErrorInfo);
  90. STDMETHODIMP OnPrompt(HRESULT hrError, LPCTSTR pszText, LPCTSTR pszCaption, UINT uType, INT *piUserResponse);
  91. STDMETHODIMP GetParentWindow(DWORD dwReserved, HWND *phwndParent);
  92. /////////////////////////////////////////////////////////////////////////
  93. // ITimeoutCallback Interface
  94. STDMETHODIMP OnTimeoutResponse(TIMEOUTRESPONSE eResponse);
  95. protected:
  96. /////////////////////////////////////////////////////////////////////////
  97. // Window callback and message handling
  98. static LRESULT CALLBACK TaskWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  99. LPARAM lParam);
  100. /////////////////////////////////////////////////////////////////////////
  101. // These functions build the event list
  102. HRESULT InsertOutbox(LPTSTR szAccount, IImnAccount *pAccount);
  103. HRESULT InsertNewMsgs(LPTSTR pszAccount, IImnAccount *pAccount, BOOL fHttp);
  104. /////////////////////////////////////////////////////////////////////////
  105. // State Machine Stuff
  106. void NextState(void);
  107. /////////////////////////////////////////////////////////////////////////
  108. // Utility functions
  109. HRESULT DisposeOfPosting(MESSAGEID dwMsgID);
  110. public:
  111. /////////////////////////////////////////////////////////////////////////
  112. // Functions that upload posts
  113. HRESULT Post_Init(void);
  114. HRESULT Post_NextPart(void);
  115. HRESULT Post_NextMsg(void);
  116. HRESULT Post_Dispose(void);
  117. HRESULT Post_Done(void);
  118. /////////////////////////////////////////////////////////////////////////
  119. // Functions that check for new messages
  120. HRESULT NewMsg_Init(void);
  121. HRESULT NewMsg_InitHttp(void);
  122. HRESULT NewMsg_NextGroup(void);
  123. HRESULT NewMsg_HttpSyncStore(void);
  124. HRESULT NewMsg_Done(void);
  125. private:
  126. void FreeSplitInfo(void);
  127. /////////////////////////////////////////////////////////////////////////
  128. // Private member data
  129. ULONG m_cRef; // Object reference count
  130. // State
  131. BOOL m_fInited; // TRUE if we've been initialized
  132. DWORD m_dwFlags; // Flags passed in from the spooler engine
  133. NEWSTASKSTATE m_state; // Current state of the task
  134. EVENTID m_eidCur; // Currently executing event
  135. EVENTINFO *m_pInfo; // EVENTINFO for the current event
  136. BOOL m_fConnectFailed;
  137. TCHAR m_szAccount[256];
  138. TCHAR m_szAccountId[256];
  139. FOLDERID m_idAccount;
  140. DWORD m_cEvents; // Number of events left to execute
  141. BOOL m_fCancel;
  142. IImnAccount *m_pAccount;
  143. // Spooler Interfaces
  144. ISpoolerBindContext *m_pBindCtx; // Interface to communicate with the spooler engine
  145. ISpoolerUI *m_pUI; // Interface to communicate with the UI
  146. // News Object Pointers
  147. IMessageServer *m_pServer; // Pointer to the transport object
  148. IMessageFolder *m_pOutbox; // Pointer to the outbox
  149. IMessageFolder *m_pSent; // Pointer to the sent items folder
  150. // Windows
  151. HWND m_hwnd; // Handle that recieves transport messages
  152. // Posting
  153. int m_cMsgsPost; // Number of messages to post
  154. int m_cCurPost; // Message currently being posted
  155. int m_cFailed; // Number of messages which failed to post
  156. int m_cCurParts; // Number of parts the current message includes
  157. int m_cPartsCompleted; // Number of parts whose post have completed.
  158. BOOL m_fPartFailed; // Did one of the parts fail?
  159. LPMESSAGEINFO m_rgMsgInfo; // Array of headers for messages to post
  160. SPLITMSGINFO *m_pSplitInfo;
  161. // New messages check
  162. int m_cGroups; // Number of groups we're checking
  163. int m_cCurGroup; // Current group we're checking
  164. FOLDERID *m_rgidGroups; // Array of group folderids we're checking
  165. DWORD m_dwNewInboxMsgs; // Number of new msgs detected in Inbox
  166. // Callback
  167. HTIMEOUT m_hTimeout;
  168. IOperationCancel *m_pCancel;
  169. STOREOPERATIONTYPE m_tyOperation;
  170. };
  171. #endif // __NEWSTASK_H__