25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

First pass of Exmpp conversion for mod_pubsub.

CAUTION:
o  Several modules aren't converted yet.
o  Existent Mnesia tables written to disc are not updated.
o  There must be bugs, mostly because of the mix between #jid record
and short JIDs.
PR:		EJABP-1

SVN Revision: 1705
This commit is contained in:
Jean-Sébastien Pédron 2008-12-05 15:13:09 +00:00
parent 6305ddca18
commit 163d185776
5 changed files with 528 additions and 527 deletions

View File

@ -7,6 +7,13 @@
* src/gen_iq_handler.erl: Add the module and function names to the * src/gen_iq_handler.erl: Add the module and function names to the
error message, when a module crash. error message, when a module crash.
* src/mod_pubsub/mod_pubsub.erl, src/mod_pubsub/nodetree_default.erl,
src/mod_pubsub/node_default.erl, src/mod_pubsub/node_pep.erl: First
pass of Exmpp conversion for mod_pubsub. Several modules aren't
converted yet. Existent Mnesia tables written to disc are not
updated. There must be bugs, mostly because of the mix between #jid
record and short JIDs.
2008-12-03 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-12-03 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/mod_proxy65/mod_proxy65_stream.erl, * src/mod_proxy65/mod_proxy65_stream.erl,

File diff suppressed because it is too large Load Diff

View File

