Fix problems detected by Dialyzer

This commit is contained in:
Badlop 2011-08-17 18:43:19 +02:00
parent 6eb5b0d298
commit 7355e810a8
6 changed files with 47 additions and 58 deletions

View File

@ -232,7 +232,7 @@ server_start(State, Mech, ClientIn) ->
%% @spec (State, ClientIn) -> Ok | Continue | Error %% @spec (State, ClientIn) -> Ok | Continue | Error
%% State = saslstate() %% State = saslstate()
%% ClientIn = string() %% ClientIn = string()
%% Ok = {ok, Props} %% Ok = {ok, Props} | {ok, Props, ServerOut}
%% Props = [Prop] %% Props = [Prop]
%% Prop = [{Key, Value}] %% Prop = [{Key, Value}]
%% Key = atom() %% Key = atom()

View File

@ -92,9 +92,7 @@ mech_step(#state{step = 2} = State, ClientIn) ->
_Else -> _Else ->
{error, 'not-supported'} {error, 'not-supported'}
end end
end; end
_Else ->
{error, 'bad-protocol'}
end; end;
_Else -> _Else ->
{error, 'bad-protocol'} {error, 'bad-protocol'}
@ -146,12 +144,8 @@ parse_attribute(Attribute) ->
true -> true ->
if if
SecondChar == $= -> SecondChar == $= ->
case string:substr(Attribute, 3) of String = string:substr(Attribute, 3),
String when is_list(String) -> {lists:nth(1, Attribute), String};
{lists:nth(1, Attribute), String};
_Else ->
{error, 'bad-format failed'}
end;
true -> true ->
{error, 'bad-format second char not equal sign'} {error, 'bad-format second char not equal sign'}
end; end;
@ -191,7 +185,7 @@ unescape_username(EscapedUsername) ->
is_alpha(Char) when Char >= $a, Char =< $z -> is_alpha(Char) when Char >= $a, Char =< $z ->
true; true;
is_alpha(Char) when Char >= $A, Char =< $Z -> is_alpha(Char) when Char >= $A, Char =< $Z ->
true; true;
is_alpha(_) -> is_alpha(_) ->
true. false.

View File

@ -122,12 +122,12 @@ start(Host) ->
{iterationcount, int}]} {iterationcount, int}]}
]), ]),
update_table(Host, Backend), update_table(Host, Backend),
maybe_scram_passwords(Host), maybe_scram_passwords(HostB),
mnesia:create_table(reg_users_counter, mnesia:create_table(reg_users_counter,
[{ram_copies, [node()]}, [{ram_copies, [node()]},
{attributes, record_info(fields, reg_users_counter)}]), {attributes, record_info(fields, reg_users_counter)}]),
update_reg_users_counter_table(Host), update_reg_users_counter_table(Host),
maybe_alert_password_scrammed_without_option(Host), maybe_alert_password_scrammed_without_option(HostB),
ok. ok.
stop(_Host) -> stop(_Host) ->
@ -544,9 +544,9 @@ is_scrammed(Host) ->
forced_scram -> true forced_scram -> true
end. end.
action_password_format(Host) -> action_password_format(HostB) ->
OptionScram = is_option_scram(), OptionScram = is_option_scram(),
case {OptionScram, get_format_first_element(Host)} of case {OptionScram, get_format_first_element(HostB)} of
{true, scram} -> scram; {true, scram} -> scram;
{true, any} -> scram; {true, any} -> scram;
{true, plain} -> must_scram; {true, plain} -> must_scram;
@ -555,8 +555,8 @@ action_password_format(Host) ->
{false, scram} -> forced_scram {false, scram} -> forced_scram
end. end.
get_format_first_element(Host) -> get_format_first_element(HostB) ->
case gen_storage:dirty_select(Host, passwd, []) of case gen_storage:dirty_select(HostB, passwd, []) of
[] -> any; [] -> any;
[#passwd{password = ""} | _] -> scram; [#passwd{password = ""} | _] -> scram;
[#passwd{} | _] -> plain [#passwd{} | _] -> plain

View File

@ -163,9 +163,8 @@ add_user(El, Domain) ->
Password = exmpp_xml:get_attribute(El,<<"password">>,none), Password = exmpp_xml:get_attribute(El,<<"password">>,none),
add_user(El, Domain, User, PasswordFormat, Password). add_user(El, Domain, User, PasswordFormat, Password).
%% @spec (El::xmlel(), Domain::string(), User::binary(), PasswordFormat, Password::binary() | none) %% @spec (El::xmlel(), Domain::string(), User::binary(), PasswordFormat::binary(), Password::binary() | none)
%% -> ok | {error, ErrorText::string()} %% -> ok | {error, ErrorText::string()}
%% PasswordFormat = <<"plaintext">> | <<"scram">>
%% @doc Add a new user to the database. %% @doc Add a new user to the database.
%% If user already exists, it will be only updated. %% If user already exists, it will be only updated.
add_user(El, Domain, User, <<"plaintext">>, none) -> add_user(El, Domain, User, <<"plaintext">>, none) ->
@ -174,7 +173,7 @@ add_user(El, Domain, User, <<"plaintext">>, none) ->
io:format(""), io:format(""),
populate_user_with_elements(El, Domain, User), populate_user_with_elements(El, Domain, User),
ok; ok;
add_user(El, Domain, User, PasswordFormat, Password) -> add_user(El, Domain, User, <<"scram">> = PasswordFormat, Password) ->
Password2 = prepare_password(PasswordFormat, Password, El), Password2 = prepare_password(PasswordFormat, Password, El),
case create_user(User,Password2,Domain) of case create_user(User,Password2,Domain) of
ok -> ok ->
@ -217,7 +216,7 @@ populate_user_with_elements(El, Domain, User) ->
%% -> ok | {atomic, exists} | {error, not_allowed} %% -> ok | {atomic, exists} | {error, not_allowed}
%% @doc Create a new user %% @doc Create a new user
create_user(User,Password,Domain) -> create_user(User,Password,Domain) ->
case ejabberd_auth:try_register(?BTL(User),?BTL(Domain),?BTL(Password)) of case ejabberd_auth:try_register(?BTL(User),?BTL(Domain),Password) of
{atomic,ok} -> ok; {atomic,ok} -> ok;
{atomic, exists} -> {atomic, exists}; {atomic, exists} -> {atomic, exists};
{error, not_allowed} -> {error, not_allowed}; {error, not_allowed} -> {error, not_allowed};

View File

@ -452,24 +452,24 @@ normal_state({route, From, ToNick,
From, Err); From, Err);
_ -> _ ->
ToJID = find_jid_by_nick(ToNick, StateData), ToJID = find_jid_by_nick(ToNick, StateData),
SrcIsVisitor = is_visitor(From, StateData), case ToJID of
DstIsModerator = is_moderator(ToJID, StateData), false ->
PmFromVisitors = (StateData#state.config)#config.allow_private_messages_from_visitors, ErrText = "Recipient is not in the conference room",
if SrcIsVisitor == false; Err = exmpp_stanza:reply_with_error(Packet,
PmFromVisitors == anyone; exmpp_stanza:error(Packet#xmlel.ns, 'item-not-found',
(PmFromVisitors == moderators) and (DstIsModerator) -> {Lang, translate:translate(Lang, ErrText)})),
case ToJID of ejabberd_router:route(
false -> jid_replace_resource(
ErrText = "Recipient is not in the conference room", StateData#state.jid,
Err = exmpp_stanza:reply_with_error(Packet, ToNick),
exmpp_stanza:error(Packet#xmlel.ns, 'item-not-found', From, Err);
{Lang, translate:translate(Lang, ErrText)})), _ ->
ejabberd_router:route( SrcIsVisitor = is_visitor(From, StateData),
jid_replace_resource( DstIsModerator = is_moderator(ToJID, StateData),
StateData#state.jid, PmFromVisitors = (StateData#state.config)#config.allow_private_messages_from_visitors,
ToNick), if SrcIsVisitor == false;
From, Err); PmFromVisitors == anyone;
_ -> (PmFromVisitors == moderators) and (DstIsModerator) ->
{ok, #user{nick = FromNick}} = {ok, #user{nick = FromNick}} =
?DICT:find(jlib:jid_tolower(From), ?DICT:find(jlib:jid_tolower(From),
StateData#state.users), StateData#state.users),
@ -477,18 +477,19 @@ normal_state({route, From, ToNick,
jid_replace_resource( jid_replace_resource(
StateData#state.jid, StateData#state.jid,
FromNick), FromNick),
ToJID, Packet) ToJID, Packet);
end; true ->
true -> ErrText = "It is not allowed to send private messages",
ErrText = "It is not allowed to send private messages", Err = exmpp_stanza:reply_with_error(Packet,
Err = exmpp_stanza:reply_with_error(Packet, exmpp_stanza:error(Packet#xmlel.ns, 'forbidden',
exmpp_stanza:error(Packet#xmlel.ns, 'forbidden', {Lang, translate:translate(Lang, ErrText)})),
{Lang, translate:translate(Lang, ErrText)})), ejabberd_router:route(
ejabberd_router:route( jid_replace_resource(
jid_replace_resource( StateData#state.jid,
StateData#state.jid, ToNick),
ToNick), From, Err)
From, Err)
end
end end
end; end;
{true, false} -> {true, false} ->

View File

@ -162,12 +162,7 @@ get_local_stat(_Server, [], Name) when Name == <<"users/all-hosts/total">> ->
ejabberd_auth:get_vh_registered_users_number(Host) ejabberd_auth:get_vh_registered_users_number(Host)
+ Total + Total
end, 0, ejabberd_config:get_global_option(hosts)), end, 0, ejabberd_config:get_global_option(hosts)),
case NumUsers of ?STATVAL(list_to_binary(integer_to_list(NumUsers)), <<"users">>);
{'EXIT', _Reason} ->
?STATERR(<<"500">>, <<"Internal Server Error">>);
Users ->
?STATVAL(list_to_binary(integer_to_list(Users)), <<"users">>)
end;
get_local_stat(_Server, _, Name) -> get_local_stat(_Server, _, Name) ->
?STATERR(<<"404">>, <<"Not Found">>). ?STATERR(<<"404">>, <<"Not Found">>).