mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
fix minor pubsub init glitch, and allow ejabberd_odbc to execute bloc of queries without transaction
SVN Revision: 2038
This commit is contained in:
parent
eab7a509f9
commit
bda111b145
@ -1,3 +1,11 @@
|
||||
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>
|
||||
|
||||
* src/mod_pubsub/mod_pubsub.erl: improve send last published items
|
||||
|
@ -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).
|
||||
@ -166,6 +166,14 @@ init([ServerHost, Opts]) ->
|
||||
PepOffline = gen_mod:get_opt(pep_sendlast_offline, Opts, false),
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
|
||||
{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, ServerHost, ?MODULE, disco_sm_identity, 75),
|
||||
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
||||
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
||||
@ -174,8 +182,6 @@ init([ServerHost, Opts]) ->
|
||||
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?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, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||
@ -186,14 +192,8 @@ init([ServerHost, Opts]) ->
|
||||
false ->
|
||||
ok
|
||||
end,
|
||||
ejabberd_router:register_route(Host),
|
||||
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),
|
||||
@ -189,6 +195,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}.
|
||||
@ -273,6 +290,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