Module node_flat_odbc [erl svg]

The module node_flat_odbc is the default PubSub plugin.

Copyright © 2006-2012 ProcessOne

Version: 3.0.0-alpha-5, May 23 2012 07:15:12

Behaviours: gen_pubsub_node.

Authors: Christophe Romain (christophe.romain@process-one.net) [web site: http://www.process-one.net/].

To do

Description

The module node_flat_odbc is the default PubSub plugin.

It is used as a default for all unknown PubSub node type. It can serve as a developer basis and reference to build its own custom pubsub node types.

PubSub plugin nodes are using the gen_node behaviour.

The API isn't stabilized yet. The pubsub plugin development is still a work in progress. However, the system is already useable and useful as is. Please, send us comments, feedback and improvements.

TODO : fix SQL requests with nodeid/id and id/idx changes

Function Index

can_fetch_item/2*Determines if the combination of Affiliation and Subscribed are allowed to get items from a node.
create_node/2
create_node_permission/6Checks if the current user has the permission to create the requested node.
decode_affiliation/1
decode_jid/1
decode_node/1
decode_subscription/1
decode_subscriptions/1
del_item/2*Delete an item from database.
del_items/2*
del_state/2*Delete a state from database.
delete_item/4Triggers item deletion.
delete_node/1purge items of deleted nodes after effective deletion.
delete_subscription/5*
encode_affiliation/1
encode_jid/1
encode_subscription/1
encode_subscriptions/1
features/0Returns the node features.
first_in_list/2*
get_affiliation/2
get_entity_affiliations/2Return the current affiliations for the given user.
get_entity_subscriptions/2Return the current subscriptions for the given user.
get_entity_subscriptions_for_send_last/2
get_item/2Returns an item (one item list), given its reference.
get_item/7
get_item_name/3Return the name of the node if known: Default is to return node id.
get_items/2Returns the list of stored items for a given node.
get_items/3
get_items/6
get_items/7
get_last_items/3
get_node_affiliations/1
get_node_subscriptions/1
get_nodes_helper/2*
get_pending_nodes/2Returns a list of Owner's nodes on Host with pending subscriptions.
get_state/2Returns a state (one state list), given its reference.
get_state_without_itemids/2*
get_states/1Returns the list of stored states for a given node.
get_subscriptions/2
i2l/1*
i2l/2*
init/3Called during pubsub modules initialisation.
is_subscribed/1*
itemids/2*
l2i/1*
new_subscription/4*
node_to_path/1
options/0Returns the default pubsub node options.
path_to_node/1
publish_item/6Publishes the item passed as parameter.
purge_node/2
raw_to_item/2*
remove_extra_items/3This function is used to remove extra items, most notably when the maximum number of items has been reached.
replace_subscription/2*
replace_subscription/3*
select_affiliation_subscriptions/2*
select_affiliation_subscriptions/3*
set_affiliation/3
set_item/1Write an item into database.
set_state/1Write a state into database.
set_state/2*
set_subscriptions/4
state_to_raw/2*
subscribe_node/8Accepts or rejects subcription requests on a PubSub node.
terminate/2Called during pubsub modules termination.
unsub_with_subid/3*
unsubscribe_node/4Unsubscribe the Subscriber from the Node.
update_affiliation/3*
update_subscription/3*

Function Details

can_fetch_item/2 *

can_fetch_item(Affiliation, Subscriptions::Subscription) -> true | false

Determines if the combination of Affiliation and Subscribed are allowed to get items from a node.

create_node/2

create_node(NodeId, Owner) -> {result, Result} | exit

create_node_permission/6

create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) -> bool()

Checks if the current user has the permission to create the requested node

In node_default, the permission is decided by the place in the hierarchy where the user is creating the node. The access parameter is also checked in the default module. This parameter depends on the value of the access_createnode ACL value in ejabberd config file.

This function also check that node can be created a a children of its parent node

PubSub plugins can redefine the PubSub node creation rights as they which. They can simply delegate this check to the node_default module by implementing this function like this:

     check_create_user_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
 	   node_default:check_create_user_permission(Host, ServerHost, Node, ParentNode, Owner, Access).

decode_affiliation/1

decode_affiliation(X1) -> any()

decode_jid/1

decode_jid(SJID) -> any()

decode_node/1

decode_node(N) -> any()

decode_subscription/1

decode_subscription(X1) -> any()

decode_subscriptions/1

