25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Improve validation of 'convert' option

This commit is contained in:
Evgeniy Khramtsov 2018-01-16 01:06:20 +03:00
parent 8bdccc25ab
commit 7b0fa7e6e2

View File

@ -407,18 +407,30 @@ decode_mime_type(MimeType) ->
encode_mime_type(Type) -> encode_mime_type(Type) ->
<<"image/", (atom_to_binary(Type, latin1))/binary>>. <<"image/", (atom_to_binary(Type, latin1))/binary>>.
warn(Format) -> -spec fail(atom()) -> no_return().
?WARNING_MSG("ejabberd is not compiled with ~p support", [Format]). fail(Format) ->
FormatS = case Format of
webp -> "WebP";
png -> "PNG";
jpeg -> "JPEG";
gif -> "GIF";
_ -> ""
end,
if FormatS /= "" ->
?WARNING_MSG("ejabberd is not compiled with ~s support", [FormatS]);
true ->
ok
end,
erlang:error(badarg).
mod_opt_type({convert, From}) when From == webp; From == jpeg; mod_opt_type({convert, From}) ->
From == png; From == gif ->
fun(To) when is_atom(To), To /= From -> fun(To) when is_atom(To), To /= From ->
case eimp:is_supported(From) of case eimp:is_supported(From) orelse From == default of
false -> false ->
warn(From); fail(From);
true -> true ->
case eimp:is_supported(To) of case eimp:is_supported(To) of
false -> warn(To); false -> fail(To);
true -> To true -> To
end end
end end