24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-10 21:47:01 +02:00

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;
@ -193,5 +187,5 @@ is_alpha(Char) when Char >= $a, Char =< $z ->
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,12 +452,6 @@ 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),
DstIsModerator = is_moderator(ToJID, StateData),
PmFromVisitors = (StateData#state.config)#config.allow_private_messages_from_visitors,
if SrcIsVisitor == false;
PmFromVisitors == anyone;
(PmFromVisitors == moderators) and (DstIsModerator) ->
case ToJID of case ToJID of
false -> false ->
ErrText = "Recipient is not in the conference room", ErrText = "Recipient is not in the conference room",
@ -470,6 +464,12 @@ normal_state({route, From, ToNick,
ToNick), ToNick),
From, Err); From, Err);
_ -> _ ->
SrcIsVisitor = is_visitor(From, StateData),
DstIsModerator = is_moderator(ToJID, StateData),
PmFromVisitors = (StateData#state.config)#config.allow_private_messages_from_visitors,
if SrcIsVisitor == false;
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,8 +477,7 @@ 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,
@ -489,6 +488,8 @@ normal_state({route, From, ToNick,
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">>).