decode_subscriptions(Subscriptions) -> any()

del_item/2 *

del_item(NodeId, ItemId) -> ok | {error, Reason::stanzaError()}

Delete an item from database.

del_items/2 *

del_items(NodeId, ItemIds) -> any()

del_state/2 *

del_state(NodeId, JID) -> ok | {error, Reason::stanzaError()}

Delete a state from database.

delete_item/4

delete_item(NodeId, Publisher, PublishModel, ItemId) -> {error, Reason::stanzaError()} | {result, []}

Triggers item deletion.

Default plugin: The user performing the deletion must be the node owner or a publisher, or PublishModel being open.

delete_node/1

delete_node(Removed) -> ok

purge items of deleted nodes after effective deletion.

delete_subscription/5 *

delete_subscription(SubKey, NodeId, X3, Affiliation, Subscriptions) -> any()

encode_affiliation/1

encode_affiliation(X1) -> any()

encode_jid/1

encode_jid(JID) -> any()

encode_subscription/1

encode_subscription(X1) -> any()

encode_subscriptions/1

encode_subscriptions(Subscriptions) -> any()

features/0

features() -> []

Returns the node features

first_in_list/2 *

first_in_list(Pred, T) -> any()

get_affiliation/2

get_affiliation(NodeId, Owner) -> any()

get_entity_affiliations/2

get_entity_affiliations(Host, Owner::JID) -> [{Node, Affiliation}]

Return the current affiliations for the given user

The default module reads affiliations in the main Mnesia pubsub_state table. If a plugin stores its data in the same table, it should return an empty list, as the affiliation will be read by the default PubSub module. Otherwise, it should return its own affiliation, that will be added to the affiliation stored in the main pubsub_state table.

get_entity_subscriptions/2

get_entity_subscriptions(Host, Owner) -> [{Node, Subscription}]

Return the current subscriptions for the given user

The default module reads subscriptions in the main Mnesia pubsub_state table. If a plugin stores its data in the same table, it should return an empty list, as the affiliation will be read by the default PubSub module. Otherwise, it should return its own affiliation, that will be added to the affiliation stored in the main pubsub_state table.

get_entity_subscriptions_for_send_last/2

get_entity_subscriptions_for_send_last(Host, Owner) -> any()

get_item/2

get_item(NodeId, ItemId) -> [Item] | []

Returns an item (one item list), given its reference.

get_item/7

get_item(NodeId, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) -> any()

get_item_name/3

get_item_name(Host, Node, Id) -> any()

Return the name of the node if known: Default is to return node id.

get_items/2

get_items(NodeId, From) -> {[Items], RsmOut} | []

Returns the list of stored items for a given node.

For the default PubSub module, items are stored in Mnesia database.

We can consider that the pubsub_item table have been created by the main mod_pubsub module.

PubSub plugins can store the items where they wants (for example in a relational database), or they can even decide not to persist any items.

If a PubSub plugin wants to delegate the item storage to the default node, they can implement this function like this:

     get_items(NodeId, From) ->
 	   node_default:get_items(NodeId, From).

get_items/3

get_items(NodeId, From, Rsm_in) -> any()

get_items/6

get_items(NodeId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) -> any()

get_items/7

get_items(NodeId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) -> any()

get_last_items/3

get_last_items(NodeId, From, Count) -> any()

get_node_affiliations/1

get_node_affiliations(NodeId) -> any()

get_node_subscriptions/1

get_node_subscriptions(NodeId) -> any()

get_nodes_helper/2 *

get_nodes_helper(NodeTree, Pubsub_state) -> any()

get_pending_nodes/2

get_pending_nodes(Host, Owner) -> {result, [Node]} | {error, Reason}

Returns a list of Owner's nodes on Host with pending subscriptions.

get_state/2

get_state(NodeId, JID) -> [State] | []

Returns a state (one state list), given its reference.

get_state_without_itemids/2 *

get_state_without_itemids(NodeId, JID) -> any()

get_states/1

get_states(NodeId) -> {result, [State] | []}

Returns the list of stored states for a given node.

For the default PubSub module, states are stored in Mnesia database.

We can consider that the pubsub_state table have been created by the main mod_pubsub module.

PubSub plugins can store the states where they wants (for example in a relational database).

If a PubSub plugin wants to delegate the states storage to the default node, they can implement this function like this:

     get_states(NodeId) ->
 	   node_default:get_states(NodeId).

get_subscriptions/2

