]> granicus.if.org Git - ejabberd/commitdiff
feat: add hook for sending packet from component
authorPouriya Jahanbakhsh <pouriya.jahanbakhsh@gmail.com>
Fri, 30 Mar 2018 17:01:30 +0000 (21:31 +0430)
committerPouriya Jahanbakhsh <pouriya.jahanbakhsh@gmail.com>
Fri, 30 Mar 2018 17:01:30 +0000 (21:31 +0430)
New hook 'component_send_packet' added.
Callback function must accept one argument {Pkt, ComponentState} and should yield 'drop' or {NewPkt, NewComponentState}.

src/ejabberd_service.erl

index 03b768bdf5926adc80193e6899b0b256beace800..a150116a9359773c5cd72002e1b5c3eb0d6fd15b 100644 (file)
@@ -185,14 +185,20 @@ handle_auth_failure(_, Mech, Reason,
               Reason]),
     State.
 
-handle_authenticated_packet(Pkt0, #{ip := {IP, _}, lang := Lang} = State)
+handle_authenticated_packet(Pkt0, #{server := Server, ip := {IP, _}, lang := Lang} = State)
   when ?is_stanza(Pkt0) ->
     Pkt = xmpp:put_meta(Pkt0, ip, IP),
     From = xmpp:get_from(Pkt),
     case check_from(From, State) of
        true ->
-           ejabberd_router:route(Pkt),
-           State;
+        {Pkt2, State2} = ejabberd_hooks:run_fold(component_send_packet, Server, {Pkt, State}, []),
+        case Pkt2 of
+            drop ->
+                ok;
+            _ ->
+                ejabberd_router:route(Pkt2)
+               end,
+        State2;
        false ->
            Txt = <<"Improper domain part of 'from' attribute">>,
            Err = xmpp:serr_invalid_from(Txt, Lang),