mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-02 21:17:12 +02:00
Rewrite 'Contact' headers in REGISTER requests
This commit is contained in:
parent
8e2bc8d19e
commit
1d771fe646
|
@ -67,23 +67,19 @@ request(#sip{hdrs = Hdrs} = Req, SIPSock) ->
|
||||||
reason = Reason})
|
reason = Reason})
|
||||||
end;
|
end;
|
||||||
[{_, _URI, _Params}|_] = Contacts ->
|
[{_, _URI, _Params}|_] = Contacts ->
|
||||||
ContactsWithExpires =
|
ExpiresList = lists:map(
|
||||||
lists:map(
|
fun({_, _, Params}) ->
|
||||||
fun({Name, URI, Params}) ->
|
case to_integer(
|
||||||
Exp = case to_integer(
|
esip:get_param(
|
||||||
esip:get_param(
|
<<"expires">>, Params),
|
||||||
<<"expires">>, Params),
|
0, (1 bsl 32)-1) of
|
||||||
0, (1 bsl 32)-1) of
|
{ok, E} -> E;
|
||||||
{ok, E} -> E;
|
_ -> Expires
|
||||||
_ -> Expires
|
end
|
||||||
end,
|
end, Contacts),
|
||||||
NewParams = esip:set_param(
|
Expires1 = lists:max(ExpiresList),
|
||||||
<<"expires">>,
|
Contact = {<<"">>, #uri{user = LUser, host = LServer},
|
||||||
erlang:integer_to_binary(Exp),
|
[{<<"expires">>, erlang:integer_to_binary(Expires1)}]},
|
||||||
Params),
|
|
||||||
{Exp, {Name, URI, NewParams}}
|
|
||||||
end, Contacts),
|
|
||||||
[{Expires1, _}|_] = lists:keysort(1, ContactsWithExpires),
|
|
||||||
MinExpires = min_expires(),
|
MinExpires = min_expires(),
|
||||||
if Expires1 >= MinExpires ->
|
if Expires1 >= MinExpires ->
|
||||||
case register_session(US, SIPSock, CallID, CSeq, Expires1) of
|
case register_session(US, SIPSock, CallID, CSeq, Expires1) of
|
||||||
|
@ -94,8 +90,7 @@ request(#sip{hdrs = Hdrs} = Req, SIPSock) ->
|
||||||
Req,
|
Req,
|
||||||
#sip{type = response,
|
#sip{type = response,
|
||||||
status = 200,
|
status = 200,
|
||||||
hdrs = [{'contact',
|
hdrs = [{'contact', [Contact]}]});
|
||||||
[C || {_, C} <- ContactsWithExpires]}]});
|
|
||||||
{error, Why} ->
|
{error, Why} ->
|
||||||
{Status, Reason} = make_status(Why),
|
{Status, Reason} = make_status(Why),
|
||||||
mod_sip:make_response(
|
mod_sip:make_response(
|
||||||
|
@ -116,8 +111,7 @@ request(#sip{hdrs = Hdrs} = Req, SIPSock) ->
|
||||||
mod_sip:make_response(
|
mod_sip:make_response(
|
||||||
Req,
|
Req,
|
||||||
#sip{type = response, status = 200,
|
#sip{type = response, status = 200,
|
||||||
hdrs = [{'contact',
|
hdrs = [{'contact', [Contact]}]});
|
||||||
[C || {_, C} <- ContactsWithExpires]}]});
|
|
||||||
{error, Why} ->
|
{error, Why} ->
|
||||||
{Status, Reason} = make_status(Why),
|
{Status, Reason} = make_status(Why),
|
||||||
mod_sip:make_response(
|
mod_sip:make_response(
|
||||||
|
@ -127,7 +121,31 @@ request(#sip{hdrs = Hdrs} = Req, SIPSock) ->
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
[] ->
|
[] ->
|
||||||
mod_sip:make_response(Req, #sip{type = response, status = 200});
|
case mnesia:dirty_read(sip_session, US) of
|
||||||
|
[#sip_session{bindings = Bindings}] ->
|
||||||
|
case pop_previous_binding(SIPSock, Bindings) of
|
||||||
|
{ok, #binding{expires = Expires1}, _} ->
|
||||||
|
Contact = {<<"">>,
|
||||||
|
#uri{user = LUser, host = LServer},
|
||||||
|
[{<<"expires">>,
|
||||||
|
erlang:integer_to_binary(Expires1)}]},
|
||||||
|
mod_sip:make_response(
|
||||||
|
Req, #sip{type = response, status = 200,
|
||||||
|
hdrs = [{'contact', [Contact]}]});
|
||||||
|
{error, notfound} ->
|
||||||
|
{Status, Reason} = make_status(notfound),
|
||||||
|
mod_sip:make_response(
|
||||||
|
Req, #sip{type = response,
|
||||||
|
status = Status,
|
||||||
|
reason = Reason})
|
||||||
|
end;
|
||||||
|
[] ->
|
||||||
|
{Status, Reason} = make_status(notfound),
|
||||||
|
mod_sip:make_response(
|
||||||
|
Req, #sip{type = response,
|
||||||
|
status = Status,
|
||||||
|
reason = Reason})
|
||||||
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
mod_sip:make_response(Req, #sip{type = response, status = 400})
|
mod_sip:make_response(Req, #sip{type = response, status = 400})
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user