Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify roster logic #359

Merged
merged 7 commits into from
Jan 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/ejabberd/src/gen_mod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

-export([start/0,
start_module/3,
start_backend_module/2,
stop_module/2,
stop_module_keep_config/2,
reload_module/3,
Expand Down Expand Up @@ -104,6 +105,26 @@ start_module(Host, Module, Opts0) ->
end
end.

-spec start_backend_module(module(), list()) -> no_return().
start_backend_module(Module, Opts) ->
ModuleStr = atom_to_list(Module),
BackendModuleStr = ModuleStr ++ "_backend",
Backend = gen_mod:get_opt(backend, Opts, mnesia),
{Mod, Code} = dynamic_compile:from_string(backend_code(ModuleStr, Backend)),
code:load_binary(Mod, BackendModuleStr ++ ".erl", Code).

-spec backend_code(string(), atom()) -> string().
backend_code(Module, Backend) when is_atom(Backend) ->
BackendModule = Module ++ "_backend",
lists:flatten(
["-module(",BackendModule,").
-export([backend/0]).

-spec backend() -> atom().
backend() ->",
Module,"_",
atom_to_list(Backend),
".\n"]).

-spec is_app_running(_) -> boolean().
is_app_running(AppName) ->
Expand Down
23 changes: 1 addition & 22 deletions apps/ejabberd/src/mod_last.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),

start_backend_module(Opts),
gen_mod:start_backend_module(?MODULE, Opts),
?BACKEND:init(Host, Opts),

gen_iq_handler:add_iq_handler(ejabberd_local, Host,
Expand All @@ -109,27 +109,6 @@ stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
?NS_LAST).

%% ------------------------------------------------------------------
%% Dynamic modules

start_backend_module(Opts) ->
Backend = gen_mod:get_opt(backend, Opts, mnesia),
{Mod, Code} = dynamic_compile:from_string(mod_last_backend(Backend)),
code:load_binary(Mod, "mod_last_backend.erl", Code).

-spec mod_last_backend(atom()) -> string().
mod_last_backend(Backend) when is_atom(Backend) ->
lists:flatten(
["-module(mod_last_backend).
-export([backend/0]).

-spec backend() -> atom().
backend() ->
mod_last_",
atom_to_list(Backend),
".\n"]).


%%%
%%% Uptime of ejabberd node
%%%
Expand Down
21 changes: 1 addition & 20 deletions apps/ejabberd/src/mod_offline.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
start(Host, Opts) ->
AccessMaxOfflineMsgs = gen_mod:get_opt(access_max_user_messages, Opts,
max_user_offline_messages),
start_backend_module(Opts),
gen_mod:start_backend_module(?MODULE, Opts),
?BACKEND:init(Host, Opts),
start_worker(Host, AccessMaxOfflineMsgs),
ejabberd_hooks:add(offline_message_hook, Host,
Expand Down Expand Up @@ -110,25 +110,6 @@ stop(Host) ->
ok.


%% Dynamic modules
%% ------------------------------------------------------------------

start_backend_module(Opts) ->
Backend = gen_mod:get_opt(backend, Opts, mnesia),
{Mod, Code} = dynamic_compile:from_string(mod_offline_backend(Backend)),
code:load_binary(Mod, "mod_offline_backend.erl", Code).

-spec mod_offline_backend(atom()) -> string().
mod_offline_backend(Backend) when is_atom(Backend) ->
lists:flatten(
["-module(mod_offline_backend).
-export([backend/0]).
-spec backend() -> atom().
backend() ->
mod_offline_",
atom_to_list(Backend),
".\n"]).

%% Server side functions
%% ------------------------------------------------------------------

Expand Down
21 changes: 1 addition & 20 deletions apps/ejabberd/src/mod_privacy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
%% ------------------------------------------------------------------

start(Host, Opts) ->
start_backend_module(Opts),
gen_mod:start_backend_module(?MODULE, Opts),
?BACKEND:init(Host, Opts),
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
ejabberd_hooks:add(privacy_iq_get, Host,
Expand Down Expand Up @@ -151,25 +151,6 @@ stop(Host) ->
?MODULE, remove_user, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PRIVACY).

%% Dynamic modules
%% ------------------------------------------------------------------

start_backend_module(Opts) ->
Backend = gen_mod:get_opt(backend, Opts, mnesia),
{Mod, Code} = dynamic_compile:from_string(mod_privacy_backend(Backend)),
code:load_binary(Mod, "mod_privacy_backend.erl", Code).

-spec mod_privacy_backend(atom()) -> string().
mod_privacy_backend(Backend) when is_atom(Backend) ->
lists:flatten(
["-module(mod_privacy_backend).
-export([backend/0]).
-spec backend() -> atom().
backend() ->
mod_privacy_",
atom_to_list(Backend),
".\n"]).

%% Handlers
%% ------------------------------------------------------------------

Expand Down
21 changes: 1 addition & 20 deletions apps/ejabberd/src/mod_private.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
%% gen_mod callbacks

start(Host, Opts) ->
start_backend_module(Opts),
gen_mod:start_backend_module(?MODULE, Opts),
?BACKEND:init(Host, Opts),
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 50),
Expand All @@ -84,25 +84,6 @@ stop(Host) ->
ejabberd_hooks:delete(anonymous_purge_hook, Host, ?MODULE, remove_user, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PRIVATE).

%% ------------------------------------------------------------------
%% Dynamic modules

start_backend_module(Opts) ->
Backend = gen_mod:get_opt(backend, Opts, mnesia),
{Mod, Code} = dynamic_compile:from_string(mod_private_backend(Backend)),
code:load_binary(Mod, "mod_private_backend.erl", Code).

-spec mod_private_backend(atom()) -> string().
mod_private_backend(Backend) when is_atom(Backend) ->
lists:flatten(
["-module(mod_private_backend).
-export([backend/0]).

-spec backend() -> atom().
backend() ->
mod_private_",
atom_to_list(Backend),
".\n"]).

%% ------------------------------------------------------------------
%% Handlers
Expand Down
Loading