gpt4 book ai didi

erlang - 无法在 ejabberd 中编译新模块

转载 作者:行者123 更新时间:2023-12-02 07:13:59 25 4
gpt4 key购买 nike

我正在尝试在 erlang 中为 ejabberd 编译一个新模块。我正在遵循本教程:http://jasonrowe.com/2011/12/30/ejabberd-offline-messages

我正在尝试编译此代码:

%% 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)", []).

我已将 jlib.hrl、ejabberd.hrl 添加到我的文件夹中。但是当我尝试编译此代码时,出现以下错误:

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

我该如何解决这个问题?

我的Ejabberd版本:2.1.11

最佳答案

ejabberd 存储库中的 jlib.hrl 文件包含 -include("ns.hrl"). (第 21 行)和 -include_lib("p1_xml/include/xml.hrl") . line 22. include_lib 表示它将在库路径中搜索文件。您可以修改它并在目录中添加必要的文件(也许是一个简单的测试解决方案?),但我认为干净的方法是将tour文件添加到ejabberd应用程序并使用rebar来编译它。

关于erlang - 无法在 ejabberd 中编译新模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27610733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com