[asterisk-commits] res pjsip outbound registration.c: Misc code cleanups. (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 24 08:37:45 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: res_pjsip_outbound_registration.c: Misc code cleanups.
......................................................................


res_pjsip_outbound_registration.c: Misc code cleanups.

* Break some long lines.

* Fix doxygen comment.

Change-Id: I8f12ba6822f84d5e7bb575280270cd7e2fefb305
---
M res/res_pjsip_outbound_registration.c
1 file changed, 50 insertions(+), 34 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Matt Jordan: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index c910c94..d06948c 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -403,9 +403,9 @@
 	RAII_VAR(struct sip_outbound_registration_state *, state, NULL, ao2_cleanup);
 
 	if (!(line = get_uri_option_line(rdata->msg_info.to->uri))
-	    && !(line = get_uri_option_line(rdata->msg_info.msg->line.req.uri))) {
+		&& !(line = get_uri_option_line(rdata->msg_info.msg->line.req.uri))) {
 		return NULL;
-        }
+	}
 
 	states = ao2_global_obj_ref(current_states);
 	if (!states) {
@@ -471,10 +471,11 @@
 	RAII_VAR(struct sip_outbound_registration_client_state *, client_state, data, ao2_cleanup);
 	pjsip_tx_data *tdata;
 	pjsip_regc_info info;
-	char server_uri[PJSIP_MAX_URL_SIZE], client_uri[PJSIP_MAX_URL_SIZE];
+	char server_uri[PJSIP_MAX_URL_SIZE];
+	char client_uri[PJSIP_MAX_URL_SIZE];
 
-	if ((client_state->status == SIP_REGISTRATION_STOPPED) ||
-		(pjsip_regc_register(client_state->client, PJ_FALSE, &tdata) != PJ_SUCCESS)) {
+	if (client_state->status == SIP_REGISTRATION_STOPPED
+		|| pjsip_regc_register(client_state->client, PJ_FALSE, &tdata) != PJ_SUCCESS) {
 		return 0;
 	}
 
@@ -571,7 +572,8 @@
 			return 0;
 		}
 
-		if (client_state->status != SIP_REGISTRATION_UNREGISTERED && client_state->status != SIP_REGISTRATION_REJECTED_PERMANENT) {
+		if (client_state->status != SIP_REGISTRATION_UNREGISTERED
+			&& client_state->status != SIP_REGISTRATION_REJECTED_PERMANENT) {
 			pjsip_tx_data *tdata;
 
 			if (pjsip_regc_unregister(client_state->client, &tdata) == PJ_SUCCESS) {
@@ -620,7 +622,7 @@
 	ao2_cleanup(response->client_state);
 }
 
-/* \brief Helper funtion which determines if a response code is temporal or not */
+/*! \brief Helper function which determines if a response code is temporal or not */
 static int sip_outbound_registration_is_temporal(unsigned int code,
 		struct sip_outbound_registration_client_state *client_state)
 {
@@ -662,7 +664,8 @@
 {
 	RAII_VAR(struct registration_response *, response, data, ao2_cleanup);
 	pjsip_regc_info info;
-	char server_uri[PJSIP_MAX_URL_SIZE], client_uri[PJSIP_MAX_URL_SIZE];
+	char server_uri[PJSIP_MAX_URL_SIZE];
+	char client_uri[PJSIP_MAX_URL_SIZE];
 
 	pjsip_regc_get_info(response->client_state->client, &info);
 	ast_copy_pj_str(server_uri, &info.server_uri, sizeof(server_uri));
@@ -713,7 +716,8 @@
 	} 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, server_uri, client_uri);
-	} else if (response->client_state->retry_interval && sip_outbound_registration_is_temporal(response->code, response->client_state)) {
+	} 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 */
 			response->client_state->status = SIP_REGISTRATION_REJECTED_PERMANENT;
@@ -746,7 +750,8 @@
 		}
 	}
 
