Skip to content

Commit a6bdce8

Browse files
committed
Changed meaning of 'class' in #sipmsg{}
Class now can be {req, Method} or {resp, Code}. Fields method and response have been removed from #sipmsg{}
1 parent 9091462 commit a6bdce8

28 files changed

+109
-104
lines changed

nksip/include/nksip.hrl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@
124124

125125
-record(sipmsg, {
126126
id :: nksip_request:id() | nksip_response:id(),
127-
class :: req | resp,
127+
class :: {req, nksip:method()} | {resp, nksip:response_code()},
128128
app_id :: nksip:app_id(),
129-
method :: nksip:method(),
130129
ruri :: nksip:uri(),
131130
vias :: [nksip:via()],
132131
from :: nksip:uri(),
@@ -140,7 +139,6 @@
140139
headers :: [nksip:header()],
141140
content_type :: [nksip_lib:token()],
142141
body :: nksip:body(),
143-
response :: nksip:response_code(),
144142
from_tag :: nksip:tag(),
145143
to_tag :: nksip:tag(),
146144
expire :: nksip_lib:timestamp(),

nksip/src/nksip_auth.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ get_authentication(Req, PassFun) ->
135135

136136
make_request(Req, #sipmsg{headers=RespHeaders}, Opts) ->
137137
#sipmsg{
138+
class = {req, Method},
138139
ruri = RUri,
139-
method = Method,
140140
from = #uri{user=User},
141-
headers=ReqHeaders
141+
headers= ReqHeaders
142142
} = Req,
143143
try
144144
ReqAuthHeaders = nksip_lib:extract(ReqHeaders, [?REQ_WWW, ?REQ_PROXY]),
@@ -317,9 +317,9 @@ make_auth_request(AuthHeaderData, UserOpts) ->
317317

318318
check_auth_header(AuthHeader, Resp, User, Realm, Pass, Req) ->
319319
#sipmsg{
320+
class = {req, Method},
320321
app_id = AppId,
321322
call_id = CallId,
322-
method = Method,
323323
transport = #transport{remote_ip=Ip, remote_port=Port}
324324
} = Req,
325325
case

nksip/src/nksip_call.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ work({incoming, RawMsg}, none, #call{app_id=AppId, call_id=CallId}=Call) ->
221221
?notice(AppId, CallId, "SIP ~p message could not be decoded: ~s",
222222
[Proto, Binary]),
223223
Call;
224-
#sipmsg{class=req}=Req ->
224+
#sipmsg{class={req, _}}=Req ->
225225
nksip_call_uas_req:request(Req, Call);
226-
#sipmsg{class=resp}=Resp ->
226+
#sipmsg{class={resp, _}}=Resp ->
227227
case nksip_uac_lib:is_stateless(Resp, GlobalId) of
228228
true -> nksip_call_proxy:response_stateless(Resp, Call);
229229
false -> nksip_call_uac_resp:response(Resp, Call)

nksip/src/nksip_call_dialog.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ target_update(Class, #dialog{response=#sipmsg{}}=Dialog, Call) ->
192192
response = Resp
193193
} = Dialog,
194194
#sipmsg{contacts=ReqContacts} = Req,
195-
#sipmsg{response=Code, contacts=RespContacts} = Resp,
195+
#sipmsg{class={resp, Code}, contacts=RespContacts} = Resp,
196196
case Class of
197197
uac ->
198198
RemoteTargets = RespContacts,
@@ -280,7 +280,7 @@ target_update(_, Dialog, _) ->
280280
session_update(Class,
281281
#dialog{
282282
answered = Answered,
283-
response = #sipmsg{body=RespBody, response=Code}
283+
response = #sipmsg{class={resp, Code}, body=RespBody}
284284
} = Dialog,
285285
Call)
286286
when

nksip/src/nksip_call_fork.erl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ next(#fork{pending=[]}=Fork, Call) ->
9696
[] when Method=:='ACK' ->
9797
delete(Fork, Call);
9898
[] ->
99-
#sipmsg{response=Code} = Resp = best_response(Fork),
99+
#sipmsg{class={resp, Code}} = Resp = best_response(Fork),
100100
?call_debug("Fork ~p ~p selected ~p response",
101101
[Id, Method, Code], Call),
102102
Call1 = send_reply(Resp, Fork, Call),
@@ -157,11 +157,11 @@ launch([Uri|Rest], Fork, Call) ->
157157
-spec response(id(), integer(), nksip:response(),call()) ->
158158
call().
159159

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

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

273273
send_reply(Resp, Fork, Call) ->
274-
#sipmsg{response=Code} = Resp,
274+
#sipmsg{class={resp, Code}} = Resp,
275275
#fork{id=TransId, method=Method} = Fork,
276276
#call{trans=Trans} = Call,
277277
case lists:keyfind(TransId, #trans.id, Trans) of
@@ -296,11 +296,11 @@ best_response(#fork{request=Req, responses=Resps}) ->
296296
if
297297
Code =:= 401; Code =:= 407 -> {3999, Resp};
298298
Code =:= 415; Code =:= 420; Code =:= 484 -> {4000, Resp};
299-
Code =:= 503 -> {5000, Resp#sipmsg{response=500}};
299+
Code =:= 503 -> {5000, Resp#sipmsg{class={resp, 500}}};
300300
Code >= 600 -> {Code, Resp};
301301
true -> {10*Code, Resp}
302302
end
303-
|| #sipmsg{response=Code}=Resp <- Resps
303+
|| #sipmsg{class={resp, Code}}=Resp <- Resps
304304
]),
305305
case Sorted of
306306
[{3999, Best}|_] ->
@@ -309,7 +309,7 @@ best_response(#fork{request=Req, responses=Resps}) ->
309309
nksip_lib:delete(Best#sipmsg.headers, Names) |
310310
[
311311
nksip_lib:extract(Headers, Names) ||
312-
#sipmsg{response=Code, headers=Headers}
312+
#sipmsg{class={resp, Code}, headers=Headers}
313313
<- Resps, Code=:=401 orelse Code=:=407
314314
]
315315
],

nksip/src/nksip_call_proxy.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ route_stateful(#trans{request=Req}=UAS, UriSet, ProxyOpts) ->
9797
stateless_proxy | {reply, nksip:sipreply()}.
9898

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

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

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

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

159-
check_forwards(#trans{request=#sipmsg{method=Method, forwards=Forwards}}) ->
159+
check_forwards(#trans{request=#sipmsg{class={req, Method}, forwards=Forwards}}) ->
160160
if
161161
is_integer(Forwards), Forwards > 0 ->
162162
ok;

nksip/src/nksip_call_uac_dialog.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
{ok, nksip_call:call()} | {error, Error}
4141
when Error :: finished | request_pending.
4242

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

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

101-
ack(#sipmsg{method='ACK'}=Req, Call) ->
101+
ack(#sipmsg{class={req, 'ACK'}}=Req, Call) ->
102102
#sipmsg{cseq=CSeq} = Req,
103103
case nksip_dialog:id(Req) of
104104
<<>> ->
@@ -131,12 +131,12 @@ ack(#sipmsg{method='ACK'}=Req, Call) ->
131131
-spec response(nksip:request(), nksip:response(), call()) ->
132132
call().
133133

134-
response(#sipmsg{method=Method}=Req, Resp, #call{dialogs=Dialogs}=Call) ->
134+
response(#sipmsg{class={req, Method}}=Req, Resp, #call{dialogs=Dialogs}=Call) ->
135135
case nksip_dialog:id(Resp) of
136136
<<>> ->
137137
Call;
138138
DialogId ->
139-
#sipmsg{response=Code} = Resp,
139+
#sipmsg{class={resp, Code}} = Resp,
140140
case nksip_call_dialog:find(DialogId, Call) of
141141
#dialog{status=Status} = Dialog ->
142142
?call_debug("Dialog ~s (~p) UAC response ~p ~p",
@@ -209,7 +209,7 @@ do_response('INVITE', Code, _Req, _Resp, #dialog{status=Status}=Dialog, Call)
209209
end;
210210

211211
do_response('INVITE', Code, _Req, Resp, Dialog, Call) ->
212-
#sipmsg{response=Code} = Resp,
212+
#sipmsg{class={resp, Code}} = Resp,
213213
#dialog{id=DialogId, status=Status} = Dialog,
214214
?call_notice("Dialog ~s (~p) ignoring 'INVITE' ~p response",
215215
[DialogId, Status, Code], Call),

nksip/src/nksip_call_uac_reply.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ reply({req, Req}, #trans{from={srv, _From}, opts=Opts}, Call) ->
5656
Call;
5757

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

9090

91-
fun_response(#sipmsg{cseq_method=Method, response=Code}=Resp, Opts) ->
91+
fun_response(#sipmsg{class={resp, Code}, cseq_method=Method}=Resp, Opts) ->
9292
case lists:member(get_response, Opts) of
9393
true ->
9494
{resp, Resp};

nksip/src/nksip_call_uac_req.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
nksip_call:call().
4949

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

107107
new_uac(Req, Opts, From, Call) ->
108-
#sipmsg{id=MsgId, method=Method, ruri=RUri} = Req,
108+
#sipmsg{class={req, Method}, id=MsgId, ruri=RUri} = Req,
109109
#call{next=Id, trans=Trans, msgs=Msgs} = Call,
110110
Status = case Method of
111111
'ACK' -> ack;

nksip/src/nksip_call_uac_resp.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
nksip_call:call().
4343

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

6161
response(Resp, UAC, Call) ->
62-
#sipmsg{id=MsgId, transport=Transport, response=Code} = Resp,
62+
#sipmsg{class={resp, Code}, id=MsgId, transport=Transport} = Resp,
6363
#trans{
6464
id = Id,
6565
start = Start,
@@ -190,7 +190,7 @@ response_status(invite_accepted, Resp, UAC, Call) ->
190190
end;
191191

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

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

@@ -241,7 +241,7 @@ response_status(proceeding, Resp, UAC, Call) ->
241241
do_received_auth(Req, Resp, UAC3, update(UAC3, Call));
242242

243243
response_status(completed, Resp, UAC, Call) ->
244-
#sipmsg{cseq_method=Method, response=Code, to_tag=ToTag} = Resp,
244+
#sipmsg{class={resp, Code}, cseq_method=Method, to_tag=ToTag} = Resp,
245245
#trans{id=Id, to_tags=ToTags} = UAC,
246246
case ToTags of
247247
[ToTag|_] ->

0 commit comments

Comments
 (0)