DmBel 1 year ago
parent
commit
e92fd4434f
4 changed files with 120 additions and 123 deletions
  1. 15 16
      blcksock.pas
  2. 4 0
      smtpsend.pas
  3. 87 87
      synacode.pas
  4. 14 20
      synautil.pas

+ 15 - 16
blcksock.pas

@@ -323,9 +323,9 @@ type
     FNonBlockMode: Boolean;
     FNonBlockMode: Boolean;
     FMaxLineLength: Integer;
     FMaxLineLength: Integer;
     FMaxSendBandwidth: Integer;
     FMaxSendBandwidth: Integer;
-    FNextSend: UInt32;
+    FNextSend: FixedUInt;
     FMaxRecvBandwidth: Integer;
     FMaxRecvBandwidth: Integer;
-    FNextRecv: UInt32;
+    FNextRecv: FixedUInt;
     FConvertLineEnd: Boolean;
     FConvertLineEnd: Boolean;
     FLastCR: Boolean;
     FLastCR: Boolean;
     FLastLF: Boolean;
     FLastLF: Boolean;
@@ -377,7 +377,7 @@ type
     procedure DoMonitor(Writing: Boolean; const Buffer: TMemory; Len: Integer);
     procedure DoMonitor(Writing: Boolean; const Buffer: TMemory; Len: Integer);
     procedure DoCreateSocket;
     procedure DoCreateSocket;
     procedure DoHeartbeat;
     procedure DoHeartbeat;
-    procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: UInt32);
+    procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
     procedure SetBandwidth(Value: Integer);
     procedure SetBandwidth(Value: Integer);
     function TestStopFlag: Boolean;
     function TestStopFlag: Boolean;
     procedure InternalSendStream(const Stream: TStream; WithSize, Indy: boolean); virtual;
     procedure InternalSendStream(const Stream: TStream; WithSize, Indy: boolean); virtual;
@@ -1509,9 +1509,9 @@ type
     TTL: Byte;
     TTL: Byte;
     Protocol: Byte;
     Protocol: Byte;
     CheckSum: Word;
     CheckSum: Word;
