Unit xBase

//////////////////////////////////////////////////////////////////////// // TinyWeb Copyright (C) 1997 RIT Research Labs // This programs is free for commercial and non-commercial use as long as the following conditions are aheared to. // Copyright remains RIT Research Labs, and as such any Copyright notices in the code are not to be removed. If this package is used in a product, RIT Research Labs should be given attribution as the RIT Research Labs of the parts of the library used. This can be in the form of a textual message at program startup or in documentation (online or textual) provided with the package. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: // 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: "Based on TinyWeb Server by RIT Research Labs." // THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "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 AUTHOR 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. // The licence and distribution terms for any publically available version or derivative of this code cannot be changed. i.e. this code cannot simply be copied and put under another distribution licence (including the GNU Public Licence). // //////////////////////////////////////////////////////////////////////// {$I DEFINE.INC

Classes

TAdvClass -
TAdvCpObject -
TAdvObject -
TColl -
TCollClass -
TResetterThread -
TSocket -
TSocketClass -
TSortedColl -
TStringColl - TStringColl object
TThread -

Functions

AddRightSpaces - --- string routines
AddrInet - --- Winsock tools
AddStr -
Add_Str -
Buf2Str - --- Basic Routines
Clear - ////////////////////////////////////////////////////////////////////// // Basic Routines // // //////////////////////////////////////////////////////////////////////
ClearHandle - --- Win32 API Hooks
CloseHandles - ////////////////////////////////////////////////////////////////////// // Win32 API Hooks // // //////////////////////////////////////////////////////////////////////
CompareMem -
CompareStr -
CopyLeft -
CreateEvt -
CreateEvtA - --- Win32 Events Extentions

////////////////////////////////////////////////////////////////////// // Win32 Events Extentions // // //////////////////////////////////////////////////////////////////////
CreateRegKey - --- Registry Routines
DelDoubles -
DeleteLeft -
DelFC -
DelLC -
DelLeft -
DelRight -
DelSpaces -
DigitsOnly -
DisposeStr -
DoCreateProcess - utils d:\bd\source\rtl\win\windows.
ExecProcess -
ExpandFileName -
ExtractDir -
ExtractFileDir -
ExtractFileDrive -
ExtractFileExt -
ExtractFileName -
ExtractFilePath -
ExtractFileRoot - ThousandSeparator
FileExists -
FillCharSet -
FillStartupInfo -
FindExecutable -
FreeObject -
FSplit -
GetEnvVariable -
GetFileNfo -
GetFileNfoByHandle -
GetHostNameByAddr -
GetWrd -
GetWrdStrict -
GetWrdStrictUC -
GlobalFail - --- Misc tools
Hex2 -
Hex4 -
Hex8 -
Inet2addr -
InetAddr -
Int2Hex -
Int2Str -
ItoS -
ItoSz -
LastDelimiter -
LowerCase -
LowerPrec -
MakeFullDir -
MakeNormName -
Max -
MemEqu -
Min -
MonthE -
NewStr -
NulSearch -
NumBits -
OpenRegKey - Reserved
OpenRegKeyEx - ////////////////////////////////////////////////////////////////////// // Registry Routines // // //////////////////////////////////////////////////////////////////////
ProcessQuotes - --- RFC Routines
ReadRegBin -
ReadRegInt -
ReadRegString -
Replace -
SignaledEvt -
StoI -
StrEnds -
StrRight -
SysErrorMsg - ////////////////////////////////////////////////////////////////////// // Objects // // //////////////////////////////////////////////////////////////////////
uCvtSetFileTime -
uGetSystemTime -
UnpackPchars -
UnpackUchars -
UpperCase -
Vl - address got - now compare it with the real one
WaitEvt -
WaitEvtA - address of event-object name
WipeChars -
WriteRegBin - buffer size
WriteRegInt - buffer size
WriteRegString - address of disposition value buffer
XAdd -
xBaseDone -
xBaseInit -
XChg -
ZeroHandle -
_CreateFile -
_CreateFileSecurity -
_GetFileSize - Prepare 'Access' and 'Share'
_LogOK -
_Val -
__alpha -
__ctl -
__digit -
__extra -
__national -
__pchar -
__reserved -
__safe -
__uchar -
__unsafe -

Types

PBoolean
PByteArray
PCharArray
PCharSet
PFileInfo
PIntArray
PItemList
PvIntArr
TByteArray
TCharArray
TCharSet
TCreateFileMode
TCreateFileModeSet
TFileInfo
TForEachProc
TIntArray
TItemList
TListSortCompare
TObjProc
TSocketOption
TSocketOptions
TThreadMethod
TThreadPriority
TuFindData
TvIntArr

Constants

CMB_FAILED
CServerName
CServerProductName
CServerVersion
MaxCollSize
rrHiHexChar
rrLoHexChar
_INADDR_ANY

Variables

ResetterThread
SocketsColl
SocksCount
TimeZoneBias


Functions


function AddRightSpaces(const S: string; NumSpaces: Integer): string;

--- string routines

function AddrInet(i: Integer): string;

--- Winsock tools

procedure AddStr(var S: string ; C : char);


