erlang / erlide_eclipse

Eclipse IDE for Erlang

Home Page:http://erlide.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

not able to run custom module in ejabberd

blacklightknight opened this issue · comments

What version of ejabberd are you using?

ejabberd 17.01

What operating system (version) are you using?

windows 10

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

ejabberd installer

I am using Pidgin as the client side messaging server and ejabberd as server side application.
I have also added some custom modules(frequency_sup.erl) in the ebin folder of ejabberd 17.01.
Now what I was trying to do was that when I was sending a message from Pidgin I tried to catch that message at server side.I was able to do this inside the ejabberd_router.erl file inside the do_route function. On catching the message I compared the value of my message with a random value and if it matches I wanted to call the custom module (frequency_sup.erl) which I had added to the ejabberd's ebin folder. But instead I got an error as badmatch sometimes and sometimes as my custom module being undefined when I use an atom as a message instead of an integer. My code and log entry are as follows:

The code inside ejabberd_router.erl at line 428:
` do_route(From, To, Packet, #route{local_hint = LocalHint,
pid = Pid}) when is_pid(Pid) ->

     Temp1=7,
   if
	(element(1,Packet)=:=message)->
		if
			(element(3,Packet)=:=chat)->
			MyMessageBin=element(3,hd(element(8,Packet))),
			
			
			Mes=binary_to_list(MyMessageBin),
			MyMessage=list_to_integer(Mes),
			if
	             (MyMessage==1)->
                      Pid=frequency_sup:start_link1(),
				  ?INFO_MSG("Pid generated is ~p",[Pid]);
	             (MyMessage=/=1)->
	              Random=5,
	              ?INFO_MSG("Application not called and Random value is ~p",[Random])
	        end,

			
		?INFO_MSG("Found message which is ~p",[MyMessage]);
			(element(2,Packet)=/=chat)->
		?INFO_MSG("Found message but not of any use ~p",[Temp1])
		end;
		(element(1,Packet)=/=message)->
                    ?INFO_MSG("Didn't Find message ~p",[Temp1])
             end,
            case LocalHint of
            {apply, Module, Function} when node(Pid) == node() ->
              Module:Function(From, To, Packet);
               _ ->
                 Pid ! {route, From, To, Packet}
             end;`

And the log entry is:
`2017-03-27 15:28:40.945 [error] <0.12703.0>@ejabberd_router:route:90 {{badmatch,{ok, <0.12709.0>}},[{ejabberd_router,do_route,4,[{file,"ejabberd_router.erl"},{line,447}]}, {ejabberd_router,route,3,[{file,"ejabberd_router.erl"},{line,88}]},{ejabberd_c2s,check_privacy_route,5, [{file,"ejabberd_c2s.erl"},{line,1893}]},{ejabberd_c2s,session_established2,2,[{file,"ejabberd_c2s.erl"},{line,1177}]},{ejabberd_c2s,decode_element,3,[{file,"ejabberd_c2s.erl"},{line,937}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}

when processing: {{jid,<<"admin2">>,<<"travel.com">>,<<"-">>,<<"admin2">>,<<"travel.com">>,<<"-">>},{jid,<<"admin1">>,<<"travel.com">>,<<>>,<<"admin1">>,<<"travel.com">>,<<>>},{message,<<"purple54ffd129">>,chat,<<>>,undefined,{jid,<<"admin1">>,<<"travel.com">>,<<>>,<<"admin1">>,<<"travel.com">>,<<>>},[],[{text,<<>>,<<"1">>}],undefined,[{xmlel,<<"active">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]}],#{}}}`

And the code inside frequency sup is like this:
`
-module(frequency_sup).

 -behaviour(supervisor).



 -export([start_link1/0, init/1]).

 -export([stop/0]).

  -define(EJABBERD_DEBUG, true).

  -export([
    start/2,
    stop/1
   ]).


  -include("ejabberd.hrl").
  -include("jlib.hrl").
  -include("ejabberd_http.hrl").



  start(_Host, _Opts) -> ok.
  stop(_Host) -> ok.



  start_link1() ->

      supervisor:start_link({local,?MODULE},?MODULE, []).

 

 




   stop() -> exit(whereis(?MODULE), shutdown).



  init(_) ->

      ChildSpecList = [ child(myapp)],

      {ok,{{rest_for_one, 2, 3600}, ChildSpecList}}.



  child(Module) ->

      {Module, {Module, start, []},

      temporary, 2000, worker, [Module]}.

`

I am not able to figure out the issue ,can anyone help
Thank you in advance.

This looks like a problem with ejabberd, maybe you posted the issue to the wrong project? I know nothing about ejabberd, so I can't help you with this, sorry.

Ok got it ..my bad