私は 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}]}]}
問題とその修正方法は何ですか?