aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_parkandannounce.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-23 19:51:41 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-23 19:51:41 +0000
commitfd0b69a4e7f57297f9c011c75820432d693e21a5 (patch)
treec9c73917bfd120da30c16650000c7296781fae50 /apps/app_parkandannounce.c
parentb5741f9dd4e38302ab7d62f3999c59f5b9011ac5 (diff)
Merge the dialplan_aesthetics branch. Most of this patch simply converts applications
using old methods of parsing arguments to using the standard macros. However, the big change is that the really old way of specifying application and arguments separated by a comma will no longer work (e.g. NoOp,foo|bar). Instead, the way that has been recommended since long before 1.0 will become the only method available (e.g. NoOp(foo,bar). git-svn-id: http://svn.digium.com/svn/asterisk/trunk@76703 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_parkandannounce.c')
-rw-r--r--apps/app_parkandannounce.c133
1 files changed, 45 insertions, 88 deletions
diff --git a/apps/app_parkandannounce.c b/apps/app_parkandannounce.c
index 138694c5a..d7d5fc787 100644
--- a/apps/app_parkandannounce.c
+++ b/apps/app_parkandannounce.c
@@ -50,6 +50,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/say.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
+#include "asterisk/app.h"
static char *app = "ParkAndAnnounce";
@@ -76,113 +77,72 @@ static char *descrip =
static int parkandannounce_exec(struct ast_channel *chan, void *data)
{
- int res=0;
- char *return_context;
+ int res = -1;
int lot, timeout = 0, dres;
- char *working, *context, *exten, *priority, *dial, *dialtech, *dialstr;
- char *template, *tpl_working, *tpl_current;
- char *tmp[100];
- char buf[13];
- int looptemp=0,i=0;
+ char *dialtech, *tmp[100], buf[13];
+ int looptemp, i;
char *s;
struct ast_channel *dchan;
- struct outgoing_helper oh;
+ 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);
- template=strsep(&s,"|");
- if(! template) {
- ast_log(LOG_WARNING, "PARK: An announce template must be defined\n");
- return -1;
- }
-
- if(s) {
- timeout = atoi(strsep(&s, "|"));
- timeout *= 1000;
- }
- dial=strsep(&s, "|");
- if(!dial) {
+ 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 Zap/g1/5551212\n");
return -1;
- } else {
- dialtech=strsep(&dial, "/");
- dialstr=dial;
- ast_verbose( VERBOSE_PREFIX_3 "Dial Tech,String: (%s,%s)\n", dialtech,dialstr);
}
- return_context = s;
-
- if(return_context != NULL) {
- /* set the return context. Code borrowed from the Goto builtin */
-
- working = return_context;
- context = strsep(&working, "|");
- exten = strsep(&working, "|");
- if(!exten) {
- /* Only a priority in this one */
- priority = context;
- exten = NULL;
- context = NULL;
- } else {
- priority = strsep(&working, "|");
- if(!priority) {
- /* Only an extension and priority in this one */
- priority = exten;
- exten = context;
- context = NULL;
- }
- }
- if(atoi(priority) < 0) {
- ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority);
- return -1;
- }
- /* At this point we have a priority and maybe an extension and a context */
- chan->priority = atoi(priority);
- if (exten)
- ast_copy_string(chan->exten, exten, sizeof(chan->exten));
- if (context)
- ast_copy_string(chan->context, context, sizeof(chan->context));
- } else { /* increment the priority by default*/
- chan->priority++;
- }
+ dialtech = strsep(&args.dial, "/");
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);
+
+ if (!ast_strlen_zero(args.return_context))
+ ast_parseable_goto(chan, args.return_context);
- if(option_verbose > 2) {
- ast_verbose( VERBOSE_PREFIX_3 "Return Context: (%s,%s,%d) ID: %s\n", chan->context,chan->exten, chan->priority, chan->cid.cid_num);
- if(!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
- ast_verbose( VERBOSE_PREFIX_3 "Warning: Return Context Invalid, call will return to default|s\n");
+ if (option_verbose > 2) {
+ ast_verbose(VERBOSE_PREFIX_3 "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten, chan->priority, chan->cid.cid_num);
+ if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
+ ast_verbose(VERBOSE_PREFIX_3 "Warning: Return Context Invalid, call will return to default|s\n");
}
}
-
+
/* 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. */
ast_masq_park_call(chan, NULL, timeout, &lot);
- res=-1;
-
- ast_verbose( VERBOSE_PREFIX_3 "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, return_context);
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, args.return_context);
- /* Now place the call to the extention */
+ /* Now place the call to the extension */
snprintf(buf, sizeof(buf), "%d", lot);
- memset(&oh, 0, sizeof(oh));
oh.parent_channel = chan;
oh.vars = ast_variable_new("_PARKEDAT", buf);
- dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, dialstr,30000, &outstate, chan->cid.cid_num, chan->cid.cid_name, &oh);
+ dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, args.dial, 30000, &outstate, chan->cid.cid_num, chan->cid.cid_name, &oh);
- if(dchan) {
- if(dchan->_state == AST_STATE_UP) {
- if(option_verbose > 3)
+ if (dchan) {
+ if (dchan->_state == AST_STATE_UP) {
+ if (option_verbose > 3)
ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", dchan->name);
} else {
- if(option_verbose > 3)
+ if (option_verbose > 3)
ast_verbose(VERBOSE_PREFIX_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);
@@ -197,24 +157,21 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
/* now we have the call placed and are ready to play stuff to it */
- ast_verbose(VERBOSE_PREFIX_4 "Announce Template:%s\n", template);
+ if (option_verbose > 3)
+ ast_verbose(VERBOSE_PREFIX_4 "Announce Template:%s\n", args.template);
- tpl_working = template;
- tpl_current=strsep(&tpl_working, ":");
-
- while(tpl_current && looptemp < sizeof(tmp)) {
- tmp[looptemp]=tpl_current;
- looptemp++;
- tpl_current=strsep(&tpl_working,":");
- }
+ for (looptemp = 0, tmp[looptemp++] = strsep(&args.template, ":");
+ looptemp < sizeof(tmp) / sizeof(tmp[0]);
+ tmp[looptemp++] = strsep(&args.template, ":"));
- for(i=0; i<looptemp; i++) {
- ast_verbose(VERBOSE_PREFIX_4 "Announce:%s\n", tmp[i]);
- if(!strcmp(tmp[i], "PARKED")) {
+ for (i = 0; i < looptemp; i++) {
+ if (option_verbose > 3)
+ ast_verbose(VERBOSE_PREFIX_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) {
+ if (!dres) {
dres = ast_waitstream(dchan, "");
} else {
ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);