2014-04-30 17:20:38 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
|
|
|
|
%%% @copyright (C) 2014, Evgeny Khramtsov
|
|
|
|
%%% @doc
|
|
|
|
%%%
|
|
|
|
%%% @end
|
|
|
|
%%% Created : 21 Apr 2014 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
-module(mod_sip_proxy).
|
|
|
|
|
|
|
|
-define(GEN_FSM, p1_fsm).
|
|
|
|
-behaviour(?GEN_FSM).
|
|
|
|
|
|
|
|
%% API
|
2014-05-23 18:13:31 +02:00
|
|
|
-export([start/2, start_link/2, route/3, route/4]).
|
2014-04-30 17:20:38 +02:00
|
|
|
|
|
|
|
%% gen_fsm callbacks
|
|
|
|
-export([init/1, wait_for_request/2, wait_for_response/2,
|
|
|
|
handle_event/3, handle_sync_event/4,
|
|
|
|
handle_info/3, terminate/3, code_change/4]).
|
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
-include("logger.hrl").
|
2014-07-05 12:01:29 +02:00
|
|
|
-include_lib("esip/include/esip.hrl").
|
2014-04-30 17:20:38 +02:00
|
|
|
|
2014-06-01 11:34:51 +02:00
|
|
|
-define(SIGN_LIFETIME, 300). %% in seconds.
|
|
|
|
|
2014-05-02 13:18:57 +02:00
|
|
|
-record(state, {host = <<"">> :: binary(),
|
|
|
|
opts = [] :: [{certfile, binary()}],
|
2014-04-30 17:20:38 +02:00
|
|
|
orig_trid,
|
2014-05-02 13:18:57 +02:00
|
|
|
responses = [] :: [#sip{}],
|
|
|
|
tr_ids = [] :: list(),
|
|
|
|
orig_req :: #sip{}}).
|
2014-04-30 17:20:38 +02:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
|
|
|
start(LServer, Opts) ->
|
|
|
|
supervisor:start_child(mod_sip_proxy_sup, [LServer, Opts]).
|
|
|
|
|
|
|
|
start_link(LServer, Opts) ->
|
|
|
|
?GEN_FSM:start_link(?MODULE, [LServer, Opts], []).
|
|
|
|
|
|
|
|
route(SIPMsg, _SIPSock, TrID, Pid) ->
|
2014-05-02 13:20:27 +02:00
|
|
|
?GEN_FSM:send_event(Pid, {SIPMsg, TrID}).
|
2014-04-30 17:20:38 +02:00
|
|
|
|
2014-06-01 11:34:51 +02:00
|
|
|
route(#sip{hdrs = Hdrs} = Req, LServer, Opts) ->
|
|
|
|
case proplists:get_bool(authenticated, Opts) of
|
|
|
|
true ->
|
|
|
|
route_statelessly(Req, LServer, Opts);
|
|
|
|
false ->
|
2014-06-02 08:16:08 +02:00
|
|
|
ConfiguredRRoute = get_configured_record_route(LServer),
|
2014-06-01 11:34:51 +02:00
|
|
|
case esip:get_hdrs('route', Hdrs) of
|
|
|
|
[{_, URI, _}|_] ->
|
2014-06-02 08:16:08 +02:00
|
|
|
case cmp_uri(URI, ConfiguredRRoute) of
|
2014-06-01 11:34:51 +02:00
|
|
|
true ->
|
|
|
|
case is_signed_by_me(URI#uri.user, Hdrs) of
|
|
|
|
true ->
|
|
|
|
route_statelessly(Req, LServer, Opts);
|
|
|
|
false ->
|
|
|
|
error
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
error
|
|
|
|
end;
|
|
|
|
[] ->
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
route_statelessly(Req, LServer, Opts) ->
|
2014-05-23 18:13:31 +02:00
|
|
|
Req1 = prepare_request(LServer, Req),
|
|
|
|
case connect(Req1, add_certfile(LServer, Opts)) of
|
2014-05-30 21:49:34 +02:00
|
|
|
{ok, SIPSocketsWithURIs} ->
|
2014-05-23 18:13:31 +02:00
|
|
|
lists:foreach(
|
2014-05-31 05:49:51 +02:00
|
|
|
fun({SIPSocket, _URI}) ->
|
2014-05-23 18:13:31 +02:00
|
|
|
Req2 = add_via(SIPSocket, LServer, Req1),
|
2014-05-31 05:49:51 +02:00
|
|
|
esip:send(SIPSocket, Req2)
|
2014-05-30 21:49:34 +02:00
|
|
|
end, SIPSocketsWithURIs);
|
2014-05-23 18:13:31 +02:00
|
|
|
_ ->
|
|
|
|
error
|
|
|
|
end.
|
|
|
|
|
2014-04-30 17:20:38 +02:00
|
|
|
%%%===================================================================
|
|
|
|
%%% gen_fsm callbacks
|
|
|
|
%%%===================================================================
|
|
|
|
init([Host, Opts]) ->
|
2014-05-02 08:51:08 +02:00
|
|
|
Opts1 = add_certfile(Host, Opts),
|
|
|
|
{ok, wait_for_request, #state{opts = Opts1, host = Host}}.
|
2014-04-30 17:20:38 +02:00
|
|
|
|
|
|
|
wait_for_request({#sip{type = request} = Req, TrID}, State) ->
|
2014-05-01 11:27:35 +02:00
|
|
|
Opts = State#state.opts,
|
2014-05-23 18:13:31 +02:00
|
|
|
Req1 = prepare_request(State#state.host, Req),
|
2014-04-30 17:20:38 +02:00
|
|
|
case connect(Req1, Opts) of
|
2014-05-30 21:11:46 +02:00
|
|
|
{ok, SIPSocketsWithURIs} ->
|
2014-05-02 13:18:57 +02:00
|
|
|
NewState =
|
|
|
|
lists:foldl(
|
2014-05-30 21:11:46 +02:00
|
|
|
fun(_SIPSocketWithURI, {error, _} = Err) ->
|
2014-05-02 13:18:57 +02:00
|
|
|
Err;
|
2014-05-30 21:11:46 +02:00
|
|
|
({SIPSocket, URI}, #state{tr_ids = TrIDs} = AccState) ->
|
2014-05-31 08:00:27 +02:00
|
|
|
Req2 = add_record_route_and_set_uri(
|
|
|
|
URI, State#state.host, Req1),
|
2014-05-23 18:13:31 +02:00
|
|
|
Req3 = add_via(SIPSocket, State#state.host, Req2),
|
2014-05-31 08:00:27 +02:00
|
|
|
case esip:request(SIPSocket, Req3,
|
2014-05-02 13:18:57 +02:00
|
|
|
{?MODULE, route, [self()]}) of
|
|
|
|
{ok, ClientTrID} ->
|
|
|
|
NewTrIDs = [ClientTrID|TrIDs],
|
|
|
|
AccState#state{tr_ids = NewTrIDs};
|
|
|
|
Err ->
|
|
|
|
cancel_pending_transactions(AccState),
|
|
|
|
Err
|
|
|
|
end
|
2014-05-30 21:11:46 +02:00
|
|
|
end, State, SIPSocketsWithURIs),
|
2014-05-02 13:18:57 +02:00
|
|
|
case NewState of
|
|
|
|
{error, _} = Err ->
|
2014-04-30 17:20:38 +02:00
|
|
|
{Status, Reason} = esip:error_status(Err),
|
|
|
|
esip:reply(TrID, mod_sip:make_response(
|
|
|
|
Req, #sip{type = response,
|
|
|
|
status = Status,
|
|
|
|
reason = Reason})),
|
2014-05-02 13:18:57 +02:00
|
|
|
{stop, normal, State};
|
|
|
|
_ ->
|
|
|
|
{next_state, wait_for_response,
|
|
|
|
NewState#state{orig_req = Req, orig_trid = TrID}}
|
2014-04-30 17:20:38 +02:00
|
|
|
end;
|
2014-05-01 11:27:35 +02:00
|
|
|
{error, notfound} ->
|
|
|
|
esip:reply(TrID, mod_sip:make_response(
|
|
|
|
Req, #sip{type = response,
|
|
|
|
status = 480,
|
|
|
|
reason = esip:reason(480)})),
|
|
|
|
{stop, normal, State};
|
2014-04-30 17:20:38 +02:00
|
|
|
Err ->
|
|
|
|
{Status, Reason} = esip:error_status(Err),
|
|
|
|
esip:reply(TrID, mod_sip:make_response(
|
|
|
|
Req, #sip{type = response,
|
|
|
|
status = Status,
|
|
|
|
reason = Reason})),
|
|
|
|
{stop, normal, State}
|
|
|
|
end;
|
|
|
|
wait_for_request(_Event, State) ->
|
|
|
|
{next_state, wait_for_request, State}.
|
|
|
|
|
|
|
|
wait_for_response({#sip{method = <<"CANCEL">>, type = request}, _TrID}, State) ->
|
2014-05-02 13:18:57 +02:00
|
|
|
cancel_pending_transactions(State),
|
2014-04-30 17:20:38 +02:00
|
|
|
{next_state, wait_for_response, State};
|
2014-05-02 13:18:57 +02:00
|
|
|
wait_for_response({Resp, TrID},
|
|
|
|
#state{orig_req = #sip{method = Method} = Req} = State) ->
|
2014-04-30 17:20:38 +02:00
|
|
|
case Resp of
|
2014-05-02 13:18:57 +02:00
|
|
|
{error, timeout} when Method /= <<"INVITE">> ->
|
|
|
|
%% Absorb useless 408. See RFC4320
|
|
|
|
choose_best_response(State),
|
|
|
|
esip:stop_transaction(State#state.orig_trid),
|
|
|
|
{stop, normal, State};
|
|
|
|
{error, _} ->
|
|
|
|
{Status, Reason} = esip:error_status(Resp),
|
|
|
|
State1 = mark_transaction_as_complete(TrID, State),
|
|
|
|
SIPResp = mod_sip:make_response(Req,
|
|
|
|
#sip{type = response,
|
|
|
|
status = Status,
|
|
|
|
reason = Reason}),
|
|
|
|
State2 = collect_response(SIPResp, State1),
|
|
|
|
case State2#state.tr_ids of
|
|
|
|
[] ->
|
|
|
|
choose_best_response(State2),
|
|
|
|
{stop, normal, State2};
|
|
|
|
_ ->
|
|
|
|
{next_state, wait_for_response, State2}
|
|
|
|
end;
|
2014-04-30 17:20:38 +02:00
|
|
|
#sip{status = 100} ->
|
|
|
|
{next_state, wait_for_response, State};
|
|
|
|
#sip{status = Status} ->
|
2014-05-02 13:18:57 +02:00
|
|
|
{[_|Vias], NewHdrs} = esip:split_hdrs('via', Resp#sip.hdrs),
|
|
|
|
NewResp = case Vias of
|
|
|
|
[] ->
|
|
|
|
Resp#sip{hdrs = NewHdrs};
|
|
|
|
_ ->
|
|
|
|
Resp#sip{hdrs = [{'via', Vias}|NewHdrs]}
|
|
|
|
end,
|
|
|
|
if Status < 300 ->
|
|
|
|
esip:reply(State#state.orig_trid, NewResp);
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
State1 = if Status >= 200 ->
|
|
|
|
mark_transaction_as_complete(TrID, State);
|
|
|
|
true ->
|
|
|
|
State
|
|
|
|
end,
|
|
|
|
State2 = if Status >= 300 ->
|
|
|
|
collect_response(NewResp, State1);
|
|
|
|
true ->
|
|
|
|
State1
|
|
|
|
end,
|
|
|
|
if Status >= 600 ->
|
|
|
|
cancel_pending_transactions(State2);
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
case State2#state.tr_ids of
|
|
|
|
[] ->
|
|
|
|
choose_best_response(State2),
|
|
|
|
{stop, normal, State2};
|
|
|
|
_ ->
|
|
|
|
{next_state, wait_for_response, State2}
|
|
|
|
end
|
2014-04-30 17:20:38 +02:00
|
|
|
end;
|
|
|
|
wait_for_response(_Event, State) ->
|
|
|
|
{next_state, wait_for_response, State}.
|
|
|
|
|
|
|
|
handle_event(_Event, StateName, State) ->
|
|
|
|
{next_state, StateName, State}.
|
|
|
|
|
|
|
|
handle_sync_event(_Event, _From, StateName, State) ->
|
|
|
|
Reply = ok,
|
|
|
|
{reply, Reply, StateName, State}.
|
|
|
|
|
|
|
|
handle_info(_Info, StateName, State) ->
|
|
|
|
{next_state, StateName, State}.
|
|
|
|
|
|
|
|
terminate(_Reason, _StateName, _State) ->
|
|
|
|
ok.
|
|
|
|
|
|
|
|
code_change(_OldVsn, StateName, State, _Extra) ->
|
|
|
|
{ok, StateName, State}.
|
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%===================================================================
|
2014-05-01 11:27:35 +02:00
|
|
|
connect(#sip{hdrs = Hdrs} = Req, Opts) ->
|
|
|
|
{_, ToURI, _} = esip:get_hdr('to', Hdrs),
|
|
|
|
case mod_sip:at_my_host(ToURI) of
|
|
|
|
true ->
|
|
|
|
LUser = jlib:nodeprep(ToURI#uri.user),
|
|
|
|
LServer = jlib:nameprep(ToURI#uri.host),
|
2014-05-01 13:51:58 +02:00
|
|
|
case mod_sip_registrar:find_sockets(LUser, LServer) of
|
2014-05-02 13:18:57 +02:00
|
|
|
[_|_] = SIPSocks ->
|
|
|
|
{ok, SIPSocks};
|
2014-05-01 13:51:58 +02:00
|
|
|
[] ->
|
2014-05-01 11:27:35 +02:00
|
|
|
{error, notfound}
|
|
|
|
end;
|
|
|
|
false ->
|
2014-05-02 13:18:57 +02:00
|
|
|
case esip:connect(Req, Opts) of
|
|
|
|
{ok, SIPSock} ->
|
2014-05-30 21:11:46 +02:00
|
|
|
{ok, [{SIPSock, Req#sip.uri}]};
|
2014-05-02 13:18:57 +02:00
|
|
|
{error, _} = Err ->
|
|
|
|
Err
|
|
|
|
end
|
2014-04-30 17:20:38 +02:00
|
|
|
end.
|
2014-05-02 08:51:08 +02:00
|
|
|
|
2014-05-02 13:18:57 +02:00
|
|
|
cancel_pending_transactions(State) ->
|
|
|
|
lists:foreach(fun esip:cancel/1, State#state.tr_ids).
|
|
|
|
|
2014-05-02 08:51:08 +02:00
|
|
|
add_certfile(LServer, Opts) ->
|
|
|
|
case ejabberd_config:get_option({domain_certfile, LServer},
|
|
|
|
fun iolist_to_binary/1) of
|
|
|
|
CertFile when is_binary(CertFile), CertFile /= <<"">> ->
|
|
|
|
[{certfile, CertFile}|Opts];
|
|
|
|
_ ->
|
|
|
|
Opts
|
|
|
|
end.
|
|
|
|
|
|
|
|
add_via(#sip_socket{type = Transport}, LServer, #sip{hdrs = Hdrs} = Req) ->
|
|
|
|
ConfiguredVias = get_configured_vias(LServer),
|
|
|
|
{ViaHost, ViaPort} = proplists:get_value(
|
|
|
|
Transport, ConfiguredVias, {LServer, undefined}),
|
|
|
|
ViaTransport = case Transport of
|
|
|
|
tls -> <<"TLS">>;
|
|
|
|
tcp -> <<"TCP">>;
|
|
|
|
udp -> <<"UDP">>
|
|
|
|
end,
|
|
|
|
Via = #via{transport = ViaTransport,
|
|
|
|
host = ViaHost,
|
|
|
|
port = ViaPort,
|
2014-06-02 18:46:09 +02:00
|
|
|
params = [{<<"branch">>, esip:make_branch()}]},
|
2014-05-02 08:51:08 +02:00
|
|
|
Req#sip{hdrs = [{'via', [Via]}|Hdrs]}.
|
|
|
|
|
2014-05-31 08:00:27 +02:00
|
|
|
add_record_route_and_set_uri(URI, LServer, #sip{hdrs = Hdrs} = Req) ->
|
|
|
|
case is_request_within_dialog(Req) of
|
|
|
|
false ->
|
2014-07-07 07:23:11 +02:00
|
|
|
case need_record_route(LServer) of
|
|
|
|
true ->
|
|
|
|
RR_URI = get_configured_record_route(LServer),
|
|
|
|
{MSecs, Secs, _} = now(),
|
|
|
|
TS = list_to_binary(integer_to_list(MSecs*1000000 + Secs)),
|
|
|
|
Sign = make_sign(TS, Hdrs),
|
|
|
|
User = <<TS/binary, $-, Sign/binary>>,
|
|
|
|
NewRR_URI = RR_URI#uri{user = User},
|
|
|
|
Hdrs1 = [{'record-route', [{<<>>, NewRR_URI, []}]}|Hdrs],
|
|
|
|
Req#sip{uri = URI, hdrs = Hdrs1};
|
|
|
|
false ->
|
|
|
|
Req
|
|
|
|
end;
|
2014-05-31 08:00:27 +02:00
|
|
|
true ->
|
|
|
|
Req
|
|
|
|
end.
|
|
|
|
|
|
|
|
is_request_within_dialog(#sip{hdrs = Hdrs}) ->
|
|
|
|
{_, _, Params} = esip:get_hdr('to', Hdrs),
|
|
|
|
esip:has_param(<<"tag">>, Params).
|
2014-05-23 18:13:31 +02:00
|
|
|
|
2014-07-07 07:23:11 +02:00
|
|
|
need_record_route(LServer) ->
|
|
|
|
gen_mod:get_module_opt(
|
|
|
|
LServer, mod_sip, always_record_route,
|
|
|
|
fun(true) -> true;
|
|
|
|
(false) -> false
|
|
|
|
end, true).
|
|
|
|
|
2014-06-01 11:34:51 +02:00
|
|
|
make_sign(TS, Hdrs) ->
|
|
|
|
{_, #uri{user = FUser, host = FServer}, FParams} = esip:get_hdr('from', Hdrs),
|
|
|
|
{_, #uri{user = TUser, host = TServer}, _} = esip:get_hdr('to', Hdrs),
|
2014-07-17 18:30:09 +02:00
|
|
|
LFUser = safe_nodeprep(FUser),
|
|
|
|
LTUser = safe_nodeprep(TUser),
|
|
|
|
LFServer = safe_nameprep(FServer),
|
|
|
|
LTServer = safe_nameprep(TServer),
|
2014-06-01 11:34:51 +02:00
|
|
|
FromTag = esip:get_param(<<"tag">>, FParams),
|
|
|
|
CallID = esip:get_hdr('call-id', Hdrs),
|
|
|
|
SharedKey = ejabberd_config:get_option(shared_key, fun(V) -> V end),
|
|
|
|
p1_sha:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
|
|
|
|
FromTag, CallID, TS]).
|
|
|
|
|
|
|
|
is_signed_by_me(TS_Sign, Hdrs) ->
|
|
|
|
try
|
|
|
|
[TSBin, Sign] = str:tokens(TS_Sign, <<"-">>),
|
|
|
|
TS = list_to_integer(binary_to_list(TSBin)),
|
|
|
|
{MSecs, Secs, _} = now(),
|
|
|
|
NowTS = MSecs*1000000 + Secs,
|
|
|
|
true = (NowTS - TS) =< ?SIGN_LIFETIME,
|
|
|
|
Sign == make_sign(TSBin, Hdrs)
|
|
|
|
catch _:_ ->
|
|
|
|
false
|
|
|
|
end.
|
|
|
|
|
2014-05-02 08:51:08 +02:00
|
|
|
get_configured_vias(LServer) ->
|
|
|
|
gen_mod:get_module_opt(
|
2014-05-31 12:21:29 +02:00
|
|
|
LServer, mod_sip, via,
|
2014-05-02 08:51:08 +02:00
|
|
|
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, []).
|
2014-05-02 13:18:57 +02:00
|
|
|
|
2014-06-02 08:16:08 +02:00
|
|
|
get_configured_record_route(LServer) ->
|
2014-05-31 12:20:38 +02:00
|
|
|
gen_mod:get_module_opt(
|
2014-06-02 08:16:08 +02:00
|
|
|
LServer, mod_sip, record_route,
|
2014-05-31 12:20:38 +02:00
|
|
|
fun(IOList) ->
|
|
|
|
S = iolist_to_binary(IOList),
|
|
|
|
#uri{} = esip:decode_uri(S)
|
|
|
|
end, #uri{host = LServer, params = [{<<"lr">>, <<"">>}]}).
|
|
|
|
|
2014-06-02 08:16:08 +02:00
|
|
|
get_configured_routes(LServer) ->
|
|
|
|
gen_mod:get_module_opt(
|
|
|
|
LServer, mod_sip, routes,
|
|
|
|
fun(L) ->
|
|
|
|
lists:map(
|
|
|
|
fun(IOList) ->
|
|
|
|
S = iolist_to_binary(IOList),
|
|
|
|
#uri{} = esip:decode_uri(S)
|
|
|
|
end, L)
|
|
|
|
end, [#uri{host = LServer, params = [{<<"lr">>, <<"">>}]}]).
|
|
|
|
|
2014-05-02 13:18:57 +02:00
|
|
|
mark_transaction_as_complete(TrID, State) ->
|
|
|
|
NewTrIDs = lists:delete(TrID, State#state.tr_ids),
|
|
|
|
State#state{tr_ids = NewTrIDs}.
|
|
|
|
|
|
|
|
collect_response(Resp, #state{responses = Resps} = State) ->
|
|
|
|
State#state{responses = [Resp|Resps]}.
|
|
|
|
|
|
|
|
choose_best_response(#state{responses = Responses} = State) ->
|
|
|
|
SortedResponses = lists:keysort(#sip.status, Responses),
|
|
|
|
case lists:filter(
|
|
|
|
fun(#sip{status = Status}) ->
|
|
|
|
Status >= 600
|
|
|
|
end, SortedResponses) of
|
|
|
|
[Resp|_] ->
|
|
|
|
esip:reply(State#state.orig_trid, Resp);
|
|
|
|
[] ->
|
|
|
|
case SortedResponses of
|
|
|
|
[Resp|_] ->
|
|
|
|
esip:reply(State#state.orig_trid, Resp);
|
|
|
|
[] ->
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
end.
|
2014-05-23 18:13:31 +02:00
|
|
|
|
2014-06-02 08:16:08 +02:00
|
|
|
%% Just compare host part only.
|
|
|
|
cmp_uri(#uri{host = H1}, #uri{host = H2}) ->
|
|
|
|
jlib:nameprep(H1) == jlib:nameprep(H2).
|
|
|
|
|
|
|
|
is_my_route(URI, URIs) ->
|
|
|
|
lists:any(fun(U) -> cmp_uri(URI, U) end, URIs).
|
2014-05-31 12:20:38 +02:00
|
|
|
|
|
|
|
prepare_request(LServer, #sip{hdrs = Hdrs} = Req) ->
|
2014-06-02 08:16:08 +02:00
|
|
|
ConfiguredRRoute = get_configured_record_route(LServer),
|
|
|
|
ConfiguredRoutes = get_configured_routes(LServer),
|
2014-05-23 18:13:31 +02:00
|
|
|
Hdrs1 = lists:flatmap(
|
|
|
|
fun({Hdr, HdrList}) when Hdr == 'route';
|
|
|
|
Hdr == 'record-route' ->
|
|
|
|
case lists:filter(
|
2014-05-31 12:20:38 +02:00
|
|
|
fun({_, URI, _}) ->
|
2014-06-02 08:16:08 +02:00
|
|
|
not cmp_uri(URI, ConfiguredRRoute)
|
|
|
|
and not is_my_route(URI, ConfiguredRoutes)
|
2014-05-23 18:13:31 +02:00
|
|
|
end, HdrList) of
|
|
|
|
[] ->
|
|
|
|
[];
|
|
|
|
HdrList1 ->
|
|
|
|
[{Hdr, HdrList1}]
|
|
|
|
end;
|
|
|
|
(Hdr) ->
|
|
|
|
[Hdr]
|
|
|
|
end, Hdrs),
|
|
|
|
MF = esip:get_hdr('max-forwards', Hdrs1),
|
|
|
|
Hdrs2 = esip:set_hdr('max-forwards', MF-1, Hdrs1),
|
|
|
|
Hdrs3 = lists:filter(
|
|
|
|
fun({'proxy-authorization', {_, Params}}) ->
|
|
|
|
Realm = esip:unquote(esip:get_param(<<"realm">>, Params)),
|
|
|
|
not mod_sip:is_my_host(jlib:nameprep(Realm));
|
|
|
|
(_) ->
|
|
|
|
true
|
|
|
|
end, Hdrs2),
|
|
|
|
Req#sip{hdrs = Hdrs3}.
|
2014-07-17 18:30:09 +02:00
|
|
|
|
|
|
|
safe_nodeprep(S) ->
|
|
|
|
case jlib:nodeprep(S) of
|
|
|
|
error -> S;
|
|
|
|
S1 -> S1
|
|
|
|
end.
|
|
|
|
|
|
|
|
safe_nameprep(S) ->
|
|
|
|
case jlib:nameprep(S) of
|
|
|
|
error -> S;
|
|
|
|
S1 -> S1
|
|
|
|
end.
|