aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiclas Eklund <[email protected]>2011-04-20 18:03:43 +0200
committerNiclas Eklund <[email protected]>2011-04-20 18:03:43 +0200
commit1b4ef1f5dffb5a99244169b7adf315a513795ee7 (patch)
tree300f092b544d23d7ec21d3b2811646630b81b7c5
parentfb1eab890f6776419b3999285dff45802658e8f0 (diff)
downloadotp-1b4ef1f5dffb5a99244169b7adf315a513795ee7.tar.gz
otp-1b4ef1f5dffb5a99244169b7adf315a513795ee7.tar.bz2
otp-1b4ef1f5dffb5a99244169b7adf315a513795ee7.zip
Added deletion of clients to be used when a session is terminated.
-rw-r--r--lib/ssh/src/ssh_cli.erl5
-rw-r--r--lib/ssh/src/ssh_userreg.erl28
2 files changed, 24 insertions, 9 deletions
diff --git a/lib/ssh/src/ssh_cli.erl b/lib/ssh/src/ssh_cli.erl
index cb78acb84c..4bfd680029 100644
--- a/lib/ssh/src/ssh_cli.erl
+++ b/lib/ssh/src/ssh_cli.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2005-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2005-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -180,7 +180,8 @@ handle_msg(_, State) ->
%% Function: terminate(Reason, State) -> void()
%% Description: Called when the channel process is trminated
%%--------------------------------------------------------------------
-terminate(_Reason, _State) ->
+terminate(_Reason, #state{cm = ConnectionManager} = _State) ->
+ (catch ssh_userreg:delete(ConnectionManager)),
ok.
%%--------------------------------------------------------------------
diff --git a/lib/ssh/src/ssh_userreg.erl b/lib/ssh/src/ssh_userreg.erl
index 33c801f490..f901461aea 100644
--- a/lib/ssh/src/ssh_userreg.erl
+++ b/lib/ssh/src/ssh_userreg.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2008-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2008-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -25,11 +25,18 @@
-behaviour(gen_server).
%% API
--export([start_link/0, register_user/2, lookup_user/1]).
+-export([start_link/0,
+ register_user/2,
+ lookup_user/1,
+ delete_user/1]).
%% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
- terminate/2, code_change/3]).
+-export([init/1,
+ handle_call/3,
+ handle_cast/2,
+ handle_info/2,
+ terminate/2,
+ code_change/3]).
-record(state, {user_db = []}).
@@ -46,6 +53,9 @@ start_link() ->
register_user(User, Cm) ->
gen_server:cast(?MODULE, {register, {User, Cm}}).
+delete_user(Cm) ->
+ gen_server:cast(?MODULE, {delete, Cm}).
+
lookup_user(Cm) ->
gen_server:call(?MODULE, {get_user, Cm}, infinity).
@@ -82,9 +92,10 @@ handle_call({get_user, Cm}, _From, #state{user_db = Db} = State) ->
%% {stop, Reason, State}
%% Description: Handling cast messages
%%--------------------------------------------------------------------
-handle_cast({register, UserCm}, State0) ->
- State = insert(UserCm, State0),
- {noreply, State}.
+handle_cast({register, UserCm}, State) ->
+ {noreply, insert(UserCm, State)};
+handle_cast({delete, UserCm}, State) ->
+ {noreply, delete(UserCm, State)}.
%%--------------------------------------------------------------------
%% Function: handle_info(Info, State) -> {noreply, State} |
@@ -118,6 +129,9 @@ code_change(_OldVsn, State, _Extra) ->
insert({User, Cm}, #state{user_db = Db} = State) ->
State#state{user_db = [{User, Cm} | Db]}.
+delete(Cm, #state{user_db = Db} = State) ->
+ State#state{user_db = lists:keydelete(Cm, 2, Db)}.
+
lookup(_, []) ->
undefined;
lookup(Cm, [{User, Cm} | _Rest]) ->