Pārlūkot izejas kodu

Remove old installer/launcher/uninstaller and libs

Change-Id: I4d415e36a46ac1977d40dc039d023947eb7bf502
Reviewed-on: http://gerrit.dmdirc.com/1727
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.6.5rc1
Chris Smith 13 gadus atpakaļ
vecāks
revīzija
189e4bbec4
66 mainītis faili ar 0 papildinājumiem un 98302 dzēšanām
  1. 0
    9
      installer/release.sh
  2. 0
    115
      installer/windows/Launcher.dpr
  3. 0
    393
      installer/windows/MD5.pas
  4. 0
    469
      installer/windows/Setup.dpr
  5. Binārs
      installer/windows/Shortcut.exe
  6. 0
    17
      installer/windows/UAC.manifest
  7. 0
    17
      installer/windows/UAC_uninstaller.manifest
  8. 0
    199
      installer/windows/Uninstaller.dpr
  9. 0
    661
      installer/windows/makeInstallerWindows.sh
  10. 0
    220
      libwin/Vista.pas
  11. 0
    1
      libwin/kolfpc/COPYING
  12. 0
    517
      libwin/kolfpc/COPYING.LIB
  13. 0
    75
      libwin/kolfpc/KOL-CE.rc
  14. 0
    57984
      libwin/kolfpc/KOL.PAS
  15. 0
    125
      libwin/kolfpc/KOLCEOpenDir.inc
  16. 0
    240
      libwin/kolfpc/KOLCE_IniFile.inc
  17. 0
    146
      libwin/kolfpc/KOLDEF.INC
  18. 0
    1354
      libwin/kolfpc/KOLDirDlgEx.pas
  19. 0
    909
      libwin/kolfpc/KOLMHToolTip.pas
  20. 0
    17630
      libwin/kolfpc/KOL_ASM.inc
  21. 0
    1160
      libwin/kolfpc/KOL_unicode.inc
  22. 0
    3619
      libwin/kolfpc/KOLadd.pas
  23. 0
    51
      libwin/kolfpc/LICENSE.txt
  24. 0
    77
      libwin/kolfpc/MCKfakeClasses.inc
  25. 0
    64
      libwin/kolfpc/READ1ST.TXT
  26. 0
    25
      libwin/kolfpc/Readme-KOL-CE.txt
  27. 0
    1512
      libwin/kolfpc/delphicommctrl.inc
  28. 0
    46
      libwin/kolfpc/delphidef.inc
  29. 0
    1
      libwin/kolfpc/delphiusesh.inc
  30. 0
    561
      libwin/kolfpc/fpc_unicode_add.inc
  31. 0
    61
      libwin/kolfpc/read1st_rus.txt
  32. 0
    1114
      libwin/kolfpc/visual_xp_styles.inc
  33. 0
    26
      libwin/lcore/Makefile
  34. 0
    148
      libwin/lcore/bfifo.pas
  35. 0
    632
      libwin/lcore/binipstuff.pas
  36. 0
    106
      libwin/lcore/blinklist.pas
  37. 0
    101
      libwin/lcore/bsearchtree.pas
  38. 0
    593
      libwin/lcore/btime.pas
  39. 0
    394
      libwin/lcore/dnsasync.pas
  40. 0
    880
      libwin/lcore/dnscore.pas
  41. 0
    407
      libwin/lcore/dnssync.pas
  42. 0
    357
      libwin/lcore/dnswin.pas
  43. 0
    297
      libwin/lcore/fastmd5.pas
  44. 0
    72
      libwin/lcore/fd_utils.pas
  45. 0
    906
      libwin/lcore/lcore.pas
  46. 0
    40
      libwin/lcore/lcoreconfig.inc
  47. 0
    142
      libwin/lcore/lcoregtklaz.pas
  48. 0
    432
      libwin/lcore/lcorernd.pas
  49. 0
    382
      libwin/lcore/lcoreselect.pas
  50. 0
    233
      libwin/lcore/lcorewsaasyncselect.pas
  51. 0
    34
      libwin/lcore/lloopback.pas
  52. 0
    675
      libwin/lcore/lmessages.pas
  53. 0
    201
      libwin/lcore/lsignal.pas
  54. 0
    747
      libwin/lcore/lsocket.pas
  55. 0
    42
      libwin/lcore/ltimevalstuff.inc
  56. 0
    20
      libwin/lcore/pgtypes.pas
  57. 0
    1
      libwin/lcore/todo.txt
  58. 0
    14
      libwin/lcore/uint32.inc
  59. 0
    114
      libwin/lcore/unitfork.pas
  60. 0
    53
      libwin/lcore/unitsettc.pas
  61. 0
    128
      libwin/lcore/unitwindowobject.pas
  62. 0
    113
      libwin/lcore/unixstuff.inc
  63. 0
    382
      libwin/lcore/wcore.pas
  64. 0
    40
      libwin/lcore/wmessages.pas
  65. 0
    19
      libwin/lcore/zlib_license.txt
  66. 0
    199
      libwin/shared.pas

+ 0
- 9
installer/release.sh Parādīt failu

@@ -196,15 +196,6 @@ if [ "windows" = "${BUILDTARGET}" -o "" = "${BUILDTARGET}" ]; then
196 196
 	cd ${THISDIR}
197 197
 fi;
198 198
 
199
-if [ "oldwindows" = "${BUILDTARGET}" ]; then
200
-	echo "================================================================"
201
-	echo "Building Old Windows installer"
202
-	echo "================================================================"
203
-	cd windows
204
-	./makeInstallerWindows.sh ${OPT}${JARFILE}${JRE}-k -s ${TAGGED}${BRANCH}${RELEASE} -p "${plugins_windows}"
205
-	cd ${THISDIR}
206
-fi;
207
-
208 199
 if [ "osx" = "${BUILDTARGET}" -o "" = "${BUILDTARGET}" ]; then
209 200
 	echo "================================================================"
210 201
 	echo "Building OSX Bundle"

+ 0
- 115
installer/windows/Launcher.dpr Parādīt failu

@@ -1,115 +0,0 @@
1
-{*
2
- * This application launches the dmdirc java-based installer.
3
- * 
4
- * DMDirc - Open Source IRC Client
5
- * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
6
- * 
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- * 
14
- * The above copyright notice and this permission notice shall be included in
15
- * all copies or substantial portions of the Software.
16
- * 
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- *}
25
-program Launcher;
26
-{$MODE Delphi}
27
-{$APPTYPE GUI}
28
-
29
-uses Windows, SysUtils, classes, MD5;
30
-procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
31
-
32
-//{$R files.res}
33
-//{$R version.res}
34
-//{$R icon.res}
35
-{$R all.res}
36
-
37
-{$I consts.inc}
38
-
39
-function GetTempDirectory(): String;
40
-var
41
-	buf: array[0..MAX_PATH] of Char;
42
-	wintemp, temp: String;
43
-begin
44
-	GetTempPath(SizeOf(buf)-1, buf);
45
-	wintemp := StrPas(buf);
46
-	Randomize;
47
-	temp := '\DMDirc-installer-'+inttostr(1000 + Random(1000));
48
-	while (DirectoryExists(wintemp+temp+'\')) do begin
49
-		temp := temp+'-'+inttostr(1+Random(1000));
50
-	end;
51
-	MkDir(wintemp+temp+'\');
52
-	result := wintemp+temp+'\';
53
-end;
54
-
55
-procedure ExtractResource(name: string; filename: string; dir: string = '');
56
-var
57
-	rStream: TResourceStream;
58
-	fStream: TFileStream;
59
-	fname: string;
60
-begin
61
-	if (dir = '') or (not DirectoryExists(dir)) then dir := IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)));
62
-	fname := dir+filename;
63
-	if FileExists(fname) then DeleteFile(fname);
64
-	
65
-	rStream := TResourceStream.Create(hInstance, name, RT_RCDATA);
66
-	try
67
-		fStream := TFileStream.Create(fname, fmCreate);
68
-		try
69
-			fStream.CopyFrom(rStream, 0);
70
-		finally
71
-			fStream.Free;
72
-		end;
73
-	finally
74
-		rStream.Free;
75
-	end;
76
-end;
77
-
78
-procedure Launch(sProgramToRun: String);
79
-var
80
-	StartupInfo: TStartupInfo;
81
-	ProcessInfo: TProcessInformation;
82
-begin
83
-	FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
84
-	with StartupInfo do begin
85
-		cb := SizeOf(TStartupInfo);
86
-		dwFlags := STARTF_USESHOWWINDOW;
87
-		wShowWindow := SW_SHOWNORMAL;
88
-	end;
89
-
90
-	CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
91
-end;
92
-
93
-function checkMD5(filename: String): boolean;
94
-var
95
-	hash: String;
96
-begin
97
-	hash := MD5Print(MD5File(filename));
98
-	result := (hash = MD5SUM);
99
-//	if not result then begin
100
-//		MessageBox(0, PChar('MD5Hash Result:'+#10+'Got: '+hash+#10+'Exp: '+MD5SUM+#10+'Res:'+booltostr(hash = MD5SUM)), 'Test', MB_OK + MB_ICONSTOP);
101
-//	end;
102
-
103
-// Uncomment this to disable MD5 Check
104
-//	result := true;
105
-end;
106
-
107
-var
108
-	ErrorMessage: String;
109
-	TempDir: String;
110
-begin
111
-        InitCommonControls;
112
-	TempDir := GetTempDirectory;
113
-	ErrorMessage := '';
114
-	{$I ExtractCode.inc}
115
-end.

+ 0
- 393
installer/windows/MD5.pas Parādīt failu

@@ -1,393 +0,0 @@
1
-                                                                              // tabs = 2
2
-// -----------------------------------------------------------------------------------------------
3
-//
4
-//                                 MD5 Message-Digest for Delphi 4
5
-//
6
-//                                 Delphi 4 Unit implementing the
7
-//                      RSA Data Security, Inc. MD5 Message-Digest Algorithm
8
-//
9
-//                          Implementation of Ronald L. Rivest's RFC 1321
10
-//
11
-//                      Copyright � 1997-1999 Medienagentur Fichtner & Meyer
12
-//                                  Written by Matthias Fichtner
13
-//
14
-// -----------------------------------------------------------------------------------------------
15
-//               See RFC 1321 for RSA Data Security's copyright and license notice!
16
-// -----------------------------------------------------------------------------------------------
17
-//
18
-//     14-Jun-97  mf  Implemented MD5 according to RFC 1321                           RFC 1321
19
-//     16-Jun-97  mf  Initial release of the compiled unit (no source code)           RFC 1321
20
-//     28-Feb-99  mf  Added MD5Match function for comparing two digests               RFC 1321
21
-//     13-Sep-99  mf  Reworked the entire unit                                        RFC 1321
22
-//     17-Sep-99  mf  Reworked the "Test Driver" project                              RFC 1321
23
-//     19-Sep-99  mf  Release of sources for MD5 unit and "Test Driver" project       RFC 1321
24
-//
25
-// -----------------------------------------------------------------------------------------------
26
-//                   The latest release of md5.pas will always be available from
27
-//                  the distribution site at: http://www.fichtner.net/delphi/md5/
28
-// -----------------------------------------------------------------------------------------------
29
-//                       Please send questions, bug reports and suggestions
30
-//                      regarding this code to: mfichtner@fichtner-meyer.com
31
-// -----------------------------------------------------------------------------------------------
32
-//                        This code is provided "as is" without express or
33
-//                     implied warranty of any kind. Use it at your own risk.
34
-// -----------------------------------------------------------------------------------------------
35
-
36
-unit md5;
37
-{$MODE Delphi}
38
-// -----------------------------------------------------------------------------------------------
39
-INTERFACE
40
-// -----------------------------------------------------------------------------------------------
41
-
42
-uses
43
-	Windows;
44
-
45
-type
46
-	MD5Count = array[0..1] of DWORD;
47
-	MD5State = array[0..3] of DWORD;
48
-	MD5Block = array[0..15] of DWORD;
49
-	MD5CBits = array[0..7] of byte;
50
-	MD5Digest = array[0..15] of byte;
51
-	MD5Buffer = array[0..63] of byte;
52
-	MD5Context = record
53
-		State: MD5State;
54
-		Count: MD5Count;
55
-		Buffer: MD5Buffer;
56
-	end;
57
-
58
-procedure MD5Init(var Context: MD5Context);
59
-procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);
60
-procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
61
-
62
-function MD5String(M: string): MD5Digest;
63
-function MD5File(N: string): MD5Digest;
64
-function MD5Print(D: MD5Digest): string;
65
-
66
-function MD5Match(D1, D2: MD5Digest): boolean;
67
-
68
-// -----------------------------------------------------------------------------------------------
69
-IMPLEMENTATION
70
-// -----------------------------------------------------------------------------------------------
71
-
72
-var
73
-	PADDING: MD5Buffer = (
74
-		$80, $00, $00, $00, $00, $00, $00, $00,
75
-		$00, $00, $00, $00, $00, $00, $00, $00,
76
-		$00, $00, $00, $00, $00, $00, $00, $00,
77
-		$00, $00, $00, $00, $00, $00, $00, $00,
78
-		$00, $00, $00, $00, $00, $00, $00, $00,
79
-		$00, $00, $00, $00, $00, $00, $00, $00,
80
-		$00, $00, $00, $00, $00, $00, $00, $00,
81
-		$00, $00, $00, $00, $00, $00, $00, $00
82
-	);
83
-
84
-function F(x, y, z: DWORD): DWORD;
85
-begin
86
-	Result := (x and y) or ((not x) and z);
87
-end;
88
-
89
-function G(x, y, z: DWORD): DWORD;
90
-begin
91
-	Result := (x and z) or (y and (not z));
92
-end;
93
-
94
-
95
-function H(x, y, z: DWORD): DWORD;
96
-begin
97
-	Result := x xor y xor z;
98
-end;
99
-
100
-function I(x, y, z: DWORD): DWORD;
101
-begin
102
-	Result := y xor (x or (not z));
103
-end;
104
-
105
-procedure rot(var x: DWORD; n: BYTE);
106
-begin
107
-	x := (x shl n) or (x shr (32 - n));
108
-end;
109
-
110
-procedure FF(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
111
-begin
112
-	inc(a, F(b, c, d) + x + ac);
113
-	rot(a, s);
114
-	inc(a, b);
115
-end;
116
-
117
-procedure GG(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
118
-begin
119
-	inc(a, G(b, c, d) + x + ac);
120
-	rot(a, s);
121
-	inc(a, b);
122
-end;
123
-
124
-procedure HH(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
125
-begin
126
-	inc(a, H(b, c, d) + x + ac);
127
-	rot(a, s);
128
-	inc(a, b);
129
-end;
130
-
131
-procedure II(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
132
-begin
133
-	inc(a, I(b, c, d) + x + ac);
134
-	rot(a, s);
135
-	inc(a, b);
136
-end;
137
-
138
-// -----------------------------------------------------------------------------------------------
139
-
140
-// Encode Count bytes at Source into (Count / 4) DWORDs at Target
141
-procedure Encode(Source, Target: pointer; Count: longword);
142
-var
143
-	S: PByte;
144
-	T: PDWORD;
145
-	I: longword;
146
-begin
147
-	S := Source;
148
-	T := Target;
149
-	for I := 1 to Count div 4 do begin
150
-		T^ := S^;
151
-		inc(S);
152
-		T^ := T^ or (S^ shl 8);
153
-		inc(S);
154
-		T^ := T^ or (S^ shl 16);
155
-		inc(S);
156
-		T^ := T^ or (S^ shl 24);
157
-		inc(S);
158
-		inc(T);
159
-	end;
160
-end;
161
-
162
-// Decode Count DWORDs at Source into (Count * 4) Bytes at Target
163
-procedure Decode(Source, Target: pointer; Count: longword);
164
-var
165
-	S: PDWORD;
166
-	T: PByte;
167
-	I: longword;
168
-begin
169
-	S := Source;
170
-	T := Target;
171
-	for I := 1 to Count do begin
172
-		T^ := S^ and $ff;
173
-		inc(T);
174
-		T^ := (S^ shr 8) and $ff;
175
-		inc(T);
176
-		T^ := (S^ shr 16) and $ff;
177
-		inc(T);
178
-		T^ := (S^ shr 24) and $ff;
179
-		inc(T);
180
-		inc(S);
181
-	end;
182
-end;
183
-
184
-// Transform State according to first 64 bytes at Buffer
185
-procedure Transform(Buffer: pointer; var State: MD5State);
186
-var
187
-	a, b, c, d: DWORD;
188
-	Block: MD5Block;
189
-begin
190
-	Encode(Buffer, @Block, 64);
191
-	a := State[0];
192
-	b := State[1];
193
-	c := State[2];
194
-	d := State[3];
195
-	FF (a, b, c, d, Block[ 0],  7, $d76aa478);
196
-	FF (d, a, b, c, Block[ 1], 12, $e8c7b756);
197
-	FF (c, d, a, b, Block[ 2], 17, $242070db);
198
-	FF (b, c, d, a, Block[ 3], 22, $c1bdceee);
199
-	FF (a, b, c, d, Block[ 4],  7, $f57c0faf);
200
-	FF (d, a, b, c, Block[ 5], 12, $4787c62a);
201
-	FF (c, d, a, b, Block[ 6], 17, $a8304613);
202
-	FF (b, c, d, a, Block[ 7], 22, $fd469501);
203
-	FF (a, b, c, d, Block[ 8],  7, $698098d8);
204
-	FF (d, a, b, c, Block[ 9], 12, $8b44f7af);
205
-	FF (c, d, a, b, Block[10], 17, $ffff5bb1);
206
-	FF (b, c, d, a, Block[11], 22, $895cd7be);
207
-	FF (a, b, c, d, Block[12],  7, $6b901122);
208
-	FF (d, a, b, c, Block[13], 12, $fd987193);
209
-	FF (c, d, a, b, Block[14], 17, $a679438e);
210
-	FF (b, c, d, a, Block[15], 22, $49b40821);
211
-	GG (a, b, c, d, Block[ 1],  5, $f61e2562);
212
-	GG (d, a, b, c, Block[ 6],  9, $c040b340);
213
-	GG (c, d, a, b, Block[11], 14, $265e5a51);
214
-	GG (b, c, d, a, Block[ 0], 20, $e9b6c7aa);
215
-	GG (a, b, c, d, Block[ 5],  5, $d62f105d);
216
-	GG (d, a, b, c, Block[10],  9,  $2441453);
217
-	GG (c, d, a, b, Block[15], 14, $d8a1e681);
218
-	GG (b, c, d, a, Block[ 4], 20, $e7d3fbc8);
219
-	GG (a, b, c, d, Block[ 9],  5, $21e1cde6);
220
-	GG (d, a, b, c, Block[14],  9, $c33707d6);
221
-	GG (c, d, a, b, Block[ 3], 14, $f4d50d87);
222
-	GG (b, c, d, a, Block[ 8], 20, $455a14ed);
223
-	GG (a, b, c, d, Block[13],  5, $a9e3e905);
224
-	GG (d, a, b, c, Block[ 2],  9, $fcefa3f8);
225
-	GG (c, d, a, b, Block[ 7], 14, $676f02d9);
226
-	GG (b, c, d, a, Block[12], 20, $8d2a4c8a);
227
-	HH (a, b, c, d, Block[ 5],  4, $fffa3942);
228
-	HH (d, a, b, c, Block[ 8], 11, $8771f681);
229
-	HH (c, d, a, b, Block[11], 16, $6d9d6122);
230
-	HH (b, c, d, a, Block[14], 23, $fde5380c);
231
-	HH (a, b, c, d, Block[ 1],  4, $a4beea44);
232
-	HH (d, a, b, c, Block[ 4], 11, $4bdecfa9);
233
-	HH (c, d, a, b, Block[ 7], 16, $f6bb4b60);
234
-	HH (b, c, d, a, Block[10], 23, $bebfbc70);
235
-	HH (a, b, c, d, Block[13],  4, $289b7ec6);
236
-	HH (d, a, b, c, Block[ 0], 11, $eaa127fa);
237
-	HH (c, d, a, b, Block[ 3], 16, $d4ef3085);
238
-	HH (b, c, d, a, Block[ 6], 23,  $4881d05);
239
-	HH (a, b, c, d, Block[ 9],  4, $d9d4d039);
240
-	HH (d, a, b, c, Block[12], 11, $e6db99e5);
241
-	HH (c, d, a, b, Block[15], 16, $1fa27cf8);
242
-	HH (b, c, d, a, Block[ 2], 23, $c4ac5665);
243
-	II (a, b, c, d, Block[ 0],  6, $f4292244);
244
-	II (d, a, b, c, Block[ 7], 10, $432aff97);
245
-	II (c, d, a, b, Block[14], 15, $ab9423a7);
246
-	II (b, c, d, a, Block[ 5], 21, $fc93a039);
247
-	II (a, b, c, d, Block[12],  6, $655b59c3);
248
-	II (d, a, b, c, Block[ 3], 10, $8f0ccc92);
249
-	II (c, d, a, b, Block[10], 15, $ffeff47d);
250
-	II (b, c, d, a, Block[ 1], 21, $85845dd1);
251
-	II (a, b, c, d, Block[ 8],  6, $6fa87e4f);
252
-	II (d, a, b, c, Block[15], 10, $fe2ce6e0);
253
-	II (c, d, a, b, Block[ 6], 15, $a3014314);
254
-	II (b, c, d, a, Block[13], 21, $4e0811a1);
255
-	II (a, b, c, d, Block[ 4],  6, $f7537e82);
256
-	II (d, a, b, c, Block[11], 10, $bd3af235);
257
-	II (c, d, a, b, Block[ 2], 15, $2ad7d2bb);
258
-	II (b, c, d, a, Block[ 9], 21, $eb86d391);
259
-	inc(State[0], a);
260
-	inc(State[1], b);
261
-	inc(State[2], c);
262
-	inc(State[3], d);
263
-end;
264
-
265
-// -----------------------------------------------------------------------------------------------
266
-
267
-// Initialize given Context
268
-procedure MD5Init(var Context: MD5Context);
269
-begin
270
-	with Context do begin
271
-		State[0] := $67452301;
272
-		State[1] := $efcdab89;
273
-		State[2] := $98badcfe;
274
-		State[3] := $10325476;
275
-		Count[0] := 0;
276
-		Count[1] := 0;
277
-		ZeroMemory(@Buffer, SizeOf(MD5Buffer));
278
-	end;
279
-end;
280
-
281
-// Update given Context to include Length bytes of Input
282
-procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);
283
-var
284
-	Index: longword;
285
-	PartLen: longword;
286
-	I: longword;
287
-begin
288
-	with Context do begin
289
-		Index := (Count[0] shr 3) and $3f;
290
-		inc(Count[0], Length shl 3);
291
-		if Count[0] < (Length shl 3) then inc(Count[1]);
292
-		inc(Count[1], Length shr 29);
293
-	end;
294
-	PartLen := 64 - Index;
295
-	if Length >= PartLen then begin
296
-		CopyMemory(@Context.Buffer[Index], Input, PartLen);
297
-		Transform(@Context.Buffer, Context.State);
298
-		I := PartLen;
299
-		while I + 63 < Length do begin
300
-			Transform(@Input[I], Context.State);
301
-			inc(I, 64);
302
-		end;
303
-		Index := 0;
304
-	end else I := 0;
305
-	CopyMemory(@Context.Buffer[Index], @Input[I], Length - I);
306
-end;
307
-
308
-// Finalize given Context, create Digest and zeroize Context
309
-procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
310
-var
311
-	Bits: MD5CBits;
312
-	Index: longword;
313
-	PadLen: longword;
314
-begin
315
-	Decode(@Context.Count, @Bits, 2);
316
-	Index := (Context.Count[0] shr 3) and $3f;
317
-	if Index < 56 then PadLen := 56 - Index else PadLen := 120 - Index;
318
-	MD5Update(Context, @PADDING, PadLen);
319
-	MD5Update(Context, @Bits, 8);
320
-	Decode(@Context.State, @Digest, 4);
321
-	ZeroMemory(@Context, SizeOf(MD5Context));
322
-end;
323
-
324
-// -----------------------------------------------------------------------------------------------
325
-
326
-// Create digest of given Message
327
-function MD5String(M: string): MD5Digest;
328
-var
329
-	Context: MD5Context;
330
-begin
331
-	MD5Init(Context);
332
-	MD5Update(Context, pChar(M), length(M));
333
-	MD5Final(Context, Result);
334
-end;
335
-
336
-// Create digest of file with given Name
337
-function MD5File(N: string): MD5Digest;
338
-var
339
-	FileHandle: THandle;
340
-	MapHandle: THandle;
341
-	ViewPointer: pointer;
342
-	Context: MD5Context;
343
-begin
344
-	MD5Init(Context);
345
-	FileHandle := CreateFile(pChar(N), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
346
-		nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);
347
-	if FileHandle <> INVALID_HANDLE_VALUE then try
348
-		MapHandle := CreateFileMapping(FileHandle, nil, PAGE_READONLY, 0, 0, nil);
349
-		if MapHandle <> 0 then try
350
-			ViewPointer := MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0);
351
-			if ViewPointer <> nil then try
352
-				MD5Update(Context, ViewPointer, GetFileSize(FileHandle, nil));
353
-			finally
354
-				UnmapViewOfFile(ViewPointer);
355
-			end;
356
-		finally
357
-			CloseHandle(MapHandle);
358
-		end;
359
-	finally
360
-		CloseHandle(FileHandle);
361
-	end;
362
-	MD5Final(Context, Result);
363
-end;
364
-
365
-// Create hex representation of given Digest
366
-function MD5Print(D: MD5Digest): string;
367
-var
368
-	I: byte;
369
-const
370
-	Digits: array[0..15] of char =
371
-		('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
372
-begin
373
-	Result := '';
374
-	for I := 0 to 15 do Result := Result + Digits[(D[I] shr 4) and $0f] + Digits[D[I] and $0f];
375
-end;
376
-
377
-// -----------------------------------------------------------------------------------------------
378
-
379
-// Compare two Digests
380
-function MD5Match(D1, D2: MD5Digest): boolean;
381
-var
382
-	I: byte;
383
-begin
384
-	I := 0;
385
-	Result := TRUE;
386
-	while Result and (I < 16) do begin
387
-		Result := D1[I] = D2[I];
388
-		inc(I);
389
-	end;
390
-end;
391
-
392
-end.
393
-

+ 0
- 469
installer/windows/Setup.dpr Parādīt failu

@@ -1,469 +0,0 @@
1
-{*
2
- * This application launches the dmdirc java-based installer.
3
- *
4
- * DMDirc - Open Source IRC Client
5
- * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes,
6
- * Michael Nixon
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in
16
- * all copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *}
26
-
27
-(* Current DMDirc windows setup flow:
28
- *
29
- * 1) Outer wrapper EXE that extracts a 7zip SFX to windows temp dir
30
- * 2) 7zip SFX unpacks
31
- * 3) Wrapper EXE starts Setup.exe (this program)
32
- * 4) Setup checks for existence of the JRE and offers to download/install it
33
- * 5) Setup starts the java portion of the DMDirc installer
34
- *)
35
-program Setup;
36
-
37
-// Resource file - icon, versioninfo, manifest
38
-{$R most.res}
39
-
40
-{ ---------------------------------------------------------------------------- }
41
-{$IFDEF FPC}
42
-  {$MODE Delphi}
43
-{$ENDIF}
44
-
45
-// Use this instead of {$APPTYPE XXX}
46
-// APP_XXX is the same as {$APPTYPE XXX}
47
-// Defaults to console
48
-// This is a work-around for a bug in FPC Cross Compiling to windows in delphi
49
-// mode (IsConsole is always true)
50
-{$DEFINE APP_GUI}
51
-
52
-// This block actually does the work for the above work-around
53
-{$IFDEF APP_GUI}
54
-  {$APPTYPE GUI}
55
-{$ELSE}
56
-  {$IFDEF APP_FS}
57
-    {$APPTYPE FS}
58
-  {$ELSE}
59
-    {$IFDEF APP_TOOL}
60
-      {$DEFINE APP_CONSOLE}
61
-      {$APPTYPE TOOL}
62
-    {$ELSE}
63
-      {$DEFINE APP_CONSOLE}
64
-      {$APPTYPE CONSOLE}
65
-    {$ENDIF}
66
-  {$ENDIF}
67
-{$ENDIF}
68
-
69
-{ ----------------------------------------------------------------------------
70
-  Debugging specific compiler directives
71
-  ---------------------------------------------------------------------------- }
72
-
73
-// If defined the JRE will always be downloaded as if it didn't exist. Used for
74
-// testing the JRE download dialog.
75
-// {$DEFINE FORCEJREDOWNLOAD}
76
-
77
-uses
78
-  kol, shared, Vista, Windows, SysUtils, classes, registry;
79
-
80
-const
81
-  // SetupConsts holds build information for this release
82
-  {$I SetupConsts.inc}
83
-  // This is also part of the above IsConsole workaround.
84
-  {$IFDEF APP_CONSOLE}
85
-    IsConsole: boolean = true;
86
-  {$ELSE}
87
-    IsConsole: boolean = false;
88
-  {$ENDIF}
89
-
90
-var
91
-  { --------------------------------------------------------------------------
92
-    KOL form objects
93
-    -------------------------------------------------------------------------- }
94
-  frmmain: pcontrol;
95
-  progressbar, btncancel: pcontrol;
96
-  label1, label2, label3, label4, labelurl, labelspeed, labelprogress: pcontrol;
97
-
98
-  { --------------------------------------------------------------------------
99
-    Other globals
100
-    -------------------------------------------------------------------------- }
101
-  terminateDownload: boolean = false;
102
-
103
-procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
104
-
105
-{ ----------------------------------------------------------------------------
106
-  Main form: Cancel button clicked event
107
-  ---------------------------------------------------------------------------- }
108
-procedure btnCancel_Click(Dummy: Pointer; Sender: PControl);
109
-begin
110
-  terminateDownload := true;
111
-end;
112
-
113
-{ ----------------------------------------------------------------------------
114
-  Main form: Set progress percentage to <value> and display in label <msg>
115
-  ---------------------------------------------------------------------------- }
116
-procedure setProgress(value: integer; msg: string);
117
-begin
118
-  ProgressBar.progress := value;
119
-  labelprogress.Caption := msg;
120
-  applet.processmessages;
121
-end;
122
-
123
-{ ----------------------------------------------------------------------------
124
-  Initialise KOL and create the main window
125
-  ---------------------------------------------------------------------------- }
126
-procedure CreateMainWindow;
127
-var
128
-  screenw, screenh: longint;
129
-  iconhandle: thandle;
130
-begin
131
-  { This call is required for common control 6 DLL to be correctly imported.
132
-    Without it strange things happen on windows XP }
133
-  InitCommonControls;
134
-
135
-  { Load the icon to assign to our window }
136
-  iconhandle := LoadIcon(hInstance, 'icon.ico');
137
-
138
-  { We need the screen size to centre the window later }
139
-  screenw := GetSystemMetrics(SM_CXSCREEN);
140
-  screenh := GetSystemMetrics(SM_CYSCREEN);
141
-
142
-  { KOL programs ideally need an Applet created }
143
-  Applet := NewApplet('DMDirc Setup');
144
-  Applet.Visible := true;
145
-
146
-  Applet.Icon := iconhandle;
147
-
148
-  { Create main form and set sane defaults. If we don't set the font here then
149
-    all child objects will have a rubbish font as a holdover from Windows 3.1! }
150
-  frmmain := NewForm(Applet, 'DMDirc Setup').SetClientSize(400, 184);
151
-  frmmain.CreateVisible := True;
152
-  frmmain.CanResize := False;
153
-  frmmain.Style := frmmain.style and (not WS_MAXIMIZEBOX);
154
-  frmmain.Font.FontName := 'Ms Sans Serif';
155
-  frmmain.Font.FontHeight := 8;
156
-  frmmain.SetPosition((screenw div 2) - (frmmain.Width div 2), (screenh div 2) - (frmmain.height div 2));
157
-
158
-  frmmain.Icon := iconhandle;
159
-
160
-  progressbar := NewProgressBar(frmmain).SetPosition(16, 114);
161
-  progressbar.SetSize(frmmain.clientWidth - (progressbar.Left * 2), 16);
162
-  progressbar.MaxProgress := 100;
163
-  progressbar.Progress := 0;
164
-  progressbar.Visible := true;
165
-
166
-  btncancel := NewButton(frmmain, 'Cancel').SetPosition(progressbar.Left +
167
-  progressbar.width - 60, progressbar.Top + progressbar.Height + 14);
168
-  btncancel.SetSize(60, 24);
169
-
170
-  label1 := NewLabel(frmmain, 'Downloading Java Runtime Environment').SetPosition(16, 16);
171
-  label1.SetSize(frmmain.ClientWidth - 32, 16);
172
-  label1.Font.FontStyle := [fsBold];
173
-
174
-  label2 := NewLabel(frmmain, 'Address:').SetPosition(16, label1.top + 28);
175
-  label2.SetSize(frmmain.ClientWidth - 32, 16);
176
-
177
-  label3 := NewLabel(frmmain, 'Speed:').SetPosition(16, label2.top + 20);
178
-  label3.SetSize(frmmain.ClientWidth - 32, 16);
179
-
180
-  label4 := NewLabel(frmmain, 'Progress:').SetPosition(16, label3.top + 20);
181
-  label4.SetSize(frmmain.ClientWidth - 32, 16);
182
-
183
-  { BringToFront calls are needed on the following labels because the labels
184
-    created earlier are as wide as the form and cover them as they are not
185
-    transparent. It seems windows creates controls in a backwards order so newer
186
-    controls are behind older ones. I could rearrange this order in the code but
187
-    it would look messy. }
188
-
189
-  labelurl := NewLabel(frmmain, '').SetPosition(70, label1.top + 28);
190
-  labelurl.SetSize(frmmain.ClientWidth - 32, 16);
191
-  labelurl.BringToFront;
192
-
193
-  labelspeed := NewLabel(frmmain, '').SetPosition(70, label2.top + 20);
194
-  labelspeed.SetSize(frmmain.ClientWidth - 32, 16);
195
-  labelspeed.BringToFront;
196
-
197
-  labelprogress := NewLabel(frmmain, '').SetPosition(70, label3.top + 20);
198
-  labelprogress.SetSize(frmmain.ClientWidth - 32, 16);
199
-  labelprogress.BringToFront;
200
-
201
-  { Assign UI methods }
202
-  btncancel.OnClick := TOnEvent(MakeMethod(nil, @btnCancel_Click ));
203
-
204
-  { The window will not appear until the messageloop is started with Run() but
205
-    this means we must yield this thread to the UI. This is unacceptable for
206
-    such a simple program. Calling CreateWindow here will cause the window to
207
-    appear but the message loop does not run; consequently the app must service
208
-    messages by hand at a timely interval to avoid windows from marking the
209
-    program as unresponsive. This is a hack but acceptable here. }
210
-
211
-  { /!\ WARNING /!\ Run() can no longer be used to enter the message loop after
212
-    this call or a nasty crash will occur. }
213
-  applet.createwindow;
214
-end;
215
-
216
-{ ----------------------------------------------------------------------------
217
-  Return the size in bytes of the file specified by <name>
218
-  Returns -1 on error
219
-  ---------------------------------------------------------------------------- }
220
-function GetFileSizeByName(name: String): Integer;
221
-var
222
-  hand: THandle;
223
-begin
224
-  hand := 0;
225
-  Result := 0;
226
-  if FileExists(name) then begin
227
-    try
228
-      hand := CreateFile(PChar(name), GENERIC_READ, FILE_SHARE_WRITE or FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
229
-      Result := GetFileSize(hand, nil);
230
-    finally
231
-      try
232
-        if (hand <> 0) then CloseHandle(hand);
233
-      except
234
-        Result := -1;
235
-      end;
236
-    end;
237
-  end;
238
-end;
239
-
240
-{$IFNDEF VER150}
241
-{ ----------------------------------------------------------------------------
242
-  Return part of a string
243
-  ---------------------------------------------------------------------------- }
244
-function AnsiMidStr(Source: String; Start: Integer; Count: Integer): String;
245
-begin
246
-  // Not perfectly accurate, but does the job
247
-  { ^ What does that mean? // Zipplet }
248
-  Result := Copy(Source, Start, Count);
249
-end;
250
-{$ENDIF}
251
-
252
-{ ----------------------------------------------------------------------------
253
-  Downloads the JRE. Returns TRUE if the user installed it. False otherwise
254
-  ---------------------------------------------------------------------------- }
255
-function downloadJRE(message: String = 'Would you like to download the java JRE?'): boolean;
256
-var
257
-  ProcessInfo: TProcessInformation;
258
-  processResult: Longword;
259
-  url: String;
260
-  dir: String;
261
-  line: String;
262
-  f: TextFile;
263
-  bits: TStringList;
264
-  match: boolean;
265
-  wantedsize: double;
266
-  currentsize: double;
267
-   lastsize: double;
268
-   i: double;
269
-   c: longint;
270
-begin
271
-  dir := IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)));
272
-  // TODO: We should probably download the 64bit version of java if we are
273
-  // 64bit.
274
-  url := 'http://www.dmdirc.com/getjava/windows/all';
275
-  Result := false;
276
-
277
-  { First we will determine the approximate size of the download.
278
-    In my opinion we should not do this until we have asked the user if they
279
-    would like to download the JRE. Might change this later.
280
-    We obtain the size by asking wget to find out. }
281
-  ExecAndWait('wget.exe -o "'+dir+'wgetoutput" --spider '+url, true);
282
-
283
-  { Just incase wget fails ... }
284
-  if not fileexists(dir+'wgetoutput') then begin
285
-    showerror('Internal error: wget returned no output.', 'DMDirc Setup');
286
-    result := false;
287
-    exit;
288
-  end;
289
-
290
-  { Parse the output and grab the approximate size }
291
-  AssignFile(f, dir+'wgetoutput');
292
-  Reset(f);
293
-  line := '';
294
-  match := false;
295
-  while not Eof(f) do begin
296
-    ReadLn(f, line);
297
-    if length(line) > 8 then begin
298
-      if copy(line, 1, 7) = 'Length:' then begin
299
-        match := true;
300
-        break;
301
-      end;
302
-    end;
303
-  end;
304
-  if match then begin
305
-    bits := TStringList.create;
306
-    try
307
-      bits.Clear;
308
-      bits.Delimiter := ' ';
309
-      bits.DelimitedText := line;
310
-      try
311
-        wantedsize := strtoint(StringReplace(bits[1], ',', '', [rfReplaceAll]))
312
-      except
313
-        wantedsize := 0;
314
-      end;
315
-
316
-      { We ask the user if they wish to download the JRE }
317
-      if askQuestion(message+' (Download Size: '+AnsiMidStr(bits[2], 2, length(bits[2])-2)+')', 'DMDirc Setup') then begin
318
-        { Create progress window and show it }
319
-        CreateMainWindow;
320
-        { Get wget to start the download }
321
-        ProcessInfo := Launch('wget.exe '+url+' -O jre.exe', true);
322
-        labelurl.caption := url;
323
-        labelspeed.caption := 'Connecting to site...';
324
-
325
-        { Why is this case needed ?! }
326
-        if wantedsize <= 0 then begin
327
-          progressbar.progress := 50;
328
-        end;
329
-        getExitCodeProcess(ProcessInfo.hProcess, processResult);
330
-
331
-        lastsize := 0;
332
-        c := 0;
333
-        i := 0;
334
-        while (processResult = STILL_ACTIVE) and (not terminateDownload) do begin
335
-          if wantedsize > 0 then begin
336
-            currentsize := GetFileSizeByName(dir + 'jre.exe');
337
-            inc(c);
338
-            if (c >= 5) then begin
339
-              i := (i + currentsize - lastsize) / 2;
340
-              labelspeed.caption := nicesize(round(i * 2)) + '/sec';
341
-              lastsize := currentsize;
342
-              c := 0;
343
-            end;
344
-            if (currentsize > 0) then setProgress(Round((currentsize/wantedsize)*100),
345
-              nicesize(currentsize) + ' of ' + nicesize(wantedsize) +
346
-              ' (' + inttostr(Round((currentsize/wantedsize)*100)) + '%)');
347
-          end;
348
-          { We must process the message loop or the window wont respond to the user }
349
-          applet.ProcessMessages;
350
-          { Sleep to prevent 100% CPU usage }
351
-          sleep(100);
352
-          GetExitCodeProcess(ProcessInfo.hProcess, processResult);
353
-        end;
354
-        frmmain.visible := false;
355
-        applet.visible := false;
356
-        if (terminateDownload) then begin
357
-          Result := false;
358
-          TerminateProcess(ProcessInfo.hProcess, 0);
359
-          showError('JRE Download was aborted', 'DMDirc Setup', false);
360
-        end
361
-        else Result := processResult = 0;
362
-        if not Result then begin
363
-          if not terminateDownload then begin
364
-            showError('JRE Download Failed', 'DMDirc Setup', false);
365
-          end
366
-          else begin
367
-            // If the download was cancelled by the form, this error will already
368
-            // have been given.
369
-            { No action needed here anymore }
370
-          end;
371
-        end;
372
-      end;
373
-    finally
374
-      bits.free;
375
-    end;
376
-  end;
377
-end;
378
-
379
-{ ----------------------------------------------------------------------------
380
-  Begin the JRE download/install.
381
-  ---------------------------------------------------------------------------- }
382
-function installJRE(isUpgrade: boolean): boolean;
383
-var
384
-  question: String;
385
-  needDownload: boolean;
386
-  canContinue: boolean;
387
-begin
388
-  Result := false;
389
-  needDownload := not FileExists(IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)))+'jre.exe');
390
-  if needDownload then begin
391
-    if not isUpgrade then question := 'Java was not detected on your machine. Would you like to download and install it now?'
392
-    else question := 'The version of java detected on your machine is not compatible with DMDirc. Would you like to download and install a compatible version now?';
393
-  end
394
-  else begin
395
-    if not isUpgrade then question := 'Java was not detected on your machine. Would you like to install it now?'
396
-    else question := 'The version of java detected on your machine is not compatible with DMDirc. Would you like to install a compatible version now?';
397
-  end;
398
-
399
-  canContinue := true;
400
-  if (needDownload) then begin
401
-    canContinue := downloadJRE(question);
402
-  end;
403
-
404
-  if canContinue then begin
405
-    // Final result of this function is the return value of installing java.
406
-    if needDownload or askQuestion(question, 'DMDirc Setup') then begin
407
-      showmessage('The Java installer will now run. Please follow the instructions given. '+#13#10+'The DMDirc installation will continue afterwards.', 'DMDirc Setup');
408
-      Result := (ExecAndWait('jre.exe') = 0);
409
-    end;
410
-  end
411
-end;
412
-
413
-{ ----------------------------------------------------------------------------
414
-  MAIN PROGRAM
415
-  ---------------------------------------------------------------------------- }
416
-var
417
-  errorMessage: String;
418
-  params: String = '';
419
-  dir: String = '';
420
-  Reg: TRegistry;
421
-  result: Integer;
422
-begin
423
-
424
-  errorMessage := '';
425
-  if FileExists('DMDirc.jar') then begin
426
-    {$IFDEF FORCEJREDOWNLOAD}if (1 <> 0) then begin{$ELSE}if (RunJava('-version') <> 0) then begin{$ENDIF}
427
-      if not installJRE(false) then begin
428
-        showError('DMDirc setup can not continue without Java. Please install Java and try again.', 'DMDirc Setup', false, false);
429
-        exit;
430
-      end;
431
-    end;
432
-
433
-    Reg := TRegistry.Create;
434
-    Reg.RootKey := HKEY_LOCAL_MACHINE;
435
-    if Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc', false) then begin
436
-      dir := Reg.ReadString('InstallDir');
437
-      if (dir <> '') then begin
438
-        params := params+' --directory "'+dir+'"';
439
-      end;
440
-    end;
441
-    Reg.CloseKey;
442
-    Reg.Free;
443
-    if (ReleaseNumber <> '') then begin
444
-      params := params+' --release '+ReleaseNumber;
445
-    end;
446
-    // Check if the installer runs
447
-    if (RunJava('-cp DMDirc.jar com.dmdirc.installer.Main --help') <> 0) then begin
448
-      if not installJRE(true) then begin
449
-        showError('Sorry, DMDirc setup can not continue without an updated version of java.', 'DMDirc Setup', false, false);
450
-        exit;
451
-      end
452
-      else begin
453
-        // Try again now that java is installed.
454
-        result := RunJava('-cp DMDirc.jar com.dmdirc.installer.Main '+params);
455
-      end;
456
-    end
457
-    else begin
458
-      // Java is the right version, run the installer
459
-      result := RunJava('-cp DMDirc.jar com.dmdirc.installer.Main '+params);
460
-    end;
461
-  end
462
-  else begin
463
-    errorMessage := errorMessage+'DMDirc.jar was not found.';
464
-    errorMessage := errorMessage+#13#10;
465
-    errorMessage := errorMessage+#13#10+'This is likely because of a corrupt installer build.';
466
-    errorMessage := errorMessage+#13#10+'Please check http://www.dmdirc.com/ for an updated build.';
467
-    showError(errorMessage, 'DMDirc Setup');
468
-  end;
469
-end.

Binārs
installer/windows/Shortcut.exe Parādīt failu


+ 0
- 17
installer/windows/UAC.manifest Parādīt failu

@@ -1,17 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
3
-  <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="DMDirc Installer" type="win32"/>
4
-  <description>DMDirc Installer</description>
5
-  <dependency>
6
-    <dependentAssembly>
7
-      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/>
8
-    </dependentAssembly>
9
-  </dependency>
10
-  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
11
-    <security>
12
-      <requestedPrivileges>
13
-        <requestedExecutionLevel level="requireAdministrator"/>
14
-      </requestedPrivileges>
15
-    </security>
16
-  </trustInfo>
17
-</assembly>

+ 0
- 17
installer/windows/UAC_uninstaller.manifest Parādīt failu

@@ -1,17 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
3
-  <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="DMDirc Uninstaller" type="win32"/>
4
-  <description>DMDirc Uninstaller</description>
5
-  <dependency>
6
-    <dependentAssembly>
7
-      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/>
8
-    </dependentAssembly>
9
-  </dependency>
10
-  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
11
-    <security>
12
-      <requestedPrivileges>
13
-        <requestedExecutionLevel level="requireAdministrator"/>
14
-      </requestedPrivileges>
15
-    </security>
16
-  </trustInfo>
17
-</assembly>

+ 0
- 199
installer/windows/Uninstaller.dpr Parādīt failu

@@ -1,199 +0,0 @@
1
-{*
2
- * DMDirc Uninstaller
3
- *
4
- * This application launches DMDirc on windows and passes control to the
5
- * update engine as necessary.
6
- *
7
- * DMDirc - Open Source IRC Client
8
- * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes,
9
- * Michael Nixon
10
- *
11
- * Permission is hereby granted, free of charge, to any person obtaining a copy
12
- * of this software and associated documentation files (the "Software"), to deal
13
- * in the Software without restriction, including without limitation the rights
14
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
- * copies of the Software, and to permit persons to whom the Software is
16
- * furnished to do so, subject to the following conditions:
17
- *
18
- * The above copyright notice and this permission notice shall be included in
19
- * all copies or substantial portions of the Software.
20
- *
21
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
- * SOFTWARE.
28
- *}
29
-program Uninstaller;
30
-{$IFDEF FPC}
31
-	{$MODE Delphi}
32
-{$ENDIF}
33
-// Use this instead of {$APPTYPE XXX}
34
-// APP_XXX is the same as {$APPTYPE XXX}
35
-// Defaults to console
36
-// This is a work-around for a bug in FPC Cross Compiling to windows in delphi
37
-// mode (IsConsole is always true)
38
-{$DEFINE APP_GUI}
39
-
40
-// This block actually does the work for the above work-around
41
-{$IFDEF APP_GUI}
42
-	{$APPTYPE GUI}
43
-{$ELSE}
44
-	{$IFDEF APP_FS}
45
-		{$APPTYPE FS}
46
-	{$ELSE}
47
-		{$IFDEF APP_TOOL}
48
-			{$DEFINE APP_CONSOLE}
49
-			{$APPTYPE TOOL}
50
-		{$ELSE}
51
-			{$DEFINE APP_CONSOLE}
52
-			{$APPTYPE CONSOLE}
53
-		{$ENDIF}
54
-	{$ENDIF}
55
-{$ENDIF}
56
-
57
-uses shared, Windows, SysUtils, registry, Vista;
58
-procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
59
-
60
-{$R uninstall.res}
61
-{ ---------------------------------------------------------------------------- }
62
-
63
-{ ----------------------------------------------------------------------------
64
-  Create a temp directory and return the path to it
65
-  ---------------------------------------------------------------------------- }
66
-function GetTempDirectory(): String;
67
-var
68
-	buf: array[0..MAX_PATH] of Char;
69
-	wintemp, temp: String;
70
-begin
71
-	GetTempPath(SizeOf(buf)-1, buf);
72
-	wintemp := StrPas(buf);
73
-	Randomize;
74
-	temp := '\DMDirc-uninstaller-'+inttostr(1000 + Random(1000));
75
-	while (DirectoryExists(wintemp+temp+'\')) do begin
76
-		temp := temp+'-'+inttostr(1+Random(1000));
77
-	end;
78
-	MkDir(wintemp+temp+'\');
79
-	result := wintemp+temp+'\';
80
-end;
81
-
82
-{ ----------------------------------------------------------------------------
83
-  Delete a directory and all files it contains
84
-  ---------------------------------------------------------------------------- }
85
-function KillDir(Dir: string): Integer;
86
-var
87
-	searchResult: TSearchRec;
88
-begin
89
-	Result := 0;
90
-	if FindFirst(Dir+'\*', faDirectory + faHidden  + faReadOnly + faSysfile + faAnyFile, searchResult) = 0 then
91
-	begin
92
-		repeat
93
-			if (searchResult.attr and faDirectory) <> faDirectory then begin
94
-				Try
95
-					DeleteFile(Dir+'\'+searchResult.name);
96
-				Except
97
-					MessageBox(0, PChar('Unable to delete "'+Dir+'\'+searchResult.name+'" - is DMDirc still running?.'), 'DMDirc Uninstaller', MB_OK);
98
-				end;
99
-			end
100
-			else begin
101
-				if (searchResult.name <> '.') and (searchResult.name <> '..') then begin
102
-					KillDir(Dir+'\'+searchResult.name);
103
-				end;
104
-			end;
105
-		until FindNext(searchResult) <> 0;
106
-		FindClose(searchResult);
107
-	end;
108
-	Try
109
-		RmDir(Dir);
110
-	Except
111
-	end;
112
-end;
113
-
114
-{ ----------------------------------------------------------------------------
115
-  MAIN PROGRAM
116
-  ---------------------------------------------------------------------------- }
117
-var
118
-	TempDir: String;
119
-	InstallDir: String = '';
120
-	i: Integer;
121
-	Reg: TRegistry;
122
-	handlerInfo: String;
123
-	profileDir: String;
124
-	deleteProtocol: boolean;
125
-begin
126
-        InitCommonControls;
127
-	if (ParamCount > 0) then begin
128
-		for i := 1 to ParamCount do begin
129
-			InstallDir := InstallDir+' '+paramstr(i);
130
-		end;
131
-		InstallDir := trim(InstallDir);
132
-		KillDir(InstallDir);
133
-		profileDir := GetEnvironmentVariable('USERPROFILE');
134
-		
135
-		if IsWindowsVista then begin
136
-			// Vista
137
-			KillDir(GetEnvironmentVariable('APPDATA')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
138
-			DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
139
-			DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
140
-			profileDir := profileDir+'\AppData\Roaming\DMDirc';
141
-		end
142
-		else begin
143
-			// Not Vista
144
-			KillDir(GetEnvironmentVariable('USERPROFILE')+'\Start Menu\Programs\DMDirc');
145
-			DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Application Data\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
146
-			DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
147
-			profileDir := profileDir+'\Application Data\DMDirc';
148
-		end;
149
-		// Remove irc:// handler if it is us.
150
-		deleteProtocol := false;
151
-		Reg := TRegistry.Create;
152
-		Reg.RootKey := HKEY_CLASSES_ROOT;
153
-		if Reg.OpenKey('irc\Shell\open\command', false) then begin
154
-			handlerInfo := Reg.ReadString('');
155
-			if (handlerInfo = '"'+InstallDir+'DMDirc.exe" -c %1') then begin
156
-				deleteProtocol := true;
157
-			end
158
-		end;
159
-		Reg.CloseKey;
160
-		Reg.Free;
161
-		
162
-		if deleteProtocol then begin
163
-			Reg := TRegistry.Create;
164
-			Reg.RootKey := HKEY_CLASSES_ROOT;
165
-			Reg.DeleteKey('irc\Shell\open\command');
166
-			Reg.DeleteKey('irc\Shell\open');
167
-			Reg.DeleteKey('irc\Shell');
168
-			Reg.DeleteKey('irc\DefaultIcon');
169
-			Reg.DeleteKey('irc');
170
-			Reg.CloseKey;
171
-			Reg.Free;
172
-		end;
173
-			
174
-		Reg := TRegistry.Create;
175
-		Reg.RootKey := HKEY_LOCAL_MACHINE;
176
-		Reg.DeleteKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc');
177
-		Reg.CloseKey;
178
-		Reg.Free;
179
-		
180
-		if (FileExists(profileDir+'\dmdirc.config')) then begin
181
-			if MessageBox(0, PChar('A dmdirc profile has been detected ('+profileDir+') '+#13#10+'Do you want to delete it as well?'), 'DMDirc Uninstaller', MB_YESNO) = IDYES then begin
182
-				KillDir(profileDir);
183
-			end;
184
-		end;
185
-		
186
-		showmessage('DMDirc has been uninstalled from "'+InstallDir+'".', 'DMDirc Uninstaller', 'Uninstall Successful');
187
-	end
188
-	else if askQuestion('This will uninstall DMDirc. '+#13#10+#13#10+'Do you want to continue?', 'DMDirc Uninstaller') then begin
189
-		if (ExecAndWait('java -jar "' + ExtractFileDir(paramstr(0)) + '\DMDirc.jar" -k', true) <> 0) then begin
190
-			TempDir := GetTempDirectory;
191
-			CopyFile(pchar(paramstr(0)), pchar(TempDir+'/uninstall.exe'), false);
192
-			Launch('"'+TempDir+'/uninstall.exe" '+ExtractFileDir(paramstr(0))+'\');
193
-		end else begin
194
-			showError('Uninstall Aborted - DMDirc is still running.' +
195
-                #13#10 + 'Please close DMDirc before continuing',
196
-                'DMDirc Uninstaller', False, False);
197
-		end;
198
-	end;
199
-end.

+ 0
- 661
installer/windows/makeInstallerWindows.sh Parādīt failu

@@ -1,661 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# This script generates a .exe file that will install DMDirc
4
-#
5
-# DMDirc - Open Source IRC Client
6
-# Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
7
-#
8
-# Permission is hereby granted, free of charge, to any person obtaining a copy
9
-# of this software and associated documentation files (the "Software"), to deal
10
-# in the Software without restriction, including without limitation the rights
11
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
-# copies of the Software, and to permit persons to whom the Software is
13
-# furnished to do so, subject to the following conditions:
14
-#
15
-# The above copyright notice and this permission notice shall be included in
16
-# all copies or substantial portions of the Software.
17
-#
18
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
-# SOFTWARE.
25
-
26
-# Name of the extractor
27
-RUNNAME=extractor.exe
28
-# Name of the installer (without .exe)
29
-INSTALLNAME=DMDirc-Setup
30
-# Name of the internal file
31
-INTNAME=extractor.7z
32
-# full name of the files to output to
33
-RUNNAME="${PWD}/${RUNNAME}"
34
-INTNAME="${PWD}/${INTNAME}"
35
-# Get 7zip path
36
-ZIP=`which 7z`
37
-
38
-PWDIR="${PWD}"
39
-# Windows binaries need real paths not cygwin-y pathhs.
40
-if [ "${WINDIR}" != "" ]; then
41
-	PWDIR=`echo "${PWDIR}" | sed 's#^/c/#c:/#'`
42
-fi;
43
-
44
-if [ "" = "${ZIP}" ]; then
45
-	echo "7Zip not found, failing."
46
-	exit 1;
47
-fi
48
-
49
-# Compress stuff!
50
-compress() {
51
-	FLAGS="-y"
52
-	if [ "${WINDIR}" = "" ]; then
53
-		FLAGS="${FLAGS}l"
54
-	fi;
55
-	
56
-	"${ZIP}" a ${FLAGS} "${INTNAME}" $@ 2>/dev/null || {
57
-		echo "Compression failed."
58
-		kill -15 $$;
59
-	};
60
-}
61
-
62
-# Get signcode path
63
-SIGNCODE=`which signcode`
64
-
65
-if [ "" = "${SIGNCODE}" ]; then
66
-	echo "Signcode not found. EXE's will not be digitally signed."
67
-fi
68
-
69
-# Sign stuff!
70
-signexe() {
71
-return;
72
-	if [ "" != "${SIGNCODE}" ]; then
73
-		if [ -e "../signing/DMDirc.spc" -a -e "../signing/DMDirc.pvk" ]; then
74
-			echo "Digitally Signing EXE (${@})..."
75
-			${SIGNCODE} -spc "../signing/DMDirc.spc" -v "../signing/DMDirc.pvk" -i "http://www.dmdirc.com/" -n "DMDirc Installer" $@ 2>/dev/null || {
76
-				kill -15 $$;
77
-			};
78
-			rm ${@}.sig
79
-			rm ${@}.bak
80
-		fi
81
-	fi
82
-}
83
-
84
-WGET=`which wget`
85
-FETCH=`which fetch`
86
-CURL=`which curl`
87
-getFile() {
88
-	URL=${1}
89
-	OUTPUT=${2}
90
-
91
-	if [ "${WGET}" != "" ]; then
92
-		"${WGET}" -O "${OUTPUT}" ${URL}
93
-	elif [ "${FETCH}" != "" ]; then
94
-		"${FETCH}" -o "${OUTPUT}" ${URL}
95
-	elif [ "${CURL}" != "" ]; then
96
-		"${CURL}" -o "${OUTPUT}" ${URL}
97
-	fi;
98
-}
99
-
100
-# Check for some CLI params
101
-compileJar="false"
102
-compileSetup="false"
103
-useOldSetup="false"
104
-isRelease=""
105
-useUPX="false"
106
-finalTag=""
107
-signEXE="true"
108
-compilerFlags="-Xs -XX -O2 -Or -Op1"
109
-BRANCH="0"
110
-plugins=""
111
-location="../../"
112
-current="1"
113
-jarfile=""
114
-jre=""
115
-jrename="jre" # Filename for JRE without the .exe
116
-TAGGED=""
117
-
118
-showHelp() {
119
-	echo "This will generate a DMDirc installer for a windows based system."
120
-	echo "The following command line arguments are known:"
121
-	echo "---------------------"
122
-	echo "-h, --help                Help information"
123
-	echo "-b, --branch              Release in -r is a branch "
124
-	echo "-s, --setup               Recompile the .exe file"
125
-	echo "-o,                       If setup.exe compile fails, use old version"
126
-	echo "-p, --plugins <plugins>   What plugins to add to the jar file"
127
-	echo "-c, --compile             Recompile the .jar file"
128
-	echo "-u, --unsigned            Don't sign the exe"
129
-	echo "-e, --extra <tag>         Tag to add to final exe name to distinguish this build from a standard build"
130
-	echo "-f, --flags <flags>       Extra flags to pass to the compiler"
131
-	echo "    --jre                 Include the JRE in this installer"
132
-	echo "    --jar <file>          use <file> as DMDirc.jar"
133
-	echo "    --current             Use the current folder as the base for the build"
134
-# This is not in the help cos its crappy really, and makes little/no difference to the
135
-# exe size unless debugging information is added using --flags, in which case the person
136
-# probably is Dataforce and knows about this flag anyway
137
-#	echo "    --upx                 UPX binary if UPX is available on the path,"
138
-#	echo "                          (Compression Level: 4 for signed exe, 9 for unsigned)"
139
-	echo "---------------------"
140
-	exit 0;
141
-}
142
-
143
-while test -n "$1"; do
144
-	case "$1" in
145
-		--plugins|-p)
146
-			shift
147
-			plugins=${1}
148
-			;;
149
-		--jar)
150
-			shift
151
-			jarfile=${1}
152
-			;;
153
-		--jre)
154
-			jre="http://www.dmdirc.com/getjava/windows/all"
155
-			;;
156
-		--jre64)
157
-			# No specific jre64 for windows.
158
-			echo "No specific 64ibt JRE for windows, exiting"
159
-			exit 1;
160
-			;;
161
-		--current)
162
-			location="../../"
163
-			current="1"
164
-			;;
165
-		--compile|-c)
166
-			compileJar="true"
167
-			;;
168
-		--setup|-s)
169
-			compileSetup="true"
170
-			;;
171
-		-o)
172
-			useOldSetup="true"
173
-			;;
174
-		--release|-r)
175
-			shift
176
-			isRelease=${1}
177
-			;;
178
-		--extra|-e)
179
-			shift
180
-			finalTag="-${1}"
181
-			;;
182
-		--flags|-f)
183
-			shift
184
-			compilerFlags="${1} "
185
-			;;
186
-		--upx)
187
-			useUPX="true"
188
-			;;
189
-		--unsigned|-u)
190
-			signEXE="false"
191
-			;;
192
-		--help|-h)
193
-			showHelp;
194
-			;;
195
-		--branch|-b)
196
-			BRANCH="1"
197
-			;;
198
-		--tag|-t)
199
-			TAGGED=`git describe --tags`
200
-			TAGGED=${TAGGED%%-*}
201
-			;;
202
-	esac
203
-	shift
204
-done
205
-
206
-# Go!
207
-echo "-----------"
208
-if [ -e "${RUNNAME}" ]; then
209
-	echo "Removing existing .exe file"
210
-	rm -Rf "${RUNNAME}"
211
-fi
212
-if [ -e "${INTNAME}" ]; then
213
-	echo "Removing existing .7z file"
214
-	rm -Rf "${INTNAME}"
215
-fi
216
-echo "Creating .7z file"
217
-
218
-if [ "" = "${current}" ]; then
219
-	jarPath="${location}trunk"
220
-else
221
-	jarPath="${location}"
222
-fi
223
-
224
-if [ "" = "${jarfile}" ]; then
225
-	jarfile=${jarPath}"/dist/DMDirc.jar"
226
-	if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
227
-		echo "Creating jar.."
228
-		OLDPWD=${PWD}
229
-		cd ${jarPath}
230
-
231
-		rm -Rf build dist
232
-		ant jar
233
-		if [ ! -e "dist/DMDirc.jar" ]; then
234
-			echo "There was an error creating the .jar file. Aborting."
235
-			exit 1;
236
-		fi;
237
-		cd ${OLDPWD}
238
-	fi;
239
-elif [ ! -e "${jarfile}" ]; then
240
-	echo "Requested Jar file (${jarfile}) does not exist."
241
-	exit 1;
242
-fi;
243
-
244
-if [ "" = "${plugins}" ]; then
245
-	echo "Linking jar (${jarfile}).."
246
-	ln -sf ${jarfile} "./DMDirc.jar"
247
-else
248
-	echo "Copying jar (${jarfile}).."
249
-	cp ${jarfile} "./DMDirc.jar"
250
-
251
-	echo "Adding plugins to jar"
252
-	ln -sf ${jarPath}"/plugins"
253
-	pluginList=""
254
-	for plugin in ${plugins}; do
255
-		pluginList=${pluginList}" plugins/${plugin}"
256
-	done
257
-	jar -uvf "DMDirc.jar" ${pluginList}
258
-
259
-	../../updateBundledPlugins.sh "DMDirc.jar";
260
-	rm -Rf plugins;
261
-fi
262
-
263
-echo "	ReleaseNumber: String = '${TAGGED}';" > SetupConsts.inc
264
-
265
-FILES=""
266
-# Icon Res file
267
-if [ -e ${jarPath}"/src/com/dmdirc/res/icon.ico" ]; then
268
-	ln -sf ${jarPath}"/src/com/dmdirc/res/icon.ico" ./icon.ico
269
-	FILES="${FILES} ${PWDIR}/icon.ico"
270
-fi
271
-echo "icon.ico ICON icon.ico" > icon.rc
272
-
273
-# Other resources
274
-echo "extractor RCDATA extractor.exe" > files.rc
275
-
276
-COMPILER_IS_BROKEN="0";
277
-
278
-NUM="${TAGGED}"
279
-
280
-
281
-
282
-# Version Numbers
283
-if [ "" = "${NUM}" ]; then
284
-	MAJORVER="0"
285
-	MINORVER="0"
286
-	RELEASE="0"
287
-	EXTRAVER="0"
288
-	TEXTVER="${isRelease}"
289
-	PRIVATE="1"
290
-	USER=`whoami`
291
-	USER=`echo "${USER}" | sed 's#\\\\#\\\\\\\\#g'`
292
-	HOST=`hostname`
293
-	DATE=`date`
294
-else
295
-	MAJORVER=${NUM%%.*}
296
-	SUBVER=${NUM#*.}
297
-	EXTRAVER="0"
298
-	DOT=`expr index "${SUBVER}" .`
299
-	if [ "${DOT}" = "0" ]; then
300
-		MINORVER=${SUBVER}
301
-		RELEASE="0"
302
-	else
303
-		MINORVER=${SUBVER%%.*}
304
-		END=${SUBVER##*.}
305
-		RELEASE=${END##*[^0-9]}
306
-	fi
307
-	TEXTVER=$NUM
308
-	PRIVATE="0"
309
-fi;
310
-
311
-# Information for the below section:
312
-#
313
-# http://support.microsoft.com/kb/139491
314
-# http://msdn2.microsoft.com/en-us/library/aa381049.aspx
315
-# http://courses.cs.vt.edu/~cs3304/FreePascal/doc/prog/node14.html#SECTION001440000000000000000
316
-# http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/src/Resources/TortoiseShell.rc2
317
-
318
-echo "1 VERSIONINFO" > version.rc.1
319
-echo "FILEVERSION 1, 0, 0, 0" >> version.rc.1
320
-echo "PRODUCTVERSION ${MAJORVER}, ${MINORVER}, ${RELEASE}, ${EXTRAVER}" >> version.rc.1
321
-if [ "${PRIVATE}" = "1" ]; then
322
-	if [ "${COMPILER_IS_BROKEN}" = "0" ]; then
323
-		echo "FILEFLAGSMASK 0x000A" >> version.rc.1
324
-		echo "FILEFLAGS 0x3f" >> version.rc.1
325
-	else
326
-		echo "FILEFLAGS 0x000A" >> version.rc.1
327
-	fi;
328
-else
329
-	echo "FILEFLAGSMASK 0" >> version.rc.1
330
-fi;
331
-echo "FILEOS 0x40004" >> version.rc.1
332
-echo "FILETYPE 1" >> version.rc.1
333
-echo "BEGIN" >> version.rc.1
334
-echo "	BLOCK \"StringFileInfo\"" >> version.rc.1
335
-echo "	BEGIN" >> version.rc.1
336
-echo "		BLOCK \"040004E4\"" >> version.rc.1
337
-echo "		BEGIN" >> version.rc.1
338
-echo "			VALUE \"Comments\", \"http://www.dmdirc.com/\"" >> version.rc.1
339
-echo "			VALUE \"CompanyName\", \"DMDirc\"" >> version.rc.1
340
-cat version.rc.1 > version.rc
341
-cat version.rc.1 > uninstallversion.rc
342
-rm version.rc.1
343
-echo "			VALUE \"FileDescription\", \"Installer for DMDirc ${TEXTVER}\"" >> version.rc
344
-echo "			VALUE \"FileDescription\", \"Uninstaller for DMDirc\"" >> uninstallversion.rc
345
-
346
-echo "			VALUE \"FileVersion\", \"2.0\"" > version.rc.2
347
-echo "			VALUE \"InternalName\", \"DMDirc.jar\"" >> version.rc.2
348
-echo "			VALUE \"LegalCopyright\", \"Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes\"" >> version.rc.2
349
-echo "			VALUE \"OriginalFilename\", \"$2\"" >> version.rc.2
350
-echo "			VALUE \"ProductName\", \"DMDirc\"" >> version.rc.2
351
-echo "			VALUE \"ProductVersion\", \"${TEXTVER}\"" >> version.rc.2
352
-if [ "${PRIVATE}" = "1" ]; then
353
-	echo "			VALUE \"PrivateBuild\", \"Build by ${USER}@${HOST} on ${DATE}\"" >> version.rc.2
354
-fi;
355
-echo "		END" >> version.rc.2
356
-echo "	END" >> version.rc.2
357
-echo "	BLOCK \"VarFileInfo\"" >> version.rc.2
358
-echo "	BEGIN" >> version.rc.2
359
-echo "		VALUE \"Translation\", 0x400, 1252" >> version.rc.2
360
-echo "	END" >> version.rc.2
361
-echo "END" >> version.rc.2
362
-
363
-
364
-cat version.rc.2 >> version.rc
365
-cat version.rc.2 >> uninstallversion.rc
366
-rm version.rc.2
367
-
368
-echo "1 24 \"UAC.manifest\"" > UAC.rc
369
-echo "1 24 \"UAC_uninstaller.manifest\"" > UAC_uninstaller.rc
370
-
371
-# Build res files
372
-#windres -F pe-i386 -i version.rc -o version.res
373
-#windres -F pe-i386 -i files.rc -o files.res
374
-#windres -F pe-i386 -i icon.rc -o icon.res
375
-
376
-# UAC really needs to match the product name / description properly
377
-# so we have a special one for the uninstaller
378
-cat UAC_uninstaller.rc > uninstall.rc
379
-# Next line seems to be silly because we add a version resource
380
-# later as all.rc is not for the uninstaller.
381
-# cat uninstallversion.rc >> all.rc
382
-cat uninstallversion.rc >> uninstall.rc
383
-cat icon.rc >> uninstall.rc
384
-
385
-windres -F pe-i386 -i uninstall.rc -o uninstall.res
386
-
387
-cat UAC.rc > all.rc
388
-cat version.rc >> all.rc
389
-cat files.rc >> all.rc
390
-cat icon.rc >> all.rc
391
-# Build later after extractor.exe exists
392
-
393
-cat UAC.rc > most.rc
394
-cat version.rc >> most.rc
395
-cat icon.rc >> most.rc
396
-
397
-windres -F pe-i386 -i most.rc -o most.res
398
-
399
-FILES="${FILES} ${PWDIR}/DMDirc.jar ${PWDIR}/Setup.exe";
400
-if [ "" != "${jre}" ]; then
401
-	if [ ! -e "../common/${jrename}.exe" ]; then
402
-		echo "Downloading JRE to include in installer"
403
-		getFile "${jre}" "../common/${jrename}.exe"
404
-	fi
405
-	ln -sf ../common/${jrename}.exe jre.exe
406
-	FILES="${FILES} ${PWDIR}/jre.exe"
407
-fi;
408
-DELETEFILES=${FILES}
409
-if [ "" != "${DMDIRC_FPC}" ]; then
410
-	FPC=${DMDIRC_FPC}
411
-else
412
-	FPC=`which fpc`
413
-fi;
414
-lazarusDir="/usr/share/lazarus"
415
-if [ ! -e "${lazarusDir}/lcl" ]; then
416
-	lazarusDir="/usr/lib/lazarus/"
417
-fi;
418
-
419
-
420
-compilerFlags="-Sd -Twin32 ${compilerFlags}";
421
-extraFlags=""
422
-if [ ! -e "Setup.exe"  -o "${compileSetup}" = "true" ]; then
423
-	echo "Setup.exe does not exist. Lets try and compile it."
424
-	if [ "${FPC}" = "" ]; then
425
-		echo "FPC Compiler not found, Setup.exe can not be built."
426
-		exit 1;
427
-	else
428
-		echo "Building Setup.exe..."
429
-		extraFlags="-dKOL -Fu${PWDIR}/../../libwin/kolfpc -Fu{$PWDIR}/../../libwin/lcore -Fu{$PWDIR} -Fu${PWDIR}/../../libwin"
430
-		echo ${FPC} ${compilerFlags} ${extraFlags} Setup.dpr
431
-		${FPC} ${compilerFlags} ${extraFlags} Setup.dpr
432
-		if [ $? -ne 0 ]; then
433
-			if [ -e "Setup.exe" -a "${useOldSetup}" = "true" ]; then
434
-				echo "Unable to compile Setup.exe, using existing version."
435
-			else
436
-				echo "Unable to compile Setup.exe, terminating."
437
-				exit 1;
438
-			fi
439
-		fi;
440
-	fi
441
-fi
442
-
443
-ls
444
-if [ ! -e "Setup.exe" ]; then
445
-	echo "Still can't find Setup.exe, terminating."
446
-	exit 1;
447
-fi
448
-
449
-echo "Compressing files.."
450
-
451
-# Shortcut.exe is from http://www.optimumx.com/download/#Shortcut
452
-if [ ! -e Shortcut.exe ]; then
453
-	getFile "http://binary.dmdirc.com/Shortcut.zip" "Shortcut.zip"
454
-	unzip -q Shortcut.zip Shortcut.exe
455
-	rm Shortcut.zip
456
-fi
457
-FILES="${FILES} ${PWDIR}/Shortcut.exe"
458
-DELETEFILES="${DELETEFILES} Shortcut.exe"
459
-
460
-if [ "${isRelease}" != "" ]; then
461
-	DOCSDIR=${jarPath}
462
-else
463
-	DOCSDIR="../common"
464
-fi
465
-
466
-if [ -e "${DOCSDIR}/README.TXT" ]; then
467
-	ln -sf "${DOCSDIR}/README.TXT" .
468
-	FILES="${FILES} ${PWDIR}/README.TXT"
469
-	DELETEFILES="${DELETEFILES} README.TXT"
470
-fi
471
-
472
-if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
473
-	ln -sf "${DOCSDIR}/CHANGES.TXT" .
474
-	FILES="${FILES} ${PWDIR}/CHANGES.TXT"
475
-	DELETEFILES="${DELETEFILES} CHANGES.TXT"
476
-elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
477
-	ln -sf "${DOCSDIR}/CHANGELOG.TXT" .
478
-	FILES="${FILES} ${PWDIR}/CHANGELOG.TXT"
479
-	DELETEFILES="${DELETEFILES} CHANGELOG.TXT"
480
-fi
481
-
482
-if [ -e "${jarPath}/launcher/windows" ]; then
483
-	# Try to compile all
484
-	olddir=${PWD}
485
-	cd "${jarPath}/launcher/windows/"
486
-	sh compile.sh
487
-	cd ${olddir}
488
-	# Now add to file list.
489
-	for thisfile in `ls -1 ${jarPath}/launcher/windows/*.exe`; do
490
-		ln -sf ${thisfile} .
491
-		FILES="${FILES} ${PWDIR}/${thisfile}"
492
-	done
493
-fi
494
-
495
-extraFlags="-dKOL -Fu${PWDIR}/../../libwin/kolfpc -Fu{$PWDIR} -Fu${PWDIR}/../../libwin"
496
-echo ${FPC} ${compilerFlags} ${extraFlags} ${3}Uninstaller.dpr
497
-${FPC} ${compilerFlags} ${extraFlags} ${3}Uninstaller.dpr
498
-if [ -e "Uninstaller.exe" ]; then
499
-	FILES="${FILES} ${PWDIR}/Uninstaller.exe"
500
-#	DELETEFILES="${DELETEFILES} ${PWDIR}/Uninstaller.exe"
501
-fi
502
-
503
-# Add wget to allow downloading jre
504
-if [ ! -e "wget.exe" ]; then
505
-	getFile "http://binary.dmdirc.com/wget.exe" "wget.exe"
506
-fi;
507
-
508
-if [ ! -e "wget.exe" ]; then
509
-	echo "wget.exe not found, unable to continue."
510
-	exit 1;
511
-fi;
512
-
513
-FILES="${FILES} ${PWDIR}/wget.exe"
514
-
515
-compress $FILES
516
-
517
-echo "Creating config.."
518
-echo ";!@Install@!UTF-8!" > 7zip.conf
519
-if [ "${isRelease}" != "" ]; then
520
-	echo "Title=\"DMDirc Installation "${isRelease}"\"" >> 7zip.conf
521
-	echo "BeginPrompt=\"Do you want to install DMDirc "${isRelease}"?\"" >> 7zip.conf
522
-elif [ "${TAGGED}" != "" ]; then
523
-	echo "Title=\"DMDirc Installation "${TAGGED}"\"" >> 7zip.conf
524
-	echo "BeginPrompt=\"Do you want to install DMDirc "${TAGGED}"?\"" >> 7zip.conf
525
-else
526
-	echo "Title=\"DMDirc Installation\"" >> 7zip.conf
527
-	echo "BeginPrompt=\"Do you want to install DMDirc?\"" >> 7zip.conf
528
-fi;
529
-echo "ExecuteFile=\"Setup.exe\"" >> 7zip.conf
530
-echo ";!@InstallEnd@!" >> 7zip.conf
531
-
532
-if [ ! -e "7zS.sfx" ]; then
533
-	echo "Obtaining sfx stub.."
534
-	getFile "http://binary.dmdirc.com/7zS.sfx" "7zS.sfx"
535
-fi
536
-
537
-if [ ! -e "7zS.sfx" ]; then
538
-	echo "7zS.sfx not found, unable to continue."
539
-	exit 1;
540
-fi;
541
-
542
-echo "Creating .exe"
543
-cat 7zS.sfx 7zip.conf "${INTNAME}" > "${RUNNAME}"
544
-
545
-doRename=0
546
-if [ "${TAGGED}" != "" ]; then
547
-	doRename=1
548
-fi;
549
-
550
-if [ ${doRename} -eq 1 ]; then
551
-	if [ "${TAGGED}" = "" ]; then
552
-		releaseTag=branch-${isRelease}
553
-	else
554
-		releaseTag=${TAGGED}
555
-	fi;
556
-	ORIGNAME="DMDirc-${releaseTag}-Setup${finalTag}.exe"
557
-else
558
-	ORIGNAME="${INSTALLNAME}${finalTag}.exe"
559
-fi;
560
-
561
-echo "Building launcher";
562
-
563
-MD5BIN=`which md5sum`
564
-AWK=`which awk`
565
-MD5SUM=""
566
-if [ "${MD5BIN}" != "" -a "${AWK}" != "" ]; then
567
-	MD5SUM=`${MD5BIN} extractor.exe | ${AWK} '{print $1}'`
568
-fi
569
-echo "const" > consts.inc
570
-echo "	MD5SUM: String = '${MD5SUM}';" >> consts.inc
571
-
572
-# Code to extract and launch resource
573
-echo "ExtractResource('extractor', 'dmdirc_extractor.exe', TempDir);" > ExtractCode.inc
574
-if [ "${MD5SUM}" != "" ]; then
575
-	echo "if FindCmdLineSwitch('-nomd5') or FindCmdLineSwitch('nomd5') or checkMD5(TempDir+'dmdirc_extractor.exe') then begin" >> ExtractCode.inc
576
-	echo -n "	"; # Oh so important for code formatting!
577
-fi;
578
-echo "Launch(TempDir+'dmdirc_extractor.exe');" >> ExtractCode.inc
579
-if [ "${MD5SUM}" != "" ]; then
580
-	echo "end" >> ExtractCode.inc
581
-	echo "else begin" >> ExtractCode.inc
582
-	echo "	ErrorMessage := 'This copy of the DMDirc installer appears to be damaged and will now exit';" >> ExtractCode.inc
583
-	echo "	ErrorMessage := ErrorMessage+#13#10+'You may choose to skip this check and run it anyway by passing the /nomd5 parameter';" >> ExtractCode.inc
584
-	echo "	ErrorMessage := ErrorMessage+#13#10+'';" >> ExtractCode.inc
585
-	echo "	ErrorMessage := ErrorMessage+#13#10;" >> ExtractCode.inc
586
-	echo "	ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';" >> ExtractCode.inc
587
-	echo "	ErrorMessage := ErrorMessage+#13#10+'please feel free to contact us.';" >> ExtractCode.inc
588
-	echo "	" >> ExtractCode.inc
589
-	echo "	MessageBox(0, PChar(ErrorMessage), 'Sorry, setup is unable to continue', MB_OK + MB_ICONSTOP);" >> ExtractCode.inc
590
-	echo "end;" >> ExtractCode.inc
591
-fi
592
-
593
-windres -F pe-i386 -i all.rc -o all.res
594
-
595
-echo ${FPC} ${compilerFlags} ${3}Launcher.dpr
596
-${FPC} ${compilerFlags} ${3}Launcher.dpr
597
-if [ $? -ne 0 ]; then
598
-	if [ -e "Launcher.exe" ]; then
599
-		echo "Unable to compile Launcher.exe, using existing version."
600
-	else
601
-		echo "Unable to compile Launcher.exe, terminating."
602
-		exit 1;
603
-	fi
604
-fi
605
-
606
-rm -f *.res
607
-rm -f *.rc
608
-rm -f *.inc
609
-rm -f *.ppu
610
-
611
-FULLINSTALLER="${PWD}/${INSTALLNAME}${finalTag}.exe"
612
-mv Launcher.exe ${FULLINSTALLER}
613
-
614
-if [ "${useUPX}" = "true" ]; then
615
-	UPX=`which upx`
616
-	if [ "${UPX}" != "" ]; then
617
-		if [ "${signEXE}" = "true" ]; then
618
-			${UPX} -4 ${FULLINSTALLER}
619
-		else
620
-			${UPX} -9 ${FULLINSTALLER}
621
-		fi
622
-	fi
623
-fi
624
-
625
-echo "Chmodding.."
626
-chmod a+x ${FULLINSTALLER}
627
-if [ "${signEXE}" = "true" ]; then
628
-	echo "Signing.."
629
-	signexe ${FULLINSTALLER}
630
-else
631
-	echo "Not Signing.."
632
-fi;
633
-
634
-if [ "" != "${jre}" ]; then
635
-	ORIGNAME=`echo ${ORIGNAME} | sed "s/.exe$/.${jrename}.exe/"`
636
-fi;
637
-
638
-mv ${FULLINSTALLER} ../output/${ORIGNAME}
639
-
640
-# Quick hack to prevent deleting of 2 important files in ${FILES}
641
-mv Setup.exe Setup.exe.tmp
642
-mv Shortcut.exe Shortcut.exe.tmp
643
-
644
-rm -f ${DELETEFILES}
645
-rm -f ./7zip.conf
646
-rm -f ./*.o
647
-rm -f ./*.or
648
-rm -f ${RUNNAME}
649
-rm -f ${INTNAME}
650
-rm -f icon.ico
651
-
652
-# And un-hack
653
-mv Setup.exe.tmp Setup.exe
654
-mv Shortcut.exe.tmp Shortcut.exe
655
-
656
-echo "-----------"
657
-echo "Done."
658
-echo "-----------"
659
-
660
-# and Done \o
661
-exit 0;

+ 0
- 220
libwin/Vista.pas Parādīt failu

@@ -1,220 +0,0 @@
1
-{*
2
- * Vista image improvements from http://www.installationexcellence.com/articles/VistaWithDelphi/Original/Index.html
3
- * and http://www.installationexcellence.com/articles/VistaWithDelphi/Index.html
4
- *
5
- * This application launches DMDirc on windows and passes control to the
6
- * update engine as necessary.
7
- *
8
- * DMDirc - Open Source IRC Client
9
- * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
10
- * Michael Nixon
11
- *
12
- * Permission is hereby granted, free of charge, to any person obtaining a copy
13
- * of this software and associated documentation files (the "Software"), to deal
14
- * in the Software without restriction, including without limitation the rights
15
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
- * copies of the Software, and to permit persons to whom the Software is
17
- * furnished to do so, subject to the following conditions:
18
- *
19
- * The above copyright notice and this permission notice shall be included in
20
- * all copies or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
- * SOFTWARE.
29
- *}
30
-{* NOTE: The version in the installer/ directory is the one to edit! *}
31
-unit Vista;
32
-
33
-interface
34
-
35
-uses Windows, SysUtils;
36
-
37
-function IsWindowsVista: Boolean;
38
-function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent: WideString; const Icon, Buttons: integer; includeDescInXP: boolean = false; stripLineFeed: boolean = true): Integer;
39
-//procedure SetVistaFonts(const AForm: TCustomForm);
40
-
41
-const
42
-  VistaFont = 'Segoe UI'; 
43
-  VistaContentFont = 'Calibri';
44
-  XPContentFont = 'Verdana';
45
-  XPFont = 'Tahoma';
46
-
47
-  TD_ICON_BLANK = 0;
48
-  TD_ICON_WARNING = 84;
49
-  TD_ICON_QUESTION = 99;
50
-  TD_ICON_ERROR = 98;
51
-  TD_ICON_INFORMATION = 81;
52
-  TD_ICON_SHIELD_QUESTION = 104;
53
-  TD_ICON_SHIELD_ERROR = 105;
54
-  TD_ICON_SHIELD_OK = 106;
55
-  TD_ICON_SHIELD_WARNING = 107;
56
-
57
-  TD_BUTTON_OK = 1;
58
-  TD_BUTTON_YES = 2;
59
-  TD_BUTTON_NO = 4;
60
-  TD_BUTTON_CANCEL = 8;
61
-  TD_BUTTON_RETRY = 16;
62
-  TD_BUTTON_CLOSE = 32;
63
-
64
-  TD_RESULT_OK = 1;
65
-  TD_RESULT_CANCEL = 2;
66
-  TD_RESULT_RETRY = 4;
67
-  TD_RESULT_YES = 6;
68
-  TD_RESULT_NO = 7;
69
-  TD_RESULT_CLOSE = 8;
70
-  
71
-  mrNone = 0;
72
-  mrOK = mrNone + 1;
73
-  mrCancel = mrNone + 2;
74
-  mrAbort = mrNone + 3;
75
-  mrRetry = mrNone + 4;
76
-  mrYes = mrNone + 6;
77
-  mrNo = mrNone + 7;
78
-
79
-implementation
80
-
81
-{*
82
-procedure SetVistaFonts(const AForm: TCustomForm);
83
-begin
84
-  if IsWindowsVista and not SameText(AForm.Font.Name, VistaFont) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then
85
-  begin
86
-    AForm.Font.Size := AForm.Font.Size + 1;
87
-    AForm.Font.Name := VistaFont;
88
-  end;
89
-end;
90
-*}
91
-
92
-function IsWindowsVista: Boolean;
93
-var
94
-  VerInfo: TOSVersioninfo;
95
-begin
96
-  VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
97
-  GetVersionEx(VerInfo);
98
-  Result := VerInfo.dwMajorVersion >= 6;
99
-end;
100
-
101
-// http://www.swissdelphicenter.ch/en/showcode.php?id=1692
102
-{:Converts Unicode string to Ansi string using specified code page.
103
-  @param   ws       Unicode string.
104
-  @param   codePage Code page to be used in conversion.
105
-  @returns Converted ansi string.
106
-}
107
-function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
108
-var
109
-  l: integer;
110
-begin
111
-  if ws = '' then begin
112
-    Result := ''
113
-  end
114
-  else begin
115
-    l := WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, nil, 0, nil, nil);
116
-    SetLength(Result, l - 1);
117
-    if l > 1 then begin
118
-      WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, @Result[1], l - 1, nil, nil);
119
-    end;
120
-  end;
121
-end;
122
-
123
-
124
-//from http://www.tmssoftware.com/atbdev5.htm
125
-function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent: WideString; const Icon, Buttons: integer; includeDescInXP: boolean = false; stripLineFeed: boolean = true): Integer;
126
-type
127
-        tTaskDialogProc = function(HWND: THandle; hInstance: THandle; cTitle, cDescription, cContent: pwidechar; Buttons: Integer; Icon: integer; ResButton: pinteger): integer; stdcall;
128
-var
129
-  DLLHandle: THandle;
130
-  res: integer;
131
-  wS: WideString;
132
-  S: String;
133
-  {$IFDEF MESSAGEDLG}
134
-  Btns: TMsgDlgButtons;
135
-  DlgType: TMsgDlgType;
136
-  {$ELSE}
137
-  Btns: Integer;
138
-  myIcon: Integer;
139
-  {$ENDIF}
140
-  TaskDialogFound: boolean;
141
-  TaskDialogProc: tTaskDialogProc;
142
-begin
143
-  TaskDialogFound := false;
144
-  Result := 0;
145
-  if IsWindowsVista then begin
146
-    DLLHandle := LoadLibrary('comctl32.dll');
147
-    if DLLHandle >= 32 then begin
148
-      TaskDialogProc := tTaskDialogProc(GetProcAddress(DLLHandle,'TaskDialog'));
149
-      
150
-      if Assigned(TaskDialogProc) then begin
151
-        
152
-        if stripLineFeed then begin
153
-          wS := StringReplace(AContent, #10, '', [rfReplaceAll]);
154
-          wS := StringReplace(wS, #13, '', [rfReplaceAll]);
155
-        end
156
-        else begin
157
-          wS := AContent;
158
-        end;
159
-
160
-        TaskDialogProc(AHandle, 0, PWideChar(ATitle), PWideChar(ADescription), PWideChar(wS), Buttons, Icon, @res);
161
-        TaskDialogFound := true;
162
-        Result := mrOK;
163
-        case res of
164
-          TD_RESULT_CANCEL : Result := mrCancel;
165
-          TD_RESULT_RETRY : Result := mrRetry;
166
-          TD_RESULT_YES : Result := mrYes;
167
-          TD_RESULT_NO : Result := mrNo;
168
-          TD_RESULT_CLOSE : Result := mrAbort;
169
-        end;
170
-      end;
171
-      FreeLibrary(DLLHandle);
172
-    end;
173
-  end;
174
-  
175
-  if not TaskDialogFound then begin
176
-    S := '';
177
-    if includeDescInXP then S := ADescription + #10#13 + #10#13 + AContent else S := AContent;
178
-    
179
-    {$IFDEF MESSAGEDLG}
180
-      Btns := [];
181
-      if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := Btns + [MBOK];
182
-      if Buttons and TD_BUTTON_YES = TD_BUTTON_YES then Btns := Btns + [MBYES];
183
-      if Buttons and TD_BUTTON_NO = TD_BUTTON_NO then Btns := Btns + [MBNO];
184
-      if Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL then Btns := Btns + [MBCANCEL];
185
-      if Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY then Btns := Btns + [MBRETRY];
186
-  
187
-      if Buttons and TD_BUTTON_CLOSE = TD_BUTTON_CLOSE then Btns := Btns + [MBABORT];
188
-  
189
-      DlgType := mtCustom;
190
-  
191
-      case Icon of
192
-        TD_ICON_WARNING : DlgType := mtWarning;
193
-        TD_ICON_QUESTION : DlgType := mtConfirmation;
194
-        TD_ICON_ERROR : DlgType := mtError;
195
-        TD_ICON_INFORMATION: DlgType := mtInformation;
196
-      end;
197
-  
198
-      Result := MessageDlg(S, DlgType, Btns, 0);
199
-    {$ELSE}
200
-      Btns := 0;
201
-      if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := MB_OK;
202
-      if (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNO;
203
-      if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNOCANCEL;
204
-      if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_OK = TD_BUTTON_OK) then Btns := MB_OKCANCEL;
205
-      if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY) then Btns := MB_RETRYCANCEL;
206
-      
207
-      myIcon := 0;
208
-      case Icon of
209
-        TD_ICON_QUESTION : myIcon := MB_ICONQUESTION;
210
-        TD_ICON_ERROR : myIcon := MB_ICONSTOP;
211
-        TD_ICON_INFORMATION: myIcon := MB_ICONINFORMATION;
212
-      end;
213
-
214
-                        Result := MessageBox(0, pchar(S), pchar(String(ATitle)), Btns + myIcon);
215
-    {$ENDIF}
216
-  end;
217
-end;
218
-
219
-end.
220
-

+ 0
- 1
libwin/kolfpc/COPYING Parādīt failu

@@ -1 +0,0 @@
1
-See files COPYING.LIB and LICENCE.TXT in top directory

+ 0
- 517
libwin/kolfpc/COPYING.LIB Parādīt failu

@@ -1,517 +0,0 @@
1
-
2
-	  GNU LIBRARY GENERAL PUBLIC LICENSE
3
-	  ==================================
4
-                Version 2, June 1991
5
-
6
- Copyright (C) 1991 Free Software Foundation, Inc.
7
-                    675 Mass Ave, Cambridge, MA 02139, USA
8
- Everyone is permitted to copy and distribute verbatim copies
9
- of this license document, but changing it is not allowed.
10
-
11
-[This is the first released version of the library GPL.  It is
12
- numbered 2 because it goes with version 2 of the ordinary GPL.]
13
-
14
-                        Preamble
15
-
16
-The licenses for most software are designed to take away your
17
-freedom to share and change it.  By contrast, the GNU General
18
-Public Licenses are intended to guarantee your freedom to share
19
-and change free software--to make sure the software is free for
20
-all its users.
21
-
22
-This license, the Library General Public License, applies to
23
-some specially designated Free Software Foundation software, and
24
-to any other libraries whose authors decide to use it.  You can
25
-use it for your libraries, too.
26
-
27
-When we speak of free software, we are referring to freedom, not
28
-price.  Our General Public Licenses are designed to make sure
29
-that you have the freedom to distribute copies of free software
30
-(and charge for this service if you wish), that you receive
31
-source code or can get it if you want it, that you can change
32
-the software or use pieces of it in new free programs; and that
33
-you know you can do these things.
34
-
35
-To protect your rights, we need to make restrictions that forbid
36
-anyone to deny you these rights or to ask you to surrender the
37
-rights. These restrictions translate to certain responsibilities
38
-for you if you distribute copies of the library, or if you
39
-modify it.
40
-
41
-For example, if you distribute copies of the library, whether
42
-gratis or for a fee, you must give the recipients all the rights
43
-that we gave you.  You must make sure that they, too, receive or
44
-can get the source code.  If you link a program with the
45
-library, you must provide complete object files to the
46
-recipients so that they can relink them with the library, after
47
-making changes to the library and recompiling it.  And you must
48
-show them these terms so they know their rights.
49
-
50
-Our method of protecting your rights has two steps: (1)
51
-copyright the library, and (2) offer you this license which
52
-gives you legal permission to copy, distribute and/or modify the
53
-library.
54
-
55
-Also, for each distributor's protection, we want to make certain
56
-that everyone understands that there is no warranty for this
57
-free library.  If the library is modified by someone else and
58
-passed on, we want its recipients to know that what they have is
59
-not the original version, so that any problems introduced by
60
-others will not reflect on the original authors' reputations.
61
- 
62
-Finally, any free program is threatened constantly by software
63
-patents.  We wish to avoid the danger that companies
64
-distributing free software will individually obtain patent
65
-licenses, thus in effect transforming the program into
66
-proprietary software.  To prevent this, we have made it clear
67
-that any patent must be licensed for everyone's free use or not
68
-licensed at all.
69
-
70
-Most GNU software, including some libraries, is covered by the
71
-ordinary GNU General Public License, which was designed for
72
-utility programs.  This license, the GNU Library General Public
73
-License, applies to certain designated libraries.  This license
74
-is quite different from the ordinary one; be sure to read it in
75
-full, and don't assume that anything in it is the same as in the
76
-ordinary license.
77
-
78
-The reason we have a separate public license for some libraries
79
-is that they blur the distinction we usually make between
80
-modifying or adding to a program and simply using it.  Linking a
81
-program with a library, without changing the library, is in some
82
-sense simply using the library, and is analogous to running a
83
-utility program or application program.  However, in a textual
84
-and legal sense, the linked executable is a combined work, a
85
-derivative of the original library, and the ordinary General
86
-Public License treats it as such.
87
-
88
-Because of this blurred distinction, using the ordinary General
89
-Public License for libraries did not effectively promote
90
-software sharing, because most developers did not use the
91
-libraries.  We concluded that weaker conditions might promote
92
-sharing better.
93
-
94
-However, unrestricted linking of non-free programs would deprive
95
-the users of those programs of all benefit from the free status
96
-of the libraries themselves.  This Library General Public
97
-License is intended to permit developers of non-free programs to
98
-use free libraries, while preserving your freedom as a user of
99
-such programs to change the free libraries that are incorporated
100
-in them.  (We have not seen how to achieve this as regards
101
-changes in header files, but we have achieved it as regards
102
-changes in the actual functions of the Library.)  The hope is
103
-that this will lead to faster development of free libraries.
104
-
105
-The precise terms and conditions for copying, distribution and
106
-modification follow.  Pay close attention to the difference
107
-between a "work based on the library" and a "work that uses the
108
-library".  The former contains code derived from the library,
109
-while the latter only works together with the library.
110
-
111
-Note that it is possible for a library to be covered by the
112
-ordinary General Public License rather than by this special one.
113
-
114
-                GNU LIBRARY GENERAL PUBLIC LICENSE
115
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
116
-
117
-0. This License Agreement applies to any software library which
118
-contains a notice placed by the copyright holder or other
119
-authorized party saying it may be distributed under the terms of
120
-this Library General Public License (also called "this
121
-License").  Each licensee is addressed as "you".
122
-
123
-A "library" means a collection of software functions and/or data
124
-prepared so as to be conveniently linked with application
125
-programs (which use some of those functions and data) to form
126
-executables.
127
-
128
-The "Library", below, refers to any such software library or
129
-work which has been distributed under these terms.  A "work
130
-based on the Library" means either the Library or any derivative
131
-work under copyright law: that is to say, a work containing the
132
-Library or a portion of it, either verbatim or with
133
-modifications and/or translated straightforwardly into another
134
-language.  (Hereinafter, translation is included without
135
-limitation in the term "modification".)
136
-
137
-"Source code" for a work means the preferred form of the work
138
-for making modifications to it.  For a library, complete source
139
-code means all the source code for all modules it contains, plus
140
-any associated interface definition files, plus the scripts used
141
-to control compilation and installation of the library.
142
-
143
-Activities other than copying, distribution and modification are
144
-not covered by this License; they are outside its scope.  The
145
-act of running a program using the Library is not restricted,
146
-and output from such a program is covered only if its contents
147
-constitute a work based on the Library (independent of the use
148
-of the Library in a tool for writing it).  Whether that is true
149
-depends on what the Library does and what the program that uses
150
-the Library does.
151
-  
152
-1. You may copy and distribute verbatim copies of the Library's
153
-complete source code as you receive it, in any medium, provided
154
-that you conspicuously and appropriately publish on each copy an
155
-appropriate copyright notice and disclaimer of warranty; keep
156
-intact all the notices that refer to this License and to the
157
-absence of any warranty; and distribute a copy of this License
158
-along with the Library.
159
-
160
-You may charge a fee for the physical act of transferring a
161
-copy, and you may at your option offer warranty protection in
162
-exchange for a fee.
163
- 
164
-2. You may modify your copy or copies of the Library or any
165
-portion of it, thus forming a work based on the Library, and
166
-copy and distribute such modifications or work under the terms
167
-of Section 1 above, provided that you also meet all of these
168
-conditions:
169
-
170
-    a) The modified work must itself be a software library.
171
-
172
-    b) You must cause the files modified to carry prominent notices
173
-    stating that you changed the files and the date of any change.
174
-
175
-    c) You must cause the whole of the work to be licensed at no
176
-    charge to all third parties under the terms of this License.
177
-
178
-    d) If a facility in the modified Library refers to a function or a
179
-    table of data to be supplied by an application program that uses
180
-    the facility, other than as an argument passed when the facility
181
-    is invoked, then you must make a good faith effort to ensure that,
182
-    in the event an application does not supply such function or
183
-    table, the facility still operates, and performs whatever part of
184
-    its purpose remains meaningful.
185
-
186
-    (For example, a function in a library to compute square roots has
187
-    a purpose that is entirely well-defined independent of the
188
-    application.  Therefore, Subsection 2d requires that any
189
-    application-supplied function or table used by this function must
190
-    be optional: if the application does not supply it, the square
191
-    root function must still compute square roots.)
192
-
193
-These requirements apply to the modified work as a whole.  If
194
-identifiable sections of that work are not derived from the
195
-Library, and can be reasonably considered independent and
196
-separate works in themselves, then this License, and its terms,
197
-do not apply to those sections when you distribute them as
198
-separate works.  But when you distribute the same sections as
199
-part of a whole which is a work based on the Library, the
200
-distribution of the whole must be on the terms of this License,
201
-whose permissions for other licensees extend to the entire
202
-whole, and thus to each and every part regardless of who wrote
203
-it.
204
-
205
-Thus, it is not the intent of this section to claim rights or
206
-contest your rights to work written entirely by you; rather, the
207
-intent is to exercise the right to control the distribution of
208
-derivative or collective works based on the Library.
209
-
210
-In addition, mere aggregation of another work not based on the
211
-Library with the Library (or with a work based on the Library)
212
-on a volume of a storage or distribution medium does not bring
213
-the other work under the scope of this License.
214
-
215
-3. You may opt to apply the terms of the ordinary GNU General
216
-Public License instead of this License to a given copy of the
217
-Library.  To do this, you must alter all the notices that refer
218
-to this License, so that they refer to the ordinary GNU General
219
-Public License, version 2, instead of to this License.  (If a
220
-newer version than version 2 of the ordinary GNU General Public
221
-License has appeared, then you can specify that version instead
222
-if you wish.)  Do not make any other change in these notices.
223
- 
224
-Once this change is made in a given copy, it is irreversible for
225
-that copy, so the ordinary GNU General Public License applies to
226
-all subsequent copies and derivative works made from that copy.
227
-
228
-This option is useful when you wish to copy part of the code of
229
-the Library into a program that is not a library.
230
-
231
-4. You may copy and distribute the Library (or a portion or
232
-derivative of it, under Section 2) in object code or executable
233
-form under the terms of Sections 1 and 2 above provided that you
234
-accompany it with the complete corresponding machine-readable
235
-source code, which must be distributed under the terms of
236
-Sections 1 and 2 above on a medium customarily used for software
237
-interchange.
238
-
239
-If distribution of object code is made by offering access to
240
-copy from a designated place, then offering equivalent access to
241
-copy the source code from the same place satisfies the
242
-requirement to distribute the source code, even though third
243
-parties are not compelled to copy the source along with the
244
-object code.
245
-
246
-5. A program that contains no derivative of any portion of the
247
-Library, but is designed to work with the Library by being
248
-compiled or linked with it, is called a "work that uses the
249
-Library".  Such a work, in isolation, is not a derivative work
250
-of the Library, and therefore falls outside the scope of this
251
-License.
252
-
253
-However, linking a "work that uses the Library" with the Library
254
-creates an executable that is a derivative of the Library
255
-(because it contains portions of the Library), rather than a
256
-"work that uses the library".  The executable is therefore
257
-covered by this License. Section 6 states terms for distribution
258
-of such executables.
259
-
260
-When a "work that uses the Library" uses material from a header
261
-file that is part of the Library, the object code for the work
262
-may be a derivative work of the Library even though the source
263
-code is not. Whether this is true is especially significant if
264
-the work can be linked without the Library, or if the work is
265
-itself a library.  The threshold for this to be true is not
266
-precisely defined by law.
267
-
268
-If such an object file uses only numerical parameters, data
269
-structure layouts and accessors, and small macros and small
270
-inline functions (ten lines or less in length), then the use of
271
-the object file is unrestricted, regardless of whether it is
272
-legally a derivative work.  (Executables containing this object
273
-code plus portions of the Library will still fall under Section
274
-6.)
275
-
276
-Otherwise, if the work is a derivative of the Library, you may
277
-distribute the object code for the work under the terms of
278
-Section 6. Any executables containing that work also fall under
279
-Section 6, whether or not they are linked directly with the
280
-Library itself.
281
- 
282
-6. As an exception to the Sections above, you may also compile
283
-or link a "work that uses the Library" with the Library to
284
-produce a work containing portions of the Library, and
285
-distribute that work under terms of your choice, provided that
286
-the terms permit modification of the work for the customer's own
287
-use and reverse engineering for debugging such modifications.
288
-
289
-You must give prominent notice with each copy of the work that
290
-the Library is used in it and that the Library and its use are
291
-covered by this License.  You must supply a copy of this
292
-License.  If the work during execution displays copyright
293
-notices, you must include the copyright notice for the Library
294
-among them, as well as a reference directing the user to the
295
-copy of this License.  Also, you must do one of these things:
296
-
297
-    a) Accompany the work with the complete corresponding
298
-    machine-readable source code for the Library including whatever
299
-    changes were used in the work (which must be distributed under
300
-    Sections 1 and 2 above); and, if the work is an executable linked
301
-    with the Library, with the complete machine-readable "work that
302
-    uses the Library", as object code and/or source code, so that the
303
-    user can modify the Library and then relink to produce a modified
304
-    executable containing the modified Library.  (It is understood
305
-    that the user who changes the contents of definitions files in the
306
-    Library will not necessarily be able to recompile the application
307
-    to use the modified definitions.)
308
-
309
-    b) Accompany the work with a written offer, valid for at
310
-    least three years, to give the same user the materials
311
-    specified in Subsection 6a, above, for a charge no more
312
-    than the cost of performing this distribution.
313
-
314
-    c) If distribution of the work is made by offering access to copy
315
-    from a designated place, offer equivalent access to copy the above
316
-    specified materials from the same place.
317
-
318
-    d) Verify that the user has already received a copy of these
319
-    materials or that you have already sent this user a copy.
320
-
321
-For an executable, the required form of the "work that uses the
322
-Library" must include any data and utility programs needed for
323
-reproducing the executable from it.  However, as a special
324
-exception, the source code distributed need not include anything
325
-that is normally distributed (in either source or binary form)
326
-with the major components (compiler, kernel, and so on) of the
327
-operating system on which the executable runs, unless that
328
-component itself accompanies the executable.
329
-
330
-It may happen that this requirement contradicts the license
331
-restrictions of other proprietary libraries that do not normally
332
-accompany the operating system.  Such a contradiction means you
333
-cannot use both them and the Library together in an executable
334
-that you distribute.
335
- 
336
-7. You may place library facilities that are a work based on the
337
-Library side-by-side in a single library together with other
338
-library facilities not covered by this License, and distribute
339
-such a combined library, provided that the separate distribution
340
-of the work based on the Library and of the other library
341
-facilities is otherwise permitted, and provided that you do
342
-these two things:
343
-
344
-    a) Accompany the combined library with a copy of the same work
345
-    based on the Library, uncombined with any other library
346
-    facilities.  This must be distributed under the terms of the
347
-    Sections above.
348
-
349
-    b) Give prominent notice with the combined library of the fact
350
-    that part of it is a work based on the Library, and explaining
351
-    where to find the accompanying uncombined form of the same work.
352
-
353
-8. You may not copy, modify, sublicense, link with, or
354
-distribute the Library except as expressly provided under this
355
-License.  Any attempt otherwise to copy, modify, sublicense,
356
-link with, or distribute the Library is void, and will
357
-automatically terminate your rights under this License.
358
-However, parties who have received copies, or rights, from you
359
-under this License will not have their licenses terminated so
360
-long as such parties remain in full compliance.
361
-
362
-9. You are not required to accept this License, since you have
363
-not signed it.  However, nothing else grants you permission to
364
-modify or distribute the Library or its derivative works.  These
365
-actions are prohibited by law if you do not accept this
366
-License.  Therefore, by modifying or distributing the Library
367
-(or any work based on the Library), you indicate your acceptance
368
-of this License to do so, and all its terms and conditions for
369
-copying, distributing or modifying the Library or works based on
370
-it.
371
-
372
-10. Each time you redistribute the Library (or any work based on
373
-the Library), the recipient automatically receives a license
374
-from the original licensor to copy, distribute, link with or
375
-modify the Library subject to these terms and conditions.  You
376
-may not impose any further restrictions on the recipients'
377
-exercise of the rights granted herein. You are not responsible
378
-for enforcing compliance by third parties to this License.
379
- 
380
-11. If, as a consequence of a court judgment or allegation of
381
-patent infringement or for any other reason (not limited to
382
-patent issues), conditions are imposed on you (whether by court
383
-order, agreement or otherwise) that contradict the conditions of
384
-this License, they do not excuse you from the conditions of this
385
-License.  If you cannot distribute so as to satisfy
386
-simultaneously your obligations under this License and any other
387
-pertinent obligations, then as a consequence you may not
388
-distribute the Library at all.  For example, if a patent license
389
-would not permit royalty-free redistribution of the Library by
390
-all those who receive copies directly or indirectly through you,
391
-then the only way you could satisfy both it and this License
392
-would be to refrain entirely from distribution of the Library.
393
-
394
-If any portion of this section is held invalid or unenforceable
395
-under any particular circumstance, the balance of the section is
396
-intended to apply, and the section as a whole is intended to
397
-apply in other circumstances.
398
-
399
-It is not the purpose of this section to induce you to infringe
400
-any patents or other property right claims or to contest
401
-validity of any such claims; this section has the sole purpose
402
-of protecting the integrity of the free software distribution
403
-system which is implemented by public license practices.  Many
404
-people have made generous contributions to the wide range of
405
-software distributed through that system in reliance on
406
-consistent application of that system; it is up to the
407
-author/donor to decide if he or she is willing to distribute
408
-software through any other system and a licensee cannot impose
409
-that choice.
410
-
411
-This section is intended to make thoroughly clear what is
412
-believed to be a consequence of the rest of this License.
413
-
414
-12. If the distribution and/or use of the Library is restricted
415
-in certain countries either by patents or by copyrighted
416
-interfaces, the original copyright holder who places the Library
417
-under this License may add an explicit geographical distribution
418
-limitation excluding those countries, so that distribution is
419
-permitted only in or among countries not thus excluded.  In such
420
-case, this License incorporates the limitation as if written in
421
-the body of this License.
422
-
423
-13. The Free Software Foundation may publish revised and/or new
424
-versions of the Library General Public License from time to
425
-time. Such new versions will be similar in spirit to the present
426
-version, but may differ in detail to address new problems or
427
-concerns.
428
-
429
-Each version is given a distinguishing version number.  If the
430
-Library specifies a version number of this License which applies
431
-to it and "any later version", you have the option of following
432
-the terms and conditions either of that version or of any later
433
-version published by the Free Software Foundation.  If the
434
-Library does not specify a license version number, you may
435
-choose any version ever published by the Free Software
436
-Foundation.
437
-
438
-14. If you wish to incorporate parts of the Library into other
439
-free programs whose distribution conditions are incompatible
440
-with these, write to the author to ask for permission.  For
441
-software which is copyrighted by the Free Software Foundation,
442
-write to the Free Software Foundation; we sometimes make
443
-exceptions for this.  Our decision will be guided by the two
444
-goals of preserving the free status of all derivatives of our
445
-free software and of promoting the sharing and reuse of software
446
-generally.
447
-
448
-                           NO WARRANTY
449
-
450
-  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
451
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
452
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
453
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND,
454
-EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
455
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
456
-PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
457
-LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
458
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
459
-
460
-  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
461
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
462
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
463
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
464
-DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
465
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
466
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
467
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
468
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
469
-
470
-                    END OF TERMS AND CONDITIONS
471
-
472
- Appendix: How to Apply These Terms to Your New Libraries
473
-
474
-If you develop a new library, and you want it to be of the
475
-greatest possible use to the public, we recommend making it free
476
-software that everyone can redistribute and change.  You can do
477
-so by permitting redistribution under these terms (or,
478
-alternatively, under the terms of the ordinary General Public
479
-License).
480
-
481
-To apply these terms, attach the following notices to the
482
-library.  It is safest to attach them to the start of each
483
-source file to most effectively convey the exclusion of
484
-warranty; and each file should have at least the "copyright"
485
-line and a pointer to where the full notice is found.
486
-
487
-    <one line to give the library's name and a brief idea of what it does.>
488
-    Copyright (C) <year>  <name of author>
489
-
490
-    This library is free software; you can redistribute it and/or
491
-    modify it under the terms of the GNU Library General Public
492
-    License as published by the Free Software Foundation; either
493
-    version 2 of the License, or (at your option) any later version.
494
-
495
-    This library is distributed in the hope that it will be useful,
496
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
497
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
498
-    Library General Public License for more details.
499
-
500
-    You should have received a copy of the GNU Library General Public
501
-    License along with this library; if not, write to the Free
502
-    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
503
-
504
-Also add information on how to contact you by electronic and paper mail.
505
-
506
-You should also get your employer (if you work as a programmer) or your
507
-school, if any, to sign a "copyright disclaimer" for the library, if
508
-necessary.  Here is a sample; alter the names:
509
-
510
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the
511
-  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
512
-
513
-  <signature of Ty Coon>, 1 April 1990
514
-  Ty Coon, President of Vice
515
-
516
-That's all there is to it!
517
-

+ 0
- 75
libwin/kolfpc/KOL-CE.rc Parādīt failu

@@ -1,75 +0,0 @@
1
-// Dummy menu resources. Needed for menu support.
2
-//*****************************************************
3
-
4
-// 2 simple menu items
5
-20000 MENU DISCARDABLE
6
-BEGIN
7
-  MENUITEM " ", 1
8
-  MENUITEM " ", 2
9
-END
10
-
11
-20000 RCDATA DISCARDABLE
12
-BEGIN
13
-    20000, 2,
14
-    -2, 1, 8, 0x10, 0, 0, 0xFFFF,
15
-    -2, 2, 8, 0x10, 0, 0, 0xFFFF
16
-END
17
-
18
-// popup and simple menu item
19
-20001 MENU DISCARDABLE
20
-BEGIN
21
-  POPUP " "
22
-  BEGIN
23
-    MENUITEM " ", 1
24
-  END
25
-  MENUITEM " ", 2
26
-END
27
-
28
-20001 RCDATA DISCARDABLE
29
-BEGIN
30
-    20001, 2,
31
-    -2, 1, 4, 0x18, 0, 0, 0,
32
-    -2, 2, 4, 0x10, 0, 0, 0xFFFF
33
-END
34
-
35
-// simple item and popup menu
36
-20002 MENU DISCARDABLE
37
-BEGIN
38
-  MENUITEM " ", 1
39
-  POPUP " "
40
-  BEGIN
41
-    MENUITEM " ", 2
42
-  END
43
-END
44
-
45
-20002 RCDATA DISCARDABLE
46
-BEGIN
47
-    20002, 2,
48
-    -2, 1, 4, 0x10, 0, 0, 0xFFFF,
49
-    -2, 2, 4, 0x18, 0, 0, 1
50
-END
51
-
52
-// 2 popup menus
53
-20003 MENU DISCARDABLE
54
-BEGIN
55
-  POPUP " "
56
-  BEGIN
57
-    MENUITEM " ", 1
58
-  END
59
-  POPUP " "
60
-  BEGIN
61
-    MENUITEM " ", 2
62
-  END
63
-END
64
-
65
-20003 RCDATA DISCARDABLE
66
-BEGIN
67
-    20003, 2,
68
-    -2, 1, 4, 0x18, 0, 0, 0,
69
-    -2, 2, 4, 0x18, 0, 0, 1
70
-END
71
-
72
-//*****************************************************
73
-
74
-// Uncomment the line below to run application in real VGA mode
75
-// HI_RES_AWARE CEUX {1}

+ 0
- 57984
libwin/kolfpc/KOL.PAS
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 125
libwin/kolfpc/KOLCEOpenDir.inc Parādīt failu

@@ -1,125 +0,0 @@
1
-{$ifdef read_interface}
2
-//[OpenDirectory Object]
3
-{ ----------------------------------------------------------------------
4
-                               TOpenDirDialog
5
------------------------------------------------------------------------ }
6
-//[TOpenDirDialog DEFINITION]
7
-  TOpenDirDialog = object( TObj )
8
-  {* Dialog for open directories, uses SHBrowseForFolder. }
9
-  private
10
-    FWnd: HWnd;
11
-    function GetDialogWnd: HWnd;
12
-    function GetTitle: KOLString;
13
-    procedure SetTitle(const AValue: KOLString);
14
-  protected
15
-    FDlg: PObj;
16
-    FOptions: TOpenDirOptions;
17
-    FCenterOnScreen: Boolean;
18
-    FOnSelChanged: TOnODSelChange;
19
-    function GetPath: KOLString;
20
-    procedure SetInitialPath(const Value: KOLString);
21
-    procedure SetCenterOnScreen(const Value: Boolean);
22
-    procedure SetOnSelChanged(const Value: TOnODSelChange);
23
-    function GetInitialPath: KOLString;
24
-  public
25
-    destructor Destroy; {-}virtual;{+}{++}(*override;*){--}
26
-    {* destructor }
27
-    function Execute : Boolean;
28
-    {* Call it to select directory by user. Returns True, if operation was
29
-       not cancelled by user. }
30
-    property Title : KOLString read GetTitle write SetTitle;
31
-    {* Title for a dialog. }
32
-    property Options : TOpenDirOptions read FOptions write FOptions;
33
-    {* Option flags. }
34
-    property Path : KOLString read GetPath;
35
-    {* Resulting (selected by user) path. }
36
-    property InitialPath: KOLString read GetInitialPath write SetInitialPath;
37
-    {* Set this property to a path of directory to be selected initially
38
-       in a dialog. }
39
-    property CenterOnScreen: Boolean read FCenterOnScreen write SetCenterOnScreen;
40
-    {* Set it to True to center dialog on screen. }
41
-    property OnSelChanged: TOnODSelChange read FOnSelChanged write SetOnSelChanged;
42
-    {* This event is called every time, when user selects another directory.
43
-       It is possible to enable/disable OK button in dialog and/or change
44
-       dialog status text in responce to event. }
45
-    property WndOwner: HWnd read FWnd write FWnd;
46
-    {* Owner window. If you want to provide your dialog visible over stay-on-top
47
-       form, fire it as a child of the form, assigning the handle of form window
48
-       to this property first. }
49
-    property DialogWnd: HWnd read GetDialogWnd;
50
-    {* Handle to the open directory dialog itself, become available on the
51
-       first call of callback procedure (i.e. on the first call to OnSelChanged).
52
-    }
53
-  end;
54
-//[END OF TOpenDirDialog DEFINITION]
55
-{$endif read_interface}
56
-
57
-{$ifdef read_implementation}
58
-{$I KOLDirDlgEx.pas}
59
-
60
-function NewOpenDirDialog( const Title: KOLString; Options: TOpenDirOptions ):
61
-         POpenDirDialog;
62
-begin
63
-  New( Result, Create );
64
-  Result.FDlg:=NewOpenDirDialogEx;
65
-  Result.FOptions := [ odOnlySystemDirs ];
66
-  if Options <> [] then
67
-    Result.FOptions := Options;
68
-  Result.Title := Title;
69
-end;
70
-
71
-{ TOpenDirDialog }
72
-
73
-function TOpenDirDialog.GetTitle: KOLString;
74
-begin
75
-  Result:=POpenDirDialogEx(FDlg).Title;
76
-end;
77
-
78
-function TOpenDirDialog.GetDialogWnd: HWnd;
79
-begin
80
-  Result:=POpenDirDialogEx(FDlg).Form.GetWindowHandle;
81
-end;
82
-
83
-procedure TOpenDirDialog.SetTitle(const AValue: KOLString);
84
-begin
85
-  POpenDirDialogEx(FDlg).Title:=AValue;
86
-end;
87
-
88
-function TOpenDirDialog.GetPath: KOLString;
89
-begin
90
-  Result:=ExcludeTrailingPathDelimiter(POpenDirDialogEx(FDlg).Path);
91
-  if Result = '' then
92
-    Result:='\';
93
-end;
94
-
95
-procedure TOpenDirDialog.SetInitialPath(const Value: KOLString);
96
-begin
97
-  POpenDirDialogEx(FDlg).InitialPath:=Value;
98
-end;
99
-
100
-procedure TOpenDirDialog.SetCenterOnScreen(const Value: Boolean);
101
-begin
102
-end;
103
-
104
-procedure TOpenDirDialog.SetOnSelChanged(const Value: TOnODSelChange);
105
-begin
106
-end;
107
-
108
-function TOpenDirDialog.GetInitialPath: KOLString;
109
-begin
110
-  Result:=POpenDirDialogEx(FDlg).InitialPath;
111
-end;
112
-
113
-destructor TOpenDirDialog.Destroy;
114
-begin
115
-  POpenDirDialogEx(FDlg).Free;
116
-  inherited;
117
-end;
118
-
119
-function TOpenDirDialog.Execute: Boolean;
120
-begin
121
-  Result:=POpenDirDialogEx(FDlg).Execute;
122
-end;
123
-
124
-{$endif read_implementation}
125
-

+ 0
- 240
libwin/kolfpc/KOLCE_IniFile.inc Parādīt failu

@@ -1,240 +0,0 @@
1
-{$ifdef read_interface}
2
-type
3
-  PIniFile = ^TIniFile;
4
-
5
-  { TIniFile }
6
-
7
-  TIniFile = object( TObj )
8
-  private
9
-    procedure SetMode(const AValue: TIniFileMode);
10
-  protected
11
-    fMode: TIniFileMode;
12
-    fFileName: KOLString;
13
-    fSection: KOLString;
14
-    fData: PStrList;
15
-  protected
16
-    function FindSection(var First, Last: Integer): Boolean;
17
-    function FindKey(Key: String; First, Last: Integer; var Value: String): Integer;
18
-  public
19
-    destructor Destroy; virtual;
20
-    property Mode: TIniFileMode read fMode write SetMode;
21
-    property FileName: KOLString read fFileName;
22
-    property Section: KOLString read fSection write fSection;
23
-    function ValueInteger( const Key: KOLString; Value: Integer ): Integer;
24
-    function ValueString( const Key: KOLString; const Value: KOLString ): KOLString;
25
-    function ValueBoolean( const Key: KOLString; Value: Boolean ): Boolean;
26
-    function ValueData( const Key: KOLString; Value: Pointer; Count: Integer ): Boolean;
27
-    procedure ClearAll;
28
-    procedure ClearSection;
29
-    procedure ClearKey( const Key: KOLString );
30
-    procedure GetSectionNames(Names: {$IFNDEF UNICODE_CTRLS}PStrList{$ELSE}PWStrList{$ENDIF});
31
-    procedure SectionData(Names: {$IFNDEF UNICODE_CTRLS}PStrList{$ELSE}PWStrList{$ENDIF});
32
-    procedure UpdateFile;
33
-  end;
34
-{$endif read_interface}
35
-
36
-{$ifdef read_implementation}
37
-function OpenIniFile( const FileName: KOLString ): PIniFile;
38
-begin
39
-  New(Result, Create);
40
-  Result.fFileName := FileName;
41
-  Result.fData:= NewStrList;
42
-  Result.fMode:= ifmRead;
43
-  Result.fData.LoadFromFile(FileName);
44
-end;
45
-
46
-function GetSection(var S: String): Boolean;
47
-var L: Integer;
48
-begin
49
-  S:= Trim(S);
50
-  L:= Length(S);
51
-  Result:= (L > 2) and (S[1] = '[') and (S[L] = ']');
52
-  if Result then begin
53
-    Delete(S, L, 1); Delete(S, 1, 1);
54
-    S:= Trim(S);
55
-//      Result:= (S <> '');
56
-  end;
57
-end;
58
-
59
-procedure TIniFile.ClearAll;
60
-begin
61
-  fData.Clear;
62
-  fData.SaveToFile(fFileName);
63
-end;
64
-
65
-procedure TIniFile.ClearKey(const Key: KOLString);
66
-var k, F, L: Integer;
67
-    S: String;
68
-begin
69
-  if FindSection(F, L) then begin
70
-    k:= FindKey(Key, F, L, S);
71
-    if k >= 0 then fData.Delete(k);
72
-    fData.SaveToFile(fFileName);
73
-  end;
74
-end;
75
-
76
-procedure TIniFile.ClearSection;
77
-var i, F, L: Integer;
78
-begin
79
-  if FindSection(F, L) then begin
80
-    for i := L downto F do begin
81
-      fData.Delete(i);
82
-    end;
83
-    fData.SaveToFile(fFileName);
84
-  end;
85
-end;
86
-
87
-destructor TIniFile.Destroy;
88
-begin
89
-  if fMode = ifmWrite then fData.SaveToFile(fFileName);
90
-  fData.Free;
91
-  fFileName := '';
92
-  fSection := '';
93
-  inherited;
94
-end;
95
-
96
-procedure TIniFile.GetSectionNames(Names: {$IFNDEF UNICODE_CTRLS}PStrList{$ELSE}PWStrList{$ENDIF});
97
-var i: Integer;
98
-    S: String;
99
-begin
100
-  for i:= 0 to fData.Count-1 do begin
101
-    S:= fData.Items[i];
102
-    if GetSection(S) then Names.Add(S)
103
-  end;
104
-end;
105
-
106
-procedure TIniFile.SectionData(Names: {$IFNDEF UNICODE_CTRLS}PStrList{$ELSE}PWStrList{$ENDIF});
107
-var i, F, L: Integer;
108
-    S: String;
109
-begin
110
-  if fMode = ifmRead then begin
111
-    if FindSection(F, L) then
112
-      for i := F+1 to L do begin
113
-        S:= Trim(fData.Items[i]);
114
-        if S <> '' then Names.Add(S);
115
-      end;
116
-  end
117
-  else begin
118
-    ClearSection;
119
-    fData.Add('[' + fSection + ']');
120
-    for i:= 0 to Names.Count-1 do begin
121
-      S:= Trim(Names.Items[i]);
122
-      if S <> '' then fData.Add(S);
123
-    end;
124
-  end;
125
-end;
126
-
127
-procedure TIniFile.UpdateFile;
128
-begin
129
-    if fMode = ifmRead then fData.LoadFromFile(fFileName)
130
-    else fData.SaveToFile(fFileName);
131
-end;
132
-
133
-function TIniFile.ValueBoolean(const Key: KOLString; Value: Boolean): Boolean;
134
-begin
135
-  Result:= ValueInteger(Key, Ord(Value)) <> 0;
136
-end;
137
-
138
-function TIniFile.ValueData(const Key: KOLString; Value: Pointer; Count: Integer): Boolean;
139
-var i: Integer;
140
-    S: String;
141
-begin
142
-  if fMode = ifmRead then begin
143
-    S:= ValueString(Key, '');
144
-    for i:= 0 to Min(Length(S) div 2, Count) - 1 do begin
145
-      PByte(Value)^:= Hex2Int(Copy(S, 1+i*2, 2));
146
-      cardinal(Value):= cardinal(Value) + 1;
147
-      Result:= True;
148
-    end;
149
-  end
150
-  else begin
151
-    S:= '';
152
-    for i:= 0 to Count - 1 do begin
153
-      S:= S + Int2Hex(PByte(Value)^, 2);
154
-      cardinal(Value):= cardinal(Value) + 1;
155
-      Result:= True;
156
-    end;
157
-    ValueString(Key, S);
158
-  end;
159
-end;
160
-
161
-function TIniFile.ValueInteger(const Key: KOLString; Value: Integer): Integer;
162
-begin
163
-  Result:= Str2Int(ValueString(Key, Int2Str(Value)));
164
-end;
165
-
166
-function TIniFile.ValueString( const Key: KOLString; const Value: KOLString ): KOLString;
167
-var k, F, L: Integer;
168
-    S: String;
169
-    fSect: Boolean;
170
-begin
171
-  fSect:= FindSection(F, L);
172
-  if fSect then k:= FindKey(Key, F, L, S) else k:= -1;
173
-  if fMode = ifmRead then begin
174
-    if fSect and (k > 0) then Result:= S else Result := Value;
175
-  end
176
-  else begin
177
-    if not fSect then begin
178
-      fData.Add('[' + fSection + ']');
179
-      fData.Add(''); k:= fData.Count-1;
180
-    end;
181
-    if k < 0 then begin k:= L+1; fData.Insert(k, ''); end;
182
-    fData.Items[k]:= Key+'='+Value;
183
-  end;
184
-end;
185
-
186
-procedure TIniFile.SetMode(const AValue: TIniFileMode);
187
-begin
188
-    if fMode = AValue then Exit;
189
-    if fMode = ifmWrite then fData.SaveToFile(fFileName)
190
-    else fData.LoadFromFile(fFileName);
191
-    fMode:= AValue;
192
-end;
193
-
194
-function TIniFile.FindSection(var First, Last: Integer): Boolean;
195
-var i: Integer;
196
-    Sec, S: String;
197
-begin
198
-  Result:= False;
199
-  Sec := Trim(fSection);
200
-  for i:= 0 to fData.Count-1 do begin
201
-    S:= fData.Items[i];
202
-    if GetSection(S) and (AnsiCompareStrNoCase(S, Sec) = 0) then begin
203
-      First:= i; Result:= True; Break;
204
-    end;
205
-  end;
206
-  if Result then begin
207
-    for i:= First+1 to fData.Count-1 do begin
208
-      S:= fData.Items[i];
209
-      if GetSection(S) then begin
210
-        Last:= i-1; Exit;
211
-      end;
212
-    end;
213
-    Last:= fData.Count-1;
214
-  end;
215
-end;
216
-
217
-function TIniFile.FindKey(Key: String; First, Last: Integer; var Value: String): Integer;
218
-var i, k: Integer;
219
-    S: String;
220
-begin
221
-  Result:= -1;
222
-  Key:= Trim(Key);
223
-  for i:= First to Last do begin
224
-    S:= fData.Items[i];
225
-    k:= Pos('=', S);
226
-    if k > 0 then begin
227
-      if AnsiCompareStrNoCase(Key, Trim(Copy(S, 1, k-1))) = 0 then Result:= i;
228
-      if Result >= 0 then begin
229
-        Delete(S, 1, k);
230
-        Value:= Trim(S);
231
-        k:= Length(Value);
232
-        if (k > 0) and (Value[1] = '"') and (Value[k] = '"') then begin
233
-          Delete(Value, k, 1); Delete(Value, 1, 1);
234
-        end;
235
-        Exit;
236
-      end;
237
-    end;
238
-  end;
239
-end;
240
-{$endif read_implementation}

+ 0
- 146
libwin/kolfpc/KOLDEF.INC Parādīt failu

@@ -1,146 +0,0 @@
1
-{$IFDEF VER90}
2
-              {$DEFINE _D2}
3
-              {$DEFINE _D2orD3}
4
-              {$DEFINE _D2orD3orD4}
5
-{$ENDIF}
6
-
7
-{$IFDEF VER100}
8
-              {$DEFINE _D3}
9
-              {$DEFINE _D3orHigher}
10
-              {$DEFINE _D2orD3}
11
-              {$DEFINE _D2orD3orD4}
12
-              {$DEFINE _D3orD4}
13
-{$ENDIF}
14
-
15
-{$IFDEF VER120}
16
-              {$DEFINE _D3orHigher}
17
-              {$DEFINE _D3orD4}
18
-              {$DEFINE _D4}
19
-              {$DEFINE _D4orHigher}
20
-              {$DEFINE _D2orD3orD4}
21
-{$ENDIF}
22
-
23
-{$IFDEF VER130}
24
-              {$DEFINE _D3orHigher}
25
-              {$DEFINE _D4orHigher}
26
-              {$DEFINE _D5}
27
-              {$DEFINE _D5orHigher}
28
-{$ENDIF}
29
-
30
-{$IFDEF VER140}
31
-              {$DEFINE _D3orHigher}
32
-              {$DEFINE _D4orHigher}
33
-              {$DEFINE _D5orHigher}
34
-              {$DEFINE _D6}
35
-              {$DEFINE _D6orHigher}
36
-{$ENDIF}
37
-
38
-{$IFDEF VER150}
39
-              {$DEFINE _D3orHigher}
40
-              {$DEFINE _D4orHigher}
41
-              {$DEFINE _D5orHigher}
42
-              {$DEFINE _D6orHigher}
43
-              {$DEFINE _D7}
44
-              {$DEFINE _D7orHigher}
45
-{$WARN UNIT_DEPRECATED OFF}
46
-{$WARN SYMBOL_PLATFORM OFF}
47
-{$WARN UNSAFE_TYPE OFF}
48
-{$WARN UNSAFE_CAST OFF}
49
-{$WARN UNSAFE_CODE OFF}
50
-{$ENDIF}
51
-
52
-{$IFDEF VER160} // Delphi 8
53
-Delphi version 8 not supported! (delphi 8 is .net only)
54
-{$ENDIF}
55
-
56
-{$IFDEF VER170} // Delphi 2005
57
-             {$DEFINE _D3orHigher}
58
-             {$DEFINE _D4orHigher}
59
-             {$DEFINE _D5orHigher}
60
-             {$DEFINE _D6orHigher}
61
-             {$DEFINE _D7}
62
-             {$DEFINE _D7orHigher}
63
-             {$DEFINE _D2005orHigher}
64
-{$WARN UNIT_DEPRECATED OFF}
65
-{$WARN SYMBOL_PLATFORM OFF}
66
-{$WARN UNSAFE_TYPE OFF}
67
-{$WARN UNSAFE_CAST OFF}
68
-{$WARN UNSAFE_CODE OFF}
69
-{$ENDIF}
70
-
71
-{$IFDEF VER180} // Delphi 2006
72
-             {$DEFINE _D3orHigher}
73
-             {$DEFINE _D4orHigher}
74
-             {$DEFINE _D5orHigher}
75
-             {$DEFINE _D6orHigher}
76
-             {$DEFINE _D7}
77
-             {$DEFINE _D7orHigher}
78
-             {$DEFINE _D2005orHigher}
79
-             {$DEFINE _D2006orHigher}
80
-{$WARN UNIT_DEPRECATED OFF}
81
-{$WARN SYMBOL_PLATFORM OFF}
82
-{$WARN UNSAFE_TYPE OFF}
83
-{$WARN UNSAFE_CAST OFF}
84
-{$WARN UNSAFE_CODE OFF}
85
-{$ENDIF}
86
-
87
-{$IFDEF _D2005orHigher}
88
-
89
-  // by Thaddy de Koning:
90
-  {$IFDEF VER185} // Delphi 2007 ( and Highlander )
91
-               {$DEFINE _D3orHigher}
92
-               {$DEFINE _D4orHigher}
93
-               {$DEFINE _D5orHigher}
94
-               {$DEFINE _D6orHigher}
95
-               {$DEFINE _D7}
96
-               {$DEFINE _D7orHigher}
97
-               {$DEFINE _D2005orHigher}
98
-               {$DEFINE _D2006orHigher}
99
-               {$DEFINE _D2007orHigher}
100
-  {$WARN UNIT_DEPRECATED OFF}
101
-  {$WARN SYMBOL_PLATFORM OFF}
102
-  {$WARN UNSAFE_TYPE OFF}
103
-  {$WARN UNSAFE_CAST OFF}
104
-  {$WARN UNSAFE_CODE OFF}
105
-  {$ENDIF}
106
-
107
-{$INLINE OFF}
108
-{$ENDIF}
109
-
110
-{$IFDEF FPC}
111
-{------------------------------------
112
-by Thaddy de Koning:
113
-
114
-FPC version 2.1.1 is very compatible with Delphi and kol now.
115
-You can simply use the $(DELPHI)\source\rtl\win\*.pas files from Delphi 4/5 instead of the prepared files that were needed for 
116
-FPC1.X
117
- 
118
-That is all to have full compatibility.
119
-------------------------------------}
120
-  {$DEFINE PAS_VERSION}
121
-    {$IFDEF VER2}
122
-     {$DEFINE _D3orHigher}
123
-     {$DEFINE _D4orHigher}
124
-     {$DEFINE _D5orHigher}
125
-     {$DEFINE _D6orHigher}
126
-     {$DEFINE _D7}
127
-     {$DEFINE _D7orHigher}
128
-    {$ENDIF VER2}
129
-  {$IFDEF WINCE}
130
-    {$DEFINE USE_PROP}
131
-    {$DEFINE UNICODE_CTRLS}
132
-    {$DEFINE NOT_USE_RICHEDIT}
133
-  {$ENDIF WINCE}
134
-  {$ELSE FPC}
135
-    {$DEFINE cpu86}
136
-{$ENDIF FPC}
137
-
138
-{$IFNDEF _NOT_KOLCtrlWrapper_}
139
- {$DEFINE _KOLCtrlWrapper_}
140
-{$ENDIF}
141
-
142
-{$IFNDEF _NOT_KOLCtrlWrapper_}
143
-  {$DEFINE _KOLCtrlWrapper_}
144
-{$ENDIF}
145
-
146
-

+ 0
- 1354
libwin/kolfpc/KOLDirDlgEx.pas
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 909
libwin/kolfpc/KOLMHToolTip.pas Parādīt failu

@@ -1,909 +0,0 @@
1
-//{$DEFINE DEBUG}
2
-{$IFDEF DEBUG}
3
-{$DEFINE interface}
4
-{$DEFINE implementation}
5
-{$DEFINE initialization}
6
-{$DEFINE finalization}
7
-{$ENDIF}
8
-
9
-{$IFDEF Frame}
10
-unit KOLMHToolTip;
11
-
12
-interface
13
-
14
-uses Windows, KOL, Messages;
15
-
16
-type
17
-{$ENDIF Frame}
18
-{$IFDEF interface}
19
-
20
-  TFE = (eTextColor, eBkColor, eAPDelay, eRDelay, eIDelay);
21
-
22
-  TFI = record
23
-    FE: set of TFE;
24
-    Colors: array[0..1] of TColor;
25
-    Delays: array[0..3] of Integer;
26
-  end;
27
-
28
-  PMHToolTipManager = ^TMHToolTipManager;
29
-  TKOLMHToolTipManager = PMHToolTipManager;
30
-
31
-  PMHToolTip = ^TMHToolTip;
32
-  TKOLMHToolTip = PMHToolTip;
33
-
34
-{$ENDIF interface}
35
-
36
-{$IFDEF pre_interface}
37
-  PMHHint = ^TMHHint;
38
-  TKOLMHHint = PMHHint;
39
-{$ENDIF pre_interface}
40
-
41
-{$IFDEF interface}
42
-
43
-  TMHToolTipManager = object(TObj)
44
-  protected
45
-    destructor Destroy; virtual;
46
-  public
47
-    TTT: array of PMHToolTip;
48
-    function AddTip: Integer;
49
-    function FindNeed(FI: TFI): PMHToolTip;
50
-    function CreateNeed(FI: TFI): PMHToolTip;
51
-  end;
52
-
53
-  TMHHint = object(TObj)
54
-  private
55
-    function GetManager:PMHToolTipManager;
56
-    // Spec
57
-    procedure ProcBegin(var TI: TToolInfo);
58
-    procedure ProcEnd(var TI: TToolInfo);
59
-    procedure ReConnect(FI: TFI);
60
-    procedure MoveTool(T1: PMHToolTip);
61
-    procedure CreateToolTip;
62
-    function GetFI: TFI;
63
-
64
-    // Group
65
-    function GetDelay(const Index: Integer): Integer;
66
-    procedure SetDelay(const Index: Integer; const Value: Integer);
67
-    function GetColor(const Index: Integer): TColor;
68
-    procedure SetColor(const Index: Integer; const Value: TColor);
69
-
70
-    // Local
71
-    procedure SetText(Value: KOLString);
72
-    function GetText: KOLString;
73
-  public
74
-    ToolTip: PMHToolTip;
75
-    HasTool: Boolean;
76
-    Parent: PControl;
77
-    destructor Destroy; virtual;
78
-    procedure Pop;
79
-    procedure Popup;
80
-
81
-    property AutoPopDelay: Integer index 2 read GetDelay write SetDelay;
82
-    property InitialDelay: Integer index 3 read GetDelay write SetDelay;
83
-    property ReshowDelay: Integer index 1 read GetDelay write SetDelay;
84
-
85
-    property TextColor: TColor index 1 read GetColor write SetColor;
86
-    property BkColor: TColor index 0 read GetColor write SetColor;
87
-    property Text: KOLString read GetText write SetText;
88
-  end;
89
-
90
-  TMHToolTip = object(TObj)
91
-
92
-  private
93
-    fHandle: THandle;
94
-    Count: Integer;
95
-
96
-    function GetDelay(const Index: Integer): Integer;
97
-    procedure SetDelay(const Index: Integer; const Value: Integer);
98
-    function GetColor(const Index: Integer): TColor;
99
-    procedure SetColor(const Index: Integer; const Value: TColor);
100
-    function GetMaxWidth: Integer;
101
-    procedure SetMaxWidth(const Value: Integer);
102
-    function GetMargin: TRect;
103
-    procedure SetMargin(const Value: TRect);
104
-    function GetActivate: Boolean;
105
-    procedure SetActivate(const Value: Boolean);
106
-//    function GetText: string;
107
-//    procedure SetText(const Value: string);
108
-//    function GetToolCount: Integer;
109
-//    function GetTool(Index: Integer): TToolInfo;
110
-
111
-
112
-
113
-  protected
114
-
115
-  public
116
-    destructor Destroy; virtual;
117
-    procedure Pop;
118
-    procedure Popup;
119
-    procedure Update;
120
-
121
-//    function GetInfo: TToolInfo; // Hide in Info
122
-//    procedure SetInfo(Value: TToolInfo);
123
-
124
-//  handle:Thandle;
125
-//    procedure SetC(C: PControl);
126
-//    procedure SetI(C: PControl; S: string);
127
-//    procedure Add(Value: TToolInfo);
128
-//    procedure Delete(Value: TToolInfo);
129
-//    function Connect(Value: PControl): Integer;
130
-
131
-
132
-//    property OnCloseUp: TOnEvent read GetOnDropDown write SetOnDropDown;
133
-
134
-
135
-
136
-    property AutoPopDelay: Integer index 2 read GetDelay write SetDelay;
137
-    property InitialDelay: Integer index 3 read GetDelay write SetDelay;
138
-    property ReshowDelay: Integer index 1 read GetDelay write SetDelay;
139
-
140
-    property TextColor: TColor index 1 read GetColor write SetColor;
141
-    property BkColor: TColor index 0 read GetColor write SetColor;
142
-
143
-    property MaxWidth: Integer read GetMaxWidth write SetMaxWidth;
144
-
145
-    property Margin: TRect read GetMargin write SetMargin;
146
-    property Activate: Boolean read GetActivate write SetActivate;
147
-    property Handle: THandle read fHandle;
148
-//    property Text: string read GetText write SetText;
149
-//    property ToolCount: Integer read GetToolCount;
150
-//    property Tools[Index: Integer]: TToolInfo read GetTool;
151
-
152
-  end;
153
-
154
-const
155
-  Dummy = 0;
156
-
157
-
158
-function NewHint(A: PControl): PMHHint;
159
-function NewManager: PMHToolTipManager;
160
-function NewMHToolTip(AParent: PControl): PMHToolTip;
161
-
162
-var
163
-  Manager: PMHToolTipManager;
164
-
165
-{$ENDIF interface}
166
-
167
-{$IFDEF Frame}
168
-
169
-implementation
170
-
171
-{$ENDIF Frame}
172
-
173
-{$IFDEF implementation}
174
-
175
-const
176
-  Dummy1 = 1;
177
-
178
-  TTDT_AUTOMATIC = 0;
179
-  TTDT_RESHOW = 1;
180
-  TTDT_AUTOPOP = 2;
181
-  TTDT_INITIAL = 3;
182
-
183
-//function WndProcMHDateTimePicker(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
184
-{begin
185
-  Result := False;}
186
-//end;
187
-
188
-
189
-
190
-function NewMHToolTip(AParent: PControl): PMHToolTip;
191
-//var
192
-//  Data: PDateTimePickerData;
193
-//  T: TWndClassEx;
194
-//  a: integer;
195
-const
196
-  CS_DROPSHADOW = $00020000;
197
-begin
198
-  DoInitCommonControls(ICC_BAR_CLASSES);
199
-  New(Result, Create);
200
-
201
-  Result.fHandle := CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, '', 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, AParent.GetWindowHandle, 0, HInstance, nil);
202
-//  SetClassLong(Result.handle,GCL_STYLE,CS_DROPSHADOW);
203
-
204
-//  Result := PMHToolTip(_NewControl(AParent, TOOLTIPS_CLASS, 0, False, 0)); //PMHToolTip(_NewCommonControl(AParent,TOOLTIPS_CLASS, 0{TTS_ALWAYSTIP}{WS_CHILD or WS_VISIBLE},False,0));
205
-//  Result.Style:=0;
206
-//  Result.ExStyle:=0;
207
-//  GetMem(Data,Sizeof(Data^));
208
-//  FillChar(Data^,Sizeof(Data^),0);
209
-//  a:=SetClassLong(Result.Handle,GCL_STYLE,CS_DROPSHADOW);
210
-//  ShowMessage(Int2Str(a));
211
-//  Result.CustomData:=Data;
212
-
213
-{  T.cbSize:=SizeOf(T);
214
-  GetClassInfoEx(hInstance,TOOLTIPS_CLASS,T);
215
-  T.style:=T.style or CS_DROPSHADOW;
216
-  T.hInstance:=hInstance;
217
-  T.lpszClassName:='ZharovHint';
218
-  a:=RegisterClassEx(T);
219
-  ShowMessage(Int2Str(a)); }
220
-//  Result.handle := CreateWindowEx(0, {'ZharovHint'} TOOLTIPS_CLASS, '', 0 {orCS_DROPSHADOW or WS_POPUP or WS_BORDER or CS_SAVEBITS or WS_CHILD or WS_CLIPSIBLINGS}, CW_USEDEFAULT, CW_USEDEFAULT,
221
-//    CW_USEDEFAULT, CW_USEDEFAULT, AParent.Handle, 0, HInstance, nil);
222
-//  Data.ttt:=CreateWindowEx (CS_IMEWS_EX_TOOLWINDOW or WS_EX_CONTROLPARENT{ or CS_SAVEBITS or WS_POPUP or WS_BORDER}{65536},{'ZharovHint'}TOOLTIPS_CLASS,'',{WS_CHILD or}{ WS_VISIBLE}{100663296}{WS_EX_TOOLWINDOW}CS_DROPSHADOW or WS_POPUP or WS_BORDER or CS_SAVEBITS or WS_CHILD or WS_CLIPSIBLINGS,CW_USEDEFAULT,CW_USEDEFAULT,
223
-//                              CW_USEDEFAULT,CW_USEDEFAULT,AParent.Handle,0,HInstance,NIL);
224
-//  SetClassLong(Data.ttt,GCL_STYLE,CS_DROPSHADOW);
225
-//  SendMessage (Data.ttt,TTM_SETDELAYTIME,TTDT_INITIAL,5);
226
-//  SendMessage (Data.ttt,TTM_SETDELAYTIME,TTDT_RESHOW,20);
227
-//  SendMessage (Result.handle,TTM_SETDELAYTIME,TTDT_AUTOPOP,2000);
228
-//  Result.CreateWindow;
229
-//  Result.Parent := AParent;
230
-//  Result.Perform(TTM_SETTIPTEXTCOLOR,clRed,0);
231
-//  SendMessage (Result.handle,TTM_SETTIPTEXTCOLOR,clBlue,0);
232
-//  SendMessage (Result.handle,TTM_SETTIPTEXTCOLOR,clRed,0);
233
-//  Result.Color:=clRed;
234
-//  Result.Font.Color:=clRed;
235
-//  Data.FCalColors:=NewMonthCalColors(Result);
236
-//  Data.FOnDropDown:=nil;
237
-//    Result.AttachProc(WndProcMHDateTimePicker);
238
-//  Result.AttachProc(WndProcMHDateTimePicker);
239
-end;
240
-
241
-{procedure TMHToolTip.SetC(C: PControl);
242
-var
243
-  TI: TToolInfo;
244
-  R: Trect;
245
-//  Data:PDateTimePickerData;
246
-begin
247
-  R := C.ClientRect;
248
- // Control:= C.Handle;
249
-  with TI do
250
-  begin
251
-    cbSize := SizeOf(TI);
252
-    uFlags := TTF_SUBCLASS; // or TTF_IDISHWND;
253
-    hWnd := C.GetWindowHandle; //Control;
254
-    uId := 0;
255
-    rect.Left := R.Left;
256
-    rect.Top := R.Top;
257
-    rect.Right := R.Right;
258
-    rect.Bottom := R.Bottom;
259
-    hInst := 0;
260
-    lpszText := Pchar('I am ' + C.Caption);
261
-  end;
262
-  PostMessage(handle, TTM_ADDTOOL, 0, DWORD(@TI));
263
-//  Perform(TTM_ADDTOOL, 0, DWord(@TI));
264
-end;      }
265
-
266
-function TMHToolTip.GetDelay(const Index: Integer): Integer;
267
-begin
268
-  Result := SendMessage(fHandle, TTM_GETDELAYTIME, Index, 0);
269
-end;
270
-
271
-
272
-procedure TMHToolTip.SetDelay(const Index, Value: Integer);
273
-begin
274
-  SendMessage(handle, TTM_SETDELAYTIME, Index, MAKELONG(Value, 0));
275
-end;
276
-
277
-
278
-function TMHToolTip.GetColor(const Index: Integer): TColor;
279
-begin
280
-  Result := SendMessage(handle, TTM_GETTIPBKCOLOR + Index, 0, 0);
281
-end;
282
-
283
-procedure TMHToolTip.SetColor(const Index: Integer; const Value: TColor);
284
-begin
285
-  SendMessage(handle, TTM_SETTIPBKCOLOR + Index, Value, 0);
286
-end;
287
-
288
-function TMHToolTip.GetMaxWidth: Integer;
289
-begin
290
-  Result := SendMessage(fHandle, TTM_GETMAXTIPWIDTH, 0, 0);
291
-end;
292
-
293
-procedure TMHToolTip.SetMaxWidth(const Value: Integer);
294
-begin
295
-  SendMessage(fHandle, TTM_SETMAXTIPWIDTH, 0, Value);
296
-end;
297
-
298
-{procedure TMHToolTip.SetI(C: PControl; S: string);
299
-var
300
-  TI: TToolInfo;
301
-  R: Trect;
302
-//  Data:PDateTimePickerData;
303
-begin
304
-  R := C.ClientRect;
305
- // Control:= C.Handle;
306
-  with TI do
307
-  begin
308
-    cbSize := SizeOf(TI);
309
-    uFlags := TTF_SUBCLASS;
310
-    hWnd := C.GetWindowHandle; //Control;
311
-    uId := 0;
312
-    rect.Left := R.Left;
313
-    rect.Top := R.Top;
314
-    rect.Right := R.Right;
315
-    rect.Bottom := R.Bottom;
316
-    hInst := 0;
317
-    lpszText := PChar(S);
318
-  end;
319
-//   PostMessage (handle,TTM_ADDTOOL,0,DWORD (@TI));
320
-//  Perform(TTM_SETTOOLINFO, 0, DWord(@TI));
321
-end;    }
322
-
323
-function TMHToolTip.GetMargin: TRect;
324
-begin
325
-  SendMessage(fHandle, TTM_GETMARGIN, 0, DWord(@Result));
326
-end;
327
-
328
-procedure TMHToolTip.SetMargin(const Value: TRect);
329
-begin
330
-  SendMessage(fHandle, TTM_SETMARGIN, 0, DWord(@Value));
331
-end;
332
-
333
-function TMHToolTip.GetActivate: Boolean;
334
-begin
335
-  // ??????
336
-  Result := False;
337
-end;
338
-
339
-procedure TMHToolTip.SetActivate(const Value: Boolean);
340
-begin
341
-  SendMessage(fHandle, TTM_ACTIVATE, DWord(Value), 0);
342
-end;
343
-
344
-procedure TMHToolTip.Pop;
345
-begin
346
-  SendMessage(fHandle, TTM_POP, 0, 0);
347
-end;
348
-
349
-procedure TMHToolTip.Popup;
350
-begin
351
-  SendMessage(fHandle, $0422 {TTM_POPUP}, 0, 0);
352
-end;
353
-
354
-{function TMHToolTip.GetText: string;
355
-begin
356
-
357
-end;
358
-
359
-procedure TMHToolTip.SetText(const Value: string);
360
-var
361
-  TI: TToolInfo;
362
-begin
363
-  TI := GetInfo;
364
-  TI.lpszText := PChar(Value);
365
-  SetInfo(TI);
366
-end;       }
367
-
368
-{function TMHToolTip.GetInfo: TToolInfo;
369
-begin
370
-  with Result do
371
-  begin
372
-    // ????
373
-    FillChar(Result, SizeOf(Result), 0);
374
-    cbSize := SizeOf(Result);
375
-//    hWnd := Parent.GetWindowHandle;
376
-    uId := 0;
377
-  end;
378
-//  Perform(TTM_GETTOOLINFO, 0, DWord(@Result));
379
-end;
380
-
381
-procedure TMHToolTip.SetInfo(Value: TToolInfo);
382
-begin
383
-//  Perform(TTM_SETTOOLINFO, 0, DWord(@Value));
384
-end;}
385
-
386
-{function TMHToolTip.GetToolCount: Integer;
387
-begin
388
-//  Result := Perform(TTM_GETTOOLCOUNT, 0, 0);
389
-end;
390
-
391
-function TMHToolTip.GetTool(Index: Integer): TToolInfo;
392
-begin
393
-  FillChar(Result, SizeOf(Result), 0); // ????
394
-  Result.cbSize := SizeOf(Result);
395
-//  Perform(TTM_ENUMTOOLS, Index, DWord(@Result));
396
-end;     }
397
-
398
-{procedure TMHToolTip.Add(Value: TToolInfo);
399
-begin
400
-//  Perform(TTM_ADDTOOL, 0, DWord(@Value));
401
-end;}
402
-
403
-{procedure TMHToolTip.Delete(Value: TToolInfo);
404
-begin
405
-//  Perform(TTM_DELTOOL, 0, DWord(@Value));
406
-end;}
407
-
408
-procedure TMHToolTip.Update;
409
-begin
410
-  inherited; // ???
411
-  SendMessage(fHandle, TTM_UPDATE, 0, 0);
412
-end;
413
-
414
-function NewHint(A: PControl): PMHHint;
415
-begin
416
-  New(Result, Create);
417
-
418
-  with Result^ do
419
-  begin
420
-    Parent := A;
421
-    ToolTip := nil; // ???
422
-    HasTool := False; // ???
423
-  end;
424
-  A.Add2AutoFree(Result);
425
-end;
426
-
427
-function NewManager: PMHToolTipManager;
428
-begin
429
-  New(Result, Create);
430
-end;
431
-
432
-{ TMHHint }
433
-
434
-function TMHHint.GetDelay(const Index: Integer): Integer;
435
-begin
436
-//  CreateToolTip;
437
-  Result := 0;
438
-  if Assigned(ToolTip) then
439
-    Result := ToolTip.GetDelay(Index);
440
-end;
441
-
442
-function TMHHint.GetFI: TFI;
443
-begin
444
-  /// !!! DANGER-WITH !!!
445
-  with Result, ToolTip^ do
446
-  begin
447
-    FE := FE + [eTextColor];
448
-    Colors[1] := TextColor;
449
-
450
-    FE := FE + [eBkColor];
451
-    Colors[0] := BkColor;
452
-
453
-    FE := FE + [eAPDelay];
454
-    Delays[TTDT_AUTOPOP] := AutoPopDelay;
455
-
456
-    FE := FE + [eRDelay];
457
-    Delays[TTDT_RESHOW] := ReshowDelay;
458
-
459
-    FE := FE + [eIDelay];
460
-    Delays[TTDT_INITIAL] := InitialDelay;
461
-  end;
462
-end;
463
-
464
-procedure TMHHint.ReConnect(FI: TFI);
465
-var
466
-  TMP: PMHToolTip;
467
-begin
468
-  with GetManager^ do
469
-  begin
470
-    TMP := FindNeed(FI);
471
-    if not Assigned(TMP) then
472
-      TMP := CreateNeed(FI);
473
-    if Assigned(ToolTip) and HasTool then
474
-      MoveTool(TMP);
475
-    ToolTip := TMP;
476
-  end;
477
-end;
478
-
479
-procedure TMHHint.MoveTool(T1: PMHToolTip);
480
-var
481
-  TI: TToolInfo;
482
-  TextL: array[0..255] of KOLChar;
483
-begin
484
-  if T1 = ToolTip then
485
-    Exit;
486
-  with TI do
487
-  begin
488
-    cbSize := SizeOf(TI);
489
-    hWnd := Parent.GetWindowHandle;
490
-    uId := Parent.GetWindowHandle;
491
-    lpszText := @TextL[0];
492
-  end;
493
-
494
-  SendMessage(ToolTip.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
495
-  SendMessage(ToolTip.handle, TTM_DELTOOL, 0, DWORD(@TI));
496
-  ToolTip.Count := ToolTip.Count - 1;
497
-  SendMessage(T1.handle, TTM_ADDTOOL, 0, DWORD(@TI));
498
-  T1.Count := T1.Count - 1;
499
-
500
-  HasTool := True;
501
-
502
-end;
503
-
504
-procedure TMHHint.SetColor(const Index: Integer; const Value: TColor);
505
-var
506
-  FI: TFI;
507
-begin
508
-  if Assigned(ToolTip) then
509
-  begin
510
-    if ToolTip.Count + Byte(not HasTool) = 1 then
511
-    begin
512
-      ToolTip.SetColor(Index, Value);
513
-      Exit;
514
-    end;
515
-    FI := GetFI;
516
-  end;
517
-
518
-  case Index of
519
-    0: FI.FE := FI.FE + [eBkColor];
520
-    1: FI.FE := FI.FE + [eTextColor];
521
-  end;
522
-  FI.Colors[Index] := Value;
523
-
524
-  ReConnect(FI);
525
-end;
526
-
527
-function TMHHint.GetColor(const Index: Integer): TColor;
528
-begin
529
-  Result := 0;
530
-  if Assigned(ToolTip) then
531
-    Result := ToolTip.GetColor(Index);
532
-end;
533
-
534
-procedure TMHHint.SetDelay(const Index, Value: Integer);
535
-var
536
-  FI: TFI;
537
-begin
538
-  if Assigned(ToolTip) then
539
-  begin
540
-    if ToolTip.Count + Byte(not HasTool) = 1 then
541
-    begin
542
-      ToolTip.SetDelay(Index, Value);
543
-      Exit;
544
-    end;
545
-    FI := GetFI;
546
-  end;
547
-
548
-  case Index of
549
-    TTDT_AUTOPOP: FI.FE := FI.FE + [eAPDelay]; // Spec
550
-    TTDT_INITIAL: FI.FE := FI.FE + [eIDelay]; // Spec
551
-    TTDT_RESHOW: FI.FE := FI.FE + [eRDelay]; // Spec
552
-  end; //case
553
-
554
-  FI.Delays[Index] := Value; //Spec
555
-
556
-  ReConnect(FI);
557
-end;
558
-
559
-procedure TMHHint.SetText(Value: KOLString);
560
-var
561
-  TI: TToolInfo;
562
-begin
563
-  ProcBegin(TI);
564
-
565
-  with TI do
566
-  begin
567
-    uFlags := TTF_SUBCLASS or TTF_IDISHWND; // Spec
568
-    lpszText := PKOLChar(Value); // Spec
569
-  end;
570
-
571
-  procEnd(TI);
572
-
573
-  if HasTool then
574
-  begin
575
-    TI.lpszText := PKOLChar(Value);
576
-    SendMessage(ToolTip.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
577
-  end;
578
-end;
579
-
580
-(*
581
-procedure TMHHint.SetText(Value: string);
582
-var
583
-  TI: TToolInfo;
584
-  R: Trect;
585
-  TextLine: array[0..255] of Char;
586
-begin
587
-  if not Assigned(ToolTip) then
588
-  begin
589
-    if Length(Manager.TTT) = 0 then
590
-      Manager.AddTip;
591
-    ToolTip := Manager.TTT[0];
592
-  end;
593
-
594
-  with TI do
595
-  begin
596
-    cbSize := SizeOf(TI);
597
-    hWnd := Parent.GetWindowHandle;
598
-    uId := Parent.GetWindowHandle;
599
-    hInst := 0;
600
-  end;
601
-
602
-  if not HasTool {TTool = -1} then
603
-  begin
604
-    R := Parent.ClientRect;
605
- // Control:= C.Handle;
606
-    with TI do
607
-    begin
608
-//      cbSize := SizeOf(TI);
609
-      uFlags := TTF_SUBCLASS;
610
-//      hWnd := Parent.GetWindowHandle; //Control;
611
-//      uId := Parent.GetWindowHandle;
612
-      rect.Left := R.Left;
613
-      rect.Top := R.Top;
614
-      rect.Right := R.Right;
615
-      rect.Bottom := R.Bottom;
616
-//      hInst := 0;
617
-      lpszText := PChar(Value);
618
-    end;
619
-    SendMessage({Manager.TTT[TTip]} ToolTip.handle, TTM_ADDTOOL, 0, DWORD(@TI));
620
-    HasTool := True;
621
-//    TTool := 0;
622
-    ToolTip {Manager.TTT[TTip]}.Count := ToolTip {Manager.TTT[TTip]}.Count + 1;
623
-
624
-  end
625
-  else
626
-  begin
627
-
628
-    with TI do
629
-    begin
630
-    // ????
631
-//      FillChar(TI, SizeOf(TI), 0);
632
-//      cbSize := SizeOf(TI);
633
-//      hWnd := Parent.GetWindowHandle;
634
-//      uId := Parent.GetWindowHandle;
635
-      lpszText := @TextLine; //PChar(S);
636
-    end;
637
-    SendMessage(ToolTip {Manager.TTT[TTip]}.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
638
-    TI.lpszText := PChar(Value);
639
-//  Perform(TTM_GETTOOLINFO, 0, DWord(@Result));
640
-    SendMessage(ToolTip {Manager.TTT[TTip]}.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
641
-  end;
642
-//  Manager.TTT[TTip].Tool[TTool].SSSetText(Value);
643
-end;
644
-*)
645
-
646
-{ TMHToolTipManager }
647
-
648
-{function TMHToolTipManager.AddColor(C: TColor): Integer;
649
-begin
650
-  SetLength(TTT, Length(TTT) + 1);
651
-  TTT[Length(TTT) - 1] := NewMHToolTip(Applet);
652
-  TTT[Length(TTT) - 1].SetColor(1, C);
653
-  Result := Length(TTT) - 1;
654
-end;         }
655
-
656
-function TMHToolTipManager.AddTip: Integer;
657
-begin
658
-  SetLength(TTT, Length(TTT) + 1);
659
-  TTT[Length(TTT) - 1] := NewMHToolTip(Applet);
660
-  Result := Length(TTT) - 1;
661
-end;
662
-
663
-{function TMHToolTip.Connect(Value: PControl): Integer;
664
-var
665
-  TI: TToolInfo;
666
-  R: Trect;
667
-//  Data:PDateTimePickerData;
668
-begin
669
-  R := Value.ClientRect;
670
- // Control:= C.Handle;
671
-  with TI do
672
-  begin
673
-    cbSize := SizeOf(TI);
674
-    uFlags := TTF_SUBCLASS;
675
-    hWnd := Value.GetWindowHandle; //Control;
676
-    uId := Value.GetWindowHandle;
677
-    rect.Left := R.Left;
678
-    rect.Top := R.Top;
679
-    rect.Right := R.Right;
680
-    rect.Bottom := R.Bottom;
681
-    hInst := 0;
682
-    lpszText := PChar('Super');
683
-  end;
684
-  PostMessage(handle, TTM_ADDTOOL, 0, DWORD(@TI));
685
-//  Perform(TTM_ADDTOOL, 0, DWord(@TI));
686
-end;}
687
-
688
-{function TMHToolTipManager.FindTip(N: Integer): Integer;
689
-begin
690
-  Result := -1;
691
-end;}
692
-
693
-function TMHToolTipManager.FindNeed(FI: TFI): PMHToolTip;
694
-var
695
-  i: Integer;
696
-begin
697
-  Result := nil;
698
-  for i := 0 to length(TTT) - 1 do
699
-  begin
700
-    if ((eTextColor in FI.FE) and (not (FI.Colors[1] = TTT[i].TextColor))) or
701
-      ((eBkColor in FI.FE) and (not (FI.Colors[0] = TTT[i].BkColor))) or
702
-      ((eAPDelay in FI.FE) and (not (FI.Delays[TTDT_AUTOPOP] = TTT[i].AutoPopDelay))) or
703
-      ((eIDelay in FI.FE) and (not (FI.Delays[TTDT_INITIAL] = TTT[i].InitialDelay))) or
704
-      ((eRDelay in FI.FE) and (not (FI.Delays[TTDT_RESHOW] = TTT[i].ReshowDelay))) then
705
-      Continue;
706
-    Result := TTT[i];
707
-    Break;
708
-  end;
709
-end;
710
-
711
-function TMHToolTipManager.CreateNeed(FI: TFI): PMHToolTip;
712
-
713
-begin
714
-  Setlength(TTT, length(TTT) + 1);
715
-  TTT[length(TTT) - 1] := NewMHToolTip(Applet);
716
-  with TTT[length(TTT) - 1]^ do
717
-  begin
718
-    if (eTextColor in FI.FE) then
719
-      TextColor := FI.Colors[1];
720
-    if (eBkColor in FI.FE) then
721
-      BkColor := FI.Colors[0];
722
-    if (eAPDelay in FI.FE) then
723
-      AutoPopDelay := FI.Delays[TTDT_AUTOPOP];
724
-    if (eIDelay in FI.FE) then
725
-      InitialDelay := FI.Delays[TTDT_INITIAL];
726
-    if (eRDelay in FI.FE) then
727
-      ReshowDelay := FI.Delays[TTDT_RESHOW];
728
-  end;
729
-  Result := TTT[length(TTT) - 1];
730
-end;
731
-
732
-procedure TMHHint.ProcBegin(var TI: TToolInfo);
733
-begin
734
-  CreateToolTip;
735
-
736
-  with TI do
737
-  begin
738
-    cbSize := SizeOf(TI);
739
-    hWnd := Parent.GetWindowHandle;
740
-    uId := Parent.GetWindowHandle;
741
-    hInst := 0;
742
-  end;
743
-end;
744
-
745
-procedure TMHHint.ProcEnd(var TI: TToolInfo);
746
-var
747
-  TextLine: array[0..255] of KOLChar;
748
-begin
749
-  if not HasTool then
750
-  begin
751
-    SendMessage(ToolTip.handle, TTM_ADDTOOL, 0, DWORD(@TI));
752
-    HasTool := True;
753
-    ToolTip.Count := ToolTip.Count + 1;
754
-  end
755
-  else
756
-  begin
757
-    with TI do
758
-    begin
759
-      lpszText := @TextLine[0];
760
-    end;
761
-    SendMessage(ToolTip.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
762
-  end;
763
-end;
764
-
765
-destructor TMHToolTipManager.Destroy;
766
-var
767
-  i: Integer;
768
-begin
769
-  for i := 0 to Length(TTT) - 1 do
770
-    TTT[i].Free;
771
-  SetLength(TTT, 0);
772
-  inherited;
773
-end;
774
-
775
-procedure TMHHint.Pop;
776
-begin
777
-  if Assigned(ToolTip) and (HasTool) then
778
-  begin // ^^^^^^^^^^^^ ???
779
-//  CreateToolTip;
780
-    ToolTip.Pop;
781
-  end;
782
-end;
783
-
784
-procedure TMHHint.Popup;
785
-begin
786
-  if Assigned(ToolTip) and (HasTool) then
787
-  begin // ^^^^^^^^^^^^ ???
788
-//  CreateToolTip;
789
-    ToolTip.Popup;
790
-  end;
791
-end;
792
-
793
-destructor TMHHint.Destroy;
794
-var
795
-  TI: TToolInfo;
796
-  i: integer;
797
-begin
798
-  with TI do
799
-  begin
800
-    cbSize := SizeOf(TI);
801
-    hWnd := Parent.GetWindowHandle;
802
-    uId := Parent.GetWindowHandle;
803
-  end;
804
-
805
-  SendMessage(ToolTip.handle, TTM_DELTOOL, 0, DWORD(@TI));
806
-  ToolTip.Count := ToolTip.Count - 1;
807
-  if ToolTip.Count <= 0 then begin
808
-    i:=Length(Manager.TTT);
809
-    if i > 1 then begin
810
-      Manager.TTT[i - 1].Free;
811
-      SetLength(Manager.TTT, i - 1);
812
-    end
813
-    else
814
-      Free_And_Nil(Manager);
815
-  end;
816
-  inherited;
817
-end;
818
-
819
-destructor TMHToolTip.Destroy;
820
-begin
821
-  inherited;
822
-end;
823
-
824
-procedure TMHHint.CreateToolTip;
825
-begin
826
-  if not Assigned(ToolTip) then
827
-  begin
828
-    if Length(GetManager.TTT) = 0 then
829
-      GetManager.AddTip;
830
-    ToolTip := GetManager.TTT[0];
831
-  end;
832
-end;
833
-
834
-function TMHHint.GetText: KOLString;
835
-var
836
-  TI: TToolInfo;
837
-  TextL: array[0..255] of KOLChar;
838
-begin
839
-  if Assigned(ToolTip) and (HasTool) then
840
-  begin
841
-    // !!!
842
-    with TI do
843
-    begin
844
-    // ????
845
-//      FillChar(TI, SizeOf(TI), 0);
846
-      cbSize := SizeOf(TI);
847
-      hWnd := Parent.GetWindowHandle;
848
-      uId := Parent.GetWindowHandle;
849
-      lpszText := @TextL[0];
850
-    end;
851
-    SendMessage(ToolTip.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
852
-    Result := TextL; //TI.lpszText;// := PChar(Value);
853
-  end;
854
-end;
855
-
856
-function TMHHint.GetManager: PMHToolTipManager;
857
-begin
858
-  if Manager=nil then
859
-    Manager:=NewManager;
860
-  Result:=Manager;
861
-end;
862
-
863
-{$ENDIF implementation}
864
-
865
-{$IFDEF Frame}
866
-
867
-initialization
868
-{$ENDIF Frame}
869
-{$IFDEF initialization}
870
-
871
-  Manager := NewManager;
872
-{$ENDIF initialization}
873
-
874
-{$IFDEF Frame}
875
-finalization
876
-{$ENDIF Frame}
877
-{$IFDEF finalization}
878
-//  Manager.Free;
879
-{$ENDIF finalization}
880
-
881
-
882
-{$IFDEF Frame}
883
-end.
884
-{$ENDIF Frame}
885
-
886
-{$IFDEF function}
887
-function GetHint: PMHHint;
888
-{$ENDIF function}
889
-
890
-{$IFDEF public}
891
-  property Hint: PMHHint read GetHint;
892
-  {$ENDIF public}
893
-
894
-  {$IFDEF code}
895
-    function TControl.GetHint: PMHHint;
896
-    begin
897
-      if fHint = nil then
898
-        fHint := NewHint(@Self);
899
-      Result := fHint;
900
-    end;
901
-  {$ENDIF code}
902
-
903
-  {$IFDEF MHdestroy}
904
-    fHint.Free;
905
-  {$ENDIF MHdestroy}
906
-
907
-  {$IFDEF var}
908
-    fHint: PMHHint;
909
-  {$ENDIF var}

+ 0
- 17630
libwin/kolfpc/KOL_ASM.inc
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 1160
libwin/kolfpc/KOL_unicode.inc
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 3619
libwin/kolfpc/KOLadd.pas
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 51
libwin/kolfpc/LICENSE.txt Parādīt failu

@@ -1,51 +0,0 @@
1
-                wxWindows Library Licence, Version 3
2
-                ====================================
3
-
4
-  Copyright (C) 1998 Julian Smart, Robert Roebling [, ...]
5
-
6
-  Everyone is permitted to copy and distribute verbatim copies
7
-  of this licence document, but changing it is not allowed.
8
-
9
-                       WXWINDOWS LIBRARY LICENCE
10
-     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
11
-  
12
-  This library is free software; you can redistribute it and/or modify it
13
-  under the terms of the GNU Library General Public Licence as published by
14
-  the Free Software Foundation; either version 2 of the Licence, or (at
15
-  your option) any later version.
16
-  
17
-  This library is distributed in the hope that it will be useful, but
18
-  WITHOUT ANY WARRANTY; without even the implied warranty of
19
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
20
-  General Public Licence for more details.
21
-
22
-  You should have received a copy of the GNU Library General Public Licence
23
-  along with this software, usually in a file named COPYING.LIB.  If not,
24
-  write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
25
-  Boston, MA 02111-1307 USA.
26
-
27
-  EXCEPTION NOTICE
28
-
29
-  1. As a special exception, the copyright holders of this library give
30
-  permission for additional uses of the text contained in this release of
31
-  the library as licenced under the wxWindows Library Licence, applying
32
-  either version 3 of the Licence, or (at your option) any later version of
33
-  the Licence as published by the copyright holders of version 3 of the
34
-  Licence document.
35
-
36
-  2. The exception is that you may use, copy, link, modify and distribute
37
-  under the user's own terms, binary object code versions of works based
38
-  on the Library.
39
-
40
-  3. If you copy code from files distributed under the terms of the GNU
41
-  General Public Licence or the GNU Library General Public Licence into a
42
-  copy of this library, as this licence permits, the exception does not
43
-  apply to the code that you add in this way.  To avoid misleading anyone as
44
-  to the status of such modified files, you must delete this exception
45
-  notice from such code and/or adjust the licensing conditions notice
46
-  accordingly.
47
-
48
-  4. If you write modifications of your own for this library, it is your
49
-  choice whether to permit this exception to apply to your modifications. 
50
-  If you do not wish that, you must delete the exception notice from such
51
-  code and/or adjust the licensing conditions notice accordingly.

+ 0
- 77
libwin/kolfpc/MCKfakeClasses.inc Parādīt failu

@@ -1,77 +0,0 @@
1
-{
2
-  KOL MCK (C) 2000 by Vladimir Kladov
3
-
4
-  MCKfakeClasses.inc
5
-
6
-  This file redefines mirror class types to PControl / PObj
7
-  to use it by Delphi compiler - while compiling mirror KOL
8
-  project. At design time these definitions are not visible
9
-  for Delphi IDE because of conditional compiling directives.
10
-}
11
-
12
-{$I KOLDEF.INC}
13
-{$IFNDEF FPC}
14
-{$IFDEF _D7orHigher}
15
-  {$WARN UNSAFE_TYPE OFF} // Too many such warnings in Delphi7
16
-  {$WARN UNSAFE_CODE OFF}
17
-  {$WARN UNSAFE_CAST OFF}
18
-{$ENDIF}
19
-{$ENDIF}
20
-
21
-  TKOLProject = Pointer;
22
-  TKOLApplet = Pointer;
23
-  TKOLForm = Pointer;
24
-  TKOLDataModule = Pointer;
25
-  TKOLFrame = Pointer;
26
-  TKOLMDIClient = PControl;
27
-  TKOLMDIChild = Pointer;
28
-  TKOLService = Pointer;
29
-
30
-  TKOLButton = PControl;
31
-  TKOLLabel = PControl;
32
-  TKOLLabelEffect = PControl;
33
-  TKOLPanel = PControl;
34
-  TKOLSplitter = PControl;
35
-  TKOLGradientPanel = PControl;
36
-  TKOLBitBtn = PControl;
37
-  TKOLGroupBox = PControl;
38
-  TKOLCheckBox = PControl;
39
-  TKOLRadioBox = PControl;
40
-  TKOLEditBox = PControl;
41
-  TKOLMemo = PControl;
42
-  TKOLListBox = PControl;
43
-  TKOLComboBox = PControl;
44
-  TKOLPaintBox = PControl;
45
-  TKOLImageShow = PControl;
46
-
47
-  TKOLRichEdit = PControl;
48
-  TKOLProgressBar = PControl;
49
-  TKOLListView = PControl;
50
-  TKOLTreeView = PControl;
51
-  TKOLToolbar = PControl;
52
-  TKOLTabControl = PControl;
53
-  TTabPage = PControl;
54
-  TKOLScrollBox = PControl;
55
-  TKOLDateTimePicker = PControl;
56
-
57
-  TKOLTimer = PTimer;
58
-  TKOLThread = PThread;
59
-  TKOLImageList = PImageList;
60
-  TKOLMainMenu = PMenu;
61
-  TKOLPopupMenu = PMenu;
62
-  TKOLOpenSaveDialog = POpenSaveDialog;
63
-  //TKOLOpenDirDialog = POpenDirDialog;
64
-  TKOLTrayIcon = PTrayIcon;
65
-  TKOLColorDialog = PColorDialog;
66
-  //TKOLActionList = PActionList;
67
-  //TKOLAction = PAction;
68
-  TKOLScrollBar = PControl;
69
-
70
-{$IFNDEF FPC}
71
-{$IFDEF _D7orHigher}
72
-  //{$WARN UNSAFE_TYPE ON} // Too many such warnings in Delphi7
73
-  //{$WARN UNSAFE_CODE ON}
74
-  //{$WARN UNSAFE_CAST ON}
75
-{$ENDIF}
76
-{$ENDIF}
77
-

+ 0
- 64
libwin/kolfpc/READ1ST.TXT Parādīt failu

@@ -1,64 +0,0 @@
1
-KEY OBJECTS LIBRARY for Delphi (and Free Pascal Compiler) - to make applications small and power. This library is freeware and open source. Delphi 2, 3, 4, 5, 6, 7, 8, BDS 2005, 2006, TurboDelphi5 and Free Pascal Compiler 1.0.5, 1.0.6, and higher (2.0.4 and above) are supported. Partially compatible with Kylix (Linux/Qt platform, use special converting tool and provided files in Tools section on the site http://kolmck.net). Also a version for WinCE exists.
2
-
3
-Copyright (C) by Vladimir Kladov, 1999-2007.
4
-Some parts of code are Copyright (C) intellectual property by other people, see comments in code and on KOL site. Thanks to all for help with KOL and MCK!
5
-
6
-version 2.80 (19-Sep-2007)
7
-
8
-To get newer version, go to Web-page http://kolmck.net and get there updates.
9
-
10
-__________________
11
-BRIEF DESCRIPTION:
12
-    KOL - Key Objects Library is a set of objects to develop applications using Delphi. It is distributed free of charge, with source code.
13
-   KOL allows to create very compact GUI applications (starting from ~14,0K without compression - if suggested system units replacement used). The majority of the code is converted to assembly.
14
-   A Help generating tool, xHelpGen is provided for KOL, which creates detailed documentation in html format. Documentation is generated on from the source code comments, so developers instantly  have access to the most fresh and complete documentation.
15
-   With advent of the MCK (Mirror Classes Kit) package, all advantages of visual programming are available for developers who use KOL. Additionally with MCK it is possible to make large enough projects smaller converting part of machine code to a byte code of Forth-like virtual (emulated at run time) machint (see more detailed: Collapse).
16
-   A lot of additions are available for KOL, which allow to work with data bases, Active-X components, print reports, different image and compression formats, etc.
17
---------------------------------------------
18
-
19
-This archive contains Key Objects Library main part: KOL.PAS and several test samples. 
20
-At the KOL Web page (http://kolmck.net), you can download also additional components:
21
-
22
-MCK		- Mirror Classes Kit - visual programming environment for KOL
23
-xHelpGen	- utility to generate html-documentation from comments within the source code;
24
-KolErr	(~25K) - "light" (for 6K), but functional exception handling unit
25
-KOLEdb, KOLODBC, StrDb (by Mike Talcott), TdkDbKol (by Thaddy de Koning) - DB-extensions for KOL
26
-KolGif	(~20K) - GIF (animated, transparent) support for KOL
27
-KolJpegObj (~127K + 340K) - JPEG support for KOL
28
-KolOGL12 (~59K) - OpenGL support for KOL
29
-KOLword (~12K) - MS Word automation
30
-Service	(~20K) - writing NT services with KOL
31
-KOLSocket (~30K) - sockets for KOL (by Alexander Shakhaylo)
32
-TestKOLRas (~20K) - RAS dial-up for KOL (by Alexander Shakhaylo)
33
-sysdcu	(~200K) - system.dcu, sysinit.dcu replacement for Delphi5 (it provides a savings of 9KBytes from the .exe's file size)
34
-sysdcuD6 (~200K) - system.dcu, ... replacement for Delphi6
35
-HeapMM  (~1K) - alteranative memory manager
36
-MapMem
37
-Widgets
38
-ZLib
39
-... and many others, this list is constantly extended with new items.
40
-
41
-
42
-_____________
43
-INSTALLATION:
44
-
45
-1. When You install KOL the first time, create a new directory for KOL (e.g., E:\KOL).
46
-
47
-2. Unpack all files from KOL.ZIP there. (If upgrading, confirm overwriting of old files with new ones).
48
-
49
-3. If You downloaded xhelpgen.zip package, also unpack it into the same directory. Read also docs for xHelpGen from the package.
50
-
51
-4. If You downloaded SYSDCU.ZIP, create subdirectory for it (e.g. E:\KOL\SYS) and unpack it there. Read also docs for system units replacement in the package.
52
-
53
-5. To learn how to install the MCK (Mirror Classes Kit) see instructions in the MCK archive.
54
-
55
-6. To learn how to install KOLEdb, see instructions in KOLEDB.ZIP archive. 
56
-
57
-7. For more information on the use and or installation of any of the packages packages and programs found on KOL site: look for help within it's package.
58
-
59
-Note: KOL itself does not require creating a package since it has no design-time components to install it onto Component Palette. See MCK, which has such components and allows visual programming using KOL.
60
---------------------------------------------------
61
-
62
-Web address: http://kolmck.net
63
-vk@kolmck.net      
64
-Vladimir Kladov

+ 0
- 25
libwin/kolfpc/Readme-KOL-CE.txt Parādīt failu

@@ -1,25 +0,0 @@
1
-KOL-CE notes.
2
-
3
-Main project page:
4
-http://wiki.freepascal.org/KOL-CE
5
-
6
-Project pages at SourceForge:
7
-http://sourceforge.net/projects/kol-ce/
8
-
9
-Usage
10
-=====
11
-
12
-You need to download or create arm-wince cross compiler to be able to use this library.
13
-How to do that read here:
14
-http://wiki.freepascal.org/index.php?title=WinCE_port
15
-
16
-Port notes
17
-==========
18
-
19
-* To make form fullscreen as most Pocket PC applications dont change the form position and size. If form size and/or position was changed the form will look like dialog with caption and close button. 
20
-
21
-Known issues
22
-============
23
-
24
-* The following components are not supported: RichEdit, TrayIcon.
25
-* Only gsVertical, gsHorizontal gradient panel styles are supported.

+ 0
- 1512
libwin/kolfpc/delphicommctrl.inc
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 46
libwin/kolfpc/delphidef.inc Parādīt failu

@@ -1,46 +0,0 @@
1
-//{$DEFINE _FPC}
2
-{$DEFINE ASM_VERSION} // Comment this line to produce Pascal code.
3
-                      // Or, just add PAS_VERSION to conditionals
4
-                      // of your project (must be rebuilt).
5
-
6
-{$IFDEF ASM_VERSION}
7
-  {$IFDEF PAS_VERSION}
8
-    {$UNDEF ASM_VERSION}
9
-    // To compile a project with ASM_VERSION option turned off,
10
-    // define a symbol PAS_VERSION in project options.
11
-  {$ENDIF}
12
-{$ENDIF}
13
-
14
-{$I KOLDEF.INC}
15
-
16
-//{$DEFINE USE_CONSTRUCTORS}
17
-// Comment this line to produce smaller code if constructors are not used.
18
-// When uncommented, this definition allows to create descendant controls
19
-// and objects overriding constructors, which are actually members of objects.
20
-// Otherwise, global functions (usually named New<ObjectName>) are used to
21
-// create and initialize object instances. This gives smaller code, but
22
-// prevents from using OOP inheritance.
23
-// Note: creating descendant objects derived from TObj does not require using
24
-// of this option. It is actually needed only for deriving new controls on
25
-// base of TControl. See also option USE_CUSTOMEXTENSIONS below.
26
-
27
-//{$DEFINE USE_CUSTOMEXTENSIONS}
28
-// Uncomment this option or add it to your project conditional defines,
29
-// if You wish to extend existing TControl object from
30
-// the inner of those. When this option is turned on, include directive at the
31
-// tail of TControl declaration is enabled, causing a compiler to include your
32
-// portion of source directly into the TControl body. See comments near this
33
-// directive there. (Search the word: USE_CUSTOMEXTENSIONS).
34
-// Please note, that this option is not fully supported now.
35
-
36
-{$IFNDEF NOT_UNLOAD_RICHEDITLIB}
37
-  {$DEFINE UNLOAD_RICHEDITLIB}
38
-{$ENDIF}
39
-// You can freely comment this directive. 1st, if the application does not
40
-// use richedit control. 2nd, even if it does, freeing the library handle
41
-// actually is not needed.
42
-// Another way to turn this option off is to define symbol NOT_UNLOAD_RICHEDITLIB
43
-// in your project options.
44
-
45
-//{$DEFINE TEST_VERSION}
46
-{$DEFINE PARANOIA} //seems not needed under D6 !!! Inprise fixed this, finally... :)

+ 0
- 1
libwin/kolfpc/delphiusesh.inc Parādīt failu

@@ -1 +0,0 @@
1
-windows, messages, RichEdit {$IFDEF CHK_GDI}, ChkGdi {$ENDIF}

+ 0
- 561
libwin/kolfpc/fpc_unicode_add.inc Parādīt failu

@@ -1,561 +0,0 @@
1
-const
2
-  MAX_PROFILE_LEN = 80;
3
-  MM_MAX_AXES_NAMELEN = 16;
4
-  MM_MAX_NUMAXES = 16;
5
-  HW_PROFILE_GUIDLEN = 39;
6
-
7
-type
8
-  HDEVNOTIFY = Pointer;
9
-  PHDEVNOTIFY = ^HDEVNOTIFY;
10
-
11
-  _GET_FILEEX_INFO_LEVELS = (GetFileExInfoStandard, GetFileExMaxInfoLevel);
12
-  TGetFileExInfoLevels = _GET_FILEEX_INFO_LEVELS;
13
-  GET_FILEEX_INFO_LEVELS = _GET_FILEEX_INFO_LEVELS;
14
-
15
-  _FINDEX_INFO_LEVELS = (FindExInfoStandard, FindExInfoMaxInfoLevel);
16
-  TFindexInfoLevels = _FINDEX_INFO_LEVELS;
17
-  FINDEX_INFO_LEVELS = _FINDEX_INFO_LEVELS;
18
-
19
-  _FINDEX_SEARCH_OPS = (FindExSearchNameMatch, FindExSearchLimitToDirectories,
20
-    FindExSearchLimitToDevices, FindExSearchMaxSearchOp);
21
-  TFindexSearchOps = _FINDEX_SEARCH_OPS;
22
-  FINDEX_SEARCH_OPS = _FINDEX_SEARCH_OPS;
23
-
24
-  TFNPropEnumProc = TFarProc;
25
-  TFNPropEnumProcEx = TFarProc;
26
-  TFNEditWordBreakProc = TFarProc;
27
-  TFNNameEnumProc = TFarProc;
28
-  TFNWinStaEnumProc = TFNNameEnumProc;
29
-  TFNDeskTopEnumProc = TFNNameEnumProc;
30
-  TFNWndProc = TFarProc;
31
-  TFNDlgProc = TFarProc;
32
-  TFNTimerProc = TFarProc;
33
-  TFNGrayStringProc = TFarProc;
34
-  TFNWndEnumProc = TFarProc;
35
-  TFNSendAsyncProc = TFarProc;
36
-  TFNDrawStateProc = TFarProc;
37
-  TFNOldFontEnumProcW = TFarProc;
38
-  TFNGObjEnumProc = TFarProc;
39
-  TFNLineDDAProc = TFarProc;
40
-  TFNFontEnumProcW = TFarProc;
41
-  TFNProgressRoutine = TFarProc;
42
-  TFNLocaleEnumProc = TFarProc;
43
-  TFNCodepageEnumProc = TFarProc;
44
-  TFNDateFmtEnumProc = TFarProc;
45
-  TFNTimeFmtEnumProc = TFarProc;
46
-  TFNCalInfoEnumProc = TFarProc;
47
-  TFNICMEnumProc = TFarProc;
48
-
49
-  MakeIntAtomW = PWideChar;
50
-  
51
-  PRecoveryAgentInformationW = ^TRecoveryAgentInformationW;
52
-  _RECOVERY_AGENT_INFORMATIONW = record
53
-    NextEntryOffset: DWORD;
54
-    AgentNameLength: DWORD;
55
-    AgentInformation: array[0..0] of CHAR;
56
-  end;
57
-  TRecoveryAgentInformationW = _RECOVERY_AGENT_INFORMATIONW;
58
-  RECOVERY_AGENT_INFORMATIONW = _RECOVERY_AGENT_INFORMATIONW;
59
-  
60
-  PWin32FindDataW = ^TWin32FindDataW;
61
-  _WIN32_FIND_DATAW = record
62
-    dwFileAttributes: DWORD;
63
-    ftCreationTime: TFileTime;
64
-    ftLastAccessTime: TFileTime;
65
-    ftLastWriteTime: TFileTime;
66
-    nFileSizeHigh: DWORD;
67
-    nFileSizeLow: DWORD;
68
-    dwReserved0: DWORD;
69
-    dwReserved1: DWORD;
70
-    cFileName: array[0..MAX_PATH - 1] of WideChar;
71
-    cAlternateFileName: array[0..13] of WideChar;
72
-  end;
73
-  TWin32FindDataW = _WIN32_FIND_DATAW;
74
-  WIN32_FIND_DATAW = _WIN32_FIND_DATAW;
75
-
76
-  PHWProfileInfoW = ^THWProfileInfoW;
77
-  tagHW_PROFILE_INFOW = packed record
78
-    dwDockInfo: DWORD;
79
-    szHwProfileGuid: packed array[0..HW_PROFILE_GUIDLEN-1] of WideChar;
80
-    szHwProfileName: packed array[0..MAX_PROFILE_LEN-1] of WideChar;
81
-  end;
82
-  THWProfileInfoW = tagHW_PROFILE_INFOW;
83
-  HW_PROFILE_INFOW = tagHW_PROFILE_INFOW;
84
-
85
-  PLogColorSpaceW = ^TLogColorSpaceW;
86
-  tagLOGCOLORSPACEW = packed record
87
-    lcsSignature: DWORD;
88
-    lcsVersion: DWORD;
89
-    lcsSize: DWORD;
90
-    lcsCSType: LCSCSTYPE;
91
-    lcsIntent: LCSGAMUTMATCH;
92
-    lcsEndpoints: TCIEXYZTriple;
93
-    lcsGammaRed: DWORD;
94
-    lcsGammaGreen: DWORD;
95
-    lcsGammaBlue: DWORD;
96
-    lcsFilename: array[0..259] of WideChar;
97
-  end;
98
-  TLogColorSpaceW = tagLOGCOLORSPACEW;
99
-  LOGCOLORSPACEW = tagLOGCOLORSPACEW;
100
-
101
-  PNewTextMetricW = ^TNewTextMetricW;
102
-  tagNEWTEXTMETRICW = record
103
-    tmHeight: Longint;
104
-    tmAscent: Longint;
105
-    tmDescent: Longint;
106
-    tmInternalLeading: Longint;
107
-    tmExternalLeading: Longint;
108
-    tmAveCharWidth: Longint;
109
-    tmMaxCharWidth: Longint;
110
-    tmWeight: Longint;
111
-    tmOverhang: Longint;
112
-    tmDigitizedAspectX: Longint;
113
-    tmDigitizedAspectY: Longint;
114
-    tmFirstChar: WideChar;
115
-    tmLastChar: WideChar;
116
-    tmDefaultChar: WideChar;
117
-    tmBreakChar: WideChar;
118
-    tmItalic: Byte;
119
-    tmUnderlined: Byte;
120
-    tmStruckOut: Byte;
121
-    tmPitchAndFamily: Byte;
122
-    tmCharSet: Byte;
123
-    ntmFlags: DWORD;
124
-    ntmSizeEM: UINT;
125
-    ntmCellHeight: UINT;
126
-    ntmAvgWidth: UINT;
127
-  end;
128
-  TNewTextMetricW = tagNEWTEXTMETRICW;
129
-  NEWTEXTMETRICW = tagNEWTEXTMETRICW;
130
-
131
-  PNewTextMetricExW = ^TNewTextMetricExW;
132
-  tagNEWTEXTMETRICEXW = packed record
133
-    ntmTm: TNewTextMetricW;
134
-    ntmFontSig: TFontSignature;
135
-  end;
136
-  TNewTextMetricExW = tagNEWTEXTMETRICEXW;
137
-  NEWTEXTMETRICEXW = tagNEWTEXTMETRICEXW;
138
-
139
-  PEnumLogFontW = ^TEnumLogFontW;
140
-  tagENUMLOGFONTW = packed record
141
-    elfLogFont: TLogFontW;
142
-    elfFullName: array[0..LF_FULLFACESIZE - 1] of WideChar;
143
-    elfStyle: array[0..LF_FACESIZE - 1] of WideChar;
144
-  end;
145
-  TEnumLogFontW = tagENUMLOGFONTW;
146
-  ENUMLOGFONTW = tagENUMLOGFONTW;
147
-
148
-  PEnumLogFontExW = ^TEnumLogFontExW;
149
-  tagENUMLOGFONTEXW = packed record
150
-    elfLogFont: TLogFontW;
151
-    elfFullName: array[0..LF_FULLFACESIZE - 1] of WideChar;
152
-    elfStyle: array[0..LF_FACESIZE - 1] of WideChar;
153
-    elfScript: array[0..LF_FACESIZE - 1] of WideChar;
154
-  end;
155
-  TEnumLogFontExW = tagENUMLOGFONTEXW;
156
-  ENUMLOGFONTEXW = tagENUMLOGFONTEXW;
157
-
158
-  PExtLogFontW = ^TExtLogFontW;
159
-  tagEXTLOGFONTW = record
160
-    elfLogFont: TLogFontW;
161
-    elfFullName: array[0..LF_FULLFACESIZE - 1] of WideChar;
162
-    elfStyle: array[0..LF_FACESIZE - 1] of WideChar;
163
-    elfVersion: DWORD;     { 0 for the first release of NT }
164
-    elfStyleSize: DWORD;
165
-    elfMatch: DWORD;
166
-    elfReserved: DWORD;
167
-    elfVendorId: array[0..ELF_VENDOR_SIZE - 1] of Byte;
168
-    elfCulture: DWORD;     { 0 for Latin }
169
-    elfPanose: TPanose;
170
-  end;
171
-  TExtLogFontW = tagEXTLOGFONTW;
172
-  EXTLOGFONTW = tagEXTLOGFONTW;
173
-
174
-  PDisplayDeviceW = ^TDisplayDeviceW;
175
-  _DISPLAY_DEVICEW = packed record
176
-    cb: DWORD;
177
-    DeviceName: array[0..31] of WideChar;
178
-    DeviceString: array[0..127] of WideChar;
179
-    StateFlags: DWORD;
180
-  end;
181
-  TDisplayDeviceW = _DISPLAY_DEVICEW;
182
-
183
-  POutlineTextmetricW = ^TOutlineTextmetricW;
184
-  _OUTLINETEXTMETRICW = record
185
-    otmSize: UINT;
186
-    otmTextMetrics: TTextMetricW;
187
-    otmFiller: Byte;
188
-    otmPanoseNumber: TPanose;
189
-    otmfsSelection: UINT;
190
-    otmfsType: UINT;
191
-    otmsCharSlopeRise: Integer;
192
-    otmsCharSlopeRun: Integer;
193
-    otmItalicAngle: Integer;
194
-    otmEMSquare: UINT;
195
-    otmAscent: Integer;
196
-    otmDescent: Integer;
197
-    otmLineGap: UINT;
198
-    otmsCapEmHeight: UINT;
199
-    otmsXHeight: UINT;
200
-    otmrcFontBox: TRect;
201
-    otmMacAscent: Integer;
202
-    otmMacDescent: Integer;
203
-    otmMacLineGap: UINT;
204
-    otmusMinimumPPEM: UINT;
205
-    otmptSubscriptSize: TPoint;
206
-    otmptSubscriptOffset: TPoint;
207
-    otmptSuperscriptSize: TPoint;
208
-    otmptSuperscriptOffset: TPoint;
209
-    otmsStrikeoutSize: UINT;
210
-    otmsStrikeoutPosition: Integer;
211
-    otmsUnderscoreSize: Integer;
212
-    otmsUnderscorePosition: Integer;
213
-    otmpFamilyName: PWideChar;
214
-    otmpFaceName: PWideChar;
215
-    otmpStyleName: PWideChar;
216
-    otmpFullName: PWideChar;
217
-  end;
218
-  TOutlineTextmetricW = _OUTLINETEXTMETRICW;
219
-  OUTLINETEXTMETRICW = _OUTLINETEXTMETRICW;
220
-
221
-  PPolyTextW = ^TPolyTextW;
222
-  tagPOLYTEXTW = packed record
223
-    x: Integer;
224
-    y: Integer;
225
-    n: UINT;
226
-    PAnsiChar: PWideChar;
227
-    uiFlags: UINT;
228
-    rcl: TRect;
229
-    pdx: PINT;
230
-  end;
231
-  TPolyTextW = tagPOLYTEXTW;
232
-  POLYTEXTW = tagPOLYTEXTW;
233
-
234
-  PGCPResultsW = ^TGCPResultsW;
235
-  tagGCP_RESULTSW = packed record
236
-    lStructSize: DWORD;
237
-    lpOutString: PWideChar;
238
-    lpOrder: PUINT;
239
-    lpDx: PINT;
240
-    lpCaretPos: PINT;
241
-    lpClass: PWideChar;
242
-    lpGlyphs: PUINT;
243
-    nGlyphs: UINT;
244
-    nMaxFit: Integer;
245
-  end;
246
-  TGCPResultsW = tagGCP_RESULTSW;
247
-  GCP_RESULTSW = tagGCP_RESULTSW;
248
-
249
- PAxisInfoW = ^TAxisInfoW;
250
-  tagAXISINFOW = packed record
251
-    axMinValue: Longint;
252
-    axMaxValue: Longint;
253
-    axAxisName: array[0..MM_MAX_AXES_NAMELEN-1] of WideChar;
254
-  end;
255
-  TAxisInfoW = tagAXISINFOW;
256
-  PAxesListW = ^TAxesListW;
257
-  tagAXESLISTW = packed record
258
-    axlReserved: DWORD;
259
-    axlNumAxes: DWORD;
260
-    axlAxisInfo: array[0..MM_MAX_NUMAXES-1] of TAxisInfoW;
261
-  end;
262
-  TAxesListW = tagAXESLISTW;
263
-
264
-  PDesignVector = ^TDesignVector;
265
-  tagDESIGNVECTOR = packed record
266
-    dvReserved: DWORD;
267
-    dvNumAxes: DWORD;
268
-    dvValues: array[0..MM_MAX_NUMAXES-1] of Longint;
269
-  end;
270
-  TDesignVector = tagDESIGNVECTOR;
271
-
272
-  PEnumLogFontExDVW = ^TEnumLogFontExDVW;
273
-  tagENUMLOGFONTEXDVW = packed record
274
-    elfEnumLogfontEx: TEnumLogFontExW;
275
-    elfDesignVector: TDesignVector;
276
-  end;
277
-  TEnumLogFontExDVW = tagENUMLOGFONTEXDVW;
278
-
279
-  PEnumTextMetricW = ^TEnumTextMetricW;
280
-  tagENUMTEXTMETRICW = packed record
281
-    etmNewTextMetricEx: TNewTextMetricExW;
282
-    etmAxesList: TAxesListW;
283
-  end;
284
-  TEnumTextMetricW = tagENUMTEXTMETRICW;
285
-
286
-  PDocInfoW = ^TDocInfoW;
287
-  _DOCINFOW = packed record
288
-    cbSize: Integer;
289
-    lpszDocName: PWideChar;
290
-    lpszOutput: PWideChar;
291
-    lpszDatatype: PWideChar;
292
-    fwType: DWORD;
293
-  end;
294
-  TDocInfoW = _DOCINFOW;
295
-  DOCINFOW = _DOCINFOW;
296
-
297
-  PCreateStructW = ^TCreateStructW;
298
-  tagCREATESTRUCTW = packed record
299
-    lpCreateParams: Pointer;
300
-    hInstance: HINST;
301
-    hMenu: HMENU;
302
-    hwndParent: HWND;
303
-    cy: Integer;
304
-    cx: Integer;
305
-    y: Integer;
306
-    x: Integer;
307
-    style: Longint;
308
-    lpszName: PWideChar;
309
-    lpszClass: PWideChar;
310
-    dwExStyle: DWORD;
311
-  end;
312
-  TCreateStructW = tagCREATESTRUCTW;
313
-  CREATESTRUCTW = tagCREATESTRUCTW;
314
-
315
-  TPRMsgBoxCallback = procedure(var lpHelpInfo: THelpInfo);
316
-  PMsgBoxParamsW = ^TMsgBoxParamsW;
317
-  tagMSGBOXPARAMSW = packed record
318
-    cbSize: UINT;
319
-    hwndOwner: HWND;
320
-    hInstance: HINST;
321
-    lpszText: PWideChar;
322
-    lpszCaption: PWideChar;
323
-    dwStyle: DWORD;
324
-    lpszIcon: PWideChar;
325
-    dwContextHelpId: DWORD;
326
-    lpfnMsgBoxCallback: TPRMsgBoxCallback;
327
-    dwLanguageId: DWORD;
328
-  end;
329
-  TMsgBoxParamsW = tagMSGBOXPARAMSW;
330
-  MSGBOXPARAMSW = tagMSGBOXPARAMSW;
331
-
332
-  PMDICreateStructW = ^TMDICreateStructW;
333
-  tagMDICREATESTRUCTW = packed record
334
-    szClass: PWideChar;
335
-    szTitle: PWideChar;
336
-    hOwner: THandle;
337
-    x: Integer;
338
-    y: Integer;
339
-    cx: Integer;
340
-    cy: Integer;
341
-    style: DWORD;
342
-    lParam: LPARAM;  { app-defined stuff }
343
-  end;
344
-  TMDICreateStructW = tagMDICREATESTRUCTW;
345
-  MDICREATESTRUCTW = tagMDICREATESTRUCTW;
346
-
347
-  PMultiKeyHelpW = ^TMultiKeyHelpW;
348
-  tagMULTIKEYHELPW = record
349
-    mkSize: DWORD;
350
-    mkKeylist: WideChar;
351
-    szKeyphrase: array[0..0] of WideChar;
352
-  end;
353
-  TMultiKeyHelpW = tagMULTIKEYHELPW;
354
-  MULTIKEYHELPW = tagMULTIKEYHELPW;
355
-
356
-  PHelpWinInfoW = ^THelpWinInfoW;
357
-  tagHELPWININFOW = record
358
-    wStructSize: Integer;
359
-    x: Integer;
360
-    y: Integer;
361
-    dx: Integer;
362
-    dy: Integer;
363
-    wMax: Integer;
364
-    rgchMember: array[0..1] of WideChar;
365
-  end;
366
-  THelpWinInfoW = tagHELPWININFOW;
367
-  HELPWININFOW = tagHELPWININFOW;
368
-
369
-  PNonClientMetricsW = ^TNonClientMetricsW;
370
-  tagNONCLIENTMETRICSW = packed record
371
-    cbSize: UINT;
372
-    iBorderWidth: Integer;
373
-    iScrollWidth: Integer;
374
-    iScrollHeight: Integer;
375
-    iCaptionWidth: Integer;
376
-    iCaptionHeight: Integer;
377
-    lfCaptionFont: TLogFontW;
378
-    iSmCaptionWidth: Integer;
379
-    iSmCaptionHeight: Integer;
380
-    lfSmCaptionFont: TLogFontW;
381
-    iMenuWidth: Integer;
382
-    iMenuHeight: Integer;
383
-    lfMenuFont: TLogFontW;
384
-    lfStatusFont: TLogFontW;
385
-    lfMessageFont: TLogFontW;
386
-  end;
387
-  TNonClientMetricsW = tagNONCLIENTMETRICSW;
388
-  NONCLIENTMETRICSW = tagNONCLIENTMETRICSW;
389
-
390
-  PIconMetricsW = ^TIconMetricsW;
391
-  tagICONMETRICSW = packed record
392
-    cbSize: UINT;
393
-    iHorzSpacing: Integer;
394
-    iVertSpacing: Integer;
395
-    iTitleWrap: Integer;
396
-    lfFont: TLogFontW;
397
-  end;
398
-  TIconMetricsW = tagICONMETRICSW;
399
-  ICONMETRICSW = tagICONMETRICSW;
400
-
401
-  PSerialKeysW = ^TSerialKeysW;
402
-  tagSERIALKEYSW = packed record
403
-    cbSize: UINT;
404
-    dwFlags: DWORD;
405
-    lpszActivePort: PWideChar;
406
-    lpszPort: PWideChar;
407
-    iBaudRate: UINT;
408
-    iPortState: UINT;
409
-    iActive: UINT;
410
-  end;
411
-  TSerialKeysW = tagSERIALKEYSW;
412
-  SERIALKEYSW = tagSERIALKEYSW;
413
-
414
-  PHighContrastW = ^THighContrastW;
415
-  tagHIGHCONTRASTW = packed record
416
-    cbSize: UINT;
417
-    dwFlags: DWORD;
418
-    lpszDefaultScheme: PWideChar;
419
-  end;
420
-  THighContrastW = tagHIGHCONTRASTW;
421
-  HIGHCONTRASTW = tagHIGHCONTRASTW;
422
-
423
-  PSoundsEntryW = ^TSoundsEntryW;
424
-  tagSOUNDSENTRYW = packed record
425
-    cbSize: UINT;
426
-    dwFlags: DWORD;
427
-    iFSTextEffect: DWORD;
428
-    iFSTextEffectMSec: DWORD;
429
-    iFSTextEffectColorBits: DWORD;
430
-    iFSGrafEffect: DWORD;
431
-    iFSGrafEffectMSec: DWORD;
432
-    iFSGrafEffectColor: DWORD;
433
-    iWindowsEffect: DWORD;
434
-    iWindowsEffectMSec: DWORD;
435
-    lpszWindowsEffectDLL: PWideChar;
436
-    iWindowsEffectOrdinal: DWORD;
437
-  end;
438
-  TSoundsEntryW = tagSOUNDSENTRYW;
439
-  SOUNDSENTRYW = tagSOUNDSENTRYW;
440
-
441
-  PNumberFmtW = ^TNumberFmtW;
442
-  _numberfmtW = packed record
443
-    NumDigits: UINT;        { number of decimal digits }
444
-    LeadingZero: UINT;      { if leading zero in decimal fields }
445
-    Grouping: UINT;         { group size left of decimal }
446
-    lpDecimalSep: PWideChar;   { ptr to decimal separator string }
447
-    lpThousandSep: PWideChar;  { ptr to thousand separator string }
448
-    NegativeOrder: UINT;    { negative number ordering }
449
-  end;
450
-  TNumberFmtW = _numberfmtW;
451
-  NUMBERFMTW = _numberfmtW;
452
-
453
-  PCurrencyFmtW = ^TCurrencyFmtW;
454
-  _currencyfmtW = packed record
455
-    NumDigits: UINT;           { number of decimal digits }
456
-    LeadingZero: UINT;         { if leading zero in decimal fields }
457
-    Grouping: UINT;            { group size left of decimal }
458
-    lpDecimalSep: PWideChar;      { ptr to decimal separator string }
459
-    lpThousandSep: PWideChar;     { ptr to thousand separator string }
460
-    NegativeOrder: UINT;       { negative currency ordering }
461
-    PositiveOrder: UINT;       { positive currency ordering }
462
-    lpCurrencySymbol: PWideChar;  { ptr to currency symbol string }
463
-  end;
464
-  TCurrencyFmtW = _currencyfmtW;
465
-  CURRENCYFMTW = _currencyfmtW;
466
-
467
-  PPValueW = ^TPValueW;
468
-  pvalueW = packed record
469
-    pv_valuename: PWideChar;           { The value name pointer }
470
-    pv_valuelen: BOOL;
471
-    pv_value_context: Pointer;
472
-    pv_type: DWORD;
473
-  end;
474
-  TPValueW = pvalueW;
475
-
476
-  PValueEntW = ^TValueEntW;
477
-  value_entW = packed record
478
-    ve_valuename: PWideChar;
479
-    ve_valuelen: DWORD;
480
-    ve_valueptr: DWORD;
481
-    ve_type: DWORD;
482
-  end;
483
-  TValueEntW = value_entW;
484
-  VALENTW = value_entW;
485
-
486
-  PNetResourceW = ^TNetResourceW;
487
-  _NETRESOURCEW = packed record
488
-    dwScope: DWORD;
489
-    dwType: DWORD;
490
-    dwDisplayType: DWORD;
491
-    dwUsage: DWORD;
492
-    lpLocalName: PWideChar;
493
-    lpRemoteName: PWideChar;
494
-    lpComment: PWideChar;
495
-    lpProvider: PWideChar;
496
-  end;
497
-  TNetResourceW = _NETRESOURCEW;
498
-  NETRESOURCEW = _NETRESOURCEW;
499
-
500
-  PDiscDlgStructW = ^TDiscDlgStructW;
501
-  _DISCDLGSTRUCTW = packed record
502
-    cbStructure: DWORD;       { size of this structure in bytes }
503
-    hwndOwner: HWND;          { owner window for the dialog }
504
-    lpLocalName: PWideChar;       { local device name }
505
-    lpRemoteName: PWideChar;      { network resource name }
506
-    dwFlags: DWORD;
507
-  end;
508
-  TDiscDlgStructW = _DISCDLGSTRUCTW;
509
-  DISCDLGSTRUCTW = _DISCDLGSTRUCTW;
510
-
511
-  PUniversalNameInfoW = ^TUniversalNameInfoW;
512
-  _UNIVERSAL_NAME_INFOW = packed record
513
-    lpUniversalName: PWideChar;
514
-  end;
515
-  TUniversalNameInfoW = _UNIVERSAL_NAME_INFOW;
516
-  UNIVERSAL_NAME_INFOW = _UNIVERSAL_NAME_INFOW;
517
-
518
-  PRemoteNameInfoW = ^TRemoteNameInfoW;
519
-  _REMOTE_NAME_INFOW = packed record
520
-    lpUniversalName: PWideChar;
521
-    lpConnectionName: PWideChar;
522
-    lpRemainingPath: PWideChar;
523
-  end;
524
-  TRemoteNameInfoW = _REMOTE_NAME_INFOW;
525
-  REMOTE_NAME_INFOW = _REMOTE_NAME_INFOW;
526
-
527
-  PAltTabInfo = ^TAltTabInfo;
528
-  tagALTTABINFO = packed record
529
-    cbSize: DWORD;
530
-    cItems: Integer;
531
-    cColumns: Integer;
532
-    cRows: Integer;
533
-    iColFocus: Integer;
534
-    iRowFocus: Integer;
535
-    cxItem: Integer;
536
-    cyItem: Integer;
537
-    ptStart: TPoint;
538
-  end;
539
-  TAltTabInfo = tagALTTABINFO;
540
-  
541
-  PMenuItemInfoW = ^TMenuItemInfoW;
542
-  tagMENUITEMINFOW = packed record
543
-    cbSize: UINT;
544
-    fMask: UINT;
545
-    fType: UINT;             { used if MIIM_TYPE}
546
-    fState: UINT;            { used if MIIM_STATE}
547
-    wID: UINT;               { used if MIIM_ID}
548
-    hSubMenu: HMENU;         { used if MIIM_SUBMENU}
549
-    hbmpChecked: HBITMAP;    { used if MIIM_CHECKMARKS}
550
-    hbmpUnchecked: HBITMAP;  { used if MIIM_CHECKMARKS}
551
-    dwItemData: DWORD;       { used if MIIM_DATA}
552
-    dwTypeData: PWideChar;      { used if MIIM_TYPE}
553
-    cch: UINT;               { used if MIIM_TYPE}
554
-    hbmpItem: HBITMAP;       { used if MIIM_BITMAP}
555
-  end;
556
-  TMenuItemInfoW = tagMENUITEMINFOW;
557
-  MENUITEMINFOW = tagMENUITEMINFOW;
558
-
559
-  PMenuItemInfo = PMenuItemInfoW;
560
-  TMenuItemInfo = TMenuItemInfoW;
561
-  MENUITEMINFO = MENUITEMINFOW;

+ 0
- 61
libwin/kolfpc/read1st_rus.txt Parādīt failu

@@ -1,61 +0,0 @@
1
-KEY OBJECTS LIBRARY для Delphi (и Free Pascal Compiler) - предназначен для того, чтобы сделать программы, изготовленные с использованием языка Паскаль, маленькими и очень маленькими. 
2
-Copyright (C) by Vladimir Kladov, 1999-2007. Бесплатно, с исходными текстами.
3
-
4
-версия 2.80 (19 сентября 2007 г.)
5
-
6
-_________________
7
-КРАТКОЕ ОПИСАНИЕ:
8
-   KOL - Key Objects Library - это библиотека объектов для программирования в среде Delphi. 
9
-   Поддерживаются версии Delphi2, Delph3, Delphi4, Delphi5, Delphi6, Delphi7, Delphi8, BDS2005, BDS2006, Turbo-Delphi а так же Free Pascal v1.0.5, v2.0.4 и выше. Имеется так же частичная совместимость с Kylix (требуется конвертер и набор файлов, см. в разделе "Инструменты разработчика" на сайте http://kolmck.net). Ведется работа над портированием на другие платформы (Linux, Win CE).
10
-   Библиотека KOL позволяет разрабатывать чрезвычайно компактные GUI-приложения (от 11К без сжатия - при условии использования предлагаемой замены системных модулей system, sysinit, см. на сайте раздел "Архивы"). Большая часть кода переведана на ассемблер.
11
-   К библиотеке прилагается программа - генератор справки (xHelpGen), формирующая подробную документацию по библиотеке в html-формате. Справка формируется на основе комментариев в исходных текстах, так что разработчики всегда имеют доступ к самой свежей и полной документации. 
12
-   С использованием MCK (Mirror Classes Kit - набор зеркальных классов) все прелести визуальной разработки программ в полной мере доступны и для разработчиков, использующих KOL. Дополнительно с MCK имеется возможность еще более уменьшать приложения, автоматически генерируя П-код виртуальной машины вместо Паскаль-кода для инициализации форм (см. подроблее: Collapse).
13
-----------------------------------
14
-
15
-Данный архив содержит самодостаточную часть библиотеки Key Objects Library: файл KOL.PAS. На странице (http://kolmck.net) возможно также загрузить дополнительные расширения, в том числе:
16
-
17
-MCK		- Mirror Classes Kit - полноценная визуальная среда для KOL
18
-xHelpGen	(~50K) - генератор html-справки на основе комментариев в исходном коде
19
-KolErr	(~20K) - "облегченная" (на 6К), но вполне фунциональная обработка исключений
20
-KOLEdb, KOLODBC, StrDb, TdkDbKol - расширения для работы с БД
21
-KOLWord	(~12K) - MS Word automation
22
-KolGif	(~20K) - поддержка анимированных gif-файлов
23
-KolJpegObj	(~127K) - поддержка JPEG
24
-KolOgl12	(~59K) - поддержка OpenGL	
25
-Service	(~30K) - написание NT сервисов в KOL
26
-KOLSocket	(~30K) - сокеты
27
-sysdcu	(~200K) - замена system.dcu, sysinit.dcu для Delphi5 (экономия еще 9К в .exe)
28
-HeapMM	(~1K) - альтернативный менеджер памяти
29
-
30
-...
31
-И так далее, список пополняется постоянно.
32
-
33
-__________________________________________________
34
-УСТАНОВКА И ПЕРЕУСТАНОВКА (УСТАНОВКА НОВОЙ ВЕРСИИ):
35
-
36
-1. При первой установке создать новую директорию (например, E:\KOL).
37
-
38
-2. Распаковать файлы из KOL.ZIP туда же. (При переустановке подтвердить замещение старых файлов новыми).
39
-
40
-4. Если Вы загрузили архив xhelpgen.zip, так же распаковывайте его в ту же директорию. Не забудьте прочитать прилагаемую к нему инструкцию.
41
-
42
-5. Если Вы загрузили архив SYSDCU.ZIP, создайте поддиректорию для него (например, E:\KOL\SYS) и распакуйте туда его содержимое. К нему так же прилагается своя инструкция.
43
-
44
-6. Инструкции по установке MCK (Mirror Classes Kit) см. в архиве MCK.ZIP.
45
-
46
-7. Аналогично для koledb, kolword и других дополнений.
47
-
48
-Примечание: для самого KOL не требуется создавать Package, т.к. KOL не имеет компонент времени разработки, требующих установки на палтру компонентов. См. пакет MCK, которое имеет такие компоненты, и позволяет разрабатывать приложения с использованием KOL, визуально.
49
--------------------------------------------------------------
50
-
51
-ЛИЦЕНЗИРОВАНИЕ.
52
-
53
-Данный параграф введен здесь, чтобы не переводить на русский язык лицензию, см. файл LICENSE.txt.
54
-
55
-На использование библиотеки в качестве инструмента для разработки исполнимых модулей (exe, dll и т.д.) не накладывается никаких ограничений. Нельзя продавать библиотеку полностью или частично. Нельзя распространять ее бесплатно, полностью или частично, без согласия автора и без ссылок на автора. В случае, если распространяется модифицированная библиотека, пользователи обязаны быть информированы о первоисточнике и о том, кто является автором оригинальной библиотеки, и как с ним связаться.
56
-
57
--------------------------------------------------------------
58
-
59
-http://kolmck.net 
60
-vk@kolmck.net
61
-Владимир Кладов

+ 0
- 1114
libwin/kolfpc/visual_xp_styles.inc
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 0
- 26
libwin/lcore/Makefile Parādīt failu

@@ -1,26 +0,0 @@
1
-all: lcoretest
2
-
3
-nomessages:
4
-	fpc -Sd -gl -dipv6 -dnomessages lcoretest.dpr
5
-
6
-lcoretest: *.pas *.inc lcoretest.dpr
7
-	fpc -Sd -gl -dipv6 lcoretest.dpr
8
-	
9
-clean:
10
-	-rm *.o
11
-	-rm *.ppu
12
-	-rm *.exe
13
-	-rm *.dcu
14
-	-rm lcoretest
15
-
16
-date := $(shell date +%Y%m%d)
17
-
18
-zip:
19
-	mkdir -p lcorewin32_$(date)
20
-	cp -a *.pas lcorewin32_$(date)
21
-	cp -a *.inc lcorewin32_$(date)
22
-	cp -a *.dpr lcorewin32_$(date)
23
-	cp -a Makefile lcorewin32_$(date)
24
-	-rm ../lcorewin32_$(date).zip
25
-	zip -r ../lcorewin32_$(date).zip lcorewin32_$(date)
26
-	rm -rf lcorewin32_$(date)

+ 0
- 148
libwin/lcore/bfifo.pas Parādīt failu

@@ -1,148 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-unit bfifo;
6
-{$ifdef fpc}
7
-  {$mode delphi}
8
-{$endif}
9
-
10
-interface
11
-
12
-uses blinklist,pgtypes;
13
-
14
-const
15
-  pagesize=1420;
16
-
17
-type
18
-  tfifo=class(tobject)
19
-  private
20
-    l:tlinklist;     {add to}
21
-    getl:tlinklist; {remove from}
22
-    ofs:integer;
23
-    getofs:integer;
24
-  public
25
-    size:integer;
26
-    procedure add(data:pointer;len:integer);
27
-    function get(var resultptr:pointer;len:integer):integer;
28
-    procedure del(len:integer);
29
-    constructor create;
30
-    destructor destroy; override;
31
-  end;
32
-
33
-
34
-implementation
35
-
36
-var
37
-  testcount:integer;
38
-
39
-{
40
-
41
-xx1..... add
42
-xxxxxxxx
43
-....2xxx delete
44
-
45
-1 ofs
46
-2 getofs
47
-
48
-}
49
-
50
-procedure tfifo.add;
51
-var
52
-  a:integer;
53
-  p:tlinklist;
54
-begin
55
-  if len <= 0 then exit;
56
-  inc(size,len);
57
-  while len > 0 do begin
58
-    p := l;
59
-    if ofs = pagesize then begin
60
-      p := tplinklist.create;
61
-      if getl = nil then getl := p;
62
-      getmem(tplinklist(p).p,pagesize);
63
-      inc(testcount);
64
-      linklistadd(l,p);
65
-      ofs := 0;
66
-    end;
67
-    a := pagesize - ofs;
68
-    if len < a then a := len;
69
-    move(data^,pointer(taddrint(tplinklist(p).p)+ofs)^,a);
70
-    inc(taddrint(data),a);
71
-    dec(len,a);
72
-    inc(ofs,a);
73
-  end;
74
-end;
75
-
76
-function tfifo.get;
77
-var
78
-  p:tlinklist;
79
-  a:integer;
80
-begin
81
-  if len > size then len := size;
82
-  if len <= 0 then begin
83
-    result := 0;
84
-    resultptr := nil;
85
-    exit;
86
-  end;
87
-  p := getl;
88
-  resultptr := pointer(taddrint(tplinklist(p).p)+getofs);
89
-  result := pagesize-getofs;
90
-  if result > len then result := len;
91
-end;
92
-
93
-procedure tfifo.del;
94
-var
95
-  a:integer;
96
-  p,p2:tlinklist;
97
-begin
98
-  if len <= 0 then exit;
99
-  p := getl;
100
-  if len > size then len := size;
101
-  dec(size,len);
102
-
103
-  if len = 0 then exit;
104
-
105
-  while len > 0 do begin
106
-    a := pagesize-getofs;
107
-    if a > len then a := len;
108
-    inc(getofs,a);
109
-    dec(len,a);
110
-    if getofs = pagesize then begin
111
-      p2 := p.prev;
112
-      freemem(tplinklist(p).p);
113
-      dec(testcount);
114
-      linklistdel(l,p);
115
-      p.destroy;
116
-      p := p2;
117
-      getl := p;
118
-      getofs := 0;
119
-    end;
120
-  end;
121
-
122
-  if size = 0 then begin
123
-    if assigned(l) then begin
124
-      p := l;
125
-      freemem(tplinklist(p).p);
126
-      dec(testcount);
127
-      linklistdel(l,p);
128
-      p.destroy;
129
-      getl := nil;
130
-    end;
131
-    ofs := pagesize;
132
-    getofs := 0;
133
-  end;
134
-end;
135
-
136
-constructor tfifo.create;
137
-begin
138
-  ofs := pagesize;
139
-  inherited create;
140
-end;
141
-
142
-destructor tfifo.destroy;
143
-begin
144
-  del(size);
145
-  inherited destroy;
146
-end;
147
-
148
-end.

+ 0
- 632
libwin/lcore/binipstuff.pas Parādīt failu

@@ -1,632 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-unit binipstuff;
6
-
7
-interface
8
-
9
-{$include lcoreconfig.inc}
10
-
11
-{$ifndef win32}
12
-{$ifdef ipv6}
13
-uses sockets;
14
-{$endif}
15
-{$endif}
16
-
17
-{$ifdef fpc}
18
-  {$mode delphi}
19
-{$endif}
20
-{$ifdef cpu386}{$define i386}{$endif}
21
-{$ifdef i386}{$define ENDIAN_LITTLE}{$endif}
22
-
23
-{$include uint32.inc}
24
-
25
-const
26
-  hexchars:array[0..15] of char='0123456789abcdef';
27
-  AF_INET=2;
28
-  {$ifdef win32}
29
-    AF_INET6=23;
30
-  {$else}
31
-    AF_INET6=10;
32
-  {$endif}
33
-
34
-type
35
-  {$ifdef ipv6}
36
-    
37
-    {$ifdef win32}
38
-      {$define want_Tin6_addr}
39
-    {$endif}
40
-    {$ifdef ver1_0}
41
-      {$define want_Tin6_addr}
42
-    {$endif}
43
-    {$ifdef want_Tin6_addr}
44
-      Tin6_addr = packed record
45
-        case byte of
46
-          0: (u6_addr8  : array[0..15] of byte);
47
-          1: (u6_addr16 : array[0..7] of Word);
48
-          2: (u6_addr32 : array[0..3] of uint32);
49
-          3: (s6_addr8  : array[0..15] of shortint);
50
-          4: (s6_addr   : array[0..15] of shortint);
51
-          5: (s6_addr16 : array[0..7] of smallint);
52
-          6: (s6_addr32 : array[0..3] of LongInt);
53
-      end;
54
-    {$endif}
55
-  {$endif}
56
-
57
-  tbinip=record
58
-    family:integer;
59
-    {$ifdef ipv6}
60
-      case integer of
61
-        0: (ip:longint);
62
-        1: (ip6:tin6_addr);
63
-    {$else}
64
-      ip:longint;
65
-    {$endif}
66
-  end;
67
-
68
-  {$ifdef win32}
69
-    TInetSockAddr = packed Record
70
-      family:Word;
71
-      port  :Word;
72
-      addr  :uint32;
73
-      pad   :array [1..8] of byte;
74
-    end;
75
-    {$ifdef ipv6}
76
-
77
-      TInetSockAddr6 = packed record
78
-        sin6_family: word;
79
-        sin6_port: word;
80
-        sin6_flowinfo: uint32;
81
-        sin6_addr: tin6_addr;
82
-        sin6_scope_id: uint32;
83
-      end;
84
-    {$endif}
85
-  {$endif}
86
-
87
-
88
-
89
-  {$ifdef ipv6}
90
-    {$ifdef ver1_0}
91
-      cuint16=word;
92
-      cuint32=dword;
93
-      sa_family_t=word;
94
-
      TInetSockAddr6 = packed record
95
-        sin6_family: word;
96
-        sin6_port: word;
97
-        sin6_flowinfo: uint32;
98
-        sin6_addr: tin6_addr;
99
-        sin6_scope_id: uint32;
100
-      end;
101
-    {$endif}
102
-  {$endif}
103
-  TinetSockAddrv = packed record
104
-    case integer of
105
-      0: (InAddr:TInetSockAddr);
106
-      {$ifdef ipv6}
107
-      1: (InAddr6:TInetSockAddr6);
108
-      {$endif}
109
-  end;
110
-  Pinetsockaddrv = ^Tinetsockaddrv;
111
-
112
-  type
113
-    tsockaddrin=TInetSockAddr;
114
-
115
-
116
-
117
-{
118
-bin IP list code, by beware
119
-while this is really just a string, on the interface side it must be treated
120
-as an opaque var which is passed as "var" when it needs to be modified}
121
-
122
-  tbiniplist=string;
123
-
124
-function biniplist_new:tbiniplist;
125
-procedure biniplist_add(var l:tbiniplist;ip:tbinip);
126
-function biniplist_getcount(const l:tbiniplist):integer;
127
-function biniplist_get(const l:tbiniplist;index:integer):tbinip;
128
-procedure biniplist_set(var l:tbiniplist;index:integer;ip:tbinip);
129
-procedure biniplist_setcount(var l:tbiniplist;newlen:integer);
130
-procedure biniplist_free(var l:tbiniplist);
131
-procedure biniplist_addlist(var l:tbiniplist;const l2:tbiniplist);
132
-function biniplist_tostr(const l:tbiniplist):string;
133
-function isbiniplist(const l:tbiniplist):boolean;
134
-
135
-function htons(w:word):word;
136
-function htonl(i:uint32):uint32;
137
-
138
-function ipstrtobin(const s:string;var binip:tbinip):boolean;
139
-function ipstrtobinf(const s:string):tbinip;
140
-function ipbintostr(const binip:tbinip):string;
141
-{$ifdef ipv6}
142
-function ip6bintostr(const bin:tin6_addr):string;
143
-function ip6strtobin(const s:string;var bin:tin6_addr):boolean;
144
-{$endif}
145
-
146
-function comparebinip(const ip1,ip2:tbinip):boolean;
147
-procedure maskbits(var binip:tbinip;bits:integer);
148
-function comparebinipmask(ip1,ip2:tbinip;bits:integer):boolean;
149
-
150
-procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer);
151
-
152
-{deprecated}
153
-function longip(s:string):longint;
154
-
155
-function needconverttov4(const ip:tbinip):boolean;
156
-procedure converttov4(var ip:tbinip);
157
-
158
-function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip;
159
-function makeinaddrv(addr:tbinip;port:string;var inaddr:tinetsockaddrv):integer;
160
-function inaddrsize(inaddr:tinetsockaddrv):integer;
161
-
162
-implementation
163
-
164
-uses sysutils;
165
-
166
-function htons(w:word):word;
167
-begin
168
-  {$ifdef ENDIAN_LITTLE}
169
-  result := ((w and $ff00) shr 8) or ((w and $ff) shl 8);
170
-  {$else}
171
-  result := w;
172
-  {$endif}
173
-end;
174
-
175
-function htonl(i:uint32):uint32;
176
-begin
177
-  {$ifdef ENDIAN_LITTLE}
178
-  result := (i shr 24) or (i shr 8 and $ff00) or (i shl 8 and $ff0000) or (i shl 24 and $ff000000);
179
-  {$else}
180
-  result := i;
181
-  {$endif}
182
-end;
183
-
184
-
185
-function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip;
186
-begin
187
-  result.family := inaddrv.inaddr.family;
188
-  if result.family = AF_INET then result.ip := inaddrv.inaddr.addr;
189
-  {$ifdef ipv6}
190
-  if result.family = AF_INET6 then result.ip6 := inaddrv.inaddr6.sin6_addr;
191
-  {$endif}
192
-end;
193
-
194
-function makeinaddrv(addr:tbinip;port:string;var inaddr:tinetsockaddrv):integer;
195
-begin
196
-  result := 0;
197
-{  biniptemp := forwardlookup(addr,10);}
198
-  fillchar(inaddr,sizeof(inaddr),0);
199
-  //writeln('converted address '+addr+' to binip '+ipbintostr(biniptemp));
200
-  if addr.family = AF_INET then begin
201
-    inAddr.InAddr.family:=AF_INET;
202
-    inAddr.InAddr.port:=htons(strtointdef(port,0));
203
-    inAddr.InAddr.addr:=addr.ip;
204
-    result := sizeof(tinetsockaddr);
205
-  end else
206
-  {$ifdef ipv6}
207
-  if addr.family = AF_INET6 then begin
208
-    inAddr.InAddr6.sin6_family:=AF_INET6;
209
-    inAddr.InAddr6.sin6_port:=htons(strtointdef(port,0));
210
-    inAddr.InAddr6.sin6_addr:=addr.ip6;
211
-    result := sizeof(tinetsockaddr6);
212
-  end;
213
-  {$endif}
214
-end;
215
-
216
-function inaddrsize(inaddr:tinetsockaddrv):integer;
217
-begin
218
-  {$ifdef ipv6}
219
-  if inaddr.inaddr.family = AF_INET6 then result := sizeof(tinetsockaddr6) else
220
-  {$endif}
221
-  result := sizeof(tinetsockaddr);
222
-end;
223
-
224
-{internal}
225
-{converts dotted v4 IP to longint. returns host endian order}
226
-function longip(s:string):longint;
227
-var
228
-  l:longint;
229
-  a,b:integer;
230
-function convertbyte(const s:string):integer;
231
-begin
232
-  result := strtointdef(s,-1);
233
-  if result < 0 then begin
234
-    result := -1;
235
-    exit;
236
-  end;
237
-  if result > 255 then begin
238
-    result := -1;
239
-    exit;
240
-  end;
241
-  {01 exception}
242
-  if (result <> 0) and (s[1] = '0') then begin
243
-    result := -1;
244
-    exit;
245
-  end;
246
-  {+1 exception}
247
-  if not (s[1] in ['0'..'9']) then begin
248
-    result := -1;
249
-    exit
250
-  end;
251
-end;
252
-
253
-begin
254
-  result := 0;
255
-  a := pos('.',s);
256
-  if a = 0 then exit;
257
-  b := convertbyte(copy(s,1,a-1));if (b < 0) then exit;
258
-  l := b shl 24;
259
-  s := copy(s,a+1,256);
260
-  a := pos('.',s);
261
-  if a = 0 then exit;
262
-  b := convertbyte(copy(s,1,a-1));if (b < 0) then exit;
263
-  l := l or b shl 16;
264
-  s := copy(s,a+1,256);
265
-  a := pos('.',s);
266
-  if a = 0 then exit;
267
-  b := convertbyte(copy(s,1,a-1));if (b < 0) then exit;
268
-  l := l or b shl 8;
269
-  s := copy(s,a+1,256);
270
-  b := convertbyte(copy(s,1,256));if (b < 0) then exit;
271
-  l := l or b;
272
-  result := l;
273
-end;
274
-
275
-
276
-function ipstrtobinf;
277
-begin
278
-  ipstrtobin(s,result);
279
-end;
280
-
281
-function ipstrtobin(const s:string;var binip:tbinip):boolean;
282
-begin
283
-  binip.family := 0;
284
-  result := false;
285
-  {$ifdef ipv6}
286
-  if pos(':',s) <> 0 then begin
287
-    {try ipv6. use builtin routine}
288
-    result := ip6strtobin(s,binip.ip6);
289
-    if result then binip.family := AF_INET6;
290
-    exit;
291
-  end;
292
-  {$endif}
293
-
294
-  {try v4}
295
-  binip.ip := htonl(longip(s));
296
-  if (binip.ip <> 0) or (s = '0.0.0.0') then begin
297
-    result := true;
298
-    binip.family := AF_INET;
299
-    exit;
300
-  end;
301
-end;
302
-
303
-function ipbintostr(const binip:tbinip):string;
304
-var
305
-  a:integer;
306
-begin
307
-  result := '';
308
-  {$ifdef ipv6}
309
-  if binip.family = AF_INET6 then begin
310
-    result := ip6bintostr(binip.ip6);
311
-  end else
312
-  {$endif}
313
-  if binip.family = AF_INET then begin
314
-    a := htonl(binip.ip);
315
-    result := inttostr(a shr 24)+'.'+inttostr((a shr 16) and $ff)+'.'+inttostr((a shr 8) and $ff)+'.'+inttostr(a and $ff);
316
-  end;
317
-end;
318
-
319
-
320
-{------------------------------------------------------------------------------}
321
-
322
-{$ifdef ipv6}
323
-
324
-{
325
-IPv6 address binary to/from string conversion routines
326
-written by beware (steendijk at xs4all dot nl)
327
-
328
-- implementation does not depend on other ipv6 code such as the tin6_addr type,
329
-  the parameter can also be untyped.
330
-- it is host endian neutral - binary format is aways network order
331
-- it supports compression of zeroes
332
-- it supports ::ffff:192.168.12.34 style addresses
333
-- they are made to do the Right Thing, more efficient implementations are possible
334
-}
335
-
336
-{fpc has hostaddrtostr6 and strtohostaddr6 but the later isnt implemented yet}
337
-
338
-
339
-function ip6bintostr(const bin:tin6_addr):string;
340
-{base16 with lowercase output}
341
-function makehex(w:word):string;
342
-begin
343
-  result := '';
344
-  if w >= 4096 then result := result + hexchars[w shr 12];
345
-  if w >= 256 then result := result + hexchars[w shr 8 and $f];
346
-  if w >= 16 then result := result + hexchars[w shr 4 and $f];
347
-  result := result + hexchars[w and $f];
348
-end;
349
-
350
-var
351
-  a,b,c,addrlen:integer;
352
-  runbegin,runlength:integer;
353
-  bytes:array[0..15] of byte absolute bin;
354
-  words:array[0..7] of word;
355
-  dwords:array[0..3] of integer absolute words;
356
-begin
357
-  for a := 0 to 7 do begin
358
-    words[a] := bytes[a shl 1] shl 8 or bytes[a shl 1 or 1];
359
-  end;
360
-  if (dwords[0] = 0) and (dwords[1] = 0) and (words[4] = 0) and (words[5] = $ffff) then begin
361
-    {::ffff:/96 exception: v4 IP}
362
-    addrlen := 6;
363
-  end else begin
364
-    addrlen := 8;
365
-  end;
366
-  {find longest run of zeroes}
367
-  runbegin := 0;
368
-  runlength := 0;
369
-  for a := 0 to addrlen-1 do begin
370
-    if words[a] = 0 then begin
371
-      c := 0;
372
-      for b := a to addrlen-1 do if words[b] = 0 then begin
373
-        inc(c);
374
-      end else break;
375
-      if (c > runlength) then begin
376
-        runlength := c;
377
-        runbegin := a;
378
-      end;
379
-    end;
380
-  end;
381
-  result := '';
382
-  for a := 0 to runbegin-1 do begin
383
-    if (a <> 0) then result := result + ':';
384
-    result := result + makehex(words[a]);
385
-  end;
386
-  if runlength > 0 then result := result + '::';
387
-  c := runbegin+runlength;
388
-  for a := c to addrlen-1 do begin
389
-    if (a > c) then result := result + ':';
390
-    result := result + makehex(words[a]);
391
-  end;
392
-  if addrlen = 6 then begin
393
-    result := result + ':'+inttostr(bytes[12])+'.'+inttostr(bytes[13])+'.'+inttostr(bytes[14])+'.'+inttostr(bytes[15]);
394
-  end;
395
-end;
396
-
397
-function ip6strtobin(const s:string;var bin:tin6_addr):boolean;
398
-var
399
-  a,b:integer;
400
-  fields:array[0..7] of string;
401
-  fieldcount:integer;
402
-  emptyfield:integer;
403
-  wordcount:integer;
404
-  words:array[0..7] of word;
405
-  bytes:array[0..15] of byte absolute bin;
406
-begin
407
-  result := false;
408
-  for a := 0 to 7 do fields[a] := '';
409
-  fieldcount := 0;
410
-  for a := 1 to length(s) do begin
411
-    if s[a] = ':' then inc(fieldcount) else fields[fieldcount] := fields[fieldcount] + s[a];
412
-    if fieldcount > 7 then exit;
413
-  end;
414
-  if fieldcount < 2 then exit;
415
-
416
-  {find the empty field (compressed zeroes), not counting the first and last there may be at most 1}
417
-  emptyfield := -1;
418
-  for a := 1 to fieldcount-1 do begin
419
-    if fields[a] = '' then begin
420
-      if emptyfield = -1 then emptyfield := a else exit;
421
-    end;
422
-  end;
423
-
424
-  {check if last field is a valid v4 IP}
425
-  a := longip(fields[fieldcount]);
426
-  if (a <> 0) or (fields[fieldcount] = '0.0.0.0') then wordcount := 6 else wordcount := 8;
427
-  {0:1:2:3:4:5:6.6.6.6
428
-   0:1:2:3:4:5:6:7}
429
-  fillchar(words,sizeof(words),0);
430
-  if wordcount = 6 then begin
431
-    if fieldcount > 6 then exit;
432
-    words[6] := a shr 16;
433
-    words[7] := a and $ffff;
434
-  end;
435
-  if emptyfield = -1 then begin
436
-    {no run length: must be an exact number of fields}
437
-    if wordcount = 6 then begin
438
-      if fieldcount <> 6 then exit;
439
-      emptyfield := 5;
440
-    end else if wordcount = 8 then begin
441
-      if fieldcount <> 7 then exit;
442
-      emptyfield := 7;
443
-    end else exit;
444
-  end;
445
-  for a := 0 to emptyfield do begin
446
-    if fields[a] = '' then b := 0 else b := strtointdef('$'+fields[a],-1);
447
-    if (b < 0) or (b > $ffff) then exit;
448
-    words[a] := b;
449
-  end;
450
-  if wordcount = 6 then dec(fieldcount);
451
-  for a := wordcount-1 downto wordcount-(fieldcount-emptyfield) do begin
452
-    b := a+fieldcount-wordcount+1;
453
-    if fields[b] = '' then b := 0 else b := strtointdef('$'+fields[b],-1);
454
-    if (b < 0) or (b > $ffff) then exit;
455
-    words[a] := b;
456
-  end;
457
-  for a := 0 to 7 do begin
458
-    bytes[a shl 1] := words[a] shr 8;
459
-    bytes[a shl 1 or 1] := words[a] and $ff;
460
-  end;
461
-  result := true;
462
-end;
463
-{$endif}
464
-
465
-function comparebinip(const ip1,ip2:tbinip):boolean;
466
-begin
467
-  if (ip1.ip <> ip2.ip) then begin
468
-    result := false;
469
-    exit;
470
-  end;
471
-
472
-  {$ifdef ipv6}
473
-  if ip1.family = AF_INET6 then begin
474
-    if (ip1.ip6.s6_addr32[1] <> ip2.ip6.s6_addr32[1])
475
-    or (ip1.ip6.s6_addr32[2] <> ip2.ip6.s6_addr32[2])
476
-    or (ip1.ip6.s6_addr32[3] <> ip2.ip6.s6_addr32[3]) then begin
477
-      result := false;
478
-      exit;
479
-    end;
480
-  end;
481
-  {$endif}
482
-
483
-  result := (ip1.family = ip2.family);
484
-end;
485
-
486
-procedure maskbits(var binip:tbinip;bits:integer);
487
-const
488
-  ipmax={$ifdef ipv6}15{$else}3{$endif};
489
-type tarr=array[0..ipmax] of byte;
490
-var
491
-  arr:^tarr;
492
-  a,b:integer;
493
-begin
494
-  arr := @binip.ip;
495
-  if bits = 0 then b := 0 else b := ((bits-1) div 8)+1;
496
-  for a := b to ipmax do begin
497
-    arr[a] := 0;
498
-  end;
499
-  if (bits and 7 <> 0) then begin
500
-    arr[bits shr 3] := arr[bits div 8] and not ($ff shr (bits and 7))
501
-  end;
502
-end;
503
-
504
-function comparebinipmask;
505
-begin
506
-  maskbits(ip1,bits);
507
-  maskbits(ip2,bits);
508
-  result := comparebinip(ip1,ip2);
509
-end;
510
-
511
-function needconverttov4(const ip:tbinip):boolean;
512
-begin
513
-  {$ifdef ipv6}
514
-  if ip.family = AF_INET6 then begin
515
-    if (ip.ip6.u6_addr32[0] = 0) and (ip.ip6.u6_addr32[1] = 0) and
516
-    (ip.ip6.u6_addr16[4] = 0) and (ip.ip6.u6_addr16[5] = $ffff) then begin
517
-      result := true;
518
-      exit;
519
-    end;
520
-  end;
521
-  {$endif}
522
-
523
-  result := false;
524
-end;
525
-
526
-{converts a binary IP to v4 if it is a v6 IP in the v4 range}
527
-procedure converttov4(var ip:tbinip);
528
-begin
529
-  {$ifdef ipv6}
530
-  if needconverttov4(ip) then begin
531
-    ip.family := AF_INET;
532
-    ip.ip := ip.ip6.s6_addr32[3];
533
-  end;
534
-  {$endif}
535
-end;
536
-
537
-{-----------biniplist stuff--------------------------------------------------}
538
-
539
-const
540
-  biniplist_prefix='bipl'#0;
541
-  //fpc 1.0.x doesn't seem to like use of length function in a constant 
542
-  //definition
543
-  //biniplist_prefixlen=length(biniplist_prefix);
544
-
  biniplist_prefixlen=5;
545
-  
546
-function biniplist_new:tbiniplist;
547
-begin
548
-  result := biniplist_prefix;
549
-end;
550
-
551
-procedure biniplist_add(var l:tbiniplist;ip:tbinip);
552
-var
553
-  a:integer;
554
-begin
555
-  a := biniplist_getcount(l);
556
-  biniplist_setcount(l,a+1);
557
-  biniplist_set(l,a,ip);
558
-end;
559
-
560
-function biniplist_getcount(const l:tbiniplist):integer;
561
-begin
562
-  result := (length(l)-biniplist_prefixlen) div sizeof(tbinip);
563
-end;
564
-
565
-function biniplist_get(const l:tbiniplist;index:integer):tbinip;
566
-begin
567
-  if (index >= biniplist_getcount(l)) then begin
568
-    fillchar(result,sizeof(result),0);
569
-    exit;
570
-  end;
571
-  move(l[index*sizeof(tbinip)+1+biniplist_prefixlen],result,sizeof(result));
572
-end;
573
-
574
-procedure biniplist_set(var l:tbiniplist;index:integer;ip:tbinip);
575
-begin
576
-  uniquestring(l);
577
-  move(ip,l[index*sizeof(tbinip)+1+biniplist_prefixlen],sizeof(ip));
578
-end;
579
-
580
-procedure biniplist_setcount(var l:tbiniplist;newlen:integer);
581
-begin
582
-  setlength(l,(sizeof(tbinip)*newlen)+biniplist_prefixlen);
583
-end;
584
-
585
-procedure biniplist_free(var l:tbiniplist);
586
-begin
587
-  l := '';
588
-end;
589
-
590
-procedure biniplist_addlist;
591
-begin
592
-  l := l + copy(l2,biniplist_prefixlen+1,maxlongint);
593
-end;
594
-
595
-function biniplist_tostr(const l:tbiniplist):string;
596
-var
597
-  a:integer;
598
-begin
599
-  result := '(';
600
-  for a := 0 to biniplist_getcount(l)-1 do begin
601
-    if result <> '(' then result := result + ', ';
602
-    result := result + ipbintostr(biniplist_get(l,a));
603
-  end;
604
-  result := result + ')';
605
-end;
606
-
607
-function isbiniplist(const l:tbiniplist):boolean;
608
-var
609
-  i : integer;
610
-begin
611
-  for i := 1 to biniplist_prefixlen do begin
612
-    if biniplist_prefix[i] <> l[i] then begin
613
-      result := false;
614
-      exit;
615
-    end;
616
-  end;
617
-  result := true;
618
-end;
619
-
620
-procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer);
621
-var
622
-  a:integer;
623
-  biniptemp:tbinip;
624
-begin
625
-  for a := biniplist_getcount(l2)-1 downto 0 do begin
626
-    biniptemp := biniplist_get(l2,a);
627
-    if (biniptemp.family = family) then biniplist_add(l,biniptemp);
628
-  end;
629
-end;
630
-
631
-
632
-end.

+ 0
- 106
libwin/lcore/blinklist.pas Parādīt failu

@@ -1,106 +0,0 @@
1
-
2
-{ Copyright (C) 2005 Bas Steendijk
3
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
4
-    which is included in the package
5
-      ----------------------------------------------------------------------------- }
6
-
7
-unit blinklist;
8
-{$ifdef fpc}
9
-  {$mode delphi}
10
-{$endif}
11
-
12
-
13
-interface
14
-
15
-type
16
-  tlinklist=class(tobject)
17
-    next:tlinklist;
18
-    prev:tlinklist;
19
-    constructor create;
20
-    destructor destroy; override;
21
-  end;
22
-
23
-  {linklist with 2 links}
24
-  tlinklist2=class(tlinklist)
25
-    next2:tlinklist2;
26
-    prev2:tlinklist2;
27
-  end;
28
-
29
-  {linklist with one pointer}
30
-  tplinklist=class(tlinklist)
31
-    p:pointer
32
-  end;
33
-
34
-  tstringlinklist=class(tlinklist)
35
-    s:string;
36
-  end;
37
-
38
-  tthing=class(tlinklist)
39
-    name:string;      {name/nick}
40
-    hashname:integer; {hash of name}
41
-  end;
42
-
43
-{
44
-adding new block to list (baseptr)
45
-}
46
-procedure linklistadd(var baseptr:tlinklist;newptr:tlinklist);
47
-procedure linklistdel(var baseptr:tlinklist;item:tlinklist);
48
-
49
-
50
-procedure linklist2add(var baseptr,newptr:tlinklist2);
51
-procedure linklist2del(var baseptr:tlinklist2;item:tlinklist2);
52
-
53
-var
54
-  linklistdebug:integer;
55
-
56
-implementation
57
-
58
-procedure linklistadd(var baseptr:tlinklist;newptr:tlinklist);
59
-var
60
-  p:tlinklist;
61
-begin
62
-  p := baseptr;
63
-  baseptr := newptr;
64
-  baseptr.prev := nil;
65
-  baseptr.next := p;
66
-  if p <> nil then p.prev := baseptr;
67
-end;
68
-
69
-procedure linklistdel(var baseptr:tlinklist;item:tlinklist);
70
-begin
71
-  if item = baseptr then baseptr := item.next;
72
-  if item.prev <> nil then item.prev.next := item.next;
73
-  if item.next <> nil then item.next.prev := item.prev;
74
-end;
75
-
76
-procedure linklist2add(var baseptr,newptr:tlinklist2);
77
-var
78
-  p:tlinklist2;
79
-begin
80
-  p := baseptr;
81
-  baseptr := newptr;
82
-  baseptr.prev2 := nil;
83
-  baseptr.next2 := p;
84
-  if p <> nil then p.prev2 := baseptr;
85
-end;
86
-
87
-procedure linklist2del(var baseptr:tlinklist2;item:tlinklist2);
88
-begin
89
-  if item = baseptr then baseptr := item.next2;
90
-  if item.prev2 <> nil then item.prev2.next2 := item.next2;
91
-  if item.next2 <> nil then item.next2.prev2 := item.prev2;
92
-end;
93
-
94
-constructor tlinklist.create;
95
-begin
96
-  inherited create;
97
-  inc(linklistdebug);
98
-end;
99
-
100
-destructor tlinklist.destroy;
101
-begin
102
-  dec(linklistdebug);
103
-  inherited destroy;
104
-end;
105
-
106
-end.

+ 0
- 101
libwin/lcore/bsearchtree.pas Parādīt failu

@@ -1,101 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-  
6
-{actually a hashtable. it was a tree in earlier versions}
7
-
8
-unit bsearchtree;
9
-
10
-interface
11
-
12
-uses blinklist;
13
-
14
-const
15
-  hashtable_size=$4000;
16
-
17
-type
18
-  thashitem=class(tlinklist)
19
-    hash:integer;
20
-    s:string;
21
-    p:pointer;
22
-  end;
23
-  thashtable=array[0..hashtable_size-1] of thashitem;
24
-  phashtable=^thashtable;
25
-
26
-{adds "item" to the tree for name "s". the name must not exist (no checking done)}
27
-procedure addtree(t:phashtable;s:string;item:pointer);
28
-
29
-{removes name "s" from the tree. the name must exist (no checking done)}
30
-procedure deltree(t:phashtable;s:string);
31
-
32
-{returns the item pointer for s, or nil if not found}
33
-function findtree(t:phashtable;s:string):pointer;
34
-
35
-implementation
36
-
37
-function makehash(s:string):integer;
38
-const
39
-  shifter=6;
40
-var
41
-  a,b:integer;
42
-begin
43
-  result := 0;
44
-  b := length(s);
45
-  for a := 1 to b do begin
46
-    result := (result shl shifter) xor byte(s[a]);
47
-  end;
48
-  result := (result xor result shr 16) and (hashtable_size-1);
49
-end;
50
-
51
-procedure addtree(t:phashtable;s:string;item:pointer);
52
-var
53
-  hash:integer;
54
-  p:thashitem;
55
-begin
56
-  hash := makehash(s);
57
-  p := thashitem.create;
58
-  p.hash := hash;
59
-  p.s := s;
60
-  p.p := item;
61
-  linklistadd(tlinklist(t[hash]),tlinklist(p));
62
-end;
63
-
64
-procedure deltree(t:phashtable;s:string);
65
-var
66
-  p,p2:thashitem;
67
-  hash:integer;
68
-begin
69
-  hash := makehash(s);
70
-  p := t[hash];
71
-  p2 := nil;
72
-  while p <> nil do begin
73
-    if p.s = s then begin
74
-      p2 := p;
75
-      break;
76
-    end;
77
-    p := thashitem(p.next);
78
-  end;
79
-  linklistdel(tlinklist(t[hash]),tlinklist(p2));
80
-  p2.destroy;
81
-end;
82
-
83
-
84
-function findtree(t:phashtable;s:string):pointer;
85
-var
86
-  p:thashitem;
87
-  hash:integer;
88
-begin
89
-  result := nil;
90
-  hash := makehash(s);
91
-  p := t[hash];
92
-  while p <> nil do begin
93
-    if p.s = s then begin
94
-      result := p.p;
95
-      exit;
96
-    end;
97
-    p := thashitem(p.next);
98
-  end;
99
-end;
100
-
101
-end.

+ 0
- 593
libwin/lcore/btime.pas Parādīt failu

@@ -1,593 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-{
6
-this unit returns unix timestamp with seconds and microseconds (as float)
7
-works on windows/delphi, and on freepascal on unix.
8
-}
9
-
10
-
11
-unit btime;
12
-
13
-interface
14
-
15
-type
16
-  float=extended;
17
-
18
-const
19
-  colorburst=39375000/11;  {3579545.4545....}
20
-
21
-var
22
-  timezone:integer;
23
-  timezonestr:string;
24
-  irctime,unixtime:integer;
25
-  tickcount:integer;
26
-  settimebias:integer;
27
-  performancecountfreq:extended;
28
-
29
-function irctimefloat:float;
30
-function irctimeint:integer;
31
-
32
-function unixtimefloat:float;
33
-function unixtimeint:integer;
34
-
35
-function wintimefloat:float;
36
-
37
-procedure settime(newtime:integer);
38
-procedure gettimezone;
39
-procedure timehandler;
40
-procedure init;
41
-
42
-function timestring(i:integer):string;
43
-function timestrshort(i:integer):string;
44
-
45
-{$ifdef win32}
46
-function unixtimefloat_systemtime:float;
47
-{$endif}
48
-
49
-function oletounixfloat(t:float):float;
50
-function oletounix(t:tdatetime):integer;
51
-function unixtoole(i:integer):tdatetime;
52
-
53
-{$ifdef win32}
54
-function mmtimefloat:float;
55
-function qpctimefloat:float;
56
-{$endif}
57
-
58
-const
59
-  mmtime_driftavgsize=32;
60
-  mmtime_warmupnum=4;
61
-  mmtime_warmupcyclelength=15;
62
-var
63
-  //this flag is to be set when btime has been running long enough to stabilise
64
-  warmup_finished:boolean;
65
-
66
-  timefloatbias:float;
67
-  ticks_freq:float=0;
68
-  ticks_freq2:float=0;
69
-  ticks_freq_known:boolean=false;
70
-  lastunixtimefloat:float=0;
71
-  lastsynctime:float=0;
72
-  lastsyncbias:float=0;
73
-
74
-  mmtime_last:integer=0;
75
-  mmtime_wrapadd:float;
76
-  mmtime_lastsyncmm:float=0;
77
-  mmtime_lastsyncqpc:float=0;
78
-  mmtime_drift:float=1;
79
-  mmtime_lastresult:float;
80
-  mmtime_nextdriftcorrection:float;
81
-  mmtime_driftavg:array[0..mmtime_driftavgsize] of float;
82
-  mmtime_synchedqpc:boolean;
83
-
84
-  mmtime_prev_drift:float;
85
-  mmtime_prev_lastsyncmm:float;
86
-  mmtime_prev_lastsyncqpc:float;
87
-
88
-implementation
89
-
90
-{$ifdef fpc}
91
-  {$mode delphi}
92
-{$endif}
93
-
94
-uses
95
-  {$ifdef UNIX}
96
-    {$ifdef VER1_0}
97
-      linux,
98
-    {$else}
99
-      baseunix,unix,unixutil, {needed for 2.0.2}
100
-    {$endif}
101
-  {$else}
102
-    windows,unitsettc,mmsystem,
103
-  {$endif}
104
-  sysutils;
105
-
106
-  {$include unixstuff.inc}
107
-
108
-
109
-const
110
-  daysdifference=25569;
111
-
112
-function oletounixfloat(t:float):float;
113
-begin
114
-  t := (t - daysdifference) * 86400;
115
-  result := t;
116
-end;
117
-
118
-function oletounix(t:tdatetime):integer;
119
-begin
120
-  result := trunc(oletounixfloat(t));
121
-end;
122
-
123
-function unixtoole(i:integer):tdatetime;
124
-begin
125
-  result := ((i)/86400)+daysdifference;
126
-end;
127
-
128
-const
129
-  highdwordconst=65536.0 * 65536.0;
130
-
131
-function utrunc(f:float):integer;
132
-{converts float to integer, in 32 bits unsigned range}
133
-begin
134
-  if f >= (highdwordconst/2) then f := f - highdwordconst;
135
-  result := trunc(f);
136
-end;
137
-
138
-function uinttofloat(i:integer):float;
139
-{converts 32 bits unsigned integer to float}
140
-begin
141
-  result := i;
142
-  if result < 0 then result := result + highdwordconst;
143
-end;
144
-
145
-{$ifdef unix}
146
-{-----------------------------------------*nix/freepascal code to read time }
147
-
148
-function unixtimefloat:float;
149
-var
150
-  tv:ttimeval;
151
-begin
152
-  gettimeofday(tv);
153
-  result := tv.tv_sec+(tv.tv_usec/1000000);
154
-end;
155
-
156
-function wintimefloat:extended;
157
-begin
158
-  result := unixtimefloat;
159
-end;
160
-
161
-function unixtimeint:integer;
162
-var
163
-  tv:ttimeval;
164
-begin
165
-  gettimeofday(tv);
166
-  result := tv.tv_sec;
167
-end;
168
-
169
-{$else} {delphi 3}
170
-{------------------------------ windows/delphi code to read time}
171
-
172
-{
173
-time float: gettickcount
174
-resolution: 9x: ~55 ms NT: 1/64th of a second
175
-guarantees: continuous without any jumps
176
-frequency base: same as system clock.
177
-epoch: system boot
178
-note: if called more than once per 49.7 days, 32 bits wrapping is compensated for and it keeps going on.
179
-note: i handle the timestamp as signed integer, but with the wrap compensation that works as well, and is faster
180
-}
181
-
182
-function mmtimefloat:float;
183
-const
184
-  wrapduration=highdwordconst * 0.001;
185
-var
186
-  i:integer;
187
-begin
188
-  i := gettickcount; {timegettime}
189
-  if i < mmtime_last then begin
190
-    mmtime_wrapadd := mmtime_wrapadd + wrapduration;
191
-  end;
192
-  mmtime_last := i;
193
-  result := mmtime_wrapadd + i * 0.001;
194
-
195
-  if (ticks_freq <> 0) and ticks_freq_known then result := int((result / ticks_freq)+0.5) * ticks_freq; //turn the float into an exact multiple of 1/64th sec to improve accuracy of things using this
196
-end;
197
-
198
-procedure measure_ticks_freq;
199
-var
200
-  f,g:float;
201
-  o:tosversioninfo;
202
-  isnt:boolean;
203
-  is9x:boolean;
204
-begin
205
-  if (performancecountfreq = 0) then qpctimefloat;
206
-  ticks_freq_known := false;
207
-  settc;
208
-  f := mmtimefloat;
209
-  repeat g := mmtimefloat until g > f;
210
-  unsettc;
211
-  f := g - f;
212
-  fillchar(o,sizeof(o),0);
213
-  o.dwOSVersionInfoSize := sizeof(o);
214
-  getversionex(o);
215
-  isnt := o.dwPlatformId = VER_PLATFORM_WIN32_NT;
216
-  is9x := o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
217
-
218
-  ticks_freq2 := f;
219
-  mmtime_synchedqpc := false;
220
-  {
221
-  NT 64 Hz
222
-  identify mode as: nt64
223
-  QPC rate: either 3579545 or TSC freq
224
-  QPC synched to gettickcount: no
225
-  duration between 2 ticks is constant: yes
226
-  gettickcount tick duration: 64 Hz
227
-  }
228
-  if (f >= 0.014) and (f <= 0.018) and isnt then begin
229
-    ticks_freq_known := true;
230
-    ticks_freq := 1/64;
231
-    mmtime_synchedqpc := false;
232
-  end;
233
-
234
-  {
235
-  NT 100 Hz
236
-  identify mode as: nt100
237
-  QPC rate: 1193182
238
-  QPC synched to gettickcount: yes
239
-  duration between 2 ticks is constant: no?
240
-  gettickcount tick duration: ~99.85 Hz
241
-  }
242
-  if (performancecountfreq = 1193182) and (f >= 0.008) and (f <= 0.012) and isnt then begin
243
-    ticks_freq_known := true;
244
-    ticks_freq2 := 11949 / (colorburst / 3);
245
-   //  ticks_freq2 := 11949 / 1193182;
246
-    ticks_freq := 0;
247
-    {the ticks freq should be very close to the real one but if it's not exact, it will cause drift and correction jumps}
248
-    mmtime_synchedqpc := true;
249
-  end;
250
-
251
-  {9x}
252
-  if (performancecountfreq = 1193182) and (g >= 0.050) and (g <= 0.060) then begin
253
-    ticks_freq_known := true;
254
-    ticks_freq := 65536 / (colorburst / 3);
255
-    mmtime_synchedqpc := true;
256
-  end;
257
-  ticks_freq_known := true;
258
-  if ticks_freq <> 0 then ticks_freq2 := ticks_freq;
259
-//  writeln(formatfloat('0.000000',ticks_freq));
260
-end;
261
-
262
-{
263
-time float: QueryPerformanceCounter
264
-resolution: <1us
265
-guarantees: can have forward jumps depending on hardware. can have forward and backwards jitter on dual core.
266
-frequency base: on NT, not the system clock, drifts compared to it.
267
-epoch: system boot
268
-}
269
-function qpctimefloat:extended;
270
-var
271
-  p:packed record
272
-    lowpart:longint;
273
-    highpart:longint
274
-  end;
275
-  p2:tlargeinteger absolute p;
276
-  e:extended;
277
-begin
278
-  if performancecountfreq = 0 then begin
279
-    QueryPerformancefrequency(p2);
280
-    e := p.lowpart;
281
-    if e < 0 then e := e + highdwordconst;
282
-    performancecountfreq := ((p.highpart*highdwordconst)+e);
283
-  end;
284
-  queryperformancecounter(p2);
285
-  e := p.lowpart;
286
-  if e < 0 then e := e + highdwordconst;
287
-
288
-  result := ((p.highpart*highdwordconst)+e)/performancecountfreq;
289
-end;
290
-
291
-{
292
-time float: QPC locked to gettickcount
293
-resolution: <1us
294
-guarantees: continuous without any jumps
295
-frequency base: same as system clock.
296
-epoch: system boot
297
-}
298
-
299
-function mmqpctimefloat:float;
300
-const
301
-  maxretries=5;
302
-  margin=0.002;
303
-var
304
-  jump:float;
305
-  mm,f,qpc,newdrift,f1,f2:float;
306
-  qpcjumped:boolean;
307
-  a,b,c:integer;
308
-  retrycount:integer;
309
-begin
310
-  if not ticks_freq_known then measure_ticks_freq;
311
-  retrycount := maxretries;
312
-
313
-  qpc := qpctimefloat;
314
-  mm := mmtimefloat;
315
-  f := (qpc - mmtime_lastsyncqpc) * mmtime_drift + mmtime_lastsyncmm;
316
-  //writeln('XXXX ',formatfloat('0.000000',qpc-mm));
317
-  qpcjumped := ((f-mm) > ticks_freq2+margin) or ((f-mm) < -margin);
318
-//  if qpcjumped then writeln('qpc jumped ',(f-mm));
319
-  if ((qpc > mmtime_nextdriftcorrection) and not mmtime_synchedqpc) or qpcjumped then begin
320
-
321
-    mmtime_nextdriftcorrection := qpc + 1;
322
-    repeat
323
-      mmtime_prev_drift := mmtime_drift;
324
-      mmtime_prev_lastsyncmm := mmtime_lastsyncmm;
325
-      mmtime_prev_lastsyncqpc := mmtime_lastsyncqpc;
326
-
327
-      mm := mmtimefloat;
328
-      dec(retrycount);
329
-      settc;
330
-      result := qpctimefloat;
331
-      f := mmtimefloat;
332
-      repeat
333
-        if f = mm then result := qpctimefloat;
334
-        f := mmtimefloat
335
-      until f > mm;
336
-      qpc := qpctimefloat;
337
-
338
-      unsettc;
339
-      if (qpc > result + 0.0001) then begin
340
-        continue;
341
-      end;
342
-      mm := f;
343
-
344
-      if (mmtime_lastsyncqpc <> 0) and not qpcjumped then begin
345
-        newdrift := (mm - mmtime_lastsyncmm) / (qpc - mmtime_lastsyncqpc);
346
-        mmtime_drift := newdrift;
347
-     {   writeln('raw drift: ',formatfloat('0.00000000',mmtime_drift));}
348
-        move(mmtime_driftavg[0],mmtime_driftavg[1],sizeof(mmtime_driftavg[0])*high(mmtime_driftavg));
349
-        mmtime_driftavg[0] := mmtime_drift;
350
-
351
-{        write('averaging drift ',formatfloat('0.00000000',mmtime_drift),' -> ');}
352
-{        mmtime_drift := 0;}
353
-        b := 0;
354
-        for a := 0 to high(mmtime_driftavg) do begin
355
-          if mmtime_driftavg[a] <> 0 then inc(b);
356
-{          mmtime_drift := mmtime_drift + mmtime_driftavg[a];}
357
-        end;
358
-{        mmtime_drift := mmtime_drift / b;}
359
-        if (b = 1) then a := 5 else if (b = 2) then a := 15 else if (b = 3) then a := 30 else if (b = 4) then a := 60 else if (b = 5) then a := 120 else if (b >= 5) then a := 120;
360
-        mmtime_nextdriftcorrection := qpc + a;
361
-        if (b >= 2) then warmup_finished := true;
362
-{        writeln(formatfloat('0.00000000',mmtime_drift));}
363
-       if mmtime_synchedqpc then mmtime_drift := 1;
364
-      end;
365
-
366
-      mmtime_lastsyncqpc := qpc;
367
-      mmtime_lastsyncmm := mm;
368
-  {   writeln(formatfloat('0.00000000',mmtime_drift));}
369
-      break;
370
-    until false;
371
-
372
-
373
-    qpc := qpctimefloat;
374
-
375
-    result := (qpc - mmtime_lastsyncqpc) * mmtime_drift + mmtime_lastsyncmm;
376
-    f := (qpc - mmtime_prev_lastsyncqpc) * mmtime_prev_drift + mmtime_prev_lastsyncmm;
377
-
378
-    jump := result-f;
379
-    {writeln('jump ',formatfloat('0.000000',jump),'   drift ',formatfloat('0.00000000',mmtime_drift),' duration ',formatfloat('0.000',(mmtime_lastsyncqpc-mmtime_prev_lastsyncqpc)),' ',formatfloat('0.00000000',jump/(mmtime_lastsyncqpc-mmtime_prev_lastsyncqpc)));}
380
-
381
-    f := result;
382
-  end;
383
-
384
-  result := f;
385
-
386
-  if (result < mmtime_lastresult) then result := mmtime_lastresult + 0.000001;
387
-  mmtime_lastresult := result;
388
-end;
389
-
390
-{ free pascals tsystemtime is incomaptible with windows api calls
391
- so we declare it ourselves - plugwash
392
-}
393
-{$ifdef fpc}
394
-type
395
-  TSystemTime = record
396
-     wYear: Word;
397
-     wMonth: Word;
398
-     wDayOfWeek: Word;
399
-     wDay: Word;
400
-     wHour: Word;
401
-     wMinute: Word;
402
-     wSecond: Word;
403
-     wMilliseconds: Word;
404
-  end;
405
- {$endif}
406
-function Date_utc: extended;
407
-var
408
-  SystemTime: TSystemTime;
409
-begin
410
-  {$ifdef fpc}
411
-    GetsystemTime(@SystemTime);
412
-  {$else}
413
-    GetsystemTime(SystemTime);
414
-  {$endif}
415
-  with SystemTime do Result := EncodeDate(wYear, wMonth, wDay);
416
-end;
417
-
418
-function Time_utc: extended;
419
-var
420
-  SystemTime: TSystemTime;
421
-begin
422
-  {$ifdef fpc}
423
-    GetsystemTime(@SystemTime);
424
-  {$else}
425
-    GetsystemTime(SystemTime);
426
-  {$endif}
427
-  with SystemTime do
428
-    Result := EncodeTime(wHour, wMinute, wSecond, wMilliSeconds);
429
-end;
430
-
431
-function Now_utc: extended;
432
-begin
433
-  Result := round(Date_utc) + Time_utc;
434
-end;
435
-
436
-function unixtimefloat_systemtime:float;
437
-begin
438
-  {result := oletounixfloat(now_utc);}
439
-
440
-  {this method gives exactly the same result with extended precision, but is less sensitive to float rounding in theory}
441
-  result := oletounixfloat(int(date_utc+0.5))+time_utc*86400;
442
-end;
443
-
444
-function wintimefloat:extended;
445
-begin
446
-  result := mmqpctimefloat;
447
-end;
448
-
449
-function unixtimefloat:float;
450
-const
451
-  margin = 0.0012;
452
-var
453
-  f,g,h:float;
454
-begin
455
-  result := wintimefloat+timefloatbias;
456
-  f := result-unixtimefloat_systemtime;
457
-  if ((f > ticks_freq2+margin) or (f < -margin)) or (timefloatbias = 0) then begin
458
-//    writeln('unixtimefloat init');
459
-    f := unixtimefloat_systemtime;
460
-    settc;
461
-    repeat g := unixtimefloat_systemtime; h := wintimefloat until g > f;
462
-    unsettc;
463
-    timefloatbias := g-h;
464
-    result := unixtimefloat;
465
-  end;
466
-
467
-  {for small changes backwards, guarantee no steps backwards}
468
-  if (result <= lastunixtimefloat) and (result > lastunixtimefloat-1.5) then result := lastunixtimefloat + 0.0000001;
469
-  lastunixtimefloat := result;
470
-end;
471
-
472
-function unixtimeint:integer;
473
-begin
474
-  result := trunc(unixtimefloat);
475
-end;
476
-
477
-{$endif}
478
-{-----------------------------------------------end of platform specific}
479
-
480
-function irctimefloat:float;
481
-begin
482
-  result := unixtimefloat+settimebias;
483
-end;
484
-
485
-function irctimeint:integer;
486
-begin
487
-  result := unixtimeint+settimebias;
488
-end;
489
-
490
-
491
-procedure settime(newtime:integer);
492
-var
493
-  a:integer;
494
-begin
495
-  a := irctimeint-settimebias;
496
-  if newtime = 0 then settimebias := 0 else settimebias := newtime-a;
497
-
498
-  irctime := irctimeint;
499
-end;
500
-
501
-procedure timehandler;
502
-begin
503
-  if unixtime = 0 then init;
504
-  unixtime := unixtimeint;
505
-  irctime := irctimeint;
506
-  if unixtime and 63 = 0 then begin
507
-    {update everything, apply timezone changes, clock changes, etc}
508
-    gettimezone;
509
-    timefloatbias := 0;
510
-    unixtime := unixtimeint;
511
-    irctime := irctimeint;
512
-  end;
513
-end;
514
-
515
-
516
-procedure gettimezone;
517
-var
518
-  {$ifdef UNIX}
519
-    {$ifndef ver1_9_4}
520
-      {$ifndef ver1_0}
521
-        {$define above194}
522
-      {$endif}
523
-    {$endif}
524
-    {$ifndef above194}
525
-      hh,mm,ss:word;
526
-    {$endif}
527
-  {$endif}
528
-  l:integer;
529
-begin
530
-  {$ifdef UNIX}
531
-    {$ifdef above194}
532
-      timezone := tzseconds;
533
-    {$else}
534
-      gettime(hh,mm,ss);
535
-      timezone := (longint(hh) * 3600 + mm * 60 + ss) - (unixtimeint mod 86400);
536
-    {$endif}
537
-  {$else}
538
-  timezone := round((now-now_utc)*86400);
539
-  {$endif}
540
-
541
-  while timezone > 43200 do dec(timezone,86400);
542
-  while timezone < -43200 do inc(timezone,86400);
543
-
544
-  if timezone >= 0 then timezonestr := '+' else timezonestr := '-';
545
-  l := abs(timezone) div 60;
546
-  timezonestr := timezonestr + char(l div 600 mod 10+48)+char(l div 60 mod 10+48)+':'+char(l div 10 mod 6+48)+char(l mod 10+48);
547
-end;
548
-
549
-function timestrshort(i:integer):string;
550
-const
551
-  weekday:array[0..6] of string[4]=('Thu','Fri','Sat','Sun','Mon','Tue','Wed');
552
-  month:array[0..11] of string[4]=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
553
-var
554
-  y,m,d,h,min,sec,ms:word;
555
-  t:tdatetime;
556
-begin
557
-  t := unixtoole(i+timezone);
558
-  decodedate(t,y,m,d);
559
-  decodetime(t,h,min,sec,ms);
560
-  result := weekday[(i+timezone) div 86400 mod 7]+' '+month[m-1]+' '+inttostr(d)+' '+
561
-  inttostr(h div 10)+inttostr(h mod 10)+':'+inttostr(min div 10)+inttostr(min mod 10)+':'+inttostr(sec div 10)+inttostr(sec mod 10)+' '+
562
-  inttostr(y);
563
-end;
564
-
565
-function timestring(i:integer):string;
566
-const
567
-  weekday:array[0..6] of string[10]=('Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday');
568
-  month:array[0..11] of string[10]=('January','February','March','April','May','June','July','August','September','October','November','December');
569
-var
570
-  y,m,d,h,min,sec,ms:word;
571
-  t:tdatetime;
572
-begin
573
-  t := unixtoole(i+timezone);
574
-  decodedate(t,y,m,d);
575
-  decodetime(t,h,min,sec,ms);
576
-  result := weekday[(i+timezone) div 86400 mod 7]+' '+month[m-1]+' '+inttostr(d)+' '+inttostr(y)+' -- '+
577
-  inttostr(h div 10)+inttostr(h mod 10)+':'+inttostr(min div 10)+inttostr(min mod 10)+':'+inttostr(sec div 10)+inttostr(sec mod 10)+' '+
578
-  timezonestr;
579
-end;
580
-
581
-procedure init;
582
-begin
583
-  {$ifdef win32}timebeginperiod(1);{$endif} //ensure stable unchanging clock
584
-  fillchar(mmtime_driftavg,sizeof(mmtime_driftavg),0);
585
-  settimebias := 0;
586
-  gettimezone;
587
-  unixtime := unixtimeint;
588
-  irctime := irctimeint;
589
-end;
590
-
591
-initialization init;
592
-
593
-end.

+ 0
- 394
libwin/lcore/dnsasync.pas Parādīt failu

@@ -1,394 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-//FIXME: this code only ever seems to use one dns server for a request and does
7
-//not seem to have any form of retry code.
8
-
9
-unit dnsasync;
10
-
11
-interface
12
-
13
-uses
14
-  {$ifdef win32}
15
-    dnswin,
16
-  {$endif}
17
-  lsocket,lcore,
18
-  classes,binipstuff,dnscore,btime,lcorernd;
19
-
20
-{$include lcoreconfig.inc}
21
-
22
-const
23
-  numsock=1{$ifdef ipv6}+1{$endif};
24
-
25
-type
26
-
27
-  //after completion or cancelation a dnswinasync may be reused
28
-  tdnsasync=class(tcomponent)
29
-
30
-  private
31
-    //made a load of stuff private that does not appear to be part of the main
32
-    //public interface. If you make any of it public again please consider the
33
-    //consequences when using windows dns. --plugwash.
34
-    sockets: array[0..numsock-1] of tlsocket;
35
-
36
-    states: array[0..numsock-1] of tdnsstate;
37
-
38
-    destinations: array[0..numsock-1] of tbinip;
39
-
40
-    dnsserverids : array[0..numsock-1] of integer;
41
-    startts:double;
42
-    {$ifdef win32}
43
-      dwas : tdnswinasync;
44
-    {$endif}
45
-
46
-    numsockused : integer;
47
-    fresultlist : tbiniplist;
48
-    requestaf : integer;
49
-    procedure asyncprocess(socketno:integer);
50
-    procedure receivehandler(sender:tobject;error:word);
51
-    function sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean;
52
-    {$ifdef win32}
53
-      procedure winrequestdone(sender:tobject;error:word);
54
-    {$endif}
55
-
56
-  public
57
-    onrequestdone:tsocketevent;
58
-
59
-    //addr and port allow the application to specify a dns server specifically
60
-    //for this dnsasync object. This is not a reccomended mode of operation
61
-    //because it limits the app to one dns server but is kept for compatibility
62
-    //and special uses.
63
-    addr,port:string;
64
-
65
-    overrideaf : integer;
66
-
67
-    procedure cancel;//cancel an outstanding dns request
68
-    function dnsresult:string; //get result of dnslookup as a string
69
-    procedure dnsresultbin(var binip:tbinip); //get result of dnslookup as a tbinip
70
-    property dnsresultlist : tbiniplist read fresultlist;
71
-    procedure forwardlookup(const name:string); //start forward lookup,
72
-                                                //preffering ipv4
73
-    procedure reverselookup(const binip:tbinip); //start reverse lookup
74
-    procedure customlookup(const name:string;querytype:integer); //start custom type lookup
75
-
76
-    constructor create(aowner:tcomponent); override;
77
-    destructor destroy; override;
78
-
79
-  end;
80
-
81
-implementation
82
-
83
-uses sysutils;
84
-
85
-constructor tdnsasync.create;
86
-begin
87
-  inherited create(aowner);
88
-  dnsserverids[0] := -1;
89
-  sockets[0] := twsocket.create(self);
90
-  sockets[0].tag := 0;
91
-  {$ifdef ipv6}
92
-    dnsserverids[1] := -1;
93
-    sockets[1] := twsocket.Create(self);
94
-    sockets[1].tag := 1;
95
-  {$endif}
96
-end;
97
-
98
-destructor tdnsasync.destroy;
99
-var
100
-  socketno : integer;
101
-begin
102
-  for socketno := 0 to numsock -1 do begin
103
-    if dnsserverids[socketno] >= 0 then begin
104
-      reportlag(dnsserverids[socketno],-1);
105
-      dnsserverids[socketno] := -1;
106
-    end;
107
-    sockets[socketno].release;
108
-    setstate_request_init('',states[socketno]);
109
-  end;
110
-  inherited destroy;
111
-end;
112
-
113
-procedure tdnsasync.receivehandler(sender:tobject;error:word);
114
-var
115
-  socketno : integer;
116
-  Src    : TInetSockAddrV;
117
-  SrcLen : Integer;
118
-  fromip:tbinip;
119
-  fromport:string;
120
-begin
121
-  socketno := tlsocket(sender).tag;
122
-  //writeln('got a reply on socket number ',socketno);
123
-  fillchar(states[socketno].recvpacket,sizeof(states[socketno].recvpacket),0);
124
-
125
-  SrcLen := SizeOf(Src);
126
-  states[socketno].recvpacketlen := twsocket(sender).ReceiveFrom(@(states[socketno].recvpacket), SizeOf(states[socketno].recvpacket), Src, SrcLen);
127
-
128
-  fromip := inaddrvtobinip(Src);
129
-  fromport := inttostr(htons(src.InAddr.port));
130
-
131
-  if ((not comparebinip(fromip,destinations[socketno])) or (fromport <> port)) then begin
132
-   // writeln('dnsasync received from wrong IP:port ',ipbintostr(fromip),'#',fromport,', expected ',ipbintostr(destinations[socketno]),'#',port);
133
-    exit;
134
-  end;
135
-
136
-  states[socketno].parsepacket := true;
137
-  if states[socketno].resultaction <> action_done then begin
138
-    //we ignore packets that come after we are done
139
-    if dnsserverids[socketno] >= 0 then begin
140
-      reportlag(dnsserverids[socketno],trunc((unixtimefloat-startts)*1000000));
141
-      dnsserverids[socketno] := -1;
142
-    end;
143
-  {  writeln('received reply');}
144
-
145
-    asyncprocess(socketno);
146
-    //writeln('processed it');
147
-  end else begin
148
-    //writeln('ignored it because request is done');
149
-  end;
150
-end;
151
-
152
-function tdnsasync.sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean;
153
-var
154
-  destination : string;
155
-  inaddr : tinetsockaddrv;
156
-  trytolisten:integer;
157
-begin
158
-{  writeln('sendquery ',decodename(state.packet,state.packetlen,12,0,a),' ',state.requesttype);}
159
-  //writeln('trying to send query on socket number ',socketno);
160
-  result := false;
161
-  if len = 0 then exit; {no packet}
162
-  if sockets[socketno].state <> wsconnected then begin
163
-    startts := unixtimefloat;
164
-    if port = '' then port := '53';
165
-    sockets[socketno].Proto := 'udp';
166
-    sockets[socketno].ondataavailable := receivehandler;
167
-
168
-    {we are going to bind on a random local port for the DNS request, against the kaminsky attack
169
-    there is a small chance that we're trying to bind on an already used port, so retry a few times}
170
-    for trytolisten := 3 downto 0 do begin
171
-      try
172
-        sockets[socketno].port := inttostr(1024 + randominteger(65536 - 1024));
173
-        sockets[socketno].listen;
174
-      except
175
-        {writeln('failed to listen ',sockets[socketno].localport,' ',trytolisten);}
176
-        if (trytolisten = 0) then begin
177
-          result := false;
178
-          exit;
179
-        end;
180
-      end;
181
-    end;
182
-
183
-  end;
184
-  if addr <> '' then begin
185
-    dnsserverids[socketno] := -1;
186
-    destination := addr
187
-  end else begin
188
-    destination := getcurrentsystemnameserver(dnsserverids[socketno]);
189
-  end;
190
-  destinations[socketno] := ipstrtobinf(destination);
191
-
192
-  {$ifdef ipv6}{$ifdef win32}
193
-  if destinations[socketno].family = AF_INET6 then if (requestaf = useaf_default) then requestaf := useaf_preferv6;
194
-  {$endif}{$endif}
195
-
196
-  makeinaddrv(destinations[socketno],port,inaddr);
197
-  sockets[socketno].sendto(inaddr,sizeof(inaddr), @packet,len);
198
-  result := true;
199
-
200
-
201
-end;
202
-
203
-procedure tdnsasync.asyncprocess(socketno:integer);
204
-begin
205
-  state_process(states[socketno]);
206
-  case states[socketno].resultaction of
207
-    action_ignore: begin {do nothing} end;
208
-    action_done: begin
209
-      {$ifdef ipv6}
210
-      if (numsockused = 1) or (states[socketno xor 1].resultaction=action_done) then
211
-      //if using two sockets we need to wait until both sockets are in the done
212
-      //state before firing the event
213
-      {$endif}
214
-      begin
215
-        fresultlist := biniplist_new;
216
-        if (numsockused = 1) then begin
217
-          //writeln('processing for one state');
218
-          biniplist_addlist(fresultlist,states[0].resultlist);
219
-        {$ifdef ipv6}
220
-        end else if (requestaf = useaf_preferv6) then begin
221
-          //writeln('processing for two states, ipv6 preference');
222
-          //writeln('merging lists '+biniplist_tostr(states[1].resultlist)+' and '+biniplist_tostr(states[0].resultlist));
223
-          biniplist_addlist(fresultlist,states[1].resultlist);
224
-          biniplist_addlist(fresultlist,states[0].resultlist);
225
-        end else begin
226
-          //writeln('processing for two states, ipv4 preference');
227
-          biniplist_addlist(fresultlist,states[0].resultlist);
228
-          biniplist_addlist(fresultlist,states[1].resultlist);
229
-        {$endif}
230
-        end;
231
-        //writeln(biniplist_tostr(fresultlist));
232
-        onrequestdone(self,0);
233
-      end;
234
-    end;
235
-    action_sendquery:begin
236
-      sendquery(socketno,states[socketno].sendpacket,states[socketno].sendpacketlen);
237
-    end;
238
-  end;
239
-end;
240
-
241
-procedure tdnsasync.forwardlookup;
242
-var
243
-  bip : tbinip;
244
-  i : integer;
245
-begin
246
-  ipstrtobin(name,bip);
247
-
248
-  if bip.family <> 0 then begin
249
-    // it was an IP address
250
-    fresultlist := biniplist_new;
251
-    biniplist_add(fresultlist,bip);
252
-    onrequestdone(self,0);
253
-    exit;
254
-  end;
255
-
256
-  if (overridednsserver <> '') and (addr = '') then addr := overridednsserver;
257
-
258
-  if overrideaf = useaf_default then begin
259
-    {$ifdef ipv6}
260
-      {$ifdef win32}if not (usewindns and (addr = '')) then{$endif}
261
-      initpreferredmode;
262
-    {$endif}
263
-    requestaf := useaf;
264
-  end else begin
265
-    requestaf := overrideaf;
266
-  end;
267
-
268
-  {$ifdef win32}
269
-    if usewindns and (addr = '') then begin
270
-      dwas := tdnswinasync.create;
271
-      dwas.onrequestdone := winrequestdone;
272
-
273
-      dwas.forwardlookup(name);
274
-
275
-      exit;
276
-    end;
277
-  {$endif}
278
-
279
-  numsockused := 0;
280
-  fresultlist := biniplist_new;
281
-  if (requestaf <> useaf_v6) then begin
282
-    setstate_forward(name,states[numsockused],af_inet);
283
-    inc(numsockused);
284
-  end;
285
-
286
-  {$ifdef ipv6}
287
-    if (requestaf <> useaf_v4) then begin
288
-      setstate_forward(name,states[numsockused],af_inet6);
289
-      inc(numsockused);
290
-    end;
291
-  {$endif}
292
-  for i := 0 to numsockused-1 do begin
293
-    asyncprocess(i);
294
-  end;
295
-
296
-end;
297
-
298
-procedure tdnsasync.reverselookup;
299
-begin
300
-  if (overridednsserver <> '') and (addr = '') then addr := overridednsserver;
301
-  {$ifdef win32}
302
-    if usewindns and (addr = '') then begin
303
-      dwas := tdnswinasync.create;
304
-      dwas.onrequestdone := winrequestdone;
305
-      dwas.reverselookup(binip);
306
-      exit;
307
-    end;
308
-  {$endif}
309
-
310
-  setstate_reverse(binip,states[0]);
311
-  numsockused := 1;
312
-  asyncprocess(0);
313
-end;
314
-
315
-procedure tdnsasync.customlookup;
316
-begin
317
-  if (overridednsserver <> '') and (addr = '') then addr := overridednsserver;
318
-  setstate_custom(name,querytype,states[0]);
319
-  numsockused := 1;
320
-  asyncprocess(0);
321
-end;
322
-
323
-function tdnsasync.dnsresult;
324
-begin
325
-  if states[0].resultstr <> '' then result := states[0].resultstr else begin
326
-    result := ipbintostr(biniplist_get(fresultlist,0));
327
-  end;
328
-end;
329
-
330
-procedure tdnsasync.dnsresultbin(var binip:tbinip);
331
-begin
332
-  binip := biniplist_get(fresultlist,0);
333
-end;
334
-
335
-procedure tdnsasync.cancel;
336
-var
337
-  socketno : integer;
338
-begin
339
-  {$ifdef win32}
340
-    if assigned(dwas) then begin
341
-      dwas.release;
342
-      dwas := nil;
343
-    end else
344
-  {$endif}
345
-  begin
346
-    for socketno := 0 to numsock-1 do begin
347
-      reportlag(dnsserverids[socketno],-1);
348
-      dnsserverids[socketno] := -1;
349
-
350
-      sockets[socketno].close;
351
-    end;
352
-
353
-  end;
354
-  for socketno := 0 to numsock-1 do begin
355
-    setstate_failure(states[socketno]);
356
-
357
-  end;
358
-  fresultlist := biniplist_new;
359
-  onrequestdone(self,0);
360
-end;
361
-
362
-{$ifdef win32}
363
-  procedure tdnsasync.winrequestdone(sender:tobject;error:word);
364
- 
365
-  begin
366
-    if dwas.reverse then begin
367
-      states[0].resultstr := dwas.name;
368
-    end else begin 
369
-
370
-      {$ifdef ipv6}
371
-      if (requestaf = useaf_preferv4) then begin
372
-        {prefer mode: sort the IP's}
373
-        fresultlist := biniplist_new;
374
-        addipsoffamily(fresultlist,dwas.iplist,af_inet);
375
-        addipsoffamily(fresultlist,dwas.iplist,af_inet6);
376
-
377
-      end else if (requestaf = useaf_preferv6) then begin
378
-        {prefer mode: sort the IP's}
379
-        fresultlist := biniplist_new;
380
-        addipsoffamily(fresultlist,dwas.iplist,af_inet6);
381
-        addipsoffamily(fresultlist,dwas.iplist,af_inet);
382
-        
383
-      end else
384
-      {$endif}
385
-      begin
386
-        fresultlist := dwas.iplist;
387
-      end;
388
-
389
-    end;
390
-    dwas.release;
391
-    onrequestdone(self,error);
392
-  end;
393
-{$endif}
394
-end.

+ 0
- 880
libwin/lcore/dnscore.pas Parādīt failu

@@ -1,880 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-{
7
-
8
-  code wanting to use this dns system should act as follows (note: app
9
-  developers will probablly want to use dnsasync or dnssync or write a similar
10
-  wrapper unit of thier own).
11
-
12
-  for normal lookups call setstate_forward or setstate_reverse to set up the
13
-  state, for more obscure lookups use setstate_request_init and fill in other
14
-  relavent state manually.
15
-
16
-  call state_process which will do processing on the information in the state
17
-  and return an action
18
-  action_ignore means that dnscore wants the code that calls it to go
19
-  back to waiting for packets
20
-  action_sendpacket means that dnscore wants the code that calls it to send
21
-  the packet in sendpacket/sendpacketlen and then start (or go back to) listening
22
-  for
23
-  action_done means the request has completed (either suceeded or failed)
24
-
25
-  callers should resend the last packet they tried to send if they have not
26
-  been asked to send a new packet for more than some timeout value they choose.
27
-
28
-  when a packet is received the application should put the packet in
29
-  recvbuf/recvbuflen , set state.parsepacket and call state_process again
30
-
31
-  once the app gets action_done it can determine sucess or failure in the
32
-  following ways.
33
-
34
-  on failure state.resultstr will be an empty string and state.resultbin will
35
-  be zeroed out (easilly detected by the fact that it will have a family of 0)
36
-
37
-  on success for a A or AAAA lookup state.resultstr will be an empty string
38
-  and state.resultbin will contain the result (note: AAAA lookups require IPV6
39
-  enabled).
40
-
41
-  if an A lookup fails and the code is built with ipv6 enabled then the code
42
-  will return any AAAA records with the same name. The reverse does not apply
43
-  so if an application preffers IPV6 but wants IPV4 results as well it must
44
-  check them seperately.
45
-
46
-  on success for any other type of lookup state.resultstr will be an empty
47
-
48
-  note the state contains ansistrings, setstate_init with a null name parameter
49
-  can be used to clean theese up if required.
50
-
51
-  callers may use setstate_failure to mark the state as failed themseleves
52
-  before passing it on to other code, for example this may be done in the event
53
-  of a timeout.
54
-}
55
-unit dnscore;
56
-
57
-{$ifdef fpc}{$mode delphi}{$endif}
58
-
59
-{$include lcoreconfig.inc}
60
-
61
-interface
62
-
63
-uses binipstuff,classes,pgtypes,lcorernd;
64
-
65
-var usewindns : boolean = {$ifdef win32}true{$else}false{$endif};
66
-{hint to users of this unit that they should use windows dns instead.
67
-May be disabled by applications if desired. (e.g. if setting a custom
68
-dnsserverlist).
69
-
70
-note: this unit will not be able to self populate it's dns server list on
71
-older versions of windows.}
72
-
73
-const
74
-  useaf_default=0;
75
-  useaf_preferv4=1;
76
-  useaf_preferv6=2;
77
-  useaf_v4=3;
78
-  useaf_v6=4;
79
-{
80
-hint to users of this unit to how to deal with connecting to hostnames regarding ipv4 or ipv6 usage
81
-can be set by apps as desired
82
-}
83
-var useaf:integer = useaf_default;
84
-
85
-{
86
-(temporarily) use a different nameserver, regardless of the dnsserverlist
87
-}
88
-var overridednsserver:string;
89
-
90
-const
91
-  maxnamelength=127;
92
-  maxnamefieldlen=63;
93
-  //note: when using action_ignore the dnscore code *must* preserve the contents of state.sendpacket to allow for retries
94
-  //note: action_ignore must not be used in response to the original request but there is no valid reason for doing this anyway
95
-  action_ignore=0;
96
-  action_done=1;
97
-  action_sendquery=2;
98
-  querytype_a=1;
99
-  querytype_cname=5;
100
-  querytype_aaaa=28;
101
-  querytype_a6=38;
102
-  querytype_ptr=12;
103
-  querytype_ns=2;
104
-  querytype_soa=6;
105
-  querytype_mx=15;
106
-  querytype_txt=16;
107
-  querytype_spf=99;
108
-  maxrecursion=50;
109
-  maxrrofakind=20;
110
-
111
-  retryafter=300000; //microseconds must be less than one second;
112
-  timeoutlag=1000000000; // penalty value to be treated as lag in the event of a timeout (microseconds)
113
-type
114
-  dvar=array[0..0] of byte;
115
-  pdvar=^dvar;
116
-  tdnspacket=packed record
117
-    id:word;
118
-    flags:word;
119
-    rrcount:array[0..3] of word;
120
-    payload:array[0..511-12] of byte;
121
-  end;
122
-
123
-
124
-
125
-  tdnsstate=record
126
-    id:word;
127
-    recursioncount:integer;
128
-    queryname:string;
129
-    requesttype:word;
130
-    parsepacket:boolean;
131
-    resultstr:string;
132
-    resultbin:tbinip;
133
-    resultlist:tbiniplist;
134
-    resultaction:integer;
135
-    numrr1:array[0..3] of integer;
136
-    numrr2:integer;
137
-    rrdata:string;
138
-    sendpacketlen:integer;
139
-    sendpacket:tdnspacket;
140
-    recvpacketlen:integer;
141
-    recvpacket:tdnspacket;
142
-    forwardfamily:integer;
143
-  end;
144
-
145
-  trr=packed record
146
-    requesttypehi:byte;
147
-    requesttype:byte;
148
-    clas:word;
149
-    ttl:integer;
150
-    datalen:word;
151
-    data:array[0..511] of byte;
152
-  end;
153
-
154
-  trrpointer=packed record
155
-    p:pointer;
156
-    ofs:integer;
157
-    len:integer;
158
-    namelen:integer;
159
-  end;
160
-
161
-//commenting out functions from interface that do not have documented semantics
162
-//and probablly should not be called from outside this unit, reenable them
163
-//if you must but please document them at the same time --plugwash
164
-
165
-//function buildrequest(const name:string;var packet:tdnspacket;requesttype:word):integer;
166
-
167
-//returns the DNS name used to reverse look up an IP, such as 4.3.2.1.in-addr.arpa for 1.2.3.4
168
-function makereversename(const binip:tbinip):string;
169
-
170
-procedure setstate_request_init(const name:string;var state:tdnsstate);
171
-
172
-//set up state for a foward lookup. A family value of AF_INET6 will give only
173
-//ipv6 results. Any other value will give only ipv4 results
174
-procedure setstate_forward(const name:string;var state:tdnsstate;family:integer);
175
-
176
-procedure setstate_reverse(const binip:tbinip;var state:tdnsstate);
177
-procedure setstate_failure(var state:tdnsstate);
178
-//procedure setstate_return(const rrp:trrpointer;len:integer;var state:tdnsstate);
179
-
180
-//for custom raw lookups such as TXT, as desired by the user
181
-procedure setstate_custom(const name:string; requesttype:integer; var state:tdnsstate);
182
-
183
-procedure state_process(var state:tdnsstate);
184
-
185
-//function decodename(const packet:tdnspacket;len,start,recursion:integer;var numread:integer):string;
186
-
187
-procedure populatednsserverlist;
188
-procedure cleardnsservercache;
189
-
190
-var
191
-  dnsserverlist : tstringlist;
192
-//  currentdnsserverno : integer;
193
-
194
-
195
-//getcurrentsystemnameserver returns the nameserver the app should use and sets
196
-//id to the id of that nameserver. id should later be used to report how laggy
197
-//the servers response was and if it was timed out.
198
-function getcurrentsystemnameserver(var id:integer) :string;
199
-procedure reportlag(id:integer;lag:integer); //lag should be in microseconds and should be -1 to report a timeout
200
-
201
-//var
202
-//  unixnameservercache:string;
203
-{ $endif}
204
-
205
-
206
-{$ifdef ipv6}
207
-function getv6localips:tbiniplist;
208
-procedure initpreferredmode;
209
-
210
-var
211
-  preferredmodeinited:boolean;
212
-
213
-{$endif}
214
-
215
-var
216
-  failurereason:string;
217
-
218
-function getquerytype(s:string):integer;
219
-
220
-implementation
221
-
222
-uses
223
-  {$ifdef win32}
224
-    windows,
225
-  {$endif}
226
-
227
-  sysutils;
228
-
229
-
230
-
231
-function getquerytype(s:string):integer;
232
-begin
233
-  s := uppercase(s);
234
-  result := 0;
235
-  if (s = 'A') then result := querytype_a else
236
-  if (s = 'CNAME') then result := querytype_cname else
237
-  if (s = 'AAAA') then result := querytype_aaaa else
238
-  if (s = 'PTR') then result := querytype_ptr else
239
-  if (s = 'NS') then result := querytype_ns else
240
-  if (s = 'MX') then result := querytype_mx else
241
-  if (s = 'A6') then result := querytype_a6 else
242
-  if (s = 'TXT') then result := querytype_txt else
243
-  if (s = 'SOA') then result := querytype_soa else
244
-  if (s = 'SPF') then result := querytype_spf;
245
-end;
246
-
247
-function buildrequest(const name:string;var packet:tdnspacket;requesttype:word):integer;
248
-var
249
-  a,b:integer;
250
-  s:string;
251
-  arr:array[0..sizeof(packet)-1] of byte absolute packet;
252
-begin
253
- { writeln('buildrequest: name: ',name);}
254
-  result := 0;
255
-  fillchar(packet,sizeof(packet),0);
256
-  packet.id := randominteger($10000);
257
-
258
-  packet.flags := htons($0100);
259
-  packet.rrcount[0] := htons($0001);
260
-
261
-
262
-  s := copy(name,1,maxnamelength);
263
-  if s = '' then exit;
264
-  if s[length(s)] <> '.' then s := s + '.';
265
-  b := 0;
266
-  {encode name}
267
-  if (s = '.') then begin
268
-    packet.payload[0] := 0;
269
-    result := 12+5;
270
-  end else begin
271
-    for a := 1 to length(s) do begin
272
-      if s[a] = '.' then begin
273
-        if b > maxnamefieldlen then exit;
274
-        if (b = 0) then exit;
275
-        packet.payload[a-b-1] := b;
276
-        b := 0;
277
-      end else begin
278
-        packet.payload[a] := byte(s[a]);
279
-        inc(b);
280
-      end;
281
-    end;
282
-    if b > maxnamefieldlen then exit;
283
-    packet.payload[length(s)-b] := b;
284
-    result := length(s) + 12+5;
285
-  end;
286
-
287
-  arr[result-1] := 1;
288
-  arr[result-3] := requesttype and $ff;
289
-  arr[result-4] := requesttype shr 8;
290
-end;
291
-
292
-function makereversename(const binip:tbinip):string;
293
-var
294
-  name:string;
295
-  a,b:integer;
296
-begin
297
-  name := '';
298
-  if binip.family = AF_INET then begin
299
-    b := htonl(binip.ip);
300
-    for a := 0 to 3 do begin
301
-      name := name + inttostr(b shr (a shl 3) and $ff)+'.';
302
-    end;
303
-    name := name + 'in-addr.arpa';
304
-  end else
305
-  {$ifdef ipv6}
306
-  if binip.family = AF_INET6 then begin
307
-    for a := 15 downto 0 do begin
308
-      b := binip.ip6.u6_addr8[a];
309
-      name := name + hexchars[b and $f]+'.'+hexchars[b shr 4]+'.';
310
-    end;
311
-    name := name + 'ip6.arpa';
312
-  end else
313
-  {$endif}
314
-  begin
315
-    {empty name}
316
-  end;
317
-  result := name;
318
-end;
319
-
320
-{
321
-decodes DNS format name to a string. does not includes the root dot.
322
-doesnt read beyond len.
323
-empty result + non null failurereason: failure
324
-empty result + null failurereason: internal use
325
-}
326
-function decodename(const packet:tdnspacket;len,start,recursion:integer;var numread:integer):string;
327
-var
328
-  arr:array[0..sizeof(packet)-1] of byte absolute packet;
329
-  s:string;
330
-  a,b:integer;
331
-begin
332
-  numread := 0;
333
-  repeat
334
-    if (start+numread < 0) or (start+numread >= len) then begin
335
-      result := '';
336
-      failurereason := 'decoding name: got out of range1';
337
-      exit;
338
-    end;
339
-    b := arr[start+numread];
340
-    if b >= $c0 then begin
341
-      {recursive sub call}
342
-      if recursion > 10 then begin
343
-        result := '';
344
-        failurereason := 'decoding name: max recursion';
345
-        exit;
346
-      end;
347
-      if ((start+numread+1) >= len) then begin
348
-        result := '';
349
-        failurereason := 'decoding name: got out of range3';
350
-        exit;
351
-      end;
352
-      a := ((b shl 8) or arr[start+numread+1]) and $3fff;
353
-      s := decodename(packet,len,a,recursion+1,a);
354
-      if (s = '') and (failurereason <> '') then begin
355
-        result := '';
356
-        exit;
357
-      end;
358
-      if result <> '' then result := result + '.';
359
-      result := result + s;
360
-      inc(numread,2);
361
-      exit;
362
-    end else if b < 64 then begin
363
-      if (numread <> 0) and (b <> 0) then result := result + '.';
364
-      for a := start+numread+1 to start+numread+b do begin
365
-        if (a >= len) then begin
366
-          result := '';
367
-          failurereason := 'decoding name: got out of range2';
368
-          exit;
369
-        end;
370
-        result := result + char(arr[a]);
371
-      end;
372
-      inc(numread,b+1);
373
-
374
-      if b = 0 then begin
375
-        if (result = '') and (recursion = 0) then result := '.';
376
-        exit; {reached end of name}
377
-      end;
378
-    end else begin
379
-      failurereason := 'decoding name: read invalid char';
380
-      result := '';
381
-      exit; {invalid}
382
-    end;
383
-  until false;
384
-end;
385
-
386
-{==============================================================================}
387
-
388
-function getrawfromrr(const rrp:trrpointer;len:integer):string;
389
-begin
390
-  setlength(result,htons(trr(rrp.p^).datalen));
391
-  uniquestring(result);
392
-  move(trr(rrp.p^).data,result[1],length(result));
393
-end;
394
-
395
-
396
-function getipfromrr(const rrp:trrpointer;len:integer):tbinip;
397
-begin
398
-  fillchar(result,sizeof(result),0);
399
-  case trr(rrp.p^).requesttype of
400
-    querytype_a: begin
401
-      if htons(trr(rrp.p^).datalen) <> 4 then exit;
402
-      move(trr(rrp.p^).data,result.ip,4);
403
-      result.family :=AF_INET;
404
-    end;
405
-    {$ifdef ipv6}
406
-    querytype_aaaa: begin
407
-      if htons(trr(rrp.p^).datalen) <> 16 then exit;
408
-      result.family := AF_INET6;
409
-      move(trr(rrp.p^).data,result.ip6,16);
410
-    end;
411
-    {$endif}
412
-  else
413
-    {}
414
-  end;
415
-end;
416
-
417
-procedure setstate_return(const rrp:trrpointer;len:integer;var state:tdnsstate);
418
-var
419
-  a:integer;
420
-begin
421
-  state.resultaction := action_done;
422
-  state.resultstr := '';
423
-  case trr(rrp.p^).requesttype of
424
-    querytype_a{$ifdef ipv6},querytype_aaaa{$endif}: begin
425
-      state.resultbin := getipfromrr(rrp,len);
426
-    end;
427
-    querytype_txt:begin
428
-      {TXT returns a raw string}
429
-      state.resultstr := copy(getrawfromrr(rrp,len),2,9999);
430
-      fillchar(state.resultbin,sizeof(state.resultbin),0);
431
-    end;
432
-    querytype_mx:begin
433
-      {MX is a name after a 16 bits word}
434
-      state.resultstr := decodename(state.recvpacket,state.recvpacketlen,taddrint(rrp.p)-taddrint(@state.recvpacket)+12,0,a);
435
-      fillchar(state.resultbin,sizeof(state.resultbin),0);
436
-    end;
437
-  else
438
-    {other reply types (PTR, MX) return a hostname}
439
-    state.resultstr := decodename(state.recvpacket,state.recvpacketlen,taddrint(rrp.p)-taddrint(@state.recvpacket)+10,0,a);
440
-    fillchar(state.resultbin,sizeof(state.resultbin),0);
441
-  end;
442
-end;
443
-
444
-procedure setstate_request_init(const name:string;var state:tdnsstate);
445
-begin
446
-  {destroy things properly}
447
-  state.resultstr := '';
448
-  state.queryname := '';
449
-  state.rrdata := '';
450
-  fillchar(state,sizeof(state),0);
451
-  state.queryname := name;
452
-  state.parsepacket := false;
453
-end;
454
-
455
-procedure setstate_forward(const name:string;var state:tdnsstate;family:integer);
456
-begin
457
-  setstate_request_init(name,state);
458
-  state.forwardfamily := family;
459
-  {$ifdef ipv6}
460
-  if family = AF_INET6 then state.requesttype := querytype_aaaa else
461
-  {$endif}
462
-  state.requesttype := querytype_a;
463
-end;
464
-
465
-procedure setstate_reverse(const binip:tbinip;var state:tdnsstate);
466
-begin
467
-  setstate_request_init(makereversename(binip),state);
468
-  state.requesttype := querytype_ptr;
469
-end;
470
-
471
-procedure setstate_custom(const name:string; requesttype:integer; var state:tdnsstate);
472
-begin
473
-  setstate_request_init(name,state);
474
-  state.requesttype := requesttype;
475
-end;
476
-
477
-
478
-procedure setstate_failure(var state:tdnsstate);
479
-begin
480
-  state.resultstr := '';
481
-  fillchar(state.resultbin,sizeof(state.resultbin),0);
482
-  state.resultaction := action_done;
483
-end;
484
-
485
-procedure state_process(var state:tdnsstate);
486
-label recursed;
487
-label failure;
488
-var
489
-  a,b,ofs:integer;
490
-  rrtemp:^trr;
491
-  rrptemp:^trrpointer;
492
-begin
493
-  if state.parsepacket then begin
494
-    if state.recvpacketlen < 12 then begin
495
-      failurereason := 'Undersized packet';
496
-      state.resultaction := action_ignore;
497
-      exit;
498
-    end;
499
-    if state.id <> state.recvpacket.id then begin
500
-      failurereason := 'ID mismatch';
501
-      state.resultaction := action_ignore;
502
-      exit;
503
-    end;
504
-    state.numrr2 := 0;
505
-    for a := 0 to 3 do begin
506
-      state.numrr1[a] := htons(state.recvpacket.rrcount[a]);
507
-      if state.numrr1[a] > maxrrofakind then goto failure;
508
-      inc(state.numrr2,state.numrr1[a]);
509
-    end;
510
-
511
-    setlength(state.rrdata,state.numrr2*sizeof(trrpointer));
512
-
513
-    {- put all replies into a list}
514
-
515
-    ofs := 12;
516
-    {get all queries}
517
-    for a := 0 to state.numrr1[0]-1 do begin
518
-      if (ofs < 12) or (ofs > state.recvpacketlen-4) then goto failure;
519
-      rrptemp := @state.rrdata[1+a*sizeof(trrpointer)];
520
-      rrptemp.p := @state.recvpacket.payload[ofs-12];
521
-      rrptemp.ofs := ofs;
522
-      decodename(state.recvpacket,state.recvpacketlen,ofs,0,b);
523
-      rrptemp.len := b + 4;
524
-      inc(ofs,rrptemp.len);
525
-    end;
526
-
527
-    for a := state.numrr1[0] to state.numrr2-1 do begin
528
-      if (ofs < 12) or (ofs > state.recvpacketlen-12) then goto failure;
529
-      rrptemp := @state.rrdata[1+a*sizeof(trrpointer)];
530
-      if decodename(state.recvpacket,state.recvpacketlen,ofs,0,b) = '' then goto failure;
531
-      rrtemp := @state.recvpacket.payload[ofs-12+b]; {rrtemp points to values and result, after initial name}
532
-      rrptemp.p := rrtemp;
533
-      rrptemp.ofs := ofs; {ofs is start of RR before initial name from start of packet}
534
-      rrptemp.namelen := b;
535
-      b := htons(rrtemp.datalen);
536
-      rrptemp.len := b + 10 + rrptemp.namelen;
537
-      inc(ofs,rrptemp.len);
538
-    end;
539
-    if (ofs <> state.recvpacketlen) then begin
540
-      failurereason := 'ofs <> state.packetlen';
541
-      goto failure;
542
-    end;
543
-
544
-    {if we requested A or AAAA build a list of all replies}
545
-    if (state.requesttype = querytype_a) or (state.requesttype = querytype_aaaa) then begin
546
-      state.resultlist := biniplist_new;
547
-      for a := state.numrr1[0] to (state.numrr1[0]+state.numrr1[1]-1) do begin
548
-        rrptemp := @state.rrdata[1+a*sizeof(trrpointer)];
549
-        rrtemp := rrptemp.p;
550
-        b := rrptemp.len;
551
-        if rrtemp.requesttype = state.requesttype then begin
552
-          biniplist_add(state.resultlist,getipfromrr(rrptemp^,b));
553
-        end;
554
-      end;
555
-    end;
556
-
557
-    {- check for items of the requested type in answer section, if so return success first}
558
-    for a := state.numrr1[0] to (state.numrr1[0]+state.numrr1[1]-1) do begin
559
-      rrptemp := @state.rrdata[1+a*sizeof(trrpointer)];
560
-      rrtemp := rrptemp.p;
561
-      b := rrptemp.len;
562
-      if rrtemp.requesttype = state.requesttype then begin
563
-        setstate_return(rrptemp^,b,state);
564
-        exit;
565
-      end;
566
-    end;
567
-
568
-    {if no items of correct type found, follow first cname in answer section}
569
-    for a := state.numrr1[0] to (state.numrr1[0]+state.numrr1[1]-1) do begin
570
-      rrptemp := @state.rrdata[1+a*sizeof(trrpointer)];
571
-      rrtemp := rrptemp.p;
572
-      b := rrptemp.len;
573
-      if rrtemp.requesttype = querytype_cname then begin
574
-        state.queryname := decodename(state.recvpacket,state.recvpacketlen,rrptemp.ofs+12,0,b);
575
-        goto recursed;
576
-      end;
577
-    end;
578
-
579
-    {no cnames found, no items of correct type found}
580
-    if state.forwardfamily <> 0 then goto failure;
581
-
582
-    goto failure;
583
-recursed:
584
-    {here it needs recursed lookup}
585
-    {if needing to follow a cname, change state to do so}
586
-    inc(state.recursioncount);
587
-    if state.recursioncount > maxrecursion then goto failure;
588
-  end;
589
-
590
-  {here, a name needs to be resolved}
591
-  if state.queryname = '' then begin
592
-    failurereason := 'empty query name';
593
-    goto failure;
594
-  end;
595
-
596
-  {do /ets/hosts lookup here}
597
-  state.sendpacketlen := buildrequest(state.queryname,state.sendpacket,state.requesttype);
598
-  if state.sendpacketlen = 0 then begin
599
-    failurereason := 'building request packet failed';
600
-    goto failure;
601
-  end;
602
-  state.id := state.sendpacket.id;
603
-  state.resultaction := action_sendquery;
604
-
605
-  exit;
606
-failure:
607
-  setstate_failure(state);
608
-end;
609
-{$ifdef win32}
610
-  const
611
-    MAX_HOSTNAME_LEN = 132;
612
-    MAX_DOMAIN_NAME_LEN = 132;
613
-    MAX_SCOPE_ID_LEN = 260    ;
614
-    MAX_ADAPTER_NAME_LENGTH = 260;
615
-    MAX_ADAPTER_ADDRESS_LENGTH = 8;
616
-    MAX_ADAPTER_DESCRIPTION_LENGTH = 132;
617
-    ERROR_BUFFER_OVERFLOW = 111;
618
-    MIB_IF_TYPE_ETHERNET = 6;
619
-    MIB_IF_TYPE_TOKENRING = 9;
620
-    MIB_IF_TYPE_FDDI = 15;
621
-    MIB_IF_TYPE_PPP = 23;
622
-    MIB_IF_TYPE_LOOPBACK = 24;
623
-    MIB_IF_TYPE_SLIP = 28;
624
-
625
-
626
-  type
627
-    tip_addr_string=packed record
628
-      Next :pointer;
629
-      IpAddress : array[0..15] of char;
630
-      ipmask    : array[0..15] of char;
631
-      context   : dword;
632
-    end;
633
-    pip_addr_string=^tip_addr_string;
634
-    tFIXED_INFO=packed record
635
-       HostName         : array[0..MAX_HOSTNAME_LEN-1] of char;
636
-       DomainName       : array[0..MAX_DOMAIN_NAME_LEN-1] of char;
637
-       currentdnsserver : pip_addr_string;
638
-       dnsserverlist    : tip_addr_string;
639
-       nodetype         : longint;
640
-       ScopeId          : array[0..MAX_SCOPE_ID_LEN + 4] of char;
641
-       enablerouting    : longbool;
642
-       enableproxy      : longbool;
643
-       enabledns        : longbool;
644
-    end;
645
-    pFIXED_INFO=^tFIXED_INFO;
646
-
647
-  var
648
-    iphlpapi : thandle;
649
-    getnetworkparams : function(pFixedInfo : PFIXED_INFO;OutBufLen : plongint) : longint;stdcall;
650
-{$endif}
651
-procedure populatednsserverlist;
652
-var
653
-  {$ifdef win32}
654
-    fixed_info : pfixed_info;
655
-    fixed_info_len : longint;
656
-    currentdnsserver : pip_addr_string;
657
-  {$else}
658
-    t:textfile;
659
-    s:string;
660
-    a:integer;
661
-  {$endif}
662
-begin
663
-  //result := '';
664
-  if assigned(dnsserverlist) then begin
665
-    dnsserverlist.clear;
666
-  end else begin
667
-    dnsserverlist := tstringlist.Create;
668
-  end;
669
-  {$ifdef win32}
670
-    if iphlpapi=0 then iphlpapi := loadlibrary('iphlpapi.dll');
671
-    if not assigned(getnetworkparams) then @getnetworkparams := getprocaddress(iphlpapi,'GetNetworkParams');
672
-    if not assigned(getnetworkparams) then exit;
673
-    fixed_info_len := 0;
674
-    if GetNetworkParams(nil,@fixed_info_len)<>ERROR_BUFFER_OVERFLOW then exit;
675
-    //fixed_info_len :=sizeof(tfixed_info);
676
-    getmem(fixed_info,fixed_info_len);
677
-    if GetNetworkParams(fixed_info,@fixed_info_len)<>0 then begin
678
-      freemem(fixed_info);
679
-      exit;
680
-    end;
681
-    currentdnsserver := @(fixed_info.dnsserverlist);
682
-    while assigned(currentdnsserver) do begin
683
-      dnsserverlist.Add(currentdnsserver.IpAddress);
684
-      currentdnsserver := currentdnsserver.next;
685
-    end;
686
-    freemem(fixed_info);
687
-  {$else}
688
-    filemode := 0;
689
-    assignfile(t,'/etc/resolv.conf');
690
-    {$i-}reset(t);{$i+}
691
-    if ioresult <> 0 then exit;
692
-
693
-    while not eof(t) do begin
694
-      readln(t,s);
695
-      if not (copy(s,1,10) = 'nameserver') then continue;
696
-      s := copy(s,11,500);
697
-      while s <> '' do begin
698
-        if (s[1] = #32) or (s[1] = #9) then s := copy(s,2,500) else break;
699
-      end;
700
-      a := pos(' ',s);
701
-      if a <> 0 then s := copy(s,1,a-1);
702
-      a := pos(#9,s);
703
-      if a <> 0 then s := copy(s,1,a-1);
704
-      //result := s;
705
-      //if result <> '' then break;
706
-      dnsserverlist.Add(s);
707
-    end;
708
-    close(t);
709
-  {$endif}
710
-end;
711
-
712
-procedure cleardnsservercache;
713
-begin
714
-  if assigned(dnsserverlist) then begin
715
-    dnsserverlist.destroy;
716
-    dnsserverlist := nil;
717
-  end;
718
-end;
719
-
720
-function getcurrentsystemnameserver(var id:integer):string;
721
-var
722
-  counter : integer;
723
-
724
-begin
725
-  if not assigned(dnsserverlist) then populatednsserverlist;
726
-  if dnsserverlist.count=0 then raise exception.create('no dns servers availible');
727
-  id := 0;
728
-  if dnsserverlist.count >1 then begin
729
-
730
-    for counter := 1 to dnsserverlist.count-1 do begin
731
-      if taddrint(dnsserverlist.objects[counter]) < taddrint(dnsserverlist.objects[id]) then id := counter;
732
-    end;
733
-  end;
734
-  result := dnsserverlist[id]
735
-end;
736
-
737
-procedure reportlag(id:integer;lag:integer); //lag should be in microseconds and should be -1 to report a timeout
738
-var
739
-  counter : integer;
740
-  temp : integer;
741
-begin
742
-  if (id < 0) or (id >= dnsserverlist.count) then exit;
743
-  if lag = -1 then lag := timeoutlag;
744
-  for counter := 0 to dnsserverlist.count-1 do begin
745
-    temp := taddrint(dnsserverlist.objects[counter]) *15;
746
-    if counter=id then temp := temp + lag;
747
-    dnsserverlist.objects[counter] := tobject(temp div 16);
748
-  end;
749
-
750
-end;
751
-
752
-
753
-
754
-{$ifdef ipv6}
755
-
756
-{$ifdef linux}
757
-function getv6localips:tbiniplist;
758
-var
759
-  t:textfile;
760
-  s,s2:string;
761
-  ip:tbinip;
762
-  a:integer;
763
-begin
764
-  result := biniplist_new;
765
-
766
-  assignfile(t,'/proc/net/if_inet6');
767
-  {$i-}reset(t);{$i+}
768
-  if ioresult <> 0 then exit; {none found, return empty list}
769
-
770
-  while not eof(t) do begin
771
-    readln(t,s);
772
-    s2 := '';
773
-    for a := 0 to 7 do begin
774
-      if (s2 <> '') then s2 := s2 + ':';
775
-      s2 := s2 + copy(s,(a shl 2)+1,4);
776
-    end;
777
-    ipstrtobin(s2,ip);
778
-    if ip.family <> 0 then biniplist_add(result,ip);
779
-  end;
780
-  closefile(t);
781
-end;
782
-
783
-{$else}
784
-function getv6localips:tbiniplist;
785
-begin
786
-  result := biniplist_new;
787
-end;
788
-{$endif}
789
-
790
-procedure initpreferredmode;
791
-var
792
-  l:tbiniplist;
793
-  a:integer;
794
-  ip:tbinip;
795
-  ipmask_global,ipmask_6to4,ipmask_teredo:tbinip;
796
-
797
-begin
798
-  if preferredmodeinited then exit;
799
-  if useaf <> useaf_default then exit;
800
-  l := getv6localips;
801
-  if biniplist_getcount(l) = 0 then exit;
802
-  useaf := useaf_preferv4;
803
-  ipstrtobin('2000::',ipmask_global);
804
-  ipstrtobin('2001::',ipmask_teredo);
805
-  ipstrtobin('2002::',ipmask_6to4);
806
-  {if there is any v6 IP which is globally routable and not 6to4 and not teredo, prefer v6}
807
-  for a := biniplist_getcount(l)-1 downto 0 do begin
808
-    ip := biniplist_get(l,a);
809
-    if not comparebinipmask(ip,ipmask_global,3) then continue;
810
-    if comparebinipmask(ip,ipmask_teredo,32) then continue;
811
-    if comparebinipmask(ip,ipmask_6to4,16) then continue;
812
-    useaf := useaf_preferv6;
813
-    preferredmodeinited := true;
814
-    exit;
815
-  end;
816
-end;
817
-
818
-{$endif}
819
-
820
-
821
-{  quick and dirty description of dns packet structure to aid writing and
822
-   understanding of parser code, refer to appropriate RFCs for proper specs
823
-- all words are network order
824
-
825
-www.google.com A request:
826
-
827
-0, 2: random transaction ID
828
-2, 2: flags: only the "recursion desired" bit set. (bit 8 of word)
829
-4, 2: questions: 1
830
-6, 2: answer RR's: 0.
831
-8, 2: authority RR's: 0.
832
-10, 2: additional RR's: 0.
833
-12, n: payload:
834
-  query:
835
-    #03 "www" #06 "google" #03 "com" #00
836
-    size-4, 2: type: host address (1)
837
-    size-2, 2: class: inet (1)
838
-
839
-reply:
840
-
841
-0,2: random transaction ID
842
-2,2: flags: set: response (bit 15), recursion desired (8), recursion available (7)
843
-4,4: questions: 1
844
-6,4: answer RR's: 2
845
-8,4: authority RR's: 9
846
-10,4: additional RR's: 9
847
-12: payload:
848
-  query:
849
-    ....
850
-  answer: CNAME
851
-    0,2 "c0 0c" "name: www.google.com"
852
-    2,2 "00 05" "type: cname for an alias"
853
-    4,2 "00 01" "class: inet"
854
-    6,4: TTL
855
-    10,2: data length "00 17" (23)
856
-    12: the cname name (www.google.akadns.net)
857
-  answer: A
858
-    0,2 ..
859
-    2,2 "00 01" host address
860
-    4,2 ...
861
-    6,4 ...
862
-    10,2: data length (4)
863
-    12,4: binary IP
864
-  authority - 9 records
865
-  additional - 9 records
866
-
867
-
868
-  ipv6 AAAA reply:
869
-    0,2: ...
870
-    2,2: type: 001c
871
-    4,2: class: inet (0001)
872
-    6,2: TTL
873
-    10,2: data size (16)
874
-    12,16: binary IP
875
-
876
-  ptr request: query type 000c
877
-
878
-name compression: word "cxxx" in the name, xxx points to offset in the packet}
879
-
880
-end.

+ 0
- 407
libwin/lcore/dnssync.pas Parādīt failu

@@ -1,407 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-unit dnssync;
6
-{$ifdef fpc}
7
-  {$mode delphi}
8
-{$endif}
9
-
10
-{$include lcoreconfig.inc}
11
-
12
-interface
13
-  uses
14
-    dnscore,
15
-    binipstuff,
16
-    {$ifdef win32}
17
-      winsock,
18
-      windows,
19
-    {$else}
20
-      {$ifdef VER1_0}
21
-        linux,
22
-      {$else}
23
-        baseunix,unix,unixutil,
24
-      {$endif}
25
-      sockets,
26
-      fd_utils,
27
-    {$endif}
28
-    lcorernd,
29
-    sysutils;
30
-
31
-//convert a name to an IP
32
-//will return v4 or v6 depending on what seems favorable, or manual preference setting
33
-//on error the binip will have a family of 0 (other fiels are also currently
34
-//zeroed out but may be used for further error information in future)
35
-//timeout is in miliseconds, it is ignored when using windows dns
36
-function forwardlookup(name:string;timeout:integer):tbinip;
37
-
38
-//convert a name to a list of all IP's returned
39
-//this returns both v4 and v6 IP's, or possibly only v4 or v6, depending on settings
40
-//on error, returns an empty list
41
-function forwardlookuplist(name:string;timeout:integer):tbiniplist;
42
-
43
-
44
-//convert an IP to a name, on error a null string will be returned, other
45
-//details as above
46
-function reverselookup(ip:tbinip;timeout:integer):string;
47
-
48
-
49
-
50
-const
51
-  tswrap=$4000;
52
-  tsmask=tswrap-1;
53
-
54
-  numsock=1{$ifdef ipv6}+1{$endif};
55
-  defaulttimeout=10000;
56
-  const mintimeout=16;
57
-
58
-  toport='53';
59
-
60
-var
61
-  id:integer;
62
-
63
-  sendquerytime:array[0..numsock-1] of integer;
64
-implementation
65
-
66
-{$ifdef win32}
67
-  uses dnswin;
68
-{$endif}
69
-
70
-
71
-{$ifndef win32}
72
-{$define syncdnscore}
73
-{$endif}
74
-
75
-{$i unixstuff.inc}
76
-{$i ltimevalstuff.inc}
77
-
78
-var
79
-  numsockused:integer;
80
-  fd:array[0..numsock-1] of integer;
81
-  state:array[0..numsock-1] of tdnsstate;
82
-  toaddr:array[0..numsock-1] of tbinip;
83
-
84
-{$ifdef syncdnscore}
85
-
86
-{$ifdef win32}
87
-  const
88
-    winsocket = 'wsock32.dll';
89
-  function sendto(s: TSocket; const Buf; len, flags: Integer; var addrto: TinetSockAddrV; tolen: Integer): Integer; stdcall; external    winsocket name 'sendto';
90
-  function bind(s: TSocket; var addr: TinetSockAddrV; namelen: Integer): Longbool; stdcall; external    winsocket name 'bind';
91
-  type
92
-    fdset=tfdset;
93
-{$endif}
94
-
95
-
96
-function getts:integer;
97
-{$ifdef win32}
98
-begin
99
-  result := GetTickCount and tsmask;
100
-{$else}
101
-var
102
-  temp:ttimeval;
103
-begin
104
-  gettimeofday(temp);
105
-  result := ((temp.tv_usec div 1000) + (temp.tv_sec * 1000)) and tsmask;
106
-{$endif}
107
-end;
108
-
109
-
110
-function sendquery(socknum:integer;const packet:tdnspacket;len:integer):boolean;
111
-var
112
-  a:integer;
113
-  addr       : string;
114
-  port       : string;
115
-  inaddr     : TInetSockAddrV;
116
-begin
117
-{  writeln('sendquery ',decodename(state.packet,state.packetlen,12,0,a),' ',state.requesttype);}
118
-  result := false;
119
-  if len = 0 then exit; {no packet}
120
-
121
-  if overridednsserver <> '' then addr := overridednsserver else addr := getcurrentsystemnameserver(id);
122
-
123
-  {$ifdef ipv6}{$ifdef win32}
124
-  if toaddr[socknum].family = AF_INET6 then if (useaf = 0) then useaf := useaf_preferv6;
125
-  {$endif}{$endif}
126
-
127
-  port := toport;
128
-  toaddr[socknum] := ipstrtobinf(addr);
129
-  makeinaddrv(toaddr[socknum],port,inaddr);
130
-
131
-  sendto(fd[socknum],packet,len,0,inaddr,inaddrsize(inaddr));
132
-  sendquerytime[socknum] := getts;
133
-  result := true;
134
-end;
135
-
136
-procedure setupsocket;
137
-var
138
-  inAddrtemp : TInetSockAddrV;
139
-  a:integer;
140
-  biniptemp:tbinip;
141
-  addr:string;
142
-begin
143
-  //init both sockets smultaneously, always, so they get succesive fd's
144
-  if fd[0] > 0 then exit;
145
-
146
-  if overridednsserver <> '' then addr := overridednsserver else addr := getcurrentsystemnameserver(id);
147
-  //must get the DNS server here so we know to init v4 or v6
148
-
149
-  ipstrtobin(addr,biniptemp);
150
-
151
-  if biniptemp.family = AF_INET6 then biniptemp := ipstrtobinf('::') else biniptemp := ipstrtobinf('0.0.0.0');
152
-
153
-
154
-  for a := 0 to numsockused-1 do begin
155
-    makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp);
156
-
157
-    fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0);
158
-
159
-    If {$ifndef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp)) Then begin
160
-      {$ifdef win32}
161
-        raise Exception.create('unable to bind '+inttostr(WSAGetLastError));
162
-      {$else}
163
-        raise Exception.create('unable to bind '+inttostr(socketError));
164
-      {$endif}
165
-    end;
166
-  end;
167
-end;
168
-
169
-procedure resolveloop(timeout:integer);
170
-var
171
-  selectresult   : integer;
172
-  fds            : fdset;
173
-
174
-  endtime      : longint;
175
-  starttime    : longint;
176
-  wrapmode     : boolean;
177
-  currenttime  : integer;
178
-
179
-  lag            : ttimeval;
180
-  currenttimeout : ttimeval;
181
-  selecttimeout	 : ttimeval;
182
-  socknum:integer;
183
-  needprocessing:array[0..numsock-1] of boolean;
184
-  finished:array[0..numsock-1] of boolean;
185
-  a,b:integer;
186
-
187
-  Src    : TInetSockAddrV;
188
-  Srcx   : {$ifdef win32}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src;
189
-  SrcLen : Integer;
190
-  fromip:tbinip;
191
-  fromport:string;
192
-
193
-begin
194
-  if timeout < mintimeout then timeout := defaulttimeout;
195
-
196
-    starttime := getts;
197
-    endtime := starttime + timeout;
198
-    if (endtime and tswrap)=0 then begin
199
-      wrapmode := false;
200
-    end else begin
201
-      wrapmode := true;
202
-    end;
203
-    endtime := endtime and tsmask;
204
-
205
-  setupsocket;
206
-  for socknum := 0 to numsockused-1 do begin
207
-    needprocessing[socknum] := true;
208
-    finished[socknum] := false;
209
-  end;
210
-
211
-  repeat
212
-    for socknum := numsockused-1 downto 0 do if needprocessing[socknum] then begin
213
-      state_process(state[socknum]);
214
-      case state[socknum].resultaction of
215
-        action_ignore: begin
216
-          {do nothing}
217
-        end;
218
-        action_done: begin
219
-          finished[socknum] := true;
220
-          //exit if all resolvers are finished
221
-          b := 0;
222
-          for a := 0 to numsockused-1 do begin
223
-            if finished[a] then inc(b);
224
-          end;
225
-          if (b = numsockused) then begin
226
-            exit;
227
-          end;
228
-          //onrequestdone(self,0);
229
-        end;
230
-        action_sendquery:begin
231
-{        writeln('send query');}
232
-          sendquery(socknum,state[socknum].sendpacket,state[socknum].sendpacketlen);
233
-        end;
234
-      end;
235
-      needprocessing[socknum] := false;
236
-    end;
237
-
238
-    currenttime := getts;
239
-    msectotimeval(selecttimeout, (endtime-currenttime) and tsmask);
240
-
241
-    fd_zero(fds);
242
-    for socknum := numsockused-1 downto 0 do if not finished[socknum] then fd_set(fd[socknum],fds);
243
-    if (selecttimeout.tv_sec > 0) or (selecttimeout.tv_usec > retryafter) then begin
244
-      selecttimeout.tv_sec := 0;
245
-      selecttimeout.tv_usec := retryafter;
246
-    end;
247
-    //find the highest of the used fd's
248
-    b := 0;
249
-    for socknum := numsockused-1 downto 0 do if fd[socknum] > b then b := fd[socknum];
250
-    selectresult := select(b+1,@fds,nil,nil,@selecttimeout);
251
-    if selectresult > 0 then begin
252
-      currenttime := getts;
253
-      for socknum := numsockused-1 downto 0 do if fd_isset(fd[socknum],fds) then begin
254
-  {      writeln('selectresult>0');}
255
-        //why the hell are we zeroing out the packet buffer before reading into it?! --plugwash
256
-
257
-        fillchar(state[socknum].recvpacket,sizeof(state[socknum].recvpacket),0);
258
-        msectotimeval(lag,(currenttime-sendquerytime[socknum]) and tsmask);
259
-
260
-        if overridednsserver = '' then reportlag(id,(lag.tv_sec*1000000)+lag.tv_usec);
261
-
262
-        SrcLen := SizeOf(Src);
263
-        state[socknum].recvpacketlen := recvfrom(fd[socknum],state[socknum].recvpacket, SizeOf(state[socknum].recvpacket),0,Srcx,SrcLen);
264
-
265
-        if (state[socknum].recvpacketlen > 0) then begin
266
-          fromip := inaddrvtobinip(Src);
267
-          fromport := inttostr(htons(src.InAddr.port));
268
-          if ((not comparebinip(toaddr[socknum],fromip)) or (fromport <> toport)) then begin
269
-//            writeln('dnssync received from wrong IP:port ',ipbintostr(fromip),'#',fromport);
270
-            state[socknum].recvpacketlen := 0;
271
-          end else begin
272
-            state[socknum].parsepacket := true;
273
-            needprocessing[socknum] := true;
274
-          end;
275
-        end;
276
-      end;
277
-    end;
278
-    if selectresult < 0 then exit;
279
-    if selectresult = 0 then begin
280
-
281
-      currenttime := getts;
282
-
283
-      if overridednsserver = '' then reportlag(id,-1);
284
-      if (currenttime >= endtime) and ((not wrapmode) or (currenttime < starttime)) then begin
285
-        exit;
286
-      end else begin
287
-        //resend
288
-        for socknum := numsockused-1 downto 0 do begin
289
-          sendquery(socknum,state[socknum].sendpacket,state[socknum].sendpacketlen);
290
-        end;
291
-      end;
292
-    end;
293
-  until false;
294
-end;
295
-{$endif}
296
-
297
-
298
-
299
-function forwardlookuplist(name:string;timeout:integer):tbiniplist;
300
-var
301
-  dummy : integer;
302
-  a,b:integer;
303
-  biniptemp:tbinip;
304
-  l:tbiniplist;
305
-begin
306
-  ipstrtobin(name,biniptemp);
307
-  if biniptemp.family <> 0 then begin
308
-    result := biniplist_new;
309
-    biniplist_add(result,biniptemp);
310
-    exit; //it was an IP address, no need for dns
311
-  end;
312
-
313
-  {$ifdef win32}
314
-  if usewindns then begin
315
-    if (useaf = useaf_v4) then a := af_inet else if (useaf = useaf_v6) then a := af_inet6 else a := 0;
316
-    result := winforwardlookuplist(name,a,dummy);
317
-    {$ifdef ipv6}
318
-    if (useaf = useaf_preferv4) then begin
319
-      {prefer mode: sort the IP's}
320
-      l := biniplist_new;
321
-      addipsoffamily(l,result,af_inet);
322
-      addipsoffamily(l,result,af_inet6);
323
-      result := l;
324
-    end;
325
-    if (useaf = useaf_preferv6) then begin
326
-      {prefer mode: sort the IP's}
327
-      l := biniplist_new;
328
-      addipsoffamily(l,result,af_inet6);
329
-      addipsoffamily(l,result,af_inet);
330
-      result := l;
331
-    end;
332
-    {$endif}
333
-  end else
334
-  {$endif}
335
-  begin
336
-  {$ifdef syncdnscore}
337
-    {$ifdef ipv6}initpreferredmode;{$endif}
338
-
339
-    numsockused := 0;
340
-
341
-    result := biniplist_new;
342
-    if (useaf <> useaf_v6) then begin
343
-      setstate_forward(name,state[numsockused],af_inet);
344
-      inc(numsockused);
345
-    end;
346
-    {$ifdef ipv6}
347
-    if (useaf <> useaf_v4) then begin
348
-      setstate_forward(name,state[numsockused],af_inet6);
349
-      inc(numsockused);
350
-    end;
351
-    {$endif}
352
-
353
-    resolveloop(timeout);
354
-
355
-    if (numsockused = 1) then begin
356
-      biniplist_addlist(result,state[0].resultlist);
357
-    {$ifdef ipv6}
358
-    end else if (useaf = useaf_preferv6) then begin
359
-      biniplist_addlist(result,state[1].resultlist);
360
-      biniplist_addlist(result,state[0].resultlist);
361
-    end else begin
362
-      biniplist_addlist(result,state[0].resultlist);
363
-      biniplist_addlist(result,state[1].resultlist);
364
-    {$endif}
365
-    end;
366
-    {$endif}
367
-  end;
368
-end;
369
-
370
-function forwardlookup(name:string;timeout:integer):tbinip;
371
-var
372
-  listtemp:tbiniplist;
373
-begin
374
-  listtemp := forwardlookuplist(name,timeout);
375
-  result := biniplist_get(listtemp,0);
376
-end;
377
-
378
-function reverselookup(ip:tbinip;timeout:integer):string;
379
-var
380
-  dummy : integer;
381
-begin
382
-  {$ifdef win32}
383
-    if usewindns then begin
384
-      result := winreverselookup(ip,dummy);
385
-      exit;
386
-    end;
387
-  {$endif}
388
-  {$ifdef syncdnscore}
389
-  setstate_reverse(ip,state[0]);
390
-  numsockused := 1;
391
-  resolveloop(timeout);
392
-  result := state[0].resultstr;
393
-  {$endif}
394
-end;
395
-
396
-{$ifdef win32}
397
-  var
398
-    wsadata : twsadata;
399
-
400
-  initialization
401
-    WSAStartUp($2,wsadata);
402
-  finalization
403
-    WSACleanUp;
404
-{$endif}
405
-end.
406
-
407
-

+ 0
- 357
libwin/lcore/dnswin.pas Parādīt failu

@@ -1,357 +0,0 @@
1
-unit dnswin;
2
-
3
-interface
4
-
5
-uses binipstuff,classes,lcore;
6
-
7
-{$include lcoreconfig.inc}
8
-
9
-//on failure a null string or zeroed out binip will be retuned and error will be
10
-//set to a windows error code (error will be left untouched under non error
11
-//conditions).
12
-function winforwardlookuplist(name : string;familyhint:integer;var error : integer) : tbiniplist;
13
-function winreverselookup(ip:tbinip;var error:integer):string;
14
-
15
-
16
-type
17
-  //do not call destroy on a tdnswinasync instead call release and the
18
-  //dnswinasync will be freed when appropriate. Calling destroy will block
19
-  //the calling thread until the dns lookup completes.
20
-  //release should only be called from the main thread
21
-  tdnswinasync=class(tthread)
22
-  private
23
-    freverse : boolean;
24
-    error : integer;
25
-    freewhendone : boolean;
26
-    hadevent : boolean;
27
-  protected
28
-    procedure execute; override;
29
-  public
30
-    onrequestdone:tsocketevent;
31
-    name : string;
32
-    iplist : tbiniplist;
33
-
34
-    procedure forwardlookup(name:string);
35
-    procedure reverselookup(ip:tbinip);
36
-    destructor destroy; override;
37
-    procedure release;
38
-    constructor create;
39
-    property reverse : boolean read freverse;
40
-
41
-  end;
42
-
43
-implementation
44
-uses
45
-  lsocket,pgtypes,sysutils,winsock,windows,messages;
46
-
47
-type
48
-  //taddrinfo = record; //forward declaration
49
-  paddrinfo = ^taddrinfo;
50
-  taddrinfo = packed record
51
-    ai_flags : longint;
52
-    ai_family : longint;
53
-    ai_socktype : longint;
54
-    ai_protocol : longint;
55
-    ai_addrlen : taddrint;
56
-    ai_canonname : pchar;
57
-    ai_addr : pinetsockaddrv;
58
-    ai_next : paddrinfo;
59
-  end;
60
-  ppaddrinfo = ^paddrinfo;
61
-  tgetaddrinfo = function(nodename : pchar; servname : pchar; hints : paddrinfo;res : ppaddrinfo) : longint; stdcall;
62
-  tfreeaddrinfo = procedure(ai : paddrinfo); stdcall;
63
-  tgetnameinfo = function(sa:Pinetsockaddrv;salen : longint; host:pchar;hostlen : longint;serv:pchar;servlen:longint;flags:longint) : longint;stdcall;
64
-var
65
-  getaddrinfo : tgetaddrinfo;
66
-  freeaddrinfo : tfreeaddrinfo;
67
-  getnameinfo : tgetnameinfo;
68
-procedure v4onlyfreeaddrinfo(ai : paddrinfo); stdcall;
69
-var
70
-  next:paddrinfo;
71
-begin
72
-  while assigned(ai) do begin
73
-    freemem(ai.ai_addr);
74
-    next := ai.ai_next;
75
-    freemem(ai);
76
-    ai := next;
77
-  end;
78
-end;
79
-
80
-type
81
-  plongint = ^longint;
82
-  pplongint = ^plongint;
83
-
84
-function v4onlygetaddrinfo(nodename : pchar; servname : pchar; hints : paddrinfo;res : ppaddrinfo) : longint; stdcall;
85
-var
86
-  output,prev,first : paddrinfo;
87
-  hostent : phostent;
88
-  addrlist:^pointer;
89
-begin
90
-  if hints.ai_family <> af_inet6 then begin
91
-    result := 0;
92
-
93
-
94
-    hostent := gethostbyname(nodename);
95
-    if hostent = nil then begin
96
-      result := wsagetlasterror;
97
-      v4onlyfreeaddrinfo(output);
98
-      exit;
99
-    end;
100
-    addrlist := pointer(hostent.h_addr_list);
101
-
102
-    //ipint := pplongint(hostent.h_addr_list)^^;
103
-    prev := nil;
104
-    first := nil;
105
-    repeat
106
-      if not assigned(addrlist^) then break;
107
-
108
-      getmem(output,sizeof(taddrinfo));
109
-      if assigned(prev) then prev.ai_next := output;
110
-      getmem(output.ai_addr,sizeof(tinetsockaddr));
111
-      if servname <> nil then output.ai_addr.InAddr.port := htons(strtoint(servname)) else output.ai_addr.InAddr.port := 0;
112
-      output.ai_addr.InAddr.addr := longint(addrlist^^);
113
-      inc(integer(addrlist),4);
114
-      output.ai_flags := 0;
115
-      output.ai_family := af_inet;
116
-      output.ai_socktype := 0;
117
-      output.ai_protocol := 0;
118
-      output.ai_addrlen := sizeof(tinetsockaddr);
119
-      output.ai_canonname := nil;
120
-      output.ai_next := nil;
121
-      prev := output;
122
-      if not assigned(first) then first := output;
123
-    until false;
124
-    res^ := first;
125
-  end else begin
126
-    result := WSANO_RECOVERY;
127
-  end;
128
-end;
129
-
130
-function min(a,b : integer):integer;
131
-begin
132
-  if a<b then result := a else result := b;
133
-end;
134
-
135
-function v4onlygetnameinfo(sa:Pinetsockaddrv;salen : longint; host:pchar;hostlen : longint;serv:pchar;servlen:longint;flags:longint) : longint;stdcall;
136
-var
137
-  hostent : phostent;
138
-  bytestocopy : integer;
139
-begin
140
-  if sa.InAddr.family = af_inet then begin
141
-    result := 0;
142
-    hostent := gethostbyaddr(@(sa.inaddr.addr),4,AF_INET);
143
-    if hostent = nil then begin
144
-      result := wsagetlasterror;
145
-      exit;
146
-    end;
147
-    bytestocopy := min(strlen(hostent.h_name)+1,hostlen);
148
-    move((hostent.h_name)^,host^,bytestocopy);
149
-
150
-
151
-  end else begin
152
-    result := WSANO_RECOVERY;
153
-  end;
154
-end;
155
-
156
-
157
-procedure populateprocvars;
158
-var
159
-  libraryhandle : hmodule;
160
-  i : integer;
161
-  dllname : string;
162
-
163
-begin
164
-  if assigned(getaddrinfo) then exit; //procvars already populated
165
-  for i := 0 to 1 do begin
166
-    if i=0 then dllname := 'Ws2_32.dll' else dllname := 'Wship6.dll';
167
-    libraryhandle := LoadLibrary(pchar(dllname));
168
-    getaddrinfo := getprocaddress(libraryhandle,'getaddrinfo');
169
-    freeaddrinfo := getprocaddress(libraryhandle,'freeaddrinfo');
170
-    getnameinfo := getprocaddress(libraryhandle,'getnameinfo');
171
-    if assigned(getaddrinfo) and assigned(freeaddrinfo) and assigned(getnameinfo) then begin
172
-      //writeln('found getaddrinfo and freeaddrinfo in'+dllname);
173
-      exit; //success
174
-    end;
175
-
176
-  end;
177
-  //writeln('could not find getaddrinfo and freeaddrinfo, falling back to ipv4 only lookup');
178
-  getaddrinfo := v4onlygetaddrinfo;
179
-  freeaddrinfo := v4onlyfreeaddrinfo;
180
-  getnameinfo := v4onlygetnameinfo;
181
-end;
182
-
183
-
184
-function winforwardlookuplist(name : string;familyhint:integer;var error : integer) : tbiniplist;
185
-var
186
-  hints: taddrinfo;
187
-  res0,res : paddrinfo;
188
-  getaddrinforesult : integer;
189
-  biniptemp:tbinip;
190
-begin
191
-  populateprocvars;
192
-
193
-  hints.ai_flags := 0;
194
-  hints.ai_family := familyhint;
195
-  hints.ai_socktype := 0;
196
-  hints.ai_protocol := 0;
197
-  hints.ai_addrlen := 0;
198
-  hints.ai_canonname := nil;
199
-  hints.ai_addr := nil;
200
-  hints.ai_next := nil;
201
-  getaddrinforesult := getaddrinfo(pchar(name),'1',@hints,@res);
202
-  res0 := res;
203
-  result := biniplist_new;
204
-  if getaddrinforesult = 0 then begin
205
-
206
-    while assigned(res) do begin
207
-      if res.ai_family = af_inet then begin
208
-        biniptemp.family := af_inet;
209
-        biniptemp.ip := res.ai_addr.InAddr.addr;
210
-        biniplist_add(result,biniptemp);
211
-      {$ifdef ipv6}
212
-      end else if res.ai_family = af_inet6 then begin
213
-        biniptemp.family := af_inet6;
214
-        biniptemp.ip6 := res.ai_addr.InAddr6.sin6_addr;
215
-        biniplist_add(result,biniptemp);
216
-      {$endif}
217
-      end;
218
-      res := res.ai_next;
219
-    end;
220
-    freeaddrinfo(res0);
221
-    exit;
222
-  end;
223
-
224
-  if getaddrinforesult <> 0 then begin
225
-    fillchar(result,0,sizeof(result));
226
-    error := getaddrinforesult;
227
-  end;
228
-end;
229
-
230
-function winreverselookup(ip:tbinip;var error : integer):string;
231
-var
232
-  sa : tinetsockaddrv;
233
-  getnameinforesult : integer;
234
-begin
235
-
236
-  if ip.family = AF_INET then begin
237
-    sa.InAddr.family := AF_INET;
238
-    sa.InAddr.port := 1;
239
-    sa.InAddr.addr := ip.ip;
240
-  end else {$ifdef ipv6}if ip.family = AF_INET6 then begin
241
-    sa.InAddr6.sin6_family  := AF_INET6;
242
-    sa.InAddr6.sin6_port := 1;
243
-    sa.InAddr6.sin6_addr := ip.ip6;
244
-  end else{$endif} begin
245
-    raise exception.create('unrecognised address family');
246
-  end;
247
-  populateprocvars;
248
-  setlength(result,1025);
249
-  getnameinforesult := getnameinfo(@sa,sizeof(tinetsockaddrv),pchar(result),length(result),nil,0,0);
250
-  if getnameinforesult <> 0 then begin
251
-    error := getnameinforesult;
252
-    result := '';
253
-    exit;
254
-  end;
255
-  if pos(#0,result) >= 0 then begin
256
-    setlength(result,pos(#0,result)-1);
257
-  end;
258
-end;
259
-
260
-var
261
-  hwnddnswin : hwnd;
262
-
263
-function MyWindowProc(
264
-    ahWnd   : HWND;
265
-    auMsg   : Integer;
266
-    awParam : WPARAM;
267
-    alParam : LPARAM): Integer; stdcall;
268
-var
269
-  dwas : tdnswinasync;
270
-begin
271
-  if (ahwnd=hwnddnswin) and (aumsg=wm_user) then begin
272
-    Dwas := tdnswinasync(alparam);
273
-    if assigned (dwas.onrequestdone) then dwas.onrequestdone(dwas,awparam);
274
-    dwas.hadevent := true;
275
-    if dwas.freewhendone then dwas.free;
276
-  end else begin
277
-    //not passing unknown messages on to defwindowproc will cause window
278
-    //creation to fail! --plugwash
279
-    Result := DefWindowProc(ahWnd, auMsg, awParam, alParam)
280
-  end;
281
-end;
282
-
283
-procedure tdnswinasync.forwardlookup(name:string);
284
-begin
285
-  self.name := name;
286
-  freverse := false;
287
-  resume;
288
-end;
289
-procedure tdnswinasync.reverselookup(ip:tbinip);
290
-begin
291
-  iplist := biniplist_new;
292
-  biniplist_add(iplist,ip);
293
-  freverse := true;
294
-  resume;
295
-end;
296
-
297
-procedure tdnswinasync.execute;
298
-var
299
-  error : integer;
300
-
301
-begin
302
-  error := 0;
303
-  if reverse then begin
304
-    name := winreverselookup(biniplist_get(iplist,0),error);
305
-  end else begin
306
-    iplist := winforwardlookuplist(name,0,error);
307
-
308
-  end;
309
-  postmessage(hwnddnswin,wm_user,error,taddrint(self));
310
-end;
311
-
312
-destructor tdnswinasync.destroy;
313
-begin
314
-  WaitFor;
315
-  inherited destroy;
316
-end;
317
-procedure tdnswinasync.release;
318
-begin
319
-  if hadevent then destroy else begin
320
-    onrequestdone := nil;
321
-    freewhendone := true;
322
-  end;
323
-end;
324
-
325
-constructor tdnswinasync.create;
326
-begin
327
-  inherited create(true);
328
-end;
329
-
330
-var
331
-  MyWindowClass : TWndClass = (style         : 0;
332
-                                 lpfnWndProc   : @MyWindowProc;
333
-                                 cbClsExtra    : 0;
334
-                                 cbWndExtra    : 0;
335
-                                 hInstance     : 0;
336
-                                 hIcon         : 0;
337
-                                 hCursor       : 0;
338
-                                 hbrBackground : 0;
339
-                                 lpszMenuName  : nil;
340
-                                 lpszClassName : 'dnswinClass');
341
-begin
342
-
343
-    if Windows.RegisterClass(MyWindowClass) = 0 then halt;
344
-  //writeln('about to create lcore handle, hinstance=',hinstance);
345
-  hwnddnswin := CreateWindowEx(WS_EX_TOOLWINDOW,
346
-                               MyWindowClass.lpszClassName,
347
-                               '',        { Window name   }
348
-                               WS_POPUP,  { Window Style  }
349
-                               0, 0,      { X, Y          }
350
-                               0, 0,      { Width, Height }
351
-                               0,         { hWndParent    }
352
-                               0,         { hMenu         }
353
-                               HInstance, { hInstance     }
354
-                               nil);      { CreateParam   }
355
-  //writeln('dnswin hwnd is ',hwnddnswin);
356
-  //writeln('last error is ',GetLastError);
357
-end.

+ 0
- 297
libwin/lcore/fastmd5.pas Parādīt failu

@@ -1,297 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  Which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-unit fastmd5;
7
-
8
-{
9
-pascal implementation of MD5
10
-
11
-written by Bas Steendijk - steendijk@xs4all.nl
12
-
13
-based on RFC1321 - The MD5 Message-Digest Algorithm
14
-
15
-optimized for speed: saved on copying and sub calls in the core routine
16
-
17
-verified on:
18
-- Borland Delphi 3
19
-- Borland Turbo Pascal 7
20
-- Free Pascal 1.0.6 for i386 (on *nix)
21
-- various other versions of freepascal on windows and linux i386
22
-- various other versions of delphi
23
-- free pascal 1.9.5 on powerpc darwin
24
-
25
-this unit is endian portable but is likely to be significantly slower on big endian systems
26
-}
27
-
28
-{$Q-,R-}
29
-
30
-interface
31
-
32
-
33
-
34
-
35
-
36
-type
37
-  Tmd5=array[0..15] of byte;
38
-
39
-{$i uint32.inc}
40
-
41
-type
42
-  dvar=array[0..0] of byte;
43
-  Tmd5state=record
44
-    buf:array[0..63] of byte;
45
-    H:array[0..3] of uint32;
46
-    msglen:longint;
47
-    msglenhi:longint;
48
-  end;
49
-
50
-procedure md5processblock(var h:array of uint32;const data);
51
-
52
-procedure md5init(var state:tmd5state);
53
-procedure md5process(var state:tmd5state;const data;len:longint);
54
-procedure md5finish(var state:tmd5state;var result);
55
-
56
-procedure getmd5(const data;len:longint;var result);
57
-
58
-function md5tostr(const md5:tmd5):string;
59
-
60
-implementation
61
-
62
-function inttohex(val,bits:integer):string;
63
-const
64
-  hexchar:array[0..15] of char='0123456789abcdef';
65
-begin
66
-  inttohex := hexchar[val shr 4]+hexchar[val and $f];
67
-end;
68
-
69
-{$ifdef cpu386}
70
-function rol(w,bits:uint32): uint32; assembler;
71
-asm
72
-  {cpu386 is not defined on freepascal. but fpc assembler is incompatible, uses different code}
73
-  {inline($89/$d1/$d3/$c0);}
74
-  mov   ecx,edx
75
-  rol   eax,cl
76
-end;
77
-{$else}
78
-function rol(w,bits:uint32):uint32;
79
-begin
80
-  rol := (w shl bits) or (w shr (32-bits));
81
-end;
82
-{$endif}
83
-
84
-
85
-{function swapbytes(invalue:uint32):uint32;
86
-var
87
-  inbytes  : array[0..3] of byte absolute invalue;
88
-  outbytes : array[0..3] of byte absolute result;
89
-
90
-
91
-begin
92
-  outbytes[0] := inbytes[3];
93
-  outbytes[1] := inbytes[2];
94
-  outbytes[2] := inbytes[1];
95
-  outbytes[3] := inbytes[0];
96
-end;}
97
-
98
-procedure md5processblock(var h:array of uint32;const data);
99
-const
100
-  S11=7;  S12=12;  S13=17;  S14=22;
101
-  S21=5;  S22=9;   S23=14;  S24=20;
102
-  S31=4;  S32=11;  S33=16;  S34=23;
103
-  S41=6;  S42=10;  S43=15;  S44=21;
104
-
105
-var
106
-  A,B,C,D:uint32;
107
-  w:array[0..63] of byte absolute data;
108
-  x:array[0..15] of uint32 {$ifndef ENDIAN_BIG} absolute data{$endif} ;
109
-  y:array[0..63] of byte absolute x;
110
-  {$ifdef ENDIAN_BIG}counter : integer;{$endif}
111
-begin
112
-  A := h[0];
113
-  B := h[1];
114
-  C := h[2];
115
-  D := h[3];
116
-  {$ifdef ENDIAN_BIG}
117
-    for counter := 0 to 63 do begin
118
-      y[counter] := w[counter xor 3];
119
-    end;
120
-  {$endif}
121
-  a := rol(a + ((b and c) or ((not b) and d)) + x[ 0] + $d76aa478, S11) + b;
122
-  d := rol(d + ((a and b) or ((not a) and c)) + x[ 1] + $e8c7b756, S12) + a;
123
-  c := rol(c + ((d and a) or ((not d) and b)) + x[ 2] + $242070db, S13) + d;
124
-  b := rol(b + ((c and d) or ((not c) and a)) + x[ 3] + $c1bdceee, S14) + c;
125
-  a := rol(a + ((b and c) or ((not b) and d)) + x[ 4] + $f57c0faf, S11) + b;
126
-  d := rol(d + ((a and b) or ((not a) and c)) + x[ 5] + $4787c62a, S12) + a;
127
-  c := rol(c + ((d and a) or ((not d) and b)) + x[ 6] + $a8304613, S13) + d;
128
-  b := rol(b + ((c and d) or ((not c) and a)) + x[ 7] + $fd469501, S14) + c;
129
-  a := rol(a + ((b and c) or ((not b) and d)) + x[ 8] + $698098d8, S11) + b;
130
-  d := rol(d + ((a and b) or ((not a) and c)) + x[ 9] + $8b44f7af, S12) + a;
131
-  c := rol(c + ((d and a) or ((not d) and b)) + x[10] + $ffff5bb1, S13) + d;
132
-  b := rol(b + ((c and d) or ((not c) and a)) + x[11] + $895cd7be, S14) + c;
133
-  a := rol(a + ((b and c) or ((not b) and d)) + x[12] + $6b901122, S11) + b;
134
-  d := rol(d + ((a and b) or ((not a) and c)) + x[13] + $fd987193, S12) + a;
135
-  c := rol(c + ((d and a) or ((not d) and b)) + x[14] + $a679438e, S13) + d;
136
-  b := rol(b + ((c and d) or ((not c) and a)) + x[15] + $49b40821, S14) + c;
137
-
138
-  a := rol(a + ((b and d) or (c and (not d))) + x[ 1] + $f61e2562, S21) + b;
139
-  d := rol(d + ((a and c) or (b and (not c))) + x[ 6] + $c040b340, S22) + a;
140
-  c := rol(c + ((d and b) or (a and (not b))) + x[11] + $265e5a51, S23) + d;
141
-  b := rol(b + ((c and a) or (d and (not a))) + x[ 0] + $e9b6c7aa, S24) + c;
142
-  a := rol(a + ((b and d) or (c and (not d))) + x[ 5] + $d62f105d, S21) + b;
143
-  d := rol(d + ((a and c) or (b and (not c))) + x[10] + $02441453, S22) + a;
144
-  c := rol(c + ((d and b) or (a and (not b))) + x[15] + $d8a1e681, S23) + d;
145
-  b := rol(b + ((c and a) or (d and (not a))) + x[ 4] + $e7d3fbc8, S24) + c;
146
-  a := rol(a + ((b and d) or (c and (not d))) + x[ 9] + $21e1cde6, S21) + b;
147
-  d := rol(d + ((a and c) or (b and (not c))) + x[14] + $c33707d6, S22) + a;
148
-  c := rol(c + ((d and b) or (a and (not b))) + x[ 3] + $f4d50d87, S23) + d;
149
-  b := rol(b + ((c and a) or (d and (not a))) + x[ 8] + $455a14ed, S24) + c;
150
-  a := rol(a + ((b and d) or (c and (not d))) + x[13] + $a9e3e905, S21) + b;
151
-  d := rol(d + ((a and c) or (b and (not c))) + x[ 2] + $fcefa3f8, S22) + a;
152
-  c := rol(c + ((d and b) or (a and (not b))) + x[ 7] + $676f02d9, S23) + d;
153
-  b := rol(b + ((c and a) or (d and (not a))) + x[12] + $8d2a4c8a, S24) + c;
154
-
155
-  a := rol(a + (b xor c xor d) + x[ 5] + $fffa3942, S31) + b;
156
-  d := rol(d + (a xor b xor c) + x[ 8] + $8771f681, S32) + a;
157
-  c := rol(c + (d xor a xor b) + x[11] + $6d9d6122, S33) + d;
158
-  b := rol(b + (c xor d xor a) + x[14] + $fde5380c, S34) + c;
159
-  a := rol(a + (b xor c xor d) + x[ 1] + $a4beea44, S31) + b;
160
-  d := rol(d + (a xor b xor c) + x[ 4] + $4bdecfa9, S32) + a;
161
-  c := rol(c + (d xor a xor b) + x[ 7] + $f6bb4b60, S33) + d;
162
-  b := rol(b + (c xor d xor a) + x[10] + $bebfbc70, S34) + c;
163
-  a := rol(a + (b xor c xor d) + x[13] + $289b7ec6, S31) + b;
164
-  d := rol(d + (a xor b xor c) + x[ 0] + $eaa127fa, S32) + a;
165
-  c := rol(c + (d xor a xor b) + x[ 3] + $d4ef3085, S33) + d;
166
-  b := rol(b + (c xor d xor a) + x[ 6] + $04881d05, S34) + c;
167
-  a := rol(a + (b xor c xor d) + x[ 9] + $d9d4d039, S31) + b;
168
-  d := rol(d + (a xor b xor c) + x[12] + $e6db99e5, S32) + a;
169
-  c := rol(c + (d xor a xor b) + x[15] + $1fa27cf8, S33) + d;
170
-  b := rol(b + (c xor d xor a) + x[ 2] + $c4ac5665, S34) + c;
171
-
172
-  a := rol(a + (c xor (b or (not d))) + x[ 0] + $f4292244, S41) + b;
173
-  d := rol(d + (b xor (a or (not c))) + x[ 7] + $432aff97, S42) + a;
174
-  c := rol(c + (a xor (d or (not b))) + x[14] + $ab9423a7, S43) + d;
175
-  b := rol(b + (d xor (c or (not a))) + x[ 5] + $fc93a039, S44) + c;
176
-  a := rol(a + (c xor (b or (not d))) + x[12] + $655b59c3, S41) + b;
177
-  d := rol(d + (b xor (a or (not c))) + x[ 3] + $8f0ccc92, S42) + a;
178
-  c := rol(c + (a xor (d or (not b))) + x[10] + $ffeff47d, S43) + d;
179
-  b := rol(b + (d xor (c or (not a))) + x[ 1] + $85845dd1, S44) + c;
180
-  a := rol(a + (c xor (b or (not d))) + x[ 8] + $6fa87e4f, S41) + b;
181
-  d := rol(d + (b xor (a or (not c))) + x[15] + $fe2ce6e0, S42) + a;
182
-  c := rol(c + (a xor (d or (not b))) + x[ 6] + $a3014314, S43) + d;
183
-  b := rol(b + (d xor (c or (not a))) + x[13] + $4e0811a1, S44) + c;
184
-  a := rol(a + (c xor (b or (not d))) + x[ 4] + $f7537e82, S41) + b;
185
-  d := rol(d + (b xor (a or (not c))) + x[11] + $bd3af235, S42) + a;
186
-  c := rol(c + (a xor (d or (not b))) + x[ 2] + $2ad7d2bb, S43) + d;
187
-  b := rol(b + (d xor (c or (not a))) + x[ 9] + $eb86d391, S44) + c;
188
-
189
-  inc(h[0],A);
190
-  inc(h[1],B);
191
-  inc(h[2],C);
192
-  inc(h[3],D);
193
-end;
194
-
195
-procedure md5init(var state:tmd5state);
196
-begin
197
-  state.h[0] := $67452301;
198
-  state.h[1] := $EFCDAB89;
199
-  state.h[2] := $98BADCFE;
200
-  state.h[3] := $10325476;
201
-  state.msglen := 0;
202
-  state.msglenhi := 0;
203
-end;
204
-
205
-procedure md5process(var state:tmd5state;const data;len:longint);
206
-var
207
-  a,b:longint;
208
-  ofs:longint;
209
-  p:dvar absolute data;
210
-begin
211
-  b := state.msglen and 63;
212
-
213
-  inc(state.msglen,len);
214
-  while (state.msglen > $20000000) do begin
215
-    dec(state.msglen,$20000000);
216
-    inc(state.msglenhi);
217
-  end;
218
-  ofs := 0;
219
-  if b > 0 then begin
220
-    a := 64-b;
221
-    if a > len then a := len;
222
-    move(p[0],state.buf[b],a);
223
-    inc(ofs,a);
224
-    dec(len,a);
225
-    if b+a = 64 then md5processblock(state.h,state.buf);
226
-    if len = 0 then exit;
227
-  end;
228
-  while len >= 64 do begin
229
-    md5processblock(state.h,p[ofs]);
230
-    inc(ofs,64);
231
-    dec(len,64);
232
-  end;
233
-  if len > 0 then move(p[ofs],state.buf[0],len);
234
-end;
235
-
236
-procedure md5finish(var state:tmd5state;var result);
237
-var
238
-  b       :integer;
239
-  {$ifdef endian_big}
240
-    h       :tmd5 absolute state.h;
241
-    r       :tmd5 absolute result;
242
-    counter :integer ;
243
-  {$endif}
244
-begin
245
-  b := state.msglen and 63;
246
-  state.buf[b] := $80;
247
-  if b >= 56 then begin
248
-    {-- for a := b+1 to 63 do state.buf[a] := 0; }
249
-    fillchar(state.buf[b+1],63-b,0);
250
-    md5processblock(state.h,state.buf);
251
-    fillchar(state.buf,56,0);
252
-  end else begin
253
-    {-- for a := b+1 to 55 do state.buf[a] := 0; }
254
-    fillchar(state.buf[b+1],55-b,0);
255
-  end;
256
-  state.msglen := state.msglen shl 3;
257
-
258
-  state.buf[56] := state.msglen;
259
-  state.buf[57] := state.msglen shr 8;
260
-  state.buf[58] := state.msglen shr 16;
261
-  state.buf[59] := state.msglen shr 24;
262
-  state.buf[60] := state.msglenhi;
263
-  state.buf[61] := state.msglenhi shr 8;
264
-  state.buf[62] := state.msglenhi shr 16;
265
-  state.buf[63] := state.msglenhi shr 24;
266
-
267
-  md5processblock(state.h,state.buf);
268
-  {$ifdef ENDIAN_BIG}
269
-    for counter := 0 to 15 do begin
270
-      r[counter] := h[counter xor 3];
271
-    end;
272
-  {$else} 
273
-    move(state.h,result,16);
274
-  {$endif}
275
-  fillchar(state,sizeof(state),0);
276
-end;
277
-
278
-procedure getmd5(const data;len:longint;var result);
279
-var
280
-  t:tmd5state;
281
-begin
282
-  md5init(t);
283
-  md5process(t,data,len);
284
-  md5finish(t,result);
285
-end;
286
-
287
-function md5tostr(const md5:tmd5):string;
288
-var
289
-  a:integer;
290
-  s:string;
291
-begin
292
-  s := '';
293
-  for a := 0 to 15 do s := s + inttohex(md5[a],2);
294
-  md5tostr := s;
295
-end;
296
-
297
-end.

+ 0
- 72
libwin/lcore/fd_utils.pas Parādīt failu

@@ -1,72 +0,0 @@
1
-// this file contains code copied from linux.pp in the free pascal rtl
2
-// i had to copy them because i use a different definition of fdset to them
3
-// the copyright block from the file in question is shown below
4
-{
5
-   $Id: fd_utils.pas,v 1.2 2004/08/19 23:12:09 plugwash Exp $
6
-   This file is part of the Free Pascal run time library.
7
-   Copyright (c) 1999-2000 by Michael Van Canneyt,
8
-   BSD parts (c) 2000 by Marco van de Voort
9
-   members of the Free Pascal development team.
10
-
11
-   See the file COPYING.FPC, included in this distribution,
12
-   for details about the copyright.
13
-
14
-   This program is distributed in the hope that it will be useful,
15
-   but WITHOUT ANY WARRANTY;without even the implied warranty of
16
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
-
18
-**********************************************************************}
19
-{$ifdef fpc}
20
-  {$mode delphi}
21
-  {$inlining on}
22
-{$endif}
23
-unit fd_utils;
24
-interface
25
-
26
-type
27
-    FDSet= Array [0..255] of longint; {31}
28
-    PFDSet= ^FDSet;
29
-
30
-Procedure FD_Clr(fd:longint;var fds:fdSet);
31
-Procedure FD_Zero(var fds:fdSet);
32
-Procedure FD_Set(fd:longint;var fds:fdSet);
33
-Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
34
-
35
-{$ifdef fpc}
36
-  {$ifndef ver1_0}
37
-    {$define useinline}
38
-  {$endif}
39
-{$endif}
40
-
41
-implementation  
42
-uses sysutils;
43
-Procedure FD_Clr(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}
44
-{ Remove fd from the set of filedescriptors}
45
-begin
46
-  if (fd < 0) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd));
47
-  fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
48
-end;
49
-
50
-Procedure FD_Zero(var fds:fdSet);
51
-{ Clear the set of filedescriptors }
52
-begin
53
-  FillChar(fds,sizeof(fdSet),0);
54
-end;
55
-
56
-Procedure FD_Set(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}
57
-{ Add fd to the set of filedescriptors }
58
-begin
59
-  if (fd < 0) then raise exception.create('FD_set fd out of range: '+inttostr(fd));
60
-  fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
61
-end;
62
-
63
-Function FD_IsSet(fd:longint;var fds:fdSet):boolean;{$ifdef useinline}inline;{$endif}
64
-{ Test if fd is part of the set of filedescriptors }
65
-begin
66
-  if (fd < 0) then begin
67
-    result := false;
68
-    exit;
69
-  end;
70
-  FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
71
-end;
72
-end.

+ 0
- 906
libwin/lcore/lcore.pas Parādīt failu

@@ -1,906 +0,0 @@
1
-{lsocket.pas}
2
-
3
-{io and timer code by plugwash}
4
-
5
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
6
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
7
-  which is included in the package
8
-  ----------------------------------------------------------------------------- }
9
-
10
-{note: you must use the @ in the last param to tltask.create not doing so will
11
- compile without error but will cause an access violation -pg}
12
-
13
-//note: events after release are normal and are the apps responsibility to deal with safely
14
-
15
-unit lcore;
16
-{$ifdef fpc}
17
-  {$mode delphi}
18
-{$endif}
19
-{$ifdef win32}
20
-  {$define nosignal}
21
-{$endif}
22
-interface
23
-  uses
24
-    sysutils,
25
-    {$ifndef win32}
26
-      {$ifdef VER1_0}
27
-        linux,
28
-      {$else}
29
-        baseunix,unix,unixutil,
30
-      {$endif}
31
-      fd_utils,
32
-    {$endif}
33
-    classes,pgtypes,bfifo;
34
-  procedure processtasks;
35
-
36
-
37
-  const
38
-    {how this number is made up:
39
-    - ethernet: MTU 1500
40
-    - be safe for either "ethernet v1" or "PPPoE", both take 8 bytes
41
-    - IPv6 header: 40 bytes (IPv4 is 20)
42
-    - TCP/UDP header: 20 bytes
43
-    }
44
-    packetbasesize = 1432;
45
-    receivebufsize=packetbasesize*8;
46
-
47
-  var
48
-    absoloutemaxs:integer=0;
49
-
50
-  type
51
-    {$ifdef ver1_0}
52
-      sigset= array[0..31] of longint;
53
-    {$endif}
54
-
55
-    ESocketException   = class(Exception);
56
-    TBgExceptionEvent  = procedure (Sender : TObject;
57
-                                  E : Exception;
58
-                                  var CanClose : Boolean) of object;
59
-
60
-    // note : tsocketstate is defined in the same way as it is in François PIETTE's twsocket
61
-    // however tlsocket currently only uses wsClosed wsConnecting wsconnected and wsListening
62
-    TSocketState       = (wsInvalidState,
63
-                        wsOpened,     wsBound,
64
-                        wsConnecting, wsConnected,
65
-                        wsAccepting,  wsListening,
66
-                        wsClosed);
67
-
68
-    TWSocketOption       = (wsoNoReceiveLoop, wsoTcpNoDelay);
69
-    TWSocketOptions      = set of TWSocketOption;
70
-
71
-    TSocketevent     = procedure(Sender: TObject; Error: word) of object;
72
-    //Tdataavailevent  = procedure(data : string);
73
-    TSendData          = procedure (Sender: TObject; BytesSent: Integer) of object;
74
-
75
-    tlcomponent = class(tcomponent)
76
-    private
77
-      procedure releasetaskhandler(wparam,lparam:longint);
78
-    public
79
-      procedure release; virtual;
80
-      destructor destroy; override;
81
-    end;
82
-
83
-    tlasio = class(tlcomponent)
84
-    public
85
-      state              : tsocketstate      ;
86
-      ComponentOptions   : TWSocketOptions;
87
-      fdhandlein         : Longint           ;  {file discriptor}
88
-      fdhandleout        : Longint           ;  {file discriptor}
89
-
90
-      onsessionclosed    : tsocketevent      ;
91
-      ondataAvailable    : tsocketevent      ;
92
-      onsessionAvailable : tsocketevent      ;
93
-
94
-      onsessionconnected : tsocketevent      ;
95
-      onsenddata         : tsenddata      ;
96
-      ondatasent         : tsocketevent      ;
97
-      //connected          : boolean         ;
98
-
99
-      recvq              : tfifo;
100
-      OnBgException      : TBgExceptionEvent ;
101
-      //connectread        : boolean           ;
102
-      sendq              : tfifo;
103
-      closehandles       : boolean           ;
104
-      writtenthiscycle   : boolean           ;
105
-      onfdwrite           : procedure (Sender: TObject; Error: word) of object; //added for bewarehttpd
106
-      lasterror:integer;
107
-      destroying:boolean;
108
-      recvbufsize:integer;
109
-      function receivestr:string; virtual;
110
-      procedure close;
111
-      procedure abort;
112
-      procedure internalclose(error:word); virtual;
113
-      constructor Create(AOwner: TComponent); override;
114
-
115
-      destructor destroy; override;
116
-      procedure fdcleanup;
117
-      procedure HandleBackGroundException(E: Exception);
118
-      procedure handlefdtrigger(readtrigger,writetrigger:boolean); virtual;
119
-      procedure dup(invalue:longint);
120
-
121
-      function sendflush : integer;
122
-      procedure sendstr(const str : string);virtual;
123
-      procedure putstringinsendbuffer(const newstring : string);
124
-      function send(data:pointer;len:integer):integer;virtual;
125
-      procedure putdatainsendbuffer(data:pointer;len:integer); virtual;
126
-      procedure deletebuffereddata;
127
-
128
-      //procedure messageloop;
129
-      function Receive(Buf:Pointer;BufSize:integer):integer; virtual;
130
-      procedure flush;virtual;
131
-      procedure dodatasent(wparam,lparam:longint);
132
-      procedure doreceiveloop(wparam,lparam:longint);
133
-      procedure sinkdata(sender:tobject;error:word);
134
-
135
-      procedure release; override; {test -beware}
136
-
137
-      function RealSend(Data : Pointer; Len : Integer) : Integer; //added for bewarehttpd
138
-
139
-      procedure myfdclose(fd : integer); virtual;{$ifdef win32}abstract;{$endif}
140
-      function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; virtual;{$ifdef win32}abstract;{$endif}
141
-      function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; virtual;{$ifdef win32}abstract;{$endif}
142
-    protected
143
-      procedure dupnowatch(invalue:longint);
144
-    end;
145
-    ttimerwrapperinterface=class(tlcomponent)
146
-    public
147
-      function createwrappedtimer : tobject;virtual;abstract;
148
-//      procedure setinitialevent(wrappedtimer : tobject;newvalue : boolean);virtual;abstract;
149
-      procedure setontimer(wrappedtimer : tobject;newvalue:tnotifyevent);virtual;abstract;
150
-      procedure setenabled(wrappedtimer : tobject;newvalue : boolean);virtual;abstract;
151
-      procedure setinterval(wrappedtimer : tobject;newvalue : integer);virtual;abstract;
152
-    end;
153
-
154
-  var
155
-    timerwrapperinterface : ttimerwrapperinterface;
156
-  type
157
-    {$ifdef win32}
158
-      ttimeval = record
159
-        tv_sec : longint;
160
-        tv_usec : longint;
161
-      end;
162
-    {$endif}
163
-    tltimer=class(tlcomponent)
164
-    protected
165
-
166
-
167
-      wrappedtimer : tobject;
168
-
169
-
170
-//      finitialevent       : boolean           ;
171
-      fontimer            : tnotifyevent      ;
172
-      fenabled            : boolean           ;
173
-      finterval	          : integer	     ; {miliseconds, default 1000}
174
-      {$ifndef win32}
175
-        procedure resettimes;
176
-      {$endif}
177
-//      procedure setinitialevent(newvalue : boolean);
178
-      procedure setontimer(newvalue:tnotifyevent);
179
-      procedure setenabled(newvalue : boolean);
180
-      procedure setinterval(newvalue : integer);
181
-    public
182
-      //making theese public for now, this code should probablly be restructured later though
183
-      prevtimer          : tltimer           ;
184
-      nexttimer          : tltimer           ;
185
-      nextts	         : ttimeval          ;
186
-
187
-      constructor create(aowner:tcomponent);override;
188
-      destructor destroy;override;
189
-//      property initialevent : boolean read finitialevent write setinitialevent;
190
-      property ontimer : tnotifyevent read fontimer write setontimer;
191
-      property enabled : boolean read fenabled write setenabled;
192
-      property interval	: integer read finterval write setinterval;
193
-
194
-    end;
195
-
196
-    ttaskevent=procedure(wparam,lparam:longint) of object;
197
-
198
-    tltask=class(tobject)
199
-    public
200
-      handler  : ttaskevent;
201
-      obj      : tobject;
202
-      wparam   : longint;
203
-      lparam   : longint;
204
-      nexttask : tltask;
205
-      constructor create(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
206
-    end;
207
-
208
-
209
-
210
-    teventcore=class
211
-    public
212
-      procedure processmessages; virtual;abstract;
213
-      procedure messageloop; virtual;abstract;
214
-      procedure exitmessageloop; virtual;abstract;
215
-      procedure setfdreverse(fd : integer;reverseto : tlasio);virtual;abstract;
216
-      procedure rmasterset(fd : integer;islistensocket : boolean);  virtual;abstract;
217
-      procedure rmasterclr(fd: integer);  virtual;abstract;
218
-      procedure wmasterset(fd : integer); virtual;abstract;
219
-      procedure wmasterclr(fd: integer);  virtual;abstract;
220
-    end;
221
-var
222
-    eventcore : teventcore;
223
-
224
-procedure processmessages;
225
-procedure messageloop;
226
-procedure exitmessageloop;
227
-
228
-var
229
-  firsttimer                            : tltimer    ;
230
-  firsttask  , lasttask   , currenttask : tltask     ;
231
-
232
-  numread                               : integer    ;
233
-  mustrefreshfds                        : boolean    ;
234
-{  lcoretestcount:integer;}
235
-
236
-  asinreleaseflag:boolean;
237
-
238
-
239
-procedure disconnecttasks(aobj:tobject);
240
-procedure addtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
241
-type
242
-  tonaddtask = procedure(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
243
-var
244
-  onaddtask : tonaddtask;
245
-
246
-
247
-procedure sleep(i:integer);
248
-{$ifndef nosignal}
249
-  procedure prepsigpipe;{$ifndef ver1_0}inline;{$endif}
250
-{$endif}
251
-
252
-
253
-implementation
254
-{$ifndef nosignal}
255
-  uses {sockets,}lloopback,lsignal;
256
-{$endif}
257
-{$ifdef win32}
258
-  uses windows,winsock;
259
-{$endif}
260
-{$ifndef win32}
261
-  {$include unixstuff.inc}
262
-{$endif}
263
-{$include ltimevalstuff.inc}
264
-
265
-
266
-{!!! added sleep call -beware}
267
-procedure sleep(i:integer);
268
-var
269
-  tv:ttimeval;
270
-begin
271
-  {$ifdef win32}
272
-    windows.sleep(i);
273
-  {$else}
274
-    tv.tv_sec := i div 1000;
275
-    tv.tv_usec := (i mod 1000) * 1000;
276
-    select(0,nil,nil,nil,@tv);
277
-  {$endif}
278
-end;
279
-
280
-destructor tlcomponent.destroy;
281
-begin
282
-  disconnecttasks(self);
283
-  inherited destroy;
284
-end;
285
-
286
-procedure tlcomponent.releasetaskhandler(wparam,lparam:longint);
287
-begin
288
-  free;
289
-end;
290
-
291
-
292
-procedure tlcomponent.release;
293
-begin
294
-  addtask(releasetaskhandler,self,0,0);
295
-end;
296
-
297
-procedure tlasio.release;
298
-begin
299
-  asinreleaseflag := true;
300
-  inherited release;
301
-end;
302
-
303
-procedure tlasio.doreceiveloop;
304
-begin
305
-  if recvq.size = 0 then exit;
306
-  if assigned(ondataavailable) then ondataavailable(self,0);
307
-  if not (wsonoreceiveloop in componentoptions) then
308
-  if recvq.size > 0 then tltask.create(self.doreceiveloop,self,0,0);
309
-end;
310
-
311
-function tlasio.receivestr;
312
-begin
313
-  setlength(result,recvq.size);
314
-  receive(@result[1],length(result));
315
-end;
316
-
317
-function tlasio.receive(Buf:Pointer;BufSize:integer):integer;
318
-var
319
-  i,a,b:integer;
320
-  p:pointer;
321
-begin
322
-  i := bufsize;
323
-  if recvq.size < i then i := recvq.size;
324
-  a := 0;
325
-  while (a < i) do begin
326
-    b := recvq.get(p,i-a);
327
-    move(p^,buf^,b);
328
-    inc(taddrint(buf),b);
329
-    recvq.del(b);
330
-    inc(a,b);
331
-  end;
332
-  result := i;
333
-  if wsonoreceiveloop in componentoptions then begin
334
-    if recvq.size = 0 then eventcore.rmasterset(fdhandlein,false);
335
-  end;
336
-end;
337
-
338
-constructor tlasio.create;
339
-begin
340
-  inherited create(AOwner);
341
-  if not assigned(eventcore) then raise exception.create('no event core');
342
-  sendq := tfifo.create;
343
-  recvq := tfifo.create;
344
-  state := wsclosed;
345
-  fdhandlein := -1;
346
-  fdhandleout := -1;
347
-end;
348
-
349
-destructor tlasio.destroy;
350
-begin
351
-  destroying := true;
352
-  if state <> wsclosed then close;
353
-  recvq.free;
354
-  sendq.free;
355
-  inherited destroy;
356
-end;
357
-
358
-procedure tlasio.close;
359
-begin
360
-  internalclose(0);
361
-end;
362
-
363
-procedure tlasio.abort;
364
-begin
365
-  close;
366
-end;
367
-
368
-procedure tlasio.fdcleanup;
369
-begin
370
-  if fdhandlein <> -1 then begin
371
-    eventcore.rmasterclr(fdhandlein); //fd_clr(fdhandlein,fdsrmaster)
372
-  end;
373
-  if fdhandleout <> -1 then begin
374
-    eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster)
375
-  end;
376
-  if fdhandlein=fdhandleout then begin
377
-    if fdhandlein <> -1 then begin
378
-      myfdclose(fdhandlein);
379
-    end;
380
-  end else begin
381
-    if fdhandlein <> -1 then begin
382
-      myfdclose(fdhandlein);
383
-    end;
384
-    if fdhandleout <> -1 then begin
385
-      myfdclose(fdhandleout);
386
-    end;
387
-  end;
388
-  fdhandlein := -1;
389
-  fdhandleout := -1;
390
-end;
391
-
392
-procedure tlasio.internalclose(error:word);
393
-begin
394
-  if (state<>wsclosed) and (state<>wsinvalidstate) then begin
395
-    // -2 is a special indication that we should just exist silently
396
-    // (used for connect failure handling when socket creation fails)
397
-    if (fdhandlein = -2) and (fdhandleout = -2) then exit;
398
-    if (fdhandlein < 0) or (fdhandleout < 0) then raise exception.create('internalclose called with invalid fd handles');
399
-    eventcore.rmasterclr(fdhandlein);//fd_clr(fdhandlein,fdsrmaster);
400
-    eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);
401
-
402
-    if closehandles then begin
403
-      {$ifndef win32}
404
-        //anyone remember why this is here? --plugwash
405
-        fcntl(fdhandlein,F_SETFL,0);
406
-      {$endif}
407
-      myfdclose(fdhandlein);
408
-      if fdhandleout <> fdhandlein then begin
409
-        {$ifndef win32}
410
-          fcntl(fdhandleout,F_SETFL,0);
411
-        {$endif}
412
-        myfdclose(fdhandleout);
413
-      end;
414
-      eventcore.setfdreverse(fdhandlein,nil);
415
-      eventcore.setfdreverse(fdhandleout,nil);
416
-
417
-      fdhandlein := -1;
418
-      fdhandleout := -1;
419
-    end;
420
-    state := wsclosed;
421
-
422
-    if assigned(onsessionclosed) then if not destroying then onsessionclosed(self,error);
423
-  end;
424
-  if assigned(sendq) then sendq.del(maxlongint);
425
-end;
426
-
427
-
428
-{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
429
-{ All exceptions *MUST* be handled. If an exception is not handled, the     }
430
-{ application will most likely be shut down !                               }
431
-procedure tlasio.HandleBackGroundException(E: Exception);
432
-var
433
-  CanAbort : Boolean;
434
-begin
435
-  CanAbort := TRUE;
436
-  { First call the error event handler, if any }
437
-  if Assigned(OnBgException) then begin
438
-    try
439
-      OnBgException(Self, E, CanAbort);
440
-    except
441
-    end;
442
-  end;
443
-  { Then abort the socket }
444
-  if CanAbort then begin
445
-    try
446
-      close;
447
-    except
448
-    end;
449
-  end;
450
-end;
451
-
452
-procedure tlasio.sendstr(const str : string);
453
-begin
454
-  putstringinsendbuffer(str);
455
-  sendflush;
456
-end;
457
-
458
-procedure tlasio.putstringinsendbuffer(const newstring : string);
459
-begin
460
-  if newstring <> '' then putdatainsendbuffer(@newstring[1],length(newstring));
461
-end;
462
-
463
-function tlasio.send(data:pointer;len:integer):integer;
464
-begin
465
-  if state <> wsconnected then begin
466
-    result := -1;
467
-    exit;
468
-  end;
469
-  if len < 0 then len := 0;
470
-  result := len;
471
-  putdatainsendbuffer(data,len);
472
-  sendflush;
473
-end;
474
-
475
-
476
-procedure tlasio.putdatainsendbuffer(data:pointer;len:integer);
477
-begin
478
-  sendq.add(data,len);
479
-end;
480
-
481
-function tlasio.sendflush : integer;
482
-var
483
-  lensent : integer;
484
-  data:pointer;
485
-//  fdstestr : fdset;
486
-//  fdstestw : fdset;
487
-begin
488
-  if state <> wsconnected then begin
489
-    result := -1;
490
-    exit;
491
-  end;
492
-
493
-  lensent := sendq.get(data,packetbasesize*2);
494
-  if assigned(data) then result := myfdwrite(fdhandleout,data^,lensent) else result := 0;
495
-
496
-  if result = -1 then lensent := 0 else lensent := result;
497
-
498
-  //sendq := copy(sendq,lensent+1,length(sendq)-lensent);
499
-  sendq.del(lensent);
500
-
501
-  //fd_clr(fdhandleout,fdsw); // this prevents the socket being closed by a write
502
-                            // that sends nothing because a previous socket has
503
-                            // slready flushed this socket when the message loop
504
-                            // reaches it
505
-//  if sendq.size > 0 then begin
506
-    eventcore.wmasterset(fdhandleout);//fd_set(fdhandleout,fdswmaster);
507
-//  end else begin
508
-//    wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);
509
-//  end;
510
-  if result > 0 then begin
511
-    if assigned(onsenddata) then onsenddata(self,result);
512
-//    if sendq.size=0 then if assigned(ondatasent) then begin
513
-//      tltask.create(self.dodatasent,self,0,0);
514
-//      //begin test code
515
-//      fd_zero(fdstestr);
516
-//      fd_zero(fdstestw);
517
-//      fd_set(fdhandlein,fdstestr);
518
-//      fd_set(fdhandleout,fdstestw);
519
-//      select(maxs,@fdstestr,@fdstestw,nil,0);
520
-//      writeln(fd_isset(fdhandlein,fdstestr),' ',fd_isset(fdhandleout,fdstestw));
521
-//      //end test code
522
-//    
523
-//    end;
524
-    writtenthiscycle := true;
525
-  end;
526
-end;
527
-
528
-procedure tlasio.dupnowatch(invalue:longint);
529
-begin
530
-  {  debugout('invalue='+inttostr(invalue));}
531
-  //readln;
532
-  if state<> wsclosed then close;
533
-  fdhandlein := invalue;
534
-  fdhandleout := invalue;
535
-  eventcore.setfdreverse(fdhandlein,self);
536
-  {$ifndef win32}
537
-    fcntl(fdhandlein,F_SETFL,OPEN_NONBLOCK);
538
-  {$endif}
539
-  state := wsconnected;
540
-
541
-end;
542
-
543
-
544
-procedure tlasio.dup(invalue:longint);
545
-begin
546
-  dupnowatch(invalue);
547
-  eventcore.rmasterset(fdhandlein,false);//fd_set(fdhandlein,fdsrmaster);
548
-  eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);
549
-end;
550
-
551
-
552
-procedure tlasio.handlefdtrigger(readtrigger,writetrigger:boolean);
553
-var
554
-  sendflushresult : integer;
555
-  tempbuf:array[0..receivebufsize-1] of byte;
556
-  a:integer;
557
-begin
558
-  if (state=wsconnected) and writetrigger then begin
559
-    //writeln('write trigger');
560
-
561
-    if (sendq.size >0) then begin
562
-
563
-      sendflushresult := sendflush;
564
-      if (sendflushresult <= 0) and (not writtenthiscycle) then begin
565
-        if sendflushresult=0 then begin // linuxerror := 0;
566
-          internalclose(0);
567
-
568
-        end else begin
569
-          {$ifdef win32}
570
-          if getlasterror=WSAEWOULDBLOCK then begin
571
-            //the asynchronous nature of windows messages means we sometimes
572
-            //get here with the buffer full
573
-            //so do nothing in that case
574
-          end else
575
-          {$endif}
576
-          begin
577
-            internalclose({$ifdef win32}getlasterror{$else}linuxerror{$endif});
578
-          end  
579
-        end;
580
-      end;
581
-
582
-    end else begin
583
-      //everything is sent fire off ondatasent event
584
-      if fdhandleout >= 0 then eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);
585
-      if assigned(ondatasent) then tltask.create(self.dodatasent,self,0,0);
586
-    end;
587
-    if assigned(onfdwrite) then onfdwrite(self,0);
588
-  end;
589
-  writtenthiscycle := false;
590
-  if (state =wsconnected) and readtrigger then begin
591
-    if recvq.size=0 then begin
592
-      a := recvbufsize;
593
-      if (a <= 0) or (a > sizeof(tempbuf)) then a := sizeof(tempbuf);
594
-      numread := myfdread(fdhandlein,tempbuf,a);
595
-      if (numread=0) and (not mustrefreshfds) then begin
596
-        {if i remember correctly numread=0 is caused by eof
597
-        if this isn't dealt with then you get a cpu eating infinite loop
598
-        however if onsessionconencted has called processmessages that could
599
-        cause us to drop to here with an empty recvq and nothing left to read
600
-        and we don't want that to cause the socket to close}
601
-
602
-        internalclose(0);
603
-      end else if (numread=-1) then begin
604
-        {$ifdef win32}
605
-          //sometimes on windows we get stale messages due to the inherent delays
606
-          //in the windows message queue
607
-          if WSAGetLastError = wsaewouldblock then begin
608
-            //do nothing
609
-          end else
610
-        {$endif}
611
-        begin
612
-          numread := 0;
613
-          internalclose({$ifdef win32}wsagetlasterror{$else}linuxerror{$endif});
614
-        end;
615
-      end else if numread > 0 then recvq.add(@tempbuf,numread);
616
-    end;
617
-
618
-    if recvq.size > 0 then begin
619
-      if wsonoreceiveloop in componentoptions then eventcore.rmasterclr(fdhandlein); //fd_clr(fdhandlein,fdsrmaster);
620
-      if assigned(ondataavailable) then ondataAvailable(self,0);
621
-      if not (wsonoreceiveloop in componentoptions) then if recvq.size > 0 then
622
-      tltask.create(self.doreceiveloop,self,0,0);
623
-    end;
624
-    //until (numread = 0) or (currentsocket.state<>wsconnected);
625
-{    debugout('inner loop complete');}
626
-  end;
627
-end;
628
-
629
-procedure tlasio.flush;
630
-{$ifdef win32}
631
-type fdset = tfdset;
632
-{$endif}
633
-var
634
-  fds : fdset;
635
-begin
636
-  fd_zero(fds);
637
-  fd_set(fdhandleout,fds);
638
-  while sendq.size>0 do begin
639
-    select(fdhandleout+1,nil,@fds,nil,nil);
640
-    if sendflush <= 0 then exit;
641
-  end;
642
-end;
643
-
644
-procedure tlasio.dodatasent(wparam,lparam:longint);
645
-begin
646
-  if assigned(ondatasent) then ondatasent(self,lparam);
647
-end;
648
-
649
-procedure tlasio.deletebuffereddata;
650
-begin
651
-  sendq.del(maxlongint);
652
-end;
653
-
654
-procedure tlasio.sinkdata(sender:tobject;error:word);
655
-begin
656
-  tlasio(sender).recvq.del(maxlongint);
657
-end;
658
-
659
-{$ifndef win32}
660
-  procedure tltimer.resettimes;
661
-  begin
662
-    gettimeofday(nextts);
663
-    {if not initialevent then} tv_add(nextts,interval);
664
-  end;
665
-{$endif}
666
-
667
-{procedure tltimer.setinitialevent(newvalue : boolean);
668
-begin
669
-  if newvalue <> finitialevent then begin
670
-    finitialevent := newvalue;
671
-    if assigned(timerwrapperinterface) then begin
672
-      timerwrapperinterface.setinitialevent(wrappedtimer,newvalue);
673
-    end else begin
674
-      resettimes;
675
-    end;
676
-  end;
677
-end;}
678
-
679
-procedure tltimer.setontimer(newvalue:tnotifyevent);
680
-begin
681
-  if @newvalue <> @fontimer then begin
682
-    fontimer := newvalue;
683
-    if assigned(timerwrapperinterface) then begin
684
-      timerwrapperinterface.setontimer(wrappedtimer,newvalue);
685
-    end else begin
686
-
687
-    end;
688
-  end;
689
-
690
-end;
691
-
692
-
693
-procedure tltimer.setenabled(newvalue : boolean);
694
-begin
695
-  if newvalue <> fenabled then begin
696
-    fenabled := newvalue;
697
-    if assigned(timerwrapperinterface) then begin
698
-      timerwrapperinterface.setenabled(wrappedtimer,newvalue);
699
-    end else begin
700
-      {$ifdef win32}
701
-        raise exception.create('non wrapper timers are not permitted on windows');
702
-      {$else}
703
-        resettimes;
704
-      {$endif}
705
-    end;
706
-  end;
707
-end;
708
-
709
-procedure tltimer.setinterval(newvalue:integer);
710
-begin
711
-  if newvalue <> finterval then begin
712
-    finterval := newvalue;
713
-    if assigned(timerwrapperinterface) then begin
714
-      timerwrapperinterface.setinterval(wrappedtimer,newvalue);
715
-    end else begin
716
-      {$ifdef win32}
717
-        raise exception.create('non wrapper timers are not permitted on windows');
718
-      {$else}
719
-        resettimes;
720
-      {$endif}
721
-    end;
722
-  end;
723
-
724
-end;
725
-
726
-
727
-
728
-
729
-constructor tltimer.create;
730
-begin
731
-  inherited create(AOwner);
732
-  if assigned(timerwrapperinterface) then begin
733
-    wrappedtimer := timerwrapperinterface.createwrappedtimer;
734
-  end else begin
735
-
736
-
737
-    nexttimer := firsttimer;
738
-    prevtimer := nil;
739
-
740
-    if assigned(nexttimer) then nexttimer.prevtimer := self;
741
-    firsttimer := self;
742
-  end;
743
-  interval := 1000;
744
-  enabled := true;
745
-end;
746
-
747
-destructor tltimer.destroy;
748
-begin
749
-  if assigned(timerwrapperinterface) then begin
750
-    wrappedtimer.free;
751
-  end else begin
752
-    if prevtimer <> nil then begin
753
-      prevtimer.nexttimer := nexttimer;
754
-    end else begin
755
-      firsttimer := nexttimer;
756
-    end;
757
-    if nexttimer <> nil then begin
758
-      nexttimer.prevtimer := prevtimer;
759
-    end;
760
-    
761
-  end;
762
-  inherited destroy;
763
-end;
764
-
765
-constructor tltask.create(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
766
-begin
767
-  inherited create;
768
-  if assigned(onaddtask) then onaddtask(ahandler,aobj,awparam,alparam);
769
-  handler   := ahandler;
770
-  obj       := aobj;
771
-  wparam    := awparam;
772
-  lparam    := alparam;
773
-  {nexttask  := firsttask;
774
-  firsttask := self;}
775
-  if assigned(lasttask) then begin
776
-    lasttask.nexttask := self;
777
-  end else begin
778
-    firsttask := self;
779
-  end;
780
-  lasttask := self;
781
-  //ahandler(wparam,lparam);
782
-end;
783
-
784
-procedure addtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
785
-begin
786
-
787
-  tltask.create(ahandler,aobj,awparam,alparam);
788
-end;
789
-
790
-{$ifndef nosignal}
791
-  procedure prepsigpipe;{$ifndef ver1_0}inline;
792
-{$endif}
793
-  begin
794
-    starthandlesignal(sigpipe);
795
-    if not assigned(signalloopback) then begin
796
-      signalloopback := tlloopback.create(nil);
797
-      signalloopback.ondataAvailable := signalloopback.sinkdata;
798
-
799
-    end;
800
-
801
-  end;
802
-{$endif}
803
-
804
-procedure processtasks;//inline;
805
-var
806
-  temptask                : tltask   ;
807
-
808
-begin
809
-
810
-  if not assigned(currenttask) then begin
811
-    currenttask := firsttask;
812
-    firsttask := nil;
813
-    lasttask  := nil;
814
-  end;
815
-  while assigned(currenttask) do begin
816
-
817
-    if assigned(currenttask.handler) then currenttask.handler(currenttask.wparam,currenttask.lparam);
818
-    if assigned(currenttask) then begin
819
-      temptask := currenttask;
820
-      currenttask := currenttask.nexttask;
821
-      temptask.free;
822
-    end;
823
-    //writeln('processed a task');
824
-  end;
825
-
826
-end;
827
-
828
-
829
-
830
-
831
-procedure disconnecttasks(aobj:tobject);
832
-var
833
-  currenttasklocal : tltask ;
834
-  counter          : byte   ;
835
-begin
836
-  for counter := 0 to 1 do begin
837
-    if counter = 0 then begin
838
-      currenttasklocal := firsttask; //main list of tasks
839
-    end else begin
840
-      currenttasklocal := currenttask; //needed in case called from a task
841
-    end;
842
-    // note i don't bother to sestroy the links here as that will happen when
843
-    // the list of tasks is processed anyway
844
-    while assigned(currenttasklocal) do begin
845
-      if currenttasklocal.obj = aobj then begin
846
-        currenttasklocal.obj := nil;
847
-        currenttasklocal.handler := nil;
848
-      end;
849
-      currenttasklocal := currenttasklocal.nexttask;
850
-    end;
851
-  end;
852
-end;
853
-
854
-
855
-procedure processmessages;
856
-begin
857
-  eventcore.processmessages;
858
-end;
859
-procedure messageloop;
860
-begin
861
-  eventcore.messageloop;
862
-end;
863
-
864
-procedure exitmessageloop;
865
-begin
866
-  eventcore.exitmessageloop;
867
-end;
868
-
869
-function tlasio.RealSend(Data : Pointer; Len : Integer) : Integer;
870
-begin
871
-  result := myfdwrite(fdhandleout,data^,len);
872
-  if (result > 0) and assigned(onsenddata) then onsenddata(self,result);
873
-  eventcore.wmasterset(fdhandleout);
874
-end;
875
-{$ifndef win32}
876
-  procedure tlasio.myfdclose(fd : integer);
877
-  begin
878
-    fdclose(fd);
879
-  end;
880
-  function tlasio.myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt;
881
-  begin
882
-    result := fdwrite(fd,buf,size);
883
-  end;
884
-
885
-  function tlasio.myfdread(fd: LongInt;var buf;size: LongInt):LongInt;
886
-  begin
887
-    result := fdread(fd,buf,size);
888
-  end;
889
-
890
-
891
-{$endif}
892
-
893
-
894
-begin
895
-  firsttask := nil;
896
-  
897
-
898
-  {$ifndef nosignal}
899
-    signalloopback := nil;
900
-  {$endif}
901
-end.
902
-
903
-
904
-
905
-
906
-

+ 0
- 40
libwin/lcore/lcoreconfig.inc Parādīt failu

@@ -1,40 +0,0 @@
1
-
2
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
3
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
4
-  which is included in the package
5
-  ----------------------------------------------------------------------------- }
6
-
7
-{this enables the entire ipv6 functionality - resolving, connecting, etc
8
-this is enabled by default to make all apps using lcore automatically ipv6 aware.
9
-to disable, undefine it here, or define "noipv6" in the app}
10
-
11
-{$ifndef noipv6}
12
-{$define ipv6}
13
-{$endif}
14
-
15
-{-------------------------------------------------------------------------------------}
16
-{there are 2 ways to use DNS in lcore: dnscore, which an entire built in DNS client, and getaddrinfo.
17
-dnscore is always included on *nix to avoid libc dependency problems, but getaddrinfo is used on windows.
18
-when getaddrinfo is used, there is no reason to include dnscore, and it increases the exe size,
19
-unless you want to use custom nameserver addresses. enable this setting to always include it.}
20
-
21
-{-$define syncdnscore}
22
-
23
-{-------------------------------------------------------------------------------------}
24
-{lcore contains a built in general purpose secure random number generator, which is used elsewhere in lcore, for
25
-example by the DNS resolver. the used random function can be hooked to point to one's own RNG as desired.
26
-it is then also possible to not include the built in RNG in the exe, which reduces code size}
27
-
28
-{-$define nolcorernd}
29
-
30
-{-------------------------------------------------------------------------------------}
31
-{on windows up to XP, listening on ipv6 will not listen on ipv4, while on other platforms it does, 
32
-so a single listener cant get all connections for a port number, only those for one address family.
33
-also it means a portable app would gave to deal with inconsistent behavior.
34
-enable this option to simulate the behavior of listening on both v4 and v6}
35
-
36
-{$ifdef win32}{$ifdef ipv6}
37
-{$define secondlistener}
38
-{$endif}{$endif}
39
-
40
-{-------------------------------------------------------------------------------------}

+ 0
- 142
libwin/lcore/lcoregtklaz.pas Parādīt failu

@@ -1,142 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-      
6
-unit lcoregtklaz;
7
-{$mode delphi}
8
-interface
9
-	
10
-uses baseunix,unix,glib, gdk, gtk,lcore,forms,fd_utils,classes;
11
-//procedure lcoregtklazrun;
12
-const
13
-  G_IO_IN=1;
14
-  G_IO_OUT=4;
15
-  G_IO_PRI=2;
16
-  G_IO_ERR=8;
17
-
18
-  G_IO_HUP=16;
19
-  G_IO_NVAL=32;
20
-type
21
-  tlaztimerwrapperinterface=class(ttimerwrapperinterface)
22
-  public
23
-    function createwrappedtimer : tobject;override;
24
-//    procedure setinitialevent(wrappedtimer : tobject;newvalue : boolean);override;
25
-    procedure setontimer(wrappedtimer : tobject;newvalue:tnotifyevent);override;
26
-    procedure setenabled(wrappedtimer : tobject;newvalue : boolean);override;
27
-    procedure setinterval(wrappedtimer : tobject;newvalue : integer);override;
28
-  end;
29
-
30
-procedure lcoregtklazinit;
31
-implementation
32
-  uses
33
-    ExtCtrls;
34
-{$I unixstuff.inc}
35
-var
36
-  giochannels : array[0..absoloutemaxs] of pgiochannel;
37
-
38
-function iocallback(source:PGIOChannel; condition:TGIOCondition; data:gpointer):gboolean;cdecl;
39
-// return true if we want the callback to stay
40
-var
41
-  fd                    : integer ;
42
-  fdsrlocal , fdswlocal : fdset   ;
43
-  currentasio           : tlasio  ;
44
-begin
45
-  fd := g_io_channel_unix_get_fd(source);
46
-  fd_zero(fdsrlocal);
47
-  fd_set(fd,fdsrlocal);
48
-  fdswlocal := fdsrlocal;
49
-  select(fd+1,@fdsrlocal,@fdswlocal,nil,0);
50
-  if fd_isset(fd,fdsrlocal) or fd_isset(fd,fdsrlocal) then begin
51
-    currentasio := fdreverse[fd];
52
-    if assigned(currentasio) then begin
53
-      currentasio.handlefdtrigger(fd_isset(currentasio.fdhandlein,fdsrlocal),fd_isset(currentasio.fdhandleout,fdswlocal));
54
-    end else begin
55
-      rmasterclr(fd);
56
-      wmasterclr(fd);
57
-    end;
58
-  end;
59
-  case condition of
60
-    G_IO_IN : begin
61
-      result := rmasterisset(fd);
62
-    end;
63
-    G_IO_OUT : begin
64
-      result := wmasterisset(fd);
65
-    end;
66
-  end;
67
-end;
68
-
69
-procedure gtkrmasterset(fd : integer);
70
-begin
71
-  if not assigned(giochannels[fd]) then giochannels[fd] := g_io_channel_unix_new(fd);
72
-  g_io_add_watch(giochannels[fd],G_IO_IN,iocallback,nil);
73
-end;
74
-
75
-procedure gtkrmasterclr(fd: integer);
76
-begin
77
-end;
78
-  
79
-procedure gtkwmasterset(fd : integer);
80
-begin
81
-  if not assigned(giochannels[fd]) then giochannels[fd] := g_io_channel_unix_new(fd);
82
-  g_io_add_watch(giochannels[fd],G_IO_OUT,iocallback,nil);
83
-end;
84
-
85
-procedure gtkwmasterclr(fd: integer);
86
-begin
87
-end;
88
-
89
-type
90
-  tsc = class
91
-    procedure dotasksandsink(sender:tobject;error:word);
92
-  end;
93
-var
94
-  taskloopback : tlloopback;
95
-  sc           : tsc;
96
-procedure tsc.dotasksandsink(sender:tobject;error:word);
97
-begin
98
-  with tlasio(sender) do begin
99
-    sinkdata(sender,error);
100
-    processtasks;
101
-  end;
102
-end;
103
-procedure gtkaddtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
104
-begin
105
-  taskloopback.sendstr(' ');
106
-  
107
-end;
108
-
109
-procedure lcoregtklazinit;
110
-begin
111
-  onrmasterset := gtkrmasterset;
112
-  onrmasterclr := gtkrmasterclr;
113
-  onwmasterset := gtkwmasterset;
114
-  onwmasterclr := gtkwmasterclr;
115
-  onaddtask := gtkaddtask;
116
-  taskloopback := tlloopback.create(nil);
117
-  taskloopback.ondataavailable := sc.dotasksandsink;
118
-  timerwrapperinterface := tlaztimerwrapperinterface.create(nil);
119
-end;
120
-
121
-function tlaztimerwrapperinterface.createwrappedtimer : tobject;
122
-begin
123
-  result := ttimer.create(nil);
124
-end;
125
-procedure tlaztimerwrapperinterface.setontimer(wrappedtimer : tobject;newvalue:tnotifyevent);
126
-begin
127
-  ttimer(wrappedtimer).ontimer := newvalue;
128
-end;
129
-procedure tlaztimerwrapperinterface.setenabled(wrappedtimer : tobject;newvalue : boolean);
130
-begin
131
-  ttimer(wrappedtimer).enabled := newvalue;
132
-end;
133
-
134
-
135
-procedure tlaztimerwrapperinterface.setinterval(wrappedtimer : tobject;newvalue : integer);
136
-begin
137
-  ttimer(wrappedtimer).interval := newvalue;
138
-end;
139
-
140
-
141
-end.
142
-

+ 0
- 432
libwin/lcore/lcorernd.pas Parādīt failu

@@ -1,432 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-unit lcorernd;
7
-
8
-interface
9
-
10
-{$include lcoreconfig.inc}
11
-
12
-{
13
-written by Bas Steendijk (beware)
14
-
15
-the aim of this unit is to provide randomness in a consistent way, using OS specific methods for seeding
16
-
17
-this unit uses MD5 for performance and code size, but it is made so it is easy to use a different hash,
18
-as long as it is atleat 128 bits, and a multiple of the "word size" (32 bits)
19
-
20
-goals:
21
-
22
-- for the code to be:
23
- - relatively simple and small
24
- - reasonably fast
25
-
26
-- for the numbers to be
27
- - random: pass diehard and similar tests
28
- - unique: generate UUID's
29
- - secure: difficult for a remote attacker to guess the internal state, even
30
-   when given some output
31
-
32
-typical intended uses:
33
- - anything that needs random numbers without extreme demands on security or
34
-   speed should be able to use this
35
- - seeding other (faster) RNG's
36
- - generation of passwords, UUID's, cookies, and session keys
37
- - randomizing protocol fields to protect against spoofing attacks
38
- - randomness for games
39
-
40
-this is not intended to be directly used for:
41
-- high securirity purposes (generating RSA root keys etc)
42
-- needing random numbers at very high rates (disk wiping, some simulations, etc)
43
-
44
-performance:
45
-- 24 MB/s on 2.2 GHz athlon64 core on windows XP 32 bits
46
-- 6.4 MB/s on 1 GHz p3 on linux
47
-
48
-exe size:
49
-- fpc 2.2, linux: fastmd5: 12 kb; lcorernd: 6 kb.
50
-- delphi 6: fastmd5: 3 kb; lcorernd: 2 kb
51
-
52
-reasoning behind the security of this RNG:
53
-
54
-- seeding:
55
-1: i assume that any attacker has no local access to the machine. if one gained
56
-  this, then there are more seriousness weaknesses to consider.
57
-2: i attempt to use enough seeding to be difficult to guess.
58
-  on windows: GUID, various readouts of hi res timestamps, heap stats, cursor
59
-  position
60
-  on *nix: i assume /dev/(u)random output is secure and difficult to guess. if
61
-  it misses, i use /dev/wtmp, which typically has as lot of entropy in it. i also use hi res timestamps.
62
-3: on a state compromise, one can easily get up to the hash size worth of previous output, beyond that one has
63
-  to invert the hash operation.
64
-
65
-- mixing/expansion: a secure hash random walk on a buffer with a constant secret and a changing exposed part,
66
-  the big secret part serves to make it difficult for an attacker to predict next and previous output.
67
-  the secret part is changed during a reseed.
68
-
69
-
70
-                                       OS randomness
71
-                                             v
72
-                              <wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww>
73
- ____________________________  ________________________________________________
74
-[            pool            ][                    seed                        ]
75
-[hashsize][hashsize][hashsize]
76
-          <rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr>
77
-                bighash()             seeding
78
-                   v
79
-          <wwwwwwwwwwwwwwwwww>
80
-<rrrrrrrrrrrrrrrrrrrrrrrrrrrr>
81
-  hash()                            random walk
82
-    v
83
-<wwwwwwww>
84
-[ output ][      secret      ]
85
-
86
-
87
-this needs testing on platforms other than i386
88
-
89
-
90
-these routines are called by everything else in lcore, and if the app coder desires, by the app.
91
-because one may want to use their own random number source, the PRNG here can be excluded from linking,
92
-and the routines here can be hooked.
93
-}
94
-
95
-{$include uint32.inc}
96
-
97
-{return a dword with 32 random bits}
98
-type
99
-  wordtype=uint32;
100
-
101
-var
102
-  randomdword:function:wordtype;
103
-
104
-{fill a buffer with random bytes}
105
-procedure fillrandom(var buf;length:integer);
106
-
107
-{generate an integer of 0 <= N < i}
108
-function randominteger(i:longint):longint;
109
-
110
-{generate an integer with the lowest b bits being random}
111
-function randombits(b:integer):longint;
112
-
113
-{generate a version 4 random uuid}
114
-function generate_uuid:string;
115
-
116
-{$ifndef nolcorernd}
117
-
118
-{call this to mix seeding into the pool. is normally done automatically and does not have to be called
119
-but can be done if one desires more security, for example for key generation}
120
-procedure seedpool;
121
-
122
-{get some raw OS specific randomness. the output is not mixed so it should not be used directly as random numbers}
123
-function collect_seeding(var output;const bufsize:integer):integer;
124
-
125
-function internalrandomdword:wordtype;
126
-
127
-var
128
-  reseedinterval:integer=64;
129
-{$endif}
130
-
131
-implementation
132
-
133
-{$ifndef nolcorernd}
134
-uses
135
-  {$ifdef win32}windows,activex,{$endif}
136
-  {$ifdef unix}
137
-    {$ifdef ver1_0}
138
-      linux,
139
-    {$else}
140
-      baseunix,unix,unixutil,
141
-    {$endif}
142
-  {$endif}
143
-  fastmd5,sysutils;
144
-
145
-{$ifdef unix}{$include unixstuff.inc}{$endif}
146
-
147
-type
148
-  {hashtype must be array of bytes}
149
-  hashtype=tmd5;
150
-
151
-const
152
-  wordsizeshift=2;
153
-  wordsize=1 shl wordsizeshift;
154
-  //wordsize check commented out for d3 compatibility
155
-  //{ $if (wordsize <> sizeof(wordtype))}'wordsizeshift must be setcorrectly'{ $ifend}
156
-  hashsize=sizeof(hashtype);
157
-  halfhashsize=hashsize div 2;
158
-  hashdwords=hashsize div wordsize;
159
-  pooldwords=3*hashdwords;
160
-  seeddwords=32;
161
-  hashpasssize=48; {this number has to be small enough that hashing this size uses only one block transform}
162
-
163
-var
164
-  {the seed part of this buffer must be atleast as big as the OS seed (windows: 104 bytes, unix: 36 bytes)}
165
-  pool:array[0..(pooldwords+seeddwords-1)] of wordtype;
166
-  reseedcountdown:integer;
167
-
168
-{$ifdef win32}
169
-function collect_seeding(var output;const bufsize:integer):integer;
170
-var
171
-  l:packed record
172
-    guid:array[0..3] of longint;
173
-    qpcbuf:array[0..1] of longint;
174
-    rdtscbuf:array[0..1] of longint;
175
-    systemtimebuf:array[0..3] of longint;
176
-    pid:longint;
177
-    tid:longint;
178
-    cursor:tpoint;
179
-    hs:theapstatus;
180
-  end absolute output;
181
-  rdtsc_0,rdtsc_1:integer;
182
-begin
183
-  result := 0;
184
-  if (bufsize < sizeof(l)) then exit;
185
-  result := sizeof(l);
186
-  {PID}
187
-  l.pid := GetCurrentProcessId;
188
-  l.tid := GetCurrentThreadId;
189
-
190
-  {COCREATEGUID}
191
-  cocreateguid(tguid(l.guid));
192
-
193
-  {QUERYPERFORMANCECOUNTER}
194
-  queryperformancecounter(tlargeinteger(l.qpcbuf));
195
-
196
-  {RDTSC}
197
-  {$ifdef cpu386}
198
-  asm
199
-    db $0F; db $31
200
-    mov rdtsc_0,eax
201
-    mov rdtsc_1,edx
202
-  end;
203
-  l.rdtscbuf[0] := rdtsc_0;
204
-  l.rdtscbuf[1] := rdtsc_1;
205
-  {$endif}
206
-  {GETSYSTEMTIME}
207
-  getsystemtime(tsystemtime(l.systemtimebuf));
208
-
209
-  {cursor position}
210
-  getcursorpos(l.cursor);
211
-
212
-  l.hs := getheapstatus;
213
-end;
214
-{$endif}
215
-
216
-{$ifdef unix}
217
-
218
-var
219
-  wtmpinited:boolean;
220
-  wtmpcached:hashtype;
221
-
222
-procedure wtmphash;
223
-var
224
-  f:file;
225
-  buf:array[0..4095] of byte;
226
-  numread:integer;
227
-  state:tmd5state;
228
-begin
229
-  if wtmpinited then exit;
230
-
231
-  assignfile(f,'/var/log/wtmp');
232
-  filemode := 0;
233
-  {$i-}reset(f,1);{$i+}
234
-  if (ioresult <> 0) then exit;
235
-  md5init(state);
236
-  while not eof(f) do begin
237
-    blockread(f,buf,sizeof(buf),numread);
238
-    md5process(state,buf,numread);
239
-  end;
240
-  closefile(f);
241
-  md5finish(state,wtmpcached);
242
-  wtmpinited := true;
243
-end;
244
-
245
-
246
-function collect_seeding(var output;const bufsize:integer):integer;
247
-var
248
-  f:file;
249
-  a:integer;
250
-  l:packed record
251
-    devrnd:array[0..3] of integer;
252
-    rdtscbuf:array[0..1] of integer;
253
-    tv:ttimeval;
254
-    pid:integer;
255
-  end absolute output;
256
-  rdtsc_0,rdtsc_1:integer;
257
-
258
-begin
259
-  result := 0;
260
-  if (bufsize < sizeof(l)) then exit;
261
-  result := sizeof(l);
262
-
263
-  {/DEV/URANDOM}
264
-  a := 1;
265
-  assignfile(f,'/dev/urandom');
266
-  filemode := 0;
267
-  {$i-}reset(f,1);{$i+}
268
-  a := ioresult;
269
-  if (a <> 0) then begin
270
-    assignfile(f,'/dev/random');
271
-    {$i-}reset(f,1);{$i+}
272
-    a := ioresult;
273
-  end;
274
-  if (a = 0) then begin
275
-    blockread(f,l.devrnd,sizeof(l.devrnd));
276
-    closefile(f);
277
-  end else begin
278
-    {the OS we are on has no /dev/random or /dev/urandom, get a hash from /var/log/wtmp}
279
-    wtmphash;
280
-    move(wtmpcached,l.devrnd,sizeof(l.devrnd));
281
-  end;
282
-  {get more randomness in case there's no /dev/random}
283
-  {$ifdef cpu386}{$ASMMODE intel}
284
-  asm
285
-    db $0F; db $31
286
-    mov rdtsc_0,eax
287
-    mov rdtsc_1,edx
288
-  end;
289
-  l.rdtscbuf[0] := rdtsc_0;
290
-  l.rdtscbuf[1] := rdtsc_1;
291
-  {$endif}
292
-
293
-  gettimeofday(l.tv);
294
-  l.pid := getpid;
295
-end;
296
-{$endif}
297
-
298
-{this produces a hash which is twice the native hash size (32 bytes for MD5)}
299
-procedure bighash(const input;len:integer;var output);
300
-var
301
-  inarr:array[0..65535] of byte absolute input;
302
-  outarr:array[0..65535] of byte absolute output;
303
-
304
-  h1,h2,h3,h4:hashtype;
305
-  a:integer;
306
-begin
307
-  a := len div 2;
308
-  {first hash round}
309
-  getmd5(inarr[0],a,h1);
310
-  getmd5(inarr[a],len-a,h2);
311
-
312
-  move(h1[0],h3[0],halfhashsize);
313
-  move(h2[0],h3[halfhashsize],halfhashsize);
314
-  move(h1[halfhashsize],h4[0],halfhashsize);
315
-  move(h2[halfhashsize],h4[halfhashsize],halfhashsize);
316
-
317
-  getmd5(h3,hashsize,outarr[0]);
318
-  getmd5(h4,hashsize,outarr[hashsize]);
319
-end;
320
-
321
-procedure seedpool;
322
-var
323
-  a:integer;
324
-begin
325
-  a := collect_seeding(pool[pooldwords],seeddwords*wordsize);
326
-  if (a = 0) then halt;
327
-  bighash(pool[hashdwords],(2*hashsize)+a,pool[hashdwords]);
328
-  getmd5(pool[0],hashpasssize,pool[0]);
329
-end;
330
-
331
-function internalrandomdword;
332
-begin
333
-  if (reseedcountdown <= 0) then begin
334
-    seedpool;
335
-    reseedcountdown := reseedinterval * hashdwords;
336
-  end else if ((reseedcountdown mod hashdwords) = 0) then begin;
337
-    getmd5(pool[0],hashpasssize,pool[0]);
338
-  end;
339
-  dec(reseedcountdown);
340
-
341
-  result := pool[reseedcountdown mod hashdwords];
342
-end;
343
-{$endif}
344
-
345
-procedure fillrandom(var buf;length:integer);
346
-var
347
-  a,b:integer;
348
-  buf_:array[0..16383] of uint32 absolute buf;
349
-
350
-begin
351
-  b := 0;
352
-  for a := (length shr wordsizeshift)-1 downto 0 do begin
353
-    buf_[b] := randomdword;
354
-    inc(b);
355
-  end;
356
-  length := length and (wordsize-1);
357
-  if length <> 0 then begin
358
-    a := randomdword;
359
-    move(a,buf_[b],length);
360
-  end;
361
-end;
362
-
363
-const
364
-  wordsizebits=32;
365
-
366
-function randombits(b:integer):longint;
367
-begin
368
-  result := randomdword;
369
-  result := result and (-1 shr (wordsizebits-b));
370
-  if (b = 0) then result := 0;
371
-end;
372
-
373
-function randominteger(i:longint):longint;
374
-var
375
-  a,b:integer;
376
-  j:integer;
377
-begin
378
-  //bitscounter := bitscounter + numofbitsininteger(i);
379
-  if (i = 0) then begin
380
-    result := 0;
381
-    exit;
382
-  end;
383
-  {find number of bits needed}
384
-  j := i-1;
385
-  if (j < 0) then begin
386
-    result := randombits(wordsizebits);
387
-    exit
388
-  end else if (j >= (1 shl (wordsizebits-2))) then begin
389
-    b := wordsizebits-1
390
-  end else begin
391
-    b := -1;
392
-    for a := 0 to (wordsizebits-2) do begin
393
-      if j < 1 shl a then begin
394
-        b := a;
395
-        break;
396
-      end;
397
-    end;
398
-  end;
399
-  repeat
400
-    result := randombits(b);
401
-  until result < i;
402
-end;
403
-
404
-const
405
-  ch:array[0..15] of char='0123456789abcdef';
406
-
407
-function generate_uuid:string;
408
-var
409
-  buf:array[0..7] of word;
410
-function inttohex(w:word):string;
411
-begin
412
-  result := ch[w shr 12] + ch[(w shr 8) and $f] + ch[(w shr 4) and $f] + ch[w and $f];
413
-end;
414
-begin
415
-  fillrandom(buf,sizeof(buf));
416
-
417
-  {uuid version 4}
418
-  buf[3] := (buf[3] and $fff) or $4000;
419
-
420
-  {uuid version 4}
421
-  buf[4] := (buf[4] and $3fff) or $8000;
422
-
423
-  result := inttohex(buf[0]) + inttohex(buf[1]) + '-' + inttohex(buf[2]) +'-'+ inttohex(buf[3]) + '-' + inttohex(buf[4])
424
-  + '-' + inttohex(buf[5]) + inttohex(buf[6]) + inttohex(buf[7]);
425
-end;
426
-
427
-{$ifndef nolcorernd}
428
-initialization randomdword := @internalrandomdword;
429
-{$endif}
430
-
431
-end.
432
-

+ 0
- 382
libwin/lcore/lcoreselect.pas Parādīt failu

@@ -1,382 +0,0 @@
1
-{lsocket.pas}
2
-
3
-{io and timer code by plugwash}
4
-
5
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
6
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
7
-  which is included in the package
8
-  ----------------------------------------------------------------------------- }
9
-
10
-{$ifdef fpc}
11
-  {$ifndef ver1_0}
12
-    {$define useinline}
13
-  {$endif}
14
-{$endif}
15
-
16
-unit lcoreselect;
17
-
18
-
19
-interface
20
-uses
21
-  {$ifdef VER1_0}
22
-    linux,
23
-  {$else}
24
-    baseunix,unix,unixutil,
25
-  {$endif}
26
-  fd_utils;
27
-var
28
-  maxs                                  : longint    ;
29
-  exitloopflag                          : boolean    ; {if set by app, exit mainloop}
30
-
31
-function getfdsrmaster : fdset; {$ifdef useinline}inline;{$endif}
32
-function getfdswmaster : fdset; {$ifdef useinline}inline;{$endif}
33
-
34
-procedure lcoreinit;
35
-
36
-implementation
37
-uses
38
-  lcore,sysutils,
39
-  classes,pgtypes,bfifo,
40
-  {$ifndef nosignal}
41
-    lsignal;
42
-  {$endif}
43
-
44
-{$include unixstuff.inc}
45
-{$include ltimevalstuff.inc}
46
-
47
-const
48
-  absoloutemaxs_select = (sizeof(fdset)*8)-1;
49
-
50
-var
51
-  fdreverse:array[0..absoloutemaxs_select] of tlasio;
52
-type
53
-  tselecteventcore=class(teventcore)
54
-    public
55
-      procedure processmessages; override;
56
-      procedure messageloop; override;
57
-      procedure exitmessageloop;override;
58
-      procedure setfdreverse(fd : integer;reverseto : tlasio); override;
59
-      procedure rmasterset(fd : integer;islistensocket : boolean); override;
60
-      procedure rmasterclr(fd: integer); override;
61
-      procedure wmasterset(fd : integer); override;
62
-      procedure wmasterclr(fd: integer); override;
63
-    end;
64
-
65
-procedure processtimers;inline;
66
-var
67
-  tv           ,tvnow     : ttimeval ;
68
-  currenttimer            : tltimer   ;
69
-  temptimer               : tltimer  ;
70
-
71
-begin
72
-  gettimeofday(tvnow);
73
-  currenttimer := firsttimer;
74
-  while assigned(currenttimer) do begin
75
-    //writeln(currenttimer.enabled);
76
-    if tv_compare(tvnow,ttimeval(currenttimer.nextts)) and currenttimer.enabled then begin
77
-      //if assigned(currenttimer.ontimer) then begin
78
-      //  if currenttimer.enabled then if currenttimer.initialevent or currenttimer.initialdone then currenttimer.ontimer(currenttimer);
79
-      //  currenttimer.initialdone := true;
80
-      //end;
81
-      if assigned(currenttimer.ontimer) then currenttimer.ontimer(currenttimer);
82
-      currenttimer.nextts := timeval(tvnow);
83
-      tv_add(ttimeval(currenttimer.nextts),currenttimer.interval);
84
-    end;
85
-    temptimer := currenttimer;
86
-    currenttimer := currenttimer.nexttimer;
87
-  end;
88
-end;
89
-
90
-procedure processasios(var fdsr,fdsw:fdset);//inline;
91
-var
92
-  currentsocket : tlasio  ;
93
-  tempsocket    : tlasio  ;
94
-  socketcount   : integer ; // for debugging perposes :)
95
-  dw,bt:integer;
96
-begin
97
-{  inc(lcoretestcount);}
98
-
99
-    //the message loop will exit if all lasio's and ltimer's and lsignal's are destroyed
100
-    //if (not assigned(firstasin)) and (not assigned(firsttimer)) and (not assigned(firstsignal)) then exit;
101
-
102
-
103
-  {------- test optimised loop}
104
-  socketcount := 0;
105
-  for dw := (maxs shr 5) downto 0 do if (fdsr[dw] or fdsw[dw]) <> 0 then begin
106
-    for bt := 0 to 31 do if (fdsr[dw] or fdsw[dw]) and (1 shl bt) <> 0 then begin
107
-      inc(socketcount);
108
-      currentsocket := fdreverse[dw shl 5 or bt];
109
-      {if not assigned(currentsocket) then raise exception.create('currentsocket not assigned');
110
-      if currentsocket.fdhandlein < 0 then raise exception.create('currentsocket.fdhandlein out of range');}
111
-      {i've seen the out of range case actually happening, so it can happen. test: just close the fd - beware}
112
-      if not assigned(currentsocket) then begin
113
-        fdclose(dw shl 5 or bt);
114
-        continue
115
-      end;
116
-      if currentsocket.fdhandlein < 0 then begin
117
-        fdclose(dw shl 5 or bt);
118
-        continue
119
-      end;
120
-      try
121
-        currentsocket.handlefdtrigger(fd_isset(currentsocket.fdhandlein,fdsr),fd_isset(currentsocket.fdhandleout,fdsw));
122
-      except
123
-        on E: exception do begin
124
-          currentsocket.HandleBackGroundException(e);
125
-        end;
126
-      end;
127
-
128
-      if mustrefreshfds then begin
129
-        if select(maxs+1,@fdsr,@fdsw,nil,0) <= 0 then begin
130
-          fd_zero(fdsr);
131
-          fd_zero(fdsw);
132
-        end;
133
-      end;
134
-    end;
135
-  end;
136
-
137
-  {
138
-  !!! issues:
139
-  - sockets which are released may not be freed because theyre never processed by the loop
140
-  made new code for handling this, using asinreleaseflag
141
-
142
-  - when/why does the mustrefreshfds select apply, sheck if i did it correctly?
143
-
144
-  - what happens if calling handlefdtrigger for a socket which does not have an event
145
-  }
146
-  {------- original loop}
147
-
148
-  (*
149
-  currentsocket := firstasin;
150
-  socketcount := 0;
151
-  while assigned(currentsocket) do begin
152
-    if mustrefreshfds then begin
153
-      if select(maxs,@fdsr,@fdsw,nil,0) <= 0 then begin
154
-        fd_zero(fdsr);
155
-        fd_zero(fdsw);
156
-      end;
157
-    end;
158
-    try
159
-      if fd_isset(currentsocket.fdhandlein,fdsr) or fd_isset(currentsocket.fdhandleout,fdsw) then begin
160
-        currentsocket.handlefdtrigger(fd_isset(currentsocket.fdhandlein,fdsr),fd_isset(currentsocket.fdhandleout,fdsw));
161
-      end;
162
-    except
163
-      on E: exception do begin
164
-        currentsocket.HandleBackGroundException(e);
165
-      end;
166
-    end;
167
-    tempsocket := currentsocket;
168
-    currentsocket := currentsocket.nextasin;
169
-    inc(socketcount);
170
-    if tempsocket.released then begin
171
-      tempsocket.free;
172
-    end;
173
-  end; *)
174
-{  debugout('socketcount='+inttostr(socketcount));}
175
-end;
176
-
177
-procedure tselecteventcore.processmessages;
178
-var
179
-  fdsr         , fdsw : fdset   ;
180
-  selectresult        : longint ;
181
-begin
182
-  mustrefreshfds := false;
183
-  {$ifndef nosignal}
184
-    prepsigpipe;
185
-  {$endif}
186
-  selectresult := select(maxs+1,@fdsr,@fdsw,nil,0);
187
-  while (selectresult>0) or assigned(firsttask) or assigned(currenttask) do begin;
188
-
189
-    processtasks;
190
-    processtimers;
191
-    if selectresult > 0 then begin
192
-      processasios(fdsr,fdsw);
193
-    end;
194
-    selectresult := select(maxs+1,@fdsr,@fdsw,nil,0);
195
-
196
-  end;
197
-  mustrefreshfds := true;
198
-end;
199
-
200
-
201
-var
202
-  FDSR , FDSW : fdset;
203
-
204
-var
205
-  fdsrmaster , fdswmaster               : fdset      ;
206
-
207
-function getfdsrmaster : fdset; {$ifdef fpc}inline;{$endif}
208
-begin
209
-  result := fdsrmaster;
210
-end;
211
-function getfdswmaster : fdset; {$ifdef fpc}inline;{$endif}
212
-begin
213
-  result := fdswmaster;
214
-end;
215
-
216
-
217
-Function  doSelect(timeOut:PTimeVal):longint;//inline;
218
-var
219
-  localtimeval : ttimeval;
220
-  maxslocal    : integer;
221
-begin
222
-  //unblock signals
223
-  //zeromemory(@sset,sizeof(sset));
224
-  //sset[0] := ;
225
-  fdsr := getfdsrmaster;
226
-  fdsw := getfdswmaster;
227
-
228
-  if assigned(firsttask) then begin
229
-    localtimeval.tv_sec  := 0;
230
-    localtimeval.tv_usec := 0;
231
-    timeout := @localtimeval;
232
-  end;
233
-
234
-  maxslocal := maxs;
235
-  mustrefreshfds := false;
236
-{  debugout('about to call select');}
237
-  {$ifndef nosignal}
238
-    sigprocmask(SIG_UNBLOCK,@blockset,nil);
239
-  {$endif}
240
-  result := select(maxslocal+1,@FDSR,@FDSW,nil,timeout);
241
-  if result <= 0 then begin
242
-    fd_zero(FDSR);
243
-    fd_zero(FDSW);
244
-    if result=-1 then begin
245
-      if linuxerror = SYS_EINTR then begin
246
-        // we received a signal it's not a problem
247
-      end else begin
248
-        raise esocketexception.create('select returned error '+inttostr(linuxerror));
249
-      end;
250
-    end;
251
-  end;
252
-  {$ifndef nosignal}
253
-    sigprocmask(SIG_BLOCK,@blockset,nil);
254
-  {$endif}
255
-{  debugout('select complete');}
256
-end;
257
-
258
-procedure tselecteventcore.exitmessageloop;
259
-begin
260
-  exitloopflag := true
261
-end;
262
-
263
-
264
-
265
-procedure tselecteventcore.messageloop;
266
-var
267
-  tv           ,tvnow     : ttimeval ;
268
-  currenttimer            : tltimer  ;
269
-  selectresult:integer;
270
-begin
271
-  {$ifndef nosignal}
272
-    prepsigpipe;
273
-  {$endif}
274
-  {currentsocket := firstasin;
275
-  if not assigned(currentsocket) then exit; //the message loop will exit if all lsockets are destroyed
276
-  repeat
277
-
278
-    if currentsocket.state = wsconnected then currentsocket.sendflush;
279
-    currentsocket := currentsocket.nextasin;
280
-  until not assigned(currentsocket);}
281
-
282
-
283
-  repeat
284
-
285
-    //the message loop will exit if all lasio's and ltimer's and lsignal's are destroyed
286
-    processtasks;
287
-    //currenttask := nil;
288
-    {beware}
289
-    //if assigned(firsttimer) then begin
290
-    //  tv.tv_sec := maxlongint;
291
-    tv := tv_invalidtimebig;
292
-    currenttimer := firsttimer;
293
-    while assigned(currenttimer) do begin
294
-      if tv_compare(tv,currenttimer.nextts) and currenttimer.enabled then tv := currenttimer.nextts;
295
-      currenttimer := currenttimer.nexttimer;
296
-    end;
297
-
298
-
299
-    if tv_compare(tv,tv_invalidtimebig) then begin    
300
-      //writeln('no timers active');
301
-      if exitloopflag then break;
302
-{    sleep(10);}
303
-      selectresult := doselect(nil);
304
-
305
-    end else begin
306
-      gettimeofday(tvnow);
307
-      tv_substract(tv,tvnow);
308
-
309
-      //writeln('timers active');
310
-      if tv.tv_sec < 0 then begin
311
-        tv.tv_sec := 0;
312
-        tv.tv_usec := 0; {0.1 sec}
313
-      end;
314
-      if exitloopflag then break;
315
-{    sleep(10);}
316
-      selectresult := doselect(@tv);
317
-      processtimers;
318
-
319
-    end;
320
-    if selectresult > 0 then processasios(fdsr,fdsw);
321
-    {!!!only call processasios if select has asio events -beware}
322
-
323
-    {artificial delay to throttle the number of processasios per second possible and reduce cpu usage}
324
-  until false;
325
-end;
326
-
327
-
328
-procedure tselecteventcore.rmasterset(fd : integer;islistensocket : boolean);
329
-begin
330
-  if fd > absoloutemaxs then raise esocketexception.create('file discriptor out of range');
331
-  if fd > maxs then maxs := fd;
332
-  if fd_isset(fd,fdsrmaster) then exit;
333
-  fd_set(fd,fdsrmaster);
334
-
335
-end;
336
-
337
-procedure tselecteventcore.rmasterclr(fd: integer);
338
-begin
339
-  if not fd_isset(fd,fdsrmaster) then exit;
340
-  fd_clr(fd,fdsrmaster);
341
-
342
-end;
343
-
344
-
345
-procedure tselecteventcore.wmasterset(fd : integer);
346
-begin
347
-  if fd > absoloutemaxs then raise esocketexception.create('file discriptor out of range');
348
-  if fd > maxs then maxs := fd;
349
-
350
-  if fd_isset(fd,fdswmaster) then exit;
351
-  fd_set(fd,fdswmaster);
352
-
353
-end;
354
-
355
-procedure tselecteventcore.wmasterclr(fd: integer);
356
-begin
357
-  if not fd_isset(fd,fdswmaster) then exit;
358
-  fd_clr(fd,fdswmaster);
359
-end;
360
-
361
-procedure tselecteventcore.setfdreverse(fd : integer;reverseto : tlasio);
362
-begin
363
-  fdreverse[fd] := reverseto;
364
-end;
365
-
366
-var
367
-  inited:boolean;
368
-
369
-procedure lcoreinit;
370
-begin
371
-  if inited then exit;
372
-  inited := true;
373
-  eventcore := tselecteventcore.create;
374
-
375
-  absoloutemaxs := absoloutemaxs_select;
376
-
377
-  maxs := 0;
378
-  fd_zero(fdsrmaster);
379
-  fd_zero(fdswmaster);
380
-end;
381
-
382
-end.

+ 0
- 233
libwin/lcore/lcorewsaasyncselect.pas Parādīt failu

@@ -1,233 +0,0 @@
1
-unit lcorewsaasyncselect;
2
-
3
-interface
4
-
5
-procedure lcoreinit;
6
-
7
-implementation
8
-
9
-uses wcore,lcore,bsearchtree,sysutils,windows,winsock,pgtypes,messages,classes,lsocket;
10
-type
11
-  twineventcore=class(teventcore)
12
-  public
13
-    procedure processmessages; override;
14
-    procedure messageloop; override;
15
-    procedure exitmessageloop;override;
16
-    procedure setfdreverse(fd : integer;reverseto : tlasio); override;
17
-    procedure rmasterset(fd : integer;islistensocket : boolean); override;
18
-    procedure rmasterclr(fd: integer); override;
19
-    procedure wmasterset(fd : integer); override;
20
-    procedure wmasterclr(fd: integer); override;
21
-  end;
22
-const
23
-  wm_dotasks=wm_user+1;
24
-type
25
-  twintimerwrapperinterface=class(ttimerwrapperinterface)
26
-  public
27
-    function createwrappedtimer : tobject;override;
28
-//    procedure setinitialevent(wrappedtimer : tobject;newvalue : boolean);override;
29
-    procedure setontimer(wrappedtimer : tobject;newvalue:tnotifyevent);override;
30
-    procedure setenabled(wrappedtimer : tobject;newvalue : boolean);override;
31
-    procedure setinterval(wrappedtimer : tobject;newvalue : integer);override;
32
-  end;
33
-
34
-procedure twineventcore.processmessages;
35
-begin
36
-  wcore.processmessages;//pass off to wcore
37
-end;
38
-procedure twineventcore.messageloop;
39
-begin
40
-  wcore.messageloop; //pass off to wcore
41
-end;
42
-procedure twineventcore.exitmessageloop;
43
-begin
44
-  wcore.exitmessageloop;
45
-end;
46
-var
47
-  fdreverse : thashtable;
48
-  fdwatches : thashtable;
49
-
50
-procedure twineventcore.setfdreverse(fd : integer;reverseto : tlasio);
51
-begin
52
-  if findtree(@fdreverse,inttostr(fd)) <> nil then deltree(@fdreverse,inttostr(fd));
53
-  if reverseto <> nil then addtree(@fdreverse,inttostr(fd),reverseto);
54
-end;
55
-
56
-var
57
-  hwndlcore : hwnd;
58
-procedure dowsaasyncselect(fd:integer; leventadd: integer; leventremove : integer);
59
-var
60
-  leventold : integer;
61
-  leventnew : integer;
62
-  wsaaresult : integer;
63
-begin
64
-  leventold := taddrint(findtree(@fdwatches,inttostr(fd)));
65
-  leventnew := leventold or leventadd;
66
-  leventnew := leventnew and not leventremove;
67
-  if leventold <> leventnew then begin
68
-    if leventold <> 0 then deltree(@fdwatches,inttostr(fd));
69
-    if leventnew <> 0 then addtree(@fdwatches,inttostr(fd),pointer(leventnew));
70
-  end;
71
-  wsaaresult := wsaasyncselect(fd,hwndlcore,wm_user,leventnew);
72
-
73
-end;
74
-
75
-
76
-//to allow detection of errors:
77
-//if we are asked to monitor for read or accept we also monitor for close
78
-//if we are asked to monitor for write we also monitor for connect
79
-
80
-
81
-procedure twineventcore.rmasterset(fd : integer;islistensocket : boolean);
82
-begin
83
-  if islistensocket then begin
84
-//    writeln('setting accept watch for socket number ',fd);
85
-    dowsaasyncselect(fd,FD_ACCEPT or FD_CLOSE,0);
86
-  end else begin
87
-//    writeln('setting read watch for socket number',fd);
88
-    dowsaasyncselect(fd,FD_READ or FD_CLOSE,0);
89
-  end;
90
-end;
91
-procedure twineventcore.rmasterclr(fd: integer);
92
-begin
93
-  //writeln('clearing read of accept watch for socket number ',fd);
94
-  dowsaasyncselect(fd,0,FD_ACCEPT or FD_READ or FD_CLOSE);
95
-end;
96
-procedure twineventcore.wmasterset(fd : integer);
97
-begin
98
-  dowsaasyncselect(fd,FD_WRITE or FD_CONNECT,0);
99
-end;
100
-
101
-procedure twineventcore.wmasterclr(fd: integer);
102
-begin
103
-  dowsaasyncselect(fd,0,FD_WRITE or FD_CONNECT);
104
-end;
105
-
106
-var
107
-  tasksoutstanding : boolean;
108
-
109
-function MyWindowProc(
110
-    ahWnd   : HWND;
111
-    auMsg   : Integer;
112
-    awParam : WPARAM;
113
-    alParam : LPARAM): Integer; stdcall;
114
-var
115
-  socket : integer;
116
-  event : integer;
117
-  error : integer;
118
-  readtrigger : boolean;
119
-  writetrigger : boolean;
120
-  lasio : tlasio;
121
-begin
122
-//  writeln('got a message');
123
-  Result := 0;  // This means we handled the message
124
-  if (ahwnd=hwndlcore) and (aumsg=wm_user) then begin
125
-//    writeln('it appears to be a response to our wsaasyncselect');
126
-    socket := awparam;
127
-    event := alparam and $FFFF;
128
-    error := alparam shr 16;
129
-//    writeln('socket=',socket,' event=',event,' error=',error);
130
-    readtrigger := false;
131
-    writetrigger := false;
132
-    lasio := findtree(@fdreverse,inttostr(socket));
133
-    if assigned(lasio) then begin
134
-      if (error <> 0) or ((event and FD_CLOSE) <> 0) then begin
135
-        if (lasio.state = wsconnecting) and (error <> 0) then begin
136
-          if lasio is tlsocket then tlsocket(lasio).connectionfailedhandler(error)
137
-        end else begin
138
-          lasio.internalclose(error);
139
-        end;
140
-      end else begin
141
-        if (event and (FD_READ or FD_ACCEPT)) <> 0 then readtrigger := true;
142
-        if (event and (FD_WRITE)) <> 0 then writetrigger := true;
143
-
144
-        if readtrigger or writetrigger then lasio.handlefdtrigger(readtrigger,writetrigger);
145
-      end;
146
-      // don't reset the event manually for listen sockets to avoid unwanted
147
-      // extra onsessionavailible events
148
-      if (taddrint(findtree(@fdwatches,inttostr(socket))) and (FD_ACCEPT)) = 0 then dowsaasyncselect(socket,0,0); // if not a listen socket reset watches
149
-    end;
150
-  end else if (ahwnd=hwndlcore) and (aumsg=wm_dotasks) then begin
151
-      //writeln('processing tasks');
152
-      tasksoutstanding := false;
153
-      processtasks;
154
-  end else begin
155
-      //writeln('passing unknown message to defwindowproc');
156
-      //not passing unknown messages on to defwindowproc will cause window
157
-      //creation to fail! --plugwash
158
-      Result := DefWindowProc(ahWnd, auMsg, awParam, alParam)
159
-  end;
160
-
161
-end;
162
-
163
-procedure winaddtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
164
-begin
165
-  if not tasksoutstanding then PostMessage(hwndlcore,wm_dotasks,0,0);
166
-end;
167
-type
168
-  twcoretimer = wcore.tltimer;
169
-
170
-function twintimerwrapperinterface.createwrappedtimer : tobject;
171
-begin
172
-  result := twcoretimer.create(nil);
173
-end;
174
-procedure twintimerwrapperinterface.setontimer(wrappedtimer : tobject;newvalue:tnotifyevent);
175
-begin
176
-  twcoretimer(wrappedtimer).ontimer := newvalue;
177
-end;
178
-procedure twintimerwrapperinterface.setenabled(wrappedtimer : tobject;newvalue : boolean);
179
-begin
180
-  twcoretimer(wrappedtimer).enabled := newvalue;
181
-end;
182
-
183
-
184
-procedure twintimerwrapperinterface.setinterval(wrappedtimer : tobject;newvalue : integer);
185
-begin
186
-  twcoretimer(wrappedtimer).interval := newvalue;
187
-end;
188
-
189
-var
190
-  MyWindowClass : TWndClass = (style         : 0;
191
-                                 lpfnWndProc   : @MyWindowProc;
192
-                                 cbClsExtra    : 0;
193
-                                 cbWndExtra    : 0;
194
-                                 hInstance     : 0;
195
-                                 hIcon         : 0;
196
-                                 hCursor       : 0;
197
-                                 hbrBackground : 0;
198
-                                 lpszMenuName  : nil;
199
-                                 lpszClassName : 'lcoreClass');
200
-  GInitData: TWSAData;
201
-
202
-var
203
-  inited:boolean;
204
-procedure lcoreinit;
205
-begin
206
-  if (inited) then exit;
207
-
208
-  eventcore := twineventcore.create;
209
-  if Windows.RegisterClass(MyWindowClass) = 0 then halt;
210
-  //writeln('about to create lcore handle, hinstance=',hinstance);
211
-  hwndlcore := CreateWindowEx(WS_EX_TOOLWINDOW,
212
-                               MyWindowClass.lpszClassName,
213
-                               '',        { Window name   }
214
-                               WS_POPUP,  { Window Style  }
215
-                               0, 0,      { X, Y          }
216
-                               0, 0,      { Width, Height }
217
-                               0,         { hWndParent    }
218
-                               0,         { hMenu         }
219
-                               HInstance, { hInstance     }
220
-                               nil);      { CreateParam   }
221
-  //writeln('lcore hwnd is ',hwndlcore);
222
-  //writeln('last error is ',GetLastError);
223
-  onaddtask := winaddtask;
224
-  timerwrapperinterface := twintimerwrapperinterface.create(nil);
225
-
226
-  WSAStartup(2, GInitData);
227
-  absoloutemaxs := maxlongint;
228
-
229
-
230
-  inited := true;
231
-end;
232
-
233
-end.

+ 0
- 34
libwin/lcore/lloopback.pas Parādīt failu

@@ -1,34 +0,0 @@
1
-unit lloopback;
2
-
3
-interface
4
-uses lcore,classes;
5
-
6
-type
7
-  tlloopback=class(tlasio)
8
-  public
9
-    constructor create(aowner:tcomponent); override;
10
-  end;
11
-
12
-
13
-implementation
14
-uses
15
-{$ifdef ver1_0}
16
-  linux;
17
-{$else}
18
-  baseunix,unix,unixutil;  
19
-{$endif}
20
-{$i unixstuff.inc}
21
-
22
-constructor tlloopback.create(aowner:tcomponent);
23
-begin
24
-  inherited create(aowner);
25
-  closehandles := true;
26
-  assignpipe(fdhandlein,fdhandleout);
27
-
28
-  eventcore.rmasterset(fdhandlein,false);//fd_set(fdhandlein,fdsrmaster);
29
-  eventcore.wmasterclr(fdhandlein);//fd_clr(fdhandleout,fdswmaster);
30
-  eventcore.setfdreverse(fdhandlein,self);
31
-  eventcore.setfdreverse(fdhandleout,self);
32
-  state := wsconnected;
33
-end;
34
-end.

+ 0
- 675
libwin/lcore/lmessages.pas Parādīt failu

@@ -1,675 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-//this unit provides a rough approximation of windows messages on linux
7
-//it is usefull for multithreaded applications on linux to communicate back to
8
-//the main lcore thread
9
-//This unit is *nix only, on windows you should use the real thing
10
-
11
-unit lmessages;
12
-//windows messages like system based on lcore tasks
13
-interface
14
-
15
-uses pgtypes,sysutils,bsearchtree,strings,syncobjs;
16
-
17
-
18
-{$if (fpc_version < 2) or ((fpc_version=2) and ((fpc_release < 2) or ((fpc_release = 2) and (fpc_patch < 2)) ))}
19
-  {$error this code is only supported under fpc 2.2.2 and above due to bugs in the eventobject code in older versions}
20
-{$endif}
21
-
22
-type
23
-  lparam=taddrint;
24
-  wparam=taddrint;
25
-  thinstance=pointer;
26
-  hicon=pointer;
27
-  hcursor=pointer;
28
-  hbrush=pointer;
29
-  hwnd=qword; //window handles are monotonically increasing 64 bit integers,
30
-              //this should allow for a million windows per second for over half
31
-              //a million years!
32
-
33
-  twndproc=function(ahWnd:HWND; auMsg:Integer; awParam:WPARAM; alParam:LPARAM):Integer; stdcall;
34
-
35
-
36
-  twndclass=record
37
-    style : dword;
38
-    lpfnwndproc : twndproc;
39
-    cbclsextra : integer;
40
-    cbwndextra : integer;
41
-    hinstance : thinstance;
42
-    hicon : hicon;
43
-    hcursor : hcursor;
44
-    hbrbackground : hbrush;
45
-    lpszmenuname : pchar;
46
-    lpszclassname : pchar;
47
-  end;
48
-  PWNDCLASS=^twndclass;
49
-  
50
-  UINT=dword;
51
-  WINBOOL = longbool;
52
-  tTIMERPROC = procedure (ahwnd:HWND; umsg:integer; idevent:taddrint;dwtime:taddrint);stdcall;
53
-  ATOM = pointer;
54
-  LPCSTR = pchar;
55
-  LPVOID = pointer;
56
-  HMENU = pointer;
57
-  HINST = pointer;
58
-
59
-  TPOINT = record 
60
-    x : LONGint; 
61
-    y : LONGint; 
62
-  end; 
63
-  
64
-  TMSG = record 
65
-    hwnd : HWND; 
66
-    message : UINT; 
67
-    wParam : WPARAM; 
68
-    lParam : LPARAM; 
69
-    time : DWORD; 
70
-    pt : TPOINT;
71
-  end; 
72
-  THevent=TEventObject;
73
-const
74
-  WS_EX_TOOLWINDOW = $80;
75
-  WS_POPUP = longint($80000000);
76
-  hinstance=nil;
77
-  PM_REMOVE = 1;
78
-  WM_USER = 1024;
79
-  WM_TIMER = 275;
80
-  INFINITE = syncobjs.infinite;
81
-function getwindowlongptr(ahwnd:hwnd;nindex:integer) : taddrint;
82
-function setwindowlongptr(ahwnd:hwnd;nindex:integer;dwNewLong : taddrint) : taddrint;
83
-function DefWindowProc(ahWnd:HWND; auMsg:Integer; awParam:WPARAM; alParam:LPARAM):Integer; stdcall;
84
-function RegisterClass(const lpWndClass:TWNDCLASS):ATOM;
85
-function CreateWindowEx(dwExStyle:DWORD; lpClassName:LPCSTR; lpWindowName:LPCSTR; dwStyle:DWORD; X:longint;Y:longint; nWidth:longint; nHeight:longint; hWndParent:HWND; hMenu:HMENU;hInstance:HINST; lpParam:LPVOID):HWND;
86
-function DestroyWindow(ahWnd:HWND):WINBOOL;
87
-function PostMessage(hWnd:HWND; Msg:UINT; wParam:WPARAM; lParam:LPARAM):WINBOOL;
88
-function PeekMessage(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): WINBOOL;
89
-function DispatchMessage(const lpMsg: TMsg): Longint;
90
-function GetMessage(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax: UINT): WINBOOL;
91
-function SetEvent(hEvent:THevent):WINBOOL;
92
-function CreateEvent(lpEventAttributes:PSECURITYATTRIBUTES; bManualReset:WINBOOL; bInitialState:WINBOOL; lpName:pchar):tHevent;
93
-function terminatethread(threadhandle : tthreadid;dummy:integer) : boolean;
94
-function waitforsingleevent(event:thevent;timeout:cardinal) : twaitresult;
95
-function SetTimer(ahWnd:HWND; nIDEvent:taddrint; uElapse:UINT; lpTimerFunc:tTIMERPROC):UINT;
96
-function KillTimer(ahWnd:HWND; uIDEvent:taddrint):WINBOOL;
97
-
98
-procedure init;
99
-
100
-implementation
101
-uses
102
-  baseunix,unix,lcore,unixutil;//,safewriteln;
103
-{$i unixstuff.inc}
104
-
105
-type
106
-  tmessageintransit = class
107
-    msg : tmsg;
108
-    next : tmessageintransit;
109
-  end;
110
-
111
-  tthreaddata = class
112
-    messagequeue : tmessageintransit;
113
-    messageevent : teventobject;
114
-    waiting : boolean;
115
-    lcorethread : boolean;
116
-    nexttimer : ttimeval;
117
-    threadid : integer;
118
-  end;
119
-  twindow=class
120
-    hwnd : hwnd;
121
-    extrawindowmemory : pointer;
122
-    threadid : tthreadid;
123
-    windowproc : twndproc;
124
-  end;
125
-
126
-var
127
-  structurelock : tcriticalsection;
128
-  threaddata : thashtable;
129
-  windowclasses : thashtable;
130
-  lcorelinkpipesend : integer;
131
-  lcorelinkpiperecv : tlasio;
132
-  windows : thashtable;
133
-  //I would rather things crash immediately
134
-  //if they use an insufficiant size type
135
-  //than crash after over four billion
136
-  //windows have been made ;)
137
-  nextwindowhandle : qword = $100000000;
138
-{$i ltimevalstuff.inc}
139
-
140
-//findthreaddata should only be called while holding the structurelock
141
-function findthreaddata(threadid : integer) : tthreaddata;
142
-begin
143
-  result := tthreaddata(findtree(@threaddata,inttostr(threadid)));
144
-  if result = nil then begin
145
-    result := tthreaddata.create;
146
-    result.messageevent := teventobject.create(nil,false,false,inttostr(taddrint(result)));
147
-    result.nexttimer := tv_invalidtimebig;
148
-    result.threadid := threadid;
149
-    addtree(@threaddata,inttostr(threadid),result);
150
-  end;
151
-end;
152
-
153
-//deletethreaddataifunused should only be called while holding the structurelock
154
-procedure deletethreaddataifunused(athreaddata : tthreaddata);
155
-begin
156
-  //writeln('in deletethreaddataifunused');
157
-  if (athreaddata <> nil) then if (athreaddata.waiting=false) and (athreaddata.messagequeue=nil) and (athreaddata.lcorethread=false) and (athreaddata.nexttimer.tv_sec=tv_invalidtimebig.tv_sec) and (athreaddata.nexttimer.tv_usec=tv_invalidtimebig.tv_usec) then begin
158
-    //writeln('threaddata is unused, freeing messageevent');
159
-    athreaddata.messageevent.free;
160
-    //writeln('freeing thread data object');
161
-    athreaddata.free;
162
-    //writeln('deleting thread data object from hashtable');
163
-    deltree(@threaddata,inttostr(athreaddata.threadid));
164
-    //writeln('finished deleting thread data');
165
-  end else begin
166
-    //writeln('thread data is not unused');
167
-  end;
168
-end;
169
-
170
-function getwindowlongptr(ahwnd:hwnd;nindex:integer) : taddrint;
171
-var
172
-  window : twindow;
173
-begin
174
-  structurelock.acquire;
175
-  try
176
-    window := findtree(@windows,inttostr(ahwnd));
177
-    if window <> nil then begin
178
-      result := paddrint(taddrint(window.extrawindowmemory)+nindex)^;
179
-    end else begin
180
-      result := 0;
181
-    end;
182
-  finally
183
-    structurelock.release;
184
-  end;
185
-end;
186
-
187
-function setwindowlongptr(ahwnd:hwnd;nindex:integer;dwNewLong : taddrint) : taddrint;
188
-var
189
-  window : twindow;
190
-begin
191
-  structurelock.acquire;
192
-  try
193
-    window := findtree(@windows,inttostr(ahwnd));
194
-    if window <> nil then begin
195
-      result := paddrint(taddrint(window.extrawindowmemory)+nindex)^;
196
-      paddrint(taddrint(window.extrawindowmemory)+nindex)^ := dwnewlong;
197
-    end else begin
198
-      result := 0;
199
-    end;
200
-  finally
201
-    structurelock.release;
202
-  end;
203
-
204
-end;
205
-
206
-
207
-function DefWindowProc(ahWnd:HWND; auMsg:Integer; awParam:WPARAM; alParam:LPARAM):Integer; stdcall;
208
-begin
209
-  result := 0;
210
-end;
211
-
212
-function strdup(s:pchar) : pchar;
213
-begin
214
-  //swriteln('in strdup, about to allocate memory');
215
-  result := getmem(strlen(s)+1);
216
-  //swriteln('about to copy string');
217
-  strcopy(s,result);
218
-  //swriteln('leaving strdup');
219
-end;
220
-
221
-function RegisterClass(const lpWndClass:TWNDCLASS):ATOM;
222
-var
223
-  storedwindowclass:pwndclass;
224
-begin
225
-  structurelock.acquire;
226
-  try
227
-    //swriteln('in registerclass, about to check for duplicate window class');
228
-    storedwindowclass := findtree(@windowclasses, lpwndclass.lpszclassname);
229
-    if storedwindowclass <> nil then begin
230
-
231
-      if comparebyte(storedwindowclass^,lpwndclass,sizeof(twndclass)-sizeof(pchar)-sizeof(pchar)) <> 0 then begin
232
-        //swriteln('duplicate window class registered with different settings');
233
-        raise exception.create('duplicate window class registered with different settings');
234
-      end else begin
235
-        //swriteln('duplicate window class registered with same settings, tollerated');
236
-      end;
237
-    end else begin
238
-      //swriteln('about to allocate memory for new windowclass');
239
-      storedwindowclass := getmem(sizeof(twndclass));
240
-      //swriteln('about to copy windowclass from parameter');
241
-      move(lpwndclass,storedwindowclass^,sizeof(twndclass));
242
-      //swriteln('about to copy strings');
243
-      if lpwndclass.lpszmenuname <> nil then storedwindowclass.lpszmenuname := strdup(lpwndclass.lpszmenuname);
244
-      if lpwndclass.lpszclassname <> nil then storedwindowclass.lpszclassname := strdup(lpwndclass.lpszclassname);
245
-      //swriteln('about to add result to list of windowclasses');
246
-      addtree(@windowclasses,lpwndclass.lpszclassname,storedwindowclass);
247
-    end;
248
-    //swriteln('about to return result');
249
-    result := storedwindowclass;
250
-    //swriteln('leaving registerclass');
251
-  finally
252
-    structurelock.release;
253
-  end;
254
-end;
255
-
256
-function CreateWindowEx(dwExStyle:DWORD; lpClassName:LPCSTR; lpWindowName:LPCSTR; dwStyle:DWORD; X:longint;Y:longint; nWidth:longint; nHeight:longint; hWndParent:HWND; hMenu:HMENU;hInstance:HINST; lpParam:LPVOID):HWND;
257
-var
258
-  wndclass : pwndclass;
259
-  tm : tthreadmanager;
260
-  window : twindow;
261
-begin
262
-  structurelock.acquire;
263
-  try
264
-    window := twindow.create;
265
-    window.hwnd := nextwindowhandle;
266
-    result := window.hwnd;
267
-    nextwindowhandle := nextwindowhandle + 1;
268
-    addtree(@windows,inttostr(window.hwnd),window);
269
-    wndclass := findtree(@windowclasses,lpclassname);
270
-    window.extrawindowmemory := getmem(wndclass.cbwndextra);
271
-
272
-    getthreadmanager(tm);
273
-    window.threadid := tm.GetCurrentThreadId;
274
-    window.windowproc := wndclass.lpfnwndproc;
275
-  finally
276
-    structurelock.release;
277
-  end;
278
-end;
279
-function DestroyWindow(ahWnd:HWND):WINBOOL;
280
-var
281
-  window : twindow;
282
-  windowthreaddata : tthreaddata;
283
-  currentmessage : tmessageintransit;
284
-  prevmessage : tmessageintransit;
285
-begin
286
-  //writeln('started to destroy window');
287
-  structurelock.acquire;
288
-  try
289
-    window := twindow(findtree(@windows,inttostr(ahwnd)));
290
-    if window <> nil then begin
291
-      freemem(window.extrawindowmemory);
292
-      //writeln('aboute to delete window from windows structure');
293
-      deltree(@windows,inttostr(ahwnd));
294
-      //writeln('deleted window from windows structure');
295
-      windowthreaddata := tthreaddata(findtree(@threaddata,inttostr(window.threadid)));
296
-
297
-      if windowthreaddata <> nil then begin
298
-        //writeln('found thread data scanning for messages to clean up');
299
-        currentmessage := windowthreaddata.messagequeue;
300
-        prevmessage := nil;
301
-        while currentmessage <> nil do begin
302
-          while (currentmessage <> nil) and (currentmessage.msg.hwnd = ahwnd) do begin
303
-            if prevmessage = nil then begin
304
-              windowthreaddata.messagequeue := currentmessage.next;
305
-            end else begin
306
-              prevmessage.next := currentmessage.next;
307
-            end;
308
-            currentmessage.free;
309
-            if prevmessage = nil then begin
310
-              currentmessage := windowthreaddata.messagequeue;
311
-            end else begin
312
-              currentmessage := prevmessage.next;
313
-            end;
314
-          end;
315
-          if currentmessage <> nil then begin
316
-            prevmessage := currentmessage;
317
-            currentmessage := currentmessage.next;
318
-          end;
319
-        end;
320
-        //writeln('deleting thread data structure if it is unused');
321
-        deletethreaddataifunused(windowthreaddata);
322
-      end else begin
323
-        //writeln('there is no thread data to search for messages to cleanup');
324
-      end;
325
-      //writeln('freeing window');
326
-      window.free;
327
-      result := true;
328
-    end else begin
329
-      result := false;
330
-    end;
331
-  finally
332
-    structurelock.release;
333
-  end;
334
-  //writeln('window destroyed');
335
-end;
336
-
337
-
338
-
339
-function PostMessage(hWnd:HWND; Msg:UINT; wParam:WPARAM; lParam:LPARAM):WINBOOL;
340
-var
341
-  threaddata : tthreaddata;
342
-  message : tmessageintransit;
343
-  messagequeueend : tmessageintransit;
344
-  window : twindow;
345
-begin
346
-  structurelock.acquire;
347
-  try
348
-    window := findtree(@windows,inttostr(hwnd));
349
-    if window <> nil then begin
350
-      threaddata := findthreaddata(window.threadid);
351
-      message := tmessageintransit.create;
352
-      message.msg.hwnd := hwnd;
353
-      message.msg.message := msg;
354
-      message.msg.wparam := wparam;
355
-      message.msg.lparam := lparam;
356
-      if threaddata.lcorethread then begin
357
-        //swriteln('posting message to lcore thread');
358
-        fdwrite(lcorelinkpipesend,message,sizeof(message));
359
-      end else begin
360
-        //writeln('posting message to non lcore thread');
361
-        if threaddata.messagequeue = nil then begin
362
-          threaddata.messagequeue := message;
363
-        end else begin
364
-          messagequeueend := threaddata.messagequeue;
365
-          while messagequeueend.next <> nil do begin
366
-            messagequeueend := messagequeueend.next;
367
-          end;
368
-          messagequeueend.next := message;
369
-        end;
370
-
371
-        //writeln('message added to queue');
372
-        if threaddata.waiting then threaddata.messageevent.setevent;
373
-      end;
374
-      result := true;
375
-    end else begin
376
-      result := false;
377
-    end;
378
-  finally
379
-    structurelock.release;
380
-  end;
381
-
382
-end;
383
-
384
-function gettickcount : dword;
385
-var
386
-  result64: integer;
387
-  tv : ttimeval;
388
-begin
389
-  gettimeofday(tv);
390
-  result64 := (tv.tv_sec*1000)+(tv.tv_usec div 1000);
391
-  result := result64;
392
-end;
393
-
394
-function DispatchMessage(const lpMsg: TMsg): Longint;
395
-var
396
-  timerproc : ttimerproc;
397
-  window : twindow;
398
-  windowproc : twndproc;
399
-begin
400
-  ////swriteln('in dispatchmessage, msg.hwnd='+inttohex(taddrint(lpmsg.hwnd),16));
401
-  if (lpmsg.lparam <> 0) and (lpmsg.message = WM_TIMER) then begin
402
-    timerproc := ttimerproc(lpmsg.lparam);
403
-    timerproc(lpmsg.hwnd,lpmsg.message,lpmsg.wparam,gettickcount);
404
-    result := 0;
405
-  end else begin
406
-    structurelock.acquire;
407
-    try
408
-      window := findtree(@windows,inttostr(lpmsg.hwnd));
409
-      //we have to get the window procedure while the structurelock
410
-      //is still held as the window could be destroyed from another thread
411
-      //otherwise.
412
-      if window <> nil then begin
413
-        windowproc := window.windowproc;
414
-      end else begin
415
-        windowproc := nil;
416
-      end;
417
-    finally
418
-      structurelock.release;
419
-    end;
420
-    if assigned(windowproc) then begin
421
-      result := windowproc(lpmsg.hwnd,lpmsg.message,lpmsg.wparam,lpmsg.lparam);
422
-    end else begin
423
-      result := -1;
424
-    end;
425
-  end;
426
-end;
427
-
428
-procedure processtimers;
429
-begin
430
-end;
431
-
432
-function GetMessageinternal(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax: UINT; wremovemsg : UINT;peek:boolean): WINBOOL;
433
-var
434
-  tm : tthreadmanager;
435
-  threaddata : tthreaddata;
436
-  message : tmessageintransit;
437
-  nowtv : ttimeval;
438
-  timeouttv : ttimeval;
439
-  timeoutms : int64;
440
-
441
-begin
442
-  if hwnd <> 0 then raise exception.create('getting messages for an individual window is not supported');
443
-  if (wmsgfiltermin <> 0) or (wmsgfiltermax <> 0) then raise exception.create('message filtering is not supported');
444
-  structurelock.acquire;
445
-  result := true;
446
-  try
447
-    getthreadmanager(tm);
448
-    threaddata := findthreaddata(tm.GetCurrentThreadId);
449
-    if threaddata.lcorethread then raise exception.create('get/peek message cannot be used in the lcore thread');
450
-    message := threaddata.messagequeue;
451
-    gettimeofday(nowtv);
452
-    while (not peek) and (message=nil) and (not tv_compare(nowtv,threaddata.nexttimer)) do begin
453
-      threaddata.waiting := true;
454
-      structurelock.release;
455
-      if (threaddata.nexttimer.tv_sec = TV_invalidtimebig.tv_sec) and (threaddata.nexttimer.tv_usec = TV_invalidtimebig.tv_usec) then begin
456
-        threaddata.messageevent.waitfor(INFINITE);
457
-      end else begin
458
-
459
-        timeouttv := threaddata.nexttimer;
460
-        timeoutms := (timeouttv.tv_sec * 1000)+(timeouttv.tv_usec div 1000);
461
-        //i'm assuming the timeout is in milliseconds
462
-        if (timeoutms > maxlongint) then timeoutms := maxlongint;
463
-        threaddata.messageevent.waitfor(timeoutms);
464
-
465
-      end;
466
-      structurelock.acquire;
467
-      threaddata.waiting := false;
468
-      message := threaddata.messagequeue;
469
-      gettimeofday(nowtv);
470
-    end;
471
-    if (message=nil) and tv_compare(nowtv,threaddata.nexttimer) then begin
472
-      processtimers;
473
-    end;
474
-    message := threaddata.messagequeue;
475
-    if message <> nil then begin
476
-      lpmsg := message.msg;
477
-      if wremovemsg=PM_REMOVE then begin
478
-        threaddata.messagequeue := message.next;
479
-        message.free;
480
-      end;
481
-    end else begin
482
-      result :=false;
483
-    end;
484
-    deletethreaddataifunused(threaddata);
485
-  finally
486
-    structurelock.release;
487
-  end;
488
-end;
489
-
490
-function GetMessage(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax: UINT): WINBOOL;
491
-begin
492
-  result := getmessageinternal(lpmsg,hwnd,wmsgfiltermin,wmsgfiltermax,PM_REMOVE,false);
493
-end;
494
-
495
-function PeekMessage(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): WINBOOL;
496
-begin
497
-  result := getmessageinternal(lpmsg,hwnd,wmsgfiltermin,wmsgfiltermax,wRemoveMsg,true);
498
-end;
499
-
500
-function SetEvent(hEvent:THevent):WINBOOL;
501
-begin
502
-  hevent.setevent;
503
-  result := true;
504
-end;
505
-
506
-function CreateEvent(lpEventAttributes:PSECURITYATTRIBUTES; bManualReset:WINBOOL; bInitialState:WINBOOL; lpName:pchar):tHevent;
507
-begin
508
-  result := teventobject.create(lpeventattributes,bmanualreset,binitialstate,lpname);
509
-end;
510
-
511
-function terminatethread(threadhandle:tthreadid;dummy : integer) : boolean;
512
-var
513
-  tm : tthreadmanager;
514
-begin
515
-  getthreadmanager(tm);
516
-  tm.killthread(threadhandle);
517
-  result := true;
518
-end;
519
-
520
-function waitforsingleevent(event:thevent;timeout:cardinal) : twaitresult;
521
-begin
522
-  result := event.waitfor(timeout);
523
-end;
524
-
525
-procedure removefrombuffer(n : integer; var buffer:string);
526
-begin
527
-  if n=length(buffer) then begin
528
-    buffer := '';
529
-  end else begin
530
-    uniquestring(buffer);
531
-    move(buffer[n+1],buffer[1],length(buffer)-n);
532
-    setlength(buffer,length(buffer)-n);
533
-  end;
534
-end;
535
-
536
-type
537
-  tsc=class
538
-    procedure available(sender:tobject;error:word);
539
-  end;
540
-
541
-var
542
-  recvbuf : string;
543
-
544
-procedure tsc.available(sender:tobject;error:word);
545
-var
546
-  message : tmessageintransit;
547
-  messagebytes : array[1..sizeof(tmessageintransit)] of char absolute  message;
548
-  i : integer;
549
-begin
550
-  //swriteln('received data on lcorelinkpipe');
551
-  recvbuf := recvbuf + lcorelinkpiperecv.receivestr;
552
-  while length(recvbuf) >= sizeof(tmessageintransit) do begin
553
-    for i := 1 to sizeof(tmessageintransit) do begin
554
-      messagebytes[i] := recvbuf[i];
555
-    end;
556
-    dispatchmessage(message.msg);
557
-    message.free;
558
-    removefrombuffer(sizeof(tmessageintransit),recvbuf);
559
-  end;
560
-end;
561
-
562
-procedure init;
563
-var
564
-  tm : tthreadmanager;
565
-  threaddata : tthreaddata;
566
-  pipeends : tfildes;
567
-  sc : tsc;
568
-begin
569
-  structurelock := tcriticalsection.create;
570
-  getthreadmanager(tm);
571
-  threaddata := findthreaddata(tm.GetCurrentThreadId);
572
-  threaddata.lcorethread := true;
573
-  fppipe(pipeends);
574
-  lcorelinkpipesend := pipeends[1];
575
-  lcorelinkpiperecv := tlasio.create(nil);
576
-  lcorelinkpiperecv.dup(pipeends[0]);
577
-  lcorelinkpiperecv.ondataavailable := sc.available;
578
-  recvbuf := '';
579
-end;
580
-
581
-var
582
-  lcorethreadtimers : thashtable;
583
-type
584
-  tltimerformsg = class(tltimer)
585
-  public
586
-    hwnd : hwnd;
587
-    id : taddrint;
588
-    procedure timer(sender : tobject);
589
-  end;
590
-
591
-procedure tltimerformsg.timer(sender : tobject);
592
-var
593
-  msg : tmsg;
594
-begin
595
-  ////swriteln('in tltimerformsg.timer');
596
-  fillchar(msg,sizeof(msg),0);
597
-  msg.message := WM_TIMER;
598
-  msg.hwnd := hwnd;
599
-  msg.wparam := ID;
600
-  msg.lparam := 0;
601
-  dispatchmessage(msg);
602
-end;
603
-
604
-function SetTimer(ahWnd:HWND; nIDEvent:taddrint; uElapse:UINT; lpTimerFunc:tTIMERPROC):UINT;
605
-var
606
-  threaddata : tthreaddata;
607
-  ltimer : tltimerformsg;
608
-  tm : tthreadmanager;
609
-  window : twindow;
610
-begin
611
-  structurelock.acquire;
612
-  try
613
-    window := findtree(@windows,inttostr(ahwnd));
614
-    if window= nil then raise exception.create('invalid window');
615
-    threaddata := findthreaddata(window.threadid);
616
-  finally
617
-    structurelock.release;
618
-  end;
619
-  if threaddata.lcorethread then begin
620
-    getthreadmanager(tm);
621
-    if tm.GetCurrentThreadId <> window.threadid then raise exception.create('timers on the lcore thread may only be added and removed from the lcore thread');
622
-    if ahwnd = 0 then raise exception.create('timers on the lcore thread must be associated with a window handle');
623
-    if @lptimerfunc <> nil then raise exception.create('seperate timer functions are not supported');
624
-
625
-    //remove preexisting timer with same ID
626
-    killtimer(ahwnd,nIDEvent);
627
-
628
-    ltimer := tltimerformsg.create(nil);
629
-    ltimer.interval := uelapse;
630
-    ltimer.id := nidevent;
631
-    ltimer.hwnd := ahwnd;
632
-    ltimer.enabled := true;
633
-    ltimer.ontimer := ltimer.timer;
634
-
635
-    addtree(@lcorethreadtimers,inttostr(taddrint(ahwnd))+' '+inttostr(nIDEvent),ltimer);
636
-
637
-    result := nidevent;
638
-  end else begin
639
-    raise exception.create('settimer not implemented for threads other than the lcore thread');
640
-  end;
641
-end;
642
-
643
-function KillTimer(ahWnd:HWND; uIDEvent:taddrint):WINBOOL;
644
-var
645
-  threaddata : tthreaddata;
646
-  ltimer : tltimerformsg;
647
-  tm : tthreadmanager;
648
-  window : twindow;
649
-begin
650
-  structurelock.acquire;
651
-  try
652
-    window := findtree(@windows,inttostr(ahwnd));
653
-    if window= nil then raise exception.create('invalid window');
654
-    threaddata := findthreaddata(window.threadid);
655
-  finally
656
-    structurelock.release;
657
-  end;
658
-  if threaddata.lcorethread then begin
659
-    getthreadmanager(tm);
660
-    if tm.GetCurrentThreadId <> window.threadid then raise exception.create('timers on the lcore thread may only be added and remove from the lcore thread');
661
-    if ahwnd = 0 then raise exception.create('timers on the lcore thread must be associated with a window handle');
662
-    ltimer := tltimerformsg(findtree(@lcorethreadtimers,inttostr(taddrint(ahwnd))+' '+inttostr(uIDEvent)));
663
-    if ltimer <> nil then begin
664
-      deltree(@lcorethreadtimers,inttostr(taddrint(ahwnd))+' '+inttostr(uIDEvent));
665
-      ltimer.free;
666
-      result := true;
667
-    end else begin
668
-      result := false;
669
-    end;
670
-  end else begin
671
-    raise exception.create('settimer not implemented for threads other than the lcore thread');
672
-  end;
673
-end;
674
-
675
-end.

+ 0
- 201
libwin/lcore/lsignal.pas Parādīt failu

@@ -1,201 +0,0 @@
1
-{lsocket.pas}
2
-
3
-{signal code by plugwash}
4
-
5
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
6
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
7
-  which is included in the package
8
-  ----------------------------------------------------------------------------- }
9
-      
10
-unit lsignal;
11
-{$mode delphi}
12
-interface
13
-  uses sysutils,
14
-    {$ifdef VER1_0}
15
-      linux,
16
-    {$else}
17
-      baseunix,unix,unixutil,
18
-    {$endif}
19
-    classes,lcore,lloopback;
20
-
21
-  type
22
-    tsignalevent=procedure(sender:tobject;signal:integer) of object;
23
-    tlsignal=class(tcomponent)
24
-    public
25
-      onsignal           : tsignalevent      ;
26
-      prevsignal         : tlsignal          ;
27
-      nextsignal         : tlsignal          ;
28
-
29
-      constructor create(aowner:tcomponent);override;
30
-      destructor destroy;override;
31
-    end;
32
-
33
-  
34
-  procedure starthandlesignal(signal:integer);
35
-
36
-var
37
-  firstsignal : tlsignal;
38
-  blockset : sigset;
39
-  signalloopback                        : tlloopback ;
40
-  
41
-implementation
42
-{$include unixstuff.inc}
43
-
44
-constructor tlsignal.create;
45
-begin
46
-  inherited create(AOwner);
47
-  nextsignal := firstsignal;
48
-  prevsignal := nil;
49
-
50
-  if assigned(nextsignal) then nextsignal.prevsignal := self;
51
-  firstsignal := self;
52
-
53
-  //interval := 1000;
54
-  //enabled := true;
55
-  //released := false;
56
-end;
57
-
58
-destructor tlsignal.destroy;
59
-begin
60
-  if prevsignal <> nil then begin
61
-    prevsignal.nextsignal := nextsignal;
62
-  end else begin
63
-    firstsignal := nextsignal;
64
-  end;
65
-  if nextsignal <> nil then begin
66
-    nextsignal.prevsignal := prevsignal;
67
-  end;
68
-  inherited destroy;
69
-end;
70
-{$ifdef linux}
71
-  {$ifdef ver1_9_8}
72
-    {$define needsignalworkaround}
73
-  {$endif}
74
-  {$ifdef ver2_0_0}
75
-    {$define needsignalworkaround}
76
-  {$endif}
77
-  {$ifdef ver2_0_2}
78
-    {$define needsignalworkaround}
79
-  {$endif}
80
-{$endif}
81
-{$ifdef needsignalworkaround}
82
-  //using the 1.9.6 version of this stuff because the 1.9.8 and 2.0.0 versions seem broken
83
-  type
84
-    TSysParam  = Longint;
85
-    TSysResult = longint;
86
-  const
87
-            syscall_nr_sigaction		= 67;
88
-  //function Do_SysCall(sysnr:TSysParam):TSysResult;  {$ifndef VER1_0} oldfpccall; {$endif} external name 'FPC_SYSCALL0';
89
-  //function Do_SysCall(sysnr,param1:TSysParam):TSysResult; {$ifndef VER1_0} oldfpccall; {$endif} external name 'FPC_SYSCALL1';
90
-  //function Do_SysCall(sysnr,param1,param2:TSysParam):TSysResult;  {$ifndef VER1_0} oldfpccall; {$endif} external name 'FPC_SYSCALL2';
91
-  function Do_SysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; {$ifndef VER1_0} oldfpccall; {$endif} external name 'FPC_SYSCALL3';
92
-  //function Do_SysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; {$ifndef VER1_0} oldfpccall; {$endif} external name 'FPC_SYSCALL4';
93
-  //function Do_SysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult;  {$ifndef VER1_0} oldfpccall; {$endif} external name 'FPC_SYSCALL5';
94
-
95
-  function Fpsigaction(sig: cint; act : psigactionrec; oact : psigactionrec): cint;// [public, alias : 'FPC_SYSC_SIGACTION'];
96
-  {
97
-    Change action of process upon receipt of a signal.
98
-    Signum specifies the signal (all except SigKill and SigStop).
99
-    If Act is non-nil, it is used to specify the new action.
100
-    If OldAct is non-nil the previous action is saved there.
101
-  }
102
-  begin
103
-  //writeln('fucking');
104
-  {$ifdef RTSIGACTION}
105
-    {$ifdef cpusparc}
106
-      { Sparc has an extra stub parameter }
107
-      Fpsigaction:=do_syscall(syscall_nr_rt_sigaction,TSysParam(sig),TSysParam(act),TSysParam(oact),TSysParam(PtrInt(@Fprt_sigreturn_stub)-8),TSysParam(8));
108
-    {$else cpusparc}
109
-      Fpsigaction:=do_syscall(syscall_nr_rt_sigaction,TSysParam(sig),TSysParam(act),TSysParam(oact),TSysParam(8));
110
-    {$endif cpusparc}
111
-  {$else RTSIGACTION}
112
-    //writeln('nice');
113
-    Fpsigaction:=do_syscall(syscall_nr_sigaction,TSysParam(sig),TSysParam(act),TSysParam(oact));
114
-  {$endif RTSIGACTION}
115
-  end;
116
-{$endif}
117
-
118
-// cdecl procedures are not name mangled
119
-// so USING something unlikely to cause colliesions in the global namespace
120
-// is a good idea
121
-procedure lsignal_handler( Sig : Integer);cdecl;
122
-var
123
-  currentsignal : tlsignal;
124
-begin
125
-//  writeln('in lsignal_hanler');
126
-  currentsignal := firstsignal;
127
-  while assigned(currentsignal) do begin
128
-    if assigned(currentsignal.onsignal) then currentsignal.onsignal(currentsignal,sig);
129
-    currentsignal := currentsignal.nextsignal;
130
-
131
-  end;
132
-//  writeln('about to send down signalloopback');
133
-  if assigned(signalloopback) then begin
134
-    signalloopback.sendstr(' ');
135
-  end;
136
-//  writeln('left lsignal_hanler');
137
-end;
138
-
139
-{$ifdef freebsd}
140
-
141
-{$if (FPC_VERSION > 2) or ((FPC_VERSION = 2) and (FPC_RELEASE >= 2))}
142
-procedure lsignal_handler2(signal:longint;info:PSigInfo;context:psigcontext); cdecl;
143
-{$else}
144
-procedure lsignal_handler2(signal:longint;var info:TSigInfo_t;var context:SigContextRec); cdecl;
145
-{$endif}
146
-
147
-begin
148
-  lsignal_handler(signal);
149
-end;
150
-{$endif}
151
-
152
-
153
-const
154
-  allbitsset=-1;
155
-  {$ifdef ver1_0}
156
-    saction : sigactionrec = (handler:(sh:lsignal_handler);sa_flags:0);
157
-  {$else}
158
-    {$ifdef darwin}
159
-      saction : sigactionrec = (sa_handler:tsigaction(lsignal_handler);sa_flags:0);
160
-    {$else}
161
-      {$ifdef freebsd}
162
-        //version number is FPC_VERSION.FPC_RELEASE.FPC_PATCH
163
-        {$if (FPC_VERSION>2) or ((FPC_VERSION=2) and (FPC_RELEASE>0)) or ((FPC_VERSION=2) and (fpc_release=0) and (fpc_patch>=2))}
164
-          saction : sigactionrec = (sa_handler:lsignal_handler2;sa_flags:0);
165
-        {$else}
166
-          saction : sigactionrec = (sa_handler:tsigaction(lsignal_handler);sa_flags:0);
167
-        {$endif}
168
-							  
169
-      {$else}
170
-        {$ifdef ver1_9_2}
171
-          saction : sigactionrec = (handler:(sh:lsignal_handler);sa_flags:0);
172
-        {$else}
173
-	  //version number is FPC_VERSION.FPC_RELEASE.FPC_PATCH
174
-	  {$if (FPC_VERSION>2) or ((FPC_VERSION=2) and (FPC_RELEASE>0)) or ((FPC_VERSION=2) and (fpc_release=0) and (fpc_patch>=2))}
175
-	    saction : sigactionrec = (sa_handler:{$ifndef ver1_9_6}{$ifndef ver1_9_4}{$ifndef ver1_0}SigActionHandler{$endif}{$endif}{$endif}(lsignal_handler);sa_flags:0;sa_restorer:nil);
176
-	  {$else}
177
-            saction : sigactionrec = (sa_handler:{$ifndef ver1_9_6}{$ifndef ver1_9_4}{$ifndef ver1_0}SigActionHandler{$endif}{$endif}{$endif}(lsignal_handler));
178
-	  {$endif}
179
-        {$endif}
180
-      {$endif}
181
-    {$endif}
182
-  {$endif}
183
-procedure starthandlesignal(signal:integer);
184
-begin
185
-  if signal in ([0..31]-[sigkill,sigstop]) then begin
186
-    sigprocmask(SIG_BLOCK,@blockset,nil);
187
-    sigaction(signal,@saction,nil)
188
-  end else begin
189
-    raise exception.create('invalid signal number')
190
-  end;
191
-end;
192
-
193
-initialization
194
-  fillchar(blockset,sizeof(blockset),0);
195
-  blockset[0] := $FFFFFFFF - (1 shl sigstop) - (1 shl sigkill) - (1 shl sigsegv);
196
-  {$ifdef ver1_0}
197
-    saction.sa_mask := blockset[0];
198
-  {$else}
199
-    saction.sa_mask := blockset;
200
-  {$endif}
201
-end.

+ 0
- 747
libwin/lcore/lsocket.pas Parādīt failu

@@ -1,747 +0,0 @@
1
-{lsocket.pas}
2
-
3
-{socket code by plugwash}
4
-
5
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
6
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
7
-  which is included in the package
8
-  ----------------------------------------------------------------------------- }
9
-{
10
-changes by plugwash (20030728)
11
-* created handlefdtrigger virtual method in tlasio (overridden in tlsocket) and moved a lot of code from messageloop into it
12
-* changed tlasio to tlasio
13
-* split fdhandle into fdhandlein and fdhandleout
14
-* i now use fdsrmaster and fdswmaster instead of rebuilding the lists every loop
15
-* split lsocket.pas into lsocket.pas and lcore.pas
16
-
17
-
18
-changes by beware (20030903)
19
-* added getxaddr, getxport (local addr, port, as string)
20
-* added getpeername, remote addr+port as binary
21
-* added htons and htonl functions (endian swap, same interface as windows API)
22
-
23
-beware (20030905)
24
-* if connect failed (conn refused) set state to connected and call internalclose, to get closed handler (instead of fdclose)
25
-* (lcore) if closing the fd's in internalcose, set fd's to -1 because closing an fd makes it invalid
26
-
27
-beware (20030927)
28
-* fixed: on connect failed, tried to close fdhandle's which were already set to -1, added check
29
-
30
-beware (20031017)
31
-* added getpeeraddr, getpeerport, remote addr+port as string
32
-}
33
-
34
-
35
-unit lsocket;
36
-{$ifdef fpc}
37
-  {$mode delphi}
38
-{$endif}
39
-
40
-{$include lcoreconfig.inc}
41
-
42
-interface
43
-  uses
44
-    sysutils,
45
-    {$ifdef win32}
46
-      windows,winsock,
47
-    {$else}
48
-
49
-      {$ifdef VER1_0}
50
-        linux,
51
-      {$else}
52
-        baseunix,unix,unixutil,
53
-      {$endif}
54
-      sockets,
55
-    {$endif}
56
-    classes,{pgdebugout,}pgtypes,lcore,fd_utils,binipstuff,dnssync;
57
-
58
-{$ifdef ipv6}
59
-const
60
-  v4listendefault:boolean=false;
61
-{$endif}
62
-
63
-
64
-type
65
-  sunB = packed record
66
-    s_b1, s_b2, s_b3, s_b4: byte;
67
-  end;
68
-
69
-  SunW = packed record
70
-    s_w1, s_w2: word;
71
-  end;
72
-
73
-  TInAddr = packed record
74
-    case integer of
75
-      0: (S_un_b: SunB);
76
-      1: (S_un_w: SunW);
77
-      2: (S_addr: cardinal);
78
-  end;
79
-
80
-  type
81
-    TLsocket = class(tlasio)
82
-    public
83
-      //a: string;
84
-
85
-      inAddr             : TInetSockAddrV;
86
-
87
-      biniplist:tbiniplist;
88
-      trymoreips:boolean;
89
-      currentip:integer;
90
-      connecttimeout:tltimer;
91
-
92
-{      inAddrSize:integer;}
93
-
94
-      //host               : THostentry      ;
95
-
96
-      //mainthread         : boolean         ; //for debuggin only
97
-      addr:string;
98
-      port:string;
99
-      localaddr:string;
100
-      localport:string;
101
-      proto:string;
102
-      udp,dgram:boolean;
103
-      listenqueue:integer;
104
-      {$ifdef secondlistener}
105
-      secondlistener:tlsocket;
106
-      lastsessionfromsecond:boolean;
107
-      procedure secondaccepthandler(sender:tobject;error:word);
108
-      procedure internalclose(error:word);override;
109
-      {$endif}
110
-      function getaddrsize:integer;
111
-      procedure connect; virtual;
112
-      procedure realconnect;
113
-      procedure bindsocket;
114
-      procedure listen;
115
-      function accept : longint;
116
-      function sendto(dest:TInetSockAddrV;destlen:integer;data:pointer;len:integer):integer; virtual;
117
-      function receivefrom(data:pointer;len:integer;var src:TInetSockAddrV;var srclen:integer):integer; virtual;
118
-
119
-      procedure handlefdtrigger(readtrigger,writetrigger:boolean); override;
120
-      function send(data:pointer;len:integer):integer;override;
121
-      procedure sendstr(const str : string);override;
122
-      function Receive(Buf:Pointer;BufSize:integer):integer; override;
123
-      function getpeername(var addr:tsockaddrin;addrlen:integer):integer; virtual;
124
-      procedure getXaddrbin(var binip:tbinip); virtual;
125
-      procedure getpeeraddrbin(var binip:tbinip); virtual;
126
-      function getXaddr:string; virtual;
127
-      function getpeeraddr:string; virtual;
128
-      function getXport:string; virtual;
129
-      function getpeerport:string; virtual;
130
-      constructor Create(AOwner: TComponent); override;
131
-
132
-      //this one has to be kept public for now because lcorewsaasyncselect calls it
133
-      procedure connectionfailedhandler(error:word);
134
-    private
135
-      procedure taskcallconnectionfailedhandler(wparam,lparam : longint);
136
-
137
-      procedure connecttimeouthandler(sender:tobject);
138
-      procedure connectsuccesshandler;
139
-      {$ifdef win32}
140
-        procedure myfdclose(fd : integer); override;
141
-        function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;
142
-        function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; override;
143
-      {$endif}
144
-    end;
145
-    tsocket=longint; // for compatibility with twsocket
146
-
147
-  twsocket=tlsocket; {easy}
148
-
149
-
150
-const
151
-  TCP_NODELAY=1;
152
-  IPPROTO_TCP=6;
153
-
154
-implementation
155
-{$include unixstuff.inc}
156
-
157
-
158
-function tlsocket.getaddrsize:integer;
159
-begin
160
-  result := inaddrsize(inaddr);
161
-end;
162
-
163
-
164
-procedure tlsocket.realconnect;
165
-var
166
-  a,b:integer;
167
-begin
168
-  //writeln('trying to connect to ',ipbintostr(biniplist_get(biniplist,currentip)),'#',port);
169
-  makeinaddrv(biniplist_get(biniplist,currentip),port,inaddr);
170
-  inc(currentip);
171
-  if (currentip >= biniplist_getcount(biniplist)) then trymoreips := false;
172
-
173
-  udp := false;
174
-  if (uppercase(proto) = 'UDP') then begin
175
-    b := IPPROTO_UDP;
176
-    a := SOCK_DGRAM;
177
-    udp := true;
178
-    dgram := true;
179
-  end else if (uppercase(proto) = 'TCP') or (uppercase(proto) = '') then begin
180
-    b := IPPROTO_TCP;
181
-    a := SOCK_STREAM;
182
-    dgram := false;
183
-  end else if (uppercase(proto) = 'ICMP') or (strtointdef(proto,256) < 256) then begin
184
-    b := strtointdef(proto,IPPROTO_ICMP);
185
-    a := SOCK_RAW;
186
-    dgram := true;
187
-  end else begin
188
-    raise ESocketException.create('unrecognised protocol');
189
-  end;
190
-
191
-  a := Socket(inaddr.inaddr.family,a,b);
192
-  //writeln(ord(inaddr.inaddr.family));
193
-  if a = -1 then begin
194
-    //unable to create socket, fire an error event (better to use an error event
195
-    //to avoid poor interaction with multilistener stuff.
196
-    //a socket value of -2 is a special value to say there is no socket but
197
-    //we want internalclose to act as if there was
198
-    fdhandlein := -2;
199
-    fdhandleout := -2;
200
-    tltask.create(taskcallconnectionfailedhandler,self,{$ifdef win32}wsagetlasterror{$else}socketerror{$endif},0);
201
-    exit;
202
-  end;
203
-  try
204
-    dup(a);
205
-    bindsocket;
206
-    if dgram then begin
207
-      {$ifndef win32}
208
-        SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));
209
-      {$else}
210
-        SetSockOpt(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));
211
-      {$endif}
212
-      state := wsconnected;
213
-      if assigned(onsessionconnected) then onsessionconnected(self,0);
214
-
215
-      eventcore.rmasterset(fdhandlein,false);
216
-      eventcore.wmasterclr(fdhandleout);
217
-    end else begin
218
-      state :=wsconnecting;
219
-      {$ifdef win32}
220
-        //writeln(inaddr.inaddr.port);
221
-        winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize);
222
-      {$else}
223
-        sockets.Connect(fdhandlein,inADDR,getaddrsize);
224
-      {$endif}
225
-      eventcore.rmasterset(fdhandlein,false);
226
-      eventcore.wmasterset(fdhandleout);
227
-      if trymoreips then connecttimeout.enabled := true;
228
-    end;
229
-    //sendq := '';
230
-  except
231
-    on e: exception do begin
232
-      fdcleanup;
233
-      raise; //reraise the exception
234
-    end;
235
-  end;
236
-
237
-end;
238
-
239
-procedure tlsocket.connecttimeouthandler(sender:tobject);
240
-begin
241
-  connecttimeout.enabled := false;
242
-  destroying := true; //hack to not cause handler to trigger
243
-  internalclose(0);
244
-  destroying := false;
245
-  realconnect;
246
-end;
247
-
248
-procedure tlsocket.connect;
249
-var
250
-  a:integer;
251
-  ip:tbinip;
252
-begin
253
-  if state <> wsclosed then close;
254
-  //prevtime := 0;
255
-  if isbiniplist(addr) then biniplist := addr else biniplist := forwardlookuplist(addr,0);
256
-  if biniplist_getcount(biniplist) = 0 then raise exception.create('unable to resolve '+addr);
257
-
258
-  //makeinaddrv(addr,port,inaddr);
259
-
260
-  currentip := 0;
261
-  if not assigned(connecttimeout) then begin
262
-    connecttimeout := tltimer.create(self);
263
-    connecttimeout.Tag := integer(self);
264
-    connecttimeout.ontimer := connecttimeouthandler;
265
-    connecttimeout.interval := 2500;
266
-    connecttimeout.enabled := false;
267
-  end;
268
-  realconnect;
269
-end;
270
-
271
-procedure tlsocket.sendstr(const str : string);
272
-begin
273
-  if dgram then begin
274
-    send(@str[1],length(str))
275
-  end else begin
276
-    inherited sendstr(str);
277
-  end;
278
-end;
279
-
280
-function tlsocket.send(data:pointer;len:integer):integer;
281
-begin
282
-  if dgram then begin
283
-//    writeln('sending to '+ipbintostr(inaddrvtobinip(inaddr)),' ',htons(inaddr.inaddr.port),' ',len,' bytes');
284
-    result := sendto(inaddr,getaddrsize,data,len);
285
-
286
-//    writeln('send result ',result);
287
-//    writeln('errno',errno);
288
-  end else begin
289
-    result := inherited send(data,len);
290
-  end;
291
-end;
292
-
293
-
294
-function tlsocket.receive(Buf:Pointer;BufSize:integer):integer;
295
-begin
296
-  if dgram then begin
297
-    {$ifdef secondlistener}
298
-    if lastsessionfromsecond then begin
299
-      result := secondlistener.receive(buf,bufsize);
300
-      lastsessionfromsecond := false;
301
-    end else
302
-    {$endif}
303
-      result := myfdread(self.fdhandlein,buf^,bufsize);
304
-  end else begin
305
-    result := inherited receive(buf,bufsize);
306
-  end;
307
-end;
308
-
309
-procedure tlsocket.bindsocket;
310
-var
311
-  a:integer;
312
-  inAddrtemp:TInetSockAddrV;
313
-  inAddrtempx:{$ifdef win32}winsock.TSockaddr{$else}TInetSockAddrV{$endif} absolute inaddrtemp;
314
-  inaddrtempsize:integer;
315
-begin
316
-  try
317
-    if (localaddr <> '') or (localport <> '') then begin
318
-      if localaddr = '' then begin
319
-        {$ifdef ipv6}
320
-        if inaddr.inaddr.family = AF_INET6 then localaddr := '::' else
321
-        {$endif}
322
-        localaddr := '0.0.0.0';
323
-      end;
324
-      //gethostbyname(localaddr,host);
325
-      inaddrtempsize := makeinaddrv(forwardlookup(localaddr,0),localport,inaddrtemp);
326
-
327
-      If Bind(fdhandlein,inaddrtempx,inaddrtempsize)<> {$ifdef win32}0{$else}true{$endif} Then begin
328
-        state := wsclosed;
329
-        lasterror := {$ifdef win32}getlasterror{$else}socketerror{$endif};
330
-        raise ESocketException.create('unable to bind on address '+localaddr+'#'+localport+', error '+inttostr(lasterror));
331
-      end;
332
-      state := wsbound;
333
-    end;
334
-  except
335
-    on e: exception do begin
336
-      fdcleanup;
337
-      raise; //reraise the exception
338
-    end;
339
-  end;
340
-end;
341
-
342
-procedure tlsocket.listen;
343
-var
344
-  yes:longint;
345
-  socktype:integer;
346
-  biniptemp:tbinip;
347
-  origaddr:string;
348
-begin
349
-  if state <> wsclosed then close;
350
-  udp := uppercase(proto) = 'UDP';
351
-  if udp then begin
352
-    socktype := SOCK_DGRAM;
353
-    dgram := true;
354
-  end else socktype := SOCK_STREAM;
355
-  origaddr := addr;
356
-
357
-  if addr = '' then begin
358
-    {$ifdef ipv6}
359
-    if not v4listendefault then begin
360
-      addr := '::';
361
-    end else
362
-    {$endif}
363
-    addr := '0.0.0.0';
364
-  end;
365
-  if isbiniplist(addr) then biniptemp := biniplist_get(addr,0) else biniptemp := forwardlookup(addr,10);
366
-  addr := ipbintostr(biniptemp);
367
-  fdhandlein := socket(biniptemp.family,socktype,0);
368
-  {$ifdef ipv6}
369
-  if (addr = '::') and (origaddr = '') and (fdhandlein < 0) then begin
370
-    addr := '0.0.0.0';
371
-    fdhandlein := socket(AF_INET,socktype,0);
372
-  end;
373
-  {$endif}
374
-
375
-  if fdhandlein = -1 then raise ESocketException.create('unable to create socket'{$ifdef win32}+' error='+inttostr(wsagetlasterror){$endif});
376
-  dupnowatch(fdhandlein); // sets up maxs and copies handle to fdhandleout among other things
377
-  //eventcore.setfdreverse(fdhandlein,self); //already taken care of by dup
378
-  state := wsclosed; // then set this back as it was an undesired side effect of dup
379
-
380
-  try
381
-    yes := $01010101;  {Copied this from existing code. Value is empiric,
382
-                    but works. (yes=true<>0) }
383
-    {$ifndef win32}
384
-      if SetSocketOptions(fdhandlein, SOL_SOCKET, SO_REUSEADDR,yes,sizeof(yes))=-1 then begin
385
-        raise ESocketException.create('unable to set socket options');
386
-      end;
387
-    {$endif}
388
-    localaddr := addr;
389
-    localport := port;
390
-    bindsocket;
391
-
392
-    if not udp then begin
393
-      {!!! allow custom queue length? default 5}
394
-      if listenqueue = 0 then listenqueue := 5;
395
-      If {$ifdef win32}winsock{$else}sockets{$endif}.Listen(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise
396
-esocketexception.create('unable to listen');
397
-      state := wsListening;
398
-    end else begin
399
-      {$ifndef win32}
400
-        SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));
401
-      {$else}
402
-        SetSockOpt(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));
403
-      {$endif}
404
-      state := wsconnected;
405
-    end;
406
-
407
-    {$ifdef secondlistener}
408
-    //listening on ::. try to listen on 0.0.0.0 as well for platforms which don't already do that
409
-    if addr = '::' then begin
410
-      secondlistener := tlsocket.create(nil);
411
-      secondlistener.proto := proto;
412
-      secondlistener.addr := '0.0.0.0';
413
-      secondlistener.port := port;
414
-      if udp then begin
415
-        secondlistener.ondataavailable := secondaccepthandler;
416
-      end else begin
417
-        secondlistener.onsessionAvailable := secondaccepthandler;
418
-      end;
419
-      try
420
-        secondlistener.listen;
421
-      except
422
-        secondlistener.destroy;
423
-        secondlistener := nil;
424
-      end;
425
-    end;
426
-    {$endif}
427
-  finally
428
-    if state = wsclosed then begin
429
-      if fdhandlein >= 0 then begin
430
-        {one *can* get here without fd -beware}
431
-        eventcore.rmasterclr(fdhandlein);
432
-        myfdclose(fdhandlein); // we musnt leak file discriptors
433
-        eventcore.setfdreverse(fdhandlein,nil);
434
-        fdhandlein := -1;
435
-      end;
436
-    end else begin
437
-      eventcore.rmasterset(fdhandlein,not udp);
438
-    end;
439
-    if fdhandleout >= 0 then eventcore.wmasterclr(fdhandleout);
440
-  end;
441
-  //writeln('listened on addr '+addr+':'+port+' '+proto+' using socket number ',fdhandlein);
442
-end;
443
-
444
-{$ifdef secondlistener}
445
-procedure tlsocket.internalclose(error:word);
446
-begin
447
-  if assigned(secondlistener) then begin
448
-    secondlistener.destroy;
449
-    secondlistener := nil;
450
-  end;
451
-  inherited internalclose(error);
452
-end;
453
-
454
-procedure tlsocket.secondaccepthandler;
455
-begin
456
-  lastsessionfromsecond := true;
457
-  if udp then begin
458
-    ondataavailable(self,error);
459
-  end else begin
460
-    if assigned(onsessionavailable) then onsessionavailable(self,error);
461
-  end;
462
-end;
463
-{$endif}
464
-
465
-function tlsocket.accept : longint;
466
-var
467
-  FromAddrSize     : LongInt;        // i don't realy know what to do with these at this
468
-  FromAddr         : TInetSockAddrV;  // at this point time will tell :)
469
-  a:integer;
470
-begin
471
-  {$ifdef secondlistener}
472
-  if (lastsessionfromsecond) then begin
473
-    lastsessionfromsecond := false;
474
-    result := secondlistener.accept;
475
-    exit;
476
-  end;
477
-  {$endif}
478
-
479
-  FromAddrSize := Sizeof(FromAddr);
480
-  {$ifdef win32}
481
-    result := winsock.accept(fdhandlein,@fromaddr,@fromaddrsize);
482
-  {$else}
483
-    result := sockets.accept(fdhandlein,fromaddr,fromaddrsize);
484
-  {$endif}
485
-  //now we have accepted one request start monitoring for more again
486
-  eventcore.rmasterset(fdhandlein,true);
487
-
488
-  if result = -1 then begin
489
-    raise esocketexception.create('error '+inttostr({$ifdef win32}getlasterror{$else}socketerror{$endif})+' while accepting');
490
-  end;
491
-  if result > absoloutemaxs then begin
492
-    myfdclose(result);
493
-    a := result;
494
-    result := -1;
495
-    raise esocketexception.create('file discriptor out of range: '+inttostr(a));
496
-  end;
497
-end;
498
-
499
-function tlsocket.sendto(dest:TInetSockAddrV;destlen:integer;data:pointer;len:integer):integer;
500
-var
501
-  destx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute dest;
502
-begin
503
-  {$ifdef secondlistener}
504
-  if assigned(secondlistener) then if (dest.inaddr.family = AF_INET) then begin
505
-    result := secondlistener.sendto(dest,destlen,data,len);
506
-    exit;
507
-  end;
508
-  {$endif}
509
-  result := {$ifdef win32}winsock{$else}sockets{$endif}.sendto(self.fdhandleout,data^,len,0,destx,destlen);
510
-end;
511
-
512
-function tlsocket.receivefrom(data:pointer;len:integer;var src:TInetSockAddrV;var srclen:integer):integer;
513
-var
514
-  tempsrc:TInetSockAddrV;
515
-  tempsrclen:integer;
516
-  srcx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute tempsrc;
517
-  biniptemp:tbinip;
518
-begin
519
-  {$ifdef secondlistener}
520
-  if assigned(secondlistener) then if lastsessionfromsecond then begin
521
-    lastsessionfromsecond := false;
522
-    result := secondlistener.receivefrom(data,len,src,srclen);
523
-    exit;
524
-  end;
525
-  {$endif}
526
-  tempsrclen := sizeof(tempsrc);
527
-  result := {$ifdef win32}winsock{$else}sockets{$endif}.recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen);
528
-
529
-  {$ifdef ipv6}
530
-  biniptemp := inaddrvtobinip(tempsrc);
531
-  if needconverttov4(biniptemp) then begin
532
-    converttov4(biniptemp);
533
-    tempsrclen := makeinaddrv(biniptemp,inttostr(ntohs(tempsrc.InAddr.port)),tempsrc);
534
-  end;
535
-  {$endif}
536
-
537
-  move(tempsrc,src,srclen);
538
-  srclen := tempsrclen;
539
-end;
540
-
541
-procedure tlsocket.taskcallconnectionfailedhandler(wparam,lparam : longint);
542
-begin
543
-  connectionfailedhandler(wparam);
544
-end;
545
-
546
-procedure tlsocket.connectionfailedhandler(error:word);
547
-begin
548
-   if trymoreips then begin
549
-//     writeln('failed with error ',error);
550
-     connecttimeout.enabled := false;
551
-     destroying := true;
552
-     state := wsconnected;
553
-     self.internalclose(0);
554
-     destroying := false;
555
-     realconnect;
556
-   end else begin
557
-     state := wsconnected;
558
-     if assigned(onsessionconnected) then onsessionconnected(self,error);
559
-     self.internalclose(0);
560
-     recvq.del(maxlongint);
561
-   end;
562
-end;
563
-
564
-procedure tlsocket.connectsuccesshandler;
565
-begin
566
-   trymoreips := false;
567
-   connecttimeout.enabled := false;
568
-   if assigned(onsessionconnected) then onsessionconnected(self,0);
569
-end;
570
-
571
-
572
-procedure tlsocket.handlefdtrigger(readtrigger,writetrigger:boolean);
573
-var
574
-  tempbuf:array[0..receivebufsize-1] of byte;
575
-begin
576
-//  writeln('got a fd trigger, readtrigger=',readtrigger,' writetrigger=',writetrigger,' state=',integer(state));
577
-  if (state =wslistening) and readtrigger then begin
578
-{    debugout('listening socket triggered on read');}
579
-    eventcore.rmasterclr(fdhandlein);
580
-    if assigned(onsessionAvailable) then onsessionAvailable(self,0);
581
-  end;
582
-  if dgram and readtrigger then begin
583
-    if assigned(ondataAvailable) then ondataAvailable(self,0);
584
-    {!!!test}
585
-    exit;
586
-  end;
587
-  if (state =wsconnecting) and writetrigger then begin
588
-    // code for dealing with the reults of a non-blocking connect is
589
-    // rather complex
590
-    // if just write is triggered it means connect suceeded
591
-    // if both read and write are triggered it can mean 2 things
592
-    // 1: connect ok and data availible
593
-    // 2: connect fail
594
-    // to find out which you must read from the socket and look for errors
595
-    // there if we read successfully we drop through into the code for fireing
596
-    // the read event
597
-    if not readtrigger then begin
598
-      state := wsconnected;
599
-      connectsuccesshandler;
600
-    end else begin
601
-      numread := myfdread(fdhandlein,tempbuf,sizeof(tempbuf));
602
-      if numread <> -1 then begin
603
-        state := wsconnected;
604
-        connectsuccesshandler;
605
-        //connectread := true;
606
-        recvq.add(@tempbuf,numread);
607
-      end else begin
608
-        connectionfailedhandler({$ifdef win32}wsagetlasterror{$else}linuxerror{$endif});
609
-        exit;
610
-      end;
611
-      // if things went well here we are now in the state wsconnected with data sitting in our receive buffer
612
-      // so we drop down into the processing for data availible
613
-    end;
614
-    if fdhandlein >= 0 then begin
615
-      if state = wsconnected then begin
616
-        eventcore.rmasterset(fdhandlein,false);
617
-      end else begin
618
-        eventcore.rmasterclr(fdhandlein);
619
-      end;
620
-    end;
621
-    if fdhandleout >= 0 then begin
622
-      if sendq.size = 0 then begin
623
-        //don't clear the bit in fdswmaster if data is in the sendq
624
-        eventcore.wmasterclr(fdhandleout);
625
-      end;
626
-    end;
627
-
628
-  end;
629
-  inherited handlefdtrigger(readtrigger,writetrigger);
630
-end;
631
-
632
-constructor tlsocket.Create(AOwner: TComponent);
633
-begin
634
-  inherited create(aowner);
635
-  closehandles := true;
636
-  trymoreips := true;
637
-end;
638
-
639
-
640
-function tlsocket.getpeername(var addr:tsockaddrin;addrlen:integer):integer;
641
-var
642
-  addrx : {$ifdef win32}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr;
643
-begin
644
-  result := {$ifdef win32}winsock{$else}sockets{$endif}.getpeername(self.fdhandlein,addrx,addrlen);
645
-end;
646
-
647
-procedure tlsocket.getxaddrbin(var binip:tbinip);
648
-var
649
-  addr:tinetsockaddrv;
650
-  i:integer;
651
-begin
652
-  i := sizeof(addr);
653
-  fillchar(addr,sizeof(addr),0);
654
-
655
-  {$ifdef win32}
656
-    winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i);
657
-  {$else}
658
-    sockets.getsocketname(self.fdhandlein,addr,i);
659
-  {$endif}
660
-  binip := inaddrvtobinip(addr);
661
-  converttov4(binip);
662
-end;
663
-
664
-procedure tlsocket.getpeeraddrbin(var binip:tbinip);
665
-var
666
-  addr:tinetsockaddrv;
667
-  i:integer;
668
-begin
669
-  i := sizeof(addr);
670
-  fillchar(addr,sizeof(addr),0);
671
-  {$ifdef win32}
672
-    winsock.getpeername(self.fdhandlein,psockaddr(@addr)^,i);
673
-  {$else}
674
-    sockets.getpeername(self.fdhandlein,addr,i);
675
-  {$endif}
676
-
677
-  binip := inaddrvtobinip(addr);
678
-  converttov4(binip);
679
-end;
680
-
681
-function tlsocket.getXaddr:string;
682
-var
683
-  biniptemp:tbinip;
684
-begin
685
-  getxaddrbin(biniptemp);
686
-  result := ipbintostr(biniptemp);
687
-  if result = '' then result := 'error';
688
-end;
689
-
690
-function tlsocket.getpeeraddr:string;
691
-var
692
-  biniptemp:tbinip;
693
-begin
694
-  getpeeraddrbin(biniptemp);
695
-  result := ipbintostr(biniptemp);
696
-  if result = '' then result := 'error';
697
-end;
698
-
699
-function tlsocket.getXport:string;
700
-var
701
-  addr:tinetsockaddrv;
702
-  i:integer;
703
-begin
704
-  i := sizeof(addr);
705
-  {$ifdef win32}
706
-    winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);
707
-
708
-  {$else}
709
-    sockets.getsocketname(self.fdhandlein,addr,i);
710
-
711
-  {$endif}
712
-  result := inttostr(htons(addr.InAddr.port));
713
-end;
714
-
715
-function tlsocket.getpeerport:string;
716
-var
717
-  addr:tinetsockaddrv;
718
-  i:integer;
719
-begin
720
-  i := sizeof(addr);
721
-  {$ifdef win32}
722
-    winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i);
723
-
724
-  {$else}
725
-    sockets.getpeername(self.fdhandlein,addr,i);
726
-
727
-  {$endif}
728
-  result := inttostr(htons(addr.InAddr.port));
729
-end;
730
-
731
-{$ifdef win32}
732
-  procedure tlsocket.myfdclose(fd : integer);
733
-  begin
734
-    closesocket(fd);
735
-  end;
736
-  function tlsocket.myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt;
737
-  begin
738
-    result := winsock.send(fd,(@buf)^,size,0);
739
-  end;
740
-  function tlsocket.myfdread(fd: LongInt;var buf;size: LongInt):LongInt;
741
-  begin
742
-    result := winsock.recv(fd,buf,size,0);
743
-  end;
744
-{$endif}
745
-
746
-end.
747
-

+ 0
- 42
libwin/lcore/ltimevalstuff.inc Parādīt failu

@@ -1,42 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-
7
-
8
-{add nn msec to tv}
9
-const
10
-  tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint);
11
-  //tv_invalidtimebig will always compare as greater than any valid timeval
12
-procedure tv_add(var tv:ttimeval;msec:integer);//{ $ifdef fpc}inline;{ $endif}
13
-begin
14
-  inc(tv.tv_usec,msec*1000);
15
-  inc(tv.tv_sec,tv.tv_usec div 1000000);
16
-  tv.tv_usec := tv.tv_usec mod 1000000;
17
-end;
18
-
19
-{tv1 >= tv2}
20
-function tv_compare(const tv1,tv2:ttimeval):boolean;//{ $ifdef fpc}inline;{ $endif}
21
-begin
22
-  if tv1.tv_sec = tv2.tv_sec then begin
23
-    result := tv1.tv_usec >= tv2.tv_usec;
24
-  end else result := tv1.tv_sec > tv2.tv_sec;
25
-end;
26
-
27
-procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);//{ $ifdef fpc}inline;{ $endif}
28
-begin
29
-  dec(tv.tv_usec,tv2.tv_usec);
30
-  if tv.tv_usec < 0 then begin
31
-    inc(tv.tv_usec,1000000);
32
-    dec(tv.tv_sec)
33
-  end;
34
-  dec(tv.tv_sec,tv2.tv_sec);
35
-end;
36
-
37
-procedure msectotimeval(var tv:ttimeval;msec:integer);
38
-begin
39
-  tv.tv_sec := msec div 1000;
40
-  tv.tv_usec := (msec mod 1000)*1000;
41
-end;
42
-

+ 0
- 20
libwin/lcore/pgtypes.pas Parādīt failu

@@ -1,20 +0,0 @@
1
-{io core originally for linux bworld}
2
-
3
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
4
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
5
-  which is included in the package
6
-  ----------------------------------------------------------------------------- }
7
-
8
-unit pgtypes;
9
-interface
10
-  type
11
-    {$ifdef cpu386}{$define i386}{$endif}
12
-    {$ifdef i386}
13
-      taddrint=longint;
14
-    {$else}
15
-      taddrint=sizeint;
16
-    {$endif}
17
-    paddrint=^taddrint;
18
-
19
-implementation
20
-end.

+ 0
- 1
libwin/lcore/todo.txt Parādīt failu

@@ -1 +0,0 @@
1
-* fixup dnsasync to perform retries and use multiple dns servers

+ 0
- 14
libwin/lcore/uint32.inc Parādīt failu

@@ -1,14 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-type
6
-  {delphi 3 and before do not have a 32 bits unsigned integer type,
7
-  but longint has the correct behavior - it doesn't on newer delphi versions}
8
-  {$ifndef fpc}
9
-    {$ifdef ver70}{$define pred4}{$endif} {tp7}
10
-    {$ifdef ver80}{$define pred4}{$endif} {delphi 1}
11
-    {$ifdef ver90}{$define pred4}{$endif} {delphi 2}
12
-    {$ifdef ver100}{$define pred4}{$endif} {delphi 3}
13
-  {$endif}
14
-  uint32={$ifdef pred4}longint{$else}longword{$endif};

+ 0
- 114
libwin/lcore/unitfork.pas Parādīt failu

@@ -1,114 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-    which is included in the package
4
-      ----------------------------------------------------------------------------- }
5
-unit unitfork;
6
-
7
-interface
8
-
9
-procedure dofork(const programname:string);
10
-procedure writepid;
11
-function checkpid(const filename:string):boolean;
12
-procedure deletepid;
13
-
14
-implementation
15
-
16
-uses
17
-  {$ifdef VER1_0}
18
-    linux,
19
-  {$else}
20
-    baseunix,unix,unixutil,
21
-  {$endif}
22
-  sysutils;
23
-
24
-{$include unixstuff.inc}
25
-
26
-const
27
-  F_WRLCK=2;
28
-
29
-var
30
-  pidfilename:string;
31
-  pidfile:text;
32
-
33
-procedure dofork(const programname:string);
34
-var
35
-  a:integer;
36
-begin
37
-  //writeln('dofork entered');
38
-  //if (paramstr(1) = 'foreground') or (paramstr(1)='debug') then exit; {no fork}
39
-  a := fork;
40
-  if a = 0 then exit; {i'm the child}
41
-  if a < 0 then begin
42
-    writeln('failed to run in background, try "'+programname+' foreground" if it doesnt work otherwise');
43
-    halt; {failed}
44
-  end;
45
-
46
-  halt; {i'm the parent}
47
-end;
48
-
49
-function checkpid;
50
-var
51
-  handle:thandle;
52
-
53
-begin
54
-  result := false;
55
-  pidfilename := '';
56
-  //debugout(filename);
57
-  assignfile(pidfile,filename);
58
-  filemode := 2;
59
-  {opening file to get a fd for it. can't rewrite because a lock appears to allow the rewrite}
60
-  {$i-}reset(pidfile);{$i+}
61
-  if ioresult <> 0 then begin
62
-    {$i-}rewrite(pidfile);{$i+}
63
-    if ioresult <> 0 then exit;
64
-  end;
65
-
66
-  handle := getfs(pidfile);
67
-
68
-  //debugout('got handle');
69
-  {check if locking is possible: it's not if other process still runs}
70
-  {$ifdef VER1_0}
71
-  if not flock(handle,LOCK_EX or LOCK_NB)
72
-  {$else}
73
-  if flock(handle,LOCK_EX or LOCK_NB) <> 0
74
-  {$endif}
75
-  then begin
76
-    //debugout('failed to lock pid file');
77
-    close(pidfile);
78
-    exit;
79
-  end;
80
-  rewrite(pidfile);
81
-  {lock again because the rewrite removes the lock}
82
-  {$ifdef VER1_0}
83
-  if not flock(handle,LOCK_EX or LOCK_NB)
84
-  {$else}
85
-  if flock(handle,LOCK_EX or LOCK_NB) <> 0
86
-  {$endif}
87
-  then raise exception.create('flock failed '+inttostr(linuxerror));
88
-  pidfilename := filename;
89
-  result := true;
90
-end;
91
-
92
-
93
-procedure writepid;
94
-begin
95
-  writeln(pidfile,getpid);
96
-  flush(pidfile);
97
-end;
98
-
99
-procedure deletepid;
100
-begin
101
-  if pidfilename = '' then exit;
102
-  try
103
-    {$i-}
104
-    closefile(pidfile);
105
-    erase(pidfile);
106
-    {$i+}
107
-    ioresult;
108
-  except
109
-    {}
110
-  end;
111
-  pidfilename := '';
112
-end;
113
-
114
-end.

+ 0
- 53
libwin/lcore/unitsettc.pas Parādīt failu

@@ -1,53 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-unit Unitsettc;
7
-
8
-interface
9
-
10
-procedure settc;
11
-procedure unsettc;
12
-
13
-implementation
14
-
15
-uses
16
-  windows,
17
-  sysutils;
18
-
19
-var
20
-  classpriority,threadpriority:integer;
21
-  refcount:integer=0;
22
-
23
-procedure settc;
24
-var
25
-  hprocess,hthread:integer;
26
-begin
27
-  if (refcount = 0) then begin
28
-    hProcess := GetCurrentProcess;
29
-    hThread := GetCurrentThread;
30
-    ClassPriority := GetPriorityClass(hProcess);
31
-    ThreadPriority := GetThreadPriority(hThread);
32
-    SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS);
33
-    SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
34
-  end;
35
-  inc(refcount);
36
-end;
37
-
38
-procedure unsettc;
39
-var
40
-  hprocess,hthread:integer;
41
-begin
42
-  dec(refcount);
43
-  if (refcount < 0) then refcount := 0;
44
-  if (refcount = 0) then begin
45
-    hProcess := GetCurrentProcess;
46
-    hThread := GetCurrentThread;
47
-    SetPriorityClass(hProcess, ClassPriority);
48
-    SetThreadPriority(hThread,  ThreadPriority);
49
-  end;
50
-end;
51
-
52
-end.
53
-

+ 0
- 128
libwin/lcore/unitwindowobject.pas Parādīt failu

@@ -1,128 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-unit unitwindowobject;
7
-
8
-interface
9
-
10
-uses
11
-  classes,
12
-  {$ifdef win32}
13
-    windows,messages,wmessages,
14
-  {$else}
15
-    lmessages,
16
-    {$macro on}
17
-    {$define windows := lmessages}
18
-  {$endif}
19
-  sysutils,
20
-  pgtypes;
21
-
22
-type
23
-  twindowobject=class(tobject)
24
-    hwndmain:hwnd;
25
-    onmsg:function(msg,wparam,lparam:taddrint):boolean of object;
26
-    exitloopflag:boolean;
27
-    function settimer(id,timeout:taddrint):integer;
28
-    function killtimer(id:taddrint):boolean;
29
-    procedure postmessage(msg,wparam,lparam:taddrint);
30
-    procedure messageloop;
31
-    {$ifdef win32}
32
-      procedure processmessages;
33
-      function processmessage:boolean;
34
-    {$endif}
35
-    constructor create;
36
-    destructor destroy; override;
37
-  end;
38
-
39
-implementation
40
-
41
-//uses safewriteln;
42
-
43
-function WindowProc(ahWnd:HWND; auMsg:Integer; awParam:WPARAM; alParam:LPARAM):Integer; stdcall;
44
-var
45
-  i:taddrint;
46
-begin
47
-  ////swriteln('in unitwindowobject.windowproc');
48
-  Result := 0;  // This means we handled the message
49
-  if ahwnd <> hwnd(0) then i := getwindowlongptr(ahwnd,0) else i := 0;
50
-  if i <> 0 then begin
51
-    if assigned(twindowobject(i).onmsg) then begin
52
-      if not twindowobject(i).onmsg(aumsg,awparam,alparam) then i := 0;
53
-    end else i := 0
54
-  end;
55
-  if i = 0 then Result := DefWindowProc(ahWnd, auMsg, awParam, alParam)
56
-end;
57
-
58
-var
59
-  twindowobject_Class : TWndClass = (style:0; lpfnWndProc:@WindowProc;
60
-  cbClsExtra:0; cbWndExtra:sizeof(pointer); hInstance:thinstance(0); hIcon:hicon(0); hCursor:hcursor(0);
61
-  hbrBackground:hbrush(0);lpszMenuName:nil; lpszClassName:'twindowobject_class');
62
-
63
-function twindowobject.settimer;
64
-begin
65
-  result := windows.settimer(hwndmain,id,timeout,nil);
66
-end;
67
-
68
-function twindowobject.killtimer;
69
-begin
70
-  result := windows.killtimer(hwndmain,id);
71
-end;
72
-
73
-constructor twindowobject.create;
74
-begin
75
-  inherited;
76
-  //swriteln('in twindowobject.create, about to call registerclass');
77
-  Windows.RegisterClass(twindowobject_Class);
78
-  //swriteln('about to call createwindowex');
79
-  hWndMain := CreateWindowEx(WS_EX_TOOLWINDOW, twindowobject_Class.lpszClassName,
80
-    '', WS_POPUP, 0, 0,0, 0, hwnd(0), 0, HInstance, nil);
81
-  //swriteln('about to check result of createwindowex');
82
-  if hWndMain = hwnd(0) then raise exception.create('CreateWindowEx failed');
83
-  //swriteln('about to store reference to self in extra windo memory');
84
-  setwindowlongptr(hwndmain,0,taddrint(self));
85
-  //swriteln('finished twindowobject.create , hwndmain='+inttohex(taddrint(hwndmain),16));
86
-end;
87
-
88
-destructor twindowobject.destroy;
89
-begin
90
-  if hWndMain <> hwnd(0) then DestroyWindow(hwndmain);
91
-  inherited;
92
-end;
93
-
94
-procedure twindowobject.postmessage;
95
-begin
96
-  windows.postmessage(hwndmain,msg,wparam,lparam);
97
-end;
98
-
99
-{$ifdef win32}
100
-  function twindowobject.ProcessMessage : Boolean;
101
-  var
102
-    Msg : TMsg;
103
-  begin
104
-    Result := FALSE;
105
-    if PeekMessage(Msg, hwndmain, 0, 0, PM_REMOVE) then begin
106
-      Result := TRUE;
107
-      DispatchMessage(Msg);
108
-    end;
109
-  end;
110
-
111
-  procedure twindowobject.processmessages;
112
-  begin
113
-    while processmessage do;
114
-  end;
115
-{$endif}
116
-
117
-procedure twindowobject.messageloop;
118
-var
119
-  MsgRec : TMsg;
120
-begin
121
-  while GetMessage(MsgRec, hwnd(0), 0, 0) do begin
122
-    DispatchMessage(MsgRec);
123
-    if exitloopflag then exit;
124
-    {if not peekmessage(msgrec,0,0,0,PM_NOREMOVE) then onidle}
125
-  end;
126
-end;
127
-
128
-end.

+ 0
- 113
libwin/lcore/unixstuff.inc Parādīt failu

@@ -1,113 +0,0 @@
1
-{$ifdef UNIX}
2
-  {$macro on}
3
-  {$ifdef VER1_0}
4
-    {$define tv_sec := sec}
5
-    {$define tv_usec := usec}
6
-    function dup(const original:integer):integer;inline;
7
-    begin
8
-      linux.dup(original,result);
9
-    end;
10
-    {$define gettimeofdaysec := gettimeofday}
11
-    const
12
-      IPPROTO_UDP=17;
13
-      IPPROTO_ICMP=1;
14
-    function ntohs(invalue:word):word;inline;
15
-    var
16
-      invaluebytes : array[0..1] of byte absolute invalue;
17
-      resultbytes : array[0..1] of byte absolute result;
18
-    begin
19
-      {$ifdef endian_little}
20
-	resultbytes[0] := invaluebytes[1];
21
-	resultbytes[1] := invaluebytes[0];
22
-      {$else}
23
-	result := invalue;
24
-      {$endif}
25
-    end;  
26
-  {$else}
27
-    
28
-    {$define sigprocmask := fpsigprocmask}
29
-    {$define sigaction   := fpsigaction}
30
-    {$define fdclose     := fpclose}
31
-    {$define fcntl       := fpfcntl}
32
-    {$define fdwrite     := fpwrite}
33
-    {$define fdread      := fpread}
34
-    {$define fdopen      := fpopen}
35
-    {$define select      := fpselect}
36
-    {$define linuxerror  := fpgeterrno}
37
-    {$define fork        := fpfork}
38
-    {$define getpid      := fpgetpid}
39
-    {$define getenv      := fpgetenv}
40
-    {$define chmod       := fpchmod}
41
-    {$define dup2        := fpdup2}
42
-    {$ifndef ver1_9_2}
43
-      {$define flock     := fpflock}
44
-      {$ifndef ver1_9_4}
45
-        procedure Execl(Todo:string);inline;
46
-	var
47
-	  p : ppchar;
48
-	begin
49
-	  p := unixutil.StringToPPChar(Todo,1);
50
-	  if (p=nil) or (p^=nil) then exit;
51
-	  fpexecv(p^,p);
52
-	end;
53
-      {$endif}
54
-    {$endif}
55
-    {$ifdef ver2_0}
56
-      const
57
-        IPPROTO_UDP=17;
58
-        IPPROTO_ICMP=1;
59
-    {$endif}
60
-    {$ifdef ver1_9}
61
-      const
62
-        IPPROTO_UDP=17;
63
-        IPPROTO_ICMP=1;
64
-      function ntohs(invalue:word):word;inline;
65
-      var
66
-        invaluebytes : array[0..1] of byte absolute invalue;
67
-	resultbytes : array[0..1] of byte absolute result;
68
-      begin
69
-        {$ifdef endian_little}
70
-	  resultbytes[0] := invaluebytes[1];
71
-	  resultbytes[1] := invaluebytes[0];
72
-	{$else}
73
-	  result := invalue;
74
-	{$endif}
75
-      end;
76
-    {$endif}
77
-    procedure gettimeofday(var tv:ttimeval);inline;
78
-    begin
79
-      fpgettimeofday(@tv,nil);    
80
-    end;
81
-    function gettimeofdaysec : longint;
82
-    var
83
-      tv:ttimeval;
84
-    begin
85
-      gettimeofday(tv);
86
-      result := tv.tv_sec;
87
-    end;
88
-
89
-    //a function is used here rather than a define to prevent issues with tlasio.dup
90
-    function dup(const original:integer):integer;inline;
91
-    begin
92
-      result := fpdup(original);
93
-    end;
94
-    function octal(invalue:longint):longint;
95
-    var
96
-      a : integer;
97
-      i : integer;
98
-    begin
99
-      i := 0;
100
-      result := 0;
101
-      while invalue <> 0 do begin
102
-        a := invalue mod 10;
103
-        result := result + (a shl (i*3));
104
-
105
-        invalue := invalue div 10;
106
-        inc(i);
107
-      end;
108
-    end;
109
-    const
110
-      sys_eintr=esyseintr;
111
-
112
-  {$endif}
113
-{$endif}

+ 0
- 382
libwin/lcore/wcore.pas Parādīt failu

@@ -1,382 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- }
5
-
6
-unit wcore;
7
-
8
-{
9
-lcore compatible interface for windows
10
-
11
-- messageloop
12
-
13
-- tltimer
14
-
15
-}
16
-//note: events after release are normal and are the apps responsibility to deal with safely
17
-interface
18
-
19
-  uses
20
-    classes,windows,mmsystem;
21
-
22
-  type
23
-    float=double;
24
-
25
-    tlcomponent = class(tcomponent)
26
-    public
27
-      released:boolean;
28
-      procedure release;
29
-      destructor destroy; override;
30
-    end;
31
-
32
-    tltimer=class(tlcomponent)
33
-    private
34
-      fenabled : boolean;
35
-      procedure setenabled(newvalue : boolean);
36
-    public
37
-      ontimer:tnotifyevent;
38
-      initialevent:boolean;
39
-      initialdone:boolean;
40
-      prevtimer:tltimer;
41
-      nexttimer:tltimer;
42
-      interval:integer;        {miliseconds, default 1000}
43
-      nextts:integer;
44
-      property enabled:boolean read fenabled write setenabled;
45
-      constructor create(aowner:tcomponent);override;
46
-      destructor destroy;override;
47
-    end;
48
-
49
-    ttaskevent=procedure(wparam,lparam:longint) of object;
50
-
51
-    tltask=class(tobject)
52
-    public
53
-      handler  : ttaskevent;
54
-      obj      : tobject;
55
-      wparam   : longint;
56
-      lparam   : longint;
57
-      nexttask : tltask;
58
-      constructor create(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
59
-    end;
60
-
61
-procedure messageloop;
62
-procedure addtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
63
-procedure disconnecttasks(aobj:tobject);
64
-procedure exitmessageloop;
65
-procedure processmessages;
66
-
67
-var
68
-  onshutdown:procedure(s:string);
69
-
70
-implementation
71
-
72
-uses
73
-  {$ifdef fpc}
74
-  bmessages;
75
-  {$else}
76
-  messages;
77
-  {$endif}
78
-
79
-
80
-const
81
-  WINMSG_TASK=WM_USER;
82
-
83
-var
84
-  hwndwcore:hwnd;
85
-  firsttimer:tltimer;
86
-  timesubstract:integer;
87
-  firsttask,lasttask,currenttask:tltask;
88
-
89
-procedure tlcomponent.release;
90
-begin
91
-  released := true;
92
-end;
93
-
94
-destructor tlcomponent.destroy;
95
-begin
96
-  disconnecttasks(self);
97
-  inherited destroy;
98
-end;
99
-
100
-{------------------------------------------------------------------------------}
101
-
102
-procedure tltimer.setenabled(newvalue : boolean);
103
-begin
104
-  fenabled := newvalue;
105
-  nextts := 0;
106
-  initialdone := false;
107
-end;
108
-
109
-constructor tltimer.create;
110
-begin
111
-  inherited create(AOwner);
112
-  nexttimer := firsttimer;
113
-  prevtimer := nil;
114
-
115
-  if assigned(nexttimer) then nexttimer.prevtimer := self;
116
-  firsttimer := self;
117
-
118
-  interval := 1000;
119
-  enabled := true;
120
-  released := false;
121
-end;
122
-
123
-destructor tltimer.destroy;
124
-begin
125
-  if prevtimer <> nil then begin
126
-    prevtimer.nexttimer := nexttimer;
127
-  end else begin
128
-    firsttimer := nexttimer;
129
-  end;
130
-  if nexttimer <> nil then begin
131
-    nexttimer.prevtimer := prevtimer;
132
-  end;
133
-  inherited destroy;
134
-end;
135
-
136
-{------------------------------------------------------------------------------}
137
-
138
-function wcore_timehandler:integer;
139
-const
140
-  rollover_bits=30;
141
-var
142
-  tv,tvnow:integer;
143
-  currenttimer,temptimer:tltimer;
144
-begin
145
-  if not assigned(firsttimer) then begin
146
-    result := 1000;
147
-    exit;
148
-  end;
149
-
150
-  tvnow := timegettime;
151
-  if (tvnow and ((-1) shl rollover_bits)) <> timesubstract then begin
152
-    currenttimer := firsttimer;
153
-    while assigned(currenttimer) do begin
154
-      dec(currenttimer.nextts,(1 shl rollover_bits));
155
-      currenttimer := currenttimer.nexttimer;
156
-    end;
157
-    timesubstract := tvnow and ((-1) shl rollover_bits);
158
-  end;
159
-  tvnow := tvnow and ((1 shl rollover_bits)-1);
160
-
161
-  currenttimer := firsttimer;
162
-  while assigned(currenttimer) do begin
163
-    if tvnow >= currenttimer.nextts then begin
164
-      if assigned(currenttimer.ontimer) then begin
165
-        if currenttimer.enabled then begin
166
-          if currenttimer.initialevent or currenttimer.initialdone then currenttimer.ontimer(currenttimer);
167
-          currenttimer.initialdone := true;
168
-        end;
169
-      end;
170
-      currenttimer.nextts := tvnow+currenttimer.interval;
171
-    end;
172
-    temptimer := currenttimer;
173
-    currenttimer := currenttimer.nexttimer;
174
-    if temptimer.released then temptimer.free;
175
-  end;
176
-
177
-  tv := maxlongint;
178
-  currenttimer := firsttimer;
179
-  while assigned(currenttimer) do begin
180
-    if currenttimer.nextts < tv then tv := currenttimer.nextts;
181
-    currenttimer := currenttimer.nexttimer;
182
-  end;
183
-  result := tv-tvnow;
184
-  if result < 15 then result := 15;
185
-end;
186
-
187
-{------------------------------------------------------------------------------}
188
-
189
-constructor tltask.create(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
190
-begin
191
-  inherited create;
192
-  handler   := ahandler;
193
-  obj       := aobj;
194
-  wparam    := awparam;
195
-  lparam    := alparam;
196
-  {nexttask  := firsttask;
197
-  firsttask := self;}
198
-  if assigned(lasttask) then begin
199
-    lasttask.nexttask := self;
200
-  end else begin
201
-    firsttask := self;
202
-    postmessage(hwndwcore,WINMSG_TASK,0,0);
203
-  end;
204
-  lasttask := self;
205
-  //ahandler(wparam,lparam);
206
-end;
207
-
208
-procedure addtask(ahandler:ttaskevent;aobj:tobject;awparam,alparam:longint);
209
-begin
210
-  tltask.create(ahandler,aobj,awparam,alparam);
211
-end;
212
-
213
-procedure disconnecttasks(aobj:tobject);
214
-var
215
-  currenttasklocal : tltask ;
216
-  counter          : byte   ;
217
-begin
218
-  for counter := 0 to 1 do begin
219
-    if counter = 0 then begin
220
-      currenttasklocal := firsttask; //main list of tasks
221
-    end else begin
222
-      currenttasklocal := currenttask; //needed in case called from a task
223
-    end;
224
-    // note i don't bother to sestroy the links here as that will happen when
225
-    // the list of tasks is processed anyway
226
-    while assigned(currenttasklocal) do begin
227
-      if currenttasklocal.obj = aobj then begin
228
-        currenttasklocal.obj := nil;
229
-        currenttasklocal.handler := nil;
230
-      end;
231
-      currenttasklocal := currenttasklocal.nexttask;
232
-    end;
233
-  end;
234
-end;
235
-
236
-procedure dotasks;
237
-var
238
-  temptask:tltask;
239
-begin
240
-  if firsttask = nil then exit;
241
-
242
-  currenttask := firsttask;
243
-  firsttask := nil;
244
-  lasttask  := nil;
245
-  while assigned(currenttask) do begin
246
-    if assigned(currenttask.handler) then currenttask.handler(currenttask.wparam,currenttask.lparam);
247
-    temptask := currenttask;
248
-    currenttask := currenttask.nexttask;
249
-    temptask.free;
250
-  end;
251
-  currenttask := nil;
252
-end;
253
-
254
-{------------------------------------------------------------------------------}
255
-
256
-procedure exitmessageloop;
257
-begin
258
-  postmessage(hwndwcore,WM_QUIT,0,0);
259
-end;
260
-
261
-  {$ifdef threadtimer}
262
-  'thread timer'
263
-  {$else}
264
-const timerid_wcore=$1000;
265
-  {$endif}
266
-
267
-function MyWindowProc(
268
-    ahWnd   : HWND;
269
-    auMsg   : Integer;
270
-    awParam : WPARAM;
271
-    alParam : LPARAM): Integer; stdcall;
272
-var
273
-    MsgRec : TMessage;
274
-    a:integer;
275
-begin
276
-  Result := 0;  // This means we handled the message
277
-
278
-  {MsgRec.hwnd    := ahWnd;}
279
-  MsgRec.wParam  := awParam;
280
-  MsgRec.lParam  := alParam;
281
-
282
-  dotasks;
283
-  case auMsg of
284
-    {$ifndef threadtimer}
285
-    WM_TIMER: begin
286
-      if msgrec.wparam = timerid_wcore then begin
287
-        a := wcore_timehandler;
288
-        killtimer(hwndwcore,timerid_wcore);
289
-        settimer(hwndwcore,timerid_wcore,a,nil);
290
-      end;
291
-    end;
292
-    {$endif}
293
-
294
-    {WINMSG_TASK:dotasks;}
295
-
296
-    WM_CLOSE: begin
297
-      {}
298
-    end;
299
-    WM_DESTROY: begin
300
-      {}
301
-    end;
302
-  else
303
-      Result := DefWindowProc(ahWnd, auMsg, awParam, alParam)
304
-  end;
305
-end;
306
-
307
-
308
-var
309
-  MyWindowClass : TWndClass = (style         : 0;
310
-                                 lpfnWndProc   : @MyWindowProc;
311
-                                 cbClsExtra    : 0;
312
-                                 cbWndExtra    : 0;
313
-                                 hInstance     : 0;
314
-                                 hIcon         : 0;
315
-                                 hCursor       : 0;
316
-                                 hbrBackground : 0;
317
-                                 lpszMenuName  : nil;
318
-                                 lpszClassName : 'wcoreClass');
319
-
320
-procedure messageloop;
321
-var
322
-  MsgRec : TMsg;
323
-begin
324
-
325
-  if Windows.RegisterClass(MyWindowClass) = 0 then halt;
326
-  //writeln('about to create wcore handle, hinstance=',hinstance);
327
-  hwndwcore := CreateWindowEx(WS_EX_TOOLWINDOW,
328
-                               MyWindowClass.lpszClassName,
329
-                               '',        { Window name   }
330
-                               WS_POPUP,  { Window Style  }
331
-                               0, 0,      { X, Y          }
332
-                               0, 0,      { Width, Height }
333
-                               0,         { hWndParent    }
334
-                               0,         { hMenu         }
335
-                               HInstance, { hInstance     }
336
-                               nil);      { CreateParam   }
337
-
338
-  if hwndwcore = 0 then halt;
339
-
340
-  {$ifdef threadtimer}
341
-  'thread timer'
342
-  {$else}
343
-  if settimer(hwndwcore,timerid_wcore,15,nil) = 0 then halt;
344
-  {$endif}
345
-
346
-
347
-  while GetMessage(MsgRec, 0, 0, 0) do begin
348
-    TranslateMessage(MsgRec);
349
-    DispatchMessage(MsgRec);
350
-    {if not peekmessage(msgrec,0,0,0,PM_NOREMOVE) then onidle}
351
-  end;
352
-
353
-  if hWndwcore <> 0 then begin
354
-    DestroyWindow(hwndwcore);
355
-    hWndwcore := 0;
356
-  end;
357
-
358
-  {$ifdef threadtimer}
359
-  'thread timer'
360
-  {$else}
361
-  killtimer(hwndwcore,timerid_wcore);
362
-  {$endif}
363
-end;
364
-
365
-function ProcessMessage : Boolean;
366
-var
367
-    Msg : TMsg;
368
-begin
369
-    Result := FALSE;
370
-    if PeekMessage(Msg, hwndwcore, 0, 0, PM_REMOVE) then begin
371
-      Result := TRUE;
372
-      DispatchMessage(Msg);
373
-    end;
374
-end;
375
-
376
-procedure processmessages;
377
-begin
378
-  while processmessage do;
379
-end;
380
-
381
-
382
-end.

+ 0
- 40
libwin/lcore/wmessages.pas Parādīt failu

@@ -1,40 +0,0 @@
1
-{ Copyright (C) 2005 Bas Steendijk and Peter Green
2
-  For conditions of distribution and use, see copyright notice in zlib_license.txt
3
-  which is included in the package
4
-  ----------------------------------------------------------------------------- } 
5
-      
6
-unit wmessages;
7
-//this unit contains varions functions and types to make it easier to write
8
-//code that works with both real windows messages and lmessages
9
-
10
-interface
11
-uses windows,messages,pgtypes;
12
-type
13
-  thinstance=thandle;
14
-  thevent=thandle;
15
-
16
-//according to MS you are supposed to use get/setwindowlongptr to get/set
17
-//pointers in extra window memory so your program can be built for win64, this
18
-//is also the only interface to window memory that lmessages offers but delphi
19
-//doesn't define it so alias it to getwindowlong here for win32.
20
-{$ifndef win64} //future proofing ;)
21
-  function getwindowlongptr(ahwnd:hwnd;nindex:integer) : taddrint;
22
-  procedure setwindowlongptr(ahwnd:hwnd;nindex:integer;dwNewLong : taddrint);
23
-{$endif}
24
-function WaitForSingleEvent(hHandle: THandle; dwMilliseconds: DWORD): DWORD; stdcall;
25
-implementation
26
-{$ifndef win64}
27
-  function getwindowlongptr(ahwnd:hwnd;nindex:integer) : taddrint;
28
-  begin
29
-    result := getwindowlong(ahwnd,nindex);
30
-  end;
31
-  procedure setwindowlongptr(ahwnd:hwnd;nindex:integer;dwNewLong : taddrint);
32
-  begin
33
-    setwindowlong(ahwnd,nindex,dwnewlong);
34
-  end;
35
-{$endif}
36
-function WaitForSingleEvent(hHandle: THandle; dwMilliseconds: DWORD): DWORD; stdcall;
37
-begin
38
-  result := waitforsingleobject(hhandle,dwmilliseconds);
39
-end;
40
-end.

+ 0
- 19
libwin/lcore/zlib_license.txt Parādīt failu

@@ -1,19 +0,0 @@
1
-Copyright (c) 2005 Bas Steendijk and Peter Green
2
-
3
-This software is provided 'as-is', without any express or implied warranty.
4
-In no event will the authors be held liable for any damages arising from the
5
-use of this software.
6
-
7
-Permission is granted to anyone to use this software for any purpose, including
8
-commercial applications, and to alter it and redistribute it freely, subject to
9
-the following restrictions:
10
-
11
-    1. The origin of this software must not be misrepresented; you must not
12
-       claim that you wrote the original software. If you use this software in a
13
-       product, an acknowledgment in the product documentation would be
14
-       appreciated but is not required.
15
-
16
-    2. Altered source versions must be plainly marked as such, and must not be
17
-       misrepresented as being the original software.
18
-
19
-    3. This notice may not be removed or altered from any source distribution.

+ 0
- 199
libwin/shared.pas Parādīt failu

@@ -1,199 +0,0 @@
1
-{*
2
- * Shared methods / classes / functions between Windows programs
3
- *
4
- * This application launches DMDirc on windows and passes control to the
5
- * update engine as necessary.
6
- *
7
- * DMDirc - Open Source IRC Client
8
- * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
9
- * Michael Nixon
10
- *
11
- * Permission is hereby granted, free of charge, to any person obtaining a copy
12
- * of this software and associated documentation files (the "Software"), to deal
13
- * in the Software without restriction, including without limitation the rights
14
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
- * copies of the Software, and to permit persons to whom the Software is
16
- * furnished to do so, subject to the following conditions:
17
- *
18
- * The above copyright notice and this permission notice shall be included in
19
- * all copies or substantial portions of the Software.
20
- *
21
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
- * SOFTWARE.
28
- *}
29
-unit shared;
30
-
31
-interface
32
-
33
-uses Windows, SysUtils, Vista;
34
-
35
-function nicesize(dsize: extended): string;
36
-function askQuestion(Question: String; Title: string): boolean;
37
-procedure showmessage(message: String; Title: string; context:String = 'Information');
38
-procedure showError(ErrorMessage: String; Title: string; addFooter: boolean = true; includeDescInXP: boolean = true);
39
-function Launch(sProgramToRun: String; hide: boolean = false): TProcessInformation;
40
-function ExecAndWait(sProgramToRun: String; hide: boolean = false): Longword;
41
-procedure RunProgram(sProgramToRun: String; wait: boolean);
42
-function RunJava(arguments: String): Longword;
43
-{ ---------------------------------------------------------------------------- }
44
-
45
-implementation
46
-
47
-{ ----------------------------------------------------------------------------
48
-  Takes a size, <dsize> in bytes, and converts it a human readable string with
49
-  a suffix (MB or GB).
50
-  ---------------------------------------------------------------------------- }
51
-function nicesize(dsize: extended): string;
52
-var
53
-  kbytes: single;
54
-  mbytes: single;
55
-  gbytes: single;
56
-begin
57
-  kbytes := dsize / 1024;
58
-  mbytes := kbytes / 1024;
59
-  gbytes := mbytes / 1024;
60
-
61
-  if kbytes < 1024 then begin
62
-    result := FloatToStrF(kbytes, ffFixed, 10, 2) + ' kB';
63
-    exit;
64
-  end;
65
-
66
-  if mbytes < 1024 then begin
67
-    result := FloatToStrF(mbytes, ffFixed, 10, 2) + ' MB';
68
-    exit;
69
-  end;
70
-
71
-  result := FloatToStrF(gbytes, ffFixed, 10, 2) + ' GB';
72
-  exit;
73
-end;
74
-
75
-{ ----------------------------------------------------------------------------
76
-  Ask a question and return True for YES and False for NO
77
-  Uses nifty vista task dialog if available
78
-  ---------------------------------------------------------------------------- }
79
-function askQuestion(Question: String; Title: string): boolean;
80
-begin
81
-  Result := TaskDialog(0, Title, 'Question', Question, TD_ICON_QUESTION, TD_BUTTON_YES + TD_BUTTON_NO) = mrYes;
82
-end;
83
-
84
-{ ----------------------------------------------------------------------------
85
-  Show a message box (information)
86
-  Uses nifty vista task dialog if available
87
-  ---------------------------------------------------------------------------- }
88
-procedure showmessage(message: String; Title: string; context:String = 'Information');
89
-begin
90
-  TaskDialog(0, Title, context, message, TD_ICON_INFORMATION, TD_BUTTON_OK);
91
-end;
92
-
93
-{ ----------------------------------------------------------------------------
94
-  Show an error message
95
-  Uses nifty vista task dialog if available
96
-  ---------------------------------------------------------------------------- }
97
-procedure showError(ErrorMessage: String; Title: string; addFooter: boolean = true; includeDescInXP: boolean = true);
98
-begin
99
-  if addFooter then begin
100
-    ErrorMessage := ErrorMessage+#13#10;
101
-    ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
102
-    if not IsWindowsVista then ErrorMessage := ErrorMessage+#13#10;
103
-    ErrorMessage := ErrorMessage+'please feel free to contact us.';
104
-  end;
105
-  TaskDialog(0, Title, 'Sorry, ' + Title + ' is unable to continue.', ErrorMessage, TD_ICON_ERROR, TD_BUTTON_OK, includeDescInXP, false);
106
-end;
107
-
108
-{ ----------------------------------------------------------------------------
109
-  Launch a process (hidden if requested) and immediately return control to
110
-  the current thread
111
-  ---------------------------------------------------------------------------- }
112
-function Launch(sProgramToRun: String; hide: boolean = false): TProcessInformation;
113
-var
114
-  StartupInfo: TStartupInfo;
115
-begin
116
-  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
117
-  with StartupInfo do begin
118
-    cb := SizeOf(TStartupInfo);
119
-    dwFlags := STARTF_USESHOWWINDOW;
120
-    if hide then wShowWindow := SW_HIDE
121
-    else wShowWindow := SW_SHOWNORMAL;
122
-  end;
123
-
124
-  CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, Result);
125
-end;
126
-
127
-{ ----------------------------------------------------------------------------
128
-  Launch a process (hidden if requested) and wait for it to finish
129
-  ---------------------------------------------------------------------------- }
130
-function ExecAndWait(sProgramToRun: String; hide: boolean = false): Longword;
131
-var
132
-  ProcessInfo: TProcessInformation;
133
-begin
134
-  ProcessInfo := Launch(sProgramToRun, hide);
135
-  getExitCodeProcess(ProcessInfo.hProcess, Result);
136
-
137
-  while Result = STILL_ACTIVE do begin
138
-    sleep(1000);
139
-    GetExitCodeProcess(ProcessInfo.hProcess, Result);
140
-  end;
141
-end;
142
-
143
-{ ----------------------------------------------------------------------------
144
-  Launch a process and either waits for it or returns control immediately
145
-  ---------------------------------------------------------------------------- }
146
-procedure RunProgram(sProgramToRun: String; wait: boolean);
147
-begin
148
-  if wait then ExecAndWait(sProgramToRun)
149
-  else Launch(sProgramToRun);
150
-end;
151
-
152
-{ ----------------------------------------------------------------------------
153
-  Launch java, allowing for 64 bit windows to be really shit.
154
-  ---------------------------------------------------------------------------- }
155
-function RunJava(arguments: String): Longword;
156
-type
157
-	TEnableRedirection = function(dwThreadId: Pointer): BOOL; stdcall;
158
-	TDisableRedirection = function(dwThreadId: Pointer): BOOL; stdcall;
159
-var
160
-	K32Handle: THandle;
161
-	EnableRedirection: TEnableRedirection;
162
-	DisableRedirection: TDisableRedirection;
163
-	hasWow64: boolean = false;
164
-	
165
-	javaCommand: String = 'javaw.exe';
166
-begin
167
-	K32Handle := GetModuleHandle('kernel32.dll');
168
-	if (K32Handle > 0) then begin
169
-		@DisableRedirection := GetProcAddress(K32Handle, 'Wow64DisableWow64FsRedirection');
170
-		@EnableRedirection := GetProcAddress(K32Handle, 'Wow64RevertWow64FsRedirection');
171
-		
172
-		hasWow64 := Assigned(DisableRedirection) and Assigned(EnableRedirection);
173
-	end;
174
-	
175
-	javaCommand := javaCommand+' '+arguments;
176
-	
177
-	if hasWow64 then begin
178
-		// Look for 64Bit Java.
179
-		DisableRedirection(nil);
180
-		result := ExecAndWait(javaCommand);
181
-		EnableRedirection(nil);
182
-		// If it didn't work, try 32 bit.
183
-		// Ideally we should only perform this check if the failure was caused
184
-		// by the file not being found, which I think is error codes 2 and/or 3.
185
-//		if ((result = 2) or (result = 3)) then begin
186
-		if (result <> 0) then begin
187
-			result := ExecAndWait(javaCommand);
188
-		end;
189
-	end
190
-	else begin
191
-		// 32Bit Windows just uses 32bit
192
-		result := ExecAndWait(javaCommand);
193
-	end;
194
-end;
195
-
196
-{ ----------------------------------------------------------------------------
197
-  ---------------------------------------------------------------------------- }
198
-end.
199
-

Notiek ielāde…
Atcelt
Saglabāt