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

Stronger tests in the test suite, SQL updates and fixes

This commit is contained in:
Alexey Shchepin 2016-05-24 18:44:07 +03:00
parent 5352037680
commit d201f013b2
11 changed files with 360 additions and 348 deletions

View File

@ -41,6 +41,7 @@
sql_bloc/2, sql_bloc/2,
sql_query_to_iolist/1, sql_query_to_iolist/1,
escape/1, escape/1,
standard_escape/1,
escape_like/1, escape_like/1,
escape_like_arg/1, escape_like_arg/1,
escape_like_arg_circumflex/1, escape_like_arg_circumflex/1,
@ -216,6 +217,8 @@ escape_like_arg_circumflex(S) when is_binary(S) ->
escape_like_arg_circumflex($%) -> <<"^%">>; escape_like_arg_circumflex($%) -> <<"^%">>;
escape_like_arg_circumflex($_) -> <<"^_">>; escape_like_arg_circumflex($_) -> <<"^_">>;
escape_like_arg_circumflex($^) -> <<"^^">>; escape_like_arg_circumflex($^) -> <<"^^">>;
escape_like_arg_circumflex($[) -> <<"^[">>; % For MSSQL
escape_like_arg_circumflex($]) -> <<"^]">>;
escape_like_arg_circumflex(C) when is_integer(C), C >= 0, C =< 255 -> <<C>>. escape_like_arg_circumflex(C) when is_integer(C), C >= 0, C =< 255 -> <<C>>.
to_bool(<<"t">>) -> true; to_bool(<<"t">>) -> true;

View File

@ -92,14 +92,16 @@ write_prefs(LUser, _LServer, #archive_prefs{default = Default,
never = Never, never = Never,
always = Always}, always = Always},
ServerHost) -> ServerHost) ->
SUser = ejabberd_sql:escape(LUser),
SDefault = erlang:atom_to_binary(Default, utf8), SDefault = erlang:atom_to_binary(Default, utf8),
SAlways = ejabberd_sql:encode_term(Always), SAlways = jlib:term_to_expr(Always),
SNever = ejabberd_sql:encode_term(Never), SNever = jlib:term_to_expr(Never),
case update(ServerHost, <<"archive_prefs">>, case ?SQL_UPSERT(
[<<"username">>, <<"def">>, <<"always">>, <<"never">>], ServerHost,
[SUser, SDefault, SAlways, SNever], "archive_prefs",
[<<"username='">>, SUser, <<"'">>]) of ["!username=%(LUser)s",
"def=%(SDefault)s",
"always=%(SAlways)s",
"never=%(SNever)s"]) of
{updated, _} -> {updated, _} ->
ok; ok;
Err -> Err ->
@ -109,10 +111,9 @@ write_prefs(LUser, _LServer, #archive_prefs{default = Default,
get_prefs(LUser, LServer) -> get_prefs(LUser, LServer) ->
case ejabberd_sql:sql_query( case ejabberd_sql:sql_query(
LServer, LServer,
[<<"select def, always, never from archive_prefs ">>, ?SQL("select @(def)s, @(always)s, @(never)s from archive_prefs"
<<"where username='">>, " where username=%(LUser)s")) of
ejabberd_sql:escape(LUser), <<"';">>]) of {selected, [{SDefault, SAlways, SNever}]} ->
{selected, _, [[SDefault, SAlways, SNever]]} ->
Default = erlang:binary_to_existing_atom(SDefault, utf8), Default = erlang:binary_to_existing_atom(SDefault, utf8),
Always = ejabberd_sql:decode_term(SAlways), Always = ejabberd_sql:decode_term(SAlways),
Never = ejabberd_sql:decode_term(SNever), Never = ejabberd_sql:decode_term(SNever),
@ -211,6 +212,12 @@ make_sql_query(User, LServer, Start, End, With, RSM) ->
ODBCType = ejabberd_config:get_option( ODBCType = ejabberd_config:get_option(
{sql_type, LServer}, {sql_type, LServer},
ejabberd_sql:opt_type(sql_type)), ejabberd_sql:opt_type(sql_type)),
Escape =
case ODBCType of
mssql -> fun ejabberd_sql:standard_escape/1;
sqlite -> fun ejabberd_sql:standard_escape/1;
_ -> fun ejabberd_sql:escape/1
end,
LimitClause = if is_integer(Max), Max >= 0, ODBCType /= mssql -> LimitClause = if is_integer(Max), Max >= 0, ODBCType /= mssql ->
[<<" limit ">>, jlib:integer_to_binary(Max+1)]; [<<" limit ">>, jlib:integer_to_binary(Max+1)];
true -> true ->
@ -226,14 +233,14 @@ make_sql_query(User, LServer, Start, End, With, RSM) ->
[]; [];
{text, Txt} -> {text, Txt} ->
[<<" and match (txt) against ('">>, [<<" and match (txt) against ('">>,
ejabberd_sql:escape(Txt), <<"')">>]; Escape(Txt), <<"')">>];
{_, _, <<>>} -> {_, _, <<>>} ->
[<<" and bare_peer='">>, [<<" and bare_peer='">>,
ejabberd_sql:escape(jid:to_string(With)), Escape(jid:to_string(With)),
<<"'">>]; <<"'">>];
{_, _, _} -> {_, _, _} ->
[<<" and peer='">>, [<<" and peer='">>,
ejabberd_sql:escape(jid:to_string(With)), Escape(jid:to_string(With)),
<<"'">>]; <<"'">>];
none -> none ->
[] []
@ -265,7 +272,7 @@ make_sql_query(User, LServer, Start, End, With, RSM) ->
_ -> _ ->
[] []
end, end,
SUser = ejabberd_sql:escape(User), SUser = Escape(User),
Query = [<<"SELECT ">>, TopClause, <<" timestamp, xml, peer, kind, nick" Query = [<<"SELECT ">>, TopClause, <<" timestamp, xml, peer, kind, nick"
" FROM archive WHERE username='">>, " FROM archive WHERE username='">>,

View File

@ -38,8 +38,7 @@ store_messages(Host, {User, _Server}, Msgs, Len, MaxOfflineMsgs) ->
true -> true ->
Query = lists:map( Query = lists:map(
fun(M) -> fun(M) ->
Username = LUser = (M#offline_msg.to)#jid.luser,
ejabberd_sql:escape((M#offline_msg.to)#jid.luser),
From = M#offline_msg.from, From = M#offline_msg.from,
To = M#offline_msg.to, To = M#offline_msg.to,
Packet = Packet =
@ -49,9 +48,8 @@ store_messages(Host, {User, _Server}, Msgs, Len, MaxOfflineMsgs) ->
jlib:add_delay_info(Packet, Host, jlib:add_delay_info(Packet, Host,
M#offline_msg.timestamp, M#offline_msg.timestamp,
<<"Offline Storage">>), <<"Offline Storage">>),
XML = XML = fxml:element_to_binary(NewPacket),
ejabberd_sql:escape(fxml:element_to_binary(NewPacket)), sql_queries:add_spool_sql(LUser, XML)
sql_queries:add_spool_sql(Username, XML)
end, end,
Msgs), Msgs),
sql_queries:add_spool(Host, Query) sql_queries:add_spool(Host, Query)
@ -95,19 +93,18 @@ remove_user(LUser, LServer) ->
sql_queries:del_spool_msg(LServer, LUser). sql_queries:del_spool_msg(LServer, LUser).
read_message_headers(LUser, LServer) -> read_message_headers(LUser, LServer) ->
Username = ejabberd_sql:escape(LUser),
case catch ejabberd_sql:sql_query( case catch ejabberd_sql:sql_query(
LServer, [<<"select xml, seq from spool where username ='">>, LServer,
Username, <<"' order by seq;">>]) of ?SQL("select @(xml)s, @(seq)d from spool"
{selected, [<<"xml">>, <<"seq">>], Rows} -> " where username=%(LUser)s order by seq")) of
{selected, Rows} ->
lists:flatmap( lists:flatmap(
fun([XML, Seq]) -> fun({XML, Seq}) ->
case xml_to_offline_msg(XML) of case xml_to_offline_msg(XML) of
{ok, #offline_msg{from = From, {ok, #offline_msg{from = From,
to = To, to = To,
packet = El}} -> packet = El}} ->
Seq0 = binary_to_integer(Seq), [{Seq, From, To, El}];
[{Seq0, From, To, El}];
_ -> _ ->
[] []
end end
@ -117,13 +114,11 @@ read_message_headers(LUser, LServer) ->
end. end.
read_message(LUser, LServer, Seq) -> read_message(LUser, LServer, Seq) ->
Username = ejabberd_sql:escape(LUser),
SSeq = ejabberd_sql:escape(integer_to_binary(Seq)),
case ejabberd_sql:sql_query( case ejabberd_sql:sql_query(
LServer, LServer,
[<<"select xml from spool where username='">>, Username, ?SQL("select @(xml)s from spool where username=%(LUser)s"
<<"' and seq='">>, SSeq, <<"';">>]) of " and seq=%(Seq)d")) of
{selected, [<<"xml">>], [[RawXML]|_]} -> {selected, [{RawXML}|_]} ->
case xml_to_offline_msg(RawXML) of case xml_to_offline_msg(RawXML) of
{ok, Msg} -> {ok, Msg} ->
{ok, Msg}; {ok, Msg};
@ -135,12 +130,10 @@ read_message(LUser, LServer, Seq) ->
end. end.
remove_message(LUser, LServer, Seq) -> remove_message(LUser, LServer, Seq) ->
Username = ejabberd_sql:escape(LUser),
SSeq = ejabberd_sql:escape(integer_to_binary(Seq)),
ejabberd_sql:sql_query( ejabberd_sql:sql_query(
LServer, LServer,
[<<"delete from spool where username='">>, Username, ?SQL("delete from spool where username=%(LUser)s"
<<"' and seq='">>, SSeq, <<"';">>]), " and seq=%(Seq)d")),
ok. ok.
read_all_messages(LUser, LServer) -> read_all_messages(LUser, LServer) ->
@ -180,14 +173,13 @@ export(_Server) ->
timestamp = TimeStamp, from = From, to = To, timestamp = TimeStamp, from = From, to = To,
packet = Packet}) packet = Packet})
when LServer == Host -> when LServer == Host ->
Username = ejabberd_sql:escape(LUser),
Packet1 = jlib:replace_from_to(From, To, Packet), Packet1 = jlib:replace_from_to(From, To, Packet),
Packet2 = jlib:add_delay_info(Packet1, LServer, TimeStamp, Packet2 = jlib:add_delay_info(Packet1, LServer, TimeStamp,
<<"Offline Storage">>), <<"Offline Storage">>),
XML = ejabberd_sql:escape(fxml:element_to_binary(Packet2)), XML = fxml:element_to_binary(Packet2),
[[<<"delete from spool where username='">>, Username, <<"';">>], [?SQL("delete from spool where username=%(LUser)s;"),
[<<"insert into spool(username, xml) values ('">>, ?SQL("insert into spool(username, xml) values ("
Username, <<"', '">>, XML, <<"');">>]]; "%(LUser)s, %(XML)s);")];
(_Host, _R) -> (_Host, _R) ->
[] []
end}]. end}].

