mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
o In start/2 and stop/1, the IQ registration must use a namespace as
atom, not list. o The functions process_local_iq/3, process_sm_iq/3 and get_last/3 receive an #iq, not an #xmlel. o In store_last_info/4 and remove_user/2, add try/catch block around exmpp_stringprep:*prep/1 uses. SVN Revision: 1594
This commit is contained in:
parent
9e018532c8
commit
1698b8ec04
@ -12,6 +12,13 @@
|
|||||||
defaults to the atom "undefined", not an empty binary. Fix a bug where
|
defaults to the atom "undefined", not an empty binary. Fix a bug where
|
||||||
we expected an #xmlelement to have only one #xmlcdata child.
|
we expected an #xmlelement to have only one #xmlcdata child.
|
||||||
|
|
||||||
|
* src/mod_last_odbc.erl (start/2, stop/1): The IQ registration must
|
||||||
|
use a namespace as atom, not list.
|
||||||
|
(process_local_iq/3, process_sm_iq/3, get_last/3): These functions
|
||||||
|
receive an #iq, not an #xmlel.
|
||||||
|
(store_last_info/4, remove_user/2): Add try/catch block around
|
||||||
|
exmpp_stringprep:*prep/1 uses.
|
||||||
|
|
||||||
2008-10-01 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-10-01 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
* src/mod_offline_odbc.erl, src/mod_vcard_odbc.erl,
|
* src/mod_offline_odbc.erl, src/mod_vcard_odbc.erl,
|
||||||
|
@ -45,9 +45,9 @@
|
|||||||
|
|
||||||
start(Host, Opts) ->
|
start(Host, Opts) ->
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY_s,
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY,
|
||||||
?MODULE, process_local_iq, IQDisc),
|
?MODULE, process_local_iq, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY_s,
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY,
|
||||||
?MODULE, process_sm_iq, IQDisc),
|
?MODULE, process_sm_iq, IQDisc),
|
||||||
ejabberd_hooks:add(remove_user, Host,
|
ejabberd_hooks:add(remove_user, Host,
|
||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
@ -59,60 +59,54 @@ stop(Host) ->
|
|||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:delete(unset_presence_hook, Host,
|
ejabberd_hooks:delete(unset_presence_hook, Host,
|
||||||
?MODULE, on_presence_update, 50),
|
?MODULE, on_presence_update, 50),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY_s),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY_s).
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY).
|
||||||
|
|
||||||
process_local_iq(_From, _To, IQ) ->
|
process_local_iq(_From, _To, #iq{type = get} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
Sec = trunc(element(1, erlang:statistics(wall_clock))/1000),
|
||||||
set ->
|
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', attrs =
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
[#xmlattr{name = 'seconds', value = integer_to_list(Sec)}]},
|
||||||
get ->
|
exmpp_iq:result(IQ_Rec, Response);
|
||||||
Sec = trunc(element(1, erlang:statistics(wall_clock))/1000),
|
process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', attrs =
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
[#xmlattr{name = 'seconds', value = integer_to_list(Sec)}]},
|
|
||||||
exmpp_iq:result(IQ, Response)
|
|
||||||
end.
|
|
||||||
|
|
||||||
process_sm_iq(From, To, IQ) ->
|
process_sm_iq(From, To, #iq{type = get} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
User = To#jid.lnode,
|
||||||
set ->
|
Server = To#jid.ldomain,
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
{Subscription, _Groups} =
|
||||||
get ->
|
ejabberd_hooks:run_fold(
|
||||||
User = To#jid.lnode,
|
roster_get_jid_info, Server,
|
||||||
Server = To#jid.ldomain,
|
{none, []}, [User, Server, From]),
|
||||||
{Subscription, _Groups} =
|
if
|
||||||
ejabberd_hooks:run_fold(
|
(Subscription == both) or (Subscription == from) ->
|
||||||
roster_get_jid_info, Server,
|
UserListRecord = ejabberd_hooks:run_fold(
|
||||||
{none, []}, [User, Server, From]),
|
privacy_get_user_list, Server,
|
||||||
if
|
#userlist{},
|
||||||
(Subscription == both) or (Subscription == from) ->
|
[User, Server]),
|
||||||
UserListRecord = ejabberd_hooks:run_fold(
|
case ejabberd_hooks:run_fold(
|
||||||
privacy_get_user_list, Server,
|
privacy_check_packet, Server,
|
||||||
#userlist{},
|
allow,
|
||||||
[User, Server]),
|
[User, Server, UserListRecord,
|
||||||
case ejabberd_hooks:run_fold(
|
{From, To,
|
||||||
privacy_check_packet, Server,
|
exmpp_presence:available()},
|
||||||
allow,
|
out]) of
|
||||||
[User, Server, UserListRecord,
|
allow ->
|
||||||
{From, To,
|
get_last(IQ_Rec, User, Server);
|
||||||
exmpp_presence:available()},
|
deny ->
|
||||||
out]) of
|
exmpp_iq:error(IQ_Rec, 'not-allowed')
|
||||||
allow ->
|
end;
|
||||||
get_last(IQ, User, Server);
|
true ->
|
||||||
deny ->
|
exmpp_iq:error(IQ_Rec, 'not-allowed')
|
||||||
exmpp_iq:error(IQ, 'not-allowed')
|
end;
|
||||||
end;
|
process_sm_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
true ->
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
exmpp_iq:error(IQ, 'not-allowed')
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% TODO: This function could use get_last_info/2
|
%% TODO: This function could use get_last_info/2
|
||||||
get_last(IQ, LUser, LServer) ->
|
get_last(IQ_Rec, LUser, LServer) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
case catch odbc_queries:get_last(LServer, Username) of
|
case catch odbc_queries:get_last(LServer, Username) of
|
||||||
{selected, ["seconds","state"], []} ->
|
{selected, ["seconds","state"], []} ->
|
||||||
exmpp_iq:error(IQ, 'service-unavailable');
|
exmpp_iq:error(IQ_Rec, 'service-unavailable');
|
||||||
{selected, ["seconds","state"], [{STimeStamp, Status}]} ->
|
{selected, ["seconds","state"], [{STimeStamp, Status}]} ->
|
||||||
case catch list_to_integer(STimeStamp) of
|
case catch list_to_integer(STimeStamp) of
|
||||||
TimeStamp when is_integer(TimeStamp) ->
|
TimeStamp when is_integer(TimeStamp) ->
|
||||||
@ -122,12 +116,12 @@ get_last(IQ, LUser, LServer) ->
|
|||||||
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query',
|
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query',
|
||||||
attrs = [#xmlattr{name = 'seconds', value = integer_to_list(Sec)}],
|
attrs = [#xmlattr{name = 'seconds', value = integer_to_list(Sec)}],
|
||||||
children = [#xmlcdata{cdata = list_to_binary(Status)}]},
|
children = [#xmlcdata{cdata = list_to_binary(Status)}]},
|
||||||
exmpp_iq:result(IQ, Response);
|
exmpp_iq:result(IQ_Rec, Response);
|
||||||
_ ->
|
_ ->
|
||||||
exmpp_iq:error(IQ, 'internal-server-error')
|
exmpp_iq:error(IQ_Rec, 'internal-server-error')
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
exmpp_iq:error(IQ, 'internal-server-error')
|
exmpp_iq:error(IQ_Rec, 'internal-server-error')
|
||||||
end.
|
end.
|
||||||
|
|
||||||
on_presence_update(User, Server, _Resource, Status) ->
|
on_presence_update(User, Server, _Resource, Status) ->
|
||||||
@ -136,12 +130,17 @@ on_presence_update(User, Server, _Resource, Status) ->
|
|||||||
store_last_info(User, Server, TimeStamp, Status).
|
store_last_info(User, Server, TimeStamp, Status).
|
||||||
|
|
||||||
store_last_info(User, Server, TimeStamp, Status) ->
|
store_last_info(User, Server, TimeStamp, Status) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
try
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
Seconds = ejabberd_odbc:escape(integer_to_list(TimeStamp)),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
State = ejabberd_odbc:escape(Status),
|
Seconds = ejabberd_odbc:escape(integer_to_list(TimeStamp)),
|
||||||
odbc_queries:set_last_t(LServer, Username, Seconds, State).
|
State = ejabberd_odbc:escape(Status),
|
||||||
|
odbc_queries:set_last_t(LServer, Username, Seconds, State)
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
%% Returns: {ok, Timestamp, Status} | not_found
|
%% Returns: {ok, Timestamp, Status} | not_found
|
||||||
get_last_info(LUser, LServer) ->
|
get_last_info(LUser, LServer) ->
|
||||||
@ -161,7 +160,12 @@ get_last_info(LUser, LServer) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
try
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
odbc_queries:del_last(LServer, Username).
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
|
odbc_queries:del_last(LServer, Username)
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user