在ejabberd的vcard中添加字段时无法理解崩溃

时间:2018-12-07 07:52:17

标签: ejabberd vcard ejabberd-module ejabberd-api ejabberd-hooks

我正在尝试在vcard中添加一个新字段,即“ Abc”。为此,我在xmpp_codec.spec文件中为此“ Abc”字段添加了xml。并在#vcard_temp中引用了它。我将在“ make spec”之后生成的xmpp_codec.erl,xmpp_codec.hrl,xep0054.erl文件放置在各自的目录中。

但是当我尝试通过发送此iq添加该字段的值时

<<"<iq id='D2sPz-22' type='set'><vCard xmlns='vcard-temp'><N><GIVEN>byname</GIVEN></N><Abc>10</Abc><FN>byname </FN><NICKNAME>byname</NICKNAME></vCard></iq>">>

我收到此错误

[error] Hook vcard_iq_set crashed when running mod_avatar:vcard_iq_convert/1:
** Reason = {error,{badrecord,vcard_temp},[{mod_avatar,convert_avatar,[{file,"src/mod_avatar.erl"},{line,320}],3},{mod_avatar,vcard_iq_convert,[{file,"src/mod_avatar.erl"},{line,110}],1},{ejabberd_hooks,safe_apply,[{file,"src/ejabberd_hooks.erl"},{line,380}],4},{ejabberd_hooks,run_fold1,[{file,"src/ejabberd_hooks.erl"},{line,364}],4},{mod_vcard,process_sm_iq,[{file,"src/mod_vcard.erl"},{line,210}],1},{gen_iq_handler,process_iq,[{file,"src/gen_iq_handler.erl"},{line,132}],3},{gen_iq_handler,process_iq,[{file,"src/gen_iq_handler.erl"},{line,111}],4},{ejabberd_sm,route,[{file,"src/ejabberd_sm.erl"},{line,143}],1}]}
** Arguments = [{iq,<<"D2sPz-22">>,set,<<"en">>,{jid,<<"dgNW1Udm4Us">>,<<"example.com">>,<<"Smack">>,<<"dgnw1udm4us">>,<<“example.com">>,<<"Smack">>},{jid,<<"dgNW1Udm4Us">>,<<"example.com">>,<<>>,<<"dgNW1Udm4Us">>,<<"example.com">>,<<>>},[{vcard_temp,undefined,<<"myname ">>,{vcard_name,undefined,<<"myname">>,undefined,undefined,undefined},<<"myname">>,undefined,undefined,[],[],[],[],undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,[],undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,<<"10">>}],#{ip => {}}}]
06:47:47.776 [debug] SQL: "begin;"
06:47:47.776 [debug] SQL: "UPDATE vcard SET vcard='<vCard xmlns=''vcard-temp''><N><GIVEN>myname</GIVEN></N><FN>myname </FN><NICKNAME>myname</NICKNAME><Abc>10</Abc></vCard>' WHERE username='dgNW1Udm4Us'"
06:47:47.777 [debug] SQL: "UPDATE vcard_search SET username='dgNW1Udm4Us', fn='myname ', lfn='myname ', family='', lfamily='', given='myname', lgiven='myname', middle='', lmiddle='', nickname='myname', lnickname='myname', bday='', lbday='', ctry='', lctry='', locality='', llocality='', email='', lemail='', orgname='', lorgname='', orgunit='', lorgunit='', abc='', labc='' WHERE lusername='dgNW1Udm4Us'"

在320行的mod_avtar.erl中是此函数

convert_avatar(LUser, LServer, VCard) ->
    case get_converting_rules(LServer) of
    [] ->
        pass;
    Rules ->
        case VCard#vcard_temp.photo of
        #vcard_photo{binval = Data} when is_binary(Data) ->
            convert_avatar(LUser, LServer, Data, Rules);
        _ ->
            pass
        end
    end.

此函数内的第320行是case VCard#vcard_temp.photo of

由于我没有更改#vcard_photo记录,所以我无法理解此错误,为什么它表示vcard_temp是错误记录?

编辑

这是添加XML并制定规范后生成的#vcard_temp记录

-record(vcard_temp, {version :: 'undefined' | binary(),
                     fn :: 'undefined' | binary(),
                     n :: 'undefined' | #vcard_name{},
                     nickname :: 'undefined' | binary(),
                     photo :: 'undefined' | #vcard_photo{},
                     bday :: 'undefined' | binary(),
                     adr = [] :: [#vcard_adr{}],
                     label = [] :: [#vcard_label{}],
                     tel = [] :: [#vcard_tel{}],
                     email = [] :: [#vcard_email{}],
                     jabberid :: 'undefined' | binary(),
                     mailer :: 'undefined' | binary(),
                     tz :: 'undefined' | binary(),
                     geo :: 'undefined' | #vcard_geo{},
                     title :: 'undefined' | binary(),
                     role :: 'undefined' | binary(),
                     logo :: 'undefined' | #vcard_logo{},
                     org :: 'undefined' | #vcard_org{},
                     categories = [] :: [binary()],
                     note :: 'undefined' | binary(),
                     prodid :: 'undefined' | binary(),
                     rev :: 'undefined' | binary(),
                     sort_string :: 'undefined' | binary(),
                     sound :: 'undefined' | #vcard_sound{},
                     uid :: 'undefined' | binary(),
                     url :: 'undefined' | binary(),
                     class :: 'confidential' | 'private' | 'public' | 'undefined',
                     key :: 'undefined' | #vcard_key{},
                     desc :: 'undefined' | binary(),
                     abc :: 'undefined' | binary()}).
-type vcard_temp() :: #vcard_temp{}. 

1 个答案:

答案 0 :(得分:0)

如果您修改了一个库来重新定义记录(在本例中为vcard_temp记录),则最好重新编译ejabberd,以确保所有代码都使用新的记录定义。

此外,值得检查一下旧的vcard_temp记录定义是否仍在某处使用。如果您将SQL存储用于mod_vcard,则可能不会,但是最好确保。