<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11164">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">main/json.c: Added app_name, app_data to channel type<br><br>It was difficult to check the channel's current application and<br>parameters using ARI for current channels. Added app_name, app_data<br>items to show the current application information.<br><br>ASTERISK-28343<br><br>Change-Id: Ia48972b3850e5099deab0faeaaf51223a1f2f38c<br>---<br>M include/asterisk/json.h<br>M main/json.c<br>M main/stasis_channels.c<br>M res/ari/ari_model_validators.c<br>M res/ari/ari_model_validators.h<br>M rest-api/api-docs/channels.json<br>M tests/test_json.c<br>M tests/test_stasis_channels.c<br>8 files changed, 91 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/json.h b/include/asterisk/json.h</span><br><span>index 665380c..ce0baa4 100644</span><br><span>--- a/include/asterisk/json.h</span><br><span>+++ b/include/asterisk/json.h</span><br><span>@@ -993,6 +993,22 @@</span><br><span> struct ast_json *ast_json_ipaddr(const struct ast_sockaddr *addr, enum ast_transport transport_type);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Construct a context/exten/priority/application/application_data as JSON.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * If a \c NULL is passed for \c context or \c exten or \c app_name or \c app_data,</span><br><span style="color: hsl(120, 100%, 40%);">+ * or -1 for \c priority, the fields is set to ast_json_null().</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param context Context name.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param exten Extension.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param priority Dialplan priority.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param app_name Application name.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param app_data Application argument.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return JSON object with \c context, \c exten and \c priority \c app_name \c app_data fields</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_json *ast_json_dialplan_cep_app(</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *context, const char *exten, int priority, const char *app_name, const char *app_data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Construct a context/exten/priority as JSON.</span><br><span> *</span><br><span> * If a \c NULL is passed for \c context or \c exten, or -1 for \c priority,</span><br><span>diff --git a/main/json.c b/main/json.c</span><br><span>index f72de41..09101aa 100644</span><br><span>--- a/main/json.c</span><br><span>+++ b/main/json.c</span><br><span>@@ -629,12 +629,21 @@</span><br><span> "number", AST_JSON_UTF8_VALIDATE(number));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_json *ast_json_dialplan_cep_app(</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *context, const char *exten, int priority, const char *app_name, const char *app_data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_json_pack("{s: s?, s: s?, s: o, s: s?, s: s?}",</span><br><span style="color: hsl(120, 100%, 40%);">+ "context", context,</span><br><span style="color: hsl(120, 100%, 40%);">+ "exten", exten,</span><br><span style="color: hsl(120, 100%, 40%);">+ "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null(),</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_name", app_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_data", app_data</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_json *ast_json_dialplan_cep(const char *context, const char *exten, int priority)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- return ast_json_pack("{s: o, s: o, s: o}",</span><br><span style="color: hsl(0, 100%, 40%);">- "context", context ? ast_json_string_create(context) : ast_json_null(),</span><br><span style="color: hsl(0, 100%, 40%);">- "exten", exten ? ast_json_string_create(exten) : ast_json_null(),</span><br><span style="color: hsl(0, 100%, 40%);">- "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_json_dialplan_cep_app(context, exten, priority, "", "");</span><br><span> }</span><br><span> </span><br><span> struct ast_json *ast_json_timeval(const struct timeval tv, const char *zone)</span><br><span>diff --git a/main/stasis_channels.c b/main/stasis_channels.c</span><br><span>index e8842c1..be77cb9 100644</span><br><span>--- a/main/stasis_channels.c</span><br><span>+++ b/main/stasis_channels.c</span><br><span>@@ -1281,8 +1281,9 @@</span><br><span> snapshot->connected->name, snapshot->connected->number),</span><br><span> "accountcode", snapshot->base->accountcode,</span><br><span> /* Third line */</span><br><span style="color: hsl(0, 100%, 40%);">- "dialplan", ast_json_dialplan_cep(</span><br><span style="color: hsl(0, 100%, 40%);">- snapshot->dialplan->context, snapshot->dialplan->exten, snapshot->dialplan->priority),</span><br><span style="color: hsl(120, 100%, 40%);">+ "dialplan", ast_json_dialplan_cep_app(</span><br><span style="color: hsl(120, 100%, 40%);">+ snapshot->dialplan->context, snapshot->dialplan->exten, snapshot->dialplan->priority,</span><br><span style="color: hsl(120, 100%, 40%);">+ snapshot->dialplan->appl, snapshot->dialplan->data),</span><br><span> "creationtime", ast_json_timeval(snapshot->base->creationtime, NULL),</span><br><span> "language", snapshot->base->language);</span><br><span> </span><br><span>diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c</span><br><span>index d5f1885..195218e 100644</span><br><span>--- a/res/ari/ari_model_validators.c</span><br><span>+++ b/res/ari/ari_model_validators.c</span><br><span>@@ -1287,11 +1287,33 @@</span><br><span> {</span><br><span> int res = 1;</span><br><span> struct ast_json_iter *iter;</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_app_data = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_app_name = 0;</span><br><span> int has_context = 0;</span><br><span> int has_exten = 0;</span><br><span> int has_priority = 0;</span><br><span> </span><br><span> for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp("app_data", ast_json_object_iter_key(iter)) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int prop_is_valid;</span><br><span style="color: hsl(120, 100%, 40%);">+ has_app_data = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ prop_is_valid = ast_ari_validate_string(</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_object_iter_value(iter));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!prop_is_valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "ARI DialplanCEP field app_data failed validation\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp("app_name", ast_json_object_iter_key(iter)) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int prop_is_valid;</span><br><span style="color: hsl(120, 100%, 40%);">+ has_app_name = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ prop_is_valid = ast_ari_validate_string(</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_object_iter_value(iter));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!prop_is_valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "ARI DialplanCEP field app_name failed validation\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span> if (strcmp("context", ast_json_object_iter_key(iter)) == 0) {</span><br><span> int prop_is_valid;</span><br><span> has_context = 1;</span><br><span>@@ -1330,6 +1352,16 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!has_app_data) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "ARI DialplanCEP missing required field app_data\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!has_app_name) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "ARI DialplanCEP missing required field app_name\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!has_context) {</span><br><span> ast_log(LOG_ERROR, "ARI DialplanCEP missing required field context\n");</span><br><span> res = 0;</span><br><span>diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h</span><br><span>index 484f9c1..b14c25f 100644</span><br><span>--- a/res/ari/ari_model_validators.h</span><br><span>+++ b/res/ari/ari_model_validators.h</span><br><span>@@ -1499,6 +1499,8 @@</span><br><span> * - state: string (required)</span><br><span> * Dialed</span><br><span> * DialplanCEP</span><br><span style="color: hsl(120, 100%, 40%);">+ * - app_data: string (required)</span><br><span style="color: hsl(120, 100%, 40%);">+ * - app_name: string (required)</span><br><span> * - context: string (required)</span><br><span> * - exten: string (required)</span><br><span> * - priority: long (required)</span><br><span>diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json</span><br><span>index 6161934..53a362e 100644</span><br><span>--- a/rest-api/api-docs/channels.json</span><br><span>+++ b/rest-api/api-docs/channels.json</span><br><span>@@ -1746,6 +1746,16 @@</span><br><span> "required": true,</span><br><span> "type": "long",</span><br><span> "description": "Priority in the dialplan"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_name": {</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": true,</span><br><span style="color: hsl(120, 100%, 40%);">+ "type": "string",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Name of current dialplan application"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_data": {</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": true,</span><br><span style="color: hsl(120, 100%, 40%);">+ "type": "string",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Parameter of current dialplan application"</span><br><span> }</span><br><span> }</span><br><span> },</span><br><span>diff --git a/tests/test_json.c b/tests/test_json.c</span><br><span>index 2f71086..8dbb872 100644</span><br><span>--- a/tests/test_json.c</span><br><span>+++ b/tests/test_json.c</span><br><span>@@ -1680,20 +1680,26 @@</span><br><span> break;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- expected = ast_json_pack("{s: o, s: o, s: o}",</span><br><span style="color: hsl(120, 100%, 40%);">+ expected = ast_json_pack("{s: o, s: o, s: o, s: o, s: o}",</span><br><span> "context", ast_json_null(),</span><br><span> "exten", ast_json_null(),</span><br><span style="color: hsl(0, 100%, 40%);">- "priority", ast_json_null());</span><br><span style="color: hsl(0, 100%, 40%);">- uut = ast_json_dialplan_cep(NULL, NULL, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ "priority", ast_json_null(),</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_name", ast_json_null(),</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_data", ast_json_null()</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+ uut = ast_json_dialplan_cep_app(NULL, NULL, -1, NULL, NULL);</span><br><span> ast_test_validate(test, ast_json_equal(expected, uut));</span><br><span> </span><br><span> ast_json_unref(expected);</span><br><span> ast_json_unref(uut);</span><br><span style="color: hsl(0, 100%, 40%);">- expected = ast_json_pack("{s: s, s: s, s: i}",</span><br><span style="color: hsl(120, 100%, 40%);">+ expected = ast_json_pack("{s: s, s: s, s: i, s: s, s: s}",</span><br><span> "context", "main",</span><br><span> "exten", "4321",</span><br><span style="color: hsl(0, 100%, 40%);">- "priority", 7);</span><br><span style="color: hsl(0, 100%, 40%);">- uut = ast_json_dialplan_cep("main", "4321", 7);</span><br><span style="color: hsl(120, 100%, 40%);">+ "priority", 7,</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_name", "",</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_data", ""</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+ uut = ast_json_dialplan_cep_app("main", "4321", 7, "", "");</span><br><span> ast_test_validate(test, ast_json_equal(expected, uut));</span><br><span> </span><br><span> return AST_TEST_PASS;</span><br><span>diff --git a/tests/test_stasis_channels.c b/tests/test_stasis_channels.c</span><br><span>index f8d2a03..d4a05b2 100644</span><br><span>--- a/tests/test_stasis_channels.c</span><br><span>+++ b/tests/test_stasis_channels.c</span><br><span>@@ -274,7 +274,7 @@</span><br><span> </span><br><span> actual = ast_channel_snapshot_to_json(snapshot, NULL);</span><br><span> expected = ast_json_pack("{ s: s, s: s, s: s, s: s,"</span><br><span style="color: hsl(0, 100%, 40%);">- " s: { s: s, s: s, s: i },"</span><br><span style="color: hsl(120, 100%, 40%);">+ " s: { s: s, s: s, s: i, s: s, s: s },"</span><br><span> " s: { s: s, s: s },"</span><br><span> " s: { s: s, s: s },"</span><br><span> " s: s"</span><br><span>@@ -288,6 +288,8 @@</span><br><span> "context", "context",</span><br><span> "exten", "exten",</span><br><span> "priority", 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_name", "",</span><br><span style="color: hsl(120, 100%, 40%);">+ "app_data", "",</span><br><span> "caller",</span><br><span> "name", "cid_name",</span><br><span> "number", "cid_num",</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11164">change 11164</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/11164"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ia48972b3850e5099deab0faeaaf51223a1f2f38c </div>
<div style="display:none"> Gerrit-Change-Number: 11164 </div>
<div style="display:none"> Gerrit-PatchSet: 7 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>