-    SourceIp: UInt32;
-    DestIp: UInt32;
-    Options: UInt32;
+    SourceIp: FixedUInt;
+    DestIp: FixedUInt;
+    Options: FixedUInt;
   end;
   end;
 
 
   {:@abstract(Parent class of application protocol implementations.)
   {:@abstract(Parent class of application protocol implementations.)
@@ -1858,8 +1858,7 @@ procedure TBlockSocket.DelayedOption(const Value: TSynaOption);
 begin
 begin
   if FSocket = INVALID_SOCKET then
   if FSocket = INVALID_SOCKET then
   begin
   begin
-    SetLength(FDelayedOptions, Length(FDelayedOptions) + 1);
-    FDelayedOptions[High(FDelayedOptions)] := Value;
+    FDelayedOptions := FDelayedOptions + [Value];
   end
   end
   else
   else
     SetDelayedOption(Value);
     SetDelayedOption(Value);
@@ -2113,10 +2112,10 @@ begin
   MaxRecvBandwidth := Value;
   MaxRecvBandwidth := Value;
 end;
 end;
 
 
-procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: UInt32);
+procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
 var
 var
-  x: UInt32;
-  y: UInt32;
+  x: FixedUInt;
+  y: FixedUInt;
   n: integer;
   n: integer;
 begin
 begin
   if FStopFlag then
   if FStopFlag then
@@ -2356,7 +2355,7 @@ function TBlockSocket.RecvBufferEx(Buffer: TMemory; Len: Integer;
 var
 var
   s: TSynaBytes;
   s: TSynaBytes;
   rl, l: integer;
   rl, l: integer;
-  ti: UInt32;
+  ti: FixedUInt;
 {$IFDEF CIL}
 {$IFDEF CIL}
   n: integer;
   n: integer;
   b: TMemory;
   b: TMemory;
@@ -2444,7 +2443,7 @@ begin
   begin
   begin
     {$IFDEF MSWINDOWS}
     {$IFDEF MSWINDOWS}
     //not drain CPU on large downloads...
     //not drain CPU on large downloads...
-    Sleep(0);
+    Sleep(10{0});
     {$ENDIF}
     {$ENDIF}
     x := WaitingData;
     x := WaitingData;
     if x > 0 then
     if x > 0 then
@@ -2529,7 +2528,7 @@ var
   CorCRLF: Boolean;
   CorCRLF: Boolean;
   t: string;
   t: string;
   tl: integer;
   tl: integer;
-  ti: UInt32;
+  ti: FixedUInt;
 begin
 begin
   ResetLastError;
   ResetLastError;
   Result := '';
   Result := '';
@@ -3507,7 +3506,7 @@ begin
           ;
           ;
         2:
         2:
           begin
           begin
-            buf := #1 + Char(Length(FSocksUsername)) + FSocksUsername +
+            Buf := #1 + Char(Length(FSocksUsername)) + FSocksUsername +
               Char(Length(FSocksPassword)) + FSocksPassword;
               Char(Length(FSocksPassword)) + FSocksPassword;
             SendString(Buf);
             SendString(Buf);
             Buf := RecvBufferStr(2, FSocksTimeout);
             Buf := RecvBufferStr(2, FSocksTimeout);
@@ -3531,7 +3530,7 @@ end;
 function TSocksBlockSocket.SocksRequest(Cmd: Byte;
 function TSocksBlockSocket.SocksRequest(Cmd: Byte;
   const IP, Port: string): Boolean;
   const IP, Port: string): Boolean;
 var
 var
-  buf: string;
+  Buf: string;
 begin
 begin
   FBypassFlag := True;
   FBypassFlag := True;
   try
   try

+ 4 - 0
smtpsend.pas

@@ -923,6 +923,7 @@ begin
   Result := False;
   Result := False;
   SMTP := TSMTPSend.Create;
   SMTP := TSMTPSend.Create;
   try
   try
+  try
 // if you need SOCKS5 support, uncomment next lines:
 // if you need SOCKS5 support, uncomment next lines:
     // SMTP.Sock.SocksIP := '127.0.0.1';
     // SMTP.Sock.SocksIP := '127.0.0.1';
     // SMTP.Sock.SocksPort := '1080';
     // SMTP.Sock.SocksPort := '1080';
@@ -956,6 +957,9 @@ begin
   finally
   finally
     SMTP.Free;
     SMTP.Free;
   end;
   end;
+  except
+   Exit(False);
+  end;
 end;
 end;
 
 
 function SendToEx(const MailFrom, MailTo, Subject, SMTPHost: string;
 function SendToEx(const MailFrom, MailTo, Subject, SMTPHost: string;

+ 87 - 87
synacode.pas

@@ -130,110 +130,110 @@ const
 
 
 {:Decodes triplet encoding with a given character delimiter. It is used for
 {:Decodes triplet encoding with a given character delimiter. It is used for
  decoding quoted-printable or URL encoding.}
  decoding quoted-printable or URL encoding.}
-function DecodeTriplet(const Value: String; Delimiter: Char): String;
+function DecodeTriplet(const Value: AnsiString; Delimiter: AnsiChar): AnsiString;
 
 
 {:Decodes a string from quoted printable form. (also decodes triplet sequences
 {:Decodes a string from quoted printable form. (also decodes triplet sequences
  like '=7F')}
  like '=7F')}
-function DecodeQuotedPrintable(const Value: String): String;
+function DecodeQuotedPrintable(const Value: AnsiString): AnsiString;
 
 
 {:Decodes a string of URL encoding. (also decodes triplet sequences like '%7F')}
 {:Decodes a string of URL encoding. (also decodes triplet sequences like '%7F')}
-function DecodeURL(const Value: String): String;
+function DecodeURL(const Value: AnsiString): AnsiString;
 
 
 {:Performs triplet encoding with a given character delimiter. Used for encoding
 {:Performs triplet encoding with a given character delimiter. Used for encoding
  quoted-printable or URL encoding.}
  quoted-printable or URL encoding.}
-function EncodeTriplet(const Value: String; Delimiter: Char;
-  Specials: TSpecials): String;
+function EncodeTriplet(const Value: AnsiString; Delimiter: AnsiChar;
+  Specials: TSpecials): AnsiString;
 
 
 {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar)
 {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar)
  are encoded.}
  are encoded.}
-function EncodeQuotedPrintable(const Value: String): String;
+function EncodeQuotedPrintable(const Value: AnsiString): AnsiString;
 
 
 {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar) and
 {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar) and
  @link(SpecialChar) are encoded.}
  @link(SpecialChar) are encoded.}
