Wed Jan 8 2020 09:49:54

Asterisk developer's documentation


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
 

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)
 
static int do_say (say_args_t *a, const char *s, const char *options, int depth)
 
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)
 
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, }
 
static char * app = "Playback"
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_playback []
 
static const void * say_api_buf [40]
 
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

static void __reg_module ( void  )
static

Definition at line 562 of file app_playback.c.

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

Definition at line 388 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, say_init_mode(), say_old, and ast_cli_entry::usage.

389 {
390  const char *old_mode = say_api_buf[0] ? say_new : say_old;
391  const char *mode;
392  switch (cmd) {
393  case CLI_INIT:
394  e->command = "say load [new|old]";
395  e->usage =
396  "Usage: say load [new|old]\n"
397  " say load\n"
398  " Report status of current say mode\n"
399  " say load new\n"
400  " Set say method, configured in say.conf\n"
401  " say load old\n"
402  " Set old say method, coded in asterisk core\n";
403  return NULL;
404  case CLI_GENERATE:
405  return NULL;
406  }
407  if (a->argc == 2) {
408  ast_cli(a->fd, "say mode is [%s]\n", old_mode);
409  return CLI_SUCCESS;
410  } else if (a->argc != e->args)
411  return CLI_SHOWUSAGE;
412  mode = a->argv[2];
413  if (!strcmp(mode, old_mode))
414  ast_cli(a->fd, "say mode is %s already\n", mode);
415  else
416  if (say_init_mode(mode) == 0)
417  ast_cli(a->fd, "setting say mode from %s to %s\n", old_mode, mode);
418 
419  return CLI_SUCCESS;
420 }
const int argc
Definition: cli.h:154
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
static const void * say_api_buf[40]
Definition: app_playback.c:96
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static const char *const say_new
Definition: app_playback.c:98
static int say_init_mode(const char *mode)
Definition: app_playback.c:357
static const char *const say_old
Definition: app_playback.c:97
static void __unreg_module ( void  )
static

Definition at line 562 of file app_playback.c.

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

Definition at line 166 of file app_playback.c.

References ast_debug, ast_extension_match(), AST_LIST_INSERT_HEAD, ast_log(), ast_skip_blanks(), 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, 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().

