anchor.diff:  	       false ->
   		   MyPort
   	   end,
  -    add_record_route(Proto, myhostname(), Port, Header).
  +    construct_record_route(RRProto, myhostname(), Port);
  +    
  +%% Returns : RRStr = string(), URL enclosed in "<>"
  +construct_record_route(Proto, Hostname, Port) ->
  +    URL =
  +	case yxa_config:get_env(record_route_url) of
  +	    {ok, RRURL} ->
  +		case {Proto, RRURL#sipurl.proto} of
  +		    {"sips", "sip"} ->
  +			%% Proto is SIPS, but RRURL's Proto is SIP. Upgrade SIP to SIPS.
  +			sipurl:set([{proto, Proto}], RRURL);
  +		    _ ->
  +			RRURL
  +		end;
  +	    none ->
  +		%% we use 'lr=true' instead of just 'lr' since some SIP stacks are known
  +		%% to require that parameters are of the format 'key=value'.
  +		Param1 = ["lr=true"],
  +		case Port of
  +		    none ->
  +			%% It was requested that we don't include a port number.
  +			sipurl:new([{proto, Proto}, {host, Hostname}, {param, Param1}]);
  +		    _ when is_integer(Port) ->
  +			sipurl:new([{proto, Proto}, {host, Hostname}, {port, Port}, {param, Param1}])
  +		end
  +	end,
  +    contact:print(contact:new(URL)).
   
   %%--------------------------------------------------------------------
   %% Function: standardcopy(Header, ExtraHeaders)
  
positive.code: 	    logger:log(debug, "Siprequest: NOT adding Record-Route since the first Record-Route matches mine"),
  	    Header;
  	false ->
  	    [Route] = sipheader:contact_print([ contact:new(none, RouteStr, []) ]),
  	    keylist:prepend({"Record-Route", [Route]}, Header)
      end.
  %%--------------------------------------------------------------------
  %% Function: add_record_route(URL, Header)
  %%           URL    = sipurl record(), original Request-URI
  %%           Header = keylist record()
  %% Descrip.: Prepend a Record-Route header for this proxy, based on
  %%           the original Request-URI, to Header.
  %% Returns : NewHeader = keylist record()
  %%--------------------------------------------------------------------
  add_record_route(URL, Header) when is_record(URL, sipurl) ->
      Proto =
  	case URL#sipurl.proto of
  	    "sips" ->
  		"sips";
  	    _ ->
  		%% Create sip: Record-Route for everything except SIPS-URIs
  		"sip"
  	end,
      URLport = sipsocket:default_port(URL#sipurl.proto, none),
      MyPort = case URL#sipurl.proto of
  		 "sips" -> sipsocket:get_listenport(tls);
  		 _ -> sipsocket:get_listenport(udp)
  	     end,
      %% If we are listening on the default port for the protocol in URL, we don't
      %% need to set a port in the Record-Route. If not however, we need to set the
      %% port because otherwise Cisco 79xx phones (version 7.5) will put port 5060
  
negative.code:     #via{proto=ViaProto, host=Hostname, port=Port, param=Parameters}.
  
  %%--------------------------------------------------------------------
  %% Function: add_record_route(URL, Header)
  %%           URL    = sipurl record(), original Request-URI
  %%           Header = keylist record()
  %% Descrip.: Prepend a Record-Route header for this proxy, based on
  %%           the original Request-URI, to Header.
  %% Returns : NewHeader = keylist record()
  %%--------------------------------------------------------------------
  add_record_route(URL, Header) when is_record(URL, sipurl) ->
      add_record_route(URL#sipurl.proto, undefined, undefined, Header).
  
  %%--------------------------------------------------------------------
  %% Function: add_record_route(Proto, Hostname, Port, Header)
  %%           Proto      = "sips" | "sip" | string()
  %%           Hostname   = undefined | string()
  %%           Port       = undefined | none | integer()
  %%           Header     = keylist record()
  %% Descrip.: Prepend a Record-Route header for Proto:Host:Port to the
  %%           Header keylist.
  %% Returns : NewHeader = keylist record()
  %%--------------------------------------------------------------------
  add_record_route(Proto, Hostname, Port, Header) when is_list(Proto), is_list(Hostname); Hostname == undefined,
  						     is_integer(Port); Port == none; Port == undefined ->
      RouteStr = construct_record_route(Proto, Hostname, Port),
  
      %% Check if our Record-Route (RouteStr) is already present as the first entry of
      %% the Record-Route set in Header.
      AlreadyPresent =
  	case keylist:fetch('record-route', Header) of
  	    [RouteStr | _] ->
  		%% We only do byte-by-byte matching since the purpose of this check is to
  		%% make sure that this function isn't used twice on a message - not to make sure
  		%% that there is no Record-Route that would resolve to this proxy/UA in there.
  		true;
  	    _ ->
  		%% No Record-Route in header, or not matching ours
  		false
  	end,
      case AlreadyPresent of
  