diff --git a/src/cyrsasl_anonymous.erl b/src/cyrsasl_anonymous.erl index af403645a..adbde246d 100644 --- a/src/cyrsasl_anonymous.erl +++ b/src/cyrsasl_anonymous.erl @@ -43,11 +43,11 @@ stop() -> ok. mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) -> {ok, #state{server = Host}}. -mech_step(#state{server = Server}, _ClientIn) -> - User = iolist_to_binary([randoms:get_string() - | [jlib:integer_to_binary(X) - || X <- tuple_to_list(now())]]), +mech_step(#state{server = Server} = S, ClientIn) -> + User = iolist_to_binary([randoms:get_string(), + randoms:get_string(), + randoms:get_string()]), case ejabberd_auth:is_user_exists(User, Server) of - true -> {error, <<"not-authorized">>}; + true -> mech_step(S, ClientIn); false -> {ok, [{username, User}, {auth_module, ejabberd_auth_anonymous}]} end. diff --git a/src/ejabberd.erl b/src/ejabberd.erl index 14404cd4c..3191e9817 100644 --- a/src/ejabberd.erl +++ b/src/ejabberd.erl @@ -105,7 +105,7 @@ start_app([], _Type, _StartFlag) -> ok. check_app_modules(App, StartFlag) -> - {A, B, C} = now(), + {A, B, C} = p1_time_compat:timestamp(), random:seed(A, B, C), sleep(5000), case application:get_key(App, modules) of diff --git a/src/ejabberd_captcha.erl b/src/ejabberd_captcha.erl index 6006b2851..4d906f324 100644 --- a/src/ejabberd_captcha.erl +++ b/src/ejabberd_captcha.erl @@ -661,8 +661,7 @@ clean_treap(Treap, CleanPriority) -> end. now_priority() -> - {MSec, Sec, USec} = now(), - -((MSec * 1000000 + Sec) * 1000000 + USec). + -p1_time_compat:system_time(micro_seconds). opt_type(captcha_cmd) -> fun (FileName) -> diff --git a/src/ejabberd_odbc.erl b/src/ejabberd_odbc.erl index f86dcca2e..123f0d558 100644 --- a/src/ejabberd_odbc.erl +++ b/src/ejabberd_odbc.erl @@ -153,7 +153,8 @@ sql_call(Host, Msg) -> case ejabberd_odbc_sup:get_random_pid(Host) of none -> {error, <<"Unknown Host">>}; Pid -> - (?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg, now()}, + (?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg, + p1_time_compat:monotonic_time(milli_seconds)}, ?TRANSACTION_TIMEOUT) end; _State -> nested_op(Msg) @@ -161,7 +162,8 @@ sql_call(Host, Msg) -> keep_alive(PID) -> (?GEN_FSM):sync_send_event(PID, - {sql_cmd, {sql_query, ?KEEPALIVE_QUERY}, now()}, + {sql_cmd, {sql_query, ?KEEPALIVE_QUERY}, + p1_time_compat:monotonic_time(milli_seconds)}, ?KEEPALIVE_TIMEOUT). -spec sql_query_t(sql_query()) -> sql_query_result(). @@ -373,7 +375,7 @@ print_state(State) -> State. %%%---------------------------------------------------------------------- run_sql_cmd(Command, From, State, Timestamp) -> - case timer:now_diff(now(), Timestamp) div 1000 of + case p1_time_compat:monotonic_time(milli_seconds) - Timestamp of Age when Age < (?TRANSACTION_TIMEOUT) -> put(?NESTING_KEY, ?TOP_LEVEL_TXN), put(?STATE_KEY, State), diff --git a/src/gen_iq_handler.erl b/src/gen_iq_handler.erl index 2b712aadc..fa2a97737 100644 --- a/src/gen_iq_handler.erl +++ b/src/gen_iq_handler.erl @@ -113,7 +113,8 @@ handle(Host, Module, Function, Opts, From, To, IQ) -> {one_queue, Pid} -> Pid ! {process_iq, From, To, IQ}; {queues, Pids} -> - Pid = lists:nth(erlang:phash(now(), length(Pids)), Pids), + Pid = lists:nth(erlang:phash(p1_time_compat:unique_integer(), + length(Pids)), Pids), Pid ! {process_iq, From, To, IQ}; parallel -> spawn(?MODULE, process_iq, @@ -179,4 +180,3 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}. %%-------------------------------------------------------------------- %%% Internal functions %%-------------------------------------------------------------------- - diff --git a/src/mod_admin_extra.erl b/src/mod_admin_extra.erl index cebd5cea4..ee0e9d092 100644 --- a/src/mod_admin_extra.erl +++ b/src/mod_admin_extra.erl @@ -554,8 +554,7 @@ num_active_users(Host, Days) -> %% Code based on ejabberd/src/web/ejabberd_web_admin.erl list_last_activity(Host, Integral, Days) -> - {MegaSecs, Secs, _MicroSecs} = now(), - TimeStamp = MegaSecs * 1000000 + Secs, + TimeStamp = p1_time_compat:system_time(seconds), TS = TimeStamp - Days * 86400, case catch mnesia:dirty_select( last_activity, [{{last_activity, {'_', Host}, '$1', '_'}, @@ -620,8 +619,7 @@ delete_old_users(Days, Users) -> SecOlder = Days*24*60*60, %% Get current time - {MegaSecs, Secs, _MicroSecs} = now(), - TimeStamp_now = MegaSecs * 1000000 + Secs, + TimeStamp_now = p1_time_compat:system_time(seconds), %% For a user, remove if required and answer true F = fun({LUser, LServer}) -> diff --git a/src/mod_configure2.erl b/src/mod_configure2.erl index efe665d23..109df2455 100644 --- a/src/mod_configure2.erl +++ b/src/mod_configure2.erl @@ -186,8 +186,7 @@ process_get(#xmlel{name = <<"last">>, attrs = Attrs}) -> {'EXIT', _Reason} -> {error, ?ERR_INTERNAL_SERVER_ERROR}; Vals -> - {MegaSecs, Secs, _MicroSecs} = now(), - TimeStamp = MegaSecs * 1000000 + Secs, + TimeStamp = p1_time_compat:system_time(seconds), Str = list_to_binary( [[jlib:integer_to_binary(TimeStamp - V), <<" ">>] || V <- Vals]), diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index cb85f2963..38fed6eab 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -149,7 +149,7 @@ normal_state({route, From, <<"">>, case xml:get_attr_s(<<"type">>, Attrs) of <<"groupchat">> -> Activity = get_user_activity(From, StateData), - Now = now_to_usec(now()), + Now = p1_time_compat:system_time(micro_seconds), MinMessageInterval = trunc(gen_mod:get_module_opt(StateData#state.server_host, mod_muc, min_message_interval, fun(MMI) when is_number(MMI) -> MMI end, 0) @@ -288,7 +288,7 @@ normal_state({route, From, <<"">>, (StateData#state.config)#config.voice_request_min_interval, BareFrom = jid:remove_resource(jid:tolower(From)), - NowPriority = -now_to_usec(now()), + NowPriority = -p1_time_compat:system_time(micro_seconds), CleanPriority = NowPriority + MinInterval * 1000000, @@ -472,7 +472,7 @@ normal_state({route, From, Nick, #xmlel{name = <<"presence">>} = Packet}, StateData) -> Activity = get_user_activity(From, StateData), - Now = now_to_usec(now()), + Now = p1_time_compat:system_time(micro_seconds), MinPresenceInterval = trunc(gen_mod:get_module_opt(StateData#state.server_host, mod_muc, min_presence_interval, @@ -1526,7 +1526,7 @@ store_user_activity(JID, UserActivity, StateData) -> 0) * 1000), Key = jid:tolower(JID), - Now = now_to_usec(now()), + Now = p1_time_compat:system_time(micro_seconds), Activity1 = clean_treap(StateData#state.activity, {1, -Now}), Activity = case treap:lookup(Key, Activity1) of @@ -1997,9 +1997,8 @@ count_stanza_shift(Nick, Els, StateData) -> Shift1 = case Seconds of false -> 0; _ -> - Sec = - calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time(now())) - - Seconds, + Sec = calendar:datetime_to_gregorian_seconds(calendar:universal_time()) + - Seconds, count_seconds_shift(Sec, HL) end, MaxStanzas = extract_history(Els, <<"maxstanzas">>), @@ -2284,9 +2283,6 @@ send_existing_presences1(ToJID, StateData) -> end, (?DICT):to_list(StateData#state.nicks)). -now_to_usec({MSec, Sec, USec}) -> - (MSec * 1000000 + Sec) * 1000000 + USec. - change_nick(JID, Nick, StateData) -> LJID = jid:tolower(JID), {ok, #user{nick = OldNick}} = (?DICT):find(LJID, @@ -2454,7 +2450,7 @@ add_message_to_history(FromNick, FromJID, Packet, StateData) -> false -> false; _ -> true end, - TimeStamp = now(), + TimeStamp = p1_time_compat:timestamp(), AddrPacket = case (StateData#state.config)#config.anonymous of true -> Packet; false -> @@ -4518,7 +4514,7 @@ handle_roommessage_from_nonparticipant(Packet, Lang, %% Check in the packet is a decline. %% If so, also returns the splitted packet. -%% This function must be catched, +%% This function must be catched, %% because it crashes when the packet is not a decline message. check_decline_invitation(Packet) -> #xmlel{name = <<"message">>} = Packet, @@ -4546,7 +4542,7 @@ send_decline_invitation({Packet, XEl, DEl, ToJID}, Packet2 = replace_subelement(Packet, XEl2), ejabberd_router:route(RoomJID, ToJID, Packet2). -%% Given an element and a new subelement, +%% Given an element and a new subelement, %% replace the instance of the subelement in element with the new subelement. replace_subelement(#xmlel{name = Name, attrs = Attrs, children = SubEls}, @@ -4630,4 +4626,3 @@ has_body_or_subject(Packet) -> (#xmlel{name = <<"subject">>}) -> false; (_) -> true end, Packet#xmlel.children). - diff --git a/src/mod_multicast.erl b/src/mod_multicast.erl index 1c8525f52..bc166b81d 100644 --- a/src/mod_multicast.erl +++ b/src/mod_multicast.erl @@ -937,8 +937,7 @@ create_cache() -> {attributes, record_info(fields, multicastc)}]). add_response(RServer, Response) -> - Secs = - calendar:datetime_to_gregorian_seconds(calendar:now_to_datetime(now())), + Secs = calendar:datetime_to_gregorian_seconds(calendar:local_time()), mnesia:dirty_write(#multicastc{rserver = RServer, response = Response, ts = Secs}). @@ -949,8 +948,7 @@ search_server_on_cache(RServer, _LServerS, Maxmins) -> case look_server(RServer) of not_cached -> not_cached; {cached, Response, Ts} -> - Now = - calendar:datetime_to_gregorian_seconds(calendar:now_to_datetime(now())), + Now = calendar:datetime_to_gregorian_seconds(calendar:local_time()), case is_obsolete(Response, Ts, Now, Maxmins) of false -> {cached, Response}; true -> {obsolete, Response} @@ -978,7 +976,7 @@ purge() -> Maxmins_positive = (?MAXTIME_CACHE_POSITIVE), Maxmins_negative = (?MAXTIME_CACHE_NEGATIVE), Now = - calendar:datetime_to_gregorian_seconds(calendar:now_to_datetime(now())), + calendar:datetime_to_gregorian_seconds(calendar:local_time()), purge(Now, {Maxmins_positive, Maxmins_negative}). purge(Now, Maxmins) -> diff --git a/src/mod_pres_counter.erl b/src/mod_pres_counter.erl index 72db36084..9834c4360 100644 --- a/src/mod_pres_counter.erl +++ b/src/mod_pres_counter.erl @@ -78,8 +78,7 @@ update(Server, JID, Dir) -> TimeInterval = gen_mod:get_module_opt(Server, ?MODULE, interval, fun(I) when is_integer(I), I>0 -> I end, 60), - {MegaSecs, Secs, _MicroSecs} = now(), - TimeStamp = MegaSecs * 1000000 + Secs, + TimeStamp = p1_time_compat:system_time(seconds), case read(Dir) of undefined -> write(Dir, diff --git a/src/mod_roster.erl b/src/mod_roster.erl index c75e128f5..eb987a2df 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -223,7 +223,7 @@ write_roster_version_t(LUser, LServer) -> write_roster_version(LUser, LServer, true). write_roster_version(LUser, LServer, InTransaction) -> - Ver = p1_sha:sha(term_to_binary(now())), + Ver = p1_sha:sha(term_to_binary(p1_time_compat:unique_integer())), write_roster_version(LUser, LServer, InTransaction, Ver, gen_mod:db_type(LServer, ?MODULE)), Ver. @@ -256,7 +256,7 @@ write_roster_version(LUser, LServer, _InTransaction, Ver, ejabberd_riak:put(#roster_version{us = US, version = Ver}, roster_version_schema()). -%% Load roster from DB only if neccesary. +%% Load roster from DB only if neccesary. %% It is neccesary if %% - roster versioning is disabled in server OR %% - roster versioning is not used by the client OR @@ -1391,7 +1391,7 @@ update_roster_table() -> end. %% Convert roster table to support virtual host -%% Convert roster table: xattrs fields become +%% Convert roster table: xattrs fields become update_roster_version_table() -> Fields = record_info(fields, roster_version), case mnesia:table_info(roster_version, attributes) of