From 2e75faefae29a96c077adeaf803f4c264c2fa226 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Mon, 20 Sep 2010 16:54:37 +0200 Subject: [PATCH] improve type specification --- src/mod_pubsub/mod_pubsub.erl | 4 +- src/mod_pubsub/mod_pubsub_odbc.erl | 4 +- src/mod_pubsub/node_buddy.erl | 2 - src/mod_pubsub/node_club.erl | 1 - src/mod_pubsub/node_dispatch.erl | 1 - src/mod_pubsub/node_flat.erl | 1 - src/mod_pubsub/node_flat_odbc.erl | 1 - src/mod_pubsub/node_hometree.erl | 1 - src/mod_pubsub/node_hometree_odbc.erl | 1 - src/mod_pubsub/node_mb.erl | 2 - src/mod_pubsub/node_pep.erl | 2 - src/mod_pubsub/node_pep_odbc.erl | 2 - src/mod_pubsub/node_private.erl | 2 - src/mod_pubsub/node_public.erl | 2 - src/mod_pubsub/nodetree_dag.erl | 1 - src/mod_pubsub/nodetree_tree.erl | 1 - src/mod_pubsub/nodetree_tree_odbc.erl | 1 - src/mod_pubsub/nodetree_virtual.erl | 2 - src/mod_pubsub/pubsub.hrl | 251 +++++++++++++++----- src/mod_pubsub/pubsub_odbc.patch | 102 ++++---- src/mod_pubsub/pubsub_subscription.erl | 1 - src/mod_pubsub/pubsub_subscription_odbc.erl | 1 - 22 files changed, 240 insertions(+), 146 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index adec996f0..419bd48e4 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -49,8 +49,6 @@ -behaviour(gen_server). -behaviour(gen_mod). --include_lib("exmpp/include/exmpp.hrl"). - -include("ejabberd.hrl"). -include("adhoc.hrl"). -include("pubsub.hrl"). @@ -2219,7 +2217,7 @@ delete_item(Host, Node, Publisher, ItemId, ForceNotify) -> Options = TNode#pubsub_node.options, broadcast_retract_items(Host, Node, Nidx, Type, Options, [ItemId], ForceNotify), case get_cached_item(Host, Nidx) of - #pubsub_item{id = {ItemId, Nidx}, _ = '_'} -> unset_cached_item(Host, Nidx); + #pubsub_item{id = {ItemId, Nidx}} -> unset_cached_item(Host, Nidx); _ -> ok end, case Result of diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index 003262583..f8b72155f 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -49,8 +49,6 @@ -behaviour(gen_server). -behaviour(gen_mod). --include_lib("exmpp/include/exmpp.hrl"). - -include("ejabberd.hrl"). -include("adhoc.hrl"). -include("pubsub.hrl"). @@ -2029,7 +2027,7 @@ delete_item(Host, Node, Publisher, ItemId, ForceNotify) -> Options = TNode#pubsub_node.options, broadcast_retract_items(Host, Node, Nidx, Type, Options, [ItemId], ForceNotify), case get_cached_item(Host, Nidx) of - #pubsub_item{id = {ItemId, Nidx}, _ = '_'} -> unset_cached_item(Host, Nidx); + #pubsub_item{id = {ItemId, Nidx}} -> unset_cached_item(Host, Nidx); _ -> ok end, case Result of diff --git a/src/mod_pubsub/node_buddy.erl b/src/mod_pubsub/node_buddy.erl index 202abcfcb..46f63ecdf 100644 --- a/src/mod_pubsub/node_buddy.erl +++ b/src/mod_pubsub/node_buddy.erl @@ -26,8 +26,6 @@ -module(node_buddy). -author('christophe.romain@process-one.net'). --include_lib("exmpp/include/exmpp.hrl"). - -include("pubsub.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/node_club.erl b/src/mod_pubsub/node_club.erl index 9dc4f202e..b7bb7cd4e 100644 --- a/src/mod_pubsub/node_club.erl +++ b/src/mod_pubsub/node_club.erl @@ -27,7 +27,6 @@ -author('christophe.romain@process-one.net'). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/node_dispatch.erl b/src/mod_pubsub/node_dispatch.erl index 2c1ad3565..b5b8419c6 100644 --- a/src/mod_pubsub/node_dispatch.erl +++ b/src/mod_pubsub/node_dispatch.erl @@ -27,7 +27,6 @@ -author('christophe.romain@process-one.net'). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/node_flat.erl b/src/mod_pubsub/node_flat.erl index b44d7bd6f..b7f0a7a16 100644 --- a/src/mod_pubsub/node_flat.erl +++ b/src/mod_pubsub/node_flat.erl @@ -42,7 +42,6 @@ -author('christophe.romain@process-one.net'). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/node_flat_odbc.erl b/src/mod_pubsub/node_flat_odbc.erl index 6efe12be4..fa249df69 100644 --- a/src/mod_pubsub/node_flat_odbc.erl +++ b/src/mod_pubsub/node_flat_odbc.erl @@ -42,7 +42,6 @@ -author('christophe.romain@process-one.net'). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -include("jlib.hrl"). %% for rsm_in and rsm_out records definitions -define(PUBSUB, mod_pubsub_odbc). diff --git a/src/mod_pubsub/node_hometree.erl b/src/mod_pubsub/node_hometree.erl index 34ec658d4..901e6cc72 100644 --- a/src/mod_pubsub/node_hometree.erl +++ b/src/mod_pubsub/node_hometree.erl @@ -26,7 +26,6 @@ -author('christophe.romain@process-one.net'). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/node_hometree_odbc.erl b/src/mod_pubsub/node_hometree_odbc.erl index ba5024822..711914511 100644 --- a/src/mod_pubsub/node_hometree_odbc.erl +++ b/src/mod_pubsub/node_hometree_odbc.erl @@ -26,7 +26,6 @@ -author('christophe.romain@process-one.net'). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/node_mb.erl b/src/mod_pubsub/node_mb.erl index 41beab5d4..162a1e96e 100644 --- a/src/mod_pubsub/node_mb.erl +++ b/src/mod_pubsub/node_mb.erl @@ -36,8 +36,6 @@ -module(node_mb). -author('eric@ohmforce.com'). --include_lib("exmpp/include/exmpp.hrl"). - -include("ejabberd.hrl"). -include("pubsub.hrl"). diff --git a/src/mod_pubsub/node_pep.erl b/src/mod_pubsub/node_pep.erl index a59fa9d57..8ec3737bf 100644 --- a/src/mod_pubsub/node_pep.erl +++ b/src/mod_pubsub/node_pep.erl @@ -29,8 +29,6 @@ -module(node_pep). -author('christophe.romain@process-one.net'). --include_lib("exmpp/include/exmpp.hrl"). - -include("ejabberd.hrl"). -include("pubsub.hrl"). diff --git a/src/mod_pubsub/node_pep_odbc.erl b/src/mod_pubsub/node_pep_odbc.erl index 91f52e60e..14d0875cc 100644 --- a/src/mod_pubsub/node_pep_odbc.erl +++ b/src/mod_pubsub/node_pep_odbc.erl @@ -29,8 +29,6 @@ -module(node_pep_odbc). -author('christophe.romain@process-one.net'). --include_lib("exmpp/include/exmpp.hrl"). - -include("ejabberd.hrl"). -include("pubsub.hrl"). diff --git a/src/mod_pubsub/node_private.erl b/src/mod_pubsub/node_private.erl index da8e90f8e..c069ad1b2 100644 --- a/src/mod_pubsub/node_private.erl +++ b/src/mod_pubsub/node_private.erl @@ -26,8 +26,6 @@ -module(node_private). -author('christophe.romain@process-one.net'). --include_lib("exmpp/include/exmpp.hrl"). - -include("pubsub.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/node_public.erl b/src/mod_pubsub/node_public.erl index f2fc6e780..b5719b5e7 100644 --- a/src/mod_pubsub/node_public.erl +++ b/src/mod_pubsub/node_public.erl @@ -26,8 +26,6 @@ -module(node_public). -author('christophe.romain@process-one.net'). --include_lib("exmpp/include/exmpp.hrl"). - -include("pubsub.hrl"). -behaviour(gen_pubsub_node). diff --git a/src/mod_pubsub/nodetree_dag.erl b/src/mod_pubsub/nodetree_dag.erl index f82353f53..722aaee51 100644 --- a/src/mod_pubsub/nodetree_dag.erl +++ b/src/mod_pubsub/nodetree_dag.erl @@ -39,7 +39,6 @@ -include("ejabberd.hrl"). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -behaviour(gen_pubsub_nodetree). diff --git a/src/mod_pubsub/nodetree_tree.erl b/src/mod_pubsub/nodetree_tree.erl index a5caa4c92..b30f2814d 100644 --- a/src/mod_pubsub/nodetree_tree.erl +++ b/src/mod_pubsub/nodetree_tree.erl @@ -37,7 +37,6 @@ -author('christophe.romain@process-one.net'). -include_lib("stdlib/include/qlc.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -include("pubsub.hrl"). diff --git a/src/mod_pubsub/nodetree_tree_odbc.erl b/src/mod_pubsub/nodetree_tree_odbc.erl index 68c3eaaae..9460bee3a 100644 --- a/src/mod_pubsub/nodetree_tree_odbc.erl +++ b/src/mod_pubsub/nodetree_tree_odbc.erl @@ -36,7 +36,6 @@ -author('christophe.romain@process-one.net'). -include_lib("stdlib/include/qlc.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -include("pubsub.hrl"). diff --git a/src/mod_pubsub/nodetree_virtual.erl b/src/mod_pubsub/nodetree_virtual.erl index 490f3aedf..c23ec82f9 100644 --- a/src/mod_pubsub/nodetree_virtual.erl +++ b/src/mod_pubsub/nodetree_virtual.erl @@ -33,8 +33,6 @@ -module(nodetree_virtual). -author('christophe.romain@process-one.net'). --include_lib("exmpp/include/exmpp.hrl"). - -include("pubsub.hrl"). -behaviour(gen_pubsub_nodetree). diff --git a/src/mod_pubsub/pubsub.hrl b/src/mod_pubsub/pubsub.hrl index 8d0569e0f..e45d4597f 100644 --- a/src/mod_pubsub/pubsub.hrl +++ b/src/mod_pubsub/pubsub.hrl @@ -21,6 +21,11 @@ %%% This file contains pubsub types definition. %%% ==================================================================== + +-include_lib("exmpp/include/exmpp.hrl"). +-include_lib("exmpp/include/exmpp_jid.hrl"). + + %% ------------------------------- %% Pubsub constants -define(ERR_EXTENDED(E,C), mod_pubsub:extended_error(E,C)). @@ -32,15 +37,22 @@ %% Would be nice to have it configurable. -define(MAX_PAYLOAD_SIZE, 60000). -%% ------------------------------- + +%% ------------ %% Pubsub types +%% ------------ %%% @type host() = binary(). +%%% %%%

