Skip to content

Commit

Permalink
fixed for Delphi/Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
DmBel committed Nov 22, 2022
1 parent 699c110 commit 0c7bbb9
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 100 deletions.
22 changes: 15 additions & 7 deletions SynHttpSrv.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1068,20 +1068,26 @@ procedure TryDecodeUtf8(var Url: string);
procedure TryDecodeUtf8(var Url: string);
var S: string;
begin
S:=UTF8ToString(Url); // returns empty, if not valid Utf8...
S:=UTF8ToString(RawByteString(Url)); // returns empty, if not valid Utf8...
if (S<>'') then
Url:=S;
end;
{$endif}

function ValHex(const S: string; var Value: integer): boolean;
function ValHex(const S: AnsiString; var Value: integer): boolean;
var
code: integer;
begin
Val('$' + S, Value, Code);
Val('$' + string(S), Value, Code);
Result := Code = 0;
end;

function AnsiCopy(const s: ansistring; StartIndex, Lenght: integer): ansistring;
begin
SetLength(Result, Lenght);
Move(s[StartIndex], Result[1], Lenght);
end;

function ConvertUrlChars(Url: string): string;
var
p, len, code: integer;
Expand All @@ -1102,7 +1108,7 @@ function ConvertUrlChars(Url: string): string;
while (p <= len) do
begin
if (buff[p] = '%') then
if ValHex(Copy(string(buff), p + 1, 2), code) then
if ValHex(AnsiCopy(buff, p + 1, 2), code) then
begin
Delete(buff, p + 1, 2);
Dec(len, 2);
Expand Down Expand Up @@ -2156,6 +2162,7 @@ procedure RegisterInternalContentTypes;
RegisterContentType('.bmp', 'image/bmp');
RegisterContentType('.htc', 'text/x-component');
RegisterContentType('.js', 'text/javascript');
RegisterContentType('.pdf', 'application/pdf');
end;

function GetContentTypeByExt(const Ext: string): string;
Expand Down Expand Up @@ -2822,7 +2829,8 @@ procedure TSynHttpServer.ReadRequest(Connection: TSynTcpSrvConnection; Request,

function PreparePostStream: boolean;
var
i, Size: integer;
i: integer;
Size: int64;
begin
Result := False;
if (Request.TransferEncoding <> '') and (not SameText(Request.TransferEncoding, 'identity')) then
Expand All @@ -2845,7 +2853,7 @@ procedure TSynHttpServer.ReadRequest(Connection: TSynTcpSrvConnection; Request,
i := Pos(';', S); {do not localize}
if i > 0 then
S := Copy(S, 1, i - 1);
Size := StrToIntDef('$' + Trim(S), 0); {do not localize}
Size := StrToInt64Def('$' + Trim(S), 0); {do not localize}
if Size = 0 then
Break;
Connection.Socket.RecvStreamSize(Request.PostStream, cDefLineTimeout, Size);
Expand All @@ -2864,7 +2872,7 @@ procedure TSynHttpServer.ReadRequest(Connection: TSynTcpSrvConnection; Request,
Request.PostStream.Position := 0;
if Request.ContentLength > '0' then
begin
Size := StrToIntDef(Request.ContentLength, 0);
Size := StrToInt64Def(Request.ContentLength, 0);
Connection.Socket.RecvStreamSize(Request.PostStream, cDefLineTimeout, Size);
Request.PostStream.Position := 0;
end;
Expand Down
60 changes: 30 additions & 30 deletions blcksock.pas
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ TBlockSocket = class(TObject)
FNonBlockMode: Boolean;
FMaxLineLength: Integer;
FMaxSendBandwidth: Integer;
FNextSend: LongWord;
FNextSend: FixedUInt;
FMaxRecvBandwidth: Integer;
FNextRecv: LongWord;
FNextRecv: FixedUInt;
FConvertLineEnd: Boolean;
FLastCR: Boolean;
FLastLF: Boolean;
Expand All @@ -339,9 +339,9 @@ TBlockSocket = class(TObject)
{$IFNDEF CIL}
FFDSet: TFDSet;
{$ENDIF}
FRecvCounter: Integer;
FSendCounter: Integer;
FSendMaxChunk: Integer;
FRecvCounter: int64;
FSendCounter: int64;
FSendMaxChunk: int64;
FStopFlag: Boolean;
FNonblockSendTimeout: Integer;
FHeartbeatRate: integer;
Expand Down Expand Up @@ -377,7 +377,7 @@ TBlockSocket = class(TObject)
procedure DoMonitor(Writing: Boolean; const Buffer: TMemory; Len: Integer);
procedure DoCreateSocket;
procedure DoHeartbeat;
procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: LongWord);
procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
procedure SetBandwidth(Value: Integer);
function TestStopFlag: Boolean;
procedure InternalSendStream(const Stream: TStream; WithSize, Indy: boolean); virtual;
Expand Down Expand Up @@ -575,7 +575,7 @@ TBlockSocket = class(TObject)
occured.)}
procedure RecvStreamRaw(const Stream: TStream; Timeout: Integer); virtual;
{:Read requested count of bytes from socket to stream.}
procedure RecvStreamSize(const Stream: TStream; Timeout: Integer; Size: Integer);
procedure RecvStreamSize(const Stream: TStream; Timeout: Integer; Size: int64);

