Mon Mar 12 2012 21:24:07

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 230 of file app_parkandannounce.c.

static void __unreg_module ( void  ) [static]

Definition at line 230 of file app_parkandannounce.c.

static int load_module ( void  ) [static]

Definition at line 224 of file app_parkandannounce.c.

References ast_register_application_xml, and parkandannounce_exec().

{
   /* return ast_register_application(app, park_exec); */
   return ast_register_application_xml(app, parkandannounce_exec);
}
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_lock, ast_channel_unlock, 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_party_id_copy(), ast_party_id_free(), 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, ast_channel::language, LOG_WARNING, ast_party_id::name, ast_channel::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().

{
   int res = -1;
   int lot, timeout = 0, dres;
   char *dialtech, *tmp[100], buf[13];
   int looptemp, i;
   char *s;
   struct ast_party_id caller_id;

   struct ast_channel *dchan;
   struct outgoing_helper oh = { 0, };
   int outstate;
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(template);
      AST_APP_ARG(timeout);
      AST_APP_ARG(dial);
      AST_APP_ARG(return_context);
   );
   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce_template,timeout,dial,[return_context])\n");
      return -1;
   }
  
   s = ast_strdupa(data);
   AST_STANDARD_APP_ARGS(args, s);

   if (args.timeout)
      timeout = atoi(args.timeout) * 1000;

   if (ast_strlen_zero(args.dial)) {
      ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
      return -1;
   }

   dialtech = strsep(&args.dial, "/");
   ast_verb(3, "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);

   if (!ast_strlen_zero(args.return_context)) {
      ast_clear_flag(chan, AST_FLAG_IN_AUTOLOOP);
      ast_parseable_goto(chan, args.return_context);
   }

   ast_verb(3, "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten,
      chan->priority,
      S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, ""));
   if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority,
      S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
      ast_verb(3, "Warning: Return Context Invalid, call will return to default|s\n");
   }

   /* Save the CallerID because the masquerade turns chan into a ZOMBIE. */
   ast_channel_lock(chan);
   ast_party_id_copy(&caller_id, &chan->caller.id);
   ast_channel_unlock(chan);

   /* we are using masq_park here to protect * from touching the channel once we park it.  If the channel comes out of timeout
   before we are done announcing and the channel is messed with, Kablooeee.  So we use Masq to prevent this.  */

   res = ast_masq_park_call(chan, NULL, timeout, &lot);
   if (res) {
      /* Parking failed. */
      ast_party_id_free(&caller_id);
      return -1;
   }

   ast_verb(3, "Call parked in space: %d, timeout: %d, return-context: %s\n",
      lot, timeout, args.return_context ? args.return_context : "");

   /* Now place the call to the extension */

   snprintf(buf, sizeof(buf), "%d", lot);
   oh.parent_channel = chan;
   oh.vars = ast_variable_new("_PARKEDAT", buf, "");
   dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, chan, args.dial, 30000,
      &outstate,
      S_COR(caller_id.number.valid, caller_id.number.str, NULL),
      S_COR(caller_id.name.valid, caller_id.name.str, NULL),
      &oh);
   ast_variables_destroy(oh.vars);
   ast_party_id_free(&caller_id);
   if (dchan) {
      if (dchan->_state == AST_STATE_UP) {
         ast_verb(4, "Channel %s was answered.\n", dchan->name);
      } else {
         ast_verb(4, "Channel %s was never answered.\n", dchan->name);
         ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
         ast_hangup(dchan);
         return -1;
      }
   } else {
      ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
      return -1; 
   }

   ast_stopstream(dchan);

   /* now we have the call placed and are ready to play stuff to it */

   ast_verb(4, "Announce Template:%s\n", args.template);

   for (looptemp = 0; looptemp < ARRAY_LEN(tmp); looptemp++) {
      if ((tmp[looptemp] = strsep(&args.template, ":")) != NULL)
         continue;
      else
         break;
   }

   for (i = 0; i < looptemp; i++) {
      ast_verb(4, "Announce:%s\n", tmp[i]);
      if (!strcmp(tmp[i], "PARKED")) {
         ast_say_digits(dchan, lot, "", dchan->language);
      } else {
         dres = ast_streamfile(dchan, tmp[i], dchan->language);
         if (!dres) {
            dres = ast_waitstream(dchan, "");
         } else {
            ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);
         }
      }
   }

   ast_stopstream(dchan);  
   ast_hangup(dchan);
   
   return res;
}
static int unload_module ( void  ) [static]

Definition at line 219 of file app_parkandannounce.c.

References ast_unregister_application().


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 230 of file app_parkandannounce.c.

char* app = "ParkAndAnnounce" [static]

Definition at line 90 of file app_parkandannounce.c.

Definition at line 230 of file app_parkandannounce.c.