25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-10 15:47:30 +01:00

Improve module structure

This commit is contained in:
Evgeniy Khramtsov 2015-03-13 13:05:16 +03:00
parent bbe5c6b74e
commit f72799b3cc

View File

@ -17,9 +17,10 @@
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details. %%% General Public License for more details.
%%% %%%
%%% You should have received a copy of the GNU General Public License along %%% You should have received a copy of the GNU General Public License
%%% with this program; if not, write to the Free Software Foundation, Inc., %%% along with this program; if not, write to the Free Software
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%% %%%
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -151,7 +152,9 @@ process_blocklist_block(LUser, LServer, JIDs) ->
broadcast_blocklist_event(LUser, LServer, broadcast_blocklist_event(LUser, LServer,
{block, JIDs}), {block, JIDs}),
{result, [], UserList}; {result, [], UserList};
_ -> {error, ?ERR_INTERNAL_SERVER_ERROR} _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
{error, ?ERR_INTERNAL_SERVER_ERROR}
end. end.
process_blocklist_block(LUser, LServer, Filter, process_blocklist_block(LUser, LServer, Filter,
@ -253,10 +256,8 @@ process_blocklist_unblock_all(LUser, LServer) ->
end, end,
List) List)
end, end,
case process_blocklist_unblock_all(LUser, LServer, DBType = gen_mod:db_type(LServer, mod_privacy),
Filter, case unblock_by_filter(LUser, LServer, Filter, DBType) of
gen_mod:db_type(LServer, mod_privacy))
of
{atomic, ok} -> {result, []}; {atomic, ok} -> {result, []};
{atomic, {ok, Default, List}} -> {atomic, {ok, Default, List}} ->
UserList = make_userlist(Default, List), UserList = make_userlist(Default, List),
@ -264,87 +265,11 @@ process_blocklist_unblock_all(LUser, LServer) ->
UserList), UserList),
broadcast_blocklist_event(LUser, LServer, unblock_all), broadcast_blocklist_event(LUser, LServer, unblock_all),
{result, [], UserList}; {result, [], UserList};
_ -> {error, ?ERR_INTERNAL_SERVER_ERROR} _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer}, _Err]),
{error, ?ERR_INTERNAL_SERVER_ERROR}
end. end.
process_blocklist_unblock_all(LUser, LServer, Filter,
mnesia) ->
F = fun () ->
case mnesia:read({privacy, {LUser, LServer}}) of
[] ->
% No lists, nothing to unblock
ok;
[#privacy{default = Default, lists = Lists} = P] ->
case lists:keysearch(Default, 1, Lists) of
{value, {_, List}} ->
NewList = Filter(List),
NewLists1 = lists:keydelete(Default, 1, Lists),
NewLists = [{Default, NewList} | NewLists1],
mnesia:write(P#privacy{lists = NewLists}),
{ok, Default, NewList};
false ->
% No default list, nothing to unblock
ok
end
end
end,
mnesia:transaction(F);
process_blocklist_unblock_all(LUser, LServer, Filter,
riak) ->
{atomic,
case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(),
{LUser, LServer}) of
{ok, #privacy{default = Default, lists = Lists} = P} ->
case lists:keysearch(Default, 1, Lists) of
{value, {_, List}} ->
NewList = Filter(List),
NewLists1 = lists:keydelete(Default, 1, Lists),
NewLists = [{Default, NewList} | NewLists1],
case ejabberd_riak:put(P#privacy{lists = NewLists},
mod_privacy:privacy_schema()) of
ok ->
{ok, Default, NewList};
Err ->
Err
end;
false ->
%% No default list, nothing to unblock
ok
end;
{error, _} ->
%% No lists, nothing to unblock
ok
end};
process_blocklist_unblock_all(LUser, LServer, Filter,
odbc) ->
F = fun () ->
case mod_privacy:sql_get_default_privacy_list_t(LUser)
of
{selected, [<<"name">>], []} -> ok;
{selected, [<<"name">>], [[Default]]} ->
{selected, [<<"id">>], [[ID]]} =
mod_privacy:sql_get_privacy_list_id_t(LUser, Default),
case mod_privacy:sql_get_privacy_list_data_by_id_t(ID)
of
{selected,
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems = [_ | _]} ->
List = lists:map(fun mod_privacy:raw_to_item/1,
RItems),
NewList = Filter(List),
NewRItems = lists:map(fun mod_privacy:item_to_raw/1,
NewList),
mod_privacy:sql_set_privacy_list(ID, NewRItems),
{ok, Default, NewList};
_ -> ok
end;
_ -> ok
end
end,
ejabberd_odbc:sql_transaction(LServer, F).
process_blocklist_unblock(LUser, LServer, JIDs) -> process_blocklist_unblock(LUser, LServer, JIDs) ->
Filter = fun (List) -> Filter = fun (List) ->
lists:filter(fun (#listitem{action = deny, type = jid, lists:filter(fun (#listitem{action = deny, type = jid,
@ -354,9 +279,8 @@ process_blocklist_unblock(LUser, LServer, JIDs) ->
end, end,
List) List)
end, end,
case process_blocklist_unblock(LUser, LServer, Filter, DBType = gen_mod:db_type(LServer, mod_privacy),
gen_mod:db_type(LServer, mod_privacy)) case unblock_by_filter(LUser, LServer, Filter, DBType) of
of
{atomic, ok} -> {result, []}; {atomic, ok} -> {result, []};
{atomic, {ok, Default, List}} -> {atomic, {ok, Default, List}} ->
UserList = make_userlist(Default, List), UserList = make_userlist(Default, List),
@ -365,11 +289,12 @@ process_blocklist_unblock(LUser, LServer, JIDs) ->
broadcast_blocklist_event(LUser, LServer, broadcast_blocklist_event(LUser, LServer,
{unblock, JIDs}), {unblock, JIDs}),
{result, [], UserList}; {result, [], UserList};
_ -> {error, ?ERR_INTERNAL_SERVER_ERROR} _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
{error, ?ERR_INTERNAL_SERVER_ERROR}
end. end.
process_blocklist_unblock(LUser, LServer, Filter, unblock_by_filter(LUser, LServer, Filter, mnesia) ->
mnesia) ->
F = fun () -> F = fun () ->
case mnesia:read({privacy, {LUser, LServer}}) of case mnesia:read({privacy, {LUser, LServer}}) of
[] -> [] ->
@ -390,8 +315,7 @@ process_blocklist_unblock(LUser, LServer, Filter,
end end
end, end,
mnesia:transaction(F); mnesia:transaction(F);
process_blocklist_unblock(LUser, LServer, Filter, unblock_by_filter(LUser, LServer, Filter, riak) ->
riak) ->
{atomic, {atomic,
case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(), case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(),
{LUser, LServer}) of {LUser, LServer}) of
@ -416,8 +340,7 @@ process_blocklist_unblock(LUser, LServer, Filter,
ok ok
end end
end}; end};
process_blocklist_unblock(LUser, LServer, Filter, unblock_by_filter(LUser, LServer, Filter, odbc) ->
odbc) ->
F = fun () -> F = fun () ->
case mod_privacy:sql_get_default_privacy_list_t(LUser) case mod_privacy:sql_get_default_privacy_list_t(LUser)
of of