Unable to compile new module in ejabberd

I am trying to compile a new module for ejabberd in erlang. I am following this tutorial: http://jasonrowe.com/2011/12/30/ejabberd-offline-messages

I am trying to compile this code:

%% name of module must match file name
-module(mod_http_offline).

-author("Earl The Squirrel").

%% Every ejabberd module implements the gen_mod behavior
%% The gen_mod behavior requires two functions: start/2 and stop/1
-behaviour(gen_mod).

%% public methods for this module
-export([start/2, stop/1, create_message/3]).

%% included for writing to ejabberd log file
-include("ejabberd.hrl").

%% ejabberd functions for JID manipulation called jlib.
-include("jlib.hrl").

start(_Host, _Opt) ->
        post_offline_message("testFrom", "testTo", "testBody"),
        ?INFO_MSG("mod_http_offline loading", []),
        ejabberd_hooks:add(offline_message_hook, _Host, ?MODULE, create_message, 50).  



stop (_Host) ->
        ?INFO_MSG("stopping mod_http_offline", []),
        ejabberd_hooks:delete(offline_message_hook, _Host, ?MODULE, create_message, 50).



create_message(_From, _To, Packet) ->
        Type = xml:get_tag_attr_s("type", Packet),
        FromS = xml:get_tag_attr_s("from", Packet),
        ToS = xml:get_tag_attr_s("to", Packet),
        Body = xml:get_path_s(Packet, [{elem, "body"}, cdata]),
        if (Type == "chat") ->
            post_offline_message(FromS, ToS, Body)
        end.



post_offline_message(From, To, Body) ->
        ?INFO_MSG("Posting From ~p To ~p Body ~p~n",[From, To, Body]),
        ?INFO_MSG("post request sent (not really yet)", []).

      

I added jlib.hrl, ejabberd.hrl to my folder. But when I try to compile this code, I get the following errors:

jlib.hrl:22: can't find include lib "p1_xml/include/xml.hrl"
mod_http_offline.erl:21: undefined macro 'INFO_MSG/2'
mod_http_offline.erl:27: undefined macro 'INFO_MSG/2'
mod_http_offline.erl:44: undefined macro 'INFO_MSG/2'
jlib.hrl:426: record xmlel undefined
jlib.hrl:466: type xmlel() undefined
mod_http_offline.erl:11: function start/2 undefined
mod_http_offline.erl:11: function stop/1 undefined
mod_http_offline.erl:38: function post_offline_message/3 undefined
mod_http_offline.erl:8: Warning: behaviour gen_mod undefined

      

How can I solve this?

My Ejabberd version: 2.1.11

+3


source to share


1 answer


The jlib.hrl file in the ejabberd repository contains line -include("ns.hrl").

(line 21) and -include_lib("p1_xml/include/xml.hrl").

. The include_lib value means it will look for the file in the library path. You can change this and add the required files to your directory (maybe a simple test solution?), But I think the clean way is to add the tour file to the ejabberd app and use an armature to compile it.



0


source







All Articles