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

* Use exmpp_jid:to_binary/1 when possible.

* ejabberd_odbc:escape/1 now can escape binaries too. This 
avoid the need to convert a binary value to list() just to 
sql-escape it. The escaped value returned is allways a list() 
(ejabberd's odbc drivers only works on lists())

SVN Revision: 1914
This commit is contained in:
Pablo Polvorin 2009-02-23 19:45:55 +00:00
parent 7a17baccac
commit acae6e20de
6 changed files with 67 additions and 56 deletions

View File

@ -1,3 +1,13 @@
2009-02-23 Pablo Polvorin <pablo.polvorin@process-one.net>
* src/ejabberd_c2s.erl, src/mod_echo.erl, src/mod_roster.erl,
src/mod_roster_odbc.erl: Use exmpp_jid:to_binary/1 when possible.
* src/mod_roster_odbc.erl, src/odbc/ejabberd_odbc.erl:
ejabberd_odbc:escape/1 now can escape binaries too. This
avoid the need to convert a binary value to list() just to
sql-escape it. The escaped value returned is allways a list()
(ejabberd's odbc drivers only works on lists())
2009-02-23 Christophe Romain <christophe.romain@process-one.net> 2009-02-23 Christophe Romain <christophe.romain@process-one.net>
* src/ejabberd_c2s.erl: Do not call mod_caps:clear_caps, this previous * src/ejabberd_c2s.erl: Do not call mod_caps:clear_caps, this previous

View File

@ -409,7 +409,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
?INFO_MSG( ?INFO_MSG(
"(~w) Accepted legacy authentication for ~s", "(~w) Accepted legacy authentication for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(JID)]), exmpp_jid:jid_to_binary(JID)]),
SID = {now(), self()}, SID = {now(), self()},
Conn = get_conn_type(StateData), Conn = get_conn_type(StateData),
Info = [{ip, StateData#state.ip}, {conn, Conn}, Info = [{ip, StateData#state.ip}, {conn, Conn},
@ -448,7 +448,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
?INFO_MSG( ?INFO_MSG(
"(~w) Failed legacy authentication for ~s", "(~w) Failed legacy authentication for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(JID)]), exmpp_jid:jid_to_binary(JID)]),
Res = exmpp_iq:error_without_original(El, Res = exmpp_iq:error_without_original(El,
'not-authorized'), 'not-authorized'),
send_element(StateData, Res), send_element(StateData, Res),
@ -458,7 +458,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
?INFO_MSG( ?INFO_MSG(
"(~w) Forbidden legacy authentication for ~s", "(~w) Forbidden legacy authentication for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(JID)]), exmpp_jid:jid_to_binary(JID)]),
Res = exmpp_iq:error_without_original(El, Res = exmpp_iq:error_without_original(El,
'not-allowed'), 'not-allowed'),
send_element(StateData, Res), send_element(StateData, Res),
@ -725,7 +725,7 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
allow -> allow ->
?INFO_MSG("(~w) Opened session for ~s", ?INFO_MSG("(~w) Opened session for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(JID)]), exmpp_jid:jid_to_binary(JID)]),
SID = {now(), self()}, SID = {now(), self()},
Conn = get_conn_type(StateData), Conn = get_conn_type(StateData),
Info = [{ip, StateData#state.ip}, {conn, Conn}, Info = [{ip, StateData#state.ip}, {conn, Conn},
@ -762,7 +762,7 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
StateData#state.server, [JID]), StateData#state.server, [JID]),
?INFO_MSG("(~w) Forbidden session for ~s", ?INFO_MSG("(~w) Forbidden session for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(JID)]), exmpp_jid:jid_to_binary(JID)]),
Err = exmpp_server_session:error(El, 'not-allowed'), Err = exmpp_server_session:error(El, 'not-allowed'),
send_element(StateData, Err), send_element(StateData, Err),
fsm_next_state(wait_for_session, StateData) fsm_next_state(wait_for_session, StateData)
@ -1222,7 +1222,7 @@ terminate(_Reason, StateName, StateData) ->
replaced -> replaced ->
?INFO_MSG("(~w) Replaced session for ~s", ?INFO_MSG("(~w) Replaced session for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(StateData#state.jid)]), exmpp_jid:jid_to_binary(StateData#state.jid)]),
From = StateData#state.jid, From = StateData#state.jid,
Packet = exmpp_presence:unavailable(), Packet = exmpp_presence:unavailable(),
Packet1 = exmpp_presence:set_status(Packet, Packet1 = exmpp_presence:set_status(Packet,
@ -1238,7 +1238,7 @@ terminate(_Reason, StateName, StateData) ->
_ -> _ ->
?INFO_MSG("(~w) Close session for ~s", ?INFO_MSG("(~w) Close session for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(StateData#state.jid)]), exmpp_jid:jid_to_binary(StateData#state.jid)]),
EmptySet = ?SETS:new(), EmptySet = ?SETS:new(),
case StateData of case StateData of

View File

@ -199,5 +199,5 @@ do_client_version(enabled, From, To) ->
%% Print in log %% Print in log
Values_string1 = [io_lib:format("~n~s: ~p", [N, V]) || {N, V} <- Values], Values_string1 = [io_lib:format("~n~s: ~p", [N, V]) || {N, V} <- Values],
Values_string2 = lists:concat(Values_string1), Values_string2 = lists:concat(Values_string1),
?INFO_MSG("Information of the client: ~s~s", [exmpp_jid:jid_to_list(To), Values_string2]). ?INFO_MSG("Information of the client: ~s~s", [exmpp_jid:jid_to_binary(To), Values_string2]).

View File

@ -200,7 +200,7 @@ get_user_roster(Acc, {U, S} = US) when is_binary(U), is_binary(S) ->
item_to_xml(Item) -> item_to_xml(Item) ->
{U, S, R} = Item#roster.jid, {U, S, R} = Item#roster.jid,
Attrs1 = exmpp_xml:set_attribute_in_list([], Attrs1 = exmpp_xml:set_attribute_in_list([],
'jid', exmpp_jid:jid_to_list(U, S, R)), 'jid', exmpp_jid:jid_to_binary(U, S, R)),
Attrs2 = case Item#roster.name of Attrs2 = case Item#roster.name of
<<>> -> <<>> ->
Attrs1; Attrs1;
@ -212,10 +212,10 @@ item_to_xml(Item) ->
Attrs4 = case ask_to_pending(Item#roster.ask) of Attrs4 = case ask_to_pending(Item#roster.ask) of
out -> out ->
exmpp_xml:set_attribute_in_list(Attrs3, exmpp_xml:set_attribute_in_list(Attrs3,
'ask', "subscribe"); 'ask', <<"subscribe">>);
both -> both ->
exmpp_xml:set_attribute_in_list(Attrs3, exmpp_xml:set_attribute_in_list(Attrs3,
'ask', "subscribe"); 'ask', <<"subscribe">>);
_ -> _ ->
Attrs3 Attrs3
end, end,
@ -806,8 +806,8 @@ get_in_pending_subscriptions(Ls, User, Server)
{U0, S0, R0} = R#roster.jid, {U0, S0, R0} = R#roster.jid,
Pres1 = exmpp_presence:subscribe(), Pres1 = exmpp_presence:subscribe(),
Pres2 = exmpp_stanza:set_jids(Pres1, Pres2 = exmpp_stanza:set_jids(Pres1,
exmpp_jid:jid_to_list(U0, S0, R0), exmpp_jid:jid_to_binary(U0, S0, R0),
exmpp_jid:jid_to_list(JID)), exmpp_jid:jid_to_binary(JID)),
exmpp_presence:set_status(Pres2, Message) exmpp_presence:set_status(Pres2, Message)
end, end,
lists:filter( lists:filter(

View File

@ -139,7 +139,7 @@ get_user_roster(Acc, {LUser, LServer}) ->
end, Items) ++ Acc. end, Items) ++ Acc.
get_roster(LUser, LServer) when is_binary(LUser), is_binary(LServer)-> get_roster(LUser, LServer) when is_binary(LUser), is_binary(LServer)->
Username = ejabberd_odbc:escape(binary_to_list(LUser)), Username = ejabberd_odbc:escape(LUser),
DomainString = binary_to_list(LServer), DomainString = binary_to_list(LServer),
case catch odbc_queries:get_roster(DomainString, Username) of case catch odbc_queries:get_roster(DomainString, Username) of
{selected, ["username", "jid", "nick", "subscription", "ask", {selected, ["username", "jid", "nick", "subscription", "ask",
@ -148,7 +148,7 @@ get_roster(LUser, LServer) when is_binary(LUser), is_binary(LServer)->
JIDGroups = case catch odbc_queries:get_roster_jid_groups(DomainString, Username) of JIDGroups = case catch odbc_queries:get_roster_jid_groups(DomainString, Username) of
{selected, ["jid","grp"], JGrps} {selected, ["jid","grp"], JGrps}
when is_list(JGrps) -> when is_list(JGrps) ->
JGrps; [{list_to_binary(S), list_to_binary(G)} || {S, G} <- JGrps];
_ -> _ ->
[] []
end, end,
@ -160,7 +160,7 @@ get_roster(LUser, LServer) when is_binary(LUser), is_binary(LServer)->
[]; [];
R -> R ->
{U2, S2, R2} = R#roster.jid, {U2, S2, R2} = R#roster.jid,
SJID = exmpp_jid:jid_to_list(U2, S2, R2), SJID = exmpp_jid:jid_to_binary(U2, S2, R2),
Groups = lists:flatmap( Groups = lists:flatmap(
fun({S, G}) when S == SJID -> fun({S, G}) when S == SJID ->
[G]; [G];
@ -179,7 +179,7 @@ get_roster(LUser, LServer) when is_binary(LUser), is_binary(LServer)->
item_to_xml(Item) -> item_to_xml(Item) ->
{U, S, R} = Item#roster.jid, {U, S, R} = Item#roster.jid,
Attrs1 = exmpp_xml:set_attribute_in_list([], Attrs1 = exmpp_xml:set_attribute_in_list([],
'jid', exmpp_jid:jid_to_list(U, S, R)), 'jid', exmpp_jid:jid_to_binary(U, S, R)),
Attrs2 = case Item#roster.name of Attrs2 = case Item#roster.name of
<<>> -> <<>> ->
Attrs1; Attrs1;
@ -191,10 +191,10 @@ item_to_xml(Item) ->
Attrs = case ask_to_pending(Item#roster.ask) of Attrs = case ask_to_pending(Item#roster.ask) of
out -> out ->
exmpp_xml:set_attribute_in_list(Attrs3, exmpp_xml:set_attribute_in_list(Attrs3,
'ask', "subscribe"); 'ask', <<"subscribe">>);
both -> both ->
exmpp_xml:set_attribute_in_list(Attrs3, exmpp_xml:set_attribute_in_list(Attrs3,
'ask', "subscribe"); 'ask', <<"subscribe">>);
_ -> _ ->
Attrs3 Attrs3
end, end,
@ -217,11 +217,12 @@ process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) ->
process_item_set(From, To, #xmlel{} = El) -> process_item_set(From, To, #xmlel{} = El) ->
try try
JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
LUser = exmpp_jid:lnode_as_list(From), User = exmpp_jid:lnode(From),
LServer = exmpp_jid:ldomain_as_list(From), Server = exmpp_jid:ldomain(From),
LServer = binary_to_list(Server),
{U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1), {U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(User),
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U0, S0, R0)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_binary(U0, S0, R0)),
F = fun() -> F = fun() ->
{selected, {selected,
["username", "jid", "nick", "subscription", ["username", "jid", "nick", "subscription",
@ -229,21 +230,21 @@ process_item_set(From, To, #xmlel{} = El) ->
Res} = odbc_queries:get_roster_by_jid(LServer, Username, SJID), Res} = odbc_queries:get_roster_by_jid(LServer, Username, SJID),
Item = case Res of Item = case Res of
[] -> [] ->
#roster{usj = {LUser, LServer, LJID}, #roster{usj = {User, Server, LJID},
us = {LUser, LServer}, us = {User, Server},
jid = LJID}; jid = LJID};
[I] -> [I] ->
R = raw_to_record(exmpp_jid:ldomain(From), I), R = raw_to_record(exmpp_jid:ldomain(From), I),
case R of case R of
%% Bad JID in database: %% Bad JID in database:
error -> error ->
#roster{usj = {LUser, LServer, LJID}, #roster{usj = {User, Server, LJID},
us = {LUser, LServer}, us = {User, Server},
jid = LJID}; jid = LJID};
_ -> _ ->
R#roster{ R#roster{
usj = {LUser, LServer, LJID}, usj = {User, Server, LJID},
us = {LUser, LServer}, us = {User, Server},
jid = LJID, jid = LJID,
name = <<>>} name = <<>>}
end end
@ -369,9 +370,8 @@ push_item(User, Server, Resource, From, Item) ->
get_subscription_lists(_, User, Server) get_subscription_lists(_, User, Server)
when is_binary(User), is_binary(Server) -> when is_binary(User), is_binary(Server) ->
try try
LUser = binary_to_list(User),
LServer = binary_to_list(Server), LServer = binary_to_list(Server),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(User),
case catch odbc_queries:get_roster(LServer, Username) of case catch odbc_queries:get_roster(LServer, Username) of
{selected, ["username", "jid", "nick", "subscription", "ask", {selected, ["username", "jid", "nick", "subscription", "ask",
"askmessage", "server", "subscribe", "type"], "askmessage", "server", "subscribe", "type"],
@ -422,11 +422,10 @@ out_subscription(User, Server, JID, Type) ->
process_subscription(Direction, User, Server, JID1, Type, Reason) process_subscription(Direction, User, Server, JID1, Type, Reason)
when is_binary(User), is_binary(Server) -> when is_binary(User), is_binary(Server) ->
try try
LUser = binary_to_list(User),
LServer = binary_to_list(Server), LServer = binary_to_list(Server),
{N0,D0,R0} = LJID = jlib:short_prepd_jid(JID1), {N0,D0,R0} = LJID = jlib:short_prepd_jid(JID1),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(User),
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(N0,D0,R0)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_binary(N0,D0,R0)),
F = fun() -> F = fun() ->
Item = Item =
case odbc_queries:get_roster_by_jid(LServer, Username, SJID) of case odbc_queries:get_roster_by_jid(LServer, Username, SJID) of
@ -440,7 +439,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason)
Groups = Groups =
case odbc_queries:get_roster_groups(LServer, Username, SJID) of case odbc_queries:get_roster_groups(LServer, Username, SJID) of
{selected, ["grp"], JGrps} when is_list(JGrps) -> {selected, ["grp"], JGrps} when is_list(JGrps) ->
[JGrp || {JGrp} <- JGrps]; [list_to_binary(JGrp) || {JGrp} <- JGrps];
_ -> _ ->
[] []
end, end,
@ -449,8 +448,8 @@ process_subscription(Direction, User, Server, JID1, Type, Reason)
["username", "jid", "nick", "subscription", "ask", ["username", "jid", "nick", "subscription", "ask",
"askmessage", "server", "subscribe", "type"], "askmessage", "server", "subscribe", "type"],
[]} -> []} ->
#roster{usj = {list_to_binary(LUser), list_to_binary(LServer), LJID}, #roster{usj = {User, Server, LJID},
us = {list_to_binary(LUser), list_to_binary(LServer)}, us = {User, Server},
jid = LJID} jid = LJID}
end, end,
NewState = case Direction of NewState = case Direction of
@ -627,7 +626,7 @@ in_auto_reply(_, _, _) -> none.
remove_user(User, Server) when is_binary(User), is_binary(Server) -> remove_user(User, Server) when is_binary(User), is_binary(Server) ->
try try
LUser = binary_to_list(exmpp_stringprep:nodeprep(User)), LUser = exmpp_stringprep:nodeprep(User),
LServer = binary_to_list(exmpp_stringprep:nameprep(Server)), LServer = binary_to_list(exmpp_stringprep:nameprep(Server)),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
odbc_queries:del_user_roster_t(LServer, Username), odbc_queries:del_user_roster_t(LServer, Username),
@ -639,7 +638,7 @@ remove_user(User, Server) when is_binary(User), is_binary(Server) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set_items(User, Server, #xmlel{children = Els}) -> set_items(User, Server, #xmlel{children = Els}) when is_binary(User), is_binary(Server) ->
LUser = exmpp_stringprep:nodeprep(User), LUser = exmpp_stringprep:nodeprep(User),
LServer = exmpp_stringprep:nameprep(Server), LServer = exmpp_stringprep:nameprep(Server),
catch odbc_queries:sql_transaction( catch odbc_queries:sql_transaction(
@ -653,7 +652,7 @@ process_item_set_t(LUser, LServer, #xmlel{} = El) ->
JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
{U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1), {U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U0, S0, R0)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_binary(U0, S0, R0)),
Item = #roster{usj = {LUser, LServer, LJID}, Item = #roster{usj = {LUser, LServer, LJID},
us = {LUser, LServer}, us = {LUser, LServer},
jid = LJID}, jid = LJID},
@ -709,7 +708,7 @@ process_item_attrs_ws(Item, []) ->
get_in_pending_subscriptions(Ls, User, Server) get_in_pending_subscriptions(Ls, User, Server)
when is_binary(User), is_binary(Server) -> when is_binary(User), is_binary(Server) ->
JID = exmpp_jid:make_jid(User, Server), JID = exmpp_jid:make_jid(User, Server),
LUser = exmpp_jid:lnode_as_list(JID), LUser = exmpp_jid:lnode(JID),
LServer = exmpp_jid:ldomain_as_list(JID), LServer = exmpp_jid:ldomain_as_list(JID),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
case catch odbc_queries:get_roster(LServer, Username) of case catch odbc_queries:get_roster(LServer, Username) of
@ -722,8 +721,8 @@ get_in_pending_subscriptions(Ls, User, Server)
{U0, S0, R0} = R#roster.jid, {U0, S0, R0} = R#roster.jid,
Pres1 = exmpp_presence:subscribe(), Pres1 = exmpp_presence:subscribe(),
Pres2 = exmpp_stanza:set_jids(Pres1, Pres2 = exmpp_stanza:set_jids(Pres1,
exmpp_jid:jid_to_list(U0, S0, R0), exmpp_jid:jid_to_binary(U0, S0, R0),
exmpp_jid:jid_to_list(JID)), exmpp_jid:jid_to_binary(JID)),
exmpp_presence:set_status(Pres2, Message) exmpp_presence:set_status(Pres2, Message)
end, end,
lists:flatmap( lists:flatmap(
@ -751,11 +750,10 @@ get_in_pending_subscriptions(Ls, User, Server)
%% and short_prepd_bare_jid %% and short_prepd_bare_jid
get_jid_info(_, User, Server, JID) when is_binary(User), is_binary(Server) -> get_jid_info(_, User, Server, JID) when is_binary(User), is_binary(Server) ->
try try
LUser = binary_to_list(User),
LServer = binary_to_list(Server), LServer = binary_to_list(Server),
LJID = {N, D, R} = jlib:short_prepd_jid(JID), LJID = {N, D, R} = jlib:short_prepd_jid(JID),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(User),
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(N, D, R)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_binary(N, D, R)),
case catch odbc_queries:get_subscription(LServer, Username, SJID) of case catch odbc_queries:get_subscription(LServer, Username, SJID) of
{selected, ["subscription"], [{SSubscription}]} -> {selected, ["subscription"], [{SSubscription}]} ->
Subscription = case SSubscription of Subscription = case SSubscription of
@ -766,7 +764,7 @@ get_jid_info(_, User, Server, JID) when is_binary(User), is_binary(Server) ->
end, end,
Groups = case catch odbc_queries:get_rostergroup_by_jid(LServer, Username, SJID) of Groups = case catch odbc_queries:get_rostergroup_by_jid(LServer, Username, SJID) of
{selected, ["grp"], JGrps} when is_list(JGrps) -> {selected, ["grp"], JGrps} when is_list(JGrps) ->
[JGrp || {JGrp} <- JGrps]; [list_to_binary(JGrp) || {JGrp} <- JGrps];
_ -> _ ->
[] []
end, end,
@ -778,7 +776,7 @@ get_jid_info(_, User, Server, JID) when is_binary(User), is_binary(Server) ->
{none, []}; {none, []};
true -> true ->
{LR_N, LR_D, LR_R} = LRJID, {LR_N, LR_D, LR_R} = LRJID,
SRJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(LR_N, LR_D, LR_R)), SRJID = ejabberd_odbc:escape(exmpp_jid:jid_to_binary(LR_N, LR_D, LR_R)),
case catch odbc_queries:get_subscription(LServer, Username, SRJID) of case catch odbc_queries:get_subscription(LServer, Username, SRJID) of
{selected, ["subscription"], [{SSubscription}]} -> {selected, ["subscription"], [{SSubscription}]} ->
Subscription = case SSubscription of Subscription = case SSubscription of
@ -789,7 +787,7 @@ get_jid_info(_, User, Server, JID) when is_binary(User), is_binary(Server) ->
end, end,
Groups = case catch odbc_queries:get_rostergroup_by_jid(LServer, Username, SRJID) of Groups = case catch odbc_queries:get_rostergroup_by_jid(LServer, Username, SRJID) of
{selected, ["grp"], JGrps} when is_list(JGrps) -> {selected, ["grp"], JGrps} when is_list(JGrps) ->
[JGrp || {JGrp} <- JGrps]; [list_to_binary(JGrp) || {JGrp} <- JGrps];
_ -> _ ->
[] []
end, end,
@ -844,10 +842,10 @@ record_to_string(#roster{us = {User, _Server},
subscription = Subscription, subscription = Subscription,
ask = Ask, ask = Ask,
askmessage = AskMessage}) -> askmessage = AskMessage}) ->
Username = ejabberd_odbc:escape(binary_to_list(User)), Username = ejabberd_odbc:escape(User),
{U, S, R} = JID, {U, S, R} = JID,
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_binary(U, S, R)),
Nick = ejabberd_odbc:escape(binary_to_list(Name)), Nick = ejabberd_odbc:escape(Name),
SSubscription = case Subscription of SSubscription = case Subscription of
both -> "B"; both -> "B";
to -> "T"; to -> "T";
@ -862,7 +860,7 @@ record_to_string(#roster{us = {User, _Server},
in -> "I"; in -> "I";
none -> "N" none -> "N"
end, end,
SAskMessage = ejabberd_odbc:escape(binary_to_list(AskMessage)), SAskMessage = ejabberd_odbc:escape(AskMessage),
[Username, SJID, Nick, SSubscription, SAsk, SAskMessage, "N", "", "item"]. [Username, SJID, Nick, SSubscription, SAsk, SAskMessage, "N", "", "item"].
groups_to_string(#roster{us = {User, _Server}, groups_to_string(#roster{us = {User, _Server},
@ -870,14 +868,14 @@ groups_to_string(#roster{us = {User, _Server},
groups = Groups}) -> groups = Groups}) ->
Username = ejabberd_odbc:escape(User), Username = ejabberd_odbc:escape(User),
{U, S, R} = JID, {U, S, R} = JID,
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_binary(U, S, R)),
%% Empty groups do not need to be converted to string to be inserted in %% Empty groups do not need to be converted to string to be inserted in
%% the database %% the database
lists:foldl( lists:foldl(
fun([], Acc) -> Acc; fun([], Acc) -> Acc;
(Group, Acc) -> (Group, Acc) ->
G = ejabberd_odbc:escape(binary_to_list(Group)), G = ejabberd_odbc:escape(Group),
[[Username, SJID, G]|Acc] end, [], Groups). [[Username, SJID, G]|Acc] end, [], Groups).
webadmin_page(_, Host, webadmin_page(_, Host,

View File

@ -110,7 +110,10 @@ sql_query_t(Query) ->
%% Escape character that will confuse an SQL engine %% Escape character that will confuse an SQL engine
escape(S) when is_list(S) -> escape(S) when is_list(S) ->
[odbc_queries:escape(C) || C <- S]. [odbc_queries:escape(C) || C <- S];
escape(S) when is_binary(S) ->
[odbc_queries:escape(C) || <<C>> <= S].
%% Escape character that will confuse an SQL engine %% Escape character that will confuse an SQL engine
%% Percent and underscore only need to be escaped for pattern matching like %% Percent and underscore only need to be escaped for pattern matching like