]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
cel: add publish user event helper
authorMike Bradeen <mbradeen@sangoma.com>
Thu, 14 Sep 2023 17:00:19 +0000 (11:00 -0600)
committerMike Bradeen <mbradeen@sangoma.com>
Thu, 21 Sep 2023 14:47:13 +0000 (14:47 +0000)
Add a wrapper function around ast_cel_publish_event that
packs event and extras into a blob before publishing

Resolves:#330

include/asterisk/cel.h
main/cel.c

index 5645e8db2a373049427ed86e461d6c1027499292..81f375be77d1b639db586ebdffa8cef27989953e 100644 (file)
@@ -195,6 +195,22 @@ void ast_cel_publish_event(struct ast_channel *chan,
        enum ast_cel_event_type event_type,
        struct ast_json *blob);
 
+/*!
+ * \brief Publish a CEL user event
+ * \since 18
+ *
+ * \note
+ * This serves as a wrapper function around ast_cel_publish_event() to help pack the
+ * extra details before publishing.
+ *
+ * \param chan This is the primary channel associated with this channel event.
+ * \param event This is the user event being reported.
+ * \param extra This contains any extra parameters that need to be conveyed for this event.
+ */
+void ast_cel_publish_user_event(struct ast_channel *chan,
+       const char *event,
+       const char *extra);
+
 /*!
  * \brief Get the CEL topic
  *
index 942a9afa129ce5ca7a0d424fbc09d7a09f5eb590..d41543c27a7f58c648b5f59d04bf7d4a57005ab2 100644 (file)
@@ -1689,6 +1689,21 @@ static int reload_module(void)
        return 0;
 }
 
+void ast_cel_publish_user_event(struct ast_channel *chan,
+       const char *event,
+       const char *extra)
+{
+       RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
+       blob = ast_json_pack("{s: s, s: {s: s}}",
+               "event", event,
+               "extra", "extra", S_OR(extra, ""));
+       if (!blob) {
+               return;
+       }
+       ast_cel_publish_event(chan, AST_CEL_USER_DEFINED, blob);
+}
+
 void ast_cel_publish_event(struct ast_channel *chan,
        enum ast_cel_event_type event_type,
        struct ast_json *blob)