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.

226 lines
12 KiB

  1. // --------------------------------------------------------------------------------
  2. // Spengine.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #ifndef __SPENGINE_H
  7. #define __SPENGINE_H
  8. // --------------------------------------------------------------------------------
  9. // Depends
  10. // --------------------------------------------------------------------------------
  11. #include "spoolapi.h"
  12. #include "imnact.h"
  13. #include "conman.h"
  14. // --------------------------------------------------------------------------------
  15. // Forward Decls
  16. // --------------------------------------------------------------------------------
  17. interface ILogFile;
  18. interface IImnAccountManager;
  19. // --------------------------------------------------------------------------------
  20. // Spooler State
  21. // --------------------------------------------------------------------------------
  22. #define SPSTATE_INIT FLAG01 // The spooler has been initialized
  23. #define SPSTATE_BUSY FLAG02 // The spooler is currently working
  24. #define SPSTATE_CANCEL FLAG03 // The user hit stop
  25. #define SPSTATE_SHUTDOWN FLAG04 // The spooler is shutting down
  26. #define SPSTATE_UISHUTDOWN FLAG05 // ::UIShutdown
  27. // ------------------------------------------------------------------------------------
  28. // NOTIFYTABLE
  29. // ------------------------------------------------------------------------------------
  30. typedef struct tagNOTIFYTABLE {
  31. ULONG cAlloc; // Number of array items allocated
  32. ULONG cNotify; // Number of registered views
  33. HWND *prghwndNotify; // Array of view who want notifications
  34. } NOTIFYTABLE, *LPNOTIFYTABLE;
  35. // ------------------------------------------------------------------------------------
  36. // SPOOLERACCOUNT
  37. // ------------------------------------------------------------------------------------
  38. typedef struct tagSPOOLERACCOUNT {
  39. CHAR szConnectoid[CCHMAX_CONNECTOID]; // RAS Connectoid Name
  40. DWORD dwSort; // Inverted Sort Index
  41. DWORD dwConnType; // CONNECTION_TYPE_XXXX (imnact.h)
  42. DWORD dwServers; // Support Server Types on this account
  43. IImnAccount *pAccount; // The Account Object
  44. } SPOOLERACCOUNT, *LPSPOOLERACCOUNT;
  45. // ------------------------------------------------------------------------------------
  46. // ACCOUNTTABLE
  47. // ------------------------------------------------------------------------------------
  48. typedef struct tagACCOUNTTABLE {
  49. ULONG cAccounts; // cRasAccts + cLanAccts
  50. ULONG cLanAlloc; // Number of elements allocated;
  51. ULONG cLanAccts; // Number of valid lan/manual accounts
  52. ULONG cRasAlloc; // Number of elements allocated;
  53. ULONG cRasAccts; // Number of valid lan/manual accounts
  54. LPSPOOLERACCOUNT prgLanAcct; // Array of elements
  55. LPSPOOLERACCOUNT prgRasAcct; // Array of elements
  56. } ACCOUNTTABLE, *LPACCOUNTTABLE;
  57. // ------------------------------------------------------------------------------------
  58. // SPOOLERTASKTYPE
  59. // ------------------------------------------------------------------------------------
  60. typedef enum tagSPOOLERTASKTYPE {
  61. TASK_POP3, // POP3 Task
  62. TASK_SMTP, // SMTP Task
  63. TASK_NNTP, // NNTP Task
  64. TASK_IMAP // IMAP Task
  65. } SPOOLERTASKTYPE;
  66. // ------------------------------------------------------------------------------------
  67. // SPOOLEREVENT
  68. // ------------------------------------------------------------------------------------
  69. typedef struct tagSPOOLEREVENT {
  70. CHAR szConnectoid[CCHMAX_CONNECTOID]; // RAS Connectoid Name
  71. DWORD dwConnType; // Connection Type
  72. IImnAccount *pAccount; // Account object for this task
  73. EVENTID eid; // Event ID
  74. ISpoolerTask *pSpoolerTask; // Pointer to Task Object
  75. DWORD_PTR dwTwinkie; // Event extra data
  76. } SPOOLEREVENT, *LPSPOOLEREVENT;
  77. // ------------------------------------------------------------------------------------
  78. // SPOOLEREVENTTABLE
  79. // ------------------------------------------------------------------------------------
  80. typedef struct tagSPOOLEREVENTTABLE {
  81. DWORD cEvents;
  82. DWORD cSucceeded;
  83. DWORD cEventsAlloc;
  84. LPSPOOLEREVENT prgEvents;
  85. } SPOOLEREVENTTABLE, *LPSPOOLEREVENTTABLE;
  86. // ------------------------------------------------------------------------------------
  87. // VIEWREGISTER
  88. // ------------------------------------------------------------------------------------
  89. typedef struct tagVIEWREGISTER {
  90. ULONG cViewAlloc; // Number of array items allocated
  91. HWND *rghwndView; // Array of view who want notifications
  92. ULONG cView; // Number of registered views
  93. } VIEWREGISTER, *LPVIEWREGISTER;
  94. #define ALL_ACCT_SERVERS 0xffffffff
  95. // --------------------------------------------------------------------------------
  96. // CSpoolerEngine
  97. // --------------------------------------------------------------------------------
  98. #ifndef WIN16 // No RAS support in Win16
  99. class CSpoolerEngine : public ISpoolerEngine, ISpoolerBindContext, IConnectionNotify
  100. #else
  101. class CSpoolerEngine : public ISpoolerEngine, ISpoolerBindContext
  102. #endif
  103. {
  104. friend HRESULT CreateThreadedSpooler(PFNCREATESPOOLERUI pfnCreateUI, ISpoolerEngine **ppSpooler, BOOL fPoll);
  105. public:
  106. // ----------------------------------------------------------------------------
  107. // CSpoolerEngine
  108. // ----------------------------------------------------------------------------
  109. CSpoolerEngine(void);
  110. ~CSpoolerEngine(void);
  111. // ---------------------------------------------------------------------------
  112. // IUnknown members
  113. // ---------------------------------------------------------------------------
  114. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  115. STDMETHODIMP_(ULONG) AddRef(void);
  116. STDMETHODIMP_(ULONG) Release(void);
  117. // ---------------------------------------------------------------------------
  118. // ISpoolerEngine members
  119. // ---------------------------------------------------------------------------
  120. STDMETHODIMP Init(ISpoolerUI *pUI, BOOL fPoll);
  121. STDMETHODIMP StartDelivery(HWND hwnd, LPCSTR pszAcctID, FOLDERID idFolder, DWORD dwFlags);
  122. STDMETHODIMP Close(void);
  123. STDMETHODIMP Advise(HWND hwndView, BOOL fRegister);
  124. STDMETHODIMP UpdateTrayIcon(TRAYICONTYPE type);
  125. STDMETHODIMP GetThreadInfo(LPDWORD pdwThreadId, HTHREAD* phThread);
  126. STDMETHODIMP OnStartupFinished(void);
  127. // ---------------------------------------------------------------------------
  128. // ISpoolerBindContext members
  129. // ---------------------------------------------------------------------------
  130. STDMETHODIMP RegisterEvent(LPCSTR pszDescription, ISpoolerTask *pTask, DWORD_PTR dwTwinkie,
  131. IImnAccount *pAccount, LPEVENTID peid);
  132. STDMETHODIMP EventDone(EVENTID eid, EVENTCOMPLETEDSTATUS status);
  133. STDMETHODIMP BindToObject(REFIID riid, void **ppvObject);
  134. STDMETHODIMP TaskFromEventId(EVENTID eid, ISpoolerTask *ppTask);
  135. STDMETHODIMP OnWindowMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  136. STDMETHODIMP Cancel(void);
  137. STDMETHODIMP Notify(DELIVERYNOTIFYTYPE notify, LPARAM lParam);
  138. STDMETHODIMP IsDialogMessage(LPMSG pMsg);
  139. STDMETHODIMP PumpMessages(void);
  140. STDMETHODIMP UIShutdown(void);
  141. STDMETHODIMP OnUIChange(BOOL fVisible);
  142. STDMETHODIMP_(LRESULT) QueryEndSession(WPARAM wParam, LPARAM lParam);
  143. #ifndef WIN16 // No RAS support in Win16
  144. // ---------------------------------------------------------------------------
  145. // IConnectionNotify
  146. // ---------------------------------------------------------------------------
  147. STDMETHODIMP OnConnectionNotify(CONNNOTIFY nCode, LPVOID pvData, CConnectionManager *pConMan);
  148. #endif //!WIN16
  149. // ---------------------------------------------------------------------------
  150. // CSpoolerEngine members
  151. // ---------------------------------------------------------------------------
  152. HRESULT Shutdown(void);
  153. private:
  154. // ---------------------------------------------------------------------------
  155. // Private Members
  156. // ---------------------------------------------------------------------------
  157. HRESULT _HrStartDeliveryActual(DWORD dwFlags);
  158. HRESULT _HrAppendAccountTable(LPACCOUNTTABLE pTable, LPCSTR pszAcctID, DWORD dwServers);
  159. HRESULT _HrAppendAccountTable(LPACCOUNTTABLE pTable, IImnAccount *pAccount, DWORD dwServers);
  160. #ifndef WIN16 // No RAS support in Win16
  161. void _InsertRasAccounts(LPACCOUNTTABLE pTable, LPCSTR pszConnectoid, DWORD dwSrvTypes);
  162. void _SortAccountTableByConnName(LONG left, LONG right, LPSPOOLERACCOUNT prgRasAcct);
  163. #endif
  164. HRESULT _HrCreateTaskObject(LPSPOOLERACCOUNT pSpoolerAcct);
  165. HRESULT _HrStartNextEvent(void);
  166. HRESULT _HrGoIdle(void);
  167. void _ShutdownTasks(void);
  168. void _DoBackgroundPoll(void);
  169. void _StartPolling(void);
  170. void _StopPolling(void);
  171. HRESULT _HrDoRasConnect(const LPSPOOLEREVENT pEvent);
  172. HRESULT _OpenMailLogFile(DWORD dwOptionId, LPCSTR pszPrefix, LPCSTR pszFileName, ILogFile **ppLogFile);
  173. private:
  174. // ---------------------------------------------------------------------------
  175. // Private Data
  176. // ---------------------------------------------------------------------------
  177. ULONG m_cRef; // Reference count
  178. DWORD m_dwThreadId; // Thread Id of this spooler
  179. HTHREAD m_hThread; // Handle to my own thread
  180. ISpoolerUI *m_pUI; // Spooler UI
  181. DWORD m_dwState; // Spooler Engine State
  182. IImnAccountManager *m_pAcctMan; // The Account Manager
  183. IDatabase *m_pUidlCache; // POP3 uidl Cache
  184. DWORD m_dwFlags; // Current DELIVERYFLAGS
  185. HWND m_hwndUI; // Spooler Window
  186. LPSTR m_pszAcctID; // Work on a specific account
  187. FOLDERID m_idFolder; // Work on a specific folder or group
  188. CRITICAL_SECTION m_cs; // Thread Safety
  189. SPOOLEREVENTTABLE m_rEventTable; // Table of events
  190. BOOL m_fBackgroundPollPending;
  191. VIEWREGISTER m_rViewRegister; // Registered Views
  192. DWORD m_dwPollInterval; // Duration between background polling
  193. HWND m_hwndTray; // The tray icon window
  194. DWORD m_cCurEvent; // Index of the currently executing event
  195. DWORD m_dwQueued; // Queued Polling Flags
  196. BOOL m_fRasSpooled; // Use this for the Hangup when done options
  197. BOOL m_fOfflineWhenDone; // Toggle the Work Offline state after spool
  198. ILogFile *m_pPop3LogFile;
  199. ILogFile *m_pSmtpLogFile;
  200. BOOL m_fIDialed;
  201. DWORD m_cSyncEvent;
  202. BOOL m_fNoSyncEvent;
  203. };
  204. #endif // __SPENGINE_H