From 58818426d60d583c4becc6a99b398cbac1b7b12f Mon Sep 17 00:00:00 2001 From: russell Date: Wed, 19 Oct 2005 18:19:02 +0000 Subject: 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: http://svn.digium.com/svn/asterisk/trunk@6832 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/app_parkandannounce.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'apps/app_parkandannounce.c') 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; } -- cgit v1.2.3