procedure Add_Str(var S: ShortString ; C : char);


function Buf2Str(const Buffer): string;

--- Basic Routines

procedure Clear(var Buf; Count: Integer);

////////////////////////////////////////////////////////////////////// // Basic Routines // // //////////////////////////////////////////////////////////////////////

function ClearHandle(var Handle: Integer): Boolean;

--- Win32 API Hooks

procedure CloseHandles(const Handles: array of Integer);

////////////////////////////////////////////////////////////////////// // Win32 API Hooks // // //////////////////////////////////////////////////////////////////////

function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;


function CompareStr(const S1, S2: string): Integer;


function CopyLeft(const S: string; I: Integer): string;


function CreateEvt(Initial: Boolean): Integer;


function CreateEvtA: Integer;

--- Win32 Events Extentions

////////////////////////////////////////////////////////////////////// // Win32 Events Extentions // // //////////////////////////////////////////////////////////////////////


function CreateRegKey(const AFName: string): Integer;

--- Registry Routines

procedure DelDoubles(const St : string;var Source : string);


procedure DeleteLeft(var S: string; I: Integer);


procedure DelFC(var s: string);


procedure DelLC(var s: string);


function DelLeft(const S: string): string;


function DelRight(const S: string): string;


function DelSpaces(const s: string): string;


function DigitsOnly(const AStr: string): Boolean;


procedure DisposeStr(P: PString);


function DoCreateProcess(const s: string; var PI: TProcessInformation): Boolean;

utils d:\bd\source\rtl\win\windows.pas d:\bd\source\rtl\win\messages.pas d:\bd\source\vcl\classes f:\xvcl\comctrls d:\bd\source\rtl\win\shellapi d:\bd\source\rtl\sys\sysutils

function ExecProcess(const Args; var PI: TProcessInformation; Env, Dir: Pointer; InheritHandles: Boolean): Boolean;


function ExpandFileName(const FileName: string): string;


function ExtractDir(const S: string): string;


function ExtractFileDir(const FileName: string): string;


function ExtractFileDrive(const FileName: string): string;


function ExtractFileExt(const FileName: string): string;


function ExtractFileName(const FileName: string): string;


function ExtractFilePath(const FileName: string): string;


function ExtractFileRoot(const FileName: string): string;

ThousandSeparator

function FileExists(const FName: string): Boolean;


procedure FillCharSet(const AStr: string; var CharSet: TCharSet);


procedure FillStartupInfo(var SI: TStartupInfo);


function FindExecutable(FileName, Directory: PChar; Result: PChar): HINST;


procedure FreeObject(var O);


procedure FSplit(const FName: string; var Path, Name, Ext: string);


function GetEnvVariable(const Name: string): string;


function GetFileNfo(const FName: string; var Info: TFileInfo; NeedAttr: Boolean): Boolean;


function GetFileNfoByHandle(Handle: Integer; var Info: TFileInfo): Boolean;


function GetHostNameByAddr(Addr: Integer): string;


procedure GetWrd(var s,w:string;c:char);


procedure GetWrdStrict(var s,w:string);


procedure GetWrdStrictUC(var s,w:string);


procedure GlobalFail;

--- Misc tools

function Hex2(a: Byte): string;


function Hex4(a: Word): string;


function Hex8(a: Integer): string;


function Inet2addr(const s: string): Integer;


function InetAddr(const s: string): Integer;


function Int2Hex(a: Integer): string;


function Int2Str(L: Integer): string;


function ItoS(I: Integer): string;


function ItoSz(I, Width: Integer): string;


function LastDelimiter(const Delimiters, S: string): Integer;


function LowerCase(const S: string): string;


procedure LowerPrec(var A, B: Integer; Bits: Byte);


function MakeFullDir(const D, S: string): string;


function MakeNormName(const Path, Name: string): string;


function Max(A, B: Integer): Integer;


function MemEqu(const A, B; Sz: Integer): Boolean;


function Min(A, B: Integer): Integer;


function MonthE(m: Integer): string;


function NewStr(const S: string): PString;


function NulSearch(const Buffer): Integer;


function NumBits(I: Integer): Integer;


function OpenRegKey(const AName: string): Integer;

Reserved

function OpenRegKeyEx(const AName: string; AMode: Integer): Integer;

////////////////////////////////////////////////////////////////////// // Registry Routines // // //////////////////////////////////////////////////////////////////////

function ProcessQuotes(var s: string): Boolean;

--- RFC Routines

function ReadRegBin(Key: Integer; const rvn: string; Bin: Pointer; Sz: Integer): Boolean;


function ReadRegInt(Key: Integer; const AStrName: string): Integer;


function ReadRegString(Key: Integer; const AStrName: string): string;


function Replace(const Pattern, ReplaceString: string; var S: string): Boolean;


function SignaledEvt(id: Integer): Boolean;


function StoI(const S: string): Integer;


function StrEnds(const S1, S2: string): Boolean;


function StrRight(const S: string; Num: Integer): string;


function SysErrorMsg(ErrorCode: Integer): string;

////////////////////////////////////////////////////////////////////// // Objects // // //////////////////////////////////////////////////////////////////////

