Asterisk - The Open Source Telephony Project  GIT-master-a24979a
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"
Include dependency graph for app_playback.c:

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 598 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 410 of file app_playback.c.

411 {
412  const char *old_mode = say_api_buf[0] ? say_new : say_old;
413  const char *mode;
414  switch (cmd) {
415  case CLI_INIT:
416  e->command = "say load [new|old]";
417  e->usage =
418  "Usage: say load [new|old]\n"
419  " say load\n"
420  " Report status of current say mode\n"
421  " say load new\n"
422  " Set say method, configured in say.conf\n"
423  " say load old\n"
424  " Set old say method, coded in asterisk core\n";
425  return NULL;
426  case CLI_GENERATE:
427  return NULL;
428  }
429  if (a->argc == 2) {
430  ast_cli(a->fd, "say mode is [%s]\n", old_mode);
431  return CLI_SUCCESS;
432  } else if (a->argc != e->args)
433  return CLI_SHOWUSAGE;
434  mode = a->argv[2];
435  if (!strcmp(mode, old_mode))
436  ast_cli(a->fd, "say mode is %s already\n", mode);
437  else
438  if (say_init_mode(mode) == 0)
439  ast_cli(a->fd, "setting say mode from %s to %s\n", old_mode, mode);
440 
441  return CLI_SUCCESS;
442 }
static const char *const say_old
Definition: app_playback.c:110
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:109
static const char *const say_new
Definition: app_playback.c:111
static int say_init_mode(const char *mode)
remap the 'say' functions to use those in this file
Definition: app_playback.c:375
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_SUCCESS
Definition: cli.h:44
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 NULL
Definition: resample.c:96
int args
This gets set in ast_cli_register()
Definition: cli.h:185
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
static struct test_val a

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

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 598 of file app_playback.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 598 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 179 of file app_playback.c.

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

References a, 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, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, options, pbx_substitute_variables_varshead(), s_streamwait3(), say_cfg, strsep(), and ast_variable::value.

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

◆ load_module()

static int load_module ( void  )
static

Definition at line 574 of file app_playback.c.

575 {
576  struct ast_variable *v;
577  struct ast_flags config_flags = { 0 };
578 
579  say_cfg = ast_config_load("say.conf", config_flags);
581  for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
582  if (ast_extension_match(v->name, "mode")) {
583  say_init_mode(v->value);
584  break;
585  }
586  }
587  }
588 
591 }
static char * app
Definition: app_playback.c:100
static struct ast_cli_entry cli_playback[]
Definition: app_playback.c:444
static int playback_exec(struct ast_channel *chan, const char *data)
Definition: app_playback.c:448
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ast_config_load(filename, flags)
Load a config file.
#define CONFIG_STATUS_FILEINVALID
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
Structure used to handle boolean flags.
Definition: utils.h:199
#define ARRAY_LEN(a)
Definition: utils.h:661

◆ playback_exec()

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

Definition at line 448 of file app_playback.c.