{:Receive data to stream. It using @link(RecvBlock) method.}
procedure RecvStream(const Stream: TStream; Timeout: Integer); virtual;
Expand Down Expand Up @@ -798,11 +798,11 @@ TBlockSocket = class(TObject)

{:Return count of received bytes on this socket from begin of current
connection.}
property RecvCounter: Integer read FRecvCounter;
property RecvCounter: int64 read FRecvCounter;

{:Return count of sended bytes on this socket from begin of current
connection.}
property SendCounter: Integer read FSendCounter;
property SendCounter: int64 read FSendCounter;
published
{:Return descriptive string for given error code. This is class function.
You may call it without created object!}
Expand Down Expand Up @@ -861,7 +861,7 @@ TBlockSocket = class(TObject)
property InterPacketTimeout: Boolean read FInterPacketTimeout Write FInterPacketTimeout;

{:All sended datas was splitted by this value.}
property SendMaxChunk: Integer read FSendMaxChunk Write FSendMaxChunk;
property SendMaxChunk: int64 read FSendMaxChunk Write FSendMaxChunk;

{:By setting this property to @true you can stop any communication. You can
use this property for soft abort of communication.}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ TDgramBlockSocket = class(TSocksBlockSocket)

{:Silently redirected to @link(TBlockSocket.RecvBufferFrom).}
function RecvBuffer(Buffer: TMemory; Length: Integer): Integer; override;

{:Specify if connect should called on the underlying socket.}
property UseConnect: Boolean read FUseConnect Write FUseConnect;
end;
Expand Down Expand Up @@ -1509,9 +1509,9 @@ TIPHeader = record
TTL: Byte;
Protocol: Byte;
CheckSum: Word;
SourceIp: LongWord;
DestIp: LongWord;
Options: LongWord;
SourceIp: FixedUInt;
DestIp: FixedUInt;
Options: FixedUInt;
end;

{:@abstract(Parent class of application protocol implementations.)
Expand Down Expand Up @@ -1649,9 +1649,9 @@ destructor TBlockSocket.Destroy;
for n := FDelayedOptions.Count - 1 downto 0 do
begin
p := TSynaOption(FDelayedOptions[n]);
p.Free;
FreeAndNil(p);
end;
FDelayedOptions.Free;
FreeAndNil(FDelayedOptions);
inherited Destroy;
end;

Expand All @@ -1673,7 +1673,7 @@ procedure TBlockSocket.SetDelayedOption(const Value: TSynaOption);
x: integer;
buf: TMemory;
{$IFNDEF MSWINDOWS}
{$IFNDEF ULTIBO}
{$IFNDEF ULTIBO}
timeval: TTimeval;
{$ENDIF}
{$ENDIF}
Expand Down Expand Up @@ -1850,7 +1850,7 @@ procedure TBlockSocket.SetDelayedOption(const Value: TSynaOption);
ExceptCheck;
end;
end;
Value.free;
FreeAndNil(Value);
end;

procedure TBlockSocket.DelayedOption(const Value: TSynaOption);
Expand Down Expand Up @@ -1999,7 +1999,7 @@ procedure TBlockSocket.AbortSocket;
for n := FDelayedOptions.Count - 1 downto 0 do
begin
p := TSynaOption(FDelayedOptions[n]);
p.Free;
FreeAndNil(p);
end;
FDelayedOptions.Clear;
FFamily := FFamilySave;
Expand Down Expand Up @@ -2104,10 +2104,10 @@ procedure TBlockSocket.SetBandwidth(Value: Integer);
MaxRecvBandwidth := Value;
end;

procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: LongWord);
procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
var
x: LongWord;
y: LongWord;
x: FixedUInt;
y: FixedUInt;
n: integer;
begin
if FStopFlag then
Expand Down Expand Up @@ -2255,7 +2255,7 @@ procedure TBlockSocket.SendBlock(const Data: string);

