Fri Jun 19 12:09:59 2009

Asterisk developer's documentation


app_parkandannounce.c File Reference

ParkAndAnnounce application for Asterisk. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/features.h"
#include "asterisk/say.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static int parkandannounce_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Call Parking and Announce 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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static char * app = "ParkAndAnnounce"
static struct ast_module_infoast_module_info = &__mod_info
static char * descrip
static char * synopsis = "Park and Announce"


Detailed Description

ParkAndAnnounce application for Asterisk.

Author:
Ben Miller <bgmiller@dccinc.com>

Definition in file app_parkandannounce.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 190 of file app_parkandannounce.c.

static void __unreg_module ( void   )  [static]

Definition at line 190 of file app_parkandannounce.c.

static int load_module ( void   )  [static]

Definition at line 184 of file app_parkandannounce.c.

References ast_register_application, and parkandannounce_exec().

00185 {
00186    /* return ast_register_application(app, park_exec); */
00187    return ast_register_application(app, parkandannounce_exec, synopsis, descrip);
00188 }

static int parkandannounce_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 69 of file app_parkandannounce.c.

References __ast_request_and_dial(), ast_channel::_state, ARRAY_LEN, AST_APP_ARG, ast_clear_flag, AST_DECLARE_APP_ARGS, ast_exists_extension(), AST_FLAG_IN_AUTOLOOP, AST_FORMAT_SLINEAR, ast_hangup(), ast_log(), ast_masq_park_call(), ast_parseable_goto(), ast_say_digits(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_variable_new(), ast_verb, ast_waitstream(), buf, chan, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::exten, ast_channel::language, LOG_WARNING, ast_channel::name, outgoing_helper::parent_channel, ast_channel::priority, s, strsep(), ast_dial::timeout, and outgoing_helper::vars.

Referenced by load_module().

00070 {
00071    int res = -1;
00072    int lot, timeout = 0, dres;
00073    char *dialtech, *tmp[100], buf[13];
00074    int looptemp, i;
00075    char *s;
00076 
00077    struct ast_channel *dchan;
00078    struct outgoing_helper oh = { 0, };
00079    int outstate;
00080    AST_DECLARE_APP_ARGS(args,
00081       AST_APP_ARG(template);
00082       AST_APP_ARG(timeout);
00083       AST_APP_ARG(dial);
00084       AST_APP_ARG(return_context);
00085    );
00086    if (ast_strlen_zero(data)) {
00087       ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce:template|timeout|dial|[return_context])\n");
00088       return -1;
00089    }
00090   
00091    s = ast_strdupa(data);
00092    AST_STANDARD_APP_ARGS(args, s);
00093 
00094    if (args.timeout)
00095       timeout = atoi(args.timeout) * 1000;
00096 
00097    if (ast_strlen_zero(args.dial)) {
00098       ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
00099       return -1;
00100    }
00101 
00102    dialtech = strsep(&args.dial, "/");
00103    ast_verb(3, "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);
00104 
00105    if (!ast_strlen_zero(args.return_context)) {
00106       ast_clear_flag(chan, AST_FLAG_IN_AUTOLOOP);
00107       ast_parseable_goto(chan, args.return_context);
00108    }
00109 
00110    ast_verb(3, "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten, chan->priority, chan->cid.cid_num);
00111       if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
00112       ast_verb(3, "Warning: Return Context Invalid, call will return to default|s\n");
00113       }
00114 
00115    /* we are using masq_park here to protect * from touching the channel once we park it.  If the channel comes out of timeout
00116    before we are done announcing and the channel is messed with, Kablooeee.  So we use Masq to prevent this.  */
00117 
00118    res = ast_masq_park_call(chan, NULL, timeout, &lot);
00119    if (res == -1)
00120       return res;
00121 
00122    ast_verb(3, "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, args.return_context);
00123 
00124    /* Now place the call to the extension */
00125 
00126    snprintf(buf, sizeof(buf), "%d", lot);
00127    oh.parent_channel = chan;
00128    oh.vars = ast_variable_new("_PARKEDAT", buf, "");
00129    dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, args.dial, 30000, &outstate, chan->cid.cid_num, chan->cid.cid_name, &oh);
00130 
00131    if (dchan) {
00132       if (dchan->_state == AST_STATE_UP) {
00133          ast_verb(4, "Channel %s was answered.\n", dchan->name);
00134       } else {
00135          ast_verb(4, "Channel %s was never answered.\n", dchan->name);
00136          ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
00137          ast_hangup(dchan);
00138          return -1;
00139       }
00140    } else {
00141       ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
00142       return -1; 
00143    }
00144 
00145    ast_stopstream(dchan);
00146 
00147    /* now we have the call placed and are ready to play stuff to it */
00148 
00149    ast_verb(4, "Announce Template:%s\n", args.template);
00150 
00151    for (looptemp = 0; looptemp < ARRAY_LEN(tmp); looptemp++) {
00152       if ((tmp[looptemp] = strsep(&args.template, ":")) != NULL)
00153          continue;
00154       else
00155          break;
00156    }
00157 
00158    for (i = 0; i < looptemp; i++) {
00159       ast_verb(4, "Announce:%s\n", tmp[i]);
00160       if (!strcmp(tmp[i], "PARKED")) {
00161          ast_say_digits(dchan, lot, "", dchan->language);
00162       } else {
00163          dres = ast_streamfile(dchan, tmp[i], dchan->language);
00164          if (!dres) {
00165             dres = ast_waitstream(dchan, "");
00166          } else {
00167             ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);
00168             dres = 0;
00169          }
00170       }
00171    }
00172 
00173    ast_stopstream(dchan);  
00174    ast_hangup(dchan);
00175    
00176    return res;
00177 }

static int unload_module ( void   )  [static]

Definition at line 179 of file app_parkandannounce.c.

References ast_unregister_application().

00180 {
00181    return ast_unregister_application(app);
00182 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Call Parking and Announce 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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 190 of file app_parkandannounce.c.

char* app = "ParkAndAnnounce" [static]

Definition at line 46 of file app_parkandannounce.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 190 of file app_parkandannounce.c.

char* descrip [static]

Definition at line 50 of file app_parkandannounce.c.

char* synopsis = "Park and Announce" [static]

Definition at line 48 of file app_parkandannounce.c.


Generated on Fri Jun 19 12:09:59 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7