Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter_packet hook #2135

Closed
skhaz opened this issue Nov 30, 2017 · 4 comments
Closed

filter_packet hook #2135

skhaz opened this issue Nov 30, 2017 · 4 comments

Comments

@skhaz
Copy link

skhaz commented Nov 30, 2017

What version of ejabberd are you using?

lastest (from the master branch)

What operating system (version) are you using?

macOS 10.12.6

How did you install ejabberd (source, package, distribution)?

source

What did not work as expected? Are there error messages in the log? What
was the unexpected behavior? What was the expected result?

I am wondering if the filter_packet hook signature was changed, I was following this article to create a simple hook in Elixir, but the code seems that doesn't work anymore.

defmodule PacketFilter do
  import Ejabberd.Logger
  @behaviour :gen_mod
  def start(_host, _opts) do
    info('Starting ejabberd module Filter Packet Demo')
    Ejabberd.Hooks.add(:filter_packet, :global, __ENV__.module, :on_filter_packet, 50)
    :ok
  end

  def stop(_host) do
    info('Stopping ejabberd module Filter Packet Demo')
    Ejabberd.Hooks.delete(:filter_packet, :global, __ENV__.module, :on_filter_packet, 50)
    :ok
  end

  def on_filter_packet({from, to, xml={:xmlel, "message", attributes, children}} = packet) do
     # This hook is never called.
    # What I want only packets of type `message` here.

    info("on_filter_packet [1] #{inspect packet}")
    packet
  end

  def on_filter_packet(packet) do
    # Always called, without this hook, the ejabberd throws a lot of erros.
    info("on_filter_packet [2] #{inspect packet}")
    packet
  end

end
@zinid
Copy link
Contributor

zinid commented Nov 30, 2017

Well, yes, and the change is almost one year old.

@badlop
Copy link
Member

badlop commented Dec 4, 2017

Right. Instead of: {From, To, Packet}, now the argument is simply: Packet

This change was introduced around ejabberd 17.03: 8b2d308#diff-b81e1bd5c308d13a2065da751c70b882L258

@skhaz
Copy link
Author

skhaz commented Dec 4, 2017

Thanks!

@skhaz skhaz closed this as completed Dec 4, 2017
@lock
Copy link

lock bot commented Jun 10, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants