Skip to content

Commit

Permalink
asynchronous calls over erlimem #276
Browse files Browse the repository at this point in the history
  • Loading branch information
shamis committed Aug 5, 2019
1 parent 1d6987e commit e68b409
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/imem_sec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,14 @@ seco_authorized(SKey) ->
case imem_meta:read(ddSeCo@, SKey) of
[#ddSeCo{pid=Pid, authState=authorized} = SeCo] when Pid == self() ->
SeCo;
[#ddSeCo{pid=Pid}] ->
?SecurityViolation({"Not logged in", {SKey,Pid}});
[#ddSeCo{pid=Pid, authState=authorized} = SeCo] ->
{links, Links} = erlang:process_info(self(), links),
case lists:member(Pid, Links) of
true ->
SeCo;
false ->
?SecurityViolation({"Not logged in", SKey})
end;
[] ->
?SecurityException({"Not logged in", SKey})
end.
Expand Down
8 changes: 8 additions & 0 deletions src/imem_seco.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
, has_role/2
, has_permission/3
, has_permission/2
, get_skey_pid/1
]).

-export([ have_role/2
Expand Down Expand Up @@ -296,6 +297,13 @@ if_has_child_permission([RootRoleId|OtherRoles], Permission) ->
false -> if_has_child_permission(OtherRoles, Permission)
end.

get_skey_pid(SKey) ->
case if_read(ddSeCo@, SKey) of
[#ddSeCo{pid=Pid}] ->
{ok, Pid};
_ ->
not_found
end.

%% --Implementation (exported helper functions) ----------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions src/imem_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ mfa({Ref, imem_sec = Mod, Fun, Args}, Transport) when Fun =:= login;
Fun =:= auth_add_cred ->
mfa(Ref, Mod, Fun, Args, Transport);
mfa({Ref, Mod, Fun, Args}, Transport) ->
% mfa(Ref, Mod, Fun, Args);
spawn_link(fun() ->
mfa(Ref, Mod, Fun, Args, Transport)
end),
Expand All @@ -190,7 +189,7 @@ mfa(Ref, Mod, Fun, Args, Transport) ->
?TLog("~p MFA -> R ~n ~p:~p(~p) -> ~p~n", [Transport,Mod,Fun,NewArgs,ApplyRes]),
?TLog("~p MF -> R ~n ~p:~p -> ~p~n", [Transport,Mod,Fun,ApplyRes]),
send_resp(ApplyRes, Transport),
ok.
ok. % 'ok' returned for erlimem compatibility

args(R, fetch_recs_async, A, {_,_,R} = T) ->
Args = lists:sublist(A, length(A)-1) ++ [T],
Expand Down
5 changes: 3 additions & 2 deletions src/imem_statement.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@
%% gen_server -----------------------------------------------------

create_stmt(Statement, SKey, IsSec) ->
{ok, SKeyPid} = imem_seco:get_skey_pid(SKey),
case IsSec of
false ->
gen_server:start(?MODULE, [Statement,self()], [{spawn_opt, [{fullsweep_after, 0}]}]);
gen_server:start(?MODULE, [Statement,SKeyPid], [{spawn_opt, [{fullsweep_after, 0}]}]);
true ->
{ok, Pid} = gen_server:start(?MODULE, [Statement,self()], []),
{ok, Pid} = gen_server:start(?MODULE, [Statement,SKeyPid], []),
NewSKey = imem_sec:clone_seco(SKey, Pid),
ok = gen_server:call(Pid, {set_seco, NewSKey}),
{ok, Pid}
Expand Down

0 comments on commit e68b409

Please sign in to comment.