diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c index 2cd0fcf3021c73ca8c4e4b5b71de7fa3fcc95bfc..e3cf32db10d35aee0fde9c640ff9df5b595db838 100644 --- a/res/res_pjsip_outbound_registration.c +++ b/res/res_pjsip_outbound_registration.c @@ -926,6 +926,39 @@ static int sip_outbound_registration_is_temporal(unsigned int code, } } +static int sip_outbound_registration_send_ubus_event(char *ev_name,int time ,char *client) +{ + struct blob_buf blob; + int res = 0; + struct ubus_context *ubusContext = NULL; + + ubusContext = ubus_connect(NULL); + if(!ubusContext){ + ast_log(LOG_ERROR, "Failed to connect to ubus."); + return -1; + } + + memset(&blob, 0, sizeof(blob)); + if(blob_buf_init(&blob, 0)) { + ubus_free(ubusContext); + return -1; + } + + blobmsg_add_string(&blob, "status", ev_name); + blobmsg_add_string(&blob, "uri", client); + blobmsg_add_u32(&blob, "expiration", time); + + if(ubus_send_event(ubusContext, broadcast_path, blob.head) != UBUS_STATUS_OK) { + ast_log(LOG_NOTICE,"Error sending ubus message %s\n", ev_name); + res = -1; + } + + ubus_free(ubusContext); + blob_buf_free(&blob); + + return res; +} + static void schedule_retry(struct registration_response *response, unsigned int interval, const char *server_uri, const char *client_uri) { @@ -941,6 +974,7 @@ static void schedule_retry(struct registration_response *response, unsigned int "registration attempt to '%s', retrying in '%u'\n", server_uri, client_uri, interval); } + sip_outbound_registration_send_ubus_event("UNREGISTERED",response->expiration,client_uri); } static int reregister_immediately_cb(void *obj) @@ -1107,40 +1141,6 @@ static void clear_endpoint_security_mechanisms(struct ast_sip_endpoint *endpoint } } -static int sip_outbound_registration_send_ubus_event(char *ev_name,int time ,char *client) -{ - struct blob_buf blob; - int res = 0; - struct ubus_context *ubusContext = NULL; - - ubusContext = ubus_connect(NULL); - if(!ubusContext){ - ast_log(LOG_ERROR, "Failed to connect to ubus."); - return -1; - } - - memset(&blob, 0, sizeof(blob)); - if(blob_buf_init(&blob, 0)) { - ubus_free(ubusContext); - return -1; - } - - blobmsg_add_string(&blob, "status", ev_name); - blobmsg_add_string(&blob, "uri", client); - blobmsg_add_u32(&blob, "expiration", time); - - if(ubus_send_event(ubusContext, broadcast_path, blob.head) != UBUS_STATUS_OK) { - ast_log(LOG_NOTICE,"Error sending ubus message %s\n", ev_name); - res = -1; - } - - ubus_free(ubusContext); - blob_buf_free(&blob); - - return res; -} - - /*! \brief Callback function for handling a response to a registration attempt */ static int handle_registration_response(void *data) { @@ -1296,6 +1296,7 @@ static int handle_registration_response(void *data) server_uri, client_uri); /* 494 loop detected! This is fatal! */ update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_PERMANENT); + sip_outbound_registration_send_ubus_event("UNREGISTERED",response->expiration,client_uri); /* reset is494 */ response->client_state->is494=0; } else { @@ -1314,6 +1315,7 @@ static int handle_registration_response(void *data) 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); + sip_outbound_registration_send_ubus_event("UNREGISTERED",response->expiration,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 { @@ -1327,6 +1329,7 @@ static int handle_registration_response(void *data) && response->client_state->retries < response->client_state->max_retries) { /* A forbidden response retry interval is configured and there are retries remaining */ update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_TEMPORARY); + sip_outbound_registration_send_ubus_event("UNREGISTERED",response->expiration,client_uri); response->client_state->retries++; 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", @@ -1335,6 +1338,7 @@ static int handle_registration_response(void *data) && 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); + sip_outbound_registration_send_ubus_event("UNREGISTERED",response->expiration,client_uri); response->client_state->retries++; 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", @@ -1342,6 +1346,7 @@ static int handle_registration_response(void *data) } else { /* Finally if there's no hope of registering give up */ update_client_state_status(response->client_state, SIP_REGISTRATION_REJECTED_PERMANENT); + sip_outbound_registration_send_ubus_event("UNREGISTERED",response->expiration,client_uri); if (response->rdata) { 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);