24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-14 22:00:16 +02:00

prosody2ejabberd: Support PEP import

This commit is contained in:
Holger Weiss 2017-08-10 19:49:20 +02:00
parent fc7ba53c37
commit 7d3609d954

View File

@ -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,6 +67,16 @@ convert_dir(Path, Host, Type) ->
lists:foreach( lists:foreach(
fun(File) -> fun(File) ->
FilePath = filename:join(Path, File), FilePath = filename:join(Path, File),
case Type of
"pep" ->
case filelib:is_dir(FilePath) of
true ->
JID = list_to_binary(File ++ "@" ++ Host),
convert_dir(FilePath, JID, "pubsub");
false ->
ok
end;
_ ->
case eval_file(FilePath) of case eval_file(FilePath) of
{ok, Data} -> {ok, Data} ->
Name = iolist_to_binary(filename:rootname(File)), Name = iolist_to_binary(filename:rootname(File)),
@ -74,6 +84,7 @@ convert_dir(Path, Host, Type) ->
Err -> Err ->
Err Err
end end
end
end, Files); end, Files);
{error, enoent} -> {error, enoent} ->
ok; ok;
@ -213,10 +224,13 @@ 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),
case decode_pubsub_host(HostStr) of
Host when is_binary(Host);
is_tuple(Host) ->
Node = url_decode(NodeId), Node = url_decode(NodeId),
Type = node_type(Host, Node), Type = node_type(Host),
NodeData = convert_node_config(Host, Data), NodeData = convert_node_config(HostStr, Data),
DefaultConfig = mod_pubsub:config(Host, default_node_config, []), DefaultConfig = mod_pubsub:config(Host, default_node_config, []),
Owner = proplists:get_value(owner, NodeData), Owner = proplists:get_value(owner, NodeData),
Options = lists:foldl( Options = lists:foldl(
@ -248,10 +262,14 @@ convert_data(PubSub, "pubsub", NodeId, [Data]) ->
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 ~s on ~p:~n~p",
[Node, Host, NodeData]), [Node, Host, NodeData]),
Error Error
end; end;
Error ->
?ERROR_MSG("failed to import pubsub node: ~p", [Error]),
Error
end;
convert_data(_Host, _Type, _User, _Data) -> convert_data(_Host, _Type, _User, _Data) ->
ok. ok.
@ -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