aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_db.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-19 18:19:02 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-19 18:19:02 +0000
commit58818426d60d583c4becc6a99b398cbac1b7b12f (patch)
tree5fee3540f8d72d45cd1b2e5bf15e5860581dd4f8 /apps/app_db.c
parenta4d6ea67a7536e2cb2337527357ce6d3db8639f3 (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_db.c')
-rwxr-xr-xapps/app_db.c81
1 files changed, 48 insertions, 33 deletions
diff --git a/apps/app_db.c b/apps/app_db.c
index b0c3d1339..970956a3a 100755
--- a/apps/app_db.c
+++ b/apps/app_db.c
@@ -77,22 +77,24 @@ LOCAL_USER_DECL;
static int deltree_exec(struct ast_channel *chan, void *data)
{
- int arglen;
char *argv, *family, *keytree;
+ struct localuser *u;
- arglen = strlen(data);
- argv = alloca(arglen + 1);
- if (!argv) { /* Why would this fail? */
- ast_log(LOG_DEBUG, "Memory allocation failed\n");
+ LOCAL_USER_ADD(u);
+
+ argv = ast_strdupa(data);
+ if (!argv) {
+ ast_log(LOG_ERROR, "Memory allocation failed\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
- memcpy(argv, data, arglen + 1);
if (strchr(argv, '/')) {
family = strsep(&argv, "/");
keytree = strsep(&argv, "\0");
if (!family || !keytree) {
ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
if (!strlen(keytree))
@@ -114,27 +116,31 @@ static int deltree_exec(struct ast_channel *chan, void *data)
ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: Error deleting key from database.\n");
}
+ LOCAL_USER_REMOVE(u);
+
return 0;
}
static int del_exec(struct ast_channel *chan, void *data)
{
- int arglen;
char *argv, *family, *key;
+ struct localuser *u;
- arglen = strlen(data);
- argv = alloca(arglen + 1);
- if (!argv) { /* Why would this fail? */
- ast_log (LOG_DEBUG, "Memory allocation failed\n");
+ LOCAL_USER_ADD(u);
+
+ argv = ast_strdupa(data);
+ if (!argv) {
+ ast_log (LOG_ERROR, "Memory allocation failed\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
- memcpy(argv, data, arglen + 1);
if (strchr(argv, '/')) {
family = strsep(&argv, "/");
key = strsep(&argv, "\0");
if (!family || !key) {
ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
if (option_verbose > 2)
@@ -146,27 +152,31 @@ static int del_exec(struct ast_channel *chan, void *data)
} else {
ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
}
+
+ LOCAL_USER_REMOVE(u);
+
return 0;
}
static int put_exec(struct ast_channel *chan, void *data)
{
- int arglen;
char *argv, *value, *family, *key;
static int dep_warning = 0;
+ struct localuser *u;
+
+ LOCAL_USER_ADD(u);
if (!dep_warning) {
ast_log(LOG_WARNING, "This application has been deprecated, please use the ${DB(family/key)} function instead.\n");
dep_warning = 1;
}
- arglen = strlen(data);
- argv = alloca(arglen + 1);
- if (!argv) { /* Why would this fail? */
- ast_log(LOG_DEBUG, "Memory allocation failed\n");
+ argv = ast_strdupa(data);
+ if (!argv) {
+ ast_log(LOG_ERROR, "Memory allocation failed\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
- memcpy(argv, data, arglen + 1);
if (strchr(argv, '/') && strchr(argv, '=')) {
family = strsep(&argv, "/");
@@ -174,6 +184,7 @@ static int put_exec(struct ast_channel *chan, void *data)
value = strsep(&argv, "\0");
if (!value || !family || !key) {
ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
if (option_verbose > 2)
@@ -186,28 +197,32 @@ static int put_exec(struct ast_channel *chan, void *data)
} else {
ast_log (LOG_DEBUG, "Ignoring, no parameters\n");
}
+
+ LOCAL_USER_REMOVE(u);
+
return 0;
}
static int get_exec(struct ast_channel *chan, void *data)
{
- int arglen;
char *argv, *varname, *family, *key;
char dbresult[256];
static int dep_warning = 0;
+ struct localuser *u;
+
+ LOCAL_USER_ADD(u);
if (!dep_warning) {
ast_log(LOG_WARNING, "This application has been deprecated, please use the ${DB(family/key)} function instead.\n");
dep_warning = 1;
}
- arglen = strlen(data);
- argv = alloca(arglen + 1);
- if (!argv) { /* Why would this fail? */
- ast_log(LOG_DEBUG, "Memory allocation failed\n");
+ argv = ast_strdupa(data);
+ if (!argv) {
+ ast_log(LOG_ERROR, "Memory allocation failed\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
- memcpy(argv, data, arglen + 1);
if (strchr(argv, '=') && strchr(argv, '/')) {
varname = strsep(&argv, "=");
@@ -215,6 +230,7 @@ static int get_exec(struct ast_channel *chan, void *data)
key = strsep(&argv, "\0");
if (!varname || !family || !key) {
ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+ LOCAL_USER_REMOVE(u);
return 0;
}
if (option_verbose > 2)
@@ -227,13 +243,14 @@ static int get_exec(struct ast_channel *chan, void *data)
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "DBget: Value not found in database.\n");
/* Send the call to n+101 priority, where n is the current priority */
- if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
- chan->priority += 100;
+ ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
}
-
} else {
ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
}
+
+ LOCAL_USER_REMOVE(u);
+
return 0;
}
@@ -256,12 +273,10 @@ int load_module(void)
int retval;
retval = ast_register_application(g_app, get_exec, g_synopsis, g_descrip);
- if (!retval)
- retval = ast_register_application(p_app, put_exec, p_synopsis, p_descrip);
- if (!retval)
- retval = ast_register_application(d_app, del_exec, d_synopsis, d_descrip);
- if (!retval)
- retval = ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip);
+ retval |= ast_register_application(p_app, put_exec, p_synopsis, p_descrip);
+ retval |= ast_register_application(d_app, del_exec, d_synopsis, d_descrip);
+ retval |= ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip);
+
return retval;
}