[Asterisk-code-review] Revert "res_pjsip_outbound_registration.c: Use our own scheduler and... (asterisk[16])

George Joseph asteriskteam at digium.com
Thu Jan 7 08:39:46 CST 2021


Attention is currently required from: Joshua Colp, Kevin Harwell, Benjamin Keith Ford.
Hello Joshua Colp, Kevin Harwell, Friendly Automation, Benjamin Keith Ford,

I'd like you to do a code review. Please visit

    https://gerrit.asterisk.org/c/asterisk/+/15290

to review the following change.


Change subject: Revert "res_pjsip_outbound_registration.c:  Use our own scheduler and other stuff"
......................................................................

Revert "res_pjsip_outbound_registration.c:  Use our own scheduler and other stuff"

This reverts commit e1fd51cd2c183a3eb61803f52277d1a7d7a18c9c.

Reason for revert: Too many issues reported.  Need to research and correct.

ASTERISK-29230
Reported by: Michael Maier

Change-Id: Ie2356c1cd74436603600599885286b98055b8a17
---
M res/res_pjsip_outbound_registration.c
1 file changed, 123 insertions(+), 173 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/90/15290/1

diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 26bfb7b..4d0e38e 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -343,7 +343,7 @@
 	 */
 	pjsip_tx_data *last_tdata;
 	/*! \brief Timer entry for retrying on temporal responses */
-	struct ast_sip_sched_task *sched_task;
+	pj_timer_entry timer;
 	/*! \brief Optional line parameter placed into Contact */
 	char line[LINE_PARAMETER_SIZE];
 	/*! \brief Current number of retries */
@@ -374,12 +374,6 @@
 	char *transport_name;
 	/*! \brief The name of the registration sorcery object */
 	char *registration_name;
-	/*! \brief Server URI */
-	char *server_uri;
-	/*! \brief Client URI */
-	char *client_uri;
-	/*! \brief Contact URI */
-	char *contact_uri;
 };
 
 /*! \brief Outbound registration state information (persists for lifetime that registration should exist) */
@@ -518,8 +512,8 @@
 		return NULL;
 	}
 
-	ast_debug(3, "%s: Line '%s', using configured endpoint '%s'\n",
-		state->client_state->registration_name, state->client_state->line, state->registration->endpoint);
+	ast_debug(3, "Determined relationship to outbound registration '%s' based on line '%s', using configured endpoint '%s'\n",
+		ast_sorcery_object_get_id(state->registration), state->client_state->line, state->registration->endpoint);
 
 	return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", state->registration->endpoint);
 }
@@ -531,10 +525,10 @@
 /*! \brief Helper function which cancels the timer on a client */
 static void cancel_registration(struct sip_outbound_registration_client_state *client_state)
 {
-	if (client_state->sched_task) {
-		ast_sip_sched_task_cancel(client_state->sched_task);
-		ao2_cleanup(client_state->sched_task);
-		client_state->sched_task = NULL;
+	if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),
+		&client_state->timer, client_state->timer.id)) {
+		/* The timer was successfully cancelled, drop the refcount of client_state */
+		ao2_ref(client_state, -1);
 	}
 }
 
@@ -551,8 +545,6 @@
 	callback_invoked = ast_threadstorage_get(&register_callback_invoked, sizeof(int));
 	if (!callback_invoked) {
 		pjsip_tx_data_dec_ref(tdata);
-		ast_log(LOG_ERROR, "%s: Failed to get threadstorage for registration to server '%s' from client '%s'\n",
-				client_state->registration_name, client_state->server_uri, client_state->client_uri);
 		return PJ_ENOMEM;
 	}
 	*callback_invoked = 0;
