25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Merge pull request #207 from weiss/xep-0334

Honor XEP-0334: Message Processing Hints
This commit is contained in:
badlop 2014-05-21 17:31:22 +02:00
commit 5d855f3723
4 changed files with 65 additions and 36 deletions

View File

@ -42,6 +42,7 @@
-define(NS_IQDATA, <<"jabber:iq:data">>). -define(NS_IQDATA, <<"jabber:iq:data">>).
-define(NS_DELAY91, <<"jabber:x:delay">>). -define(NS_DELAY91, <<"jabber:x:delay">>).
-define(NS_DELAY, <<"urn:xmpp:delay">>). -define(NS_DELAY, <<"urn:xmpp:delay">>).
-define(NS_HINTS, <<"urn:xmpp:hints">>).
-define(NS_EXPIRE, <<"jabber:x:expire">>). -define(NS_EXPIRE, <<"jabber:x:expire">>).
-define(NS_EVENT, <<"jabber:x:event">>). -define(NS_EVENT, <<"jabber:x:event">>).
-define(NS_CHATSTATES, -define(NS_CHATSTATES,

View File

@ -143,24 +143,29 @@ check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet,
<<"chat">> -> <<"chat">> ->
case xml:get_subtag(Packet, <<"private">>) of case xml:get_subtag(Packet, <<"private">>) of
false -> false ->
case xml:get_subtag(Packet,<<"received">>) of case xml:get_subtag(Packet, <<"no-copy">>) of
false -> false ->
%% We must check if a packet contains "<sent><forwarded></sent></forwarded>" tags in order to avoid case xml:get_subtag(Packet,<<"received">>) of
%% receiving message back to original sender. false ->
SubTag = xml:get_subtag(Packet,<<"sent">>), %% We must check if a packet contains "<sent><forwarded></sent></forwarded>"
if SubTag == false -> %% tags in order to avoid receiving message back to original sender.
send_copies(JID, To, Packet, Direction); SubTag = xml:get_subtag(Packet,<<"sent">>),
true -> if SubTag == false ->
case xml:get_subtag(SubTag,<<"forwarded">>) of send_copies(JID, To, Packet, Direction);
false-> true ->
send_copies(JID, To, Packet, Direction); case xml:get_subtag(SubTag,<<"forwarded">>) of
_ -> false->
stop send_copies(JID, To, Packet, Direction);
end _ ->
end; stop
end
end;
_ ->
%% stop the hook chain, we don't want mod_logdb to register this message (duplicate)
stop
end;
_ -> _ ->
%% stop the hook chain, we don't want mod_logdb to register this message (duplicate) ok
stop
end; end;
_ -> _ ->
ok ok

View File

@ -233,16 +233,22 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
%%% Internal functions %%% Internal functions
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
add_to_log2(text, {Nick, Packet}, Room, Opts, State) -> add_to_log2(text, {Nick, Packet}, Room, Opts, State) ->
case {xml:get_subtag(Packet, <<"subject">>), case {xml:get_subtag(Packet, <<"no-store">>),
xml:get_subtag(Packet, <<"body">>)} xml:get_subtag(Packet, <<"no-permanent-store">>)}
of of
{false, false} -> ok; {false, false} ->
{false, SubEl} -> case {xml:get_subtag(Packet, <<"subject">>),
Message = {body, xml:get_tag_cdata(SubEl)}, xml:get_subtag(Packet, <<"body">>)}
add_message_to_log(Nick, Message, Room, Opts, State); of
{SubEl, _} -> {false, false} -> ok;
Message = {subject, xml:get_tag_cdata(SubEl)}, {false, SubEl} ->
add_message_to_log(Nick, Message, Room, Opts, State) Message = {body, xml:get_tag_cdata(SubEl)},
add_message_to_log(Nick, Message, Room, Opts, State);
{SubEl, _} ->
Message = {subject, xml:get_tag_cdata(SubEl)},
add_message_to_log(Nick, Message, Room, Opts, State)
end;
{_, _} -> ok
end; end;
add_to_log2(roomconfig_change, _Occupants, Room, Opts, add_to_log2(roomconfig_change, _Occupants, Room, Opts,
State) -> State) ->

View File

@ -237,22 +237,39 @@ store_packet(From, To, Packet) ->
Type = xml:get_tag_attr_s(<<"type">>, Packet), Type = xml:get_tag_attr_s(<<"type">>, Packet),
if (Type /= <<"error">>) and (Type /= <<"groupchat">>) if (Type /= <<"error">>) and (Type /= <<"groupchat">>)
and (Type /= <<"headline">>) -> and (Type /= <<"headline">>) ->
case check_event(From, To, Packet) of case has_no_storage_hint(Packet) of
true -> false ->
#jid{luser = LUser, lserver = LServer} = To, case check_event(From, To, Packet) of
TimeStamp = now(), true ->
#xmlel{children = Els} = Packet, #jid{luser = LUser, lserver = LServer} = To,
Expire = find_x_expire(TimeStamp, Els), TimeStamp = now(),
gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) ! #xmlel{children = Els} = Packet,
#offline_msg{us = {LUser, LServer}, Expire = find_x_expire(TimeStamp, Els),
timestamp = TimeStamp, expire = Expire, gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
from = From, to = To, packet = Packet}, #offline_msg{us = {LUser, LServer},
stop; timestamp = TimeStamp, expire = Expire,
from = From, to = To, packet = Packet},
stop;
_ -> ok
end;
_ -> ok _ -> ok
end; end;
true -> ok true -> ok
end. end.
has_no_storage_hint(Packet) ->
case xml:get_subtag(Packet, <<"no-store">>) of
#xmlel{attrs = Attrs} ->
case xml:get_attr_s(<<"xmlns">>, Attrs) of
?NS_HINTS ->
true;
_ ->
false
end;
_ ->
false
end.
%% Check if the packet has any content about XEP-0022 or XEP-0085 %% Check if the packet has any content about XEP-0022 or XEP-0085
check_event(From, To, Packet) -> check_event(From, To, Packet) ->
#xmlel{name = Name, attrs = Attrs, children = Els} = #xmlel{name = Name, attrs = Attrs, children = Els} =