aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'res/res_monitor.c')
-rw-r--r--res/res_monitor.c67
1 files changed, 44 insertions, 23 deletions
diff --git a/res/res_monitor.c b/res/res_monitor.c
index 6bd96fbca..dde35a9be 100644
--- a/res/res_monitor.c
+++ b/res/res_monitor.c
@@ -579,34 +579,41 @@ static int start_monitor_action(struct mansession *s, const struct message *m)
astman_send_error(s, m, "No channel specified");
return 0;
}
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return 0;
}
if (ast_strlen_zero(fname)) {
- /* No filename base specified, default to channel name as per CLI */
+ /* No filename base specified, default to channel name as per CLI */
+ ast_channel_lock(c);
fname = ast_strdupa(c->name);
+ ast_channel_unlock(c);
/* Channels have the format technology/channel_name - have to replace that / */
- if ((d = strchr(fname, '/')))
+ if ((d = strchr(fname, '/'))) {
*d = '-';
+ }
}
if (ast_monitor_start(c, format, fname, 1, X_REC_IN | X_REC_OUT)) {
if (ast_monitor_change_fname(c, fname, 1)) {
astman_send_error(s, m, "Could not start monitoring channel");
- ast_channel_unlock(c);
+ c = ast_channel_unref(c);
return 0;
}
}
if (ast_true(mix)) {
+ ast_channel_lock(c);
ast_monitor_setjoinfiles(c, 1);
+ ast_channel_unlock(c);
}
- ast_channel_unlock(c);
+ c = ast_channel_unref(c);
+
astman_send_ack(s, m, "Started monitoring channel");
+
return 0;
}
@@ -621,22 +628,28 @@ static int stop_monitor_action(struct mansession *s, const struct message *m)
struct ast_channel *c = NULL;
const char *name = astman_get_header(m, "Channel");
int res;
+
if (ast_strlen_zero(name)) {
astman_send_error(s, m, "No channel specified");
return 0;
}
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return 0;
}
+
res = ast_monitor_stop(c, 1);
- ast_channel_unlock(c);
+
+ c = ast_channel_unref(c);
+
if (res) {
astman_send_error(s, m, "Could not stop monitoring channel");
return 0;
}
+
astman_send_ack(s, m, "Stopped monitoring channel");
+
return 0;
}
@@ -654,26 +667,32 @@ static int change_monitor_action(struct mansession *s, const struct message *m)
struct ast_channel *c = NULL;
const char *name = astman_get_header(m, "Channel");
const char *fname = astman_get_header(m, "File");
+
if (ast_strlen_zero(name)) {
astman_send_error(s, m, "No channel specified");
return 0;
}
+
if (ast_strlen_zero(fname)) {
astman_send_error(s, m, "No filename specified");
return 0;
}
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return 0;
}
+
if (ast_monitor_change_fname(c, fname, 1)) {
+ c = ast_channel_unref(c);
astman_send_error(s, m, "Could not change monitored filename of channel");
- ast_channel_unlock(c);
return 0;
}
- ast_channel_unlock(c);
+
+ c = ast_channel_unref(c);
+
astman_send_ack(s, m, "Changed monitor filename");
+
return 0;
}
@@ -688,31 +707,33 @@ enum MONITOR_PAUSING_ACTION
MONITOR_ACTION_PAUSE,
MONITOR_ACTION_UNPAUSE
};
-
+
static int do_pause_or_unpause(struct mansession *s, const struct message *m, int action)
{
struct ast_channel *c = NULL;
const char *name = astman_get_header(m, "Channel");
-
+
if (ast_strlen_zero(name)) {
astman_send_error(s, m, "No channel specified");
return -1;
}
-
- c = ast_get_channel_by_name_locked(name);
- if (!c) {
+
+ if (!(c = ast_channel_get_by_name(name))) {
astman_send_error(s, m, "No such channel");
return -1;
}
- if (action == MONITOR_ACTION_PAUSE)
+ if (action == MONITOR_ACTION_PAUSE) {
ast_monitor_pause(c);
- else
+ } else {
ast_monitor_unpause(c);
-
- ast_channel_unlock(c);
+ }
+
+ c = ast_channel_unref(c);
+
astman_send_ack(s, m, (action == MONITOR_ACTION_PAUSE ? "Paused monitoring of the channel" : "Unpaused monitoring of the channel"));
- return 0;
+
+ return 0;
}
static char pause_monitor_action_help[] =