diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-19 18:19:02 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-19 18:19:02 +0000 |
commit | 58818426d60d583c4becc6a99b398cbac1b7b12f (patch) | |
tree | 5fee3540f8d72d45cd1b2e5bf15e5860581dd4f8 /apps/app_setcallerid.c | |
parent | a4d6ea67a7536e2cb2337527357ce6d3db8639f3 (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: http://svn.digium.com/svn/asterisk/trunk@6832 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_setcallerid.c')
-rwxr-xr-x | apps/app_setcallerid.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/apps/app_setcallerid.c b/apps/app_setcallerid.c index 4fd381fe5..fec0ad605 100755 --- a/apps/app_setcallerid.c +++ b/apps/app_setcallerid.c @@ -68,15 +68,17 @@ static int setcallerid_pres_exec(struct ast_channel *chan, void *data) struct localuser *u; int pres = -1; + LOCAL_USER_ADD(u); + pres = ast_parse_caller_presentation(data); if (pres < 0) { ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n", (char *) data); + LOCAL_USER_REMOVE(u); return 0; } - - LOCAL_USER_ADD(u); + chan->cid.cid_pres = pres; LOCAL_USER_REMOVE(u); return 0; @@ -97,14 +99,27 @@ static char *descrip = static int setcallerid_exec(struct ast_channel *chan, void *data) { int res = 0; - char tmp[256] = ""; + char *tmp = NULL; char name[256]; char num[256]; struct localuser *u; char *opt; int anitoo = 0; - if (data) - ast_copy_string(tmp, (char *)data, sizeof(tmp)); + + if (!data || ast_strlen_zero(data)) { + ast_log(LOG_WARNING, "SetCallerID requires an argument!\n"); + return 0; + } + + LOCAL_USER_ADD(u); + + tmp = ast_strdupa(data); + if (!tmp) { + ast_log(LOG_ERROR, "Out of memory\n"); + LOCAL_USER_REMOVE(u); + return -1; + } + opt = strchr(tmp, '|'); if (opt) { *opt = '\0'; @@ -112,10 +127,12 @@ static int setcallerid_exec(struct ast_channel *chan, void *data) if (*opt == 'a') anitoo = 1; } - LOCAL_USER_ADD(u); + ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num)); ast_set_callerid(chan, num, name, anitoo ? num : NULL); + LOCAL_USER_REMOVE(u); + return res; } |