167 {
168  struct ast_variable *v;
169  char *lang, *x, *rule = NULL;
170  int ret = 0;
171  struct varshead head = { .first = NULL, .last = NULL };
172  struct ast_var_t *n;
173 
174  ast_debug(2, "string <%s> depth <%d>\n", s, depth);
175  if (depth++ > 10) {
176  ast_log(LOG_WARNING, "recursion too deep, exiting\n");
177  return -1;
178  } else if (!say_cfg) {
179  ast_log(LOG_WARNING, "no say.conf, cannot spell '%s'\n", s);
180  return -1;
181  }
182 
183  /* scan languages same as in file.c */
184  if (a->language == NULL)
185  a->language = "en"; /* default */
186  ast_debug(2, "try <%s> in <%s>\n", s, a->language);
187  lang = ast_strdupa(a->language);
188  for (;;) {
189  for (v = ast_variable_browse(say_cfg, lang); v ; v = v->next) {
190  if (ast_extension_match(v->name, s)) {
191  rule = ast_strdupa(v->value);
192  break;
193  }
194  }
195  if (rule)
196  break;
197  if ( (x = strchr(lang, '_')) )
198  *x = '\0'; /* try without suffix */
199  else if (strcmp(lang, "en"))
200  lang = "en"; /* last resort, try 'en' if not done yet */
201  else
202  break;
203  }
204  if (!rule)
205  return 0;
206 
207  /* skip up to two prefixes to get the value */
208  if ( (x = strchr(s, ':')) )
209  s = x + 1;
210  if ( (x = strchr(s, ':')) )
211  s = x + 1;
212  ast_debug(2, "value is <%s>\n", s);
213  n = ast_var_assign("SAY", s);
214  if (!n) {
215  ast_log(LOG_ERROR, "Memory allocation error in do_say\n");
216  return -1;
217  }
218  AST_LIST_INSERT_HEAD(&head, n, entries);
219 
220  /* scan the body, one piece at a time */
221  while ( !ret && (x = strsep(&rule, ",")) ) { /* exit on key */
222  char fn[128];
223  const char *p, *fmt, *data; /* format and data pointers */
224 
225  /* prepare a decent file name */
226  x = ast_skip_blanks(x);
227  ast_trim_blanks(x);
228 
229  /* replace variables */
230  pbx_substitute_variables_varshead(&head, x, fn, sizeof(fn));
231  ast_debug(2, "doing [%s]\n", fn);
232 
233  /* locate prefix and data, if any */
234  fmt = strchr(fn, ':');
235  if (!fmt || fmt == fn) { /* regular filename */
236  ret = s_streamwait3(a, fn);
237  continue;
238  }
239  fmt++;
240  data = strchr(fmt, ':'); /* colon before data */
241  if (!data || data == fmt) { /* simple prefix-fmt */
242  ret = do_say(a, fn, options, depth);
243  continue;
244  }
245  /* prefix:fmt:data */
246  for (p = fmt; p < data && ret <= 0; p++) {
247  char fn2[sizeof(fn)];
248  if (*p == ' ' || *p == '\t') /* skip blanks */
249  continue;
250  if (*p == '\'') {/* file name - we trim them */
251  char *y;
252  strcpy(fn2, ast_skip_blanks(p+1)); /* make a full copy */
253  y = strchr(fn2, '\'');
254  if (!y) {
255  p = data; /* invalid. prepare to end */
256  break;
257  }
258  *y = '\0';
259  ast_trim_blanks(fn2);
260  p = strchr(p+1, '\'');
261  ret = s_streamwait3(a, fn2);
262  } else {
263  int l = fmt-fn;
264  strcpy(fn2, fn); /* copy everything */
265  /* after prefix, append the format */
266  fn2[l++] = *p;
267  strcpy(fn2 + l, data);
268  ret = do_say(a, fn2, options, depth);
269  }
270 
271  if (ret) {
272  break;
273  }
274  }
275  }
276  ast_var_delete(n);
277  return ret;
278 }
const char * language
Definition: app_playback.c:143
char * strsep(char **str, const char *delims)
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
Definition: app_playback.c:166
struct ast_var_t * ast_var_assign(const char *name, const char *value)
Definition: chanvars.c:41
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
void ast_var_delete(struct ast_var_t *var)
Definition: chanvars.c:63
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
const char * value
Definition: config.h:79
struct ast_var_t * first
Definition: chanvars.h:34
static struct ast_config * say_cfg
Definition: app_playback.c:90
const char * name
Definition: config.h:77
static int s_streamwait3(const say_args_t *a, const char *fn)
Definition: app_playback.c:148
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:97
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
Definition: strings.h:122
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
struct ast_var_t::@158 entries
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: pbx.c:2943
struct ast_variable * next
Definition: config.h:82
void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count)
Definition: pbx.c:4682
static int load_module ( void  )
static

Definition at line 539 of file app_playback.c.

References ARRAY_LEN, ast_cli_register_multiple(), ast_config_load, ast_extension_match(), ast_register_application_xml, ast_variable_browse(), CONFIG_STATUS_FILEINVALID, ast_variable::name, ast_variable::next, playback_exec(), say_init_mode(), and ast_variable::value.

540 {
541  struct ast_variable *v;
542  struct ast_flags config_flags = { 0 };
543 
544  say_cfg = ast_config_load("say.conf", config_flags);
546  for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
547  if (ast_extension_match(v->name, "mode")) {
548  say_init_mode(v->value);
549  break;
550  }
551  }
552  }
553 
556 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static struct ast_cli_entry cli_playback[]
Definition: app_playback.c:422
const char * value
Definition: config.h:79
#define ast_config_load(filename, flags)
Load a config file.
Definition: config.h:170
static struct ast_config * say_cfg
Definition: app_playback.c:90
const char * name
Definition: config.h:77
static char * app
Definition: app_playback.c:88
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: pbx.c:2943
Structure used to handle boolean flags.
Definition: utils.h:200
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static int playback_exec(struct ast_channel *chan, const char *data)
Definition: app_playback.c:426
static int say_init_mode(const char *mode)
Definition: app_playback.c:357
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int playback_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 426 of file app_playback.c.

