25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Don't pass empty resource to jid:make()

This commit is contained in:
Evgeniy Khramtsov 2017-02-25 10:01:01 +03:00
parent 485aae8134
commit 603ec9cb19
23 changed files with 44 additions and 48 deletions

View File

@ -731,7 +731,7 @@ check_access(Command, Access, Auth, CallerInfo)
Command#ejabberd_commands.policy == user ->
case check_auth(Command, Auth) of
{ok, User, Server} ->
check_access2(Access, CallerInfo#{usr => jid:split(jid:make(User, Server, <<>>))}, Server);
check_access2(Access, CallerInfo#{usr => jid:split(jid:make(User, Server))}, Server);
no_auth_provided ->
case Command#ejabberd_commands.policy of
user ->
@ -834,7 +834,7 @@ oauth_token_user(noauth) ->
oauth_token_user(admin) ->
undefined;
oauth_token_user({User, Server, _, _}) ->
jid:make(User, Server, <<>>).
jid:make(User, Server).
is_admin(_Name, admin, _Extra) ->
true;
@ -845,7 +845,7 @@ is_admin(_Name, Map, _extra) when is_map(Map) ->
is_admin(Name, Auth, Extra) ->
{ACLInfo, Server} = case Auth of
{U, S, _, _} ->
{Extra#{usr=>jid:split(jid:make(U, S, <<>>))}, S};
{Extra#{usr=>jid:split(jid:make(U, S))}, S};
_ ->
{Extra, global}
end,

View File

@ -127,7 +127,7 @@ oauth_list_tokens() ->
Tokens = mnesia:dirty_match_object(#oauth_token{_ = '_'}),
{MegaSecs, Secs, _MiniSecs} = os:timestamp(),
TS = 1000000 * MegaSecs + Secs,
[{Token, jid:to_string(jid:make(U,S,<<>>)), Scope, integer_to_list(Expires - TS) ++ " seconds"} ||
[{Token, jid:to_string(jid:make(U,S)), Scope, integer_to_list(Expires - TS) ++ " seconds"} ||
#oauth_token{token=Token, scope=Scope, us= {U,S},expire=Expires} <- Tokens].
@ -193,7 +193,7 @@ get_client_identity(Client, Ctx) -> {ok, {Ctx, {client, Client}}}.
verify_redirection_uri(_, _, Ctx) -> {ok, Ctx}.
authenticate_user({User, Server}, Ctx) ->
case jid:make(User, Server, <<"">>) of
case jid:make(User, Server) of
#jid{} = JID ->
Access =
ejabberd_config:get_option(

View File

@ -246,7 +246,7 @@ get_privacy(User, Server) ->
-spec get_roster(binary(), binary()) -> [xmlel()].
get_roster(User, Server) ->
JID = jid:make(User, Server, <<>>),
JID = jid:make(User, Server),
case mod_roster:get_roster(User, Server) of
[_|_] = Items ->
Subs =

View File

@ -189,7 +189,7 @@ bounce_offline_message(Acc) ->
-spec disconnect_removed_user(binary(), binary()) -> ok.
disconnect_removed_user(User, Server) ->
route(jid:make(User, Server, <<"">>), {exit, <<"User removed">>}).
route(jid:make(User, Server), {exit, <<"User removed">>}).
get_user_resources(User, Server) ->
LUser = jid:nodeprep(User),
@ -739,7 +739,7 @@ check_max_sessions(LUser, LServer) ->
-spec get_max_user_sessions(binary(), binary()) -> infinity | non_neg_integer().
get_max_user_sessions(LUser, Host) ->
case acl:match_rule(Host, max_user_sessions,
jid:make(LUser, Host, <<"">>))
jid:make(LUser, Host))
of
Max when is_integer(Max) -> Max;
infinity -> infinity;

View File

@ -102,7 +102,7 @@ get_acl_rule(_RPath, 'POST') ->
get_jid(Auth, HostHTTP, Method) ->
case get_auth_admin(Auth, HostHTTP, [], Method) of
{ok, {User, Server}} ->
jid:make(User, Server, <<"">>);
jid:make(User, Server);
{unauthorized, Error} ->
?ERROR_MSG("Unauthorized ~p: ~p", [Auth, Error]),
throw({unauthorized, Auth})
@ -274,7 +274,7 @@ get_auth_account(HostOfRule, AccessRule, User, Server,
case ejabberd_auth:check_password(User, <<"">>, Server, Pass) of
true ->
case acl:any_rules_allowed(HostOfRule, AccessRule,
jid:make(User, Server, <<"">>))
jid:make(User, Server))
of
false -> {unauthorized, <<"unprivileged-account">>};
true -> {ok, {User, Server}}

View File

@ -638,7 +638,7 @@ create_delay_tag(TimeStamp, FromJID, Desc) when is_tuple(FromJID) ->
{<<"stamp">>, Stamp}],
children = Children};
create_delay_tag(DateTime, Host, Desc) when is_binary(Host) ->
FromJID = jid:make(<<"">>, Host, <<"">>),
FromJID = jid:make(Host),
create_delay_tag(DateTime, FromJID, Desc).
-type tz() :: {binary(), {integer(), integer()}} | {integer(), integer()} | utc.

View File

@ -1418,7 +1418,7 @@ btl(B) -> binary_to_list(B).
srg_get_members(Group, Host) ->
Members = mod_shared_roster:get_group_explicit_users(Host,Group),
[jid:to_string(jid:make(MUser, MServer, <<>>))
[jid:to_string(jid:make(MUser, MServer))
|| {MUser, MServer} <- Members].
srg_user_add(User, Host, Group, GroupHost) ->

View File

@ -630,7 +630,7 @@ announce_all(#message{to = To} = Packet) ->
Local = jid:make(To#jid.server),
lists:foreach(
fun({User, Server}) ->
Dest = jid:make(User, Server, <<>>),
Dest = jid:make(User, Server),
ejabberd_router:route(
xmpp:set_from_to(add_store_hint(Packet), Local, Dest))
end, ejabberd_auth:get_vh_registered_users(To#jid.lserver)).
@ -639,7 +639,7 @@ announce_all_hosts_all(#message{to = To} = Packet) ->
Local = jid:make(To#jid.server),
lists:foreach(
fun({User, Server}) ->
Dest = jid:make(User, Server, <<>>),
Dest = jid:make(User, Server),
ejabberd_router:route(
xmpp:set_from_to(add_store_hint(Packet), Local, Dest))
end, ejabberd_auth:dirty_get_registered_users()).

View File

@ -395,7 +395,7 @@ caps_write_fun(Host, Node, Features) ->
-spec make_my_disco_hash(binary()) -> binary().
make_my_disco_hash(Host) ->
JID = jid:make(<<"">>, Host, <<"">>),
JID = jid:make(Host),
case {ejabberd_hooks:run_fold(disco_local_features,
Host, empty, [JID, JID, <<"">>, <<"">>]),
ejabberd_hooks:run_fold(disco_local_identity, Host, [],

View File

@ -928,7 +928,7 @@ remove_user(User, Server) ->
end,
sha1),
DocRoot1 = expand_host(expand_home(DocRoot), ServerHost),
UserStr = make_user_string(jid:make(User, Server, <<"">>), JIDinURL),
UserStr = make_user_string(jid:make(User, Server), JIDinURL),
UserDir = str:join([DocRoot1, UserStr], <<$/>>),
case del_tree(UserDir) of
ok ->

View File

@ -73,7 +73,7 @@ update_table() ->
fun(#irc_custom{us_host = {_, H}}) -> H end,
fun(#irc_custom{us_host = {{U, S}, H},
data = Data} = R) ->
JID = jid:make(U, S, <<"">>),
JID = jid:make(U, S),
R#irc_custom{us_host = {{iolist_to_binary(U),
iolist_to_binary(S)},
iolist_to_binary(H)},

View File

@ -72,7 +72,7 @@ export(_Server) ->
data = Data}) ->
case str:suffix(Host, IRCHost) of
true ->
SJID = jid:to_string(jid:make(U, S, <<"">>)),
SJID = jid:to_string(jid:make(U, S)),
SData = jlib:term_to_expr(Data),
[?SQL("delete from irc_custom"
" where jid=%(SJID)s and host=%(IRCHost)s;"),

View File

@ -732,7 +732,7 @@ get_room_occupants_number(Room, Host) ->
%% http://xmpp.org/extensions/xep-0249.html
send_direct_invitation(RoomName, RoomService, Password, Reason, UsersString) ->
RoomJid = jid:make(RoomName, RoomService, <<"">>),
RoomJid = jid:make(RoomName, RoomService),
XmlEl = build_invitation(Password, Reason, RoomJid),
UsersStrings = get_users_to_invite(RoomJid, UsersString),
[send_direct_invitation(RoomJid, UserStrings, XmlEl)

View File

@ -126,7 +126,7 @@ init([Host, ServerHost, Access, Room, HistorySize,
#state{host = Host, server_host = ServerHost,
access = Access, room = Room,
history = lqueue_new(HistorySize),
jid = jid:make(Room, Host, <<"">>),
jid = jid:make(Room, Host),
just_created = true,
room_shaper = Shaper}),
State1 = set_opts(DefRoomOpts, State),
@ -144,7 +144,7 @@ init([Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts]) ->
access = Access,
room = Room,
history = lqueue_new(HistorySize),
jid = jid:make(Room, Host, <<"">>),
jid = jid:make(Room, Host),
room_shaper = Shaper}),
add_to_log(room_existence, started, State),
{ok, normal_state, State}.

View File

@ -215,7 +215,7 @@ export(_Server) ->
nick = Nick}) ->
case str:suffix(Host, RoomHost) of
true ->
SJID = jid:to_string(jid:make(U, S, <<"">>)),
SJID = jid:to_string(jid:make(U, S)),
[?SQL("delete from muc_registered where"
" jid=%(SJID)s and host=%(RoomHost)s;"),
?SQL("insert into muc_registered(jid, host, "

View File

@ -251,7 +251,7 @@ store_offline_msg(Host, US, Msgs, Len, MaxOfflineMsgs) ->
get_max_user_messages(AccessRule, {User, Server}, Host) ->
case acl:match_rule(
Host, AccessRule, jid:make(User, Server, <<"">>)) of
Host, AccessRule, jid:make(User, Server)) of
Max when is_integer(Max) -> Max;
infinity -> infinity;
_ -> ?MAX_USER_MESSAGES
@ -817,7 +817,7 @@ get_messages_subset2(Max, Length, MsgsAll) ->
{MsgsFirstN, Msgs2} = lists:split(FirstN, MsgsAll),
MsgsLastN = lists:nthtail(Length - FirstN - FirstN,
Msgs2),
NoJID = jid:make(<<"...">>, <<"...">>, <<"">>),
NoJID = jid:make(<<"...">>, <<"...">>),
Seq = <<"0">>,
IntermediateMsg = #xmlel{name = <<"...">>, attrs = [],
children = []},

View File

@ -414,7 +414,7 @@ user_receive_packet({#iq{type = set, meta = #{privacy_updated_list := New}} = IQ
true ->
State
end,
From = jid:make(U, S, <<"">>),
From = jid:make(U, S),
To = jid:make(U, S, R),
{xmpp:set_from_to(IQ, From, To), State1};
user_receive_packet(Acc) ->

View File

@ -723,7 +723,7 @@ presence(ServerHost, Presence) ->
binary(), binary(), jid(),
subscribed | unsubscribed | subscribe | unsubscribe) -> boolean().
out_subscription(User, Server, JID, subscribed) ->
Owner = jid:make(User, Server, <<>>),
Owner = jid:make(User, Server),
{PUser, PServer, PResource} = jid:tolower(JID),
PResources = case PResource of
<<>> -> user_resources(PUser, PServer);
@ -738,7 +738,7 @@ out_subscription(_, _, _, _) ->
subscribe | subscribed | unsubscribe | unsubscribed,
binary()) -> true.
in_subscription(_, User, Server, Owner, unsubscribed, _) ->
unsubscribe_user(jid:make(User, Server, <<>>), Owner),
unsubscribe_user(jid:make(User, Server), Owner),
true;
in_subscription(_, _, _, _, _, _) ->
true.
@ -789,7 +789,7 @@ unsubscribe_user(Host, Entity, Owner) ->
remove_user(User, Server) ->
LUser = jid:nodeprep(User),
LServer = jid:nameprep(Server),
Entity = jid:make(LUser, LServer, <<>>),
Entity = jid:make(LUser, LServer),
Host = host(LServer),
HomeTreeBase = <<"/home/", LServer/binary, "/", LUser/binary>>,
spawn(fun () ->
@ -3023,7 +3023,7 @@ broadcast_stanza({LUser, LServer, LResource}, Publisher, Node, Nidx, Type, NodeO
%% See XEP-0163 1.1 section 4.3.1
ejabberd_sm:route(jid:make(LUser, LServer, SenderResource),
{pep_message, <<((Node))/binary, "+notify">>,
jid:make(LUser, LServer, <<"">>),
jid:make(LUser, LServer),
add_extended_headers(
Stanza, extended_headers([Publisher]))});
broadcast_stanza(Host, _Publisher, Node, Nidx, Type, NodeOptions, SubsByDepth, NotifyType, BaseStanza, SHIM) ->

View File

@ -316,7 +316,7 @@ try_register(User, Server, Password, SourceRaw, Lang) ->
case jid:is_nodename(User) of
false -> {error, xmpp:err_bad_request(<<"Malformed username">>, Lang)};
_ ->
JID = jid:make(User, Server, <<"">>),
JID = jid:make(User, Server),
Access = gen_mod:get_module_opt(Server, ?MODULE, access,
fun(A) -> A end,
all),

View File

@ -106,7 +106,7 @@ process([<<"new">>],
lang = Lang, host = _HTTPHost}) ->
case form_new_post(Q) of
{success, ok, {Username, Host, _Password}} ->
Jid = jid:make(Username, Host, <<"">>),
Jid = jid:make(Username, Host),
mod_register:send_registration_notifications(?MODULE, Jid, Ip),
Text = (?T(<<"Your Jabber account was successfully "
"created.">>)),
@ -499,7 +499,7 @@ register_account(Username, Host, Password) ->
Access = gen_mod:get_module_opt(Host, mod_register, access,
fun(A) -> A end,
all),
case jid:make(Username, Host, <<"">>) of
case jid:make(Username, Host) of
error -> {error, invalid_jid};
JID ->
case acl:match_rule(Host, Access, JID) of

View File

@ -643,7 +643,7 @@ process_subscription(Direction, User, Server, JID1,
_ ->
ejabberd_router:route(
#presence{type = AutoReply,
from = jid:make(User, Server, <<"">>),
from = jid:make(User, Server),
to = JID1})
end,
case Push of
@ -653,7 +653,7 @@ process_subscription(Direction, User, Server, JID1,
ok;
true ->
push_item(User, Server,
jid:make(User, Server, <<"">>), Item)
jid:make(User, Server), Item)
end,
true;
none -> false
@ -1068,7 +1068,7 @@ user_roster_parse_query(User, Server, Items, Query) ->
user_roster_subscribe_jid(User, Server, JID) ->
out_subscription(User, Server, JID, subscribe),
UJID = jid:make(User, Server, <<"">>),
UJID = jid:make(User, Server),
ejabberd_router:route(#presence{from = UJID, to = JID, type = subscribe}).
user_roster_item_parse_query(User, Server, Items,
@ -1083,7 +1083,7 @@ user_roster_item_parse_query(User, Server, Items,
JID1 = jid:make(JID),
out_subscription(User, Server, JID1,
subscribed),
UJID = jid:make(User, Server, <<"">>),
UJID = jid:make(User, Server),
ejabberd_router:route(
#presence{from = UJID, to = JID1,
type = subscribed}),

View File

@ -240,12 +240,10 @@ process_item(RosterItem, Host) ->
%% existing roster groups.
[] ->
mod_roster:out_subscription(UserTo, ServerTo,
jid:make(UserFrom, ServerFrom,
<<"">>),
jid:make(UserFrom, ServerFrom),
unsubscribe),
mod_roster:in_subscription(false, UserFrom, ServerFrom,
jid:make(UserTo, ServerTo,
<<"">>),
jid:make(UserTo, ServerTo),
unsubscribe, <<"">>),
RosterItem#roster{subscription = both, ask = none};
%% If so, it means the user wants to add that contact
@ -269,8 +267,8 @@ set_new_rosteritems(UserFrom, ServerFrom, UserTo,
RIFrom = build_roster_record(UserFrom, ServerFrom,
UserTo, ServerTo, NameTo, GroupsFrom),
set_item(UserFrom, ServerFrom, ResourceTo, RIFrom),
JIDTo = jid:make(UserTo, ServerTo, <<"">>),
JIDFrom = jid:make(UserFrom, ServerFrom, <<"">>),
JIDTo = jid:make(UserTo, ServerTo),
JIDFrom = jid:make(UserFrom, ServerFrom),
RITo = build_roster_record(UserTo, ServerTo, UserFrom,
ServerFrom, UserFrom, []),
set_item(UserTo, ServerTo, <<"">>, RITo),
@ -360,7 +358,7 @@ in_subscription(Acc, User, Server, JID, Type,
out_subscription(UserFrom, ServerFrom, JIDTo,
unsubscribed) ->
#jid{luser = UserTo, lserver = ServerTo} = JIDTo,
JIDFrom = jid:make(UserFrom, ServerFrom, <<"">>),
JIDFrom = jid:make(UserFrom, ServerFrom),
mod_roster:out_subscription(UserTo, ServerTo, JIDFrom,
unsubscribe),
mod_roster:in_subscription(false, UserFrom, ServerFrom,
@ -1054,7 +1052,7 @@ split_grouphost(Host, Group) ->
end.
broadcast_subscription(User, Server, ContactJid, Subscription) ->
ejabberd_sm:route(jid:make(User, Server, <<"">>),
ejabberd_sm:route(jid:make(User, Server),
{item, ContactJid, Subscription}).
displayed_groups_update(Members, DisplayedGroups, Subscription) ->

View File

@ -182,9 +182,7 @@ export(_Server) ->
{sr_user,
fun(Host, #sr_user{us = {U, S}, group_host = {Group, LServer}})
when LServer == Host ->
SJID = jid:to_string(
jid:tolower(
jid:make(U, S, <<"">>))),
SJID = make_jid_s(U, S),
[?SQL("select @(jid)s from sr_user where jid=%(SJID)s"
" and grp=%(Group)s;"),
?SQL("insert into sr_user(jid, grp) values ("
@ -200,6 +198,6 @@ import(_, _, _) ->
%%% Internal functions
%%%===================================================================
make_jid_s(U, S) ->
jid:to_string(jid:tolower(jid:make(U, S, <<"">>))).
jid:to_string(jid:tolower(jid:make(U, S))).
make_jid_s({U, S}) -> make_jid_s(U, S).