]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
AMI: Add AMI event to expose hook flash events
authorNaveen Albert <mail@interlinked.x10host.com>
Thu, 13 May 2021 15:32:06 +0000 (11:32 -0400)
committerJoshua Colp <jcolp@sangoma.com>
Wed, 19 May 2021 13:02:46 +0000 (08:02 -0500)
Although Asterisk can receive and propogate flash events, it currently
provides no mechanism for doing anything with them itself.

This AMI event allows flash events to be processed by Asterisk.
Additionally, AST_CONTROL_FLASH is included in a switch statement
in channel.c to avoid throwing a warning when we shouldn't.

ASTERISK-29380

Change-Id: Ie17ffe65086e0282c88542e38eed6a461ec79e81

configs/samples/stasis.conf.sample
doc/CHANGES-staging/flash_ami_event.txt [new file with mode: 0644]
include/asterisk/stasis_channels.h
main/channel.c
main/manager_channels.c
main/stasis.c
main/stasis_channels.c

index 46a240eb25e75f57fd2b76b22f2edea5c5a00db5..6fadc74073eea23813bbe699206d5fa6e1a1144c 100644 (file)
@@ -53,6 +53,7 @@
 ; decline=ast_channel_hangup_request_type
 ; decline=ast_channel_dtmf_begin_type
 ; decline=ast_channel_dtmf_end_type
+; decline=ast_channel_flash_type
 ; decline=ast_channel_hold_type
 ; decline=ast_channel_unhold_type
 ; decline=ast_channel_chanspy_start_type
diff --git a/doc/CHANGES-staging/flash_ami_event.txt b/doc/CHANGES-staging/flash_ami_event.txt
new file mode 100644 (file)
index 0000000..4cbea80
--- /dev/null
@@ -0,0 +1,3 @@
+Subject: AMI Flash event
+
+Hook flash events are now exposed as AMI events.
index 0efefa7b2e05bb4ffd851cb82fcdf69799b65632..f0e5e47dbe0d5b1ac890b75e85217edea3ee0356 100644 (file)
@@ -416,6 +416,13 @@ struct stasis_message_type *ast_channel_dtmf_begin_type(void);
  */
 struct stasis_message_type *ast_channel_dtmf_end_type(void);
 
+/*!
+ * \brief Message type for when a hook flash occurs on a channel.
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_flash_type(void);
+
 /*!
  * \since 12
  * \brief Message type for when a channel is placed on hold.
index 9154a2c41fef306731b307ab6ccb893f8fc44cb8..f27a0a3900e580def7469b4b01e80c9e4e596d9c 100644 (file)
@@ -3327,6 +3327,7 @@ int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, const char *bre
                                case AST_CONTROL_UPDATE_RTP_PEER:
                                case AST_CONTROL_HOLD:
                                case AST_CONTROL_UNHOLD:
+                               case AST_CONTROL_FLASH:
                                case -1:
                                        /* Unimportant */
                                        break;
@@ -3405,6 +3406,11 @@ static void send_dtmf_end_event(struct ast_channel *chan,
        ast_channel_publish_cached_blob(chan, ast_channel_dtmf_end_type(), blob);
 }
 
+static void send_flash_event(struct ast_channel *chan)
+{
+       ast_channel_publish_blob(chan, ast_channel_flash_type(), NULL);
+}
+
 static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
 {
        struct ast_generator *generator;
@@ -3871,6 +3877,8 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int
                                 */
                                ast_frfree(f);
                                f = &ast_null_frame;
+                       } else if (f->subclass.integer == AST_CONTROL_FLASH) {
+                               send_flash_event(chan);
                        }
                        break;
                case AST_FRAME_DTMF_END:
index 9bc51ed2b6605f1dee547e1e4ec0f9cc5c45310c..943e9f4ab7116b457233987cf10234acc3f35c2f 100644 (file)
@@ -985,6 +985,24 @@ static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub,
                digit, duration_ms, direction);
 }
 
+static void channel_flash_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_message *message)
+{
+       struct ast_channel_blob *obj = stasis_message_data(message);
+       struct ast_str *channel_event_string;
+
+       channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+       if (!channel_event_string) {
+               return;
+       }
+
+       manager_event(EVENT_FLAG_CALL, "Flash",
+               "%s",
+               ast_str_buffer(channel_event_string));
+
+       ast_free(channel_event_string);
+}
+
 static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub,
                struct stasis_message *message)
 {
@@ -1344,6 +1362,9 @@ int manager_channels_init(void)
        ret |= stasis_message_router_add(message_router,
                ast_channel_dtmf_end_type(), channel_dtmf_end_cb, NULL);
 
+       ret |= stasis_message_router_add(message_router,
+               ast_channel_flash_type(), channel_flash_cb, NULL);
+
        ret |= stasis_message_router_add(message_router,
                ast_channel_hangup_request_type(), channel_hangup_request_cb,
                NULL);
index e0c0446c37cdea284a5ec831e17ea97f06c78753..30567abc7177cb9f376699468d77754f4d8c3b0c 100644 (file)
                                                        <enum name="ast_channel_hangup_request_type" />
                                                        <enum name="ast_channel_dtmf_begin_type" />
                                                        <enum name="ast_channel_dtmf_end_type" />
+                                                       <enum name="ast_channel_flash_type" />
                                                        <enum name="ast_channel_hold_type" />
                                                        <enum name="ast_channel_unhold_type" />
                                                        <enum name="ast_channel_chanspy_start_type" />
index e97806cf35321f045cf2ea9e4002f51d94c25924..1da2db5753512cc98dd07612d8851714b311af8a 100644 (file)
@@ -1307,6 +1307,7 @@ STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type,
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type,
        .to_json = unhold_to_json,
        );
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_flash_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);
@@ -1351,6 +1352,7 @@ static void stasis_channels_cleanup(void)
        STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_masquerade_type);
        STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);
        STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_flash_type);
        STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hold_type);
        STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_unhold_type);
        STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type);
@@ -1405,6 +1407,7 @@ int ast_stasis_channels_init(void)
        res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_masquerade_type);
        res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);
        res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);
+       res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_flash_type);
        res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type);
        res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_unhold_type);
        res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);