25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Support static_modules in mod_vcard, vcard_xupdate, version, http_bind and http_fileserver

This commit is contained in:
Badlop 2011-07-15 02:50:45 +02:00
parent ff8bd0c2ec
commit 06d4889586
6 changed files with 41 additions and 28 deletions

View File

@ -104,20 +104,21 @@
-define(PROCNAME, ejabberd_mod_vcard).
start(Host, Opts) ->
HostB = list_to_binary(Host),
start(Host, Opts) when is_list(Host) ->
start(list_to_binary(Host), Opts);
start(HostB, Opts) ->
Backend = gen_mod:get_opt(backend, Opts, mnesia),
gen_storage:create_table(Backend, HostB, vcard,
[{disc_only_copies, [node()]},
{odbc_host, Host},
{odbc_host, HostB},
{attributes, record_info(fields, vcard)},
{types, [{user_host, {text, text}}]}]),
gen_storage:create_table(Backend, HostB, vcard_search,
[{disc_copies, [node()]},
{odbc_host, Host},
{odbc_host, HostB},
{attributes, record_info(fields, vcard_search)},
{types, [{user_host, {text, text}}]}]),
update_tables(Host, Backend),
update_tables(HostB, Backend),
gen_storage:add_table_index(HostB, vcard_search, lusername),
gen_storage:add_table_index(HostB, vcard_search, lfn),
gen_storage:add_table_index(HostB, vcard_search, lfamily),
@ -147,10 +148,10 @@ start(Host, Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_sm, HostB, ?NS_VCARD,
?MODULE, process_sm_iq, IQDisc),
ejabberd_hooks:add(disco_sm_features, HostB, ?MODULE, get_sm_features, 50),
MyHost = gen_mod:expand_host_name(Host, Opts, "vjud"),
MyHost = gen_mod:expand_host_name(HostB, Opts, "vjud"),
Search = gen_mod:get_opt(search, Opts, true),
register(gen_mod:get_module_proc(Host, ?PROCNAME),
spawn(?MODULE, init, [MyHost, Host, Search])).
register(gen_mod:get_module_proc(HostB, ?PROCNAME),
spawn(?MODULE, init, [MyHost, HostB, Search])).
init(Host, ServerHost, Search) ->
@ -343,7 +344,7 @@ set_vcard(User, Server, VCARD) ->
})
end,
gen_storage:transaction(Server, vcard, F),
ejabberd_hooks:run(vcard_set, Server, [LUser, Server, VCARD])
ejabberd_hooks:run(vcard_set, Server, [User, Server, VCARD])
catch
_ ->
{error, badarg}
@ -755,6 +756,9 @@ remove_user(User, Server) when is_binary(User), is_binary(Server) ->
%%% Update tables
%%%
update_tables(global, Storage) ->
[update_tables(HostB, Storage) || HostB <- ejabberd_hosts:get_hosts(ejabberd)];
update_tables(Host, mnesia) ->
gen_storage_migration:migrate_mnesia(
Host, vcard,

View File

@ -26,8 +26,9 @@
%% gen_mod callbacks
%%====================================================================
start(Host, _Opts) ->
HostB = list_to_binary(Host),
start(Host, Opts) when is_list(Host) ->
start(list_to_binary(Host), Opts);
start(HostB, _Opts) ->
mnesia:create_table(vcard_xupdate,
[{disc_copies, [node()]},
{attributes, record_info(fields, vcard_xupdate)}]),
@ -65,7 +66,7 @@ vcard_set(User, Server, VCARD) ->
[] ->
remove_xupdate(User, Server);
BinVal ->
add_xupdate(User, Server, sha:sha(jlib:decode_base64(BinVal)))
add_xupdate(User, Server, list_to_binary(sha:sha(jlib:decode_base64(BinVal))))
end,
ejabberd_sm:force_update_presence(US).
@ -105,7 +106,7 @@ presence_with_xupdate(Stanza, User, Host) ->
build_xphotoel(User, Host) ->
Hash = get_xupdate(User, Host),
PhotoSubEls = case Hash of
Hash when is_list(Hash) ->
Hash when is_binary(Hash) ->
[exmpp_xml:cdata(Hash)];
_ ->
[]

View File

@ -38,10 +38,11 @@
-include("ejabberd.hrl").
start(Host, Opts) ->
start(Host, Opts) when is_list(Host) ->
start(list_to_binary(Host), Opts);
start(HostB, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, list_to_binary(Host), ?NS_SOFT_VERSION,
gen_iq_handler:add_iq_handler(ejabberd_local, HostB, ?NS_SOFT_VERSION,
?MODULE, process_local_iq, IQDisc).
stop(Host) ->

View File

@ -121,7 +121,7 @@
%% supervisor
start(XMPPDomain, Sid, Key, IP) ->
?DEBUG("Starting session", []),
SupervisorProc = gen_mod:get_module_proc(XMPPDomain, ?PROCNAME_MHB),
SupervisorProc = gen_mod:get_module_proc_existing(XMPPDomain, ?PROCNAME_MHB),
case catch supervisor:start_child(SupervisorProc, [Sid, Key, IP]) of
{ok, Pid} ->
{ok, Pid};

View File

@ -103,9 +103,11 @@ get_human_html_xmlel() ->
%%%----------------------------------------------------------------------
%%% BEHAVIOUR CALLBACKS
%%%----------------------------------------------------------------------
start(Host, _Opts) ->
start(Host, Opts) when is_list(Host) ->
start(list_to_binary(Host), Opts);
start(HostB, _Opts) ->
setup_database(),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB),
Proc = gen_mod:get_module_proc(HostB, ?PROCNAME_MHB),
ChildSpec =
{Proc,
{ejabberd_tmp_sup, start_link,

View File

@ -44,7 +44,7 @@
-export([process/2]).
%% ejabberd_hooks callbacks
-export([reopen_log/1]).
-export([reopen_log/0, reopen_log/1]).
-include("ejabberd.hrl").
-include("jlib.hrl").
@ -95,11 +95,13 @@
%% gen_mod callbacks
%%====================================================================
start(Host, Opts) ->
Proc = get_proc_name(Host),
start(Host, Opts) when is_list(Host) ->
start(list_to_binary(Host), Opts);
start(HostB, Opts) ->
Proc = get_proc_name(HostB),
ChildSpec =
{Proc,
{?MODULE, start_link, [Host, Opts]},
{?MODULE, start_link, [HostB, Opts]},
transient, % if process crashes abruptly, it gets restarted
1000,
worker,
@ -205,7 +207,7 @@ check_docroot_is_readable(DRInfo, DocRoot) ->
try_open_log(undefined, _Host) ->
undefined;
try_open_log(FN, Host) ->
try_open_log(FN, HostB) ->
FD = try open_log(FN) of
FD1 -> FD1
catch
@ -213,7 +215,6 @@ try_open_log(FN, Host) ->
?ERROR_MSG("Cannot open access log file: ~p~nReason: ~p", [FN, Reason]),
undefined
end,
HostB = list_to_binary(Host),
ejabberd_hooks:add(reopen_log_hook, HostB, ?MODULE, reopen_log, 50),
FD.
@ -287,7 +288,7 @@ code_change(_OldVsn, State, _Extra) ->
%% Returns the page to be sent back to the client and/or HTTP status code.
process(LocalPath, Request) ->
?DEBUG("Requested ~p", [LocalPath]),
try gen_server:call(get_proc_name(Request#request.host), {serve, LocalPath}) of
try gen_server:call(get_proc_name_existing(Request#request.host), {serve, LocalPath}) of
{FileSize, Code, Headers, Contents} ->
add_to_log(FileSize, Code, Request),
{Code, Headers, Contents}
@ -359,11 +360,14 @@ reopen_log(FN, FD) ->
close_log(FD),
open_log(FN).
reopen_log() ->
%% This function is called when the hook was registered for host 'global'
gen_server:cast(get_proc_name_existing(global), reopen_log).
reopen_log(Host) ->
gen_server:cast(get_proc_name(Host), reopen_log).
gen_server:cast(get_proc_name_existing(Host), reopen_log).
add_to_log(FileSize, Code, Request) ->
gen_server:cast(get_proc_name(Request#request.host),
gen_server:cast(get_proc_name_existing(Request#request.host),
{add_to_log, FileSize, Code, Request}).
add_to_log(undefined, _FileSize, _Code, _Request) ->
@ -404,6 +408,7 @@ find_header(Header, Headers, Default) ->
%%----------------------------------------------------------------------
get_proc_name(Host) -> gen_mod:get_module_proc(Host, ?PROCNAME).
get_proc_name_existing(Host) -> gen_mod:get_module_proc_existing(Host, ?PROCNAME).
join([], _) ->
"";