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_voicemail.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_voicemail.c')
-rwxr-xr-x | apps/app_voicemail.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 54351f9d6..7cd529ad3 100755 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -5478,9 +5478,9 @@ static int vm_exec(struct ast_channel *chan, void *data) struct ast_flags flags = { 0 }; char *opts[OPT_ARG_ARRAY_SIZE]; - memset(&leave_options, 0, sizeof(leave_options)); - LOCAL_USER_ADD(u); + + memset(&leave_options, 0, sizeof(leave_options)); if (chan->_state != AST_STATE_UP) ast_answer(chan); @@ -5523,16 +5523,18 @@ static int vm_exec(struct ast_channel *chan, void *data) } } else { res = ast_app_getdata(chan, "vm-whichbox", tmp, sizeof(tmp) - 1, 0); - if (res < 0) + if (res < 0) { + LOCAL_USER_REMOVE(u); return res; - if (ast_strlen_zero(tmp)) + } + if (ast_strlen_zero(tmp)) { + LOCAL_USER_REMOVE(u); return 0; + } } res = leave_voicemail(chan, argv[0], &leave_options); - LOCAL_USER_REMOVE(u); - if (res == ERROR_LOCK_PATH) { ast_log(LOG_ERROR, "Could not leave voicemail. The path is already locked.\n"); /*Send the call to n+101 priority, where n is the current priority*/ @@ -5541,6 +5543,8 @@ static int vm_exec(struct ast_channel *chan, void *data) res = 0; } + LOCAL_USER_REMOVE(u); + return res; } @@ -5589,13 +5593,20 @@ static int vm_box_exists(struct ast_channel *chan, void *data) struct ast_vm_user svm; char *context, *box; - if (!data || !(box = ast_strdupa(data))) { + if (!data || ast_strlen_zero(data)) { ast_log(LOG_ERROR, "MailboxExists requires an argument: (vmbox[@context])\n"); return -1; } LOCAL_USER_ADD(u); + box = ast_strdupa(data); + if (!box) { + ast_log(LOG_ERROR, "Out of memory\n"); + LOCAL_USER_REMOVE(u); + return -1; + } + if ((context = strchr(box, '@'))) { *context = '\0'; context++; @@ -5618,6 +5629,8 @@ static int vmauthenticate(struct ast_channel *chan, void *data) int silent = 0; int res = -1; + LOCAL_USER_ADD(u); + if (s) { s = ast_strdupa(s); if (!s) { @@ -5637,8 +5650,6 @@ static int vmauthenticate(struct ast_channel *chan, void *data) silent = (strchr(options, 's')) != NULL; } - LOCAL_USER_ADD(u); - if (!vm_authenticate(chan, mailbox, sizeof(mailbox), &vmus, context, NULL, 0, 3, silent)) { pbx_builtin_setvar_helper(chan, "AUTH_MAILBOX", mailbox); pbx_builtin_setvar_helper(chan, "AUTH_CONTEXT", vmus.context); |