procedure uCvtSetFileTime(T: Integer; var L, H: Integer);


function uGetSystemTime: Integer;


function UnpackPchars(var s: string): Boolean;


function UnpackUchars(var s: string): Boolean;


function UpperCase(const S: string): string;


function Vl(const s: string): Integer;

address got - now compare it with the real one

function WaitEvt(const id: TWOHandleArray; Timeout: Integer): Integer;


function WaitEvtA(nCount: Integer; lpHandles: PWOHandleArray; Timeout: Integer): Integer;

address of event-object name

function WipeChars(const AStr, AWipeChars: string): string;


function WriteRegBin(Key: Integer; const rvn: string; Bin: Pointer; Sz: Integer): Boolean;

buffer size

function WriteRegInt(Key: Integer; const AStrName: string; AValue: Integer): Boolean;

buffer size

function WriteRegString(Key: Integer; const AStrName, AStr: string): Boolean;

address of disposition value buffer

procedure XAdd(var Critical, Normal: Integer);


procedure xBaseDone;


procedure xBaseInit;


procedure XChg(var Critical, Normal: Integer);


function ZeroHandle(var Handle: Integer): Boolean;


function _CreateFile(const FName: string; Mode: TCreateFileModeSet): Integer;


function _CreateFileSecurity(const FName: string; Mode: TCreateFileModeSet; lpSecurityAttributes: PSecurityAttributes): Integer;


function _GetFileSize(const FName: string): Integer;

Prepare 'Access' and 'Share'

function _LogOK(const Name: string; var Handle: Integer): Boolean;


function _Val(const S: string; var V: Integer): Boolean;


function __alpha(c: char): Boolean;


function __ctl(c: char): Boolean;


function __digit(c: char): Boolean;


function __extra(c: char): Boolean;


function __national(c: char): Boolean;


function __pchar(c: char): Boolean;


function __reserved(c: char): Boolean;


function __safe(c: char): Boolean;


function __uchar(c: char): Boolean;


function __unsafe(c: char): Boolean;


Types


PBoolean   = ^Boolean

PByteArray = ^TByteArray

PCharArray = ^TCharArray
General arrays
PCharSet = ^TCharSet
Character set type
PFileInfo = ^TFileInfo

PIntArray = ^TIntArray

PItemList = ^TItemList

PvIntArr = ^TvIntArr

TByteArray = array[0..MaxLongInt-1] of Byte;

TCharArray = array[0..MaxLongInt-1] of Char;

TCharSet = set of Char

TCreateFileMode = (

   cRead,            // Specifies read access to the file
   cWrite,           // Specifies write access to the file

   cFlag,

   cEnsureNew,       // Creates a NEW file. The function fails
                     // if the specified file already exists.

   cTruncate,        // Once opened, the file is truncated so that
                     // its size is zero bytes.

   cExisting,        //  For communications resources, console diveces

   cShareAllowWrite,
   cShareDenyRead,

   cOverlapped,      // This flag enables more than one operation to be
                     // performed simultaneously with the handle
                     // (e.g. a simultaneous read and write operation).

   cRandomAccess,    // Indicates that the file is accessed randomly.
                     // Windows uses this flag to optimize file caching.

   cSequentialScan,  // Indicates that the file is to be accessed
                     // sequentially from beginning to end.

   cDeleteOnClose    // Indicates that the operating system is to delete
                     // the file immediately after all of its handles
                     // have been closed.

                    );

TCreateFileModeSet = set of TCreateFileMode
Indicates that the operating system is to delete the file immediately after all of its handles have been closed.
TFileInfo = record
Attr : Integer;
Size : Integer;
Time : Integer;
end;

TForEachProc = procedure(P: Pointer) of object

TIntArray = array[0..(MaxLongInt div 4)-1] of Integer;

TItemList = array[0..MaxCollSize - 1] of Pointer;

TListSortCompare = function (Item1, Item2: Pointer): Integer

TObjProc = procedure of object

TSocketOption = (soBroadcast, soDebug, soDontLinger,
                     soDontRoute, soKeepAlive, soOOBInLine,
                     soReuseAddr, soNoDelay, soBlocking, soAcceptConn);

TSocketOptions = Set of TSocketOption

TThreadMethod = procedure of object

TThreadPriority = (tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest,
    tpTimeCritical);

TuFindData = record
Info : TFileInfo;
FName : string;
end;

TvIntArr = record
Arr : PIntArray;
Cnt : Integer;
end;

Constants

CMB_FAILED = MB_APPLMODAL or MB_OK or MB_ICONSTOP

CServerName = CServerProductName+'/'+CServerVersion

CServerProductName = 'TinyWeb'{$ENDIF}

CServerVersion = '0.7'

MaxCollSize = $20000 div SizeOf(Pointer)

Maximum TColl size

rrHiHexChar = '0123456789ABCDEF'

rrLoHexChar = '0123456789abcdef'

_INADDR_ANY = INADDR_ANY


Variables

ResetterThread : TResetterThread

SocketsColl : TColl

SocksCount : Integer

TimeZoneBias : Integer