我是 erlang 和 ejabbered/mongooseIM 的新手。我正在尝试编写一个非常简单的猫鼬模块,它将在发送之前向数据包添加一个额外的子元素。下面是我的代码:
-module(mod_test).
-behavior(gen_mod).
-export([start/2, stop/1]).
-export([add_child/1]).
-include("ejabberd.hrl").
start(Host, Opts) ->
ejabberd_hooks:add(filter_packet, Host, ?MODULE, add_child, 0),
?DEBUG(" MOD_TEST Started",[]),
ok.
stop(Host) ->
ejabberd_hooks:delete(filter_packet, Host, ?MODULE, add_child, 0),
ok.
add_child({From, To, XML} = Packet) ->
Tag = {"a","b"},
NewPacket = xml:append_subtags(Packet, [Tag]),
?INFO_MSG(" To party: ~p~n",[To]),
NewPacket.
我可以成功编译并启动模块。但是,我在运行时收到以下错误:
2015-03-04 12:16:30.506 [error] <0.760.0>@ejabberd_hooks:run_fold1:259
{function_clause,
[{xml,append_subtags,[{{jid,<<"user2">>,<<"localhost">>,<<"Damien">>,<<"user2">>,<<"localhost">>,<<"Damien">>},{jid,<<"user1">>,<<"localhost">>,<<"Gajim">>,<<"user1">>,<<"localhost">>,<<"Gajim">>},{xmlel,<<"message">>,[{<<"xml:lang">>,<<"en">>},{<<"type">>,<<"chat">>},{<<"to">>,<<"user1@localhost/Gajim">>},{<<"id">>,<<"ab68a">>}],[{xmlcdata,<<"\n">>},{xmlel,<<"body">>,[],[{xmlcdata,<<"mmmmm">>}]},{xmlcdata,<<"\n">>},{xmlel,<<"active">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]},{xmlcdata,<<"\n">>}]}},
[{"a","b"}]],[{file,"src/xml.erl"},{line,276}]},
{safely,apply,3,[{file,"src/safely.erl"},{line,19}]},
{ejabberd_hooks,run_fold1,4,[{file,"src/ejabberd_hooks.erl"},{line,255}]},
{ejabberd_router,do_route,3,[{file,"src/ejabberd_router.erl"},{line,246}]},
{ejabberd_router,route,3,[{file,"src/ejabberd_router.erl"},{line,78}]},
{ejabberd_c2s,session_established2,2,[{file,"src/ejabberd_c2s.erl"},{line,1098}]},
{p1_fsm_old,handle_msg,10,[{file,"src/p1_fsm_old.erl"},{line,542}]},
{proc_lib,wake_up,3,[{file,"proc_lib.erl"},{line,247}]}]}
问题是什么以及如何解决?