Skip to content
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Uncomment these types if you want even more clean repository. But be careful.
# It can make harm to an existing project source. Read explanations below.
#
# Resource files are binaries containing manifest, project icon and version info.
# They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
*.res
*.dres
#
# Type library file (binary). In old Delphi versions it should be stored.
# Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
#*.tlb
#
# Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
# Uncomment this if you are not using diagrams or use newer Delphi version.
#*.ddp
#
# Visual LiveBindings file. Added in Delphi XE2.
# Uncomment this if you are not using LiveBindings Designer.
#*.vlb
#
# Deployment Manager configuration file for your project. Added in Delphi XE2.
# Uncomment this if it is not mobile development and you do not use remote debug feature.
#*.deployproj
#
# Delphi compiler-generated binaries (safe to delete)
*.exe
*.dll
*.bpl
*.bpi
*.dcp
*.so
*.apk
*.drc
*.map
*.dres
*.rsm
*.tds
*.dcu
*.lib

#3rd party
*.skincfg
*.vrc

# Delphi autogenerated files (duplicated info)
*.cfg
*Resource.rc
# Delphi local files (user-specific info)
*.local
*.identcache
*.projdata
*.tvsconfig
*.dsk
*.todo
# Delphi history and backups
__history/
*.~*
60 changes: 43 additions & 17 deletions StompClient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -340,22 +340,45 @@ procedure TStompClient.Disconnect;
var
Frame: IStompFrame;
begin
if Connected then
begin
Frame := TStompFrame.Create;
Frame.SetCommand('DISCONNECT');
SendFrame(Frame);
try
if Connected then
begin

try
Frame := TStompFrame.Create;
Frame.SetCommand('DISCONNECT');
SendFrame(Frame);
except
on E: EIdException do
begin
{$IFDEF USESYNAPSE}
FSynapseTCP.CloseSocket;
FSynapseConnected := False;

// nop
{$ELSE}
FTCP.Disconnect;
FTCP.Socket.Close;
{$ENDIF}
raise;
end;
end;

{$IFDEF USESYNAPSE}
FSynapseTCP.CloseSocket;
FSynapseConnected := False;

{$ELSE}
try
FTCP.Disconnect;
except
on E: EIdException do
begin
FTCP.Socket.Close;
raise;
end;
end;
{$ENDIF}
end;
finally
DeInit;
end;
DeInit;
end;

function TStompClient.FormatErrorFrame(const AErrorFrame: IStompFrame): string;
Expand Down Expand Up @@ -533,14 +556,14 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame;
FreeEncoding: boolean;
{$ELSE}
Encoding: IIdTextEncoding;
{$ENDIF}
{$IFEND}
begin
Result := nil;
lSBuilder := TStringBuilder.Create(1024 * 4);
try
FTCP.Socket.ReadTimeout := ATimeout;
FTCP.Socket.DefStringEncoding :=
{$IF CompilerVersion < 24}TIdTextEncoding.UTF8{$ELSE}IndyTextEncoding_UTF8{$ENDIF};
{$IF CompilerVersion < 24}TIdTextEncoding.UTF8{$ELSE}IndyTextEncoding_UTF8{$IFEND};

try
// read command line
Expand Down Expand Up @@ -576,19 +599,19 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame;
Encoding := CharsetToEncoding(Charset);
{$IF CompilerVersion < 24}
FreeEncoding := True;
{$ENDIF}
{$IFEND}
end
else
begin
Encoding := IndyTextEncoding_8Bit();
Encoding := Indy8BitEncoding;
{$IF CompilerVersion < 24}
FreeEncoding := False;
{$ENDIF}
{$IFEND}
end;

{$IF CompilerVersion < 24}
try
{$ENDIF}
{$IFEND}
if Headers.IndexOfName('content-length') <> -1 then
begin
// length specified, read exactly that many bytes
Expand All @@ -615,7 +638,7 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame;
if FreeEncoding then
Encoding.Free;
end;
{$ENDIF}
{$IFEND}
finally
Headers.Free;
end;
Expand All @@ -629,6 +652,9 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame;
end;
end;
Result := StompUtils.CreateFrame(lSBuilder.toString);
// ATRLP: StompUtils.CreateFrame hides STOMP exceptions and returns nil
if Result = nil then
Exit;
if Result.GetCommand = 'ERROR' then
raise EStomp.Create(FormatErrorFrame(Result));
finally
Expand Down
7 changes: 6 additions & 1 deletion StompTypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,14 @@ class function StompUtils.CreateFrame(Buf: string): TStompFrame;
contLen := StrToInt(sContLen);
other := StripLastChar(other, COMMAND_END);

if TEncoding.UTF8.GetByteCount(other) <> contLen then
{ ATRLP ignore bad length
if TEncoding.UTF8.GetByteCount(other) <> contLen then
// there is still the command_end
raise EStomp.Create('frame too short');
}
other := UTF8ToUnicodeString(other);
// TEncoding.UTF8.UTF8.
// other:=TEncoding.UTF8.GetString(other,0,Length(other));
Result.Body := other;
end
else
Expand Down