| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // Copyright (c) 2000-2017 Ericsson Telecom AB |
| // |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // Contributors: |
| // Elemer Lelik-initial implementation |
| // |
| // |
| |
| /* |
| |
| https://stomp.github.io/stomp-specification-1.2.html |
| |
| |
| Augmented BNF |
| |
| NULL = <US-ASCII null (octet 0)> |
| LF = <US-ASCII line feed (aka newline) (octet 10)> |
| CR = <US-ASCII carriage return (octet 13)> |
| EOL = [CR] LF |
| OCTET = <any 8-bit sequence of data> |
| |
| frame-stream = 1*frame |
| |
| frame = command EOL |
| *( header EOL ) |
| EOL |
| *OCTET |
| NULL |
| *( EOL ) |
| |
| command = client-command | server-command |
| |
| client-command = "SEND" |
| | "SUBSCRIBE" |
| | "UNSUBSCRIBE" |
| | "BEGIN" |
| | "COMMIT" |
| | "ABORT" |
| | "ACK" |
| | "NACK" |
| | "DISCONNECT" |
| | "CONNECT" |
| | "STOMP" |
| |
| server-command = "CONNECTED" |
| | "MESSAGE" |
| | "RECEIPT" |
| | "ERROR" |
| |
| header = header-name ":" header-value |
| header-name = 1*<any OCTET except CR or LF or ":"> |
| header-value = *<any OCTET except CR or LF or ":"> |
| |
| */ |
| |
| |
| module STOMP_Types { |
| |
| external function enc_STOMP(in STOMPFrame frame) return charstring |
| with { extension "prototype(convert) encode(TEXT)" }; |
| external function dec_STOMP(in charstring stream) return STOMPFrame |
| with { extension "prototype(convert) decode(TEXT)" }; |
| |
| function f_enc_stomp(in STOMPFrame frame) return octetstring |
| { |
| var octetstring v_os:=char2oct(enc_STOMP(frame)); |
| v_os:=substr(v_os,0,lengthof(v_os)-2)&'000D0A'O;//cut @@ and add NULL EOL; |
| |
| //log("v_os :",v_os) |
| return v_os |
| } |
| |
| function f_dec_stomp(in octetstring stream) return STOMPFrame |
| { |
| |
| var STOMPFrame v_frame; |
| var octetstring v_os; |
| var integer v_l:=lengthof(stream); |
| |
| for(var integer i:=v_l-1;i>=0;i:=i-1) |
| |
| { |
| |
| if(stream[i]=='00'O) { |
| v_os:=substr(stream,0,i)&'4040'O;//add @ |
| }//endif |
| }//endfor |
| |
| //log("v_os :",v_os) |
| |
| v_frame:=dec_STOMP(oct2char(v_os)); |
| |
| return v_frame; |
| } |
| |
| |
| type charstring MyCharstringType ( pattern "(([\q{0,0,0,14}-9]|[;-}])#(1,))" ); |
| |
| |
| type record Header { |
| MyCharstringType header_name, |
| MyCharstringType header_value |
| }with { |
| variant "SEPARATOR(':',,)" |
| variant "END('\r\n','(\r)#(0,1)\n',)" //EOL |
| } |
| |
| |
| type record of Header Headers with { |
| variant "END('\r\n','(\r)#(0,1)\n',)" //EOL |
| } |
| |
| type record STOMPFrame { |
| |
| Command command, |
| Headers headers, |
| charstring payload optional |
| |
| }with { |
| variant "END('@@','[\q{0,0,0,64}]#(2,2)',)" |
| } |
| |
| type enumerated Command { |
| SEND, |
| SUBSCRIBE, |
| UNSUBSCRIBE, |
| BEGIN, |
| COMMIT, |
| ABORT, |
| ACK, |
| NACK, |
| DISCONNECT, |
| CONNECTED, |
| CONNECT, |
| STOMP, |
| MESSAGE, |
| RECEIPT, |
| ERROR |
| } |
| with { |
| variant "END('\r\n','(\r)#(0,1)\n',)" //EOL |
| |
| } |
| |
| }with { encode "TEXT" } |
| |
| |