Asterisk - The Open Source Telephony Project  GIT-master-9ed6387
Data Structures | Functions | Variables
app_playback.c File Reference

Trivial application to playback a sound file. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/say.h"
#include "asterisk/cli.h"

Go to the source code of this file.

Data Structures

struct  say_args_t
 Typical 'say' arguments in addition to the date or number or string to say. We do not include 'options' because they may be different in recursive calls, and so they are better left as an external parameter. More...
 

Functions

static void __reg_module (void)
 
static char * __say_cli_init (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int do_say (say_args_t *a, const char *s, const char *options, int depth)
 the string is 'prefix:data' or prefix:fmt:data' with ':' being invalid in strings. More...
 
static int load_module (void)
 
static int playback_exec (struct ast_channel *chan, const char *data)
 
static int reload (void)
 
static void restore_say_mode (void *arg)
 
static int s_streamwait3 (const say_args_t *a, const char *fn)
 
static void save_say_mode (const void *arg)
 
static int say_date (struct ast_channel *chan, time_t t, const char *ints, const char *lang)
 
static int say_date_generic (struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezonename, const char *prefix)
 
static int say_date_with_format (struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezonename)
 
static int say_datetime (struct ast_channel *chan, time_t t, const char *ints, const char *lang)
 
static int say_enumeration_full (struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd)
 
static int say_full (struct ast_channel *chan, const char *string, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd)
 
static int say_init_mode (const char *mode)
 remap the 'say' functions to use those in this file More...
 
static int say_number_full (struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd)
 
static int say_time (struct ast_channel *chan, time_t t, const char *ints, const char *lang)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Sound File Playback Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, }
 
static char * app = "Playback"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_playback []
 
static const void * say_api_buf [40]
 save the say' api calls. The first entry is NULL if we have the standard source, otherwise we are sourcing from here. 'say load [new|old]' will enable the new or old method, or report status More...
 
static struct ast_configsay_cfg = NULL
 
static const char *const say_new = "new"
 
static const char *const say_old = "old"
 

Detailed Description

Trivial application to playback a sound file.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_playback.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 582 of file app_playback.c.

◆ __say_cli_init()

static char* __say_cli_init ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 404 of file app_playback.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, say_api_buf, say_init_mode(), say_new, say_old, and ast_cli_entry::usage.

