2007-12-01 06:16:30 +01:00
|
|
|
%%% ====================================================================
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% ``The contents of this file are subject to the Erlang Public License,
|
|
|
|
%%% Version 1.1, (the "License"); you may not use this file except in
|
|
|
|
%%% compliance with the License. You should have received a copy of the
|
|
|
|
%%% Erlang Public License along with this software. If not, it can be
|
|
|
|
%%% retrieved via the world wide web at http://www.erlang.org/.
|
|
|
|
%%%
|
2013-03-14 10:33:02 +01:00
|
|
|
%%%
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% Software distributed under the License is distributed on an "AS IS"
|
|
|
|
%%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
%%% the License for the specific language governing rights and limitations
|
|
|
|
%%% under the License.
|
|
|
|
%%%
|
2013-03-14 10:33:02 +01:00
|
|
|
%%%
|
2008-07-31 13:18:49 +02:00
|
|
|
%%% The Initial Developer of the Original Code is ProcessOne.
|
2014-03-13 12:29:21 +01:00
|
|
|
%%% Portions created by ProcessOne are Copyright 2006-2014, ProcessOne
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% All Rights Reserved.''
|
2014-03-13 12:29:21 +01:00
|
|
|
%%% This software is copyright 2006-2014, ProcessOne.
|
2007-12-24 14:57:53 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2014-03-13 12:29:21 +01:00
|
|
|
%%% copyright 2006-2014 ProcessOne
|
2007-12-01 06:16:30 +01:00
|
|
|
%%%
|
|
|
|
%%% This file contains pubsub types definition.
|
|
|
|
%%% ====================================================================
|
|
|
|
|
|
|
|
%% -------------------------------
|
|
|
|
%% Pubsub constants
|
2013-03-14 10:33:02 +01:00
|
|
|
-define(ERR_EXTENDED(E, C),
|
|
|
|
mod_pubsub:extended_error(E, C)).
|
2007-12-01 06:16:30 +01:00
|
|
|
|
2009-09-23 17:56:06 +02:00
|
|
|
%% The actual limit can be configured with mod_pubsub's option max_items_node
|
|
|
|
-define(MAXITEMS, 10).
|
|
|
|
|
2007-12-01 06:16:30 +01:00
|
|
|
%% this is currently a hard limit.
|
|
|
|
%% Would be nice to have it configurable.
|
|
|
|
-define(MAX_PAYLOAD_SIZE, 60000).
|
|
|
|
|
|
|
|
%% -------------------------------
|
|
|
|
%% Pubsub types
|
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type hostPubsub() = string().
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(hostPubsub() :: binary()).
|
2010-10-21 11:14:24 +02:00
|
|
|
%% <p><tt>hostPubsub</tt> is the name of the PubSub service. For example, it can be
|
|
|
|
%% <tt>"pubsub.localhost"</tt>.</p>
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(hostPEP() :: {binary(), binary(), <<>>}).
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type hostPEP() = {User, Server, Resource}
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Resource = [].
|
|
|
|
%% <p>For example, it can be :
|
|
|
|
%% ```{"bob", "example.org", []}'''.</p>
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(host() :: hostPubsub() | hostPEP()).
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type host() = hostPubsub() | hostPEP().
|
2010-10-18 16:53:21 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(nodeId() :: binary()).
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @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:
|
2013-03-14 10:33:02 +01:00
|
|
|
%% of the current node. For example:
|
2010-10-18 16:53:21 +02:00
|
|
|
%% ```<<"/home/localhost/user">>'''</p>
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(nodeIdx() :: pos_integer()).
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @type nodeIdx() = integer().
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(itemId() :: binary()).
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @type itemId() = string().
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(subId() :: binary()).
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @type subId() = string().
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @type payload() = [#xmlelement{} | #xmlcdata{}].
|
|
|
|
|
|
|
|
%% @type stanzaError() = #xmlelement{}.
|
|
|
|
%% Example:
|
2013-03-14 10:33:02 +01:00
|
|
|
%% Example:
|
2010-10-18 16:53:21 +02:00
|
|
|
%% ```{xmlelement, "error",
|
|
|
|
%% [{"code", Code}, {"type", Type}],
|
|
|
|
%% [{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []}]}'''
|
|
|
|
%% @type pubsubIQResponse() = #xmlelement{}.
|
|
|
|
%% Example:
|
|
|
|
%% ```{xmlelement, "pubsub",
|
|
|
|
%% [{"xmlns", ?NS_PUBSUB_EVENT}],
|
|
|
|
%% [{xmlelement, "affiliations", [],
|
|
|
|
%% []}]}'''
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(nodeOption() ::
|
|
|
|
{Option::atom(),
|
|
|
|
Value::binary() | [binary()] | boolean() | non_neg_integer()
|
|
|
|
}).
|
|
|
|
|
|
|
|
-type(nodeOptions() :: [NodeOption::mod_pubsub:nodeOption(),...]).
|
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type nodeOption() = {Option, Value}
|
|
|
|
%% Option = atom()
|
2010-10-18 16:53:21 +02:00
|
|
|
%% Value = term().
|
|
|
|
%% Example:
|
|
|
|
%% ```{deliver_payloads, true}'''
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(subOption() ::
|
|
|
|
{Option::atom(),
|
|
|
|
Value::binary() | [binary()] | boolean()
|
|
|
|
}).
|
|
|
|
|
|
|
|
-type(subOptions() :: [SubOption::mod_pubsub:subOption(),...]).
|
|
|
|
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @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>
|
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type jid() = {jid, User, Server, Resource, LUser, LServer, LResource}
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Resource = string()
|
|
|
|
%% LUser = string()
|
|
|
|
%% LServer = string()
|
2010-10-18 16:53:21 +02:00
|
|
|
%% LResource = string().
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
%-type(ljid() :: {binary(), binary(), binary()}).
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type ljid() = {User, Server, Resource}
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
2010-10-18 16:53:21 +02:00
|
|
|
%% Resource = string().
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(affiliation() :: 'none'
|
|
|
|
| 'owner'
|
|
|
|
| 'publisher'
|
|
|
|
%| 'publish-only'
|
|
|
|
| 'member'
|
|
|
|
| 'outcast'
|
|
|
|
).
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @type affiliation() = 'none' | 'owner' | 'publisher' | 'publish-only' | 'member' | 'outcast'.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(subscription() :: 'none'
|
|
|
|
| 'pending'
|
|
|
|
| 'unconfigured'
|
|
|
|
| 'subscribed'
|
|
|
|
).
|
2010-10-18 16:53:21 +02:00
|
|
|
%% @type subscription() = 'none' | 'pending' | 'unconfigured' | 'subscribed'.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(accessModel() :: 'open'
|
|
|
|
| 'presence'
|
|
|
|
| 'roster'
|
|
|
|
| 'authorize'
|
|
|
|
| 'whitelist'
|
|
|
|
).
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type accessModel() = 'open' | 'presence' | 'roster' | 'authorize' | 'whitelist'.
|
2010-10-18 16:53:21 +02:00
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type pubsubIndex() = {pubsub_index, Index, Last, Free}
|
|
|
|
%% Index = atom()
|
|
|
|
%% Last = integer()
|
2010-10-18 16:53:21 +02:00
|
|
|
%% Free = [integer()].
|
|
|
|
%% internal pubsub index table
|
2013-03-14 10:33:02 +01:00
|
|
|
-type(publishModel() :: 'publishers'
|
|
|
|
| 'subscribers'
|
|
|
|
| 'open'
|
|
|
|
).
|
|
|
|
|
|
|
|
|
2010-10-18 16:53:21 +02:00
|
|
|
-record(pubsub_index,
|
|
|
|
{
|
2013-03-14 10:33:02 +01:00
|
|
|
index :: atom(),
|
|
|
|
last :: mod_pubsub:nodeIdx(),
|
|
|
|
free :: [mod_pubsub:nodeIdx()]
|
2007-12-01 06:16:30 +01:00
|
|
|
}).
|
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type pubsubNode() = {pubsub_node, NodeId, Id, Parents, Type, Owners, Options}
|
|
|
|
%% NodeId = {host() | ljid(), nodeId()}
|
|
|
|
%% Id = nodeIdx()
|
|
|
|
%% Parents = [nodeId()]
|
|
|
|
%% Type = nodeType()
|
|
|
|
%% Owners = [ljid()]
|
2010-10-18 16:53:21 +02:00
|
|
|
%% 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,
|
|
|
|
{
|
2013-03-14 10:33:02 +01:00
|
|
|
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()
|
2010-10-18 16:53:21 +02:00
|
|
|
}).
|
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type pubsubState() = {pubsub_state, StateId, Items, Affiliation, Subscriptions}
|
|
|
|
%% StateId = {ljid(), nodeIdx()}
|
|
|
|
%% Items = [itemId()]
|
|
|
|
%% Affiliation = affiliation()
|
2010-10-18 16:53:21 +02:00
|
|
|
%% 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>
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
%-record(pubsub_state,
|
|
|
|
% {stateid, items = [], affiliation = none,
|
|
|
|
% subscriptions = []}).
|
2010-10-18 16:53:21 +02:00
|
|
|
-record(pubsub_state,
|
|
|
|
{
|
2013-03-14 10:33:02 +01:00
|
|
|
stateid ,%:: {Entity::ljid(), NodeIdx::mod_pubsub:nodeIdx()},
|
|
|
|
items = [] ,%:: [ItemId::mod_pubsub:itemId()],
|
|
|
|
affiliation = 'none' ,%:: mod_pubsub:affiliation(),
|
|
|
|
subscriptions = [] %:: [{mod_pubsub:subscription(), mod_pubsub:subId()}]
|
2010-10-18 16:53:21 +02:00
|
|
|
}).
|
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type pubsubItem() = {pubsub_item, ItemId, Creation, Modification, Payload}
|
|
|
|
%% ItemId = {itemId(), nodeIdx()}
|
|
|
|
%% Creation = {now(), ljid()}
|
|
|
|
%% Modification = {now(), ljid()}
|
2010-10-18 16:53:21 +02:00
|
|
|
%% 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>
|
2013-03-14 10:33:02 +01:00
|
|
|
%-record(pubsub_item,
|
|
|
|
% {itemid, creation = {unknown, unknown},
|
|
|
|
% modification = {unknown, unknown}, payload = []}).
|
|
|
|
|
2010-10-18 16:53:21 +02:00
|
|
|
-record(pubsub_item,
|
|
|
|
{
|
2013-03-14 10:33:02 +01:00
|
|
|
itemid ,%:: {mod_pubsub:itemId(), mod_pubsub:nodeIdx()},
|
|
|
|
creation = {unknown, unknown} ,%:: {erlang:timestamp(), ljid()},
|
|
|
|
modification = {unknown, unknown} ,%:: {erlang:timestamp(), ljid()},
|
|
|
|
payload = [] %:: mod_pubsub:payload()
|
2010-10-18 16:53:21 +02:00
|
|
|
}).
|
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type pubsubSubscription() = {pubsub_subscription, SubId, Options}
|
|
|
|
%% SubId = subId()
|
2010-10-18 16:53:21 +02:00
|
|
|
%% Options = [nodeOption()].
|
2009-05-29 04:14:07 +02:00
|
|
|
%% <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>
|
2013-03-14 10:33:02 +01:00
|
|
|
%-record(pubsub_subscription, {subid, options}).
|
2010-10-18 16:53:21 +02:00
|
|
|
-record(pubsub_subscription,
|
|
|
|
{
|
2013-03-14 10:33:02 +01:00
|
|
|
subid ,%:: mod_pubsub:subId(),
|
|
|
|
options %:: [] | mod_pubsub:subOptions()
|
2010-10-18 16:53:21 +02:00
|
|
|
}).
|
2010-05-28 11:56:09 +02:00
|
|
|
|
2010-10-21 11:14:24 +02:00
|
|
|
%% @type pubsubLastItem() = {pubsub_last_item, NodeId, ItemId, Creation, Payload}
|
|
|
|
%% NodeId = nodeIdx()
|
|
|
|
%% ItemId = itemId()
|
|
|
|
%% Creation = {now(),ljid()}
|
2010-10-18 16:53:21 +02:00
|
|
|
%% Payload = payload().
|
2010-05-28 11:56:09 +02:00
|
|
|
%% <p>This is the format of the <tt>last items</tt> table. it stores last item payload
|
|
|
|
%% for every node</p>
|
2013-03-14 10:33:02 +01:00
|
|
|
%-record(pubsub_last_item,
|
|
|
|
% {nodeid, itemid, creation, payload}).
|
|
|
|
|
2010-10-18 16:53:21 +02:00
|
|
|
-record(pubsub_last_item,
|
|
|
|
{
|
2013-03-14 10:33:02 +01:00
|
|
|
nodeid ,%:: mod_pubsub:nodeIdx(),
|
|
|
|
itemid ,%:: mod_pubsub:itemId(),
|
|
|
|
creation ,%:: {erlang:timestamp(), ljid()},
|
|
|
|
payload %:: mod_pubsub:payload()
|
2010-10-18 16:53:21 +02:00
|
|
|
}).
|