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.

360 lines
11 KiB

  1. //---------------------------------------------------------------
  2. // Copyright (c)1998 Microsoft Corporation, All Rights Reserved.
  3. //
  4. // conn.h
  5. //
  6. // Connection mapping between sockets and CCONNECTION objects.
  7. //
  8. // Author:
  9. //
  10. // Edward Reus (edwardr) 02-26-98 Initial coding.
  11. //
  12. //---------------------------------------------------------------
  13. #ifndef __CONN_HXX__
  14. #define __CONN_HXX__
  15. #define MAX_MAP_ENTRIES 16
  16. //---------------------------------------------------------------
  17. // Class CCONNECTION
  18. //---------------------------------------------------------------
  19. class CCONNECTION
  20. {
  21. public:
  22. // CCONNECTION();
  23. CCONNECTION( DWORD dwKind = PACKET_KIND_LISTEN,
  24. SOCKET Socket = 0,
  25. HANDLE hIoCP = INVALID_HANDLE_VALUE,
  26. CSCEP_CONNECTION *pScepConnection = 0,
  27. BOOL fSaveAsUPF = FALSE );
  28. ~CCONNECTION();
  29. void *operator new( IN size_t Size );
  30. void operator delete( IN void *pObj,
  31. IN size_t Size );
  32. DWORD InitializeForListen( IN char *pszServiceName,
  33. IN BOOL fIsIrCOMM,
  34. IN HANDLE hIoCP );
  35. char *GetServiceName();
  36. char *GetPathPlusFileName();
  37. void SetKind( DWORD dwKind );
  38. DWORD GetKind();
  39. void SetSocket( SOCKET Socket );
  40. SOCKET GetSocket();
  41. DWORD ShutdownSocket();
  42. void CloseSocket();
  43. void SetListenSocket( SOCKET ListenSocket );
  44. SOCKET GetListenSocket();
  45. void CloseListenSocket();
  46. void SetIoCompletionPort( HANDLE hIoCP );
  47. HANDLE GetIoCompletionPort();
  48. void SetScepConnection( CSCEP_CONNECTION *pScepConnection );
  49. CSCEP_CONNECTION *GetScepConnection();
  50. void SetJpegOffsetAndSize( DWORD dwOffset,
  51. DWORD dwSize );
  52. LONG IncrementPendingReads();
  53. LONG DecrementPendingReads();
  54. LONG IncrementPendingWrites();
  55. LONG DecrementPendingWrites();
  56. LONG NumPendingIos();
  57. DWORD PostMoreIos( CIOPACKET *pIoPacket = NULL );
  58. DWORD SendPdu( IN SCEP_HEADER *pPdu,
  59. IN DWORD dwPduSize,
  60. OUT CIOPACKET **ppIoPacket );
  61. static char *ConstructPicturesSubDirectory( IN DWORD dwExtraChars = 0 );
  62. char *ConstructFullFileName( IN DWORD dwCopyCount );
  63. BOOL CheckSaveAsUPF();
  64. DWORD Impersonate();
  65. DWORD RevertToSelf();
  66. DWORD CreatePictureFile();
  67. DWORD SetPictureFileTime( IN FILETIME *pFileTime );
  68. DWORD WritePictureFile( IN UCHAR *pBuffer,
  69. IN DWORD dwBufferSize,
  70. OUT CIOPACKET **ppIoPacket );
  71. DWORD DeletePictureFile();
  72. DWORD ClosePictureFile();
  73. BOOL IncompleteFile();
  74. void SetReceiveComplete( IN BOOL fReceiveComplete );
  75. DWORD StartProgress();
  76. DWORD UpdateProgress();
  77. DWORD EndProgress();
  78. private:
  79. static void CleanupDateString( IN OUT char *pszDateStr );
  80. DWORD m_dwKind;
  81. char *m_pszServiceName; // Service name (for Listen Sockets).
  82. SOCKET m_ListenSocket;
  83. SOCKET m_Socket;
  84. HANDLE m_hFile;
  85. char *m_pszPathPlusFileName;
  86. DWORD m_dwFileBytesWritten;
  87. LONG m_lMaxPendingReads;
  88. LONG m_lPendingReads;
  89. LONG m_lMaxPendingWrites;
  90. LONG m_lPendingWrites;
  91. DWORD m_dwJpegOffset; // Offset in UPF file of JPEG image.
  92. DWORD m_dwJpegSize; // Size of JPEG image in UPF file.
  93. BOOL m_fSaveAsUPF; // If TRUE, write the entire UPF file.
  94. DWORD m_dwUpfBytes; // Total UPF bytes read in from Camera.
  95. DWORD m_dwBytesWritten; // Actual number of bytes written to disk.
  96. BOOL m_fReceiveComplete; // Set to TRUE when a SCEP disconnect
  97. // packet is received from the camera.
  98. BOOL m_fImpersonating; // TRUE iff we are currently impersonating.
  99. CIrProgress *m_pIrProgress; // Progress bar during receive.
  100. CSCEP_CONNECTION *m_pScepConnection; // SCEP protocol object.
  101. EXECUTION_STATE m_ExecutionState; // Use to tell the system not to
  102. // hibernate during file transfer.
  103. };
  104. //---------------------------------------------------------------
  105. // Class CCONNECTION_MAP
  106. //---------------------------------------------------------------
  107. typedef struct _CONNECTION_MAP_ENTRY
  108. {
  109. SOCKET Socket;
  110. CCONNECTION *pConnection;
  111. } CONNECTION_MAP_ENTRY;
  112. class CCONNECTION_MAP
  113. {
  114. public:
  115. CCONNECTION_MAP();
  116. ~CCONNECTION_MAP();
  117. void *operator new( IN size_t Size );
  118. void operator delete( IN void *pObj,
  119. IN size_t Size );
  120. BOOL Initialize( DWORD dwMapSize = MAX_MAP_ENTRIES );
  121. // Lookup
  122. CCONNECTION *Lookup( IN SOCKET Socket );
  123. // Lookup Connection by name:
  124. CCONNECTION *LookupByServiceName( IN char *pszServiceName );
  125. // Add a new (value,key) pair
  126. BOOL Add( IN CCONNECTION *pConnection,
  127. IN SOCKET Socket );
  128. // Remove an entry from the mapping
  129. CCONNECTION *Remove( IN SOCKET Socket );
  130. CCONNECTION *RemoveConnection( IN CCONNECTION *pConnection );
  131. // Remove the "next" entry from the mapping
  132. CCONNECTION *RemoveNext();
  133. // Walk through all the connections (set State to 0 for "first").
  134. CCONNECTION *ReturnNext( IN OUT DWORD *pdwState );
  135. SOCKET ReturnNextSocket( IN OUT DWORD *pdwState );
  136. private:
  137. CRITICAL_SECTION m_cs;
  138. DWORD m_dwMapSize;
  139. CONNECTION_MAP_ENTRY *m_pMap;
  140. };
  141. //---------------------------------------------------------------
  142. // CCONNECTION::GetServiceName()
  143. //---------------------------------------------------------------
  144. inline char *CCONNECTION::GetServiceName()
  145. {
  146. return m_pszServiceName;
  147. }
  148. //---------------------------------------------------------------
  149. // CCONNECTION::GetPathPlusFileName()
  150. //---------------------------------------------------------------
  151. inline char *CCONNECTION::GetPathPlusFileName()
  152. {
  153. return m_pszPathPlusFileName;
  154. }
  155. //---------------------------------------------------------------
  156. // CCONNECTION::SetKind()
  157. //---------------------------------------------------------------
  158. inline void CCONNECTION::SetKind( DWORD dwKind )
  159. {
  160. m_dwKind = dwKind;
  161. if (m_dwKind == PACKET_KIND_LISTEN)
  162. {
  163. m_lMaxPendingReads = MAX_PENDING_LISTEN;
  164. }
  165. else if (m_dwKind == PACKET_KIND_READ)
  166. {
  167. m_lMaxPendingReads = MAX_PENDING_READ;
  168. }
  169. }
  170. //---------------------------------------------------------------
  171. // CCONNECTION::GetKind()
  172. //---------------------------------------------------------------
  173. inline DWORD CCONNECTION::GetKind()
  174. {
  175. return m_dwKind;
  176. }
  177. //---------------------------------------------------------------
  178. // CCONNECTION::SetSocket()
  179. //---------------------------------------------------------------
  180. inline void CCONNECTION::SetSocket( SOCKET Socket )
  181. {
  182. m_Socket = Socket;
  183. }
  184. //---------------------------------------------------------------
  185. // CCONNECTION::GetSocket()
  186. //---------------------------------------------------------------
  187. inline SOCKET CCONNECTION::GetSocket()
  188. {
  189. return m_Socket;
  190. }
  191. //---------------------------------------------------------------
  192. // CCONNECTION::SetListenSocket()
  193. //---------------------------------------------------------------
  194. inline void CCONNECTION::SetListenSocket( SOCKET ListenSocket )
  195. {
  196. m_ListenSocket = ListenSocket;
  197. }
  198. //---------------------------------------------------------------
  199. // CCONNECTION::GetListenSocket()
  200. //---------------------------------------------------------------
  201. inline SOCKET CCONNECTION::GetListenSocket()
  202. {
  203. return m_ListenSocket;
  204. }
  205. //---------------------------------------------------------------
  206. // CCONNECTION::IncrementPendingReads()
  207. //---------------------------------------------------------------
  208. inline LONG CCONNECTION::IncrementPendingReads()
  209. {
  210. return InterlockedIncrement(&m_lPendingReads);
  211. }
  212. //---------------------------------------------------------------
  213. // CCONNECTION::DecrementPendingReads()
  214. //---------------------------------------------------------------
  215. inline LONG CCONNECTION::DecrementPendingReads()
  216. {
  217. return InterlockedDecrement(&m_lPendingReads);
  218. }
  219. //---------------------------------------------------------------
  220. // CCONNECTION::IncrementPendingWrites()
  221. //---------------------------------------------------------------
  222. inline LONG CCONNECTION::IncrementPendingWrites()
  223. {
  224. return InterlockedIncrement(&m_lPendingWrites);
  225. }
  226. //---------------------------------------------------------------
  227. // CCONNECTION::DecrementPendingReads()
  228. //---------------------------------------------------------------
  229. inline LONG CCONNECTION::DecrementPendingWrites()
  230. {
  231. return InterlockedDecrement(&m_lPendingWrites);
  232. }
  233. //---------------------------------------------------------------
  234. // CCONNECTION::NumPendingIos()
  235. //---------------------------------------------------------------
  236. inline LONG CCONNECTION::NumPendingIos()
  237. {
  238. return m_lPendingReads + m_lPendingWrites;
  239. }
  240. //---------------------------------------------------------------
  241. // CCONNECTION::SetIoCompletionPort()
  242. //---------------------------------------------------------------
  243. inline void CCONNECTION::SetIoCompletionPort( HANDLE hIoCP )
  244. {
  245. }
  246. //---------------------------------------------------------------
  247. // CCONNECTION::GetIoCompletionPort()
  248. //---------------------------------------------------------------
  249. inline HANDLE CCONNECTION::GetIoCompletionPort()
  250. {
  251. return INVALID_HANDLE_VALUE;
  252. }
  253. //---------------------------------------------------------------
  254. // CCONNECTION::SetScepConnection()
  255. //---------------------------------------------------------------
  256. inline void CCONNECTION::SetScepConnection( CSCEP_CONNECTION *pScepConnection )
  257. {
  258. m_pScepConnection = pScepConnection;
  259. }
  260. //---------------------------------------------------------------
  261. // CCONNECTION::GetScepConnection()
  262. //---------------------------------------------------------------
  263. inline CSCEP_CONNECTION *CCONNECTION::GetScepConnection()
  264. {
  265. return m_pScepConnection;
  266. }
  267. //---------------------------------------------------------------
  268. // CCONNECTION::SetJpegOffset()
  269. //---------------------------------------------------------------
  270. inline void CCONNECTION::SetJpegOffsetAndSize( IN DWORD dwOffset,
  271. IN DWORD dwSize )
  272. {
  273. m_dwJpegOffset = dwOffset;
  274. m_dwJpegSize = dwSize;
  275. }
  276. //---------------------------------------------------------------
  277. // CCONNECTION::CheckSaveAsUPF()
  278. //---------------------------------------------------------------
  279. inline BOOL CCONNECTION::CheckSaveAsUPF()
  280. {
  281. return m_fSaveAsUPF;
  282. }
  283. //---------------------------------------------------------------
  284. // CCONNECTION::SetReceiveComplete()
  285. //---------------------------------------------------------------
  286. inline void CCONNECTION::SetReceiveComplete( IN BOOL fReceiveComplete )
  287. {
  288. m_fReceiveComplete = fReceiveComplete;
  289. }
  290. #endif