host is the name of the PubSub service. For example, it can be %%% pubsub.localhost.

-%%% @type node() = binary(). -%%%

A node is the name of a Node. It can be anything and may represent +-type(host() :: binary()). + + +%%% @type nodeId() = binary(). +%%% +%%%

A nodeId is the name of a Node. It can be anything and may represent %%% some hierarchical tree depending of the node type. %%% For example: %%% /home/localhost/user/node @@ -48,14 +60,66 @@ %%% http://jabber.org/protocol/tune %%% My-Own_Node

-%%% @type item() = binary(). -%%%

An item is the name of an Item. It can be anything. +-type(nodeId() :: binary()). + + +%%% @type itemId() = binary(). +%%% +%%%

An itemId is the name of an Item. It can be anything. %%% For example: %%% 38964 %%% my-tune %%% FD6SBE6a27d

+-type(itemId() :: binary()). + + +%%% @type subId() = binary(). + +-type(subId() :: binary()). + + +%%% @type nodeType() = string(). +%%% +%%%

The nodeType is a string containing the name of the PubSub +%%% plugin to use to manage a given node. For example, it can be +%%% "flat", "hometree" or "blog".

+ +-type(nodeType() :: string()). + + +%%% @type ljid() = {User::binary(), Server::binary(), Resource::binary()}. + +-type(ljid() :: {User::binary(), Server::binary(), Resource::binary()}). + + +%%% @type nodeIdx() = integer(). + +-type(nodeIdx() :: integer()). + + +%%% @type now() = {Megaseconds::integer(), Seconds::integer(), Microseconds::integer()}. + +-type(now() :: {Megaseconds::integer(), Seconds::integer(), Microseconds::integer()}). + + +%%% @type affiliation() = none | owner | publisher | member | outcast. + +-type(affiliation() :: none | owner | publisher | member | outcast). + + +%%% @type subscription() = none | pending | unconfigured | subscribed. + +-type(subscription() :: none | pending | unconfigured | subscribed). + + +%%% @type payload() = string(). + +-type(payload() :: string()). + + %%% @type stanzaError() = #xmlel{}. +%%% %%% Example: %%% ```#xmlel{name = 'error' %%% ns = ?NS_STANZAS, @@ -73,7 +137,11 @@ %%% } %%% ]}''' +-type(stanzaError() :: #xmlel{}). + + %%% @type pubsubIQResponse() = #xmlel{}. +%%% %%% Example: %%% ```#xmlel{name = 'pubsub', %%% ns = ?NS_PUBSUB, @@ -84,84 +152,139 @@ %%% ] %%% }''' -%%% @type nodeOption() = {Option::atom(), Value::term()}. +-type(pubsubIQResponse() :: #xmlel{}). + + +%%% @type nodeOption() = {Option, Value}. +%%% Option = atom() +%%% Value = term(). +%%% %%% Example: %%% ```{deliver_payloads, true}''' -%%% @type nodeType() = string(). -%%%

