dec_lines(Msg, Lines) ->
dec_lines(Msg, Lines, fun hdr/5).
dec_lines(Msg, Lines, DecodeFun) ->
lists:foldl(fun(L1, M) -> dec_line(M, L1, DecodeFun) end, Msg, Lines).
dec_line(Msg, {Key, Line}, DecodeFun) ->
KeyN = keyN(Key),
case catch DecodeFun(decode, Key, undefined, Line, Msg) of
{Msg1=#sip_msg{}, Bin1} ->
case skip_LWS(Bin1) of
<< ?CRLFb >> ->
Msg1;
_Bin2 ->
Msg#sip_msg{error_hdrs = [{Key,
{KeyN, rem_trail_crlf_str(Line)}}
| Msg#sip_msg.error_hdrs]}
end;
_E ->
Msg#sip_msg{error_hdrs = [{Key, {KeyN, rem_trail_crlf_str(Line)}}
| Msg#sip_msg.error_hdrs]}
end.
有趣的hdr / 5:
hdr(Op, Short=[_], O0, O1, O2) ->
case lists:member(Short, ?LONG) of
true -> hdr(Op, long(Short), O0, O1, O2);
false -> case {Op, is_binary(O1)} of
{decode, true} -> hdr_dec(Short, O0, O1, O2);
_ -> hdr1(Op, Short, O1, O2)
end
end;
这是一些dbg日志:
(<0.4158.10>) call sip_decode:keyN("history-info")
(<0.4158.10>) returned from sip_decode:keyN/1 -> 1
(<0.4158.10>) call sip_decode:skip_LWS(<<"\r\n">>)
(<0.4158.10>) returned from sip_decode:skip_LWS/1 -> <<"\r\n">>
我使用这些cmds:
dbg:stop_clear().
dbg:tracer().
dbg:p(all,c).
dbg:tpl(sip_decode,'_',[{'_',[],[{return_trace}]}]).
从dbg日志中,我们知道sip_decode:keyN
和skip_LWS(Bin1)
都是exectue,所以我认为catch DecodeFun(decode, Key, undefined, Line, Msg)
应该被提取,结果匹配{Msg1=#sip_msg{}, Bin1}
。
但是从dbg日志中,我找不到DecodeFun
的来电,即hdr/5
。