summaryrefslogtreecommitdiff
path: root/apps/app_parkandannounce.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2005-10-19 18:19:02 +0000
committerRussell Bryant <russell@russellbryant.com>2005-10-19 18:19:02 +0000
commit4aa7912057e83f052e94637f0b1a10026fe14558 (patch)
tree5fee3540f8d72d45cd1b2e5bf15e5860581dd4f8 /apps/app_parkandannounce.c
parente5afdbbe160b3267df769c9f04c04c6f152b1c94 (diff)
Massive cleanups to applications for LOCAL_USER handling and some other things.
In general, LOCAL_USER_ADD/REMOVE should be the first/last thing called in an application. An exception is if there is some *fast* setup code that might halt the execution of the application, such as checking to see if an argument exists. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6832 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/app_parkandannounce.c')
-rwxr-xr-xapps/app_parkandannounce.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/apps/app_parkandannounce.c b/apps/app_parkandannounce.c
index ff49e80c6..3524b5cac 100755
--- a/apps/app_parkandannounce.c
+++ b/apps/app_parkandannounce.c
@@ -80,15 +80,19 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
int outstate;
struct localuser *u;
- if(!data || (data && !strlen(data))) {
+
+ if (!data || ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce:template|timeout|dial|[return_context])\n");
return -1;
}
+ LOCAL_USER_ADD(u);
+
l=strlen(data)+2;
orig_s=malloc(l);
if(!orig_s) {
ast_log(LOG_WARNING, "Out of memory\n");
+ LOCAL_USER_REMOVE(u);
return -1;
}
s=orig_s;
@@ -98,6 +102,7 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
if(! template) {
ast_log(LOG_WARNING, "PARK: An announce template must be defined\n");
free(orig_s);
+ LOCAL_USER_REMOVE(u);
return -1;
}
@@ -109,6 +114,7 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
if(!dial) {
ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or Zap/g1/5551212\n");
free(orig_s);
+ LOCAL_USER_REMOVE(u);
return -1;
} else {
dialtech=strsep(&dial, "/");
@@ -141,6 +147,7 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
if(atoi(priority) < 0) {
ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority);
free(orig_s);
+ LOCAL_USER_REMOVE(u);
return -1;
}
/* At this point we have a priority and maybe an extension and a context */
@@ -153,7 +160,6 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
chan->priority++;
}
-
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)) {
@@ -161,8 +167,6 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
}
}
- LOCAL_USER_ADD(u);
-
/* 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. */
@@ -228,9 +232,10 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
ast_stopstream(dchan);
ast_hangup(dchan);
-
- LOCAL_USER_REMOVE(u);
free(orig_s);
+
+ LOCAL_USER_REMOVE(u);
+
return res;
}