PageRenderTime 68ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 2ms

/trunk/Common/Overbyte ICS 7/OverbyteIcsWSocket.pas

http://castlesand.googlecode.com/
Pascal | 13101 lines | 8520 code | 1213 blank | 3368 comment | 953 complexity | 18a1064fb08682cabeaaa7b92ee1e260 MD5 | raw file
Possible License(s): MIT, LGPL-2.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. {*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. Author: François PIETTE
  3. Description: TWSocket class encapsulate the Windows Socket paradigm
  4. Creation: April 1996
  5. Version: 7.47
  6. EMail: francois.piette@overbyte.be http://www.overbyte.be
  7. Support: Use the mailing list twsocket@elists.org
  8. Follow "support" link at http://www.overbyte.be for subscription.
  9. Legal issues: Copyright (C) 1996-2010 by François PIETTE
  10. Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
  11. <francois.piette@overbyte.be>
  12. SSL implementation includes code written by Arno Garrels,
  13. Berlin, Germany, contact: <arno.garrels@gmx.de>
  14. This software is provided 'as-is', without any express or
  15. implied warranty. In no event will the author be held liable
  16. for any damages arising from the use of this software.
  17. Permission is granted to anyone to use this software for any
  18. purpose, including commercial applications, and to alter it
  19. and redistribute it freely, subject to the following
  20. restrictions:
  21. 1. The origin of this software must not be misrepresented,
  22. you must not claim that you wrote the original software.
  23. If you use this software in a product, an acknowledgment
  24. in the product documentation would be appreciated but is
  25. not required.
  26. 2. Altered source versions must be plainly marked as such, and
  27. must not be misrepresented as being the original software.
  28. 3. This notice may not be removed or altered from any source
  29. distribution.
  30. 4. You must register this software by sending a picture postcard
  31. to the author. Use a nice stamp and mention your name, street
  32. address, EMail address and any comment you like to say.
  33. History:
  34. If not otherwise noted, changes are by Francois Piette
  35. Jul 18, 1996 Move all low level socket to winsock to be Delphi 2.x compatible
  36. Sep 18, 1996 Use structured exception for handling errors
  37. Sep 19, 1996 Check csDestroying before invoking event handler
  38. Nov 04, 1996 Better error handling
  39. Jan 31, 1997 Changed property assignation for Addr, Port and Proto
  40. Added notification handler
  41. Feb 14, 1997 Corrected bug in property assignation for Addr, Port and Proto
  42. Mar 26, 1997 Make UDP protocol work correctly
  43. Enable UDP broadcasting by using addr 255.255.255.255
  44. Apr 1, 1997 Added class function when independent of any open socket
  45. Moved InitData as global
  46. Added ReceivedFrom function
  47. Added ResolveHost function
  48. Jul 22, 1997 Adapted to Delphi 3 which has a modified winsock.accept
  49. Aug 13, 1997 'sin' member made public
  50. Aug 24, 1997 Create the only help
  51. Makes writing HSocket the same as calling Dup.
  52. Sep 5, 1997 Version 2.01, added WinsockInfo function
  53. Sep 21, 1997 Version 2.02, make it really thread safe
  54. created global WSocketVersion
  55. Sep 25, 1997 Version 2.04, port to C++Builder
  56. Sep 27, 1997 Version 2.05. All class methods converted to global
  57. procedure or function because C++Builder do not like
  58. class method very much.
  59. Old class method New global function
  60. ---------------- -------------------
  61. WinsockInfo WinsockInfo
  62. SocketErrorDesc WSocketErrorDesc
  63. GetHostByAddr WSocketGetHostByAddr
  64. GetHostByName WSocketGetHostByName
  65. ResolveHost WSocketResolveHost
  66. HostName LocalHostName
  67. Oct 02, 1997 V2.06 Added a check in destructor to avoid calling WSACleanup at
  68. design time which crashes the excellent Eagle Software CDK.
  69. Oct 16, 1997 V2.07 Added PortNum property with numeric value for Port.
  70. Added RcvdCount property to return the number of
  71. characters received in the buffer but not read yet. Do not
  72. confuse with ReadCount which returns the number of chars
  73. already received.
  74. Added a check for FWait assignation in front of ReadLine
  75. Prefixed each TSocketState value by 'ws' to avoid name conflict.
  76. Moved FHSocket member to private section because the property
  77. HSocket does the right job.
  78. Added a check for state closed when changing Port, Proto and Addr.
  79. Oct 22, 1997 V2.08 Added Flush method (asked by john@nexnix.co.uk) and
  80. FlushTimeout property (default to 60 seconds).
  81. Oct 22, 1997 V2.09 Added SendFlags property to enable sending in or out of
  82. band data (normal or urgent, see RFC-1122)
  83. Oct 28, 1997 V2.10 Added an OnLineTooLong event and code to handle the case
  84. where ReadLine has been called and the buffer overflowed (line
  85. long)
  86. Oct 29, 1997 V2.11 Added DnsLookup functionnality (DnsLookup method, DnsResult
  87. property and DnsLookupDone event).
  88. Calling the connect method with a hostname work well except that
  89. it could block for a long period (ie: 2 minutes) if DNS do not
  90. respond. Calling the connect method with a numeric IP address will
  91. never block. So you can call DnsLookup to start hostname
  92. resolution in the background, after some time you evenutually
  93. receive the OnDnsLookupDone event. The copy the DnsResult property
  94. to the Addr property and call connect.
  95. Oct 30, 1997 V2.12 added a check in DnsLookup to handel numeric IP which do
  96. not require any lookup. The numeric IP is treated immediately
  97. and immediately trigger the DnsLookupDone event.
  98. I modified the code to be compatible with Delphi 1.
  99. Oct 31, 1997 V2.13 added CancelDnsLookup procedure.
  100. Nov 09, 1997 V2.14 add LocalIPList function to get the list of local IP
  101. addresses (you have two IP addresses when connected to a LAN
  102. and an ISP).
  103. Nov 11, 1997 V2.15 Made TCustomWSocket with virtual functions. This will
  104. allow to easily descend a new component from TCustomWSocket.
  105. Make ReadLine stop when the connection is broken.
  106. Nov 12, 1997 V2.16 Corrected bug (Justin Yunke <yunke@productivity.org>)
  107. in LocalIPList: phe should be checked for nil.
  108. Nov 18, 1997 Added ReceiveStr function (Suggested by FLDKNHA@danisco.com)
  109. Nov 30, 1997 V2.18 Added a call to OnDnsLookupDone when canceling.
  110. Dec 04, 1997 V2.19 Added LocalPort property and SessionConnected event
  111. for UDP socket.
  112. V2.20 Modified MessageLoop and ProcessMessages to process not
  113. only the socket messages, but all messages (necessary if the
  114. thread has several TWSocket for example).
  115. Dec 09, 1997 V2.21 Corrected a minor bug in ReceiveStr. Detected by
  116. david@e.co.za (David Butler).
  117. Dec 10, 1997 V2.22 Corrected a minor bug in Send which now correctly
  118. returns the number of bytes sent. Detected by
  119. james.huggins@blockbuster.com
  120. Dec 16, 1997 V2.23 Corrected a bug which prevented the receiving of datagram
  121. from a UDP socket.
  122. Thank to Mark Melvin (melvin@misrg.ml.org) for pointing it.
  123. Dec 20, 1997 V2.24 Added the PeekData function as suggested by Matt Rose
  124. mcrose@avproinc.com
  125. Dec 26, 1997 V2.25 Added the Text property as suggested by Daniel P. Stasinski
  126. <dse@pacific.net>. Made GetXPort work even when listening as
  127. suggested by is81024@cis.nctu.edu.tw.
  128. Jan 10, 1998 V2.26 Check for null hostname in DNSLookup
  129. Added DnsResultList with all IP addresses returned form DNS
  130. Jan 13, 1998 V2.27 a Added MultiThreaaded property to tell the component that
  131. it is working in a thread and should take care of it (call
  132. internal ProcessMessages in place of Application.ProcessMessages,
  133. and do not use the WaitCtrl object).
  134. Jan 15, 1998 V2.28 WMAsyncSelect revisited to work properly with NT winsock 2.
  135. Feb 10, 1998 V2.29 Added an OnError event. If not assigned, then the component
  136. raise an exception when the error occurs.
  137. Feb 14, 1998 V2.30 Published Text property
  138. Feb 16, 1998 V2.31 Added virtual methods to trigger events
  139. Renamed all event handler variable to begin with FOn
  140. Feb 26, 1998 V2.32 Added procedure PutDataInSendBuffer and PutStringInSendBuffer
  141. Using PutDataInSendBuffer you can place data in the send buffer
  142. without actualy trying to send it. This allows to place several
  143. (probably small) data chunk before the component attempt to send
  144. it. This prevent small packet to be sent. You can call
  145. Send(nil, 0) to force the component to begin to send data.
  146. If the buffer was not empty, PutDataInSendBuffer will just queue
  147. data to the buffer. This data will be sent in sequence.
  148. Mar 02, 1998 V2.33 Changed the error check with WSAstartup as pointed out by
  149. Donald Strenczewilk (dstrenz@servtech.com)
  150. Mar 06, 1998 V2.34 Added a runtime property to change the buffer size.
  151. Mar 27, 1998 V2.35 Adapted for C++Builder 3
  152. Apr 08, 1998 V2.36 Made SetDefaultValue virtual
  153. Apr 13, 1998 V2.37 Reset FDnsLookupHandle to 0 after a failed call to
  154. WSACancelAsyncRequest
  155. Apr 22, 1998 V2.38 Published AllSent property to let outside know if our
  156. buffer has some data unsent.
  157. Apr 28, 1998 V2.39 Added LingerOnOff and LingerTimeout. Default values are
  158. wsLingerOn and timeout = 0 to behave by default as before.
  159. This value is setup just before Connect. Call SetLingerOption to
  160. set the linger option on the fly (the connection must be
  161. established to set the option). See winsock.closesocket on line
  162. help (winsock.hlp or win32.hlp) for a dsicussion of this option
  163. usage.
  164. May 06, 1998 V2.40 Added a workaround for Trumpet winsock inet_addr bug.
  165. Thanks to Andrej Cuckov <andrej@cuckov.com> for his code.
  166. May 18, 1998 V2.41 Jan Tomasek <xtomasej@feld.cvut.cz> found that Trumpet
  167. Winsock (Win 3.11) has some bugs and suggested a workaround in
  168. TryToSend procedure. This workaround makes TWSocket blocking in
  169. some cases. A new property enables the workaround. See code.
  170. Jun 01, 1998 V2.42 In finalization section, check for not assigned IPList.
  171. Jun 15, 1998 V2.43 Added code to finalization section to unload winsock if
  172. still loaded at that point (this happend if no socket where
  173. created but WinsockInfo called). Suggested by Daniel Fazekas
  174. <fdsoft@dns.gyor-ph.hu>
  175. Jun 27, 1998 V2.44 Added checks for valid arguments in SetPort, SetProto
  176. and SetAddr. Deferred address resolution until Connect or Listen.
  177. Jul 08, 1998 V2.45 Adadpted for Delphi 4
  178. Jul 20, 1998 V2.46 Added SetWindowLong(FWindowHandle, 0, 0) in the destructor
  179. and a check for TWSocket class in XSocketWindowProc.
  180. Added virtual method RealSend.
  181. Jul 23, 1998 V2.47 Added a TriggerSessionClosed from TryToSend in case of
  182. send error. This was called before, but with a nul error argument.
  183. Now it correctly gives the error number.
  184. Added a trashcan to receive data if no OnDataAvailable event
  185. handler is installed. Just receive the data and throw it away.
  186. Added reverse dns lookup asynchronous code (IP -> HostName).
  187. Thanks to Daniel Fazekas <fdsoft@dns.gyor-ph.hu> for his code.
  188. Jul 30, 1998 V2.48 Changed local variable "error" by FLastError in SocketError
  189. to make it available from the OnError handler. Thanks to
  190. dana@medical-info.com for finding this bug.
  191. In Abort procedure, deleted all buffered data because it was send
  192. the next time the socket is opened !
  193. Added CancelDnsLookup in Abort procedure.
  194. Aug 28, 1998 V2.49 Made InternalClose and ReceiveStr virtual
  195. Sep 01, 1998 V2.50 Ignore CancelDnsLookup exception during destroy
  196. Sep 29, 1998 V2.51 In InternalClose, protect AssignDefaultValue with
  197. try/except because SessionClosed event handler may have destroyed
  198. the component.
  199. Oct 11, 1998 V2.52 Changed Shutdown(2) to Shutdown(1) in Internal Close to
  200. prevent data lost on send. You may have to call Shutdown(2) in
  201. your own code before calling Close to have the same behaviour as
  202. before.
  203. Changed argument type for ASyncReceive and passed 0 from FD_CLOSE
  204. message handler.
  205. Oct 28, 1998 V2.53 Made WSocketLoadWinsock and WSocketUnloadWinsock public.
  206. Nov 11, 1998 V2.54 Added OnDisplay event for debugging purpose
  207. Nov 16, 1998 V2.55 Ignore WSANOTINITIALIZED error calling CloseSocket. This
  208. occurs when using TWSocket from a DLL and the finalization
  209. section is called before destroying TWSocket components (this is
  210. a program logic error).
  211. Made some properties and methods protected instead of private.
  212. Made some methods virtual.
  213. Added an Error argument to InternalClose.
  214. Added DoRecv virtual function.
  215. Added WSocketResolvePort
  216. Added WSocketResolveProto
  217. Deferred port and protocol resolution until really needed
  218. Transformed Listen to procedure (in case of failure Listen
  219. always calls SocketError which triggers an exception or the
  220. OnError event).
  221. Nov 22, 1998 V3.00 Skipped from V2.55 to V3.00. Socks support is major update!
  222. Added SOCKS5 (RFC-1928) support for TCP connection and
  223. simple usercode passwword authentication.
  224. Consider the socks code as beta !
  225. New properties: SocksServer, SocksPort, SocksUsercode,
  226. SocksPassword, FSocksAuthentication. New events: OnSocksError,
  227. OnSocksConnected, OnSocksAuthState.
  228. I used WinGate 2.1d to test my code. Unfortunately WinGate do
  229. not correctly handle user authentication, so the code here is
  230. just untested...
  231. Dec 05, 1998 V3.10 Removed ReadLine feature using TWait component.
  232. Added new TCustomLineWSocket and TCustomSyncWSocket.
  233. Those modifications implies that the ReadLine functionnality is
  234. slightly changed. Notably, the end of line marker is now
  235. configurable and remains in the received line unless a timeout
  236. occurs or the buffer is too small.
  237. Dec 10, 1998 V3.11 Added missing code to resolve port in the Listen method.
  238. Dec 12, 1998 V3.12 Added write method for LocalPort property. Thanks to
  239. Jan Tomasek <xtomasej@feld.cvut.cz> for his code.
  240. Added background exception handling.
  241. Fixed a bug in TCustomLineWSocket.TriggerDataAvailable which was
  242. not calling the inherited function when it actually should.
  243. Added a check on multithreaded in WaitForClose to call the
  244. correct ProcessMessages procedure.
  245. Added SOCKS4 support (only tcp connect is supported).
  246. Dec 28, 1998 V3.13 Changed WSocketResolveHost to check for invalid numeric
  247. IP addresses whitout trying to use them as hostnames.
  248. Dec 30, 1998 V3.14 Changed SetPort to SetRemotePort to solve the SetPort
  249. syndrome with BCB. Also chnaged GetPort to be consistant.
  250. Jan 12, 1999 V3.15 Introduced DoRecvFrom virtual function. This correct a bug
  251. introduced in V3.14 related to UDP and RecvFrom.
  252. Jan 23, 1999 V3.16 Changed FRcvdFlag computation in DoRecv and DoRecvFrom
  253. because it caused problems with HTTP component and large blocks.
  254. Removed modification by Jan Tomasek in TriggerDataAvailable
  255. Jan 30, 1999 V3.17 Added WSocketResolveIp function.
  256. Checked for tcp protocol before setting linger off in abort.
  257. Moved a lot of variables from private to protected sections.
  258. Removed check for Assigned(FOnDataSent) in WMASyncSelect.
  259. Feb 03, 1999 V3.18 Removed useless units in the uses clause.
  260. Feb 14, 1999 V4.00 Jump to next major version number because lots of
  261. fundamental changes have been done. See below.
  262. Use runtime dynamic link with winsock. All winsock functions
  263. used by TWSocket are linked at runtime instead of loadtime. This
  264. allows programs to run without winsock installed, provided program
  265. doesn't try to use TWSocket or winsock function without first
  266. checking for winsock installation.
  267. Removed WSocketLoadWinsock and all use to DllStarted because it
  268. is no longer necessary because winsock is automatically loaded
  269. and initialized with the first call to a winsock function.
  270. Added MessagePump to centralize call to the message pump.
  271. It is a virtual procedure so that you can override it to
  272. cutomize your message pump. Also changed slightly ProcessMessages
  273. to closely match what is done in the forms unit.
  274. Removed old stuff related to WaitCtrl (was already excluded from
  275. compilation using a conditional directive).
  276. Added NOFORMS conditional compilation to exclude the Forms unit
  277. from wsocket. This will reduce exe or dll size by 100 to 150KB.
  278. To use this feature, you have to add NOFORMS in your project
  279. options in the "defines" edit box in the "directory/conditional"
  280. tab. Then you must add a message pump to your application and
  281. call it from TWSocket.OnMessagePump event handler. TWSocket really
  282. need a message pump in order to receive messages from winsock.
  283. Depending on how your application is built, you can use either
  284. TWSocket.MessageLoop or TWSocket.ProcessMessages to quickly build
  285. a working message pump. Or you may build your own custom message
  286. pump taylored to your needs. Your message pump must set
  287. TWSocket.Terminated property to TRUE when your application
  288. terminates or you may experience long delays when closing your
  289. application.
  290. You may use NOFORMS setting even if you use the forms unit (GUI
  291. application). Simply call Application.ProcessMessages in the
  292. OnMessagePump event handler.
  293. OnMessagePump event is not visible in the object inspector. You
  294. must assign it at run-time before using the component and after
  295. having created it (in a GUI application you can do that in the
  296. FormCreate event, in a console application, you can do it right
  297. after TWSocket.Create call).
  298. Feb 17, 1999 V4.01 Added LineEcho and LineEdit features.
  299. Feb 27, 1999 V4.02 Added TCustomLineWSocket.GetRcvdCount to make RcvdCount
  300. property and ReceiveStr work in line mode.
  301. Mar 01, 1999 V4.03 Added conditional compile for BCB4. Thanks to James
  302. Legg <jlegg@iname.com>.
  303. Mar 14, 1999 V4.04 Corrected a bug: wsocket hangup when there was no
  304. OnDataAvailable handler and line mode was on.
  305. Apr 21, 1999 V4.05 Added H+ (long strings) and X+ (extended syntax)
  306. compilation options
  307. May 07, 1999 V4.06 Added WSAECONNABORTED to valid error codes in TryToSend.
  308. Jul 21, 1999 V4.07 Added GetPeerPort method, PeerPort and PeerAddr propertied
  309. as suggested by J. Punter <JPunter@login-bv.com>.
  310. Aug 20, 1999 V4.05 Changed conditional compilation so that default is same
  311. as latest compiler (currently Delphi 4, Bcb 4). Should be ok for
  312. Delphi 5.
  313. Added LocalAddr property as suggested by Rod Pickering
  314. <fuzzylogic123@yahoo.com>. LocalAddr default to '0.0.0.0' and is
  315. intended to be used by a client when connecting to a server, to
  316. select a local interface for multihomed computer. Note that to
  317. select an interface for a server, use Addr property before
  318. listening.
  319. LocalAddr has to be an IP address in dotted form. Valid values are
  320. '0.0.0.0' for any interface, '127.0.0.1' for localhost or any
  321. value returned by LocalIPList.
  322. Replaced loadtime import for ntohs and getpeername by runtime
  323. load.
  324. Revised check for dotted numeric IP address in WSocketResolveHost
  325. to allow correct handling of hostnames beginning by a digit.
  326. Added OnSendData event. Triggered each time data has been sent
  327. to winsock. Do not confuse with OnDataSent which is triggered
  328. when TWSocket internal buffer is emptyed. This event has been
  329. suggested by Paul Gertzen" <pgertzen@livetechnology.com> to
  330. easyly implement progress bar.
  331. Corrected WSocketGetHostByAddr to make it dynamically link to
  332. winsock.
  333. Sep 5, 1999 V4.09 Added CloseDelayed method.
  334. Make sure that TriggerSessionClosed is called from WMASyncSelect
  335. and InternalClose, even if there is no OnSessionClosed event
  336. handler assigned. This is required to make derived components
  337. work correctly.
  338. Created message WM_TRIGGER_EXCEPTION to help checking background
  339. exception handling (OnBgException event).
  340. Corrected bug for Delphi 1 and ReallocMem.
  341. Oct 02, 1999 V4.10 Added Release method.
  342. Oct 16, 1999 V4.11 Corrected a bug in TCustomLineWSocket.DoRecv: need to move
  343. data in front of buffer instead of changing buffer pointer which
  344. will crash the whole thing at free time.
  345. Oct 23, 1999 V4.12 Made WSocketIsDottedIP a public function
  346. Nov 12, 1999 V4.13 removed 3 calls to TriggerSocksAuthState because it was
  347. called twice. By A. Burlakov <alex@helexis.com>.
  348. Jan 24, 1999 V4.14 Call Receive instead of DoRecv from ReceiveStr to be sure
  349. to set LastError correctly. Thanks to Farkas Balazs
  350. <megasys@www.iridium.hu>
  351. Suppressed FDllName and used winsocket constant directly. I had
  352. troubles with some DLL code and string handling at program
  353. termination.
  354. Apr 09, 2000 V4.15 Added error number when resolving proto and port
  355. Apr 29, 2000 V4.16 Added WSocketForceLoadWinsock and
  356. WSocketCancelForceLoadWinsock. Thanks to Steve Williams.
  357. Created variable FSelectEvent to store current async event mask.
  358. Added ComponentOptions property with currently only one options
  359. wsoNoReceiveLoop which disable a receive loop in AsyncReceive.
  360. This loop breaking was suggested by Davie <smatters@smatters.com>
  361. to lower resource usage with really fast LAN and large transfers.
  362. By default, this option is disabled so there is no change needed
  363. in current code.
  364. May 20, 2000 V4.17 Made TSocket = u_int (same def as in winsock.pas)
  365. Moved bind after setting options.
  366. Thanks to Primoz Gabrijelcic <fab@siol.net>
  367. Jul 15, 2000 V4.18 Alon Gingold <gingold@hiker.org.il> changed
  368. TCustomSocksWSocket calls to inherited triggers of
  369. TriggerSessionConnected and TriggerDataAvailable.
  370. Now, it calls the trigger directly. This solves the problem
  371. of descendent classes with overridden triggers, not being
  372. called when a REAL connection was established, and when real
  373. data starts coming in. Special care MUST be taken in such
  374. overridden triggers to ONLY call the inherited trigger AND
  375. IMMEDIATELY EXIT when FSocksState <> socksData to avoid loopback
  376. Jul 22, 2000 V4.19 John Goodwin <john@jjgoodwin.com> found a failure in the
  377. logic for DnsLookup. He also implemented a workaround.
  378. See DnsLookup comments for explanation.
  379. Aug 09, 2000 V4.20 Alon Gingold <gingold2@mrm-multicat.com> found a bug in
  380. SOCKS4 implementation where a nul byte was incorrectly added
  381. (it should be added only with SOCKS4A version, not straith
  382. SOCKS4).
  383. Sep 17, 2000 V4.21 Eugene Mayevski <Mayevski@eldos.org> added TWndMethod for
  384. NOFORMS applications in other components.
  385. Oct 15, 2000 V4.22 Added method GetXAddr which returns local IP address to
  386. which a socket has been bound. There was already a GetXPort.
  387. Thanks to Wilfried Mestdagh <wilfried_sonal@compuserve.com>
  388. and Steve Williams <stevewilliams@kromestudios.com>.
  389. Nov 08, 2000 V4.23 Moved FSelectEvent from private to protected section.
  390. Nov 11, 2000 V4.24 Added LineLimit property and OnLineLimitExceeded event.
  391. When using line mode, line length is checked as each data block is
  392. comming. If the length is greater than the limit, then the event
  393. is triggered. You have the opportunity to close the socket or
  394. change the limit to a higher value. Thus you can prevent a hacker
  395. from locking your system by sending unlimited line which otherwise
  396. would eat up all system resources.
  397. Changed line handling variables to LongInt
  398. Checked all length involved in StrPCopy calls.
  399. Nov 26, 2000 V4.25 Do not trust GetRcvdCount. Always call Receive to check for
  400. incomming data (sometime NT4 will hang if we don't do that).
  401. Jan 24, 2001 V4.26 Blaine R Southam <bsoutham@iname.com> fixed out of bound
  402. error in TCustomLineWSocket.TriggerDataAvailable
  403. Feb 17, 2001 V4.27 Davie <smatters@smatters.com> fixed a bug causing byte lost
  404. when closing (related to wsoNoReceiveLoop option).
  405. May 04, 2001 V4.28 Fixed W2K bug (winsock message ordering)
  406. Jun 18, 2001 V4.29 Added AllocateHWnd and DeallocateHWnd from Forms unit to
  407. avoid warning from Delphi 6 in all other components.
  408. Jul 08, 2001 V4.30 Fixed small bug related to NOFOMRS and V4.29
  409. Jul 26, 2001 V4.31 Checked csDesigning in GetRcvdCount so that Delphi 6 does'nt
  410. crash when object inspector wants to display RcvdCount value.
  411. Added multicast capability and UDP ReuseAddr. Thanks to Mark
  412. G. Lewis <Lewis@erg.sri.com> for his code.
  413. Added TriggerSessionClosed to SocketError as suggested by Wilfried
  414. Mestdagh <wilfried_sonal@compuserve.com>
  415. Jul 28, 2001 V4.32 New option wsoTcpNoDelay implemented. Code by Arnaldo Braun
  416. <abraun@th.com.br>
  417. Jul 30, 2001 V4.33 Corrected at few glitches with Delphi 1
  418. Sep 08, 2001 V4.34 Added ThreadAttach and related functions
  419. Nov 27, 2001 V4.35 Added type definition for in_addr and Delphi 2 (Yes there are
  420. still some peoples who wants to use it. Don't ask me why !).
  421. Dec 02, 2001 V4.36 david.brock2@btinternet.com found a bug in SOCKS4 where
  422. error check incorrectly checked "FRcvBuf[1] = #$90" instead of
  423. "FRcvBuf[1] <> #90". He also found a bug when receiving domain name
  424. where length of name was incorrectly copyed to the buffer.
  425. Dec 23, 2001 V4.37 Removed bWrite, nMoreCnt, bMoreFlag and nMoreMax which where
  426. not more really used. Thanks to Al Kirk <akirk@pacific.net> for
  427. showing that.
  428. Feb 24, 2002 V4.38 Wilfried Mestdagh <wilfried@mestdagh.biz> added ThreadDetach
  429. and a property editor for LineEnd. XSocketDeallocateHWnd made a
  430. function.
  431. I created a new unit WSocketE.pas to put Wilfried's property
  432. editor so that it works correctly with Delphi 6.
  433. Apr 24, 2002 V4.39 Removed OnLineTooLong event which was not used anywhere.
  434. Use OnLineLimitExceeded event if you used this event.
  435. Thanks to Alex Kook <cookis@mail.ru> for finding this one.
  436. Apr 27, 2002 V4.40 Added procedure WSocketUnregisterClass to be able to
  437. unregister hidden window. This is necessary when TWSocket is
  438. used within a DLL which is unloaded and reloaded by applications,
  439. specially when running with Windows-XP. Thanks to Jean-Michel Aliu
  440. <jmaliu@jmasoftware.com> who provided a test case.
  441. Jun 02, 2002 V4.41 allow SOCK_RAW in Connect method for any protocol which is
  442. not TCP or UDP. Thanks to Holger Lembke <holger@hlembke.de>.
  443. Jun 04, 2002 V4.42 Do not call Listen for SOCK_RAW.
  444. Thanks to Holger Lembke <holger@hlembke.de>.
  445. Jun 08, 2002 V4.43 Add a dummy Register procedure for BCB1.
  446. Thanks to Marc-Alexander Prowe <listen@mohajer.de>.
  447. Jul 07, 2002 V4.44 Added code in Connect method to check if socket still opened
  448. after OnChangeState event. If not, trigger an error WSAINVAL.
  449. Sep 16, 2002 V4.45 Exposed RcvdPtr and RcvdCnt readonly properties.
  450. Sep 17, 2002 V4.46 Used InterlockedIncrement/InterlockedDecrement to Inc/Dec
  451. socket count safely when TWSocket is used within a thread. This
  452. was proposed by Matthew Meadows <matthew.meadows@inquisite.com>
  453. Sep 28, 2002 V4.47 Changed DnsLookup so that a hostname is checked for dotted
  454. IP addresse and resolve it numerically. Thanks to Bogdan Calin
  455. <soul4blade@yahoo.com> who found this bug. Alos loaded the result
  456. list with the address to be consistant with real lookup result.
  457. Nov 17, 2002 V4.48 Roland Klabunde <roland.klabunde@gmx.net> found a bug in
  458. multicast code: listening on a specific interface was ignored.
  459. He fixed Listen and Connect.
  460. Nov 27, 2002 V4.49 Added ListenBacklog property, default to 5.
  461. Dec 17, 2002 V4.50 Moved code to virtual function to permit SSL implementation.
  462. Jan 19, 2003 V5.00 First pre-release for ICS-SSL. New major version number
  463. V5.01 Gabi Slonto <buffne01@gmx.net> found a bug in DnsLookup
  464. when hostname was actulally a dotted IP address.
  465. Mar 18, 2003 V5.02 Fixed WSocketIsDottedIP: reordering of boolean expressions
  466. involaving a string. Thanks to Ian Baker <ibaker@codecutters.org>
  467. Apr 30, 2003 V5.03 Replaced all calls to setsockopt by calls to
  468. WSocket_setsockopt to avoid statically linked winsock DLL.
  469. Thanks to Piotr Dalek <enigmatical@interia.pl>.
  470. Also replaced inet_addr by WSocket_inet_addr.
  471. Aug 27, 2003 V5.04 Marco van de Voort <marcov@stack.nl> added FreePascal (FPC)
  472. conditional compilation. Please contact him for any FPC support
  473. question.
  474. Aug 28, 2003 V5.05 Fixed a multithreading issue related to windows class
  475. registration. Now using a critical section around the code.
  476. Thanks to Bogdan Ureche <bureche@omnivex.com> for his precious help.
  477. Aug 31, 2003 V5.06 Added warning about deprecated procedures Synchronize,
  478. WaitUntilReady and ReadLine. Do not use them in new applications.
  479. Sep 03, 2003 V5.07 Bogdan Ureche <bureche@omnivex.com> added a critical section
  480. to avoid problem when winsock.dll is unloaded by a thread while
  481. another thread is still using some TWSocket.
  482. Sep 15, 2003 V5.08 Fixed finalization section to no free critical section if
  483. a TWSocket is still existing. This happend for example when a
  484. TWSocket is on a form and Halt is called from FormCreate event.
  485. Changed SendStr argument to const.
  486. Nov 09, 2003 V5.09 Added manifest constants for Shutdown
  487. Added TCustomLineWSocket.SendLine method.
  488. Jan 16, 2004 V5.10 Added "const" in front of all method using strings.
  489. Jan 17, 2004 V5.11 Modified TriggerDataAvailable so that when in LineMode, we
  490. check if a line is still in the buffer of already received data.
  491. Also updated WMTriggerDataAvailable to avoid infinite loops.
  492. Introduced FLineFound to flag when a line has been found.
  493. See "OLD_20040117" to find this code.
  494. Jan 21, 2004 V5.12 Checked null string in PutStringInSendBuffer and null
  495. pointer in PutDataInSendBuffer.
  496. Jan 26, 2004 V5.13 Conditional compilation for BCB for constants for Shutdown.
  497. Reordered uses clause for FPC compatibility.
  498. Fixed TCustomLineWSocket.TriggerDataAvailable to deliver data
  499. already received while in line mode but after component user
  500. turned line mode off in the middle of the way. This could occur
  501. for example in a HTTP application where line mode is used to
  502. receive HTTP header line and turned off when last header line is
  503. found. At that point, if posted data (HTTP document) was completely
  504. in the same packet as the last header line, that data was not
  505. delivered until the next packet comes, which could never occur !
  506. Mar 20, 2004 V5.14 Added partial support for RAW socket.
  507. To use RAW sockets, set Proto to 'raw_ip', 'raw_icmp', ...
  508. Set Port to '0' or whatever value is useful for the protocol.
  509. When using IP protocol, you can add option wsoSIO_RCVALL so that
  510. your program receive ALL datagrams when you listen on a given
  511. interface (You can't use 0.0.0.0).
  512. Do not use Connect with RAW socket. Always use Listen and then
  513. use SendTo to send datagrams use the socket.
  514. Added ReqVerHigh and ReqVerLow properties to be able to select
  515. which winsock version you want to load. Default to 1.1 but need
  516. 2.2 for RAW sockets to be used.
  517. Mar 24, 2004 V5.15 Changed WSocket_Synchronized_ResolveProto to hard code
  518. protocol number for tcp, udp and raw.
  519. Apr 17, 2004 V6.00 New major release started. Move all platform and runtime
  520. dependencies to separate units. New base component for handling
  521. component with window handle.
  522. Jun 20, 2004 V 5.16 John Mulvey <john@mulvey.eurobell.co.uk> fixed error message
  523. in GetPeerAddr which incorrectly reported an error about
  524. GetPeerName.
  525. May 23, 2005 V5.17 PutDataInSendBuffer set bAllSent to false.
  526. Jun 03, 2005 V5.18 Added SocketSndBufSize property which gives the size of
  527. winsock internal send buffer. When using TCP, you must make sure
  528. you never use a BufSize equal or greater than this value or
  529. you'll experience bad performances. See description in MSDN
  530. http://support.microsoft.com/default.aspx?scid=kb;en-us;823764
  531. Default value for BufSize is 1460 and SocketSndBufSize is 8192 so
  532. there is no problem when not changing those values.
  533. Jun 18, 2005 V5.19 Made TCustomSocksWSocket.Connect accept 'tcp' as well as '6'
  534. for protocol. By Piotr "Hellrayzer" Dalek.
  535. Renamed event OnDisplay to OnDebugDisplay.
  536. Sept 4, 2005 V5.20 added BufferedByteCount property used to ensure winsock has sent
  537. data, currently used in TFtpCli to check a put has finished correctly
  538. Thanks to Tobias Giesen <tobias@tgtools.de> for the fix
  539. Dec 27, 2005 V6.00a Updated new release with change done in the old release.
  540. Dec 31, 2005 V6.00b added new debug and logging event and log levels, replacing
  541. conditional debug code with optional code to avoid rebuilding apps.
  542. Works in combination with new component TIcsLogger.
  543. This is controlled by the new LogOptions property:
  544. loDestEvent - write to OnIcsLogEvent (called from higher level protocols)
  545. loDestFile - write to file debug_out.myprog.txt
  546. loDestOutDebug - write to OutputDebugString (shown in Debugger Event Log window)
  547. loAddStamp - time stamp each log line (accurate only to about 18ms)
  548. loWsockErr - log wsocket errors
  549. loWsockInfo - log wsocket general information
  550. loWsockDump - log wsocket data (not implemented yet)
  551. loSslErr - log SSL errors
  552. loSslInfo - log SSL general information
  553. loSslDump - log SSL packets and data
  554. loProtSpecErr - log protocol specific error
  555. loProtSpecInfo - log protocol specific general information
  556. loProtSpecDump - log protocol specific data and packets
  557. Jan 22, 2006 V6.00c Added some KeepAlive stuff (seems winsock is bugged and
  558. doesn't care any setting done !).
  559. Jan 28, 2006 V6.00d Gerhard Rattinger fixed SetKeepAliveOption for Delphi 3
  560. Mar 09, 2006 V6.00e Arno made properties to select keepalive parameters.
  561. He also fixed ReverseDnsLookup to return a list of
  562. host names (aliases) instead of just the first entry. Added func.
  563. ReverseDnsLookupSync.
  564. Apr 27, 2006 V6.00f Roger Tinembart <tinembart@brain.ch> added a critical section
  565. around the list of sendbuffers (FBufHandler) to avoid problems when
  566. the data is placed in the sendbuffer (for example with SendStr)
  567. by a different thread than the one that is effectively sending the
  568. data with TryToSend
  569. June 11, 2006 V6.01 Use new TIcsBufferHandler.
  570. Aug 06, 2006 V6.02 Angus added GetWinsockErr to give alpha and numeric winsock
  571. errors and improved many other error messages,
  572. and fixed FReadCount for 64-bit downloads
  573. added some EXTERNALSYM for BCB compatiblity
  574. Aug 18, 2006 V6.03 Fixed a bug in ASyncReceive(). This bug caused data loss.
  575. Oct 28, 2006 V6.04 Added setter for SocketSndBufSize and SocketRcvBufSize
  576. Dec 22, 2006 V6.05 Oliver Grahl fixed SendLine to properly count LineEnd characters.
  577. Jan 18, 2007 V6.06 Fixed constructor and DeleteBufferedData to behave correctly
  578. when an exception occur in AllocateSocketHWnd.
  579. Mar 23, 2007 V6.07 Removed FD_CONNECT from dup().
  580. Apr 04, 2007 V6.08 Arno Garrels updated SetKeepAliveOption
  581. Mar 10, 2008 V6.09 Francois Piette & Arno Garrels made some changes to
  582. prepare code for Unicode
  583. WSocket_gethostname conversion from String to AnsiString
  584. WSocketGetProc and WSocket2GetProc use AnsiString
  585. GetAliasList simplified and use AnsiString
  586. Apr 25, 2008 V6.10 A. Garrels, added some getters/setters to store and use some
  587. string-property-values as AnsiString internally.
  588. This reduced number of string casts with potential data loss to 17.
  589. These ansi-values are used to call winsock API that doesn't provide
  590. W functions. Modified depending code including some type changes
  591. from PChar to PAnsiChar. Made some casts Unicode => Ansi with
  592. potential data loss *explicit* casts (conditionally compiled) some
  593. unicode strings with only 7 bit ASCII characters are casted using
  594. new function UnicodeToAscii() in new unit OverbyteIcsUtils which
  595. should be fast and reliable and doesn't produce compiler warnings.
  596. Added new warning symbols.
  597. Apr 30, 2008 V6.11 A. Garrels - Function names adjusted according to changes in
  598. OverbyteIcsLibrary.pas.
  599. May 11, 2008 V6.12 USchuster removed local atoi implementation (atoi is now in
  600. OverbyteIcsUtils.pas)
  601. May 15, 2008 V6.13 AGarrels type change of some published String properties
  602. to AnsiString, this is an attempt to avoid too many implicit
  603. string casts, only a few higher level components have been adjusted
  604. accordingly so far.
  605. Jun 30, 2008 A.Garrels made some changes to prepare SSL code for Unicode.
  606. Jul 04, 2008 V6.11 Rev.58 SSL - Still lacked a few changes I made last year.
  607. Jul 13, 2008 V6.12 Added SafeWSocketGCount
  608. Aug 03, 2008 V6.16 A. Garrels removed packed from record TExtension.
  609. Jul 07, 2008 V6.17 Still a small fix from December 2007 missing in SSL code.
  610. Aug 11, 2008 V6.18 A. Garrels - Type AnsiString rolled back to String.
  611. Two bugs fixed in SSL code introduced with Unicode change.
  612. Socks was not fully prepared for Unicode.
  613. Sep 19, 2008 V6.19 A. Garrels changed some AnsiString types to RawByteString.
  614. Sep 21, 2008 V6.20 A. Garrels removed BoolToStr(), available since D7
  615. Oct 22, 2008 V7.21 A. Garrels removed the const modifier from parameter Data
  616. in function SendTo to fix a bug in C++ Builder.
  617. Nov 03, 2008 V7.22 Added property Counter, a class reference to TWSocketCounter
  618. which provides some useful automatic counters. By default property
  619. Counter is unassigned and has to be enabled by a call to
  620. CreateCounter.
  621. Apr 24, 2009 V7.23 A. Garrels added *experimental* OpenSSL engine support which
  622. is not compiled in by default. You have to uncomment conditional
  623. define OPENSSL_NO_ENGINE in OverbyteIcsSslDefs.inc and rebuild your
  624. packages to get it included. With engine support included a new
  625. published property AutoEnableBuiltinEngines of TSslContext has to
  626. be set to TRUE in order to enable OpenSSL's built-in hardware
  627. accelerators support, that's all.
  628. ******************************************************************
  629. * Due to the lack of hardware this feature is completely untested*
  630. ******************************************************************
  631. Any feedback and fixes are welcome, please contact the ICS mailing
  632. list. The OpenSSL engine documentation can be found here:
  633. http://openssl.org/docs/crypto/engine.html
  634. Additionally a new component TSslEngine is installed on the palette.
  635. Its purpose is to control (dynamic) engines.
  636. Typically control commands of an OpenSC dynamic pkcs11 engine
  637. (SmartCard) are :
  638. Cmds.Add('SO_PATH=d:\opensc\bin\engine_pkcs11.dll');
  639. Cmds.Add('ID=pkcs11');
  640. Cmds.Add('LIST_ADD=1');
  641. Cmds.Add('LOAD=');
  642. Cmds.Add('MODULE_PATH=d:\opensc\bin\opensc-pkcs11.dll');
  643. Cmds.Add('INIT='); <= Special ICS-control command to initialize the engine
  644. Sample test code (Dod couldn't get it working :(
  645. It assumes that the X509 certificate has been exported from
  646. the SmartCard to PEM file that is available in property
  647. SslCertFile. It's also assumed that SslEngine1 is created
  648. dynamically at run-time in this sample.
  649. We are in new event TSslContext.OnBeforeInit:
  650. if not Assigned(SslEngine1) then
  651. begin
  652. SslEngine1 := TSslEngine.Create(Self);
  653. try
  654. SslEngine1.NameID := 'dynamic';
  655. // The SmartCard holds the private key.
  656. // Next two lines advise SslContext to load the key
  657. // from the engine instead from PEM file.
  658. TSslContext(Sender).CtxEngine := SslEngine1;
  659. SslEngine1.CtxCapabilities := [eccLoadPrivKey];
  660. // The PIN code is expected in property SslPassPhrase
  661. TSslContext(Sender).SslPassPhrase := 'ics';
  662. // Tell the engine which key to use.
  663. SslEngine1.KeyID := KeyIdEdit.Text;
  664. // At first open the engine
  665. if not SslEngine1.Open then
  666. raise Exception.Create(FEngine.LastErrorMsg);
  667. // Now send our vendor specific control commands
  668. for I := 0 to Cmds.Count -1 do
  669. begin
  670. if not SslEngine1.Control(Cmds.Names[I],
  671. Cmds.ValueFromIndex[I]) then
  672. raise Exception.Create(SslEngine1.LastErrorMsg);
  673. end;
  674. Display('Engine set up and loaded successfully');
  675. except
  676. FreeAndNil(SslEngine1);
  677. raise;
  678. end;
  679. end;
  680. Jun 12, 2009 V7.24 Angus added WriteCount property, how many bytes sent since
  681. connection opened
  682. Only reset ReadCount when connection opened, not closed
  683. Jul 16, 2009 V7.25 Arno fixed and changed SetCounterClass()
  684. Jul 19, 2009 V7.26 Arno - SSL code ignored FPaused flag, the change is in
  685. TCustomSslWSocket.TriggerEvent.
  686. Sep 04, 2009 V7.27 Set option TCP_NODELAY in Dup as well as provide a public
  687. method to set this option, similar as suggested by
  688. Samuel Soldat.
  689. Sep 08, 2009 V7.28 Arno - Minor Unicode bugfix in TX509Base.GetExtension().
  690. Sep 09, 2009 V7.29 Arno - Added new public methods TX509Base.WriteToBio() and
  691. TX509Base.ReadFromBio(). Method SafeToPemFile got an arg.
  692. that adds human readable certificate text to the output.
  693. InitializeSsl inlined. Removed a Delphi 1 conditional.
  694. Sep 17, 2009 V7.30 Anton Sviridov optimized setting of SSL options.
  695. Sep 17, 2009 V7.31 Arno fixed a Unicode bug in TX509Base.GetExtension and
  696. a general bug in TX509Base.GetSha1Hash (AnsiString as
  697. digest buffer should really be avoided)
  698. Sep 18, 2009 V7.32 Arno changed visibility of TX509Base.WriteToBio() and
  699. TX509Base.ReadFromBio() to protected.
  700. Nov 01, 2009 V7.33 Arno fixed a memory overwrite bug in
  701. TCustomSocksWSocket.DoRecv().
  702. Nov 07, 2009 V7.34 OpenSSL V0.9.8L disables session renegotiation due to
  703. TLS renegotiation vulnerability.
  704. Dec 20, 2009 V7.35 Arno added support for SSL Server Name Indication (SNI).
  705. SNI has to be turned on in OverbyteIcsSslDefs.inc, see define
  706. "OPENSSL_NO_TLSEXT". Exchanged symbol "NO_ADV_MT" in the
  707. SSL source by "NO_SSL_MT" (This and SNI was sponsored by
  708. Fastream Technologies).
  709. SNI Howto: In SSL server mode assign event OnSslServerName,
  710. it triggers whenever a client sent a server name in the TLS
  711. client helo. From the event handler read public property
  712. SslServerName, lookup and pass a matching, valid and
  713. initialized SslContext instance associated with the server name.
  714. In SSL client mode, if property SslServerName was not empty
  715. this server name is sent to the server in the TLS client helo.
  716. Currently IE 7 and FireFox >= V2 support SNI, note that both
  717. browers don't send both "localhost" and IP addresses as
  718. server names, this is specified in RFC.
  719. Dec 24, 2009 V7.36 SSL SNI - Do not switch context if not initialized.
  720. Dec 26, 2009 V7.37 Arno fixed TCustomSyncWSocket.ReadLine for Unicode. It
  721. now takes an AnsiString buffer. Since this method is highly
  722. deprecated it's also marked as "deprecated". Do not use it
  723. in new applications.
  724. May 08, 2010 V7.38 Arno Garrels added support for OpenSSL 0.9.8n. Read comments
  725. in OverbyteIcsLIBEAY.pas for details.
  726. May 16, 2010 V7.39 Arno Garrels reenabled check for nil in WMAsyncGetHostByName.
  727. Jun 10, 2010 V7.40 Arno Garrels added experimental timeout and throttle feature
  728. to TWSocket. Currently both features have to be enabled
  729. explicitly with conditional defines BUILTIN_TIMEOUT
  730. and/or BUILTIN_THROTTLE (see OverbyteIcsDefs.inc )
  731. Aug 02, 2010 V7.41 Arno removed an option to send plain UTF-16 strings with
  732. SendStr() and SendLine() by passing 1200 (CP_UTF16) in the
  733. codepage parameter. Changed SendLine() to return correct
  734. number of bytes written.
  735. Aug 08, 2010 V7.42 FPiette prevented socket close in TCustomWSocket.Destroy when
  736. socket state is wsInvalidState (this happend when an
  737. exception is raise early in the constructor).
  738. Sep 05, 2010 V7.43 Arno fixed a bug in the experimental throttle and timeout
  739. source which made it impossible to use both features at the
  740. same time. Renamed conditionals EXPERIMENTAL_THROTTLE and
  741. EXPERIMENTAL_TIMEOUT to BUILTIN_THROTTLE and BUILTIN_TIMEOUT.
  742. It's now possible to either enable them in OverbyteIcsDefs.inc
  743. or define them in project options.
  744. Sep 08, 2010 V7.44 Arno reworked the experimental timeout and throttle code.

Large files files are truncated, but you can click here to view the full file