References ast_channel::_state, args, ast_answer(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_waitstream(), ast_channel::language, LOG_WARNING, ast_channel::name, pbx_builtin_setvar_helper(), say_full(), strcasestr(), and strsep().

Referenced by load_module().

427 {
428  int res = 0;
429  int mres = 0;
430  char *tmp;
431  int option_skip=0;
432  int option_say=0;
433  int option_noanswer = 0;
434 
436  AST_APP_ARG(filenames);
437  AST_APP_ARG(options);
438  );
439 
440  if (ast_strlen_zero(data)) {
441  ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
442  return -1;
443  }
444 
445  tmp = ast_strdupa(data);
447 
448  if (args.options) {
449  if (strcasestr(args.options, "skip"))
450  option_skip = 1;
451  if (strcasestr(args.options, "say"))
452  option_say = 1;
453  if (strcasestr(args.options, "noanswer"))
454  option_noanswer = 1;
455  }
456  if (chan->_state != AST_STATE_UP) {
457  if (option_skip) {
458  /* At the user's option, skip if the line is not up */
459  goto done;
460  } else if (!option_noanswer) {
461  /* Otherwise answer unless we're supposed to send this while on-hook */
462  res = ast_answer(chan);
463  }
464  }
465  if (!res) {
466  char *back = args.filenames;
467  char *front;
468 
469  ast_stopstream(chan);
470  while (!res && (front = strsep(&back, "&"))) {
471  if (option_say)
472  res = say_full(chan, front, "", chan->language, NULL, -1, -1);
473  else
474  res = ast_streamfile(chan, front, chan->language);
475  if (!res) {
476  res = ast_waitstream(chan, "");
477  ast_stopstream(chan);
478  } else {
479  ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
480  res = 0;
481  mres = 1;
482  }
483  }
484  }
485 done:
486  pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", mres ? "FAILED" : "SUCCESS");
487  return res;
488 }
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
char * strsep(char **str, const char *delims)
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
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:280
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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...
Definition: pbx.c:10546
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1343
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:3086
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
char * strcasestr(const char *, const char *)
const ast_string_field language
Definition: channel.h:787
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:128
static int reload ( void  )
static

Definition at line 490 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.

491 {
492  struct ast_variable *v;
493  struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
494  struct ast_config *newcfg;
495 
496  if ((newcfg = ast_config_load("say.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
497  return 0;
498  } else if (newcfg == CONFIG_STATUS_FILEINVALID) {
499  ast_log(LOG_ERROR, "Config file say.conf is in an invalid format. Aborting.\n");
500  return 0;
501  }
502 
503  if (say_cfg) {
505  ast_log(LOG_NOTICE, "Reloading say.conf\n");
506  }
507  say_cfg = newcfg;
508 
509  if (say_cfg) {
510  for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
511  if (ast_extension_match(v->name, "mode")) {
512  say_init_mode(v->value);
513  break;
514  }
515  }
516  }
517 
518  /*
519  * XXX here we should sort rules according to the same order
520  * we have in pbx.c so we have the same matching behaviour.
521  */
522  return 0;
523 }
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
const char * value
Definition: config.h:79
#define ast_config_load(filename, flags)
Load a config file.
Definition: config.h:170
static struct ast_config * say_cfg
Definition: app_playback.c:90
const char * name
Definition: config.h:77
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: pbx.c:2943
Structure used to handle boolean flags.
Definition: utils.h:200
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static int say_init_mode(const char *mode)
Definition: app_playback.c:357
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
static void restore_say_mode ( void *  arg)
static

Definition at line 117 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, and ast_say_time.

Referenced by say_init_mode().

118 {
119  int i = 0;
120  say_api_buf[i++] = arg;
121 
128  ast_say_time = say_api_buf[i++];
129  ast_say_date = say_api_buf[i++];
132 }
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:161
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:164
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)
Definition: say.h:105
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:159
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:154
static const void * say_api_buf[40]
Definition: app_playback.c:96
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:166
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)
Definition: say.h:140
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:168
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)
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:162
static int s_streamwait3 ( const say_args_t a,
const char *  fn 
)
static