@@ -580,8 +572,6 @@
 	 * drop the references we just added
 	 */
 	if ((status != PJ_SUCCESS) && !(*callback_invoked)) {
-		ast_log(LOG_ERROR, "%s: Failed send registration to server '%s' from client '%s'\n",
-				client_state->registration_name, client_state->server_uri, client_state->client_uri);
 		pjsip_tx_data_dec_ref(tdata);
 		ao2_ref(client_state, -1);
 		return status;
@@ -603,23 +593,23 @@
 /*! \brief Callback function for registering */
 static int handle_client_registration(void *data)
 {
-	struct sip_outbound_registration_client_state *client_state = data;
+	RAII_VAR(struct sip_outbound_registration_client_state *, client_state, data, ao2_cleanup);
 	pjsip_tx_data *tdata;
 
-	if (client_state->status == SIP_REGISTRATION_STOPPED) {
+	if (client_state->status == SIP_REGISTRATION_STOPPED
+		|| pjsip_regc_register(client_state->client, PJ_FALSE, &tdata) != PJ_SUCCESS) {
 		return 0;
 	}
 
-	if (pjsip_regc_register(client_state->client, PJ_FALSE, &tdata) != PJ_SUCCESS) {
-		ast_log(LOG_ERROR, "%s: Failed to create registration to server '%s' from client '%s'\n",
-			client_state->registration_name, client_state->server_uri, client_state->client_uri);
-		return 0;
-	}
+	if (DEBUG_ATLEAST(1)) {
+		pjsip_regc_info info;
 
-	ast_debug(1, "%s: Outbound REGISTER attempt %u to '%s' with client '%s'\n",
-		client_state->registration_name,
-		client_state->retries + 1,
-		client_state->server_uri, client_state->client_uri);
+		pjsip_regc_get_info(client_state->client, &info);
+		ast_log(LOG_DEBUG, "Outbound REGISTER attempt %u to '%.*s' with client '%.*s'\n",
+			client_state->retries + 1,
+			(int) info.server_uri.slen, info.server_uri.ptr,
+			(int) info.client_uri.slen, info.client_uri.ptr);
+	}
 
 	if (client_state->support_path) {
 		pjsip_supported_hdr *hdr;
@@ -630,9 +620,7 @@
 			hdr = pjsip_supported_hdr_create(tdata->pool);
 			if (!hdr) {
 				pjsip_tx_data_dec_ref(tdata);
-				ast_log(LOG_ERROR, "%s: Failed to add SUPPORTED header to registration to server '%s' from client '%s'\n",
-					client_state->registration_name, client_state->server_uri, client_state->client_uri);
-				return 0;
+				return -1;
 			}
 
 			pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
@@ -647,23 +635,44 @@
 	return 0;
 }
 
-/*! \brief Helper function which sets up the timer to re-register in a specific amount of time */
-static void schedule_registration(struct sip_outbound_registration_client_state *client_state, unsigned int ms)
+/*! \brief Timer callback function, used just for registrations */
+static void sip_outbound_registration_timer_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
 {
+	struct sip_outbound_registration_client_state *client_state = entry->user_data;
 
-	ast_debug(1, "%s: Scheduling outbound registration to server '%s' from client '%s' in %d ms\n",
-		client_state->registration_name, client_state->server_uri, client_state->client_uri,	ms);
+	entry->id = 0;
+
+	/*
+	 * Transfer client_state reference to serializer task so the
+	 * nominal path will not dec the client_state ref in this
+	 * pjproject callback thread.
+	 */
+	if (ast_sip_push_task(client_state->serializer, handle_client_registration, client_state)) {
+		ast_log(LOG_WARNING, "Scheduled outbound registration could not be executed.\n");
+		ao2_ref(client_state, -1);
+	}
+}
+
+/*! \brief Helper function which sets up the timer to re-register in a specific amount of time */
+static void schedule_registration(struct sip_outbound_registration_client_state *client_state, unsigned int seconds)
+{
+	pj_time_val delay = { .sec = seconds, };
+	pjsip_regc_info info;
 
 	cancel_registration(client_state);
 
-	client_state->sched_task = ast_sip_schedule_task(client_state->serializer,
-		ms, handle_client_registration, ast_taskprocessor_name(client_state->serializer),
-		client_state,
-		AST_SIP_SCHED_TASK_ONESHOT | AST_SIP_SCHED_TASK_DATA_AO2);
+	pjsip_regc_get_info(client_state->client, &info);
+	ast_debug(1, "Scheduling outbound registration to server '%.*s' from client '%.*s' in %d seconds\n",
+			(int) info.server_uri.slen, info.server_uri.ptr,
+			(int) info.client_uri.slen, info.client_uri.ptr,
+			seconds);
 
-	if (!client_state->sched_task) {
-		ast_log(LOG_WARNING, "%s: Failed to schedule registration to server '%s' from client '%s'\n",
-			client_state->registration_name, client_state->server_uri, client_state->client_uri);
+	ao2_ref(client_state, +1);
+	if (pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(), &client_state->timer, &delay) != PJ_SUCCESS) {
+		ast_log(LOG_WARNING, "Failed to schedule registration to server '%.*s' from client '%.*s'\n",
+				(int) info.server_uri.slen, info.server_uri.ptr,
+				(int) info.client_uri.slen, info.client_uri.ptr);
+		ao2_ref(client_state, -1);
 	}
 }
 
@@ -700,18 +709,18 @@
 {
 	struct sip_outbound_registration_client_state *client_state = data;
 
+	cancel_registration(client_state);
+
 	if (client_state->client) {
 		pjsip_regc_info info;
 		pjsip_tx_data *tdata;
 
-		/* We need to get the live state to test "is_busy" */
 		pjsip_regc_get_info(client_state->client, &info);
 
 		if (info.is_busy == PJ_TRUE) {
 			/* If a client transaction is in progress we defer until it is complete */
 			ast_debug(1,
-				"%s: Registration transaction is busy with server '%.*s' from client '%.*s'.\n",
-				client_state->registration_name,
+				"Registration transaction is busy with server '%.*s' from client '%.*s'.\n",
 				(int) info.server_uri.slen, info.server_uri.ptr,
 				(int) info.client_uri.slen, info.client_uri.ptr);
 			client_state->destroy = 1;
@@ -724,11 +733,10 @@
 			break;
 		case SIP_REGISTRATION_REGISTERED:
 			ast_debug(1,
-				"%s: Trying to unregister with server '%.*s' from client '%.*s' before destruction.\n",
-				client_state->registration_name,
+				"Trying to unregister with server '%.*s' from client '%.*s' before destruction.\n",
 				(int) info.server_uri.slen, info.server_uri.ptr,
 				(int) info.client_uri.slen, info.client_uri.ptr);
-			cancel_registration(client_state);
+
 			update_client_state_status(client_state, SIP_REGISTRATION_STOPPING);
 			client_state->destroy = 1;
 			if (pjsip_regc_unregister(client_state->client, &tdata) == PJ_SUCCESS
@@ -738,10 +746,8 @@
 			}
 			break;
 		case SIP_REGISTRATION_REJECTED_TEMPORARY:
-		case SIP_REGISTRATION_STOPPING:
-			cancel_registration(client_state);
-			break;
 		case SIP_REGISTRATION_REJECTED_PERMANENT:
+		case SIP_REGISTRATION_STOPPING:
 		case SIP_REGISTRATION_STOPPED:
 			break;
 		}
@@ -752,7 +758,6 @@
 
 	update_client_state_status(client_state, SIP_REGISTRATION_STOPPED);
 	ast_sip_auth_vector_destroy(&client_state->outbound_auths);
-
 	ao2_ref(client_state, -1);
 
 	return 0;
@@ -810,21 +815,20 @@
 	}
 }
 
-static void schedule_retry(struct registration_response *response, unsigned int interval)
+static void schedule_retry(struct registration_response *response, unsigned int interval,
+			   const char *server_uri, const char *client_uri)
 {
 	update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_TEMPORARY);
-	schedule_registration(response->client_state, interval * 1000);
+	schedule_registration(response->client_state, interval);
 
 	if (response->rdata) {
-		ast_log(LOG_WARNING, "%s: Temporal response '%d' received from '%s' on "
+		ast_log(LOG_WARNING, "Temporal response '%d' received from '%s' on "
 			"registration attempt to '%s', retrying in '%u'\n",
-			response->client_state->registration_name,
-			response->code, response->client_state->server_uri, response->client_state->client_uri, interval);
+			response->code, server_uri, client_uri, interval);
 	} else {
-		ast_log(LOG_WARNING, "%s: No response received from '%s' on "
+		ast_log(LOG_WARNING, "No response received from '%s' on "
 			"registration attempt to '%s', retrying in '%u'\n",
-			response->client_state->registration_name,
-			response->client_state->server_uri, response->client_state->client_uri, interval);
+			server_uri, client_uri, interval);
 	}
 }
 
@@ -837,9 +841,15 @@
 		return 0;
 	}
 
-	ast_debug(1,
-		"%s: Outbound registration transport to server '%s' from client '%s' shutdown\n",
-		state->client_state->registration_name, state->client_state->server_uri, state->client_state->client_uri);
+	if (DEBUG_ATLEAST(1)) {
+		pjsip_regc_info info;
+
+		pjsip_regc_get_info(state->client_state->client, &info);
+		ast_log(LOG_DEBUG,
+			"Outbound registration transport to server '%.*s' from client '%.*s' shutdown\n",
+			(int) info.server_uri.slen, info.server_uri.ptr,
+			(int) info.client_uri.slen, info.client_uri.ptr);
+	}
 
 	cancel_registration(state->client_state);
 
@@ -912,15 +922,21 @@
 static int handle_registration_response(void *data)
 {
 	struct registration_response *response = data;
+	pjsip_regc_info info;
+	char server_uri[PJSIP_MAX_URL_SIZE];
+	char client_uri[PJSIP_MAX_URL_SIZE];
 
 	if (response->client_state->status == SIP_REGISTRATION_STOPPED) {
 		ao2_ref(response, -1);
 		return 0;
 	}
 
-	ast_debug(1, "%s: Processing REGISTER response %d from server '%s' for client '%s' with expiration '%d'\n",
-		response->client_state->registration_name, response->code, response->client_state->server_uri,
-		response->client_state->client_uri, response->expiration);
+	pjsip_regc_get_info(response->client_state->client, &info);
+	ast_copy_pj_str(server_uri, &info.server_uri, sizeof(server_uri));
+	ast_copy_pj_str(client_uri, &info.client_uri, sizeof(client_uri));
+
+	ast_debug(1, "Processing REGISTER response %d from server '%s' for client '%s'\n",
+			response->code, server_uri, client_uri);
 
 	if (response->code == 408 || response->code == 503) {
 		if ((ast_sip_failover_request(response->old_request))) {
@@ -942,9 +958,8 @@
 		if (!ast_sip_create_request_with_auth(&response->client_state->outbound_auths,
 				response->rdata, response->old_request, &tdata)) {
 			response->client_state->auth_attempted = 1;
-			ast_debug(1, "%s: Sending authenticated REGISTER to server '%s' from client '%s'\n",
-				response->client_state->registration_name, response->client_state->server_uri,
-				response->client_state->client_uri);
+			ast_debug(1, "Sending authenticated REGISTER to server '%s' from client '%s'\n",
+					server_uri, client_uri);
 			pjsip_tx_data_add_ref(tdata);
 			res = registration_client_send(response->client_state, tdata);
 
@@ -958,9 +973,8 @@
 				return 0;
 			}
 		} else {
-			ast_log(LOG_WARNING, "%s: Failed to create authenticated REGISTER request to server '%s' from client '%s'\n",
-				response->client_state->registration_name, response->client_state->server_uri,
-				response->client_state->client_uri);
+			ast_log(LOG_WARNING, "Failed to create authenticated REGISTER request to server '%s' from client '%s'\n",
+					server_uri, client_uri);
 		}
 		/* Otherwise, fall through so the failure is processed appropriately */
 	}
@@ -973,15 +987,13 @@
 			int next_registration_round;
 
 			/* If the registration went fine simply reschedule registration for the future */
-			ast_debug(1, "%s: Outbound registration to '%s' with client '%s' successful\n",
-				response->client_state->registration_name, response->client_state->server_uri,
-				response->client_state->client_uri);
+			ast_debug(1, "Outbound registration to '%s' with client '%s' successful\n", server_uri, client_uri);
 			update_client_state_status(response->client_state, SIP_REGISTRATION_REGISTERED);
 			response->client_state->retries = 0;
-			next_registration_round = (response->expiration - REREGISTER_BUFFER_TIME) * 1000;
+			next_registration_round = response->expiration - REREGISTER_BUFFER_TIME;
 			if (next_registration_round < 0) {
-				/* Re-register no sooner than the buffer time. */
-				next_registration_round = REREGISTER_BUFFER_TIME * 1000;
+				/* Re-register immediately. */
+				next_registration_round = 0;
 			}
 			schedule_registration(response->client_state, next_registration_round);
 
@@ -989,9 +1001,7 @@
 			registration_transport_monitor_setup(response->rdata->tp_info.transport,
 				response->client_state->registration_name);
 		} else {
-			ast_debug(1, "%s: Outbound unregistration to '%s' with client '%s' successful\n",
-				response->client_state->registration_name, response->client_state->server_uri,
-				response->client_state->client_uri);
+			ast_debug(1, "Outbound unregistration to '%s' with client '%s' successful\n", server_uri, client_uri);
 			update_client_state_status(response->client_state, SIP_REGISTRATION_UNREGISTERED);
 			ast_sip_transport_monitor_unregister(response->rdata->tp_info.transport,
 				registration_transport_shutdown_cb, response->client_state->registration_name,
@@ -1001,19 +1011,18 @@
 		/* We need to deal with the pending destruction instead. */
 	} else if (response->retry_after) {
 		/* If we have been instructed to retry after a period of time, schedule it as such */
-		schedule_retry(response, response->retry_after);
+		schedule_retry(response, response->retry_after, server_uri, client_uri);
 	} else if (response->client_state->retry_interval
 		&& sip_outbound_registration_is_temporal(response->code, response->client_state)) {
 		if (response->client_state->retries == response->client_state->max_retries) {
 			/* If we received enough temporal responses to exceed our maximum give up permanently */
 			update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_PERMANENT);
-			ast_log(LOG_WARNING, "%s: Maximum retries reached when attempting outbound registration to '%s' with client '%s', stopping registration attempt\n",
-				response->client_state->registration_name, response->client_state->server_uri,
-				response->client_state->client_uri);
+			ast_log(LOG_WARNING, "Maximum retries reached when attempting outbound registration to '%s' with client '%s', stopping registration attempt\n",
+				server_uri, client_uri);
 		} else {
 			/* On the other hand if we can still try some more do so */
 			response->client_state->retries++;
-			schedule_retry(response, response->client_state->retry_interval);
+			schedule_retry(response, response->client_state->retry_interval, server_uri, client_uri);
 		}
 	} else {
 		if (response->code == 403
@@ -1022,34 +1031,30 @@
 			/* A forbidden response retry interval is configured and there are retries remaining */
 			update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_TEMPORARY);
 			response->client_state->retries++;
-			schedule_registration(response->client_state, response->client_state->forbidden_retry_interval * 1000);
-			ast_log(LOG_WARNING, "%s: 403 Forbidden fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",
-				response->client_state->registration_name, response->client_state->server_uri,
-				response->client_state->client_uri, response->client_state->forbidden_retry_interval);
+			schedule_registration(response->client_state, response->client_state->forbidden_retry_interval);
+			ast_log(LOG_WARNING, "403 Forbidden fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",
+				server_uri, client_uri, response->client_state->forbidden_retry_interval);
 		} else if (response->client_state->fatal_retry_interval
 			   && response->client_state->retries < response->client_state->max_retries) {
 			/* Some kind of fatal failure response received, so retry according to configured interval */
 			update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_TEMPORARY);
 			response->client_state->retries++;
-			schedule_registration(response->client_state, response->client_state->fatal_retry_interval * 1000);
-			ast_log(LOG_WARNING, "%s: '%d' fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",
-				response->client_state->registration_name, response->code, response->client_state->server_uri,
-				response->client_state->client_uri, response->client_state->fatal_retry_interval);
+			schedule_registration(response->client_state, response->client_state->fatal_retry_interval);
+			ast_log(LOG_WARNING, "'%d' fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",
+				response->code, server_uri, client_uri, response->client_state->fatal_retry_interval);
 		} else {
 			/* Finally if there's no hope of registering give up */
 			update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_PERMANENT);
 			if (response->rdata) {
-				ast_log(LOG_WARNING, "%s: Fatal response '%d' received from '%s' on registration attempt to '%s', stopping outbound registration\n",
-					response->client_state->registration_name, response->code, response->client_state->server_uri,
-					response->client_state->client_uri);
+				ast_log(LOG_WARNING, "Fatal response '%d' received from '%s' on registration attempt to '%s', stopping outbound registration\n",
+					response->code, server_uri, client_uri);
 			} else {
-				ast_log(LOG_WARNING, "%s: Fatal registration attempt to '%s', stopping outbound registration\n",
-					response->client_state->registration_name, response->client_state->client_uri);
+				ast_log(LOG_WARNING, "Fatal registration attempt to '%s', stopping outbound registration\n", client_uri);
 			}
 		}
 	}
 
