Skip to content

Commit

Permalink
Changed meaning of 'class' in #sipmsg{}
Browse files Browse the repository at this point in the history
Class now can be {req, Method} or {resp, Code}.
Fields method and response have been removed from #sipmsg{}
  • Loading branch information
kalta committed Oct 18, 2013
1 parent 9091462 commit a6bdce8
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 104 deletions.
4 changes: 1 addition & 3 deletions nksip/include/nksip.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@

-record(sipmsg, {
id :: nksip_request:id() | nksip_response:id(),
class :: req | resp,
class :: {req, nksip:method()} | {resp, nksip:response_code()},
app_id :: nksip:app_id(),
method :: nksip:method(),
ruri :: nksip:uri(),
vias :: [nksip:via()],
from :: nksip:uri(),
Expand All @@ -140,7 +139,6 @@
headers :: [nksip:header()],
content_type :: [nksip_lib:token()],
body :: nksip:body(),
response :: nksip:response_code(),
from_tag :: nksip:tag(),
to_tag :: nksip:tag(),
expire :: nksip_lib:timestamp(),
Expand Down
6 changes: 3 additions & 3 deletions nksip/src/nksip_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ get_authentication(Req, PassFun) ->

make_request(Req, #sipmsg{headers=RespHeaders}, Opts) ->
#sipmsg{
class = {req, Method},
ruri = RUri,
method = Method,
from = #uri{user=User},
headers=ReqHeaders
headers= ReqHeaders
} = Req,
try
ReqAuthHeaders = nksip_lib:extract(ReqHeaders, [?REQ_WWW, ?REQ_PROXY]),
Expand Down Expand Up @@ -317,9 +317,9 @@ make_auth_request(AuthHeaderData, UserOpts) ->

check_auth_header(AuthHeader, Resp, User, Realm, Pass, Req) ->
#sipmsg{
class = {req, Method},
app_id = AppId,
call_id = CallId,
method = Method,
transport = #transport{remote_ip=Ip, remote_port=Port}
} = Req,
case
Expand Down
4 changes: 2 additions & 2 deletions nksip/src/nksip_call.erl
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ work({incoming, RawMsg}, none, #call{app_id=AppId, call_id=CallId}=Call) ->
?notice(AppId, CallId, "SIP ~p message could not be decoded: ~s",
[Proto, Binary]),
Call;
#sipmsg{class=req}=Req ->
#sipmsg{class={req, _}}=Req ->
nksip_call_uas_req:request(Req, Call);
#sipmsg{class=resp}=Resp ->
#sipmsg{class={resp, _}}=Resp ->
case nksip_uac_lib:is_stateless(Resp, GlobalId) of
true -> nksip_call_proxy:response_stateless(Resp, Call);
false -> nksip_call_uac_resp:response(Resp, Call)
Expand Down
4 changes: 2 additions & 2 deletions nksip/src/nksip_call_dialog.erl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ target_update(Class, #dialog{response=#sipmsg{}}=Dialog, Call) ->
response = Resp
} = Dialog,
#sipmsg{contacts=ReqContacts} = Req,
#sipmsg{response=Code, contacts=RespContacts} = Resp,
#sipmsg{class={resp, Code}, contacts=RespContacts} = Resp,
case Class of
uac ->
RemoteTargets = RespContacts,
Expand Down Expand Up @@ -280,7 +280,7 @@ target_update(_, Dialog, _) ->
session_update(Class,
#dialog{
answered = Answered,
response = #sipmsg{body=RespBody, response=Code}
response = #sipmsg{class={resp, Code}, body=RespBody}
} = Dialog,
Call)
when
Expand Down
14 changes: 7 additions & 7 deletions nksip/src/nksip_call_fork.erl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ next(#fork{pending=[]}=Fork, Call) ->
[] when Method=:='ACK' ->
delete(Fork, Call);
[] ->
#sipmsg{response=Code} = Resp = best_response(Fork),
#sipmsg{class={resp, Code}} = Resp = best_response(Fork),
?call_debug("Fork ~p ~p selected ~p response",
[Id, Method, Code], Call),
Call1 = send_reply(Resp, Fork, Call),
Expand Down Expand Up @@ -157,11 +157,11 @@ launch([Uri|Rest], Fork, Call) ->
-spec response(id(), integer(), nksip:response(),call()) ->
call().

response(_, _, #sipmsg{response=Code}, Call) when Code < 101 ->
response(_, _, #sipmsg{class={resp, Code}}, Call) when Code < 101 ->
Call;

response(Id, Pos, #sipmsg{vias=[_|Vias]}=Resp, #call{forks=Forks}=Call) ->
#sipmsg{to_tag=ToTag, response=Code} = Resp,
#sipmsg{class={resp, Code}, to_tag=ToTag} = Resp,
case lists:keyfind(Id, #fork.id, Forks) of
#fork{pending=Pending, uacs=UACs, method=Method}=Fork ->
?call_debug("Fork ~p ~p received ~p (~s)",
Expand Down Expand Up @@ -271,7 +271,7 @@ waiting(Code, Resp, Pos, Fork, Call) when Code >= 600 ->
call().

send_reply(Resp, Fork, Call) ->
#sipmsg{response=Code} = Resp,
#sipmsg{class={resp, Code}} = Resp,
#fork{id=TransId, method=Method} = Fork,
#call{trans=Trans} = Call,
case lists:keyfind(TransId, #trans.id, Trans) of
Expand All @@ -296,11 +296,11 @@ best_response(#fork{request=Req, responses=Resps}) ->
if
Code =:= 401; Code =:= 407 -> {3999, Resp};
Code =:= 415; Code =:= 420; Code =:= 484 -> {4000, Resp};
Code =:= 503 -> {5000, Resp#sipmsg{response=500}};
Code =:= 503 -> {5000, Resp#sipmsg{class={resp, 500}}};
Code >= 600 -> {Code, Resp};
true -> {10*Code, Resp}
end
|| #sipmsg{response=Code}=Resp <- Resps
|| #sipmsg{class={resp, Code}}=Resp <- Resps
]),
case Sorted of
[{3999, Best}|_] ->
Expand All @@ -309,7 +309,7 @@ best_response(#fork{request=Req, responses=Resps}) ->
nksip_lib:delete(Best#sipmsg.headers, Names) |
[
nksip_lib:extract(Headers, Names) ||
#sipmsg{response=Code, headers=Headers}
#sipmsg{class={resp, Code}, headers=Headers}
<- Resps, Code=:=401 orelse Code=:=407
]
],
Expand Down
8 changes: 4 additions & 4 deletions nksip/src/nksip_call_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ route_stateful(#trans{request=Req}=UAS, UriSet, ProxyOpts) ->
stateless_proxy | {reply, nksip:sipreply()}.

route_stateless(#trans{request=Req}, Uri, ProxyOpts, Call) ->
#sipmsg{method=Method} = Req,
#sipmsg{class={req, Method}} = Req,
#call{opts=#call_opts{app_opts=AppOpts, global_id=GlobalId}} = Call,
Req1 = preprocess(Req#sipmsg{ruri=Uri}, ProxyOpts),
case nksip_request:is_local_route(Req1) of
Expand All @@ -123,15 +123,15 @@ route_stateless(#trans{request=Req}, Uri, ProxyOpts, Call) ->
-spec response_stateless(nksip:response(), nksip_call:call()) ->
nksip_call:call().

response_stateless(#sipmsg{response=Code}, Call) when Code < 101 ->
response_stateless(#sipmsg{class={resp, Code}}, Call) when Code < 101 ->
Call;

response_stateless(#sipmsg{vias=[]}, Call) ->
?call_notice("Stateless proxy could not send response: no Via", [], Call),
Call;

response_stateless(#sipmsg{vias=[_|RestVia]}=Resp, Call) ->
#sipmsg{cseq_method=Method, response=Code} = Resp,
#sipmsg{cseq_method=Method, class={resp, Code}} = Resp,
#call{opts=#call_opts{app_opts=AppOpts, global_id=GlobalId}} = Call,
Resp1 = Resp#sipmsg{vias=RestVia},
case nksip_transport_uas:send_response(Resp1, GlobalId, AppOpts) of
Expand All @@ -156,7 +156,7 @@ response_stateless(#sipmsg{vias=[_|RestVia]}=Resp, Call) ->
-spec check_forwards(nksip_call:trans()) ->
ok | {reply, nksip:sipreply()}.

check_forwards(#trans{request=#sipmsg{method=Method, forwards=Forwards}}) ->
check_forwards(#trans{request=#sipmsg{class={req, Method}, forwards=Forwards}}) ->
if
is_integer(Forwards), Forwards > 0 ->
ok;
Expand Down
12 changes: 6 additions & 6 deletions nksip/src/nksip_call_uac_dialog.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
{ok, nksip_call:call()} | {error, Error}
when Error :: finished | request_pending.

request(#sipmsg{method='ACK'}, _) ->
request(#sipmsg{class={req, 'ACK'}}, _) ->
error(ack_in_dialog_request);

request(#sipmsg{method=Method}=Req, Call) ->
request(#sipmsg{class={req, Method}}=Req, Call) ->
case nksip_dialog:id(Req) of
<<>> ->
{ok, Call};
Expand Down Expand Up @@ -98,7 +98,7 @@ do_request(_Method, _Status, _Req, Dialog, _Call) ->
-spec ack(nksip:request(), call()) ->
call().

ack(#sipmsg{method='ACK'}=Req, Call) ->
ack(#sipmsg{class={req, 'ACK'}}=Req, Call) ->
#sipmsg{cseq=CSeq} = Req,
case nksip_dialog:id(Req) of
<<>> ->
Expand Down Expand Up @@ -131,12 +131,12 @@ ack(#sipmsg{method='ACK'}=Req, Call) ->
-spec response(nksip:request(), nksip:response(), call()) ->
call().

response(#sipmsg{method=Method}=Req, Resp, #call{dialogs=Dialogs}=Call) ->
response(#sipmsg{class={req, Method}}=Req, Resp, #call{dialogs=Dialogs}=Call) ->
case nksip_dialog:id(Resp) of
<<>> ->
Call;
DialogId ->
#sipmsg{response=Code} = Resp,
#sipmsg{class={resp, Code}} = Resp,
case nksip_call_dialog:find(DialogId, Call) of
#dialog{status=Status} = Dialog ->
?call_debug("Dialog ~s (~p) UAC response ~p ~p",
Expand Down Expand Up @@ -209,7 +209,7 @@ do_response('INVITE', Code, _Req, _Resp, #dialog{status=Status}=Dialog, Call)
end;

do_response('INVITE', Code, _Req, Resp, Dialog, Call) ->
#sipmsg{response=Code} = Resp,
#sipmsg{class={resp, Code}} = Resp,
#dialog{id=DialogId, status=Status} = Dialog,
?call_notice("Dialog ~s (~p) ignoring 'INVITE' ~p response",
[DialogId, Status, Code], Call),
Expand Down
4 changes: 2 additions & 2 deletions nksip/src/nksip_call_uac_reply.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ reply({req, Req}, #trans{from={srv, _From}, opts=Opts}, Call) ->
Call;

reply({resp, Resp}, #trans{from={srv, From}, opts=Opts}, Call) ->
#sipmsg{response=Code} = Resp,
#sipmsg{class={resp, Code}} = Resp,
Async = lists:member(async, Opts),
if
Code < 101 -> ok;
Expand Down Expand Up @@ -88,7 +88,7 @@ fun_call(Msg, Opts) ->
end.


fun_response(#sipmsg{cseq_method=Method, response=Code}=Resp, Opts) ->
fun_response(#sipmsg{class={resp, Code}, cseq_method=Method}=Resp, Opts) ->
case lists:member(get_response, Opts) of
true ->
{resp, Resp};
Expand Down
4 changes: 2 additions & 2 deletions nksip/src/nksip_call_uac_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
nksip_call:call().

request(Req, Opts, From, Call) ->
#sipmsg{method=Method, id=MsgId} = Req,
#sipmsg{class={req, Method}, id=MsgId} = Req,
#call{opts=#call_opts{app_opts=AppOpts, global_id=GlobalId}} = Call,
Req1 = case Method of
'CANCEL' -> Req;
Expand Down Expand Up @@ -105,7 +105,7 @@ resend_auth(Req, UAC, Call) ->
{nksip_call:trans(), nksip_call:call()}.

new_uac(Req, Opts, From, Call) ->
#sipmsg{id=MsgId, method=Method, ruri=RUri} = Req,
#sipmsg{class={req, Method}, id=MsgId, ruri=RUri} = Req,
#call{next=Id, trans=Trans, msgs=Msgs} = Call,
Status = case Method of
'ACK' -> ack;
Expand Down
10 changes: 5 additions & 5 deletions nksip/src/nksip_call_uac_resp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
nksip_call:call().

response(Resp, #call{trans=Trans}=Call) ->
#sipmsg{cseq_method=Method, response=Code} = Resp,
#sipmsg{class={resp, Code}, cseq_method=Method} = Resp,
TransId = nksip_call_uac:transaction_id(Resp),
case lists:keyfind(TransId, #trans.trans_id, Trans) of
#trans{class=uac}=UAC ->
Expand All @@ -59,7 +59,7 @@ response(Resp, #call{trans=Trans}=Call) ->
nksip_call:call().

response(Resp, UAC, Call) ->
#sipmsg{id=MsgId, transport=Transport, response=Code} = Resp,
#sipmsg{class={resp, Code}, id=MsgId, transport=Transport} = Resp,
#trans{
id = Id,
start = Start,
Expand Down Expand Up @@ -190,7 +190,7 @@ response_status(invite_accepted, Resp, UAC, Call) ->
end;

response_status(invite_completed, Resp, UAC, Call) ->
#sipmsg{to_tag=ToTag, response=RespCode} = Resp,
#sipmsg{class={resp, RespCode}, to_tag=ToTag} = Resp,
#trans{id=Id, code=Code, to_tags=ToTags} = UAC,
case ToTags of
[ToTag|_] ->
Expand All @@ -211,7 +211,7 @@ response_status(trying, Resp, UAC, Call) ->
UAC2 = nksip_call_lib:cancel_timers([retrans], UAC1),
response_status(proceeding, Resp, UAC2, Call);

response_status(proceeding, #sipmsg{response=Code}=Resp, UAC, Call)
response_status(proceeding, #sipmsg{class={resp, Code}}=Resp, UAC, Call)
when Code < 200 ->
nksip_call_uac_reply:reply({resp, Resp}, UAC, Call);

Expand Down Expand Up @@ -241,7 +241,7 @@ response_status(proceeding, Resp, UAC, Call) ->
do_received_auth(Req, Resp, UAC3, update(UAC3, Call));

response_status(completed, Resp, UAC, Call) ->
#sipmsg{cseq_method=Method, response=Code, to_tag=ToTag} = Resp,
#sipmsg{class={resp, Code}, cseq_method=Method, to_tag=ToTag} = Resp,
#trans{id=Id, to_tags=ToTags} = UAC,
case ToTags of
[ToTag|_] ->
Expand Down
4 changes: 2 additions & 2 deletions nksip/src/nksip_call_uas.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ timer(noinvite, #trans{id=Id, method=Method}=UAS, Call) ->

% INVITE 3456xx retrans
timer(timer_g, #trans{id=Id, response=Resp}=UAS, Call) ->
#sipmsg{response=Code} = Resp,
#sipmsg{class={resp, Code}} = Resp,
#call{opts=#call_opts{app_opts=Opts}} = Call,
UAS1 = case nksip_transport_uas:resend_response(Resp, Opts) of
{ok, _} ->
Expand Down Expand Up @@ -176,9 +176,9 @@ app_cast(Fun, Args, UAS, Call) ->

transaction_id(Req) ->
#sipmsg{
class = {req, Method},
app_id = AppId,
ruri = RUri,
method = Method,
from_tag = FromTag,
to_tag = ToTag,
vias = [Via|_],
Expand Down
10 changes: 5 additions & 5 deletions nksip/src/nksip_call_uas_dialog.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ request(Req, Call) ->
<<>> ->
{ok, undefined, Call};
DialogId ->
#sipmsg{method=Method, cseq=CSeq} = Req,
#sipmsg{class={req, Method}, cseq=CSeq} = Req,
case nksip_call_dialog:find(DialogId, Call) of
#dialog{status=Status, remote_seq=RemoteSeq}=Dialog ->
?call_debug("Dialog ~s (~p) UAS request ~p",
Expand Down Expand Up @@ -130,16 +130,16 @@ do_request(_, _, _, Dialog, _Call) ->
-spec response(nksip:request(), nksip:response(), call()) ->
call().

response(#sipmsg{method=Method}=Req, Resp, Call) ->
#sipmsg{response=Code} = Resp,
response(#sipmsg{class={req, Method}}=Req, Resp, Call) ->
#sipmsg{class={resp, Code}} = Resp,
#call{dialogs=Dialogs} = Call,
case nksip_dialog:id(Resp) of
<<>> ->
Call;
DialogId ->
case nksip_call_dialog:find(DialogId, Call) of
#dialog{status=Status}=Dialog ->
#sipmsg{response=Code} = Resp,
#sipmsg{class={resp, Code}} = Resp,
?call_debug("Dialog ~s (~p) UAS ~p response ~p",
[DialogId, Status, Method, Code], Call),
Dialog1 = do_response(Method, Code, Req, Resp, Dialog, Call),
Expand Down Expand Up @@ -182,7 +182,7 @@ do_response('INVITE', Code, _Req, _Resp, #dialog{answered=Answered}=Dialog, Call
end;

do_response('INVITE', Code, _Req, Resp, Dialog, Call) ->
#sipmsg{response=Code} = Resp,
#sipmsg{class={resp, Code}} = Resp,
#dialog{status=Status} = Dialog,
?call_notice("Dialog unexpected INVITE response ~p in ~p", [Code, Status], Call),
Dialog;
Expand Down
6 changes: 3 additions & 3 deletions nksip/src/nksip_call_uas_reply.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ reply(Reply, #trans{status=Status, method=Method}=UAS, Call)
end,
reply(Reply, UAS1, nksip_call_lib:update(UAS1, Call));

reply({#sipmsg{id=MsgId, response=Code}=Resp, SendOpts},
reply({#sipmsg{class={resp, Code}, id=MsgId}=Resp, SendOpts},
#trans{status=Status, code=LastCode}=UAS,
#call{msgs=Msgs}=Call)
when Status=:=invite_proceeding orelse
Expand Down Expand Up @@ -82,7 +82,7 @@ reply({#sipmsg{id=MsgId, response=Code}=Resp, SendOpts},
{ok, Resp1} -> ok;
error -> {Resp1, _} = nksip_reply:reply(Req, service_unavailable)
end,
#sipmsg{response=Code1} = Resp1,
#sipmsg{class={resp, Code1}} = Resp1,
Call1 = case Req of
#sipmsg{} when Code1>=200, Code<300 ->
nksip_call_lib:update_auth(nksip_dialog:id(Resp1), Req, Call);
Expand Down Expand Up @@ -113,7 +113,7 @@ reply({#sipmsg{id=MsgId, response=Code}=Resp, SendOpts},
{{ok, Resp1}, nksip_call_lib:update(UAS2, Call3)}
end;

reply({#sipmsg{response=Code}, _}, #trans{code=LastCode}=UAS, Call) ->
reply({#sipmsg{class={resp, Code}}, _}, #trans{code=LastCode}=UAS, Call) ->
#trans{status=Status, id=Id, method=Method} = UAS,
?call_info("UAS ~p ~p cannot send ~p response in ~p (last code was ~p)",
[Id, Method, Code, Status, LastCode], Call),
Expand Down
Loading

0 comments on commit a6bdce8

Please sign in to comment.