diff options
Diffstat (limited to 'src/node_flat_sql.erl')
-rw-r--r-- | src/node_flat_sql.erl | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/node_flat_sql.erl b/src/node_flat_sql.erl index 76b1c8ccc..38feed821 100644 --- a/src/node_flat_sql.erl +++ b/src/node_flat_sql.erl @@ -5,7 +5,7 @@ %%% Created : 1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net> %%% %%% -%%% ejabberd, Copyright (C) 2002-2019 ProcessOne +%%% ejabberd, Copyright (C) 2002-2020 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as @@ -393,7 +393,7 @@ get_entity_subscriptions(Host, Owner) -> ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s " "from pubsub_state i, pubsub_node n " "where i.nodeid = n.nodeid and " - "(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host=%(H)s"); + "(jid=%(GJ)s or jid like %(GJLike)s %ESCAPE) and host=%(H)s"); _ -> SJ = encode_jid(SubKey), ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s " @@ -436,7 +436,7 @@ get_entity_subscriptions_for_send_last(Host, Owner) -> "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=%(GJ)s or jid like %(GJLike)s escape '^') and host=%(H)s"); + "(jid=%(GJ)s or jid like %(GJLike)s %ESCAPE) and host=%(H)s"); _ -> SJ = encode_jid(SubKey), ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s " @@ -869,7 +869,7 @@ itemids(Nidx, {_U, _S, _R} = JID) -> ejabberd_sql:sql_query_t( ?SQL("select @(itemid)s from pubsub_item where " "nodeid=%(Nidx)d and (publisher=%(SJID)s" - " or publisher like %(SJIDLike)s escape '^') " + " or publisher like %(SJIDLike)s %ESCAPE) " "order by modification desc")) of {selected, RItems} -> @@ -894,10 +894,23 @@ select_affiliation_subscriptions(Nidx, JID) -> select_affiliation_subscriptions(Nidx, JID, JID) -> select_affiliation_subscriptions(Nidx, JID); select_affiliation_subscriptions(Nidx, GenKey, SubKey) -> - {result, Affiliation} = get_affiliation(Nidx, GenKey), - {result, BareJidSubs} = get_subscriptions(Nidx, GenKey), - {result, FullJidSubs} = get_subscriptions(Nidx, SubKey), - {Affiliation, BareJidSubs++FullJidSubs}. + GJ = encode_jid(GenKey), + SJ = encode_jid(SubKey), + case catch + ejabberd_sql:sql_query_t( + ?SQL("select jid = %(GJ)s as @(G)d, @(affiliation)s, @(subscriptions)s from " + " pubsub_state where nodeid=%(Nidx)d and jid in (%(GJ)s, %(SJ)s)")) + of + {selected, Res} -> + lists:foldr( + fun({1, A, S}, {_, Subs}) -> + {decode_affiliation(A), Subs ++ decode_subscriptions(S)}; + ({_, _, S}, {Aff, Subs}) -> + {Aff, Subs ++ decode_subscriptions(S)} + end, {none, []}, Res); + _ -> + {none, []} + end. update_affiliation(Nidx, JID, Affiliation) -> J = encode_jid(JID), @@ -955,16 +968,16 @@ encode_jid(JID) -> -spec encode_jid_like(JID :: ljid()) -> binary(). encode_jid_like(JID) -> - ejabberd_sql:escape_like_arg_circumflex(jid:encode(JID)). + ejabberd_sql:escape_like_arg(jid:encode(JID)). -spec encode_host(Host :: host()) -> binary(). encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID); encode_host(Host) -> Host. -spec encode_host_like(Host :: host()) -> binary(). -encode_host_like({_U, _S, _R} = LJID) -> ejabberd_sql:escape(encode_jid_like(LJID)); +encode_host_like({_U, _S, _R} = LJID) -> encode_jid_like(LJID); encode_host_like(Host) -> - ejabberd_sql:escape(ejabberd_sql:escape_like_arg_circumflex(Host)). + ejabberd_sql:escape_like_arg(Host). -spec encode_affiliation(Arg :: atom()) -> binary(). encode_affiliation(owner) -> <<"o">>; |