Skip to content

Commit

Permalink
Changed parameter 'reason' to 'reason_phrase' everywhere
Browse files Browse the repository at this point in the history
'reason' will be used for "Reason" header
  • Loading branch information
kalta committed Dec 17, 2013
1 parent 611bed9 commit ffa3e67
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 48 deletions.
4 changes: 2 additions & 2 deletions samples/nksip_tutorial/src/nksip_tutorial.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ launch() ->
]),

{ok,200,[]} = nksip_uac:options(client2, "sip:127.0.0.1:5070", []),
{ok,407,[{reason,<<"Proxy Authentication Required">>}]} =
nksip_uac:options(client1, "sip:127.0.0.1", [{fields, [reason]}]),
{ok,407,[{reason_phrase,<<"Proxy Authentication Required">>}]} =
nksip_uac:options(client1, "sip:127.0.0.1", [{fields, [reason_phrase]}]),

{ok,200,[]} = nksip_uac:options(client1, "sip:127.0.0.1", [{pass, "1234"}]),
{ok,200,[]} = nksip_uac:options(client2, "<sip:127.0.0.1;transport=tls>", [{pass, "1234"}]),
Expand Down
2 changes: 1 addition & 1 deletion src/nksip_call_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ check_forwards(#trans{request=#sipmsg{class={req, Method}, forwards=Forwards}})
ok;
Forwards==0, Method=='OPTIONS' ->
throw({ok, [], <<>>, [make_supported, make_accept, make_allow,
{reason, <<"Max Forwards">>}]});
{reason_phrase, <<"Max Forwards">>}]});
Forwards==0 ->
throw(too_many_hops);
true ->
Expand Down
2 changes: 1 addition & 1 deletion src/nksip_call_uas_dialog.erl
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ retry() ->
500,
[{<<"Retry-After">>, crypto:rand_uniform(0, 11)}],
<<>>,
[{reason, <<"Processing Previous INVITE">>}]
[{reason_phrase, <<"Processing Previous INVITE">>}]
}.


