diff options
Diffstat (limited to 'src/mod_last.erl')
-rw-r--r-- | src/mod_last.erl | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/mod_last.erl b/src/mod_last.erl index ef7a61b9..ecda0271 100644 --- a/src/mod_last.erl +++ b/src/mod_last.erl @@ -38,25 +38,24 @@ start(Opts) -> stop() -> gen_iq_handler:remove_iq_handler(ejabberd_local, ?NS_LAST). -process_local_iq(_From, _To, {iq, ID, Type, XMLNS, SubEl}) -> +process_local_iq(_From, _To, #iq{type = Type, sub_el = SubEl} = IQ) -> case Type of set -> - {iq, ID, error, XMLNS, - [SubEl, ?ERR_NOT_ALLOWED]}; + IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}; get -> Sec = trunc(element(1, erlang:statistics(wall_clock))/1000), - {iq, ID, result, XMLNS, - [{xmlelement, "query", - [{"xmlns", ?NS_LAST}, - {"seconds", integer_to_list(Sec)}], - []}]} + IQ#iq{type = result, + sub_el = [{xmlelement, "query", + [{"xmlns", ?NS_LAST}, + {"seconds", integer_to_list(Sec)}], + []}]} end. -process_sm_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) -> +process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) -> case Type of set -> - {iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]}; + IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}; get -> User = To#jid.luser, {Subscription, _Groups} = @@ -65,7 +64,7 @@ process_sm_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) -> (Subscription == both) or (Subscription == from) -> case catch mod_privacy:get_user_list(User) of {'EXIT', _Reason} -> - get_last(ID, XMLNS, SubEl, User); + get_last(IQ, SubEl, User); List -> case mod_privacy:check_packet( User, List, @@ -73,32 +72,33 @@ process_sm_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) -> {xmlelement, "presence", [], []}}, out) of allow -> - get_last(ID, XMLNS, SubEl, User); + get_last(IQ, SubEl, User); deny -> - {iq, ID, error, XMLNS, - [SubEl, ?ERR_NOT_ALLOWED]} + IQ#iq{type = error, + sub_el = [SubEl, ?ERR_NOT_ALLOWED]} end end; true -> - {iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]} + IQ#iq{type = error, + sub_el = [SubEl, ?ERR_NOT_ALLOWED]} end end. -get_last(ID, XMLNS, SubEl, LUser) -> +get_last(IQ, SubEl, LUser) -> case catch mnesia:dirty_read(last_activity, LUser) of {'EXIT', _Reason} -> - {iq, ID, error, XMLNS, [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}; + IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}; [] -> - {iq, ID, error, XMLNS, [SubEl, ?ERR_SERVICE_UNAVAILABLE]}; + IQ#iq{type = error, sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]}; [#last_activity{timestamp = TimeStamp}] -> {MegaSecs, Secs, _MicroSecs} = now(), TimeStamp2 = MegaSecs * 1000000 + Secs, Sec = TimeStamp2 - TimeStamp, - {iq, ID, result, XMLNS, - [{xmlelement, "query", - [{"xmlns", ?NS_LAST}, - {"seconds", integer_to_list(Sec)}], - []}]} + IQ#iq{type = result, + sub_el = [{xmlelement, "query", + [{"xmlns", ?NS_LAST}, + {"seconds", integer_to_list(Sec)}], + []}]} end. |