405 {
406  const char *old_mode = say_api_buf[0] ? say_new : say_old;
407  const char *mode;
408  switch (cmd) {
409  case CLI_INIT:
410  e->command = "say load [new|old]";
411  e->usage =
412  "Usage: say load [new|old]\n"
413  " say load\n"
414  " Report status of current say mode\n"
415  " say load new\n"
416  " Set say method, configured in say.conf\n"
417  " say load old\n"
418  " Set old say method, coded in asterisk core\n";
419  return NULL;
420  case CLI_GENERATE:
421  return NULL;
422  }
423  if (a->argc == 2) {
424  ast_cli(a->fd, "say mode is [%s]\n", old_mode);
425  return CLI_SUCCESS;
426  } else if (a->argc != e->args)
427  return CLI_SHOWUSAGE;
428  mode = a->argv[2];
429  if (!strcmp(mode, old_mode))
430  ast_cli(a->fd, "say mode is %s already\n", mode);
431  else
432  if (say_init_mode(mode) == 0)
433  ast_cli(a->fd, "setting say mode from %s to %s\n", old_mode, mode);
434 
435  return CLI_SUCCESS;
436 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int args
This gets set in ast_cli_register()
Definition: cli.h:185
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
static const void * say_api_buf[40]
save the say' api calls. The first entry is NULL if we have the standard source, otherwise we are sou...
Definition: app_playback.c:103
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
static const char *const say_new
Definition: app_playback.c:105
static int say_init_mode(const char *mode)
remap the 'say' functions to use those in this file
Definition: app_playback.c:369
static const char *const say_old
Definition: app_playback.c:104

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 582 of file app_playback.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 582 of file app_playback.c.

◆ do_say()

static int do_say ( say_args_t a,
const char *  s,
const char *  options,
int  depth 
)
static

the string is 'prefix:data' or prefix:fmt:data' with ':' being invalid in strings.

Definition at line 173 of file app_playback.c.

References ast_debug, ast_extension_match(), ast_free, AST_LIST_INSERT_HEAD, ast_log, ast_skip_blanks(), ast_strdup, ast_strdupa, ast_trim_blanks(), ast_var_assign, ast_var_delete(), ast_variable_browse(), ast_var_t::entries, varshead::first, say_args_t::language, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, pbx_substitute_variables_varshead(), s_streamwait3(), strsep(), and ast_variable::value.

Referenced by say_date_generic(), say_enumeration_full(), say_full(), and say_number_full().

174 {
175  struct ast_variable *v;
176  char *lang;
177  char *x;
178  char *rule = NULL;
179  char *rule_head = NULL;
180  int ret = 0;
181  struct varshead head = { .first = NULL, .last = NULL };
182  struct ast_var_t *n;
183 
184  ast_debug(2, "string <%s> depth <%d>\n", s, depth);
185  if (depth++ > 10) {
186  ast_log(LOG_WARNING, "recursion too deep, exiting\n");
187  return -1;
188  } else if (!say_cfg) {
189  ast_log(LOG_WARNING, "no say.conf, cannot spell '%s'\n", s);
190  return -1;
191  }
192 
193  /* scan languages same as in file.c */
194  if (a->language == NULL)
195  a->language = "en"; /* default */
196  ast_debug(2, "try <%s> in <%s>\n", s, a->language);
197  lang = ast_strdupa(a->language);
198  for (;;) {
199  for (v = ast_variable_browse(say_cfg, lang); v ; v = v->next) {
200  if (ast_extension_match(v->name, s)) {
201  rule_head = rule = ast_strdup(v->value);
202  break;
203  }
204  }
205  if (rule)
206  break;
207  if ( (x = strchr(lang, '_')) )
208  *x = '\0'; /* try without suffix */
209  else if (strcmp(lang, "en"))
210  lang = "en"; /* last resort, try 'en' if not done yet */
211  else
212  break;
213  }
214  if (!rule)
215  return 0;
216 
217  /* skip up to two prefixes to get the value */
218  if ( (x = strchr(s, ':')) )
219  s = x + 1;
220  if ( (x = strchr(s, ':')) )
221  s = x + 1;
222  ast_debug(2, "value is <%s>\n", s);
223  n = ast_var_assign("SAY", s);
224  if (!n) {
225  ast_log(LOG_ERROR, "Memory allocation error in do_say\n");
226  ast_free(rule_head);
227  return -1;
228  }
229  AST_LIST_INSERT_HEAD(&head, n, entries);
230 
231  /* scan the body, one piece at a time */
232  while ( !ret && (x = strsep(&rule, ",")) ) { /* exit on key */
233  char fn[128];
234  const char *p, *fmt, *data; /* format and data pointers */
235 
236  /* prepare a decent file name */
237  x = ast_skip_blanks(x);
238  ast_trim_blanks(x);
239 
240  /* replace variables */
241  pbx_substitute_variables_varshead(&head, x, fn, sizeof(fn));
242  ast_debug(2, "doing [%s]\n", fn);
243 
244  /* locate prefix and data, if any */
245  fmt = strchr(fn, ':');
246  if (!fmt || fmt == fn) { /* regular filename */
247  ret = s_streamwait3(a, fn);
248  continue;
249  }
250  fmt++;
251  data = strchr(fmt, ':'); /* colon before data */
252  if (!data || data == fmt) { /* simple prefix-fmt */
253  ret = do_say(a, fn, options, depth);
254  continue;
255  }
256  /* prefix:fmt:data */
257  for (p = fmt; p < data && ret <= 0; p++) {
258  char fn2[sizeof(fn)];
259  if (*p == ' ' || *p == '\t') /* skip blanks */
260  continue;
261  if (*p == '\'') {/* file name - we trim them */
262  char *y;
263  strcpy(fn2, ast_skip_blanks(p+1)); /* make a full copy */
264  y = strchr(fn2, '\'');
265  if (!y) {
266  p = data; /* invalid. prepare to end */
267  break;
268  }
269  *y = '\0';
270  ast_trim_blanks(fn2);
271  p = strchr(p+1, '\'');
272  ret = s_streamwait3(a, fn2);
273  } else {
274  int l = fmt-fn;
275  strcpy(fn2, fn); /* copy everything */
276  /* after prefix, append the format */
277  fn2[l++] = *p;
278  strcpy(fn2 + l, data);
279  ret = do_say(a, fn2, options, depth);
280  }
281 
282  if (ret) {
283  break;
284  }
285  }
286  }
287  ast_var_delete(n);
288  ast_free(rule_head);
289  return ret;
290 }
struct ast_variable * next
const char * language
Definition: app_playback.c:150
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
the string is &#39;prefix:data&#39; or prefix:fmt:data&#39; with &#39;:&#39; being invalid in strings.
Definition: app_playback.c:173
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
#define LOG_WARNING
Definition: logger.h:274
Structure for variables, used for configurations and for channel variables.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
#define ast_log
Definition: astobj2.c:42
struct ast_var_t::@243 entries
static struct ast_config * say_cfg
Definition: app_playback.c:96
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static int s_streamwait3(const say_args_t *a, const char *fn)
Definition: app_playback.c:155
struct ast_var_t * first
Definition: chanvars.h:34
#define LOG_ERROR
Definition: logger.h:285
void ast_var_delete(struct ast_var_t *var)
Definition: extconf.c:2473
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
Definition: strings.h:182
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_free(a)
Definition: astmm.h:182
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: extconf.c:4297
#define ast_var_assign(name, value)
Definition: chanvars.h:40
char * strsep(char **str, const char *delims)
static struct test_options options
void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count)

