[Asterisk-code-review] main/json.c: Added app_name, app_data to channel type (...asterisk[master])

sungtae kim asteriskteam at digium.com
Thu Mar 21 18:09:13 CDT 2019


sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/11164


Change subject: main/json.c: Added app_name, app_data to channel type
......................................................................

main/json.c: Added app_name, app_data to channel type

It was not possible to check the channel's current application and
parameters using ARI for current channels. Added app_name, app_data
items to show the current application information.

ASTERISK-28343

Change-Id: Ia48972b3850e5099deab0faeaaf51223a1f2f38c
---
M include/asterisk/json.h
M main/json.c
M main/stasis_channels.c
M res/ari/ari_model_validators.c
M res/ari/ari_model_validators.h
M rest-api/api-docs/channels.json
M tests/test_json.c
7 files changed, 65 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/64/11164/1

diff --git a/include/asterisk/json.h b/include/asterisk/json.h
index 665380c..cca55f9 100644
--- a/include/asterisk/json.h
+++ b/include/asterisk/json.h
@@ -1001,9 +1001,12 @@
  * \param context Context name.
  * \param exten Extension.
  * \param priority Dialplan priority.
+ * \param app_name Current application name
+ * \param app_data Current application parameter
  * \return JSON object with \c context, \c exten and \c priority fields
  */
-struct ast_json *ast_json_dialplan_cep(const char *context, const char *exten, int priority);
+struct ast_json *ast_json_dialplan_cep(
+		const char *context, const char *exten, int priority, const char *app_name, const char *app_data);
 
 struct ast_json_payload {
 	struct ast_json *json;
diff --git a/main/json.c b/main/json.c
index f72de41..ccfd9de 100644
--- a/main/json.c
+++ b/main/json.c
@@ -629,12 +629,16 @@
 		"number", AST_JSON_UTF8_VALIDATE(number));
 }
 
-struct ast_json *ast_json_dialplan_cep(const char *context, const char *exten, int priority)
+struct ast_json *ast_json_dialplan_cep(
+		const char *context, const char *exten, int priority, const char *app_name, const char *app_data)
 {
-	return ast_json_pack("{s: o, s: o, s: o}",
-		"context", context ? ast_json_string_create(context) : ast_json_null(),
-		"exten", exten ? ast_json_string_create(exten) : ast_json_null(),
-		"priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
+	return ast_json_pack("{s: s?, s: s?, s: o, s: s?, s: s?}",
+		"context", context,
+		"exten", exten,
+		"priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null(),
+		"app_name", app_name,
+		"app_data", app_data
+		);
 }
 
 struct ast_json *ast_json_timeval(const struct timeval tv, const char *zone)
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index e8842c1..e96ec91 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -1282,7 +1282,8 @@
 		"accountcode", snapshot->base->accountcode,
 		/* Third line */
 		"dialplan", ast_json_dialplan_cep(
-			snapshot->dialplan->context, snapshot->dialplan->exten, snapshot->dialplan->priority),
+			snapshot->dialplan->context, snapshot->dialplan->exten, snapshot->dialplan->priority,
+			snapshot->dialplan->appl, snapshot->dialplan->data),
 		"creationtime", ast_json_timeval(snapshot->base->creationtime, NULL),
 		"language", snapshot->base->language);
 
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index d5f1885..195218e 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -1287,11 +1287,33 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_app_data = 0;
+	int has_app_name = 0;
 	int has_context = 0;
 	int has_exten = 0;
 	int has_priority = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("app_data", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_app_data = 1;
+			prop_is_valid = ast_ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI DialplanCEP field app_data failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("app_name", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_app_name = 1;
+			prop_is_valid = ast_ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI DialplanCEP field app_name failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("context", ast_json_object_iter_key(iter)) == 0) {
 			int prop_is_valid;
 			has_context = 1;
@@ -1330,6 +1352,16 @@
 		}
 	}
 
+	if (!has_app_data) {
+		ast_log(LOG_ERROR, "ARI DialplanCEP missing required field app_data\n");
+		res = 0;
+	}
+
+	if (!has_app_name) {
+		ast_log(LOG_ERROR, "ARI DialplanCEP missing required field app_name\n");
+		res = 0;
+	}
+
 	if (!has_context) {
 		ast_log(LOG_ERROR, "ARI DialplanCEP missing required field context\n");
 		res = 0;
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index 484f9c1..b14c25f 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -1499,6 +1499,8 @@
  * - state: string (required)
  * Dialed
  * DialplanCEP
+ * - app_data: string (required)
+ * - app_name: string (required)
  * - context: string (required)
  * - exten: string (required)
  * - priority: long (required)
diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json
index 6161934..53a362e 100644
--- a/rest-api/api-docs/channels.json
+++ b/rest-api/api-docs/channels.json
@@ -1746,6 +1746,16 @@
 					"required": true,
 					"type": "long",
 					"description": "Priority in the dialplan"
+				},
+				"app_name": {
+					"required": true,
+					"type": "string",
+					"description": "Name of current dialplan application"
+				},
+				"app_data": {
+					"required": true,
+					"type": "string",
+					"description": "Parameter of current dialplan application"
 				}
 			}
 		},
diff --git a/tests/test_json.c b/tests/test_json.c
index 2f71086..a5485ef 100644
--- a/tests/test_json.c
+++ b/tests/test_json.c
@@ -1680,11 +1680,14 @@
 		break;
 	}
 
-	expected = ast_json_pack("{s: o, s: o, s: o}",
+	expected = ast_json_pack("{s: o, s: o, s: o, s: o, s: o}",
 				 "context", ast_json_null(),
 				 "exten", ast_json_null(),
-				 "priority", ast_json_null());
-	uut = ast_json_dialplan_cep(NULL, NULL, -1);
+				 "priority", ast_json_null(),
+				 "app_name", ast_json_null(),
+				 "app_data", ast_json_null()
+				 );
+	uut = ast_json_dialplan_cep(NULL, NULL, -1, NULL, NULL);
 	ast_test_validate(test, ast_json_equal(expected, uut));
 
 	ast_json_unref(expected);

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ia48972b3850e5099deab0faeaaf51223a1f2f38c
Gerrit-Change-Number: 11164
Gerrit-PatchSet: 1
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190321/8023d90d/attachment-0001.html>


More information about the asterisk-code-review mailing list