aboutsummaryrefslogtreecommitdiff
path: root/src/mod_sip.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mod_sip.erl')
-rw-r--r--src/mod_sip.erl118
1 files changed, 67 insertions, 51 deletions
diff --git a/src/mod_sip.erl b/src/mod_sip.erl
index 816100f47..0e8394e37 100644
--- a/src/mod_sip.erl
+++ b/src/mod_sip.erl
@@ -1,12 +1,11 @@
%%%-------------------------------------------------------------------
-%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
-%%% @doc
-%%%
-%%% @end
+%%% File : mod_sip.erl
+%%% Author : Evgeny Khramtsov <ekhramtsov@process-one.net>
+%%% Purpose : SIP RFC-3261
%%% Created : 21 Apr 2014 by Evgeny Khramtsov <ekhramtsov@process-one.net>
%%%
%%%
-%%% ejabberd, Copyright (C) 2014-2016 ProcessOne
+%%% ejabberd, Copyright (C) 2014-2019 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
@@ -21,23 +20,37 @@
%%% You should have received a copy of the GNU General Public License along
%%% with this program; if not, write to the Free Software Foundation, Inc.,
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+%%%
%%%-------------------------------------------------------------------
+
-module(mod_sip).
-protocol({rfc, 3261}).
+-include("logger.hrl").
+
+-ifndef(SIP).
+-export([start/2, stop/1, depends/2, mod_options/1]).
+start(_, _) ->
+ ?CRITICAL_MSG("ejabberd is not compiled with SIP support", []),
+ {error, sip_not_compiled}.
+stop(_) ->
+ ok.
+depends(_, _) ->
+ [].
+mod_options(_) ->
+ [].
+-else.
-behaviour(gen_mod).
-behaviour(esip).
%% API
--export([start/2, stop/1, make_response/2, is_my_host/1, at_my_host/1]).
+-export([start/2, stop/1, reload/3,
+ make_response/2, is_my_host/1, at_my_host/1]).
-export([data_in/2, data_out/2, message_in/2,
message_out/2, request/2, request/3, response/2,
- locate/1, mod_opt_type/1, depends/2]).
+ locate/1, mod_opt_type/1, mod_options/1, depends/2]).
--include("ejabberd.hrl").
--include("logger.hrl").
-include_lib("esip/include/esip.hrl").
%%%===================================================================
@@ -47,7 +60,8 @@ start(_Host, _Opts) ->
ejabberd:start_app(esip),
esip:set_config_value(max_server_transactions, 10000),
esip:set_config_value(max_client_transactions, 10000),
- esip:set_config_value(software, <<"ejabberd ", (?VERSION)/binary>>),
+ esip:set_config_value(
+ software, <<"ejabberd ", (ejabberd_option:version())/binary>>),
esip:set_config_value(module, ?MODULE),
Spec = {mod_sip_registrar, {mod_sip_registrar, start_link, []},
transient, 2000, worker, [mod_sip_registrar]},
@@ -55,13 +69,16 @@ start(_Host, _Opts) ->
{ejabberd_tmp_sup, start_link,
[mod_sip_proxy_sup, mod_sip_proxy]},
permanent, infinity, supervisor, [ejabberd_tmp_sup]},
- supervisor:start_child(ejabberd_sup, Spec),
- supervisor:start_child(ejabberd_sup, TmpSupSpec),
+ supervisor:start_child(ejabberd_gen_mod_sup, Spec),
+ supervisor:start_child(ejabberd_gen_mod_sup, TmpSupSpec),
ok.
stop(_Host) ->
ok.
+reload(_Host, _NewOpts, _OldOpts) ->
+ ok.
+
depends(_Host, _Opts) ->
[].
@@ -69,7 +86,7 @@ data_in(Data, #sip_socket{type = Transport,
addr = {MyIP, MyPort},
peer = {PeerIP, PeerPort}}) ->
?DEBUG(
- "SIP [~p/in] ~s:~p -> ~s:~p:~n~s",
+ "SIP [~p/in] ~ts:~p -> ~ts:~p:~n~ts",
[Transport, inet_parse:ntoa(PeerIP), PeerPort,
inet_parse:ntoa(MyIP), MyPort, Data]).
@@ -77,7 +94,7 @@ data_out(Data, #sip_socket{type = Transport,
addr = {MyIP, MyPort},
peer = {PeerIP, PeerPort}}) ->
?DEBUG(
- "SIP [~p/out] ~s:~p -> ~s:~p:~n~s",
+ "SIP [~p/out] ~ts:~p -> ~ts:~p:~n~ts",
[Transport, inet_parse:ntoa(MyIP), MyPort,
inet_parse:ntoa(PeerIP), PeerPort, Data]).
@@ -134,7 +151,7 @@ request(Req, SIPSock, TrID, Action) ->
mod_sip_proxy:route(Req, SIPSock, TrID, Pid),
{mod_sip_proxy, route, [Pid]};
Err ->
- ?INFO_MSG("failed to proxy request ~p: ~p", [Req, Err]),
+ ?WARNING_MSG("Failed to proxy request ~p: ~p", [Req, Err]),
Err
end;
{proxy_auth, LServer} ->
@@ -269,7 +286,7 @@ check_auth(#sip{method = Method, hdrs = Hdrs, body = Body}, AuthHdr, _SIPSock) -
Password when is_binary(Password) ->
esip:check_auth(Auth, Method, Body, Password);
_ScramedPassword ->
- ?ERROR_MSG("unable to authenticate ~s@~s against SCRAM'ed "
+ ?ERROR_MSG("Unable to authenticate ~ts@~ts against SCRAM'ed "
"password", [LUser, LServer]),
false
end;
@@ -308,42 +325,41 @@ is_my_host(LServer) ->
gen_mod:is_loaded(LServer, ?MODULE).
mod_opt_type(always_record_route) ->
- fun (true) -> true;
- (false) -> false
- end;
+ econf:bool();
mod_opt_type(flow_timeout_tcp) ->
- fun (I) when is_integer(I), I > 0 -> I end;
+ econf:timeout(second);
mod_opt_type(flow_timeout_udp) ->
- fun (I) when is_integer(I), I > 0 -> I end;
+ econf:timeout(second);
mod_opt_type(record_route) ->
- fun (IOList) ->
- S = iolist_to_binary(IOList),
- #uri{} = esip:decode_uri(S)
- end;
+ econf:sip_uri();
mod_opt_type(routes) ->
- fun (L) ->
- lists:map(fun (IOList) ->
- S = iolist_to_binary(IOList),
- #uri{} = esip:decode_uri(S)
- end,
- L)
- end;
+ econf:list(econf:sip_uri());
mod_opt_type(via) ->
- fun (L) ->
- lists:map(fun (Opts) ->
- Type = proplists:get_value(type, Opts),
- Host = proplists:get_value(host, Opts),
- Port = proplists:get_value(port, Opts),
- true = (Type == tcp) or (Type == tls) or
- (Type == udp),
- true = is_binary(Host) and (Host /= <<"">>),
- true = is_integer(Port) and (Port > 0) and
- (Port < 65536)
- or (Port == undefined),
- {Type, {Host, Port}}
- end,
- L)
- end;
-mod_opt_type(_) ->
- [always_record_route, flow_timeout_tcp,
- flow_timeout_udp, record_route, routes, via].
+ econf:list(
+ econf:and_then(
+ econf:options(
+ #{type => econf:enum([tcp, tls, udp]),
+ host => econf:domain(),
+ port => econf:port()},
+ [{required, [type, host]}]),
+ fun(Opts) ->
+ Type = proplists:get_value(type, Opts),
+ Host = proplists:get_value(host, Opts),
+ Port = proplists:get_value(port, Opts),
+ {Type, {Host, Port}}
+ end)).
+
+-spec mod_options(binary()) -> [{via, [{tcp | tls | udp, {binary(), 1..65535 | undefined}}]} |
+ {atom(), term()}].
+mod_options(Host) ->
+ Route = #uri{scheme = <<"sip">>,
+ host = Host,
+ params = [{<<"lr">>, <<>>}]},
+ [{always_record_route, true},
+ {flow_timeout_tcp, timer:seconds(120)},
+ {flow_timeout_udp, timer:seconds(29)},
+ {record_route, Route},
+ {routes, [Route]},
+ {via, []}].
+
+-endif.