Skip to content
Snippets Groups Projects
Commit ae232491 authored by Dwayne M. Hubbard's avatar Dwayne M. Hubbard
Browse files

Added AND, OR, and XOR bitwise operations to MATH for issue 9891, thanks jcmoore

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@72524 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 6f7cbd1c
Branches
Tags
No related merge requests found
...@@ -53,6 +53,9 @@ enum TypeOfFunctions { ...@@ -53,6 +53,9 @@ enum TypeOfFunctions {
POWFUNCTION, POWFUNCTION,
SHLEFTFUNCTION, SHLEFTFUNCTION,
SHRIGHTFUNCTION, SHRIGHTFUNCTION,
BITWISEANDFUNCTION,
BITWISEXORFUNCTION,
BITWISEORFUNCTION,
GTFUNCTION, GTFUNCTION,
LTFUNCTION, LTFUNCTION,
GTEFUNCTION, GTEFUNCTION,
...@@ -114,6 +117,18 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse, ...@@ -114,6 +117,18 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse,
} else if ((op = strchr(mvalue1, '^'))) { } else if ((op = strchr(mvalue1, '^'))) {
iaction = POWFUNCTION; iaction = POWFUNCTION;
*op = '\0'; *op = '\0';
} else if ((op = strstr(mvalue1, "AND"))) {
iaction = BITWISEANDFUNCTION;
op += 3;
*op = '\0';
} else if ((op = strstr(mvalue1, "XOR"))) {
iaction = BITWISEXORFUNCTION;
op += 3;
*op = '\0';
} else if ((op = strstr(mvalue1, "OR"))) {
iaction = BITWISEORFUNCTION;
op += 2;
*op = '\0';
} else if ((op = strchr(mvalue1, '>'))) { } else if ((op = strchr(mvalue1, '>'))) {
iaction = GTFUNCTION; iaction = GTFUNCTION;
*op = '\0'; *op = '\0';
...@@ -237,6 +252,27 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse, ...@@ -237,6 +252,27 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse,
ftmp = (inum1 >> inum2); ftmp = (inum1 >> inum2);
break; break;
} }
case BITWISEANDFUNCTION:
{
int inum1 = fnum1;
int inum2 = fnum2;
ftmp = (inum1 & inum2);
break;
}
case BITWISEXORFUNCTION:
{
int inum1 = fnum1;
int inum2 = fnum2;
ftmp = (inum1 ^ inum2);
break;
}
case BITWISEORFUNCTION:
{
int inum1 = fnum1;
int inum2 = fnum2;
ftmp = (inum1 | inum2);
break;
}
case GTFUNCTION: case GTFUNCTION:
ast_copy_string(buf, (fnum1 > fnum2) ? "TRUE" : "FALSE", len); ast_copy_string(buf, (fnum1 > fnum2) ? "TRUE" : "FALSE", len);
break; break;
...@@ -278,7 +314,7 @@ static struct ast_custom_function math_function = { ...@@ -278,7 +314,7 @@ static struct ast_custom_function math_function = {
.synopsis = "Performs Mathematical Functions", .synopsis = "Performs Mathematical Functions",
.syntax = "MATH(<number1><op><number2>[,<type_of_result>])", .syntax = "MATH(<number1><op><number2>[,<type_of_result>])",
.desc = "Perform calculation on number1 to number2. Valid ops are: \n" .desc = "Perform calculation on number1 to number2. Valid ops are: \n"
" +,-,/,*,%,<<,>>,^,<,>,>=,<=,==\n" " +,-,/,*,%,<<,>>,^,AND,OR,XOR,<,>,>=,<=,==\n"
"and behave as their C equivalents.\n" "and behave as their C equivalents.\n"
"<type_of_result> - wanted type of result:\n" "<type_of_result> - wanted type of result:\n"
" f, float - float(default)\n" " f, float - float(default)\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment