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_DELAY91, <<"jabber:x:delay">>).
-define(NS_DELAY, <<"urn:xmpp:delay">>).
-define(NS_HINTS, <<"urn:xmpp:hints">>).
-define(NS_EXPIRE, <<"jabber:x:expire">>).
-define(NS_EVENT, <<"jabber:x:event">>).
-define(NS_CHATSTATES,

View File

@ -143,24 +143,29 @@ check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet,
<<"chat">> ->
case xml:get_subtag(Packet, <<"private">>) of
false ->
case xml:get_subtag(Packet,<<"received">>) of
case xml:get_subtag(Packet, <<"no-copy">>) of
false ->
%% We must check if a packet contains "<sent><forwarded></sent></forwarded>" tags in order to avoid
%% receiving message back to original sender.
SubTag = xml:get_subtag(Packet,<<"sent">>),
if SubTag == false ->
send_copies(JID, To, Packet, Direction);
true ->
case xml:get_subtag(SubTag,<<"forwarded">>) of
false->
send_copies(JID, To, Packet, Direction);
_ ->
stop
end
end;
case xml:get_subtag(Packet,<<"received">>) of
false ->
%% We must check if a packet contains "<sent><forwarded></sent></forwarded>"
%% tags in order to avoid receiving message back to original sender.
SubTag = xml:get_subtag(Packet,<<"sent">>),
if SubTag == false ->
send_copies(JID, To, Packet, Direction);
true ->
case xml:get_subtag(SubTag,<<"forwarded">>) of
false->
send_copies(JID, To, Packet, Direction);
_ ->
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)
stop
ok
end;
_ ->
ok

View File

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

View File

@ -237,22 +237,39 @@ store_packet(From, To, Packet) ->
Type = xml:get_tag_attr_s(<<"type">>, Packet),
if (Type /= <<"error">>) and (Type /= <<"groupchat">>)
and (Type /= <<"headline">>) ->
case check_event(From, To, Packet) of
true ->
#jid{luser = LUser, lserver = LServer} = To,
TimeStamp = now(),
#xmlel{children = Els} = Packet,
Expire = find_x_expire(TimeStamp, Els),
gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
#offline_msg{us = {LUser, LServer},
timestamp = TimeStamp, expire = Expire,
from = From, to = To, packet = Packet},
stop;
case has_no_storage_hint(Packet) of
false ->
case check_event(From, To, Packet) of
true ->
#jid{luser = LUser, lserver = LServer} = To,
TimeStamp = now(),
#xmlel{children = Els} = Packet,
Expire = find_x_expire(TimeStamp, Els),
gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
#offline_msg{us = {LUser, LServer},
timestamp = TimeStamp, expire = Expire,
from = From, to = To, packet = Packet},
stop;
_ -> ok
end;
_ -> ok
end;
true -> ok
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_event(From, To, Packet) ->
#xmlel{name = Name, attrs = Attrs, children = Els} =