diff options
Diffstat (limited to 'src/ejabberd_oauth_mnesia.erl')
-rw-r--r-- | src/ejabberd_oauth_mnesia.erl | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/src/ejabberd_oauth_mnesia.erl b/src/ejabberd_oauth_mnesia.erl index a23f443ed..de851f1ea 100644 --- a/src/ejabberd_oauth_mnesia.erl +++ b/src/ejabberd_oauth_mnesia.erl @@ -5,7 +5,7 @@ %%% Created : 20 Jul 2016 by Alexey Shchepin <alexey@process-one.net> %%% %%% -%%% ejabberd, Copyright (C) 2002-2016 ProcessOne +%%% ejabberd, Copyright (C) 2002-2019 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as @@ -25,31 +25,47 @@ %%%------------------------------------------------------------------- -module(ejabberd_oauth_mnesia). +-behaviour(ejabberd_oauth). -export([init/0, store/1, lookup/1, - clean/1]). + clean/1, + lookup_client/1, + store_client/1, + remove_client/1, + use_cache/0]). -include("ejabberd_oauth.hrl"). init() -> - mnesia:create_table(oauth_token, - [{disc_copies, [node()]}, + ejabberd_mnesia:create(?MODULE, oauth_token, + [{disc_only_copies, [node()]}, {attributes, record_info(fields, oauth_token)}]), - mnesia:add_table_copy(oauth_token, node(), disc_copies), + ejabberd_mnesia:create(?MODULE, oauth_client, + [{disc_copies, [node()]}, + {attributes, + record_info(fields, oauth_client)}]), ok. +use_cache() -> + case mnesia:table_info(oauth_token, storage_type) of + disc_only_copies -> + ejabberd_option:oauth_use_cache(); + _ -> + false + end. + store(R) -> mnesia:dirty_write(R). lookup(Token) -> case catch mnesia:dirty_read(oauth_token, Token) of [R] -> - R; + {ok, R}; _ -> - false + error end. clean(TS) -> @@ -63,3 +79,16 @@ clean(TS) -> end, mnesia:async_dirty(F). +lookup_client(ClientID) -> + case catch mnesia:dirty_read(oauth_client, ClientID) of + [R] -> + {ok, R}; + _ -> + error + end. + +remove_client(ClientID) -> + mnesia:dirty_delete(oauth_client, ClientID). + +store_client(R) -> + mnesia:dirty_write(R). |