aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2013-11-10 00:56:28 +1000
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2015-03-13 12:59:16 +0300
commitbbe5c6b74eaf9b9b3ba35f717c40617e11b225b7 (patch)
tree196450a0cfa50f2b1f3b5d14a11f904073998801
parentFix unblock all when Riak is used as a backend (diff)
Do not fail on badly formed SQL results
-rw-r--r--src/mod_blocking.erl8
-rw-r--r--src/mod_privacy.erl78
2 files changed, 45 insertions, 41 deletions
diff --git a/src/mod_blocking.erl b/src/mod_blocking.erl
index 9eba5c950..27d727a14 100644
--- a/src/mod_blocking.erl
+++ b/src/mod_blocking.erl
@@ -236,7 +236,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),
@@ -432,8 +432,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),
@@ -521,7 +521,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,