static int controlplayback_exec(struct cw_channel *chan, int argc, char **argv) { int res = 0; int skipms = 0; struct localuser *u; int i; if (argc < 1 || argc > 7) { cw_log(LOG_ERROR, "Syntax: %s\n", controlplayback_syntax); pbx_builtin_setvar_helper(chan, controlplayback_chanvar, "ERROR"); return 0; } LOCAL_USER_ADD(u); skipms = (argc > 1 && argv[1] ? atoi(argv[1]) : 3000); if (!skipms) skipms = 3000; for (i = 2; i < 6; i++) { if (i >= argc || !argv[i] || !is_on_phonepad(argv[i][0])) argv[i] = NULL; } if (!argv[2]) argv[2] = "#"; if (!argv[3]) argv[2] = "*"; res = cw_control_streamfile(chan, argv[0], argv[2], argv[3], argv[4], argv[5], argv[6], skipms); /* If we stopped on one of our stop keys, return 0 */ if (argv[4] && strchr(argv[4], res)) res = 0; if (res < 0) { pbx_builtin_setvar_helper(chan, controlplayback_chanvar, "ERROR"); return 0; } pbx_builtin_setvar_helper(chan, controlplayback_chanvar, "OK"); LOCAL_USER_REMOVE(u); return 0; }
static int controlplayback_exec(struct ast_channel *chan, void *data) { int res = 0, priority_jump = 0; int skipms = 0; struct localuser *u; char *tmp; int argc; char *argv[8]; enum arg_ids { arg_file = 0, arg_skip = 1, arg_fwd = 2, arg_rev = 3, arg_stop = 4, arg_pause = 5, arg_restart = 6, options = 7, }; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n"); return -1; } LOCAL_USER_ADD(u); tmp = ast_strdupa(data); memset(argv, 0, sizeof(argv)); argc = ast_app_separate_args(tmp, '|', argv, sizeof(argv) / sizeof(argv[0])); if (argc < 1) { ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n"); LOCAL_USER_REMOVE(u); return -1; } skipms = argv[arg_skip] ? atoi(argv[arg_skip]) : 3000; if (!skipms) skipms = 3000; if (!argv[arg_fwd] || !is_on_phonepad(*argv[arg_fwd])) argv[arg_fwd] = "#"; if (!argv[arg_rev] || !is_on_phonepad(*argv[arg_rev])) argv[arg_rev] = "*"; if (argv[arg_stop] && !is_on_phonepad(*argv[arg_stop])) argv[arg_stop] = NULL; if (argv[arg_pause] && !is_on_phonepad(*argv[arg_pause])) argv[arg_pause] = NULL; if (argv[arg_restart] && !is_on_phonepad(*argv[arg_restart])) argv[arg_restart] = NULL; if (argv[options]) { if (strchr(argv[options], 'j')) priority_jump = 1; } res = ast_control_streamfile(chan, argv[arg_file], argv[arg_fwd], argv[arg_rev], argv[arg_stop], argv[arg_pause], argv[arg_restart], skipms); /* If we stopped on one of our stop keys, return 0 */ if (argv[arg_stop] && strchr(argv[arg_stop], res)) { res = 0; pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED"); } else { if (res < 0) { if (priority_jump || ast_opt_priority_jumping) { if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { ast_log(LOG_WARNING, "ControlPlayback tried to jump to priority n+101 as requested, but priority didn't exist\n"); } } res = 0; pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR"); } else pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS"); } LOCAL_USER_REMOVE(u); return res; }