aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mod_blocking.erl124
-rw-r--r--src/mod_privacy.erl78
2 files changed, 65 insertions, 137 deletions
diff --git a/src/mod_blocking.erl b/src/mod_blocking.erl
index 07e9027b6..172786810 100644
--- a/src/mod_blocking.erl
+++ b/src/mod_blocking.erl
@@ -17,9 +17,10 @@
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
-%%% You should have received a copy of the GNU General Public License along
-%%% with this program; if not, write to the Free Software Foundation, Inc.,
-%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+%%% You should have received a copy of the GNU General Public License
+%%% along with this program; if not, write to the Free Software
+%%% 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,
{block, JIDs}),
{result, [], UserList};
- _ -> {error, ?ERR_INTERNAL_SERVER_ERROR}
+ _Err ->
+ ?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
+ {error, ?ERR_INTERNAL_SERVER_ERROR}
end.
process_blocklist_block(LUser, LServer, Filter,
@@ -236,7 +239,7 @@ process_blocklist_block(LUser, LServer, Filter, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems = [_ | _]} ->
- List = lists:map(fun mod_privacy:raw_to_item/1, RItems);
+ List = lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
_ -> List = []
end,
NewList = Filter(List),
@@ -253,10 +256,8 @@ process_blocklist_unblock_all(LUser, LServer) ->
end,
List)
end,
- case process_blocklist_unblock_all(LUser, LServer,
- Filter,
- gen_mod:db_type(LServer, mod_privacy))
- of
+ DBType = gen_mod:db_type(LServer, mod_privacy),
+ case unblock_by_filter(LUser, LServer, Filter, DBType) of
{atomic, ok} -> {result, []};
{atomic, {ok, Default, List}} ->
UserList = make_userlist(Default, List),
@@ -264,86 +265,11 @@ process_blocklist_unblock_all(LUser, LServer) ->
UserList),
broadcast_blocklist_event(LUser, LServer, unblock_all),
{result, [], UserList};
- _ -> {error, ?ERR_INTERNAL_SERVER_ERROR}
+ _Err ->
+ ?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer}, _Err]),
+ {error, ?ERR_INTERNAL_SERVER_ERROR}
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, {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) ->
Filter = fun (List) ->
lists:filter(fun (#listitem{action = deny, type = jid,
@@ -353,9 +279,8 @@ process_blocklist_unblock(LUser, LServer, JIDs) ->
end,
List)
end,
- case process_blocklist_unblock(LUser, LServer, Filter,
- gen_mod:db_type(LServer, mod_privacy))
- of
+ DBType = gen_mod:db_type(LServer, mod_privacy),
+ case unblock_by_filter(LUser, LServer, Filter, DBType) of
{atomic, ok} -> {result, []};
{atomic, {ok, Default, List}} ->
UserList = make_userlist(Default, List),
@@ -364,11 +289,12 @@ process_blocklist_unblock(LUser, LServer, JIDs) ->
broadcast_blocklist_event(LUser, LServer,
{unblock, JIDs}),
{result, [], UserList};
- _ -> {error, ?ERR_INTERNAL_SERVER_ERROR}
+ _Err ->
+ ?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
+ {error, ?ERR_INTERNAL_SERVER_ERROR}
end.
-process_blocklist_unblock(LUser, LServer, Filter,
- mnesia) ->
+unblock_by_filter(LUser, LServer, Filter, mnesia) ->
F = fun () ->
case mnesia:read({privacy, {LUser, LServer}}) of
[] ->
@@ -389,8 +315,7 @@ process_blocklist_unblock(LUser, LServer, Filter,
end
end,
mnesia:transaction(F);
-process_blocklist_unblock(LUser, LServer, Filter,
- riak) ->
+unblock_by_filter(LUser, LServer, Filter, riak) ->
{atomic,
case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(),
{LUser, LServer}) of
@@ -415,8 +340,7 @@ process_blocklist_unblock(LUser, LServer, Filter,
ok
end
end};
-process_blocklist_unblock(LUser, LServer, Filter,
- odbc) ->
+unblock_by_filter(LUser, LServer, Filter, odbc) ->
F = fun () ->
case mod_privacy:sql_get_default_privacy_list_t(LUser)
of
@@ -431,8 +355,8 @@ process_blocklist_unblock(LUser, LServer, Filter,
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems = [_ | _]} ->
- List = lists:map(fun mod_privacy:raw_to_item/1,
- RItems),
+ List = lists:flatmap(fun mod_privacy:raw_to_item/1,
+ RItems),
NewList = Filter(List),
NewRItems = lists:map(fun mod_privacy:item_to_raw/1,
NewList),
@@ -520,7 +444,7 @@ process_blocklist_get(LUser, LServer, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems} ->
- lists:map(fun mod_privacy:raw_to_item/1, RItems);
+ lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
{'EXIT', _} -> error
end;
{'EXIT', _} -> error
diff --git a/src/mod_privacy.erl b/src/mod_privacy.erl
index c83a953c4..971be9524 100644
--- a/src/mod_privacy.erl
+++ b/src/mod_privacy.erl
@@ -251,7 +251,7 @@ process_list_get(LUser, LServer, Name, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems} ->
- lists:map(fun raw_to_item/1, RItems);
+ lists:flatmap(fun raw_to_item/1, RItems);
_ -> error
end;
_ -> error
@@ -482,7 +482,7 @@ process_active_set(LUser, LServer, Name, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems} ->
- lists:map(fun raw_to_item/1, RItems);
+ lists:flatmap(fun raw_to_item/1, RItems);
_ -> error
end;
_ -> error
@@ -766,7 +766,7 @@ get_user_list(_, LUser, LServer, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems} ->
- {Default, lists:map(fun raw_to_item/1, RItems)};
+ {Default, lists:flatmap(fun raw_to_item/1, RItems)};
_ -> {none, []}
end;
_ -> {none, []}
@@ -813,7 +813,7 @@ get_user_lists(LUser, LServer, odbc) ->
<<"match_message">>, <<"match_presence_in">>,
<<"match_presence_out">>],
RItems} ->
- [{Name, lists:map(fun raw_to_item/1, RItems)}];
+ [{Name, lists:flatmap(fun raw_to_item/1, RItems)}];
_ ->
[]
end
@@ -967,39 +967,43 @@ updated_list(_, #userlist{name = OldName} = Old,
raw_to_item([SType, SValue, SAction, SOrder, SMatchAll,
SMatchIQ, SMatchMessage, SMatchPresenceIn,
- SMatchPresenceOut]) ->
- {Type, Value} = case SType of
- <<"n">> -> {none, none};
- <<"j">> ->
- case jlib:string_to_jid(SValue) of
- #jid{} = JID -> {jid, jlib:jid_tolower(JID)}
- end;
- <<"g">> -> {group, SValue};
- <<"s">> ->
- case SValue of
- <<"none">> -> {subscription, none};
- <<"both">> -> {subscription, both};
- <<"from">> -> {subscription, from};
- <<"to">> -> {subscription, to}
- end
- end,
- Action = case SAction of
- <<"a">> -> allow;
- <<"d">> -> deny
- end,
- Order = jlib:binary_to_integer(SOrder),
- MatchAll = ejabberd_odbc:to_bool(SMatchAll),
- MatchIQ = ejabberd_odbc:to_bool(SMatchIQ),
- MatchMessage = ejabberd_odbc:to_bool(SMatchMessage),
- MatchPresenceIn =
- ejabberd_odbc:to_bool(SMatchPresenceIn),
- MatchPresenceOut =
- ejabberd_odbc:to_bool(SMatchPresenceOut),
- #listitem{type = Type, value = Value, action = Action,
- order = Order, match_all = MatchAll, match_iq = MatchIQ,
- match_message = MatchMessage,
- match_presence_in = MatchPresenceIn,
- match_presence_out = MatchPresenceOut}.
+ SMatchPresenceOut] = Row) ->
+ try
+ {Type, Value} = case SType of
+ <<"n">> -> {none, none};
+ <<"j">> ->
+ case jlib:string_to_jid(SValue) of
+ #jid{} = JID ->
+ {jid, jlib:jid_tolower(JID)}
+ end;
+ <<"g">> -> {group, SValue};
+ <<"s">> ->
+ case SValue of
+ <<"none">> -> {subscription, none};
+ <<"both">> -> {subscription, both};
+ <<"from">> -> {subscription, from};
+ <<"to">> -> {subscription, to}
+ end
+ end,
+ Action = case SAction of
+ <<"a">> -> allow;
+ <<"d">> -> deny
+ end,
+ Order = jlib:binary_to_integer(SOrder),
+ MatchAll = ejabberd_odbc:to_bool(SMatchAll),
+ MatchIQ = ejabberd_odbc:to_bool(SMatchIQ),
+ MatchMessage = ejabberd_odbc:to_bool(SMatchMessage),
+ MatchPresenceIn = ejabberd_odbc:to_bool(SMatchPresenceIn),
+ MatchPresenceOut = ejabberd_odbc:to_bool(SMatchPresenceOut),
+ [#listitem{type = Type, value = Value, action = Action,
+ order = Order, match_all = MatchAll, match_iq = MatchIQ,
+ match_message = MatchMessage,
+ match_presence_in = MatchPresenceIn,
+ match_presence_out = MatchPresenceOut}]
+ catch _:_ ->
+ ?WARNING_MSG("failed to parse row: ~p", [Row]),
+ []
+ end.
item_to_raw(#listitem{type = Type, value = Value,
action = Action, order = Order, match_all = MatchAll,