Sat Feb 11 06:33:52 2012

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"

Include dependency graph for app_parkandannounce.c:

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, const char *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static char * app = "ParkAndAnnounce"
static struct ast_module_infoast_module_info = &__mod_info


Detailed Description

ParkAndAnnounce application for Asterisk.

Author:
Ben Miller <bgmiller@dccinc.com>
  • With TONS of help from Mark!

Definition in file app_parkandannounce.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 247 of file app_parkandannounce.c.

static void __unreg_module ( void   )  [static]

Definition at line 247 of file app_parkandannounce.c.

static int load_module ( void   )  [static]

Definition at line 241 of file app_parkandannounce.c.

References ast_register_application_xml, and parkandannounce_exec().

00242 {
00243    /* return ast_register_application(app, park_exec); */
00244    return ast_register_application_xml(app, parkandannounce_exec);
00245 }

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

Definition at line 92 of file app_parkandannounce.c.

References __ast_request_and_dial(), ast_channel::_state, args, ARRAY_LEN, AST_APP_ARG, ast_channel_language(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_clear_flag, AST_DECLARE_APP_ARGS, ast_exists_extension(), AST_FLAG_IN_AUTOLOOP, ast_format_cap_add(), ast_format_cap_alloc_nolock(), ast_format_cap_destroy(), ast_format_set(), AST_FORMAT_SLINEAR, ast_hangup(), ast_log(), ast_masq_park_call(), ast_parseable_goto(), ast_party_id_copy(), ast_party_id_free(), ast_party_id_init(), ast_say_digits(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_variable_new(), ast_variables_destroy(), ast_verb, ast_waitstream(), ast_channel::caller, ast_channel::context, ast_channel::exten, ast_party_caller::id, LOG_WARNING, ast_party_id::name, ast_party_id::number, outgoing_helper::parent_channel, ast_channel::priority, S_COR, ast_party_name::str, ast_party_number::str, strsep(), ast_dial::timeout, ast_party_name::valid, ast_party_number::valid, and outgoing_helper::vars.

Referenced by load_module().

00093 {
00094    int res = -1;
00095    int lot, timeout = 0, dres;
00096    char *dialtech, *tmp[100], buf[13];
00097    int looptemp, i;
00098    char *s;
00099    struct ast_party_id caller_id;
00100 
00101    struct ast_channel *dchan;
00102    struct outgoing_helper oh = { 0, };
00103    int outstate;
00104    struct ast_format tmpfmt;
00105    struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
00106 
00107    AST_DECLARE_APP_ARGS(args,
00108       AST_APP_ARG(template);
00109       AST_APP_ARG(timeout);
00110       AST_APP_ARG(dial);
00111       AST_APP_ARG(return_context);
00112    );
00113    if (ast_strlen_zero(data)) {
00114       ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce_template,timeout,dial,[return_context])\n");
00115       res = -1;
00116       goto parkcleanup;
00117    }
00118    if (!cap_slin) {
00119       res = -1;
00120       goto parkcleanup;
00121    }
00122    ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
00123 
00124    s = ast_strdupa(data);
00125    AST_STANDARD_APP_ARGS(args, s);
00126 
00127    if (args.timeout)
00128       timeout = atoi(args.timeout) * 1000;
00129 
00130    if (ast_strlen_zero(args.dial)) {
00131       ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
00132       res = -1;
00133       goto parkcleanup;
00134    }
00135 
00136    dialtech = strsep(&args.dial, "/");
00137    ast_verb(3, "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);
00138 
00139    if (!ast_strlen_zero(args.return_context)) {
00140       ast_clear_flag(chan, AST_FLAG_IN_AUTOLOOP);
00141       ast_parseable_goto(chan, args.return_context);
00142    }
00143 
00144    ast_verb(3, "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten,
00145       chan->priority,
00146       S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, ""));
00147    if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority,
00148       S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
00149       ast_verb(3, "Warning: Return Context Invalid, call will return to default|s\n");
00150    }
00151 
00152    /* Save the CallerID because the masquerade turns chan into a ZOMBIE. */
00153    ast_party_id_init(&caller_id);
00154    ast_channel_lock(chan);
00155    ast_party_id_copy(&caller_id, &chan->caller.id);
00156    ast_channel_unlock(chan);
00157 
00158    /* we are using masq_park here to protect * from touching the channel once we park it.  If the channel comes out of timeout
00159    before we are done announcing and the channel is messed with, Kablooeee.  So we use Masq to prevent this.  */
00160 
00161    res = ast_masq_park_call(chan, NULL, timeout, &lot);
00162    if (res) {
00163       /* Parking failed. */
00164       ast_party_id_free(&caller_id);
00165       res = -1;
00166       goto parkcleanup;
00167    }
00168 
00169    ast_verb(3, "Call parked in space: %d, timeout: %d, return-context: %s\n",
00170       lot, timeout, args.return_context ? args.return_context : "");
00171 
00172    /* Now place the call to the extension */
00173 
00174    snprintf(buf, sizeof(buf), "%d", lot);
00175    oh.parent_channel = chan;
00176    oh.vars = ast_variable_new("_PARKEDAT", buf, "");
00177    dchan = __ast_request_and_dial(dialtech, cap_slin, chan, args.dial, 30000,
00178       &outstate,
00179       S_COR(caller_id.number.valid, caller_id.number.str, NULL),
00180       S_COR(caller_id.name.valid, caller_id.name.str, NULL),
00181       &oh);
00182    ast_variables_destroy(oh.vars);
00183    ast_party_id_free(&caller_id);
00184    if (dchan) {
00185       if (dchan->_state == AST_STATE_UP) {
00186          ast_verb(4, "Channel %s was answered.\n", ast_channel_name(dchan));
00187       } else {
00188          ast_verb(4, "Channel %s was never answered.\n", ast_channel_name(dchan));
00189          ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", ast_channel_name(dchan));
00190          ast_hangup(dchan);
00191          res = -1;
00192          goto parkcleanup;
00193       }
00194    } else {
00195       ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
00196       res = -1;
00197       goto parkcleanup;
00198    }
00199 
00200    ast_stopstream(dchan);
00201 
00202    /* now we have the call placed and are ready to play stuff to it */
00203 
00204    ast_verb(4, "Announce Template:%s\n", args.template);
00205 
00206    for (looptemp = 0; looptemp < ARRAY_LEN(tmp); looptemp++) {
00207       if ((tmp[looptemp] = strsep(&args.template, ":")) != NULL)
00208          continue;
00209       else
00210          break;
00211    }
00212 
00213    for (i = 0; i < looptemp; i++) {
00214       ast_verb(4, "Announce:%s\n", tmp[i]);
00215       if (!strcmp(tmp[i], "PARKED")) {
00216          ast_say_digits(dchan, lot, "", ast_channel_language(dchan));
00217       } else {
00218          dres = ast_streamfile(dchan, tmp[i], ast_channel_language(dchan));
00219          if (!dres) {
00220             dres = ast_waitstream(dchan, "");
00221          } else {
00222             ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], ast_channel_name(dchan));
00223          }
00224       }
00225    }
00226 
00227    ast_stopstream(dchan);  
00228    ast_hangup(dchan);
00229 
00230 parkcleanup:
00231    cap_slin = ast_format_cap_destroy(cap_slin);
00232 
00233    return res;
00234 }

static int unload_module ( void   )  [static]

Definition at line 236 of file app_parkandannounce.c.

References ast_unregister_application().

00237 {
00238    return ast_unregister_application(app);
00239 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 247 of file app_parkandannounce.c.

char* app = "ParkAndAnnounce" [static]

Definition at line 90 of file app_parkandannounce.c.

Definition at line 247 of file app_parkandannounce.c.


Generated on Sat Feb 11 06:33:52 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6