mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Rename option 'route' to 'record_route' and add new option 'routes'
This commit is contained in:
parent
9a0d77571d
commit
0aea9c74bd
@ -49,12 +49,10 @@ route(#sip{hdrs = Hdrs} = Req, LServer, Opts) ->
|
|||||||
true ->
|
true ->
|
||||||
route_statelessly(Req, LServer, Opts);
|
route_statelessly(Req, LServer, Opts);
|
||||||
false ->
|
false ->
|
||||||
ConfiguredRoute = get_configured_route(LServer),
|
ConfiguredRRoute = get_configured_record_route(LServer),
|
||||||
ConfiguredBareRoute = ConfiguredRoute#uri{user = <<"">>},
|
|
||||||
case esip:get_hdrs('route', Hdrs) of
|
case esip:get_hdrs('route', Hdrs) of
|
||||||
[{_, URI, _}|_] ->
|
[{_, URI, _}|_] ->
|
||||||
BareURI = URI#uri{user = <<"">>},
|
case cmp_uri(URI, ConfiguredRRoute) of
|
||||||
case cmp_uri(BareURI, ConfiguredBareRoute) of
|
|
||||||
true ->
|
true ->
|
||||||
case is_signed_by_me(URI#uri.user, Hdrs) of
|
case is_signed_by_me(URI#uri.user, Hdrs) of
|
||||||
true ->
|
true ->
|
||||||
@ -280,7 +278,7 @@ add_via(#sip_socket{type = Transport}, LServer, #sip{hdrs = Hdrs} = Req) ->
|
|||||||
add_record_route_and_set_uri(URI, LServer, #sip{hdrs = Hdrs} = Req) ->
|
add_record_route_and_set_uri(URI, LServer, #sip{hdrs = Hdrs} = Req) ->
|
||||||
case is_request_within_dialog(Req) of
|
case is_request_within_dialog(Req) of
|
||||||
false ->
|
false ->
|
||||||
RR_URI = get_configured_route(LServer),
|
RR_URI = get_configured_record_route(LServer),
|
||||||
{MSecs, Secs, _} = now(),
|
{MSecs, Secs, _} = now(),
|
||||||
TS = list_to_binary(integer_to_list(MSecs*1000000 + Secs)),
|
TS = list_to_binary(integer_to_list(MSecs*1000000 + Secs)),
|
||||||
Sign = make_sign(TS, Hdrs),
|
Sign = make_sign(TS, Hdrs),
|
||||||
@ -338,14 +336,25 @@ get_configured_vias(LServer) ->
|
|||||||
end, L)
|
end, L)
|
||||||
end, []).
|
end, []).
|
||||||
|
|
||||||
get_configured_route(LServer) ->
|
get_configured_record_route(LServer) ->
|
||||||
gen_mod:get_module_opt(
|
gen_mod:get_module_opt(
|
||||||
LServer, mod_sip, route,
|
LServer, mod_sip, record_route,
|
||||||
fun(IOList) ->
|
fun(IOList) ->
|
||||||
S = iolist_to_binary(IOList),
|
S = iolist_to_binary(IOList),
|
||||||
#uri{} = esip:decode_uri(S)
|
#uri{} = esip:decode_uri(S)
|
||||||
end, #uri{host = LServer, params = [{<<"lr">>, <<"">>}]}).
|
end, #uri{host = LServer, params = [{<<"lr">>, <<"">>}]}).
|
||||||
|
|
||||||
|
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">>, <<"">>}]}]).
|
||||||
|
|
||||||
mark_transaction_as_complete(TrID, State) ->
|
mark_transaction_as_complete(TrID, State) ->
|
||||||
NewTrIDs = lists:delete(TrID, State#state.tr_ids),
|
NewTrIDs = lists:delete(TrID, State#state.tr_ids),
|
||||||
State#state{tr_ids = NewTrIDs}.
|
State#state{tr_ids = NewTrIDs}.
|
||||||
@ -370,24 +379,23 @@ choose_best_response(#state{responses = Responses} = State) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% TODO: this is *totally* wrong.
|
%% Just compare host part only.
|
||||||
%% Rewrite this using URI comparison rules
|
cmp_uri(#uri{host = H1}, #uri{host = H2}) ->
|
||||||
cmp_uri(#uri{user = U, host = H, port = P},
|
jlib:nameprep(H1) == jlib:nameprep(H2).
|
||||||
#uri{user = U, host = H, port = P}) ->
|
|
||||||
true;
|
is_my_route(URI, URIs) ->
|
||||||
cmp_uri(_, _) ->
|
lists:any(fun(U) -> cmp_uri(URI, U) end, URIs).
|
||||||
false.
|
|
||||||
|
|
||||||
prepare_request(LServer, #sip{hdrs = Hdrs} = Req) ->
|
prepare_request(LServer, #sip{hdrs = Hdrs} = Req) ->
|
||||||
ConfiguredRoute = get_configured_route(LServer),
|
ConfiguredRRoute = get_configured_record_route(LServer),
|
||||||
ConfiguredBareRoute = ConfiguredRoute#uri{user = <<"">>},
|
ConfiguredRoutes = get_configured_routes(LServer),
|
||||||
Hdrs1 = lists:flatmap(
|
Hdrs1 = lists:flatmap(
|
||||||
fun({Hdr, HdrList}) when Hdr == 'route';
|
fun({Hdr, HdrList}) when Hdr == 'route';
|
||||||
Hdr == 'record-route' ->
|
Hdr == 'record-route' ->
|
||||||
case lists:filter(
|
case lists:filter(
|
||||||
fun({_, URI, _}) ->
|
fun({_, URI, _}) ->
|
||||||
BareURI = URI#uri{user = <<"">>},
|
not cmp_uri(URI, ConfiguredRRoute)
|
||||||
not cmp_uri(BareURI, ConfiguredBareRoute)
|
and not is_my_route(URI, ConfiguredRoutes)
|
||||||
end, HdrList) of
|
end, HdrList) of
|
||||||
[] ->
|
[] ->
|
||||||
[];
|
[];
|
||||||
|
Loading…
Reference in New Issue
Block a user