449 {
450  int res = 0;
451  int mres = 0;
452  char *tmp;
453  int option_skip=0;
454  int option_say=0;
455  int option_mix=0;
456  int option_noanswer = 0;
457 
459  AST_APP_ARG(filenames);
461  );
462 
463  if (ast_strlen_zero(data)) {
464  ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
465  return -1;
466  }
467 
468  tmp = ast_strdupa(data);
470 
471  if (args.options) {
472  if (strcasestr(args.options, "skip"))
473  option_skip = 1;
474  if (strcasestr(args.options, "say"))
475  option_say = 1;
476  if (strcasestr(args.options, "mix"))
477  option_mix = 1;
478  if (strcasestr(args.options, "noanswer"))
479  option_noanswer = 1;
480  }
481  if (ast_channel_state(chan) != AST_STATE_UP) {
482  if (option_skip) {
483  /* At the user's option, skip if the line is not up */
484  goto done;
485  } else if (!option_noanswer) {
486  /* Otherwise answer unless we're supposed to send this while on-hook */
487  res = ast_answer(chan);
488  }
489  }
490  if (!res) {
491  char *back = args.filenames;
492  char *front;
493 
494  ast_stopstream(chan);
495  while (!res && (front = strsep(&back, "&"))) {
496  if (option_say)
497  res = say_full(chan, front, "", ast_channel_language(chan), NULL, -1, -1);
498  else if (option_mix){
499  /* Check if it is in say format but not remote audio file */
500  if (strcasestr(front, ":") && !strcasestr(front, "://"))
501  res = say_full(chan, front, "", ast_channel_language(chan), NULL, -1, -1);
502  else
503  res = ast_streamfile(chan, front, ast_channel_language(chan));
504  }
505  else
506  res = ast_streamfile(chan, front, ast_channel_language(chan));
507  if (!res) {
508  res = ast_waitstream(chan, "");
509  ast_stopstream(chan);
510  }
511  if (res) {
512  if (!ast_check_hangup(chan)) {
513  ast_log(LOG_WARNING, "Playback failed on %s for %s\n", ast_channel_name(chan), (char *)data);
514  }
515  res = 0;
516  mres = 1;
517  }
518  }
519  }
520 done:
521  pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", mres ? "FAILED" : "SUCCESS");
522  return res;
523 }
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:298
static int tmp()
Definition: bt_open.c:389
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_language(const struct ast_channel *chan)
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2806
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1291
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1817
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
char * strcasestr(const char *, const char *)
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.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int done
Definition: test_amihooks.c:48
const char * args

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().

◆ 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 525 of file app_playback.c.

526 {
527  struct ast_variable *v;
528  struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
529  struct ast_config *newcfg;
530 
531  if ((newcfg = ast_config_load("say.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
532  return 0;
533  } else if (newcfg == CONFIG_STATUS_FILEINVALID) {
534  ast_log(LOG_ERROR, "Config file say.conf is in an invalid format. Aborting.\n");
535  return 0;
536  }
537 
538  if (say_cfg) {
540  ast_log(LOG_NOTICE, "Reloading say.conf\n");
541  }
542  say_cfg = newcfg;
543 
544  if (say_cfg) {
545  for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
546  if (ast_extension_match(v->name, "mode")) {
547  say_init_mode(v->value);
548  break;
549  }
550  }
551  }
552 
553  /*! \todo
554  * XXX here we should sort rules according to the same order
555  * we have in pbx.c so we have the same matching behaviour.
556  */
557  return 0;
558 }
@ CONFIG_FLAG_FILEUNCHANGED
#define CONFIG_STATUS_FILEUNCHANGED
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
#define LOG_NOTICE

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_cfg, say_init_mode(), and ast_variable::value.

◆ restore_say_mode()

static void restore_say_mode ( void *  arg)
static

Definition at line 130 of file app_playback.c.

131 {
132  int i = 0;
133  say_api_buf[i++] = arg;
134 
141  ast_say_time = say_api_buf[i++];
142  ast_say_date = say_api_buf[i++];
145 }
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:206
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:204
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_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:125
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:194
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:208
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:162
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:202
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:199
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:201

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().

◆ s_streamwait3()

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

Definition at line 161 of file app_playback.c.

162 {
163  int res = ast_streamfile(a->chan, fn, a->language);
164  if (res) {
165  ast_log(LOG_WARNING, "Unable to play message %s\n", fn);
166  return res;
167  }
168  res = (a->audiofd > -1 && a->ctrlfd > -1) ?
169  ast_waitstream_full(a->chan, a->ints, a->audiofd, a->ctrlfd) :
170  ast_waitstream(a->chan, a->ints);
171  ast_stopstream(a->chan);
172  return res;
173 }
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd)
Definition: file.c:1826

References a, ast_log, ast_stopstream(), ast_streamfile(), ast_waitstream(), ast_waitstream_full(), and LOG_WARNING.

Referenced by do_say().

◆ save_say_mode()

static void save_say_mode ( const void *  arg)
static

◆ say_date()

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

Definition at line 357 of file app_playback.c.

358 {
359  return say_date_generic(chan, t, ints, lang, "", NULL, "date");
360 }
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:326

References NULL, and say_date_generic().

Referenced by say_init_mode().

◆ 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 326 of file app_playback.c.

