anchor.diff:  
   %%--------------------------------------------------------------------
   %% Function: register_contact(LogTag, SipUser, Location, Priority,
  -%%                            ExpireHeader)
  -%%           LogTag        = string()
  -%%           SipUser       = string()
  -%%           Location      = contact record()
  -%%           Priority      = integer()
  -%%           ExpireHeader  =
  -%%           RequestCallId = string()
  -%%           RequestCSeq   = integer()
  +%%                            ExpireHeader, CallId, CSeq, AppName)
  +%%           LogTag       = string()
  +%%           SipUser      = string()
  +%%           Location     = contact record()
  +%%           Priority     = integer()
  +%%           ExpireHeader = list() of string(), Expire header from
  +%%                          REGISTER request, or [] if not present
  +%%           CallId       = string(), Call-Id header from REGISTER
  +%%                          request
  +%%           CSeq         = integer(), CSeq number from REGISTER
  +%%                          request
   %% Descrip.: add or update a Location entry
   %% Returns : -
   %%--------------------------------------------------------------------
  -register_contact(LogTag, SipUser, Location, Priority, ExpireHeader,RequestCallId, RequestCSeq)
  -  when is_record(Location, contact) ->
  +register_contact(LogTag, SipUser, Location, Priority, ExpireHeader, CallId, CSeq, AppName)
  +  when is_list(SipUser), is_record(Location, contact), is_integer(Priority), is_list(CallId), is_integer(CSeq) ->
       Expire = parse_register_expire(ExpireHeader, Location),
       logger:log(normal, "~s: REGISTER ~s at ~s (priority ~p, expire in ~p)",
   	       [LogTag, SipUser, Location#contact.urlstr, Priority, Expire]),
  -    phone:insert_purge_phone(SipUser, [{priority, Priority}],
  -			     dynamic,
  +    Flags = register_contact_flags(Priority, Location, AppName),
  +    phone:insert_purge_phone(SipUser, Flags, dynamic,
   			     Expire + util:timestamp(),
   			     sipurl:parse(Location#contact.urlstr),
  -			     RequestCallId,
  -			     RequestCSeq).
  +			     CallId, CSeq).
  +
  +register_contact_flags(Priority, _Contact, incomingproxy) ->
  +    [{priority, Priority}];
  +register_contact_flags(Priority, Contact, outgoingproxy) ->
  +    ContactURL = sipurl:parse(Contact#contact.urlstr),
  +    Proto = sipurl:get_port(ContactURL),
  +    MyURL = sipurl:new([{host, siprequest:myhostname()},
  +			{port, sipserver:get_listenport(Proto)}
  +		       ]),
  +    [{priority, Priority}, {outgoingproxy, sipurl:print(MyURL)}].
   
   %% determine expiration time for a specific contact. Use default
   %% value if contact/header supplies no expiration period.
  
positive.code: 		    phone:delete_record(DBLocation);
  		false ->
  		    %% non-zero expire-time, update the binding
  		    register_contact(LogTag, SipUser, ReqLocation, Priority, ExpireHeader, RequestCallId, RequestCSeq)
  	    end
      end.
  
  check_greater_cseq(LogTag, SipUser, ReqLocation, DBLocation, Priority, RequestCallId, RequestCSeq, ExpireHeader) ->
      %% only process reqest if cseq is > than the last one processed i.e. ignore
      %% old, out of order requests
      case RequestCSeq > DBLocation#phone.cseq of
  	true ->
  	    case parse_register_contact_expire(ExpireHeader, ReqLocation) == 0 of
  		true ->
  
negative.code: 
  
  %%--------------------------------------------------------------------
  %% Function: process_register_request(Request, THandler, LogTag,
  %%                                    LogStr, AppName)
  %%           Request  = response record()
  %%           THandler = term(), server transaction handler
  %%           LogTag   = string(), tag for log messages
  %%           LogStr   = string(), description of request
  %%           AppName  = atom(), application name
  %% Descrip.: Process a received REGISTER. First check if it is for
  %%           one of our domains (homedomain), then check that it
  %%           contains proper authentication and that the authenticated
  %%           user is allowed to register using this address-of-record.
  %%           Finally, let process_updates() process all the
  %%           Contact headers and update the location database.
  %% Returns : not_homedomain | void()
  %%--------------------------------------------------------------------
  process_register_request(Request, THandler, LogTag, LogStr, AppName) when is_record(Request, request),
  									  is_list(LogStr), is_list(LogTag),
  									  is_atom(AppName) ->
      URL = Request#request.uri,
      logger:log(debug, "~p: REGISTER ~p", [AppName, sipurl:print(URL)]),
      %% RFC 3261 chapter 10.3 - Processing REGISTER Request - step 1
      %% check if this registrar handles the domain the request wants to register for
      case local:homedomain(URL#sipurl.host) of
  	true ->
  	    register_require_supported(Request, LogStr, THandler, LogTag, AppName);
  	false ->
  	    %% act as proxy and forward message to other domain
  	    logger:log(debug, "~p: REGISTER for non-homedomain ~p", [AppName, URL#sipurl.host]),
  	    not_homedomain
      end.
  
  %%--------------------------------------------------------------------
  %% Function: register_require_supported(Request, LogStr, THandler,
  %%                                      LogTag, AppName)
  %%           Request  = request record()
  %%           LogStr   = string(), describes REGISTER request
  %%           THandler = thandler record(), server transaction handler
  %%           LogTag   = string(), prefix for logging
  %%           AppName  = atom(), incomingproxy | outgoingproxy
  %% Descrip.: After we have checked that the REGISTER request is for
  %%           one of our homedomains, we start checking the validity of
  %%           the request. First, we do some checks in this function
  %%           before going on to making sure the request is
  %%           authenticated in register_authenticate(...).
  %% Returns :
  %%--------------------------------------------------------------------
  register_require_supported(Request, LogStr, THandler, LogTag, AppName) ->
      Header = Request#request.header,
      %% RFC 3261 chapter 10.3 - Processing REGISTER Request - step 2
      case is_valid_register_request(Header) of
  	true ->
  	    register_authenticate(Request, LogStr, THandler, LogTag, AppName);
  	{siperror, Status, Reason, ExtraHeaders} ->
  	    transactionlayer:send_response_handler(THandler, Status, Reason, ExtraHeaders)
      end.
  
  %% part of process_register/6
  register_authenticate(Request, LogStr, THandler, LogTag, AppName) ->
      Header = Request#request.header,
      logger:log(debug, "~p: ~s -> processing", [AppName, LogStr]),
      %% delete any present Record-Route header (RFC3261, #10.3)
      NewHeader = keylist:delete("Record-Route", Header),
      {_, ToURL} = sipheader:to(Header),
  