<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18565">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ari: expose channel driver's unique id to ARI channel resource<br><br>This change exposes the channel driver's unique id (i.e. the Call-ID<br>for chan_sip/chan_pjsip based channels) to ARI channel resources<br>as `protocol_id`.<br><br>ASTERISK-30027<br>Reported by: Moritz Fain<br>Tested by: Moritz Fain<br><br>Change-Id: I7cc6e7a9d29efe74bc27811d788dac20fe559b87<br>---<br>M channels/chan_pjsip.c<br>A doc/CHANGES-staging/ari_add_pvt_id_to_channel_resource.txt<br>M include/asterisk/stasis_channels.h<br>M main/channel_internal_api.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_stasis_channels.c<br>9 files changed, 44 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index b70b210..7c6b301 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -1273,7 +1273,7 @@</span><br><span> struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);</span><br><span> char *uniqueid = ast_threadstorage_get(&uniqueid_threadbuf, UNIQUEID_BUFSIZE);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!uniqueid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!channel || !uniqueid) {</span><br><span> return "";</span><br><span> }</span><br><span> </span><br><span>diff --git a/doc/CHANGES-staging/ari_add_pvt_id_to_channel_resource.txt b/doc/CHANGES-staging/ari_add_pvt_id_to_channel_resource.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..a4f008f</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/ari_add_pvt_id_to_channel_resource.txt</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: ari</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: stasis_channels</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Expose channel driver's unique id (which is the Call-ID for SIP/PJSIP)</span><br><span style="color: hsl(120, 100%, 40%);">+to ARI channel resources as 'protocol_id'.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ASTERISK-30027</span><br><span>diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h</span><br><span>index 80c79eb..7377186 100644</span><br><span>--- a/include/asterisk/stasis_channels.h</span><br><span>+++ b/include/asterisk/stasis_channels.h</span><br><span>@@ -112,6 +112,7 @@</span><br><span> );</span><br><span> struct timeval creationtime; /*!< The time of channel creation */</span><br><span> int tech_properties; /*!< Properties of the channel's technology */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STRING_FIELD_EXTENDED(protocol_id); /*!< Channel driver protocol id (i.e. Call-ID for chan_sip/chan_pjsip) */</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c</span><br><span>index 131faae..123f61a 100644</span><br><span>--- a/main/channel_internal_api.c</span><br><span>+++ b/main/channel_internal_api.c</span><br><span>@@ -587,6 +587,9 @@</span><br><span> void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)</span><br><span> {</span><br><span> chan->tech_pvt = value;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (value != NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_BASE);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> void *ast_channel_timingdata(const struct ast_channel *chan)</span><br><span> {</span><br><span>diff --git a/main/stasis_channels.c b/main/stasis_channels.c</span><br><span>index 8becf96..d373f6a 100644</span><br><span>--- a/main/stasis_channels.c</span><br><span>+++ b/main/stasis_channels.c</span><br><span>@@ -273,7 +273,7 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_string_field_init(snapshot, 256)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_string_field_init(snapshot, 256) || ast_string_field_init_extended(snapshot, protocol_id)) {</span><br><span> ao2_ref(snapshot, -1);</span><br><span> return NULL;</span><br><span> }</span><br><span>@@ -288,6 +288,10 @@</span><br><span> snapshot->creationtime = ast_channel_creationtime(chan);</span><br><span> snapshot->tech_properties = ast_channel_tech(chan)->properties;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_channel_tech(chan)->get_pvt_uniqueid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_string_field_set(snapshot, protocol_id, ast_channel_tech(chan)->get_pvt_uniqueid(chan));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return snapshot;</span><br><span> }</span><br><span> </span><br><span>@@ -1266,14 +1270,15 @@</span><br><span> }</span><br><span> </span><br><span> json_chan = ast_json_pack(</span><br><span style="color: hsl(0, 100%, 40%);">- /* Broken up into groups of three for readability */</span><br><span style="color: hsl(0, 100%, 40%);">- "{ s: s, s: s, s: s,"</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Broken up into groups for readability */</span><br><span style="color: hsl(120, 100%, 40%);">+ "{ s: s, s: s, s: s, s: s,"</span><br><span> " s: o, s: o, s: s,"</span><br><span> " s: o, s: o, s: s }",</span><br><span> /* First line */</span><br><span> "id", snapshot->base->uniqueid,</span><br><span> "name", snapshot->base->name,</span><br><span> "state", ast_state2str(snapshot->state),</span><br><span style="color: hsl(120, 100%, 40%);">+ "protocol_id", snapshot->base->protocol_id,</span><br><span> /* Second line */</span><br><span> "caller", ast_json_name_number(</span><br><span> snapshot->caller->name, snapshot->caller->number),</span><br><span>diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c</span><br><span>index 0bbbb19..fffb87a 100644</span><br><span>--- a/res/ari/ari_model_validators.c</span><br><span>+++ b/res/ari/ari_model_validators.c</span><br><span>@@ -1043,6 +1043,7 @@</span><br><span> int has_id = 0;</span><br><span> int has_language = 0;</span><br><span> int has_name = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int has_protocol_id = 0;</span><br><span> int has_state = 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>@@ -1135,6 +1136,16 @@</span><br><span> res = 0;</span><br><span> }</span><br><span> } else</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp("protocol_id", 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_protocol_id = 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 Channel field protocol_id 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("state", ast_json_object_iter_key(iter)) == 0) {</span><br><span> int prop_is_valid;</span><br><span> has_state = 1;</span><br><span>@@ -1193,6 +1204,11 @@</span><br><span> res = 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!has_protocol_id) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "ARI Channel missing required field protocol_id\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_state) {</span><br><span> ast_log(LOG_ERROR, "ARI Channel missing required field state\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 583cba3..64f167c 100644</span><br><span>--- a/res/ari/ari_model_validators.h</span><br><span>+++ b/res/ari/ari_model_validators.h</span><br><span>@@ -1353,6 +1353,7 @@</span><br><span> * - id: string (required)</span><br><span> * - language: string (required)</span><br><span> * - name: string (required)</span><br><span style="color: hsl(120, 100%, 40%);">+ * - protocol_id: string (required)</span><br><span> * - state: string (required)</span><br><span> * Dialed</span><br><span> * DialplanCEP</span><br><span>diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json</span><br><span>index 04d1577..269976d 100644</span><br><span>--- a/rest-api/api-docs/channels.json</span><br><span>+++ b/rest-api/api-docs/channels.json</span><br><span>@@ -2126,6 +2126,11 @@</span><br><span> "type": "string",</span><br><span> "description": "Unique identifier of the channel.\n\nThis is the same as the Uniqueid field in AMI."</span><br><span> },</span><br><span style="color: hsl(120, 100%, 40%);">+ "protocol_id": {</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": "Protocol id from underlying channel driver (i.e. Call-ID for chan_sip/chan_pjsip; will be empty if not applicable or not implemented by driver)."</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span> "name": {</span><br><span> "required": true,</span><br><span> "type": "string",</span><br><span>diff --git a/tests/test_stasis_channels.c b/tests/test_stasis_channels.c</span><br><span>index d4a05b2..5ea9dd8 100644</span><br><span>--- a/tests/test_stasis_channels.c</span><br><span>+++ b/tests/test_stasis_channels.c</span><br><span>@@ -273,7 +273,7 @@</span><br><span> ast_test_validate(test, NULL != snapshot);</span><br><span> </span><br><span> actual = ast_channel_snapshot_to_json(snapshot, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- expected = ast_json_pack("{ s: s, s: s, s: s, s: s,"</span><br><span style="color: hsl(120, 100%, 40%);">+ expected = ast_json_pack("{ s: s, s: s, s: s, s: s, s: s,"</span><br><span> " 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>@@ -284,6 +284,7 @@</span><br><span> "state", "Down",</span><br><span> "accountcode", "acctcode",</span><br><span> "id", ast_channel_uniqueid(chan),</span><br><span style="color: hsl(120, 100%, 40%);">+ "protocol_id", "",</span><br><span> "dialplan",</span><br><span> "context", "context",</span><br><span> "exten", "exten",</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18565">change 18565</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/+/18565"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I7cc6e7a9d29efe74bc27811d788dac20fe559b87 </div>
<div style="display:none"> Gerrit-Change-Number: 18565 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Moritz Fain <moritz@fain.io> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>