From b8c42a476674eea0813791502fc2d906cb01d681 Mon Sep 17 00:00:00 2001 From: Badlop Date: Fri, 23 Aug 2019 12:59:53 +0200 Subject: [PATCH] Fix errors detected with Dialyzer (#277) --- mod_log_chat/src/mod_log_chat.erl | 19 ++++++------- mod_logsession/src/mod_logsession.erl | 4 +-- mod_muc_log_http/src/mod_muc_log_http.erl | 3 +- mod_rest/src/mod_rest.erl | 13 ++++----- mod_statsdx/src/mod_statsdx.erl | 34 ++++++++--------------- mod_webpresence/src/mod_webpresence.erl | 7 +---- 6 files changed, 28 insertions(+), 52 deletions(-) diff --git a/mod_log_chat/src/mod_log_chat.erl b/mod_log_chat/src/mod_log_chat.erl index 39a1689..6e59d9b 100644 --- a/mod_log_chat/src/mod_log_chat.erl +++ b/mod_log_chat/src/mod_log_chat.erl @@ -97,10 +97,10 @@ log_packet_receive({Packet, C2SState}) -> log_packet(From, To, #message{type = Type} = Packet, Host) -> case Type of groupchat -> %% mod_muc_log already does it - ?DEBUG("dropping groupchat: ~s", [fxml:element_to_binary(Packet)]), + ?DEBUG("dropping groupchat: ~s", [fxml:element_to_binary(xmpp:encode(Packet))]), ok; error -> %% we don't log errors - ?DEBUG("dropping error: ~s", [fxml:element_to_binary(Packet)]), + ?DEBUG("dropping error: ~s", [fxml:element_to_binary(xmpp:encode(Packet))]), ok; _ -> write_packet(From, To, Packet, Host) @@ -116,15 +116,15 @@ write_packet(From, To, Packet, Host) -> end, Format = Config#config.format, {Subject, Body} = {case Packet#message.subject of - false -> - ""; + [] -> + <<>>; SubjEl -> escape(Format, xmpp:get_text(SubjEl)) end, escape(Format, xmpp:get_text(Packet#message.body))}, case Subject == <<>> andalso Body == <<>> of true -> %% don't log empty messages - ?DEBUG("not logging empty message from ~s",[jlib:jid_to_string(From)]), + ?DEBUG("not logging empty message from ~s",[jid:encode(From)]), ok; false -> Path = Config#config.path, @@ -153,7 +153,7 @@ write_packet(From, To, Packet, Host) -> end, ?DEBUG("FilenameTemplate ~p~n",[FilenameTemplate]), Filename = make_filename(FilenameTemplate, [Y, M, D]), - ?DEBUG("logging message from ~s into ~s~n",[jlib:jid_to_string(From), Filename]), + ?DEBUG("logging message from ~s into ~s~n",[jid:encode(From), Filename]), File = case file:read_file_info(Filename) of {ok, _} -> open_logfile(Filename); @@ -163,7 +163,7 @@ write_packet(From, To, Packet, Host) -> io:format(NewFile, Header, []), NewFile end, - MessageText = case Subject == [] of + MessageText = case Subject == <<>> of true -> Body; false -> @@ -209,10 +209,7 @@ escape(html, <<>>, Acc) -> Acc. escape(html, Text) -> escape(html,Text,<<>>); -escape(text, Text) -> - Text; -escape(_, "") -> - "". +escape(text, Text) -> Text. % return the number of occurence of Word in String count(String, Word) -> diff --git a/mod_logsession/src/mod_logsession.erl b/mod_logsession/src/mod_logsession.erl index d4b5cb5..451d712 100644 --- a/mod_logsession/src/mod_logsession.erl +++ b/mod_logsession/src/mod_logsession.erl @@ -153,6 +153,4 @@ make_message(Host, {failed_auth, Username, {IPTuple, IPPort}, Reason}) -> io_lib:format("Failed authentication for ~s@~s from ~s port ~p: ~s", [Username, Host, IPString, IPPort, Reason]); make_message(_Host, {forbidden, JID}) -> - io_lib:format("Forbidden session for ~s", - [jlib:jid_to_string(JID)]). - + io_lib:format("Forbidden session for ~s", [jid:encode(JID)]). diff --git a/mod_muc_log_http/src/mod_muc_log_http.erl b/mod_muc_log_http/src/mod_muc_log_http.erl index 88c1795..098abaa 100644 --- a/mod_muc_log_http/src/mod_muc_log_http.erl +++ b/mod_muc_log_http/src/mod_muc_log_http.erl @@ -50,7 +50,8 @@ serve(LocalPathBin, #request{host = Host} = Request) -> {error, eisdir} -> FileNameIndex = FileName ++ "/index.html", case file:read_file_info(FileNameIndex) of - {ok, _FileInfo} -> serve(LocalPath ++ ["index.html"], Request); + {ok, _FileInfo} -> + serve(LocalPathBin ++ [<<"index.html">>], Request); {error, _Error} -> show_dir_listing(FileName, LocalPath) end; {error, Error} -> diff --git a/mod_rest/src/mod_rest.erl b/mod_rest/src/mod_rest.erl index 493a70c..c434a6a 100644 --- a/mod_rest/src/mod_rest.erl +++ b/mod_rest/src/mod_rest.erl @@ -50,8 +50,7 @@ depends(_Host, _Opts) -> process([], #request{method = 'POST', data = Data, host = Host, ip = ClientIp}) -> try - {ClientAddress, _PortNumber} = ClientIp, - check_member_option(Host, ClientAddress, allowed_ips), + check_member_option(Host, ClientIp, allowed_ips), maybe_post_request(Data, Host, ClientIp) catch error:{badmatch, _} = Error -> @@ -136,9 +135,9 @@ check_member_option(Host, Element, Option) -> AllowedValues -> lists:member(Element, AllowedValues) end. -ip_matches(ClientIp, AllowedValues) -> +ip_matches({Address, Port}, AllowedValues) -> lists:any(fun({Net, Mask}) -> - acl:match_acl(useless_host, {ip,{Net,Mask}}, #{ip => {ClientIp,useless_port}}) + acl:match_acl(global, {ip,{Net,Mask}}, #{ip => Address}) end, AllowedValues). @@ -146,10 +145,8 @@ post_request(Pkt) -> From = xmpp:get_from(Pkt), LServer = From#jid.lserver, ejabberd_hooks:run_fold(user_send_packet, LServer, {Pkt, #{jid => From}}, []), - case ejabberd_router:route(Pkt) of - ok -> {200, [], <<"Ok">>}; - _ -> {500, [], <<"Error">>} - end. + ejabberd_router:route(Pkt), + {200, [], <<"Ok">>}. %% Split a line into args. Args are splitted by blankspaces. Args can be enclosed in "". %% diff --git a/mod_statsdx/src/mod_statsdx.erl b/mod_statsdx/src/mod_statsdx.erl index 5e5fcde..b04f3d2 100644 --- a/mod_statsdx/src/mod_statsdx.erl +++ b/mod_statsdx/src/mod_statsdx.erl @@ -1149,8 +1149,7 @@ web_page_main(_, #request{path=[<<"statsdx">>, <<"top">>, Topic, Topnumber], q = ]) ], {stop, Res}; -web_page_main(_, #request{path=[<<"statsdx">> | FilterURL], q = Q, lang = Lang} = _Request) -> - Filter = parse_url_filter(FilterURL), +web_page_main(_, #request{path=[<<"statsdx">> | Filter], q = Q, lang = Lang} = _Request) -> Sort_query = get_sort_query(Q), FilterS = io_lib:format("~p", [Filter]), Res = [?XC(<<"h1">>, <<(translate:translate(Lang, ?T("Statistics")))/binary, " Dx">>), @@ -1196,8 +1195,8 @@ get_sort_query(Q) -> _ -> {normal, 1} end. get_sort_query2(Q) -> - {value, {_, String}} = lists:keysearch("sort", 1, Q), - Integer = list_to_integer(String), + {value, {_, Binary}} = lists:keysearch(<<"sort">>, 1, Q), + Integer = binary_to_integer(Binary), case Integer >= 0 of true -> {ok, {normal, Integer}}; false -> {ok, {reverse, abs(Integer)}} @@ -1226,16 +1225,6 @@ make_sessions_table_tr(Lang) -> Titles), Titles_TR. -%% @spec (Filter::string()) -> [{Class::string(), Type::string()}] -parse_url_filter(FilterURL) -> - [List] = string:tokens(FilterURL, "/"), - parse_url_filter(List, []). -parse_url_filter([Class, Type | List], Res) -> - parse_url_filter(List, Res ++ [{Class, Type}]); -parse_url_filter(_, Res) -> - Res. - - web_page_node(_, Node, [<<"statsdx">>], _Query, Lang) -> TransactionsCommited = rpc:call(Node, mnesia, system_info, [transaction_commits]), @@ -1491,9 +1480,8 @@ web_page_host(_, Host, #request{path=[<<"statsdx">>, <<"top">>, Topic, Topnumber ]) ], {stop, Res}; -web_page_host(_, Host, #request{path=[<<"statsdx">> | FilterURL], q = Q, +web_page_host(_, Host, #request{path=[<<"statsdx">> | Filter], q = Q, lang = Lang} = _Request) -> - Filter = parse_url_filter(FilterURL), Sort_query = get_sort_query(Q), Res = [?XC(<<"h1">>, <<(translate:translate(Lang, ?T("Statistics")))/binary, " Dx">>), ?XC(<<"h2">>, list_to_binary("Sessions with: "++io_lib:format("~p", [Filter]))), @@ -1590,15 +1578,15 @@ get_sessions_filtered(Filter, server) -> end end, [], - ejabberd_config:get_myhosts()); + ejabberd_config:get_option(hosts)); get_sessions_filtered(Filter, Host) -> Match = case Filter of - [{<<"client">>, Client}] -> {{session, '$1'}, misc:binary_to_atom(Client), '$2', '$3', '$4', '$5', '$6', '$7'}; - [{<<"os">>, OS}] -> {{session, '$1'}, '$2', misc:binary_to_atom(OS), '$3', '$4', '$5', '$6', '$7'}; - [{<<"conntype">>, ConnType}] -> {{session, '$1'}, '$2', '$3', '$4', misc:binary_to_atom(ConnType), '$5', '$6', '$7'}; - [{<<"languages">>, Lang}] -> {{session, '$1'}, '$2', '$3', binary_to_list(Lang), '$4', '$5', '$6', '$7'}; - [{<<"client">>, Client}, {<<"os">>, OS}] -> {{session, '$1'}, misc:binary_to_atom(Client), misc:binary_to_atom(OS), '$3', '$4', '$5', '$6', '$7'}; - [{<<"client">>, Client}, {<<"conntype">>, ConnType}] -> {{session, '$1'}, misc:binary_to_atom(Client), '$2', '$3', misc:binary_to_atom(ConnType), '$5', '$6', '$7'}; + [<<"client">>, Client] -> {{session, '$1'}, misc:binary_to_atom(Client), '$2', '$3', '$4', '$5', '$6', '$7'}; + [<<"os">>, OS] -> {{session, '$1'}, '$2', misc:binary_to_atom(OS), '$3', '$4', '$5', '$6', '$7'}; + [<<"conntype">>, ConnType] -> {{session, '$1'}, '$2', '$3', '$4', misc:binary_to_atom(ConnType), '$5', '$6', '$7'}; + [<<"languages">>, Lang] -> {{session, '$1'}, '$2', '$3', binary_to_list(Lang), '$4', '$5', '$6', '$7'}; + [<<"client">>, Client, <<"os">>, OS] -> {{session, '$1'}, misc:binary_to_atom(Client), misc:binary_to_atom(OS), '$3', '$4', '$5', '$6', '$7'}; + [<<"client">>, Client, <<"conntype">>, ConnType] -> {{session, '$1'}, misc:binary_to_atom(Client), '$2', '$3', misc:binary_to_atom(ConnType), '$5', '$6', '$7'}; _ -> {{session, '$1'}, '$2', '$3', '$4', '$5'} end, ets:match_object(table_name(Host), Match). diff --git a/mod_webpresence/src/mod_webpresence.erl b/mod_webpresence/src/mod_webpresence.erl index effbcf0..aceaee2 100644 --- a/mod_webpresence/src/mod_webpresence.erl +++ b/mod_webpresence/src/mod_webpresence.erl @@ -242,7 +242,6 @@ do_route1(_Host, _From, _To, #iq{} = IQ, _BaseURL) -> do_route1(_Host, _From, _To, Packet, _BaseURL) -> case xmpp:get_type(Packet) of error -> ok; - result -> ok; _ -> Err = xmpp:err_item_not_found(), ejabberd_router:route_error(Packet, Err) @@ -397,10 +396,6 @@ iq_set_register_info(ServerHost, Host, From, Nick, Lang) -> case iq_set_register_info2(ServerHost, Host, From, Nick, Lang) of {atomic, ok} -> {result, undefined}; - {atomic, false} -> - ErrText = <<"That nickname is registered by another " - "person">>, - {error, xmpp:err_conflict(ErrText, Lang)}; _ -> Txt = <<"Database failure">>, {error, xmpp:err_internal_server_error(Txt, Lang)} @@ -919,7 +914,7 @@ process2([User, Server | Tail], Request) -> serve_web_presence(TypeURL, User, Server, Tail, #request{lang = Lang1, q = Q}) -> LServer = jid:nameprep(Server), - true = lists:member(Server, ejabberd_config:get_myhosts()), + true = lists:member(Server, ejabberd_config:get_option(hosts)), LUser = jid:nodeprep(User), WP = get_wp(LUser, LServer), case TypeURL of