[Asterisk-code-review] pjsip/dialplan_functions.c: Get dialable string from function. (asterisk[13])

cmaj asteriskteam at digium.com
Tue Dec 3 15:42:52 CST 2019


cmaj has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13363 )


Change subject: pjsip/dialplan_functions.c: Get dialable string from function.
......................................................................

pjsip/dialplan_functions.c: Get dialable string from function.

It is convenient to get back a dialable string from the PJSIP_DIAL_CONTACTS
function so you can pass it in to the Dial() application without modification.

Change-Id: I1709ee211705edac4d93f55723b8153bb653a338
---
M channels/pjsip/dialplan_functions.c
1 file changed, 21 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/63/13363/1

diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c
index 3a6f0a4..a69146a 100644
--- a/channels/pjsip/dialplan_functions.c
+++ b/channels/pjsip/dialplan_functions.c
@@ -44,9 +44,12 @@
 		<parameter name="request_user" required="false">
 			<para>Optional request user to use in the request URI</para>
 		</parameter>
+		<parameter name="please" required="false">
+			<para>Optional return of 'PJSIP/endpoint' if no contacts are found. Otherwise, with no contacts, this function will return an empty string that will cause the Dial application to exit with an error and hang up the call.</para>
+		</parameter>
 	</syntax>
 	<description>
-		<para>Returns a properly formatted dial string for dialing all contacts on an AOR.</para>
+		<para>Returns a properly formatted dial string for dialing all contacts on an AOR. If there are no contacts, then an empty string is returned -- unless you specify the 'please' argument.</para>
 	</description>
 </function>
 <function name="PJSIP_MEDIA_OFFER" language="en_US">
@@ -985,13 +988,14 @@
 {
 	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_str *, dial, NULL, ast_free_ptr);
-	const char *aor_name;
+	const char *aor_name = "";
 	char *rest;
 
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(endpoint_name);
 		AST_APP_ARG(aor_name);
 		AST_APP_ARG(request_user);
+		AST_APP_ARG(please);
 	);
 
 	AST_STANDARD_APP_ARGS(args, data);
@@ -1000,13 +1004,19 @@
 		ast_log(LOG_WARNING, "An endpoint name must be specified when using the '%s' dialplan function\n", cmd);
 		return -1;
 	} else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", args.endpoint_name))) {
-		ast_log(LOG_WARNING, "Specified endpoint '%s' was not found\n", args.endpoint_name);
-		return -1;
+		if (!ast_strlen_zero(args.please)) {
+			ast_log(LOG_WARNING, "Specified endpoint '%s' was not found but the 'please' argument was provided so keeping calm and carrying on\n", args.endpoint_name);
+		} else {
+			ast_log(LOG_WARNING, "Specified endpoint '%s' was not found\n", args.endpoint_name);
+			return -1;
+		}
 	}
 
-	aor_name = S_OR(args.aor_name, endpoint->aors);
+	if (endpoint) {
+		aor_name = S_OR(args.aor_name, endpoint->aors);
+	}
 
-	if (ast_strlen_zero(aor_name)) {
+	if (ast_strlen_zero(aor_name) && ast_strlen_zero(args.please)) {
 		ast_log(LOG_WARNING, "No AOR has been provided and no AORs are configured on endpoint '%s'\n", args.endpoint_name);
 		return -1;
 	} else if (!(dial = ast_str_create(len))) {
@@ -1049,6 +1059,11 @@
 	/* Trim the '&' at the end off */
 	ast_str_truncate(dial, ast_str_strlen(dial) - 1);
 
+	if (ast_str_strlen(dial) == 0 && !ast_strlen_zero(args.please)) {
+		ast_log(LOG_WARNING, "No current Contacts found for endpoint '%s' but the 'please' argument was provided so keeping calm and carrying on\n", args.endpoint_name);
+		ast_str_append(&dial, -1, "PJSIP/%s", args.endpoint_name);
+	}
+
 	ast_copy_string(buf, ast_str_buffer(dial), len);
 
 	return 0;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13363
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I1709ee211705edac4d93f55723b8153bb653a338
Gerrit-Change-Number: 13363
Gerrit-PatchSet: 1
Gerrit-Owner: cmaj <chris at penguinpbx.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20191203/2d0eabbe/attachment.html>


More information about the asterisk-code-review mailing list