From 6c37f735da6905704d5451e3209fd94cec2aaac1 Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Thu, 4 Feb 2021 20:42:55 +0100 Subject: [PATCH] Simplify some deprecated uses of http_uri --- src/auth/ejabberd_auth_http.erl | 7 +++---- src/mod_muc_room.erl | 15 ++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/auth/ejabberd_auth_http.erl b/src/auth/ejabberd_auth_http.erl index bc18a7484a..9c49c7d529 100644 --- a/src/auth/ejabberd_auth_http.erl +++ b/src/auth/ejabberd_auth_http.erl @@ -191,10 +191,9 @@ remove_user_req(LUser, LServer, Password, Method) -> make_req(_, _, LUser, LServer, _) when LUser == error orelse LServer == error -> {error, invalid_jid}; make_req(Method, Path, LUser, LServer, Password) -> - LUserE = list_to_binary(http_uri:encode(binary_to_list(LUser))), - LServerE = list_to_binary(http_uri:encode(binary_to_list(LServer))), - PasswordE = list_to_binary(http_uri:encode(binary_to_list(Password))), - Query = <<"user=", LUserE/binary, "&server=", LServerE/binary, "&pass=", PasswordE/binary>>, + Query = uri_string:compose_query([{<<"user">>, LUser}, + {<<"server">>, LServer}, + {<<"pass">>, Password}]), Header = case ejabberd_auth:get_opt(LServer, basic_auth) of undefined -> []; diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index 19d5ca7b40..406bbb222a 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -1919,12 +1919,12 @@ perform_http_auth(From, Nick, Packet, Role, Password, StateData) -> end. make_http_auth_request(From, RoomJid, Password, Pool) -> - FromVal = uri_encode(jid:to_binary(From)), - RoomJidVal = uri_encode(jid:to_binary(RoomJid)), - PassVal = uri_encode(Password), - Path = <<"check_password?from=", FromVal/binary, - "&to=", RoomJidVal/binary, - "&pass=", PassVal/binary>>, + Query = uri_string:compose_query( + [{<<"from">>, jid:to_binary(From)}, + {<<"to">>, jid:to_binary(RoomJid)}, + {<<"pass">>, Password} + ]), + Path = <<"check_password", "?", Query/binary>>, case mongoose_http_client:get(global, Pool, Path, []) of {ok, {<<"200">>, Body}} -> decode_http_auth_response(Body); _ -> error @@ -1937,9 +1937,6 @@ handle_http_auth_result({invalid_password, ErrorMsg}, From, Nick, Packet, _Role, handle_http_auth_result(error, From, Nick, Packet, _Role, StateData) -> reply_service_unavailable(From, Nick, Packet, StateData, <<"Internal server error">>). -uri_encode(Bin) -> - list_to_binary(http_uri:encode(binary_to_list(Bin))). - decode_http_auth_response(Body) -> try decode_json_auth_response(Body) of {0, _} ->