19
19
-export([init/1, resource_exists/2, to_json/2,
20
20
content_types_provided/2, content_types_accepted/2,
21
is_authorized/2, allowed_methods/2, accept_content/2,
21
is_authorized/2, allowed_methods/2, delete_resource/2,
24
24
-include("rabbit_mgmt.hrl").
25
25
-include_lib("webmachine/include/webmachine.hrl").
35
35
{[{"application/json", accept_content}], ReqData, Context}.
37
37
allowed_methods(ReqData, Context) ->
38
{['HEAD', 'GET', 'PUT', 'DELETE'], ReqData, Context}.
38
{['HEAD', 'GET', 'DELETE'], ReqData, Context}.
40
40
resource_exists(ReqData, Context) ->
41
41
Binding = binding(ReqData),
59
accept_content(ReqData, Context) ->
60
MethodName = case rabbit_mgmt_util:destination_type(ReqData) of
61
exchange -> 'exchange.bind';
64
sync_resource(MethodName, ReqData, Context).
66
59
delete_resource(ReqData, Context) ->
67
60
MethodName = case rabbit_mgmt_util:destination_type(ReqData) of
68
61
exchange -> 'exchange.unbind';
82
75
Dest = rabbit_mgmt_util:id(destination, ReqData),
83
76
DestType = rabbit_mgmt_util:destination_type(ReqData),
84
77
Props = rabbit_mgmt_util:id(props, ReqData),
85
case rabbit_mgmt_format:unpack_binding_props(Props) of
78
SName = rabbit_misc:r(VHost, exchange, Source),
79
DName = rabbit_misc:r(VHost, DestType, Dest),
80
case unpack(SName, DName, Props) of
86
81
{bad_request, Str} ->
87
82
{bad_request, Str};
89
SName = rabbit_misc:r(VHost, exchange, Source),
90
DName = rabbit_misc:r(VHost, DestType, Dest),
91
84
#binding{ source = SName,
92
85
destination = DName,
91
unpack(Src, Dst, Props) ->
92
case rabbit_mgmt_format:tokenise(binary_to_list(Props)) of
94
[Key] -> {unquote(Key), []};
95
["~", ArgsEnc] -> lookup(<<>>, ArgsEnc, Src, Dst);
96
[Key, ArgsEnc] -> lookup(unquote(Key), ArgsEnc, Src, Dst);
97
_ -> {bad_request, {too_many_tokens, Props}}
100
lookup(RoutingKey, ArgsEnc, Src, Dst) ->
101
lookup(RoutingKey, unquote(ArgsEnc),
102
rabbit_binding:list_for_source_and_destination(Src, Dst)).
104
lookup(_RoutingKey, _Hash, []) ->
105
{bad_request, "binding not found"};
106
lookup(RoutingKey, Hash, [#binding{args = Args} | Rest]) ->
107
case args_hash(Args) =:= Hash of
108
true -> {RoutingKey, Args};
109
false -> lookup(RoutingKey, Hash, Rest)
113
list_to_binary(rabbit_misc:base64url(erlang:md5(term_to_binary(Args)))).
116
list_to_binary(mochiweb_util:unquote(Name)).
98
118
with_binding(ReqData, Context, Fun) ->
99
119
case binding(ReqData) of
100
120
{bad_request, Reason} ->