Skip to content

Commit 604785f

Browse files
InterLinked1jcolp
authored andcommitted
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
1 parent 432a1d2 commit 604785f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

res/res_pjsip_outbound_registration.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ struct sip_outbound_registration_client_state {
392392
char *transport_name;
393393
/*! \brief The name of the registration sorcery object */
394394
char *registration_name;
395+
/*! \brief Expected time of registration lapse/expiration */
396+
unsigned int registration_expires;
395397
};
396398

397399
/*! \brief Outbound registration state information (persists for lifetime that registration should exist) */
@@ -738,6 +740,7 @@ static void schedule_registration(struct sip_outbound_registration_client_state
738740
(int) info.client_uri.slen, info.client_uri.ptr);
739741
ao2_ref(client_state, -1);
740742
}
743+
client_state->registration_expires = ((int) time(NULL)) + seconds;
741744
}
742745

743746
static void update_client_state_status(struct sip_outbound_registration_client_state *client_state, enum sip_outbound_registration_status status)
@@ -2261,7 +2264,7 @@ static int cli_print_header(void *obj, void *arg, int flags)
22612264
ast_assert(context->output_buffer != NULL);
22622265

22632266
ast_str_append(&context->output_buffer, 0,
2264-
" <Registration/ServerURI..............................> <Auth..........> <Status.......>\n");
2267+
" <Registration/ServerURI..............................> <Auth....................> <Status.......>\n");
22652268

22662269
return 0;
22672270
}
@@ -2272,19 +2275,22 @@ static int cli_print_body(void *obj, void *arg, int flags)
22722275
struct ast_sip_cli_context *context = arg;
22732276
const char *id = ast_sorcery_object_get_id(registration);
22742277
struct sip_outbound_registration_state *state = get_state(id);
2278+
int expsecs;
22752279
#define REGISTRATION_URI_FIELD_LEN 53
22762280

22772281
ast_assert(context->output_buffer != NULL);
2282+
expsecs = state ? state->client_state->registration_expires - ((int) time(NULL)) : 0;
22782283

2279-
ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s %-16s %-16s\n",
2284+
ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s %-26s %-16s %s%d%s\n",
22802285
id,
22812286
(int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
22822287
(int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
22832288
registration->server_uri,
22842289
AST_VECTOR_SIZE(&registration->outbound_auths)
22852290
? AST_VECTOR_GET(&registration->outbound_auths, 0)
22862291
: "n/a",
2287-
(state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered"));
2292+
(state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered"),
2293+
state ? " (exp. " : "", abs(expsecs), state ? (expsecs < 0 ? "s ago)" : "s)") : "");
22882294
ao2_cleanup(state);
22892295

22902296
if (context->show_details

0 commit comments

Comments
 (0)