1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
%% 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-2020 VMware, Inc. or its affiliates. All rights reserved.
%%
-module(rabbit_amqp1_0_link_util).
-include_lib("amqp_client/include/amqp_client.hrl").
-include("rabbit_amqp1_0.hrl").
-export([outcomes/1, ctag_to_handle/1, handle_to_ctag/1, durable/1]).
-define(EXCHANGE_SUB_LIFETIME, "delete-on-close").
-define(DEFAULT_OUTCOME, #'v1_0.released'{}).
-define(SUPPORTED_OUTCOMES, [?V_1_0_SYMBOL_ACCEPTED,
?V_1_0_SYMBOL_REJECTED,
?V_1_0_SYMBOL_RELEASED]).
-define(OUTCOMES, [?V_1_0_SYMBOL_ACCEPTED,
?V_1_0_SYMBOL_REJECTED,
?V_1_0_SYMBOL_RELEASED,
?V_1_0_SYMBOL_MODIFIED]).
outcomes(Source) ->
{DefaultOutcome, Outcomes} =
case Source of
#'v1_0.source' {
default_outcome = DO,
outcomes = Os
} ->
DO1 = case DO of
undefined -> ?DEFAULT_OUTCOME;
_ -> DO
end,
Os1 = case Os of
undefined -> ?SUPPORTED_OUTCOMES;
{array, symbol, Syms} -> Syms;
Bad1 -> rabbit_amqp1_0_util:protocol_error(
?V_1_0_AMQP_ERROR_NOT_IMPLEMENTED,
"Outcomes not supported: ~p",
[Bad1])
end,
{DO1, Os1};
_ ->
{?DEFAULT_OUTCOME, ?SUPPORTED_OUTCOMES}
end,
case [O || O <- Outcomes, not lists:member(O, ?OUTCOMES)] of
[] -> {DefaultOutcome, {array, symbol, Outcomes}};
Bad -> rabbit_amqp1_0_util:protocol_error(
?V_1_0_AMQP_ERROR_NOT_IMPLEMENTED,
"Outcomes not supported: ~p", [Bad])
end.
handle_to_ctag({uint, H}) ->
<<"ctag-", H:32/integer>>.
ctag_to_handle(<<"ctag-", H:32/integer>>) ->
{uint, H}.
durable(undefined) -> false; %% default: none
durable(?V_1_0_TERMINUS_DURABILITY_NONE) -> false;
%% This one means "existence of the thing is durable, but unacked msgs
%% aren't". We choose to upgrade that.
durable(?V_1_0_TERMINUS_DURABILITY_CONFIGURATION) -> true;
durable(?V_1_0_TERMINUS_DURABILITY_UNSETTLED_STATE) -> true.
|