The nodeType is a string containing the name of the PubSub -%%% plugin to use to manage a given node. For example, it can be -%%% "flat", "hometree" or "blog".

+-type(nodeOption() :: {Option::atom(), Value::term()}). -%%% @type ljid() = {User::binary(), Server::binary(), Resource::binary()}. +%%% @type subOption() = {Option, Value}. +%%% Option = atom() +%%% Value = term(). -%%% @type nodeidx() = int() +-type(subOption() :: {Option::atom(), Value::term()}). -%%% @type affiliation() = none | owner | publisher | member | outcast. -%%% @type subscription() = none | pending | unconfigured | subscribed. -%%% internal pubsub index table --record(pubsub_index, {index, last, free}). +%%% @type pubsubIndex() = {pubsub_index, Index, Last, Free}. +%%% Index = atom() +%%% Last = nodeIdx() +%%% Free = [nodeIdx()]. +%%% +%%% Internal pubsub index table. -%%% @type pubsubNode() = #pubsub_node{ -%%% id = {host(), node()}, -%%% idx = nodeidx(), -%%% parents = [Node::pubsubNode()], -%%% type = nodeType(), -%%% owners = [ljid()], -%%% options = [nodeOption()]}. +-record(pubsub_index, +{ + index :: atom(), + last :: integer(), + free :: [integer()] +}). + +-type(pubsubIndex() :: #pubsub_index{}). + + +%%% @type pubsubNode() = {pubsub_node, Id, Idx, Parents, Type, Owners, Options} +%%% Id = {host(), nodeId()} +%%% Idx = nodeIdx() +%%% Parents = [nodeId()] +%%% Type = nodeType() +%%% Owners = [ljid()] +%%% Options = [nodeOption()]. +%%% %%%

