Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjc/96b4d5e6f9c6ed8981db to your computer and use it in GitHub Desktop.
Save bjc/96b4d5e6f9c6ed8981db to your computer and use it in GitHub Desktop.
From dc22ff123d4eb35e17228ea4321f50c057a77b76 Mon Sep 17 00:00:00 2001
From: Brian Cully <bjc@kublai.com>
Date: Wed, 19 Nov 2008 19:35:34 -0500
Subject: [PATCH] Add authenticated versions of get_node and get_nodes for nodetree plugins.
* Plugin:get_node/3 - From JID is passed in, for potential
authorization.
* Plugin:get_nodes/2 - From JID is passed in, for potential
authorization and result filtering.
---
src/mod_pubsub/gen_pubsub_nodetree.erl | 2 ++
src/mod_pubsub/mod_pubsub.erl | 11 ++++++-----
src/mod_pubsub/nodetree_default.erl | 8 ++++++++
src/mod_pubsub/nodetree_virtual.erl | 8 ++++++++
4 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/src/mod_pubsub/gen_pubsub_nodetree.erl b/src/mod_pubsub/gen_pubsub_nodetree.erl
index ebdeca4..c249ff4 100644
--- a/src/mod_pubsub/gen_pubsub_nodetree.erl
+++ b/src/mod_pubsub/gen_pubsub_nodetree.erl
@@ -42,7 +42,9 @@ behaviour_info(callbacks) ->
{terminate, 2},
{options, 0},
{set_node, 1},
+ {get_node, 3},
{get_node, 2},
+ {get_nodes, 2},
{get_nodes, 1},
{get_subnodes, 3},
{get_subnodes_tree, 2},
diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl
index 24f39c9..d14a92b 100644
--- a/src/mod_pubsub/mod_pubsub.erl
+++ b/src/mod_pubsub/mod_pubsub.erl
@@ -355,11 +355,11 @@ disco_sm_features(Acc, From, To, Node, _Lang) ->
Acc
end.
-disco_sm_items(Acc, _From, To, [], _Lang) ->
+disco_sm_items(Acc, From, To, [], _Lang) ->
%% TODO, use iq_disco_items(Host, [], From)
Host = To#jid.lserver,
LJID = jlib:jid_tolower(jlib:jid_remove_resource(To)),
- case tree_action(Host, get_nodes, [Host]) of
+ case tree_action(Host, get_nodes, [Host, From]) of
[] ->
Acc;
Nodes ->
@@ -461,7 +461,7 @@ handle_cast({presence, JID, Pid}, State) ->
{result, Subscriptions} = node_action(Type, get_entity_subscriptions, [Host, JID]),
lists:foreach(
fun({Node, subscribed}) ->
- case tree_action(Host, get_node, [Host, Node]) of
+ case tree_action(Host, get_node, [Host, Node, JID]) of
#pubsub_node{options = Options} ->
case get_option(Options, send_last_published_item) of
on_sub_and_presence ->
@@ -511,7 +511,7 @@ handle_cast({presence, JID, Pid}, State) ->
_ ->
ok
end
- end, tree_action(Host, get_nodes, [PepKey]))
+ end, tree_action(Host, get_nodes, [PepKey, JID]))
end, ContactsUsers);
_ ->
ok
@@ -1024,7 +1024,7 @@ send_authorization_request(Host, Node, Subscriber) ->
{"type", "boolean"},
{"label", translate:translate(Lang, "Allow this JID to subscribe to this pubsub node?")}],
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
- case tree_action(Host, get_node, [Host, Node]) of
+ case tree_action(Host, get_node, [Host, Node, Subscriber]) of
#pubsub_node{owners = Owners} ->
lists:foreach(
fun(Owner) ->
@@ -1057,6 +1057,7 @@ find_authorization_response(Packet) ->
[invalid] -> invalid;
[] -> none;
[XFields] when is_list(XFields) ->
+ ?DEBUG("XFields: ~p", [XFields]),
case lists:keysearch("FORM_TYPE", 1, XFields) of
{value, {_, ?NS_PUBSUB_SUB_AUTH}} ->
XFields;
diff --git a/src/mod_pubsub/nodetree_default.erl b/src/mod_pubsub/nodetree_default.erl
index 700397e..05dd877 100644
--- a/src/mod_pubsub/nodetree_default.erl
+++ b/src/mod_pubsub/nodetree_default.erl
@@ -45,7 +45,9 @@
terminate/2,
options/0,
set_node/1,
+ get_node/3,
get_node/2,
+ get_nodes/2,
get_nodes/1,
get_subnodes/3,
get_subnodes_tree/2,
@@ -97,6 +99,9 @@ set_node(_) ->
%% @spec (Host, Node) -> pubsubNode() | {error, Reason}
%% Host = mod_pubsub:host()
%% Node = mod_pubsub:pubsubNode()
+get_node(Host, Node, _From) ->
+ get_node(Host, Node).
+
get_node(Host, Node) ->
case catch mnesia:read({pubsub_node, {Host, Node}}) of
[Record] when is_record(Record, pubsub_node) -> Record;
@@ -106,6 +111,9 @@ get_node(Host, Node) ->
%% @spec (Key) -> [pubsubNode()] | {error, Reason}
%% Key = mod_pubsub:host() | mod_pubsub:jid()
+get_nodes(Key, _From) ->
+ get_nodes(Key).
+
get_nodes(Key) ->
mnesia:match_object(#pubsub_node{nodeid = {Key, '_'}, _ = '_'}).
diff --git a/src/mod_pubsub/nodetree_virtual.erl b/src/mod_pubsub/nodetree_virtual.erl
index 7b057a0..a122c4b 100644
--- a/src/mod_pubsub/nodetree_virtual.erl
+++ b/src/mod_pubsub/nodetree_virtual.erl
@@ -43,7 +43,9 @@
terminate/2,
options/0,
set_node/1,
+ get_node/3,
get_node/2,
+ get_nodes/2,
get_nodes/1,
get_subnodes/3,
get_subnodes_tree/2,
@@ -86,6 +88,9 @@ set_node(_NodeRecord) ->
%% Node = mod_pubsub:pubsubNode()
%% @doc <p>Virtual node tree does not handle a node database. Any node is considered
%% as existing. Node record contains default values.</p>
+get_node(Host, Node, _From) ->
+ get_node(Host, Node).
+
get_node(Host, Node) ->
#pubsub_node{nodeid = {Host, Node}}.
@@ -93,6 +98,9 @@ get_node(Host, Node) ->
%% Host = mod_pubsub:host() | mod_pubsub:jid()
%% @doc <p>Virtual node tree does not handle a node database. Any node is considered
%% as existing. Nodes list can not be determined.</p>
+get_nodes(Key, _From) ->
+ get_nodes(Key).
+
get_nodes(_Key) ->
[].
--
1.6.0.rc2+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment