[Asterisk-code-review] res_pjsip_outbound_registration: Show time until expiration (asterisk[16])

N A asteriskteam at digium.com
Wed May 11 07:27:20 CDT 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18517 )


Change subject: res_pjsip_outbound_registration: Show time until expiration
......................................................................

res_pjsip_outbound_registration: Show time until expiration

Adjusts the pjsip show registration(s) commands to show
the amount of seconds remaining until a registration
expires.

ASTERISK-29845 #close

Change-Id: Ic4fea15a1a1056c424416def49d1ca8e776c0483
---
M res/res_pjsip_outbound_registration.c
1 file changed, 9 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/17/18517/1

diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 2cf5713..add3ddf 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -374,6 +374,8 @@
 	char *transport_name;
 	/*! \brief The name of the registration sorcery object */
 	char *registration_name;
+	/*! \brief Expected time of registration lapse/expiration */
+	unsigned int registration_expires;
 };
 
 /*! \brief Outbound registration state information (persists for lifetime that registration should exist) */
@@ -686,6 +688,7 @@
 				(int) info.client_uri.slen, info.client_uri.ptr);
 		ao2_ref(client_state, -1);
 	}
+	client_state->registration_expires = ((int) time(NULL)) + seconds;
 }
 
 static void update_client_state_status(struct sip_outbound_registration_client_state *client_state, enum sip_outbound_registration_status status)
@@ -2012,7 +2015,7 @@
 	ast_assert(context->output_buffer != NULL);
 
 	ast_str_append(&context->output_buffer, 0,
-		" <Registration/ServerURI..............................>  <Auth..........>  <Status.......>\n");
+		" <Registration/ServerURI..............................>  <Auth....................>  <Status.......>\n");
 
 	return 0;
 }
@@ -2023,11 +2026,13 @@
 	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 expsecs;
 #define REGISTRATION_URI_FIELD_LEN	53
 
 	ast_assert(context->output_buffer != NULL);
+	expsecs = state ? state->client_state->registration_expires - ((int) time(NULL)) : 0;
 
-	ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s  %-16s  %-16s\n",
+	ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s  %-26s  %-16s %s%d%s\n",
 		id,
 		(int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
 		(int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
@@ -2035,7 +2040,8 @@
 		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"));
+		(state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered"),
+		state ? " (exp. " : "", abs(expsecs), state ? (expsecs < 0 ? "s ago)" : "s)") : "");
 	ao2_cleanup(state);
 
 	if (context->show_details

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ic4fea15a1a1056c424416def49d1ca8e776c0483
Gerrit-Change-Number: 18517
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220511/96b790b7/attachment-0001.html>


More information about the asterisk-code-review mailing list