View File

@ -33,8 +33,11 @@
-behaviour(gen_pubsub_node). -behaviour(gen_pubsub_node).
-author('christophe.romain@process-one.net'). -author('christophe.romain@process-one.net').
-compile([{parse_transform, ejabberd_sql_pt}]).
-include("pubsub.hrl"). -include("pubsub.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
-include("ejabberd_sql_pt.hrl").
-export([init/3, terminate/2, options/0, features/0, -export([init/3, terminate/2, options/0, features/0,
create_node_permission/6, create_node/2, delete_node/1, create_node_permission/6, create_node/2, delete_node/1,
@ -75,19 +78,25 @@ create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
create_node(Nidx, Owner) -> create_node(Nidx, Owner) ->
{_U, _S, _R} = OwnerKey = jid:tolower(jid:remove_resource(Owner)), {_U, _S, _R} = OwnerKey = jid:tolower(jid:remove_resource(Owner)),
State = #pubsub_state{stateid = {OwnerKey, Nidx}, affiliation = owner}, J = encode_jid(OwnerKey),
catch ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) " A = encode_affiliation(owner),
"values(">>, state_to_raw(Nidx, State), <<");">>]), S = encode_subscriptions([]),
catch ejabberd_sql:sql_query_t(
?SQL("insert into pubsub_state("
"nodeid, jid, affiliation, subscriptions) "
"values (%(Nidx)d, %(J)s, %(A)s, %(S)s)")),
{result, {default, broadcast}}. {result, {default, broadcast}}.
delete_node(Nodes) -> delete_node(Nodes) ->
Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) -> Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) ->
Subscriptions = case catch Subscriptions = case catch
ejabberd_sql:sql_query_t([<<"select jid, subscriptions " ejabberd_sql:sql_query_t(
"from pubsub_state where nodeid='">>, Nidx, <<"';">>]) ?SQL("select @(jid)s, @(subscriptions)s "
"from pubsub_state where nodeid=%(Nidx)d"))
of of
{selected, [<<"jid">>, <<"subscriptions">>], RItems} -> {selected, RItems} ->
[{decode_jid(SJID), decode_subscriptions(Subs)} || [SJID, Subs] <- RItems]; [{decode_jid(SJID), decode_subscriptions(Subs)} ||
{SJID, Subs} <- RItems];
_ -> _ ->
[] []
end, end,
@ -299,13 +308,14 @@ get_entity_affiliations(Host, Owner) ->
H = encode_host(Host), H = encode_host(Host),
J = encode_jid(GenKey), J = encode_jid(GenKey),
Reply = case catch Reply = case catch
ejabberd_sql:sql_query_t([<<"select node, type, i.nodeid, affiliation " ejabberd_sql:sql_query_t(
"from pubsub_state i, pubsub_node n where " ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(affiliation)s "
"i.nodeid = n.nodeid and jid='">>, J, <<"' and host='">>, H, <<"';">>]) "from pubsub_state i, pubsub_node n where "
"i.nodeid = n.nodeid and jid=%(J)s and host=%(H)s"))
of of
{selected, [<<"node">>, <<"type">>, <<"nodeid">>, <<"affiliation">>], RItems} -> {selected, RItems} ->
[{nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]), decode_affiliation(A)} [{nodetree_tree_sql:raw_to_node(Host, {N, <<"">>, T, I}), decode_affiliation(A)}
|| [N, T, I, A] <- RItems]; || {N, T, I, A} <- RItems];
_ -> _ ->
[] []
end, end,
@ -313,11 +323,12 @@ get_entity_affiliations(Host, Owner) ->
get_node_affiliations(Nidx) -> get_node_affiliations(Nidx) ->
Reply = case catch Reply = case catch
ejabberd_sql:sql_query_t([<<"select jid, affiliation from pubsub_state " ejabberd_sql:sql_query_t(
"where nodeid='">>, Nidx, <<"';">>]) ?SQL("select @(jid)s, @(affiliation)s from pubsub_state "
"where nodeid=%(Nidx)d"))
of of
{selected, [<<"jid">>, <<"affiliation">>], RItems} -> {selected, RItems} ->
[{decode_jid(J), decode_affiliation(A)} || [J, A] <- RItems]; [{decode_jid(J), decode_affiliation(A)} || {J, A} <- RItems];
_ -> _ ->
[] []
end, end,
@ -328,10 +339,11 @@ get_affiliation(Nidx, Owner) ->
GenKey = jid:remove_resource(SubKey), GenKey = jid:remove_resource(SubKey),
J = encode_jid(GenKey), J = encode_jid(GenKey),
Reply = case catch Reply = case catch
ejabberd_sql:sql_query_t([<<"select affiliation from pubsub_state " ejabberd_sql:sql_query_t(
"where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>]) ?SQL("select @(affiliation)s from pubsub_state "
"where nodeid=%(Nidx)d and jid=%(J)s"))
of of
{selected, [<<"affiliation">>], [[A]]} -> {selected, [{A}]} ->
decode_affiliation(A); decode_affiliation(A);
_ -> _ ->
none none
@ -353,23 +365,26 @@ get_entity_subscriptions(Host, Owner) ->
H = encode_host(Host), H = encode_host(Host),
SJ = encode_jid(SubKey), SJ = encode_jid(SubKey),
GJ = encode_jid(GenKey), GJ = encode_jid(GenKey),
GJLike = encode_jid_like(GenKey), GJLike = <<(encode_jid_like(GenKey))/binary, "%">>,
Query = case SubKey of Query =
GenKey -> case SubKey of
[<<"select node, type, i.nodeid, jid, subscriptions " GenKey ->
"from pubsub_state i, pubsub_node n " ?SQL("select @(node)s, @(type)s, @(i.nodeid)d,"
"where i.nodeid = n.nodeid and jid like '">>, GJLike, " @(jid)s, @(subscriptions)s "
<<"%' escape '^' and host='">>, H, <<"';">>]; "from pubsub_state i, pubsub_node n "
_ -> "where i.nodeid = n.nodeid and jid like %(GJLike)s"
[<<"select node, type, i.nodeid, jid, subscriptions " " escape '^' and host=%(H)s");
"from pubsub_state i, pubsub_node n " _ ->
"where i.nodeid = n.nodeid and jid in ('">>, SJ, <<"', '">>, GJ, <<"') and host='">>, H, <<"';">>] ?SQL("select @(node)s, @(type)s, @(i.nodeid)d,"
end, " @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid and jid in"
" (%(SJ)s, %(GJ)s) and host=%(H)s")
end,
Reply = case catch ejabberd_sql:sql_query_t(Query) of Reply = case catch ejabberd_sql:sql_query_t(Query) of
{selected, {selected, RItems} ->
[<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} -> lists:foldl(fun ({N, T, I, J, S}, Acc) ->
lists:foldl(fun ([N, T, I, J, S], Acc) -> Node = nodetree_tree_sql:raw_to_node(Host, {N, <<"">>, T, I}),
Node = nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]),
Jid = decode_jid(J), Jid = decode_jid(J),
case decode_subscriptions(S) of case decode_subscriptions(S) of
[] -> [] ->
@ -404,25 +419,28 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
H = encode_host(Host), H = encode_host(Host),
SJ = encode_jid(SubKey), SJ = encode_jid(SubKey),
GJ = encode_jid(GenKey), GJ = encode_jid(GenKey),
GJLike = encode_jid_like(GenKey), GJLike = <<(encode_jid_like(GenKey))/binary, "%">>,
Query = case SubKey of Query =
GenKey -> case SubKey of
[<<"select node, type, i.nodeid, jid, subscriptions " GenKey ->
"from pubsub_state i, pubsub_node n, pubsub_node_option o " ?SQL("select @(node)s, @(type)s, @(i.nodeid)d,"
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and name='send_last_published_item' " " @(jid)s, @(subscriptions)s "
"and val='on_sub_and_presence' and jid like '">>, GJLike, "from pubsub_state i, pubsub_node n, pubsub_node_option o "
<<"%' escape '^' and host='">>, H, <<"';">>]; "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and name='send_last_published_item' "
_ -> "and val='on_sub_and_presence' and jid like %(GJLike)s"
[<<"select node, type, i.nodeid, jid, subscriptions " " escape '^' and host=%(H)s");
"from pubsub_state i, pubsub_node n, pubsub_node_option o " _ ->
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and name='send_last_published_item' " ?SQL("select @(node)s, @(type)s, @(i.nodeid)d,"
"and val='on_sub_and_presence' and jid in ('">>, SJ, <<"', '">>, GJ, <<"') and host='">>, H, <<"';">>] " @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n, pubsub_node_option o "
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and name='send_last_published_item' "
"and val='on_sub_and_presence' and"
" jid in (%(SJ)s, %(GJ)s) and host=%(H)s")
end, end,
Reply = case catch ejabberd_sql:sql_query_t(Query) of Reply = case catch ejabberd_sql:sql_query_t(Query) of
{selected, {selected, RItems} ->
[<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} -> lists:foldl(fun ({N, T, I, J, S}, Acc) ->
lists:foldl(fun ([N, T, I, J, S], Acc) -> Node = nodetree_tree_sql:raw_to_node(Host, {N, <<"">>, T, I}),
Node = nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]),
Jid = decode_jid(J), Jid = decode_jid(J),
case decode_subscriptions(S) of case decode_subscriptions(S) of
[] -> [] ->
@ -442,11 +460,12 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
get_node_subscriptions(Nidx) -> get_node_subscriptions(Nidx) ->
Reply = case catch Reply = case catch
ejabberd_sql:sql_query_t([<<"select jid, subscriptions from pubsub_state " ejabberd_sql:sql_query_t(
"where nodeid='">>, Nidx, <<"';">>]) ?SQL("select @(jid)s, @(subscriptions)s from pubsub_state "
"where nodeid=%(Nidx)d"))
of of
{selected, [<<"jid">>, <<"subscriptions">>], RItems} -> {selected, RItems} ->
lists:foldl(fun ([J, S], Acc) -> lists:foldl(fun ({J, S}, Acc) ->
Jid = decode_jid(J), Jid = decode_jid(J),
case decode_subscriptions(S) of case decode_subscriptions(S) of
[] -> [] ->
@ -468,10 +487,11 @@ get_subscriptions(Nidx, Owner) ->
SubKey = jid:tolower(Owner), SubKey = jid:tolower(Owner),
J = encode_jid(SubKey), J = encode_jid(SubKey),
Reply = case catch Reply = case catch
ejabberd_sql:sql_query_t([<<"select subscriptions from pubsub_state where " ejabberd_sql:sql_query_t(
"nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>]) ?SQL("select @(subscriptions)s from pubsub_state"
" where nodeid=%(Nidx)d and jid=%(J)s"))
of of
{selected, [<<"subscriptions">>], [[S]]} -> {selected, [{S}]} ->
decode_subscriptions(S); decode_subscriptions(S);
_ -> _ ->
[] []
@ -568,13 +588,13 @@ get_nodes_helper(NodeTree, #pubsub_state{stateid = {_, N}, subscriptions = Subs}
get_states(Nidx) -> get_states(Nidx) ->
case catch case catch
ejabberd_sql:sql_query_t([<<"select jid, affiliation, subscriptions " ejabberd_sql:sql_query_t(
"from pubsub_state where nodeid='">>, Nidx, <<"';">>]) ?SQL("select @(jid)s, @(affiliation)s, @(subscriptions)s "
"from pubsub_state where nodeid=%(Nidx)d"))
of of
{selected, {selected, RItems} ->
[<<"jid">>, <<"affiliation">>, <<"subscriptions">>], RItems} ->
{result, {result,
lists:map(fun ([SJID, Aff, Subs]) -> lists:map(fun ({SJID, Aff, Subs}) ->
JID = decode_jid(SJID), JID = decode_jid(SJID),
#pubsub_state{stateid = {JID, Nidx}, #pubsub_state{stateid = {JID, Nidx},
items = itemids(Nidx, JID), items = itemids(Nidx, JID),
@ -599,11 +619,12 @@ get_state(Nidx, JID) ->
get_state_without_itemids(Nidx, JID) -> get_state_without_itemids(Nidx, JID) ->
J = encode_jid(JID), J = encode_jid(JID),
case catch case catch
ejabberd_sql:sql_query_t([<<"select jid, affiliation, subscriptions " ejabberd_sql:sql_query_t(
"from pubsub_state where jid='">>, J, <<"' and nodeid='">>, Nidx, <<"';">>]) ?SQL("select @(jid)s, @(affiliation)s, @(subscriptions)s "
"from pubsub_state "
"where nodeid=%(Nidx)d and jid=%(J)s"))
of of
{selected, {selected, [{SJID, Aff, Subs}]} ->
[<<"jid">>, <<"affiliation">>, <<"subscriptions">>], [[SJID, Aff, Subs]]} ->
#pubsub_state{stateid = {decode_jid(SJID), Nidx}, #pubsub_state{stateid = {decode_jid(SJID), Nidx},
affiliation = decode_affiliation(Aff), affiliation = decode_affiliation(Aff),
subscriptions = decode_subscriptions(Subs)}; subscriptions = decode_subscriptions(Subs)};
@ -620,24 +641,20 @@ set_state(Nidx, State) ->
J = encode_jid(JID), J = encode_jid(JID),
S = encode_subscriptions(State#pubsub_state.subscriptions), S = encode_subscriptions(State#pubsub_state.subscriptions),
A = encode_affiliation(State#pubsub_state.affiliation), A = encode_affiliation(State#pubsub_state.affiliation),
case catch ?SQL_UPSERT_T(
ejabberd_sql:sql_query_t([<<"update pubsub_state set subscriptions='">>, S, <<"', affiliation='">>, A, "pubsub_state",
<<"' where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>]) ["!nodeid=%(Nidx)d",
of "!jid=%(J)s",
{updated, 1} -> "affiliation=%(A)s",
ok; "subscriptions=%(S)s"
_ -> ]),
catch
ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
"values('">>,
Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '">>, S, <<"');">>])
end,
ok. ok.
del_state(Nidx, JID) -> del_state(Nidx, JID) ->
J = encode_jid(JID), J = encode_jid(JID),
catch ejabberd_sql:sql_query_t([<<"delete from pubsub_state where jid='">>, catch ejabberd_sql:sql_query_t(
J, <<"' and nodeid='">>, Nidx, <<"';">>]), ?SQL("delete from pubsub_state"
" where jid=%(J)s and nodeid=%(Nidx)d")),
ok. ok.
%get_items(Nidx, _From) -> %get_items(Nidx, _From) ->
@ -655,12 +672,12 @@ del_state(Nidx, JID) ->
get_items(Nidx, From, none) -> get_items(Nidx, From, none) ->
MaxItems = case catch MaxItems = case catch
ejabberd_sql:sql_query_t([<<"select val from pubsub_node_option " ejabberd_sql:sql_query_t(
"where nodeid='">>, Nidx, <<"' and name='max_items';">>]) ?SQL("select @(val)s from pubsub_node_option "
"where nodeid=%(Nidx)d and name='max_items'"))
of of
{selected, [<<"val">>], [[Value]]} -> {selected, [{Value}]} ->
Tokens = element(2, erl_scan:string(binary_to_list(<<Value/binary, ".">>))), jlib:expr_to_term(Value);
element(2, erl_parse:parse_term(Tokens));
_ -> _ ->
?MAXITEMS ?MAXITEMS
end, end,
@ -677,12 +694,13 @@ get_items(Nidx, _From,
_ -> _ ->
{<<"is not">>, <<"desc">>}% Can be better {<<"is not">>, <<"desc">>}% Can be better
end, end,
SNidx = integer_to_binary(Nidx),
[AttrName, Id] = case I of [AttrName, Id] = case I of
undefined when IncIndex =/= undefined -> undefined when IncIndex =/= undefined ->
case catch case catch
ejabberd_sql:sql_query_t([<<"select modification from pubsub_item pi " ejabberd_sql:sql_query_t([<<"select modification from pubsub_item pi "
"where exists ( select count(*) as count1 " "where exists ( select count(*) as count1 "
"from pubsub_item where nodeid='">>, Nidx, "from pubsub_item where nodeid='">>, SNidx,
<<"' and modification > pi.modification having count1 = ">>, <<"' and modification > pi.modification having count1 = ">>,
ejabberd_sql:escape(jlib:i2l(IncIndex)), <<" );">>]) ejabberd_sql:escape(jlib:i2l(IncIndex)), <<" );">>])
of of
@ -700,7 +718,7 @@ get_items(Nidx, _From,
[A, <<"'", B/binary, "'">>] [A, <<"'", B/binary, "'">>]
end, end,
Count = case catch Count = case catch
ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item where nodeid='">>, Nidx, <<"';">>]) ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item where nodeid='">>, SNidx, <<"';">>])
of of
{selected, [_], [[C]]} -> C; {selected, [_], [[C]]} -> C;
_ -> <<"0">> _ -> <<"0">>
@ -709,13 +727,13 @@ get_items(Nidx, _From,
ejabberd_sql:sql_query_t( ejabberd_sql:sql_query_t(
[<<"select top ">>, jlib:i2l(Max), [<<"select top ">>, jlib:i2l(Max),
<<" itemid, publisher, creation, modification, payload " <<" itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx, "from pubsub_item where nodeid='">>, SNidx,
<<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>, <<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>,
AttrName, <<" ">>, Order, <<";">>]); AttrName, <<" ">>, Order, <<";">>]);
(_, _) -> (_, _) ->
ejabberd_sql:sql_query_t( ejabberd_sql:sql_query_t(
[<<"select itemid, publisher, creation, modification, payload " [<<"select itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx, "from pubsub_item where nodeid='">>, SNidx,
<<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>, <<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>,
AttrName, <<" ">>, Order, <<" limit ">>, jlib:i2l(Max), <<" ;">>]) AttrName, <<" ">>, Order, <<" limit ">>, jlib:i2l(Max), <<" ;">>])
end, end,
@ -726,7 +744,7 @@ get_items(Nidx, _From,
[[_, _, _, F, _]|_] -> [[_, _, _, F, _]|_] ->
Index = case catch Index = case catch
ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item " ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item "
"where nodeid='">>, Nidx, <<"' and ">>, "where nodeid='">>, SNidx, <<"' and ">>,
AttrName, <<" > '">>, F, <<"';">>]) AttrName, <<" > '">>, F, <<"';">>])
of of
%{selected, [_], [{C}, {In}]} -> [string:strip(C, both, $"), string:strip(In, both, $")]; %{selected, [_], [{C}, {In}]} -> [string:strip(C, both, $"), string:strip(In, both, $")];
@ -778,16 +796,17 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId, RSM
get_last_items(Nidx, _From, Count) -> get_last_items(Nidx, _From, Count) ->
Limit = jlib:i2l(Count), Limit = jlib:i2l(Count),
SNidx = integer_to_binary(Nidx),
Query = fun(mssql, _) -> Query = fun(mssql, _) ->
ejabberd_sql:sql_query_t( ejabberd_sql:sql_query_t(
[<<"select top ">>, Limit, [<<"select top ">>, Limit,
<<" itemid, publisher, creation, modification, payload " <<" itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx, "from pubsub_item where nodeid='">>, SNidx,
<<"' order by modification desc ;">>]); <<"' order by modification desc ;">>]);
(_, _) -> (_, _) ->
ejabberd_sql:sql_query_t( ejabberd_sql:sql_query_t(
[<<"select itemid, publisher, creation, modification, payload " [<<"select itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx, "from pubsub_item where nodeid='">>, SNidx,
<<"' order by modification desc limit ">>, Limit, <<";">>]) <<"' order by modification desc limit ">>, Limit, <<";">>])
end, end,
case catch ejabberd_sql:sql_query_t(Query) of case catch ejabberd_sql:sql_query_t(Query) of
@ -799,16 +818,14 @@ get_last_items(Nidx, _From, Count) ->
end. end.
get_item(Nidx, ItemId) -> get_item(Nidx, ItemId) ->
I = ejabberd_sql:escape(ItemId), case catch ejabberd_sql:sql_query_t(
case catch ?SQL("select @(itemid)s, @(publisher)s, @(creation)s,"
ejabberd_sql:sql_query_t([<<"select itemid, publisher, creation, " " @(modification)s, @(payload)s from pubsub_item"
"modification, payload from pubsub_item " " where nodeid=%(Nidx)d and itemid=%(ItemId)s"))
"where nodeid='">>, Nidx, <<"' and itemid='">>, I, <<"';">>])
of of
{selected, {selected, [RItem]} ->
[<<"itemid">>, <<"publisher">>, <<"creation">>, <<"modification">>, <<"payload">>], [RItem]} ->
{result, raw_to_item(Nidx, RItem)}; {result, raw_to_item(Nidx, RItem)};
{selected, _, []} -> {selected, []} ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, ?ERR_ITEM_NOT_FOUND};
{'EXIT', _} -> {'EXIT', _} ->
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)} {error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)}
@ -847,37 +864,31 @@ get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, _Sub
set_item(Item) -> set_item(Item) ->
{ItemId, Nidx} = Item#pubsub_item.itemid, {ItemId, Nidx} = Item#pubsub_item.itemid,
I = ejabberd_sql:escape(ItemId),
{C, _} = Item#pubsub_item.creation, {C, _} = Item#pubsub_item.creation,
{M, JID} = Item#pubsub_item.modification, {M, JID} = Item#pubsub_item.modification,
P = encode_jid(JID), P = encode_jid(JID),
Payload = Item#pubsub_item.payload, Payload = Item#pubsub_item.payload,
XML = ejabberd_sql:escape(str:join([fxml:element_to_binary(X) || X<-Payload], <<>>)), XML = str:join([fxml:element_to_binary(X) || X<-Payload], <<>>),
S = fun ({T1, T2, T3}) -> S = fun ({T1, T2, T3}) ->
str:join([jlib:i2l(T1, 6), jlib:i2l(T2, 6), jlib:i2l(T3, 6)], <<":">>) str:join([jlib:i2l(T1, 6), jlib:i2l(T2, 6), jlib:i2l(T3, 6)], <<":">>)
end, end,
case catch SM = S(M),
ejabberd_sql:sql_query_t([<<"update pubsub_item set publisher='">>, P, SC = S(C),
<<"', modification='">>, S(M), ?SQL_UPSERT_T(
<<"', payload='">>, XML, "pubsub_item",
<<"' where nodeid='">>, Nidx, <<"' and itemid='">>, I, <<"';">>]) ["!nodeid=%(Nidx)d",
of "!itemid=%(ItemId)s",
{updated, 1} -> "publisher=%(P)s",
ok; "modification=%(SM)s",
_ -> "payload=%(XML)s",
catch "-creation=%(SC)s"
ejabberd_sql:sql_query_t([<<"insert into pubsub_item (nodeid, itemid, " ]),
"publisher, creation, modification, payload) "
"values('">>, Nidx, <<"', '">>, I, <<"', '">>, P,
<<"', '">>, S(C), <<"', '">>, S(M),
<<"', '">>, XML, <<"');">>])
end,
ok. ok.
del_item(Nidx, ItemId) -> del_item(Nidx, ItemId) ->
I = ejabberd_sql:escape(ItemId), catch ejabberd_sql:sql_query_t(
catch ejabberd_sql:sql_query_t([<<"delete from pubsub_item where itemid='">>, ?SQL("delete from pubsub_item where itemid=%(ItemId)s"
I, <<"' and nodeid='">>, Nidx, <<"';">>]). " and nodeid=%(Nidx)d")).
del_items(_, []) -> del_items(_, []) ->
ok; ok;
@ -885,9 +896,10 @@ del_items(Nidx, [ItemId]) ->
del_item(Nidx, ItemId); del_item(Nidx, ItemId);
del_items(Nidx, ItemIds) -> del_items(Nidx, ItemIds) ->
I = str:join([[<<"'">>, ejabberd_sql:escape(X), <<"'">>] || X <- ItemIds], <<",">>), I = str:join([[<<"'">>, ejabberd_sql:escape(X), <<"'">>] || X <- ItemIds], <<",">>),
SNidx = integer_to_binary(Nidx),
catch catch
ejabberd_sql:sql_query_t([<<"delete from pubsub_item where itemid in (">>, ejabberd_sql:sql_query_t([<<"delete from pubsub_item where itemid in (">>,
I, <<") and nodeid='">>, Nidx, <<"';">>]). I, <<") and nodeid='">>, SNidx, <<"';">>]).
get_item_name(_Host, _Node, Id) -> get_item_name(_Host, _Node, Id) ->
Id. Id.
@ -908,14 +920,15 @@ first_in_list(Pred, [H | T]) ->
end. end.
itemids(Nidx, {_U, _S, _R} = JID) -> itemids(Nidx, {_U, _S, _R} = JID) ->
SJID = encode_jid_like(JID), SJID = <<(ejabberd_sql:escape(encode_jid_like(JID)))/binary, "%">>,
case catch case catch
ejabberd_sql:sql_query_t([<<"select itemid from pubsub_item where " ejabberd_sql:sql_query_t(
"nodeid='">>, Nidx, <<"' and publisher like '">>, SJID, ?SQL("select @(itemid)s from pubsub_item where "
<<"%' escape '^' order by modification desc;">>]) "nodeid=%(Nidx)d and publisher like %(SJID)s escape '^' "
"order by modification desc"))
of of
{selected, [<<"itemid">>], RItems} -> {selected, RItems} ->
[ItemId || [ItemId] <- RItems]; [ItemId || {ItemId} <- RItems];
_ -> _ ->
[] []
end. end.
@ -923,11 +936,11 @@ itemids(Nidx, {_U, _S, _R} = JID) ->
select_affiliation_subscriptions(Nidx, JID) -> select_affiliation_subscriptions(Nidx, JID) ->
J = encode_jid(JID), J = encode_jid(JID),
case catch case catch
ejabberd_sql:sql_query_t([<<"select affiliation,subscriptions from " ejabberd_sql:sql_query_t(
"pubsub_state where nodeid='">>, ?SQL("select @(affiliation)s, @(subscriptions)s from "
Nidx, <<"' and jid='">>, J, <<"';">>]) " pubsub_state where nodeid=%(Nidx)d and jid=%(J)s"))
of of
{selected, [<<"affiliation">>, <<"subscriptions">>], [[A, S]]} -> {selected, [{A, S}]} ->
{decode_affiliation(A), decode_subscriptions(S)}; {decode_affiliation(A), decode_subscriptions(S)};
_ -> _ ->
{none, []} {none, []}
@ -943,33 +956,24 @@ select_affiliation_subscriptions(Nidx, GenKey, SubKey) ->
update_affiliation(Nidx, JID, Affiliation) -> update_affiliation(Nidx, JID, Affiliation) ->
J = encode_jid(JID), J = encode_jid(JID),
A = encode_affiliation(Affiliation), A = encode_affiliation(Affiliation),
case catch ?SQL_UPSERT_T(
ejabberd_sql:sql_query_t([<<"update pubsub_state set affiliation='">>, "pubsub_state",
A, <<"' where nodeid='">>, Nidx, ["!nodeid=%(Nidx)d",
<<"' and jid='">>, J, <<"';">>]) "!jid=%(J)s",
of "affiliation=%(A)s",
{updated, 1} -> "-subscriptions=''"
ok; ]).
_ ->
catch
ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
"values('">>, Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '');">>])
end.
update_subscription(Nidx, JID, Subscription) -> update_subscription(Nidx, JID, Subscription) ->
J = encode_jid(JID), J = encode_jid(JID),
S = encode_subscriptions(Subscription), S = encode_subscriptions(Subscription),
case catch ?SQL_UPSERT_T(
ejabberd_sql:sql_query_t([<<"update pubsub_state set subscriptions='">>, S, "pubsub_state",
<<"' where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>]) ["!nodeid=%(Nidx)d",
of "!jid=%(J)s",
{updated, 1} -> "subscriptions=%(S)s",
ok; "-affiliation='n'"
_ -> ]).
catch
ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
"values('">>, Nidx, <<"', '">>, J, <<"', 'n', '">>, S, <<"');">>])
end.
-spec(decode_jid/1 :: -spec(decode_jid/1 ::
( SJID :: binary()) ( SJID :: binary())
@ -1016,24 +1020,24 @@ decode_subscriptions(Subscriptions) ->
-> binary() -> binary()
). ).
encode_jid(JID) -> encode_jid(JID) ->
ejabberd_sql:escape(jid:to_string(JID)). jid:to_string(JID).
-spec(encode_jid_like/1 :: (JID :: ljid()) -> binary()). -spec(encode_jid_like/1 :: (JID :: ljid()) -> binary()).
encode_jid_like(JID) -> encode_jid_like(JID) ->
ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(jid:to_string(JID))). ejabberd_sql:escape_like_arg_circumflex(jid:to_string(JID)).
-spec(encode_host/1 :: -spec(encode_host/1 ::
( Host :: host()) ( Host :: host())
-> binary() -> binary()
). ).
encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID); encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID);
encode_host(Host) -> ejabberd_sql:escape(Host). encode_host(Host) -> Host.
-spec(encode_host_like/1 :: -spec(encode_host_like/1 ::
( Host :: host()) ( Host :: host())
-> binary() -> binary()
). ).
encode_host_like({_U, _S, _R} = LJID) -> encode_jid_like(LJID); encode_host_like({_U, _S, _R} = LJID) -> ejabberd_sql:escape(encode_jid_like(LJID));
encode_host_like(Host) -> encode_host_like(Host) ->
ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(Host)). ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(Host)).
@ -1069,12 +1073,14 @@ encode_subscriptions(Subscriptions) ->
state_to_raw(Nidx, State) -> state_to_raw(Nidx, State) ->
{JID, _} = State#pubsub_state.stateid, {JID, _} = State#pubsub_state.stateid,
J = encode_jid(JID), J = ejabberd_sql:escape(encode_jid(JID)),
A = encode_affiliation(State#pubsub_state.affiliation), A = encode_affiliation(State#pubsub_state.affiliation),
S = encode_subscriptions(State#pubsub_state.subscriptions), S = encode_subscriptions(State#pubsub_state.subscriptions),
[<<"'">>, Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '">>, S, <<"'">>]. [<<"'">>, Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '">>, S, <<"'">>].
raw_to_item(Nidx, [ItemId, SJID, Creation, Modification, XML]) -> raw_to_item(Nidx, [ItemId, SJID, Creation, Modification, XML]) ->
raw_to_item(Nidx, {ItemId, SJID, Creation, Modification, XML});
raw_to_item(Nidx, {ItemId, SJID, Creation, Modification, XML}) ->
JID = decode_jid(SJID), JID = decode_jid(SJID),
ToTime = fun (Str) -> ToTime = fun (Str) ->
[T1, T2, T3] = str:tokens(Str, <<":">>), [T1, T2, T3] = str:tokens(Str, <<":">>),

View File

@ -116,9 +116,9 @@ get_entity_subscriptions(_Host, Owner) ->
SubKey = jid:tolower(Owner), SubKey = jid:tolower(Owner),
GenKey = jid:remove_resource(SubKey), GenKey = jid:remove_resource(SubKey),
HostLike = node_flat_sql:encode_host_like(element(2, SubKey)), HostLike = node_flat_sql:encode_host_like(element(2, SubKey)),
SJ = node_flat_sql:encode_jid(SubKey), SJ = ejabberd_sql:escape(node_flat_sql:encode_jid(SubKey)),
GJ = node_flat_sql:encode_jid(GenKey), GJ = ejabberd_sql:escape(node_flat_sql:encode_jid(GenKey)),
GJLike = node_flat_sql:encode_jid_like(GenKey), GJLike = ejabberd_sql:escape(node_flat_sql:encode_jid_like(GenKey)),
Query = case SubKey of Query = case SubKey of
GenKey -> GenKey ->
[<<"select host, node, type, i.nodeid, jid, " [<<"select host, node, type, i.nodeid, jid, "
@ -152,9 +152,9 @@ get_entity_subscriptions_for_send_last(_Host, Owner) ->
SubKey = jid:tolower(Owner), SubKey = jid:tolower(Owner),
GenKey = jid:remove_resource(SubKey), GenKey = jid:remove_resource(SubKey),
HostLike = node_flat_sql:encode_host_like(element(2, SubKey)), HostLike = node_flat_sql:encode_host_like(element(2, SubKey)),
SJ = node_flat_sql:encode_jid(SubKey), SJ = ejabberd_sql:escape(node_flat_sql:encode_jid(SubKey)),
GJ = node_flat_sql:encode_jid(GenKey), GJ = ejabberd_sql:escape(node_flat_sql:encode_jid(GenKey)),
GJLike = node_flat_sql:encode_jid_like(GenKey), GJLike = ejabberd_sql:escape(node_flat_sql:encode_jid_like(GenKey)),
Query = case SubKey of Query = case SubKey of
GenKey -> GenKey ->
[<<"select host, node, type, i.nodeid, jid, " [<<"select host, node, type, i.nodeid, jid, "

View File

@ -37,8 +37,11 @@
-behaviour(gen_pubsub_nodetree). -behaviour(gen_pubsub_nodetree).
-author('christophe.romain@process-one.net'). -author('christophe.romain@process-one.net').
-compile([{parse_transform, ejabberd_sql_pt}]).
-include("pubsub.hrl"). -include("pubsub.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
-include("ejabberd_sql_pt.hrl").
-export([init/3, terminate/2, options/0, set_node/1, -export([init/3, terminate/2, options/0, set_node/1,
get_node/3, get_node/2, get_node/1, get_nodes/2, get_node/3, get_node/2, get_node/1, get_nodes/2,
@ -65,27 +68,27 @@ set_node(Record) when is_record(Record, pubsub_node) ->
end, end,
Type = Record#pubsub_node.type, Type = Record#pubsub_node.type,
H = node_flat_sql:encode_host(Host), H = node_flat_sql:encode_host(Host),
N = ejabberd_sql:escape(Node),
P = ejabberd_sql:escape(Parent),
Nidx = case nodeidx(Host, Node) of Nidx = case nodeidx(Host, Node) of
{result, OldNidx} -> {result, OldNidx} ->
catch catch
ejabberd_sql:sql_query_t([<<"delete from pubsub_node_option where " ejabberd_sql:sql_query_t(
"nodeid='">>, OldNidx, <<"';">>]), ?SQL("delete from pubsub_node_option where "
"nodeid=%(OldNidx)d")),
catch catch
ejabberd_sql:sql_query_t([<<"update pubsub_node set host='">>, ejabberd_sql:sql_query_t(
H, <<"' node='">>, N, ?SQL("update pubsub_node set"
<<"' parent='">>, P, " host=%(H)s"
<<"' type='">>, Type, " node=%(Node)s"
<<"' where nodeid='">>, " parent=%(Parent)s"
OldNidx, <<"';">>]), " type=%(Type)s "
"where nodeid=%(OldNidx)d")),
OldNidx; OldNidx;
_ -> _ ->
catch catch
ejabberd_sql:sql_query_t([<<"insert into pubsub_node(host, node, " ejabberd_sql:sql_query_t(
"parent, type) values('">>, ?SQL("insert into pubsub_node(host, node, "
H, <<"', '">>, N, <<"', '">>, P, "parent, type) values("
<<"', '">>, Type, <<"');">>]), "%(H)s, %(Node)s, %(Parent)s, %(Type)s)")),
case nodeidx(Host, Node) of case nodeidx(Host, Node) of
{result, NewNidx} -> NewNidx; {result, NewNidx} -> NewNidx;
_ -> none % this should not happen _ -> none % this should not happen
@ -98,14 +101,12 @@ set_node(Record) when is_record(Record, pubsub_node) ->
_ -> _ ->
lists:foreach(fun ({Key, Value}) -> lists:foreach(fun ({Key, Value}) ->
SKey = iolist_to_binary(atom_to_list(Key)), SKey = iolist_to_binary(atom_to_list(Key)),
SValue = ejabberd_sql:escape( SValue = jlib:term_to_expr(Value),
list_to_binary(
lists:flatten(io_lib:fwrite("~p", [Value])))),
catch catch
ejabberd_sql:sql_query_t([<<"insert into pubsub_node_option(nodeid, " ejabberd_sql:sql_query_t(
"name, val) values('">>, ?SQL("insert into pubsub_node_option(nodeid, "
Nidx, <<"', '">>, "name, val) values ("
SKey, <<"', '">>, SValue, <<"');">>]) "%(Nidx)d, %(SKey)s, %(SValue)s)"))
end, end,
Record#pubsub_node.options), Record#pubsub_node.options),
{result, Nidx} {result, Nidx}
@ -116,14 +117,12 @@ get_node(Host, Node, _From) ->
get_node(Host, Node) -> get_node(Host, Node) ->
H = node_flat_sql:encode_host(Host), H = node_flat_sql:encode_host(Host),
N = ejabberd_sql:escape(Node),
case catch case catch
ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from " ejabberd_sql:sql_query_t(
"pubsub_node where host='">>, ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
H, <<"' and node='">>, N, <<"';">>]) "pubsub_node where host=%(H)s and node=%(Node)s"))
of of
{selected, {selected, [RItem]} ->
[<<"node">>, <<"parent">>, <<"type">>, <<"nodeid">>], [RItem]} ->
raw_to_node(Host, RItem); raw_to_node(Host, RItem);
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)}; {error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)};
@ -133,13 +132,12 @@ get_node(Host, Node) ->
get_node(Nidx) -> get_node(Nidx) ->
case catch case catch
ejabberd_sql:sql_query_t([<<"select host, node, parent, type from " ejabberd_sql:sql_query_t(
"pubsub_node where nodeid='">>, ?SQL("select @(host)s, @(node)s, @(parent)s, @(type)s from "
Nidx, <<"';">>]) "pubsub_node where nodeid=%(Nidx)d"))
of of
{selected, {selected, [{Host, Node, Parent, Type}]} ->
[<<"host">>, <<"node">>, <<"parent">>, <<"type">>], [[Host, Node, Parent, Type]]} -> raw_to_node(Host, {Node, Parent, Type, Nidx});
raw_to_node(Host, [Node, Parent, Type, Nidx]);
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)}; {error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)};
_ -> _ ->
@ -152,11 +150,11 @@ get_nodes(Host, _From) ->
get_nodes(Host) -> get_nodes(Host) ->
H = node_flat_sql:encode_host(Host), H = node_flat_sql:encode_host(Host),
case catch case catch
ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from " ejabberd_sql:sql_query_t(
"pubsub_node where host='">>, H, <<"';">>]) ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
"pubsub_node where host=%(H)s"))
of of
{selected, {selected, RItems} ->
[<<"node">>, <<"parent">>, <<"type">>, <<"nodeid">>], RItems} ->
[raw_to_node(Host, Item) || Item <- RItems]; [raw_to_node(Host, Item) || Item <- RItems];
_ -> _ ->
[] []
@ -178,14 +176,12 @@ get_subnodes(Host, Node, _From) ->
get_subnodes(Host, Node) -> get_subnodes(Host, Node) ->
H = node_flat_sql:encode_host(Host), H = node_flat_sql:encode_host(Host),
N = ejabberd_sql:escape(Node),
case catch case catch
ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from " ejabberd_sql:sql_query_t(
"pubsub_node where host='">>, ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
H, <<"' and parent='">>, N, <<"';">>]) "pubsub_node where host=%(H)s and parent=%(Node)s"))
of of
{selected, {selected, RItems} ->
[<<"node">>, <<"parent">>, <<"type">>, <<"nodeid">>], RItems} ->
[raw_to_node(Host, Item) || Item <- RItems]; [raw_to_node(Host, Item) || Item <- RItems];
_ -> _ ->
[] []
@ -196,14 +192,14 @@ get_subnodes_tree(Host, Node, _From) ->
get_subnodes_tree(Host, Node) -> get_subnodes_tree(Host, Node) ->
H = node_flat_sql:encode_host(Host), H = node_flat_sql:encode_host(Host),
N = ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(Node)), N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "%">>,
case catch case catch
ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from " ejabberd_sql:sql_query_t(
"pubsub_node where host='">>, ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
H, <<"' and node like '">>, N, <<"%' escape '^';">>]) "pubsub_node where host=%(H)s"
" and node like %(N)s escape '^'"))
of of
{selected, {selected, RItems} ->
[<<"node">>, <<"parent">>, <<"type">>, <<"nodeid">>], RItems} ->
[raw_to_node(Host, Item) || Item <- RItems]; [raw_to_node(Host, Item) || Item <- RItems];
_ -> _ ->
[] []
@ -256,20 +252,24 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
delete_node(Host, Node) -> delete_node(Host, Node) ->
H = node_flat_sql:encode_host(Host), H = node_flat_sql:encode_host(Host),
N = ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(Node)), N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "%">>,
Removed = get_subnodes_tree(Host, Node), Removed = get_subnodes_tree(Host, Node),
catch ejabberd_sql:sql_query_t([<<"delete from pubsub_node where host='">>, catch ejabberd_sql:sql_query_t(
H, <<"' and node like '">>, N, <<"%' escape '^';">>]), ?SQL("delete from pubsub_node where host=%(H)s"
" and node like %(N)s escape '^'")),
Removed. Removed.
%% helpers %% helpers
raw_to_node(Host, [Node, Parent, Type, Nidx]) -> raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
raw_to_node(Host, {Node, Parent, Type, binary_to_integer(Nidx)});
raw_to_node(Host, {Node, Parent, Type, Nidx}) ->
Options = case catch Options = case catch
ejabberd_sql:sql_query_t([<<"select name,val from pubsub_node_option " ejabberd_sql:sql_query_t(
"where nodeid='">>, Nidx, <<"';">>]) ?SQL("select @(name)s, @(val)s from pubsub_node_option "
"where nodeid=%(Nidx)d"))
of of
{selected, [<<"name">>, <<"val">>], ROptions} -> {selected, ROptions} ->
DbOpts = lists:map(fun ([Key, Value]) -> DbOpts = lists:map(fun ({Key, Value}) ->
RKey = jlib:binary_to_atom(Key), RKey = jlib:binary_to_atom(Key),
Tokens = element(2, erl_scan:string(binary_to_list(<<Value/binary, ".">>))), Tokens = element(2, erl_scan:string(binary_to_list(<<Value/binary, ".">>))),
RValue = element(2, erl_parse:parse_term(Tokens)), RValue = element(2, erl_parse:parse_term(Tokens)),
@ -295,13 +295,12 @@ raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
nodeidx(Host, Node) -> nodeidx(Host, Node) ->
H = node_flat_sql:encode_host(Host), H = node_flat_sql:encode_host(Host),
N = ejabberd_sql:escape(Node),
case catch case catch
ejabberd_sql:sql_query_t([<<"select nodeid from pubsub_node where " ejabberd_sql:sql_query_t(
"host='">>, ?SQL("select @(nodeid)d from pubsub_node where "
H, <<"' and node='">>, N, <<"';">>]) "host=%(H)s and node=%(Node)s"))
of of
{selected, [<<"nodeid">>], [[Nidx]]} -> {selected, [{Nidx}]} ->
{result, Nidx}; {result, Nidx};
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, db_fail}; {error, db_fail};

View File

@ -273,9 +273,8 @@ users_number(LServer, [{prefix, Prefix}])
users_number(LServer, []) -> users_number(LServer, []) ->
users_number(LServer). users_number(LServer).
add_spool_sql(Username, XML) -> add_spool_sql(LUser, XML) ->
[<<"insert into spool(username, xml) values ('">>, ?SQL("insert into spool(username, xml) values (%(LUser)s, %(XML)s)").
Username, <<"', '">>, XML, <<"');">>].
add_spool(LServer, Queries) -> add_spool(LServer, Queries) ->
ejabberd_sql:sql_transaction(LServer, Queries). ejabberd_sql:sql_transaction(LServer, Queries).

View File

@ -162,23 +162,23 @@ init_per_testcase(TestCase, OrigConfig) ->
IsMaster = lists:suffix("_master", Test), IsMaster = lists:suffix("_master", Test),
IsSlave = lists:suffix("_slave", Test), IsSlave = lists:suffix("_slave", Test),
IsCarbons = lists:prefix("carbons_", Test), IsCarbons = lists:prefix("carbons_", Test),
User = if IsMaster or IsCarbons -> <<"test_master">>; User = if IsMaster or IsCarbons -> <<"test_master!#$%^*()`~+-;_=[]{}|\\">>;
IsSlave -> <<"test_slave">>; IsSlave -> <<"test_slave!#$%^*()`~+-;_=[]{}|\\">>;
true -> <<"test_single">> true -> <<"test_single!#$%^*()`~+-;_=[]{}|\\">>
end, end,
MyResource = if IsMaster and IsCarbons -> MasterResource; MyResource = if IsMaster and IsCarbons -> MasterResource;
IsSlave and IsCarbons -> SlaveResource; IsSlave and IsCarbons -> SlaveResource;
true -> Resource true -> Resource
end, end,
Slave = if IsCarbons -> Slave = if IsCarbons ->
jid:make(<<"test_master">>, Server, SlaveResource); jid:make(<<"test_master!#$%^*()`~+-;_=[]{}|\\">>, Server, SlaveResource);
true -> true ->
jid:make(<<"test_slave">>, Server, Resource) jid:make(<<"test_slave!#$%^*()`~+-;_=[]{}|\\">>, Server, Resource)
end, end,
Master = if IsCarbons -> Master = if IsCarbons ->
jid:make(<<"test_master">>, Server, MasterResource); jid:make(<<"test_master!#$%^*()`~+-;_=[]{}|\\">>, Server, MasterResource);
true -> true ->
jid:make(<<"test_master">>, Server, Resource) jid:make(<<"test_master!#$%^*()`~+-;_=[]{}|\\">>, Server, Resource)
end, end,
Config = set_opt(user, User, Config = set_opt(user, User,
set_opt(slave, Slave, set_opt(slave, Slave,
@ -882,7 +882,7 @@ pubsub(Config) ->
true = lists:member(?NS_PUBSUB, Features), true = lists:member(?NS_PUBSUB, Features),
%% Publish <presence/> element within node "presence" %% Publish <presence/> element within node "presence"
ItemID = randoms:get_string(), ItemID = randoms:get_string(),
Node = <<"presence">>, Node = <<"presence!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>,
Item = #pubsub_item{id = ItemID, Item = #pubsub_item{id = ItemID,
xml_els = [xmpp_codec:encode(#presence{})]}, xml_els = [xmpp_codec:encode(#presence{})]},
#iq{type = result, #iq{type = result,

View File

@ -1,51 +1,52 @@
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIDETCCAcmgAwIBAgIEUbsa1zANBgkqhkiG9w0BAQsFADAAMCIYDzIwMTMwNjE0 MIIGbDCCBVSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJBVTET
MTMzMDAwWhgPMjAyMzA2MTIxMzMwMDhaMAAwggFSMA0GCSqGSIb3DQEBAQUAA4IB MBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQ
PwAwggE6AoIBMQCXdtt12OFu2j8tlF4x2Da/kbxyMxFnovJXHNzpx7CE/cGthAR5 dHkgTHRkMB4XDTE2MDUyNDE3NDIyNVoXDTQzMTAxMDE3NDIyNVowVjELMAkGA1UE
w7Cl92pECog2/d6ryIcjqzzCyCeOVQxIaE3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rITgbWjoFgF+yp0MiTlxgvjpmbg7RBlOvvM0t2ZDwUMhKvf00
9n6z/f1s1MSMgp6BY7HoHUv++FSYllCv06Qz7q9zFajN29wP046qZm9xPkegW7cy
KKylAoGYTg94GOWlUTz7Pe9PDrDSFVEAi0LcDmul0ntorvEFDvU2pCRK14gyvl9O
IJKVyYcDAqA3uvT+zMAniuf8KXNUCcYeEpfzpT+e2eznhczO8hI14M5U0X0LA8P2
vn0Y+yUWb9Ppu/dcjvaUA+qR/UTHqjAlAr3hFTKRxXFoGwwzTXCXvZGKOnzJRTpj
LpjI1RG7Weeoyx/8qDs=
-----END RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----

View File

@ -15,35 +15,35 @@ ou: groups
objectClass: organizationalUnit objectClass: organizationalUnit
dn: uid=test_single,ou=users,dc=localhost dn: uid=test_single,ou=users,dc=localhost
uid: test_single uid: test_single!#$%^*()`~+-;_=[]{}|\
mail: test_single@localhost mail: test_single!#$%^*()`~+-;_=[]{}|\@localhost
objectClass: person objectClass: person
jpegPhoto:: /9g= jpegPhoto:: /9g=
cn: Test Single cn: Test Single
password: password password: password!@#$%^&*()'"`~<>+-/;:_=[]{}|\
dn: uid=test_master,ou=users,dc=localhost dn: uid=test_master,ou=users,dc=localhost
uid: test_master uid: test_master!#$%^*()`~+-;_=[]{}|\
mail: test_master@localhost mail: test_master!#$%^*()`~+-;_=[]{}|\@localhost
objectClass: person objectClass: person
jpegPhoto:: /9g= jpegPhoto:: /9g=
cn: Test Master cn: Test Master
password: password password: password!@#$%^&*()'"`~<>+-/;:_=[]{}|\
dn: uid=test_slave,ou=users,dc=localhost dn: uid=test_slave,ou=users,dc=localhost
uid: test_slave uid: test_slave!#$%^*()`~+-;_=[]{}|\
mail: test_slave@localhost mail: test_slave!#$%^*()`~+-;_=[]{}|\@localhost
objectClass: person objectClass: person
jpegPhoto:: /9g= jpegPhoto:: /9g=
cn: Test Slave cn: Test Slave
password: password password: password!@#$%^&*()'"`~<>+-/;:_=[]{}|\
dn: uid=user2,ou=users,dc=localhost dn: uid=user2,ou=users,dc=localhost
uid: user2 uid: user2
mail: user2@localhost mail: user2@localhost
objectClass: person objectClass: person
cn: Test User 2 cn: Test User 2
password: password password: password!@#$%^&*()'"`~<>+-/;:_=[]{}|\
dn: cn=group1,ou=groups,dc=localhost dn: cn=group1,ou=groups,dc=localhost
objectClass: posixGroup objectClass: posixGroup

View File

@ -59,16 +59,16 @@ init_config(Config) ->
[{server_port, ct:get_config(c2s_port, 5222)}, [{server_port, ct:get_config(c2s_port, 5222)},
{server_host, "localhost"}, {server_host, "localhost"},
{server, ?COMMON_VHOST}, {server, ?COMMON_VHOST},
{user, <<"test_single">>}, {user, <<"test_single!#$%^*()`~+-;_=[]{}|\\">>},
{master_nick, <<"master_nick">>}, {master_nick, <<"master_nick!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{slave_nick, <<"slave_nick">>}, {slave_nick, <<"slave_nick!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{room_subject, <<"hello, world!">>}, {room_subject, <<"hello, world!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{certfile, CertFile}, {certfile, CertFile},
{base_dir, BaseDir}, {base_dir, BaseDir},
{resource, <<"resource">>}, {resource, <<"resource!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{master_resource, <<"master_resource">>}, {master_resource, <<"master_resource!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{slave_resource, <<"slave_resource">>}, {slave_resource, <<"slave_resource!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{password, <<"password!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>}, {password, <<"password!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>}
{backends, get_config_backends()} {backends, get_config_backends()}
|Config]. |Config].
@ -317,7 +317,12 @@ sasl_new(<<"DIGEST-MD5">>, User, Server, Password) ->
MyResponse = response(User, Password, Nonce, AuthzId, MyResponse = response(User, Password, Nonce, AuthzId,
Realm, CNonce, DigestURI, NC, QOP, Realm, CNonce, DigestURI, NC, QOP,
<<"AUTHENTICATE">>), <<"AUTHENTICATE">>),
Resp = <<"username=\"", User/binary, "\",realm=\"", SUser = << <<(case Char of
$" -> <<"\\\"">>;
$\\ -> <<"\\\\">>;
_ -> <<Char>>
end)/binary>> || <<Char>> <= User >>,
Resp = <<"username=\"", SUser/binary, "\",realm=\"",
Realm/binary, "\",nonce=\"", Nonce/binary, Realm/binary, "\",nonce=\"", Nonce/binary,
"\",cnonce=\"", CNonce/binary, "\",nc=", NC/binary, "\",cnonce=\"", CNonce/binary, "\",nc=", NC/binary,
",qop=", QOP/binary, ",digest-uri=\"", ",qop=", QOP/binary, ",digest-uri=\"",