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

Fix some type specs and errors

This commit is contained in:
Evgeniy Khramtsov 2013-12-10 17:40:43 +10:00
parent 33764bb931
commit d03de1bb43
8 changed files with 33 additions and 41 deletions

View File

@ -37,7 +37,7 @@
-include("jlib.hrl"). -include("jlib.hrl").
-record(acl, {aclname, aclspec}). -record(acl, {aclname, aclspec}).
-record(access, {name :: access_name(), -record(access, {name :: aclname(),
rules = [] :: [access_rule()]}). rules = [] :: [access_rule()]}).
-type regexp() :: binary(). -type regexp() :: binary().

View File

@ -84,7 +84,7 @@ start() ->
Node = list_to_atom(SNode1), Node = list_to_atom(SNode1),
Status = case rpc:call(Node, ?MODULE, process, [Args]) of Status = case rpc:call(Node, ?MODULE, process, [Args]) of
{badrpc, Reason} -> {badrpc, Reason} ->
?PRINT("Failed RPC connection to the node ~p: ~p~n", print("Failed RPC connection to the node ~p: ~p~n",
[Node, Reason]), [Node, Reason]),
%% TODO: show minimal start help %% TODO: show minimal start help
?STATUS_BADRPC; ?STATUS_BADRPC;
@ -131,17 +131,17 @@ unregister_commands(CmdDescs, Module, Function) ->
%% they are usable even if ejabberd is completely stopped. %% they are usable even if ejabberd is completely stopped.
process(["status"]) -> process(["status"]) ->
{InternalStatus, ProvidedStatus} = init:get_status(), {InternalStatus, ProvidedStatus} = init:get_status(),
?PRINT("The node ~p is ~p with status: ~p~n", print("The node ~p is ~p with status: ~p~n",
[node(), InternalStatus, ProvidedStatus]), [node(), InternalStatus, ProvidedStatus]),
case lists:keysearch(ejabberd, 1, application:which_applications()) of case lists:keysearch(ejabberd, 1, application:which_applications()) of
false -> false ->
EjabberdLogPath = ejabberd_logger:get_log_path(), EjabberdLogPath = ejabberd_logger:get_log_path(),
?PRINT("ejabberd is not running in that node~n" print("ejabberd is not running in that node~n"
"Check for error messages: ~s~n" "Check for error messages: ~s~n"
"or other files in that directory.~n", [EjabberdLogPath]), "or other files in that directory.~n", [EjabberdLogPath]),
?STATUS_ERROR; ?STATUS_ERROR;
{value, {_, _, Version}} -> {value, {_, _, Version}} ->
?PRINT("ejabberd ~s is running in that node~n", [Version]), print("ejabberd ~s is running in that node~n", [Version]),
?STATUS_SUCCESS ?STATUS_SUCCESS
end; end;
@ -155,7 +155,7 @@ process(["restart"]) ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
process(["mnesia"]) -> process(["mnesia"]) ->
?PRINT("~p~n", [mnesia:system_info(all)]), print("~p~n", [mnesia:system_info(all)]),
?STATUS_SUCCESS; ?STATUS_SUCCESS;
process(["mnesia", "info"]) -> process(["mnesia", "info"]) ->
@ -164,8 +164,8 @@ process(["mnesia", "info"]) ->
process(["mnesia", Arg]) -> process(["mnesia", Arg]) ->
case catch mnesia:system_info(list_to_atom(Arg)) of case catch mnesia:system_info(list_to_atom(Arg)) of
{'EXIT', Error} -> ?PRINT("Error: ~p~n", [Error]); {'EXIT', Error} -> print("Error: ~p~n", [Error]);
Return -> ?PRINT("~p~n", [Return]) Return -> print("~p~n", [Return])
end, end,
?STATUS_SUCCESS; ?STATUS_SUCCESS;
@ -261,7 +261,7 @@ try_run_ctp(Args, Auth, AccessCommands) ->
Error:Why -> Error:Why ->
%% In this case probably ejabberd is not started, so let's show Status %% In this case probably ejabberd is not started, so let's show Status
process(["status"]), process(["status"]),
?PRINT("~n", []), print("~n", []),
{io_lib:format("Error in ejabberd ctl process: '~p' ~p", [Error, Why]), ?STATUS_USAGE} {io_lib:format("Error in ejabberd ctl process: '~p' ~p", [Error, Why]), ?STATUS_USAGE}
end. end.
@ -457,14 +457,14 @@ print_usage(HelpMode, MaxC, ShCode) ->
get_list_commands() ++ get_list_commands() ++
get_list_ctls(), get_list_ctls(),
?PRINT( print(
["Usage: ", ?B("ejabberdctl"), " [--node ", ?U("nodename"), "] [--auth ", ["Usage: ", ?B("ejabberdctl"), " [--node ", ?U("nodename"), "] [--auth ",
?U("user"), " ", ?U("host"), " ", ?U("password"), "] ", ?U("user"), " ", ?U("host"), " ", ?U("password"), "] ",
?U("command"), " [", ?U("options"), "]\n" ?U("command"), " [", ?U("options"), "]\n"
"\n" "\n"
"Available commands in this ejabberd node:\n"], []), "Available commands in this ejabberd node:\n"], []),
print_usage_commands(HelpMode, MaxC, ShCode, AllCommands), print_usage_commands(HelpMode, MaxC, ShCode, AllCommands),
?PRINT( print(
["\n" ["\n"
"Examples:\n" "Examples:\n"
" ejabberdctl restart\n" " ejabberdctl restart\n"
@ -498,7 +498,7 @@ print_usage_commands(HelpMode, MaxC, ShCode, Commands) ->
%% Convert its definition to a line %% Convert its definition to a line
FmtCmdDescs = format_command_lines(CmdArgsLenDescsSorted, MaxCmdLen, MaxC, ShCode, HelpMode), FmtCmdDescs = format_command_lines(CmdArgsLenDescsSorted, MaxCmdLen, MaxC, ShCode, HelpMode),
?PRINT([FmtCmdDescs], []). print([FmtCmdDescs], []).
%% Get some info about the shell: %% Get some info about the shell:
@ -584,20 +584,20 @@ format_command_lines(CALD, _MaxCmdLen, MaxC, ShCode, long) ->
%%----------------------------- %%-----------------------------
print_usage_tags(MaxC, ShCode) -> print_usage_tags(MaxC, ShCode) ->
?PRINT("Available tags and commands:", []), print("Available tags and commands:", []),
TagsCommands = ejabberd_commands:get_tags_commands(), TagsCommands = ejabberd_commands:get_tags_commands(),
lists:foreach( lists:foreach(
fun({Tag, Commands} = _TagCommands) -> fun({Tag, Commands} = _TagCommands) ->
?PRINT(["\n\n ", ?B(Tag), "\n "], []), print(["\n\n ", ?B(Tag), "\n "], []),
Words = lists:sort(Commands), Words = lists:sort(Commands),
Desc = prepare_long_line(5, MaxC, Words), Desc = prepare_long_line(5, MaxC, Words),
?PRINT(Desc, []) print(Desc, [])
end, end,
TagsCommands), TagsCommands),
?PRINT("\n\n", []). print("\n\n", []).
print_usage_tags(Tag, MaxC, ShCode) -> print_usage_tags(Tag, MaxC, ShCode) ->
?PRINT(["Available commands with tag ", ?B(Tag), ":", "\n"], []), print(["Available commands with tag ", ?B(Tag), ":", "\n"], []),
HelpMode = long, HelpMode = long,
TagsCommands = ejabberd_commands:get_tags_commands(), TagsCommands = ejabberd_commands:get_tags_commands(),
CommandsNames = case lists:keysearch(Tag, 1, TagsCommands) of CommandsNames = case lists:keysearch(Tag, 1, TagsCommands) of
@ -615,7 +615,7 @@ print_usage_tags(Tag, MaxC, ShCode) ->
end, end,
CommandsNames), CommandsNames),
print_usage_commands(HelpMode, MaxC, ShCode, CommandsList), print_usage_commands(HelpMode, MaxC, ShCode, CommandsList),
?PRINT("\n", []). print("\n", []).
%%----------------------------- %%-----------------------------
@ -673,7 +673,7 @@ print_usage_commands2(Cmds, MaxC, ShCode) ->
fun(Cmd, Remaining) -> fun(Cmd, Remaining) ->
print_usage_command(Cmd, MaxC, ShCode), print_usage_command(Cmd, MaxC, ShCode),
case Remaining > 1 of case Remaining > 1 of
true -> ?PRINT([" ", lists:duplicate(MaxC, 126), " \n"], []); true -> print([" ", lists:duplicate(MaxC, 126), " \n"], []);
false -> ok false -> ok
end, end,
{ok, Remaining-1} {ok, Remaining-1}
@ -749,7 +749,7 @@ print_usage_command(Cmd, C, MaxC, ShCode) ->
false -> [" ", ?B("Note:"), " This command cannot be executed using ejabberdctl. Try ejabberd_xmlrpc.\n\n"] false -> [" ", ?B("Note:"), " This command cannot be executed using ejabberdctl. Try ejabberd_xmlrpc.\n\n"]
end, end,
?PRINT(["\n", NameFmt, "\n", ArgsFmt, "\n", ReturnsFmt, "\n\n", XmlrpcFmt, TagsFmt, "\n\n", DescFmt, "\n\n", LongDescFmt, NoteEjabberdctl], []). print(["\n", NameFmt, "\n", ArgsFmt, "\n", ReturnsFmt, "\n\n", XmlrpcFmt, TagsFmt, "\n\n", DescFmt, "\n\n", LongDescFmt, NoteEjabberdctl], []).
format_usage_ctype(Type, _Indentation) format_usage_ctype(Type, _Indentation)
when (Type==atom) or (Type==integer) or (Type==string) or (Type==binary) or (Type==rescode) or (Type==restuple)-> when (Type==atom) or (Type==integer) or (Type==string) or (Type==binary) or (Type==rescode) or (Type==restuple)->
@ -780,6 +780,8 @@ format_usage_tuple([ElementDef | ElementsDef], Indentation) ->
MarginString = lists:duplicate(Indentation, $\s), % Put spaces MarginString = lists:duplicate(Indentation, $\s), % Put spaces
[ElementFmt, ",\n", MarginString, format_usage_tuple(ElementsDef, Indentation)]. [ElementFmt, ",\n", MarginString, format_usage_tuple(ElementsDef, Indentation)].
print(Format, Args) ->
io:format(lists:flatten(Format), Args).
%%----------------------------- %%-----------------------------
%% Command managment %% Command managment

View File

@ -646,10 +646,7 @@ process_admin(Host,
{ok, Tokens, _} -> {ok, Tokens, _} ->
case erl_parse:parse_term(Tokens) of case erl_parse:parse_term(Tokens) of
{ok, NewACLs} -> {ok, NewACLs} ->
case acl:add_list(Host, NewACLs, true) of acl:add_list(Host, NewACLs, true);
ok -> ok;
_ -> error
end;
_ -> error _ -> error
end; end;
_ -> error _ -> error
@ -689,10 +686,7 @@ process_admin(Host,
{'EXIT', _} -> error; {'EXIT', _} -> error;
NewACLs -> NewACLs ->
?INFO_MSG("NewACLs at ~s: ~p", [Host, NewACLs]), ?INFO_MSG("NewACLs at ~s: ~p", [Host, NewACLs]),
case acl:add_list(Host, NewACLs, true) of acl:add_list(Host, NewACLs, true)
ok -> ?INFO_MSG("NewACLs: ok", []), ok;
_ -> error
end
end; end;
_ -> nothing _ -> nothing
end, end,

View File

@ -1756,10 +1756,8 @@ set_form(_From, Host, [<<"config">>, <<"acls">>], _Lang,
{ok, Tokens, _} -> {ok, Tokens, _} ->
case erl_parse:parse_term(Tokens) of case erl_parse:parse_term(Tokens) of
{ok, ACLs} -> {ok, ACLs} ->
case acl:add_list(Host, ACLs, true) of acl:add_list(Host, ACLs, true),
ok -> {result, []}; {result, []};
_ -> {error, ?ERR_BAD_REQUEST}
end;
_ -> {error, ?ERR_BAD_REQUEST} _ -> {error, ?ERR_BAD_REQUEST}
end; end;
_ -> {error, ?ERR_BAD_REQUEST} _ -> {error, ?ERR_BAD_REQUEST}

View File

@ -491,7 +491,7 @@ get_fields_xml(Host, Module) ->
Name = proplists:get_value(names, Opts, <<>>), Name = proplists:get_value(names, Opts, <<>>),
URLs = proplists:get_value(urls, Opts, []), URLs = proplists:get_value(urls, Opts, []),
{Mods, Name, URLs} {Mods, Name, URLs}
end, lists:flatmap(L)) end, lists:flatten(L))
end, []), end, []),
Fields_good = lists:filter(fun ({Modules, _, _}) -> Fields_good = lists:filter(fun ({Modules, _, _}) ->
case Modules of case Modules of

View File

@ -677,5 +677,7 @@ check_ip_access({User, Server, Resource}, IPAccess) ->
_ -> _ ->
deny deny
end; end;
check_ip_access(undefined, _IPAccess) ->
deny;
check_ip_access(IPAddress, IPAccess) -> check_ip_access(IPAddress, IPAccess) ->
acl:match_rule(global, IPAccess, IPAddress). acl:match_rule(global, IPAccess, IPAddress).

View File

@ -78,12 +78,8 @@ process_local_iq(_From, To,
end. end.
get_os() -> get_os() ->
OSType = case os:type() of {Osfamily, Osname} = os:type(),
{Osfamily, Osname} -> OSType = list_to_binary([atom_to_list(Osfamily), $/, atom_to_list(Osname)]),
<<(iolist_to_binary(atom_to_list(Osfamily)))/binary,
"/", (iolist_to_binary(atom_to_list(Osname)))/binary>>;
Osfamily -> iolist_to_binary(atom_to_list(Osfamily))
end,
OSVersion = case os:version() of OSVersion = case os:version() of
{Major, Minor, Release} -> {Major, Minor, Release} ->
iolist_to_binary(io_lib:format("~w.~w.~w", iolist_to_binary(io_lib:format("~w.~w.~w",

View File

@ -122,9 +122,9 @@ update(#maxrate{} = State, Size) ->
transform_options(Opts) -> transform_options(Opts) ->
lists:foldl(fun transform_options/2, [], Opts). lists:foldl(fun transform_options/2, [], Opts).
transform_options({shaper, Name, {maxrate, N}}, Opts) -> transform_options({OptName, Name, {maxrate, N}}, Opts) when OptName == shaper ->
[{shaper, [{Name, N}]}|Opts]; [{shaper, [{Name, N}]}|Opts];
transform_options({shaper, Name, none}, Opts) -> transform_options({OptName, Name, none}, Opts) when OptName == shaper ->
[{shaper, [{Name, none}]}|Opts]; [{shaper, [{Name, none}]}|Opts];
transform_options(Opt, Opts) -> transform_options(Opt, Opts) ->
[Opt|Opts]. [Opt|Opts].