25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Do not fail on badly formed SQL results

This commit is contained in:
Evgeniy Khramtsov 2013-11-10 00:56:28 +10:00
parent c7dc56c314
commit bbe5c6b74e
2 changed files with 45 additions and 41 deletions

View File

@ -236,7 +236,7 @@ process_blocklist_block(LUser, LServer, Filter, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>, <<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>], <<"match_presence_in">>, <<"match_presence_out">>],
RItems = [_ | _]} -> RItems = [_ | _]} ->
List = lists:map(fun mod_privacy:raw_to_item/1, RItems); List = lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
_ -> List = [] _ -> List = []
end, end,
NewList = Filter(List), NewList = Filter(List),
@ -432,7 +432,7 @@ process_blocklist_unblock(LUser, LServer, Filter,
<<"match_all">>, <<"match_iq">>, <<"match_message">>, <<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>], <<"match_presence_in">>, <<"match_presence_out">>],
RItems = [_ | _]} -> RItems = [_ | _]} ->
List = lists:map(fun mod_privacy:raw_to_item/1, List = lists:flatmap(fun mod_privacy:raw_to_item/1,
RItems), RItems),
NewList = Filter(List), NewList = Filter(List),
NewRItems = lists:map(fun mod_privacy:item_to_raw/1, NewRItems = lists:map(fun mod_privacy:item_to_raw/1,
@ -521,7 +521,7 @@ process_blocklist_get(LUser, LServer, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>, <<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>], <<"match_presence_in">>, <<"match_presence_out">>],
RItems} -> RItems} ->
lists:map(fun mod_privacy:raw_to_item/1, RItems); lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
{'EXIT', _} -> error {'EXIT', _} -> error
end; end;
{'EXIT', _} -> error {'EXIT', _} -> error

View File

@ -251,7 +251,7 @@ process_list_get(LUser, LServer, Name, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>, <<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>], <<"match_presence_in">>, <<"match_presence_out">>],
RItems} -> RItems} ->
lists:map(fun raw_to_item/1, RItems); lists:flatmap(fun raw_to_item/1, RItems);
_ -> error _ -> error
end; end;
_ -> error _ -> error
@ -482,7 +482,7 @@ process_active_set(LUser, LServer, Name, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>, <<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>], <<"match_presence_in">>, <<"match_presence_out">>],
RItems} -> RItems} ->
lists:map(fun raw_to_item/1, RItems); lists:flatmap(fun raw_to_item/1, RItems);
_ -> error _ -> error
end; end;
_ -> error _ -> error
@ -766,7 +766,7 @@ get_user_list(_, LUser, LServer, odbc) ->
<<"match_all">>, <<"match_iq">>, <<"match_message">>, <<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>], <<"match_presence_in">>, <<"match_presence_out">>],
RItems} -> RItems} ->
{Default, lists:map(fun raw_to_item/1, RItems)}; {Default, lists:flatmap(fun raw_to_item/1, RItems)};
_ -> {none, []} _ -> {none, []}
end; end;
_ -> {none, []} _ -> {none, []}
@ -813,7 +813,7 @@ get_user_lists(LUser, LServer, odbc) ->
<<"match_message">>, <<"match_presence_in">>, <<"match_message">>, <<"match_presence_in">>,
<<"match_presence_out">>], <<"match_presence_out">>],
RItems} -> RItems} ->
[{Name, lists:map(fun raw_to_item/1, RItems)}]; [{Name, lists:flatmap(fun raw_to_item/1, RItems)}];
_ -> _ ->
[] []
end end
@ -967,12 +967,14 @@ updated_list(_, #userlist{name = OldName} = Old,
raw_to_item([SType, SValue, SAction, SOrder, SMatchAll, raw_to_item([SType, SValue, SAction, SOrder, SMatchAll,
SMatchIQ, SMatchMessage, SMatchPresenceIn, SMatchIQ, SMatchMessage, SMatchPresenceIn,
SMatchPresenceOut]) -> SMatchPresenceOut] = Row) ->
try
{Type, Value} = case SType of {Type, Value} = case SType of
<<"n">> -> {none, none}; <<"n">> -> {none, none};
<<"j">> -> <<"j">> ->
case jlib:string_to_jid(SValue) of case jlib:string_to_jid(SValue) of
#jid{} = JID -> {jid, jlib:jid_tolower(JID)} #jid{} = JID ->
{jid, jlib:jid_tolower(JID)}
end; end;
<<"g">> -> {group, SValue}; <<"g">> -> {group, SValue};
<<"s">> -> <<"s">> ->
@ -991,15 +993,17 @@ raw_to_item([SType, SValue, SAction, SOrder, SMatchAll,
MatchAll = ejabberd_odbc:to_bool(SMatchAll), MatchAll = ejabberd_odbc:to_bool(SMatchAll),
MatchIQ = ejabberd_odbc:to_bool(SMatchIQ), MatchIQ = ejabberd_odbc:to_bool(SMatchIQ),
MatchMessage = ejabberd_odbc:to_bool(SMatchMessage), MatchMessage = ejabberd_odbc:to_bool(SMatchMessage),
MatchPresenceIn = MatchPresenceIn = ejabberd_odbc:to_bool(SMatchPresenceIn),
ejabberd_odbc:to_bool(SMatchPresenceIn), MatchPresenceOut = ejabberd_odbc:to_bool(SMatchPresenceOut),
MatchPresenceOut = [#listitem{type = Type, value = Value, action = Action,
ejabberd_odbc:to_bool(SMatchPresenceOut),
#listitem{type = Type, value = Value, action = Action,
order = Order, match_all = MatchAll, match_iq = MatchIQ, order = Order, match_all = MatchAll, match_iq = MatchIQ,
match_message = MatchMessage, match_message = MatchMessage,
match_presence_in = MatchPresenceIn, match_presence_in = MatchPresenceIn,
match_presence_out = MatchPresenceOut}. match_presence_out = MatchPresenceOut}]
catch _:_ ->
?WARNING_MSG("failed to parse row: ~p", [Row]),
[]
end.
item_to_raw(#listitem{type = Type, value = Value, item_to_raw(#listitem{type = Type, value = Value,
action = Action, order = Order, match_all = MatchAll, action = Action, order = Order, match_all = MatchAll,