<commit_before>-module(outgoingproxy).
-export([start/0, start/2, process/2]).

start(normal, Args) ->
    Pid = spawn(outgoingproxy, start, []),
    {ok, Pid}.

start() ->
    logger:start("sipd.log"),
    {ok, Socket} = gen_udp:open(5060, [{reuseaddr, true}]),
    logger:log(normal, "proxy started"),
    recvloop(Socket).

recvloop(Socket) ->
    receive
	{udp, Socket, IP, InPortNo, Packet} ->
	    spawn(outgoingproxy, process, [Packet, Socket]),
	    recvloop(Socket)
    end.

process(Packet, Socket) ->
    case sippacket:parse(Packet) of
	{request, Method, URL, Header, Body} ->
	    request(Method, URL, Header, Body, Socket);
	{response, Status, Reason, Header, Body} ->
	    response(Status, Reason, Header, Body, Socket)
    end.

request("ACK", {User, Pass, Host, Port, Parameters}, Header, Body, Socket) ->
    true;

request("REGISTER", {User, Pass, Host, Port, Parameters}, Header, Body, Socket) ->
    URL = {none, none, "kth.se", none, []},
    siprequest:send_redirect(none, URL, Header, Socket);

request(Method, {User, Pass, Host, Port, Parameters}, Header, Body, Socket) ->
    {NewHost, NewPort} = case {User, Host} of
			     {"00" ++ _, "sip-proxy.kth.se"} ->
				 {"sip-pstn.kth.se", none};
			     {_, "sip-proxy.kth.se"} ->
				 {"kth.se", none};
			     {_, _} ->
				 {Host, Port}
			 end,
    URL = {User, Pass, NewHost, NewPort, []},
    siprequest:send_redirect(none, URL, Header, Socket).

response(Status, Reason, Header, Body, Socket) ->
    true.<commit_msg>Changed siprequest:send_redirect calls<commit_after>-module(outgoingproxy).
-export([start/0, start/2, process/2]).

start(normal, Args) ->
    Pid = spawn(outgoingproxy, start, []),
    {ok, Pid}.

start() ->
    logger:start("sipd.log"),
    {ok, Socket} = gen_udp:open(5060, [{reuseaddr, true}]),
    logger:log(normal, "proxy started"),
    recvloop(Socket).

recvloop(Socket) ->
    receive
	{udp, Socket, IP, InPortNo, Packet} ->
	    spawn(outgoingproxy, process, [Packet, Socket]),
	    recvloop(Socket)
    end.

process(Packet, Socket) ->
    case sippacket:parse(Packet) of
	{request, Method, URL, Header, Body} ->
	    request(Method, URL, Header, Body, Socket);
	{response, Status, Reason, Header, Body} ->
	    response(Status, Reason, Header, Body, Socket)
    end.

request("ACK", {User, Pass, Host, Port, Parameters}, Header, Body, Socket) ->
    true;

request("REGISTER", {User, Pass, Host, Port, Parameters}, Header, Body, Socket) ->
    URL = {none, none, "kth.se", none, []},
    siprequest:send_redirect(URL, Header, Socket);

request(Method, {User, Pass, Host, Port, Parameters}, Header, Body, Socket) ->
    {NewHost, NewPort} = case {User, Host} of
			     {"00" ++ _, "sip-proxy.kth.se"} ->
				 {"sip-pstn.kth.se", none};
			     {_, "sip-proxy.kth.se"} ->
				 {"kth.se", none};
			     {_, _} ->
				 {Host, Port}
			 end,
    URL = {User, Pass, NewHost, NewPort, []},
    siprequest:send_redirect(URL, Header, Socket).

response(Status, Reason, Header, Body, Socket) ->
    true.
{'fraction_non_alphanumeric': 0.185899567675424, 'fraction_numerical': 0.005986032590621883, 'mean_word_length': 3.4695393759286777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2710355', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1072, 'n_words': 257}