anchor.diff:  	 process_route_header/2,
   	 check_proxy_request/1,
   	 make_base64_md5_token/1,
  +	 stateless_route_proxy_request/1,
  +	 fix_content_length/2,
  +	 binary_make_message/3,
  +	 proxy_add_via/4,
  +	 standardcopy/2,
  +	 get_approximate_msgsize/1,
   
   	 test/0
   	]).
  
positive.code:     end.
  
  %%--------------------------------------------------------------------
  %% Function: send_to_available_dst(DstList, Request, ViaParam)
  %%           DstList       = list() of sipdst record()
  %%           Request       = request record()
  %%           ViaParam      = list() of {key, value} tuple()
  %% Descrip.: Sequentially try to get sockets for, and send request
  %%           to, the destinations listed in DstList.
  %% Returns : {ok, Socket, Branch} |
  %%           {error, Reason}      |
  %%           Socket = sipsocket record(), the socket finally used
  %%           Branch = string(), the branch we put in the Via header
  %%           Reason = string()
  %% Note    : XXX This function should no longer accept a list - we are
  %%           always transaction stateful now!
  %%--------------------------------------------------------------------
  send_to_available_dst([], Request, _ViaParam) when is_record(Request, request) ->
      {Method, URI, Header, Body} = {Request#request.method, Request#request.uri,
  				   Request#request.header, Request#request.body},
      BinLine1 = list_to_binary([Method, " ", sipurl:print(URI), " SIP/2.0"]),
      BinMsg = binary_make_message(BinLine1, Header, list_to_binary(Body)),
      Message = binary_to_list(BinMsg),
      logger:log(debug, "Siprequest (transport layer) : Failed sending request"
  	       " (my Via not added, original URI shown) :~n~s", [Message]),
      {senderror, "failed"};
  send_to_available_dst([Dst | DstT], Request, ViaParam)
    when is_record(Dst, sipdst), is_record(Request, request) ->
      IP = Dst#sipdst.addr,
      Port = Dst#sipdst.port,
      Proto = Dst#sipdst.proto,
      SocketModule = sipsocket:proto2module(Proto),
      DestStr = sipdst:dst2str(Dst),
      case sipsocket:get_socket(SocketModule, Proto, IP, Port) of
  	{error, What} ->
  	    logger:log(debug, "Siprequest (transport layer) : Failed to get ~p socket for ~s : ~p",
  		       [Proto, DestStr, What]),
  	    %% try next
  	    send_to_available_dst(DstT, Request, ViaParam);
  	SipSocket when is_record(SipSocket, sipsocket) ->
  	    {Method, OrigURI, Header, Body} = {Request#request.method, Request#request.uri,
  					       Request#request.header, Request#request.body},
  	    NewHeader1 = proxy_add_via(Header, OrigURI, ViaParam, Proto),
  	    BinLine1 = list_to_binary([Method, " ", sipurl:print(Dst#sipdst.uri), " SIP/2.0"]),
  	    BinMsg = binary_make_message(BinLine1, NewHeader1, list_to_binary(Body)),
  	    SendRes = sipsocket:send(SipSocket, Proto, IP, Port, BinMsg),
  	    case SendRes of
  		ok ->
  		    logger:log(debug, "Siprequest (transport layer) : sent request(dst=~s) :~n~s~n",
  			       [DestStr, binary_to_list(BinMsg)]),
  		    TopVia = sipheader:topvia(NewHeader1),
  		    UsedBranch = lists:flatten(sipheader:get_via_branch_full(TopVia)),
  		    {ok, SipSocket, UsedBranch};
  		{error, E} ->
  		    logger:log(debug, "Siprequest (transport layer) : Failed sending message to ~p:~s:~p, error ~p",
  			       [Proto, IP, Port, E]),
  		    send_to_available_dst(DstT, Request, ViaParam)
  	    end
      end;
  send_to_available_dst([Dst | DstT], Request, ViaParam) ->
      logger:log(error, "Siprequest (transport layer) : send_to_available_dst called with illegal dst ~p", [Dst]),
      send_to_available_dst(DstT, Request, ViaParam).
  
  
  %%--------------------------------------------------------------------
  %% Function: proxy_check_maxforwards(Header)
  
negative.code:     end.
  
  %%--------------------------------------------------------------------
  %% Function: stateless_route_proxy_request(Request)
  %%           Request = request record()
  %% Descrip.: Inspect a request that some Yxa application has found it
  %%           should proxy statelessly. Figure out a single sipdst
  %%           destination for this request (sorry, stateless SIP does
  %%           not handle multiple destinations) and return that
  %%           destination plus a new request (the headers might change
  %%           if we have popped a Route header).
  %% Returns : {ok, Dst, NewRequest} |
  %%           throw {siperror, ...}
  %%           Dst        = sipdst record()
  %%           NewRequest = request record()
  %%--------------------------------------------------------------------
  stateless_route_proxy_request(Request) when is_record(Request, request) ->
      {ok, NewHeader, ApproxMsgSize} = check_proxy_request(Request),
      case stateless_route_proxy_request2(Request#request{header=NewHeader}, ApproxMsgSize) of
  	{ok, [Dst], NewRequest} ->
  	    {ok, Dst, NewRequest};
  	{ok, [Dst | Rest], NewRequest} ->
  	    logger:log(debug, "Warning: request being forwarded statelessly had more than one destination, "
  		       "ignoring all but the first one :~n~p", [sipdst:debugfriendly([Dst | Rest])]),
  	    {ok, Dst, NewRequest};
  	_ ->
  	    {error, "stateless_route_proxy_request() failed"}
      end.
  
  %% part of stateless_route_proxy_request/1
  stateless_route_proxy_request2(Request, ApproxMsgSize) ->
      {Header, URI} = {Request#request.header, Request#request.uri},
      case process_route_header(Header, URI) of
  	nomatch ->
  	    case sipdst:url_to_dstlist(URI, ApproxMsgSize, URI) of
  		DstList when is_list(DstList) ->
  		    {ok, DstList, Request};
  		Unknown ->
  		    logger:log(error, "Siprequest (transport layer) : Failed resolving URI ~s : ~p",
  			       [sipurl:print(URI), Unknown]),
  		    {error, "Failed resolving destination"}
  	    end;
  	{ok, NewHeader1, DstURI, ReqURI} when is_record(DstURI, sipurl), is_record(ReqURI, sipurl) ->
  	    logger:log(debug, "Siprequest (transport layer) : Routing request as per the Route header,"
  		       " Destination ~p, Request-URI ~p",
  		       [sipurl:print(DstURI), sipurl:print(ReqURI)]),
  	    case sipdst:url_to_dstlist(DstURI, ApproxMsgSize, ReqURI) of
  		DstList when is_list(DstList) ->
  		    {ok, DstList, Request#request{header=NewHeader1}};
  		Unknown ->
  		    logger:log(error, "Siprequest (transport layer) : Failed resolving URI "
  			       "(from Route header) ~s : ~p", [sipurl:print(URI), Unknown]),
  