◆ load_module()

static int load_module ( void  )
static

Definition at line 558 of file app_playback.c.

References app, ARRAY_LEN, ast_cli_register_multiple, ast_config_load, ast_extension_match(), AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ast_register_application_xml, ast_variable_browse(), ASTERISK_GPL_KEY, CONFIG_STATUS_FILEINVALID, ast_variable::name, ast_variable::next, playback_exec(), reload(), say_init_mode(), unload_module(), and ast_variable::value.

559 {
560  struct ast_variable *v;
561  struct ast_flags config_flags = { 0 };
562 
563  say_cfg = ast_config_load("say.conf", config_flags);
565  for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
566  if (ast_extension_match(v->name, "mode")) {
567  say_init_mode(v->value);
568  break;
569  }
570  }
571  }
572 
575 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
#define CONFIG_STATUS_FILEINVALID
Structure for variables, used for configurations and for channel variables.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry cli_playback[]
Definition: app_playback.c:438
#define ast_config_load(filename, flags)
Load a config file.
static struct ast_config * say_cfg
Definition: app_playback.c:96
static char * app
Definition: app_playback.c:94
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: extconf.c:4297
Structure used to handle boolean flags.
Definition: utils.h:199
static int playback_exec(struct ast_channel *chan, const char *data)
Definition: app_playback.c:442
static int say_init_mode(const char *mode)
remap the &#39;say&#39; functions to use those in this file
Definition: app_playback.c:369
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ playback_exec()

static int playback_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 442 of file app_playback.c.

References args, ast_answer(), AST_APP_ARG, ast_channel_language(), ast_channel_name(), ast_check_hangup(), AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero, ast_waitstream(), done, LOG_WARNING, NULL, options, pbx_builtin_setvar_helper(), say_full(), strcasestr(), strsep(), and tmp().

Referenced by load_module().

