diff options
author | Vlad Alexandru Ionescu <vlad@rabbitmq.com> | 2011-01-22 01:34:35 +0000 |
---|---|---|
committer | Vlad Alexandru Ionescu <vlad@rabbitmq.com> | 2011-01-22 01:34:35 +0000 |
commit | 94420112db50c0db6408bb9bccd1ca84f38c083e (patch) | |
tree | 7170755b7a406c1ad24296f61e67e10a7d9f0405 | |
parent | 9af87d4f2762ea8652dec8eb42d1c751d5028556 (diff) | |
download | rabbitmq-server-94420112db50c0db6408bb9bccd1ca84f38c083e.tar.gz |
adding rabbit_direct:connect/3 for the erlang client to use
-rw-r--r-- | src/rabbit_direct.erl | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/rabbit_direct.erl b/src/rabbit_direct.erl index 6b829abf..1bb5e5ce 100644 --- a/src/rabbit_direct.erl +++ b/src/rabbit_direct.erl @@ -16,7 +16,7 @@ -module(rabbit_direct). --export([boot/0, start_channel/5]). +-export([boot/0, connect/3, start_channel/5]). -include("rabbit.hrl"). @@ -25,6 +25,9 @@ -ifdef(use_specs). -spec(boot/0 :: () -> 'ok'). +-spec(connect/3 :: (binary(), binary(), binary()) -> + {'ok', {rabbit_types:user(), + rabbit_framing:amqp_table()}}). -spec(start_channel/5 :: (rabbit_channel:channel_number(), pid(), rabbit_types:user(), rabbit_types:vhost(), pid()) -> {'ok', pid()}). @@ -44,6 +47,25 @@ boot() -> transient, infinity, supervisor, [rabbit_client_sup]}), ok. +%%---------------------------------------------------------------------------- + +connect(Username, Password, VHost) -> + case lists:keymember(rabbit, 1, application:which_applications()) of + true -> ok; + false -> exit(broker_not_found_in_vm) + end, + User = try rabbit_access_control:user_pass_login(Username, Password) of + #user{} = User1 -> User1 + catch + exit:#amqp_error{name = access_refused} -> exit(auth_failure) + end, + try rabbit_access_control:check_vhost_access(User, VHost) of + ok -> ok + catch + exit:#amqp_error{name = access_refused} -> exit(access_refused) + end, + {ok, {User, rabbit_reader:server_properties()}}. + start_channel(Number, ClientChannelPid, User, VHost, Collector) -> {ok, _, {ChannelPid, _}} = supervisor2:start_child( |