summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2015-04-08 17:12:05 +0200
committerChristophe Romain <christophe.romain@process-one.net>2015-04-21 15:24:16 +0200
commite0563e3918984d151fbea45a5f6fc8255913726d (patch)
treee62bcc5cc538a722f81c3f53291e02594e576711 /include
parentImprove join/leave cluster scripts (diff)
PubSub improvements
This commit contains - code cleanup - use of db_type instead of old mod_pubsub_odbc - some minor optimizations - some minor bugfixes
Diffstat (limited to 'include')
-rw-r--r--include/pubsub.hrl148
1 files changed, 31 insertions, 117 deletions
diff --git a/include/pubsub.hrl b/include/pubsub.hrl
index 3be41e3f..2f85bdbf 100644
--- a/include/pubsub.hrl
+++ b/include/pubsub.hrl
@@ -27,8 +27,7 @@
%% -------------------------------
%% Pubsub constants
--define(ERR_EXTENDED(E, C),
- mod_pubsub:extended_error(E, C)).
+-define(ERR_EXTENDED(E, C), mod_pubsub:extended_error(E, C)).
%% The actual limit can be configured with mod_pubsub's option max_items_node
-define(MAXITEMS, 10).
@@ -40,7 +39,6 @@
%% -------------------------------
%% Pubsub types
-%% @type hostPubsub() = string().
-type(hostPubsub() :: binary()).
%% <p><tt>hostPubsub</tt> is the name of the PubSub service. For example, it can be
%% <tt>"pubsub.localhost"</tt>.</p>
@@ -59,12 +57,15 @@
-type(nodeId() :: binary()).
%% @type nodeId() = binary().
%% <p>A node is defined by a list of its ancestors. The last element is the name
-%% of the current node. For example:
%% of the current node. For example:
%% ```<<"/home/localhost/user">>'''</p>
--type(nodeIdx() :: pos_integer()).
-%% @type nodeIdx() = integer().
+-type(nodeIdx() :: pos_integer() | binary()).
+%% @type nodeIdx() = integer() | binary().
+%% note: pos_integer() should always be used, but we allow anything else coded
+%% as binary, so one can have a custom implementation of nodetree with custom
+%% indexing (see nodetree_virtual). this also allows to use any kind of key for
+%% indexing nodes, as this can be usefull with external backends such as odbc.
-type(itemId() :: binary()).
%% @type itemId() = string().
@@ -72,28 +73,12 @@
-type(subId() :: binary()).
%% @type subId() = string().
-
-%% @type payload() = [#xmlelement{} | #xmlcdata{}].
-
-%% @type stanzaError() = #xmlelement{}.
-%% Example:
-%% Example:
-%% ```{xmlelement, "error",
-%% [{"code", Code}, {"type", Type}],
-%% [{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []}]}'''
-%% @type pubsubIQResponse() = #xmlelement{}.
-%% Example:
-%% ```{xmlelement, "pubsub",
-%% [{"xmlns", ?NS_PUBSUB_EVENT}],
-%% [{xmlelement, "affiliations", [],
-%% []}]}'''
-
-type(nodeOption() ::
{Option::atom(),
- Value::binary() | [binary()] | boolean() | non_neg_integer()
+ Value::atom() | [binary()] | boolean() | non_neg_integer()
}).
--type(nodeOptions() :: [NodeOption::mod_pubsub:nodeOption(),...]).
+-type(nodeOptions() :: [mod_pubsub:nodeOption(),...]).
%% @type nodeOption() = {Option, Value}
%% Option = atom()
@@ -106,26 +91,9 @@
Value::binary() | [binary()] | boolean()
}).
--type(subOptions() :: [SubOption::mod_pubsub:subOption(),...]).
-
-%% @type nodeType() = string().
-%% <p>The <tt>nodeType</tt> is a string containing the name of the PubSub
-%% plugin to use to manage a given node. For example, it can be
-%% <tt>"flat"</tt>, <tt>"hometree"</tt> or <tt>"blog"</tt>.</p>
+-type(subOptions() :: [mod_pubsub:subOption(),...]).
-%% @type jid() = {jid, User, Server, Resource, LUser, LServer, LResource}
-%% User = string()
-%% Server = string()
-%% Resource = string()
-%% LUser = string()
-%% LServer = string()
-%% LResource = string().
-%-type(ljid() :: {binary(), binary(), binary()}).
-%% @type ljid() = {User, Server, Resource}
-%% User = string()
-%% Server = string()
-%% Resource = string().
-type(affiliation() :: 'none'
| 'owner'
@@ -151,16 +119,11 @@
).
%% @type accessModel() = 'open' | 'presence' | 'roster' | 'authorize' | 'whitelist'.
-%% @type pubsubIndex() = {pubsub_index, Index, Last, Free}
-%% Index = atom()
-%% Last = integer()
-%% Free = [integer()].
-%% internal pubsub index table
-type(publishModel() :: 'publishers'
| 'subscribers'
| 'open'
).
-
+%% @type publishModel() = 'publishers' | 'subscribers' | 'open'
-record(pubsub_index,
{
@@ -169,91 +132,42 @@
free :: [mod_pubsub:nodeIdx()]
}).
-%% @type pubsubNode() = {pubsub_node, NodeId, Id, Parents, Type, Owners, Options}
-%% NodeId = {host() | ljid(), nodeId()}
-%% Id = nodeIdx()
-%% Parents = [nodeId()]
-%% Type = nodeType()
-%% Owners = [ljid()]
-%% Options = [nodeOption()].
-%% <p>This is the format of the <tt>nodes</tt> table. The type of the table
-%% is: <tt>set</tt>,<tt>ram/disc</tt>.</p>
-%% <p>The <tt>Parents</tt> and <tt>type</tt> fields are indexed.</p>
-%% <tt>id</tt> can be anything you want.
-record(pubsub_node,
{
- nodeid ,%:: {Host::mod_pubsub:host(), NodeId::mod_pubsub:nodeId()},
- id ,%:: mod_pubsub:nodeIdx(),
- parents = [] ,%:: [Parent_NodeId::mod_pubsub:nodeId()],
- type = <<"flat">> ,%:: binary(),
- owners = [] ,%:: [Owner::ljid(),...],
- options = [] %:: mod_pubsub:nodeOptions()
+ nodeid ,% :: {mod_pubsub:host(), mod_pubsub:nodeId()},
+ id ,% :: mod_pubsub:nodeIdx(),
+ parents = [] ,% :: [mod_pubsub:nodeId(),...],
+ type = <<"flat">>,% :: binary(),
+ owners = [] ,% :: [jlib:ljid(),...],
+ options = [] % :: mod_pubsub:nodeOptions()
}).
-%% @type pubsubState() = {pubsub_state, StateId, Items, Affiliation, Subscriptions}
-%% StateId = {ljid(), nodeIdx()}
-%% Items = [itemId()]
-%% Affiliation = affiliation()
-%% Subscriptions = [{subscription(), subId()}].
-%% <p>This is the format of the <tt>affiliations</tt> table. The type of the
-%% table is: <tt>set</tt>,<tt>ram/disc</tt>.</p>
-
-%-record(pubsub_state,
-% {stateid, items = [], affiliation = none,
-% subscriptions = []}).
-record(pubsub_state,
{
- stateid ,%:: {Entity::ljid(), NodeIdx::mod_pubsub:nodeIdx()},
- items = [] ,%:: [ItemId::mod_pubsub:itemId()],
- affiliation = 'none' ,%:: mod_pubsub:affiliation(),
- subscriptions = [] %:: [{mod_pubsub:subscription(), mod_pubsub:subId()}]
+ stateid ,% :: {jlib:ljid(), mod_pubsub:nodeIdx()},
+ items = [] ,% :: [mod_pubsub:itemId(),...],
+ affiliation = 'none',% :: mod_pubsub:affiliation(),
+ subscriptions = [] % :: [{mod_pubsub:subscription(), mod_pubsub:subId()}]
}).
-%% @type pubsubItem() = {pubsub_item, ItemId, Creation, Modification, Payload}
-%% ItemId = {itemId(), nodeIdx()}
-%% Creation = {now(), ljid()}
-%% Modification = {now(), ljid()}
-%% Payload = payload().
-%% <p>This is the format of the <tt>published items</tt> table. The type of the
-%% table is: <tt>set</tt>,<tt>disc</tt>,<tt>fragmented</tt>.</p>
-%-record(pubsub_item,
-% {itemid, creation = {unknown, unknown},
-% modification = {unknown, unknown}, payload = []}).
-
-record(pubsub_item,
{
- itemid ,%:: {mod_pubsub:itemId(), mod_pubsub:nodeIdx()},
- creation = {unknown, unknown} ,%:: {erlang:timestamp(), ljid()},
- modification = {unknown, unknown} ,%:: {erlang:timestamp(), ljid()},
- payload = [] %:: mod_pubsub:payload()
+ itemid ,% :: {mod_pubsub:itemId(), mod_pubsub:nodeIdx()},
+ creation = {unknown, unknown},% :: {erlang:timestamp(), jlib:ljid()},
+ modification = {unknown, unknown},% :: {erlang:timestamp(), jlib:ljid()},
+ payload = [] % :: mod_pubsub:payload()
}).
-%% @type pubsubSubscription() = {pubsub_subscription, SubId, Options}
-%% SubId = subId()
-%% Options = [nodeOption()].
-%% <p>This is the format of the <tt>subscriptions</tt> table. The type of the
-%% table is: <tt>set</tt>,<tt>ram/disc</tt>.</p>
-%-record(pubsub_subscription, {subid, options}).
-record(pubsub_subscription,
{
- subid ,%:: mod_pubsub:subId(),
- options %:: [] | mod_pubsub:subOptions()
+ subid ,% :: mod_pubsub:subId(),
+ options = [] % :: mod_pubsub:subOptions()
}).
-%% @type pubsubLastItem() = {pubsub_last_item, NodeId, ItemId, Creation, Payload}
-%% NodeId = nodeIdx()
-%% ItemId = itemId()
-%% Creation = {now(),ljid()}
-%% Payload = payload().
-%% <p>This is the format of the <tt>last items</tt> table. it stores last item payload
-%% for every node</p>
-%-record(pubsub_last_item,
-% {nodeid, itemid, creation, payload}).
-
-record(pubsub_last_item,
{
- nodeid ,%:: mod_pubsub:nodeIdx(),
- itemid ,%:: mod_pubsub:itemId(),
- creation ,%:: {erlang:timestamp(), ljid()},
- payload %:: mod_pubsub:payload()
+ nodeid ,% :: mod_pubsub:nodeIdx(),
+ itemid ,% :: mod_pubsub:itemId(),
+ creation ,% :: {erlang:timestamp(), jlib:ljid()},
+ payload % :: mod_pubsub:payload()
}).