processone / ejabberd-contrib

Growing and curated ejabberd contributions repository - PR or ask to join !
http://ejabberd.im
250 stars 140 forks source link

Custom module beam error: error writing file: no such file or directory #226

Closed jjdp closed 7 years ago

jjdp commented 7 years ago

17.07 Ubuntu Server 16.04 LTS in AWS EC2 installed using .deb distribution

Im getting this beam error when i module_check, any idea why is that? There are also no ebin directories in https://github.com/processone/ejabberd-contrib

ejabberd-17.07/.ejabberd-modules/sources/ejabberd-contrib/mod_offline_post/ebin/mod_offline_post.bea#: error writing file: no such file or directory

err

I also tried the hello world from the website. no dice, still the same error

the mod_offline_post:

-module(mod_offline_post).

-behaviour(gen_mod).

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

-define(PROCNAME, ?MODULE).

-include("ejabberd.hrl").
-include("xmpp.hrl").
-include("logger.hrl").

start(Host, Opts) ->
    ?INFO_MSG("Starting mod_offline_post", [] ),
    register(?PROCNAME,spawn(?MODULE, init, [Host, Opts])),  
    ok.

init(Host, _Opts) ->
    inets:start(),
    ssl:start(),
    ejabberd_hooks:add(offline_message_hook, Host, ?MODULE, send_notice, 100),
    ok.

stop(Host) ->
    ?INFO_MSG("Stopping mod_offline_post", [] ),
    ejabberd_hooks:delete(offline_message_hook, Host,
                  ?MODULE, send_notice, 10),
    ok.

send_notice({Action,Packet}) -> 
    From = element(5,Packet),
    To = element(6,Packet),

    From1 = From#jid.luser,
    To1 = To#jid.luser,

    Body = binary_to_list(element(3,lists:nth(1,element(8,Packet)))),

    PostUrl = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, post_url,fun(S) -> iolist_to_binary(S) end, list_to_binary("")),
    AppId = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, app_id, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),
    ApiKey = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, api_key, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),

    Data = string:join(["to=", binary_to_list(To1), "&from=", binary_to_list(From1), "&body=", Body], ""),
    Request = {binary_to_list(PostUrl), [{"X-Parse-Application-Id", binary_to_list(AppId)}, {"X-Parse-REST-API-Key", binary_to_list(ApiKey)}], "application/json", Data},
    httpc:request(post, Request,[],[]),

    ok.
cromain commented 7 years ago

assuming you followed this https://blog.process-one.net/easy-installer-and-structure-for-ejabberd-contributed-modules/ and your setup is correct, you should open ejabberd debug console and try following commands {code} ext_mod:update(). ext_mod:check(mod_offline_post). {code}

note: ejabberd-17.07/.ejabberd-modules is an old path, not absolute... by default (until you tune ejabberdctl) custom modules should be in $HOME/.ejabberd-modules

jjdp commented 7 years ago

oh ok good to know, i just assumed since that it was the default path

turns out it was really a permission error after all. uploading used the root user instead of ejabberd

zinid commented 7 years ago
From = element(5,Packet),
To = element(6,Packet),
...
Body = binary_to_list(element(3,lists:nth(1,element(8,Packet)))),

My eyes...

jjdp commented 7 years ago

surely there's a better way to parse that?

zinid commented 7 years ago

There is nothing to parse, you should use API functions to work with XMPP packets, see Overview and API. So, for example, you should write:

From = xmpp:get_from(Packet),
To = xmpp:get_to(Packet),

Or, assuming the Packet is a #message{} (which is the case):

From = Packet#message.from,
To = Packet#message.to,
Body = binary_to_list(xmpp:get_text(Packet#message.body))