summaryrefslogtreecommitdiff
path: root/res/res_stasis_recording.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2013-12-13 16:38:57 +0000
committerKevin Harwell <kharwell@digium.com>2013-12-13 16:38:57 +0000
commitce18946de46a6f16463391a9c07af02b8ee4e925 (patch)
tree3679fcee389fa7725b00389e6bd7f99cf058bb2e /res/res_stasis_recording.c
parentfc8c0ef28f669a53bcab3a862b4ef71b33665b2e (diff)
ARI: Adding a channel to a bridge while a live recording is active blocks
Added the ability to have rules that are checked when adding and/or removing channels to/from a bridge. In this case, if a channel is currently recording and someone attempts to add it to a bridge an "is recording" rule is checked, fails, and a 409 conflict is returned. Also command functions now return an integer value that can be descriptive of what kind of problems, if any, occurred before or during execution. (closes issue ASTERISK-22624) Reported by: Joshua Colp Review: https://reviewboard.asterisk.org/r/2947/ ........ Merged revisions 403749 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403750 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_stasis_recording.c')
-rw-r--r--res/res_stasis_recording.c56
1 files changed, 39 insertions, 17 deletions
diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c
index ecf0cfa49..f0fa1e5f6 100644
--- a/res/res_stasis_recording.c
+++ b/res/res_stasis_recording.c
@@ -244,20 +244,43 @@ static void recording_publish(struct stasis_app_recording *recording, const char
stasis_app_control_publish(recording->control, message);
}
-static void recording_fail(struct stasis_app_recording *recording, const char *cause)
+
+static void recording_set_state(struct stasis_app_recording *recording,
+ enum stasis_app_recording_state state,
+ const char *cause)
{
SCOPED_AO2LOCK(lock, recording);
- recording->state = STASIS_APP_RECORDING_STATE_FAILED;
+ recording->state = state;
recording_publish(recording, cause);
}
+static enum stasis_app_control_channel_result check_rule_recording(
+ const struct stasis_app_control *control)
+{
+ return STASIS_APP_CHANNEL_RECORDING;
+}
+
+struct stasis_app_control_rule rule_recording = {
+ .check_rule = check_rule_recording
+};
+
+static void recording_fail(struct stasis_app_control *control,
+ struct stasis_app_recording *recording,
+ const char *cause)
+{
+ stasis_app_control_unregister_add_rule(control, &rule_recording);
+
+ recording_set_state(
+ recording, STASIS_APP_RECORDING_STATE_FAILED, cause);
+}
+
static void recording_cleanup(struct stasis_app_recording *recording)
{
ao2_unlink_flags(recordings, recording,
OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
}
-static void *record_file(struct stasis_app_control *control,
+static int record_file(struct stasis_app_control *control,
struct ast_channel *chan, void *data)
{
RAII_VAR(struct stasis_app_recording *, recording,
@@ -271,8 +294,8 @@ static void *record_file(struct stasis_app_control *control,
if (stasis_app_get_bridge(control)) {
ast_log(LOG_ERROR, "Cannot record channel while in bridge\n");
- recording_fail(recording, "Cannot record channel while in bridge");
- return NULL;
+ recording_fail(control, recording, "Cannot record channel while in bridge");
+ return -1;
}
switch (recording->options->terminate_on) {
@@ -293,15 +316,12 @@ static void *record_file(struct stasis_app_control *control,
if (res != 0) {
ast_debug(3, "%s: Failed to answer\n",
ast_channel_uniqueid(chan));
- recording_fail(recording, "Failed to answer channel");
- return NULL;
+ recording_fail(control, recording, "Failed to answer channel");
+ return -1;
}
- ao2_lock(recording);
- recording->state = STASIS_APP_RECORDING_STATE_RECORDING;
- recording_publish(recording, NULL);
- ao2_unlock(recording);
-
+ recording_set_state(
+ recording, STASIS_APP_RECORDING_STATE_RECORDING, NULL);
ast_play_and_record_full(chan,
NULL, /* playfile */
recording->absolute_name,
@@ -320,12 +340,12 @@ static void *record_file(struct stasis_app_control *control,
ast_debug(3, "%s: Recording complete\n", ast_channel_uniqueid(chan));
- ao2_lock(recording);
- recording->state = STASIS_APP_RECORDING_STATE_COMPLETE;
- recording_publish(recording, NULL);
- ao2_unlock(recording);
+ recording_set_state(
+ recording, STASIS_APP_RECORDING_STATE_COMPLETE, NULL);
+
+ stasis_app_control_unregister_add_rule(control, &rule_recording);
- return NULL;
+ return 0;
}
static void recording_dtor(void *obj)
@@ -412,6 +432,8 @@ struct stasis_app_recording *stasis_app_control_record(
ao2_link(recordings, recording);
}
+ stasis_app_control_register_add_rule(control, &rule_recording);
+
/* A ref is kept in the recordings container; no need to bump */
stasis_app_send_command_async(control, record_file, recording);