@ -41,8 +41,9 @@
-module(node_default). -module(node_default).
-author('christophe.romain@process-one.net'). -author('christophe.romain@process-one.net').
-include_lib("exmpp/include/exmpp.hrl").
-include("pubsub.hrl"). -include("pubsub.hrl").
-include("jlib.hrl").
-behaviour(gen_pubsub_node). -behaviour(gen_pubsub_node).
@ -194,10 +195,10 @@ features() ->
%% ```check_create_user_permission(Host, Node, Owner, Access) -> %% ```check_create_user_permission(Host, Node, Owner, Access) ->
%% node_default:check_create_user_permission(Host, Node, Owner, Access).'''</p> %% node_default:check_create_user_permission(Host, Node, Owner, Access).'''</p>
create_node_permission(Host, ServerHost, Node, _ParentNode, Owner, Access) -> create_node_permission(Host, ServerHost, Node, _ParentNode, Owner, Access) ->
LOwner = jlib:jid_tolower(Owner), LOwner = jlib:short_prepd_jid(Owner),
{User, Server, _Resource} = LOwner, {User, Server, _Resource} = LOwner,
Allowed = case LOwner of Allowed = case LOwner of
{"", Host, ""} -> {undefined, Host, undefined} ->
true; % pubsub service always allowed true; % pubsub service always allowed
_ -> _ ->
case acl:match_rule(ServerHost, Access, LOwner) of case acl:match_rule(ServerHost, Access, LOwner) of
@ -219,7 +220,7 @@ create_node_permission(Host, ServerHost, Node, _ParentNode, Owner, Access) ->
%% Owner = mod_pubsub:jid() %% Owner = mod_pubsub:jid()
%% @doc <p></p> %% @doc <p></p>
create_node(Host, Node, Owner) -> create_node(Host, Node, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
mnesia:write(#pubsub_state{stateid = {OwnerKey, {Host, Node}}, mnesia:write(#pubsub_state{stateid = {OwnerKey, {Host, Node}},
affiliation = owner, subscription = none}), affiliation = owner, subscription = none}),
{result, {default, broadcast}}. {result, {default, broadcast}}.
@ -281,11 +282,10 @@ delete_node(Host, Removed) ->
%% <p>In the default plugin module, the record is unchanged.</p> %% <p>In the default plugin module, the record is unchanged.</p>
subscribe_node(Host, Node, Sender, Subscriber, AccessModel, subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
SendLast, PresenceSubscription, RosterGroup) -> SendLast, PresenceSubscription, RosterGroup) ->
SenderKey = jlib:jid_tolower(Sender), Authorized = (jlib:short_prepd_bare_jid(Sender) == jlib:short_bare_jid(Subscriber)),
Authorized = (jlib:jid_remove_resource(SenderKey) == jlib:jid_remove_resource(Subscriber)),
% TODO add some acl check for Authorized ? % TODO add some acl check for Authorized ?
State = case get_state(Host, Node, Subscriber) of State = case get_state(Host, Node, Subscriber) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, 'item-not-found'} ->
#pubsub_state{stateid = {Subscriber, {Host, Node}}}; % TODO: bug on Key ? #pubsub_state{stateid = {Subscriber, {Host, Node}}}; % TODO: bug on Key ?
{result, S} -> S {result, S} -> S
end, end,
@ -294,31 +294,31 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
if if
not Authorized -> not Authorized ->
%% JIDs do not match %% JIDs do not match
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "invalid-jid")}; {error, ?ERR_EXTENDED('bad-request', "invalid-jid")};
Affiliation == outcast -> Affiliation == outcast ->
%% Requesting entity is blocked %% Requesting entity is blocked
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
Subscription == pending -> Subscription == pending ->
%% Requesting entity has pending subscription %% Requesting entity has pending subscription
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "pending-subscription")}; {error, ?ERR_EXTENDED('not-authorized', "pending-subscription")};
(AccessModel == presence) and (not PresenceSubscription) -> (AccessModel == presence) and (not PresenceSubscription) ->
%% Entity is not authorized to create a subscription (presence subscription required) %% Entity is not authorized to create a subscription (presence subscription required)
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "presence-subscription-required")}; {error, ?ERR_EXTENDED('not-authorized', "presence-subscription-required")};
(AccessModel == roster) and (not RosterGroup) -> (AccessModel == roster) and (not RosterGroup) ->
%% Entity is not authorized to create a subscription (not in roster group) %% Entity is not authorized to create a subscription (not in roster group)
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-in-roster-group")}; {error, ?ERR_EXTENDED('not-authorized', "not-in-roster-group")};
(AccessModel == whitelist) -> % TODO: to be done (AccessModel == whitelist) -> % TODO: to be done
%% Node has whitelist access model %% Node has whitelist access model
{error, ?ERR_EXTENDED(?ERR_NOT_ALLOWED, "closed-node")}; {error, ?ERR_EXTENDED('not-allowed', "closed-node")};
(AccessModel == authorize) -> % TODO: to be done (AccessModel == authorize) -> % TODO: to be done
%% Node has authorize access model %% Node has authorize access model
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
%%MustPay -> %%MustPay ->
%% % Payment is required for a subscription %% % Payment is required for a subscription
%% {error, ?ERR_PAYMENT_REQUIRED}; %% {error, ?ERR_PAYMENT_REQUIRED};
%%ForbiddenAnonymous -> %%ForbiddenAnonymous ->
%% % Requesting entity is anonymous %% % Requesting entity is anonymous
%% {error, ?ERR_FORBIDDEN}; %% {error, 'forbidden'};
true -> true ->
NewSubscription = NewSubscription =
if if
@ -352,8 +352,8 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
%% Reason = mod_pubsub:stanzaError() %% Reason = mod_pubsub:stanzaError()
%% @doc <p>Unsubscribe the <tt>Subscriber</tt> from the <tt>Node</tt>.</p> %% @doc <p>Unsubscribe the <tt>Subscriber</tt> from the <tt>Node</tt>.</p>
unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) -> unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
SenderKey = jlib:jid_tolower(Sender), SenderKey = jlib:short_prepd_jid(Sender),
Match = jlib:jid_remove_resource(SenderKey) == jlib:jid_remove_resource(Subscriber), Match = jlib:short_prepd_bare_jid(Sender) == jlib:short_bare_jid(Subscriber),
Authorized = case Match of Authorized = case Match of
true -> true ->
true; true;
@ -364,23 +364,23 @@ unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
end end
end, end,
case get_state(Host, Node, Subscriber) of case get_state(Host, Node, Subscriber) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, 'item-not-found'} ->
%% Requesting entity is not a subscriber %% Requesting entity is not a subscriber
{error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST, "not-subscribed")}; {error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")};
{result, State} -> {result, State} ->
if if
%% Entity did not specify SubID %% Entity did not specify SubID
%%SubID == "", ?? -> %%SubID == "", ?? ->
%% {error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")}; %% {error, ?ERR_EXTENDED('bad-request', "subid-required")};
%% Invalid subscription identifier %% Invalid subscription identifier
%%InvalidSubID -> %%InvalidSubID ->
%% {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; %% {error, ?ERR_EXTENDED('not-acceptable', "invalid-subid")};
%% Requesting entity is not a subscriber %% Requesting entity is not a subscriber
State#pubsub_state.subscription == none -> State#pubsub_state.subscription == none ->
{error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST, "not-subscribed")}; {error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")};
%% Requesting entity is prohibited from unsubscribing entity %% Requesting entity is prohibited from unsubscribing entity
not Authorized -> not Authorized ->
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
true -> true ->
set_state(State#pubsub_state{subscription = none}), set_state(State#pubsub_state{subscription = none}),
{result, default} {result, default}
@ -427,9 +427,9 @@ unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
%% </p> %% </p>
%% <p>In the default plugin module, the record is unchanged.</p> %% <p>In the default plugin module, the record is unchanged.</p>
publish_item(Host, Node, Publisher, PublishModel, MaxItems, ItemId, Payload) -> publish_item(Host, Node, Publisher, PublishModel, MaxItems, ItemId, Payload) ->
PublisherKey = jlib:jid_tolower(jlib:jid_remove_resource(Publisher)), PublisherKey = jlib:short_prepd_bare_jid(Publisher),
State = case get_state(Host, Node, PublisherKey) of State = case get_state(Host, Node, PublisherKey) of
{error, ?ERR_ITEM_NOT_FOUND} -> #pubsub_state{stateid={PublisherKey, {Host, Node}}}; {error, 'item-not-found'} -> #pubsub_state{stateid={PublisherKey, {Host, Node}}};
{result, S} -> S {result, S} -> S
end, end,
#pubsub_state{affiliation = Affiliation, #pubsub_state{affiliation = Affiliation,
@ -441,12 +441,12 @@ publish_item(Host, Node, Publisher, PublishModel, MaxItems, ItemId, Payload) ->
or ((PublishModel == subscribers) or ((PublishModel == subscribers)
and (Subscription == subscribed))) -> and (Subscription == subscribed))) ->
%% Entity does not have sufficient privileges to publish to node %% Entity does not have sufficient privileges to publish to node
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
true -> true ->
PubId = {PublisherKey, now()}, PubId = {PublisherKey, now()},
%% TODO: check creation, presence, roster (EJAB-663) %% TODO: check creation, presence, roster (EJAB-663)
Item = case get_item(Host, Node, ItemId) of Item = case get_item(Host, Node, ItemId) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, 'item-not-found'} ->
#pubsub_item{itemid = {ItemId, {Host, Node}}, #pubsub_item{itemid = {ItemId, {Host, Node}},
creation = PubId, creation = PubId,
modification = PubId, modification = PubId,
@ -504,9 +504,9 @@ remove_extra_items(Host, Node, MaxItems, ItemIds) ->
%% <p>Default plugin: The user performing the deletion must be the node owner %% <p>Default plugin: The user performing the deletion must be the node owner
%% or a publisher.</p> %% or a publisher.</p>
delete_item(Host, Node, Publisher, ItemId) -> delete_item(Host, Node, Publisher, ItemId) ->
PublisherKey = jlib:jid_tolower(jlib:jid_remove_resource(Publisher)), PublisherKey = jlib:short_prepd_bare_jid(Publisher),
State = case get_state(Host, Node, PublisherKey) of State = case get_state(Host, Node, PublisherKey) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, 'item-not-found'} ->
#pubsub_state{stateid = {PublisherKey, {Host, Node}}}; #pubsub_state{stateid = {PublisherKey, {Host, Node}}};
{result, S} -> {result, S} ->
S S
@ -520,7 +520,7 @@ delete_item(Host, Node, Publisher, ItemId) ->
if if
not Allowed -> not Allowed ->
%% Requesting entity does not have sufficient privileges %% Requesting entity does not have sufficient privileges
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
true -> true ->
case get_item(Host, Node, ItemId) of case get_item(Host, Node, ItemId) of
{result, _} -> {result, _} ->
@ -530,7 +530,7 @@ delete_item(Host, Node, Publisher, ItemId) ->
{result, {default, broadcast}}; {result, {default, broadcast}};
_ -> _ ->
%% Non-existent node or item %% Non-existent node or item
{error, ?ERR_ITEM_NOT_FOUND} {error, 'item-not-found'}
end end
end. end.
@ -541,7 +541,7 @@ delete_item(Host, Node, Publisher, ItemId) ->
%% Node = mod_pubsub:pubsubNode() %% Node = mod_pubsub:pubsubNode()
%% Owner = mod_pubsub:jid() %% Owner = mod_pubsub:jid()
purge_node(Host, Node, Owner) -> purge_node(Host, Node, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
case get_state(Host, Node, OwnerKey) of case get_state(Host, Node, OwnerKey) of
{result, #pubsub_state{items = Items, affiliation = owner}} -> {result, #pubsub_state{items = Items, affiliation = owner}} ->
lists:foreach(fun(ItemId) -> lists:foreach(fun(ItemId) ->
@ -550,9 +550,9 @@ purge_node(Host, Node, Owner) ->
{result, {default, broadcast}}; {result, {default, broadcast}};
{result, _} -> {result, _} ->
%% Entity is not owner %% Entity is not owner
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
_ -> _ ->
{error, ?ERR_ITEM_NOT_FOUND} {error, 'item-not-found'}
end. end.
%% @spec (Host, JID) -> [{Node,Affiliation}] %% @spec (Host, JID) -> [{Node,Affiliation}]
@ -566,7 +566,7 @@ purge_node(Host, Node, Owner) ->
%% that will be added to the affiliation stored in the main %% that will be added to the affiliation stored in the main
%% <tt>pubsub_state</tt> table.</p> %% <tt>pubsub_state</tt> table.</p>
get_entity_affiliations(Host, Owner) -> get_entity_affiliations(Host, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
States = mnesia:match_object( States = mnesia:match_object(
#pubsub_state{stateid = {OwnerKey, {Host, '_'}}, #pubsub_state{stateid = {OwnerKey, {Host, '_'}},
_ = '_'}), _ = '_'}),
@ -585,7 +585,7 @@ get_node_affiliations(Host, Node) ->
{result, lists:map(Tr, States)}. {result, lists:map(Tr, States)}.
get_affiliation(Host, Node, Owner) -> get_affiliation(Host, Node, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
Affiliation = case get_state(Host, Node, OwnerKey) of Affiliation = case get_state(Host, Node, OwnerKey) of
{result, #pubsub_state{affiliation = A}} -> A; {result, #pubsub_state{affiliation = A}} -> A;
_ -> none _ -> none
@ -593,9 +593,9 @@ get_affiliation(Host, Node, Owner) ->
{result, Affiliation}. {result, Affiliation}.
set_affiliation(Host, Node, Owner, Affiliation) -> set_affiliation(Host, Node, Owner, Affiliation) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
Record = case get_state(Host, Node, OwnerKey) of Record = case get_state(Host, Node, OwnerKey) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, 'item-not-found'} ->
#pubsub_state{stateid = {OwnerKey, {Host, Node}}, #pubsub_state{stateid = {OwnerKey, {Host, Node}},
affiliation = Affiliation}; affiliation = Affiliation};
{result, State} -> {result, State} ->
@ -616,7 +616,7 @@ set_affiliation(Host, Node, Owner, Affiliation) ->
%% that will be added to the affiliation stored in the main %% that will be added to the affiliation stored in the main
%% <tt>pubsub_state</tt> table.</p> %% <tt>pubsub_state</tt> table.</p>
get_entity_subscriptions(Host, Owner) -> get_entity_subscriptions(Host, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
States = mnesia:match_object( States = mnesia:match_object(
#pubsub_state{stateid = {OwnerKey, {Host, '_'}}, #pubsub_state{stateid = {OwnerKey, {Host, '_'}},
_ = '_'}), _ = '_'}),
@ -635,7 +635,7 @@ get_node_subscriptions(Host, Node) ->
{result, lists:map(Tr, States)}. {result, lists:map(Tr, States)}.
get_subscription(Host, Node, Owner) -> get_subscription(Host, Node, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
Subscription = case get_state(Host, Node, OwnerKey) of Subscription = case get_state(Host, Node, OwnerKey) of
{result, #pubsub_state{subscription = S}} -> S; {result, #pubsub_state{subscription = S}} -> S;
_ -> none _ -> none
@ -643,9 +643,9 @@ get_subscription(Host, Node, Owner) ->
{result, Subscription}. {result, Subscription}.
set_subscription(Host, Node, Owner, Subscription) -> set_subscription(Host, Node, Owner, Subscription) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
Record = case get_state(Host, Node, OwnerKey) of Record = case get_state(Host, Node, OwnerKey) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, 'item-not-found'} ->
#pubsub_state{stateid = {OwnerKey, {Host, Node}}, #pubsub_state{stateid = {OwnerKey, {Host, Node}},
subscription = Subscription}; subscription = Subscription};
{result, State} -> {result, State} ->
@ -684,7 +684,7 @@ get_state(Host, Node, JID) ->
[State] when is_record(State, pubsub_state) -> [State] when is_record(State, pubsub_state) ->
{result, State}; {result, State};
_ -> _ ->
{error, ?ERR_ITEM_NOT_FOUND} {error, 'item-not-found'}
end. end.
%% @spec (State) -> ok | {error, Reason::stanzaError()} %% @spec (State) -> ok | {error, Reason::stanzaError()}
@ -693,7 +693,7 @@ get_state(Host, Node, JID) ->
set_state(State) when is_record(State, pubsub_state) -> set_state(State) when is_record(State, pubsub_state) ->
mnesia:write(State); mnesia:write(State);
set_state(_) -> set_state(_) ->
{error, ?ERR_INTERNAL_SERVER_ERROR}. {error, 'internal-server-error'}.
%% @spec (Host, Node) -> [Items] | [] %% @spec (Host, Node) -> [Items] | []
%% Host = mod_pubsub:host() %% Host = mod_pubsub:host()
@ -715,7 +715,7 @@ get_items(Host, Node, _From) ->
{result, Items}. {result, Items}.
get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) -> get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) ->
{Affiliation, Subscription} = {Affiliation, Subscription} =
case get_state(Host, Node, jlib:jid_tolower(jlib:jid_remove_resource(JID))) of case get_state(Host, Node, jlib:short_prepd_bare_jid(JID)) of
{result, #pubsub_state{affiliation = A, subscription = S}} -> {A, S}; {result, #pubsub_state{affiliation = A, subscription = S}} -> {A, S};
_ -> {none, none} _ -> {none, none}
end, end,
@ -723,28 +723,28 @@ get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubI
if if
%%SubID == "", ?? -> %%SubID == "", ?? ->
%% Entity has multiple subscriptions to the node but does not specify a subscription ID %% Entity has multiple subscriptions to the node but does not specify a subscription ID
%{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")}; %{error, ?ERR_EXTENDED('bad-request', "subid-required")};
%%InvalidSubID -> %%InvalidSubID ->
%% Entity is subscribed but specifies an invalid subscription ID %% Entity is subscribed but specifies an invalid subscription ID
%{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; %{error, ?ERR_EXTENDED('not-acceptable', "invalid-subid")};
Affiliation == outcast -> Affiliation == outcast ->
%% Requesting entity is blocked %% Requesting entity is blocked
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
(AccessModel == open) and (not Subscribed) -> (AccessModel == open) and (not Subscribed) ->
%% Entity is not subscribed %% Entity is not subscribed
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-subscribed")}; {error, ?ERR_EXTENDED('not-authorized', "not-subscribed")};
(AccessModel == presence) and (not PresenceSubscription) -> (AccessModel == presence) and (not PresenceSubscription) ->
%% Entity is not authorized to create a subscription (presence subscription required) %% Entity is not authorized to create a subscription (presence subscription required)
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "presence-subscription-required")}; {error, ?ERR_EXTENDED('not-authorized', "presence-subscription-required")};
(AccessModel == roster) and (not RosterGroup) -> (AccessModel == roster) and (not RosterGroup) ->
%% Entity is not authorized to create a subscription (not in roster group) %% Entity is not authorized to create a subscription (not in roster group)
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-in-roster-group")}; {error, ?ERR_EXTENDED('not-authorized', "not-in-roster-group")};
(AccessModel == whitelist) -> % TODO: to be done (AccessModel == whitelist) -> % TODO: to be done
%% Node has whitelist access model %% Node has whitelist access model
{error, ?ERR_EXTENDED(?ERR_NOT_ALLOWED, "closed-node")}; {error, ?ERR_EXTENDED('not-allowed', "closed-node")};
(AccessModel == authorize) -> % TODO: to be done (AccessModel == authorize) -> % TODO: to be done
%% Node has authorize access model %% Node has authorize access model
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
%%MustPay -> %%MustPay ->
%% % Payment is required for a subscription %% % Payment is required for a subscription
%% {error, ?ERR_PAYMENT_REQUIRED}; %% {error, ?ERR_PAYMENT_REQUIRED};
@ -763,11 +763,11 @@ get_item(Host, Node, ItemId) ->
[Item] when is_record(Item, pubsub_item) -> [Item] when is_record(Item, pubsub_item) ->
{result, Item}; {result, Item};
_ -> _ ->
{error, ?ERR_ITEM_NOT_FOUND} {error, 'item-not-found'}
end. end.
get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) -> get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) ->
{Affiliation, Subscription} = {Affiliation, Subscription} =
case get_state(Host, Node, jlib:jid_tolower(jlib:jid_remove_resource(JID))) of case get_state(Host, Node, jlib:short_prepd_bare_jid(JID)) of
{result, #pubsub_state{affiliation = A, subscription = S}} -> {A, S}; {result, #pubsub_state{affiliation = A, subscription = S}} -> {A, S};
_ -> {none, none} _ -> {none, none}
end, end,
@ -775,28 +775,28 @@ get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup
if if
%%SubID == "", ?? -> %%SubID == "", ?? ->
%% Entity has multiple subscriptions to the node but does not specify a subscription ID %% Entity has multiple subscriptions to the node but does not specify a subscription ID
%{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")}; %{error, ?ERR_EXTENDED('bad-request', "subid-required")};
%%InvalidSubID -> %%InvalidSubID ->
%% Entity is subscribed but specifies an invalid subscription ID %% Entity is subscribed but specifies an invalid subscription ID
%{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; %{error, ?ERR_EXTENDED('not-acceptable', "invalid-subid")};
Affiliation == outcast -> Affiliation == outcast ->
%% Requesting entity is blocked %% Requesting entity is blocked
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
(AccessModel == open) and (not Subscribed) -> (AccessModel == open) and (not Subscribed) ->
%% Entity is not subscribed %% Entity is not subscribed
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-subscribed")}; {error, ?ERR_EXTENDED('not-authorized', "not-subscribed")};
(AccessModel == presence) and (not PresenceSubscription) -> (AccessModel == presence) and (not PresenceSubscription) ->
%% Entity is not authorized to create a subscription (presence subscription required) %% Entity is not authorized to create a subscription (presence subscription required)
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "presence-subscription-required")}; {error, ?ERR_EXTENDED('not-authorized', "presence-subscription-required")};
(AccessModel == roster) and (not RosterGroup) -> (AccessModel == roster) and (not RosterGroup) ->
%% Entity is not authorized to create a subscription (not in roster group) %% Entity is not authorized to create a subscription (not in roster group)
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-in-roster-group")}; {error, ?ERR_EXTENDED('not-authorized', "not-in-roster-group")};
(AccessModel == whitelist) -> % TODO: to be done (AccessModel == whitelist) -> % TODO: to be done
%% Node has whitelist access model %% Node has whitelist access model
{error, ?ERR_EXTENDED(?ERR_NOT_ALLOWED, "closed-node")}; {error, ?ERR_EXTENDED('not-allowed', "closed-node")};
(AccessModel == authorize) -> % TODO: to be done (AccessModel == authorize) -> % TODO: to be done
%% Node has authorize access model %% Node has authorize access model
{error, ?ERR_FORBIDDEN}; {error, 'forbidden'};
%%MustPay -> %%MustPay ->
%% % Payment is required for a subscription %% % Payment is required for a subscription
%% {error, ?ERR_PAYMENT_REQUIRED}; %% {error, ?ERR_PAYMENT_REQUIRED};
@ -810,7 +810,7 @@ get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup
set_item(Item) when is_record(Item, pubsub_item) -> set_item(Item) when is_record(Item, pubsub_item) ->
mnesia:write(Item); mnesia:write(Item);
set_item(_) -> set_item(_) ->
{error, ?ERR_INTERNAL_SERVER_ERROR}. {error, 'internal-server-error'}.
%% @doc <p>Return the name of the node if known: Default is to return %% @doc <p>Return the name of the node if known: Default is to return
%% node id.</p> %% node id.</p>

View File

@ -29,9 +29,10 @@
-module(node_pep). -module(node_pep).
-author('christophe.romain@process-one.net'). -author('christophe.romain@process-one.net').
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("pubsub.hrl"). -include("pubsub.hrl").
-include("jlib.hrl").
-behaviour(gen_pubsub_node). -behaviour(gen_pubsub_node).
@ -111,10 +112,10 @@ features() ->
]. ].
create_node_permission(Host, ServerHost, _Node, _ParentNode, Owner, Access) -> create_node_permission(Host, ServerHost, _Node, _ParentNode, Owner, Access) ->
LOwner = jlib:jid_tolower(Owner), LOwner = jlib:short_prepd_jid(Owner),
{User, Server, _Resource} = LOwner, {User, Server, _Resource} = LOwner,
Allowed = case LOwner of Allowed = case LOwner of
{"", Host, ""} -> {undefined, Host, undefined} ->
true; % pubsub service always allowed true; % pubsub service always allowed
_ -> _ ->
case acl:match_rule(ServerHost, Access, LOwner) of case acl:match_rule(ServerHost, Access, LOwner) of
@ -167,21 +168,21 @@ purge_node(Host, Node, Owner) ->
node_default:purge_node(Host, Node, Owner). node_default:purge_node(Host, Node, Owner).
get_entity_affiliations(_Host, Owner) -> get_entity_affiliations(_Host, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
node_default:get_entity_affiliations(OwnerKey, Owner). node_default:get_entity_affiliations(OwnerKey, Owner).
get_node_affiliations(Host, Node) -> get_node_affiliations(Host, Node) ->
OwnerKey = jlib:jid_remove_resource(Host), OwnerKey = jlib:short_bare_jid(Host),
node_default:get_node_affiliations(OwnerKey, Node). node_default:get_node_affiliations(OwnerKey, Node).
get_affiliation(_Host, Node, Owner) -> get_affiliation(_Host, Node, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
node_default:get_affiliation(OwnerKey, Node, Owner). node_default:get_affiliation(OwnerKey, Node, Owner).
set_affiliation(_Host, Node, Owner, Affiliation) -> set_affiliation(_Host, Node, Owner, Affiliation) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
Record = case get_state(OwnerKey, Node, OwnerKey) of Record = case get_state(OwnerKey, Node, OwnerKey) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, 'item-not-found'} ->
#pubsub_state{stateid = {OwnerKey, {OwnerKey, Node}}, #pubsub_state{stateid = {OwnerKey, {OwnerKey, Node}},
affiliation = Affiliation}; affiliation = Affiliation};
{result, State} -> {result, State} ->

View File

@ -92,7 +92,7 @@ options() ->
set_node(Record) when is_record(Record, pubsub_node) -> set_node(Record) when is_record(Record, pubsub_node) ->
mnesia:write(Record); mnesia:write(Record);
set_node(_) -> set_node(_) ->
{error, ?ERR_INTERNAL_SERVER_ERROR}. {error, 'internal-server-error'}.
%% @spec (Host, Node) -> pubsubNode() | {error, Reason} %% @spec (Host, Node) -> pubsubNode() | {error, Reason}
%% Host = mod_pubsub:host() %% Host = mod_pubsub:host()
@ -100,7 +100,7 @@ set_node(_) ->
get_node(Host, Node) -> get_node(Host, Node) ->
case catch mnesia:read({pubsub_node, {Host, Node}}) of case catch mnesia:read({pubsub_node, {Host, Node}}) of
[Record] when is_record(Record, pubsub_node) -> Record; [Record] when is_record(Record, pubsub_node) -> Record;
[] -> {error, ?ERR_ITEM_NOT_FOUND}; [] -> {error, 'item-not-found'};
Error -> Error Error -> Error
end. end.
@ -134,7 +134,7 @@ get_subnodes_tree(Host, Node) ->
%% Owner = mod_pubsub:jid() %% Owner = mod_pubsub:jid()
%% Options = list() %% Options = list()
create_node(Key, Node, Type, Owner, Options) -> create_node(Key, Node, Type, Owner, Options) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), OwnerKey = jlib:short_prepd_bare_jid(Owner),
case mnesia:read({pubsub_node, {Key, Node}}) of case mnesia:read({pubsub_node, {Key, Node}}) of
[] -> [] ->
{ParentNode, ParentExists} = {ParentNode, ParentExists} =
@ -166,11 +166,11 @@ create_node(Key, Node, Type, Owner, Options) ->
options = Options}); options = Options});
false -> false ->
%% Requesting entity is prohibited from creating nodes %% Requesting entity is prohibited from creating nodes
{error, ?ERR_FORBIDDEN} {error, 'forbidden'}
end; end;
_ -> _ ->
%% NodeID already exists %% NodeID already exists
{error, ?ERR_CONFLICT} {error, 'conflict'}
end. end.
%% @spec (Key, Node) -> [mod_pubsub:node()] %% @spec (Key, Node) -> [mod_pubsub:node()]