-	ast_system_publish_registry("PJSIP", client_uri, server_uri, sip_outbound_registration_status_str[response->client_state->status], NULL);
+	ast_system_publish_registry("PJSIP", client_uri, server_uri,
+		sip_outbound_registration_status_str[response->client_state->status], NULL);
 
 	/* If deferred destruction is in use see if we need to destroy now */
 	if (response->client_state->destroy) {
@@ -787,9 +792,11 @@
 			(int) info.client_uri.slen, info.client_uri.ptr);
 
 	if (param->rdata) {
-		struct pjsip_retry_after_hdr *retry_after = pjsip_msg_find_hdr(param->rdata->msg_info.msg, PJSIP_H_RETRY_AFTER, NULL);
+		struct pjsip_retry_after_hdr *retry_after;
 		pjsip_transaction *tsx;
 
+		retry_after = pjsip_msg_find_hdr(param->rdata->msg_info.msg, PJSIP_H_RETRY_AFTER,
+			NULL);
 		response->retry_after = retry_after ? retry_after->ivalue : 0;
 		tsx = pjsip_rdata_get_tsx(param->rdata);
 		response->old_request = tsx->last_tx;
@@ -874,7 +881,10 @@
 /*! \brief Allocator function for registration information */
 static void *sip_outbound_registration_alloc(const char *name)
 {
-	struct sip_outbound_registration *registration = ast_sorcery_generic_alloc(sizeof(*registration), sip_outbound_registration_destroy);
+	struct sip_outbound_registration *registration;
+
+	registration = ast_sorcery_generic_alloc(sizeof(*registration),
+		sip_outbound_registration_destroy);
 	if (!registration || ast_string_field_init(registration, 256)) {
 		ao2_cleanup(registration);
 		return NULL;
@@ -884,8 +894,8 @@
 }
 
 /*! \brief Helper function which populates a pj_str_t with a contact header */
-static int sip_dialog_create_contact(pj_pool_t *pool, pj_str_t *contact, const char *user, const pj_str_t *target, pjsip_tpselector *selector,
-	const char *line)
+static int sip_dialog_create_contact(pj_pool_t *pool, pj_str_t *contact, const char *user,
+	const pj_str_t *target, pjsip_tpselector *selector, const char *line)
 {
 	pj_str_t tmp, local_addr;
 	pjsip_uri *uri;
@@ -918,8 +928,8 @@
 		type = (pjsip_transport_type_e)(((int)type) + PJSIP_TRANSPORT_IPV6);
 	}
 
-	if (pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), pool, type, selector,
-							      &local_addr, &local_port) != PJ_SUCCESS) {
+	if (pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()),
+		pool, type, selector, &local_addr, &local_port) != PJ_SUCCESS) {
 		return -1;
 	}
 
@@ -929,18 +939,18 @@
 
 	contact->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
 	contact->slen = pj_ansi_snprintf(contact->ptr, PJSIP_MAX_URL_SIZE,
-				      "<%s:%s@%s%.*s%s:%d%s%s%s%s>",
-				      (pjsip_transport_get_flag_from_type(type) & PJSIP_TRANSPORT_SECURE) ? "sips" : "sip",
-				      user,
-				      (type & PJSIP_TRANSPORT_IPV6) ? "[" : "",
-				      (int)local_addr.slen,
-				      local_addr.ptr,
-				      (type & PJSIP_TRANSPORT_IPV6) ? "]" : "",
-				      local_port,
-				      (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
-				      (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "",
-				      !ast_strlen_zero(line) ? ";line=" : "",
-				      S_OR(line, ""));
+		"<%s:%s@%s%.*s%s:%d%s%s%s%s>",
+		(pjsip_transport_get_flag_from_type(type) & PJSIP_TRANSPORT_SECURE) ? "sips" : "sip",
+		user,
+		(type & PJSIP_TRANSPORT_IPV6) ? "[" : "",
+		(int)local_addr.slen,
+		local_addr.ptr,
+		(type & PJSIP_TRANSPORT_IPV6) ? "]" : "",
+		local_port,
+		(type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
+		(type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "",
+		!ast_strlen_zero(line) ? ";line=" : "",
+		S_OR(line, ""));
 
 	return 0;
 }
@@ -1053,8 +1063,11 @@
 
 		pj_list_init(&route_set);
 
-		pj_strdup2_with_null(pjsip_regc_get_pool(state->client_state->client), &tmp, registration->outbound_proxy);
-		if (!(route = pjsip_parse_hdr(pjsip_regc_get_pool(state->client_state->client), &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL))) {
+		pj_strdup2_with_null(pjsip_regc_get_pool(state->client_state->client), &tmp,
+			registration->outbound_proxy);
+		route = pjsip_parse_hdr(pjsip_regc_get_pool(state->client_state->client),
+			&ROUTE_HNAME, tmp.ptr, tmp.slen, NULL);
+		if (!route) {
 			return -1;
 		}
 		pj_list_insert_nodes_before(&route_set, route);
@@ -1069,13 +1082,15 @@
 	pj_cstr(&server_uri, 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,
+	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;
 	}
 
 	pj_cstr(&client_uri, registration->client_uri);
-	if (pjsip_regc_init(state->client_state->client, &server_uri, &client_uri, &client_uri, 1, &contact_uri, registration->expiration) != PJ_SUCCESS) {
+	if (pjsip_regc_init(state->client_state->client, &server_uri, &client_uri,
+		&client_uri, 1, &contact_uri, registration->expiration) != PJ_SUCCESS) {
 		return -1;
 	}
 
@@ -1798,8 +1813,9 @@
 	ast_sip_register_cli_formatter(cli_formatter);
 	ast_cli_register_multiple(cli_outbound_registration, ARRAY_LEN(cli_outbound_registration));
 
-	if (!(new_states = ao2_container_alloc(
-		      DEFAULT_STATE_BUCKETS, registration_state_hash, registration_state_cmp))) {
+	new_states = ao2_container_alloc(DEFAULT_STATE_BUCKETS,
+		registration_state_hash, registration_state_cmp);
+	if (!new_states) {
 		ast_log(LOG_ERROR, "Unable to allocate registration states container\n");
 		unload_module();
 		return AST_MODULE_LOAD_FAILURE;

-- 
To view, visit https://gerrit.asterisk.org/683
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8f12ba6822f84d5e7bb575280270cd7e2fefb305
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-commits mailing list