[Asterisk-code-review] chan pjsip.c: Improve ast request() diagnostic msgs. (asterisk[15])

Richard Mudgett asteriskteam at digium.com
Fri Dec 15 19:59:38 CST 2017


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/7613


Change subject: chan_pjsip.c: Improve ast_request() diagnostic msgs.
......................................................................

chan_pjsip.c: Improve ast_request() diagnostic msgs.

Attempting to dial PJSIP/endpoint when the endpoint doesn't exist and
disable_multi_domain=no results in a misleading empty endpoint name
message.  The message should say the endpoint was not found.

* Added missing endpoint not found message.

* Added more information to the empty endpoint name msgs if available.

* Eliminated RAII_VAR in request().

Change-Id: I21da85ebd62dcc32115b2ffcb5157416ebae51e4
---
M channels/chan_pjsip.c
1 file changed, 36 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/13/7613/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 69bcc18..10f45a4 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -2381,7 +2381,7 @@
 	struct request_data *req_data = obj;
 	struct ast_sip_session *session = NULL;
 	char *tmp = ast_strdupa(req_data->dest), *endpoint_name = NULL, *request_user = NULL;
-	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+	struct ast_sip_endpoint *endpoint;
 
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(endpoint);
@@ -2406,10 +2406,18 @@
 		}
 
 		if (ast_strlen_zero(endpoint_name)) {
-			ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
+			if (request_user) {
+				ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name: %s@<endpoint-name>\n",
+					request_user);
+			} else {
+				ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
+			}
 			req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
 			return -1;
-		} else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+		}
+		endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+			endpoint_name);
+		if (!endpoint) {
 			ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n", endpoint_name);
 			req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
 			return -1;
@@ -2421,23 +2429,38 @@
 			ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
 			req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
 			return -1;
-		} else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+		}
+		endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+			endpoint_name);
+		if (!endpoint) {
 			/* It seems it's not a multi-domain endpoint or single endpoint exact match,
 			 * it's possible that it's a SIP trunk with a specified user (user at trunkname),
 			 * so extract the user before @ sign.
 			 */
-			if ((endpoint_name = strchr(args.endpoint, '@'))) {
-				request_user = args.endpoint;
-				*endpoint_name++ = '\0';
+			endpoint_name = strchr(args.endpoint, '@');
+			if (!endpoint_name) {
+				/*
+				 * Couldn't find an '@' so it had to be an endpoint
+				 * name that doesn't exist.
+				 */
+				ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n",
+					args.endpoint);
+				req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
+				return -1;
 			}
+			request_user = args.endpoint;
+			*endpoint_name++ = '\0';
 
 			if (ast_strlen_zero(endpoint_name)) {
-				ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
+				ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name: %s@<endpoint-name>\n",
+					request_user);
 				req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
 				return -1;
 			}
 
-			if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+			endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+				endpoint_name);
+			if (!endpoint) {
 				ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n", endpoint_name);
 				req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
 				return -1;
@@ -2445,7 +2468,10 @@
 		}
 	}
 
-	if (!(session = ast_sip_session_create_outgoing(endpoint, NULL, args.aor, request_user, req_data->topology))) {
+	session = ast_sip_session_create_outgoing(endpoint, NULL, args.aor, request_user,
+		req_data->topology);
+	ao2_ref(endpoint, -1);
+	if (!session) {
 		ast_log(LOG_ERROR, "Failed to create outgoing session to endpoint '%s'\n", endpoint_name);
 		req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
 		return -1;

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

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I21da85ebd62dcc32115b2ffcb5157416ebae51e4
Gerrit-Change-Number: 7613
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171215/068fdaa2/attachment.html>


More information about the asterisk-code-review mailing list