From 50f8d8aa4f59d01a6aa7209e201e7fbd27bde90f Mon Sep 17 00:00:00 2001
From: Wenpeng Song <wenpeng.song@iopsys.eu>
Date: Thu, 20 Mar 2025 09:04:14 +0000
Subject: [PATCH] Adjust the use of registration_resend() due to the previous
 commit, REF 16559

registration_resend() simply does nothing and returns 0 when client_state->
registration_resend_timer_id is -1.
This commit creates a 1s timer and causes registration_resend() to do the actual
work.
---
 res/res_pjsip_outbound_registration.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index c3afe5d467..2085b82fc9 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -1870,7 +1870,7 @@ static int handle_registration_response(void *data)
 			// E-unreg failed while E-reg success, stop further trying, trigger a resend which will reset the transport and queue normal registration.
 			endpoint->Emergency=false;
 			ast_log(LOG_NOTICE,"===== E-unreg failed while E-reg success, E-unreg stopped and send normal reg direct=====\n");
-			registration_resend(response);
+			client_state->registration_resend_timer_id = ast_sched_add(sched, 1, registration_resend, response);
 			return 0;
 		}
 		if(!response->retry_after && endpoint && endpoint->failover_reg_addr == 1){
@@ -1910,7 +1910,7 @@ static int handle_registration_response(void *data)
 
 			if (response->code == 444 || client_state->attempts == 0){
 				ast_debug(1, "%s: Registration re-try to the next address immediately.\n", client_state->registration_name);
-				registration_resend(response);
+				client_state->registration_resend_timer_id = ast_sched_add(sched, 1, registration_resend, response);
 			} else {
 				ast_debug(1, "%s: Registration re-try after %d seconds.\n", client_state->registration_name, waiting_time);
 				client_state->registration_resend_timer_id = ast_sched_add(sched, waiting_time * 1000, registration_resend, response);
@@ -1922,7 +1922,7 @@ static int handle_registration_response(void *data)
 			client_state->Emergency_unreg_ongoing=true;
 			update_client_state_status(client_state, SIP_REGISTRATION_UNREGISTERED);
 			sip_outbound_registration_send_ubus_event("UNREGISTERED",response->expiration,client_uri);
-			registration_resend(response);
+			client_state->registration_resend_timer_id = ast_sched_add(sched, 1, registration_resend, response);
 			return 0;
 		}
 	} else if ((response->code == 401 || response->code == 407)
-- 
GitLab