2008-04-23 23:26:50 +03:00
|
|
|
{==============================================================================|
|
2008-04-24 10:22:17 +03:00
|
|
|
| Project : Delphree - Synapse | 003.003.000 |
|
2008-04-23 23:26:50 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| Content: support procedures and functions |
|
|
|
|
|==============================================================================|
|
2008-04-24 10:22:17 +03:00
|
|
|
| Copyright (c)1999-2003, Lukas Gebauer |
|
2008-04-24 10:20:39 +03:00
|
|
|
| All rights reserved. |
|
2008-04-23 23:26:50 +03:00
|
|
|
| |
|
2008-04-24 10:20:39 +03:00
|
|
|
| Redistribution and use in source and binary forms, with or without |
|
|
|
|
| modification, are permitted provided that the following conditions are met: |
|
|
|
|
| |
|
|
|
|
| Redistributions of source code must retain the above copyright notice, this |
|
|
|
|
| list of conditions and the following disclaimer. |
|
|
|
|
| |
|
|
|
|
| Redistributions in binary form must reproduce the above copyright notice, |
|
|
|
|
| this list of conditions and the following disclaimer in the documentation |
|
|
|
|
| and/or other materials provided with the distribution. |
|
|
|
|
| |
|
|
|
|
| Neither the name of Lukas Gebauer nor the names of its contributors may |
|
|
|
|
| be used to endorse or promote products derived from this software without |
|
|
|
|
| specific prior written permission. |
|
|
|
|
| |
|
|
|
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
|
|
|
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
|
|
|
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
|
|
| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
|
|
|
|
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
|
|
|
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
|
|
|
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
|
|
|
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
|
|
|
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
|
|
|
| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
|
|
|
|
| DAMAGE. |
|
2008-04-23 23:26:50 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
|
2008-04-24 10:22:17 +03:00
|
|
|
| Portions created by Lukas Gebauer are Copyright (c) 1999-2003. |
|
2008-04-23 23:32:54 +03:00
|
|
|
| Portions created by Hernan Sanchez are Copyright (c) 2000. |
|
2008-04-23 23:26:50 +03:00
|
|
|
| All Rights Reserved. |
|
|
|
|
|==============================================================================|
|
|
|
|
| Contributor(s): |
|
2008-04-23 23:32:54 +03:00
|
|
|
| Hernan Sanchez (hernan.sanchez@iname.com) |
|
2008-04-23 23:26:50 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| History: see HISTORY.HTM from distribution package |
|
2008-04-23 23:48:39 +03:00
|
|
|
| (Found at URL: http://www.ararat.cz/synapse/) |
|
2008-04-23 23:26:50 +03:00
|
|
|
|==============================================================================}
|
|
|
|
|
2008-04-24 10:00:43 +03:00
|
|
|
{$Q-}
|
|
|
|
|
2008-04-23 23:26:50 +03:00
|
|
|
unit SynaUtil;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2008-04-24 10:05:26 +03:00
|
|
|
SysUtils, Classes,
|
2008-04-24 09:59:26 +03:00
|
|
|
{$IFDEF LINUX}
|
2008-04-24 10:05:26 +03:00
|
|
|
Libc;
|
2008-04-24 09:59:26 +03:00
|
|
|
{$ELSE}
|
2008-04-24 10:05:26 +03:00
|
|
|
Windows;
|
2008-04-24 09:59:26 +03:00
|
|
|
{$ENDIF}
|
2008-04-23 23:26:50 +03:00
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function TimeZoneBias: integer;
|
|
|
|
function TimeZone: string;
|
2008-04-24 10:05:26 +03:00
|
|
|
function Rfc822DateTime(t: TDateTime): string;
|
2008-04-24 10:09:13 +03:00
|
|
|
function CDateTime(t: TDateTime): string;
|
2008-04-24 10:12:01 +03:00
|
|
|
function SimpleDateTime(t: TDateTime): string;
|
2008-04-24 10:18:26 +03:00
|
|
|
function AnsiCDateTime(t: TDateTime): string;
|
|
|
|
function GetMonthNumber(Value: string): integer;
|
|
|
|
function GetTimeFromStr(Value: string): TDateTime;
|
|
|
|
function GetDateMDYFromStr(Value: string): TDateTime;
|
2008-04-24 10:12:01 +03:00
|
|
|
function DecodeRfcDateTime(Value: string): TDateTime;
|
|
|
|
function GetUTTime: TDateTime;
|
|
|
|
function SetUTTime(Newdt: TDateTime): Boolean;
|
|
|
|
function GetTick: Cardinal;
|
2008-04-24 10:05:26 +03:00
|
|
|
function CodeInt(Value: Word): string;
|
|
|
|
function DecodeInt(const Value: string; Index: Integer): Word;
|
|
|
|
function IsIP(const Value: string): Boolean;
|
|
|
|
function ReverseIP(Value: string): string;
|
2008-04-24 10:09:13 +03:00
|
|
|
function IPToID(Host: string): string;
|
2008-04-24 10:05:26 +03:00
|
|
|
procedure Dump(const Buffer, DumpFile: string);
|
2008-04-24 10:12:01 +03:00
|
|
|
procedure DumpEx(const Buffer, DumpFile: string);
|
2008-04-24 10:05:26 +03:00
|
|
|
function SeparateLeft(const Value, Delimiter: string): string;
|
|
|
|
function SeparateRight(const Value, Delimiter: string): string;
|
|
|
|
function GetParameter(const Value, Parameter: string): string;
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure ParseParameters(Value: string; const Parameters: TStrings);
|
|
|
|
function IndexByBegin(Value: string; const List: TStrings): integer;
|
2008-04-24 10:05:26 +03:00
|
|
|
function GetEmailAddr(const Value: string): string;
|
|
|
|
function GetEmailDesc(Value: string): string;
|
|
|
|
function StrToHex(const Value: string): string;
|
|
|
|
function IntToBin(Value: Integer; Digits: Byte): string;
|
|
|
|
function BinToInt(const Value: string): Integer;
|
|
|
|
function ParseURL(URL: string; var Prot, User, Pass, Host, Port, Path,
|
|
|
|
Para: string): string;
|
2008-04-24 10:22:17 +03:00
|
|
|
function ReplaceString(Value, Search, Replace: string): string;
|
2008-04-24 10:18:26 +03:00
|
|
|
function RPosEx(const Sub, Value: string; From: integer): Integer;
|
2008-04-24 10:07:45 +03:00
|
|
|
function RPos(const Sub, Value: String): Integer;
|
|
|
|
function Fetch(var Value: string; const Delimiter: string): string;
|
2008-04-24 10:20:39 +03:00
|
|
|
function IsBinaryString(const Value: string): Boolean;
|
|
|
|
function PosCRLF(const Value: string; var Terminator: string): integer;
|
|
|
|
Procedure StringsTrim(const value: TStrings);
|
|
|
|
function PosFrom(const SubStr, Value: String; From: integer): integer;
|
2008-04-24 10:22:17 +03:00
|
|
|
function IncPoint(const p: pointer; Value: integer): pointer;
|
2008-04-23 23:26:50 +03:00
|
|
|
|
|
|
|
implementation
|
2008-04-24 10:20:39 +03:00
|
|
|
|
2008-04-24 10:09:13 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:20:39 +03:00
|
|
|
|
2008-04-24 10:09:13 +03:00
|
|
|
const
|
|
|
|
MyDayNames: array[1..7] of string =
|
2008-04-24 10:20:39 +03:00
|
|
|
('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
|
2008-04-24 10:09:13 +03:00
|
|
|
MyMonthNames: array[1..12] of string =
|
2008-04-24 10:20:39 +03:00
|
|
|
('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
|
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
|
2008-04-24 10:09:13 +03:00
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function TimeZoneBias: integer;
|
2008-04-24 09:59:26 +03:00
|
|
|
{$IFDEF LINUX}
|
|
|
|
var
|
|
|
|
t: TTime_T;
|
2008-04-24 10:05:26 +03:00
|
|
|
UT: TUnixTime;
|
2008-04-24 09:59:26 +03:00
|
|
|
begin
|
|
|
|
__time(@T);
|
2008-04-24 10:05:26 +03:00
|
|
|
localtime_r(@T, UT);
|
2008-04-24 10:12:01 +03:00
|
|
|
Result := ut.__tm_gmtoff div 60;
|
2008-04-24 10:05:26 +03:00
|
|
|
{$ELSE}
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
zoneinfo: TTimeZoneInformation;
|
|
|
|
bias: Integer;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-23 23:46:58 +03:00
|
|
|
case GetTimeZoneInformation(Zoneinfo) of
|
2008-04-24 10:05:26 +03:00
|
|
|
2:
|
|
|
|
bias := zoneinfo.Bias + zoneinfo.DaylightBias;
|
|
|
|
1:
|
|
|
|
bias := zoneinfo.Bias + zoneinfo.StandardBias;
|
|
|
|
else
|
|
|
|
bias := zoneinfo.Bias;
|
2008-04-23 23:46:58 +03:00
|
|
|
end;
|
2008-04-24 10:12:01 +03:00
|
|
|
Result := bias * (-1);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function TimeZone: string;
|
|
|
|
var
|
|
|
|
bias: Integer;
|
|
|
|
h, m: Integer;
|
|
|
|
begin
|
|
|
|
bias := TimeZoneBias;
|
|
|
|
if bias >= 0 then
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := '+'
|
|
|
|
else
|
|
|
|
Result := '-';
|
|
|
|
bias := Abs(bias);
|
|
|
|
h := bias div 60;
|
|
|
|
m := bias mod 60;
|
|
|
|
Result := Result + Format('%.2d%.2d', [h, m]);
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function Rfc822DateTime(t: TDateTime): string;
|
2008-04-24 10:20:39 +03:00
|
|
|
var
|
|
|
|
wYear, wMonth, wDay: word;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
DecodeDate(t, wYear, wMonth, wDay);
|
|
|
|
Result := Format('%s, %d %s %s %s', [MyDayNames[DayOfWeek(t)], wDay,
|
|
|
|
MyMonthNames[wMonth], FormatDateTime('yyyy hh:nn:ss', t), TimeZone]);
|
2008-04-24 10:09:13 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function CDateTime(t: TDateTime): string;
|
2008-04-24 10:20:39 +03:00
|
|
|
var
|
|
|
|
wYear, wMonth, wDay: word;
|
2008-04-24 10:09:13 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
DecodeDate(t, wYear, wMonth, wDay);
|
|
|
|
Result:= Format('%s %2d %s', [MyMonthNames[wMonth], wDay,
|
|
|
|
FormatDateTime('hh:nn:ss', t)]);
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function SimpleDateTime(t: TDateTime): string;
|
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := FormatDateTime('yymmdd hhnnss', t);
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:18:26 +03:00
|
|
|
function AnsiCDateTime(t: TDateTime): string;
|
2008-04-24 10:20:39 +03:00
|
|
|
var
|
|
|
|
wYear, wMonth, wDay: word;
|
2008-04-24 10:18:26 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
DecodeDate(t, wYear, wMonth, wDay);
|
|
|
|
Result := Format('%s %s %d %s', [MyDayNames[DayOfWeek(t)], MyMonthNames[wMonth],
|
|
|
|
wDay, FormatDateTime('hh:nn:ss yyyy ', t)]);
|
2008-04-24 10:18:26 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function DecodeTimeZone(Value: string; var Zone: integer): Boolean;
|
|
|
|
var
|
|
|
|
x: integer;
|
|
|
|
zh, zm: integer;
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
s := Value;
|
|
|
|
if (Pos('+', s) = 1) or (Pos('-',s) = 1) then
|
|
|
|
begin
|
|
|
|
if s = '-0000' then
|
|
|
|
Zone := TimeZoneBias
|
|
|
|
else
|
|
|
|
if Length(s) > 4 then
|
|
|
|
begin
|
|
|
|
zh := StrToIntdef(s[2] + s[3], 0);
|
|
|
|
zm := StrToIntdef(s[4] + s[5], 0);
|
|
|
|
zone := zh * 60 + zm;
|
|
|
|
if s[1] = '-' then
|
|
|
|
zone := zone * (-1);
|
|
|
|
end;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
x := 32767;
|
|
|
|
if s = 'NZDT' then x := 13;
|
|
|
|
if s = 'IDLE' then x := 12;
|
|
|
|
if s = 'NZST' then x := 12;
|
|
|
|
if s = 'NZT' then x := 12;
|
|
|
|
if s = 'EADT' then x := 11;
|
|
|
|
if s = 'GST' then x := 10;
|
|
|
|
if s = 'JST' then x := 9;
|
|
|
|
if s = 'CCT' then x := 8;
|
|
|
|
if s = 'WADT' then x := 8;
|
|
|
|
if s = 'WAST' then x := 7;
|
|
|
|
if s = 'ZP6' then x := 6;
|
|
|
|
if s = 'ZP5' then x := 5;
|
|
|
|
if s = 'ZP4' then x := 4;
|
|
|
|
if s = 'BT' then x := 3;
|
|
|
|
if s = 'EET' then x := 2;
|
|
|
|
if s = 'MEST' then x := 2;
|
|
|
|
if s = 'MESZ' then x := 2;
|
|
|
|
if s = 'SST' then x := 2;
|
|
|
|
if s = 'FST' then x := 2;
|
|
|
|
if s = 'CEST' then x := 2;
|
|
|
|
if s = 'CET' then x := 1;
|
|
|
|
if s = 'FWT' then x := 1;
|
|
|
|
if s = 'MET' then x := 1;
|
|
|
|
if s = 'MEWT' then x := 1;
|
|
|
|
if s = 'SWT' then x := 1;
|
|
|
|
if s = 'UT' then x := 0;
|
|
|
|
if s = 'UTC' then x := 0;
|
|
|
|
if s = 'GMT' then x := 0;
|
|
|
|
if s = 'WET' then x := 0;
|
|
|
|
if s = 'WAT' then x := -1;
|
|
|
|
if s = 'BST' then x := -1;
|
|
|
|
if s = 'AT' then x := -2;
|
|
|
|
if s = 'ADT' then x := -3;
|
|
|
|
if s = 'AST' then x := -4;
|
|
|
|
if s = 'EDT' then x := -4;
|
|
|
|
if s = 'EST' then x := -5;
|
|
|
|
if s = 'CDT' then x := -5;
|
|
|
|
if s = 'CST' then x := -6;
|
|
|
|
if s = 'MDT' then x := -6;
|
|
|
|
if s = 'MST' then x := -7;
|
|
|
|
if s = 'PDT' then x := -7;
|
|
|
|
if s = 'PST' then x := -8;
|
|
|
|
if s = 'YDT' then x := -8;
|
|
|
|
if s = 'YST' then x := -9;
|
|
|
|
if s = 'HDT' then x := -9;
|
|
|
|
if s = 'AHST' then x := -10;
|
|
|
|
if s = 'CAT' then x := -10;
|
|
|
|
if s = 'HST' then x := -10;
|
|
|
|
if s = 'EAST' then x := -10;
|
|
|
|
if s = 'NT' then x := -11;
|
|
|
|
if s = 'IDLW' then x := -12;
|
|
|
|
if x <> 32767 then
|
|
|
|
begin
|
|
|
|
zone := x * 60;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:18:26 +03:00
|
|
|
function GetMonthNumber(Value: string): integer;
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
Value := Uppercase(Value);
|
|
|
|
for n := 1 to 12 do
|
|
|
|
if Value = uppercase(MyMonthNames[n]) then
|
|
|
|
begin
|
|
|
|
Result := n;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function GetTimeFromStr(Value: string): TDateTime;
|
|
|
|
var
|
2008-04-24 10:20:39 +03:00
|
|
|
x: integer;
|
2008-04-24 10:18:26 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
x := rpos(':', Value);
|
|
|
|
if (x > 0) and ((Length(Value) - x) > 2) then
|
|
|
|
Value := Copy(Value, 1, x + 2);
|
2008-04-24 10:22:17 +03:00
|
|
|
Value := ReplaceString(Value, ':', TimeSeparator);
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := 0;
|
2008-04-24 10:18:26 +03:00
|
|
|
try
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := StrToTime(Value);
|
|
|
|
except
|
|
|
|
on Exception do ;
|
2008-04-24 10:18:26 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function GetDateMDYFromStr(Value: string): TDateTime;
|
|
|
|
var
|
2008-04-24 10:20:39 +03:00
|
|
|
wYear, wMonth, wDay: word;
|
|
|
|
s: string;
|
2008-04-24 10:18:26 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := 0;
|
|
|
|
s := Fetch(Value, '-');
|
|
|
|
wMonth := StrToIntDef(s, 12);
|
|
|
|
s := Fetch(Value, '-');
|
|
|
|
wDay := StrToIntDef(s, 30);
|
|
|
|
wYear := StrToIntDef(Value, 1899);
|
|
|
|
if wYear < 1000 then
|
|
|
|
if (wYear > 99) then
|
|
|
|
wYear := wYear + 1900
|
|
|
|
else
|
|
|
|
if wYear > 50 then
|
|
|
|
wYear := wYear + 1900
|
|
|
|
else
|
|
|
|
wYear := wYear + 2000;
|
2008-04-24 10:18:26 +03:00
|
|
|
try
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := EncodeDate(wYear, wMonth, wDay);
|
|
|
|
except
|
|
|
|
on Exception do ;
|
2008-04-24 10:18:26 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function DecodeRfcDateTime(Value: string): TDateTime;
|
|
|
|
var
|
|
|
|
day, month, year: Word;
|
|
|
|
zone: integer;
|
2008-04-24 10:20:39 +03:00
|
|
|
x, y: integer;
|
2008-04-24 10:12:01 +03:00
|
|
|
s: string;
|
|
|
|
t: TDateTime;
|
|
|
|
begin
|
|
|
|
// ddd, d mmm yyyy hh:mm:ss
|
|
|
|
// ddd, d mmm yy hh:mm:ss
|
|
|
|
// ddd, mmm d yyyy hh:mm:ss
|
|
|
|
// ddd mmm dd hh:mm:ss yyyy
|
2008-04-24 10:18:26 +03:00
|
|
|
// Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
|
|
|
|
// Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
|
|
|
|
// Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() Format
|
2008-04-24 10:12:01 +03:00
|
|
|
|
|
|
|
Result := 0;
|
2008-04-24 10:18:26 +03:00
|
|
|
if Value = '' then
|
|
|
|
Exit;
|
|
|
|
day := 0;
|
|
|
|
month := 0;
|
|
|
|
year := 0;
|
|
|
|
zone := 0;
|
2008-04-24 10:22:17 +03:00
|
|
|
Value := ReplaceString(Value, ' -', ' #');
|
|
|
|
Value := ReplaceString(Value, '-', ' ');
|
|
|
|
Value := ReplaceString(Value, ' #', ' -');
|
2008-04-24 10:18:26 +03:00
|
|
|
while Value <> '' do
|
|
|
|
begin
|
|
|
|
s := Fetch(Value, ' ');
|
|
|
|
s := uppercase(s);
|
|
|
|
// timezone
|
|
|
|
if DecodetimeZone(s, x) then
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
2008-04-24 10:18:26 +03:00
|
|
|
zone := x;
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
x := StrToIntDef(s, 0);
|
|
|
|
// day or year
|
|
|
|
if x > 0 then
|
|
|
|
if (x < 32) and (day = 0) then
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
2008-04-24 10:18:26 +03:00
|
|
|
day := x;
|
2008-04-24 10:12:01 +03:00
|
|
|
continue;
|
2008-04-24 10:18:26 +03:00
|
|
|
end
|
|
|
|
else
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
2008-04-24 10:18:26 +03:00
|
|
|
year := x;
|
|
|
|
if year < 32 then
|
|
|
|
year := year + 2000;
|
|
|
|
if year < 1000 then
|
|
|
|
year := year + 1900;
|
2008-04-24 10:12:01 +03:00
|
|
|
continue;
|
|
|
|
end;
|
2008-04-24 10:18:26 +03:00
|
|
|
// time
|
|
|
|
if rpos(':', s) > Pos(':', s) then
|
|
|
|
begin
|
|
|
|
t := GetTimeFromStr(s);
|
|
|
|
if t <> 0 then
|
|
|
|
Result := t;
|
|
|
|
continue;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
2008-04-24 10:18:26 +03:00
|
|
|
//timezone daylight saving time
|
|
|
|
if s = 'DST' then
|
|
|
|
begin
|
|
|
|
zone := zone + 60;
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
// month
|
2008-04-24 10:20:39 +03:00
|
|
|
y := GetMonthNumber(s);
|
|
|
|
if y > 0 then
|
|
|
|
month := y;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
2008-04-24 10:22:17 +03:00
|
|
|
if year = 0 then
|
|
|
|
year := 1980;
|
2008-04-24 10:20:39 +03:00
|
|
|
if (month < 1) or (month > 12) then
|
|
|
|
month := 1;
|
|
|
|
if (day < 1) or (day > 31) then
|
|
|
|
day := 1;
|
2008-04-24 10:18:26 +03:00
|
|
|
Result := Result + Encodedate(year, month, day);
|
|
|
|
zone := zone - TimeZoneBias;
|
|
|
|
t := EncodeTime(Abs(zone) div 60, Abs(zone) mod 60, 0, 0);
|
|
|
|
if zone < 0 then
|
|
|
|
t := 0 - t;
|
|
|
|
Result := Result - t;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function GetUTTime: TDateTime;
|
|
|
|
{$IFNDEF LINUX}
|
|
|
|
var
|
|
|
|
st: TSystemTime;
|
|
|
|
begin
|
|
|
|
GetSystemTime(st);
|
|
|
|
result:=SystemTimeToDateTime(st);
|
|
|
|
{$ELSE}
|
|
|
|
var
|
|
|
|
TV: TTimeVal;
|
|
|
|
begin
|
|
|
|
gettimeofday(TV, nil);
|
|
|
|
Result:=UnixDateDelta + (TV.tv_sec + TV.tv_usec / 1000000) / 86400;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function SetUTTime(Newdt: TDateTime): Boolean;
|
|
|
|
{$IFNDEF LINUX}
|
|
|
|
var
|
|
|
|
st: TSystemTime;
|
|
|
|
begin
|
|
|
|
DateTimeToSystemTime(newdt,st);
|
|
|
|
Result:=SetSystemTime(st);
|
|
|
|
{$ELSE}
|
|
|
|
var
|
|
|
|
TV: TTimeVal;
|
|
|
|
d: double;
|
|
|
|
TZ: Ttimezone;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
gettimeofday(TV, TZ);
|
|
|
|
d := (newdt - UnixDateDelta) * 86400;
|
|
|
|
TV.tv_sec := trunc(d);
|
|
|
|
TV.tv_usec := trunc(frac(d) * 1000000);
|
|
|
|
Result := settimeofday(TV, TZ) <> -1;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
{$IFDEF LINUX}
|
|
|
|
function GetTick: Cardinal;
|
|
|
|
var
|
|
|
|
Stamp: TTimeStamp;
|
|
|
|
begin
|
|
|
|
Stamp := DateTimeToTimeStamp(Now);
|
|
|
|
Result := Stamp.Time;
|
|
|
|
end;
|
|
|
|
{$ELSE}
|
|
|
|
function GetTick: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := Windows.GetTickCount;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function CodeInt(Value: Word): string;
|
2008-04-23 23:28:55 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := Chr(Hi(Value)) + Chr(Lo(Value))
|
2008-04-23 23:28:55 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function DecodeInt(const Value: string; Index: Integer): Word;
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, y: Byte;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
if Length(Value) > Index then
|
|
|
|
x := Ord(Value[Index])
|
|
|
|
else
|
|
|
|
x := 0;
|
2008-04-24 10:09:13 +03:00
|
|
|
if Length(Value) >= (Index + 1) then
|
2008-04-24 10:05:26 +03:00
|
|
|
y := Ord(Value[Index + 1])
|
|
|
|
else
|
|
|
|
y := 0;
|
|
|
|
Result := x * 256 + y;
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function IsIP(const Value: string): Boolean;
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:20:39 +03:00
|
|
|
TempIP: string;
|
|
|
|
|
|
|
|
function ByteIsOk(const Value: string): Boolean;
|
|
|
|
var
|
|
|
|
x, n: integer;
|
2008-04-24 10:13:22 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
x := StrToIntDef(Value, -1);
|
|
|
|
Result := (x >= 0) and (x < 256);
|
|
|
|
// X may be in correct range, but value still may not be correct value!
|
|
|
|
// i.e. "$80"
|
|
|
|
if Result then
|
|
|
|
for n := 1 to length(Value) do
|
|
|
|
if not (Value[n] in ['0'..'9']) then
|
|
|
|
begin
|
2008-04-24 10:13:22 +03:00
|
|
|
Result := False;
|
2008-04-24 10:20:39 +03:00
|
|
|
Break;
|
|
|
|
end;
|
2008-04-24 10:13:22 +03:00
|
|
|
end;
|
2008-04-24 10:20:39 +03:00
|
|
|
|
|
|
|
begin
|
|
|
|
TempIP := Value;
|
|
|
|
Result := False;
|
|
|
|
if not ByteIsOk(Fetch(TempIP, '.')) then
|
|
|
|
Exit;
|
|
|
|
if not ByteIsOk(Fetch(TempIP, '.')) then
|
|
|
|
Exit;
|
|
|
|
if not ByteIsOk(Fetch(TempIP, '.')) then
|
|
|
|
Exit;
|
|
|
|
if ByteIsOk(TempIP) then
|
|
|
|
Result := True;
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function ReverseIP(Value: string): string;
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x: Integer;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := '';
|
2008-04-23 23:26:50 +03:00
|
|
|
repeat
|
2008-04-24 10:05:26 +03:00
|
|
|
x := LastDelimiter('.', Value);
|
|
|
|
Result := Result + '.' + Copy(Value, x + 1, Length(Value) - x);
|
|
|
|
Delete(Value, x, Length(Value) - x + 1);
|
|
|
|
until x < 1;
|
|
|
|
if Length(Result) > 0 then
|
|
|
|
if Result[1] = '.' then
|
2008-04-23 23:32:54 +03:00
|
|
|
Delete(Result, 1, 1);
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:09:13 +03:00
|
|
|
{==============================================================================}
|
|
|
|
//Hernan Sanchez
|
|
|
|
function IPToID(Host: string): string;
|
|
|
|
var
|
|
|
|
s, t: string;
|
|
|
|
i, x: Integer;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
for x := 1 to 3 do
|
|
|
|
begin
|
|
|
|
t := '';
|
|
|
|
s := StrScan(PChar(Host), '.');
|
|
|
|
t := Copy(Host, 1, (Length(Host) - Length(s)));
|
|
|
|
Delete(Host, 1, (Length(Host) - Length(s) + 1));
|
|
|
|
i := StrToIntDef(t, 0);
|
|
|
|
Result := Result + Chr(i);
|
|
|
|
end;
|
|
|
|
i := StrToIntDef(Host, 0);
|
|
|
|
Result := Result + Chr(i);
|
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
procedure Dump(const Buffer, DumpFile: string);
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
n: Integer;
|
|
|
|
s: string;
|
|
|
|
f: Text;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
s := '';
|
|
|
|
for n := 1 to Length(Buffer) do
|
|
|
|
s := s + ' +#$' + IntToHex(Ord(Buffer[n]), 2);
|
|
|
|
AssignFile(f, DumpFile);
|
|
|
|
if FileExists(DumpFile) then
|
|
|
|
DeleteFile(PChar(DumpFile));
|
|
|
|
Rewrite(f);
|
2008-04-23 23:26:50 +03:00
|
|
|
try
|
2008-04-24 10:05:26 +03:00
|
|
|
Writeln(f, s);
|
2008-04-23 23:26:50 +03:00
|
|
|
finally
|
2008-04-24 10:05:26 +03:00
|
|
|
CloseFile(f);
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-23 23:48:39 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
procedure DumpEx(const Buffer, DumpFile: string);
|
|
|
|
var
|
|
|
|
n: Integer;
|
|
|
|
x: Byte;
|
|
|
|
s: string;
|
|
|
|
f: Text;
|
|
|
|
begin
|
|
|
|
s := '';
|
|
|
|
for n := 1 to Length(Buffer) do
|
|
|
|
begin
|
|
|
|
x := Ord(Buffer[n]);
|
|
|
|
if x in [65..90, 97..122] then
|
|
|
|
s := s + ' +''' + char(x) + ''''
|
|
|
|
else
|
|
|
|
s := s + ' +#$' + IntToHex(Ord(Buffer[n]), 2);
|
|
|
|
end;
|
|
|
|
AssignFile(f, DumpFile);
|
|
|
|
if FileExists(DumpFile) then
|
|
|
|
DeleteFile(PChar(DumpFile));
|
|
|
|
Rewrite(f);
|
|
|
|
try
|
|
|
|
Writeln(f, s);
|
|
|
|
finally
|
|
|
|
CloseFile(f);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function SeparateLeft(const Value, Delimiter: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x: Integer;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
x := Pos(Delimiter, Value);
|
|
|
|
if x < 1 then
|
|
|
|
Result := Trim(Value)
|
|
|
|
else
|
|
|
|
Result := Trim(Copy(Value, 1, x - 1));
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function SeparateRight(const Value, Delimiter: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x: Integer;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
x := Pos(Delimiter, Value);
|
|
|
|
if x > 0 then
|
|
|
|
x := x + Length(Delimiter) - 1;
|
|
|
|
Result := Trim(Copy(Value, x + 1, Length(Value) - x));
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function GetParameter(const Value, Parameter: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, x1: Integer;
|
|
|
|
s: string;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
x := Pos(UpperCase(Parameter), UpperCase(Value));
|
|
|
|
Result := '';
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
s := Copy(Value, x + Length(Parameter), Length(Value)
|
|
|
|
- (x + Length(Parameter)) + 1);
|
|
|
|
s := Trim(s);
|
|
|
|
x1 := Length(s);
|
|
|
|
if Length(s) > 1 then
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
if s[1] = '"' then
|
|
|
|
begin
|
|
|
|
s := Copy(s, 2, Length(s) - 1);
|
|
|
|
x := Pos('"', s);
|
|
|
|
if x > 0 then
|
|
|
|
x1 := x - 1;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
x := Pos(' ', s);
|
|
|
|
if x > 0 then
|
|
|
|
x1 := x - 1;
|
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := Copy(s, 1, x1);
|
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure ParseParameters(Value: string; const Parameters: TStrings);
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
Parameters.Clear;
|
|
|
|
while Value <> '' do
|
|
|
|
begin
|
|
|
|
s := Fetch(Value, ';');
|
|
|
|
Parameters.Add(s);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function IndexByBegin(Value: string; const List: TStrings): integer;
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
Value := uppercase(Value);
|
|
|
|
for n := 0 to List.Count -1 do
|
|
|
|
begin
|
|
|
|
s := UpperCase(List[n]);
|
|
|
|
if Pos(Value, s) = 1 then
|
|
|
|
begin
|
|
|
|
Result := n;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function GetEmailAddr(const Value: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
s: string;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
s := SeparateRight(Value, '<');
|
|
|
|
s := SeparateLeft(s, '>');
|
|
|
|
Result := Trim(s);
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function GetEmailDesc(Value: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
s: string;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Value := Trim(Value);
|
|
|
|
s := SeparateRight(Value, '"');
|
|
|
|
if s <> Value then
|
|
|
|
s := SeparateLeft(s, '"')
|
|
|
|
else
|
|
|
|
begin
|
2008-04-24 10:12:01 +03:00
|
|
|
s := SeparateLeft(Value, '<');
|
|
|
|
if s = Value then
|
2008-04-24 10:05:26 +03:00
|
|
|
begin
|
2008-04-24 10:12:01 +03:00
|
|
|
s := SeparateRight(Value, '(');
|
|
|
|
if s <> Value then
|
|
|
|
s := SeparateLeft(s, ')')
|
|
|
|
else
|
2008-04-24 10:05:26 +03:00
|
|
|
s := '';
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := Trim(s);
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:49:43 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function StrToHex(const Value: string): string;
|
2008-04-23 23:49:43 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
n: Integer;
|
2008-04-23 23:49:43 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := '';
|
|
|
|
for n := 1 to Length(Value) do
|
|
|
|
Result := Result + IntToHex(Byte(Value[n]), 2);
|
|
|
|
Result := LowerCase(Result);
|
2008-04-23 23:49:43 +03:00
|
|
|
end;
|
2008-04-24 09:40:58 +03:00
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function IntToBin(Value: Integer; Digits: Byte): string;
|
2008-04-24 09:40:58 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, y, n: Integer;
|
2008-04-24 09:40:58 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := '';
|
|
|
|
x := Value;
|
2008-04-24 09:40:58 +03:00
|
|
|
repeat
|
2008-04-24 10:05:26 +03:00
|
|
|
y := x mod 2;
|
|
|
|
x := x div 2;
|
|
|
|
if y > 0 then
|
|
|
|
Result := '1' + Result
|
|
|
|
else
|
|
|
|
Result := '0' + Result;
|
|
|
|
until x = 0;
|
|
|
|
x := Length(Result);
|
|
|
|
for n := x to Digits - 1 do
|
|
|
|
Result := '0' + Result;
|
2008-04-24 09:40:58 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function BinToInt(const Value: string): Integer;
|
2008-04-24 09:40:58 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
n: Integer;
|
2008-04-24 09:40:58 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := 0;
|
|
|
|
for n := 1 to Length(Value) do
|
|
|
|
begin
|
|
|
|
if Value[n] = '0' then
|
|
|
|
Result := Result * 2
|
|
|
|
else
|
|
|
|
if Value[n] = '1' then
|
|
|
|
Result := Result * 2 + 1
|
|
|
|
else
|
|
|
|
Break;
|
|
|
|
end;
|
2008-04-24 09:40:58 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 09:42:13 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function ParseURL(URL: string; var Prot, User, Pass, Host, Port, Path,
|
|
|
|
Para: string): string;
|
2008-04-24 09:42:13 +03:00
|
|
|
var
|
2008-04-24 10:22:17 +03:00
|
|
|
x, y: Integer;
|
2008-04-24 10:05:26 +03:00
|
|
|
sURL: string;
|
|
|
|
s: string;
|
|
|
|
s1, s2: string;
|
2008-04-24 09:42:13 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Prot := 'http';
|
|
|
|
User := '';
|
|
|
|
Pass := '';
|
|
|
|
Port := '80';
|
|
|
|
Para := '';
|
|
|
|
|
|
|
|
x := Pos('://', URL);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
Prot := SeparateLeft(URL, '://');
|
|
|
|
sURL := SeparateRight(URL, '://');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
sURL := URL;
|
2008-04-24 10:13:22 +03:00
|
|
|
if UpperCase(Prot) = 'HTTPS' then
|
|
|
|
Port := '443';
|
|
|
|
if UpperCase(Prot) = 'FTP' then
|
|
|
|
Port := '21';
|
2008-04-24 10:05:26 +03:00
|
|
|
x := Pos('@', sURL);
|
2008-04-24 10:22:17 +03:00
|
|
|
y := Pos('/', sURL);
|
|
|
|
if (x > 0) and ((x < y) or (y < 1))then
|
2008-04-24 10:05:26 +03:00
|
|
|
begin
|
|
|
|
s := SeparateLeft(sURL, '@');
|
|
|
|
sURL := SeparateRight(sURL, '@');
|
|
|
|
x := Pos(':', s);
|
|
|
|
if x > 0 then
|
2008-04-24 09:42:13 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
User := SeparateLeft(s, ':');
|
|
|
|
Pass := SeparateRight(s, ':');
|
2008-04-24 09:42:13 +03:00
|
|
|
end
|
|
|
|
else
|
2008-04-24 10:05:26 +03:00
|
|
|
User := s;
|
|
|
|
end;
|
|
|
|
x := Pos('/', sURL);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
s1 := SeparateLeft(sURL, '/');
|
|
|
|
s2 := SeparateRight(sURL, '/');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
s1 := sURL;
|
|
|
|
s2 := '';
|
|
|
|
end;
|
|
|
|
x := Pos(':', s1);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
Host := SeparateLeft(s1, ':');
|
|
|
|
Port := SeparateRight(s1, ':');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Host := s1;
|
|
|
|
Result := '/' + s2;
|
|
|
|
x := Pos('?', s2);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
Path := '/' + SeparateLeft(s2, '?');
|
|
|
|
Para := SeparateRight(s2, '?');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Path := '/' + s2;
|
|
|
|
if Host = '' then
|
|
|
|
Host := 'localhost';
|
2008-04-24 09:42:13 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 09:46:22 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:22:17 +03:00
|
|
|
function ReplaceString(Value, Search, Replace: string): string;
|
2008-04-24 09:46:22 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, l, ls, lr: Integer;
|
2008-04-24 09:46:22 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
if (Value = '') or (Search = '') then
|
|
|
|
begin
|
|
|
|
Result := Value;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
ls := Length(Search);
|
|
|
|
lr := Length(Replace);
|
|
|
|
Result := '';
|
|
|
|
x := Pos(Search, Value);
|
|
|
|
while x > 0 do
|
|
|
|
begin
|
|
|
|
l := Length(Result);
|
|
|
|
SetLength(Result, l + x - 1);
|
|
|
|
Move(Pointer(Value)^, Pointer(@Result[l + 1])^, x - 1);
|
|
|
|
// Result:=Result+Copy(Value,1,x-1);
|
|
|
|
l := Length(Result);
|
|
|
|
SetLength(Result, l + lr);
|
|
|
|
Move(Pointer(Replace)^, Pointer(@Result[l + 1])^, lr);
|
|
|
|
// Result:=Result+Replace;
|
|
|
|
Delete(Value, 1, x - 1 + ls);
|
|
|
|
x := Pos(Search, Value);
|
|
|
|
end;
|
|
|
|
Result := Result + Value;
|
2008-04-24 09:46:22 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:07:45 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:18:26 +03:00
|
|
|
function RPosEx(const Sub, Value: string; From: integer): Integer;
|
2008-04-24 10:07:45 +03:00
|
|
|
var
|
|
|
|
n: Integer;
|
|
|
|
l: Integer;
|
|
|
|
begin
|
|
|
|
result := 0;
|
|
|
|
l := Length(Sub);
|
2008-04-24 10:18:26 +03:00
|
|
|
for n := From - l + 1 downto 1 do
|
2008-04-24 10:07:45 +03:00
|
|
|
begin
|
|
|
|
if Copy(Value, n, l) = Sub then
|
|
|
|
begin
|
|
|
|
result := n;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:18:26 +03:00
|
|
|
function RPos(const Sub, Value: String): Integer;
|
|
|
|
begin
|
|
|
|
Result := RPosEx(Sub, Value, Length(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:07:45 +03:00
|
|
|
function Fetch(var Value: string; const Delimiter: string): string;
|
2008-04-24 10:12:01 +03:00
|
|
|
var
|
|
|
|
s: string;
|
2008-04-24 10:07:45 +03:00
|
|
|
begin
|
|
|
|
Result := SeparateLeft(Value, Delimiter);
|
2008-04-24 10:12:01 +03:00
|
|
|
s := SeparateRight(Value, Delimiter);
|
|
|
|
if s = Value then
|
|
|
|
Value := ''
|
|
|
|
else
|
|
|
|
Value := Trim(s);
|
|
|
|
Result := Trim(Result);
|
2008-04-24 10:07:45 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function IsBinaryString(const Value: string): Boolean;
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
for n := 1 to Length(Value) do
|
|
|
|
if Value[n] in [#0..#8, #10..#31] then
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function PosCRLF(const Value: string; var Terminator: string): integer;
|
|
|
|
var
|
|
|
|
p1, p2, p3, p4: integer;
|
|
|
|
const
|
|
|
|
t1 = #$0d + #$0a;
|
|
|
|
t2 = #$0a + #$0d;
|
|
|
|
t3 = #$0d;
|
|
|
|
t4 = #$0a;
|
|
|
|
begin
|
|
|
|
Terminator := '';
|
|
|
|
p1 := Pos(t1, Value);
|
|
|
|
p2 := Pos(t2, Value);
|
|
|
|
p3 := Pos(t3, Value);
|
|
|
|
p4 := Pos(t4, Value);
|
|
|
|
if p1 > 0 then
|
|
|
|
Terminator := t1;
|
|
|
|
Result := p1;
|
|
|
|
if (p2 > 0) then
|
|
|
|
if (Result = 0) or (p2 < Result) then
|
|
|
|
begin
|
|
|
|
Result := p2;
|
|
|
|
Terminator := t2;
|
|
|
|
end;
|
|
|
|
if (p3 > 0) then
|
|
|
|
if (Result = 0) or (p3 < Result) then
|
|
|
|
begin
|
|
|
|
Result := p3;
|
|
|
|
Terminator := t3;
|
|
|
|
end;
|
|
|
|
if (p4 > 0) then
|
|
|
|
if (Result = 0) or (p4 < Result) then
|
|
|
|
begin
|
|
|
|
Result := p4;
|
|
|
|
Terminator := t4;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
Procedure StringsTrim(const Value: TStrings);
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
for n := Value.Count - 1 downto 0 do
|
|
|
|
if Value[n] = '' then
|
|
|
|
Value.Delete(n)
|
|
|
|
else
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function PosFrom(const SubStr, Value: String; From: integer): integer;
|
|
|
|
var
|
|
|
|
ls,lv: integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
ls := Length(SubStr);
|
|
|
|
lv := Length(Value);
|
|
|
|
if (ls = 0) or (lv = 0) then
|
|
|
|
Exit;
|
|
|
|
if From < 1 then
|
|
|
|
From := 1;
|
|
|
|
while (ls + from - 1) <= (lv) do
|
|
|
|
begin
|
|
|
|
if CompareMem(@SubStr[1],@Value[from],ls) then
|
|
|
|
begin
|
|
|
|
result := from;
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
inc(from);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:22:17 +03:00
|
|
|
function IncPoint(const p: pointer; Value: integer): pointer;
|
|
|
|
begin
|
|
|
|
Result := pointer(integer(p) + Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-23 23:26:50 +03:00
|
|
|
end.
|