emqx_stomp.hrl 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -ifndef(EMQX_STOMP_HRL).
  17. -define(EMQX_STOMP_HRL, true).
  18. -define(STOMP_VER, <<"1.2">>).
  19. -define(STOMP_SERVER, <<"emqx-stomp/1.2">>).
  20. %%--------------------------------------------------------------------
  21. %% STOMP Frame
  22. %%--------------------------------------------------------------------
  23. %% client command
  24. -define(CMD_STOMP, <<"STOMP">>).
  25. -define(CMD_CONNECT, <<"CONNECT">>).
  26. -define(CMD_SEND, <<"SEND">>).
  27. -define(CMD_SUBSCRIBE, <<"SUBSCRIBE">>).
  28. -define(CMD_UNSUBSCRIBE, <<"UNSUBSCRIBE">>).
  29. -define(CMD_BEGIN, <<"BEGIN">>).
  30. -define(CMD_COMMIT, <<"COMMIT">>).
  31. -define(CMD_ABORT, <<"ABORT">>).
  32. -define(CMD_ACK, <<"ACK">>).
  33. -define(CMD_NACK, <<"NACK">>).
  34. -define(CMD_DISCONNECT, <<"DISCONNECT">>).
  35. %% server command
  36. -define(CMD_CONNECTED, <<"CONNECTED">>).
  37. -define(CMD_MESSAGE, <<"MESSAGE">>).
  38. -define(CMD_RECEIPT, <<"RECEIPT">>).
  39. -define(CMD_ERROR, <<"ERROR">>).
  40. -define(CMD_HEARTBEAT, <<"HEARTBEAT">>).
  41. %-type client_command() :: ?CMD_SEND | ?CMD_SUBSCRIBE | ?CMD_UNSUBSCRIBE
  42. % | ?CMD_BEGIN | ?CMD_COMMIT | ?CMD_ABORT | ?CMD_ACK
  43. % | ?CMD_NACK | ?CMD_DISCONNECT | ?CMD_CONNECT
  44. % | ?CMD_STOMP.
  45. %
  46. -type client_command() :: binary().
  47. %-type server_command() :: ?CMD_CONNECTED | ?CMD_MESSAGE | ?CMD_RECEIPT
  48. % | ?CMD_ERROR.
  49. -type server_command() :: binary().
  50. -record(stomp_frame, {
  51. command :: client_command() | server_command(),
  52. headers = [],
  53. body = <<>> :: iodata()
  54. }).
  55. -type stomp_frame() :: #stomp_frame{}.
  56. -define(PACKET(CMD), #stomp_frame{command = CMD}).
  57. -define(PACKET(CMD, Headers), #stomp_frame{command = CMD, headers = Headers}).
  58. -define(PACKET(CMD, Headers, Body), #stomp_frame{
  59. command = CMD,
  60. headers = Headers,
  61. body = Body
  62. }).
  63. %%--------------------------------------------------------------------
  64. %% Frame Size Limits
  65. %%
  66. %% To prevent malicious clients from exploiting memory allocation in a server,
  67. %% servers MAY place maximum limits on:
  68. %%
  69. %% the number of frame headers allowed in a single frame
  70. %% the maximum length of header lines
  71. %% the maximum size of a frame body
  72. %%
  73. %% If these limits are exceeded the server SHOULD send the client an ERROR frame
  74. %% and then close the connection.
  75. %%--------------------------------------------------------------------
  76. -define(MAX_HEADER_NUM, 10).
  77. -define(MAX_HEADER_LENGTH, 1024).
  78. -define(MAX_BODY_LENGTH, 65536).
  79. -endif.