diff options
Diffstat (limited to 'res/res_stasis_json_events.c')
-rw-r--r-- | res/res_stasis_json_events.c | 142 |
1 files changed, 103 insertions, 39 deletions
diff --git a/res/res_stasis_json_events.c b/res/res_stasis_json_events.c index 10d36be42..e96d84e4f 100644 --- a/res/res_stasis_json_events.c +++ b/res/res_stasis_json_events.c @@ -116,30 +116,18 @@ struct ast_json *stasis_json_event_bridge_created_create( return ast_json_ref(message); } -struct ast_json *stasis_json_event_channel_destroyed_create( - struct ast_channel_snapshot *channel_snapshot, +struct ast_json *stasis_json_event_playback_finished_create( struct ast_json *blob ) { RAII_VAR(struct ast_json *, message, NULL, ast_json_unref); RAII_VAR(struct ast_json *, event, NULL, ast_json_unref); struct ast_json *validator; - int ret; - ast_assert(channel_snapshot != NULL); ast_assert(blob != NULL); - ast_assert(ast_json_object_get(blob, "channel") == NULL); ast_assert(ast_json_object_get(blob, "type") == NULL); - validator = ast_json_object_get(blob, "cause"); - if (validator) { - /* do validation? XXX */ - } else { - /* fail message generation if the required parameter doesn't exist */ - return NULL; - } - - validator = ast_json_object_get(blob, "cause_txt"); + validator = ast_json_object_get(blob, "playback"); if (validator) { /* do validation? XXX */ } else { @@ -152,13 +140,7 @@ struct ast_json *stasis_json_event_channel_destroyed_create( return NULL; } - ret = ast_json_object_set(event, - "channel", ast_channel_snapshot_to_json(channel_snapshot)); - if (ret) { - return NULL; - } - - message = ast_json_pack("{s: o}", "channel_destroyed", ast_json_ref(event)); + message = ast_json_pack("{s: o}", "playback_finished", ast_json_ref(event)); if (!message) { return NULL; } @@ -245,29 +227,23 @@ struct ast_json *stasis_json_event_channel_caller_id_create( return ast_json_ref(message); } -struct ast_json *stasis_json_event_channel_hangup_request_create( - struct ast_channel_snapshot *channel_snapshot, +struct ast_json *stasis_json_event_playback_started_create( struct ast_json *blob ) { RAII_VAR(struct ast_json *, message, NULL, ast_json_unref); RAII_VAR(struct ast_json *, event, NULL, ast_json_unref); struct ast_json *validator; - int ret; - ast_assert(channel_snapshot != NULL); ast_assert(blob != NULL); - ast_assert(ast_json_object_get(blob, "channel") == NULL); ast_assert(ast_json_object_get(blob, "type") == NULL); - validator = ast_json_object_get(blob, "soft"); - if (validator) { - /* do validation? XXX */ - } - - validator = ast_json_object_get(blob, "cause"); + validator = ast_json_object_get(blob, "playback"); if (validator) { /* do validation? XXX */ + } else { + /* fail message generation if the required parameter doesn't exist */ + return NULL; } event = ast_json_deep_copy(blob); @@ -275,13 +251,7 @@ struct ast_json *stasis_json_event_channel_hangup_request_create( return NULL; } - ret = ast_json_object_set(event, - "channel", ast_channel_snapshot_to_json(channel_snapshot)); - if (ret) { - return NULL; - } - - message = ast_json_pack("{s: o}", "channel_hangup_request", ast_json_ref(event)); + message = ast_json_pack("{s: o}", "playback_started", ast_json_ref(event)); if (!message) { return NULL; } @@ -350,6 +320,56 @@ struct ast_json *stasis_json_event_application_replaced_create( return ast_json_ref(message); } +struct ast_json *stasis_json_event_channel_destroyed_create( + struct ast_channel_snapshot *channel_snapshot, + struct ast_json *blob + ) +{ + RAII_VAR(struct ast_json *, message, NULL, ast_json_unref); + RAII_VAR(struct ast_json *, event, NULL, ast_json_unref); + struct ast_json *validator; + int ret; + + ast_assert(channel_snapshot != NULL); + ast_assert(blob != NULL); + ast_assert(ast_json_object_get(blob, "channel") == NULL); + ast_assert(ast_json_object_get(blob, "type") == NULL); + + validator = ast_json_object_get(blob, "cause"); + if (validator) { + /* do validation? XXX */ + } else { + /* fail message generation if the required parameter doesn't exist */ + return NULL; + } + + validator = ast_json_object_get(blob, "cause_txt"); + if (validator) { + /* do validation? XXX */ + } else { + /* fail message generation if the required parameter doesn't exist */ + return NULL; + } + + event = ast_json_deep_copy(blob); + if (!event) { + return NULL; + } + + ret = ast_json_object_set(event, + "channel", ast_channel_snapshot_to_json(channel_snapshot)); + if (ret) { + return NULL; + } + + message = ast_json_pack("{s: o}", "channel_destroyed", ast_json_ref(event)); + if (!message) { + return NULL; + } + + return ast_json_ref(message); +} + struct ast_json *stasis_json_event_channel_varset_create( struct ast_channel_snapshot *channel_snapshot, struct ast_json *blob @@ -587,6 +607,50 @@ struct ast_json *stasis_json_event_channel_state_change_create( return ast_json_ref(message); } +struct ast_json *stasis_json_event_channel_hangup_request_create( + struct ast_channel_snapshot *channel_snapshot, + struct ast_json *blob + ) +{ + RAII_VAR(struct ast_json *, message, NULL, ast_json_unref); + RAII_VAR(struct ast_json *, event, NULL, ast_json_unref); + struct ast_json *validator; + int ret; + + ast_assert(channel_snapshot != NULL); + ast_assert(blob != NULL); + ast_assert(ast_json_object_get(blob, "channel") == NULL); + ast_assert(ast_json_object_get(blob, "type") == NULL); + + validator = ast_json_object_get(blob, "soft"); + if (validator) { + /* do validation? XXX */ + } + + validator = ast_json_object_get(blob, "cause"); + if (validator) { + /* do validation? XXX */ + } + + event = ast_json_deep_copy(blob); + if (!event) { + return NULL; + } + + ret = ast_json_object_set(event, + "channel", ast_channel_snapshot_to_json(channel_snapshot)); + if (ret) { + return NULL; + } + + message = ast_json_pack("{s: o}", "channel_hangup_request", ast_json_ref(event)); + if (!message) { + return NULL; + } + + return ast_json_ref(message); +} + struct ast_json *stasis_json_event_channel_entered_bridge_create( struct ast_bridge_snapshot *bridge_snapshot, struct ast_channel_snapshot *channel_snapshot |