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)
|
||||
end, ["vcard", "accounts", "roster",
|
||||
"private", "config", "offline",
|
||||
"privacy", "pubsub"])
|
||||
"privacy", "pep", "pubsub"])
|
||||
end, HostDirs);
|
||||
{error, Why} = Err ->
|
||||
?ERROR_MSG("failed to list ~s: ~s",
|
||||
@ -67,6 +67,16 @@ convert_dir(Path, Host, Type) ->
|
||||
lists:foreach(
|
||||
fun(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
|
||||
{ok, Data} ->
|
||||
Name = iolist_to_binary(filename:rootname(File)),
|
||||
@ -74,6 +84,7 @@ convert_dir(Path, Host, Type) ->
|
||||
Err ->
|
||||
Err
|
||||
end
|
||||
end
|
||||
end, Files);
|
||||
{error, enoent} ->
|
||||
ok;
|
||||
@ -213,10 +224,13 @@ convert_data(Host, "privacy", User, [Data]) ->
|
||||
end, Lists)},
|
||||
mod_privacy:set_list(Priv);
|
||||
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),
|
||||
Type = node_type(Host, Node),
|
||||
NodeData = convert_node_config(Host, Data),
|
||||
Type = node_type(Host),
|
||||
NodeData = convert_node_config(HostStr, Data),
|
||||
DefaultConfig = mod_pubsub:config(Host, default_node_config, []),
|
||||
Owner = proplists:get_value(owner, NodeData),
|
||||
Options = lists:foldl(
|
||||
@ -248,10 +262,14 @@ convert_data(PubSub, "pubsub", NodeId, [Data]) ->
|
||||
Error
|
||||
end;
|
||||
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]),
|
||||
Error
|
||||
end;
|
||||
Error ->
|
||||
?ERROR_MSG("failed to import pubsub node: ~p", [Error]),
|
||||
Error
|
||||
end;
|
||||
convert_data(_Host, _Type, _User, _Data) ->
|
||||
ok.
|
||||
|
||||
@ -383,10 +401,15 @@ url_decode(<<H, Tail/binary>>, Acc) ->
|
||||
url_decode(<<>>, Acc) ->
|
||||
Acc.
|
||||
|
||||
node_type(_Host, <<"urn:", _Tail/binary>>) -> <<"pep">>;
|
||||
node_type(_Host, <<"http:", _Tail/binary>>) -> <<"pep">>;
|
||||
node_type(_Host, <<"https:", _Tail/binary>>) -> <<"pep">>;
|
||||
node_type(Host, _) -> hd(mod_pubsub:plugins(Host)).
|
||||
decode_pubsub_host(Host) ->
|
||||
try jid:decode(Host) of
|
||||
#jid{luser = <<>>, lserver = LServer} -> LServer;
|
||||
#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) ->
|
||||
case round(proplists:get_value(<<"max_items">>, Config, Default)) of
|
||||
|
Loading…
Reference in New Issue
Block a user