static int send_bridge_info_item_cb(void *obj, void *arg, void *data, int flags) { char *uniqueid = obj; struct mansession *s = arg; char *id_text = data; RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); struct ast_channel_snapshot *snapshot; RAII_VAR(struct ast_str *, channel_text, NULL, ast_free); msg = stasis_cache_get(ast_channel_cache(), ast_channel_snapshot_type(), uniqueid); if (!msg) { return 0; } snapshot = stasis_message_data(msg); if (snapshot->tech_properties & AST_CHAN_TP_INTERNAL) { return 0; } channel_text = ast_manager_build_channel_state_string(snapshot); if (!channel_text) { return 0; } astman_append(s, "Event: BridgeInfoChannel\r\n" "%s" "%s" "\r\n", ast_str_buffer(channel_text), id_text); return 0; }
void ast_ari_channels_get(struct ast_variable *headers, struct ast_ari_channels_get_args *args, struct ast_ari_response *response) { RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); struct stasis_cache *cache; struct ast_channel_snapshot *snapshot; cache = ast_channel_cache(); if (!cache) { ast_ari_response_error( response, 500, "Internal Server Error", "Message bus not initialized"); return; } msg = stasis_cache_get(cache, ast_channel_snapshot_type(), args->channel_id); if (!msg) { ast_ari_response_error( response, 404, "Not Found", "Channel not found"); return; } snapshot = stasis_message_data(msg); ast_assert(snapshot != NULL); ast_ari_response_ok(response, ast_channel_snapshot_to_json(snapshot, NULL)); }
void ast_ari_channels_list(struct ast_variable *headers, struct ast_ari_channels_list_args *args, struct ast_ari_response *response) { RAII_VAR(struct stasis_cache *, cache, NULL, ao2_cleanup); RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup); RAII_VAR(struct ast_json *, json, NULL, ast_json_unref); struct ao2_iterator i; void *obj; struct stasis_message_sanitizer *sanitize = stasis_app_get_sanitizer(); cache = ast_channel_cache(); if (!cache) { ast_ari_response_error( response, 500, "Internal Server Error", "Message bus not initialized"); return; } ao2_ref(cache, +1); snapshots = stasis_cache_dump(cache, ast_channel_snapshot_type()); if (!snapshots) { ast_ari_response_alloc_failed(response); return; } json = ast_json_array_create(); if (!json) { ast_ari_response_alloc_failed(response); return; } for (i = ao2_iterator_init(snapshots, 0); (obj = ao2_iterator_next(&i)); ao2_cleanup(obj)) { RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup); struct ast_channel_snapshot *snapshot = stasis_message_data(msg); int r; if (sanitize && sanitize->channel_snapshot && sanitize->channel_snapshot(snapshot)) { continue; } r = ast_json_array_append( json, ast_channel_snapshot_to_json(snapshot, NULL)); if (r != 0) { ast_ari_response_alloc_failed(response); ao2_cleanup(obj); ao2_iterator_destroy(&i); return; } } ao2_iterator_destroy(&i); ast_ari_response_ok(response, ast_json_ref(json)); }
struct ast_channel_snapshot *stasis_app_control_get_snapshot( const struct stasis_app_control *control) { RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); struct ast_channel_snapshot *snapshot; msg = stasis_cache_get(ast_channel_cache(), ast_channel_snapshot_type(), stasis_app_control_get_channel_id(control)); if (!msg) { return NULL; } snapshot = stasis_message_data(msg); ast_assert(snapshot != NULL); ao2_ref(snapshot, +1); return snapshot; }
struct ast_channel_snapshot *ast_channel_snapshot_get_latest(const char *uniqueid) { RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup); struct ast_channel_snapshot *snapshot; ast_assert(!ast_strlen_zero(uniqueid)); message = stasis_cache_get(ast_channel_cache(), ast_channel_snapshot_type(), uniqueid); if (!message) { return NULL; } snapshot = stasis_message_data(message); if (!snapshot) { return NULL; } ao2_ref(snapshot, +1); return snapshot; }