Skip to content

Commit

Permalink
New user reply mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
kalta committed Mar 27, 2014
1 parent ecfc998 commit 88ed631
Show file tree
Hide file tree
Showing 14 changed files with 628 additions and 620 deletions.
2 changes: 1 addition & 1 deletion samples/nksip_loadtest/src/nksip_loadtest_sipapp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ route(_Request, _Scheme, _User, _Domain, _From) ->

%% @doc Answer the call with the same SDP body
invite(Req, _Meta, _From) ->
{ok, [], nksip_sipmsg:field(Req, body)}.
{answer, nksip_sipmsg:field(Req, body)}.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ invite(ReqId, Meta, From, #state{id=AppId}=State) ->
Fun = fun() ->
nksip_request:reply(AppId, ReqId, ringing),
timer:sleep(2000),
nksip:reply(From, {ok, [], SDP})
nksip:reply(From, {answer, SDP})
end,
spawn(Fun),
{noreply, State};
Expand Down
26 changes: 13 additions & 13 deletions src/nksip.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
-author('Carlos Gonzalez <[email protected]>').

-export([start/4, stop/1, stop_all/0, get_all/0]).
-export([get/3, get/4, put/4, del/3]).
-export([get/2, get/3, put/3, del/2]).
-export([call/2, call/3, cast/2, reply/2, get_pid/1, get_port/3]).

-include("nksip.hrl").
Expand Down Expand Up @@ -369,39 +369,39 @@ reply(From, Reply) ->


%% @doc Gets a value from SipApp's store
-spec get(nksip:app_id(), term(), sync|async) ->
-spec get(nksip:app_id(), term()) ->
{ok, term()} | not_found | error.

get(AppId, Key, Sync) ->
nksip_sipapp_srv:get(AppId, Key, Sync).
get(AppId, Key) ->
nksip_sipapp_srv:get(AppId, Key, async).


%% @doc Gets a value from SipApp's store, using a default if not found
-spec get(nksip:app_id(), term(), term(), sync|async) ->
-spec get(nksip:app_id(), term(), term()) ->
{ok, term()} | error.

get(AppId, Key, Default, Sync) ->
case get(AppId, Key, Sync) of
get(AppId, Key, Default) ->
case get(AppId, Key) of
not_found -> {ok, Default};
{ok, Value} -> {ok, Value};
error -> error
end.


%% @doc Inserts a value in SipApp's store
-spec put(nksip:app_id(), term(), term(), sync|async) ->
-spec put(nksip:app_id(), term(), term()) ->
ok | error.

put(AppId, Key, Value, Sync) ->
nksip_sipapp_srv:put(AppId, Key, Value, Sync).
put(AppId, Key, Value) ->
nksip_sipapp_srv:put(AppId, Key, Value, async).


%% @doc Deletes a value from SipApp's store
-spec del(nksip:app_id(), term(), sync|async) ->
-spec del(nksip:app_id(), term()) ->
ok | error.

del(AppId, Key, Sync) ->
nksip_sipapp_srv:del(AppId, Key, Sync).
del(AppId, Key) ->
nksip_sipapp_srv:del(AppId, Key, async).


%% @doc Sends a synchronous message to the SipApp's process,
Expand Down
2 changes: 1 addition & 1 deletion src/nksip_call_fork.erl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ launch([Uri|Rest], Id, Call) ->
{error, Error} ->
?call_warning("Error processing fork options: ~p, ~p: ~p",
[Uri, Opts, Error], Call),
Reply = {internal_error, "Fork Options"},
Reply = {internal_error, <<"Invalid Fork Options">>},
{Resp, _} = nksip_reply:reply(Req, Reply, AppOpts),
ForkT = Fork#fork{responses=[Resp|Resps]},
update(ForkT, Call1)
Expand Down
4 changes: 2 additions & 2 deletions src/nksip_call_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ check_request(#sipmsg{class={req, Method}, forwards=Forwards}=Req, Opts) ->
is_integer(Forwards), Forwards > 0 ->
ok;
Forwards==0, Method=='OPTIONS' ->
throw({reply, {ok, [], <<>>, [supported, accept, allow,
{reason_phrase, <<"Max Forwards">>}]}});
throw({reply, {ok, [supported, accept, allow,
{reason_phrase, <<"Max Forwards">>}]}});
Forwards==0 ->
throw({reply, too_many_hops});
true ->
Expand Down
2 changes: 1 addition & 1 deletion src/nksip_call_timer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ uas_check_422(#sipmsg{class={req, Method}}=Req, Call) ->
end,
case nksip_sipmsg:supported(Req, <<"timer">>) of
true ->
{reply, {422, [{<<"min-se">>, MinSE}]}, Call1};
{reply, {session_too_small, MinSE}, Call1};
false ->
% No point in returning 422
% Update in case we are a proxy
Expand Down
8 changes: 4 additions & 4 deletions src/nksip_call_uac_reply.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ reply({resp, Resp}, #trans{id=Id, from={fork, ForkId}}, Call) ->
nksip_call_fork:response(ForkId, Id, Resp, Call);

reply({error, Error}, #trans{id=Id, from={fork, ForkId}, request=Req}, Call) ->
Reply = case nksip_reply:reqreply(Error) of
Reply = case nksip_reply:parse(Error) of
error ->
?call_notice("Invalid proxy internal response: ~p", [Error], Call),
{internal_error, "Invalid Internal Proxy UAC Response"};
_ ->
Error
{internal_error, <<"Invalid Internal Proxy UAC Response">>};
{ErrCode, ErrOpts} ->
{ErrCode, ErrOpts}
end,
#call{opts=#call_opts{app_opts=AppOpts}} = Call,
{Resp, _} = nksip_reply:reply(Req, Reply, AppOpts),
Expand Down
10 changes: 4 additions & 6 deletions src/nksip_call_uas_dialog.erl
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,9 @@ get_sdp(#sipmsg{body=Body}, #invite{sdp_offer=Offer, sdp_answer=Answer}) ->

%% @private
retry() ->
{
500,
[{<<"retry-after">>, crypto:rand_uniform(0, 11)}],
<<>>,
[{reason_phrase, <<"Processing Previous INVITE">>}]
}.
{500, [
{add, "retry-after", crypto:rand_uniform(0, 11)},
{reason_phrase, <<"Processing Previous INVITE">>}
]}.


1 change: 0 additions & 1 deletion src/nksip_call_uas_reply.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
%% Private
%% ===================================================================


%% @doc Sends a transaction reply
-spec reply(incoming(), nksip_call:trans(), nksip_call:call()) ->
reply_return().
Expand Down
2 changes: 1 addition & 1 deletion src/nksip_publish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ make_reg(Body) ->

%% @private
reply(Tag, Expires) ->
{ok, [{<<"sip-etag">>, Tag}], <<>>, [{expires, Expires}]}.
{ok, [{sip_etag, Tag}, {expires, Expires}]}.


%% @private
Expand Down
3 changes: 1 addition & 2 deletions src/nksip_registrar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ request(#sipmsg{app_id=AppId, to={To, _}}=Req) ->
[_|_] -> [{require, <<"outbound">>}];
_ -> []
end,
{ok, [], <<>>,
[{contact, Contacts1}, date, allow, supported | ObReq]}
{ok, [{contact, Contacts1}, date, allow, supported | ObReq]}
catch
throw:Throw -> Throw
end.
Expand Down
Loading

0 comments on commit 88ed631

Please sign in to comment.