From e5da1efea498d9dc04c649344e490e294e1975c1 Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 23 Jul 2025 21:21:28 +0200 Subject: [PATCH] misc: Move uri_parse/1 to yconf and merge with yconf:parse_uri/1 --- mix.exs | 2 +- mix.lock | 2 +- rebar.config | 2 +- rebar.lock | 11 ++++++----- src/misc.erl | 38 ++------------------------------------ 5 files changed, 11 insertions(+), 44 deletions(-) diff --git a/mix.exs b/mix.exs index 7fe59ec88..70a9c5fc9 100644 --- a/mix.exs +++ b/mix.exs @@ -131,7 +131,7 @@ defmodule Ejabberd.MixProject do {:pkix, "~> 1.0"}, {:stringprep, ">= 1.0.26"}, {:xmpp, ">= 1.11.0"}, - {:yconf, ">= 1.0.18"}] + {:yconf, git: "https://github.com/processone/yconf", ref: "c59f94097af5b78a8c6c72a143dcefaa5b3f406f", override: true}] ++ cond_deps() end diff --git a/mix.lock b/mix.lock index 60edccdc5..288453f3a 100644 --- a/mix.lock +++ b/mix.lock @@ -35,5 +35,5 @@ "stun": {:hex, :stun, "1.2.20", "62a149cea122a78a104b9e064a12d9e33105b26c23168ecf3aea6e0c26de0748", [:rebar3], [{:fast_tls, "1.1.24", [hex: :fast_tls, repo: "hexpm", optional: false]}, {:p1_utils, "1.0.28", [hex: :p1_utils, repo: "hexpm", optional: false]}], "hexpm", "79e49f826a4f7d522c939ab633d935c79d7d6b229e4cb7e05f62f33b50177414"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.1", "a48703a25c170eedadca83b11e88985af08d35f37c6f664d6dcfb106a97782fc", [:rebar3], [], "hexpm", "b3a917854ce3ae233619744ad1e0102e05673136776fb2fa76234f3e03b23642"}, "xmpp": {:hex, :xmpp, "1.11.0", "a3158c486c9b86a7090c361d876db622381f4312ede8c125d7a52ad390387932", [:rebar3], [{:ezlib, "~> 1.0.12", [hex: :ezlib, repo: "hexpm", optional: false]}, {:fast_tls, "~> 1.1.19", [hex: :fast_tls, repo: "hexpm", optional: false]}, {:fast_xml, "~> 1.1.51", [hex: :fast_xml, repo: "hexpm", optional: false]}, {:idna, "~> 6.0", [hex: :idna, repo: "hexpm", optional: false]}, {:p1_utils, "~> 1.0.26", [hex: :p1_utils, repo: "hexpm", optional: false]}, {:stringprep, "~> 1.0.29", [hex: :stringprep, repo: "hexpm", optional: false]}], "hexpm", "34a191d6a3b74e8f0a42346f859e2cab5b3a2ae7e5c28f392e5cb56612e7ce85"}, - "yconf": {:hex, :yconf, "1.0.20", "f2b38db613fa826966e8d22bdc3e3ebae46919f2a27ab149a5a086c1d99d3bbd", [:rebar3], [{:fast_yaml, "1.0.39", [hex: :fast_yaml, repo: "hexpm", optional: false]}], "hexpm", "f2b3d730756fc2e4afd1c0b0ab6efb99f0e448952d25dc15ed75ac1635bf8882"}, + "yconf": {:git, "https://github.com/processone/yconf", "c59f94097af5b78a8c6c72a143dcefaa5b3f406f", [ref: "c59f94097af5b78a8c6c72a143dcefaa5b3f406f"]}, } diff --git a/rebar.config b/rebar.config index cfe938a9d..039fdd40a 100644 --- a/rebar.config +++ b/rebar.config @@ -78,7 +78,7 @@ {if_var_true, stun, {stun, "~> 1.2.20", {git, "https://github.com/processone/stun", {tag, "1.2.20"}}}}, {xmpp, "~> 1.11.0", {git, "https://github.com/processone/xmpp", {tag, "1.11.0"}}}, - {yconf, "~> 1.0.20", {git, "https://github.com/processone/yconf", {tag, "1.0.20"}}} + {yconf, "~> 1.0.20", {git, "https://github.com/processone/yconf", "c59f94097af5b78a8c6c72a143dcefaa5b3f406f"}} ]}. {gitonly_deps, [ejabberd_po]}. diff --git a/rebar.lock b/rebar.lock index 342bbe80f..921129904 100644 --- a/rebar.lock +++ b/rebar.lock @@ -28,7 +28,10 @@ {<<"stun">>,{pkg,<<"stun">>,<<"1.2.20">>},0}, {<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.7.1">>},1}, {<<"xmpp">>,{pkg,<<"xmpp">>,<<"1.11.0">>},0}, - {<<"yconf">>,{pkg,<<"yconf">>,<<"1.0.20">>},0}]}. + {<<"yconf">>, + {git,"https://github.com/processone/yconf", + {ref,"c59f94097af5b78a8c6c72a143dcefaa5b3f406f"}}, + 0}]}. [ {pkg_hash,[ {<<"base64url">>, <<"F8C7F2DA04CA9A5D0F5F50258F055E1D699F0E8BF4CFDB30B750865368403CF6">>}, @@ -55,8 +58,7 @@ {<<"stringprep">>, <<"22F42866B4F6F3C238EA2B9CB6241791184DDEDBAB55E94A025511F46325F3CA">>}, {<<"stun">>, <<"62A149CEA122A78A104B9E064A12D9E33105B26C23168ECF3AEA6E0C26DE0748">>}, {<<"unicode_util_compat">>, <<"A48703A25C170EEDADCA83B11E88985AF08D35F37C6F664D6DCFB106A97782FC">>}, - {<<"xmpp">>, <<"A3158C486C9B86A7090C361D876DB622381F4312EDE8C125D7A52AD390387932">>}, - {<<"yconf">>, <<"F2B38DB613FA826966E8D22BDC3E3EBAE46919F2A27AB149A5A086C1D99D3BBD">>}]}, + {<<"xmpp">>, <<"A3158C486C9B86A7090C361D876DB622381F4312EDE8C125D7A52AD390387932">>}]}, {pkg_hash_ext,[ {<<"base64url">>, <<"F9B3ADD4731A02A9B0410398B475B33E7566A695365237A6BDEE1BB447719F5C">>}, {<<"cache_tab">>, <<"4258009EB050B22AABE0C848E230BBA58401A6895C58C2FF74DFB635E3C35900">>}, @@ -82,6 +84,5 @@ {<<"stringprep">>, <<"96F8B30BC50887F605B33B46BCA1D248C19A879319B8C482790E3B4DA5DA98C0">>}, {<<"stun">>, <<"79E49F826A4F7D522C939AB633D935C79D7D6B229E4CB7E05F62F33B50177414">>}, {<<"unicode_util_compat">>, <<"B3A917854CE3AE233619744AD1E0102E05673136776FB2FA76234F3E03B23642">>}, - {<<"xmpp">>, <<"34A191D6A3B74E8F0A42346F859E2CAB5B3A2AE7E5C28F392E5CB56612E7CE85">>}, - {<<"yconf">>, <<"F2B3D730756FC2E4AFD1C0B0AB6EFB99F0E448952D25DC15ED75AC1635BF8882">>}]} + {<<"xmpp">>, <<"34A191D6A3B74E8F0A42346F859E2CAB5B3A2AE7E5C28F392E5CB56612E7CE85">>}]} ]. diff --git a/src/misc.erl b/src/misc.erl index ce1b7c636..87f8b24e6 100644 --- a/src/misc.erl +++ b/src/misc.erl @@ -73,45 +73,11 @@ -type distance_cache() :: #{{string(), string()} => non_neg_integer()}. -spec uri_parse(binary()|string()) -> {ok, string(), string(), string(), number(), string(), string()} | {error, term()}. --ifdef(USE_OLD_HTTP_URI). -uri_parse(URL) when is_binary(URL) -> - uri_parse(binary_to_list(URL)); uri_parse(URL) -> - uri_parse(URL, []). + yconf:parse_uri(URL). -uri_parse(URL, Protocols) when is_binary(URL) -> - uri_parse(binary_to_list(URL), Protocols); uri_parse(URL, Protocols) -> - case http_uri:parse(URL, [{scheme_defaults, Protocols}]) of - {ok, {Scheme, UserInfo, Host, Port, Path, Query}} -> - {ok, atom_to_list(Scheme), UserInfo, Host, Port, Path, Query}; - {error, _} = E -> - E - end. - --else. -uri_parse(URL) when is_binary(URL) -> - uri_parse(binary_to_list(URL)); -uri_parse(URL) -> - uri_parse(URL, [{http, 80}, {https, 443}]). - -uri_parse(URL, Protocols) when is_binary(URL) -> - uri_parse(binary_to_list(URL), Protocols); -uri_parse(URL, Protocols) -> - case uri_string:parse(URL) of - #{scheme := Scheme, host := Host, port := Port, path := Path} = M1 -> - {ok, Scheme, maps:get(userinfo, M1, ""), Host, Port, Path, maps:get(query, M1, "")}; - #{scheme := Scheme, host := Host, path := Path} = M2 -> - case lists:keyfind(list_to_atom(Scheme), 1, Protocols) of - {_, Port} -> - {ok, Scheme, maps:get(userinfo, M2, ""), Host, Port, Path, maps:get(query, M2, "")}; - _ -> - {error, unknown_protocol} - end; - {error, Atom, _} -> - {error, Atom} - end. --endif. + yconf:parse_uri(URL, Protocols). -ifdef(OTP_BELOW_25). -ifdef(OTP_BELOW_24).