mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
prosody2ejabberd: Support PEP import
This commit is contained in:
parent
fc7ba53c37
commit
7d3609d954
@ -50,7 +50,7 @@ from_dir(ProsodyDir) ->
|
|||||||
convert_dir(Path, Host, SubDir)
|
convert_dir(Path, Host, SubDir)
|
||||||
end, ["vcard", "accounts", "roster",
|
end, ["vcard", "accounts", "roster",
|
||||||
"private", "config", "offline",
|
"private", "config", "offline",
|
||||||
"privacy", "pubsub"])
|
"privacy", "pep", "pubsub"])
|
||||||
end, HostDirs);
|
end, HostDirs);
|
||||||
{error, Why} = Err ->
|
{error, Why} = Err ->
|
||||||
?ERROR_MSG("failed to list ~s: ~s",
|
?ERROR_MSG("failed to list ~s: ~s",
|
||||||
@ -67,12 +67,23 @@ convert_dir(Path, Host, Type) ->
|
|||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(File) ->
|
fun(File) ->
|
||||||
FilePath = filename:join(Path, File),
|
FilePath = filename:join(Path, File),
|
||||||
case eval_file(FilePath) of
|
case Type of
|
||||||
{ok, Data} ->
|
"pep" ->
|
||||||
Name = iolist_to_binary(filename:rootname(File)),
|
case filelib:is_dir(FilePath) of
|
||||||
convert_data(Host, Type, Name, Data);
|
true ->
|
||||||
Err ->
|
JID = list_to_binary(File ++ "@" ++ Host),
|
||||||
Err
|
convert_dir(FilePath, JID, "pubsub");
|
||||||
|
false ->
|
||||||
|
ok
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
case eval_file(FilePath) of
|
||||||
|
{ok, Data} ->
|
||||||
|
Name = iolist_to_binary(filename:rootname(File)),
|
||||||
|
convert_data(Host, Type, Name, Data);
|
||||||
|
Err ->
|
||||||
|
Err
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end, Files);
|
end, Files);
|
||||||
{error, enoent} ->
|
{error, enoent} ->
|
||||||
@ -213,43 +224,50 @@ convert_data(Host, "privacy", User, [Data]) ->
|
|||||||
end, Lists)},
|
end, Lists)},
|
||||||
mod_privacy:set_list(Priv);
|
mod_privacy:set_list(Priv);
|
||||||
convert_data(PubSub, "pubsub", NodeId, [Data]) ->
|
convert_data(PubSub, "pubsub", NodeId, [Data]) ->
|
||||||
Host = url_decode(PubSub),
|
HostStr = url_decode(PubSub),
|
||||||
Node = url_decode(NodeId),
|
case decode_pubsub_host(HostStr) of
|
||||||
Type = node_type(Host, Node),
|
Host when is_binary(Host);
|
||||||
NodeData = convert_node_config(Host, Data),
|
is_tuple(Host) ->
|
||||||
DefaultConfig = mod_pubsub:config(Host, default_node_config, []),
|
Node = url_decode(NodeId),
|
||||||
Owner = proplists:get_value(owner, NodeData),
|
Type = node_type(Host),
|
||||||
Options = lists:foldl(
|
NodeData = convert_node_config(HostStr, Data),
|
||||||
fun({_Opt, undefined}, Acc) ->
|
DefaultConfig = mod_pubsub:config(Host, default_node_config, []),
|
||||||
Acc;
|
Owner = proplists:get_value(owner, NodeData),
|
||||||
({Opt, Val}, Acc) ->
|
Options = lists:foldl(
|
||||||
lists:keystore(Opt, 1, Acc, {Opt, Val})
|
fun({_Opt, undefined}, Acc) ->
|
||||||
end, DefaultConfig, proplists:get_value(options, NodeData)),
|
Acc;
|
||||||
case mod_pubsub:tree_action(Host, create_node, [Host, Node, Type, Owner, Options, []]) of
|
({Opt, Val}, Acc) ->
|
||||||
{ok, Nidx} ->
|
lists:keystore(Opt, 1, Acc, {Opt, Val})
|
||||||
case mod_pubsub:node_action(Host, Type, create_node, [Nidx, Owner]) of
|
end, DefaultConfig, proplists:get_value(options, NodeData)),
|
||||||
{result, _} ->
|
case mod_pubsub:tree_action(Host, create_node, [Host, Node, Type, Owner, Options, []]) of
|
||||||
Access = open, % always allow subscriptions proplists:get_value(access_model, Options),
|
{ok, Nidx} ->
|
||||||
Publish = open, % always allow publications proplists:get_value(publish_model, Options),
|
case mod_pubsub:node_action(Host, Type, create_node, [Nidx, Owner]) of
|
||||||
MaxItems = proplists:get_value(max_items, Options),
|
{result, _} ->
|
||||||
Affiliations = proplists:get_value(affiliations, NodeData),
|
Access = open, % always allow subscriptions proplists:get_value(access_model, Options),
|
||||||
Subscriptions = proplists:get_value(subscriptions, NodeData),
|
Publish = open, % always allow publications proplists:get_value(publish_model, Options),
|
||||||
Items = proplists:get_value(items, NodeData),
|
MaxItems = proplists:get_value(max_items, Options),
|
||||||
[mod_pubsub:node_action(Host, Type, set_affiliation,
|
Affiliations = proplists:get_value(affiliations, NodeData),
|
||||||
[Nidx, Entity, Aff])
|
Subscriptions = proplists:get_value(subscriptions, NodeData),
|
||||||
|| {Entity, Aff} <- Affiliations, Entity =/= Owner],
|
Items = proplists:get_value(items, NodeData),
|
||||||
[mod_pubsub:node_action(Host, Type, subscribe_node,
|
[mod_pubsub:node_action(Host, Type, set_affiliation,
|
||||||
[Nidx, jid:make(Entity), Entity, Access, never, [], [], []])
|
[Nidx, Entity, Aff])
|
||||||
|| Entity <- Subscriptions],
|
|| {Entity, Aff} <- Affiliations, Entity =/= Owner],
|
||||||
[mod_pubsub:node_action(Host, Type, publish_item,
|
[mod_pubsub:node_action(Host, Type, subscribe_node,
|
||||||
[Nidx, Publisher, Publish, MaxItems, ItemId, Payload, []])
|
[Nidx, jid:make(Entity), Entity, Access, never, [], [], []])
|
||||||
|| {ItemId, Publisher, Payload} <- Items];
|
|| Entity <- Subscriptions],
|
||||||
|
[mod_pubsub:node_action(Host, Type, publish_item,
|
||||||
|
[Nidx, Publisher, Publish, MaxItems, ItemId, Payload, []])
|
||||||
|
|| {ItemId, Publisher, Payload} <- Items];
|
||||||
|
Error ->
|
||||||
|
Error
|
||||||
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
|
?ERROR_MSG("failed to import pubsub node ~s on ~p:~n~p",
|
||||||
|
[Node, Host, NodeData]),
|
||||||
Error
|
Error
|
||||||
end;
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
?ERROR_MSG("failed to import pubsub node ~s on host ~s:~n~p",
|
?ERROR_MSG("failed to import pubsub node: ~p", [Error]),
|
||||||
[Node, Host, NodeData]),
|
|
||||||
Error
|
Error
|
||||||
end;
|
end;
|
||||||
convert_data(_Host, _Type, _User, _Data) ->
|
convert_data(_Host, _Type, _User, _Data) ->
|
||||||
@ -383,10 +401,15 @@ url_decode(<<H, Tail/binary>>, Acc) ->
|
|||||||
url_decode(<<>>, Acc) ->
|
url_decode(<<>>, Acc) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
node_type(_Host, <<"urn:", _Tail/binary>>) -> <<"pep">>;
|
decode_pubsub_host(Host) ->
|
||||||
node_type(_Host, <<"http:", _Tail/binary>>) -> <<"pep">>;
|
try jid:decode(Host) of
|
||||||
node_type(_Host, <<"https:", _Tail/binary>>) -> <<"pep">>;
|
#jid{luser = <<>>, lserver = LServer} -> LServer;
|
||||||
node_type(Host, _) -> hd(mod_pubsub:plugins(Host)).
|
#jid{luser = LUser, lserver = LServer} -> {LUser, LServer, <<>>}
|
||||||
|
catch _:{bad_jid, _} -> bad_jid
|
||||||
|
end.
|
||||||
|
|
||||||
|
node_type({_U, _S, _R}) -> <<"pep">>;
|
||||||
|
node_type(Host) -> hd(mod_pubsub:plugins(Host)).
|
||||||
|
|
||||||
max_items(Config, Default) ->
|
max_items(Config, Default) ->
|
||||||
case round(proplists:get_value(<<"max_items">>, Config, Default)) of
|
case round(proplists:get_value(<<"max_items">>, Config, Default)) of
|
||||||
|
Loading…
Reference in New Issue
Block a user