{===========================================================================}
{                                                                           }
{                           Dialer+ Open API                                }
{                                                                           }
{                   http://www.piafi.wm.ru/dialerp/                         }
{                   Dialer+ 32bit DLL function Unit                         }
{                                                                           }
{                Copyright (c) 1997-99, Piafi SoftIntl                      }
{                                                                           }
{===========================================================================}
{$H-,I-,A-}
unit DP_Uses;

interface

type
  ROutLogProc = function ( S: shortstring): shortstring; stdcall;

  PStringLines = ^TStringLines;
  TStringLines =
  record
    Str : shortstring;
    Next: PStringLines;
  end;

  PConnectionUserData = ^TConnectionUserData;
  TConnectionUserData =
  record
    Name        : string;  { connect name }
    WinName     : string;  { use windows connection name }
    UserName    : string;  { user name }
    UserPassword: string;  { user password }
    Phone       : string;  { main phone }
    Domain      : string;  { domain }
    CheckURL    : string;  { URL for check network connect }
    CheckURLTime: word;    { repeat check time }
    LogFile     : string;  { log filename }
    AutoHide    : boolean; { hide dialer window (for dialerpw)}

    Redial      : boolean; { need redial }
    DialPreffix : string;  { phone preffix }
    WaitDial    : word;    { wait time for connect }
    MaxRetry    : word;    { max redial try }
    WaitTime    : word;    { wait circle time }
    SleepTime   : word;    { wait circle sleep time }
    AddPhone    : TStringLines; { add phone list }
    OffPhone    : TStringLines; { disable phone list }

    EventID     : TStringLines; { event's list }
    BreakFlag   : string;       { break flag filename }
    SleepFlag   : string;       { sleep flag filename }
    ConnectFlag : string;       { connect flag filename }
    DialFlag    : string;       { dial flag filename }
    BreakIfFound: boolean;      { break if use current windows connect }
    BreakTime   : TStringLines; { break time event list }

    ExecuteFlag      : TStringLines; { execute list for found flag }
    ExecuteStart     : TStringLines; { execute list for start program }
    ExecuteDisconnect: TStringLines; { execute list for disconnect }
    ExecuteConnect   : TStringLines; { execute list for connect }
    ExecuteTime      : TStringLines; { execute list for need time }

    Cost        : TStringLines; { cost list }

    DayLimit    : integer; { day time limit }
    WeekLimit   : integer; { week time limit }
    MonthLimit  : integer; { month time limit }

    Proxy       : string; { external proxy name }
    POP3        : string; { external pop3 name }
    SMTP        : string; { external smtp name }
    NNTP        : string; { external nntp name }
    FTP         : word;   { default ftp-gate port }
    SOCKS       : word;   { default socks4 port }
    PortDog     : string; { port's list for check }
    CacheDNSDay : word;   { day's to cache host name }
    NetStopTime : integer; { network stop after not activities }
    NetSleepTime: integer; { network sleep after not activities }
    MapLinks    : TStringLines; { map link's list }
    HideProxy   : boolean;
    HidePOP3    : boolean;
    HideSMTP    : boolean;
    HideNNTP    : boolean;
    HideFTP     : boolean;
    HideSOCKS   : boolean;
    HidePort    : boolean;
    DialerPort  : word;
  end;

  PConnectionStatus = ^TConnectionUserData;
  TConnectionStatus =
  record
    Name        : string; { connect name }
    Status      : string;
    IP          : string;
  end;

  PConnectionInfo = ^TConnectionInfo;
  TConnectionInfo =
  record
    tmDay,tmWeek,tmMonth: cardinal;
    csDay,csWeek,csMonth: real;
    ReadBytes,WriteBytes: cardinal;
    rCPS,wCPS,mCPS,aCPS: cardinal;
    rDisk,rNet: cardinal;
    OnLine: byte;
  end;

procedure ClearStringLines( var S: TStringLines);
procedure AddStringLines( var S: TStringLines; const St: string);
function  SearchStringLines( var S: TStringLines; const St: string): PStringLines;
procedure InitStringLines( var S: TStringLines);
function  CountStringLines( var S: TStringLines): integer;

procedure InitConnectionUserData( var Data: TConnectionUserData);
procedure ClearConnectionUserData( var Data: TConnectionUserData);

function Int2Str( I: integer): string;
function Real2Str( I: real): string;
function Str2Int( S: string): word;

implementation

function Int2Str;
begin
  Str(I,Result);
  if Result = '0' then Result := '';
end;

function Real2Str;
begin
  Str(I:0:2,Result);
end;

function Str2Int;
var
  Res: integer;
begin
  if S <> '' then Val(S,Result,Res)
             else Result := 0;
end;

procedure InitStringLines;
begin
  S.Str  := '';
  S.Next := nil;
end;

procedure ClearStringLines;
begin
  if S.Next <> nil then ClearStringLines(S.Next^);
  InitStringLines(S);
end;

procedure AddStringLines;
begin
  if St = '' then Exit;
  if S.Str = '' then
  begin
    S.Str := St;
    Exit;
  end;
  if S.Next = nil then
  begin
    New(S.Next);
    InitStringLines(S.Next^);
  end;
  AddStringLines(S.Next^,St);
end;

function SearchStringLines;
begin
  Result := nil;
  if S.Str = '' then Exit;
  if S.Str <> St then
  begin
    if S.Next = nil then Exit;
    Result := SearchStringLines(S.Next^,St);
  end
    else Result := @S;
end;

function CountStringLines;
begin
  if S.Str <> '' then Result := 1
                 else Result := 0;
  if S.Next <> nil then Result := Result + CountStringLines(S.Next^);
end;

procedure InitConnectionUserData;
begin
  with Data do
  begin
    Name         := '';
    WinName      := '';
    UserName     := '';
    UserPassword := '';
    Domain       := '';
    CheckURL     := '';
    CheckURLTime := 0;
    LogFile      := '';
    AutoHide     := false;
    Redial       := false;
    HideProxy    := true;
    HidePOP3     := true;
    HideSMTP     := true;
    HideNNTP     := true;
    HideFTP      := true;
    HideSOCKS    := true;
    HidePort     := true;
    DialerPort   := 0;
    DialPreffix  := 't';
    WaitDial     := 60;
    MaxRetry     := 0;
    WaitTime     := 1;
    SleepTime    := 1;
    Phone        := '';
    BreakFlag    := '';
    SleepFlag    := '';
    ConnectFlag  := '';
    DialFlag     := '';
    BreakIfFound := true;
    DayLimit     := 0;
    WeekLimit    := 0;
    MonthLimit   := 0;
    Proxy        := '';
    POP3         := '';
    SMTP         := '';
    NNTP         := '';
    FTP          := 0;
    SOCKS        := 0;
    PortDog      := '159';
    CacheDNSDay  := 0;
    NetStopTime  := 0;
    NetSleepTime := 0;
    InitStringLines(AddPhone);
    InitStringLines(OffPhone);
    InitStringLines(EventID);
    InitStringLines(BreakTime);
    InitStringLines(Cost);
    InitStringLines(MapLinks);
    InitStringLines(ExecuteStart);
    InitStringLines(ExecuteConnect);
    InitStringLines(ExecuteDisconnect);
    InitStringLines(ExecuteFlag);
    InitStringLines(ExecuteTime);
  end;
end;

procedure ClearConnectionUserData;
begin
  with Data do
  begin
    ClearStringLines(AddPhone);
    ClearStringLines(OffPhone);
    ClearStringLines(EventID);
    ClearStringLines(BreakTime);
    ClearStringLines(ExecuteStart);
    ClearStringLines(ExecuteConnect);
    ClearStringLines(ExecuteDisconnect);
    ClearStringLines(ExecuteFlag);
    ClearStringLines(ExecuteTime);
    ClearStringLines(Cost);
    ClearStringLines(MapLinks);
  end;
  InitConnectionUserData(Data);
end;

end.
