diff --git a/include/nksip.hrl b/include/nksip.hrl index e9d072ca..ae1b497f 100644 --- a/include/nksip.hrl +++ b/include/nksip.hrl @@ -134,14 +134,14 @@ id :: nksip_sipmsg:id(), class :: {req, nksip:method()} | {resp, nksip:sip_code(), binary()}, srv_id :: nkserver:id(), - dialog_id :: nksip_dialog_lib:id(), - ruri :: nksip:uri(), + dialog_id :: nksip_dialog_lib:id() | undefined, + ruri :: nksip:uri() | undefined, vias = [] :: [nksip:via()], - from :: {nksip:uri(), FromTag::binary()}, - to :: {nksip:uri(), ToTag::binary()}, + from :: {nksip:uri(), FromTag::binary()} | undefined, + to :: {nksip:uri(), ToTag::binary()} | undefined, call_id :: nksip:call_id(), - cseq :: {nksip:cseq(), nksip:method()}, - forwards :: non_neg_integer(), + cseq :: {nksip:cseq(), nksip:method()} | undefined, + forwards :: non_neg_integer() | undefined, routes = [] :: [nksip:uri()], contacts = [] :: [nksip:uri()], content_type :: nksip:token() | undefined, @@ -152,7 +152,7 @@ headers = [] :: [nksip:header()], body = <<>> :: nksip:body(), to_tag_candidate = <<>> :: nksip:tag(), - nkport :: nkpacket:nkport(), + nkport :: nkpacket:nkport() | undefined, start :: nklib_util:l_timestamp(), meta = [] :: nksip:optslist() % No current use }). @@ -166,7 +166,7 @@ }). -record(via, { - transp = udp :: nkpacket:transport(), + transp = udp :: nkpacket:transport() | binary(), domain = <<"invalid.invalid">> :: binary(), port = 0 :: inet:port_number(), opts = [] :: nksip:optslist() @@ -175,33 +175,33 @@ -record(invite, { status :: nksip_dialog:invite_status(), - answered :: nklib_util:timestamp(), - class :: uac | uas | proxy, - request :: nksip:request(), - response :: nksip:response(), - ack :: nksip:request(), - local_sdp :: nksip_sdp:sdp(), - remote_sdp :: nksip_sdp:sdp(), - media_started :: boolean(), + answered :: nklib_util:timestamp() | undefined, + class :: uac | uas | proxy | undefined, + request :: nksip:request() | undefined, + response :: nksip:response() | undefined, + ack :: nksip:request() | undefined, + local_sdp :: nksip_sdp:sdp() | undefined, + remote_sdp :: nksip_sdp:sdp() | undefined, + media_started :: boolean() | undefined, sdp_offer :: nksip_call_dialog:sdp_offer(), sdp_answer :: nksip_call_dialog:sdp_offer(), - timeout_timer :: reference(), - retrans_timer :: reference(), - next_retrans :: integer() + timeout_timer :: reference() | undefined, + retrans_timer :: reference() | undefined, + next_retrans :: integer() | undefined }). -record(subscription, { id :: nksip_subscription_lib:id(), event :: nksip:token(), - expires :: pos_integer(), + expires :: pos_integer() | undefined, status :: nksip_subscription:status(), class :: uac | uas, - answered :: nklib_util:timestamp(), - timer_n :: reference(), - timer_expire :: reference(), - timer_middle :: reference(), - last_notify_cseq :: nksip:cseq() + answered :: nklib_util:timestamp() | undefined, + timer_n :: reference() | undefined, + timer_expire :: reference() | undefined, + timer_middle :: reference() | undefined, + last_notify_cseq :: nksip:cseq() | undefined }). @@ -214,10 +214,10 @@ call_id :: nksip:call_id(), created :: nklib_util:timestamp(), updated :: nklib_util:timestamp(), - local_seq :: 0 | nksip:cseq(), - remote_seq :: 0 | nksip:cseq(), - local_uri :: nksip:uri(), - remote_uri :: nksip:uri(), + local_seq :: 0 | nksip:cseq() | undefined, + remote_seq :: 0 | nksip:cseq() | undefined, + local_uri :: nksip:uri() | undefined, + remote_uri :: nksip:uri() | undefined, local_target :: nksip:uri(), % Only for use in proxy remote_target :: nksip:uri(), route_set :: [nksip:uri()], @@ -225,7 +225,7 @@ early :: boolean(), secure :: boolean(), caller_tag :: nksip:tag(), - invite :: nksip:invite(), + invite :: nksip:invite() | undefined, subscriptions = [] :: [#subscription{}], supported = [] :: [nksip:token()], meta = [] :: nksip:optslist() @@ -239,10 +239,10 @@ nports = 1 :: integer(), proto = <<"RTP/AVP">> :: binary(), fmt = [] :: [binary()], % <<"0">>, <<"101">> ... - info :: binary(), - connect :: nksip_sdp:address(), + info :: binary() | undefined, + connect :: nksip_sdp:address() | undefined, bandwidth = [] :: [binary()], - key :: binary(), + key :: binary() | undefined, attributes = [] :: [nksip_sdp:sdp_a()] }). @@ -253,15 +253,15 @@ vsn = 0 :: non_neg_integer(), address = {<<"IN">>, <<"IP4">>, <<"0.0.0.0">>} :: nksip_sdp:address(), session = <<"nksip">> :: binary(), - info :: binary(), - uri :: binary(), - email :: binary(), - phone :: binary(), - connect :: nksip_sdp:address(), + info :: binary() | undefined, + uri :: binary() | undefined, + email :: binary() | undefined, + phone :: binary() | undefined, + connect :: nksip_sdp:address() | undefined, bandwidth = [] :: [binary()], time = [] :: [nksip_sdp:sdp_t()], - zone :: binary(), - key :: binary(), + zone :: binary() | undefined, + key :: binary() | undefined, attributes = [] :: [nksip_sdp:sdp_a()], medias = [] :: [nksip_sdp:sdp_m()] }). diff --git a/include/nksip_call.hrl b/include/nksip_call.hrl index 14744ba7..82518c01 100644 --- a/include/nksip_call.hrl +++ b/include/nksip_call.hrl @@ -71,27 +71,27 @@ -record(trans, { id :: nksip_call:trans_id(), class :: uac | uas, - status :: nksip_call_uac:status() | nksip_call_uas:status(), + status :: nksip_call_uac:status() | nksip_call_uas:status() | undefined, start :: nklib_util:timestamp(), - from :: none | {srv, {pid(), term()}} | {fork, nksip_call_fork:id()}, + from :: none | {srv, {pid(), term()}} | {fork, nksip_call_fork:id()} | undefined, opts :: nksip:optslist(), - trans_id :: integer(), - request :: nksip:request(), + trans_id :: integer() | undefined, + request :: nksip:request() | undefined, method :: nksip:method(), ruri :: nksip:uri(), - transp :: nkpacket:transport(), - response :: nksip:response(), + transp :: nkpacket:transport() | undefined, + response :: nksip:response() | undefined, code :: 0 | nksip:sip_code(), to_tags = [] :: [nksip:tag()], - stateless :: boolean(), + stateless :: boolean() | undefined, iter = 1 :: pos_integer(), cancel :: undefined | to_cancel | cancelled, - loop_id :: integer(), - timeout_timer :: {nksip_call_lib:timeout_timer(), reference()}, - retrans_timer :: {nksip_call_lib:retrans_timer(), reference()}, - next_retrans :: non_neg_integer(), - expire_timer :: {nksip_call_lib:expire_timer(), reference()}, - ack_trans_id :: integer(), + loop_id :: integer() | undefined, + timeout_timer :: {nksip_call_lib:timeout_timer(), reference()} | undefined, + retrans_timer :: {nksip_call_lib:retrans_timer(), reference()} | undefined, + next_retrans :: non_neg_integer() | undefined, + expire_timer :: {nksip_call_lib:expire_timer(), reference()} | undefined, + ack_trans_id :: integer() | undefined, meta = [] :: nksip:optslist() }). @@ -120,7 +120,7 @@ -type call_auth() :: { nksip_dialog_lib:id(), - nkpacket:nkport(), + nkpacket:transport(), inet:ip_address(), inet:port_number() }. @@ -173,8 +173,8 @@ event_expires :: integer(), event_expires_offset :: integer(), nonce_timeout :: integer(), - from :: #uri{}, - accept :: [binary()], + from :: #uri{} | undefined, + accept :: [binary()] | undefined, events :: [binary()], route :: [#uri{}], no_100 :: boolean(), diff --git a/include/nksip_event_compositor.hrl b/include/nksip_event_compositor.hrl index 63c12b90..d8d4ab11 100755 --- a/include/nksip_event_compositor.hrl +++ b/include/nksip_event_compositor.hrl @@ -21,7 +21,7 @@ -record(reg_publish, { data :: nksip:body(), - expires :: nklib_util:timestamp(), + expires :: nklib_util:timestamp() | undefined, meta = [] :: nksip:optslist() }). diff --git a/include/nksip_registrar.hrl b/include/nksip_registrar.hrl index 80d7970f..6b71002f 100755 --- a/include/nksip_registrar.hrl +++ b/include/nksip_registrar.hrl @@ -20,24 +20,24 @@ -record(reg_contact, { - index :: nksip_registrar_lib:index(), - contact :: nksip:uri(), - updated :: nklib_util:l_timestamp(), - expire :: nklib_util:timestamp(), - q :: float(), - call_id :: nksip:call_id(), - cseq :: nksip:cseq(), - nkport :: nkpacket:nkport(), - path = [] :: [nksip:uri()], - meta = [] :: nksip:optslist() + index :: nksip_registrar_lib:index() | undefined, + contact :: nksip:uri() | undefined, + updated :: nklib_util:l_timestamp() | undefined, + expire :: nklib_util:timestamp() | undefined, + q :: float() | undefined, + call_id :: nksip:call_id() | undefined, + cseq :: nksip:cseq() | undefined, + nkport :: nkpacket:nkport() | undefined, + path = [] :: [nksip:uri()] | undefined, + meta = [] :: nksip:optslist() | undefined }). -record(nksip_registrar_time, { min :: pos_integer(), max :: pos_integer(), default :: pos_integer(), - time :: pos_integer(), - time_long :: pos_integer() + time :: pos_integer() | undefined, + time_long :: pos_integer() | undefined }). diff --git a/include/nksip_uac_auto_outbound.hrl b/include/nksip_uac_auto_outbound.hrl index 6fab350a..cc9bdab1 100755 --- a/include/nksip_uac_auto_outbound.hrl +++ b/include/nksip_uac_auto_outbound.hrl @@ -23,8 +23,8 @@ id :: term(), pos :: integer(), cseq :: nksip:cseq(), - conn_monitor :: reference(), - conn_pid :: pid(), + conn_monitor :: reference() | undefined, + conn_pid :: pid() | undefined, fails :: non_neg_integer() }). diff --git a/include/nksip_uac_auto_register.hrl b/include/nksip_uac_auto_register.hrl index b8a8e7e3..59200ecc 100755 --- a/include/nksip_uac_auto_register.hrl +++ b/include/nksip_uac_auto_register.hrl @@ -27,8 +27,8 @@ interval :: non_neg_integer(), from :: any(), cseq :: nksip:cseq(), - next :: nklib_util:timestamp(), - ok :: boolean() + next :: nklib_util:timestamp() | undefined, + ok :: boolean() | undefined }). diff --git a/rebar.config b/rebar.config index 9a7906a0..1810f286 100644 --- a/rebar.config +++ b/rebar.config @@ -19,3 +19,5 @@ {nkpacket, {git, "https://github.com/netcomposer/nkpacket", {branch, "master"}}}, {nkserver, {git, "https://github.com/netcomposer/nkserver", {branch, "master"}}} ]}. + +{dialyzer, [{plt_extra_apps, [ nklib, nkpacket, nkserver, cowboy, cowlib, ranch ]}]}. diff --git a/src/nksip.erl b/src/nksip.erl index f087925e..f679ee8f 100644 --- a/src/nksip.erl +++ b/src/nksip.erl @@ -58,7 +58,7 @@ -type config() :: #{ - plugins => [atom()], + plugins => [any()], sip_listen => binary(), sip_allow => binary(), sip_supported => binary(), @@ -224,7 +224,7 @@ stop(Id) -> %% @doc Retrieves a service as a supervisor child specification -spec get_sup_spec(id(), config()) -> - {ok, supervisor:child_spec()} | {error, term()}. + supervisor:child_spec(). get_sup_spec(Id, Config) -> Config2 = nklib_util:to_map(Config), diff --git a/src/nksip_auth.erl b/src/nksip_auth.erl index 04d650f3..652bc87a 100644 --- a/src/nksip_auth.erl +++ b/src/nksip_auth.erl @@ -763,13 +763,13 @@ ha1_test() -> ?assertMatch( <<"194370e184088fb011b140d770936009">>, make_auth_response([], 'INVITE', <<"test@test.com">>, HA1, - <<"gfedcba">>, <<"abcdefg">>, 1)), + <<"gfedcba">>, <<"abcdefg">>, <<"00000001">>)), ?assertMatch( - <<"788a70e3b5d371dc5f9dee5e59bb80cd">>, + <<"bf47fa2667ddc2be29b88d0cec6ae35e">>, make_auth_response([other, auth], 'INVITE', <<"test@test.com">>, HA1, - <<"gfedcba">>, <<"abcdefg">>, 1)), + <<"gfedcba">>, <<"abcdefg">>, <<"00000001">>)), ?assertMatch(<<>>, make_auth_response([other], 'INVITE', <<"any">>, HA1, <<"any">>, - <<"any">>, 1)), + <<"any">>, <<"00000001">>)), [ {scheme,digest}, {realm,<<"av">>}, diff --git a/src/nksip_call_proxy.erl b/src/nksip_call_proxy.erl index e813b634..db50dffa 100644 --- a/src/nksip_call_proxy.erl +++ b/src/nksip_call_proxy.erl @@ -38,7 +38,7 @@ %% @doc Tries to route a request to set of uris, serially and/or in parallel. -spec route(nksip:uri_set(), nksip:optslist(), nksip_call:trans(), nksip_call:call()) -> - {fork, nksip_call:trans(), nksip:uri_set()} | noreply | + {fork, nksip_call:trans(), nksip:uri_set()} | {reply, nksip:sipreply(), nksip_call:call()}. route(UriList, ProxyOpts, UAS, Call) -> @@ -197,7 +197,7 @@ check_request(#sipmsg{class={req, Method}, forwards=Forwards}=Req, Opts) -> %% @doc Process a UriSet generating a standard `[[nksip:uri()]]'. %% See test code for examples. --spec normalize_uriset(nksip:uri_set()) -> +-spec normalize_uriset(nksip:uri_set() | atom() | [atom()]) -> [[nksip:uri()]]. normalize_uriset(#uri{}=Uri) -> diff --git a/src/nksip_call_uac.erl b/src/nksip_call_uac.erl index d35ac711..2ddfb6da 100644 --- a/src/nksip_call_uac.erl +++ b/src/nksip_call_uac.erl @@ -26,6 +26,7 @@ -export([is_stateless/1, response/2]). -export_type([status/0, uac_from/0]). -import(nksip_call_lib, [update/2]). +-dialyzer(no_missing_calls). -include("nksip.hrl"). -include("nksip_call.hrl"). diff --git a/src/nksip_call_uac_make.erl b/src/nksip_call_uac_make.erl index 77bbf410..9d3097c7 100644 --- a/src/nksip_call_uac_make.erl +++ b/src/nksip_call_uac_make.erl @@ -241,7 +241,7 @@ make_ack(#sipmsg{vias=[Via|_], cseq={CSeq, _}}=Req) -> %% @private --spec parse_opts(nksip:optslist(), nksip:request(), nksip:optslist()) -> +-spec parse_opts([nksip_uac:req_option()], nksip:request(), nksip:optslist()) -> {nksip:request(), nksip:optslist()}. @@ -494,7 +494,7 @@ parse_opts([Term|Rest], Req, Opts) -> %% @private -spec parse_plugin_opts(nksip:request(), map()) -> - {nksip:request(), map()}. + {nksip:request(), [nksip_uac:req_option()]}. parse_plugin_opts(#sipmsg{srv_id=SrvId}=Req, Opts) -> case ?CALL_SRV(SrvId, nksip_parse_uac_opts, [Req, Opts]) of diff --git a/src/nksip_call_uac_transp.erl b/src/nksip_call_uac_transp.erl index 1ce8dc9d..4f81dd15 100644 --- a/src/nksip_call_uac_transp.erl +++ b/src/nksip_call_uac_transp.erl @@ -23,6 +23,7 @@ -author('Carlos Gonzalez '). -export([send_request/3, resend_request/2, add_headers/6]). +-dialyzer(no_missing_calls). -include_lib("nklib/include/nklib.hrl"). -include_lib("nkpacket/include/nkpacket.hrl"). @@ -128,7 +129,7 @@ send_request(Req, Call, Opts) -> -spec resend_request(nksip:request(), nksip:optslist()) -> {ok, nksip:request()} | error. -resend_request(#sipmsg{ srv_id=SrvId, nkport=NkPort}=Req, Opts) -> +resend_request(#sipmsg{ srv_id=SrvId, nkport=NkPort}=Req, Opts) when NkPort =/= undefined -> Msg = fun(NkPort2) -> Req#sipmsg{nkport=NkPort2} end, nksip_util:send(SrvId, [NkPort], Msg, Opts). diff --git a/src/nksip_call_uas.erl b/src/nksip_call_uas.erl index b46d3884..bbd71b1b 100644 --- a/src/nksip_call_uas.erl +++ b/src/nksip_call_uas.erl @@ -24,6 +24,7 @@ -export([request/2, reply/3, do_reply/3]). -export_type([status/0, incoming/0]). +-dialyzer(no_missing_calls). -import(nksip_call_lib, [update/2]). -include_lib("nklib/include/nklib.hrl"). diff --git a/src/nksip_call_uas_route.erl b/src/nksip_call_uas_route.erl index 62feb0d5..b8b2f0fe 100644 --- a/src/nksip_call_uas_route.erl +++ b/src/nksip_call_uas_route.erl @@ -278,9 +278,6 @@ do_route(process_stateless, UAS, Call) -> do_route({proxy, UriList, ProxyOpts}, UAS, Call) -> #trans{id=Id, opts=Opts, method=Method} = UAS, case nksip_call_proxy:route(UriList, ProxyOpts, UAS, Call) of - noreply -> - UAS1 = UAS#trans{status=finished}, - update(UAS1, Call); {fork, _, _, _} when Method=='CANCEL' -> nksip_call_uas:do_reply(no_transaction, UAS, Call); {fork, UAS1, UriSet, ProxyOpts1} -> diff --git a/src/nksip_call_uas_transp.erl b/src/nksip_call_uas_transp.erl index c51e610f..4b5abcb2 100644 --- a/src/nksip_call_uas_transp.erl +++ b/src/nksip_call_uas_transp.erl @@ -23,6 +23,7 @@ -author('Carlos Gonzalez '). -export([send_response/2, resend_response/2]). +-dialyzer(no_missing_calls). -include_lib("nklib/include/nklib.hrl"). -include_lib("nkpacket/include/nkpacket.hrl"). diff --git a/src/nksip_call_worker.erl b/src/nksip_call_worker.erl index e0d6d4c5..cc544a14 100644 --- a/src/nksip_call_worker.erl +++ b/src/nksip_call_worker.erl @@ -44,6 +44,7 @@ {cancel, nksip_sipmsg:id()} | {send_reply, nksip_sipmsg:id(), nksip:sipreply()} | {incoming, #sipmsg{}} | + {incoming, #nkport{}, binary()} | {incoming, nkserver:id(), nkservice:id(), nksip:call_id(), nkpacket:nkport(), binary()} | info | get_all_dialogs | diff --git a/src/nksip_dialog.erl b/src/nksip_dialog.erl index 4713c6eb..21dd6d34 100644 --- a/src/nksip_dialog.erl +++ b/src/nksip_dialog.erl @@ -108,7 +108,7 @@ call_id(Handle) -> %% @doc Get a specific metadata --spec get_meta(field(), nksip:dialog()|nksip:handle()) -> +-spec get_meta(field() | {function, function()}, nksip:dialog()|nksip:handle()) -> {ok, term()} | {error, term()}. get_meta(Field, #dialog{}=Dialog) -> diff --git a/src/nksip_dialog_lib.erl b/src/nksip_dialog_lib.erl index 61bd8927..68e2345f 100644 --- a/src/nksip_dialog_lib.erl +++ b/src/nksip_dialog_lib.erl @@ -86,7 +86,7 @@ parse_handle(_O) -> %% @doc Get specific metadata from the dialog --spec get_meta(nksip_dialog:field(), nksip:dialog()) -> +-spec get_meta(nksip_dialog:field() | {function, function()}, nksip:dialog()) -> term(). get_meta(Field, #dialog{invite=I}=D) -> @@ -166,7 +166,7 @@ get_meta(Field, #dialog{invite=I}=D) -> end. %% @doc Get specific metadata from the dialog --spec get_metas([nksip_dialog:field()], nksip:dialog()|nksip:handle()) -> +-spec get_metas([nksip_dialog:field() | {function, function()}], nksip:dialog()|nksip:handle()) -> [{nksip_dialog:field(), term()}]. get_metas(Fields, #dialog{}=Dialog) when is_list(Fields) -> @@ -187,7 +187,7 @@ remote_meta(Field, Handle) -> %% @doc Extracts remote metas --spec remote_metas([nksip_dialog:field()], nksip:handle()) -> +-spec remote_metas([nksip_dialog:field() | {function, function()}], nksip:handle()) -> {ok, [{nksip_dialog:field(), term()}]} | {error, term()}. remote_metas(Fields, Handle) when is_list(Fields) -> diff --git a/src/nksip_parse.erl b/src/nksip_parse.erl index 06c299af..7e47cbf4 100644 --- a/src/nksip_parse.erl +++ b/src/nksip_parse.erl @@ -161,7 +161,7 @@ vias(Term) -> UriOrVia :: nksip:uri() | other_test | nksip:via(), - Transport :: nkpacket:transport(), + Transport :: nkpacket:transport() | binary(), Host :: binary(), Port :: inet:port_number(). diff --git a/src/nksip_parse_header.erl b/src/nksip_parse_header.erl index 7acac055..4919b0af 100644 --- a/src/nksip_parse_header.erl +++ b/src/nksip_parse_header.erl @@ -486,10 +486,14 @@ uri_test() -> [#uri{headers=UriHeaders}] = nklib_parse:uris(Uri), Base = #sipmsg{ + id = <<"id">>, + class = {req, 'MESSAGE'}, + call_id = <<"call-id">>, from = {#uri{domain = <<"f">>, ext_opts=[{<<"tag">>, <<"f">>}]}, <<"f">>}, to = {#uri{domain = <<"t">>, ext_opts=[{<<"tag">>, <<"t">>}]}, <<"t">>}, headers = [{<<"previous">>, <<"term">>}], - routes = [#uri{domain = <<"previous">>}] + routes = [#uri{domain = <<"previous">>}], + start = nklib_util:timestamp() }, Req1 = headers(UriHeaders, Base, add), diff --git a/src/nksip_protocol.erl b/src/nksip_protocol.erl index 70710c88..086f1ed4 100644 --- a/src/nksip_protocol.erl +++ b/src/nksip_protocol.erl @@ -35,6 +35,9 @@ -include_lib("nkpacket/include/nkpacket.hrl"). -include_lib("nkserver/include/nkserver.hrl"). +-dialyzer(no_missing_calls). +-dialyzer(no_undefined_callbacks). + -define(MAX_MSG, 65507). @@ -123,10 +126,10 @@ naptr(_, _) -> invalid. buffer = <<>> :: binary(), rnrn_pattern :: binary:cp(), in_refresh = false :: boolean(), - refresh_time :: pos_integer(), - refresh_timer :: reference(), - nat_ip :: inet:ip_address(), - nat_port :: inet:port_number(), + refresh_time :: pos_integer() | undefined, + refresh_timer :: reference() | undefined, + nat_ip :: inet:ip_address() | undefined, + nat_port :: inet:port_number() | undefined, refresh_notify = [] :: [{pid(), term()}] }). @@ -154,7 +157,7 @@ conn_init(NkPort) -> %% @doc This function is called when a new message arrives to the connection -spec conn_parse(nkpacket:incoming()|close, nkpacket:nkport(), conn_state()) -> - {ok, conn_state()} | {bridge, nkpacket:nkport()} | + {ok, conn_state()} | {bridge, nkpacket:nkport(), conn_state()} | {stop, Reason::term(), conn_state()}. conn_parse(close, _NkPort, State) -> @@ -183,15 +186,14 @@ conn_parse(Binary, NkPort, #conn_state{buffer=Buffer}=State) -> %% @doc This function is called when a new message must be send to the connection -spec conn_encode(term(), nkpacket:nkport(), conn_state()) -> - {ok, nkpacket:outcoming(), conn_state()} | {error, term(), conn_state()} | - {stop, Reason::term(), conn_state()}. + {error, term(), conn_state()}. conn_encode(_Term, _NkPort, ConnState) -> {error, not_defined, ConnState}. -spec conn_encode(nksip:request()|nksip:response(), nkpacket:nkport()) -> - {ok, nkpacket:outcoming()} | continue | {error, term()}. + {ok, nkpacket:outcoming()}. conn_encode(#sipmsg{srv_id=SrvId}=SipMsg, _NkPort) -> Packet = nksip_unparse:packet(SipMsg), diff --git a/src/nksip_router.erl b/src/nksip_router.erl index 565d7531..03ce236f 100644 --- a/src/nksip_router.erl +++ b/src/nksip_router.erl @@ -30,6 +30,8 @@ -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]). +-dialyzer(no_missing_calls). + -include("nksip.hrl"). -include("nksip_call.hrl"). @@ -50,7 +52,7 @@ send_work(SrvId, CallId, Work) -> %% @doc Called when a new request or response has been received. -spec incoming(nkserver:id(), nksip:call_id(), nkpacket:nkport(), binary()) -> - ok | {error, too_many_calls | looped_process | {exit, term()}}. + any() | {error, too_many_calls | looped_process | {exit, term()}}. incoming(SrvId, CallId, NkPort, Msg) -> Work = {incoming, NkPort, Msg}, @@ -58,7 +60,7 @@ incoming(SrvId, CallId, NkPort, Msg) -> %% @doc Sends a synchronous piece of {@link nksip_call_worker:work()} to a call. --spec send_work(nkserver:id(), nksip:call_id(), nksip_call_worker:work(), pid()) -> +-spec send_work(nkserver:id(), nksip:call_id(), nksip_call_worker:work(), pid() | none) -> any() | {error, too_many_calls | looped_process | {exit, term()}}. send_work(SrvId, CallId, Work, Caller) -> @@ -232,8 +234,8 @@ worker_name(CallId) -> %% @private --spec send_work_sync(nkserver:id(), nksip:call_id(), nksip_call_worker:work(), - pid() | none, {pid(), term()}, #state{}) -> +-spec send_work_sync(nksip:srv_id(), nksip:call_id(), nksip_call_worker:work(), + pid() | none, {pid(), term()} | none, #state{}) -> {ok, #state{}} | {error, looped_process | service_not_found | too_many_calls}. send_work_sync(SrvId, CallId, Work, Caller, From, State) -> diff --git a/src/nksip_sample.erl b/src/nksip_sample.erl deleted file mode 100755 index 054ae9a4..00000000 --- a/src/nksip_sample.erl +++ /dev/null @@ -1,50 +0,0 @@ -%% ------------------------------------------------------------------- -%% -%% Copyright (c) 2019 Carlos Gonzalez Florido. All Rights Reserved. -%% -%% This file is provided to you under the Apache License, -%% Version 2.0 (the "License"); you may not use this file -%% except in compliance with the License. You may obtain -%% a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, -%% software distributed under the License is distributed on an -%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -%% KIND, either express or implied. See the License for the -%% specific language governing permissions and limitations -%% under the License. -%% -%% ------------------------------------------------------------------- - -%% @doc Companion code for NkSIP Tutorial. - - --module(nksip_sample). --author('Carlos Gonzalez '). - --export([start/0, stop/0]). --export([s1/0]). - --define(NAME, test). - - - -%% @doc Launches the full tutorial. -start() -> - Spec = #{ - callback => ?MODULE, - sip_debug => [nkpacket, call, protocol] - - }, - nksip:start(?NAME, Spec). - - - -stop() -> - nksip:stop(?NAME). - - -s1() -> - nksip_uac:options(?NAME, <<"sip1">>, ";transport=tcp", []). \ No newline at end of file diff --git a/src/nksip_sdp.erl b/src/nksip_sdp.erl index 0a4a077a..8286357d 100644 --- a/src/nksip_sdp.erl +++ b/src/nksip_sdp.erl @@ -27,6 +27,8 @@ -export([new/2, new/0, empty/0, update/2, increment/1, parse/1, unparse/1]). -export([is_sdp/1, is_new/2, update_ip/2]). +-dialyzer(no_behaviours). + -export_type([sdp/0, sdp_a/0, sdp_m/0, sdp_t/0, address/0]). %% =================================================================== @@ -54,7 +56,7 @@ Media :: binary(), % <<"audio">>, <<"video">> Port :: inet:port_number(), Attributes :: - [{rtpmap, Pos::integer(), Data::binary()} | binary()] + [{rtpmap, Pos::integer(), Data::string() | binary()} | binary()] }. @@ -669,8 +671,8 @@ sdp2_test() -> sdp3_test() -> Media = [ - {<<"audio">>, 10000, [{rtpmap, 0, "Params0"}, {rtpmap, 1, "Params1"}, sendrecv]}, - {<<"video">>, 10001, [{rtpmap, 2, "Params2"}, {rtpmap, 3, "Params3"}, sendrecv]} + {<<"audio">>, 10000, [{rtpmap, 0, "Params0"}, {rtpmap, 1, "Params1"}, <<"sendrecv">>]}, + {<<"video">>, 10001, [{rtpmap, 2, "Params2"}, {rtpmap, 3, "Params3"}, <<"sendrecv">>]} ], #sdp{id=Id, vsn=Vsn} = SDP = new("local", Media), Bin = list_to_binary([ diff --git a/src/nksip_sdp_util.erl b/src/nksip_sdp_util.erl index 96b79e60..bc877d3a 100755 --- a/src/nksip_sdp_util.erl +++ b/src/nksip_sdp_util.erl @@ -61,12 +61,8 @@ #sdp{} | {error, term()}. add_candidates(#sdp{medias=Medias}=SDP, Candidates) -> - case add_candidates(Medias, 0, Candidates, []) of - {ok, Medias2} -> - SDP#sdp{medias=Medias2}; - {error, Error} -> - {error, Error} - end; + {ok, Medias2} = add_candidates(Medias, 0, Candidates, []), + SDP#sdp{medias=Medias2}; add_candidates(SDP, Candidates) -> case nksip_sdp:parse(SDP) of diff --git a/src/nksip_sup.erl b/src/nksip_sup.erl index 0feacfb4..6a5fe19f 100644 --- a/src/nksip_sup.erl +++ b/src/nksip_sup.erl @@ -26,6 +26,7 @@ % -export([start_sipapp/2, stop_sipapp/1]). -export([init/1, start_link/0]). +-dialyzer(no_missing_calls). -include("nksip.hrl"). diff --git a/src/nksip_uac.erl b/src/nksip_uac.erl index b5a14a1d..8405c24f 100644 --- a/src/nksip_uac.erl +++ b/src/nksip_uac.erl @@ -66,8 +66,14 @@ allow | accept | allow_event | + contact | % Special parameters + async | + ignore | + auto_2xx_ack | + + date | to_as_from | {body, value()} | {cseq_num, value()} | @@ -89,6 +95,7 @@ % Subscription {subscription_state, term()} | {refer_to, binary()} | + {refer_subscription_id, binary()} | % Publish {sip_if_match, binary()} | diff --git a/src/nksip_util.erl b/src/nksip_util.erl index 9e44a30e..452cf106 100644 --- a/src/nksip_util.erl +++ b/src/nksip_util.erl @@ -27,6 +27,8 @@ -export([get_connected/2, get_connected/5, is_local/2, send/4]). -export([print_all/0, user_callback/3]). +-dialyzer(no_missing_calls). + -include_lib("nklib/include/nklib.hrl"). -include_lib("nkpacket/include/nkpacket.hrl"). -include_lib("nkserver/include/nkserver.hrl"). @@ -166,8 +168,8 @@ is_local(SrvId, #via{}=Via) -> %% @private -spec send(nkserver:id(), [nkpacket:send_spec()], - nksip:request()|nksip:response()|function(), - [nksip_uac:req_option()]) -> + function()|nksip:request()|nksip:response(), + list()) -> {ok, #sipmsg{}} | {error, term()}. send(SrvId, Spec, Msg, Opts) when is_list(Spec) -> diff --git a/src/plugins/nksip_debug.erl b/src/plugins/nksip_debug.erl index c3f67a92..e741e675 100755 --- a/src/plugins/nksip_debug.erl +++ b/src/plugins/nksip_debug.erl @@ -43,7 +43,7 @@ start(SrvId) -> Plugins1 = ?CALL_SRV(SrvId, plugins, []), Plugins2 = nklib_util:store_value(nksip_debug, Plugins1), - case nksip:update(SrvId, #{plugins=>Plugins2, sip_debug=>true}) of + case nksip:update(SrvId, #{plugins=>Plugins2, sip_debug=>[nkpacket,call,protocol]}) of ok -> ok; {error, Error} -> @@ -58,7 +58,7 @@ start(SrvId) -> stop(SrvId) -> Plugins1 = ?CALL_SRV(SrvId, plugins, []), Plugins2 = Plugins1 -- [nksip_debug], - case nksip:update(SrvId, #{plugins=>Plugins2, sip_debug=>false}) of + case nksip:update(SrvId, #{plugins=>Plugins2, sip_debug=>[]}) of ok -> ok; {error, Error} -> diff --git a/src/plugins/nksip_gruu_lib.erl b/src/plugins/nksip_gruu_lib.erl index 9cb84eb4..8b2a93a4 100755 --- a/src/plugins/nksip_gruu_lib.erl +++ b/src/plugins/nksip_gruu_lib.erl @@ -28,6 +28,7 @@ -include("nksip_registrar.hrl"). -export([find/2, update_gruu/1, check_gr/2, update_regcontact/4]). +-dialyzer(no_missing_calls). -define(AES_IV, <<"12345678abcdefgh">>). diff --git a/src/plugins/nksip_outbound.erl b/src/plugins/nksip_outbound.erl index 8a4d08c7..b23ab0c8 100755 --- a/src/plugins/nksip_outbound.erl +++ b/src/plugins/nksip_outbound.erl @@ -25,6 +25,7 @@ -export([proxy_opts/2, add_headers/6, check_several_reg_id/1]). -export([registrar/1]). -export([decode_flow/1]). +-dialyzer(no_missing_calls). -include_lib("nklib/include/nklib.hrl"). -include_lib("nkpacket/include/nkpacket.hrl"). @@ -176,7 +177,7 @@ do_proxy_opts(Req, Opts, [Route|RestRoutes]) -> case lists:member(<<"ob">>, RouteOpts) of true -> Opts1 = case nksip_util:get_connected(SrvId, NkPort) of - [{_, Pid}|_] -> + [Pid|_] when is_pid(Pid) -> [{record_flow, Pid}|Opts]; _ -> Opts @@ -244,7 +245,7 @@ add_headers(Req, Opts, Scheme, Transp, ListenHost, ListenPort) -> end, RouteHash = nklib_util:hash({GlobalId, SrvId, RouteBranch}), <<"NkQ", RouteHash/binary>>; - FlowPid -> + _ -> FlowToken = encode_flow(FlowPid), <<"NkF", FlowToken/binary>> end, @@ -367,7 +368,7 @@ check_several_reg_id([#uri{ext_opts=Opts}|Rest], Found) -> %% @private -spec registrar(nksip:request()) -> - {boolean(), nksip:request()} | no_outbound. + {boolean(), nksip:request()} | {error, nksip:sipreply()} | no_outbound. registrar(Req) -> #sipmsg{ srv_id=SrvId, vias=Vias, nkport=NkPort} = Req, diff --git a/src/plugins/nksip_stats_srv.erl b/src/plugins/nksip_stats_srv.erl index 7891def3..874f8555 100755 --- a/src/plugins/nksip_stats_srv.erl +++ b/src/plugins/nksip_stats_srv.erl @@ -61,8 +61,8 @@ init([Period]) -> %% @private --spec handle_call(term(), {pid(), term()}, #state{}) -> - {reply, term(), #state{}} | {noreply, #state{}}. +-spec handle_call(term(), {pid(), term()} | term(), #state{}) -> + {reply, term(), #state{}, non_neg_integer()} | {noreply, #state{}, non_neg_integer()}. handle_call(get_uas_avg, _From, #state{last_uas=LastUas}=State) -> @@ -75,7 +75,7 @@ handle_call(Msg, _From, State) -> %% @private -spec handle_cast(term(), #state{}) -> - {noreply, #state{}}. + {noreply, #state{}, non_neg_integer()}. handle_cast({response_time, Time}, #state{avg_uas_values=Values}=State) -> State1 = State#state{avg_uas_values=[Time|Values]}, @@ -88,7 +88,7 @@ handle_cast(Msg, State) -> %% @private -spec handle_info(term(), #state{}) -> - {noreply, #state{}}. + {noreply, #state{}, non_neg_integer()}. handle_info(timeout, #state{avg_uas_values=Values, period=Period}=State) -> LastUas = calculate(Values), @@ -124,6 +124,8 @@ terminate(_Reason, _State) -> %% @private +-spec timeout(#state{}) -> non_neg_integer(). + timeout(#state{last_check=Last, period=Period}) -> case (Last+Period) - nklib_util:timestamp() of Time when Time > 0 -> diff --git a/src/plugins/nksip_timers_callbacks.erl b/src/plugins/nksip_timers_callbacks.erl index e571bd8e..9562bb1f 100755 --- a/src/plugins/nksip_timers_callbacks.erl +++ b/src/plugins/nksip_timers_callbacks.erl @@ -200,7 +200,8 @@ nksip_uac_response(Req, Resp, UAC, Call) -> %% @doc Called when preparing a UAS dialog response -spec nksip_uas_dialog_response(nksip:request(), nksip:response(), nksip:optslist(), nksip:call()) -> - {ok, nksip:response(), nksip:optslist()} | continue. + {ok, nksip:response(), nksip:optslist()} | + {continue, [nksip:request() | nksip:response() | nksip:optslist() | nksip:call()]}. nksip_uas_dialog_response(Req, Resp, Opts, Call) -> Resp1 = case Req of diff --git a/src/plugins/nksip_trace.erl b/src/plugins/nksip_trace.erl old mode 100755 new mode 100644 diff --git a/src/plugins/nksip_uac_auto_outbound_callbacks.erl b/src/plugins/nksip_uac_auto_outbound_callbacks.erl index 7a668b01..51016aa0 100755 --- a/src/plugins/nksip_uac_auto_outbound_callbacks.erl +++ b/src/plugins/nksip_uac_auto_outbound_callbacks.erl @@ -125,8 +125,8 @@ srv_handle_info(_Msg, _Service, _State) -> %% @doc Called when the plugin is shutdown --spec srv_terminate(nkserver:id(), nkserver:service(), map()) -> - {ok, map()}. +-spec srv_terminate(atom(), term(), map()) -> + {continue, [term()]}. srv_terminate(Reason, Service, State) -> State2 = case State of diff --git a/src/plugins/nksip_uac_auto_register_callbacks.erl b/src/plugins/nksip_uac_auto_register_callbacks.erl index 25c44702..77e71fd3 100755 --- a/src/plugins/nksip_uac_auto_register_callbacks.erl +++ b/src/plugins/nksip_uac_auto_register_callbacks.erl @@ -226,7 +226,7 @@ srv_handle_cast(nksip_uac_auto_register_check, {noreply, State2#{nksip_uac_auto_register:=RegState2#state{pings=Pings1, regs=Regs2}}}; srv_handle_cast(nksip_uac_auto_register_terminate, Service, SrvState) -> - {ok, SrvState1} = srv_terminate(normal, Service, SrvState), + {continue, [_, _, SrvState1]} = srv_terminate(normal, Service, SrvState), {noreply, SrvState1}; srv_handle_cast(_Msg, _Service, _State) -> diff --git a/test/tests/t22_ipv6.erl b/test/tests/t22_ipv6.erl old mode 100755 new mode 100644 index 9df2e306..ca02f809 --- a/test/tests/t22_ipv6.erl +++ b/test/tests/t22_ipv6.erl @@ -28,6 +28,8 @@ -include_lib("nklib/include/nklib.hrl"). -compile([export_all, nowarn_export_all]). +-dialyzer(no_missing_calls). + -define(RECV(T), receive T -> ok after 1000 -> error(recv) end). ipv6_gen() ->