From 96147b9d386b69fdf45925abd1d070cd0eb8241f Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Tue, 26 Apr 2022 15:32:41 +0200 Subject: [PATCH 1/4] Update wpool version containing minimal perf improvements --- rebar.config | 2 +- rebar.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rebar.config b/rebar.config index 8ea3f95f3b..4d1ce64a58 100644 --- a/rebar.config +++ b/rebar.config @@ -76,7 +76,7 @@ %%% Stateful apps {cache_tab, "1.0.29"}, {segmented_cache, "0.1.1"}, - {worker_pool, "6.0.0"}, + {worker_pool, "6.0.1"}, %%% HTTP tools {cowboy, "2.9.0"}, diff --git a/rebar.lock b/rebar.lock index fc013f8cf3..4aa4d8359b 100644 --- a/rebar.lock +++ b/rebar.lock @@ -133,7 +133,7 @@ {<<"trails">>,{pkg,<<"trails">>,<<"2.3.0">>},0}, {<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.7.0">>},1}, {<<"uuid">>,{pkg,<<"uuid_erl">>,<<"2.0.4">>},0}, - {<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"6.0.0">>},0}]}. + {<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"6.0.1">>},0}]}. [ {pkg_hash,[ {<<"amqp_client">>, <<"4EBE8040BE3EE195E42BB483D37CD64FAF3C306201DC22A3F5CCE2A91A9E562E">>}, @@ -196,7 +196,7 @@ {<<"trails">>, <<"B09703F056705F4943E14FFF077B98C711A6F48FAD40F4FF0B350794074AD69C">>}, {<<"unicode_util_compat">>, <<"BC84380C9AB48177092F43AC89E4DFA2C6D62B40B8BD132B1059ECC7232F9A78">>}, {<<"uuid">>, <<"77C3E3EE1E1701A2856CE945846D7CEB71931C60633A305D0B0FEAE03B2B3B5C">>}, - {<<"worker_pool">>, <<"F7B442B30121EED6D8C828833533E5C15DB61E4AB2EF343C8B67824267656822">>}]}, + {<<"worker_pool">>, <<"CA262C2DFB3B4AF661B206C82065D86F83922B7227508AA6E0BC34D3E5AE5135">>}]}, {pkg_hash_ext,[ {<<"amqp_client">>, <<"CDD74BC8E9D5E8610975009DCAE1293BDF7198EE6D8315A1FFB5055467010520">>}, {<<"backoff">>, <<"30CEAD738D20E4C8D36CD37857DD5E23AEBA57CB868BF64766D47D371422BDFF">>}, @@ -258,5 +258,5 @@ {<<"trails">>, <<"40804001EB80417AA9D02400F39B7216956C3F251539A8A6096A69B3FAC0EA07">>}, {<<"unicode_util_compat">>, <<"25EEE6D67DF61960CF6A794239566599B09E17E668D3700247BC498638152521">>}, {<<"uuid">>, <<"7A4CCD1C151D9B88B4383FA802BCCF9BCB3754B7F53D7CAA164D51A14A6652E4">>}, - {<<"worker_pool">>, <<"F9D95B85E80C5C27B7AB2E60BF780DA70A5E26DD9E6D30BE45032742FC039CC5">>}]} + {<<"worker_pool">>, <<"772E12CCB26909EA7F804B52E86E733DF66BB8150F683B591B0A762196494C74">>}]} ]. From 98df6f7e0879facca005e697f30ecefd38b393df Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Mon, 31 Jan 2022 09:51:59 +0100 Subject: [PATCH 2/4] Upgrade to the latest mongoose_jid --- big_tests/rebar.config | 2 +- big_tests/rebar.lock | 6 +++--- big_tests/tests/accounts_SUITE.erl | 4 ++-- big_tests/tests/domain_removal_SUITE.erl | 2 +- big_tests/tests/inbox_SUITE.erl | 2 +- big_tests/tests/mongooseimctl_SUITE.erl | 9 ++++----- big_tests/tests/muc_helper.erl | 4 ++-- big_tests/tests/oauth_SUITE.erl | 7 +++---- big_tests/tests/vcard_SUITE.erl | 2 +- include/mod_roster.hrl | 4 ++-- rebar.config | 2 +- rebar.lock | 6 +++--- src/admin_extra/service_admin_extra_roster.erl | 4 ++-- src/admin_extra/service_admin_extra_stanza.erl | 4 ++-- src/ejabberd_c2s.erl | 15 +++++---------- src/jingle_sip/jingle_sip_helper.erl | 2 +- src/mam/mod_mam.erl | 8 ++++---- src/mam/mod_mam_muc.erl | 6 +++--- src/mod_disco.erl | 7 +++---- src/mod_muc_commands.erl | 2 +- src/mod_muc_log.erl | 2 +- src/mod_register.erl | 12 ++++++------ src/mod_roster.erl | 13 +++++-------- src/mod_sic.erl | 5 +++-- .../mongoose_client_api_sse.erl | 2 +- src/mongoose_commands.erl | 5 ++--- src/mongoose_privacy.erl | 4 ++-- src/muc_light/mod_muc_light_codec_modern.erl | 3 +-- src/pubsub/mod_pubsub.erl | 15 ++++++--------- src/sasl/cyrsasl_external.erl | 2 +- src/vcard/mod_vcard.erl | 15 +++++++-------- test/auth_tokens_SUITE.erl | 11 +++++------ test/ejabberd_admin_SUITE.erl | 8 ++++---- test/json_formatter_SUITE.erl | 14 +++++++------- 34 files changed, 96 insertions(+), 113 deletions(-) diff --git a/big_tests/rebar.config b/big_tests/rebar.config index 14e328374c..ac51485a3f 100644 --- a/big_tests/rebar.config +++ b/big_tests/rebar.config @@ -20,5 +20,5 @@ {csv, "3.0.3", {pkg, csve}}, {amqp_client, "3.9.5"}, {esip, "1.0.43"}, - {jid, "1.1.1", {pkg, mongoose_jid}} + {jid, "2.0.0", {pkg, mongoose_jid}} ]}. diff --git a/big_tests/rebar.lock b/big_tests/rebar.lock index b5e17d3c4f..6b4531f948 100644 --- a/big_tests/rebar.lock +++ b/big_tests/rebar.lock @@ -17,7 +17,7 @@ {<<"fusco">>,{pkg,<<"fusco">>,<<"0.1.1">>},0}, {<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1}, {<<"gun">>,{pkg,<<"gun">>,<<"2.0.0-rc.2">>},0}, - {<<"jid">>,{pkg,<<"mongoose_jid">>,<<"1.1.1">>},0}, + {<<"jid">>,{pkg,<<"mongoose_jid">>,<<"2.0.0">>},0}, {<<"jiffy">>,{pkg,<<"jiffy">>,<<"1.1.1">>},0}, {<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},2}, {<<"lager">>,{pkg,<<"lager">>,<<"3.9.2">>},0}, @@ -50,7 +50,7 @@ {<<"fusco">>, <<"3DD6A90151DFEF30EA1937CC44E9A59177C0094918388D9BCAA2F2DC5E2AE4AA">>}, {<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>}, {<<"gun">>, <<"7C489A32DEDCCB77B6E82D1F3C5A7DADFBFA004EC14E322CDB5E579C438632D2">>}, - {<<"jid">>, <<"C9D92768FBC120C717E944AFE523FA0062C5B665E4D776724B2F8E54831AB2CA">>}, + {<<"jid">>, <<"0D0FD1130EAD05DF672D1C9E0405D3000F0C87A7D446577755CF5EB173104FE9">>}, {<<"jiffy">>, <<"ACA10F47AA91697BF24AB9582C74E00E8E95474C7EF9F76D4F1A338D0F5DE21B">>}, {<<"jsx">>, <<"D12516BAA0BB23A59BB35DCCAF02A1BD08243FCBB9EFE24F2D9D056CCFF71268">>}, {<<"lager">>, <<"4CAB289120EB24964E3886BD22323CB5FEFE4510C076992A23AD18CF85413D8C">>}, @@ -82,7 +82,7 @@ {<<"fusco">>, <<"6343551BD1E824F2A6CA85E1158C5B37C320FD449FBFEC7450A73F192AAF9022">>}, {<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>}, {<<"gun">>, <<"6B9D1EAE146410D727140DBF8B404B9631302ECC2066D1D12F22097AD7D254FC">>}, - {<<"jid">>, <<"61EDDBAC9908747DA29F7C79545C744C31A25652CCB53248E684DBB083EFBE9A">>}, + {<<"jid">>, <<"7BAE8403552D5BCECD1CD2A848445B5FC3533F5EEB355173A0531A1A1AA8E008">>}, {<<"jiffy">>, <<"62E1F0581C3C19C33A725C781DFA88410D8BFF1BBAFC3885A2552286B4785C4C">>}, {<<"jsx">>, <<"0C5CC8FDC11B53CC25CF65AC6705AD39E54ECC56D1C22E4ADB8F5A53FB9427F3">>}, {<<"lager">>, <<"7F904D9E87A8CB7E66156ED31768D1C8E26EBA1D54F4BC85B1AA4AC1F6340C28">>}, diff --git a/big_tests/tests/accounts_SUITE.erl b/big_tests/tests/accounts_SUITE.erl index 9fe8097977..015dc0a0fb 100644 --- a/big_tests/tests/accounts_SUITE.erl +++ b/big_tests/tests/accounts_SUITE.erl @@ -198,8 +198,8 @@ registration_conflict(Config) -> admin_notify(Config) -> [{Name1, UserSpec1}, {Name2, UserSpec2}] = escalus_users:get_users([alice, bob]), [{_, AdminSpec}] = escalus_users:get_users([admin]), - [Username1, _Server1, _Pass1] = escalus_users:get_usp(Config, UserSpec1), - [Username2, _Server2, _Pass2] = escalus_users:get_usp(Config, UserSpec2), + Username1 = jid:str_tolower(escalus_users:get_username(Config, UserSpec1)), + Username2 = jid:str_tolower(escalus_users:get_username(Config, UserSpec2)), [AdminU, AdminS, AdminP] = escalus_users:get_usp(Config, AdminSpec), rpc(mim(), ejabberd_auth, try_register, [mongoose_helper:make_jid(AdminU, AdminS), AdminP]), diff --git a/big_tests/tests/domain_removal_SUITE.erl b/big_tests/tests/domain_removal_SUITE.erl index eea7924562..2406c27013 100644 --- a/big_tests/tests/domain_removal_SUITE.erl +++ b/big_tests/tests/domain_removal_SUITE.erl @@ -419,7 +419,7 @@ connect_and_disconnect(Spec) -> escalus_connection:stop(Client). does_cached_user_exist(Config, User) -> - Jid = #jid{server = Domain} = jid:from_binary(escalus_users:get_jid(Config, User)), + Jid = #jid{lserver = Domain} = jid:from_binary(escalus_users:get_jid(Config, User)), HostType = domain_to_host_type(mim(), Domain), rpc(mim(), mod_cache_users, does_cached_user_exist, [false, HostType, Jid, stored]). diff --git a/big_tests/tests/inbox_SUITE.erl b/big_tests/tests/inbox_SUITE.erl index 2281fb959b..0259eada6b 100644 --- a/big_tests/tests/inbox_SUITE.erl +++ b/big_tests/tests/inbox_SUITE.erl @@ -1397,7 +1397,7 @@ rpc_stop_hook_handler(HookExtra, HostType) -> hook_handler_fn(Acc, #{args := [_HostType, User, _Stored]} = _Params, #{test_case_pid := Pid} = _Extra) -> - Pid ! {input, User#jid.user}, + Pid ! {input, User#jid.luser}, {ok, Acc}. verify_hook_listener(RoomName) -> diff --git a/big_tests/tests/mongooseimctl_SUITE.erl b/big_tests/tests/mongooseimctl_SUITE.erl index 7f92fc04a5..ab8146ea54 100644 --- a/big_tests/tests/mongooseimctl_SUITE.erl +++ b/big_tests/tests/mongooseimctl_SUITE.erl @@ -1232,7 +1232,7 @@ remove_old_messages_test(Config) -> OldTimestamp = fallback_timestamp(10, os:system_time(microsecond)), OfflineOld = generate_offline_message(JidRecordAlice, JidRecordBob, Msg1, OldTimestamp), OfflineNew = generate_offline_message(JidRecordAlice, JidRecordBob, Msg2, os:system_time(microsecond)), - {jid, _, _, _, LUser, LServer, _} = JidRecordBob, + {LUser, LServer} = jid:to_lus(JidRecordBob), HostType = host_type(), rpc_call(mod_offline_backend, write_messages, [host_type(), LUser, LServer, [OfflineOld, OfflineNew]]), %% when @@ -1269,7 +1269,7 @@ remove_expired_messages_test(Config) -> JidRecordKate, Msg4, OldTimestamp, ExpirationTimeFuture), - {jid, _, _, _, LUser, LServer, _} = JidRecordKate, + {LUser, LServer} = jid:to_lus(JidRecordKate), Args = [OfflineOld, OfflineNow, OfflineFuture, OfflineFuture2], HostType = host_type(), rpc_call(mod_offline_backend, write_messages, [HostType, LUser, LServer, Args]), @@ -1290,12 +1290,12 @@ nick_to_jid(UserName, Config) when is_atom(UserName) -> escalus_utils:jid_to_lower(escalus_users:get_jid(Config, UserSpec)). generate_offline_message(From, To, Msg, TimeStamp) -> - {jid, _, _, _, LUser, LServer, _} = To, + {LUser, LServer} = jid:to_lus(To), #offline_msg{us = {LUser, LServer}, timestamp = TimeStamp, expire = never, from = From, to = To, packet = Msg}. generate_offline_expired_message(From, To, Msg, TimeStamp, ExpirationTime) -> - {jid, _, _, _, LUser, LServer, _} = To, + {LUser, LServer} = jid:to_lus(To), #offline_msg{us = {LUser, LServer}, timestamp = TimeStamp, expire = ExpirationTime, from = From, to = To, packet = Msg}. @@ -1336,7 +1336,6 @@ delete_users(_Config) -> match_user_status(Users, StatusTxt) -> Statuses = string:tokens(StatusTxt, "\n"), - true = (length(Users) == length(Statuses)), match_user_status2(Users, Statuses). diff --git a/big_tests/tests/muc_helper.erl b/big_tests/tests/muc_helper.erl index 1dab729cfb..4e48234a82 100644 --- a/big_tests/tests/muc_helper.erl +++ b/big_tests/tests/muc_helper.erl @@ -145,7 +145,7 @@ generate_rpc_jid({_,User}) -> {server, Server} = lists:keyfind(server, 1, User), LUsername = escalus_utils:jid_to_lower(Username), LServer = escalus_utils:jid_to_lower(Server), - {jid, Username, Server, <<"rpc">>, LUsername, LServer, <<"rpc">>}. + jid:make_noprep(LUsername, LServer, <<"rpc">>). create_instant_room(Room, From, Nick, Opts) -> ServerHost = ct:get_config({hosts, mim, domain}), @@ -170,7 +170,7 @@ destroy_room(Config) -> destroy_room(muc_host(), ?config(room, Config)). destroy_room(Host, Room) when is_binary(Host), is_binary(Room) -> - Room1 = rpc(mim(), jid, nodeprep, [Room]), + Room1 = jid:nodeprep(Room), case rpc(mim(), ets, lookup, [muc_online_room, {Room1, Host}]) of [{_,_,Pid}|_] -> %% @TODO related to gen_fsm_compat: after migration to gen_statem diff --git a/big_tests/tests/oauth_SUITE.erl b/big_tests/tests/oauth_SUITE.erl index 5c7cb5b02d..3ad5e3fc2e 100644 --- a/big_tests/tests/oauth_SUITE.erl +++ b/big_tests/tests/oauth_SUITE.erl @@ -161,7 +161,7 @@ token_login_failure(Config, User, Token) -> get_revoked_token(Config, UserName) -> BJID = escalus_users:get_jid(Config, UserName), - JID = rpc(mim(), jid, from_binary, [BJID]), + JID = jid:from_binary(BJID), HostType = domain_helper:host_type(), Token = rpc(mim(), mod_auth_token, token, [HostType, JID, refresh]), ValidSeqNo = rpc(mim(), mod_auth_token_rdbms, get_valid_sequence_number, [HostType, JID]), @@ -280,7 +280,7 @@ token_revocation_test(Config) -> get_owner_seqno_to_revoke(Config, User) -> {_, RefreshToken} = request_tokens_once_logged_in_impl(Config, User), [_, BOwner, _, SeqNo, _] = binary:split(RefreshToken, <<0>>, [global]), - Owner = rpc(mim(), jid, from_binary, [BOwner]), + Owner = jid:from_binary(BOwner), {Owner, binary_to_integer(SeqNo), RefreshToken}. revoke_token(Owner) -> @@ -433,8 +433,7 @@ make_provision_token(Config, User, VCard) -> ExpiryFarInTheFuture = {{2055, 10, 27}, {10, 54, 22}}, Username = escalus_users:get_username(Config, User), Domain = escalus_users:get_server(Config, User), - ServerSideJID = {jid, Username, Domain, <<>>, - Username, Domain, <<>>}, + ServerSideJID = jid:make(Username, Domain, <<>>), T0 = {token, provision, ExpiryFarInTheFuture, ServerSideJID, diff --git a/big_tests/tests/vcard_SUITE.erl b/big_tests/tests/vcard_SUITE.erl index 18fcc7c21a..14218da631 100644 --- a/big_tests/tests/vcard_SUITE.erl +++ b/big_tests/tests/vcard_SUITE.erl @@ -1111,7 +1111,7 @@ delete_vcards(Config) -> get_jid_record(JID) -> [User, Server] = binary:split(JID, <<"@">>), - {jid, User, Server, <<"">>, User, Server, <<"">>}. + jid:make_bare(User, Server). vcard_rpc(JID, Stanza) -> Res = rpc(mim(), ejabberd_router, route, [JID, JID, Stanza]), diff --git a/include/mod_roster.hrl b/include/mod_roster.hrl index a24c7dda16..e591c6d8b6 100644 --- a/include/mod_roster.hrl +++ b/include/mod_roster.hrl @@ -18,9 +18,9 @@ %%% %%%---------------------------------------------------------------------- --record(roster, {usj :: {jid:luser(), jid:lserver(), jid:simple_jid()}, +-record(roster, {usj :: {jid:luser(), jid:lserver(), jid:ljid()}, us :: {jid:luser(), jid:lserver()}, - jid :: jid:simple_jid(), + jid :: jid:ljid(), name = <<>> :: binary(), subscription = none :: both | from | to | none | remove, ask = none :: subscribe | unsubscribe | in | out | both | none, diff --git a/rebar.config b/rebar.config index 4d1ce64a58..d7d186eb28 100644 --- a/rebar.config +++ b/rebar.config @@ -52,7 +52,7 @@ {base16, "2.0.1"}, {exml, "3.1.1", {pkg, hexml}}, {jiffy, "1.1.1"}, - {jid, "1.1.1", {pkg, mongoose_jid}}, + {jid, "2.0.0", {pkg, mongoose_jid}}, {tomerl, "0.5.0"}, {bbmustache, "1.12.2"}, {erl_csv, "0.2.0"}, diff --git a/rebar.lock b/rebar.lock index 4aa4d8359b..52a9a66b25 100644 --- a/rebar.lock +++ b/rebar.lock @@ -54,7 +54,7 @@ {ref,"ad3dbab419762fc2d5821abb88b989da006b85c6"}}, 2}, {<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},0}, - {<<"jid">>,{pkg,<<"mongoose_jid">>,<<"1.1.1">>},0}, + {<<"jid">>,{pkg,<<"mongoose_jid">>,<<"2.0.0">>},0}, {<<"jiffy">>,{pkg,<<"jiffy">>,<<"1.1.1">>},0}, {<<"jsx">>,{pkg,<<"jsx">>,<<"2.9.0">>},1}, {<<"jwerl">>, @@ -165,7 +165,7 @@ {<<"gun">>, <<"CF8B51BEB36C22B9C8DF1921E3F2BC4D2B1F68B49AD4FBC64E91875AA14E16B4">>}, {<<"hackney">>, <<"24EDC8CD2B28E1C652593833862435C80661834F6C9344E84B6A2255E7AEEF03">>}, {<<"idna">>, <<"8A63070E9F7D0C62EB9D9FCB360A7DE382448200FBBD1B106CC96D3D8099DF8D">>}, - {<<"jid">>, <<"C9D92768FBC120C717E944AFE523FA0062C5B665E4D776724B2F8E54831AB2CA">>}, + {<<"jid">>, <<"0D0FD1130EAD05DF672D1C9E0405D3000F0C87A7D446577755CF5EB173104FE9">>}, {<<"jiffy">>, <<"ACA10F47AA91697BF24AB9582C74E00E8E95474C7EF9F76D4F1A338D0F5DE21B">>}, {<<"jsx">>, <<"D2F6E5F069C00266CAD52FB15D87C428579EA4D7D73A33669E12679E203329DD">>}, {<<"lager">>, <<"4CAB289120EB24964E3886BD22323CB5FEFE4510C076992A23AD18CF85413D8C">>}, @@ -227,7 +227,7 @@ {<<"gun">>, <<"3106CE167F9C9723F849E4FB54EA4A4D814E3996AE243A1C828B256E749041E0">>}, {<<"hackney">>, <<"4D605D33DD07EE1B82B105033CCCB02379515105FCEB1850746591814B00C205">>}, {<<"idna">>, <<"92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA">>}, - {<<"jid">>, <<"61EDDBAC9908747DA29F7C79545C744C31A25652CCB53248E684DBB083EFBE9A">>}, + {<<"jid">>, <<"7BAE8403552D5BCECD1CD2A848445B5FC3533F5EEB355173A0531A1A1AA8E008">>}, {<<"jiffy">>, <<"62E1F0581C3C19C33A725C781DFA88410D8BFF1BBAFC3885A2552286B4785C4C">>}, {<<"jsx">>, <<"8EE1DB1CABAFDD578A2776A6AAAE87C2A8CE54B47B59E9EC7DAB5D7EB71CD8DC">>}, {<<"lager">>, <<"7F904D9E87A8CB7E66156ED31768D1C8E26EBA1D54F4BC85B1AA4AC1F6340C28">>}, diff --git a/src/admin_extra/service_admin_extra_roster.erl b/src/admin_extra/service_admin_extra_roster.erl index f786ca16c4..d6873c709b 100644 --- a/src/admin_extra/service_admin_extra_roster.erl +++ b/src/admin_extra/service_admin_extra_roster.erl @@ -367,14 +367,14 @@ push_roster_item(JID, #jid{luser = U, lserver = S} = RemJID, Action) -> end, ejabberd_sm:get_user_resources(JID)). -spec build_roster_item(jid:jid(), push_action()) -> exml:element(). -build_roster_item(#jid{resource = <<>>} = JID, {add, Nick, Subs, Group}) -> +build_roster_item(#jid{lresource = <<>>} = JID, {add, Nick, Subs, Group}) -> #xmlel{ name = <<"item">>, attrs = [{<<"jid">>, jid:to_binary(JID)}, {<<"name">>, Nick}, {<<"subscription">>, Subs}], children = [#xmlel{name = <<"group">>, children = [#xmlcdata{content = Group}]}] }; -build_roster_item(#jid{resource = <<>>} = JID, remove) -> +build_roster_item(#jid{lresource = <<>>} = JID, remove) -> #xmlel{ name = <<"item">>, attrs = [{<<"jid">>, jid:to_binary(JID)}, {<<"subscription">>, <<"remove">>}]}; diff --git a/src/admin_extra/service_admin_extra_stanza.erl b/src/admin_extra/service_admin_extra_stanza.erl index 6ee14a9d2b..3353437b90 100644 --- a/src/admin_extra/service_admin_extra_stanza.erl +++ b/src/admin_extra/service_admin_extra_stanza.erl @@ -120,8 +120,8 @@ send_packet_all_resources(FromJID, ToJIDString, Packet) when is_binary(ToJIDStri {ok, ""} end; send_packet_all_resources(#jid{} = FromJID, #jid{} = ToJID, Packet) -> - case ToJID#jid.resource of - <<"">> -> + case ToJID#jid.lresource of + <<>> -> send_packet_all_resources_2(FromJID, ToJID, Packet), {ok, ""}; _Res -> diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 28bc1e6e97..391acf2d74 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -876,15 +876,13 @@ process_outgoing_stanza(Acc, StateData) -> fsm_next_state(session_established, NState). process_outgoing_stanza(Acc, ToJID, <<"presence">>, StateData) -> - #jid{user = User, server = Server} = FromJID = mongoose_acc:from_jid(Acc), + FromJID = mongoose_acc:from_jid(Acc), HostType = mongoose_acc:host_type(Acc), Res = mongoose_hooks:c2s_update_presence(HostType, Acc), El = mongoose_acc:element(Res), Res1 = mongoose_hooks:user_send_packet(Res, FromJID, ToJID, El), - {_Acc1, NState} = case ToJID of - #jid{user = User, - server = Server, - resource = <<>>} -> + {_Acc1, NState} = case jid:are_bare_equal(FromJID, ToJID) of + true -> presence_update(Res1, FromJID, StateData); _ -> presence_track(Res1, StateData) @@ -983,13 +981,10 @@ handle_event(_Event, StateName, StateData) -> -> {'reply', Reply :: [any()], statename(), state()} | {'reply', Reply :: 'ok' | {_, _, _, _}, statename(), state(), timeout()}. handle_sync_event(get_presence, _From, StateName, StateData) -> - User = StateData#state.user, + #jid{luser = User, lresource = Resource} = StateData#state.jid, PresLast = StateData#state.pres_last, - Show = get_showtag(PresLast), Status = get_statustag(PresLast), - Resource = StateData#state.resource, - Reply = {User, Resource, Show, Status}, fsm_reply(Reply, StateName, StateData); handle_sync_event(get_info, _From, StateName, StateData) -> @@ -3256,7 +3251,7 @@ handle_sasl_success(State, Creds) -> authenticated = true, auth_module = AuthModule, user = User, - jid = jid:make(User, Server, <<>>)}, + jid = jid:make_bare(User, Server)}, ?LOG_INFO(#{what => auth_success, text => <<"Accepted SASL authentication">>, stream_id => StreamID, auth_module => AuthModule, c2s_state => NewState}), diff --git a/src/jingle_sip/jingle_sip_helper.erl b/src/jingle_sip/jingle_sip_helper.erl index 119874639b..16da661c8e 100644 --- a/src/jingle_sip/jingle_sip_helper.erl +++ b/src/jingle_sip/jingle_sip_helper.erl @@ -50,7 +50,7 @@ maybe_rewrite_to_phone(Acc) -> ToRewrite = gen_mod:get_module_opt(HostType, mod_jingle_sip, username_to_phone), case lists:keyfind(ToUser, 1, ToRewrite) of {ToUser, PhoneNumber} -> - JID#jid{user = PhoneNumber, luser = PhoneNumber}; + JID#jid{luser = PhoneNumber}; _ -> JID end. diff --git a/src/mam/mod_mam.erl b/src/mam/mod_mam.erl index 79112663a8..a553cdb2df 100644 --- a/src/mam/mod_mam.erl +++ b/src/mam/mod_mam.erl @@ -176,7 +176,7 @@ get_personal_data(Acc, HostType, ArcJID) -> delete_archive(Server, User) when is_binary(Server), is_binary(User) -> ?LOG_DEBUG(#{what => mam_delete_archive, user => User, server => Server}), - ArcJID = jid:make(User, Server, <<>>), + ArcJID = jid:make_bare(User, Server), HostType = jid_to_host_type(ArcJID), ArcID = archive_id_int(HostType, ArcJID), remove_archive_hook(HostType, ArcID, ArcJID), @@ -185,21 +185,21 @@ delete_archive(Server, User) -spec archive_size(jid:server(), jid:user()) -> integer(). archive_size(Server, User) when is_binary(Server), is_binary(User) -> - ArcJID = jid:make(User, Server, <<>>), + ArcJID = jid:make_bare(User, Server), HostType = jid_to_host_type(ArcJID), ArcID = archive_id_int(HostType, ArcJID), archive_size(HostType, ArcID, ArcJID). -spec archive_size_with_host_type(host_type(), jid:server(), jid:user()) -> integer(). archive_size_with_host_type(HostType, Server, User) -> - ArcJID = jid:make(User, Server, <<>>), + ArcJID = jid:make_bare(User, Server), ArcID = archive_id_int(HostType, ArcJID), archive_size(HostType, ArcID, ArcJID). -spec archive_id(jid:server(), jid:user()) -> integer() | undefined. archive_id(Server, User) when is_binary(Server), is_binary(User) -> - ArcJID = jid:make(User, Server, <<>>), + ArcJID = jid:make_bare(User, Server), HostType = jid_to_host_type(ArcJID), archive_id_int(HostType, ArcJID). diff --git a/src/mam/mod_mam_muc.erl b/src/mam/mod_mam_muc.erl index 72ba5989f2..c8b4780194 100644 --- a/src/mam/mod_mam_muc.erl +++ b/src/mam/mod_mam_muc.erl @@ -124,7 +124,7 @@ get_personal_data(Acc, HostType, ArcJID) -> -spec delete_archive(jid:server(), jid:user()) -> ok. delete_archive(MucHost, RoomName) when is_binary(MucHost), is_binary(RoomName) -> ?LOG_DEBUG(#{what => mam_delete_room, room => RoomName, sub_host => MucHost}), - ArcJID = jid:make(RoomName, MucHost, <<>>), + ArcJID = jid:make_bare(RoomName, MucHost), HostType = mod_muc_light_utils:room_jid_to_host_type(ArcJID), ArcID = archive_id_int(HostType, ArcJID), remove_archive(HostType, ArcID, ArcJID), @@ -132,14 +132,14 @@ delete_archive(MucHost, RoomName) when is_binary(MucHost), is_binary(RoomName) - -spec archive_size(jid:server(), jid:user()) -> integer(). archive_size(MucHost, RoomName) when is_binary(MucHost), is_binary(RoomName) -> - ArcJID = jid:make(RoomName, MucHost, <<>>), + ArcJID = jid:make_bare(RoomName, MucHost), HostType = mod_muc_light_utils:room_jid_to_host_type(ArcJID), ArcID = archive_id_int(HostType, ArcJID), archive_size(HostType, ArcID, ArcJID). -spec archive_id(jid:server(), jid:user()) -> integer(). archive_id(MucHost, RoomName) when is_binary(MucHost), is_binary(RoomName) -> - ArcJID = jid:make(RoomName, MucHost, <<>>), + ArcJID = jid:make_bare(RoomName, MucHost), HostType = mod_muc_light_utils:room_jid_to_host_type(ArcJID), archive_id_int(HostType, ArcJID). diff --git a/src/mod_disco.erl b/src/mod_disco.erl index f2ddf88cc9..858672a932 100644 --- a/src/mod_disco.erl +++ b/src/mod_disco.erl @@ -316,12 +316,11 @@ sm_error(_From, _To) -> mongoose_xmpp_errors:not_allowed(). -spec get_user_resources(jid:jid()) -> [mongoose_disco:item()]. -get_user_resources(JID) -> - #jid{user = User, server = Server} = JID, +get_user_resources(JID = #jid{luser = LUser}) -> Rs = ejabberd_sm:get_user_resources(JID), lists:map(fun(R) -> - BJID = jid:to_binary({User, Server, R}), - #{jid => BJID, name => User} + BJID = jid:to_binary(jid:replace_resource_noprep(JID, R)), + #{jid => BJID, name => LUser} end, lists:sort(Rs)). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/mod_muc_commands.erl b/src/mod_muc_commands.erl index 8dc3520c44..eff28dc9da 100644 --- a/src/mod_muc_commands.erl +++ b/src/mod_muc_commands.erl @@ -120,7 +120,7 @@ create_instant_room(Domain, Name, Owner, Nick) -> %% the HTTP API, they will certainly recieve stanzas as a %% consequence, even if their client(s) did not initiate this. OwnerJID = jid:binary_to_bare(Owner), - BareRoomJID = #jid{server = MUCDomain} = room_jid(Domain, Name), + BareRoomJID = #jid{lserver = MUCDomain} = room_jid(Domain, Name), UserRoomJID = jid:make(Name, MUCDomain, Nick), %% Send presence to create a room. ejabberd_router:route(OwnerJID, UserRoomJID, diff --git a/src/mod_muc_log.erl b/src/mod_muc_log.erl index b64a94aeb8..7b63139a8a 100644 --- a/src/mod_muc_log.erl +++ b/src/mod_muc_log.erl @@ -402,7 +402,7 @@ build_filename_string(TimeStamp, OutDir, RoomJID, DirType, DirName, FileFormat) -spec get_room_name(jid:literal_jid()) -> mod_muc:room(). get_room_name(RoomJID) -> JID = jid:from_binary(RoomJID), - JID#jid.user. + JID#jid.luser. %% @doc calculate day before diff --git a/src/mod_register.erl b/src/mod_register.erl index e289320497..ae6ecf92e2 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -271,13 +271,13 @@ process_iq_get(_HostType, From, _To, #iq{lang = Lang, sub_el = Child} = IQ, _Sou true = is_query_element(Child), {_IsRegistered, UsernameSubels, QuerySubels} = case From of - JID = #jid{user = User} -> + JID = #jid{luser = LUser} -> case ejabberd_auth:does_user_exist(JID) of true -> - {true, [#xmlcdata{content = User}], + {true, [#xmlcdata{content = LUser}], [#xmlel{name = <<"registered">>}]}; false -> - {false, [#xmlcdata{content = User}], []} + {false, [#xmlcdata{content = LUser}], []} end; _ -> {false, [], []} @@ -294,13 +294,13 @@ process_iq_get(_HostType, From, _To, #iq{lang = Lang, sub_el = Child} = IQ, _Sou #xmlel{name = <<"password">>} | QuerySubels]}]}. -try_register_or_set_password(HostType, User, Server, Password, #jid{user = User, lserver = Server} = UserJID, +try_register_or_set_password(HostType, LUser, Server, Password, #jid{luser = LUser, lserver = Server} = UserJID, IQ, SubEl, _Source, Lang) -> try_set_password(HostType, UserJID, Password, IQ, SubEl, Lang); -try_register_or_set_password(HostType, User, Server, Password, _From, IQ, SubEl, Source, Lang) -> +try_register_or_set_password(HostType, LUser, Server, Password, _From, IQ, SubEl, Source, Lang) -> case check_timeout(Source) of true -> - case try_register(HostType, User, Server, Password, Source, Lang) of + case try_register(HostType, LUser, Server, Password, Source, Lang) of ok -> IQ#iq{type = result, sub_el = [SubEl]}; {error, Error} -> diff --git a/src/mod_roster.erl b/src/mod_roster.erl index b7ab3f654a..8c7e5ec61b 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -289,13 +289,13 @@ get_user_roster_db_versioning(HostType, RequestedVersion, From, To) error -> RosterVersion = write_roster_version(HostType, LUser, LServer), {lists:map(fun item_to_xml/1, - get_roster_old(HostType, To#jid.server, From)), + get_roster_old(HostType, To#jid.lserver, From)), RosterVersion}; RequestedVersion -> {false, false}; NewVersion -> {lists:map(fun item_to_xml/1, - get_roster_old(HostType, To#jid.server, From)), + get_roster_old(HostType, To#jid.lserver, From)), NewVersion} end. @@ -844,7 +844,7 @@ send_presence_type(From, To, Type) -> -spec remove_domain(mongoose_hooks:simple_acc(), mongooseim:host_type(), jid:lserver()) -> mongoose_hooks:simple_acc(). -remove_domain(Acc, HostType, Domain) -> +remove_domain(Acc, HostType, Domain) -> case backend_module:is_exported(mod_roster_backend, remove_domain_t, 2) of true -> F = fun() -> mod_roster_backend:remove_domain_t(HostType, Domain) end, @@ -895,12 +895,9 @@ process_item_set_t(HostType, LUser, LServer, case JID1 of error -> ok; _ -> - JID = {JID1#jid.user, JID1#jid.server, - JID1#jid.resource}, - LJID = {JID1#jid.luser, JID1#jid.lserver, - JID1#jid.lresource}, + LJID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource}, Item = #roster{usj = {LUser, LServer, LJID}, - us = {LUser, LServer}, jid = JID}, + us = {LUser, LServer}, jid = LJID}, Item1 = process_item_attrs_ws(Item, Attrs), Item2 = process_item_els(Item1, Els), case Item2#roster.subscription of diff --git a/src/mod_sic.erl b/src/mod_sic.erl index 8aa92c7cbf..7f0f86b4b6 100644 --- a/src/mod_sic.erl +++ b/src/mod_sic.erl @@ -92,8 +92,9 @@ process_local_iq(Acc, _From, _To, #iq{type = 'set', sub_el = SubEl} = IQ, _Extra -spec process_sm_iq(mongoose_acc:t(), jid:jid(), jid:jid(), jlib:iq(), map()) -> {mongoose_acc:t(), jlib:iq()}. -process_sm_iq(Acc, #jid{user = User, server = Server} = JID, - #jid{user = User, server = Server}, +process_sm_iq(Acc, + #jid{luser = LUser, lserver = LServer} = JID, + #jid{luser = LUser, lserver = LServer}, #iq{type = 'get', sub_el = _SubEl} = IQ, _Extra) -> {Acc, get_ip(JID, IQ)}; process_sm_iq(Acc, _From, _To, #iq{type = 'get', sub_el = SubEl} = IQ, _Extra) -> diff --git a/src/mongoose_client_api/mongoose_client_api_sse.erl b/src/mongoose_client_api/mongoose_client_api_sse.erl index af7f3be36f..6c34664e76 100644 --- a/src/mongoose_client_api/mongoose_client_api_sse.erl +++ b/src/mongoose_client_api/mongoose_client_api_sse.erl @@ -56,7 +56,7 @@ terminate(_Reason, _Req, #{creds := Creds} = State) -> undefined -> ok; SID -> - JID = #jid{server = S} = maps:get(jid, State), + JID = #jid{lserver = S} = maps:get(jid, State), Acc = mongoose_acc:new( #{location => ?LOCATION, lserver => S, diff --git a/src/mongoose_commands.erl b/src/mongoose_commands.erl index 917c6c951e..5aed01647e 100644 --- a/src/mongoose_commands.erl +++ b/src/mongoose_commands.erl @@ -685,9 +685,8 @@ check_caller(Caller, #mongoose_command{caller_pos = CallerPos}, Args) -> ACaller = lists:nth(CallerPos, Args), CallerJid = jid:from_binary(Caller), ACallerJid = jid:from_binary(ACaller), - ACal = {ACallerJid#jid.user, ACallerJid#jid.server}, - case {CallerJid#jid.user, CallerJid#jid.server} of - ACal -> + case jid:are_bare_equal(CallerJid, ACallerJid) of + true -> ok; _ -> throw({denied, "Caller ids do not match"}) diff --git a/src/mongoose_privacy.erl b/src/mongoose_privacy.erl index bb6ed292db..b3b789d104 100644 --- a/src/mongoose_privacy.erl +++ b/src/mongoose_privacy.erl @@ -49,7 +49,7 @@ privacy_check_packet(Acc0, JID, PrivacyList, To, Dir) -> From :: jid:jid(), To :: jid:jid(), Dir :: 'in' | 'out') -> {mongoose_acc:t(), decision()}. -privacy_check_packet(Acc0, #jid{luser = User, server = Server} = JID, +privacy_check_packet(Acc0, #jid{luser = LUser, lserver = LServer} = JID, PrivacyList, From, To, Dir) -> % see if we have just Acc or also stanza to check - may have different name/type {Acc, Name, Type} = case Acc0 of @@ -60,7 +60,7 @@ privacy_check_packet(Acc0, #jid{luser = User, server = Server} = JID, {Acc0, mongoose_acc:stanza_name(Acc0), mongoose_acc:stanza_type(Acc0)} end, % check if it is there, if not then set default and run a hook - Key = {cached_check, Server, User, From, To, Name, Type, Dir}, + Key = {cached_check, LServer, LUser, From, To, Name, Type, Dir}, case mongoose_acc:get(privacy, Key, undefined, Acc) of undefined -> Acc1 = mongoose_hooks:privacy_check_packet(Acc, JID, PrivacyList, diff --git a/src/muc_light/mod_muc_light_codec_modern.erl b/src/muc_light/mod_muc_light_codec_modern.erl index 16886160f0..59dbbbfb87 100644 --- a/src/muc_light/mod_muc_light_codec_modern.erl +++ b/src/muc_light/mod_muc_light_codec_modern.erl @@ -356,8 +356,7 @@ encode_iq({set, #create{} = Create, UniqueRequested}, %% IQ reply "from" %% Sent from service JID when unique room was requested {ResFromJID, ResFromBin} = case UniqueRequested of - true -> {#jid{ server = RoomJID#jid.lserver, - lserver = RoomJID#jid.lserver }, + true -> {#jid{lserver = RoomJID#jid.lserver}, RoomJID#jid.lserver}; false -> {RoomJID, RoomBin} end, diff --git a/src/pubsub/mod_pubsub.erl b/src/pubsub/mod_pubsub.erl index 15c9725ad3..2e7433fc9b 100644 --- a/src/pubsub/mod_pubsub.erl +++ b/src/pubsub/mod_pubsub.erl @@ -3242,14 +3242,11 @@ subscription_to_string(subscribed) -> <<"subscribed">>; subscription_to_string(pending) -> <<"pending">>; subscription_to_string(_) -> <<"none">>. --spec service_jid( - Host :: mod_pubsub:host()) - ->jid:jid(). +-spec service_jid(mod_pubsub:host()) -> jid:jid(). +service_jid({U, S, _}) -> + jid:make_bare(U, S); service_jid(Host) -> - case Host of - {U, S, _} -> {jid, U, S, <<>>, U, S, <<>>}; - _ -> {jid, <<>>, Host, <<>>, <<>>, Host, <<>>} - end. + jid:make_bare(<<>>, Host). %% @doc

Check if a notification must be delivered or not based on %% node and subscription options.

@@ -3608,7 +3605,7 @@ broadcast_stanza({LUser, LServer, LResource}, Publisher, Node, Nidx, Type, NodeO ejabberd_c2s:run_remote_hook(C2SPid, pep_message, {<<((Node))/binary, "+notify">>, - jid:make(LUser, LServer, <<"">>), + jid:make_bare(LUser, LServer), add_extended_headers(Stanza, ReplyTo)}); _ -> @@ -3688,7 +3685,7 @@ process_jid_to_deliver(JIDs, SubID, NodeName, JIDToDeliver, {JIDsAcc, Recipients end. user_resources(User, Server) -> - JID = jid:make(User, Server, <<>>), + JID = jid:make_bare(User, Server), ejabberd_sm:get_user_resources(JID). user_resource(User, Server, <<>>) -> diff --git a/src/sasl/cyrsasl_external.erl b/src/sasl/cyrsasl_external.erl index 95e3909580..f751802902 100644 --- a/src/sasl/cyrsasl_external.erl +++ b/src/sasl/cyrsasl_external.erl @@ -197,7 +197,7 @@ verify_server(Jid, Server) -> JidRecord = jid:binary_to_bare(Jid), case JidRecord#jid.lserver of Server -> - {ok, JidRecord#jid.user}; + {ok, JidRecord#jid.luser}; _ -> {error, <<"not-authorized">>} end. diff --git a/src/vcard/mod_vcard.erl b/src/vcard/mod_vcard.erl index 1fe9bbe2d5..13398670f2 100644 --- a/src/vcard/mod_vcard.erl +++ b/src/vcard/mod_vcard.erl @@ -409,8 +409,8 @@ process_sm_iq(Acc, From, To, IQ = #iq{type = get, sub_el = VCARD}, _Extra) -> process_sm_iq_get(HostType, From, To, Acc, IQ, VCARD). process_sm_iq_set(HostType, From, To, Acc, IQ, VCARD) -> - #jid{user = FromUser, lserver = FromVHost} = From, - #jid{user = ToUser, lserver = ToVHost, resource = ToResource} = To, + #jid{luser = FromUser, lserver = FromVHost} = From, + #jid{luser = ToUser, lserver = ToVHost, lresource = ToResource} = To, Local = ((FromUser == ToUser) andalso (FromVHost == ToVHost) andalso (ToResource == <<>>)) orelse ((ToUser == <<>>) andalso (ToVHost == <<>>)), Res = case Local of @@ -456,7 +456,7 @@ process_sm_iq_get(HostType, _From, To, Acc, IQ, SubEl) -> {Acc, Res}. unsafe_set_vcard(HostType, From, VCARD) -> - #jid{user = FromUser, lserver = FromVHost} = From, + #jid{luser = FromUser, lserver = FromVHost} = From, case parse_vcard(FromUser, FromVHost, VCARD) of {ok, VcardSearch} -> mod_vcard_backend:set_vcard(HostType, FromUser, FromVHost, VCARD, VcardSearch); @@ -506,8 +506,8 @@ remove_user(Acc, User, Server) -> %% Internal %% ------------------------------------------------------------------ do_route(_HostType, _LServer, From, - #jid{user = User, resource = Resource} = To, Acc, _IQ) - when (User /= <<>>) or (Resource /= <<>>) -> + #jid{luser = LUser, lresource = LResource} = To, Acc, _IQ) + when (LUser /= <<>>) or (LResource /= <<>>) -> {Acc1, Err} = jlib:make_error_reply(Acc, mongoose_xmpp_errors:service_unavailable()), ejabberd_router:route(To, From, Acc1, Err); do_route(HostType, LServer, From, To, Acc, @@ -744,7 +744,7 @@ search_result_get_jid(#xmlel{name = <<"item">>, undefined end. -parse_vcard(User, VHost, VCARD) -> +parse_vcard(LUser, VHost, VCARD) -> FN = xml:get_path_s(VCARD, [{elem, <<"FN">>}, cdata]), Family = xml:get_path_s(VCARD, [{elem, <<"N">>}, {elem, <<"FAMILY">>}, cdata]), @@ -770,7 +770,6 @@ parse_vcard(User, VHost, VCARD) -> _ -> EMail1 end, try - LUser = jid:nodeprep(User), LFN = prepare_index(<<"FN">>, FN), LFamily = prepare_index(<<"FAMILY">>, Family), LGiven = prepare_index(<<"GIVEN">>, Given), @@ -786,7 +785,7 @@ parse_vcard(User, VHost, VCARD) -> US = {LUser, VHost}, {ok, #vcard_search{us = US, - user = {User, VHost}, + user = {LUser, VHost}, luser = LUser, fn = FN, lfn = LFN, family = Family, lfamily = LFamily, diff --git a/test/auth_tokens_SUITE.erl b/test/auth_tokens_SUITE.erl index 4a533e0512..24bab70a1b 100644 --- a/test/auth_tokens_SUITE.erl +++ b/test/auth_tokens_SUITE.erl @@ -259,8 +259,7 @@ mock_ejabberd_commands() -> provision_token_example() -> {token,provision, {{2055,10,27},{10,54,22}}, - {jid,<<"cEE2M1S0I">>,domain(),<<>>,<<"cee2m1s0i">>, - domain(),<<>>}, + {jid,<<"cee2m1s0i">>,domain(),<<>>}, undefined, {xmlel,<<"vCard">>, [{<<"sgzldnl">>,<<"inxdutpu">>}, @@ -282,9 +281,9 @@ provision_token_example() -> [{<<"femjc">>,<<"qqb">>},{<<"tirfmekvpk">>,<<"sa">>}], []}, {xmlcdata,<<"bgxlyqdeeuo">>}]}, - <<109,213,86,17,172,7,27,229,193,103,207,86,43,31,239,117,234,234, - 232,0,223,168,125,154,189,87,232,159,77,11,35,216,127,171,83,207, - 208,184,40,208,45,102,189,131,110,204,245,28>>, + <<40,147,30,116,208,228,12,231,163,180,143,193,209,7,131,166, + 44,123,76,50,14,34,31,163,142,88,138,73,220,190,130,60,151, + 113,46,103,66,94,187,90,137,184,0,64,114,199,73,150>>, <<112,114,111,118,105,115,105,111,110,0,99,69,69,50,77,49,83,48,73, 64,108,111,99,97,108,104,111,115,116,0,54,52,56,55,53,52,54,54,52, 54,50,0,60,118,67,97,114,100,32,115,103,122,108,100,110,108,61,39, @@ -307,7 +306,7 @@ provision_token_example() -> refresh_token_example() -> {token,refresh, {{2055,10,27},{10,54,14}}, - {jid,<<"a">>,domain(),<<>>,<<"a">>,domain(),<<>>}, + {jid,<<"a">>,domain(),<<>>}, 4,undefined, <<151,225,117,181,0,168,228,208,238,182,157,253,24,200,231,25,189, 160,176,144,85,193,20,108,31,23,46,35,215,41,250,57,68,201,45,33, diff --git a/test/ejabberd_admin_SUITE.erl b/test/ejabberd_admin_SUITE.erl index 427adb8843..b8cf5f1795 100644 --- a/test/ejabberd_admin_SUITE.erl +++ b/test/ejabberd_admin_SUITE.erl @@ -26,10 +26,10 @@ end_per_suite(_Config) -> init_per_group(_, Config) -> meck:new(ejabberd_auth, [no_link]), meck:expect(ejabberd_auth, try_register, - fun(#jid{user = <<"existing_user">>}, _) -> {error, exists}; - (#jid{user = <<"null_password_user">>}, _) -> {error, null_password}; - (#jid{server = <<"not_allowed_domain">>}, _) -> {error, not_allowed}; - (#jid{user = <<"invalid_jid_user">>}, _) -> {error, invalid_jid}; + fun(#jid{luser = <<"existing_user">>}, _) -> {error, exists}; + (#jid{luser = <<"null_password_user">>}, _) -> {error, null_password}; + (#jid{lserver = <<"not_allowed_domain">>}, _) -> {error, not_allowed}; + (#jid{luser = <<"invalid_jid_user">>}, _) -> {error, invalid_jid}; (_, _) -> ok end), Config. diff --git a/test/json_formatter_SUITE.erl b/test/json_formatter_SUITE.erl index deffa3265c..9e15aa5717 100644 --- a/test/json_formatter_SUITE.erl +++ b/test/json_formatter_SUITE.erl @@ -151,13 +151,13 @@ acc_is_formatted(Config) -> <<"pid">> := Pid}, % Because of the format_acc_filter/2 we don't get the full accumulator <<"acc_timestamp">> := DateTimeStrBin2, - <<"from_jid">> := <<"userA@localhost">>, + <<"from_jid">> := <<"usera@localhost">>, <<"origin_pid">> := Pid, % format_packet_filter/2 changes the packet <<"packet">> := <<"JSON-match-this-acc">>, <<"routing_modules">> := [<<"mongoose_router_1">>, <<"mongoose_router_2">>], <<"routing_result">> := [<<"{{inside,two_tuples}}">>,<<"{inside,one_tuple}">>], - <<"to_jid">> := <<"userB@localhost">>, + <<"to_jid">> := <<"userb@localhost">>, <<"what">> := <<"routing_result">>} = Decoded, ?assert(is_integer(calendar:rfc3339_to_system_time(binary_to_list(DateTimeStrBin)))), @@ -196,13 +196,13 @@ acc_is_preserved(Config) -> % Because of the preserve_acc_filter/2 we get the full accumulator as acc_original <<"acc_original">> := A, <<"acc_timestamp">> := DateTimeStrBin2, - <<"from_jid">> := <<"userA@localhost">>, + <<"from_jid">> := <<"usera@localhost">>, <<"origin_pid">> := Pid, % format_packet_filter/2 changes the packet <<"packet">> := <<"JSON-match-this-preserve-acc">>, <<"routing_modules">> := [<<"mongoose_router_1">>, <<"mongoose_router_2">>], <<"routing_result">> := [<<"{{inside,two_tuples}}">>,<<"{inside,one_tuple}">>], - <<"to_jid">> := <<"userB@localhost">>, + <<"to_jid">> := <<"userb@localhost">>, <<"what">> := <<"routing_result">>} = Decoded, % This is not ideal but that's how the filter behaves @@ -348,7 +348,7 @@ large_event_dont_crash_formatter(_Config) -> example_acc(Body) -> Elem = {xmlel, <<"message">>, [{<<"type">>, <<"chat">>}, {<<"id">>, <<"1111">>}], - [{xmlel, <<"body">>,[], [{xmlcdata, Body}]}]}, + [{xmlel, <<"body">>, [], [{xmlcdata, Body}]}]}, #{lserver => <<"localhost">>, mongoose_acc => true, non_strippable => [], @@ -358,10 +358,10 @@ example_acc(Body) -> origin_pid => self(), ref => make_ref(), stanza => #{element => Elem, - from_jid => {jid,<<"userA">>,<<"localhost">>,<<>>,<<"usera">>,<<"localhost">>,<<>>}, + from_jid => {jid, <<"usera">>, <<"localhost">>, <<>>}, name => <<"message">>, ref => make_ref(), - to_jid => {jid,<<"userB">>,<<"localhost">>,<<>>,<<"userb">>,<<"localhost">>,<<>>}, + to_jid => {jid, <<"userb">>, <<"localhost">>, <<>>}, type => <<"chat">>}, timestamp => 1598878576962100}. From 3f3f976c0cec13979959b76d11887a4a3c6b518d Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Tue, 26 Apr 2022 18:30:05 +0200 Subject: [PATCH 3/4] Simplify to_binary(to_lus()) with to_bare_binary --- src/event_pusher/mod_event_pusher_push_rdbms.erl | 10 +++++----- src/inbox/mod_inbox_utils.erl | 2 +- src/jingle_sip/mod_jingle_sip.erl | 4 ++-- src/muc_light/mod_muc_light_codec_legacy.erl | 2 +- src/offline/mod_offline_chatmarkers.erl | 2 +- src/offline/mod_offline_chatmarkers_rdbms.erl | 2 +- src/smart_markers/mod_smart_markers.erl | 2 +- src/smart_markers/mod_smart_markers_rdbms.erl | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/event_pusher/mod_event_pusher_push_rdbms.erl b/src/event_pusher/mod_event_pusher_push_rdbms.erl index 93210ef5ea..73f0a6840b 100644 --- a/src/event_pusher/mod_event_pusher_push_rdbms.erl +++ b/src/event_pusher/mod_event_pusher_push_rdbms.erl @@ -35,7 +35,7 @@ init(_HostType, _Opts) -> Form :: mod_event_pusher_push:form(), Result :: ok | {error, term()}. enable(HostType, User, PubSub, Node, Forms) -> - ExtUser = jid:to_binary(jid:to_lus(User)), + ExtUser = jid:to_bare_binary(User), ExtPubSub = jid:to_binary(PubSub), ExtForms = encode_form(Forms), execute_delete(HostType, ExtUser, Node, ExtPubSub), @@ -47,19 +47,19 @@ enable(HostType, User, PubSub, Node, Forms) -> -spec disable(mongooseim:host_type(), User :: jid:jid()) -> ok. disable(HostType, User) -> - ExtUser = jid:to_binary(jid:to_lus(User)), + ExtUser = jid:to_bare_binary(User), execute_delete(HostType, ExtUser), ok. -spec disable(mongooseim:host_type(), User :: jid:jid(), PubSub :: jid:jid(), Node :: mod_event_pusher_push:pubsub_node() | undefined) -> ok. disable(HostType, User, PubSub, undefined) -> - ExtUser = jid:to_binary(jid:to_lus(User)), + ExtUser = jid:to_bare_binary(User), ExtPubSub = jid:to_binary(PubSub), execute_delete(HostType, ExtUser, ExtPubSub), ok; disable(HostType, User, PubSub, Node) -> - ExtUser = jid:to_binary(jid:to_lus(User)), + ExtUser = jid:to_bare_binary(User), ExtPubSub = jid:to_binary(PubSub), execute_delete(HostType, ExtUser, Node, ExtPubSub), ok. @@ -69,7 +69,7 @@ disable(HostType, User, PubSub, Node) -> Node :: mod_event_pusher_push:pubsub_node(), Form :: mod_event_pusher_push:form()}]}. get_publish_services(HostType, User) -> - ExtUser = jid:to_binary(jid:to_lus(User)), + ExtUser = jid:to_bare_binary(User), {selected, Rows} = execute_select(HostType, ExtUser), {ok, decode_rows(Rows)}. diff --git a/src/inbox/mod_inbox_utils.erl b/src/inbox/mod_inbox_utils.erl index c57f97a89d..534df68c6c 100644 --- a/src/inbox/mod_inbox_utils.erl +++ b/src/inbox/mod_inbox_utils.erl @@ -211,7 +211,7 @@ bool_to_binary(_) -> error. build_inbox_entry_key(FromJid, ToJid) -> {LUser, LServer} = jid:to_lus(FromJid), - ToBareJid = jid:nameprep(jid:to_binary(jid:to_lus(ToJid))), + ToBareJid = jid:nameprep(jid:to_bare_binary(ToJid)), {LUser, LServer, ToBareJid}. -spec build_forward_el(inbox_res()) -> exml:element(). diff --git a/src/jingle_sip/mod_jingle_sip.erl b/src/jingle_sip/mod_jingle_sip.erl index 35817839c8..b1c05af4c4 100644 --- a/src/jingle_sip/mod_jingle_sip.erl +++ b/src/jingle_sip/mod_jingle_sip.erl @@ -236,8 +236,8 @@ translate_to_sip(<<"session-initiate">>, Jingle, Acc) -> SID = exml_query:attr(Jingle, <<"sid">>), #jid{luser = ToUser} = ToJID = jingle_sip_helper:maybe_rewrite_to_phone(Acc), #jid{luser = FromUser} = FromJID = mongoose_acc:from_jid(Acc), - From = jid:to_binary(jid:to_lus(FromJID)), - To = jid:to_binary(jid:to_lus(ToJID)), + From = jid:to_bare_binary(FromJID), + To = jid:to_bare_binary(ToJID), LServer = mongoose_acc:lserver(Acc), SDP = prepare_initial_sdp(LServer, Jingle), ProxyURI = get_proxy_uri(LServer), diff --git a/src/muc_light/mod_muc_light_codec_legacy.erl b/src/muc_light/mod_muc_light_codec_legacy.erl index ab6225513f..0f13505d60 100644 --- a/src/muc_light/mod_muc_light_codec_legacy.erl +++ b/src/muc_light/mod_muc_light_codec_legacy.erl @@ -50,7 +50,7 @@ decode(_, _, _, _Acc) -> encode({#msg{} = Msg, AffUsers}, Sender, RoomBareJid, HandleFun, Acc) -> US = jid:to_lus(Sender), Aff = get_sender_aff(AffUsers, US), - FromNick = jid:to_binary(jid:to_lus(Sender)), + FromNick = jid:to_bare_binary(Sender), {RoomJID, RoomBin} = jids_from_room_with_resource(RoomBareJid, FromNick), Attrs = [ {<<"id">>, Msg#msg.id}, diff --git a/src/offline/mod_offline_chatmarkers.erl b/src/offline/mod_offline_chatmarkers.erl index 67b5685d4f..e1a834efa7 100644 --- a/src/offline/mod_offline_chatmarkers.erl +++ b/src/offline/mod_offline_chatmarkers.erl @@ -169,7 +169,7 @@ build_one2one_chatmarker_msg(Acc, CM) -> build_room_chatmarker_msg(Acc, To, CM) -> #{from := FromUser, to := Room, thread := Thread, type := Type, id := Id, timestamp := TS} = CM, - FromUserBin = jid:to_binary(jid:to_lus(FromUser)), + FromUserBin = jid:to_bare_binary(FromUser), From = jid:make(Room#jid.luser, Room#jid.lserver, FromUserBin), FromBin = jid:to_binary(From), Children = thread(Thread) ++ marker(Type, Id), diff --git a/src/offline/mod_offline_chatmarkers_rdbms.erl b/src/offline/mod_offline_chatmarkers_rdbms.erl index 545b83588b..0474049c6a 100644 --- a/src/offline/mod_offline_chatmarkers_rdbms.erl +++ b/src/offline/mod_offline_chatmarkers_rdbms.erl @@ -70,7 +70,7 @@ remove_user(HostType, Jid) -> ok. encode_jid(undefined) -> <<>>; -encode_jid(JID) -> jid:to_binary(jid:to_lus(JID)). +encode_jid(JID) -> jid:to_bare_binary(JID). encode_thread(undefined) -> <<>>; encode_thread(Thread) -> Thread. diff --git a/src/smart_markers/mod_smart_markers.erl b/src/smart_markers/mod_smart_markers.erl index cb1ba54a43..642d4bfc2b 100644 --- a/src/smart_markers/mod_smart_markers.erl +++ b/src/smart_markers/mod_smart_markers.erl @@ -171,7 +171,7 @@ fetch_markers(IQ, Acc, From, Peer, Thread, TS, Private) -> Markers = mod_smart_markers_backend:get_conv_chat_marker(HostType, From, Peer, Thread, TS, Private), SubEl = #xmlel{name = <<"query">>, attrs = [{<<"xmlns">>, ?NS_ESL_SMART_MARKERS}, - {<<"peer">>, jid:to_binary(jid:to_lus(Peer))}], + {<<"peer">>, jid:to_bare_binary(Peer)}], children = build_result(Markers)}, IQ#iq{type = result, sub_el = SubEl}. diff --git a/src/smart_markers/mod_smart_markers_rdbms.erl b/src/smart_markers/mod_smart_markers_rdbms.erl index 1d7f26bfa2..3d70f6501d 100644 --- a/src/smart_markers/mod_smart_markers_rdbms.erl +++ b/src/smart_markers/mod_smart_markers_rdbms.erl @@ -146,7 +146,7 @@ remove_to_for_user(HostType, #jid{luser = LU, lserver = LS}, To) -> %%-------------------------------------------------------------------- %% local functions %%-------------------------------------------------------------------- -encode_jid(JID) -> jid:to_binary(jid:to_lus(JID)). +encode_jid(JID) -> jid:to_bare_binary(JID). encode_thread(undefined) -> <<>>; encode_thread(Thread) -> Thread. From b9dc81d17dee2d7dc019da55132fdb957046142d Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Tue, 26 Apr 2022 18:31:43 +0200 Subject: [PATCH 4/4] Simplify to_binary(to_bare()) with to_bare_binary --- src/event_pusher/mod_event_pusher_push_plugin_defaults.erl | 2 +- src/mam/mod_mam_rdbms_prefs.erl | 2 +- src/mam/mod_mam_utils.erl | 6 +++--- src/mod_auth_token_rdbms.erl | 6 +++--- src/mod_carboncopy.erl | 2 +- src/offline/mod_offline.erl | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/event_pusher/mod_event_pusher_push_plugin_defaults.erl b/src/event_pusher/mod_event_pusher_push_plugin_defaults.erl index e030e50ac1..450d5b2f6d 100644 --- a/src/event_pusher/mod_event_pusher_push_plugin_defaults.erl +++ b/src/event_pusher/mod_event_pusher_push_plugin_defaults.erl @@ -100,7 +100,7 @@ get_unread_count(Acc, To) -> sender_id(From, Packet) -> case exml_query:attr(Packet, <<"type">>) of <<"chat">> -> - jid:to_binary(jid:to_bare(jid:to_lower(From))); + jid:to_bare_binary(jid:to_lower(From)); <<"groupchat">> -> jid:to_binary(jid:to_lower(From)) end. diff --git a/src/mam/mod_mam_rdbms_prefs.erl b/src/mam/mod_mam_rdbms_prefs.erl index 761c5ff3d7..b4cfa01b01 100644 --- a/src/mam/mod_mam_rdbms_prefs.erl +++ b/src/mam/mod_mam_rdbms_prefs.erl @@ -109,7 +109,7 @@ order_by_remote_jid_in_delete(HostType) -> get_behaviour(DefaultBehaviour, HostType, UserID, _LocJID, RemJID) when is_integer(UserID) -> RemLJID = jid:to_lower(RemJID), - BRemLBareJID = jid:to_binary(jid:to_bare(RemLJID)), + BRemLBareJID = jid:to_bare_binary(RemLJID), BRemLJID = jid:to_binary(RemLJID), case query_behaviour(HostType, UserID, BRemLJID, BRemLBareJID) of {selected, []} -> diff --git a/src/mam/mod_mam_utils.erl b/src/mam/mod_mam_utils.erl index ce2bcec627..0c8938e0c7 100644 --- a/src/mam/mod_mam_utils.erl +++ b/src/mam/mod_mam_utils.erl @@ -237,7 +237,7 @@ external_binary_to_mess_id(BExtMessID) when is_binary(BExtMessID) -> AddStanzaid :: boolean()) -> AlteredPacket :: exml:element(). maybe_add_arcid_elems(To, MessID, Packet, AddStanzaid) -> - BareTo = jid:to_binary(jid:to_bare(To)), + BareTo = jid:to_bare_binary(To), case AddStanzaid of true -> replace_arcid_elem(<<"stanza-id">>, BareTo, MessID, Packet); @@ -427,7 +427,7 @@ retracted_element(#{retract_on := stanza_id, children = [#xmlel{name = <<"stanza-id">>, attrs = [{<<"xmlns">>, ?NS_STANZAID}, {<<"id">>, StanzaID}, - {<<"by">>, jid:to_binary(jid:to_bare(LocJid))}]} | + {<<"by">>, jid:to_bare_binary(LocJid)}]} | MaybeOriginId ]}. @@ -953,7 +953,7 @@ is_loaded_application(AppName) when is_atom(AppName) -> -spec bare_jid(undefined | jid:jid()) -> undefined | binary(). bare_jid(undefined) -> undefined; bare_jid(JID) -> - jid:to_binary(jid:to_bare(jid:to_lower(JID))). + jid:to_bare_binary(jid:to_lower(JID)). -spec full_jid(jid:jid()) -> binary(). full_jid(JID) -> diff --git a/src/mod_auth_token_rdbms.erl b/src/mod_auth_token_rdbms.erl index 23e7f25da3..2d808cd72b 100644 --- a/src/mod_auth_token_rdbms.erl +++ b/src/mod_auth_token_rdbms.erl @@ -16,7 +16,7 @@ start(HostType) -> %% are not valid. -spec get_valid_sequence_number(mongooseim:host_type(), jid:jid()) -> integer(). get_valid_sequence_number(HostType, JID) -> - BBareJID = jid:to_binary(jid:to_bare(JID)), + BBareJID = jid:to_bare_binary(JID), {atomic, Selected} = mongoose_rdbms:sql_transaction( HostType, fun() -> get_sequence_number_t(HostType, BBareJID) end), @@ -24,7 +24,7 @@ get_valid_sequence_number(HostType, JID) -> -spec revoke(mongooseim:host_type(), jid:jid()) -> ok | not_found. revoke(HostType, JID) -> - BBareJID = jid:to_binary(jid:to_bare(JID)), + BBareJID = jid:to_bare_binary(JID), QueryResult = execute_revoke_token(HostType, BBareJID), ?LOG_DEBUG(#{what => auth_token_revoke, owner => BBareJID, sql_result => QueryResult}), case QueryResult of @@ -34,7 +34,7 @@ revoke(HostType, JID) -> -spec clean_tokens(mongooseim:host_type(), jid:jid()) -> ok. clean_tokens(HostType, Owner) -> - BBareJID = jid:to_binary(jid:to_bare(Owner)), + BBareJID = jid:to_bare_binary(Owner), execute_delete_token(HostType, BBareJID), ok. diff --git a/src/mod_carboncopy.erl b/src/mod_carboncopy.erl index 54a6320cbe..7b9c637a71 100644 --- a/src/mod_carboncopy.erl +++ b/src/mod_carboncopy.erl @@ -395,5 +395,5 @@ set_stanza_id(Acc, From, Packet) -> set_stanza_id(undefined, _From, _Acc, Packet) -> Packet; set_stanza_id(MamId, From, _Acc, Packet) -> - By = jid:to_binary(jid:to_bare(From)), + By = jid:to_bare_binary(From), mod_mam_utils:replace_arcid_elem(<<"stanza-id">>, By, MamId, Packet). diff --git a/src/offline/mod_offline.erl b/src/offline/mod_offline.erl index 3f4ecf274c..40209639e8 100644 --- a/src/offline/mod_offline.erl +++ b/src/offline/mod_offline.erl @@ -519,7 +519,7 @@ offline_msg_to_gdpr_format(#offline_msg{timestamp = TimeStamp, from = From, SystemTime = erlang:convert_time_unit(TimeStamp, microsecond, second), UTCTime = calendar:system_time_to_rfc3339(SystemTime, [{offset, "Z"}]), UTC = list_to_binary(UTCTime), - {UTC, jid:to_binary(From), jid:to_binary(jid:to_bare(To)), exml:to_binary(Packet)}. + {UTC, jid:to_binary(From), jid:to_bare_binary(To), exml:to_binary(Packet)}. skip_expired_messages(TimeStamp, Rs) -> [R || R <- Rs, not is_expired_message(TimeStamp, R)].