-	ast_system_publish_registry("PJSIP", response->client_state->client_uri, response->client_state->server_uri,
+	ast_system_publish_registry("PJSIP", client_uri, server_uri,
 		sip_outbound_registration_status_str(response->client_state->status), NULL);
 
 	if (response->client_state->destroy) {
@@ -1090,10 +1095,8 @@
 	 */
 	response->client_state = client_state;
 
-	ast_debug(1, "%s: Received REGISTER response %d(%.*s) from '%s': Expires: %d\n",
-		client_state->registration_name,
-		param->code, (int) param->reason.slen, param->reason.ptr,
-		client_state->server_uri, param->expiration);
+	ast_debug(1, "Received REGISTER response %d(%.*s)\n",
+		param->code, (int) param->reason.slen, param->reason.ptr);
 
 	if (param->rdata) {
 		struct pjsip_retry_after_hdr *retry_after;
@@ -1128,8 +1131,7 @@
 	 * pjproject callback thread.
 	 */
 	if (ast_sip_push_task(client_state->serializer, handle_registration_response, response)) {
-		ast_log(LOG_WARNING, "%s: Failed to pass incoming registration response to threadpool\n",
-			client_state->registration_name);
+		ast_log(LOG_WARNING, "Failed to pass incoming registration response to threadpool\n");
 		ao2_cleanup(response);
 	}
 }
@@ -1139,8 +1141,7 @@
 {
 	struct sip_outbound_registration_state *state = obj;
 
-	ast_debug(3, "%s: Destroying registration state for registration to server '%s' from client '%s'\n",
-		state->client_state->registration_name,
+	ast_debug(3, "Destroying registration state for registration to server '%s' from client '%s'\n",
 		state->registration ? state->registration->server_uri : "",
 		state->registration ? state->registration->client_uri : "");
 	ao2_cleanup(state->registration);
@@ -1151,8 +1152,7 @@
 		ao2_ref(state->client_state, -1);
 	} else if (ast_sip_push_task(state->client_state->serializer,
 		handle_client_state_destruction, state->client_state)) {
-		ast_log(LOG_WARNING, "%s: Failed to pass outbound registration client destruction to threadpool\n",
-			state->client_state->registration_name);
+		ast_log(LOG_WARNING, "Failed to pass outbound registration client destruction to threadpool\n");
 		ao2_ref(state->client_state, -1);
 	}
 }
@@ -1162,9 +1162,6 @@
 {
 	struct sip_outbound_registration_client_state *client_state = obj;
 
-	ast_debug(3, "%s: Destroying registration client state\n",
-		client_state->registration_name);
-
 	ast_statsd_log_string("PJSIP.registrations.count", AST_STATSD_GAUGE, "-1", 1.0);
 	ast_statsd_log_string_va("PJSIP.registrations.state.%s", AST_STATSD_GAUGE, "-1", 1.0,
 		sip_outbound_registration_status_str(client_state->status));
@@ -1172,9 +1169,6 @@
 	ast_taskprocessor_unreference(client_state->serializer);
 	ast_free(client_state->transport_name);
 	ast_free(client_state->registration_name);
-	ast_free(client_state->server_uri);
-	ast_free(client_state->client_uri);
-	ast_free(client_state->contact_uri);
 	if (client_state->last_tdata) {
 		pjsip_tx_data_dec_ref(client_state->last_tdata);
 	}
@@ -1198,6 +1192,8 @@
 	}
 
 	state->client_state->status = SIP_REGISTRATION_UNREGISTERED;
+	pj_timer_entry_init(&state->client_state->timer, 0, state->client_state,
+		sip_outbound_registration_timer_cb);
 	state->client_state->transport_name = ast_strdup(registration->transport);
 	state->client_state->registration_name =
 		ast_strdup(ast_sorcery_object_get_id(registration));
@@ -1432,24 +1428,20 @@
 	}
 
 	pj_cstr(&server_uri, registration->server_uri);
-	state->client_state->server_uri = ast_strdup(registration->server_uri);
+
 
 	if (sip_dialog_create_contact(pjsip_regc_get_pool(state->client_state->client),
 		&contact_uri, S_OR(registration->contact_user, "s"), &server_uri, &selector,
 		state->client_state->line)) {
 		return -1;
 	}
-	ast_copy_pj_str2(&state->client_state->contact_uri, &contact_uri);
 
 	pj_cstr(&client_uri, registration->client_uri);
-	state->client_state->client_uri = ast_strdup(registration->client_uri);
-
 	if (pjsip_regc_init(state->client_state->client, &server_uri, &client_uri,
 		&client_uri, 1, &contact_uri, registration->expiration) != PJ_SUCCESS) {
 		return -1;
 	}
 
-
 	return 0;
 }
 
