%% This Source Code Form is subject to the terms of the Mozilla Public
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2026 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

%% ==========================================================================
%% ----------------------------------------------------------------------------
%% RabbitMQ Stomp Adapter
%%
%% See https://www.rabbitmq.com/stomp.html for details
%% ----------------------------------------------------------------------------

%  {rabbitmq_stomp,
%   [%% Network Configuration - the format is generally the same as for the broker

%% Listen only on localhost (ipv4 & ipv6) on a specific port.
%% {tcp_listeners, [{"127.0.0.1", 61613},
%%                  {"::1",       61613}]},

{mapping, "stomp.listeners.tcp", "rabbitmq_stomp.tcp_listeners",[
    {datatype, {enum, [none]}}
]}.

{mapping, "stomp.listeners.tcp.$name", "rabbitmq_stomp.tcp_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbitmq_stomp.tcp_listeners",
fun(Conf) ->
    case cuttlefish:conf_get("stomp.listeners.tcp", Conf, undefined) of
        none -> [];
        _ ->
            Settings = cuttlefish_variable:filter_by_prefix("stomp.listeners.tcp", Conf),
            [ V || {_, V} <- Settings ]
    end
end}.

{include_partial, {rabbit, "tcp_listen_options"},
    [{prefix, "stomp.tcp_listen_options"},
     {app_prefix, "rabbitmq_stomp.tcp_listen_options"},
     {disable_with, none}]}.


%%
%% TLS
%%

{mapping, "stomp.listeners.ssl", "rabbitmq_stomp.ssl_listeners",[
    {datatype, {enum, [none]}}
]}.

{mapping, "stomp.listeners.ssl.$name", "rabbitmq_stomp.ssl_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbitmq_stomp.ssl_listeners",
fun(Conf) ->
    case cuttlefish:conf_get("stomp.listeners.ssl", Conf, undefined) of
        none -> [];
        _ ->
            Settings = cuttlefish_variable:filter_by_prefix("stomp.listeners.ssl", Conf),
            [ V || {_, V} <- Settings ]
    end
end}.

%% Number of Erlang processes that will accept connections for the TCP
%% and SSL listeners.
%%
%% {num_tcp_acceptors, 10},
%% {num_ssl_acceptors, 10},

{mapping, "stomp.num_acceptors.ssl", "rabbitmq_stomp.num_ssl_acceptors", [
    {datatype, integer}
]}.

{mapping, "stomp.num_acceptors.tcp", "rabbitmq_stomp.num_tcp_acceptors", [
    {datatype, integer}
]}.

%% Additional TLS options

%% Extract a name from the client's certificate when using TLS.
%%
%% Defaults to true.

{mapping, "stomp.ssl_cert_login", "rabbitmq_stomp.ssl_cert_login",
    [{datatype, boolean}]}.

%% Set a default user name and password. This is used as the default login
%% whenever a CONNECT frame omits the login and passcode headers.
%%
%% Please note that setting this will allow clients to connect without
%% authenticating!
%%
%% {default_user, [{login,    "guest"},
%%                 {passcode, "guest"}]},

{mapping, "stomp.default_vhost", "rabbitmq_stomp.default_vhost", [
    {datatype, string}
]}.

{translation, "rabbitmq_stomp.default_vhost",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("stomp.default_vhost", Conf, "/"))
end}.

{mapping, "stomp.default_user", "rabbitmq_stomp.default_user.login", [
    {datatype, string}
]}.

{mapping, "stomp.default_pass", "rabbitmq_stomp.default_user.passcode", [
    {datatype, [tagged_binary, binary]}
]}.

{mapping, "stomp.default_topic_exchange", "rabbitmq_stomp.default_topic_exchange", [
    {datatype, string}
]}.

{translation, "rabbitmq_stomp.default_topic_exchange",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("stomp.default_topic_exchange", Conf, "amq.topic"))
end}.

%% If a default user is configured, or if x.509
%% certificate-based client authentication is used, use this setting to allow clients to
%% omit the CONNECT frame entirely. If set to true, the client is
%% automatically connected as the default user or user supplied in the
%% x.509/TLS certificate whenever the first frame sent on a session is not a
%% CONNECT frame.
%%
%% Defaults to true.

{mapping, "stomp.implicit_connect", "rabbitmq_stomp.implicit_connect",
    [{datatype, boolean}]}.

{mapping, "stomp.login_timeout", "rabbitmq_stomp.login_timeout",
    [{datatype, {integer, non_negative}}]}.

%% Whether or not to enable proxy protocol support.
%%
%% Defaults to false.

{mapping, "stomp.proxy_protocol", "rabbitmq_stomp.proxy_protocol",
    [{datatype, boolean}]}.

%% Whether or not to hide server info
%%
%% Defaults to false.

{mapping, "stomp.hide_server_info", "rabbitmq_stomp.hide_server_info",
    [{datatype, boolean}]}.

%% Whether or not to always requeue the message on nack
%% If not set then coordinated by the usage of the frame "requeue" header
%% Useful when you are not fully controlling the STOMP consumer implementation
%%
%% Defaults to true.

{mapping, "stomp.default_nack_requeue", "rabbitmq_stomp.default_nack_requeue",
    [{datatype, boolean}]}.



%% Maximum frame size.
%%
%% Defaults to 192Kb.

{mapping, "stomp.max_frame_size", "rabbitmq_stomp.max_frame_size",
    [{datatype, {integer, non_negative}}]}.

{mapping, "stomp.max_frame_size_unauthenticated", "rabbitmq_stomp.max_frame_size_unauthenticated",
    [{datatype, {integer, positive}}]}.
