25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Remove remanants of pre-binary strings

This commit is contained in:
Paweł Chmielowski 2016-02-09 15:49:47 +01:00
parent 583476380a
commit 2bca8d5121

View File

@ -280,7 +280,7 @@ get_sort_query(Q) ->
get_sort_query2(Q) -> get_sort_query2(Q) ->
{value, {_, String}} = lists:keysearch(<<"sort">>, 1, Q), {value, {_, String}} = lists:keysearch(<<"sort">>, 1, Q),
Integer = list_to_integer(binary_to_list(String)), Integer = jlib:binary_to_integer(String),
case Integer >= 0 of case Integer >= 0 of
true -> {ok, {normal, Integer}}; true -> {ok, {normal, Integer}};
false -> {ok, {reverse, abs(Integer)}} false -> {ok, {reverse, abs(Integer)}}
@ -472,7 +472,7 @@ destroy_room({N, H, SH}) ->
%% The file encoding must be UTF-8 %% The file encoding must be UTF-8
destroy_rooms_file(Filename) -> destroy_rooms_file(Filename) ->
{ok, F} = file:open(Filename, [read]), {ok, F} = file:open(Filename, [read, binary]),
RJID = read_room(F), RJID = read_room(F),
Rooms = read_rooms(F, RJID, []), Rooms = read_rooms(F, RJID, []),
file:close(F), file:close(F),
@ -500,23 +500,16 @@ read_room(F) ->
%% This function is quite rudimentary %% This function is quite rudimentary
%% and may not be accurate %% and may not be accurate
split_roomjid(RoomJID) -> split_roomjid(RoomJID) ->
[Name, Host] = string:tokens(RoomJID, "@"), [Name, Host] = binary:split(RoomJID, <<"@">>),
[_MUC_service_name | ServerHostList] = string:tokens(Host, "."), [_MUC_service_name, ServerHost] = binary:split(Host, <<".">>),
ServerHost = join(ServerHostList, "."), {Name, Host, ServerHost}.
{list_to_binary(Name), list_to_binary(Host), list_to_binary(ServerHost)}.
%% This function is copied from string:join/2 in Erlang/OTP R12B-1
%% Note that string:join/2 is not implemented in Erlang/OTP R11B
join([H|T], Sep) ->
H ++ lists:concat([Sep ++ X || X <- T]).
%%---------------------------- %%----------------------------
%% Create Rooms in File %% Create Rooms in File
%%---------------------------- %%----------------------------
create_rooms_file(Filename) -> create_rooms_file(Filename) ->
{ok, F} = file:open(Filename, [read]), {ok, F} = file:open(Filename, [read, binary]),
RJID = read_room(F), RJID = read_room(F),
Rooms = read_rooms(F, RJID, []), Rooms = read_rooms(F, RJID, []),
file:close(F), file:close(F),
@ -693,29 +686,32 @@ send_direct_invitation(RoomName, RoomService, Password, Reason, UsersString) ->
RoomJid = jid:make(RoomName, RoomService, <<"">>), RoomJid = jid:make(RoomName, RoomService, <<"">>),
RoomString = jid:to_string(RoomJid), RoomString = jid:to_string(RoomJid),
XmlEl = build_invitation(Password, Reason, RoomString), XmlEl = build_invitation(Password, Reason, RoomString),
UsersStrings = get_users_to_invite(RoomJid, binary_to_list(UsersString)), UsersStrings = get_users_to_invite(RoomJid, UsersString),
[send_direct_invitation(RoomJid, jid:from_string(list_to_binary(UserStrings)), XmlEl) [send_direct_invitation(RoomJid, UserStrings, XmlEl)
|| UserStrings <- UsersStrings], || UserStrings <- UsersStrings],
timer:sleep(1000), timer:sleep(1000),
ok. ok.
get_users_to_invite(RoomJid, UsersString) -> get_users_to_invite(RoomJid, UsersString) ->
UsersStrings = string:tokens(UsersString, ":"), UsersStrings = binary:split(UsersString, <<":">>, [global]),
OccupantsTuples = get_room_occupants(RoomJid#jid.luser, OccupantsTuples = get_room_occupants(RoomJid#jid.luser,
RoomJid#jid.lserver), RoomJid#jid.lserver),
OccupantsJids = [jid:from_string(JidString) OccupantsJids = [jid:from_string(JidString)
|| {JidString, _Nick, _} <- OccupantsTuples], || {JidString, _Nick, _} <- OccupantsTuples],
lists:filter( lists:filtermap(
fun(UserString) -> fun(UserString) ->
UserJid = jid:from_string(list_to_binary(UserString)), UserJid = jid:from_string(UserString),
%% [{"badlop@localhost/work","badlop","moderator"}] Val = lists:all(fun(OccupantJid) ->
lists:all(fun(OccupantJid) -> UserJid#jid.luser /= OccupantJid#jid.luser
UserJid#jid.luser /= OccupantJid#jid.luser orelse UserJid#jid.lserver /= OccupantJid#jid.lserver
orelse UserJid#jid.lserver /= OccupantJid#jid.lserver end,
end, OccupantsJids),
OccupantsJids) case Val of
end, true -> {true, UserJid};
UsersStrings). _ -> false
end
end,
UsersStrings).
build_invitation(Password, Reason, RoomString) -> build_invitation(Password, Reason, RoomString) ->
PasswordAttrList = case Password of PasswordAttrList = case Password of