Index: main/pbx.c =================================================================== --- main/pbx.c (revision 188028) +++ main/pbx.c (working copy) @@ -237,6 +237,8 @@ static int pbx_builtin_saycharacters(struct ast_channel *, void *); static int pbx_builtin_sayphonetic(struct ast_channel *, void *); int pbx_builtin_setvar(struct ast_channel *, void *); +int pbx_builtin_incvar(struct ast_channel *, void *); +int pbx_builtin_decvar(struct ast_channel *, void *); static int pbx_builtin_importvar(struct ast_channel *, void *); AST_MUTEX_DEFINE_STATIC(globalslock); @@ -460,6 +462,24 @@ "function instead.\n" }, + { "Inc", pbx_builtin_incvar, + "Increment channel variable by 1", + " Inc(name)\n" + "This function can be used to increment the value of a channel variable.\n" + "Essentially, this function can be used instead of issuing the following:\n" + " Set(Var=$[${Var} + 1])\n" + "\n\nThis function will accept a single variable only\n" + }, + + { "Dec", pbx_builtin_decvar, + "Decrement channel variable by 1", + " Dec(name)\n" + "This function can be used to decrement the value of a channel variable.\n" + "Essentially, this function can be used instead of issuing the following:\n" + " Set(Var=$[${Var} - 1])\n" + "\n\nThis function will accept a single variable only\n" + }, + { "ImportVar", pbx_builtin_importvar, "Import a variable from a channel into a new variable", " ImportVar(newvar=channelname|variable): This application imports a variable\n" @@ -5948,6 +5968,85 @@ return(0); } +/* This function will increment the value of a variable by 1 */ +int pbx_builtin_incvar(struct ast_channel *chan, void *data) +{ + char *mydata, *newvalue; + int argc; + char *argv[24]; /* This really isn't used here */ + int global = 0; + int x; + + if (ast_strlen_zero(data)) { + ast_log(LOG_WARNING, "Inc requires a variable name.\n"); + return 0; + } + + mydata = ast_strdupa(data); + + ast_log(LOG_NOTICE, "mydata now contains: %s\n",mydata); + + argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0])); + + if (argc > 1) { + ast_log(LOG_WARNING, "The use of Inc accepts a single variable name\n"); + return 0; + } + + const char *value = pbx_builtin_getvar_helper(chan, mydata); + + x = atoi(value); + x++; + + sprintf(newvalue,"%d",x); + + ast_log(LOG_NOTICE, "The value of %s is now: %s\n", mydata, newvalue); + + pbx_builtin_setvar_helper((global) ? NULL : chan, mydata, newvalue); + + return(0); +} + +/* This function will decrement the value of a variable by 1 */ +int pbx_builtin_decvar(struct ast_channel *chan, void *data) +{ + char *mydata, *newvalue; + int argc; + char *argv[24]; /* This really isn't used here */ + int global = 0; + int x; + + if (ast_strlen_zero(data)) { + ast_log(LOG_WARNING, "Inc requires a variable name.\n"); + return 0; + } + + mydata = ast_strdupa(data); + + ast_log(LOG_NOTICE, "mydata now contains: %s\n",mydata); + + argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0])); + + if (argc > 1) { + ast_log(LOG_WARNING, "The use of Inc accepts a single variable name\n"); + return 0; + } + + const char *value = pbx_builtin_getvar_helper(chan, mydata); + + x = atoi(value); + x--; + + sprintf(newvalue,"%d",x); + + ast_log(LOG_NOTICE, "The value of %s is now: %s\n", mydata, newvalue); + + pbx_builtin_setvar_helper((global) ? NULL : chan, mydata, newvalue); + + return(0); +} + + int pbx_builtin_importvar(struct ast_channel *chan, void *data) { char *name;