Definition at line 148 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().

149 {
150  int res = ast_streamfile(a->chan, fn, a->language);
151  if (res) {
152  ast_log(LOG_WARNING, "Unable to play message %s\n", fn);
153  return res;
154  }
155  res = (a->audiofd > -1 && a->ctrlfd > -1) ?
156  ast_waitstream_full(a->chan, a->ints, a->audiofd, a->ctrlfd) :
157  ast_waitstream(a->chan, a->ints);
158  ast_stopstream(a->chan);
159  return res;
160 }
const char * language
Definition: app_playback.c:143
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
#define LOG_WARNING
Definition: logger.h:144
const char * ints
Definition: app_playback.c:142
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_channel * chan
Definition: app_playback.c:141
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd)
Definition: file.c:1348
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1343
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:128
static void save_say_mode ( const void *  arg)
static

Definition at line 100 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, and ast_say_time.

Referenced by say_init_mode().

101 {
102  int i = 0;
103  say_api_buf[i++] = arg;
104 
111  say_api_buf[i++] = ast_say_time;
112  say_api_buf[i++] = ast_say_date;
115 }
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:161
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:164
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)
Definition: say.h:105
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:159
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:154
static const void * say_api_buf[40]
Definition: app_playback.c:96
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:166
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)
Definition: say.h:140
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:168
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)
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:162
static int say_date ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang 
)
static

Definition at line 339 of file app_playback.c.

References say_date_generic().

Referenced by say_init_mode().

340 {
341  return say_date_generic(chan, t, ints, lang, "", NULL, "date");
342 }
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:308
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 308 of file app_playback.c.

References ast_localtime(), do_say(), 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().

310 {
311  char buf[128];
312  struct ast_tm tm;
313  struct timeval when = { t, 0 };
314  say_args_t a = { chan, ints, lang, -1, -1 };
315  if (format == NULL)
316  format = "";
317 
318  ast_localtime(&when, &tm, NULL);
319  snprintf(buf, sizeof(buf), "%s:%s:%04d%02d%02d%02d%02d.%02d-%d-%3d",
320  prefix,
321  format,
322  tm.tm_year+1900,
323  tm.tm_mon+1,
324  tm.tm_mday,
325  tm.tm_hour,
326  tm.tm_min,
327  tm.tm_sec,
328  tm.tm_wday,
329  tm.tm_yday);
330  return do_say(&a, buf, NULL, 0);
331 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
Definition: app_playback.c:166
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:1570
static snd_pcm_format_t format
Definition: chan_alsa.c:93
static char prefix[MAX_PREFIX]
Definition: http.c:107
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 333 of file app_playback.c.

References say_date_generic().

Referenced by say_init_mode().

335 {
336  return say_date_generic(chan, t, ints, lang, format, timezonename, "datetime");
337 }
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:308
static snd_pcm_format_t format
Definition: chan_alsa.c:93
static int say_datetime ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang 
)
static

Definition at line 349 of file app_playback.c.

References say_date_generic().

Referenced by say_init_mode().

350 {
351  return say_date_generic(chan, t, ints, lang, "", NULL, "datetime");
352 }
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:308
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 298 of file app_playback.c.

References do_say().

Referenced by say_init_mode().

