[asterisk-commits] trunk - r8505 in /trunk: funcs/func_db.c
funcs/func_rand.c manager.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Jan 23 11:07:13 MST 2006
Author: mogorman
Date: Mon Jan 23 12:07:12 2006
New Revision: 8505
URL: http://svn.digium.com/view/asterisk?rev=8505&view=rev
Log:
code clean up and macro implementation from
bug 6247
Modified:
trunk/funcs/func_db.c
trunk/funcs/func_rand.c
trunk/manager.c
Modified: trunk/funcs/func_db.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_db.c?rev=8505&r1=8504&r2=8505&view=diff
==============================================================================
--- trunk/funcs/func_db.c (original)
+++ trunk/funcs/func_db.c Mon Jan 23 12:07:12 2006
@@ -44,30 +44,35 @@
static char *function_db_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
- int argc;
- char *args;
- char *argv[2];
- char *family;
- char *key;
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(family);
+ AST_APP_ARG(key);
+ );
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
+ buf[0] = '\0';
return buf;
}
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
+ parse = ast_strdupa(data);
+ if (!parse) {
+ ast_log(LOG_ERROR, "Out of memory!\n");
+ buf[0] = '\0';
+ return buf;
+ }
+
+ AST_NONSTANDARD_APP_ARGS(args, parse, '/');
- if (argc > 1) {
- family = argv[0];
- key = argv[1];
- } else {
+ if (args.argc < 2) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
+ buf[0] = '\0';
return buf;
}
- if (ast_db_get(family, key, buf, len-1)) {
- ast_log(LOG_DEBUG, "DB: %s/%s not found in database.\n", family, key);
+ if (ast_db_get(args.family, args.key, buf, len-1)) {
+ ast_log(LOG_DEBUG, "DB: %s/%s not found in database.\n", args.family, args.key);
} else
pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
@@ -77,29 +82,31 @@
static void function_db_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
{
- int argc;
- char *args;
- char *argv[2];
- char *family;
- char *key;
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(family);
+ AST_APP_ARG(key);
+ );
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=<value>\n");
return;
}
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
-
- if (argc > 1) {
- family = argv[0];
- key = argv[1];
- } else {
+ parse = ast_strdupa(data);
+ if (!parse) {
+ ast_log(LOG_ERROR, "Out of memory!\n");
+ return;
+ }
+
+ AST_NONSTANDARD_APP_ARGS(args, parse, '/');
+
+ if (args.argc < 2) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n");
return;
}
- if (ast_db_put(family, key, (char*)value)) {
+ if (ast_db_put(args.family, args.key, (char*)value)) {
ast_log(LOG_WARNING, "DB: Error writing value to database.\n");
}
}
@@ -123,29 +130,34 @@
static char *function_db_exists(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
- int argc;
- char *args;
- char *argv[2];
- char *family;
- char *key;
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(family);
+ AST_APP_ARG(key);
+ );
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
+ buf[0] = '\0';
return buf;
}
- args = ast_strdupa(data);
- argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
+ parse = ast_strdupa(data);
+ if (!parse) {
+ ast_log(LOG_ERROR, "Out of memory!\n");
+ buf[0] = '\0';
+ return buf;
+ }
+
+ AST_NONSTANDARD_APP_ARGS(args, parse, '/');
- if (argc > 1) {
- family = argv[0];
- key = argv[1];
- } else {
+ if (args.argc < 2) {
ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
+ buf[0] = '\0';
return buf;
}
- if (ast_db_get(family, key, buf, len-1))
+ if (ast_db_get(args.family, args.key, buf, len-1))
ast_copy_string(buf, "0", len);
else {
pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
Modified: trunk/funcs/func_rand.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_rand.c?rev=8505&r1=8504&r2=8505&view=diff
==============================================================================
--- trunk/funcs/func_rand.c (original)
+++ trunk/funcs/func_rand.c Mon Jan 23 12:07:12 2006
@@ -50,24 +50,29 @@
static char *acf_rand_exec(struct ast_channel *chan, char *cmd, char *data, char *buffer, size_t buflen)
{
struct localuser *u;
- char *args[2] = { "", "" }, *s;
int min_int, response_int, max_int;
+ char *parse;
+
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(min);
+ AST_APP_ARG(max);
+ );
+
+ if (!(parse = ast_strdupa(data))) {
+ *buffer = '\0';
+ return buffer;
+ }
LOCAL_USER_ACF_ADD(u);
- if (!(s = ast_strdupa(data))) {
- *buffer = '\0';
- LOCAL_USER_REMOVE(u);
- return buffer;
- }
-
- ast_app_separate_args(s, '|', args, sizeof(args) / sizeof(args[0]));
-
- if (ast_strlen_zero(args[0]) || sscanf(args[0], "%d", &min_int) != 1) {
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ if (ast_strlen_zero(args.min) || sscanf(args.min, "%d", &min_int) != 1) {
min_int = 0;
}
- if (ast_strlen_zero(args[1]) || sscanf(args[1], "%d", &max_int) != 1) {
+
+ if (ast_strlen_zero(args.max) || sscanf(args.max, "%d", &max_int) != 1) {
max_int = RAND_MAX;
}
Modified: trunk/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/manager.c?rev=8505&r1=8504&r2=8505&view=diff
==============================================================================
--- trunk/manager.c (original)
+++ trunk/manager.c Mon Jan 23 12:07:12 2006
@@ -320,23 +320,27 @@
int varlen, x, y;
struct ast_variable *head = NULL, *cur;
char *var, *val;
- unsigned int var_count;
- char *vars[32];
-
+
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(vars)[32];
+ );
+
varlen = strlen("Variable: ");
for (x = 0; x < m->hdrcount; x++) {
if (strncasecmp("Variable: ", m->headers[x], varlen))
continue;
- if (!(var = ast_strdupa(m->headers[x] + varlen)))
+ if (!(parse = ast_strdupa(m->headers[x] + varlen)))
return head;
- if ((var_count = ast_app_separate_args(var, '|', vars, sizeof(vars) / sizeof(vars[0])))) {
- for (y = 0; y < var_count; y++) {
- if (!vars[y])
+ AST_STANDARD_APP_ARGS(args, parse);
+ if (args.argc) {
+ for (y = 0; y < args.argc; y++) {
+ if (!args.vars[y])
continue;
- var = val = ast_strdupa(vars[y]);
+ var = val = ast_strdupa(args.vars[y]);
strsep(&val, "=");
if (!val || ast_strlen_zero(var))
continue;
More information about the asterisk-commits
mailing list