procedure TBlockSocket.InternalSendStream(const Stream: TStream; WithSize, Indy: boolean);
var
l: integer;
l: int64;
yr: integer;
s: string;
b: boolean;
Expand Down Expand Up @@ -2347,7 +2347,7 @@ function TBlockSocket.RecvBufferEx(Buffer: TMemory; Len: Integer;
var
s: TSynaBytes;
rl, l: integer;
ti: LongWord;
ti: FixedUInt;
{$IFDEF CIL}
n: integer;
b: TMemory;
Expand Down Expand Up @@ -2520,7 +2520,7 @@ function TBlockSocket.RecvTerminated(Timeout: Integer; const Terminator: string)
CorCRLF: Boolean;
t: string;
tl: integer;
ti: LongWord;
ti: FixedUInt;
begin
ResetLastError;
Result := '';
Expand Down Expand Up @@ -2611,7 +2611,7 @@ procedure TBlockSocket.RecvStreamRaw(const Stream: TStream; Timeout: Integer);
until FLastError <> 0;
end;

procedure TBlockSocket.RecvStreamSize(const Stream: TStream; Timeout: Integer; Size: Integer);
procedure TBlockSocket.RecvStreamSize(const Stream: TStream; Timeout: Integer; Size: int64);
var
s: TSynaBytes;
n: integer;
Expand Down Expand Up @@ -2835,7 +2835,7 @@ function TBlockSocket.ResolveName(const Name: string): string;
ResolveNameToIP(Name, l);
Result := l[0];
finally
l.Free;
FreeAndNil(l);
end;
end;

Expand Down Expand Up @@ -3731,7 +3731,7 @@ procedure TDgramBlockSocket.Connect(const IP, Port: string);
SockCheck(synsock.Connect(FSocket, FRemoteSin));
if FLastError = 0 then
GetSins;
end;
end;
FBuffer := '';
DoStatus(HR_Connect, IP + ':' + Port);
end;
Expand All @@ -3751,7 +3751,7 @@ function TDgramBlockSocket.SendBuffer(const Buffer: TMemory; Length: Integer): I
destructor TUDPBlockSocket.Destroy;
begin
if Assigned(FSocksControlSock) then
FSocksControlSock.Free;
FreeAndNil(FSocksControlSock);
inherited;
end;

Expand Down Expand Up @@ -3983,7 +3983,7 @@ constructor TTCPBlockSocket.Create;
destructor TTCPBlockSocket.Destroy;
begin
inherited Destroy;
FSSL.Free;
FreeAndNil(FSSL);
end;

function TTCPBlockSocket.GetErrorDescEx: string;
Expand Down
12 changes: 6 additions & 6 deletions ssfpc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ type
sin_addr: TInAddr;
sin_zero: array[0..7] of Char);
AF_INET6: (sin6_port: word;
sin6_flowinfo: longword;
sin6_flowinfo: FixedUInt;
sin6_addr: TInAddr6;
sin6_scope_id: longword);
sin6_scope_id: FixedUInt);
);
end;

Expand All @@ -390,11 +390,11 @@ function SizeOfVarSin(sin: TVarSin): integer;
function SendTo(s: TSocket; Buf: TMemory; len, flags: Integer; addrto: TVarSin): Integer;
function RecvFrom(s: TSocket; Buf: TMemory; len, flags: Integer; var from: TVarSin): Integer;
function ntohs(netshort: word): word;
function ntohl(netlong: longword): longword;
function ntohl(netlong: FixedUInt): FixedUInt;
function Listen(s: TSocket; backlog: Integer): Integer;
function IoctlSocket(s: TSocket; cmd: DWORD; var arg: integer): Integer;
function htons(hostshort: word): word;
function htonl(hostlong: longword): longword;
function htonl(hostlong: FixedUInt): FixedUInt;
function GetSockName(s: TSocket; var name: TVarSin): Integer;
function GetPeerName(s: TSocket; var name: TVarSin): Integer;
function Connect(s: TSocket; const name: TVarSin): Integer;
Expand Down Expand Up @@ -617,7 +617,7 @@ begin
Result := sockets.ntohs(NetShort);
end;

function ntohl(netlong: longword): longword;
function ntohl(netlong: FixedUInt): FixedUInt;
begin
Result := sockets.ntohl(NetLong);
end;
Expand All @@ -640,7 +640,7 @@ begin
Result := sockets.htons(Hostshort);
end;

function htonl(hostlong: longword): longword;
function htonl(hostlong: FixedUInt): FixedUInt;
begin
Result := sockets.htonl(HostLong);
end;
Expand Down
1 change: 0 additions & 1 deletion ssl_openssl_lib.pas
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ interface
BaseUnix,
{$ENDIF UNIX}
{$ELSE}
Libc,
{$ENDIF}
SysUtils;
{$ELSE}
Expand Down
4 changes: 2 additions & 2 deletions sslinux.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const

type
DWORD = Integer;
__fd_mask = LongWord;
__fd_mask = FixedUInt;
const
__FD_SETSIZE = 1024;
__NFDBITS = 8 * sizeof(__fd_mask);
Expand Down Expand Up @@ -731,7 +731,7 @@ end;

function __FDMASK(Socket: TSocket): __fd_mask;
begin
Result := LongWord(1) shl (Socket mod __NFDBITS);
Result := FixedUInt(1) shl (Socket mod __NFDBITS);
end;

function FD_ISSET(Socket: TSocket; var fdset: TFDSet): Boolean;
Expand Down
Loading

0 comments on commit 0c7bbb9

Please sign in to comment.