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.

340 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. dirnot.hxx
  5. Abstract:
  6. This module defines the directory notification class.
  7. This object maintains information about a new client connection
  8. Author:
  9. Rohan Phillips ( Rohanp ) 11-Dec-1995
  10. Project:
  11. SMTP Server DLL
  12. Revision History:
  13. --*/
  14. #ifndef _SMTP_DIRNOT_HXX_
  15. #define _SMTP_DIRNOT_HXX_
  16. /************************************************************
  17. * Include Headers
  18. ************************************************************/
  19. //
  20. // Redefine the type to indicate that this is a call-back function
  21. //
  22. typedef ATQ_COMPLETION PFN_ATQ_COMPLETION;
  23. /************************************************************
  24. * Symbolic Constants
  25. ************************************************************/
  26. #define SMTP_DIRNOT_SIGNATURE_VALID 'DIRV'
  27. #define SMTP_DIRNOT_SIGNATURE_FREE 'DIRF'
  28. /************************************************************
  29. * Type Definitions
  30. ************************************************************/
  31. #define OUTSTANDING_NOTIFICATIONS 3
  32. //
  33. // forward class declrations
  34. //
  35. class CBuffer;
  36. class SMTP_SERVER_INSTANCE;
  37. //class CPickupRetryQ;
  38. enum BUFIOSTATE {
  39. CLIENT_WRITE, MESSAGE_READ
  40. };
  41. typedef struct _DIRNOT_OVERLAPPED
  42. {
  43. SERVEREVENT_OVERLAPPED SeoOverlapped;
  44. // OVERLAPPED Overlapped;
  45. CBuffer* pBuffer;
  46. } DIRNOT_OVERLAPPED;
  47. #define DIRNOT_BUFFER_SIGNATURE '3fuB'
  48. #define DIRNOT_IO_BUFFER_SIGNATURE '3oiB'
  49. // Exposed public
  50. BOOL CopyRestOfMessage(HANDLE hSrcFile, HANDLE hDstFile);
  51. class CIoBuffer
  52. {
  53. public:
  54. static CPool Pool;
  55. //
  56. // override mem functions to use CPool functions
  57. //
  58. void* operator new( size_t cSize )
  59. { return Pool.Alloc(); }
  60. void operator delete( void *pInstance )
  61. { Pool.Free( pInstance ); }
  62. //
  63. // the actual buffer area. size is set by reg entry
  64. //
  65. char Buffer[1];
  66. };
  67. class CBuffer {
  68. public:
  69. static CPool Pool;
  70. CBuffer( BOOL bEncrypted = FALSE );
  71. ~CBuffer( void );
  72. //
  73. // override mem functions to use CPool functions
  74. //
  75. void* operator new( size_t cSize )
  76. { return Pool.Alloc(); }
  77. void operator delete( void *pInstance )
  78. { Pool.Free(pInstance); }
  79. //
  80. // is this buffer in the right pool?
  81. //
  82. BOOL IsValid( DWORD Signature );
  83. //
  84. // get the number of bytes in the buffer
  85. //
  86. DWORD GetSize() { return m_cCount; }
  87. //
  88. // get the max number of bytes in the buffer
  89. //
  90. DWORD GetMaxSize() { return Pool.GetInstanceSize(); }
  91. //
  92. // set the expected number of bytes in the buffer
  93. //
  94. void SetSize( DWORD dw ) { m_cCount = dw; }
  95. //
  96. // get a pointer to the buffers data area
  97. //
  98. LPBYTE GetData() { return (LPBYTE)m_pIoBuffer; }
  99. //
  100. // copy data into a buffer
  101. //
  102. BOOL ReplaceData(PVOID src, DWORD count);
  103. //
  104. // clear the buffer so that it can be reused
  105. //
  106. void Reset(void) { m_cCount = 0; }
  107. //
  108. // get the IoState for this operation
  109. //
  110. BUFIOSTATE GetIoState(void) { return m_eIoState; }
  111. //
  112. // set the IoState for this operation
  113. //
  114. void SetIoState(BUFIOSTATE io) { m_eIoState = io; }
  115. //
  116. // signature for the class
  117. //
  118. DWORD m_dwSignature;
  119. //
  120. // the extended IO overlap structure
  121. // In order for the completion port to work, the overlap
  122. // structure is extended to add one pointer to the
  123. // associated CBuffer object
  124. //
  125. DIRNOT_OVERLAPPED m_Overlapped;
  126. private:
  127. //
  128. // the amount of data in the buffer
  129. //
  130. DWORD m_cCount;
  131. //
  132. // the initial IO type
  133. //
  134. BUFIOSTATE m_eIoState;
  135. //
  136. // the buffer itself must be the last member
  137. //
  138. CIoBuffer* m_pIoBuffer;
  139. //
  140. // whether this buffer will be used for encrypted data
  141. //
  142. BOOL m_bEncrypted;
  143. };
  144. /*++
  145. class SMTP_DIRNOT
  146. It maintains the state of the directory notifications.
  147. --*/
  148. class SMTP_DIRNOT
  149. {
  150. public:
  151. ~SMTP_DIRNOT(void);
  152. BOOL ProcessClient( IN DWORD cbWritten,
  153. IN DWORD dwCompletionStatus,
  154. IN OUT OVERLAPPED * lpo);
  155. BOOL ProcessFile(IMailMsgProperties *pIMsg);
  156. static SMTP_DIRNOT * CreateSmtpDirNotification (char * Dir, ATQ_COMPLETION pfnCompletion, SMTP_SERVER_INSTANCE * pInstance);
  157. static DWORD WINAPI PickupInitialFiles(void * ClassPtr);
  158. static DWORD WINAPI CreateNonIISFindThread(void * ClassPtr);
  159. void CloseDirHandle (void);
  160. LONG GetThreadCount(void) const {return m_cActiveThreads;}
  161. PATQ_CONTEXT QueryAtqContext(void) const {return m_pAtqContext;}
  162. void SetPickupRetryQueueEvent(void);
  163. SMTP_SERVER_INSTANCE * QuerySmtpInstance( VOID ) const
  164. { _ASSERT(m_pInstance != NULL); return m_pInstance; }
  165. BOOL IsSmtpInstance( VOID ) const
  166. { return m_pInstance != NULL; }
  167. VOID SetSmtpInstance( IN SMTP_SERVER_INSTANCE * pInstance )
  168. { _ASSERT(m_pInstance == NULL); m_pInstance = pInstance; }
  169. //
  170. // IsValid()
  171. // o Checks the signature of the object to determine
  172. // if this is a valid SMTP_DIRNOT object.
  173. //
  174. // Returns: TRUE on success and FALSE if invalid.
  175. //
  176. BOOL IsValid( VOID) const
  177. { return ( m_Signature == SMTP_DIRNOT_SIGNATURE_VALID); }
  178. //
  179. // this function is also called by smtpcli.cxx to create extra delivery threads when needed.
  180. //
  181. void CreateLocalDeliveryThread (void);
  182. static VOID ReadDirectoryCompletion(PVOID pvContext, DWORD cbWritten,
  183. DWORD dwCompletionStatus, OVERLAPPED * lpo);
  184. private :
  185. ULONG m_Signature;
  186. SMTP_SERVER_INSTANCE * m_pInstance;
  187. //CPickupRetryQ * m_pRetryQ;
  188. HANDLE m_hDir;
  189. LONG m_cPendingIoCount;
  190. LONG m_cDirChangeIoCount;
  191. LONG m_cActiveThreads;
  192. PATQ_CONTEXT m_pAtqContext;
  193. CRITICAL_SECTION m_CritFindLock;
  194. LONG m_FindThreads;
  195. HANDLE m_FindFirstHandle;
  196. BOOL m_bDelayedFind;
  197. SMTP_DIRNOT (SMTP_SERVER_INSTANCE * pInstance);
  198. BOOL DoFindFirstFile(BOOL bIISThread = TRUE);
  199. BOOL InitializeObject (char *DirPickupName, ATQ_COMPLETION pfnCompletion);
  200. BOOL CreateToList (char *AddrsList, IMailMsgRecipientsAdd *pIMsgRecips, IMailMsgProperties *pIMsg);
  201. BOOL PendDirChangeNotification (void);
  202. BOOL ProcessDirNotification( IN DWORD InputBufferLen, IN DWORD dwCompletionStatus, IN OUT OVERLAPPED * lpo);
  203. LONG IncPendingIoCount(void) { return InterlockedIncrement( &m_cPendingIoCount ); }
  204. LONG DecPendingIoCount(void) { return InterlockedDecrement( &m_cPendingIoCount ); }
  205. DWORD GetPendingIoCount(void) { return m_cPendingIoCount; }
  206. LONG IncDirChangeIoCount(void) { return InterlockedIncrement( &m_cDirChangeIoCount ); }
  207. LONG DecDirChangeIoCount(void) { return InterlockedDecrement( &m_cDirChangeIoCount ); }
  208. LONG IncThreadCount(void) { return InterlockedIncrement( &m_cActiveThreads ); }
  209. LONG DecThreadCount(void) { return InterlockedDecrement( &m_cActiveThreads ); }
  210. VOID LockFind() { EnterCriticalSection(&m_CritFindLock); }
  211. VOID UnLockFind() { LeaveCriticalSection(&m_CritFindLock); }
  212. BOOL IncFindThreads(void)
  213. {
  214. LONG NewFindThreads;
  215. NewFindThreads = InterlockedIncrement( &m_FindThreads );
  216. if (NewFindThreads > g_MaxFindThreads)
  217. {
  218. InterlockedDecrement( &m_FindThreads );
  219. return FALSE;
  220. }
  221. return TRUE;
  222. }
  223. LONG DecFindThreads(void) { return InterlockedDecrement( &m_FindThreads ); }
  224. HANDLE GetFindFirstHandle()
  225. {
  226. return m_FindFirstHandle;
  227. }
  228. VOID SetFindFirstHandle(HANDLE hFind)
  229. {
  230. m_FindFirstHandle = hFind;
  231. }
  232. VOID CloseFindHandle()
  233. {
  234. LONG NumThreads;
  235. NumThreads = DecFindThreads();
  236. if (NumThreads == 0)
  237. {
  238. _VERIFY(FindClose(m_FindFirstHandle));
  239. m_FindFirstHandle = INVALID_HANDLE_VALUE;
  240. }
  241. }
  242. DWORD GetNumFindThreads() { return m_FindThreads; }
  243. VOID SetDelayedFindNotification (BOOL bIn) { m_bDelayedFind = bIn; }
  244. BOOL GetDelayedFindNotification () { return m_bDelayedFind; }
  245. HRESULT SetAvailableMailMsgProperties( IMailMsgProperties *pIMsg );
  246. HRESULT GetAndPersistRFC822Headers( char* InputLine,
  247. char* pszValueBuf,
  248. IMailMsgProperties* pIMsg,
  249. BOOL & fSeenRFC822FromAddress,
  250. BOOL & fSeenRFC822ToAddress,
  251. BOOL & fSeenRFC822BccAddress,
  252. BOOL & fSeenRFC822CcAddress,
  253. BOOL & fSeenRFC822Subject,
  254. BOOL & fSeenRFC822SenderAddress,
  255. BOOL & fSeenXPriority,
  256. BOOL & fSeenContentType,
  257. BOOL & fSetContentType );
  258. };
  259. #endif
  260. /************************ End of File ***********************/