mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
*** empty log message ***
SVN Revision: 56
This commit is contained in:
parent
6599d1ecc5
commit
14f050331a
2
TODO
2
TODO
@ -9,3 +9,5 @@ SRV DNS records
|
|||||||
karma
|
karma
|
||||||
SSL
|
SSL
|
||||||
JEP-62,63 (?)
|
JEP-62,63 (?)
|
||||||
|
make roster set work in one transaction
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
% $Id$
|
% $Id$
|
||||||
|
|
||||||
|
override_acls.
|
||||||
|
|
||||||
{acl, admin, {user, "aleksey"}}.
|
{acl, admin, {user, "aleksey"}}.
|
||||||
{acl, admin, {user, "ermine"}}.
|
{acl, admin, {user, "ermine"}}.
|
||||||
{acl, admin, {user, "test"}}.
|
{acl, admin, {user, "test"}}.
|
||||||
|
@ -50,17 +50,18 @@ load_file(File) ->
|
|||||||
process_term(Term, State) ->
|
process_term(Term, State) ->
|
||||||
case Term of
|
case Term of
|
||||||
override_global ->
|
override_global ->
|
||||||
#state{override_global = true};
|
State#state{override_global = true};
|
||||||
override_local ->
|
override_local ->
|
||||||
#state{override_local = true};
|
State#state{override_local = true};
|
||||||
override_acls ->
|
override_acls ->
|
||||||
#state{override_acls = true};
|
State#state{override_acls = true};
|
||||||
{acl, ACLName, ACLData} ->
|
{acl, ACLName, ACLData} ->
|
||||||
#state{opts =
|
State#state{opts =
|
||||||
[acl:to_record(ACLName, ACLData) | State#state.opts]};
|
[acl:to_record(ACLName, ACLData) | State#state.opts]};
|
||||||
{access, RuleName, Rules} ->
|
{access, RuleName, Rules} ->
|
||||||
#state{opts = [#config{key = {access, RuleName}, value = Rules} |
|
State#state{opts = [#config{key = {access, RuleName},
|
||||||
State#state.opts]};
|
value = Rules} |
|
||||||
|
State#state.opts]};
|
||||||
{Opt, Val} ->
|
{Opt, Val} ->
|
||||||
add_option(Opt, Val, State)
|
add_option(Opt, Val, State)
|
||||||
end.
|
end.
|
||||||
@ -74,49 +75,49 @@ add_option(Opt, Val, State) ->
|
|||||||
end,
|
end,
|
||||||
case Table of
|
case Table of
|
||||||
config ->
|
config ->
|
||||||
#state{opts = [#config{key = Opt, value = Val} |
|
State#state{opts = [#config{key = Opt, value = Val} |
|
||||||
State#state.opts]};
|
State#state.opts]};
|
||||||
local_config ->
|
local_config ->
|
||||||
#state{opts = [#local_config{key = Opt, value = Val} |
|
State#state{opts = [#local_config{key = Opt, value = Val} |
|
||||||
State#state.opts]}
|
State#state.opts]}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
set_opts(State) ->
|
set_opts(State) ->
|
||||||
Opts = lists:reverse(State#state.opts),
|
Opts = lists:reverse(State#state.opts),
|
||||||
mnesia:transaction(
|
F = fun() ->
|
||||||
fun() ->
|
if
|
||||||
if
|
State#state.override_global ->
|
||||||
State#state.override_global ->
|
Ksg = mnesia:all_keys(config),
|
||||||
Ksg = mnesia:all_keys(config),
|
lists:foreach(fun(K) ->
|
||||||
lists:foreach(fun(K) ->
|
mnesia:delete({config, K})
|
||||||
mnesia:delete({config, K})
|
end, Ksg);
|
||||||
end, Ksg);
|
true ->
|
||||||
true ->
|
ok
|
||||||
ok
|
end,
|
||||||
end,
|
if
|
||||||
if
|
State#state.override_local ->
|
||||||
State#state.override_local ->
|
Ksl = mnesia:all_keys(local_config),
|
||||||
Ksl = mnesia:all_keys(local_config),
|
lists:foreach(fun(K) ->
|
||||||
lists:foreach(fun(K) ->
|
mnesia:delete({local_config, K})
|
||||||
mnesia:delete({local_config, K})
|
end, Ksl);
|
||||||
end, Ksl);
|
true ->
|
||||||
true ->
|
ok
|
||||||
ok
|
end,
|
||||||
end,
|
if
|
||||||
if
|
State#state.override_acls ->
|
||||||
State#state.override_acls ->
|
Ksa = mnesia:all_keys(acl),
|
||||||
Ksa = mnesia:all_keys(acl),
|
lists:foreach(fun(K) ->
|
||||||
lists:foreach(fun(K) ->
|
mnesia:delete({acl, K})
|
||||||
mnesia:delete({acl, K})
|
end, Ksa);
|
||||||
end, Ksa);
|
true ->
|
||||||
true ->
|
ok
|
||||||
ok
|
end,
|
||||||
end,
|
lists:foreach(fun(R) ->
|
||||||
lists:foreach(fun(R) ->
|
mnesia:write(R)
|
||||||
mnesia:write(R)
|
end, Opts)
|
||||||
end, Opts)
|
end,
|
||||||
end).
|
{atomic, _} = mnesia:transaction(F).
|
||||||
|
|
||||||
|
|
||||||
add_global_option(Opt, Val) ->
|
add_global_option(Opt, Val) ->
|
||||||
|
204
src/jd2ejd.erl
Normal file
204
src/jd2ejd.erl
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
%%% File : jd2ejd.erl
|
||||||
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
%%% Purpose : Import of jabberd1.4 user spool file
|
||||||
|
%%% Created : 2 Feb 2003 by Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
%%% Id : $Id$
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
-module(jd2ejd).
|
||||||
|
-author('alexey@sevcom.net').
|
||||||
|
-vsn('$Revision$ ').
|
||||||
|
|
||||||
|
-behaviour(gen_fsm).
|
||||||
|
|
||||||
|
%% External exports
|
||||||
|
-export([start/1, start/2, receiver/2]).
|
||||||
|
|
||||||
|
%% gen_fsm callbacks
|
||||||
|
-export([init/1,
|
||||||
|
wait_for_xdb/2,
|
||||||
|
xdb_data/2,
|
||||||
|
handle_event/3,
|
||||||
|
handle_sync_event/4,
|
||||||
|
code_change/4,
|
||||||
|
handle_info/3,
|
||||||
|
terminate/3]).
|
||||||
|
|
||||||
|
-include("ejabberd.hrl").
|
||||||
|
-include("namespaces.hrl").
|
||||||
|
|
||||||
|
-record(state, {socket, receiver,
|
||||||
|
user = "", server = ?MYNAME, resource = ""
|
||||||
|
}).
|
||||||
|
|
||||||
|
%-define(DBGFSM, true).
|
||||||
|
|
||||||
|
-ifdef(DBGFSM).
|
||||||
|
-define(FSMOPTS, [{debug, [trace]}]).
|
||||||
|
-else.
|
||||||
|
-define(FSMOPTS, []).
|
||||||
|
-endif.
|
||||||
|
|
||||||
|
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
%%% API
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
start(File) ->
|
||||||
|
User = filename:rootname(filename:basename(File)),
|
||||||
|
start(File, User).
|
||||||
|
|
||||||
|
start(File, User) ->
|
||||||
|
gen_fsm:start(?MODULE, [File, User], ?FSMOPTS).
|
||||||
|
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
%%% Callback functions from gen_fsm
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%% Func: init/1
|
||||||
|
%% Returns: {ok, StateName, StateData} |
|
||||||
|
%% {ok, StateName, StateData, Timeout} |
|
||||||
|
%% ignore |
|
||||||
|
%% {stop, StopReason}
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
init([File, User]) ->
|
||||||
|
%ReceiverPid = spawn(?MODULE, receiver, [Socket, self()]),
|
||||||
|
XMLStreamPid = xml_stream:start(self()),
|
||||||
|
{ok, Text} = file:read_file(File),
|
||||||
|
xml_stream:send_text(XMLStreamPid, Text),
|
||||||
|
{ok, wait_for_xdb, #state{user = User}}.
|
||||||
|
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%% Func: StateName/2
|
||||||
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
||||||
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||||
|
%% {stop, Reason, NewStateData}
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
wait_for_xdb({xmlstreamstart, Name, Attrs}, StateData) ->
|
||||||
|
case Name of
|
||||||
|
"xdb" ->
|
||||||
|
{next_state, xdb_data, StateData};
|
||||||
|
_ ->
|
||||||
|
{stop, normal, StateData}
|
||||||
|
end;
|
||||||
|
|
||||||
|
wait_for_xdb(closed, StateData) ->
|
||||||
|
{stop, normal, StateData}.
|
||||||
|
|
||||||
|
|
||||||
|
xdb_data({xmlstreamelement, El}, StateData) ->
|
||||||
|
{xmlelement, Name, Attrs, Els} = El,
|
||||||
|
Server = StateData#state.server,
|
||||||
|
From = {StateData#state.user,
|
||||||
|
Server,
|
||||||
|
""},
|
||||||
|
NewState =
|
||||||
|
case xml:get_attr_s("xmlns", Attrs) of
|
||||||
|
?NS_AUTH ->
|
||||||
|
Password = xml:get_tag_cdata(El),
|
||||||
|
ejabberd_auth:set_password(StateData#state.user, Password),
|
||||||
|
StateData;
|
||||||
|
?NS_ROSTER ->
|
||||||
|
%mod_roster:process_iq(From,
|
||||||
|
% {"", ?MYNAME, ""},
|
||||||
|
% {iq, "", set, ?NS_ROSTER, El}),
|
||||||
|
mod_roster:set_items(StateData#state.user, El),
|
||||||
|
StateData;
|
||||||
|
%?NS_REGISTER ->
|
||||||
|
% mod_register:process_iq(
|
||||||
|
% {"", "", ""}, {"", ?MYNAME, ""},
|
||||||
|
% {iq, "", set, ?NS_REGISTER, El}),
|
||||||
|
% User = xml:get_path_s(El, [{elem, "username"}, cdata]),
|
||||||
|
% io:format("user ~s~n", [User]),
|
||||||
|
% StateData;
|
||||||
|
XMLNS ->
|
||||||
|
io:format("Unknown namespace \"~s\"~n", [XMLNS]),
|
||||||
|
StateData
|
||||||
|
end,
|
||||||
|
{next_state, xdb_data, NewState};
|
||||||
|
|
||||||
|
xdb_data({xmlstreamend, Name}, StateData) ->
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
xdb_data(closed, StateData) ->
|
||||||
|
% TODO
|
||||||
|
{stop, normal, StateData}.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%% Func: StateName/3
|
||||||
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
||||||
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||||
|
%% {reply, Reply, NextStateName, NextStateData} |
|
||||||
|
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
|
||||||
|
%% {stop, Reason, NewStateData} |
|
||||||
|
%% {stop, Reason, Reply, NewStateData}
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%state_name(Event, From, StateData) ->
|
||||||
|
% Reply = ok,
|
||||||
|
% {reply, Reply, state_name, StateData}.
|
||||||
|
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%% Func: handle_event/3
|
||||||
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
||||||
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||||
|
%% {stop, Reason, NewStateData}
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
handle_event(Event, StateName, StateData) ->
|
||||||
|
{next_state, StateName, StateData}.
|
||||||
|
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%% Func: handle_sync_event/4
|
||||||
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
||||||
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||||
|
%% {reply, Reply, NextStateName, NextStateData} |
|
||||||
|
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
|
||||||
|
%% {stop, Reason, NewStateData} |
|
||||||
|
%% {stop, Reason, Reply, NewStateData}
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
handle_sync_event(Event, From, StateName, StateData) ->
|
||||||
|
Reply = ok,
|
||||||
|
{reply, Reply, StateName, StateData}.
|
||||||
|
|
||||||
|
code_change(OldVsn, StateName, StateData, Extra) ->
|
||||||
|
{ok, StateName, StateData}.
|
||||||
|
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%% Func: handle_info/3
|
||||||
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
||||||
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||||
|
%% {stop, Reason, NewStateData}
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
handle_info(_, StateName, StateData) ->
|
||||||
|
{next_state, StateName, StateData}.
|
||||||
|
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
%% Func: terminate/3
|
||||||
|
%% Purpose: Shutdown the fsm
|
||||||
|
%% Returns: any
|
||||||
|
%%----------------------------------------------------------------------
|
||||||
|
terminate(Reason, StateName, StateData) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
%%% Internal functions
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
receiver(Socket, C2SPid) ->
|
||||||
|
XMLStreamPid = xml_stream:start(C2SPid),
|
||||||
|
receiver(Socket, C2SPid, XMLStreamPid).
|
||||||
|
|
||||||
|
receiver(Socket, C2SPid, XMLStreamPid) ->
|
||||||
|
case gen_tcp:recv(Socket, 0) of
|
||||||
|
{ok, Text} ->
|
||||||
|
xml_stream:send_text(XMLStreamPid, Text),
|
||||||
|
receiver(Socket, C2SPid, XMLStreamPid);
|
||||||
|
{error, Reason} ->
|
||||||
|
exit(XMLStreamPid, closed),
|
||||||
|
gen_fsm:send_event(C2SPid, closed),
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
@ -58,7 +58,7 @@ process_local_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
|||||||
[{"code", "500"}],
|
[{"code", "500"}],
|
||||||
[{xmlcdata, "Internal Server Error"}]}]};
|
[{xmlcdata, "Internal Server Error"}]}]};
|
||||||
Res ->
|
Res ->
|
||||||
{iq, ID, error, XMLNS,
|
{iq, ID, result, XMLNS,
|
||||||
[{xmlelement, Name, Attrs, Res}]}
|
[{xmlelement, Name, Attrs, Res}]}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
get_subscription_lists/1,
|
get_subscription_lists/1,
|
||||||
in_subscription/3,
|
in_subscription/3,
|
||||||
out_subscription/3,
|
out_subscription/3,
|
||||||
|
set_items/2,
|
||||||
remove_user/1]).
|
remove_user/1]).
|
||||||
|
|
||||||
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
||||||
@ -470,3 +471,76 @@ remove_user(User) ->
|
|||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
set_items(User, SubEl) ->
|
||||||
|
{xmlelement, Name, Attrs, Els} = SubEl,
|
||||||
|
F = fun() ->
|
||||||
|
lists:foreach(fun(El) -> process_item_set_t(User, El) end, Els)
|
||||||
|
end,
|
||||||
|
mnesia:transaction(F).
|
||||||
|
|
||||||
|
process_item_set_t(User, XItem) ->
|
||||||
|
{xmlelement, Name, Attrs, Els} = XItem,
|
||||||
|
JID = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)),
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
|
case JID of
|
||||||
|
error ->
|
||||||
|
ok;
|
||||||
|
_ ->
|
||||||
|
LJID = jlib:jid_tolower(JID),
|
||||||
|
Res = mnesia:read({roster, {LUser, LJID}}),
|
||||||
|
Item = #roster{uj = {LUser, LJID},
|
||||||
|
user = LUser,
|
||||||
|
jid = JID},
|
||||||
|
Item1 = process_item_attrs_ws(Item, Attrs),
|
||||||
|
Item2 = process_item_els(Item1, Els),
|
||||||
|
case Item2#roster.subscription of
|
||||||
|
remove ->
|
||||||
|
mnesia:delete({roster, {LUser, LJID}});
|
||||||
|
_ ->
|
||||||
|
mnesia:write(Item2)
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
process_item_attrs_ws(Item, [{Attr, Val} | Attrs]) ->
|
||||||
|
case Attr of
|
||||||
|
"jid" ->
|
||||||
|
case jlib:string_to_jid(Val) of
|
||||||
|
error ->
|
||||||
|
process_item_attrs_ws(Item, Attrs);
|
||||||
|
JID ->
|
||||||
|
process_item_attrs_ws(Item#roster{jid = JID}, Attrs)
|
||||||
|
end;
|
||||||
|
"name" ->
|
||||||
|
process_item_attrs_ws(Item#roster{name = Val}, Attrs);
|
||||||
|
"subscription" ->
|
||||||
|
case Val of
|
||||||
|
"remove" ->
|
||||||
|
process_item_attrs_ws(Item#roster{subscription = remove},
|
||||||
|
Attrs);
|
||||||
|
"none" ->
|
||||||
|
process_item_attrs_ws(Item#roster{subscription = none},
|
||||||
|
Attrs);
|
||||||
|
"both" ->
|
||||||
|
process_item_attrs_ws(Item#roster{subscription = both},
|
||||||
|
Attrs);
|
||||||
|
"from" ->
|
||||||
|
process_item_attrs_ws(Item#roster{subscription = from},
|
||||||
|
Attrs);
|
||||||
|
"to" ->
|
||||||
|
process_item_attrs_ws(Item#roster{subscription = to},
|
||||||
|
Attrs);
|
||||||
|
_ ->
|
||||||
|
process_item_attrs_ws(Item, Attrs)
|
||||||
|
end;
|
||||||
|
"ask" ->
|
||||||
|
process_item_attrs_ws(Item, Attrs);
|
||||||
|
_ ->
|
||||||
|
XAttrs = Item#roster.xattrs,
|
||||||
|
process_item_attrs_ws(Item#roster{xattrs = [{Attr, Val} | XAttrs]},
|
||||||
|
Attrs)
|
||||||
|
end;
|
||||||
|
process_item_attrs_ws(Item, []) ->
|
||||||
|
Item.
|
||||||
|
Loading…
Reference in New Issue
Block a user