[ejabberd] Programatically denying presence, cleaning roster

Hisham Mardam Bey hisham.mardambey at gmail.com
Wed Jul 10 18:45:45 MSK 2013

Hi guys,

I have some requirements in one of my ejabberd modules where I need to
block subscribe presences from making it through. The purpose of this is to
block certain users from inviting other users to chat based on some
business logic - so perhaps blocking subscribe is not the best way to go,
this is why I'm asking you guys (=

I was thinking of intercepting the packet in a module via filter_packet and
dropping it if it was a presence of type subscribe and the business rules
don't allow it. This works fine however it leaves a remnant in the roster.
Next time the users are on line ejabberd sends the presence notifications
and they don't go through my module. I was thinking I should also make sure
the roster state matches the fact I dropped the presence packet.

1- Can someone confirm that simply blocking presence (subscribe) will still
populate the roster and cause what I mentioned above to happen?
2- Am I thinking about this correctly? Should I drop the packet then clean
out the roster? Are there better ways to do this?
3- Assuming the approach is correct, is there a recommended way of cleaning
out the roster? I use mod_roster_odbc so I can craft out SQL to do so and
run it in the my module. Obviously if I can do this without taking into
account whether I use mnesia or odbc for roster storage that would be
better. Should I perhaps avoid interacting with the roster directly and use
an approach similar to mod_admin_extra?

delete_rosteritem(LocalUser, LocalServer, User, Server) ->
    case unsubscribe(LocalUser, LocalServer, User, Server) of
{atomic, ok} ->
    push_roster_item(LocalUser, LocalServer, User, Server, remove),
_  ->

unsubscribe(LU, LS, User, Server) ->
    ItemEl = build_roster_item(User, Server, remove),
    {ok, M} = loaded_module(LS,[mod_roster_odbc,mod_roster]),

Thank's for you help guys! (=


Hisham Mardam-Bey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20130710/df104986/attachment.html>

More information about the ejabberd mailing list