mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-10 21:47:01 +02:00
* src/mod_pubsub/mod_pubsub.erl: Added suport for meta-node
"pubsub/nodes" SVN Revision: 122
This commit is contained in:
parent
e9fb1795d8
commit
e8bbcfeecd
|
@ -1,3 +1,8 @@
|
||||||
|
2003-07-09 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
|
* src/mod_pubsub/mod_pubsub.erl: Added suport for meta-node
|
||||||
|
"pubsub/nodes"
|
||||||
|
|
||||||
2003-07-08 Alexey Shchepin <alexey@sevcom.net>
|
2003-07-08 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
* src/mod_pubsub/mod_pubsub.erl: Most of functions now works
|
* src/mod_pubsub/mod_pubsub.erl: Most of functions now works
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
-define(NS_PUBSUB, "http://jabber.org/protocol/pubsub").
|
-define(NS_PUBSUB, "http://jabber.org/protocol/pubsub").
|
||||||
-define(NS_PUBSUB_EVENT, "http://jabber.org/protocol/pubsub#event").
|
-define(NS_PUBSUB_EVENT, "http://jabber.org/protocol/pubsub#event").
|
||||||
-define(NS_PUBSUB_OWNER, "http://jabber.org/protocol/pubsub#owner").
|
-define(NS_PUBSUB_OWNER, "http://jabber.org/protocol/pubsub#owner").
|
||||||
|
-define(NS_PUBSUB_NMI, "http://jabber.org/protocol/pubsub#node-meta-info").
|
||||||
|
|
||||||
-define(NS_STREAM, "http://etherx.jabber.org/streams").
|
-define(NS_STREAM, "http://etherx.jabber.org/streams").
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
init/2,
|
init/2,
|
||||||
stop/0,
|
stop/0,
|
||||||
% TODO: remove
|
% TODO: remove
|
||||||
create_new_node/2,
|
create_new_node/3,
|
||||||
publish_item/5,
|
publish_item/5,
|
||||||
delete_item/4]).
|
delete_item/4]).
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
-record(pubsub_node, {node, parent, info}).
|
-record(pubsub_node, {node, parent, info}).
|
||||||
-record(nodeinfo, {items = [],
|
-record(nodeinfo, {items = [],
|
||||||
|
options = [],
|
||||||
entities = ?DICT:new()
|
entities = ?DICT:new()
|
||||||
}).
|
}).
|
||||||
-record(entity, {affiliation = none,
|
-record(entity, {affiliation = none,
|
||||||
|
@ -48,11 +49,11 @@ start(Opts) ->
|
||||||
|
|
||||||
init(Host, ServedHosts) ->
|
init(Host, ServedHosts) ->
|
||||||
ejabberd_router:register_route(Host),
|
ejabberd_router:register_route(Host),
|
||||||
create_new_node(["pubsub"], {"", Host, ""}),
|
create_new_node(Host, ["pubsub"], {"", Host, ""}),
|
||||||
create_new_node(["pubsub", "nodes"], {"", Host, ""}),
|
create_new_node(Host, ["pubsub", "nodes"], {"", Host, ""}),
|
||||||
create_new_node(["home"], {"", Host, ""}),
|
create_new_node(Host, ["home"], {"", Host, ""}),
|
||||||
lists:foreach(fun(H) ->
|
lists:foreach(fun(H) ->
|
||||||
create_new_node(["home", H], {"", Host, ""})
|
create_new_node(Host, ["home", H], {"", Host, ""})
|
||||||
end, ServedHosts),
|
end, ServedHosts),
|
||||||
loop(Host).
|
loop(Host).
|
||||||
|
|
||||||
|
@ -72,6 +73,8 @@ loop(Host) ->
|
||||||
stop ->
|
stop ->
|
||||||
ejabberd_router:unregister_global_route(Host),
|
ejabberd_router:unregister_global_route(Host),
|
||||||
ok;
|
ok;
|
||||||
|
reload ->
|
||||||
|
?MODULE:loop(Host);
|
||||||
_ ->
|
_ ->
|
||||||
loop(Host)
|
loop(Host)
|
||||||
end.
|
end.
|
||||||
|
@ -393,7 +396,7 @@ iq_pubsub(Host, From, Type, SubEl) ->
|
||||||
Node = string:tokens(SNode, "/"),
|
Node = string:tokens(SNode, "/"),
|
||||||
case {Type, Name} of
|
case {Type, Name} of
|
||||||
{set, "create"} ->
|
{set, "create"} ->
|
||||||
create_new_node(Node, From);
|
create_new_node(Host, Node, From);
|
||||||
{set, "publish"} ->
|
{set, "publish"} ->
|
||||||
case xml:remove_cdata(Els) of
|
case xml:remove_cdata(Els) of
|
||||||
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
||||||
|
@ -427,6 +430,8 @@ iq_pubsub(Host, From, Type, SubEl) ->
|
||||||
get_entities(From, Node);
|
get_entities(From, Node);
|
||||||
{set, "entities"} ->
|
{set, "entities"} ->
|
||||||
set_entities(From, Node, xml:remove_cdata(Els));
|
set_entities(From, Node, xml:remove_cdata(Els));
|
||||||
|
%{get, "configure"} ->
|
||||||
|
% get_node_config(From, Node);
|
||||||
_ ->
|
_ ->
|
||||||
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}
|
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}
|
||||||
end;
|
end;
|
||||||
|
@ -435,8 +440,14 @@ iq_pubsub(Host, From, Type, SubEl) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-define(XFIELD(Type, Label, Var, Val),
|
||||||
|
{xmlelement, "field", [{"type", Type},
|
||||||
|
{"label", translate:translate(Lang, Label)},
|
||||||
|
{"var", Var}],
|
||||||
|
[{xmlelement, "value", [], [{xmlcdata, Val}]}]}).
|
||||||
|
|
||||||
create_new_node(Node, Owner) ->
|
|
||||||
|
create_new_node(Host, Node, Owner) ->
|
||||||
case Node of
|
case Node of
|
||||||
[] ->
|
[] ->
|
||||||
{error, ?ERR_CONFLICT};
|
{error, ?ERR_CONFLICT};
|
||||||
|
@ -474,10 +485,21 @@ create_new_node(Node, Owner) ->
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
case check_create_permission(Node, Owner) of
|
case check_create_permission(Host, Node, Owner) of
|
||||||
true ->
|
true ->
|
||||||
case mnesia:transaction(F) of
|
case mnesia:transaction(F) of
|
||||||
{atomic, ok} ->
|
{atomic, ok} ->
|
||||||
|
Lang = "",
|
||||||
|
broadcast_publish_item(
|
||||||
|
Host, ["pubsub", "nodes"], "",
|
||||||
|
[{xmlelement, "x",
|
||||||
|
[{"xmlns", ?NS_PUBSUB_EVENT},
|
||||||
|
{"type", "result"}],
|
||||||
|
[?XFIELD("hidden", "", "FORM_TYPE",
|
||||||
|
?NS_PUBSUB_NMI),
|
||||||
|
?XFIELD("jid-single", "Node Creator",
|
||||||
|
"creator",
|
||||||
|
jlib:jid_to_string(LOwner))]}]),
|
||||||
{result, []};
|
{result, []};
|
||||||
{atomic, {error, _} = Error} ->
|
{atomic, {error, _} = Error} ->
|
||||||
Error;
|
Error;
|
||||||
|
@ -870,6 +892,40 @@ set_entities(OJID, Node, EntitiesEls) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
%get_node_config(OJID, Node) ->
|
||||||
|
% Owner = jlib:jid_tolower(jlib:jid_remove_resource(OJID)),
|
||||||
|
% case catch mnesia:dirty_read(pubsub_node, Node) of
|
||||||
|
% [#pubsub_node{info = Info}] ->
|
||||||
|
% case get_affiliation(Info, Owner) of
|
||||||
|
% owner ->
|
||||||
|
% Entities = Info#nodeinfo.entities,
|
||||||
|
% EntitiesEls =
|
||||||
|
% ?DICT:fold(
|
||||||
|
% fun(JID,
|
||||||
|
% #entity{affiliation = Affiliation,
|
||||||
|
% subscription = Subscription},
|
||||||
|
% Acc) ->
|
||||||
|
% [{xmlelement, "entity",
|
||||||
|
% [{"jid", jlib:jid_to_string(JID)},
|
||||||
|
% {"affiliation",
|
||||||
|
% affiliation_to_string(Affiliation)},
|
||||||
|
% {"subscription",
|
||||||
|
% subscription_to_string(Subscription)}],
|
||||||
|
% []} | Acc]
|
||||||
|
% end, [], Entities),
|
||||||
|
% {result, [{xmlelement, "pubsub",
|
||||||
|
% [{"xmlns", ?NS_PUBSUB_EVENT}],
|
||||||
|
% [{xmlelement, "entities",
|
||||||
|
% [{"node", node_to_string(Node)}],
|
||||||
|
% EntitiesEls}]}]};
|
||||||
|
% _ ->
|
||||||
|
% {error, ?ERR_NOT_ALLOWED}
|
||||||
|
% end;
|
||||||
|
% _ ->
|
||||||
|
% {error, ?ERR_ITEM_NOT_FOUND}
|
||||||
|
% end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -910,13 +966,18 @@ subscription_to_string(Subscription) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
check_create_permission(Node, Owner) ->
|
check_create_permission(Host, Node, Owner) ->
|
||||||
{User, Server, _} = Owner,
|
if
|
||||||
case Node of
|
{"", Host, ""} == Owner ->
|
||||||
["home", Server, User | _] ->
|
|
||||||
true;
|
true;
|
||||||
_ ->
|
true ->
|
||||||
false
|
{User, Server, _} = Owner,
|
||||||
|
case Node of
|
||||||
|
["home", Server, User | _] ->
|
||||||
|
true;
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
insert_item(Info, ItemID, Publisher, Payload) ->
|
insert_item(Info, ItemID, Publisher, Payload) ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user