Make bridge snapshots use prefixes.
authorRichard Mudgett <rmudgett@digium.com>
Thu, 8 Aug 2013 19:16:33 +0000 (19:16 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Thu, 8 Aug 2013 19:16:33 +0000 (19:16 +0000)
* Changed ast_manager_build_bridge_state_string() to assume an empty
prefix string just like ast_manager_build_channel_state_string().

* Created ast_manager_build_bridge_state_string_prefix() to work just like
ast_manager_build_channel_state_string_prefix().

* Made BridgeMerge AMI event use To/From prefixes.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396417 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/confbridge/confbridge_manager.c
include/asterisk/manager.h
main/manager_bridges.c
main/stasis_bridges.c

index e6e859f..57bf64b 100644 (file)
@@ -200,7 +200,7 @@ static void confbridge_publish_manager_event(
        ast_assert(blob != NULL);
        ast_assert(event != NULL);
 
-       bridge_text = ast_manager_build_bridge_state_string(blob->bridge, "");
+       bridge_text = ast_manager_build_bridge_state_string(blob->bridge);
        if (!bridge_text) {
                return;
        }
index 8cceb07..4c36118 100644 (file)
@@ -397,13 +397,27 @@ struct ast_str *ast_manager_str_from_json_object(struct ast_json *blob, key_excl
  *
  * \param snapshot the bridge snapshot for which to generate an AMI message
  *                 body
+ * \param prefix What to prepend to the bridge fields
  *
  * \retval NULL on error
  * \retval ast_str* on success (must be ast_freed by caller)
  */
-struct ast_str *ast_manager_build_bridge_state_string(
+struct ast_str *ast_manager_build_bridge_state_string_prefix(
        const struct ast_bridge_snapshot *snapshot,
-       const char *suffix);
+       const char *prefix);
+
+/*!
+ * \brief Generate the AMI message body from a bridge snapshot
+ * \since 12
+ *
+ * \param snapshot the bridge snapshot for which to generate an AMI message
+ *                 body
+ *
+ * \retval NULL on error
+ * \retval ast_str* on success (must be ast_freed by caller)
+ */
+struct ast_str *ast_manager_build_bridge_state_string(
+       const struct ast_bridge_snapshot *snapshot);
 
 /*! \brief Struct containing info for an AMI event to send out. */
 struct ast_manager_event_blob {
index b045ca5..77d9ff0 100644 (file)
@@ -108,25 +108,26 @@ static struct stasis_message_router *bridge_state_router;
  */
 static struct stasis_subscription *topic_forwarder;
 
-struct ast_str *ast_manager_build_bridge_state_string(
+struct ast_str *ast_manager_build_bridge_state_string_prefix(
        const struct ast_bridge_snapshot *snapshot,
-       const char *suffix)
+       const char *prefix)
 {
        struct ast_str *out = ast_str_create(128);
-       int res = 0;
+       int res;
+
        if (!out) {
                return NULL;
        }
-       res = ast_str_set(&out, 0,
-               "BridgeUniqueid%s: %s\r\n"
-               "BridgeType%s: %s\r\n"
-               "BridgeTechnology%s: %s\r\n"
-               "BridgeNumChannels%s: %d\r\n",
-               suffix, snapshot->uniqueid,
-               suffix, snapshot->subclass,
-               suffix, snapshot->technology,
-               suffix, snapshot->num_channels);
 
+       res = ast_str_set(&out, 0,
+               "%sBridgeUniqueid: %s\r\n"
+               "%sBridgeType: %s\r\n"
+               "%sBridgeTechnology: %s\r\n"
+               "%sBridgeNumChannels: %d\r\n",
+               prefix, snapshot->uniqueid,
+               prefix, snapshot->subclass,
+               prefix, snapshot->technology,
+               prefix, snapshot->num_channels);
        if (!res) {
                ast_free(out);
                return NULL;
@@ -135,6 +136,12 @@ struct ast_str *ast_manager_build_bridge_state_string(
        return out;
 }
 
+struct ast_str *ast_manager_build_bridge_state_string(
+       const struct ast_bridge_snapshot *snapshot)
+{
+       return ast_manager_build_bridge_state_string_prefix(snapshot, "");
+}
+
 /*! \brief Typedef for callbacks that get called on channel snapshot updates */
 typedef struct ast_manager_event_blob *(*bridge_snapshot_monitor)(
        struct ast_bridge_snapshot *old_snapshot,
@@ -201,7 +208,7 @@ static void bridge_snapshot_update(void *data, struct stasis_subscription *sub,
                if (!bridge_event_string) {
                        bridge_event_string =
                                ast_manager_build_bridge_state_string(
-                                       new_snapshot ? new_snapshot : old_snapshot, "");
+                                       new_snapshot ? new_snapshot : old_snapshot);
                        if (!bridge_event_string) {
                                return;
                        }
@@ -224,8 +231,8 @@ static void bridge_merge_cb(void *data, struct stasis_subscription *sub,
        ast_assert(merge_msg->to != NULL);
        ast_assert(merge_msg->from != NULL);
 
-       to_text = ast_manager_build_bridge_state_string(merge_msg->to, "");
-       from_text = ast_manager_build_bridge_state_string(merge_msg->from, "From");
+       to_text = ast_manager_build_bridge_state_string_prefix(merge_msg->to, "To");
+       from_text = ast_manager_build_bridge_state_string_prefix(merge_msg->from, "From");
        if (!to_text || !from_text) {
                return;
        }
@@ -234,7 +241,7 @@ static void bridge_merge_cb(void *data, struct stasis_subscription *sub,
                <managerEventInstance>
                        <synopsis>Raised when two bridges are merged.</synopsis>
                        <syntax>
-                               <bridge_snapshot/>
+                               <bridge_snapshot prefix="To"/>
                                <bridge_snapshot prefix="From"/>
                        </syntax>
                </managerEventInstance>
@@ -256,7 +263,7 @@ static void channel_enter_cb(void *data, struct stasis_subscription *sub,
        RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
        const char *swap_id;
 
-       bridge_text = ast_manager_build_bridge_state_string(blob->bridge, "");
+       bridge_text = ast_manager_build_bridge_state_string(blob->bridge);
        channel_text = ast_manager_build_channel_state_string(blob->channel);
        if (!bridge_text || !channel_text) {
                return;
@@ -283,7 +290,7 @@ static void channel_leave_cb(void *data, struct stasis_subscription *sub,
        RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free);
        RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
 
-       bridge_text = ast_manager_build_bridge_state_string(blob->bridge, "");
+       bridge_text = ast_manager_build_bridge_state_string(blob->bridge);
        channel_text = ast_manager_build_channel_state_string(blob->channel);
        if (!bridge_text || !channel_text) {
                return;
@@ -309,7 +316,7 @@ static int send_bridge_list_item_cb(void *obj, void *arg, void *data, int flags)
        struct ast_bridge_snapshot *snapshot = stasis_message_data(obj);
        struct mansession *s = arg;
        char *id_text = data;
-       RAII_VAR(struct ast_str *, bridge_info, ast_manager_build_bridge_state_string(snapshot, ""), ast_free);
+       RAII_VAR(struct ast_str *, bridge_info, ast_manager_build_bridge_state_string(snapshot), ast_free_ptr);
 
        if (!bridge_info) {
                return 0;
@@ -432,7 +439,7 @@ static int manager_bridge_info(struct mansession *s, const struct message *m)
        astman_send_ack(s, m, "Bridge channel listing will follow");
 
        snapshot = stasis_message_data(msg);
-       bridge_info = ast_manager_build_bridge_state_string(snapshot, "");
+       bridge_info = ast_manager_build_bridge_state_string(snapshot);
 
        ao2_callback_data(snapshot->channels, OBJ_NODATA, send_bridge_info_item_cb, s, ast_str_buffer(id_text));
 
index 865134a..29cc783 100644 (file)
@@ -537,8 +537,7 @@ static struct ast_manager_event_blob *blind_transfer_to_ami(struct stasis_messag
        }
 
        channel_state = ast_manager_build_channel_state_string_prefix(blob->channel, "Transferer");
-       bridge_state = ast_manager_build_bridge_state_string(blob->bridge, "");
-
+       bridge_state = ast_manager_build_bridge_state_string(blob->bridge);
        if (!channel_state || !bridge_state) {
                return NULL;
        }
@@ -605,20 +604,21 @@ static struct ast_manager_event_blob *attended_transfer_to_ami(struct stasis_mes
 
        transferer1_state = ast_manager_build_channel_state_string_prefix(transfer_msg->to_transferee.channel_snapshot, "OrigTransferer");
        transferer2_state = ast_manager_build_channel_state_string_prefix(transfer_msg->to_transfer_target.channel_snapshot, "SecondTransferer");
-
        if (!transferer1_state || !transferer2_state) {
                return NULL;
        }
 
        if (transfer_msg->to_transferee.bridge_snapshot) {
-               bridge1_state = ast_manager_build_bridge_state_string(transfer_msg->to_transferee.bridge_snapshot, "Orig");
+               bridge1_state = ast_manager_build_bridge_state_string_prefix(
+                       transfer_msg->to_transferee.bridge_snapshot, "Orig");
                if (!bridge1_state) {
                        return NULL;
                }
        }
 
        if (transfer_msg->to_transfer_target.bridge_snapshot) {
-               bridge2_state = ast_manager_build_bridge_state_string(transfer_msg->to_transfer_target.bridge_snapshot, "Second");
+               bridge2_state = ast_manager_build_bridge_state_string_prefix(
+                       transfer_msg->to_transfer_target.bridge_snapshot, "Second");
                if (!bridge2_state) {
                        return NULL;
                }