]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix bridge snapshot conversion to JSON
authorKinsey Moore <kmoore@digium.com>
Tue, 18 Jun 2013 14:30:06 +0000 (14:30 +0000)
committerKinsey Moore <kmoore@digium.com>
Tue, 18 Jun 2013 14:30:06 +0000 (14:30 +0000)
This makes ast_bridge_snapshot_to_json conform to the swagger Bridge
model by adding the two fields it required.

Review: https://reviewboard.asterisk.org/r/2583/

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

include/asterisk/stasis_bridging.h
main/stasis_bridging.c
rest-api/api-docs/bridges.json

index a9366e73dc8dbd0b913d4912629d95a1ab5705b7..76f4a9fed38796d61cb1dda9f27e85d561a3dd61 100644 (file)
@@ -39,6 +39,8 @@ struct ast_bridge_snapshot {
                AST_STRING_FIELD(uniqueid);
                /*! Bridge technology that is handling the bridge */
                AST_STRING_FIELD(technology);
+               /*! Bridge subclass that is handling the bridge */
+               AST_STRING_FIELD(subclass);
        );
        /*! AO2 container of bare channel uniqueid strings participating in the bridge.
         * Allocated from ast_str_container_alloc() */
index 0200d05e78aabb836ec51eb01f048aa8bc46276d..3c4ac1fb176d9475e42aac191da2461877d15efa 100644 (file)
@@ -92,6 +92,7 @@ struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge
 
        ast_string_field_set(snapshot, uniqueid, bridge->uniqueid);
        ast_string_field_set(snapshot, technology, bridge->technology->name);
+       ast_string_field_set(snapshot, subclass, bridge->v_table->name);
 
        snapshot->feature_flags = bridge->feature_flags;
        snapshot->capabilities = bridge->technology->capabilities;
@@ -291,24 +292,64 @@ void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *cha
        stasis_publish(ast_bridge_topic(bridge), msg);
 }
 
+typedef struct ast_json *(*json_item_serializer_cb)(void *obj);
+
+static struct ast_json *container_to_json_array(struct ao2_container *items, json_item_serializer_cb item_cb)
+{
+       RAII_VAR(struct ast_json *, json_items, ast_json_array_create(), ast_json_unref);
+       void *item;
+       struct ao2_iterator it;
+       if (!json_items) {
+               return NULL;
+       }
+
+       it = ao2_iterator_init(items, 0);
+       while ((item = ao2_iterator_next(&it))) {
+               if (ast_json_array_append(json_items, item_cb(item))) {
+                       ao2_iterator_destroy(&it);
+                       return NULL;
+               }
+       }
+       ao2_iterator_destroy(&it);
+
+       return ast_json_ref(json_items);
+}
+
+static const char *capability2str(uint32_t capabilities)
+{
+       if (capabilities & AST_BRIDGE_CAPABILITY_HOLDING) {
+               return "holding";
+       } else {
+               return "mixing";
+       }
+}
+
 struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot)
 {
-       RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);
-       int r = 0;
+       RAII_VAR(struct ast_json *, json_bridge, NULL, ast_json_unref);
+       struct ast_json *json_channels;
 
        if (snapshot == NULL) {
                return NULL;
        }
 
-       json_chan = ast_json_object_create();
-       if (!json_chan) { ast_log(LOG_ERROR, "Error creating channel json object\n"); return NULL; }
+       json_channels = container_to_json_array(snapshot->channels,
+               (json_item_serializer_cb)ast_json_string_create);
+       if (!json_channels) {
+               return NULL;
+       }
 
-       r = ast_json_object_set(json_chan, "bridge-uniqueid", ast_json_string_create(snapshot->uniqueid));
-       if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
-       r = ast_json_object_set(json_chan, "bridge-technology", ast_json_string_create(snapshot->technology));
-       if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+       json_bridge = ast_json_pack("{s: s, s: s, s: s, s: s, s: o}",
+               "bridgeUniqueid", snapshot->uniqueid,
+               "bridgeTechnology", snapshot->technology,
+               "bridgeType", capability2str(snapshot->capabilities),
+               "bridgeClass", snapshot->subclass,
+               "channels", json_channels);
+       if (!json_bridge) {
+               return NULL;
+       }
 
-       return ast_json_ref(json_chan);
+       return ast_json_ref(json_bridge);
 }
 
 struct ast_bridge_snapshot *ast_bridge_snapshot_get_latest(const char *uniqueid)
index e4a33f8c33f487b20d7705f73bfb4f3501371bb8..5b0cf629852958dfa0427b6a6ee5cd358783a807 100644 (file)
@@ -34,8 +34,7 @@
                                                        "allowedValues": {
                                                                "type": "LIST",
                                                                "values": [
-                                                                       "two-party",
-                                                                       "multi-party",
+                                                                       "mixing",
                                                                        "holding"
                                                                ]
                                                        }
                                        "allowedValues": {
                                                "type": "LIST",
                                                "values": [
-                                                       "two-party",
-                                                       "multi-party",
+                                                       "mixing",
                                                        "holding"
                                                ]
                                        }