Skip to content
Snippets Groups Projects
Commit 9a43a7e5 authored by Kinsey Moore's avatar Kinsey Moore
Browse files

Fix two more possible crashes in CEL

These are locations that should return valid snapshots, but need to be
handled if not.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391855 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent bfdff342
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,8 @@ struct ast_bridge_snapshot { ...@@ -39,6 +39,8 @@ struct ast_bridge_snapshot {
AST_STRING_FIELD(uniqueid); AST_STRING_FIELD(uniqueid);
/*! Bridge technology that is handling the bridge */ /*! Bridge technology that is handling the bridge */
AST_STRING_FIELD(technology); 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. /*! AO2 container of bare channel uniqueid strings participating in the bridge.
* Allocated from ast_str_container_alloc() */ * Allocated from ast_str_container_alloc() */
......
...@@ -1283,6 +1283,10 @@ static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub, ...@@ -1283,6 +1283,10 @@ static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
/* create a bridge_assoc for this bridge and mark it as being tracked appropriately */ /* create a bridge_assoc for this bridge and mark it as being tracked appropriately */
chan_snapshot = ast_channel_snapshot_get_latest(channel_id); chan_snapshot = ast_channel_snapshot_get_latest(channel_id);
if (!chan_snapshot) {
return;
}
ast_assert(chan_snapshot != NULL); ast_assert(chan_snapshot != NULL);
assoc = bridge_assoc_alloc(chan_snapshot, new_snapshot->uniqueid, chan_snapshot->name); assoc = bridge_assoc_alloc(chan_snapshot, new_snapshot->uniqueid, chan_snapshot->name);
if (!assoc) { if (!assoc) {
...@@ -1329,6 +1333,10 @@ static void cel_bridge_enter_cb( ...@@ -1329,6 +1333,10 @@ static void cel_bridge_enter_cb(
ao2_iterator_destroy(&i); ao2_iterator_destroy(&i);
latest_primary = ast_channel_snapshot_get_latest(channel_id); latest_primary = ast_channel_snapshot_get_latest(channel_id);
if (!latest_primary) {
return;
}
add_bridge_primary(latest_primary, snapshot->uniqueid, chan_snapshot->name); add_bridge_primary(latest_primary, snapshot->uniqueid, chan_snapshot->name);
report_event_snapshot(latest_primary, AST_CEL_BRIDGE_START, NULL, NULL, chan_snapshot->name); report_event_snapshot(latest_primary, AST_CEL_BRIDGE_START, NULL, NULL, chan_snapshot->name);
} }
......
...@@ -92,6 +92,7 @@ struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge ...@@ -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, uniqueid, bridge->uniqueid);
ast_string_field_set(snapshot, technology, bridge->technology->name); 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->feature_flags = bridge->feature_flags;
snapshot->capabilities = bridge->technology->capabilities; snapshot->capabilities = bridge->technology->capabilities;
...@@ -291,24 +292,68 @@ void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *cha ...@@ -291,24 +292,68 @@ void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *cha
stasis_publish(ast_bridge_topic(bridge), msg); 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) 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); RAII_VAR(struct ast_json *, json_bridge, NULL, ast_json_unref);
int r = 0; struct ast_json *json_channels;
if (snapshot == NULL) { if (snapshot == NULL) {
return NULL; return NULL;
} }
json_chan = ast_json_object_create(); json_channels = container_to_json_array(snapshot->channels,
if (!json_chan) { ast_log(LOG_ERROR, "Error creating channel json object\n"); return NULL; } (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)); json_bridge = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: s, s: s, s: o}",
if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; } "bridgeUniqueid", snapshot->uniqueid,
r = ast_json_object_set(json_chan, "bridge-technology", ast_json_string_create(snapshot->technology)); "bridgeTechnology", snapshot->technology,
if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; } "bridgeType", capability2str(snapshot->capabilities),
"one_to_one", (snapshot->capabilities & AST_BRIDGE_CAPABILITY_1TO1MIX) ? "yes" : "no",
"multimix", (snapshot->capabilities & AST_BRIDGE_CAPABILITY_MULTIMIX) ? "yes" : "no",
"native", (snapshot->capabilities & AST_BRIDGE_CAPABILITY_NATIVE) ? "yes" : "no",
"holding", (snapshot->capabilities & AST_BRIDGE_CAPABILITY_HOLDING) ? "yes" : "no",
"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) struct ast_bridge_snapshot *ast_bridge_snapshot_get_latest(const char *uniqueid)
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
"allowedValues": { "allowedValues": {
"type": "LIST", "type": "LIST",
"values": [ "values": [
"two-party", "mixing",
"multi-party",
"holding" "holding"
] ]
} }
...@@ -240,8 +239,7 @@ ...@@ -240,8 +239,7 @@
"allowedValues": { "allowedValues": {
"type": "LIST", "type": "LIST",
"values": [ "values": [
"two-party", "mixing",
"multi-party",
"holding" "holding"
] ]
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment