summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Alexandru Ionescu <vlad@rabbitmq.com>2011-01-22 01:37:53 +0000
committerVlad Alexandru Ionescu <vlad@rabbitmq.com>2011-01-22 01:37:53 +0000
commit37692ccb4afc9545807ff438ebae8d3d83602e40 (patch)
treed719238a3a0bce9431860456479a75c2b979ae40
parent0608720d495472f31067f5af7f148e8bff4158d7 (diff)
parent94420112db50c0db6408bb9bccd1ca84f38c083e (diff)
downloadrabbitmq-server-37692ccb4afc9545807ff438ebae8d3d83602e40.tar.gz
merging bug23696's two heads
-rw-r--r--src/rabbit_client_sup.erl15
-rw-r--r--src/rabbit_direct.erl24
2 files changed, 38 insertions, 1 deletions
diff --git a/src/rabbit_client_sup.erl b/src/rabbit_client_sup.erl
index 336a8cd7..dbdc6cd4 100644
--- a/src/rabbit_client_sup.erl
+++ b/src/rabbit_client_sup.erl
@@ -22,6 +22,21 @@
-export([init/1]).
+-include("rabbit.hrl").
+
+%%----------------------------------------------------------------------------
+
+-ifdef(use_specs).
+
+-spec(start_link/1 :: (mfa()) ->
+ rabbit_types:ok_pid_or_error()).
+-spec(start_link/2 :: ({'local', atom()}, mfa()) ->
+ rabbit_types:ok_pid_or_error()).
+
+-endif.
+
+%%----------------------------------------------------------------------------
+
start_link(Callback) ->
supervisor2:start_link(?MODULE, Callback).
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(