2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief PBX channel monitoring
23 * \author Mark Spencer <markster@digium.com>
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33 #include "asterisk/paths.h" /* use ast_config_AST_MONITOR_DIR */
34 #include "asterisk/lock.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/file.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/module.h"
39 #include "asterisk/manager.h"
40 #include "asterisk/cli.h"
41 #define AST_API_MODULE
42 #include "asterisk/monitor.h"
43 #include "asterisk/app.h"
44 #include "asterisk/utils.h"
45 #include "asterisk/config.h"
46 #include "asterisk/options.h"
49 <application name="Monitor" language="en_US">
54 <parameter name="file_format" argsep=":">
55 <argument name="file_format" required="true">
56 <para>optional, if not set, defaults to <literal>wav</literal></para>
58 <argument name="urlbase" />
60 <parameter name="fname_base">
61 <para>if set, changes the filename used to the one specified.</para>
63 <parameter name="options">
66 <para>when the recording ends mix the two leg files into one and
67 delete the two leg files. If the variable <variable>MONITOR_EXEC</variable>
68 is set, the application referenced in it will be executed instead of
69 soxmix/sox and the raw leg files will NOT be deleted automatically.
70 soxmix/sox or <variable>MONITOR_EXEC</variable> is handed 3 arguments,
71 the two leg files and a target mixed file name which is the same as
72 the leg file names only without the in/out designator.</para>
73 <para>If <variable>MONITOR_EXEC_ARGS</variable> is set, the contents
74 will be passed on as additional arguments to <variable>MONITOR_EXEC</variable>.
75 Both <variable>MONITOR_EXEC</variable> and the Mix flag can be set from the
76 administrator interface.</para>
79 <para>Don't begin recording unless a call is bridged to another channel.</para>
82 <para>Skip recording of input stream (disables <literal>m</literal> option).</para>
85 <para>Skip recording of output stream (disables <literal>m</literal> option).</para>
91 <para>Used to start monitoring a channel. The channel's input and output
92 voice packets are logged to files until the channel hangs up or
93 monitoring is stopped by the StopMonitor application.</para>
94 <para>By default, files are stored to <filename>/var/spool/asterisk/monitor/</filename>.
95 Returns <literal>-1</literal> if monitor files can't be opened or if the channel is
96 already monitored, otherwise <literal>0</literal>.</para>
99 <ref type="application">StopMonitor</ref>
102 <application name="StopMonitor" language="en_US">
104 Stop monitoring a channel.
108 <para>Stops monitoring a channel. Has no effect if the channel is not monitored.</para>
111 <application name="ChangeMonitor" language="en_US">
113 Change monitoring filename of a channel.
116 <parameter name="filename_base" required="true">
117 <para>The new filename base to use for monitoring this channel.</para>
121 <para>Changes monitoring filename of a channel. Has no effect if the
122 channel is not monitored.</para>
125 <application name="PauseMonitor" language="en_US">
127 Pause monitoring of a channel.
131 <para>Pauses monitoring of a channel until it is re-enabled by a call to UnpauseMonitor.</para>
134 <ref type="application">UnpauseMonitor</ref>
137 <application name="UnpauseMonitor" language="en_US">
139 Unpause monitoring of a channel.
143 <para>Unpauses monitoring of a channel on which monitoring had
144 previously been paused with PauseMonitor.</para>
147 <ref type="application">PauseMonitor</ref>
150 <manager name="Monitor" language="en_US">
155 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
156 <parameter name="Channel" required="true">
157 <para>Used to specify the channel to record.</para>
159 <parameter name="File">
160 <para>Is the name of the file created in the monitor spool directory.
161 Defaults to the same name as the channel (with slashes replaced with dashes).</para>
163 <parameter name="Format">
164 <para>Is the audio recording format. Defaults to <literal>wav</literal>.</para>
166 <parameter name="Mix">
167 <para>Boolean parameter as to whether to mix the input and output channels
168 together after the recording is finished.</para>
172 <para>This action may be used to record the audio on a
173 specified channel.</para>
176 <manager name="StopMonitor" language="en_US">
178 Stop monitoring a channel.
181 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
182 <parameter name="Channel" required="true">
183 <para>The name of the channel monitored.</para>
187 <para>This action may be used to end a previously started 'Monitor' action.</para>
190 <manager name="ChangeMonitor" language="en_US">
192 Change monitoring filename of a channel.
195 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
196 <parameter name="Channel" required="true">
197 <para>Used to specify the channel to record.</para>
199 <parameter name="File" required="true">
200 <para>Is the new name of the file created in the
201 monitor spool directory.</para>
205 <para>This action may be used to change the file
206 started by a previous 'Monitor' action.</para>
209 <manager name="PauseMonitor" language="en_US">
211 Pause monitoring of a channel.
214 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
215 <parameter name="Channel" required="true">
216 <para>Used to specify the channel to record.</para>
220 <para>This action may be used to temporarily stop the
221 recording of a channel.</para>
224 <manager name="UnpauseMonitor" language="en_US">
226 Unpause monitoring of a channel.
229 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
230 <parameter name="Channel" required="true">
231 <para>Used to specify the channel to record.</para>
235 <para>This action may be used to re-enable recording
236 of a channel after calling PauseMonitor.</para>
242 AST_MUTEX_DEFINE_STATIC(monitorlock);
244 #define LOCK_IF_NEEDED(lock, needed) do { \
246 ast_channel_lock(lock); \
249 #define UNLOCK_IF_NEEDED(lock, needed) do { \
251 ast_channel_unlock(lock); \
254 static unsigned long seq = 0;
257 * \brief Change state of monitored channel
259 * \param state monitor state
260 * \retval 0 on success.
261 * \retval -1 on failure.
263 static int ast_monitor_set_state(struct ast_channel *chan, int state)
265 LOCK_IF_NEEDED(chan, 1);
266 if (!chan->monitor) {
267 UNLOCK_IF_NEEDED(chan, 1);
270 chan->monitor->state = state;
271 UNLOCK_IF_NEEDED(chan, 1);
275 /*! \brief Start monitoring a channel
276 * \param chan ast_channel struct to record
277 * \param format_spec file format to use for recording
278 * \param fname_base filename base to record to
279 * \param need_lock whether to lock the channel mutex
280 * \param stream_action whether to record the input and/or output streams. X_REC_IN | X_REC_OUT is most often used
281 * Creates the file to record, if no format is specified it assumes WAV
282 * It also sets channel variable __MONITORED=yes
283 * \retval 0 on success
284 * \retval -1 on failure
286 int AST_OPTIONAL_API_NAME(ast_monitor_start)(struct ast_channel *chan, const char *format_spec,
287 const char *fname_base, int need_lock, int stream_action)
291 LOCK_IF_NEEDED(chan, need_lock);
293 if (!(chan->monitor)) {
294 struct ast_channel_monitor *monitor;
295 char *channel_name, *p;
297 /* Create monitoring directory if needed */
298 ast_mkdir(ast_config_AST_MONITOR_DIR, 0777);
300 if (!(monitor = ast_calloc(1, sizeof(*monitor)))) {
301 UNLOCK_IF_NEEDED(chan, need_lock);
305 /* Determine file names */
306 if (!ast_strlen_zero(fname_base)) {
307 int directory = strchr(fname_base, '/') ? 1 : 0;
308 const char *absolute = *fname_base == '/' ? "" : ast_config_AST_MONITOR_DIR;
309 const char *absolute_suffix = *fname_base == '/' ? "" : "/";
311 snprintf(monitor->read_filename, FILENAME_MAX, "%s%s%s-in",
312 absolute, absolute_suffix, fname_base);
313 snprintf(monitor->write_filename, FILENAME_MAX, "%s%s%s-out",
314 absolute, absolute_suffix, fname_base);
315 snprintf(monitor->filename_base, FILENAME_MAX, "%s%s%s",
316 absolute, absolute_suffix, fname_base);
318 /* try creating the directory just in case it doesn't exist */
320 char *name = ast_strdupa(monitor->filename_base);
321 ast_mkdir(dirname(name), 0777);
324 ast_mutex_lock(&monitorlock);
325 snprintf(monitor->read_filename, FILENAME_MAX, "%s/audio-in-%ld",
326 ast_config_AST_MONITOR_DIR, seq);
327 snprintf(monitor->write_filename, FILENAME_MAX, "%s/audio-out-%ld",
328 ast_config_AST_MONITOR_DIR, seq);
330 ast_mutex_unlock(&monitorlock);
332 channel_name = ast_strdupa(chan->name);
333 while ((p = strchr(channel_name, '/'))) {
336 snprintf(monitor->filename_base, FILENAME_MAX, "%s/%d-%s",
337 ast_config_AST_MONITOR_DIR, (int)time(NULL), channel_name);
338 monitor->filename_changed = 1;
341 monitor->stop = ast_monitor_stop;
343 /* Determine file format */
344 if (!ast_strlen_zero(format_spec)) {
345 monitor->format = ast_strdup(format_spec);
347 monitor->format = ast_strdup("wav");
351 if (stream_action & X_REC_IN) {
352 if (ast_fileexists(monitor->read_filename, NULL, NULL) > 0)
353 ast_filedelete(monitor->read_filename, NULL);
354 if (!(monitor->read_stream = ast_writefile(monitor->read_filename,
355 monitor->format, NULL,
356 O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
357 ast_log(LOG_WARNING, "Could not create file %s\n",
358 monitor->read_filename);
360 UNLOCK_IF_NEEDED(chan, need_lock);
364 monitor->read_stream = NULL;
366 if (stream_action & X_REC_OUT) {
367 if (ast_fileexists(monitor->write_filename, NULL, NULL) > 0) {
368 ast_filedelete(monitor->write_filename, NULL);
370 if (!(monitor->write_stream = ast_writefile(monitor->write_filename,
371 monitor->format, NULL,
372 O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
373 ast_log(LOG_WARNING, "Could not create file %s\n",
374 monitor->write_filename);
375 ast_closestream(monitor->read_stream);
377 UNLOCK_IF_NEEDED(chan, need_lock);
381 monitor->write_stream = NULL;
383 chan->monitor = monitor;
384 ast_monitor_set_state(chan, AST_MONITOR_RUNNING);
385 /* so we know this call has been monitored in case we need to bill for it or something */
386 pbx_builtin_setvar_helper(chan, "__MONITORED","true");
388 ast_manager_event(chan, EVENT_FLAG_CALL, "MonitorStart",
394 ast_debug(1,"Cannot start monitoring %s, already monitored\n", chan->name);
398 UNLOCK_IF_NEEDED(chan, need_lock);
404 * \brief Get audio format.
405 * \param format recording format.
406 * The file format extensions that Asterisk uses are not all the same as that
407 * which soxmix expects. This function ensures that the format used as the
408 * extension on the filename is something soxmix will understand.
410 static const char *get_soxmix_format(const char *format)
412 const char *res = format;
414 if (!strcasecmp(format,"ulaw"))
416 if (!strcasecmp(format,"alaw"))
423 * \brief Stop monitoring channel
426 * Stop the recording, close any open streams, mix in/out channels if required
429 int AST_OPTIONAL_API_NAME(ast_monitor_stop)(struct ast_channel *chan, int need_lock)
433 LOCK_IF_NEEDED(chan, need_lock);
436 char filename[ FILENAME_MAX ];
438 if (chan->monitor->read_stream) {
439 ast_closestream(chan->monitor->read_stream);
441 if (chan->monitor->write_stream) {
442 ast_closestream(chan->monitor->write_stream);
445 if (chan->monitor->filename_changed && !ast_strlen_zero(chan->monitor->filename_base)) {
446 if (ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0) {
447 snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base);
448 if (ast_fileexists(filename, NULL, NULL) > 0) {
449 ast_filedelete(filename, NULL);
451 ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format);
453 ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename);
456 if (ast_fileexists(chan->monitor->write_filename,NULL,NULL) > 0) {
457 snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base);
458 if (ast_fileexists(filename, NULL, NULL) > 0) {
459 ast_filedelete(filename, NULL);
461 ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format);
463 ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename);
467 if (chan->monitor->joinfiles && !ast_strlen_zero(chan->monitor->filename_base)) {
470 const char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format;
471 char *fname_base = chan->monitor->filename_base;
472 const char *execute, *execute_args;
473 /* at this point, fname_base really is the full path */
475 /* Set the execute application */
476 execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC");
477 if (ast_strlen_zero(execute)) {
479 execute = "nice -n 19 soxmix";
481 execute = "nice -n 19 sox -m";
483 format = get_soxmix_format(format);
486 execute_args = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC_ARGS");
487 if (ast_strlen_zero(execute_args)) {
491 snprintf(tmp, sizeof(tmp), "%s \"%s-in.%s\" \"%s-out.%s\" \"%s.%s\" %s &",
492 execute, fname_base, format, fname_base, format, fname_base, format,execute_args);
494 snprintf(tmp2,sizeof(tmp2), "( %s& rm -f \"%s-\"* ) &",tmp, fname_base); /* remove legs when done mixing */
495 ast_copy_string(tmp, tmp2, sizeof(tmp));
497 ast_debug(1,"monitor executing %s\n",tmp);
498 if (ast_safe_system(tmp) == -1)
499 ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp);
502 ast_free(chan->monitor->format);
503 ast_free(chan->monitor);
504 chan->monitor = NULL;
506 ast_manager_event(chan, EVENT_FLAG_CALL, "MonitorStop",
514 UNLOCK_IF_NEEDED(chan, need_lock);
520 /*! \brief Pause monitoring of channel */
521 int AST_OPTIONAL_API_NAME(ast_monitor_pause)(struct ast_channel *chan)
523 return ast_monitor_set_state(chan, AST_MONITOR_PAUSED);
526 /*! \brief Unpause monitoring of channel */
527 int AST_OPTIONAL_API_NAME(ast_monitor_unpause)(struct ast_channel *chan)
529 return ast_monitor_set_state(chan, AST_MONITOR_RUNNING);
532 /*! \brief Wrapper for ast_monitor_pause */
533 static int pause_monitor_exec(struct ast_channel *chan, const char *data)
535 return ast_monitor_pause(chan);
538 /*! \brief Wrapper for ast_monitor_unpause */
539 static int unpause_monitor_exec(struct ast_channel *chan, const char *data)
541 return ast_monitor_unpause(chan);
545 * \brief Change monitored filename of channel
547 * \param fname_base new filename
549 * \retval 0 on success.
550 * \retval -1 on failure.
552 int AST_OPTIONAL_API_NAME(ast_monitor_change_fname)(struct ast_channel *chan, const char *fname_base, int need_lock)
554 if (ast_strlen_zero(fname_base)) {
555 ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to null\n", chan->name);
559 LOCK_IF_NEEDED(chan, need_lock);
562 int directory = strchr(fname_base, '/') ? 1 : 0;
563 const char *absolute = *fname_base == '/' ? "" : ast_config_AST_MONITOR_DIR;
564 const char *absolute_suffix = *fname_base == '/' ? "" : "/";
565 char tmpstring[sizeof(chan->monitor->filename_base)] = "";
566 int i, fd[2] = { -1, -1 }, doexit = 0;
568 /* before continuing, see if we're trying to rename the file to itself... */
569 snprintf(tmpstring, sizeof(tmpstring), "%s%s%s", absolute, absolute_suffix, fname_base);
571 /* try creating the directory just in case it doesn't exist */
573 char *name = ast_strdupa(tmpstring);
574 ast_mkdir(dirname(name), 0777);
577 /*!\note We cannot just compare filenames, due to symlinks, relative
578 * paths, and other possible filesystem issues. We could use
579 * realpath(3), but its use is discouraged. However, if we try to
580 * create the same file from two different paths, the second will
581 * fail, and so we have our notification that the filenames point to
584 * Remember, also, that we're using the basename of the file (i.e.
585 * the file without the format suffix), so it does not already exist
586 * and we aren't interfering with the recording itself.
588 ast_debug(2, "comparing tmpstring %s to filename_base %s\n", tmpstring, chan->monitor->filename_base);
590 if ((fd[0] = open(tmpstring, O_CREAT | O_WRONLY, 0644)) < 0 ||
591 (fd[1] = open(chan->monitor->filename_base, O_CREAT | O_EXCL | O_WRONLY, 0644)) < 0) {
593 ast_log(LOG_ERROR, "Unable to compare filenames: %s\n", strerror(errno));
595 ast_debug(2, "No need to rename monitor filename to itself\n");
600 /* Cleanup temporary files */
601 for (i = 0; i < 2; i++) {
603 while (close(fd[i]) < 0 && errno == EINTR);
607 /* if previous monitor file existed in a subdirectory, the directory will not be removed */
608 unlink(chan->monitor->filename_base);
611 UNLOCK_IF_NEEDED(chan, need_lock);
615 ast_copy_string(chan->monitor->filename_base, tmpstring, sizeof(chan->monitor->filename_base));
616 chan->monitor->filename_changed = 1;
618 ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to %s, monitoring not started\n", chan->name, fname_base);
621 UNLOCK_IF_NEEDED(chan, need_lock);
628 * \brief Start monitor
630 * \param data arguments passed fname|options
631 * \retval 0 on success.
632 * \retval -1 on failure.
634 static int start_monitor_exec(struct ast_channel *chan, const char *data)
637 char *options = NULL;
639 char *urlprefix = NULL;
641 int stream_action = X_REC_IN | X_REC_OUT;
643 int waitforbridge = 0;
646 AST_DECLARE_APP_ARGS(args,
648 AST_APP_ARG(fname_base);
649 AST_APP_ARG(options);
652 /* Parse arguments. */
653 if (ast_strlen_zero(data)) {
654 ast_log(LOG_ERROR, "Monitor requires an argument\n");
658 parse = ast_strdupa(data);
659 AST_STANDARD_APP_ARGS(args, parse);
661 if (!ast_strlen_zero(args.options)) {
662 if (strchr(args.options, 'm'))
663 stream_action |= X_JOIN;
664 if (strchr(args.options, 'b'))
666 if (strchr(args.options, 'i'))
667 stream_action &= ~X_REC_IN;
668 if (strchr(args.options, 'o'))
669 stream_action &= ~X_REC_OUT;
672 arg = strchr(args.format, ':');
679 snprintf(tmp, sizeof(tmp), "%s/%s.%s", urlprefix, args.fname_base,
680 ((strcmp(args.format, "gsm")) ? "wav" : "gsm"));
681 if (!chan->cdr && !(chan->cdr = ast_cdr_alloc()))
683 ast_cdr_setuserfield(chan, tmp);
686 /* We must remove the "b" option if listed. In principle none of
687 the following could give NULL results, but we check just to
688 be pedantic. Reconstructing with checks for 'm' option does not
689 work if we end up adding more options than 'm' in the future. */
690 delay = ast_strdupa(data);
691 options = strrchr(delay, ',');
693 arg = strchr(options, 'b');
696 pbx_builtin_setvar_helper(chan,"AUTO_MONITOR", delay);
702 res = ast_monitor_start(chan, args.format, args.fname_base, 1, stream_action);
704 res = ast_monitor_change_fname(chan, args.fname_base, 1);
706 if (stream_action & X_JOIN) {
707 if ((stream_action & X_REC_IN) && (stream_action & X_REC_OUT))
710 ast_log(LOG_WARNING, "Won't mix streams unless both input and output streams are recorded\n");
712 ast_monitor_setjoinfiles(chan, joinfiles);
717 /*! \brief Wrapper function \see ast_monitor_stop */
718 static int stop_monitor_exec(struct ast_channel *chan, const char *data)
720 return ast_monitor_stop(chan, 1);
723 /*! \brief Wrapper function \see ast_monitor_change_fname */
724 static int change_monitor_exec(struct ast_channel *chan, const char *data)
726 return ast_monitor_change_fname(chan, data, 1);
729 /*! \brief Start monitoring a channel by manager connection */
730 static int start_monitor_action(struct mansession *s, const struct message *m)
732 struct ast_channel *c = NULL;
733 const char *name = astman_get_header(m, "Channel");
734 const char *fname = astman_get_header(m, "File");
735 const char *format = astman_get_header(m, "Format");
736 const char *mix = astman_get_header(m, "Mix");
739 if (ast_strlen_zero(name)) {
740 astman_send_error(s, m, "No channel specified");
744 if (!(c = ast_channel_get_by_name(name))) {
745 astman_send_error(s, m, "No such channel");
749 if (ast_strlen_zero(fname)) {
750 /* No filename base specified, default to channel name as per CLI */
752 fname = ast_strdupa(c->name);
753 ast_channel_unlock(c);
754 /* Channels have the format technology/channel_name - have to replace that / */
755 if ((d = strchr(fname, '/'))) {
760 if (ast_monitor_start(c, format, fname, 1, X_REC_IN | X_REC_OUT)) {
761 if (ast_monitor_change_fname(c, fname, 1)) {
762 astman_send_error(s, m, "Could not start monitoring channel");
763 c = ast_channel_unref(c);
770 ast_monitor_setjoinfiles(c, 1);
771 ast_channel_unlock(c);
774 c = ast_channel_unref(c);
776 astman_send_ack(s, m, "Started monitoring channel");
781 /*! \brief Stop monitoring a channel by manager connection */
782 static int stop_monitor_action(struct mansession *s, const struct message *m)
784 struct ast_channel *c = NULL;
785 const char *name = astman_get_header(m, "Channel");
788 if (ast_strlen_zero(name)) {
789 astman_send_error(s, m, "No channel specified");
793 if (!(c = ast_channel_get_by_name(name))) {
794 astman_send_error(s, m, "No such channel");
798 res = ast_monitor_stop(c, 1);
800 c = ast_channel_unref(c);
803 astman_send_error(s, m, "Could not stop monitoring channel");
807 astman_send_ack(s, m, "Stopped monitoring channel");
812 /*! \brief Change filename of a monitored channel by manager connection */
813 static int change_monitor_action(struct mansession *s, const struct message *m)
815 struct ast_channel *c = NULL;
816 const char *name = astman_get_header(m, "Channel");
817 const char *fname = astman_get_header(m, "File");
819 if (ast_strlen_zero(name)) {
820 astman_send_error(s, m, "No channel specified");
824 if (ast_strlen_zero(fname)) {
825 astman_send_error(s, m, "No filename specified");
829 if (!(c = ast_channel_get_by_name(name))) {
830 astman_send_error(s, m, "No such channel");
834 if (ast_monitor_change_fname(c, fname, 1)) {
835 c = ast_channel_unref(c);
836 astman_send_error(s, m, "Could not change monitored filename of channel");
840 c = ast_channel_unref(c);
842 astman_send_ack(s, m, "Changed monitor filename");
847 void AST_OPTIONAL_API_NAME(ast_monitor_setjoinfiles)(struct ast_channel *chan, int turnon)
850 chan->monitor->joinfiles = turnon;
853 enum MONITOR_PAUSING_ACTION
855 MONITOR_ACTION_PAUSE,
856 MONITOR_ACTION_UNPAUSE
859 static int do_pause_or_unpause(struct mansession *s, const struct message *m, int action)
861 struct ast_channel *c = NULL;
862 const char *name = astman_get_header(m, "Channel");
864 if (ast_strlen_zero(name)) {
865 astman_send_error(s, m, "No channel specified");
869 if (!(c = ast_channel_get_by_name(name))) {
870 astman_send_error(s, m, "No such channel");
874 if (action == MONITOR_ACTION_PAUSE) {
875 ast_monitor_pause(c);
877 ast_monitor_unpause(c);
880 c = ast_channel_unref(c);
882 astman_send_ack(s, m, (action == MONITOR_ACTION_PAUSE ? "Paused monitoring of the channel" : "Unpaused monitoring of the channel"));
887 static int pause_monitor_action(struct mansession *s, const struct message *m)
889 return do_pause_or_unpause(s, m, MONITOR_ACTION_PAUSE);
892 static int unpause_monitor_action(struct mansession *s, const struct message *m)
894 return do_pause_or_unpause(s, m, MONITOR_ACTION_UNPAUSE);
898 static int load_module(void)
900 ast_register_application_xml("Monitor", start_monitor_exec);
901 ast_register_application_xml("StopMonitor", stop_monitor_exec);
902 ast_register_application_xml("ChangeMonitor", change_monitor_exec);
903 ast_register_application_xml("PauseMonitor", pause_monitor_exec);
904 ast_register_application_xml("UnpauseMonitor", unpause_monitor_exec);
905 ast_manager_register_xml("Monitor", EVENT_FLAG_CALL, start_monitor_action);
906 ast_manager_register_xml("StopMonitor", EVENT_FLAG_CALL, stop_monitor_action);
907 ast_manager_register_xml("ChangeMonitor", EVENT_FLAG_CALL, change_monitor_action);
908 ast_manager_register_xml("PauseMonitor", EVENT_FLAG_CALL, pause_monitor_action);
909 ast_manager_register_xml("UnpauseMonitor", EVENT_FLAG_CALL, unpause_monitor_action);
911 return AST_MODULE_LOAD_SUCCESS;
914 static int unload_module(void)
916 ast_unregister_application("Monitor");
917 ast_unregister_application("StopMonitor");
918 ast_unregister_application("ChangeMonitor");
919 ast_unregister_application("PauseMonitor");
920 ast_unregister_application("UnpauseMonitor");
921 ast_manager_unregister("Monitor");
922 ast_manager_unregister("StopMonitor");
923 ast_manager_unregister("ChangeMonitor");
924 ast_manager_unregister("PauseMonitor");
925 ast_manager_unregister("UnpauseMonitor");
930 /* usecount semantics need to be defined */
931 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Call Monitoring Resource",
933 .unload = unload_module,