]> granicus.if.org Git - ejabberd/commitdiff
Fix some type specs and errors 13.12
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 10 Dec 2013 07:40:43 +0000 (17:40 +1000)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 10 Dec 2013 11:44:46 +0000 (21:44 +1000)
src/acl.erl
src/ejabberd_ctl.erl
src/ejabberd_web_admin.erl
src/mod_configure.erl
src/mod_disco.erl
src/mod_register.erl
src/mod_version.erl
src/shaper.erl

index d669d289657a8a943d2d6a7bcd656754f1ac9f68..3cd78946334239b1e4ac5186459eddb6e7ce696f 100644 (file)
@@ -37,7 +37,7 @@
 -include("jlib.hrl").
 
 -record(acl, {aclname, aclspec}).
--record(access, {name       :: access_name(),
+-record(access, {name       :: aclname(),
                  rules = [] :: [access_rule()]}).
 
 -type regexp() :: binary().
index d3944e26622f597fa7a157add8a6ad2c330c0969..46a3650193ed784e33f5dd9083812464e64052f4 100644 (file)
@@ -84,7 +84,7 @@ start() ->
            Node = list_to_atom(SNode1),
            Status = case rpc:call(Node, ?MODULE, process, [Args]) of
                         {badrpc, Reason} ->
-                            ?PRINT("Failed RPC connection to the node ~p: ~p~n",
+                            print("Failed RPC connection to the node ~p: ~p~n",
                                    [Node, Reason]),
                             %% TODO: show minimal start help
                             ?STATUS_BADRPC;
@@ -131,17 +131,17 @@ unregister_commands(CmdDescs, Module, Function) ->
 %% they are usable even if ejabberd is completely stopped.
 process(["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]),
     case lists:keysearch(ejabberd, 1, application:which_applications()) of
         false ->
             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"
                   "or other files in that directory.~n", [EjabberdLogPath]),
             ?STATUS_ERROR;
         {value, {_, _, Version}} ->
-            ?PRINT("ejabberd ~s is running in that node~n", [Version]),
+            print("ejabberd ~s is running in that node~n", [Version]),
             ?STATUS_SUCCESS
     end;
 
@@ -155,7 +155,7 @@ process(["restart"]) ->
     ?STATUS_SUCCESS;
 
 process(["mnesia"]) ->
-    ?PRINT("~p~n", [mnesia:system_info(all)]),
+    print("~p~n", [mnesia:system_info(all)]),
     ?STATUS_SUCCESS;
 
 process(["mnesia", "info"]) ->
@@ -164,8 +164,8 @@ process(["mnesia", "info"]) ->
 
 process(["mnesia", Arg]) ->
     case catch mnesia:system_info(list_to_atom(Arg)) of
-       {'EXIT', Error} -> ?PRINT("Error: ~p~n", [Error]);
-       Return -> ?PRINT("~p~n", [Return])
+       {'EXIT', Error} -> print("Error: ~p~n", [Error]);
+       Return -> print("~p~n", [Return])
     end,
     ?STATUS_SUCCESS;
 
@@ -261,7 +261,7 @@ try_run_ctp(Args, Auth, AccessCommands) ->
        Error:Why ->
             %% In this case probably ejabberd is not started, so let's show Status
             process(["status"]),
-            ?PRINT("~n", []),
+            print("~n", []),
            {io_lib:format("Error in ejabberd ctl process: '~p' ~p", [Error, Why]), ?STATUS_USAGE}
     end.
 
@@ -457,14 +457,14 @@ print_usage(HelpMode, MaxC, ShCode) ->
        get_list_commands() ++
        get_list_ctls(),
 
-    ?PRINT(
+    print(
        ["Usage: ", ?B("ejabberdctl"), " [--node ", ?U("nodename"), "] [--auth ",
        ?U("user"), " ", ?U("host"), " ", ?U("password"), "] ",
        ?U("command"), " [", ?U("options"), "]\n"
        "\n"
        "Available commands in this ejabberd node:\n"], []),
     print_usage_commands(HelpMode, MaxC, ShCode, AllCommands),
-    ?PRINT(
+    print(
        ["\n"
        "Examples:\n"
        "  ejabberdctl restart\n"
@@ -498,7 +498,7 @@ print_usage_commands(HelpMode, MaxC, ShCode, Commands) ->
     %% Convert its definition to a line
     FmtCmdDescs = format_command_lines(CmdArgsLenDescsSorted, MaxCmdLen, MaxC, ShCode, HelpMode),
 
-    ?PRINT([FmtCmdDescs], []).
+    print([FmtCmdDescs], []).
 
 
 %% Get some info about the shell:
@@ -584,20 +584,20 @@ format_command_lines(CALD, _MaxCmdLen, MaxC, ShCode, long) ->
 %%-----------------------------
 
 print_usage_tags(MaxC, ShCode) ->
-    ?PRINT("Available tags and commands:", []),
+    print("Available tags and commands:", []),
     TagsCommands = ejabberd_commands:get_tags_commands(),
     lists:foreach(
       fun({Tag, Commands} = _TagCommands) ->
-             ?PRINT(["\n\n  ", ?B(Tag), "\n     "], []),
+             print(["\n\n  ", ?B(Tag), "\n     "], []),
              Words = lists:sort(Commands),
              Desc = prepare_long_line(5, MaxC, Words),
-             ?PRINT(Desc, [])
+             print(Desc, [])
       end,
       TagsCommands),
-    ?PRINT("\n\n", []).
+    print("\n\n", []).
 
 print_usage_tags(Tag, MaxC, ShCode) ->
-    ?PRINT(["Available commands with tag ", ?B(Tag), ":", "\n"], []),
+    print(["Available commands with tag ", ?B(Tag), ":", "\n"], []),
     HelpMode = long,
     TagsCommands = ejabberd_commands:get_tags_commands(),
     CommandsNames = case lists:keysearch(Tag, 1, TagsCommands) of
@@ -615,7 +615,7 @@ print_usage_tags(Tag, MaxC, ShCode) ->
                     end,
                     CommandsNames),
     print_usage_commands(HelpMode, MaxC, ShCode, CommandsList),
-    ?PRINT("\n", []).
+    print("\n", []).
 
 
 %%-----------------------------
@@ -673,7 +673,7 @@ print_usage_commands2(Cmds, MaxC, ShCode) ->
       fun(Cmd, Remaining) ->
              print_usage_command(Cmd, MaxC, ShCode),
              case Remaining > 1 of
-                 true -> ?PRINT([" ", lists:duplicate(MaxC, 126), " \n"], []);
+                 true -> print([" ", lists:duplicate(MaxC, 126), " \n"], []);
                  false -> ok
              end,
              {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"]
                      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)
   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
     [ElementFmt, ",\n", MarginString, format_usage_tuple(ElementsDef, Indentation)].
 
+print(Format, Args) ->
+    io:format(lists:flatten(Format), Args).
 
 %%-----------------------------
 %% Command managment
index 5744a08665e363560eb5d653f89f9e1cd49a2ebc..a1c4b25a987d58df9a63de07ed9e5cec7b544eb1 100644 (file)
@@ -646,10 +646,7 @@ process_admin(Host,
                  {ok, Tokens, _} ->
                      case erl_parse:parse_term(Tokens) of
                        {ok, NewACLs} ->
-                           case acl:add_list(Host, NewACLs, true) of
-                             ok -> ok;
-                             _ -> error
-                           end;
+                            acl:add_list(Host, NewACLs, true);
                        _ -> error
                      end;
                  _ -> error
@@ -689,10 +686,7 @@ process_admin(Host,
                  {'EXIT', _} -> error;
                  NewACLs ->
                      ?INFO_MSG("NewACLs at ~s: ~p", [Host, NewACLs]),
-                     case acl:add_list(Host, NewACLs, true) of
-                       ok -> ?INFO_MSG("NewACLs: ok", []), ok;
-                       _ -> error
-                     end
+                     acl:add_list(Host, NewACLs, true)
                end;
            _ -> nothing
          end,
index 6462ba133154cac1a5b1bb0f5c2e957b033038a8..b6c8f55b779c57498718cb97de8705807b2856ce 100644 (file)
@@ -1756,10 +1756,8 @@ set_form(_From, Host, [<<"config">>, <<"acls">>], _Lang,
            {ok, Tokens, _} ->
                case erl_parse:parse_term(Tokens) of
                  {ok, ACLs} ->
-                     case acl:add_list(Host, ACLs, true) of
-                       ok -> {result, []};
-                       _ -> {error, ?ERR_BAD_REQUEST}
-                     end;
+                     acl:add_list(Host, ACLs, true),
+                      {result, []};
                  _ -> {error, ?ERR_BAD_REQUEST}
                end;
            _ -> {error, ?ERR_BAD_REQUEST}
index df3f320c79090181fdddb221e4b9b525610044e3..b11c9629aa729e2264b25abaebd4e5c50b530f3d 100644 (file)
@@ -491,7 +491,7 @@ get_fields_xml(Host, Module) ->
                                  Name = proplists:get_value(names, Opts, <<>>),
                                  URLs = proplists:get_value(urls, Opts, []),
                                  {Mods, Name, URLs}
-                         end, lists:flatmap(L))
+                         end, lists:flatten(L))
                end, []),
     Fields_good = lists:filter(fun ({Modules, _, _}) ->
                                       case Modules of
index 197927df031bfdbcf4e51ca11c693df1a240510f..c7da225ef031239e6daa7767221c09a3782009d5 100644 (file)
@@ -677,5 +677,7 @@ check_ip_access({User, Server, Resource}, IPAccess) ->
         _ ->
             deny
     end;
+check_ip_access(undefined, _IPAccess) ->
+    deny;
 check_ip_access(IPAddress, IPAccess) ->
     acl:match_rule(global, IPAccess, IPAddress).
index a36f62889bcbd8343e7a406966706464b22046be..3ae9b842889847d1c3bede16e0b7ff07700dd627 100644 (file)
@@ -78,12 +78,8 @@ process_local_iq(_From, To,
     end.
 
 get_os() ->
-    OSType = case os:type() of
-              {Osfamily, 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,
+    {Osfamily, Osname} = os:type(),
+    OSType = list_to_binary([atom_to_list(Osfamily), $/, atom_to_list(Osname)]),
     OSVersion = case os:version() of
                  {Major, Minor, Release} ->
                      iolist_to_binary(io_lib:format("~w.~w.~w",
index 41e5f062605f68159e7693eb00d7df2f3cc5a358..b9f4603958ab4d7c9c1df14b67ee9336649b714f 100644 (file)
@@ -122,9 +122,9 @@ update(#maxrate{} = State, Size) ->
 transform_options(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];
-transform_options({shaper, Name, none}, Opts) ->
+transform_options({OptName, Name, none}, Opts) when OptName == shaper ->
     [{shaper, [{Name, none}]}|Opts];
 transform_options(Opt, Opts) ->
     [Opt|Opts].