443 {
444  int res = 0;
445  int mres = 0;
446  char *tmp;
447  int option_skip=0;
448  int option_say=0;
449  int option_noanswer = 0;
450 
452  AST_APP_ARG(filenames);
454  );
455 
456  if (ast_strlen_zero(data)) {
457  ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
458  return -1;
459  }
460 
461  tmp = ast_strdupa(data);
463 
464  if (args.options) {
465  if (strcasestr(args.options, "skip"))
466  option_skip = 1;
467  if (strcasestr(args.options, "say"))
468  option_say = 1;
469  if (strcasestr(args.options, "noanswer"))
470  option_noanswer = 1;
471  }
472  if (ast_channel_state(chan) != AST_STATE_UP) {
473  if (option_skip) {
474  /* At the user's option, skip if the line is not up */
475  goto done;
476  } else if (!option_noanswer) {
477  /* Otherwise answer unless we're supposed to send this while on-hook */
478  res = ast_answer(chan);
479  }
480  }
481  if (!res) {
482  char *back = args.filenames;
483  char *front;
484 
485  ast_stopstream(chan);
486  while (!res && (front = strsep(&back, "&"))) {
487  if (option_say)
488  res = say_full(chan, front, "", ast_channel_language(chan), NULL, -1, -1);
489  else
490  res = ast_streamfile(chan, front, ast_channel_language(chan));
491  if (!res) {
492  res = ast_waitstream(chan, "");
493  ast_stopstream(chan);
494  }
495  if (res) {
496  if (!ast_check_hangup(chan)) {
497  ast_log(LOG_WARNING, "Playback failed on %s for %s\n", ast_channel_name(chan), (char *)data);
498  }
499  res = 0;
500  mres = 1;
501  }
502  }
503  }
504 done:
505  pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", mres ? "FAILED" : "SUCCESS");
506  return res;
507 }
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1250
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
ast_channel_state
ast_channel states
Definition: channelstate.h:35
const char * args
#define NULL
Definition: resample.c:96
int done
Definition: test_amihooks.c:48
#define ast_log
Definition: astobj2.c:42
static int say_full(struct ast_channel *chan, const char *string, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd)
Definition: app_playback.c:292
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:441
char * strcasestr(const char *, const char *)
#define ast_strlen_zero(a)
Definition: muted.c:73
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...
char * strsep(char **str, const char *delims)
const char * ast_channel_name(const struct ast_channel *chan)
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1775
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2780
const char * ast_channel_language(const struct ast_channel *chan)
static struct test_options options
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:187
#define AST_APP_ARG(name)
Define an application argument.

◆ reload()

static int reload ( void  )
static
Todo:
XXX here we should sort rules according to the same order we have in pbx.c so we have the same matching behaviour.

Definition at line 509 of file app_playback.c.

