anchor.diff:  	    error -> PstnCtx#pstn_ctx.called_number;
   	    N when is_list(N) -> N
   	end,
  -    {ok, Classdefs} = yxa_config:get_env(classdefs),
  -    {ok, Class} = sipauth:classify_number(DstNumber, Classdefs),
  +    Class =
  +	case DstNumber of
  +	    undefined ->
  +		undefined;
  +	    _ ->
  +		{ok, Classdefs} = yxa_config:get_env(classdefs),
  +		{ok, Class1} = sipauth:classify_number(DstNumber, Classdefs),
  +		Class1
  +	end,
       {ok, UnauthClasses} = yxa_config:get_env(sipauth_unauth_classlist),
       User = PstnCtx#pstn_ctx.user,
       PstnCtx1 =
   	PstnCtx#pstn_ctx{dst_number = DstNumber,
   			 dst_class  = Class
   			},
  -    case lists:member(Class, UnauthClasses) of
  -	true ->
  -	    logger:log(normal, "~s: pstnproxy: Allowing request from user ~p to number available to anyone "
  -		       "(~s, class '~p')", [YxaCtx#yxa_ctx.app_logtag, User, DstNumber, Class]),
  -	    {ok, true, PstnCtx1};
  -	false when is_list(User) ->
  -	    case local:is_allowed_pstn_dst(User, DstNumber, Request#request.header, Class) of
  -		true ->
  -		    Verdict = check_auth_for_allowed_pstn_dst(Request, YxaCtx, PstnCtx1),
  -		    {ok, Verdict, PstnCtx1};
  -		false ->
  -		    logger:log(normal, "~s: pstnproxy: User ~p NOT allowed request to number ~s, class '~p'",
  -			       [YxaCtx#yxa_ctx.app_logtag, User, DstNumber, Class]),
  +
  +    case DstNumber of
  +	undefined ->
  +	    case Request#request.method of
  +                "BYE" ->
  +                    logger:log(debug, "~s: pstnproxy: Allowing BYE request to PSTN GW without trying to "
  +			       "determine PSTN number destination", [YxaCtx#yxa_ctx.app_logtag]),
  +		    %% BYEs from IP to PSTN are sent to the Contact used by the gateway. The Contact may
  +		    %% include the PSTN number, or it may not - it depends completely on the gateway.
  +		    %% Better not make any assumptions. XXX check that there is a to-tag too?
  +		    {ok, true, PstnCtx1};
  +		_ ->
  +		    logger:log(debug, "~s: pstnproxy: Disallowing non-BYE request to PSTN gateway because "
  +			       "no PSTN number destination could be determined", [YxaCtx#yxa_ctx.app_logtag]),
   		    transactionlayer:send_response_handler(YxaCtx#yxa_ctx.thandler, 403, "Forbidden", []),
   		    {ok, false, PstnCtx1}
   	    end;
  -	false when User == undefined ->
  -	    Verdict = check_unauth_request_to_pstn_dst(Request, YxaCtx, PstnCtx1),
  -	    {ok, Verdict, PstnCtx1}
  -    end.
  +	_ when is_list(DstNumber) ->
  +	    case lists:member(Class, UnauthClasses) of
  +		true ->
  +		    logger:log(normal, "~s: pstnproxy: Allowing request from user ~p to number available to anyone "
  +			       "(~s, class '~p')", [YxaCtx#yxa_ctx.app_logtag, User, DstNumber, Class]),
  +		    {ok, true, PstnCtx1};
  +		false when is_list(User) ->
  +		    case local:is_allowed_pstn_dst(User, DstNumber, Request#request.header, Class) of
  +			true ->
  +			    %% Ok, now just check that the authorization isn't stale (or is allowed to be stale)
  +			    Verdict = check_auth_for_allowed_pstn_dst(Request, YxaCtx, PstnCtx1),
  +			    {ok, Verdict, PstnCtx1};
  +			false ->
  +			    logger:log(normal, "~s: pstnproxy: User ~p NOT allowed request to number ~s, class '~p'",
  +				       [YxaCtx#yxa_ctx.app_logtag, User, DstNumber, Class]),
  +			    transactionlayer:send_response_handler(YxaCtx#yxa_ctx.thandler, 403, "Forbidden", []),
  +			    {ok, false, PstnCtx1}
  +		    end;
  +		false when User == undefined ->
  +		    Verdict = check_unauth_request_to_pstn_dst(Request, YxaCtx, PstnCtx1),
  +		    {ok, Verdict, PstnCtx1}
  +	    end
  +    end.
  +
   
   %% part of authorize_user_call_to_pstn/3
   %% Returns: true | false
  
positive.code: 					 {"Autotest", ["true"]}
  					]),
      ACI_SIP_Header3 = add_caller_identity(sip, "INVITE", ACI_SIP_Header3, ACI_SIP_Dst1, ACI_SIP_Ctx2),
      
  
  
      autotest:mark(?LINE, "add_caller_identity/3 - other 1"),
  
negative.code: 	false ->
  	    local:start_sippipe(Request, YxaCtx, Dst, AppData)
      end.
  
  
  %%====================================================================
  %% Test functions
  