@@ -1460,10 +1452,6 @@
 	struct sip_outbound_registration *registration = ao2_bump(state->registration);
 	size_t i;
 
-	ast_debug(1, "%s: Performing register to server '%s' from client '%s'  Expiration: %d\n",
-		state->client_state->registration_name,
-		state->registration->server_uri, state->registration->client_uri, registration->expiration);
-
 	/* Just in case the client state is being reused for this registration, free the auth information */
 	ast_sip_auth_vector_destroy(&state->client_state->outbound_auths);
 
@@ -1485,7 +1473,7 @@
 
 	pjsip_regc_update_expires(state->client_state->client, registration->expiration);
 
-	schedule_registration(state->client_state, ((ast_random() % 10) + 1) * 1000);
+	schedule_registration(state->client_state, (ast_random() % 10) + 1);
 
 	ao2_ref(registration, -1);
 	ao2_ref(state, -1);
@@ -1614,9 +1602,10 @@
 	struct sip_outbound_registration_state *state = obj;
 	struct pjsip_regc *client = state->client_state->client;
 	pjsip_tx_data *tdata;
+	pjsip_regc_info info;
 
-	ast_debug(1, "%s: Unregistering contacts with server '%s' from client '%s'\n",
-		state->client_state->registration_name,
+	pjsip_regc_get_info(client, &info);
+	ast_debug(1, "Unregistering contacts with server '%s' from client '%s'\n",
 		state->registration->server_uri, state->registration->client_uri);
 
 	cancel_registration(state->client_state);
@@ -1643,11 +1632,6 @@
 static int queue_register(struct sip_outbound_registration_state *state)
 {
 	ao2_ref(state, +1);
-
-	ast_debug(1, "%s: Queueing register to server '%s' from client '%s'\n",
-		state->client_state->registration_name,
-		state->registration->server_uri, state->registration->client_uri);
-
 	if (ast_sip_push_task(state->client_state->serializer, sip_outbound_registration_perform, state)) {
 		ao2_ref(state, -1);
 		return -1;
@@ -1901,7 +1885,7 @@
 	ast_sip_sorcery_object_to_ami(ami->registration, &buf);
 
 	if ((state = get_state(ast_sorcery_object_get_id(ami->registration)))) {
-		int next_reg = 0;
+		pjsip_regc_info info;
 
 		if (state->client_state->status == SIP_REGISTRATION_REGISTERED) {
 			++ami->registered;
@@ -1912,12 +1896,8 @@
 		ast_str_append(&buf, 0, "Status: %s\r\n",
 			sip_outbound_registration_status_str(state->client_state->status));
 
-		if (state->client_state->status == SIP_REGISTRATION_REGISTERED && state->client_state->sched_task) {
-			ast_sip_sched_task_get_times2(state->client_state->sched_task, NULL, NULL, NULL, NULL,
-				&next_reg, NULL);
-		}
-
-		ast_str_append(&buf, 0, "NextReg: %d\r\n", next_reg / 1000);
+		pjsip_regc_get_info(state->client_state->client, &info);
+		ast_str_append(&buf, 0, "NextReg: %d\r\n", info.next_reg);
 		ao2_ref(state, -1);
 	}
 
@@ -2022,46 +2002,22 @@
 	ast_assert(context->output_buffer != NULL);
 
 	ast_str_append(&context->output_buffer, 0,
-		" <Registration/ServerURI..............................>  <Auth..........>  <Status.......>");
-	ast_str_append(&context->output_buffer, 0,
-		"  <Last Reg..>  <Intvl>  <Next Start.....secs>\n"
-		"==============================================");
+		" <Registration/ServerURI..............................>  <Auth..........>  <Status.......>\n");
 
 	return 0;
 }
 
-#define TIME_FORMAT "%a %T"
-
 static int cli_print_body(void *obj, void *arg, int flags)
 {
 	struct sip_outbound_registration *registration = obj;
 	struct ast_sip_cli_context *context = arg;
 	const char *id = ast_sorcery_object_get_id(registration);
 	struct sip_outbound_registration_state *state = get_state(id);
-	int next_run_ms = 0;
-	struct timeval next = { 0, 0 };
-	struct timeval last = { 0, 0 };
-	struct ast_tm tm;
-	char next_start[32] = "";
-	char last_start[32] = "";
-	int interval;
-
 #define REGISTRATION_URI_FIELD_LEN	53
 
 	ast_assert(context->output_buffer != NULL);
 
-	if (state->client_state->sched_task) {
-		ast_sip_sched_task_get_times2(state->client_state->sched_task, &last, NULL, NULL, &interval,
-			&next_run_ms, &next);
-
-		ast_localtime(&last, &tm, NULL);
-		ast_strftime(last_start, sizeof(last_start), TIME_FORMAT, &tm);
-
-		ast_localtime(&next, &tm, NULL);
-		ast_strftime(next_start, sizeof(next_start), TIME_FORMAT, &tm);
-	}
-
-	ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s  %-16s  %-16s",
+	ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s  %-16s  %-16s\n",
 		id,
 		(int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
 		(int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
@@ -2069,15 +2025,9 @@
 		AST_VECTOR_SIZE(&registration->outbound_auths)
 			? AST_VECTOR_GET(&registration->outbound_auths, 0)
 			: "n/a",
-		(state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered")
-		);
-
-	ast_str_append(&context->output_buffer, 0, " %-12s  %7d  %-12s %8d\n",
-		last_start, interval / 1000, next_start, next_run_ms / 1000);
-
+		(state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered"));
 	ao2_cleanup(state);
 
-
 	if (context->show_details
 		|| (context->show_details_only_level_0 && context->indent_level == 0)) {
 		ast_str_append(&context->output_buffer, 0, "\n");

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15290
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ie2356c1cd74436603600599885286b98055b8a17
Gerrit-Change-Number: 15290
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Attention: Joshua Colp <jcolp at sangoma.com>
Gerrit-Attention: Kevin Harwell <kharwell at digium.com>
Gerrit-Attention: Benjamin Keith Ford <bford at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210107/248b6551/attachment-0001.html>


More information about the asterisk-code-review mailing list