References ast_config_destroy(), ast_config_load, ast_extension_match(), ast_log, ast_variable_browse(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, LOG_ERROR, LOG_NOTICE, ast_variable::name, ast_variable::next, say_init_mode(), and ast_variable::value.

Referenced by load_module().

510 {
511  struct ast_variable *v;
512  struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
513  struct ast_config *newcfg;
514 
515  if ((newcfg = ast_config_load("say.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
516  return 0;
517  } else if (newcfg == CONFIG_STATUS_FILEINVALID) {
518  ast_log(LOG_ERROR, "Config file say.conf is in an invalid format. Aborting.\n");
519  return 0;
520  }
521 
522  if (say_cfg) {
524  ast_log(LOG_NOTICE, "Reloading say.conf\n");
525  }
526  say_cfg = newcfg;
527 
528  if (say_cfg) {
529  for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
530  if (ast_extension_match(v->name, "mode")) {
531  say_init_mode(v->value);
532  break;
533  }
534  }
535  }
536 
537  /*! \todo
538  * XXX here we should sort rules according to the same order
539  * we have in pbx.c so we have the same matching behaviour.
540  */
541  return 0;
542 }
struct ast_variable * next
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
#define CONFIG_STATUS_FILEINVALID
Structure for variables, used for configurations and for channel variables.
#define ast_log
Definition: astobj2.c:42
#define ast_config_load(filename, flags)
Load a config file.
static struct ast_config * say_cfg
Definition: app_playback.c:96
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define CONFIG_STATUS_FILEUNCHANGED
#define LOG_ERROR
Definition: logger.h:285
#define LOG_NOTICE
Definition: logger.h:263
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: extconf.c:4297
Structure used to handle boolean flags.
Definition: utils.h:199
static int say_init_mode(const char *mode)
remap the &#39;say&#39; functions to use those in this file
Definition: app_playback.c:369

◆ restore_say_mode()

static void restore_say_mode ( void *  arg)
static

Definition at line 124 of file app_playback.c.

References ast_say_character_str_full, ast_say_date, ast_say_date_with_format, ast_say_datetime, ast_say_datetime_from_now, ast_say_digit_str_full, ast_say_enumeration_full, ast_say_number_full, ast_say_phonetic_str_full, ast_say_time, and say_api_buf.

Referenced by say_init_mode().

125 {
126  int i = 0;
127  say_api_buf[i++] = arg;
128 
135  ast_say_time = say_api_buf[i++];
136  ast_say_date = say_api_buf[i++];
139 }
SAY_EXTERN int(* ast_say_number_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_number_full)
Same as ast_say_number() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:86
SAY_EXTERN int(* ast_say_time)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_time)
Definition: say.h:175
SAY_EXTERN int(* ast_say_enumeration_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_enumeration_full)
Same as ast_say_enumeration() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:106
SAY_EXTERN int(* ast_say_datetime_from_now)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_datetime_from_now)
Definition: say.h:179
SAY_EXTERN int(* ast_say_digit_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_digit_str_full)
Same as ast_say_digit_str() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:143
SAY_EXTERN int(* ast_say_date)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_date)
Definition: say.h:177
SAY_EXTERN int(* ast_say_date_with_format)(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone) SAY_INIT(ast_say_date_with_format)
Definition: say.h:181
static const void * say_api_buf[40]
save the say&#39; api calls. The first entry is NULL if we have the standard source, otherwise we are sou...
Definition: app_playback.c:103
SAY_EXTERN int(* ast_say_datetime)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_datetime)
Definition: say.h:174
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:167
SAY_EXTERN int(* ast_say_phonetic_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_phonetic_str_full)
Definition: say.h:172

◆ s_streamwait3()

static int s_streamwait3 ( const say_args_t a,
const char *  fn 
)
static

Definition at line 155 of file app_playback.c.

References ast_log, ast_stopstream(), ast_streamfile(), ast_waitstream(), ast_waitstream_full(), say_args_t::audiofd, say_args_t::chan, say_args_t::ctrlfd, say_args_t::ints, say_args_t::language, and LOG_WARNING.

Referenced by do_say().

156 {
157  int res = ast_streamfile(a->chan, fn, a->language);
158  if (res) {
159  ast_log(LOG_WARNING, "Unable to play message %s\n", fn);
160  return res;
161  }
162  res = (a->audiofd > -1 && a->ctrlfd > -1) ?
163  ast_waitstream_full(a->chan, a->ints, a->audiofd, a->ctrlfd) :
164  ast_waitstream(a->chan, a->ints);
165  ast_stopstream(a->chan);
166  return res;
167 }
const char * language
Definition: app_playback.c:150
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1250
#define LOG_WARNING
Definition: logger.h:274
const char * ints
Definition: app_playback.c:149
#define ast_log
Definition: astobj2.c:42
struct ast_channel * chan
Definition: app_playback.c:148
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd)
Definition: file.c:1784
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1775
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:187

◆ save_say_mode()

static void save_say_mode ( const void *  arg)
static

Definition at line 107 of file app_playback.c.

References ast_say_character_str_full, ast_say_date, ast_say_date_with_format, ast_say_datetime, ast_say_datetime_from_now, ast_say_digit_str_full, ast_say_enumeration_full, ast_say_number_full, ast_say_phonetic_str_full, ast_say_time, and say_api_buf.

Referenced by say_init_mode().

