<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15134">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_outbound_registration.c: Use our own scheduler and other stuff<br><br>* Instead of using the pjproject timer heap, we now use our own<br> pjsip_scheduler. This allows us to more easily debug and allows us to<br> see times in "pjsip show/list registrations" as well as being able to<br> see the registrations in "pjsip show scheduled_tasks".<br><br>* Added the last registration time, registration interval, and the next<br> registration time to the CLI output.<br><br>* Added log messages where needed.<br><br>Change-Id: I4534a0fc78c7cb69f23b7b449dda9748c90daca2<br>---<br>M res/res_pjsip_outbound_registration.c<br>1 file changed, 107 insertions(+), 61 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/34/15134/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c</span><br><span>index 2c58986..240b006 100644</span><br><span>--- a/res/res_pjsip_outbound_registration.c</span><br><span>+++ b/res/res_pjsip_outbound_registration.c</span><br><span>@@ -359,7 +359,7 @@</span><br><span> */</span><br><span> pjsip_tx_data *last_tdata;</span><br><span> /*! \brief Timer entry for retrying on temporal responses */</span><br><span style="color: hsl(0, 100%, 40%);">- pj_timer_entry timer;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_sched_task *sched_task;</span><br><span> /*! \brief Optional line parameter placed into Contact */</span><br><span> char line[LINE_PARAMETER_SIZE];</span><br><span> /*! \brief Current number of retries */</span><br><span>@@ -543,10 +543,10 @@</span><br><span> /*! \brief Helper function which cancels the timer on a client */</span><br><span> static void cancel_registration(struct sip_outbound_registration_client_state *client_state)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),</span><br><span style="color: hsl(0, 100%, 40%);">- &client_state->timer, client_state->timer.id)) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* The timer was successfully cancelled, drop the refcount of client_state */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(client_state, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (client_state->sched_task) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_sched_task_cancel(client_state->sched_task);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(client_state->sched_task);</span><br><span style="color: hsl(120, 100%, 40%);">+ client_state->sched_task = NULL;</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>@@ -560,10 +560,16 @@</span><br><span> pj_status_t status;</span><br><span> int *callback_invoked;</span><br><span> pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_info info;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_get_info(client_state->client, &info);</span><br><span> </span><br><span> callback_invoked = ast_threadstorage_get(®ister_callback_invoked, sizeof(int));</span><br><span> if (!callback_invoked) {</span><br><span> pjsip_tx_data_dec_ref(tdata);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to get threadstorage for registration to server '%.*s' from client '%.*s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.client_uri.slen, info.client_uri.ptr);</span><br><span> return PJ_ENOMEM;</span><br><span> }</span><br><span> *callback_invoked = 0;</span><br><span>@@ -593,6 +599,9 @@</span><br><span> * drop the references we just added</span><br><span> */</span><br><span> if ((status != PJ_SUCCESS) && !(*callback_invoked)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed send registration to server '%.*s' from client '%.*s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.client_uri.slen, info.client_uri.ptr);</span><br><span> pjsip_tx_data_dec_ref(tdata);</span><br><span> ao2_ref(client_state, -1);</span><br><span> return status;</span><br><span>@@ -655,23 +664,31 @@</span><br><span> /*! \brief Callback function for registering */</span><br><span> static int handle_client_registration(void *data)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct sip_outbound_registration_client_state *, client_state, data, ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sip_outbound_registration_client_state *client_state = data;</span><br><span> pjsip_tx_data *tdata;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_info info;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (client_state->status == SIP_REGISTRATION_STOPPED) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (set_outbound_initial_authentication_credentials(client_state->client, &client_state->outbound_auths)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Failed to set initial authentication credentials\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to set auth credentials on registration to server '%.*s' from client '%.*s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.client_uri.slen, info.client_uri.ptr);</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (client_state->status == SIP_REGISTRATION_STOPPED</span><br><span style="color: hsl(0, 100%, 40%);">- || pjsip_regc_register(client_state->client, PJ_FALSE, &tdata) != PJ_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_get_info(client_state->client, &info);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pjsip_regc_register(client_state->client, PJ_FALSE, &tdata) != PJ_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to create registration to server '%.*s' from client '%.*s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.client_uri.slen, info.client_uri.ptr);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span> if (DEBUG_ATLEAST(1)) {</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_regc_info info;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_regc_get_info(client_state->client, &info);</span><br><span> ast_log(LOG_DEBUG, "Outbound REGISTER attempt %u to '%.*s' with client '%.*s'\n",</span><br><span> client_state->retries + 1,</span><br><span> (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span>@@ -679,7 +696,9 @@</span><br><span> }</span><br><span> </span><br><span> if (!add_configured_supported_headers(client_state, tdata)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Failed to set supported headers\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to add SUPPORTED header to registration to server '%.*s' from client '%.*s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.client_uri.slen, info.client_uri.ptr);</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span>@@ -688,44 +707,28 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief Timer callback function, used just for registrations */</span><br><span style="color: hsl(0, 100%, 40%);">-static void sip_outbound_registration_timer_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- struct sip_outbound_registration_client_state *client_state = entry->user_data;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- entry->id = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /*</span><br><span style="color: hsl(0, 100%, 40%);">- * Transfer client_state reference to serializer task so the</span><br><span style="color: hsl(0, 100%, 40%);">- * nominal path will not dec the client_state ref in this</span><br><span style="color: hsl(0, 100%, 40%);">- * pjproject callback thread.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_sip_push_task(client_state->serializer, handle_client_registration, client_state)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Scheduled outbound registration could not be executed.\n");</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(client_state, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*! \brief Helper function which sets up the timer to re-register in a specific amount of time */</span><br><span style="color: hsl(0, 100%, 40%);">-static void schedule_registration(struct sip_outbound_registration_client_state *client_state, unsigned int seconds)</span><br><span style="color: hsl(120, 100%, 40%);">+static void schedule_registration(struct sip_outbound_registration_client_state *client_state, unsigned int ms)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- pj_time_val delay = { .sec = seconds, };</span><br><span> pjsip_regc_info info;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_get_info(client_state->client, &info);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Scheduling outbound registration to server '%.*s' from client '%.*s' in %d ms\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) info.client_uri.slen, info.client_uri.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ ms);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> cancel_registration(client_state);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_regc_get_info(client_state->client, &info);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(1, "Scheduling outbound registration to server '%.*s' from client '%.*s' in %d seconds\n",</span><br><span style="color: hsl(0, 100%, 40%);">- (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span style="color: hsl(0, 100%, 40%);">- (int) info.client_uri.slen, info.client_uri.ptr,</span><br><span style="color: hsl(0, 100%, 40%);">- seconds);</span><br><span style="color: hsl(120, 100%, 40%);">+ client_state->sched_task = ast_sip_schedule_task(client_state->serializer,</span><br><span style="color: hsl(120, 100%, 40%);">+ ms, handle_client_registration, ast_taskprocessor_name(client_state->serializer),</span><br><span style="color: hsl(120, 100%, 40%);">+ client_state,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_SCHED_TASK_ONESHOT | AST_SIP_SCHED_TASK_DATA_AO2);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(client_state, +1);</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(), &client_state->timer, &delay) != PJ_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!client_state->sched_task) {</span><br><span> ast_log(LOG_WARNING, "Failed to schedule registration to server '%.*s' from client '%.*s'\n",</span><br><span> (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span> (int) info.client_uri.slen, info.client_uri.ptr);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(client_state, -1);</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>@@ -762,8 +765,6 @@</span><br><span> {</span><br><span> struct sip_outbound_registration_client_state *client_state = data;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- cancel_registration(client_state);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (client_state->client) {</span><br><span> pjsip_regc_info info;</span><br><span> pjsip_tx_data *tdata;</span><br><span>@@ -789,7 +790,7 @@</span><br><span> "Trying to unregister with server '%.*s' from client '%.*s' before destruction.\n",</span><br><span> (int) info.server_uri.slen, info.server_uri.ptr,</span><br><span> (int) info.client_uri.slen, info.client_uri.ptr);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ cancel_registration(client_state);</span><br><span> update_client_state_status(client_state, SIP_REGISTRATION_STOPPING);</span><br><span> client_state->destroy = 1;</span><br><span> if (pjsip_regc_unregister(client_state->client, &tdata) == PJ_SUCCESS</span><br><span>@@ -800,8 +801,10 @@</span><br><span> }</span><br><span> break;</span><br><span> case SIP_REGISTRATION_REJECTED_TEMPORARY:</span><br><span style="color: hsl(0, 100%, 40%);">- case SIP_REGISTRATION_REJECTED_PERMANENT:</span><br><span> case SIP_REGISTRATION_STOPPING:</span><br><span style="color: hsl(120, 100%, 40%);">+ cancel_registration(client_state);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case SIP_REGISTRATION_REJECTED_PERMANENT:</span><br><span> case SIP_REGISTRATION_STOPPED:</span><br><span> break;</span><br><span> }</span><br><span>@@ -812,6 +815,7 @@</span><br><span> </span><br><span> update_client_state_status(client_state, SIP_REGISTRATION_STOPPED);</span><br><span> ast_sip_auth_vector_destroy(&client_state->outbound_auths);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_ref(client_state, -1);</span><br><span> </span><br><span> return 0;</span><br><span>@@ -873,7 +877,7 @@</span><br><span> const char *server_uri, const char *client_uri)</span><br><span> {</span><br><span> update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_TEMPORARY);</span><br><span style="color: hsl(0, 100%, 40%);">- schedule_registration(response->client_state, interval);</span><br><span style="color: hsl(120, 100%, 40%);">+ schedule_registration(response->client_state, interval * 1000);</span><br><span> </span><br><span> if (response->rdata) {</span><br><span> ast_log(LOG_WARNING, "Temporal response '%d' received from '%s' on "</span><br><span>@@ -1058,8 +1062,8 @@</span><br><span> ast_copy_pj_str(server_uri, &info.server_uri, sizeof(server_uri));</span><br><span> ast_copy_pj_str(client_uri, &info.client_uri, sizeof(client_uri));</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(1, "Processing REGISTER response %d from server '%s' for client '%s'\n",</span><br><span style="color: hsl(0, 100%, 40%);">- response->code, server_uri, client_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Processing REGISTER response %d from server '%s' for client '%s' with expiration '%d'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ response->code, server_uri, client_uri, response->expiration);</span><br><span> </span><br><span> if (response->code == 408 || response->code == 503) {</span><br><span> if ((ast_sip_failover_request(response->old_request))) {</span><br><span>@@ -1113,10 +1117,10 @@</span><br><span> ast_debug(1, "Outbound registration to '%s' with client '%s' successful\n", server_uri, client_uri);</span><br><span> update_client_state_status(response->client_state, SIP_REGISTRATION_REGISTERED);</span><br><span> response->client_state->retries = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- next_registration_round = response->expiration - REREGISTER_BUFFER_TIME;</span><br><span style="color: hsl(120, 100%, 40%);">+ next_registration_round = (response->expiration - REREGISTER_BUFFER_TIME) * 1000;</span><br><span> if (next_registration_round < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Re-register immediately. */</span><br><span style="color: hsl(0, 100%, 40%);">- next_registration_round = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Re-register no sooner than the buffer time. */</span><br><span style="color: hsl(120, 100%, 40%);">+ next_registration_round = REREGISTER_BUFFER_TIME * 1000;</span><br><span> }</span><br><span> schedule_registration(response->client_state, next_registration_round);</span><br><span> </span><br><span>@@ -1156,7 +1160,7 @@</span><br><span> /* A forbidden response retry interval is configured and there are retries remaining */</span><br><span> update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_TEMPORARY);</span><br><span> response->client_state->retries++;</span><br><span style="color: hsl(0, 100%, 40%);">- schedule_registration(response->client_state, response->client_state->forbidden_retry_interval);</span><br><span style="color: hsl(120, 100%, 40%);">+ schedule_registration(response->client_state, response->client_state->forbidden_retry_interval * 1000);</span><br><span> ast_log(LOG_WARNING, "403 Forbidden fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",</span><br><span> server_uri, client_uri, response->client_state->forbidden_retry_interval);</span><br><span> } else if (response->client_state->fatal_retry_interval</span><br><span>@@ -1164,7 +1168,7 @@</span><br><span> /* Some kind of fatal failure response received, so retry according to configured interval */</span><br><span> update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_TEMPORARY);</span><br><span> response->client_state->retries++;</span><br><span style="color: hsl(0, 100%, 40%);">- schedule_registration(response->client_state, response->client_state->fatal_retry_interval);</span><br><span style="color: hsl(120, 100%, 40%);">+ schedule_registration(response->client_state, response->client_state->fatal_retry_interval * 1000);</span><br><span> ast_log(LOG_WARNING, "'%d' fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",</span><br><span> response->code, server_uri, client_uri, response->client_state->fatal_retry_interval);</span><br><span> } else {</span><br><span>@@ -1220,8 +1224,8 @@</span><br><span> */</span><br><span> response->client_state = client_state;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(1, "Received REGISTER response %d(%.*s)\n",</span><br><span style="color: hsl(0, 100%, 40%);">- param->code, (int) param->reason.slen, param->reason.ptr);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Received REGISTER response %d(%.*s) Expires: %d\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ param->code, (int) param->reason.slen, param->reason.ptr, param->expiration);</span><br><span> </span><br><span> if (param->rdata) {</span><br><span> struct pjsip_retry_after_hdr *retry_after;</span><br><span>@@ -1317,8 +1321,6 @@</span><br><span> }</span><br><span> </span><br><span> state->client_state->status = SIP_REGISTRATION_UNREGISTERED;</span><br><span style="color: hsl(0, 100%, 40%);">- pj_timer_entry_init(&state->client_state->timer, 0, state->client_state,</span><br><span style="color: hsl(0, 100%, 40%);">- sip_outbound_registration_timer_cb);</span><br><span> state->client_state->transport_name = ast_strdup(registration->transport);</span><br><span> state->client_state->registration_name =</span><br><span> ast_strdup(ast_sorcery_object_get_id(registration));</span><br><span>@@ -1698,8 +1700,14 @@</span><br><span> {</span><br><span> struct sip_outbound_registration_state *state = data;</span><br><span> struct sip_outbound_registration *registration = ao2_bump(state->registration);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_info info;</span><br><span> size_t i;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_get_info(state->client_state->client, &info);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Performing register to server '%s' from client '%s' Expiration: %d\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ state->registration->server_uri, state->registration->client_uri, registration->expiration);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Just in case the client state is being reused for this registration, free the auth information */</span><br><span> ast_sip_auth_vector_destroy(&state->client_state->outbound_auths);</span><br><span> </span><br><span>@@ -1722,7 +1730,7 @@</span><br><span> </span><br><span> pjsip_regc_update_expires(state->client_state->client, registration->expiration);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- schedule_registration(state->client_state, (ast_random() % 10) + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ schedule_registration(state->client_state, ((ast_random() % 10) + 1) * 1000);</span><br><span> </span><br><span> ao2_ref(registration, -1);</span><br><span> ao2_ref(state, -1);</span><br><span>@@ -1881,7 +1889,14 @@</span><br><span> </span><br><span> static int queue_register(struct sip_outbound_registration_state *state)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_info info;</span><br><span> ao2_ref(state, +1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_regc_get_info(state->client_state->client, &info);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Queueing register to server '%s' from client '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ state->registration->server_uri, state->registration->client_uri);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (ast_sip_push_task(state->client_state->serializer, sip_outbound_registration_perform, state)) {</span><br><span> ao2_ref(state, -1);</span><br><span> return -1;</span><br><span>@@ -2252,22 +2267,46 @@</span><br><span> ast_assert(context->output_buffer != NULL);</span><br><span> </span><br><span> ast_str_append(&context->output_buffer, 0,</span><br><span style="color: hsl(0, 100%, 40%);">- " <Registration/ServerURI..............................> <Auth..........> <Status.......>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ " <Registration/ServerURI..............................> <Auth..........> <Status.......>");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&context->output_buffer, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ " <Last Reg..> <Intvl> <Next Start.....secs>\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ "==============================================");</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define TIME_FORMAT "%a %T"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int cli_print_body(void *obj, void *arg, int flags)</span><br><span> {</span><br><span> struct sip_outbound_registration *registration = obj;</span><br><span> struct ast_sip_cli_context *context = arg;</span><br><span> const char *id = ast_sorcery_object_get_id(registration);</span><br><span> struct sip_outbound_registration_state *state = get_state(id);</span><br><span style="color: hsl(120, 100%, 40%);">+ int next_run_ms = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval next = { 0, 0 };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval last = { 0, 0 };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_tm tm;</span><br><span style="color: hsl(120, 100%, 40%);">+ char next_start[32] = "";</span><br><span style="color: hsl(120, 100%, 40%);">+ char last_start[32] = "";</span><br><span style="color: hsl(120, 100%, 40%);">+ int interval;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #define REGISTRATION_URI_FIELD_LEN 53</span><br><span> </span><br><span> ast_assert(context->output_buffer != NULL);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s %-16s %-16s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ if (state->client_state->sched_task) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_sched_task_get_times2(state->client_state->sched_task, &last, NULL, NULL, &interval,</span><br><span style="color: hsl(120, 100%, 40%);">+ &next_run_ms, &next);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_localtime(&last, &tm, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_strftime(last_start, sizeof(last_start), TIME_FORMAT, &tm);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_localtime(&next, &tm, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_strftime(next_start, sizeof(next_start), TIME_FORMAT, &tm);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s %-16s %-16s",</span><br><span> id,</span><br><span> (int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),</span><br><span> (int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),</span><br><span>@@ -2275,9 +2314,15 @@</span><br><span> AST_VECTOR_SIZE(®istration->outbound_auths)</span><br><span> ? AST_VECTOR_GET(®istration->outbound_auths, 0)</span><br><span> : "n/a",</span><br><span style="color: hsl(0, 100%, 40%);">- (state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered"));</span><br><span style="color: hsl(120, 100%, 40%);">+ (state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered")</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&context->output_buffer, 0, " %-12s %7d %-12s %8d\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ last_start, interval / 1000, next_start, next_run_ms / 1000);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_cleanup(state);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (context->show_details</span><br><span> || (context->show_details_only_level_0 && context->indent_level == 0)) {</span><br><span> ast_str_append(&context->output_buffer, 0, "\n");</span><br><span>@@ -2467,6 +2512,7 @@</span><br><span> ast_sorcery_instance_observer_remove(ast_sip_get_sorcery(), &observer_callbacks_registrations);</span><br><span> </span><br><span> ast_sorcery_object_unregister(ast_sip_get_sorcery(), "registration");</span><br><span style="color: hsl(120, 100%, 40%);">+ unregister_all();</span><br><span> </span><br><span> ao2_global_obj_release(current_states);</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15134">change 15134</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15134"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I4534a0fc78c7cb69f23b7b449dda9748c90daca2 </div>
<div style="display:none"> Gerrit-Change-Number: 15134 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>