Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify some deprecated uses of http_uri #3026

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/auth/ejabberd_auth_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
[];
Expand Down
15 changes: 6 additions & 9 deletions src/mod_muc_room.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, _} ->
Expand Down