108 {
109  int i = 0;
110  say_api_buf[i++] = arg;
111 
118  say_api_buf[i++] = ast_say_time;
119  say_api_buf[i++] = ast_say_date;
122 }
SAY_EXTERN int(* ast_say_number_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_number_full)
Same as ast_say_number() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:86
SAY_EXTERN int(* ast_say_time)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_time)
Definition: say.h:175
SAY_EXTERN int(* ast_say_enumeration_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_enumeration_full)
Same as ast_say_enumeration() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:106
SAY_EXTERN int(* ast_say_datetime_from_now)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_datetime_from_now)
Definition: say.h:179
SAY_EXTERN int(* ast_say_digit_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_digit_str_full)
Same as ast_say_digit_str() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:143
SAY_EXTERN int(* ast_say_date)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_date)
Definition: say.h:177
SAY_EXTERN int(* ast_say_date_with_format)(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone) SAY_INIT(ast_say_date_with_format)
Definition: say.h:181
static const void * say_api_buf[40]
save the say&#39; api calls. The first entry is NULL if we have the standard source, otherwise we are sou...
Definition: app_playback.c:103
SAY_EXTERN int(* ast_say_datetime)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_datetime)
Definition: say.h:174
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:167
SAY_EXTERN int(* ast_say_phonetic_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_phonetic_str_full)
Definition: say.h:172

◆ say_date()

static int say_date ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang 
)
static

Definition at line 351 of file app_playback.c.

References NULL, and say_date_generic().

Referenced by say_init_mode().

352 {
353  return say_date_generic(chan, t, ints, lang, "", NULL, "date");
354 }
#define NULL
Definition: resample.c:96
static int say_date_generic(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezonename, const char *prefix)
Definition: app_playback.c:320

◆ say_date_generic()

static int say_date_generic ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang,
const char *  format,
const char *  timezonename,
const char *  prefix 
)
static

Definition at line 320 of file app_playback.c.

References a, ast_localtime(), buf, do_say(), NULL, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, ast_tm::tm_sec, ast_tm::tm_wday, ast_tm::tm_yday, and ast_tm::tm_year.

Referenced by say_date(), say_date_with_format(), say_datetime(), and say_time().

322 {
323  char buf[128];
324  struct ast_tm tm;
325  struct timeval when = { t, 0 };
326  say_args_t a = { chan, ints, lang, -1, -1 };
327  if (format == NULL)
328  format = "";
329 
330  ast_localtime(&when, &tm, timezonename);
331  snprintf(buf, sizeof(buf), "%s:%s:%04d%02d%02d%02d%02d.%02d-%d-%3d",
332  prefix,
333  format,
334  tm.tm_year+1900,
335  tm.tm_mon+1,
336  tm.tm_mday,
337  tm.tm_hour,
338  tm.tm_min,
339  tm.tm_sec,
340  tm.tm_wday,
341  tm.tm_yday);
342  return do_say(&a, buf, NULL, 0);
343 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
the string is &#39;prefix:data&#39; or prefix:fmt:data&#39; with &#39;:&#39; being invalid in strings.
Definition: app_playback.c:173
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
#define NULL
Definition: resample.c:96
Typical &#39;say&#39; arguments in addition to the date or number or string to say. We do not include &#39;option...
Definition: app_playback.c:147
static snd_pcm_format_t format
Definition: chan_alsa.c:102
static char prefix[MAX_PREFIX]
Definition: http.c:141
static struct test_val a

◆ say_date_with_format()

static int say_date_with_format ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang,
const char *  format,
const char *  timezonename 
)
static

Definition at line 345 of file app_playback.c.

References say_date_generic().

Referenced by say_init_mode().

347 {
348  return say_date_generic(chan, t, ints, lang, format, timezonename, "datetime");
349 }
static int say_date_generic(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezonename, const char *prefix)
Definition: app_playback.c:320
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ say_datetime()

static int say_datetime ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang 
)
static

Definition at line 361 of file app_playback.c.

References NULL, and say_date_generic().

Referenced by say_init_mode().

362 {
363  return say_date_generic(chan, t, ints, lang, "", NULL, "datetime");
364 }
#define NULL
Definition: resample.c:96
static int say_date_generic(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezonename, const char *prefix)
Definition: app_playback.c:320

◆ say_enumeration_full()

static int say_enumeration_full ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang,
const char *  options,
int  audiofd,
int  ctrlfd 
)
static

Definition at line 310 of file app_playback.c.

References a, buf, and do_say().

Referenced by say_init_mode().

