static void test_handler(void *data, const char *app_name, struct ast_json *message) { struct app_data *actual = data; int res; ++(actual->invocations); res = ast_json_array_append(actual->messages, ast_json_copy(message)); ast_assert(res == 0); }
static struct ast_json *channel_blob_to_json( struct stasis_message *message, const char *type, const struct stasis_message_sanitizer *sanitize) { RAII_VAR(struct ast_json *, out, NULL, ast_json_unref); struct ast_channel_blob *channel_blob = stasis_message_data(message); struct ast_json *blob = channel_blob->blob; struct ast_channel_snapshot *snapshot = channel_blob->snapshot; const struct timeval *tv = stasis_message_timestamp(message); int res = 0; if (blob == NULL || ast_json_is_null(blob)) { out = ast_json_object_create(); } else { /* blobs are immutable, so shallow copies are fine */ out = ast_json_copy(blob); } if (!out) { return NULL; } res |= ast_json_object_set(out, "type", ast_json_string_create(type)); res |= ast_json_object_set(out, "timestamp", ast_json_timeval(*tv, NULL)); /* For global channel messages, the snapshot is optional */ if (snapshot) { struct ast_json *json_channel = ast_channel_snapshot_to_json(snapshot, sanitize); if (!json_channel) { return NULL; } res |= ast_json_object_set(out, "channel", json_channel); } if (res != 0) { return NULL; } return ast_json_ref(out); }