This is the format of the nodes table. The type of the table %%% is: set,ram/disc.

%%%

The parents and type fields are indexed.

-%%%

nodeidx is an integer.

--record(pubsub_node, {id, - idx, - parents = [], - type = "flat", - owners = [], - options = [] - }). +%%%

idx is an integer.

-%%% @type pubsubState() = #pubsub_state{ -%%% id = {ljid(), nodeidx()}, -%%% items = [item()], -%%% affiliation = affiliation(), -%%% subscriptions = [subscription()]}. -%%%

This is the format of the affiliations table. The type of the -%%% table is: set,ram/disc.

--record(pubsub_state, {id, - items = [], - affiliation = none, - subscriptions = [] +-record(pubsub_node, +{ + id :: {host(), nodeId()}, + idx :: nodeIdx(), + parents = [] :: [nodeId()], + type = "flat" :: nodeType(), + owners = [] :: [ljid()], + options = [] :: [nodeOption()] }). -%%% @type pubsubItem() = #pubsub_item{ -%%% id = {item(), nodeidx()}, -%%% creation = {now(), ljid()}, -%%% modification = {now(), ljid()}, -%%% payload = XMLContent::string()}. +-type(pubsubNode() :: #pubsub_node{}). + + +%%% @type pubsubState() = {pubsub_state, Id, Items, Affiliation, Subscriptions} +%%% Id = {ljid(), nodeIdx()} +%%% Items = [itemId()] +%%% Affiliation = affiliation() +%%% Subscriptions = [subscription()]. +%%% +%%%

This is the format of the affiliations table. The type of the +%%% table is: set,ram/disc.

+ +-record(pubsub_state, +{ + id :: {ljid(), nodeIdx()}, + items = [] :: [itemId()], + affiliation = none :: affiliation(), + subscriptions = [] :: [subscription()] +}). + +-type(pubsubState() :: #pubsub_state{}). + + +%%% @type pubsubItem() = {pubsub_item, Id, Creation, Modification, Payload} +%%% Id = {itemId(), nodeIdx()} +%%% Creation = {now(), ljid()} +%%% Modification = {now(), ljid()} +%%% Payload = payload(). +%%% %%%

This is the format of the published items table. The type of the %%% table is: set,disc,fragmented.

--record(pubsub_item, {id, - creation = {unknown,unknown}, - modification = {unknown,unknown}, - payload = [] - }). -%% @type pubsubSubscription() = #pubsub_subscription{ -%% subid = string(), -%% state_key = {ljid(), nodeidx()}, -%% options = [{atom(), term()}] -%% }. +-record(pubsub_item, +{ + id :: {itemId(), nodeIdx()}, + creation = {unknown,unknown} :: {now(), ljid()}, + modification = {unknown,unknown} :: {now(), ljid()}, + payload = [] :: payload() +}). + +-type(pubsubItem() :: #pubsub_item{}). + + +%%% @type pubsubSubscription() = {pubsub_subscription, SubId, Options} +%%% SubId = subId() +%%% Options = [nodeOption()]. +%%% %%

This is the format of the subscriptions table. The type of the %% table is: set,ram/disc.

--record(pubsub_subscription, {subid, options}). -%% @type pubsubLastItem() = #pubsub_last_item{ -%% nodeid = nodeidx(), -%% itemid = item(), -%% creation = {now(), ljid()}, -%% payload = XMLContent::string()}. +-record(pubsub_subscription, +{ + subid :: subId(), + options :: [subOption()] +}). + +-type(pubsubSubscription() :: #pubsub_subscription{}). + + +%%% @type pubsubLastItem() = {pubsub_last_item, NodeId, ItemId, Creation, Payload} +%%% NodeId = nodeIdx() +%%% ItemId = itemId() +%%% Creation = {now(), ljid()}() +%%% Payload = payload(). +%%% %%

This is the format of the last items table. it stores last item payload %% for every node

--record(pubsub_last_item, {nodeid, itemid, creation, payload}). + +-record(pubsub_last_item, +{ + nodeid :: nodeIdx(), + itemid :: itemId(), + creation :: {now(), ljid()}, + payload :: payload() +}). + +-type(pubsubLastItem() :: #pubsub_last_item{}). diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index e1e483f08..08c274887 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2010-09-10 18:04:47.000000000 +0200 -+++ mod_pubsub_odbc.erl 2010-09-10 19:43:53.000000000 +0200 +--- mod_pubsub.erl 2010-09-20 15:56:56.000000000 +0200 ++++ mod_pubsub_odbc.erl 2010-09-20 16:50:49.000000000 +0200 @@ -42,7 +42,7 @@ %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see %%% XEP-0060 section 12.18. @@ -9,7 +9,7 @@ -author('christophe.romain@process-one.net'). -version('1.13-0'). -@@ -55,9 +55,9 @@ +@@ -53,9 +53,9 @@ -include("adhoc.hrl"). -include("pubsub.hrl"). @@ -22,7 +22,7 @@ %% exports for hooks -export([presence_probe/3, -@@ -104,7 +104,7 @@ +@@ -102,7 +102,7 @@ string_to_affiliation/1, extended_error/2, extended_error/3, @@ -31,7 +31,7 @@ ]). %% API and gen_server callbacks -@@ -123,7 +123,7 @@ +@@ -121,7 +121,7 @@ -export([send_loop/1 ]). @@ -40,7 +40,7 @@ -define(LOOPNAME, ejabberd_mod_pubsub_loop). -define(PLUGIN_PREFIX, "node_"). -define(TREE_PREFIX, "nodetree_"). -@@ -220,8 +220,6 @@ +@@ -218,8 +218,6 @@ ok end, ejabberd_router:register_route(Host), @@ -49,7 +49,7 @@ init_nodes(Host, ServerHost, NodeTree, Plugins), State = #state{host = Host, server_host = ServerHost, -@@ -280,209 +278,14 @@ +@@ -278,209 +276,14 @@ init_nodes(Host, ServerHost, _NodeTree, Plugins) -> %% TODO, this call should be done plugin side @@ -262,7 +262,7 @@ send_loop(State) -> receive {presence, JID, Pid} -> -@@ -493,7 +296,10 @@ +@@ -491,7 +294,10 @@ %% for each node From is subscribed to %% and if the node is so configured, send the last published item to From lists:foreach(fun(PType) -> @@ -274,7 +274,7 @@ lists:foreach( fun({Node, subscribed, _, SubJID}) -> if (SubJID == LJID) or (SubJID == BJID) -> -@@ -618,7 +424,8 @@ +@@ -616,7 +422,8 @@ [#xmlel{name = 'identity', ns = ?NS_DISCO_INFO, attrs = [?XMLATTR('category', <<"pubsub">>), ?XMLATTR('type', <<"pep">>)]}]; disco_identity(Host, Node, From) -> @@ -284,7 +284,7 @@ case get_allowed_items_call(Host, Nidx, From, Type, Options, Owners) of {result, _} -> {result, -@@ -649,7 +456,8 @@ +@@ -647,7 +454,8 @@ [?NS_PUBSUB_s | [?NS_PUBSUB_s++"#"++Feature || Feature <- features("pep")]]; disco_features(Host, Node, From) -> @@ -294,7 +294,7 @@ case get_allowed_items_call(Host, Nidx, From, Type, Options, Owners) of {result, _} -> {result, [?NS_PUBSUB_s -@@ -668,7 +476,8 @@ +@@ -666,7 +474,8 @@ {result, disco_items(To, Node, From) ++ OtherItems}. disco_items(Host, <<>>, From) -> @@ -304,7 +304,7 @@ case get_allowed_items_call(Host, Nidx, From, Type, Options, Owners) of {result, _} -> [#xmlel{name = 'item', ns = ?NS_DISCO_INFO, -@@ -682,13 +491,14 @@ +@@ -680,13 +489,14 @@ _ -> Acc end end, @@ -321,7 +321,7 @@ case get_allowed_items_call(Host, Nidx, From, Type, Options, Owners) of {result, Items} -> {result, -@@ -774,10 +584,10 @@ +@@ -772,10 +582,10 @@ lists:foreach(fun(PType) -> {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]), lists:foreach(fun @@ -334,7 +334,7 @@ true -> node_action(Host, PType, unsubscribe_node, [Nidx, Entity, JID, all]); false -> -@@ -952,10 +762,11 @@ +@@ -950,10 +760,11 @@ end, ejabberd_router:route(To, From, Res); #iq{type = get, ns = ?NS_DISCO_ITEMS, @@ -348,7 +348,7 @@ {result, IQRes} -> Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query', attrs = QAttrs, -@@ -1092,7 +903,7 @@ +@@ -1090,7 +901,7 @@ [] -> ["leaf"]; %% No sub-nodes: it's a leaf node _ -> @@ -357,7 +357,7 @@ {result, []} -> ["collection"]; {result, _} -> ["leaf", "collection"]; _ -> [] -@@ -1108,8 +919,9 @@ +@@ -1106,8 +917,9 @@ []; true -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} | @@ -369,7 +369,7 @@ end, features(Type))] end, %% TODO: add meta-data info (spec section 5.4) -@@ -1138,8 +950,9 @@ +@@ -1136,8 +948,9 @@ #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++ @@ -381,7 +381,7 @@ end, features(Host, Node))}; ?NS_ADHOC_b -> command_disco_info(Host, Node, From); -@@ -1149,7 +962,7 @@ +@@ -1147,7 +960,7 @@ node_disco_info(Host, Node, From) end. @@ -390,7 +390,7 @@ case tree_action(Host, get_subnodes, [Host, <<>>, From]) of Nodes when is_list(Nodes) -> {result, lists:map( -@@ -1166,7 +979,7 @@ +@@ -1164,7 +977,7 @@ Other -> Other end; @@ -399,7 +399,7 @@ %% TODO: support localization of this string CommandItems = [ #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', -@@ -1175,19 +988,20 @@ +@@ -1173,19 +986,20 @@ ?XMLATTR('name', "Get Pending") ]}], {result, CommandItems}; @@ -425,7 +425,7 @@ end, Nodes = lists:map( fun(#pubsub_node{id = {_, SubNode}, options = SubOptions}) -> -@@ -1205,7 +1019,7 @@ +@@ -1203,7 +1017,7 @@ {result, Name} = node_call(Type, get_item_name, [Host, Node, RN]), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name)]} end, NodeItems), @@ -434,7 +434,7 @@ end, case transaction(Host, Node, Action, sync_dirty) of {result, {_, Result}} -> {result, Result}; -@@ -1213,12 +1027,6 @@ +@@ -1211,12 +1025,6 @@ end end. @@ -447,7 +447,7 @@ get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups) -> if (AccessModel == presence) or (AccessModel == roster) -> case Host of -@@ -1336,7 +1144,7 @@ +@@ -1334,7 +1142,7 @@ (_, Acc) -> Acc end, [], exmpp_xml:remove_cdata_from_list(Els)), @@ -456,7 +456,7 @@ {get, 'subscriptions'} -> get_subscriptions(Host, Node, From, Plugins); {get, 'affiliations'} -> -@@ -1493,7 +1301,8 @@ +@@ -1491,7 +1299,8 @@ _ -> [] end end, @@ -466,7 +466,7 @@ sync_dirty) of {result, Res} -> Res; Err -> Err -@@ -1537,7 +1346,7 @@ +@@ -1535,7 +1344,7 @@ %%% authorization handling @@ -475,7 +475,7 @@ Lang = <<"en">>, %% TODO fix {U, S, R} = Subscriber, Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children = -@@ -1567,7 +1376,7 @@ +@@ -1565,7 +1374,7 @@ lists:foreach(fun(Owner) -> {U, S, R} = Owner, ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza) @@ -484,7 +484,7 @@ find_authorization_response(Packet) -> Els = Packet#xmlel.children, -@@ -1626,8 +1435,8 @@ +@@ -1624,8 +1433,8 @@ "true" -> true; _ -> false end, @@ -495,7 +495,7 @@ {result, Subscriptions} = node_call(Type, get_subscriptions, [Nidx, Subscriber]), if not IsApprover -> -@@ -1826,7 +1635,7 @@ +@@ -1824,7 +1633,7 @@ end, Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]}, @@ -504,7 +504,7 @@ {result, {NodeId, SubsByDepth, {Result, broadcast}}} -> broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth), case Result of -@@ -1930,7 +1739,7 @@ +@@ -1928,7 +1737,7 @@ %%
  • The node does not exist.
  • %% subscribe_node(Host, Node, From, JID, Configuration) -> @@ -513,7 +513,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -1940,7 +1749,7 @@ +@@ -1938,7 +1747,7 @@ _:_ -> {undefined, undefined, undefined} end, @@ -522,7 +522,7 @@ Features = features(Type), SubscribeFeature = lists:member("subscribe", Features), OptionsFeature = lists:member("subscription-options", Features), -@@ -1949,6 +1758,7 @@ +@@ -1947,6 +1756,7 @@ AccessModel = get_option(Options, access_model), SendLast = get_option(Options, send_last_published_item), AllowedGroups = get_option(Options, roster_groups_allowed, []), @@ -530,7 +530,7 @@ {PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups), if not SubscribeFeature -> -@@ -2293,7 +2103,7 @@ +@@ -2291,7 +2101,7 @@ %%

    The permission are not checked in this function.

    %% @todo We probably need to check that the user doing the query has the right %% to read the items. @@ -539,7 +539,7 @@ MaxItems = if SMaxItems == "" -> get_max_items_node(Host); -@@ -2307,12 +2117,13 @@ +@@ -2305,12 +2115,13 @@ {error, Error} -> {error, Error}; _ -> @@ -554,7 +554,7 @@ {PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups), if not RetreiveFeature -> -@@ -2325,11 +2136,11 @@ +@@ -2323,11 +2134,11 @@ node_call(Type, get_items, [Nidx, From, AccessModel, PresenceSubscription, RosterGroup, @@ -568,7 +568,7 @@ SendItems = case ItemIds of [] -> Items; -@@ -2342,7 +2153,7 @@ +@@ -2340,7 +2151,7 @@ %% number of items sent to MaxItems: {result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children = @@ -577,7 +577,7 @@ Error -> Error end -@@ -2365,6 +2176,17 @@ +@@ -2363,6 +2174,17 @@ {result, {_, Items}} -> Items; Error -> Error end. @@ -595,7 +595,7 @@ %% @spec (Host, Node, NodeId, Type, LJID, Number) -> any() %% Host = pubsubHost() -@@ -2376,16 +2198,29 @@ +@@ -2374,16 +2196,29 @@ %% @doc

    Resend the items of a node to the user.

    %% @todo use cache-last-item feature send_items(Host, Node, NodeId, Type, LJID, last) -> @@ -631,7 +631,7 @@ send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) -> ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of {result, []} -> -@@ -2512,7 +2347,8 @@ +@@ -2510,7 +2345,8 @@ error -> {error, 'bad-request'}; _ -> @@ -641,7 +641,7 @@ case lists:member(Owner, Owners) of true -> OwnerJID = exmpp_jid:make(Owner), -@@ -2522,24 +2358,8 @@ +@@ -2520,24 +2356,8 @@ end, lists:foreach( fun({JID, Affiliation}) -> @@ -668,7 +668,7 @@ end, FilteredEntities), {result, []}; _ -> -@@ -2594,11 +2414,11 @@ +@@ -2592,11 +2412,11 @@ end. read_sub(Subscriber, Node, NodeId, SubId, Lang) -> @@ -682,7 +682,7 @@ OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options', attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)), ?XMLATTR('subid', SubId) | nodeAttr(Node)], -@@ -2625,7 +2445,7 @@ +@@ -2623,7 +2443,7 @@ end. set_options_helper(Configuration, JID, NodeId, SubId, Type) -> @@ -691,7 +691,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -2655,7 +2475,7 @@ +@@ -2653,7 +2473,7 @@ write_sub(_Subscriber, _NodeId, _SubId, invalid) -> {error, extended_error('bad-request', "invalid-options")}; write_sub(Subscriber, NodeId, SubId, Options) -> @@ -700,7 +700,7 @@ {error, notfound} -> {error, extended_error('not-acceptable', "invalid-subid")}; {result, _} -> -@@ -2829,8 +2649,8 @@ +@@ -2827,8 +2647,8 @@ ?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]}, ejabberd_router:route(service_jid(Host), JID, Stanza) end, @@ -711,7 +711,7 @@ true -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> -@@ -3179,7 +2999,7 @@ +@@ -3177,7 +2997,7 @@ {Depth, [{N, get_node_subs(N)} || N <- Nodes]} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, @@ -720,7 +720,7 @@ {result, CollSubs} -> CollSubs; _ -> [] end. -@@ -3192,7 +3012,7 @@ +@@ -3190,7 +3010,7 @@ get_options_for_subs(Nidx, Subs) -> lists:foldl(fun({JID, subscribed, SubId}, Acc) -> @@ -729,7 +729,7 @@ {error, notfound} -> [{JID, SubId, []} | Acc]; #pubsub_subscription{options = Options} -> [{JID, SubId, Options} | Acc]; _ -> Acc -@@ -3416,6 +3236,30 @@ +@@ -3414,6 +3234,30 @@ Result end. @@ -760,7 +760,7 @@ %% @spec (Host, Options) -> MaxItems %% Host = host() %% Options = [Option] -@@ -3819,7 +3663,13 @@ +@@ -3817,7 +3661,13 @@ tree_action(Host, Function, Args) -> ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), Fun = fun() -> tree_call(Host, Function, Args) end, @@ -775,7 +775,7 @@ %% @doc

    node plugin call.

    node_call(Type, Function, Args) -> -@@ -3839,13 +3689,13 @@ +@@ -3837,13 +3687,13 @@ node_action(Host, Type, Function, Args) -> ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), @@ -791,7 +791,7 @@ case tree_call(Host, get_node, [Host, Node]) of N when is_record(N, pubsub_node) -> case Action(N) of -@@ -3858,13 +3708,20 @@ +@@ -3856,13 +3706,20 @@ end end, Trans). @@ -816,7 +816,7 @@ {result, Result} -> {result, Result}; {error, Error} -> {error, Error}; {atomic, {result, Result}} -> {result, Result}; -@@ -3872,6 +3729,15 @@ +@@ -3870,6 +3727,15 @@ {aborted, Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), {error, 'internal-server-error'}; @@ -832,7 +832,7 @@ {'EXIT', Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), {error, 'internal-server-error'}; -@@ -3880,6 +3746,16 @@ +@@ -3878,6 +3744,16 @@ {error, 'internal-server-error'} end. diff --git a/src/mod_pubsub/pubsub_subscription.erl b/src/mod_pubsub/pubsub_subscription.erl index 87753acde..7e129068d 100644 --- a/src/mod_pubsub/pubsub_subscription.erl +++ b/src/mod_pubsub/pubsub_subscription.erl @@ -39,7 +39,6 @@ write_subscription/4]). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -define(PUBSUB_DELIVER, "pubsub#deliver"). -define(PUBSUB_DIGEST, "pubsub#digest"). diff --git a/src/mod_pubsub/pubsub_subscription_odbc.erl b/src/mod_pubsub/pubsub_subscription_odbc.erl index 88070a136..b03b10cd2 100644 --- a/src/mod_pubsub/pubsub_subscription_odbc.erl +++ b/src/mod_pubsub/pubsub_subscription_odbc.erl @@ -37,7 +37,6 @@ -include_lib("stdlib/include/qlc.hrl"). -include("pubsub.hrl"). --include_lib("exmpp/include/exmpp.hrl"). -define(PUBSUB_DELIVER, "pubsub#deliver"). -define(PUBSUB_DIGEST, "pubsub#digest").