313 {
314  char buf[64];
315  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
316  snprintf(buf, sizeof(buf), "enum:%d", num);
317  return do_say(&a, buf, options, 0);
318 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
the string is &#39;prefix:data&#39; or prefix:fmt:data&#39; with &#39;:&#39; being invalid in strings.
Definition: app_playback.c:173
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
Typical &#39;say&#39; arguments in addition to the date or number or string to say. We do not include &#39;option...
Definition: app_playback.c:147
static struct test_options options
static struct test_val a

◆ say_full()

static int say_full ( struct ast_channel chan,
const char *  string,
const char *  ints,
const char *  lang,
const char *  options,
int  audiofd,
int  ctrlfd 
)
static

Definition at line 292 of file app_playback.c.

References a, and do_say().

Referenced by playback_exec().

295 {
296  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
297  return do_say(&a, string, options, 0);
298 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
the string is &#39;prefix:data&#39; or prefix:fmt:data&#39; with &#39;:&#39; being invalid in strings.
Definition: app_playback.c:173
Typical &#39;say&#39; arguments in addition to the date or number or string to say. We do not include &#39;option...
Definition: app_playback.c:147
static struct test_options options
static struct test_val a

◆ say_init_mode()

static int say_init_mode ( const char *  mode)
static

remap the 'say' functions to use those in this file

Definition at line 369 of file app_playback.c.

References ast_log, ast_say_character_str_full, ast_say_date, ast_say_date_with_format, ast_say_datetime, ast_say_datetime_from_now, ast_say_digit_str_full, ast_say_digits_full(), ast_say_enumeration_full, ast_say_number_full, ast_say_phonetic_str_full, ast_say_time, LOG_ERROR, LOG_WARNING, NULL, restore_say_mode(), save_say_mode(), say_api_buf, say_character_str_full(), say_date(), say_date_with_format(), say_datetime(), say_datetime_from_now(), say_digit_str_full(), say_enumeration_full(), say_new, say_number_full(), say_old, say_phonetic_str_full(), and say_time().

Referenced by __say_cli_init(), load_module(), and reload().

369  {
370  if (!strcmp(mode, say_new)) {
371  if (say_cfg == NULL) {
372  ast_log(LOG_ERROR, "There is no say.conf file to use new mode\n");
373  return -1;
374  }
377 
379 #if 0
380  /*! \todo XXX
381  These functions doesn't exist.
382  say.conf.sample indicates this is working...
383  */
384  ast_say_digits_full = say_digits_full;
389 #endif
394  } else if (!strcmp(mode, say_old) && say_api_buf[0] == say_new) {
396  } else if (strcmp(mode, say_old)) {
397  ast_log(LOG_WARNING, "unrecognized mode %s\n", mode);
398  return -1;
399  }
400 
401  return 0;
402 }
static void save_say_mode(const void *arg)
Definition: app_playback.c:107
static int say_character_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd)
Definition: say.c:62
SAY_EXTERN int(* ast_say_number_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_number_full)
Same as ast_say_number() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:86
SAY_EXTERN int(* ast_say_time)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_time)
Definition: say.h:175
SAY_EXTERN int(* ast_say_enumeration_full)(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd) SAY_INIT(ast_say_enumeration_full)
Same as ast_say_enumeration() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:106
static int say_date_with_format(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezonename)
Definition: app_playback.c:345
static int say_number_full(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd)
Definition: app_playback.c:300
#define LOG_WARNING
Definition: logger.h:274
SAY_EXTERN int(* ast_say_datetime_from_now)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_datetime_from_now)
Definition: say.h:179
int ast_say_digits_full(struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd)
Same as ast_say_digits() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: channel.c:8212
static int say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: say.c:7613
#define NULL
Definition: resample.c:96
static int say_enumeration_full(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options, int audiofd, int ctrlfd)
Definition: app_playback.c:310
#define ast_log
Definition: astobj2.c:42
SAY_EXTERN int(* ast_say_digit_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_digit_str_full)
Same as ast_say_digit_str() with audiofd for received audio and returns 1 on ctrlfd being readable...
Definition: say.h:143
static struct ast_config * say_cfg
Definition: app_playback.c:96
static int say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:361
SAY_EXTERN int(* ast_say_date)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_date)
Definition: say.h:177
SAY_EXTERN int(* ast_say_date_with_format)(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone) SAY_INIT(ast_say_date_with_format)
Definition: say.h:181
#define LOG_ERROR
Definition: logger.h:285
static const void * say_api_buf[40]
save the say&#39; api calls. The first entry is NULL if we have the standard source, otherwise we are sou...
Definition: app_playback.c:103
static int say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:356
SAY_EXTERN int(* ast_say_datetime)(struct ast_channel *chan, time_t t, const char *ints, const char *lang) SAY_INIT(ast_say_datetime)
Definition: say.h:174
static int say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:351
static int say_digit_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
Definition: say.c:255
static int say_phonetic_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
Definition: say.c:175
static const char *const say_new
Definition: app_playback.c:105
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:167
SAY_EXTERN int(* ast_say_phonetic_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_phonetic_str_full)
Definition: say.h:172
static const char *const say_old
Definition: app_playback.c:104
static void restore_say_mode(void *arg)
Definition: app_playback.c:124

