I'm trying to send packet from ejabberd to Python script then python script will do his function and return with (true or false). I found project name of it: ErlPort which helps connect Erlang to a number of other programming languages.
And it's working 100% but when received a lot of packet ejabberd shutdown.
This example working 100% but crashed when a lot of packet sent like what I say before :
My Python script
from erlport import Port, Protocol, String
class SecurityProtocol(Protocol):
def handle_security(self, body):
BadList = ["bad1", "bad2"]
body = String(body).lower()
body = u" " + body + u" "
for x in BadList:
if body.count(x): return True
return False
if __name__ == "__main__":
proto = SecurityProtocol()
proto.run(Port(use_stdio=True))
In (ejabberd_c2s.erl) line 1896 --> ejabberd v2.1.13 :
security(Body) ->
Port = open_port({spawn, "python -u /home/ejabberd/lib/ejabberd/ebin/security.py"}, [{packet, 1}, binary, use_stdio]),
ReqData = term_to_binary({security, Body}),
port_command(Port, ReqData),
receive
{Port, {data, RespData}} ->
binary_to_term(RespData)
after
5000 ->
{error, timeout}
end.
privacy_check_packet(StateData, From, To, Packet, Dir) ->
case Packet of
{xmlelement, "message", _, _} ->
LBody = xml:get_subtag_cdata(Packet, "body"),
case security(LBody) of
true -> deny;
false -> ejabberd_hooks:run_fold(privacy_check_packet, StateData#state.server, allow, [StateData#state.user, StateData#state.server, StateData#state.privacy_list, {From, To, Packet}, Dir]);
_ -> "Error TimeOut"
end
end.
And the error is : http://paste.ubuntu.com/15414683/
Is there any way to connect ejabberd with a Python script without any errors or problem?