我正在尝试在 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'"
在 mod_avtar.erl 中的第 320 行是这个函数
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{}.