1 |
|
-module(ejabberd_auth_anonymous_mnesia). |
2 |
|
|
3 |
|
-behaviour(ejabberd_auth_anonymous_backend). |
4 |
|
|
5 |
|
-export([init/1, stop/1, does_anonymous_user_exist/2, add_connection/3, remove_connection/3]). |
6 |
|
|
7 |
|
-record(anonymous, {us :: jid:simple_bare_jid(), sid :: ejabberd_sm:sid()}). |
8 |
|
|
9 |
|
-spec init(mongooseim:host_type()) -> ok. |
10 |
|
init(_HostType) -> |
11 |
145 |
mnesia:create_table(anonymous, |
12 |
|
[{ram_copies, [node()]}, {type, bag}, |
13 |
|
{attributes, record_info(fields, anonymous)}]), |
14 |
145 |
mnesia:add_table_copy(anonymous, node(), ram_copies), |
15 |
145 |
ok. |
16 |
|
|
17 |
|
-spec does_anonymous_user_exist(mongooseim:host_type(), jid:simple_bare_jid()) -> boolean(). |
18 |
|
does_anonymous_user_exist(_HostType, US) -> |
19 |
17 |
[] =/= catch mnesia:dirty_read({anonymous, US}). |
20 |
|
|
21 |
|
-spec add_connection(mongooseim:host_type(), ejabberd_sm:sid(), jid:simple_bare_jid()) -> ok. |
22 |
|
add_connection(_HostType, SID, US) -> |
23 |
4 |
mnesia:sync_dirty(fun() -> mnesia:write(#anonymous{us = US, sid = SID}) end). |
24 |
|
|
25 |
|
-spec remove_connection(mongooseim:host_type(), ejabberd_sm:sid(), jid:simple_bare_jid()) -> ok. |
26 |
|
remove_connection(_HostType, SID, US) -> |
27 |
4 |
mnesia:transaction(fun() -> mnesia:delete_object({anonymous, US, SID}) end), |
28 |
4 |
ok. |
29 |
|
|
30 |
|
-spec stop(mongooseim:host_type()) -> ok. |
31 |
|
stop(_HostType) -> |
32 |
:-( |
ok. |