25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-02 16:37:52 +01:00

Fix problems reported by Dialyzer

This commit is contained in:
Badlop 2010-09-15 20:04:35 +02:00
parent 52deb16676
commit cb953f949f
2 changed files with 30 additions and 37 deletions

View File

@ -81,13 +81,13 @@ start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
create_captcha(SID, From, To, Lang, Args) create_captcha(SID, From, To, Lang, Args)
when is_binary(Lang), is_list(SID) -> when is_binary(Lang), is_binary(SID) ->
case create_image() of case create_image() of
{ok, Type, Key, Image} -> {ok, Type, Key, Image} ->
Id = randoms:get_string() ++ "-" ++ ejabberd_cluster:node_id(), Id = list_to_binary(randoms:get_string() ++ "-" ++ ejabberd_cluster:node_id()),
B64Image = jlib:encode_base64(binary_to_list(Image)), B64Image = list_to_binary(jlib:encode_base64(binary_to_list(Image))),
JID = exmpp_jid:to_list(From), JID = exmpp_jid:to_list(From),
CID = "sha1+" ++ sha:sha(Image) ++ "@bob.xmpp.org", CID = list_to_binary(["sha1+", sha:sha(Image), "@bob.xmpp.org"]),
% Data = {xmlelement, "data", % Data = {xmlelement, "data",
% [{"xmlns", ?NS_BOB}, {"cid", CID}, % [{"xmlns", ?NS_BOB}, {"cid", CID},
% {"max-age", "0"}, {"type", Type}], % {"max-age", "0"}, {"type", Type}],
@ -103,7 +103,7 @@ create_captcha(SID, From, To, Lang, Args)
}, },
#xmlattr{ #xmlattr{
name = 'max-age', name = 'max-age',
value = "0" value = <<"0">>
}, },
#xmlattr{ #xmlattr{
name = 'type', name = 'type',
@ -134,20 +134,20 @@ create_captcha(SID, From, To, Lang, Args)
attrs = [ attrs = [
#xmlattr{ #xmlattr{
name = 'type', name = 'type',
value = "form" value = <<"form">>
} }
], ],
children = [ children = [
?VFIELD("hidden", "FORM_TYPE", #xmlcdata{cdata = ?NS_CAPTCHA}), ?VFIELD(<<"hidden">>, <<"FORM_TYPE">>, #xmlcdata{cdata = ?NS_CAPTCHA}),
?VFIELD("hidden", "from", #xmlcdata{cdata = exmpp_jid:to_list(To)}), ?VFIELD(<<"hidden">>, <<"from">>, #xmlcdata{cdata = exmpp_jid:to_binary(To)}),
?VFIELD("hidden", "challenge", #xmlcdata{cdata = Id}), ?VFIELD(<<"hidden">>, <<"challenge">>, #xmlcdata{cdata = Id}),
?VFIELD("hidden", "sid", #xmlcdata{cdata = SID}), ?VFIELD(<<"hidden">>, <<"sid">>, #xmlcdata{cdata = SID}),
#xmlel{ #xmlel{
name = 'field', name = 'field',
attrs = [ attrs = [
#xmlattr{ #xmlattr{
name = 'var', name = 'var',
value = "ocr" value = <<"ocr">>
}, },
#xmlattr{ #xmlattr{
name = 'label', name = 'label',
@ -168,7 +168,7 @@ create_captcha(SID, From, To, Lang, Args)
} }
], ],
children = [ children = [
#xmlcdata{cdata = "cid:" ++ CID} #xmlcdata{cdata = list_to_binary(["cid:", CID])}
] ]
} }
] ]
@ -199,7 +199,7 @@ create_captcha(SID, From, To, Lang, Args)
name = 'url', name = 'url',
children = [ children = [
#xmlcdata{ #xmlcdata{
cdata = get_url(Id)} cdata = list_to_binary(get_url(Id))}
] ]
} }
] ]
@ -232,7 +232,7 @@ build_captcha_html(Id, Lang) ->
attrs = [ attrs = [
#xmlattr{ #xmlattr{
name = 'src', name = 'src',
value = get_url(Id ++ "/image") value = list_to_binary(get_url(Id ++ "/image"))
} }
] ]
}, },
@ -247,15 +247,15 @@ build_captcha_html(Id, Lang) ->
attrs = [ attrs = [
#xmlattr{ #xmlattr{
name = 'type', name = 'type',
value = "hidden" value = <<"hidden">>
}, },
#xmlattr{ #xmlattr{
name = 'name', name = 'name',
value = "id" value = <<"id">>
}, },
#xmlattr{ #xmlattr{
name = 'value', name = 'value',
value = Id value = list_to_binary(Id)
} }
] ]
}, },
@ -300,7 +300,7 @@ build_captcha_html(Id, Lang) ->
attrs = [ attrs = [
#xmlattr{ #xmlattr{
name = 'action', name = 'action',
value = get_url(Id) value = list_to_binary(get_url(Id))
}, },
#xmlattr{ #xmlattr{
name = 'name', name = 'name',
@ -399,7 +399,7 @@ process_reply(El) ->
process(_Handlers, #request{method='GET', lang=Lang, path=[_, Id]}) -> process(_Handlers, #request{method='GET', lang=Lang, path=[_, Id]}) ->
case build_captcha_html(Id, Lang) of case build_captcha_html(Id, Lang) of
{FormEl, _} when is_tuple(FormEl) -> {FormEl, CaptchaTuple} when is_tuple(CaptchaTuple) ->
Form = Form =
%{xmlelement, "div", [{"align", "center"}], %{xmlelement, "div", [{"align", "center"}],
%[FormEl]}, %[FormEl]},
@ -502,25 +502,25 @@ code_change(_OldVsn, State, _Extra) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Function: create_image() -> {ok, Type, Key, Image} | {error, Reason} %% Function: create_image() -> {ok, Type, Key, Image} | {error, Reason}
%% Type = "image/png" | "image/jpeg" | "image/gif" %% Type = "image/png" | "image/jpeg" | "image/gif"
%% Key = string() %% Key = binary()
%% Image = binary() %% Image = binary()
%% Reason = atom() %% Reason = atom()
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
create_image() -> create_image() ->
%% Six numbers from 1 to 9. %% Six numbers from 1 to 9.
Key = string:substr(randoms:get_string(), 1, 6), Key = list_to_binary(string:substr(randoms:get_string(), 1, 6)),
create_image(Key). create_image(Key).
create_image(Key) -> create_image(Key) ->
FileName = get_prog_name(), FileName = get_prog_name(),
Cmd = lists:flatten(io_lib:format("~s ~s", [FileName, Key])), Cmd = lists:flatten(io_lib:format("~s ~p", [FileName, Key])),
case cmd(Cmd) of case cmd(Cmd) of
{ok, <<16#89, $P, $N, $G, $\r, $\n, 16#1a, $\n, _/binary>> = Img} -> {ok, <<16#89, $P, $N, $G, $\r, $\n, 16#1a, $\n, _/binary>> = Img} ->
{ok, "image/png", Key, Img}; {ok, <<"image/png">>, Key, Img};
{ok, <<16#ff, 16#d8, _/binary>> = Img} -> {ok, <<16#ff, 16#d8, _/binary>> = Img} ->
{ok, "image/jpeg", Key, Img}; {ok, <<"image/jpeg">>, Key, Img};
{ok, <<$G, $I, $F, $8, X, $a, _/binary>> = Img} when X==$7; X==$9 -> {ok, <<$G, $I, $F, $8, X, $a, _/binary>> = Img} when X==$7; X==$9 ->
{ok, "image/gif", Key, Img}; {ok, <<"image/gif">>, Key, Img};
{error, enodata = Reason} -> {error, enodata = Reason} ->
?ERROR_MSG("Failed to process output from \"~s\". " ?ERROR_MSG("Failed to process output from \"~s\". "
"Maybe ImageMagick's Convert program is not installed.", "Maybe ImageMagick's Convert program is not installed.",

View File

@ -423,8 +423,8 @@ get_handle(Name) when is_list(Name) -> list_to_atom("eldap_" ++ Name).
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
init([]) -> init([]) ->
case get_config() of case get_config() of
{ok, Hosts, Rootdn, Passwd, Opts} -> {ok, Hosts, Port, Rootdn, Passwd, Opts} ->
init({Hosts, Rootdn, Passwd, Opts}); init({Hosts, Port, Rootdn, Passwd, Opts});
{error, Reason} -> {error, Reason} ->
{stop, Reason} {stop, Reason}
end; end;
@ -440,8 +440,6 @@ init({Hosts, Port, Rootdn, Passwd, Opts}) ->
case Encrypt of case Encrypt of
tls -> tls ->
?LDAPS_PORT; ?LDAPS_PORT;
starttls ->
?LDAP_PORT;
_ -> _ ->
?LDAP_PORT ?LDAP_PORT
end; end;
@ -886,14 +884,9 @@ cancel_timer(Timer) ->
%%% Sanity check of received packet %%% Sanity check of received packet
check_tag(Data) -> check_tag(Data) ->
case asn1rt_ber_bin:decode_tag(Data) of {_Tag, Data1, _Rb} = asn1rt_ber_bin:decode_tag(Data),
{_Tag, Data1, _Rb} -> {{_Len,_Data2}, _Rb2} = asn1rt_ber_bin:decode_length(Data1),
case asn1rt_ber_bin:decode_length(Data1) of ok.
{{_Len,_Data2}, _Rb2} -> ok;
_ -> throw({error,decoded_tag_length})
end;
_ -> throw({error,decoded_tag})
end.
close_and_retry(S, Timeout) -> close_and_retry(S, Timeout) ->
catch (S#eldap.sockmod):close(S#eldap.fd), catch (S#eldap.sockmod):close(S#eldap.fd),