-function EncodeSafeQuotedPrintable(const Value: String): String;
+function EncodeSafeQuotedPrintable(const Value: AnsiString): AnsiString;
 
 
 {:Encodes a string to URL format. Used for encoding data from a form field in
 {:Encodes a string to URL format. Used for encoding data from a form field in
  HTTP, etc. (Encodes all critical characters including characters used as URL
  HTTP, etc. (Encodes all critical characters including characters used as URL
  delimiters ('/',':', etc.)}
  delimiters ('/',':', etc.)}
-function EncodeURLElement(const Value: String): String;
+function EncodeURLElement(const Value: AnsiString): AnsiString;
 
 
 {:Encodes a string to URL format. Used to encode critical characters in all
 {:Encodes a string to URL format. Used to encode critical characters in all
  URLs.}
  URLs.}
-function EncodeURL(const Value: String): String;
+function EncodeURL(const Value: AnsiString): AnsiString;
 
 
 {:Decode 4to3 encoding with given table. If some element is not found in table,
 {:Decode 4to3 encoding with given table. If some element is not found in table,
  first item from table is used. This is good for buggy coded items by Microsoft
  first item from table is used. This is good for buggy coded items by Microsoft
  Outlook. This software sometimes using wrong table for UUcode, where is used
  Outlook. This software sometimes using wrong table for UUcode, where is used
  ' ' instead '`'.}
  ' ' instead '`'.}
-function Decode4to3(const Value, Table: String): String;
+function Decode4to3(const Value, Table: AnsiString): AnsiString;
 
 
 {:Decode 4to3 encoding with given REVERSE table. Using this function with
 {:Decode 4to3 encoding with given REVERSE table. Using this function with
 reverse table is much faster then @link(Decode4to3). This function is used
 reverse table is much faster then @link(Decode4to3). This function is used
 internally for Base64, UU or XX decoding.}
 internally for Base64, UU or XX decoding.}
-function Decode4to3Ex(const Value, Table: String): String;
+function Decode4to3Ex(const Value, Table: AnsiString): AnsiString;
 
 
 {:Encode by system 3to4 (used by Base64, UU coding, etc) by given table.}
 {:Encode by system 3to4 (used by Base64, UU coding, etc) by given table.}
-function Encode3to4(const Value, Table: String): String;
+function Encode3to4(const Value, Table: AnsiString): AnsiString;
 
 
 {:Decode string from base64 format.}
 {:Decode string from base64 format.}
-function DecodeBase64(const Value: String): String;
+function DecodeBase64(const Value: AnsiString): AnsiString;
 
 
 {:Encodes a string to base64 format.}
 {:Encodes a string to base64 format.}
-function EncodeBase64(const Value: String): String;
+function EncodeBase64(const Value: AnsiString): AnsiString;
 
 
 {:Decode string from modified base64 format. (used in IMAP, for example.)}
 {:Decode string from modified base64 format. (used in IMAP, for example.)}
-function DecodeBase64mod(const Value: String): String;
+function DecodeBase64mod(const Value: AnsiString): AnsiString;
 
 
 {:Encodes a string to  modified base64 format. (used in IMAP, for example.)}
 {:Encodes a string to  modified base64 format. (used in IMAP, for example.)}
-function EncodeBase64mod(const Value: String): String;
+function EncodeBase64mod(const Value: AnsiString): AnsiString;
 
 
 {:Decodes a string from UUcode format.}
 {:Decodes a string from UUcode format.}
-function DecodeUU(const Value: String): String;
+function DecodeUU(const Value: AnsiString): AnsiString;
 
 
 {:encode UUcode. it encode only datas, you must also add header and footer for
 {:encode UUcode. it encode only datas, you must also add header and footer for
  proper encode.}
  proper encode.}
-function EncodeUU(const Value: String): String;
+function EncodeUU(const Value: AnsiString): AnsiString;
 
 
 {:Decodes a string from XXcode format.}
 {:Decodes a string from XXcode format.}
-function DecodeXX(const Value: String): String;
+function DecodeXX(const Value: AnsiString): AnsiString;
 
 
 {:decode line with Yenc code. This code is sometimes used in newsgroups.}
 {:decode line with Yenc code. This code is sometimes used in newsgroups.}
-function DecodeYEnc(const Value: String): String;
+function DecodeYEnc(const Value: AnsiString): AnsiString;
 
 
 {:Returns a new CRC32 value after adding a new byte of data.}
 {:Returns a new CRC32 value after adding a new byte of data.}
 function UpdateCrc32(Value: Byte; Crc32: Cardinal): Cardinal;
 function UpdateCrc32(Value: Byte; Crc32: Cardinal): Cardinal;
 
 
 {:return CRC32 from a value string.}
 {:return CRC32 from a value string.}
-function Crc32(const Value: String): Cardinal;
+function Crc32(const Value: AnsiString): Cardinal;
 
 
 {:Returns a new CRC16 value after adding a new byte of data.}
 {:Returns a new CRC16 value after adding a new byte of data.}
 function UpdateCrc16(Value: Byte; Crc16: Word): Word;
 function UpdateCrc16(Value: Byte; Crc16: Word): Word;
 
 
 {:return CRC16 from a value string.}
 {:return CRC16 from a value string.}
-function Crc16(const Value: String): Word;
+function Crc16(const Value: AnsiString): Word;
 
 
 {:Returns a binary string with a RSA-MD5 hashing of "Value" string.}
 {:Returns a binary string with a RSA-MD5 hashing of "Value" string.}
-function MD5(const Value: String): String;
+function MD5(const Value: AnsiString): AnsiString;
 
 
 {:Returns a binary string with HMAC-MD5 hash.}
 {:Returns a binary string with HMAC-MD5 hash.}
-function HMAC_MD5(const Text: String; Key: String): String;
+function HMAC_MD5(Text, Key: AnsiString): AnsiString;
 
 
 {:Returns a binary string with a RSA-MD5 hashing of string what is constructed
 {:Returns a binary string with a RSA-MD5 hashing of string what is constructed
  by repeating "value" until length is "Len".}
  by repeating "value" until length is "Len".}
-function MD5LongHash(const Value: String; Len: integer): String;
+function MD5LongHash(const Value: AnsiString; Len: integer): AnsiString;
 
 
 {:Returns a binary string with a SHA-1 hashing of "Value" string.}
 {:Returns a binary string with a SHA-1 hashing of "Value" string.}
-function SHA1(const Value: String): String;
+function SHA1(const Value: AnsiString): AnsiString;
 
 
 {:Returns a binary string with HMAC-SHA1 hash.}
 {:Returns a binary string with HMAC-SHA1 hash.}
-function HMAC_SHA1(const Text: String; Key: String): String;
+function HMAC_SHA1(Text, Key: AnsiString): AnsiString;
 
 
 {:Returns a binary string with a SHA-1 hashing of string what is constructed
 {:Returns a binary string with a SHA-1 hashing of string what is constructed
  by repeating "value" until length is "Len".}
  by repeating "value" until length is "Len".}
-function SHA1LongHash(const Value: String; Len: integer): String;
+function SHA1LongHash(const Value: AnsiString; Len: integer): AnsiString;
 
 
 {:Returns a binary string with a RSA-MD4 hashing of "Value" string.}
 {:Returns a binary string with a RSA-MD4 hashing of "Value" string.}
-function MD4(const Value: String): String;
+function MD4(const Value: AnsiString): AnsiString;
 
 
 implementation
 implementation
 
 
@@ -400,10 +400,10 @@ type
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeTriplet(const Value: String; Delimiter: Char): String;
+function DecodeTriplet(const Value: AnsiString; Delimiter: AnsiChar): AnsiString;
 var
 var
   x, l, lv: Integer;
   x, l, lv: Integer;
-  c: Char;
+  c: AnsiChar;
   b: Byte;
   b: Byte;
   bad: Boolean;
   bad: Boolean;
 begin
 begin
@@ -460,7 +460,7 @@ begin
             else
             else
             begin
             begin
               Inc(x, 2);
               Inc(x, 2);
-              Result[l] := Char(b);
+              Result[l] := AnsiChar(b);
               Inc(l);
               Inc(l);
             end;
             end;
           end;
           end;
@@ -475,26 +475,26 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeQuotedPrintable(const Value: String): String;
+function DecodeQuotedPrintable(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := DecodeTriplet(Value, '=');
   Result := DecodeTriplet(Value, '=');
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeURL(const Value: String): String;
+function DecodeURL(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := DecodeTriplet(Value, '%');
   Result := DecodeTriplet(Value, '%');
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeTriplet(const Value: String; Delimiter: Char;
-  Specials: TSpecials): String;
+function EncodeTriplet(const Value: AnsiString; Delimiter: AnsiChar;
+  Specials: TSpecials): AnsiString;
 var
 var
   n, l: Integer;
   n, l: Integer;
-  s: String;
-  c: Char;
+  s: AnsiString;
+  c: AnsiChar;
 begin
 begin
   SetLength(Result, Length(Value) * 3);
   SetLength(Result, Length(Value) * 3);
   l := 1;
   l := 1;
@@ -523,35 +523,35 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeQuotedPrintable(const Value: String): String;
+function EncodeQuotedPrintable(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := EncodeTriplet(Value, '=',  ['='] + NonAsciiChar);
   Result := EncodeTriplet(Value, '=',  ['='] + NonAsciiChar);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeSafeQuotedPrintable(const Value: String): String;
+function EncodeSafeQuotedPrintable(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := EncodeTriplet(Value, '=', SpecialChar + NonAsciiChar);
   Result := EncodeTriplet(Value, '=', SpecialChar + NonAsciiChar);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeURLElement(const Value: String): String;
+function EncodeURLElement(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := EncodeTriplet(Value, '%', URLSpecialChar + URLFullSpecialChar);
   Result := EncodeTriplet(Value, '%', URLSpecialChar + URLFullSpecialChar);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeURL(const Value: String): String;
+function EncodeURL(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := EncodeTriplet(Value, '%', URLSpecialChar);
   Result := EncodeTriplet(Value, '%', URLSpecialChar);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function Decode4to3(const Value, Table: String): String;
+function Decode4to3(const Value, Table: AnsiString): AnsiString;
 var
 var
   x, y, n, l: Integer;
   x, y, n, l: Integer;
   d: array[0..3] of Byte;
   d: array[0..3] of Byte;
@@ -574,15 +574,15 @@ begin
       end;
       end;
       Inc(x);
       Inc(x);
     end;
     end;
-    Result[l] := Char((D[0] and $3F) shl 2 + (D[1] and $30) shr 4);
+    Result[l] := AnsiChar((D[0] and $3F) shl 2 + (D[1] and $30) shr 4);
     Inc(l);
     Inc(l);
     if d[2] <> 64 then
     if d[2] <> 64 then
     begin
     begin
-      Result[l] := Char((D[1] and $0F) shl 4 + (D[2] and $3C) shr 2);
+      Result[l] := AnsiChar((D[1] and $0F) shl 4 + (D[2] and $3C) shr 2);
       Inc(l);
       Inc(l);
       if d[3] <> 64 then
       if d[3] <> 64 then
       begin
       begin
-        Result[l] := Char((D[2] and $03) shl 6 + (D[3] and $3F));
+        Result[l] := AnsiChar((D[2] and $03) shl 6 + (D[3] and $3F));
         Inc(l);
         Inc(l);
       end;
       end;
     end;
     end;
@@ -592,7 +592,7 @@ begin
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
-function Decode4to3Ex(const Value, Table: String): String;
+function Decode4to3Ex(const Value, Table: AnsiString): AnsiString;
 var
 var
   x, y, lv: Integer;
   x, y, lv: Integer;
   d: integer;
   d: integer;
@@ -620,11 +620,11 @@ begin
     dec(dl);
     dec(dl);
     if dl <> 0 then
     if dl <> 0 then
       continue;
       continue;
-    Result[p] := Char((d shr 16) and $ff);
+    Result[p] := AnsiChar((d shr 16) and $ff);
     inc(p);
     inc(p);
-    Result[p] := Char((d shr 8) and $ff);
+    Result[p] := AnsiChar((d shr 8) and $ff);
     inc(p);
     inc(p);
-    Result[p] := Char(d and $ff);
+    Result[p] := AnsiChar(d and $ff);
     inc(p);
     inc(p);
     d := 0;
     d := 0;
     dl := 4;
     dl := 4;
@@ -633,15 +633,15 @@ begin
     1:
     1:
       begin
       begin
         d := d shr 2;
         d := d shr 2;
-        Result[p] := Char((d shr 8) and $ff);
+        Result[p] := AnsiChar((d shr 8) and $ff);
         inc(p);
         inc(p);
-        Result[p] := Char(d and $ff);
+        Result[p] := AnsiChar(d and $ff);
         inc(p);
         inc(p);
       end;
       end;
     2:
     2:
       begin
       begin
         d := d shr 4;
         d := d shr 4;
-        Result[p] := Char(d and $ff);
+        Result[p] := AnsiChar(d and $ff);
         inc(p);
         inc(p);
       end;
       end;
   end;
   end;
@@ -650,7 +650,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function Encode3to4(const Value, Table: String): String;
+function Encode3to4(const Value, Table: AnsiString): AnsiString;
 var
 var
   c: Byte;
   c: Byte;
   n, l: Integer;
   n, l: Integer;
@@ -703,38 +703,38 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeBase64(const Value: String): String;
+function DecodeBase64(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := Decode4to3Ex(Value, ReTableBase64);
   Result := Decode4to3Ex(Value, ReTableBase64);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeBase64(const Value: String): String;
+function EncodeBase64(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := Encode3to4(Value, TableBase64);
   Result := Encode3to4(Value, TableBase64);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeBase64mod(const Value: String): String;
+function DecodeBase64mod(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := Decode4to3(Value, TableBase64mod);
   Result := Decode4to3(Value, TableBase64mod);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeBase64mod(const Value: String): String;
+function EncodeBase64mod(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := Encode3to4(Value, TableBase64mod);
   Result := Encode3to4(Value, TableBase64mod);
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeUU(const Value: String): String;
+function DecodeUU(const Value: AnsiString): AnsiString;
 var
 var
-  s: String;
-  uut: String;
+  s: AnsiString;
+  uut: AnsiString;
   x: Integer;
   x: Integer;
 begin
 begin
   Result := '';
   Result := '';
@@ -764,7 +764,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function EncodeUU(const Value: String): String;
+function EncodeUU(const Value: AnsiString): AnsiString;
 begin
 begin
   Result := '';
   Result := '';
   if Length(Value) < Length(TableUU) then
   if Length(Value) < Length(TableUU) then
@@ -773,9 +773,9 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeXX(const Value: String): String;
+function DecodeXX(const Value: AnsiString): AnsiString;
 var
 var
-  s: String;
+  s: AnsiString;
   x: Integer;
   x: Integer;
 begin
 begin
   Result := '';
   Result := '';
@@ -803,7 +803,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function DecodeYEnc(const Value: String): String;
+function DecodeYEnc(const Value: AnsiString): AnsiString;
 var
 var
   C : Byte;
   C : Byte;
   i: integer;
   i: integer;
@@ -821,7 +821,7 @@ begin
       Dec(c, 64);
       Dec(c, 64);
     end;
     end;
     Dec(C, 42);
     Dec(C, 42);
-    Result := Result + Char(C);
+    Result := Result + AnsiChar(C);
   end;
   end;
 end;
 end;
 
 
@@ -835,7 +835,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function Crc32(const Value: String): Cardinal;
+function Crc32(const Value: AnsiString): Cardinal;
 var
 var
   n: Integer;
   n: Integer;
 begin
 begin
@@ -855,7 +855,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function Crc16(const Value: String): Word;
+function Crc16(const Value: AnsiString): Word;
 var
 var
   n: Integer;
   n: Integer;
 begin
 begin
@@ -994,7 +994,7 @@ begin
 end;
 end;
 
 
 //fixed by James McAdams
 //fixed by James McAdams
-procedure MDUpdate(var MDContext: TMDCtx; const Data: String; transform: TMDTransform);
+procedure MDUpdate(var MDContext: TMDCtx; const Data: AnsiString; transform: TMDTransform);
 var
 var
   Index, partLen, InputLen, I: integer;
   Index, partLen, InputLen, I: integer;
 {$IFDEF SYNACODE_NATIVE}
 {$IFDEF SYNACODE_NATIVE}
@@ -1050,7 +1050,7 @@ begin
   end
   end
 end;
 end;
 
 
-function MDFinal(var MDContext: TMDCtx; transform: TMDTransform): String;
+function MDFinal(var MDContext: TMDCtx; transform: TMDTransform): AnsiString;
 var
 var
   Cnt: Word;
   Cnt: Word;
   P: Byte;
   P: Byte;
@@ -1094,14 +1094,14 @@ begin
 //    Move(State, Digest, 16);
 //    Move(State, Digest, 16);
     Result := '';
     Result := '';
     for i := 0 to 15 do
     for i := 0 to 15 do
-      Result := Result + Char(digest[i]);
+      Result := Result + AnsiChar(digest[i]);
   end;
   end;
 //  FillChar(MD5Context, SizeOf(TMD5Ctx), #0)
 //  FillChar(MD5Context, SizeOf(TMD5Ctx), #0)
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function MD5(const Value: String): String;
+function MD5(const Value: AnsiString): AnsiString;
 var
 var
   MDContext: TMDCtx;
   MDContext: TMDCtx;
 begin
 begin
@@ -1112,9 +1112,9 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function HMAC_MD5(const Text: String; Key: String): String;
+function HMAC_MD5(Text, Key: AnsiString): AnsiString;
 var
 var
-  ipad, opad, s: String;
+  ipad, opad, s: AnsiString;
   n: Integer;
   n: Integer;
   MDContext: TMDCtx;
   MDContext: TMDCtx;
 begin
 begin
@@ -1124,8 +1124,8 @@ begin
   opad := StringOfChar(HMAC_MD5_OPAD_CHAR, 64);
   opad := StringOfChar(HMAC_MD5_OPAD_CHAR, 64);
   for n := 1 to Length(Key) do
   for n := 1 to Length(Key) do
   begin
   begin
-    ipad[n] := Char(Byte(ipad[n]) xor Byte(Key[n]));
-    opad[n] := Char(Byte(opad[n]) xor Byte(Key[n]));
+    ipad[n] := AnsiChar(Byte(ipad[n]) xor Byte(Key[n]));
+    opad[n] := AnsiChar(Byte(opad[n]) xor Byte(Key[n]));
   end;
   end;
   MDInit(MDContext);
   MDInit(MDContext);
   MDUpdate(MDContext, ipad, @MD5Transform);
   MDUpdate(MDContext, ipad, @MD5Transform);
@@ -1139,7 +1139,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function MD5LongHash(const Value: String; Len: integer): String;
+function MD5LongHash(const Value: AnsiString; Len: integer): AnsiString;
 var
 var
   cnt, rest: integer;
   cnt, rest: integer;
   l: integer;
   l: integer;
@@ -1270,7 +1270,7 @@ begin
 end;
 end;
 
 
 //******************************************************************************
 //******************************************************************************
-procedure SHA1Update(var Context: TSHA1Ctx; const Data: String);
+procedure SHA1Update(var Context: TSHA1Ctx; const Data: AnsiString);
 var
 var
   Len: integer;
   Len: integer;
   n: integer;
   n: integer;
@@ -1297,7 +1297,7 @@ begin
 end;
 end;
 
 
 //******************************************************************************
 //******************************************************************************
-function SHA1Final(var Context: TSHA1Ctx): String;
+function SHA1Final(var Context: TSHA1Ctx): AnsiString;
 type
 type
   Pinteger = ^integer;
   Pinteger = ^integer;
 var
 var
@@ -1326,10 +1326,10 @@ begin
   ArrLongToByte(Context.Hash, Context.HashByte);
   ArrLongToByte(Context.Hash, Context.HashByte);
   Result := '';
   Result := '';
   for i := 0 to 19 do
   for i := 0 to 19 do
-    Result := Result + Char(Context.HashByte[i]);
+    Result := Result + AnsiChar(Context.HashByte[i]);
 end;
 end;
 
 
-function SHA1(const Value: String): String;
+function SHA1(const Value: AnsiString): AnsiString;
 var
 var
   SHA1Context: TSHA1Ctx;
   SHA1Context: TSHA1Ctx;
 begin
 begin
@@ -1340,9 +1340,9 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function HMAC_SHA1(const Text: String; Key: String): String;
+function HMAC_SHA1(Text, Key: AnsiString): AnsiString;
 var
 var
-  ipad, opad, s: String;
+  ipad, opad, s: AnsiString;
   n: Integer;
   n: Integer;
   SHA1Context: TSHA1Ctx;
   SHA1Context: TSHA1Ctx;
 begin
 begin
@@ -1352,8 +1352,8 @@ begin
   opad := StringOfChar(HMAC_SHA1_OPAD_CHAR, 64);
   opad := StringOfChar(HMAC_SHA1_OPAD_CHAR, 64);
   for n := 1 to Length(Key) do
   for n := 1 to Length(Key) do
   begin
   begin
-    ipad[n] := Char(Byte(ipad[n]) xor Byte(Key[n]));
-    opad[n] := Char(Byte(opad[n]) xor Byte(Key[n]));
+    ipad[n] := AnsiChar(Byte(ipad[n]) xor Byte(Key[n]));
+    opad[n] := AnsiChar(Byte(opad[n]) xor Byte(Key[n]));
   end;
   end;
   SHA1Init(SHA1Context);
   SHA1Init(SHA1Context);
   SHA1Update(SHA1Context, ipad);
   SHA1Update(SHA1Context, ipad);
@@ -1367,7 +1367,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function SHA1LongHash(const Value: String; Len: integer): String;
+function SHA1LongHash(const Value: AnsiString; Len: integer): AnsiString;
 var
 var
   cnt, rest: integer;
   cnt, rest: integer;
   l: integer;
   l: integer;
@@ -1459,7 +1459,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function MD4(const Value: String): String;
+function MD4(const Value: AnsiString): AnsiString;
 var
 var
   MDContext: TMDCtx;
   MDContext: TMDCtx;
 begin
 begin

+ 14 - 20
synautil.pas

@@ -76,7 +76,7 @@ uses
 {$ELSE MSWINDOWS}
 {$ELSE MSWINDOWS}
   {$IFDEF ULTIBO}
   {$IFDEF ULTIBO}
     Ultibo,
     Ultibo,
-  {$ELSE} 
+  {$ELSE}
     {$IFDEF FPC}
     {$IFDEF FPC}
       {$IFDEF OS2}
       {$IFDEF OS2}
       Dos, TZUtil,
       Dos, TZUtil,
@@ -96,13 +96,12 @@ uses
 {$IFDEF CIL}
 {$IFDEF CIL}
   System.IO,
   System.IO,
 {$ENDIF}
 {$ENDIF}
-  SysUtils, Classes, SynaFpc, synabyte;
+  Math, SysUtils, Classes, SynaFpc, synabyte;
 
 
 {$IFDEF VER100}
 {$IFDEF VER100}
 type
 type
   int64 = integer;
   int64 = integer;
 {$ENDIF}
 {$ENDIF}
-
 {$IFDEF POSIX}
 {$IFDEF POSIX}
 type
 type
   TTimeVal = Posix.SysTime.timeval;
   TTimeVal = Posix.SysTime.timeval;
@@ -182,11 +181,11 @@ function SetUTTime(Newdt: TDateTime): Boolean;
 
 
 {:Return current value of system timer with precizion 1 millisecond. Good for
 {:Return current value of system timer with precizion 1 millisecond. Good for
  measure time difference.}
  measure time difference.}
-function GetTick: UInt32;
+function GetTick: FixedUInt;
 
 
 {:Return difference between two timestamps. It working fine only for differences
 {:Return difference between two timestamps. It working fine only for differences
  smaller then maxint. (difference must be smaller then 24 days.)}
  smaller then maxint. (difference must be smaller then 24 days.)}
-function TickDelta(TickOld, TickNew: UInt32): UInt32;
+function TickDelta(TickOld, TickNew: FixedUInt): FixedUInt;
 
 
 {:Return two characters, which ordinal values represents the value in byte
 {:Return two characters, which ordinal values represents the value in byte
  format. (High-endian)}
  format. (High-endian)}
@@ -340,7 +339,7 @@ procedure ListToHeaders(const Value: TStrings);
 function SwapBytes(Value: integer): integer;
 function SwapBytes(Value: integer): integer;
 
 
 {:read string with requested length form stream.}
 {:read string with requested length form stream.}
-function ReadStrFromStream(const Stream: TStream; len: integer): string;
+function ReadStrFromStream(const Stream: TStream; len: integer): ansistring;
 
 
 {:write string to stream.}
 {:write string to stream.}
 procedure WriteStrToStream(const Stream: TStream; const Value: string); {$IFDEF UNICODE} overload;{$ENDIF}
 procedure WriteStrToStream(const Stream: TStream; const Value: string); {$IFDEF UNICODE} overload;{$ENDIF}
@@ -911,7 +910,7 @@ end;
 {==============================================================================}
 {==============================================================================}
 
 
 {$IFNDEF MSWINDOWS}
 {$IFNDEF MSWINDOWS}
-function GetTick: UInt32;
+function GetTick: FixedUInt;
 var
 var
   Stamp: TTimeStamp;
   Stamp: TTimeStamp;
 begin
 begin
@@ -919,7 +918,7 @@ begin
   Result := Stamp.Time;
   Result := Stamp.Time;
 end;
 end;
 {$ELSE}
 {$ELSE}
-function GetTick: UInt32;
+function GetTick: FixedUInt;
 var
 var
   tick, freq: TLargeInteger;
   tick, freq: TLargeInteger;
 {$IFDEF VER100}
 {$IFDEF VER100}
@@ -933,7 +932,7 @@ begin
     x.QuadPart := (tick.QuadPart / freq.QuadPart) * 1000;
     x.QuadPart := (tick.QuadPart / freq.QuadPart) * 1000;
     Result := x.LowPart;
     Result := x.LowPart;
 {$ELSE}
 {$ELSE}
-    Result := Trunc((tick / freq) * 1000) and High(UInt32)
+    Result := Trunc((tick / freq) * 1000) and High(FixedUInt)
 {$ENDIF}
 {$ENDIF}
   end
   end
   else
   else
@@ -943,7 +942,7 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function TickDelta(TickOld, TickNew: UInt32): UInt32;
+function TickDelta(TickOld, TickNew: FixedUInt): FixedUInt;
 begin
 begin
 //if DWord is signed type (older Deplhi),
 //if DWord is signed type (older Deplhi),
 // then it not work properly on differencies larger then maxint!
 // then it not work properly on differencies larger then maxint!
@@ -952,8 +951,8 @@ begin
   begin
   begin
     if TickNew < TickOld then
     if TickNew < TickOld then
     begin
     begin
-      TickNew := TickNew + UInt32(MaxInt) + 1;
-      TickOld := TickOld + UInt32(MaxInt) + 1;
+      TickNew := TickNew + FixedUInt(MaxInt) + 1;
+      TickOld := TickOld + FixedUInt(MaxInt) + 1;
     end;
     end;
     Result := TickNew - TickOld;
     Result := TickNew - TickOld;
     if TickNew < TickOld then
     if TickNew < TickOld then
@@ -1812,15 +1811,10 @@ end;
 
 
 {==============================================================================}
 {==============================================================================}
 
 
-function ReadStrFromStream(const Stream: TStream; len: integer): string;
-var
-  x: integer;
-  Buf: TBytes;
+function ReadStrFromStream(const Stream: TStream; len: integer): ansistring;
 begin
 begin
-  Setlength(Buf, Len);
-  x := Stream.Read(Buf, Len);
-  Setlength(Buf, x);
-  Result := StringOf(Buf);
+  SetLength(Result, Min(len, Stream.Size));
+  Stream.ReadBuffer(Result[1], Length(Result));
 end;
 end;
 
 
 {==============================================================================}
 {==============================================================================}