diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-02-26 10:07:12 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-02-26 10:07:12 +0300 |
commit | c1439ddd5bff82292919774c224a2bf3c8f63258 (patch) | |
tree | cc80ebe280ac56fcdfa9656f8f03a1938f53bdeb /src/mod_muc_admin.erl | |
parent | Don't pass empty resource to jid:make() (diff) |
Get rid of jid:to_string/1 and jid:from_string/1
Diffstat (limited to 'src/mod_muc_admin.erl')
-rw-r--r-- | src/mod_muc_admin.erl | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 714e3dd3..4b1509fc 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -717,7 +717,7 @@ get_room_occupants(Pid) -> S = get_room_state(Pid), lists:map( fun({_LJID, Info}) -> - {jid:to_string(Info#user.jid), + {jid:encode(Info#user.jid), Info#user.nick, atom_to_list(Info#user.role)} end, @@ -744,11 +744,11 @@ get_users_to_invite(RoomJid, UsersString) -> UsersStrings = binary:split(UsersString, <<":">>, [global]), OccupantsTuples = get_room_occupants(RoomJid#jid.luser, RoomJid#jid.lserver), - OccupantsJids = [jid:from_string(JidString) + OccupantsJids = [jid:decode(JidString) || {JidString, _Nick, _} <- OccupantsTuples], lists:filtermap( fun(UserString) -> - UserJid = jid:from_string(UserString), + UserJid = jid:decode(UserString), Val = lists:all(fun(OccupantJid) -> UserJid#jid.luser /= OccupantJid#jid.luser orelse UserJid#jid.lserver /= OccupantJid#jid.lserver @@ -918,7 +918,7 @@ set_room_affiliation(Name, Service, JID, AffiliationString) -> case mod_muc:find_online_room(Name, Service) of {ok, Pid} -> %% Get the PID for the online room so we can get the state of the room - {ok, StateData} = gen_fsm:sync_send_all_state_event(Pid, {process_item_change, {jid:from_string(JID), affiliation, Affiliation, <<"">>}, <<"">>}), + {ok, StateData} = gen_fsm:sync_send_all_state_event(Pid, {process_item_change, {jid:decode(JID), affiliation, Affiliation, <<"">>}, <<"">>}), mod_muc:store_room(StateData#state.server_host, StateData#state.host, StateData#state.room, make_opts(StateData)), ok; error -> @@ -933,11 +933,9 @@ subscribe_room(_User, Nick, _Room, _Nodes) when Nick == <<"">> -> throw({error, "Nickname must be set"}); subscribe_room(User, Nick, Room, Nodes) -> NodeList = re:split(Nodes, "\\h*,\\h*"), - case jid:from_string(Room) of + try jid:decode(Room) of #jid{luser = Name, lserver = Host} when Name /= <<"">> -> - case jid:from_string(User) of - error -> - throw({error, "Malformed user JID"}); + try jid:decode(User) of #jid{lresource = <<"">>} -> throw({error, "User's JID should have a resource"}); UserJID -> @@ -954,17 +952,19 @@ subscribe_room(User, Nick, Room, Nodes) -> _ -> throw({error, "The room does not exist"}) end + catch _:{bad_jid, _} -> + throw({error, "Malformed user JID"}) end; _ -> throw({error, "Malformed room JID"}) + catch _:{bad_jid, _} -> + throw({error, "Malformed room JID"}) end. unsubscribe_room(User, Room) -> - case jid:from_string(Room) of + try jid:decode(Room) of #jid{luser = Name, lserver = Host} when Name /= <<"">> -> - case jid:from_string(User) of - error -> - throw({error, "Malformed user JID"}); + try jid:decode(User) of UserJID -> case get_room_pid(Name, Host) of Pid when is_pid(Pid) -> @@ -979,16 +979,20 @@ unsubscribe_room(User, Room) -> _ -> throw({error, "The room does not exist"}) end + catch _:{bad_jid, _} -> + throw({error, "Malformed user JID"}) end; _ -> throw({error, "Malformed room JID"}) + catch _:{bad_jid, _} -> + throw({error, "Malformed room JID"}) end. get_subscribers(Name, Host) -> case get_room_pid(Name, Host) of Pid when is_pid(Pid) -> {ok, JIDList} = gen_fsm:sync_send_all_state_event(Pid, get_subscribers), - [jid:to_string(jid:remove_resource(J)) || J <- JIDList]; + [jid:encode(jid:remove_resource(J)) || J <- JIDList]; _ -> throw({error, "The room does not exist"}) end. |