301 {
302  char buf[64];
303  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
304  snprintf(buf, sizeof(buf), "enum:%d", num);
305  return do_say(&a, buf, options, 0);
306 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
Definition: app_playback.c:166
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 280 of file app_playback.c.

References do_say().

Referenced by playback_exec().

283 {
284  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
285  return do_say(&a, string, options, 0);
286 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
Definition: app_playback.c:166
static int say_init_mode ( const char *  mode)
static

Definition at line 357 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, restore_say_mode(), save_say_mode(), say_character_str_full(), say_date(), say_date_with_format(), say_datetime(), say_datetime_from_now(), say_digit_str_full(), say_enumeration_full(), say_number_full(), say_phonetic_str_full(), and say_time().

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

357  {
358  if (!strcmp(mode, say_new)) {
359  if (say_cfg == NULL) {
360  ast_log(LOG_ERROR, "There is no say.conf file to use new mode\n");
361  return -1;
362  }
365 
367 #if 0
368  ast_say_digits_full = say_digits_full;
373 #endif
378  } else if (!strcmp(mode, say_old) && say_api_buf[0] == say_new) {
379  restore_say_mode(NULL);
380  } else if (strcmp(mode, say_old)) {
381  ast_log(LOG_WARNING, "unrecognized mode %s\n", mode);
382  return -1;
383  }
384 
385  return 0;
386 }
static void save_say_mode(const void *arg)
Definition: app_playback.c:100
static int say_character_str_full(struct ast_channel *chan, const char *str, const char *ints, const char *lang, int audiofd, int ctrlfd)
Definition: say.c:63
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:333
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:288
#define LOG_WARNING
Definition: logger.h:144
int ast_say_digits_full(struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd)
Definition: channel.c:8433
static int say_datetime_from_now(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: say.c:7022
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:161
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:298
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:164
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)
Definition: say.h:105
static struct ast_config * say_cfg
Definition: app_playback.c:90
static int say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:349
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:159
#define LOG_ERROR
Definition: logger.h:155
SAY_EXTERN int(* ast_say_character_str_full)(struct ast_channel *chan, const char *num, const char *ints, const char *lang, int audiofd, int ctrlfd) SAY_INIT(ast_say_character_str_full)
Definition: say.h:154
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static const void * say_api_buf[40]
Definition: app_playback.c:96
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:166
static int say_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:344
static int say_date(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
Definition: app_playback.c:339
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)
Definition: say.h:140
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:225
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:168
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:145
static const char *const say_new
Definition: app_playback.c:98
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)
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:162
static const char *const say_old
Definition: app_playback.c:97
static void restore_say_mode(void *arg)
Definition: app_playback.c:117
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 288 of file app_playback.c.

References do_say().

Referenced by say_init_mode().

291 {
292  char buf[64];
293  say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
294  snprintf(buf, sizeof(buf), "num:%d", num);
295  return do_say(&a, buf, options, 0);
296 }
static int do_say(say_args_t *a, const char *s, const char *options, int depth)
Definition: app_playback.c:166
static int say_time ( struct ast_channel chan,
time_t  t,
const char *  ints,
const char *  lang 
)
static

Definition at line 344 of file app_playback.c.

References say_date_generic().

Referenced by say_init_mode().

345 {
346  return say_date_generic(chan, t, ints, lang, "", NULL, "time");
347 }
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:308
static int unload_module ( void  )
static

Definition at line 525 of file app_playback.c.

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

526 {
527  int res;
528 
530 
532 
533  if (say_cfg)
535 
536  return res;
537 }
#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: cli.c:2177
static struct ast_cli_entry cli_playback[]
Definition: app_playback.c:422
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
static struct ast_config * say_cfg
Definition: app_playback.c:90
static char * app
Definition: app_playback.c:88

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, }
static

Definition at line 562 of file app_playback.c.

char* app = "Playback"
static

Definition at line 88 of file app_playback.c.

Definition at line 562 of file app_playback.c.

struct ast_cli_entry cli_playback[]
static
Initial value:
= {
AST_CLI_DEFINE(__say_cli_init, "Set or show the say mode"),
}
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
static char * __say_cli_init(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: app_playback.c:388

Definition at line 422 of file app_playback.c.

const void* say_api_buf[40]
static

Definition at line 96 of file app_playback.c.

struct ast_config* say_cfg = NULL
static

Definition at line 90 of file app_playback.c.

const char* const say_new = "new"
static

Definition at line 98 of file app_playback.c.

const char* const say_old = "old"
static

Definition at line 97 of file app_playback.c.

Referenced by __say_cli_init().