Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2016-07-05 16:43:59 +0300
committerChristophe Romain <christophe.romain@process-one.net>2016-07-05 16:43:59 +0300
commite300f8095deec16db79bdbd2f491cc6a432d9f47 (patch)
treeca034bc190cab43bbae8a1b7244ef072a7b529e0
parent8e04a7ef4d6225c2ca4b2bdc59b50d0ff11e4217 (diff)
Fix use of like parameter in sql pubsub's requests
-rw-r--r--src/node_flat_sql.erl21
-rw-r--r--src/nodetree_tree_sql.erl36
2 files changed, 34 insertions, 23 deletions
diff --git a/src/node_flat_sql.erl b/src/node_flat_sql.erl
index 2030b12c7..37615ca1e 100644
--- a/src/node_flat_sql.erl
+++ b/src/node_flat_sql.erl
@@ -365,21 +365,22 @@ get_entity_subscriptions(Host, Owner) ->
H = encode_host(Host),
SJ = encode_jid(SubKey),
GJ = encode_jid(GenKey),
- GJLike = <<(encode_jid_like(GenKey))/binary, "%">>,
+ GJLike = <<(encode_jid_like(GenKey))/binary, "/%">>,
Query =
case SubKey of
GenKey ->
?SQL("select @(node)s, @(type)s, @(i.nodeid)d,"
" @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n "
- "where i.nodeid = n.nodeid and jid like %(GJLike)s"
- " escape '^' and host=%(H)s");
+ "where i.nodeid = n.nodeid and "
+ "(jid=%(GJ)s or jid like %(GJLike)s escape '^')"
+ " and host=%(H)s");
_ ->
?SQL("select @(node)s, @(type)s, @(i.nodeid)d,"
" @(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")
+ "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
{selected, RItems} ->
@@ -423,8 +424,9 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
" @(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 like %(GJLike)s"
- " escape '^' and host=%(H)s");
+ "and val='on_sub_and_presence' and "
+ "(jid=%(GJ)s or jid like %(GJLike)s escape '^')"
+ " and host=%(H)s");
_ ->
?SQL("select @(node)s, @(type)s, @(i.nodeid)d,"
" @(jid)s, @(subscriptions)s "
@@ -912,11 +914,12 @@ first_in_list(Pred, [H | T]) ->
end.
itemids(Nidx, {_U, _S, _R} = JID) ->
- SJID = <<(ejabberd_sql:escape(encode_jid_like(JID)))/binary, "%">>,
+ SJID = <<(ejabberd_sql:escape(encode_jid_like(JID)))/binary, "/%">>,
case catch
ejabberd_sql:sql_query_t(
?SQL("select @(itemid)s from pubsub_item where "
- "nodeid=%(Nidx)d and publisher like %(SJID)s escape '^' "
+ "nodeid=%(Nidx)d and (publisher=%(JID)s"
+ " or publisher like %(SJID)s escape '^') "
"order by modification desc"))
of
{selected, RItems} ->
diff --git a/src/nodetree_tree_sql.erl b/src/nodetree_tree_sql.erl
index 1ad4046cd..fb5141bf3 100644
--- a/src/nodetree_tree_sql.erl
+++ b/src/nodetree_tree_sql.erl
@@ -191,18 +191,25 @@ get_subnodes_tree(Host, Node, _From) ->
get_subnodes_tree(Host, Node).
get_subnodes_tree(Host, Node) ->
- H = node_flat_sql:encode_host(Host),
- N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "%">>,
- case catch
- ejabberd_sql:sql_query_t(
- ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
- "pubsub_node where host=%(H)s"
- " and node like %(N)s escape '^'"))
- of
- {selected, RItems} ->
- [raw_to_node(Host, Item) || Item <- RItems];
- _ ->
- []
+ case get_node(Host, Node) of
+ {error, _} ->
+ [];
+ Rec ->
+ H = node_flat_sql:encode_host(Host),
+ N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "/%">>,
+ Sub = case catch
+ ejabberd_sql:sql_query_t(
+ ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
+ "pubsub_node where host=%(H)s"
+ " and node like %(N)s escape '^'"
+ " and type='hometree'"))
+ of
+ {selected, RItems} ->
+ [raw_to_node(Host, Item) || Item <- RItems];
+ _ ->
+ []
+ end,
+ [Rec|Sub]
end.
create_node(Host, Node, Type, Owner, Options, Parents) ->
@@ -252,11 +259,12 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
delete_node(Host, Node) ->
H = node_flat_sql:encode_host(Host),
- N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "%">>,
+ N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "/%">>,
Removed = get_subnodes_tree(Host, Node),
catch ejabberd_sql:sql_query_t(
?SQL("delete from pubsub_node where host=%(H)s"
- " and node like %(N)s escape '^'")),
+ " and (node=%(Node)s"
+ " or (type = 'hometree' and node like %(N)s escape '^'))")),
Removed.
%% helpers