328 {
329  char buf[128];
330  struct ast_tm tm;
331  struct timeval when = { t, 0 };
332  say_args_t a = { chan, ints, lang, -1, -1 };
333  if (format == NULL)
334  format = "";
335 
336  ast_localtime(&when, &tm, timezonename);
337  snprintf(buf, sizeof(buf), "%s:%s:%04d%02d%02d%02d%02d.%02d-%d-%3d",
338  prefix,
339  format,
340  tm.tm_year+1900,
341  tm.tm_mon+1,
342  tm.tm_mday,
343  tm.tm_hour,
344  tm.tm_min,
345  tm.tm_sec,
346  tm.tm_wday,
347  tm.tm_yday);
348  return do_say(&a, buf, NULL, 0);
349 }
static snd_pcm_format_t format
Definition: chan_alsa.c:106
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static char prefix[MAX_PREFIX]
Definition: http.c:144
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
Typical 'say' arguments in addition to the date or number or string to say. We do not include 'option...
Definition: app_playback.c:153

References a, ast_localtime(), buf, do_say(), format, NULL, prefix, 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().

◆ 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 351 of file app_playback.c.

353 {
354  return say_date_generic(chan, t, ints, lang, format, timezonename, "datetime");
355 }

References format, and say_date_generic().

Referenced by say_init_mode().

◆ say_datetime()

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

Definition at line 367 of file app_playback.c.

368 {
369  return say_date_generic(chan, t, ints, lang, "", NULL, "datetime");
370 }

References NULL, and say_date_generic().

Referenced by say_init_mode().

◆ 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 316 of file app_playback.c.

319 {
320  char buf[64];
321  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
322  snprintf(buf, sizeof(buf), "enum:%d", num);
323  return do_say(&a, buf, options, 0);
324 }

References a, buf, do_say(), and options.

Referenced by say_init_mode().

◆ 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 298 of file app_playback.c.

301 {
302  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
303  return do_say(&a, string, options, 0);
304 }

References a, do_say(), and options.

Referenced by playback_exec().

◆ 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 375 of file app_playback.c.

375  {
376  if (!strcmp(mode, say_new)) {
377  if (say_cfg == NULL) {
378  ast_log(LOG_ERROR, "There is no say.conf file to use new mode\n");
379  return -1;
380  }
383 
385 #if 0
386  /*! \todo XXX
387  These functions doesn't exist.
388  say.conf.sample indicates this is working...
389  */
390  ast_say_digits_full = say_digits_full;
395 #endif
400  } else if (!strcmp(mode, say_old) && say_api_buf[0] == say_new) {
402  } else if (strcmp(mode, say_old)) {
403  ast_log(LOG_WARNING, "unrecognized mode %s\n", mode);
404  return -1;
405  }
406 
407  return 0;
408 }
static int say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:362
static void restore_say_mode(void *arg)
Definition: app_playback.c:130
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:351
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:316
static void save_say_mode(const void *arg)
Definition: app_playback.c:113
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:306
static int say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:367
static int say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:357
static int say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: say.c:7967
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:353
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:299
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:215
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:8366

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_cfg, 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(), and reload().

◆ 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 306 of file app_playback.c.

309 {
310  char buf[64];
311  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
312  snprintf(buf, sizeof(buf), "num:%d", num);
313  return do_say(&a, buf, options, 0);
314 }

References a, buf, do_say(), and options.

Referenced by say_init_mode().

◆ say_time()

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

Definition at line 362 of file app_playback.c.

363 {
364  return say_date_generic(chan, t, ints, lang, "", NULL, "time");
365 }

References NULL, and say_date_generic().

Referenced by say_init_mode().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 560 of file app_playback.c.

561 {
562  int res;
563 
565 
567 
568  if (say_cfg)
570 
571  return res;
572 }
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

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

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 574 of file app_playback.c.

◆ app

char* app = "Playback"
static

< provides config-file based 'say' functions

Definition at line 100 of file app_playback.c.

Referenced by unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 598 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:410

Definition at line 410 of file app_playback.c.

Referenced by unload_module().

◆ 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 109 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 102 of file app_playback.c.

Referenced by do_say(), reload(), say_init_mode(), and unload_module().

◆ say_new

const char* const say_new = "new"
static

Definition at line 111 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 110 of file app_playback.c.

Referenced by __say_cli_init(), and say_init_mode().