mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
fix minor pubsub init glitch, and allow ejabberd_odbc to execute bloc of queries without transaction
SVN Revision: 2039
This commit is contained in:
parent
1d44abfc8a
commit
6710d66a58
@ -1,3 +1,10 @@
|
||||
2009-04-24 Christophe Romain <christophe.romain@process-one.net>
|
||||
|
||||
* src/odbc/ejabberd_odbc.erl: allow to run query bloc as erlang
|
||||
function without transaction
|
||||
|
||||
* src/mod_pubsub/mod_pubsub.erl: do not register handlers and hooks
|
||||
while plugins and ets tables are not initialized.
|
||||
|
||||
2009-04-23 Christophe Romain <christophe.romain@process-one.net>
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
-module(mod_pubsub).
|
||||
-author('christophe.romain@process-one.net').
|
||||
-version('1.12-03').
|
||||
-version('1.12-04').
|
||||
|
||||
-behaviour(gen_server).
|
||||
-behaviour(gen_mod).
|
||||
@ -168,6 +168,14 @@ init([ServerHost, Opts]) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
ServerHostB = list_to_binary(ServerHost),
|
||||
mod_disco:register_feature(ServerHost, ?NS_PUBSUB_s),
|
||||
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
||||
ets:new(gen_mod:get_module_proc(Host, pubsub_state), [set, named_table]),
|
||||
ets:insert(gen_mod:get_module_proc(Host, pubsub_state), {nodetree, NodeTree}),
|
||||
ets:insert(gen_mod:get_module_proc(Host, pubsub_state), {plugins, Plugins}),
|
||||
ets:new(gen_mod:get_module_proc(ServerHost, pubsub_state), [set, named_table]),
|
||||
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {nodetree, NodeTree}),
|
||||
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {plugins, Plugins}),
|
||||
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {pep_mapping, PepMapping}),
|
||||
ejabberd_hooks:add(disco_sm_identity, ServerHostB, ?MODULE, disco_sm_identity, 75),
|
||||
ejabberd_hooks:add(disco_sm_features, ServerHostB, ?MODULE, disco_sm_features, 75),
|
||||
ejabberd_hooks:add(disco_sm_items, ServerHostB, ?MODULE, disco_sm_items, 75),
|
||||
@ -177,7 +185,6 @@ init([ServerHost, Opts]) ->
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHostB, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHostB, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc),
|
||||
ejabberd_router:register_route(Host),
|
||||
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
||||
case lists:member(?PEPNODE, Plugins) of
|
||||
true ->
|
||||
ejabberd_hooks:add(disco_local_identity, ServerHostB, ?MODULE, disco_local_identity, 75),
|
||||
@ -189,13 +196,6 @@ init([ServerHost, Opts]) ->
|
||||
ok
|
||||
end,
|
||||
update_database(Host),
|
||||
ets:new(gen_mod:get_module_proc(Host, pubsub_state), [set, named_table]),
|
||||
ets:insert(gen_mod:get_module_proc(Host, pubsub_state), {nodetree, NodeTree}),
|
||||
ets:insert(gen_mod:get_module_proc(Host, pubsub_state), {plugins, Plugins}),
|
||||
ets:new(gen_mod:get_module_proc(ServerHost, pubsub_state), [set, named_table]),
|
||||
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {nodetree, NodeTree}),
|
||||
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {plugins, Plugins}),
|
||||
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {pep_mapping, PepMapping}),
|
||||
init_nodes(Host, ServerHost),
|
||||
State = #state{host = Host,
|
||||
server_host = ServerHost,
|
||||
|
@ -34,6 +34,7 @@
|
||||
sql_query/2,
|
||||
sql_query_t/1,
|
||||
sql_transaction/2,
|
||||
sql_bloc/2,
|
||||
escape/1,
|
||||
escape_like/1,
|
||||
keep_alive/1]).
|
||||
@ -87,6 +88,11 @@ sql_transaction(Host, F) ->
|
||||
gen_server:call(ejabberd_odbc_sup:get_random_pid(Host),
|
||||
{sql_transaction, F}, ?TRANSACTION_TIMEOUT).
|
||||
|
||||
%% SQL bloc, based on a erlang anonymous function (F = fun)
|
||||
sql_bloc(Host, F) ->
|
||||
gen_server:call(ejabberd_odbc_sup:get_random_pid(Host),
|
||||
{sql_bloc, F}, ?TRANSACTION_TIMEOUT).
|
||||
|
||||
%% This function is intended to be used from inside an sql_transaction:
|
||||
sql_query_t(Query) ->
|
||||
State = get(?STATE_KEY),
|
||||
@ -192,6 +198,17 @@ handle_call({sql_transaction, F}, _From, State) ->
|
||||
Reply ->
|
||||
{reply, Reply, State}
|
||||
end;
|
||||
handle_call({sql_bloc, F}, _From, State) ->
|
||||
case execute_bloc(State, F) of
|
||||
% error returned by MySQL driver
|
||||
{error, "query timed out"} ->
|
||||
{stop, timeout, State};
|
||||
% error returned by MySQL driver
|
||||
{error, "Failed sending data on socket"++_} = Reply ->
|
||||
{stop, closed, Reply, State};
|
||||
Reply ->
|
||||
{reply, Reply, State}
|
||||
end;
|
||||
handle_call(_Request, _From, State) ->
|
||||
Reply = ok,
|
||||
{reply, Reply, State}.
|
||||
@ -276,6 +293,17 @@ execute_transaction(State, F, NRestarts, _Reason) ->
|
||||
{atomic, Res}
|
||||
end.
|
||||
|
||||
execute_bloc(State, F) ->
|
||||
put(?STATE_KEY, State),
|
||||
case catch F() of
|
||||
{aborted, Reason} ->
|
||||
{aborted, Reason};
|
||||
{'EXIT', Reason} ->
|
||||
{aborted, Reason};
|
||||
Res ->
|
||||
{atomic, Res}
|
||||
end.
|
||||
|
||||
%% == pure ODBC code
|
||||
|
||||
%% part of init/1
|
||||
|
Loading…
Reference in New Issue
Block a user