From cced118278fe1ae35993947103497596e55bb7a0 Mon Sep 17 00:00:00 2001 From: "artt.rlprojects.dev" Date: Wed, 10 Aug 2016 09:34:11 +0400 Subject: [PATCH 1/5] compatibility with XE2 --- .gitignore | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ StompClient.pas | 14 ++++++------ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8c0286 --- /dev/null +++ b/.gitignore @@ -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/ +*.~* \ No newline at end of file diff --git a/StompClient.pas b/StompClient.pas index c9b879e..7c8160d 100644 --- a/StompClient.pas +++ b/StompClient.pas @@ -533,14 +533,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 @@ -576,19 +576,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 @@ -615,7 +615,7 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame; if FreeEncoding then Encoding.Free; end; -{$ENDIF} +{$IFEND} finally Headers.Free; end; From 69240e588b28b02e3c991877ae63e4a8a093a5c9 Mon Sep 17 00:00:00 2001 From: "artt.rlprojects.dev" Date: Wed, 10 Aug 2016 09:51:11 +0400 Subject: [PATCH 2/5] [!]RLP-4504 force socket close on disconnect. Workaround for permanent 'Socket Error # 10054 Connection reset by peer' --- StompClient.pas | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/StompClient.pas b/StompClient.pas index 7c8160d..29505be 100644 --- a/StompClient.pas +++ b/StompClient.pas @@ -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; From 358f5daefbd6857035bf649da6f3fc08e0d16f1b Mon Sep 17 00:00:00 2001 From: "artt.rlprojects.dev" Date: Wed, 24 Aug 2016 21:24:00 +0400 Subject: [PATCH 3/5] =?UTF-8?q?StompUtils.CreateFrame=20hides=20STOMP=20ex?= =?UTF-8?q?ceptions=20and=20returns=20nil=20such=20exception=20may=20be=20?= =?UTF-8?q?caused=20by=20sending=20UNICODE=20message=20via=20rabbitMQ=20co?= =?UTF-8?q?nsole=20(Publish=20message=20with=20text=20"=D1=8E=D0=BD=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=B4")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StompClient.pas | 3 +++ 1 file changed, 3 insertions(+) diff --git a/StompClient.pas b/StompClient.pas index 29505be..0775095 100644 --- a/StompClient.pas +++ b/StompClient.pas @@ -652,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 From 7c13f85add3206b6b1da839fb98095324f5afeec Mon Sep 17 00:00:00 2001 From: "artt.rlprojects.dev" Date: Tue, 8 Nov 2016 15:01:40 +0400 Subject: [PATCH 4/5] =?UTF-8?q?[-]RLP-4673=20=D0=BF=D0=BE=D0=B4=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82,=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=20=D1=81=20=D0=BE=D1=81=D0=B2=D0=BE=D0=B1=D0=BE=D0=B6?= =?UTF-8?q?=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B2=20=D0=BC=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D0=B8=D1=82=D1=80=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B3=D0=B5.=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=20=D1=81=20=D0=BA=D0=BE=D0=B4=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=BE=D0=B9=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D1=86?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D1=81=D1=82=D0=BE=D0=BC=D0=BF=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StompTypes.pas | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/StompTypes.pas b/StompTypes.pas index 22d7952..78cc483 100644 --- a/StompTypes.pas +++ b/StompTypes.pas @@ -409,9 +409,13 @@ class function StompUtils.CreateFrame(Buf: string): TStompFrame; contLen := StrToInt(sContLen); other := StripLastChar(other, COMMAND_END); + {ATRLP ignore bad length if TEncoding.UTF8.GetByteCount(other) <> contLen then // there is still the command_end raise EStomp.Create('frame too short'); + } +other:= UTF8Decode(other); +// TEncoding.UTF8.UTF8. Result.Body := other; end else From fb2b41b20c25621d98c1063d3febf0bc6aa2826e Mon Sep 17 00:00:00 2001 From: "artt.rlprojects.dev" Date: Tue, 8 Nov 2016 15:26:44 +0400 Subject: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B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BC=D1=8B.=20=D0=98=20=D1=81=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StompTypes.pas | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/StompTypes.pas b/StompTypes.pas index 78cc483..aaedc0f 100644 --- a/StompTypes.pas +++ b/StompTypes.pas @@ -409,13 +409,14 @@ class function StompUtils.CreateFrame(Buf: string): TStompFrame; contLen := StrToInt(sContLen); other := StripLastChar(other, COMMAND_END); - {ATRLP ignore bad length - 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:= UTF8Decode(other); -// TEncoding.UTF8.UTF8. + } + other := UTF8ToUnicodeString(other); + // TEncoding.UTF8.UTF8. + // other:=TEncoding.UTF8.GetString(other,0,Length(other)); Result.Body := other; end else