◆ say_number_full()

static int say_number_full ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang,
const char *  options,
int  audiofd,
int  ctrlfd 
)
static

Definition at line 300 of file app_playback.c.

References a, buf, and do_say().

Referenced by say_init_mode().

303 {
304  char buf[64];
305  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
306  snprintf(buf, sizeof(buf), "num:%d", num);
307  return do_say(&a, buf, options, 0);
308 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
the string is &#39;prefix:data&#39; or prefix:fmt:data&#39; with &#39;:&#39; being invalid in strings.
Definition: app_playback.c:173
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
Typical &#39;say&#39; arguments in addition to the date or number or string to say. We do not include &#39;option...
Definition: app_playback.c:147
static struct test_options options
static struct test_val a

◆ say_time()

static int say_time ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang 
)
static

Definition at line 356 of file app_playback.c.

References NULL, and say_date_generic().

Referenced by say_init_mode().

357 {
358  return say_date_generic(chan, t, ints, lang, "", NULL, "time");
359 }
#define NULL
Definition: resample.c:96
static int say_date_generic(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezonename, const char *prefix)
Definition: app_playback.c:320

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 544 of file app_playback.c.

References app, ARRAY_LEN, ast_cli_unregister_multiple(), ast_config_destroy(), and ast_unregister_application().

Referenced by load_module().

545 {
546  int res;
547 
549 
551 
552  if (say_cfg)
554 
555  return res;
556 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_cli_entry cli_playback[]
Definition: app_playback.c:438
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static struct ast_config * say_cfg
Definition: app_playback.c:96
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
static char * app
Definition: app_playback.c:94

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Sound File Playback Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, }
static

Definition at line 582 of file app_playback.c.

◆ app

char* app = "Playback"
static

< provides config-file based 'say' functions

Definition at line 94 of file app_playback.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 582 of file app_playback.c.

◆ cli_playback

struct ast_cli_entry cli_playback[]
static
Initial value:
= {
{ .handler = __say_cli_init , .summary = "Set or show the say mode" ,},
}
static char * __say_cli_init(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: app_playback.c:404

Definition at line 438 of file app_playback.c.

◆ say_api_buf

const void* say_api_buf[40]
static

save the say' api calls. The first entry is NULL if we have the standard source, otherwise we are sourcing from here. 'say load [new|old]' will enable the new or old method, or report status

Definition at line 103 of file app_playback.c.

Referenced by __say_cli_init(), restore_say_mode(), save_say_mode(), and say_init_mode().

◆ say_cfg

struct ast_config* say_cfg = NULL
static

Definition at line 96 of file app_playback.c.

◆ say_new

const char* const say_new = "new"
static

Definition at line 105 of file app_playback.c.

Referenced by __say_cli_init(), and say_init_mode().

◆ say_old

const char* const say_old = "old"
static

Definition at line 104 of file app_playback.c.

Referenced by __say_cli_init(), and say_init_mode().