<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17716">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_frameintercept: Add FRAME_INTERCEPT function<br><br>Adds a function that can be used to intercept<br>certain control frames on a channel.<br><br>This function contains a superset of the functionality<br>in the existing HOLD_INTERCEPT function.<br><br>ASTERISK-29825 #close<br><br>Change-Id: I5ad83b95a4dce3b64b408a1497b0cd63051eb274<br>---<br>M configs/samples/stasis.conf.sample<br>A doc/CHANGES-staging/func_frameintercept.txt<br>A funcs/func_frameintercept.c<br>M include/asterisk/stasis_channels.h<br>M main/stasis.c<br>M main/stasis_channels.c<br>6 files changed, 298 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/16/17716/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/stasis.conf.sample b/configs/samples/stasis.conf.sample</span><br><span>index 6fadc74..b62d1c6 100644</span><br><span>--- a/configs/samples/stasis.conf.sample</span><br><span>+++ b/configs/samples/stasis.conf.sample</span><br><span>@@ -54,6 +54,7 @@</span><br><span> ; decline=ast_channel_dtmf_begin_type</span><br><span> ; decline=ast_channel_dtmf_end_type</span><br><span> ; decline=ast_channel_flash_type</span><br><span style="color: hsl(120, 100%, 40%);">+; decline=ast_channel_wink_type</span><br><span> ; decline=ast_channel_hold_type</span><br><span> ; decline=ast_channel_unhold_type</span><br><span> ; decline=ast_channel_chanspy_start_type</span><br><span>diff --git a/doc/CHANGES-staging/func_frameintercept.txt b/doc/CHANGES-staging/func_frameintercept.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..babbe06</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/func_frameintercept.txt</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: func_frameintercept</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Adds the FRAME_INTERCEPT function, which can be used</span><br><span style="color: hsl(120, 100%, 40%);">+to intercept certain control frames on a channel.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This function contains a superset of the functionality</span><br><span style="color: hsl(120, 100%, 40%);">+contained within the existing HOLD_INTERCEPT function.</span><br><span>diff --git a/funcs/func_frameintercept.c b/funcs/func_frameintercept.c</span><br><span>new file mode 100644</span><br><span>index 0000000..b4c2344</span><br><span>--- /dev/null</span><br><span>+++ b/funcs/func_frameintercept.c</span><br><span>@@ -0,0 +1,279 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Asterisk -- An open source telephony toolkit.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2021, Naveen Albert</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Naveen Albert <asterisk@phreaknet.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * See http://www.asterisk.org for more information about</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Asterisk project. Please do not directly contact</span><br><span style="color: hsl(120, 100%, 40%);">+ * any of the maintainers of this project for assistance;</span><br><span style="color: hsl(120, 100%, 40%);">+ * the project provides a web site, mailing lists and IRC</span><br><span style="color: hsl(120, 100%, 40%);">+ * channels for your use.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+ * the GNU General Public License Version 2. See the LICENSE file</span><br><span style="color: hsl(120, 100%, 40%);">+ * at the top of the source tree.</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%);">+/*! \file</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Function that intercepts specified frames on channels</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \author Naveen Albert <asterisk@phreaknet.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \ingroup functions</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%);">+/*** MODULEINFO</span><br><span style="color: hsl(120, 100%, 40%);">+ <support_level>extended</support_level></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%);">+/*! \todo deprecate/remove func_holdintercept in 21, since this module is a superset of its functionality */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/module.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/channel.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/pbx.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/framehook.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/stasis.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/stasis_channels.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*** DOCUMENTATION</span><br><span style="color: hsl(120, 100%, 40%);">+ <function name="FRAME_INTERCEPT" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ Intercepts specific frame types in the TX or RX direction on a channel and raises an event</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="direction" required="true"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>List of frame types to be intercepted for the specified direction. Direction can be <literal>TX</literal> or <literal>RX</literal>. The <literal>TX</literal> direction will intercept to a channel, and the <literal>RX</literal> direction will intercept frames from a channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Subsequent calls to this function will replace previous settings, allowing certain frames to be intercepted only temporarily, for instance.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Below are the different types of frames that can be intercepted.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>The following CONTROL frames can be intercepted:</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "FLASH" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "WINK" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "HOLD" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "UNHOLD" /></span><br><span style="color: hsl(120, 100%, 40%);">+ </enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Examples:</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <example title="Raise an event when a hold/unhold event is received on a channel from the called party"></span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Set(FRAME_INTERCEPT(TX)=HOLD,UNHOLD)</span><br><span style="color: hsl(120, 100%, 40%);">+ </example></span><br><span style="color: hsl(120, 100%, 40%);">+ <example title="Raise an event when a wink is received on a channel from the called party"></span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Set(FRAME_INTERCEPT(TX)=WINK)</span><br><span style="color: hsl(120, 100%, 40%);">+ </example></span><br><span style="color: hsl(120, 100%, 40%);">+ <example title="Disable frame interception"></span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Set(FRAME_INTERCEPT(TX)=)</span><br><span style="color: hsl(120, 100%, 40%);">+ </example></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ </function></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%);">+static struct {</span><br><span style="color: hsl(120, 100%, 40%);">+ int type;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *str;</span><br><span style="color: hsl(120, 100%, 40%);">+} controlframetype2str[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_FLASH, ",FLASH," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_WINK, ",WINK," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_HOLD, ",HOLD," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_UNHOLD, ",UNHOLD," },</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%);">+enum direction {</span><br><span style="color: hsl(120, 100%, 40%);">+ TX = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ RX,</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%);">+struct frame_intercept_data {</span><br><span style="color: hsl(120, 100%, 40%);">+ enum direction list_type;</span><br><span style="color: hsl(120, 100%, 40%);">+ int controlvalues[ARRAY_LEN(controlframetype2str)];</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%);">+static void datastore_destroy_cb(void *data) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(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%);">+static const struct ast_datastore_info frame_intercept_datastore = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .type = "frame_intercept",</span><br><span style="color: hsl(120, 100%, 40%);">+ .destroy = datastore_destroy_cb</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%);">+static void hook_destroy_cb(void *framedata)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(framedata);</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%);">+/*! \brief Frame hook that is called to intercept frames */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i, frame_type;</span><br><span style="color: hsl(120, 100%, 40%);">+ int intercept = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct frame_intercept_data *framedata = data;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!frame) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return frame;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (frame->frametype != AST_FRAME_CONTROL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return frame;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!((event == AST_FRAMEHOOK_EVENT_WRITE && framedata->list_type == TX) ||</span><br><span style="color: hsl(120, 100%, 40%);">+ (event == AST_FRAMEHOOK_EVENT_READ && framedata->list_type == RX))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return frame;</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 (frame->frametype == AST_FRAME_CONTROL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (frame->subclass.integer == controlframetype2str[i].type) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (framedata->controlvalues[i]) {</span><br><span style="color: hsl(120, 100%, 40%);">+ intercept = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ frame_type = frame->subclass.integer;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</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 style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (intercept) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_message_type *message = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *intercepted = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (frame_type) {</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (frame_type) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_CONTROL_FLASH:</span><br><span style="color: hsl(120, 100%, 40%);">+ message = ast_channel_flash_type();</span><br><span style="color: hsl(120, 100%, 40%);">+ intercepted = "flash";</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_CONTROL_WINK:</span><br><span style="color: hsl(120, 100%, 40%);">+ message = ast_channel_wink_type();</span><br><span style="color: hsl(120, 100%, 40%);">+ intercepted = "wink";</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_CONTROL_HOLD:</span><br><span style="color: hsl(120, 100%, 40%);">+ message = ast_channel_hold_type();</span><br><span style="color: hsl(120, 100%, 40%);">+ intercepted = "hold";</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_CONTROL_UNHOLD:</span><br><span style="color: hsl(120, 100%, 40%);">+ message = ast_channel_unhold_type();</span><br><span style="color: hsl(120, 100%, 40%);">+ intercepted = "unhold";</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ default:</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Frame subclass type %d not supported\n", frame_type); /* shouldn't happen */</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 style="color: hsl(120, 100%, 40%);">+ if (message) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Munch munch */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frfree(frame);</span><br><span style="color: hsl(120, 100%, 40%);">+ frame = &ast_null_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_publish_cached_blob(chan, message, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verb(3, "Intercepted a %s frame on channel %s\n", intercepted, ast_channel_name(chan));</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%);">+ return frame;</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%);">+/*! \brief Callback function which informs upstream if we are consuming a frame of a specific type */</span><br><span style="color: hsl(120, 100%, 40%);">+static int frame_intercept_framehook_consume(void *data, enum ast_frame_type type)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return (type == AST_FRAME_CONTROL ? 1 : 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%);">+/*! \internal \brief FRAME_INTERCEPT write function callback */</span><br><span style="color: hsl(120, 100%, 40%);">+static int frame_intercept_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char *buffer;</span><br><span style="color: hsl(120, 100%, 40%);">+ int intercepting = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct frame_intercept_data *framedata;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_datastore *datastore = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_framehook_interface interface = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .version = AST_FRAMEHOOK_INTERFACE_VERSION,</span><br><span style="color: hsl(120, 100%, 40%);">+ .event_cb = hook_event_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+ .destroy_cb = hook_destroy_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+ .consume_cb = frame_intercept_framehook_consume,</span><br><span style="color: hsl(120, 100%, 40%);">+ .disable_inheritance = 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ };</span><br><span style="color: hsl(120, 100%, 40%);">+ int i = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 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%);">+ interface.data = framedata;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcasecmp(data, "RX")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ framedata->list_type = RX;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ framedata->list_type = TX;</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%);">+ buffer = ast_malloc(sizeof(value) + 3); /* leading and trailing comma and null terminator */</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buffer, sizeof(value) + 2, ",%s,", value);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcasestr(value, controlframetype2str[i].str)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ framedata->controlvalues[i] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ intercepting++;</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%);">+ ast_free(buffer);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ i = ast_framehook_attach(chan, &interface);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (i >= 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int *id;</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((datastore = ast_channel_datastore_find(chan, &frame_intercept_datastore, NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id = datastore->data;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_framehook_detach(chan, *id);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_datastore_remove(chan, datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_datastore_free(datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!intercepting) { /* if we just removed all the intercepts, then we're not needed anymore */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(datastore = ast_datastore_alloc(&frame_intercept_datastore, NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Failed to setup FRAME_INTERCEPT framehook\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_framehook_detach(chan, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 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 (!(id = ast_calloc(1, sizeof(int)))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Failed to setup FRAME_INTERCEPT framehook\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_datastore_free(datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_framehook_detach(chan, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 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%);">+ *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */</span><br><span style="color: hsl(120, 100%, 40%);">+ datastore->data = id;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_datastore_add(chan, datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 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%);">+/*! \brief Definition of the FRAME_INTERCEPT function */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_custom_function frame_intercept_function = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "FRAME_INTERCEPT",</span><br><span style="color: hsl(120, 100%, 40%);">+ .write = frame_intercept_helper,</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%);">+static int unload_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_custom_function_unregister(&frame_intercept_function);</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%);">+static int load_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int res = ast_custom_function_register(&frame_intercept_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;</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%);">+AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Function to intercept frames on a channel.");</span><br><span>diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h</span><br><span>index f345228..80c79eb 100644</span><br><span>--- a/include/asterisk/stasis_channels.h</span><br><span>+++ b/include/asterisk/stasis_channels.h</span><br><span>@@ -529,6 +529,13 @@</span><br><span> struct stasis_message_type *ast_channel_flash_type(void);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Message type for when a wink occurs on a channel.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return A stasis message type</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct stasis_message_type *ast_channel_wink_type(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \since 12</span><br><span> * \brief Message type for when a channel is placed on hold.</span><br><span> *</span><br><span>diff --git a/main/stasis.c b/main/stasis.c</span><br><span>index a75fe66..cf89a99 100644</span><br><span>--- a/main/stasis.c</span><br><span>+++ b/main/stasis.c</span><br><span>@@ -121,6 +121,7 @@</span><br><span> <enum name="ast_channel_dtmf_begin_type" /></span><br><span> <enum name="ast_channel_dtmf_end_type" /></span><br><span> <enum name="ast_channel_flash_type" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="ast_channel_wink_type" /></span><br><span> <enum name="ast_channel_hold_type" /></span><br><span> <enum name="ast_channel_unhold_type" /></span><br><span> <enum name="ast_channel_chanspy_start_type" /></span><br><span>diff --git a/main/stasis_channels.c b/main/stasis_channels.c</span><br><span>index 5e39c07..8becf96 100644</span><br><span>--- a/main/stasis_channels.c</span><br><span>+++ b/main/stasis_channels.c</span><br><span>@@ -1599,6 +1599,7 @@</span><br><span> .to_json = unhold_to_json,</span><br><span> );</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_flash_type);</span><br><span style="color: hsl(120, 100%, 40%);">+STASIS_MESSAGE_TYPE_DEFN(ast_channel_wink_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);</span><br><span>@@ -1644,6 +1645,7 @@</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_flash_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_wink_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hold_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_unhold_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type);</span><br><span>@@ -1698,6 +1700,7 @@</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_flash_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_wink_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_unhold_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17716">change 17716</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/+/17716"/><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: I5ad83b95a4dce3b64b408a1497b0cd63051eb274 </div>
<div style="display:none"> Gerrit-Change-Number: 17716 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>