Asterisk - The Open Source Telephony Project  GIT-master-a24979a
app_mixmonitor.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2005, Anthony Minessale II
5  * Copyright (C) 2005 - 2006, Digium, Inc.
6  *
7  * Mark Spencer <markster@digium.com>
8  * Kevin P. Fleming <kpfleming@digium.com>
9  *
10  * Based on app_muxmon.c provided by
11  * Anthony Minessale II <anthmct@yahoo.com>
12  *
13  * See http://www.asterisk.org for more information about
14  * the Asterisk project. Please do not directly contact
15  * any of the maintainers of this project for assistance;
16  * the project provides a web site, mailing lists and IRC
17  * channels for your use.
18  *
19  * This program is free software, distributed under the terms of
20  * the GNU General Public License Version 2. See the LICENSE file
21  * at the top of the source tree.
22  */
23 
24 /*! \file
25  *
26  * \brief MixMonitor() - Record a call and mix the audio during the recording
27  * \ingroup applications
28  *
29  * \author Mark Spencer <markster@digium.com>
30  * \author Kevin P. Fleming <kpfleming@digium.com>
31  *
32  * \note Based on app_muxmon.c provided by
33  * Anthony Minessale II <anthmct@yahoo.com>
34  */
35 
36 /*** MODULEINFO
37  <use type="module">func_periodic_hook</use>
38  <support_level>core</support_level>
39  ***/
40 
41 #include "asterisk.h"
42 
43 #include "asterisk/paths.h" /* use ast_config_AST_MONITOR_DIR */
44 #include "asterisk/stringfields.h"
45 #include "asterisk/file.h"
46 #include "asterisk/audiohook.h"
47 #include "asterisk/pbx.h"
48 #include "asterisk/module.h"
49 #include "asterisk/cli.h"
50 #include "asterisk/app.h"
51 #include "asterisk/channel.h"
52 #include "asterisk/autochan.h"
53 #include "asterisk/manager.h"
54 #include "asterisk/stasis.h"
56 #include "asterisk/callerid.h"
57 #include "asterisk/mod_format.h"
58 #include "asterisk/linkedlists.h"
59 #include "asterisk/test.h"
60 #include "asterisk/mixmonitor.h"
61 #include "asterisk/format_cache.h"
62 #include "asterisk/beep.h"
63 
64 /*** DOCUMENTATION
65  <application name="MixMonitor" language="en_US">
66  <synopsis>
67  Record a call and mix the audio during the recording. Use of StopMixMonitor is required
68  to guarantee the audio file is available for processing during dialplan execution.
69  </synopsis>
70  <syntax>
71  <parameter name="file" required="true" argsep=".">
72  <argument name="filename" required="true">
73  <para>If <replaceable>filename</replaceable> is an absolute path, uses that path, otherwise
74  creates the file in the configured monitoring directory from <filename>asterisk.conf.</filename></para>
75  </argument>
76  <argument name="extension" required="true" />
77  </parameter>
78  <parameter name="options">
79  <optionlist>
80  <option name="a">
81  <para>Append to the file instead of overwriting it.</para>
82  </option>
83  <option name="b">
84  <para>Only save audio to the file while the channel is bridged.</para>
85  <note><para>If you utilize this option inside a Local channel, you must make sure the Local
86  channel is not optimized away. To do this, be sure to call your Local channel with the
87  <literal>/n</literal> option. For example: Dial(Local/start@mycontext/n)</para></note>
88  </option>
89  <option name="B">
90  <para>Play a periodic beep while this call is being recorded.</para>
91  <argument name="interval"><para>Interval, in seconds. Default is 15.</para></argument>
92  </option>
93  <option name="v">
94  <para>Adjust the <emphasis>heard</emphasis> volume by a factor of <replaceable>x</replaceable>
95  (range <literal>-4</literal> to <literal>4</literal>)</para>
96  <argument name="x" required="true" />
97  </option>
98  <option name="V">
99  <para>Adjust the <emphasis>spoken</emphasis> volume by a factor
100  of <replaceable>x</replaceable> (range <literal>-4</literal> to <literal>4</literal>)</para>
101  <argument name="x" required="true" />
102  </option>
103  <option name="W">
104  <para>Adjust both, <emphasis>heard and spoken</emphasis> volumes by a factor
105  of <replaceable>x</replaceable> (range <literal>-4</literal> to <literal>4</literal>)</para>
106  <argument name="x" required="true" />
107  </option>
108  <option name="r">
109  <argument name="file" required="true" />
110  <para>Use the specified file to record the <emphasis>receive</emphasis> audio feed.
111  Like with the basic filename argument, if an absolute path isn't given, it will create
112  the file in the configured monitoring directory.</para>
113  </option>
114  <option name="t">
115  <argument name="file" required="true" />
116  <para>Use the specified file to record the <emphasis>transmit</emphasis> audio feed.
117  Like with the basic filename argument, if an absolute path isn't given, it will create
118  the file in the configured monitoring directory.</para>
119  </option>
120  <option name="n">
121  <para>When the <replaceable>r</replaceable> or <replaceable>t</replaceable> option is
122  used, MixMonitor will insert silence into the specified files to maintain
123  synchronization between them. Use this option to disable that behavior.</para>
124  </option>
125  <option name="i">
126  <argument name="chanvar" required="true" />
127  <para>Stores the MixMonitor's ID on this channel variable.</para>
128  </option>
129  <option name="p">
130  <para>Play a beep on the channel that starts the recording.</para>
131  </option>
132  <option name="P">
133  <para>Play a beep on the channel that stops the recording.</para>
134  </option>
135  <option name="m">
136  <argument name="mailbox" required="true" />
137  <para>Create a copy of the recording as a voicemail in the indicated <emphasis>mailbox</emphasis>(es)
138  separated by commas eg. m(1111@default,2222@default,...). Folders can be optionally specified using
139  the syntax: mailbox@context/folder</para>
140  </option>
141  </optionlist>
142  </parameter>
143  <parameter name="command">
144  <para>Will be executed when the recording is over.</para>
145  <para>Any strings matching <literal>^{X}</literal> will be unescaped to <variable>X</variable>.</para>
146  <para>All variables will be evaluated at the time MixMonitor is called.</para>
147  <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
148  or <variable>CALLERID(name)</variable> as part of the command parameters. You
149  risk a command injection attack executing arbitrary commands if the untrusted
150  strings aren't filtered to remove dangerous characters. See function
151  <variable>FILTER()</variable>.</para></warning>
152  </parameter>
153  </syntax>
154  <description>
155  <para>Records the audio on the current channel to the specified file.</para>
156  <para>This application does not automatically answer and should be preceeded by
157  an application such as Answer or Progress().</para>
158  <note><para>MixMonitor runs as an audiohook.</para></note>
159  <note><para>If a filename passed to MixMonitor ends with
160  <literal>.wav49</literal>, Asterisk will silently convert the extension to
161  <literal>.WAV</literal> for legacy reasons. <variable>MIXMONITOR_FILENAME</variable>
162  will contain the actual filename that Asterisk is writing to, not necessarily the
163  value that was passed in.</para></note>
164  <variablelist>
165  <variable name="MIXMONITOR_FILENAME">
166  <para>Will contain the filename used to record.</para>
167  </variable>
168  </variablelist>
169  <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
170  or <variable>CALLERID(name)</variable> as part of ANY of the application's
171  parameters. You risk a command injection attack executing arbitrary commands
172  if the untrusted strings aren't filtered to remove dangerous characters. See
173  function <variable>FILTER()</variable>.</para></warning>
174  </description>
175  <see-also>
176  <ref type="application">Monitor</ref>
177  <ref type="application">StopMixMonitor</ref>
178  <ref type="application">PauseMonitor</ref>
179  <ref type="application">UnpauseMonitor</ref>
180  <ref type="function">AUDIOHOOK_INHERIT</ref>
181  </see-also>
182  </application>
183  <application name="StopMixMonitor" language="en_US">
184  <synopsis>
185  Stop recording a call through MixMonitor, and free the recording's file handle.
186  </synopsis>
187  <syntax>
188  <parameter name="MixMonitorID" required="false">
189  <para>If a valid ID is provided, then this command will stop only that specific
190  MixMonitor.</para>
191  </parameter>
192  </syntax>
193  <description>
194  <para>Stops the audio recording that was started with a call to <literal>MixMonitor()</literal>
195  on the current channel.</para>
196  </description>
197  <see-also>
198  <ref type="application">MixMonitor</ref>
199  </see-also>
200  </application>
201  <manager name="MixMonitorMute" language="en_US">
202  <synopsis>
203  Mute / unMute a Mixmonitor recording.
204  </synopsis>
205  <syntax>
206  <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
207  <parameter name="Channel" required="true">
208  <para>Used to specify the channel to mute.</para>
209  </parameter>
210  <parameter name="Direction">
211  <para>Which part of the recording to mute: read, write or both (from channel, to channel or both channels).</para>
212  </parameter>
213  <parameter name="State">
214  <para>Turn mute on or off : 1 to turn on, 0 to turn off.</para>
215  </parameter>
216  </syntax>
217  <description>
218  <para>This action may be used to mute a MixMonitor recording.</para>
219  </description>
220  </manager>
221  <manager name="MixMonitor" language="en_US">
222  <synopsis>
223  Record a call and mix the audio during the recording. Use of StopMixMonitor is required
224  to guarantee the audio file is available for processing during dialplan execution.
225  </synopsis>
226  <syntax>
227  <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
228  <parameter name="Channel" required="true">
229  <para>Used to specify the channel to record.</para>
230  </parameter>
231  <parameter name="File">
232  <para>Is the name of the file created in the monitor spool directory.
233  Defaults to the same name as the channel (with slashes replaced with dashes).
234  This argument is optional if you specify to record unidirectional audio with
235  either the r(filename) or t(filename) options in the options field. If
236  neither MIXMONITOR_FILENAME or this parameter is set, the mixed stream won't
237  be recorded.</para>
238  </parameter>
239  <parameter name="options">
240  <para>Options that apply to the MixMonitor in the same way as they
241  would apply if invoked from the MixMonitor application. For a list of
242  available options, see the documentation for the mixmonitor application. </para>
243  </parameter>
244  <parameter name="Command">
245  <para>Will be executed when the recording is over.
246  Any strings matching <literal>^{X}</literal> will be unescaped to <variable>X</variable>.
247  All variables will be evaluated at the time MixMonitor is called.</para>
248  <warning><para>Do not use untrusted strings such as <variable>CALLERID(num)</variable>
249  or <variable>CALLERID(name)</variable> as part of the command parameters. You
250  risk a command injection attack executing arbitrary commands if the untrusted
251  strings aren't filtered to remove dangerous characters. See function
252  <variable>FILTER()</variable>.</para></warning>
253  </parameter>
254  </syntax>
255  <description>
256  <para>This action records the audio on the current channel to the specified file.</para>
257  <variablelist>
258  <variable name="MIXMONITOR_FILENAME">
259  <para>Will contain the filename used to record the mixed stream.</para>
260  </variable>
261  </variablelist>
262  </description>
263  </manager>
264  <manager name="StopMixMonitor" language="en_US">
265  <synopsis>
266  Stop recording a call through MixMonitor, and free the recording's file handle.
267  </synopsis>
268  <syntax>
269  <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
270  <parameter name="Channel" required="true">
271  <para>The name of the channel monitored.</para>
272  </parameter>
273  <parameter name="MixMonitorID" required="false">
274  <para>If a valid ID is provided, then this command will stop only that specific
275  MixMonitor.</para>
276  </parameter>
277  </syntax>
278  <description>
279  <para>This action stops the audio recording that was started with the <literal>MixMonitor</literal>
280  action on the current channel.</para>
281  </description>
282  </manager>
283  <function name="MIXMONITOR" language="en_US">
284  <synopsis>
285  Retrieve data pertaining to specific instances of MixMonitor on a channel.
286  </synopsis>
287  <syntax>
288  <parameter name="id" required="true">
289  <para>The unique ID of the MixMonitor instance. The unique ID can be retrieved through the channel
290  variable used as an argument to the <replaceable>i</replaceable> option to MixMonitor.</para>
291  </parameter>
292  <parameter name="key" required="true">
293  <para>The piece of data to retrieve from the MixMonitor.</para>
294  <enumlist>
295  <enum name="filename" />
296  </enumlist>
297  </parameter>
298  </syntax>
299  </function>
300  <managerEvent language="en_US" name="MixMonitorStart">
301  <managerEventInstance class="EVENT_FLAG_CALL">
302  <synopsis>Raised when monitoring has started on a channel.</synopsis>
303  <syntax>
304  <channel_snapshot/>
305  </syntax>
306  <see-also>
307  <ref type="managerEvent">MixMonitorStop</ref>
308  <ref type="application">MixMonitor</ref>
309  <ref type="manager">MixMonitor</ref>
310  </see-also>
311  </managerEventInstance>
312  </managerEvent>
313  <managerEvent language="en_US" name="MixMonitorStop">
314  <managerEventInstance class="EVENT_FLAG_CALL">
315  <synopsis>Raised when monitoring has stopped on a channel.</synopsis>
316  <syntax>
317  <channel_snapshot/>
318  </syntax>
319  <see-also>
320  <ref type="managerEvent">MixMonitorStart</ref>
321  <ref type="application">StopMixMonitor</ref>
322  <ref type="manager">StopMixMonitor</ref>
323  </see-also>
324  </managerEventInstance>
325  </managerEvent>
326  <managerEvent language="en_US" name="MixMonitorMute">
327  <managerEventInstance class="EVENT_FLAG_CALL">
328  <synopsis>Raised when monitoring is muted or unmuted on a channel.</synopsis>
329  <syntax>
330  <channel_snapshot/>
331  <parameter name="Direction">
332  <para>Which part of the recording was muted or unmuted: read, write or both
333  (from channel, to channel or both directions).</para>
334  </parameter>
335  <parameter name="State">
336  <para>If the monitoring was muted or unmuted: 1 when muted, 0 when unmuted.</para>
337  </parameter>
338  </syntax>
339  <see-also>
340  <ref type="manager">MixMonitorMute</ref>
341  </see-also>
342  </managerEventInstance>
343  </managerEvent>
344 
345 
346  ***/
347 
348 #define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0
349 
350 static const char * const app = "MixMonitor";
351 
352 static const char * const stop_app = "StopMixMonitor";
353 
354 static const char * const mixmonitor_spy_type = "MixMonitor";
355 
356 /*!
357  * \internal
358  * \brief This struct is a list item holds data needed to find a vm_recipient within voicemail
359  */
360 struct vm_recipient {
363  char folder[80];
365 };
366 
367 struct mixmonitor {
368  struct ast_audiohook audiohook;
369  char *filename;
373  char *name;
375  unsigned int flags;
378 
379  /* the below string fields describe data used for creating voicemails from the recording */
386  );
388 
389  /* FUTURE DEVELOPMENT NOTICE
390  * recipient_list will need locks if we make it editable after the monitor is started */
392 };
393 
395  MUXFLAG_APPEND = (1 << 1),
396  MUXFLAG_BRIDGED = (1 << 2),
397  MUXFLAG_VOLUME = (1 << 3),
398  MUXFLAG_READVOLUME = (1 << 4),
400  MUXFLAG_READ = (1 << 6),
401  MUXFLAG_WRITE = (1 << 7),
402  MUXFLAG_COMBINED = (1 << 8),
403  MUXFLAG_UID = (1 << 9),
404  MUXFLAG_VMRECIPIENTS = (1 << 10),
405  MUXFLAG_BEEP = (1 << 11),
406  MUXFLAG_BEEP_START = (1 << 12),
407  MUXFLAG_BEEP_STOP = (1 << 13),
409  MUXFLAG_NO_RWSYNC = (1 << 15),
410 };
411 
423  OPT_ARG_ARRAY_SIZE, /* Always last element of the enum */
424 };
425 
441 });
442 
444  unsigned int destruction_ok;
447 
448  /* The filestream is held in the datastore so it can be stopped
449  * immediately during stop_mixmonitor or channel destruction. */
450  int fs_quit;
451 
455 
457 
458  unsigned int samp_rate;
459  char *filename;
460  char *beep_id;
461 };
462 
463 /*!
464  * \internal
465  * \pre mixmonitor_ds must be locked before calling this function
466  */
468 {
469  unsigned char quitting = 0;
470 
471  if (mixmonitor_ds->fs) {
472  quitting = 1;
474  mixmonitor_ds->fs = NULL;
475  ast_verb(2, "MixMonitor close filestream (mixed)\n");
476  }
477 
478  if (mixmonitor_ds->fs_read) {
479  quitting = 1;
482  ast_verb(2, "MixMonitor close filestream (read)\n");
483  }
484 
485  if (mixmonitor_ds->fs_write) {
486  quitting = 1;
489  ast_verb(2, "MixMonitor close filestream (write)\n");
490  }
491 
492  if (quitting) {
493  mixmonitor_ds->fs_quit = 1;
494  }
495 }
496 
497 static void mixmonitor_ds_destroy(void *data)
498 {
499  struct mixmonitor_ds *mixmonitor_ds = data;
500 
508 }
509 
510 static const struct ast_datastore_info mixmonitor_ds_info = {
511  .type = "mixmonitor",
512  .destroy = mixmonitor_ds_destroy,
513 };
514 
516 {
517  if (mixmonitor->mixmonitor_ds) {
521  }
522  /* kill the audiohook.*/
527 }
528 
529 static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook)
530 {
531  if (!chan) {
532  return -1;
533  }
534 
535  return ast_audiohook_attach(chan, audiohook);
536 }
537 
538 /*!
539  * \internal
540  * \brief adds recipients to a mixmonitor's recipient list
541  * \param mixmonitor mixmonitor being affected
542  * \param vm_recipients string containing the desired recipients to add
543  */
544 static void add_vm_recipients_from_string(struct mixmonitor *mixmonitor, const char *vm_recipients)
545 {
546  /* recipients are in a single string with a format format resembling "mailbox@context/INBOX,mailbox2@context2,mailbox3@context3/Work" */
547  char *cur_mailbox = ast_strdupa(vm_recipients);
548  char *cur_context;
549  char *cur_folder;
550  char *next;
551  int elements_processed = 0;
552 
553  while (!ast_strlen_zero(cur_mailbox)) {
554  ast_debug(3, "attempting to add next element %d from %s\n", elements_processed, cur_mailbox);
555  if ((next = strchr(cur_mailbox, ',')) || (next = strchr(cur_mailbox, '&'))) {
556  *(next++) = '\0';
557  }
558 
559  if ((cur_folder = strchr(cur_mailbox, '/'))) {
560  *(cur_folder++) = '\0';
561  } else {
562  cur_folder = "INBOX";
563  }
564 
565  if ((cur_context = strchr(cur_mailbox, '@'))) {
566  *(cur_context++) = '\0';
567  } else {
568  cur_context = "default";
569  }
570 
571  if (!ast_strlen_zero(cur_mailbox) && !ast_strlen_zero(cur_context)) {
572  struct vm_recipient *recipient;
573  if (!(recipient = ast_malloc(sizeof(*recipient)))) {
574  ast_log(LOG_ERROR, "Failed to allocate recipient. Aborting function.\n");
575  return;
576  }
577  ast_copy_string(recipient->context, cur_context, sizeof(recipient->context));
578  ast_copy_string(recipient->mailbox, cur_mailbox, sizeof(recipient->mailbox));
579  ast_copy_string(recipient->folder, cur_folder, sizeof(recipient->folder));
580 
581  /* Add to list */
582  ast_verb(4, "Adding %s@%s to recipient list\n", recipient->mailbox, recipient->context);
584  } else {
585  ast_log(LOG_ERROR, "Failed to properly parse extension and/or context from element %d of recipient string: %s\n", elements_processed, vm_recipients);
586  }
587 
588  cur_mailbox = next;
589  elements_processed++;
590  }
591 }
592 
594 {
595  struct vm_recipient *current;
597  /* Clear list element data */
598  ast_free(current);
599  }
600 }
601 
602 #define SAMPLES_PER_FRAME 160
603 
605 {
606  if (mixmonitor) {
607  if (mixmonitor->mixmonitor_ds) {
611  }
612 
618 
619  /* Free everything in the recipient list */
621 
622  /* clean stringfields */
624 
626  }
627 }
628 
629 /*!
630  * \internal
631  * \brief Copies the mixmonitor to all voicemail recipients
632  * \param mixmonitor The mixmonitor that needs to forward its file to recipients
633  * \param ext Format of the file that was saved
634  * \param filename
635  */
636 static void copy_to_voicemail(struct mixmonitor *mixmonitor, const char *ext, const char *filename)
637 {
638  struct vm_recipient *recipient = NULL;
639  struct ast_vm_recording_data recording_data;
640  if (ast_string_field_init(&recording_data, 512)) {
641  ast_log(LOG_ERROR, "Failed to string_field_init, skipping copy_to_voicemail\n");
642  return;
643  }
644 
645  /* Copy strings to stringfields that will be used for all recipients */
646  ast_string_field_set(&recording_data, recording_file, filename);
647  ast_string_field_set(&recording_data, recording_ext, ext);
653  /* and call_priority gets copied too */
654  recording_data.call_priority = mixmonitor->call_priority;
655 
656  AST_LIST_TRAVERSE(&mixmonitor->recipient_list, recipient, list) {
657  /* context, mailbox, and folder need to be set per recipient */
658  ast_string_field_set(&recording_data, context, recipient->context);
659  ast_string_field_set(&recording_data, mailbox, recipient->mailbox);
660  ast_string_field_set(&recording_data, folder, recipient->folder);
661 
662  ast_verb(4, "MixMonitor attempting to send voicemail copy to %s@%s\n", recording_data.mailbox,
663  recording_data.context);
664  ast_app_copy_recording_to_vm(&recording_data);
665  }
666 
667  /* Free the string fields for recording_data before exiting the function. */
668  ast_string_field_free_memory(&recording_data);
669 }
670 
671 static void mixmonitor_save_prep(struct mixmonitor *mixmonitor, char *filename, struct ast_filestream **fs, unsigned int *oflags, int *errflag, char **ext)
672 {
673  /* Initialize the file if not already done so */
674  char *last_slash = NULL;
675  if (!ast_strlen_zero(filename)) {
676  if (!*fs && !*errflag && !mixmonitor->mixmonitor_ds->fs_quit) {
677  *oflags = O_CREAT | O_WRONLY;
678  *oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
679 
680  last_slash = strrchr(filename, '/');
681 
682  if ((*ext = strrchr(filename, '.')) && (*ext > last_slash)) {
683  **ext = '\0';
684  *ext = *ext + 1;
685  } else {
686  *ext = "raw";
687  }
688 
689  if (!(*fs = ast_writefile(filename, *ext, NULL, *oflags, 0, 0666))) {
690  ast_log(LOG_ERROR, "Cannot open %s.%s\n", filename, *ext);
691  *errflag = 1;
692  } else {
693  struct ast_filestream *tmp = *fs;
695  }
696  }
697  }
698 }
699 
700 static int mixmonitor_autochan_is_bridged(struct ast_autochan *autochan)
701 {
702  int is_bridged;
703 
704  ast_autochan_channel_lock(autochan);
705  is_bridged = ast_channel_is_bridged(autochan->chan);
706  ast_autochan_channel_unlock(autochan);
707  return is_bridged;
708 }
709 
710 static void *mixmonitor_thread(void *obj)
711 {
712  struct mixmonitor *mixmonitor = obj;
713  char *fs_ext = "";
714  char *fs_read_ext = "";
715  char *fs_write_ext = "";
716 
717  struct ast_filestream **fs = NULL;
718  struct ast_filestream **fs_read = NULL;
719  struct ast_filestream **fs_write = NULL;
720 
721  unsigned int oflags;
722  int errflag = 0;
723  struct ast_format *format_slin;
724 
725  /* Keep callid association before any log messages */
726  if (mixmonitor->callid) {
728  }
729 
730  ast_verb(2, "Begin MixMonitor Recording %s\n", mixmonitor->name);
731 
732  fs = &mixmonitor->mixmonitor_ds->fs;
733  fs_read = &mixmonitor->mixmonitor_ds->fs_read;
734  fs_write = &mixmonitor->mixmonitor_ds->fs_write;
735 
737  mixmonitor_save_prep(mixmonitor, mixmonitor->filename, fs, &oflags, &errflag, &fs_ext);
738  mixmonitor_save_prep(mixmonitor, mixmonitor->filename_read, fs_read, &oflags, &errflag, &fs_read_ext);
739  mixmonitor_save_prep(mixmonitor, mixmonitor->filename_write, fs_write, &oflags, &errflag, &fs_write_ext);
740 
742 
744 
745  /* The audiohook must enter and exit the loop locked */
748  struct ast_frame *fr = NULL;
749  struct ast_frame *fr_read = NULL;
750  struct ast_frame *fr_write = NULL;
751 
753  &fr_read, &fr_write))) {
755 
757  break;
758  }
759  continue;
760  }
761 
762  /* audiohook lock is not required for the next block.
763  * Unlock it, but remember to lock it before looping or exiting */
765 
769 
770  /* Write out the frame(s) */
771  if ((*fs_read) && (fr_read)) {
772  struct ast_frame *cur;
773 
774  for (cur = fr_read; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
775  ast_writestream(*fs_read, cur);
776  }
777  }
778 
779  if ((*fs_write) && (fr_write)) {
780  struct ast_frame *cur;
781 
782  for (cur = fr_write; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
783  ast_writestream(*fs_write, cur);
784  }
785  }
786 
787  if ((*fs) && (fr)) {
788  struct ast_frame *cur;
789 
790  for (cur = fr; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
791  ast_writestream(*fs, cur);
792  }
793  }
795  }
796  /* All done! free it. */
797  if (fr) {
798  ast_frame_free(fr, 0);
799  }
800  if (fr_read) {
801  ast_frame_free(fr_read, 0);
802  }
803  if (fr_write) {
804  ast_frame_free(fr_write, 0);
805  }
806 
807  fr = NULL;
808  fr_write = NULL;
809  fr_read = NULL;
810 
812  }
813 
815 
820  }
821 
823 
824  /* Datastore cleanup. close the filestream and wait for ds destruction */
829  }
831 
832  /* kill the audiohook */
834 
835  if (mixmonitor->post_process) {
836  ast_verb(2, "Executing [%s]\n", mixmonitor->post_process);
838  }
839 
840  ast_verb(2, "End MixMonitor Recording %s\n", mixmonitor->name);
841  ast_test_suite_event_notify("MIXMONITOR_END", "File: %s\r\n", mixmonitor->filename);
842 
844  if (ast_strlen_zero(fs_ext)) {
845  ast_log(LOG_ERROR, "No file extension set for Mixmonitor %s. Skipping copy to voicemail.\n",
846  mixmonitor -> name);
847  } else {
848  ast_verb(3, "Copying recordings for Mixmonitor %s to voicemail recipients\n", mixmonitor->name);
850  }
851  if (!ast_strlen_zero(fs_read_ext)) {
852  ast_verb(3, "Copying read recording for Mixmonitor %s to voicemail recipients\n", mixmonitor->name);
854  }
855  if (!ast_strlen_zero(fs_write_ext)) {
856  ast_verb(3, "Copying write recording for Mixmonitor %s to voicemail recipients\n", mixmonitor->name);
858  }
859  } else {
860  ast_debug(3, "No recipients to forward monitor to, moving on.\n");
861  }
862 
864 
866  return NULL;
867 }
868 
869 static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel *chan, char **datastore_id, const char *beep_id)
870 {
871  struct ast_datastore *datastore = NULL;
873 
874  if (!(mixmonitor_ds = ast_calloc(1, sizeof(*mixmonitor_ds)))) {
875  return -1;
876  }
877 
878  if (ast_asprintf(datastore_id, "%p", mixmonitor_ds) == -1) {
879  ast_log(LOG_ERROR, "Failed to allocate memory for MixMonitor ID.\n");
881  return -1;
882  }
883 
886 
887  if (!(datastore = ast_datastore_alloc(&mixmonitor_ds_info, *datastore_id))) {
891  return -1;
892  }
893 
898  }
899 
900  mixmonitor_ds->samp_rate = 8000;
903  if (!ast_strlen_zero(beep_id)) {
905  }
906  datastore->data = mixmonitor_ds;
907 
908  ast_channel_lock(chan);
909  ast_channel_datastore_add(chan, datastore);
910  ast_channel_unlock(chan);
911 
913  return 0;
914 }
915 
916 static void mixmonitor_ds_remove_and_free(struct ast_channel *chan, const char *datastore_id)
917 {
918  struct ast_datastore *datastore;
919 
920  ast_channel_lock(chan);
921 
922  datastore = ast_channel_datastore_find(chan, &mixmonitor_ds_info, datastore_id);
923 
924  /*
925  * Currently the one place this function is called from guarantees a
926  * datastore is present, thus return checks can be avoided here.
927  */
928  ast_channel_datastore_remove(chan, datastore);
929  ast_datastore_free(datastore);
930 
931  ast_channel_unlock(chan);
932 }
933 
934 static int launch_monitor_thread(struct ast_channel *chan, const char *filename,
935  unsigned int flags, int readvol, int writevol,
936  const char *post_process, const char *filename_write,
937  char *filename_read, const char *uid_channel_var,
938  const char *recipients, const char *beep_id)
939 {
940  pthread_t thread;
941  struct mixmonitor *mixmonitor;
942  char postprocess2[1024] = "";
943  char *datastore_id = NULL;
944 
945  postprocess2[0] = 0;
946  /* If a post process system command is given attach it to the structure */
948  char *p1, *p2;
949 
951  for (p2 = p1; *p2; p2++) {
952  if (*p2 == '^' && *(p2+1) == '{') {
953  *p2 = '$';
954  }
955  }
956  ast_channel_lock(chan);
957  pbx_substitute_variables_helper(chan, p1, postprocess2, sizeof(postprocess2) - 1);
958  ast_channel_unlock(chan);
959  }
960 
961  /* Pre-allocate mixmonitor structure and spy */
962  if (!(mixmonitor = ast_calloc(1, sizeof(*mixmonitor)))) {
963  return -1;
964  }
965 
966  /* Now that the struct has been calloced, go ahead and initialize the string fields. */
967  if (ast_string_field_init(mixmonitor, 512)) {
969  return -1;
970  }
971 
972  /* Setup the actual spy before creating our thread */
975  return -1;
976  }
977 
978  /* Copy over flags and channel name */
980  if (!(mixmonitor->autochan = ast_autochan_setup(chan))) {
982  return -1;
983  }
984 
985  if (!ast_strlen_zero(filename)) {
987  }
988 
991  }
992 
995  }
996 
997  if (setup_mixmonitor_ds(mixmonitor, chan, &datastore_id, beep_id)) {
1000  ast_free(datastore_id);
1001  return -1;
1002  }
1003 
1004  if (!ast_strlen_zero(uid_channel_var)) {
1005  if (datastore_id) {
1006  pbx_builtin_setvar_helper(chan, uid_channel_var, datastore_id);
1007  }
1008  }
1009 
1011 
1012  if (!ast_strlen_zero(postprocess2)) {
1013  mixmonitor->post_process = ast_strdup(postprocess2);
1014  }
1015 
1016  if (!ast_strlen_zero(recipients)) {
1017  char callerid[256];
1019 
1020  ast_channel_lock(chan);
1021 
1022  /* We use the connected line of the invoking channel for caller ID. */
1023 
1025  ast_debug(3, "Connected Line CID = %d - %s : %d - %s\n", connected->id.name.valid,
1026  connected->id.name.str, connected->id.number.valid,
1027  connected->id.number.str);
1028  ast_callerid_merge(callerid, sizeof(callerid),
1029  S_COR(connected->id.name.valid, connected->id.name.str, NULL),
1030  S_COR(connected->id.number.valid, connected->id.number.str, NULL),
1031  "Unknown");
1032 
1033  ast_string_field_set(mixmonitor, call_context, ast_channel_context(chan));
1034  ast_string_field_set(mixmonitor, call_macrocontext, ast_channel_macrocontext(chan));
1035  ast_string_field_set(mixmonitor, call_extension, ast_channel_exten(chan));
1036  ast_string_field_set(mixmonitor, call_callerchan, ast_channel_name(chan));
1037  ast_string_field_set(mixmonitor, call_callerid, callerid);
1039 
1040  ast_channel_unlock(chan);
1041 
1043  }
1044 
1048  }
1049 
1050  if (readvol)
1052  if (writevol)
1054 
1055  if (startmon(chan, &mixmonitor->audiohook)) {
1056  ast_log(LOG_WARNING, "Unable to add '%s' spy to channel '%s'\n",
1058  mixmonitor_ds_remove_and_free(chan, datastore_id);
1059  ast_free(datastore_id);
1063  return -1;
1064  }
1065 
1066  ast_free(datastore_id);
1067 
1068  /* reference be released at mixmonitor destruction */
1070 
1072 }
1073 
1074 /* a note on filename_parse: creates directory structure and assigns absolute path from relative paths for filenames */
1075 /* requires immediate copying of string from return to retain data since otherwise it will immediately lose scope */
1076 static char *filename_parse(char *filename, char *buffer, size_t len)
1077 {
1078  char *slash;
1079  char *ext;
1080 
1081  ast_assert(len > 0);
1082 
1083  if (ast_strlen_zero(filename)) {
1084  ast_log(LOG_WARNING, "No file name was provided for a file save option.\n");
1085  buffer[0] = 0;
1086  return buffer;
1087  }
1088 
1089  /* If we don't have an absolute path, make one */
1090  if (*filename != '/') {
1091  char *build = ast_alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(filename) + 3);
1092  sprintf(build, "%s/%s", ast_config_AST_MONITOR_DIR, filename);
1093  filename = build;
1094  }
1095 
1096  ast_copy_string(buffer, filename, len);
1097 
1098  /* If the provided filename has a .wav49 extension, we need to convert it to .WAV to
1099  match the behavior of build_filename in main/file.c. Otherwise MIXMONITOR_FILENAME
1100  ends up referring to a file that does not/will not exist */
1101  ext = strrchr(buffer, '.');
1102  if (ext && !strcmp(ext, ".wav49")) {
1103  /* Change to WAV - we know we have at least 6 writeable bytes where 'ext' points,
1104  * so this is safe */
1105  memcpy(ext, ".WAV", sizeof(".WAV"));
1106  }
1107 
1108  if ((slash = strrchr(filename, '/'))) {
1109  *slash = '\0';
1110  }
1111  ast_mkdir(filename, 0777);
1112 
1113  return buffer;
1114 }
1115 
1116 static int mixmonitor_exec(struct ast_channel *chan, const char *data)
1117 {
1118  int x, readvol = 0, writevol = 0;
1119  char *filename_read = NULL;
1120  char *filename_write = NULL;
1121  char filename_buffer[1024] = "";
1122  char *uid_channel_var = NULL;
1123  char beep_id[64] = "";
1124 
1125  struct ast_flags flags = { 0 };
1126  char *recipients = NULL;
1127  char *parse;
1130  AST_APP_ARG(filename);
1132  AST_APP_ARG(post_process);
1133  );
1134 
1135  if (ast_strlen_zero(data)) {
1136  ast_log(LOG_WARNING, "MixMonitor requires an argument (filename or ,t(filename) and/or r(filename)\n");
1137  return -1;
1138  }
1139 
1140  parse = ast_strdupa(data);
1141 
1143 
1144  if (args.options) {
1145  char *opts[OPT_ARG_ARRAY_SIZE] = { NULL, };
1146 
1147  ast_app_parse_options(mixmonitor_opts, &flags, opts, args.options);
1148 
1150  ast_log(LOG_NOTICE, "The synchronization behavior enabled by the 'S' option is now the default"
1151  " and does not need to be specified.\n");
1152  }
1153 
1155  if (ast_strlen_zero(opts[OPT_ARG_READVOLUME])) {
1156  ast_log(LOG_WARNING, "No volume level was provided for the heard volume ('v') option.\n");
1157  } else if ((sscanf(opts[OPT_ARG_READVOLUME], "%2d", &x) != 1) || (x < -4) || (x > 4)) {
1158  ast_log(LOG_NOTICE, "Heard volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_READVOLUME]);
1159  } else {
1160  readvol = get_volfactor(x);
1161  }
1162  }
1163 
1165  if (ast_strlen_zero(opts[OPT_ARG_WRITEVOLUME])) {
1166  ast_log(LOG_WARNING, "No volume level was provided for the spoken volume ('V') option.\n");
1167  } else if ((sscanf(opts[OPT_ARG_WRITEVOLUME], "%2d", &x) != 1) || (x < -4) || (x > 4)) {
1168  ast_log(LOG_NOTICE, "Spoken volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_WRITEVOLUME]);
1169  } else {
1170  writevol = get_volfactor(x);
1171  }
1172  }
1173 
1175  if (ast_strlen_zero(opts[OPT_ARG_VOLUME])) {
1176  ast_log(LOG_WARNING, "No volume level was provided for the combined volume ('W') option.\n");
1177  } else if ((sscanf(opts[OPT_ARG_VOLUME], "%2d", &x) != 1) || (x < -4) || (x > 4)) {
1178  ast_log(LOG_NOTICE, "Combined volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_VOLUME]);
1179  } else {
1180  readvol = writevol = get_volfactor(x);
1181  }
1182  }
1183 
1186  ast_log(LOG_WARNING, "No voicemail recipients were specified for the vm copy ('m') option.\n");
1187  } else {
1188  recipients = ast_strdupa(opts[OPT_ARG_VMRECIPIENTS]);
1189  }
1190  }
1191 
1193  filename_write = ast_strdupa(filename_parse(opts[OPT_ARG_WRITENAME], filename_buffer, sizeof(filename_buffer)));
1194  }
1195 
1196  if (ast_test_flag(&flags, MUXFLAG_READ)) {
1197  filename_read = ast_strdupa(filename_parse(opts[OPT_ARG_READNAME], filename_buffer, sizeof(filename_buffer)));
1198  }
1199 
1200  if (ast_test_flag(&flags, MUXFLAG_UID)) {
1201  uid_channel_var = opts[OPT_ARG_UID];
1202  }
1203 
1204  if (ast_test_flag(&flags, MUXFLAG_BEEP)) {
1205  const char *interval_str = S_OR(opts[OPT_ARG_BEEP_INTERVAL], "15");
1206  unsigned int interval = 15;
1207 
1208  if (sscanf(interval_str, "%30u", &interval) != 1) {
1209  ast_log(LOG_WARNING, "Invalid interval '%s' for periodic beep. Using default of %u\n",
1210  interval_str, interval);
1211  }
1212 
1213  if (ast_beep_start(chan, interval, beep_id, sizeof(beep_id))) {
1214  ast_log(LOG_WARNING, "Unable to enable periodic beep, please ensure func_periodic_hook is loaded.\n");
1215  return -1;
1216  }
1217  }
1218  }
1219  /* If there are no file writing arguments/options for the mix monitor, send a warning message and return -1 */
1220 
1222  ast_log(LOG_WARNING, "MixMonitor requires an argument (filename)\n");
1223  return -1;
1224  }
1225 
1226  /* If filename exists, try to create directories for it */
1227  if (!(ast_strlen_zero(args.filename))) {
1228  args.filename = ast_strdupa(filename_parse(args.filename, filename_buffer, sizeof(filename_buffer)));
1229  }
1230 
1231  pbx_builtin_setvar_helper(chan, "MIXMONITOR_FILENAME", args.filename);
1232 
1233  /* If launch_monitor_thread works, the module reference must not be released until it is finished. */
1235  if (launch_monitor_thread(chan,
1236  args.filename,
1237  flags.flags,
1238  readvol,
1239  writevol,
1240  args.post_process,
1241  filename_write,
1242  filename_read,
1243  uid_channel_var,
1244  recipients,
1245  beep_id)) {
1247  }
1248 
1251  if (message) {
1253  }
1254 
1255  return 0;
1256 }
1257 
1258 static int stop_mixmonitor_full(struct ast_channel *chan, const char *data)
1259 {
1260  struct ast_datastore *datastore = NULL;
1261  char *parse = "";
1262  struct mixmonitor_ds *mixmonitor_ds;
1263  const char *beep_id = NULL;
1265 
1267  AST_APP_ARG(mixmonid);
1268  );
1269 
1270  if (!ast_strlen_zero(data)) {
1271  parse = ast_strdupa(data);
1272  }
1273 
1275 
1276  ast_channel_lock(chan);
1277 
1279  S_OR(args.mixmonid, NULL));
1280  if (!datastore) {
1281  ast_channel_unlock(chan);
1282  return -1;
1283  }
1284  mixmonitor_ds = datastore->data;
1285 
1287 
1288  /* closing the filestream here guarantees the file is available to the dialplan
1289  * after calling StopMixMonitor */
1291 
1292  /* The mixmonitor thread may be waiting on the audiohook trigger.
1293  * In order to exit from the mixmonitor loop before waiting on channel
1294  * destruction, poke the audiohook trigger. */
1295  if (mixmonitor_ds->audiohook) {
1298  }
1303  }
1304 
1307  }
1308 
1310 
1311  /* Remove the datastore so the monitor thread can exit */
1312  if (!ast_channel_datastore_remove(chan, datastore)) {
1313  ast_datastore_free(datastore);
1314  }
1315 
1316  ast_channel_unlock(chan);
1317 
1318  if (!ast_strlen_zero(beep_id)) {
1319  ast_beep_stop(chan, beep_id);
1320  }
1321 
1324  NULL);
1325  if (message) {
1327  }
1328 
1329  return 0;
1330 }
1331 
1332 static int stop_mixmonitor_exec(struct ast_channel *chan, const char *data)
1333 {
1334  stop_mixmonitor_full(chan, data);
1335  return 0;
1336 }
1337 
1338 static char *handle_cli_mixmonitor(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1339 {
1340  struct ast_channel *chan;
1341  struct ast_datastore *datastore = NULL;
1342  struct mixmonitor_ds *mixmonitor_ds = NULL;
1343 
1344  switch (cmd) {
1345  case CLI_INIT:
1346  e->command = "mixmonitor {start|stop|list}";
1347  e->usage =
1348  "Usage: mixmonitor start <chan_name> [args]\n"
1349  " The optional arguments are passed to the MixMonitor application.\n"
1350  " mixmonitor stop <chan_name> [args]\n"
1351  " The optional arguments are passed to the StopMixMonitor application.\n"
1352  " mixmonitor list <chan_name>\n";
1353  return NULL;
1354  case CLI_GENERATE:
1355  return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
1356  }
1357 
1358  if (a->argc < 3) {
1359  return CLI_SHOWUSAGE;
1360  }
1361 
1362  if (!(chan = ast_channel_get_by_name_prefix(a->argv[2], strlen(a->argv[2])))) {
1363  ast_cli(a->fd, "No channel matching '%s' found.\n", a->argv[2]);
1364  /* Technically this is a failure, but we don't want 2 errors printing out */
1365  return CLI_SUCCESS;
1366  }
1367 
1368  if (!strcasecmp(a->argv[1], "start")) {
1369  mixmonitor_exec(chan, (a->argc >= 4) ? a->argv[3] : "");
1370  } else if (!strcasecmp(a->argv[1], "stop")){
1371  stop_mixmonitor_exec(chan, (a->argc >= 4) ? a->argv[3] : "");
1372  } else if (!strcasecmp(a->argv[1], "list")) {
1373  ast_cli(a->fd, "MixMonitor ID\tFile\tReceive File\tTransmit File\n");
1374  ast_cli(a->fd, "=========================================================================\n");
1375  ast_channel_lock(chan);
1376  AST_LIST_TRAVERSE(ast_channel_datastores(chan), datastore, entry) {
1377  if (datastore->info == &mixmonitor_ds_info) {
1378  char *filename = "";
1379  char *filename_read = "";
1380  char *filename_write = "";
1381 
1382  mixmonitor_ds = datastore->data;
1383  if (mixmonitor_ds->fs) {
1385  }
1386  if (mixmonitor_ds->fs_read) {
1387  filename_read = mixmonitor_ds->fs_read->filename;
1388  }
1389  if (mixmonitor_ds->fs_write) {
1390  filename_write = mixmonitor_ds->fs_write->filename;
1391  }
1392  ast_cli(a->fd, "%p\t%s\t%s\t%s\n", mixmonitor_ds, filename, filename_read, filename_write);
1393  }
1394  }
1395  ast_channel_unlock(chan);
1396  } else {
1397  chan = ast_channel_unref(chan);
1398  return CLI_SHOWUSAGE;
1399  }
1400 
1401  chan = ast_channel_unref(chan);
1402 
1403  return CLI_SUCCESS;
1404 }
1405 
1406 /*! \brief Mute / unmute a MixMonitor channel */
1407 static int manager_mute_mixmonitor(struct mansession *s, const struct message *m)
1408 {
1409  struct ast_channel *c;
1410  const char *name = astman_get_header(m, "Channel");
1411  const char *id = astman_get_header(m, "ActionID");
1412  const char *state = astman_get_header(m, "State");
1413  const char *direction = astman_get_header(m,"Direction");
1414  int clearmute = 1;
1417  RAII_VAR(struct ast_json *, stasis_message_blob, NULL, ast_json_unref);
1418 
1419  if (ast_strlen_zero(direction)) {
1420  astman_send_error(s, m, "No direction specified. Must be read, write or both");
1421  return AMI_SUCCESS;
1422  }
1423 
1424  if (!strcasecmp(direction, "read")) {
1426  } else if (!strcasecmp(direction, "write")) {
1428  } else if (!strcasecmp(direction, "both")) {
1430  } else {
1431  astman_send_error(s, m, "Invalid direction specified. Must be read, write or both");
1432  return AMI_SUCCESS;
1433  }
1434 
1435  if (ast_strlen_zero(name)) {
1436  astman_send_error(s, m, "No channel specified");
1437  return AMI_SUCCESS;
1438  }
1439 
1440  if (ast_strlen_zero(state)) {
1441  astman_send_error(s, m, "No state specified");
1442  return AMI_SUCCESS;
1443  }
1444 
1445  clearmute = ast_false(state);
1446 
1448  if (!c) {
1449  astman_send_error(s, m, "No such channel");
1450  return AMI_SUCCESS;
1451  }
1452 
1453  if (ast_audiohook_set_mute(c, mixmonitor_spy_type, flag, clearmute)) {
1455  astman_send_error(s, m, "Cannot set mute flag");
1456  return AMI_SUCCESS;
1457  }
1458 
1459  stasis_message_blob = ast_json_pack("{s: s, s: b}",
1460  "direction", direction,
1461  "state", ast_true(state));
1462 
1464  ast_channel_mixmonitor_mute_type(), stasis_message_blob);
1465 
1466  if (stasis_message) {
1468  }
1469 
1470  astman_append(s, "Response: Success\r\n");
1471 
1472  if (!ast_strlen_zero(id)) {
1473  astman_append(s, "ActionID: %s\r\n", id);
1474  }
1475 
1476  astman_append(s, "\r\n");
1477 
1479 
1480  return AMI_SUCCESS;
1481 }
1482 
1483 static int start_mixmonitor_callback(struct ast_channel *chan, const char *filename, const char *options)
1484 {
1485  char args[PATH_MAX];
1486 
1487  if (ast_strlen_zero(options)) {
1488  snprintf(args, sizeof(args), "%s", filename);
1489  } else {
1490  snprintf(args, sizeof(args), "%s,%s", filename, options);
1491  }
1492 
1493  return mixmonitor_exec(chan, args);
1494 }
1495 
1496 static int stop_mixmonitor_callback(struct ast_channel *chan, const char *mixmonitor_id)
1497 {
1498  return stop_mixmonitor_full(chan, mixmonitor_id);
1499 }
1500 
1501 static int manager_mixmonitor(struct mansession *s, const struct message *m)
1502 {
1503  struct ast_channel *c;
1504  const char *name = astman_get_header(m, "Channel");
1505  const char *id = astman_get_header(m, "ActionID");
1506  const char *file = astman_get_header(m, "File");
1507  const char *options = astman_get_header(m, "Options");
1508  const char *command = astman_get_header(m, "Command");
1509  char *opts[OPT_ARG_ARRAY_SIZE] = { NULL, };
1510  struct ast_flags flags = { 0 };
1511  char *uid_channel_var = NULL;
1512  const char *mixmonitor_id = NULL;
1513  int res;
1514  char args[PATH_MAX];
1515 
1516  if (ast_strlen_zero(name)) {
1517  astman_send_error(s, m, "No channel specified");
1518  return AMI_SUCCESS;
1519  }
1520 
1522  if (!c) {
1523  astman_send_error(s, m, "No such channel");
1524  return AMI_SUCCESS;
1525  }
1526 
1527  if (!ast_strlen_zero(options)) {
1529  }
1530 
1531  snprintf(args, sizeof(args), "%s,%s,%s", file, options, command);
1532 
1533  res = mixmonitor_exec(c, args);
1534 
1535  if (ast_test_flag(&flags, MUXFLAG_UID)) {
1536  uid_channel_var = opts[OPT_ARG_UID];
1538  mixmonitor_id = pbx_builtin_getvar_helper(c, uid_channel_var);
1539  mixmonitor_id = ast_strdupa(S_OR(mixmonitor_id, ""));
1541  }
1542 
1543  if (res) {
1545  astman_send_error(s, m, "Could not start monitoring channel");
1546  return AMI_SUCCESS;
1547  }
1548 
1549  astman_append(s, "Response: Success\r\n");
1550 
1551  if (!ast_strlen_zero(id)) {
1552  astman_append(s, "ActionID: %s\r\n", id);
1553  }
1554 
1555  if (!ast_strlen_zero(mixmonitor_id)) {
1556  astman_append(s, "MixMonitorID: %s\r\n", mixmonitor_id);
1557  }
1558 
1559  astman_append(s, "\r\n");
1560 
1562 
1563  return AMI_SUCCESS;
1564 }
1565 
1566 static int manager_stop_mixmonitor(struct mansession *s, const struct message *m)
1567 {
1568  struct ast_channel *c;
1569  const char *name = astman_get_header(m, "Channel");
1570  const char *id = astman_get_header(m, "ActionID");
1571  const char *mixmonitor_id = astman_get_header(m, "MixMonitorID");
1572  int res;
1573 
1574  if (ast_strlen_zero(name)) {
1575  astman_send_error(s, m, "No channel specified");
1576  return AMI_SUCCESS;
1577  }
1578 
1580  if (!c) {
1581  astman_send_error(s, m, "No such channel");
1582  return AMI_SUCCESS;
1583  }
1584 
1585  res = stop_mixmonitor_full(c, mixmonitor_id);
1586  if (res) {
1588  astman_send_error(s, m, "Could not stop monitoring channel");
1589  return AMI_SUCCESS;
1590  }
1591 
1592  astman_append(s, "Response: Success\r\n");
1593 
1594  if (!ast_strlen_zero(id)) {
1595  astman_append(s, "ActionID: %s\r\n", id);
1596  }
1597 
1598  astman_append(s, "\r\n");
1599 
1601 
1602  return AMI_SUCCESS;
1603 }
1604 
1605 static int func_mixmonitor_read(struct ast_channel *chan, const char *cmd, char *data,
1606  char *buf, size_t len)
1607 {
1608  struct ast_datastore *datastore;
1609  struct mixmonitor_ds *ds_data;
1611  AST_APP_ARG(id);
1612  AST_APP_ARG(key);
1613  );
1614 
1615  AST_STANDARD_APP_ARGS(args, data);
1616 
1617  if (ast_strlen_zero(args.id) || ast_strlen_zero(args.key)) {
1618  ast_log(LOG_WARNING, "Not enough arguments provided to %s. "
1619  "An ID and key must be provided\n", cmd);
1620  return -1;
1621  }
1622 
1623  ast_channel_lock(chan);
1624  datastore = ast_channel_datastore_find(chan, &mixmonitor_ds_info, args.id);
1625  ast_channel_unlock(chan);
1626 
1627  if (!datastore) {
1628  ast_log(LOG_WARNING, "Could not find MixMonitor with ID %s\n", args.id);
1629  return -1;
1630  }
1631 
1632  ds_data = datastore->data;
1633 
1634  if (!strcasecmp(args.key, "filename")) {
1635  ast_copy_string(buf, ds_data->filename, len);
1636  } else {
1637  ast_log(LOG_WARNING, "Unrecognized %s option %s\n", cmd, args.key);
1638  return -1;
1639  }
1640  return 0;
1641 }
1642 
1643 static struct ast_custom_function mixmonitor_function = {
1644  .name = "MIXMONITOR",
1645  .read = func_mixmonitor_read,
1646 };
1647 
1648 static struct ast_cli_entry cli_mixmonitor[] = {
1649  AST_CLI_DEFINE(handle_cli_mixmonitor, "Execute a MixMonitor command")
1650 };
1651 
1652 static int set_mixmonitor_methods(void)
1653 {
1656  .stop = stop_mixmonitor_callback,
1657  };
1658 
1660 }
1661 
1663 {
1665 }
1666 
1667 static int unload_module(void)
1668 {
1669  int res;
1670 
1674  res |= ast_manager_unregister("MixMonitorMute");
1675  res |= ast_manager_unregister("MixMonitor");
1676  res |= ast_manager_unregister("StopMixMonitor");
1678  res |= clear_mixmonitor_methods();
1679 
1680  return res;
1681 }
1682 
1683 static int load_module(void)
1684 {
1685  int res;
1686 
1694  res |= set_mixmonitor_methods();
1695 
1696  return res;
1697 }
1698 
1699 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Mixed Audio Monitoring Application",
1700  .support_level = AST_MODULE_SUPPORT_CORE,
1701  .load = load_module,
1702  .unload = unload_module,
1703  .optional_modules = "func_periodic_hook",
1704 );
pthread_t thread
Definition: app_meetme.c:1091
static int mixmonitor_exec(struct ast_channel *chan, const char *data)
static int manager_stop_mixmonitor(struct mansession *s, const struct message *m)
static struct ast_cli_entry cli_mixmonitor[]
static void * mixmonitor_thread(void *obj)
static struct ast_custom_function mixmonitor_function
static void destroy_monitor_audiohook(struct mixmonitor *mixmonitor)
static const struct ast_datastore_info mixmonitor_ds_info
mixmonitor_args
@ OPT_ARG_WRITEVOLUME
@ OPT_ARG_UID
@ OPT_ARG_VMRECIPIENTS
@ OPT_ARG_DEPRECATED_RWSYNC
@ OPT_ARG_NO_RWSYNC
@ OPT_ARG_WRITENAME
@ OPT_ARG_READNAME
@ OPT_ARG_BEEP_INTERVAL
@ OPT_ARG_READVOLUME
@ OPT_ARG_VOLUME
@ OPT_ARG_ARRAY_SIZE
static int set_mixmonitor_methods(void)
static const struct ast_app_option mixmonitor_opts[128]
static const char *const app
static void mixmonitor_save_prep(struct mixmonitor *mixmonitor, char *filename, struct ast_filestream **fs, unsigned int *oflags, int *errflag, char **ext)
static char * handle_cli_mixmonitor(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int mixmonitor_autochan_is_bridged(struct ast_autochan *autochan)
static int launch_monitor_thread(struct ast_channel *chan, const char *filename, unsigned int flags, int readvol, int writevol, const char *post_process, const char *filename_write, char *filename_read, const char *uid_channel_var, const char *recipients, const char *beep_id)
static int manager_mute_mixmonitor(struct mansession *s, const struct message *m)
Mute / unmute a MixMonitor channel.
static int clear_mixmonitor_methods(void)
static void copy_to_voicemail(struct mixmonitor *mixmonitor, const char *ext, const char *filename)
#define get_volfactor(x)
static int start_mixmonitor_callback(struct ast_channel *chan, const char *filename, const char *options)
#define SAMPLES_PER_FRAME
static void mixmonitor_free(struct mixmonitor *mixmonitor)
static int stop_mixmonitor_exec(struct ast_channel *chan, const char *data)
static int func_mixmonitor_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static const char *const stop_app
static void mixmonitor_ds_close_fs(struct mixmonitor_ds *mixmonitor_ds)
static int load_module(void)
static void mixmonitor_ds_remove_and_free(struct ast_channel *chan, const char *datastore_id)
static int manager_mixmonitor(struct mansession *s, const struct message *m)
static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel *chan, char **datastore_id, const char *beep_id)
static int unload_module(void)
static int stop_mixmonitor_full(struct ast_channel *chan, const char *data)
mixmonitor_flags
@ MUXFLAG_VMRECIPIENTS
@ MUXFLAG_READ
@ MUXFLAG_DEPRECATED_RWSYNC
@ MUXFLAG_WRITEVOLUME
@ MUXFLAG_NO_RWSYNC
@ MUXFLAG_VOLUME
@ MUXFLAG_BEEP_STOP
@ MUXFLAG_UID
@ MUXFLAG_APPEND
@ MUXFLAG_BEEP_START
@ MUXFLAG_WRITE
@ MUXFLAG_COMBINED
@ MUXFLAG_BEEP
@ MUXFLAG_BRIDGED
@ MUXFLAG_READVOLUME
static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook)
static const char *const mixmonitor_spy_type
static void mixmonitor_ds_destroy(void *data)
static int stop_mixmonitor_callback(struct ast_channel *chan, const char *mixmonitor_id)
static char * filename_parse(char *filename, char *buffer, size_t len)
static void add_vm_recipients_from_string(struct mixmonitor *mixmonitor, const char *vm_recipients)
static void clear_mixmonitor_recipient_list(struct mixmonitor *mixmonitor)
Asterisk main include file. File version handling, generic pbx functions.
#define PATH_MAX
Definition: asterisk.h:40
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
#define ast_log
Definition: astobj2.c:42
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
Audiohooks Architecture.
int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags)
Initialize an audiohook structure.
Definition: audiohook.c:100
int ast_audiohook_set_mute(struct ast_channel *chan, const char *source, enum ast_audiohook_flags flag, int clear)
Mute frames read from or written to a channel.
Definition: audiohook.c:1331
struct ast_frame * ast_audiohook_read_frame_all(struct ast_audiohook *audiohook, size_t samples, struct ast_format *format, struct ast_frame **read_frame, struct ast_frame **write_frame)
Reads a frame in from the audiohook structure in mixed audio mode and copies read and write frame dat...
Definition: audiohook.c:429
void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook)
Wait for audiohook trigger to be triggered.
Definition: audiohook.c:1072
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook's status.
Definition: audiohook.c:518
#define ast_audiohook_lock(ah)
Lock an audiohook.
Definition: audiohook.h:304
ast_audiohook_flags
Definition: audiohook.h:54
@ AST_AUDIOHOOK_MUTE_READ
Definition: audiohook.h:64
@ AST_AUDIOHOOK_MUTE_WRITE
Definition: audiohook.h:65
@ AST_AUDIOHOOK_SUBSTITUTE_SILENCE
Definition: audiohook.h:68
@ AST_AUDIOHOOK_TRIGGER_SYNC
Definition: audiohook.h:59
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
Definition: audiohook.c:528
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
Definition: audiohook.c:462
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
Definition: audiohook.c:121
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
Definition: audiohook.h:309
@ AST_AUDIOHOOK_TYPE_SPY
Definition: audiohook.h:36
@ AST_AUDIOHOOK_STATUS_DONE
Definition: audiohook.h:45
@ AST_AUDIOHOOK_STATUS_RUNNING
Definition: audiohook.h:43
@ AST_AUDIOHOOK_STATUS_SHUTDOWN
Definition: audiohook.h:44
"smart" channels that update automatically if a channel is masqueraded
void ast_autochan_destroy(struct ast_autochan *autochan)
destroy an ast_autochan structure
Definition: autochan.c:64
#define ast_autochan_channel_lock(autochan)
Lock the autochan's channel lock.
Definition: autochan.h:75
struct ast_autochan * ast_autochan_setup(struct ast_channel *chan)
set up a new ast_autochan structure
Definition: autochan.c:38
#define ast_autochan_channel_unlock(autochan)
Definition: autochan.h:84
Periodic beeps into the audio of a call.
static int tmp()
Definition: bt_open.c:389
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
char * ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
Definition: callerid.c:1073
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
Definition: chan_mgcp.c:207
General Asterisk PBX channel definitions.
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2384
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2393
const char * ast_channel_uniqueid(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2922
const char * ast_channel_context(const struct ast_channel *chan)
int ast_channel_priority(const struct ast_channel *chan)
struct ast_channel * ast_channel_get_by_name_prefix(const char *name, size_t name_len)
Find a channel by a name prefix.
Definition: channel.c:1428
const char * ast_channel_name(const struct ast_channel *chan)
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10731
const char * ast_channel_exten(const struct ast_channel *chan)
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2398
struct ast_datastore_list * ast_channel_datastores(struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
#define AST_MAX_CONTEXT
Definition: channel.h:135
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1448
const char * ast_channel_macrocontext(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define AST_MAX_EXTENSION
Definition: channel.h:134
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
Standard Command Line Interface.
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
Command completion for the list of active channels.
Definition: main/cli.c:1862
#define CLI_SUCCESS
Definition: cli.h:44
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
char connected
Definition: eagi_proxy.c:82
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
long int flag
Definition: f2c.h:83
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
Definition: file.c:244
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1855
struct ast_filestream * ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts writing a file.
Definition: file.c:1402
int ast_closestream(struct ast_filestream *f)
Closes a stream.
Definition: file.c:1109
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
Media Format Cache API.
struct ast_format * ast_format_cache_get_slin_by_rate(unsigned int rate)
Retrieve the best signed linear format given a sample rate.
Definition: format_cache.c:512
static const char name[]
Definition: format_mp3.c:68
direction
int AST_OPTIONAL_API_NAME() ast_beep_start(struct ast_channel *chan, unsigned int interval, char *beep_id, size_t len)
int AST_OPTIONAL_API_NAME() ast_beep_stop(struct ast_channel *chan, const char *beep_id)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3166
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3087
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:2827
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7268
struct stasis_message_type * ast_channel_mixmonitor_start_type(void)
Message type for starting mixmonitor on a channel.
struct stasis_message_type * ast_channel_mixmonitor_mute_type(void)
Message type for muting or unmuting mixmonitor on a channel.
struct stasis_message_type * ast_channel_mixmonitor_stop_type(void)
Message type for stopping mixmonitor on a channel.
struct stasis_message * ast_channel_blob_create_from_cache(const char *uniqueid, struct stasis_message_type *type, struct ast_json *blob)
Create a ast_channel_blob message, pulling channel state from the cache.
const char * ext
Definition: http.c:150
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
int ast_app_copy_recording_to_vm(struct ast_vm_recording_data *vm_rec_data)
param[in] vm_rec_data Contains data needed to make the recording. retval 0 voicemail successfully cre...
Definition: main/app.c:666
int ast_safe_system(const char *s)
Safely spawn an OS shell command while closing file descriptors.
Definition: extconf.c:829
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3126
void ast_frame_free(struct ast_frame *frame, int cache)
Frees a frame or list of frames.
Definition: main/frame.c:176
#define ast_debug(level,...)
Log a DEBUG message.
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:2048
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition: logger.c:2070
unsigned int ast_callid
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
A set of macros to manage forward-linked lists.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
#define ast_cond_destroy(cond)
Definition: lock.h:200
#define ast_cond_wait(cond, mutex)
Definition: lock.h:203
#define ast_cond_init(cond, attr)
Definition: lock.h:199
#define ast_mutex_init(pmutex)
Definition: lock.h:184
#define ast_mutex_unlock(a)
Definition: lock.h:188
pthread_cond_t ast_cond_t
Definition: lock.h:176
#define ast_mutex_destroy(a)
Definition: lock.h:186
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ast_cond_signal(cond)
Definition: lock.h:201
size_t current
Definition: main/cli.c:113
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define AMI_SUCCESS
Definition: manager.h:66
#define EVENT_FLAG_SYSTEM
Definition: manager.h:75
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:191
#define EVENT_FLAG_CALL
Definition: manager.h:76
static struct ast_mixmonitor_methods mixmonitor_methods
Definition: mixmonitor.c:40
loadable MixMonitor functionality
int ast_set_mixmonitor_methods(struct ast_mixmonitor_methods *vmethod_table)
Setup MixMonitor virtual methods table. Use this to provide the MixMonitor functionality from a loada...
Definition: mixmonitor.c:43
int ast_clear_mixmonitor_methods(void)
Clear the MixMonitor virtual methods table. Use this to cleanup function pointers provided by a modul...
Definition: mixmonitor.c:59
Header for providers of file and format handling routines. Clients of these routines should include "...
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:315
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:443
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_MONITOR_DIR
Definition: options.c:155
Core PBX routines and definitions.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1543
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: ael_main.c:211
AST_LIST_HEAD_NOLOCK(contactliststruct, contact)
#define NULL
Definition: resample.c:96
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition: stasis.c:1513
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:341
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:303
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: main/utils.c:2097
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
Definition: main/utils.c:2114
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
ast_cond_t trigger
Definition: audiohook.h:106
struct ast_audiohook_options options
Definition: audiohook.h:119
enum ast_audiohook_status status
Definition: audiohook.h:108
struct ast_channel * chan
Definition: autochan.h:33
Main Channel structure associated with a channel.
const char * data
descriptor for a cli entry.
Definition: cli.h:171
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
Structure for a data store type.
Definition: datastore.h:31
const char * type
Definition: datastore.h:32
Structure for a data store object.
Definition: datastore.h:64
const struct ast_datastore_info * info
Definition: datastore.h:67
void * data
Definition: datastore.h:66
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Definition: mod_format.h:101
char * filename
Definition: mod_format.h:107
Structure used to handle boolean flags.
Definition: utils.h:199
unsigned int flags
Definition: utils.h:200
Definition of a media format.
Definition: format.c:43
Data structure associated with a single frame of data.
Abstract JSON element (object, array, string, int, ...).
MixMonitor virtual methods table definition.
Definition: mixmonitor.h:58
ast_mixmonitor_start_fn start
Definition: mixmonitor.h:59
struct ast_module * self
Definition: module.h:342
Structure for mutex and tracking information.
Definition: lock.h:135
Connected Line/Party information.
Definition: channel.h:456
Structure used for ast_copy_recording_to_vm in order to cleanly supply data needed for making the rec...
const ast_string_field call_macrocontext
const ast_string_field recording_file
const ast_string_field call_callerchan
const ast_string_field context
const ast_string_field folder
const ast_string_field call_callerid
const ast_string_field call_context
const ast_string_field recording_ext
const ast_string_field call_extension
const ast_string_field mailbox
Definition: search.h:40
In case you didn't read that giant block of text above the mansession_session struct,...
Definition: manager.c:1632
unsigned int destruction_ok
struct ast_audiohook * audiohook
struct ast_filestream * fs_read
struct ast_filestream * fs_write
struct ast_filestream * fs
unsigned int samp_rate
ast_mutex_t lock
ast_cond_t destruction_condition
const ast_string_field call_macrocontext
char * filename_write
const ast_string_field call_callerchan
ast_callid callid
const ast_string_field call_callerid
struct ast_autochan * autochan
char * post_process
struct ast_audiohook audiohook
const ast_string_field call_context
const ast_string_field call_extension
char * filename_read
unsigned int flags
struct mixmonitor_ds * mixmonitor_ds
struct mixmonitor::@55 recipient_list
char * filename
char mailbox[AST_MAX_CONTEXT]
char context[AST_MAX_EXTENSION]
struct vm_recipient * next
struct vm_recipient::@54 list
char folder[80]
Test Framework API.
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:189
const char * args
static struct test_options options
static struct test_val a
static struct test_val c
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:936
#define ast_assert(a)
Definition: utils.h:734
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: main/utils.c:2377
#define ast_pthread_create_detached_background(a, b, c, d)
Definition: utils.h:592
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define ARRAY_LEN(a)
Definition: utils.h:661
#define MAX(a, b)
Definition: utils.h:228