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"
#include "asterisk/manager.h"
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"

Include dependency graph for app_controlplayback.c:

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 controlplayback_manager (struct mansession *s, const struct message *m)
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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
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 <markster@digium.com>

Definition in file app_controlplayback.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
OPT_OFFSET 

Definition at line 168 of file app_controlplayback.c.

00168      {
00169    OPT_OFFSET = (1 << 1),
00170 };

anonymous enum

Enumerator:
OPT_ARG_OFFSET 
OPT_ARG_ARRAY_LEN 

Definition at line 172 of file app_controlplayback.c.

00172      {
00173    OPT_ARG_OFFSET = 0,
00174    /* must stay as the last entry ... */
00175    OPT_ARG_ARRAY_LEN,
00176 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 351 of file app_controlplayback.c.

static void __unreg_module ( void   )  [static]

Definition at line 351 of file app_controlplayback.c.

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

Definition at line 199 of file app_controlplayback.c.

References args, AST_APP_ARG, ast_app_parse_options(), AST_CONTROL_STREAM_STOP, 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, digit, is_argument(), is_on_phonepad(), LOG_WARNING, NULL, OPT_ARG_ARRAY_LEN, OPT_ARG_OFFSET, OPT_OFFSET, pbx_builtin_setvar_helper(), skipms, stop, and tmp().

Referenced by load_module().

00200 {
00201    int res = 0;
00202    int skipms = 0;
00203    long offsetms = 0;
00204    char offsetbuf[20];
00205    char stopkeybuf[2];
00206    char *tmp;
00207    struct ast_flags opts = { 0, };
00208    char *opt_args[OPT_ARG_ARRAY_LEN];
00209    AST_DECLARE_APP_ARGS(args,
00210       AST_APP_ARG(filename);
00211       AST_APP_ARG(skip);
00212       AST_APP_ARG(fwd);
00213       AST_APP_ARG(rev);
00214       AST_APP_ARG(stop);
00215       AST_APP_ARG(pause);
00216       AST_APP_ARG(restart);
00217       AST_APP_ARG(options);
00218    );
00219 
00220    if (ast_strlen_zero(data)) {
00221       ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
00222       return -1;
00223    }
00224    
00225    tmp = ast_strdupa(data);
00226    AST_STANDARD_APP_ARGS(args, tmp);
00227 
00228    if (args.argc < 1) {
00229       ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
00230       return -1;
00231    }
00232 
00233    skipms = args.skip ? (atoi(args.skip) ? atoi(args.skip) : 3000) : 3000;
00234 
00235    if (!args.fwd || !is_on_phonepad(*args.fwd)) {
00236       char *digit = "#";
00237       if (!is_argument(args.rev, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
00238          args.fwd = digit;
00239       else
00240          args.fwd = NULL;
00241    }
00242    if (!args.rev || !is_on_phonepad(*args.rev)) {
00243       char *digit = "*";
00244       if (!is_argument(args.fwd, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
00245          args.rev = digit;
00246       else
00247          args.rev = NULL;
00248    }
00249    ast_debug(1, "Forward key = %s, Rewind key = %s\n", args.fwd, args.rev);
00250    if (args.stop && !is_on_phonepad(*args.stop))
00251       args.stop = NULL;
00252    if (args.pause && !is_on_phonepad(*args.pause))
00253       args.pause = NULL;
00254    if (args.restart && !is_on_phonepad(*args.restart))
00255       args.restart = NULL;
00256 
00257    if (args.options) {
00258       ast_app_parse_options(cpb_opts, &opts, opt_args, args.options);
00259       if (ast_test_flag(&opts, OPT_OFFSET))
00260          offsetms = atol(opt_args[OPT_ARG_OFFSET]);
00261    }
00262 
00263    res = ast_control_streamfile(chan, args.filename, args.fwd, args.rev, args.stop, args.pause, args.restart, skipms, &offsetms);
00264 
00265    /* If we stopped on one of our stop keys, return 0  */
00266    if (res > 0 && args.stop && strchr(args.stop, res)) {
00267       pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
00268       snprintf(stopkeybuf, sizeof(stopkeybuf), "%c", res);
00269       pbx_builtin_setvar_helper(chan, "CPLAYBACKSTOPKEY", stopkeybuf);
00270       res = 0;
00271    } else if (res > 0 && res == AST_CONTROL_STREAM_STOP) {
00272       pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "REMOTESTOPPED");
00273       res = 0;
00274    } else {
00275       if (res < 0) {
00276          res = 0;
00277          pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
00278       } else
00279          pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
00280    }
00281 
00282    snprintf(offsetbuf, sizeof(offsetbuf), "%ld", offsetms);
00283    pbx_builtin_setvar_helper(chan, "CPLAYBACKOFFSET", offsetbuf);
00284 
00285    return res;
00286 }

static int controlplayback_manager ( struct mansession s,
const struct message m 
) [static]

Definition at line 288 of file app_controlplayback.c.

References ast_channel_get_by_name(), ast_channel_unref, AST_CONTROL_STREAM_FORWARD, AST_CONTROL_STREAM_RESTART, AST_CONTROL_STREAM_REVERSE, AST_CONTROL_STREAM_STOP, AST_CONTROL_STREAM_SUSPEND, ast_queue_control(), ast_strlen_zero, astman_get_header(), astman_send_ack(), astman_send_error(), and NULL.

Referenced by load_module().

00289 {
00290    const char *channel_name = astman_get_header(m, "Channel");
00291    const char *control_type = astman_get_header(m, "Control");
00292    struct ast_channel *chan;
00293 
00294    if (ast_strlen_zero(channel_name)) {
00295       astman_send_error(s, m, "Channel not specified");
00296       return 0;
00297    }
00298 
00299    if (ast_strlen_zero(control_type)) {
00300       astman_send_error(s, m, "Control not specified");
00301       return 0;
00302    }
00303 
00304    chan = ast_channel_get_by_name(channel_name);
00305    if (!chan) {
00306       astman_send_error(s, m, "No such channel");
00307       return 0;
00308    }
00309 
00310    if (!strcasecmp(control_type, "stop")) {
00311       ast_queue_control(chan, AST_CONTROL_STREAM_STOP);
00312    } else if (!strcasecmp(control_type, "forward")) {
00313       ast_queue_control(chan, AST_CONTROL_STREAM_FORWARD);
00314    } else if (!strcasecmp(control_type, "reverse")) {
00315       ast_queue_control(chan, AST_CONTROL_STREAM_REVERSE);
00316    } else if (!strcasecmp(control_type, "pause")) {
00317       ast_queue_control(chan, AST_CONTROL_STREAM_SUSPEND);
00318    } else if (!strcasecmp(control_type, "restart")) {
00319       ast_queue_control(chan, AST_CONTROL_STREAM_RESTART);
00320    } else {
00321       astman_send_error(s, m, "Unknown control type");
00322       chan = ast_channel_unref(chan);
00323       return 0;
00324    }
00325 
00326    chan = ast_channel_unref(chan);
00327    astman_send_ack(s, m, NULL);
00328    return 0;
00329 }

static int is_argument ( const char *  haystack,
int  needle 
) [static]

Definition at line 188 of file app_controlplayback.c.

References ast_strlen_zero.

Referenced by controlplayback_exec().

00189 {
00190    if (ast_strlen_zero(haystack))
00191       return 0;
00192 
00193    if (strchr(haystack, needle))
00194       return -1;
00195 
00196    return 0;
00197 }

static int is_on_phonepad ( char  key  )  [static]

Definition at line 183 of file app_controlplayback.c.

Referenced by controlplayback_exec().

00184 {
00185    return key == 35 || key == 42 || (key >= 48 && key <= 57);
00186 }

static int load_module ( void   )  [static]

Definition at line 341 of file app_controlplayback.c.

References ast_manager_register_xml, ast_register_application_xml, controlplayback_exec(), controlplayback_manager(), and EVENT_FLAG_CALL.

00342 {
00343    int res = 0;
00344 
00345    res |= ast_register_application_xml(app, controlplayback_exec);
00346    res |= ast_manager_register_xml("ControlPlayback", EVENT_FLAG_CALL, controlplayback_manager);
00347 
00348    return res;
00349 }

static int unload_module ( void   )  [static]

Definition at line 331 of file app_controlplayback.c.

References ast_manager_unregister(), and ast_unregister_application().

00332 {
00333    int res = 0;
00334 
00335    res |= ast_unregister_application(app);
00336    res |= ast_manager_unregister("ControlPlayback");
00337 
00338    return res;
00339 }


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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 351 of file app_controlplayback.c.

const char app[] = "ControlPlayback" [static]

Definition at line 166 of file app_controlplayback.c.

Definition at line 351 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 181 of file app_controlplayback.c.

Referenced by controlplayback_exec().


Generated on Thu Apr 16 06:28:23 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6