Expand Down
8 changes: 4 additions & 4 deletions src/nksip_reply.erl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
%% <li>`{local_host, Host::binary()}': uses this Host instead of the default one for
%% <i>Contact</i>, <i>Record-Route</i>, etc.</li>
%% <li>`{contact, [nksip:user_uri()]}': adds one or more `Contact' headers.</li>
%% <li>`{reason, Text::binary()}': changes the default response line to `Text'.</li>
%% <li>`{reason_phrase, Text::binary()}': changes the default response line to `Text'.</li>
%% <li>`{make_www_auth, Realm::from|binary()}': a <i>WWW-Authenticate</i>
%% header will be generated for this `Realm' (see
%% {@link nksip_auth:make_response/2}).</li>
Expand Down Expand Up @@ -239,7 +239,7 @@ reply(Req, #reqreply{}=ReqReply, AppOpts) ->
error ->
?warning(AppId, CallId, "UAS returned invalid contact: ~p",
[ContactSpec]),
Opts1 = [{reason, <<"Invalid SipApp Response">>}],
Opts1 = [{reason_phrase, <<"Invalid SipApp Response">>}],
response(Req, 500, [], <<>>, Opts1, AppOpts);
Contacts ->
Opts1 = [{contact, Contacts}],
Expand Down Expand Up @@ -412,7 +412,7 @@ reqreply(decline) ->
reqreply(Code) when is_integer(Code) ->
#reqreply{code=Code};
reqreply({Code, Text}) when is_integer(Code), is_binary(Text) ->
#reqreply{code=Code, opts=[{reason, Text}]};
#reqreply{code=Code, opts=[{reason_phrase, Text}]};
reqreply({Code, Headers}) when is_integer(Code), is_list(Headers) ->
#reqreply{code=Code, headers=Headers};
reqreply({Code, Headers, Body}) when is_integer(Code), is_list(Headers) ->
Expand All @@ -436,7 +436,7 @@ reqreply(_Other) ->
#reqreply{}.

helper_debug(#reqreply{opts=Opts}=SipReply, Text) ->
SipReply#reqreply{opts=[{reason, Text}, make_date|Opts]}.
SipReply#reqreply{opts=[{reason_phrase, Text}, make_date|Opts]}.


%% @private
Expand Down
14 changes: 3 additions & 11 deletions src/nksip_response.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
-include("nksip.hrl").

-export([field/3, fields/3, header/3]).
-export([body/2, code/2, reason/2, dialog_id/2, call_id/1, get_response/2, wait_491/0]).
-export([body/2, code/2, dialog_id/2, call_id/1, get_response/2, wait_491/0]).
-export_type([id/0, field/0]).


Expand All @@ -36,7 +36,7 @@

-type id() :: binary().

-type field() :: app_id | code | reason | call_id | vias | parsed_vias |
-type field() :: app_id | code | reason_phrase | call_id | vias | parsed_vias |
ruri | ruri_scheme | ruri_user | ruri_domain | parsed_ruri | aor |
from | from_scheme | from_user | from_domain | parsed_from |
to | to_scheme | to_user | to_domain | parsed_to |
Expand Down Expand Up @@ -64,7 +64,7 @@
%% <td>Response Code</td>
%% </tr>
%% <tr>
%% <td>`reason'</td>
%% <td>`reason_phrase'</td>
%% <td>`binary()'</td>
%% <td>Reason Phrase</td>
%% </tr>
Expand Down Expand Up @@ -111,14 +111,6 @@ code(AppId, RespId) ->
field(AppId, RespId, code).


%% @doc Gets the <i>reason</i> of a response.
-spec reason(nksip:app_id(), id()) ->
binary() | error.

reason(AppId, RespId) ->
field(AppId, RespId, reason).


%% @doc Gets the <i>body</i> of a response.
-spec body(nksip:app_id(), id()) ->
nksip:body() | error.
Expand Down
2 changes: 1 addition & 1 deletion src/nksip_sipmsg.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ field(#sipmsg{class=Class, ruri=RUri, transport=T}=S, Field) ->
parsed_event -> S#sipmsg.event;
all_headers -> all_headers(S);
code -> case Class of {resp, Code, _Reason} -> Code; _ -> 0 end;
reason -> case Class of {resp, _Code, Reason} -> Reason; _ -> <<>> end;
reason_phrase -> case Class of {resp, _Code, Reason} -> Reason; _ -> <<>> end;
realms -> nksip_auth:realms(S);
rseq_num ->
case header(S, <<"RSeq">>, integers) of [RSeq] -> RSeq; _ -> undefined end;
Expand Down
4 changes: 2 additions & 2 deletions src/nksip_uas_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ preprocess(Req, GlobalId) ->
%% <li>`make_date': Generates a Date header</li>
%% <li>`make_100rel': If present a Require: 100rel header will be included</li>
%% <li>`{expires, non_neg_integer()}: If present generates a Event header</li>
%% <li>`reason': Custom reason phrase</li>
%% <li>`reason_phrase': Custom reason phrase</li>
%% <li>`to_tag': If present, it will override the To tag in the request</li>
%% </ul>
%%
Expand Down Expand Up @@ -325,7 +325,7 @@ response2(Req, Code, Headers, Body, Opts, AppOpts) ->
false
end
end,
Reason = nksip_lib:get_binary(reason, Opts),
Reason = nksip_lib:get_binary(reason_phrase, Opts),
AllRespContacts = lists:flatten(proplists:get_all_values(contact, Opts)),
RespContacts = case nksip_parse:uris(AllRespContacts) of
error -> throw(invalid_contact);
Expand Down
8 changes: 4 additions & 4 deletions test/invite_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ dialog() ->
CSeq = nksip_dialog:field(C2, DialogIdB, remote_seq) -1,

% Force invalid CSeq
{ok, 500, [{reason, <<"Old CSeq in Dialog">>}]} =
nksip_uac:options(C2, DialogIdB, [{cseq, 9998}, {fields, [reason]}]),
{ok, 500, [{reason_phrase, <<"Old CSeq in Dialog">>}]} =
nksip_uac:options(C2, DialogIdB, [{cseq, 9998}, {fields, [reason_phrase]}]),

[DialogIdA] = nksip_dialog:get_all(C1, CallId),
[DialogIdB] = nksip_dialog:get_all(C2, CallId),
Expand Down Expand Up @@ -504,10 +504,10 @@ multiple_uas() ->

% Before the previous invite has been answered, we send a new one
% UAS replies with 500
% {ok, 500, [{dialog_id, DialogId1A}, {reason, <<"Processing Previous INVITE">>}]} =
% {ok, 500, [{dialog_id, DialogId1A}, {reason_phrase, <<"Processing Previous INVITE">>}]} =
{error, request_pending} =
nksip_uac:invite(C1, DialogId1A,
[no_dialog, {headers, [Hds]}, {fields, [reason]}]),
[no_dialog, {headers, [Hds]}, {fields, [reason_phrase]}]),

% % Previous invite will reply 200, and Fun will send ACK
ok = tests_util:wait(Ref, [{client2, ack}, {client2, dialog_confirmed}]),
Expand Down
4 changes: 2 additions & 2 deletions test/proxy_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ invalid(Test) ->
CallId5 = nksip_lib:luid(),
Work5 = {make, 'OPTIONS', "sip:any", []},
{ok, Req5, Opts5} = nksip_call_router:send_work_sync(C1, CallId5, Work5),
{ok, 200, [{reason, <<"Max Forwards">>}]} =
nksip_call:send(Req5#sipmsg{forwards=0}, [{fields, [reason]}|Opts5]),
{ok, 200, [{reason_phrase, <<"Max Forwards">>}]} =
nksip_call:send(Req5#sipmsg{forwards=0}, [{fields, [reason_phrase]}|Opts5]),

% User not registered: Temporarily Unavailable
{ok, 480, []} = nksip_uac:options(C1, "sip:other@nksip", []),
Expand Down
4 changes: 2 additions & 2 deletions test/register_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ register1() ->

{ok, 400, Values3} = nksip_uac:register(Client1, "sip:127.0.0.1",
[{call_id, CallId}, {cseq, CSeq}, make_contact,
{fields, [reason]}]),
[{reason, <<"Rejected Old CSeq">>}] = Values3,
{fields, [reason_phrase]}]),
[{reason_phrase, <<"Rejected Old CSeq">>}] = Values3,

{ok, 200, []} = nksip_uac:register(Client1, "sip:127.0.0.1",
[{call_id, CallId}, {cseq, CSeq+1}, make_contact]),
Expand Down
16 changes: 8 additions & 8 deletions test/uac_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,21 @@ timeout() ->

nksip_trace:notice("Next notices about several timeouts are expected"),

{ok, 408, [{reason, <<"Timer F Timeout">>}]} =
nksip_uac:options(C2, "sip:127.0.0.1:9999", [{fields, [reason]}]),
{ok, 408, [{reason_phrase, <<"Timer F Timeout">>}]} =
nksip_uac:options(C2, "sip:127.0.0.1:9999", [{fields, [reason_phrase]}]),

{ok, 408, [{reason, <<"Timer B Timeout">>}]} =
nksip_uac:invite(C2, "sip:127.0.0.1:9999", [{fields, [reason]}]),
{ok, 408, [{reason_phrase, <<"Timer B Timeout">>}]} =
nksip_uac:invite(C2, "sip:127.0.0.1:9999", [{fields, [reason_phrase]}]),

% REGISTER sends a provisional response, but the timeout is the same
Hds1 = {headers, [{<<"Nk-Sleep">>, 2000}]},
{ok, 408, [{reason, <<"Timer F Timeout">>}]} =
nksip_uac:options(C2, SipC1, [Hds1, {fields, [reason]}]),
{ok, 408, [{reason_phrase, <<"Timer F Timeout">>}]} =
nksip_uac:options(C2, SipC1, [Hds1, {fields, [reason_phrase]}]),

% INVITE sends
Hds2 = {headers, [{"Nk-Op", busy}, {"Nk-Prov", "true"}, {"Nk-Sleep", 20000}]},
{ok, 408, [{reason, Reason}]} =
nksip_uac:invite(C2, SipC1, [Hds2, {fields, [reason]}]),
{ok, 408, [{reason_phrase, Reason}]} =
nksip_uac:invite(C2, SipC1, [Hds2, {fields, [reason_phrase]}]),

% TODO: Should fire timer C, sometimes it fires timer B
case Reason of
Expand Down
20 changes: 10 additions & 10 deletions test/uas_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ uas() ->
{ok, 200, Values1} = nksip_uac:options(C1, "sip:127.0.0.1", Opts1),
[{call_id, CallId1}, {from, From1}, {cseq_num, CSeq1}] = Values1,
ForceLoopOpts1 = [{call_id, CallId1}, {from, From1}, {cseq, CSeq1},
{fields, [reason]} | Opts1],
{ok, 482, [{reason, <<"Loop Detected">>}]} =
{fields, [reason_phrase]} | Opts1],
{ok, 482, [{reason_phrase, <<"Loop Detected">>}]} =
nksip_uac:options(C1, "sip:127.0.0.1", ForceLoopOpts1),

% Stateless proxies do not detect loops
Expand Down Expand Up @@ -112,9 +112,9 @@ uas() ->
[<<"a,b,d">>] = proplists:get_all_values(<<"Unsupported">>, Hds6),

% Force invalid response
Opts7 = [{headers, [{"Nksip-Op", "reply-invalid"}]}, {fields, [reason]}],
Opts7 = [{headers, [{"Nksip-Op", "reply-invalid"}]}, {fields, [reason_phrase]}],
nksip_trace:warning("Next warning about a invalid sipreply is expected"),
{ok, 500, [{reason, <<"Invalid SipApp Response">>}]} =
{ok, 500, [{reason_phrase, <<"Invalid SipApp Response">>}]} =
nksip_uac:options(C1, "sip:127.0.0.1", Opts7),
ok.

Expand Down Expand Up @@ -183,19 +183,19 @@ timeout() ->
ok = nksip_sipapp_srv:put_opts(C1, Opts1),

% Client1 callback module has a 50msecs delay in route()
{ok, 500, [{reason, <<"No SipApp Response">>}]} =
nksip_uac:options(C2, SipC1, [{fields, [reason]}]),
{ok, 500, [{reason_phrase, <<"No SipApp Response">>}]} =
nksip_uac:options(C2, SipC1, [{fields, [reason_phrase]}]),

Opts2 = [{timer_t1, 10}, {timer_c, 500}|Opts] -- [{sipapp_timeout, 50}],
ok = nksip_sipapp_srv:put_opts(C1, Opts2),

Hds1 = {headers, [{<<"Nk-Sleep">>, 2000}]},
{ok, 408, [{reason, <<"No-INVITE Timeout">>}]} =
nksip_uac:options(C2, SipC1, [Hds1, {fields, [reason]}]),
{ok, 408, [{reason_phrase, <<"No-INVITE Timeout">>}]} =
nksip_uac:options(C2, SipC1, [Hds1, {fields, [reason_phrase]}]),

Hds2 = {headers, [{"Nk-Op", busy}, {"Nk-Sleep", 2000}]},
{ok, 408, [{reason, <<"Timer C Timeout">>}]} =
nksip_uac:invite(C2, SipC1, [Hds2, {fields, [reason]}]),
{ok, 408, [{reason_phrase, <<"Timer C Timeout">>}]} =
nksip_uac:invite(C2, SipC1, [Hds2, {fields, [reason_phrase]}]),
ok.


Expand Down

0 comments on commit ffa3e67

Please sign in to comment.