Wed Jan 8 2020 09:49:53

Asterisk developer's documentation


app_controlplayback.c File Reference

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

#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/module.h"

Go to the source code of this file.

Enumerations

enum  { OPT_OFFSET = (1 << 1) }
 
enum  { OPT_ARG_OFFSET = 0, OPT_ARG_ARRAY_LEN }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int controlplayback_exec (struct ast_channel *chan, const char *data)
 
static int is_argument (const char *haystack, int needle)
 
static int is_on_phonepad (char key)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Control 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, .load_pri = AST_MODPRI_DEFAULT, }
 
static const char app [] = "ControlPlayback"
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_app_option cpb_opts [128] = { [ 'o' ] = { .flag = OPT_OFFSET , .arg_index = OPT_ARG_OFFSET + 1 }, }
 

Detailed Description

Trivial application to control playback of a sound file.

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

Definition in file app_controlplayback.c.

Enumeration Type Documentation

anonymous enum
Enumerator
OPT_OFFSET 

Definition at line 101 of file app_controlplayback.c.

101  {
102  OPT_OFFSET = (1 << 1),
103 };
anonymous enum
Enumerator
OPT_ARG_OFFSET 
OPT_ARG_ARRAY_LEN 

Definition at line 105 of file app_controlplayback.c.

105  {
106  OPT_ARG_OFFSET = 0,
107  /* must stay as the last entry ... */
109 };

Function Documentation

static void __reg_module ( void  )
static

Definition at line 230 of file app_controlplayback.c.

static void __unreg_module ( void  )
static

Definition at line 230 of file app_controlplayback.c.

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

Definition at line 132 of file app_controlplayback.c.

References args, AST_APP_ARG, ast_app_parse_options(), ast_control_streamfile(), ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, cpb_opts, is_argument(), is_on_phonepad(), LOG_WARNING, OPT_ARG_ARRAY_LEN, OPT_ARG_OFFSET, OPT_OFFSET, pbx_builtin_setvar_helper(), skipms, and stop.

Referenced by load_module().

133 {
134  int res = 0;
135  int skipms = 0;
136  long offsetms = 0;
137  char offsetbuf[20];
138  char stopkeybuf[2];
139  char *tmp;
140  struct ast_flags opts = { 0, };
141  char *opt_args[OPT_ARG_ARRAY_LEN];
143  AST_APP_ARG(filename);
144  AST_APP_ARG(skip);
145  AST_APP_ARG(fwd);
146  AST_APP_ARG(rev);
147  AST_APP_ARG(stop);
148  AST_APP_ARG(pause);
149  AST_APP_ARG(restart);
150  AST_APP_ARG(options);
151  );
152 
153  if (ast_strlen_zero(data)) {
154  ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
155  return -1;
156  }
157 
158  tmp = ast_strdupa(data);
160 
161  if (args.argc < 1) {
162  ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
163  return -1;
164  }
165 
166  skipms = args.skip ? (atoi(args.skip) ? atoi(args.skip) : 3000) : 3000;
167 
168  if (!args.fwd || !is_on_phonepad(*args.fwd)) {
169  char *digit = "#";
170  if (!is_argument(args.rev, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
171  args.fwd = digit;
172  else
173  args.fwd = NULL;
174  }
175  if (!args.rev || !is_on_phonepad(*args.rev)) {
176  char *digit = "*";
177  if (!is_argument(args.fwd, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
178  args.rev = digit;
179  else
180  args.rev = NULL;
181  }
182  ast_debug(1, "Forward key = %s, Rewind key = %s\n", args.fwd, args.rev);
183  if (args.stop && !is_on_phonepad(*args.stop))
184  args.stop = NULL;
185  if (args.pause && !is_on_phonepad(*args.pause))
186  args.pause = NULL;
187  if (args.restart && !is_on_phonepad(*args.restart))
188  args.restart = NULL;
189 
190  if (args.options) {
191  ast_app_parse_options(cpb_opts, &opts, opt_args, args.options);
192  if (ast_test_flag(&opts, OPT_OFFSET))
193  offsetms = atol(opt_args[OPT_ARG_OFFSET]);
194  }
195 
196  res = ast_control_streamfile(chan, args.filename, args.fwd, args.rev, args.stop, args.pause, args.restart, skipms, &offsetms);
197 
198  /* If we stopped on one of our stop keys, return 0 */
199  if (res > 0 && args.stop && strchr(args.stop, res)) {
200  pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
201  snprintf(stopkeybuf, sizeof(stopkeybuf), "%c", res);
202  pbx_builtin_setvar_helper(chan, "CPLAYBACKSTOPKEY", stopkeybuf);
203  res = 0;
204  } else {
205  if (res < 0) {
206  res = 0;
207  pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
208  } else
209  pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
210  }
211 
212  snprintf(offsetbuf, sizeof(offsetbuf), "%ld", offsetms);
213  pbx_builtin_setvar_helper(chan, "CPLAYBACKOFFSET", offsetbuf);
214 
215  return res;
216 }
int ast_control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, const char *restart, int skipms, long *offsetms)
Stream a file with fast forward, pause, reverse, restart.
Definition: app.c:683
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define LOG_WARNING
Definition: logger.h:144
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
unsigned int stop
Definition: app_meetme.c:969
static int is_argument(const char *haystack, int needle)
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int is_on_phonepad(char key)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static int skipms
static struct @350 args
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
Structure used to handle boolean flags.
Definition: utils.h:200
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
static struct ast_app_option cpb_opts[128]
#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
static int is_argument ( const char *  haystack,
int  needle 
)
static

Definition at line 121 of file app_controlplayback.c.

References ast_strlen_zero().

Referenced by controlplayback_exec().

122 {
123  if (ast_strlen_zero(haystack))
124  return 0;
125 
126  if (strchr(haystack, needle))
127  return -1;
128 
129  return 0;
130 }
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int is_on_phonepad ( char  key)
static

Definition at line 116 of file app_controlplayback.c.

Referenced by controlplayback_exec().

117 {
118  return key == 35 || key == 42 || (key >= 48 && key <= 57);
119 }
static int load_module ( void  )
static

Definition at line 225 of file app_controlplayback.c.

References ast_register_application_xml, and controlplayback_exec().

226 {
228 }
static const char app[]
static int controlplayback_exec(struct ast_channel *chan, const char *data)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int unload_module ( void  )
static

Definition at line 218 of file app_controlplayback.c.

References ast_unregister_application().

219 {
220  int res;
222  return res;
223 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static const char app[]

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Control 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, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 230 of file app_controlplayback.c.

const char app[] = "ControlPlayback"
static

Definition at line 99 of file app_controlplayback.c.

Definition at line 230 of file app_controlplayback.c.

struct ast_app_option cpb_opts[128] = { [ 'o' ] = { .flag = OPT_OFFSET , .arg_index = OPT_ARG_OFFSET + 1 }, }
static

Definition at line 114 of file app_controlplayback.c.

Referenced by controlplayback_exec().