Skip to content

Commit

Permalink
Merge pull request #383 from gmodarelli/stop-sending-obsolete-XEP-0091
Browse files Browse the repository at this point in the history
Remove obsolete XEP-0091 timestamp
  • Loading branch information
michalwski committed Mar 16, 2015
2 parents d17b636 + f74471f commit bda8185
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 45 deletions.
12 changes: 4 additions & 8 deletions apps/ejabberd/src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,7 @@ process_presence_probe(From, To, StateData) ->
Packet = xml:append_subtags(
StateData#state.pres_last,
%% To is the one sending the presence (the target of the probe)
[jlib:timestamp_to_xml(Timestamp, utc, To, <<>>),
%% TODO: Delete the next line once XEP-0091 is Obsolete
jlib:timestamp_to_xml(Timestamp)]),
[jlib:timestamp_to_xml(Timestamp, utc, To, <<>>)]),
case privacy_check_packet(StateData, To, From, Packet, out) of
deny ->
ok;
Expand Down Expand Up @@ -2955,15 +2953,13 @@ add_timestamp({_,_,Micro} = TimeStamp, Server, Packet) ->
Time = {D,{H,M,S, Micro}},
case xml:get_subtag(Packet, <<"delay">>) of
false ->
%% TODO: Delete the next element once XEP-0091 is Obsolete
TimeStampLegacyXML = timestamp_legacy_xml(Server, Time),
TimeStampXML = jlib:timestamp_to_xml(Time),
xml:append_subtags(Packet, [TimeStampLegacyXML, TimeStampXML]);
TimeStampXML = timestamp_xml(Server, Time),
xml:append_subtags(Packet, [TimeStampXML]);
_ ->
Packet
end.

timestamp_legacy_xml(Server, Time) ->
timestamp_xml(Server, Time) ->
FromJID = jlib:make_jid(<<>>, Server, <<>>),
jlib:timestamp_to_xml(Time, utc, FromJID, <<"SM Storage">>).

Expand Down
28 changes: 0 additions & 28 deletions apps/ejabberd/src/jlib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
iq_query_or_response_info/1,
iq_to_xml/1,
parse_xdata_submit/1,
timestamp_to_iso/1, % TODO: Remove once XEP-0091 is Obsolete
timestamp_to_xml/4,
timestamp_to_xml/1, % TODO: Remove once XEP-0091 is Obsolete
timestamp_to_mam_xml/4,
now_to_utc_binary/1,
datetime_binary_to_timestamp/1,
Expand Down Expand Up @@ -743,14 +741,6 @@ timestamp_to_iso({{Year, Month, Day}, {Hour, Minute, Second}}, Timezone) ->
end,
{Timestamp_string, Timezone_string}.


-spec timestamp_to_iso(calendar:datetime()) -> string().
timestamp_to_iso({{Year, Month, Day}, {Hour, Minute, Second}}) ->
lists:flatten(
io_lib:format("~4..0w~2..0w~2..0wT~2..0w:~2..0w:~2..0w",
[Year, Month, Day, Hour, Minute, Second])).


-spec timestamp_to_xml(DateTime :: calendar:datetime(),
Timezone :: tz(),
FromJID :: ejabberd:simple_jid() | ejabberd:jid(),
Expand Down Expand Up @@ -778,24 +768,6 @@ timestamp_to_mam_xml(DateTime, Timezone, QueryID, MessageUID) ->
{<<"id">>, MessageUID}] ++
[{<<"queryid">>, QueryID} || QueryID =/= undefined, QueryID =/= <<>>]}.


%% @doc TODO: Remove this function once XEP-0091 is Obsolete
-spec timestamp_to_xml(calendar:datetime()) -> xmlel().
timestamp_to_xml({{Year, Month, Day}, {Hour, Minute, Second, Micro}}) ->
#xmlel{name = <<"x">>,
attrs = [{<<"xmlns">>, ?NS_DELAY91},
{<<"stamp">>, lists:flatten(
io_lib:format("~4..0w~2..0w~2..0wT~2..0w:~2..0w:~2..0w.~6..0w",
[Year, Month, Day, Hour, Minute, Second, Micro]))}]};

timestamp_to_xml({{Year, Month, Day}, {Hour, Minute, Second}}) ->
#xmlel{name = <<"x">>,
attrs = [{<<"xmlns">>, ?NS_DELAY91},
{<<"stamp">>, lists:flatten(
io_lib:format("~4..0w~2..0w~2..0wT~2..0w:~2..0w:~2..0w",
[Year, Month, Day, Hour, Minute, Second]))}]}.


-spec now_to_utc_string(erlang:timestamp()) -> string().
now_to_utc_string({MegaSecs, Secs, MicroSecs}) ->
{{Year, Month, Day}, {Hour, Minute, Second}} =
Expand Down
6 changes: 5 additions & 1 deletion apps/ejabberd/src/mod_admin_extra_accounts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ set_random_password(User, Server, Reason) ->

-spec build_random_password(Reason :: binary()) -> binary().
build_random_password(Reason) ->
Date = list_to_binary(jlib:timestamp_to_iso(calendar:universal_time())),
{{Year,Month,Day},{Hour,Minute,Second}} = calendar:universal_time(),
Date = list_to_binary(
lists:flatten(
io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0wZ",
[Year, Month, Day, Hour, Minute, Second]))),
RandomString = list_to_binary(randoms:get_string()),
<<"BANNED_ACCOUNT--", Date/binary, "--", RandomString/binary, "--", Reason/binary>>.

Expand Down
4 changes: 1 addition & 3 deletions apps/ejabberd/src/mod_muc_room.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2462,9 +2462,7 @@ add_message_to_history(FromNick, FromJID, Packet, StateData) ->
false -> FromJID
end,
TSPacket = xml:append_subtags(Packet,
[jlib:timestamp_to_xml(TimeStamp, utc, SenderJid, <<>>),
%% TODO: Delete the next line once XEP-0091 is Obsolete
jlib:timestamp_to_xml(TimeStamp)]),
[jlib:timestamp_to_xml(TimeStamp, utc, SenderJid, <<>>)]),
SPacket = jlib:replace_from_to(
jlib:jid_replace_resource(StateData#state.jid, FromNick),
StateData#state.jid,
Expand Down
8 changes: 3 additions & 5 deletions apps/ejabberd/src/mod_offline.erl
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,10 @@ add_timestamp(undefined, _Server, Packet) ->
add_timestamp({_,_,Micro} = TimeStamp, Server, Packet) ->
{D,{H,M,S}} = calendar:now_to_universal_time(TimeStamp),
Time = {D,{H,M,S, Micro}},
%% TODO: Delete the next element once XEP-0091 is Obsolete
TimeStampLegacyXML = timestamp_legacy_xml(Server, Time),
TimeStampXML = jlib:timestamp_to_xml(Time),
xml:append_subtags(Packet, [TimeStampLegacyXML, TimeStampXML]).
TimeStampXML = timestamp_xml(Server, Time),
xml:append_subtags(Packet, [TimeStampXML]).

timestamp_legacy_xml(Server, Time) ->
timestamp_xml(Server, Time) ->
FromJID = jlib:make_jid(<<>>, Server, <<>>),
jlib:timestamp_to_xml(Time, utc, FromJID, <<"Offline Storage">>).

Expand Down

0 comments on commit bda8185

Please sign in to comment.