get_subscriptions(NodeId, Owner) -> any()

i2l/1 *

i2l(I) -> any()

i2l/2 *

i2l(I, N) -> any()

init/3

init(Host, ServerHost, Opts) -> any()

Called during pubsub modules initialisation. Any pubsub plugin must implement this function. It can return anything.

This function is mainly used to trigger the setup task necessary for the plugin. It can be used for example by the developer to create the specific module database schema if it does not exists yet.

is_subscribed/1 *

is_subscribed(Subscriptions) -> any()

itemids/2 *

itemids(NodeId, SJID) -> any()

l2i/1 *

l2i(L) -> any()

new_subscription/4 *

new_subscription(NodeId, Owner, Subscription, SubState) -> any()

node_to_path/1

node_to_path(Node) -> any()

options/0

options() -> [Option]

Returns the default pubsub node options.

Example of function return value:

 	 [{deliver_payloads, true},
 	  {notify_config, false},
 	  {notify_delete, false},
 	  {notify_retract, true},
 	  {persist_items, true},
 	  {max_items, 10},
 	  {subscribe, true},
 	  {access_model, open},
 	  {publish_model, publishers},
 	  {max_payload_size, 100000},
 	  {send_last_published_item, never},
 	  {presence_based_delivery, false}]

path_to_node/1

path_to_node(Path) -> any()

publish_item/6

publish_item(NodeId, Publisher, PublishModel, MaxItems, ItemId, Payload) -> {true, PubsubItem} | {result, Reply}

Publishes the item passed as parameter.

The mechanism works as follow:

The selected behaviour depends on the return parameter:

In the default plugin module, the record is unchanged.

purge_node/2

purge_node(NodeId, Owner) -> {error, Reason::stanzaError()} | {result, {default, broadcast}}

raw_to_item/2 *

raw_to_item(NodeId, X2) -> any()

remove_extra_items/3

remove_extra_items(NodeId, MaxItems, ItemIds) -> {NewItemIds, OldItemIds}

This function is used to remove extra items, most notably when the maximum number of items has been reached.

This function is used internally by the core PubSub module, as no permission check is performed.

In the default plugin module, the oldest items are removed, but other rules can be used.

If another PubSub plugin wants to delegate the item removal (and if the plugin is using the default pubsub storage), it can implements this function like this:

     remove_extra_items(NodeId, MaxItems, ItemIds) ->
 	   node_default:remove_extra_items(NodeId, MaxItems, ItemIds).

replace_subscription/2 *

replace_subscription(NewSub, SubState) -> any()

replace_subscription/3 *

replace_subscription(X1, T, Acc) -> any()

select_affiliation_subscriptions/2 *

select_affiliation_subscriptions(NodeId, JID) -> any()

select_affiliation_subscriptions/3 *

select_affiliation_subscriptions(NodeId, JID, SubKey) -> any()

set_affiliation/3

set_affiliation(NodeId, Owner, Affiliation) -> any()

set_item/1

set_item(Item) -> ok | {error, Reason::stanzaError()}

Write an item into database.

set_state/1

set_state(State) -> ok | {error, Reason::stanzaError()}

Write a state into database.

set_state/2 *

set_state(NodeId, State) -> any()

set_subscriptions/4

set_subscriptions(NodeId, Owner, Subscription, SubId) -> any()

state_to_raw/2 *

state_to_raw(NodeId, State) -> any()

subscribe_node/8

subscribe_node(NodeId, Sender, Subscriber, AccessModel, SendLast, PresenceSubscription, RosterGroup, Options) -> {error, Reason} | {result, Result}

Accepts or rejects subcription requests on a PubSub node.

The mechanism works as follow:

The selected behaviour depends on the return parameter:

In the default plugin module, the record is unchanged.

terminate/2

terminate(Host, ServerHost) -> any()

Called during pubsub modules termination. Any pubsub plugin must implement this function. It can return anything.

unsub_with_subid/3 *

unsub_with_subid(NodeId, SubId, SubState) -> any()

unsubscribe_node/4

unsubscribe_node(NodeId, Sender, Subscriber, SubId) -> {error, Reason} | {result, []}

Unsubscribe the Subscriber from the Node.

update_affiliation/3 *

update_affiliation(NodeId, JID, Affiliation) -> any()

update_subscription/3 *

update_subscription(NodeId, JID, Subscription) -> any()


Generated by EDoc, May 23 2012, 07:15:12.