Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
func_math.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2004 - 2006, Andy Powell
5 *
6 * Updated by Mark Spencer <markster@digium.com>
7 * Updated by Nir Simionovich <nirs@greenfieldtech.net>
8 * Updated by Naveen Albert <asterisk@phreaknet.org>
9 *
10 * See http://www.asterisk.org for more information about
11 * the Asterisk project. Please do not directly contact
12 * any of the maintainers of this project for assistance;
13 * the project provides a web site, mailing lists and IRC
14 * channels for your use.
15 *
16 * This program is free software, distributed under the terms of
17 * the GNU General Public License Version 2. See the LICENSE file
18 * at the top of the source tree.
19 */
20
21/*! \file
22 *
23 * \brief Math related dialplan function
24 *
25 * \author Andy Powell
26 * \author Mark Spencer <markster@digium.com>
27 * \author Nir Simionovich <nirs@greenfieldtech.net>
28 * \author Naveen Albert <asterisk@phreaknet.org>
29 *
30 * \ingroup functions
31 */
32
33/*** MODULEINFO
34 <support_level>core</support_level>
35 ***/
36
37#include "asterisk.h"
38
39#include <math.h>
40
41#include "asterisk/module.h"
42#include "asterisk/channel.h"
43#include "asterisk/pbx.h"
44#include "asterisk/utils.h"
46#include "asterisk/app.h"
47#include "asterisk/config.h"
48#include "asterisk/test.h"
49
50/*** DOCUMENTATION
51 <function name="MATH" language="en_US">
52 <since>
53 <version>1.2.0</version>
54 </since>
55 <synopsis>
56 Performs Mathematical Functions.
57 </synopsis>
58 <syntax>
59 <parameter name="expression" required="true">
60 <para>Is of the form:
61 <replaceable>number1</replaceable><replaceable>op</replaceable><replaceable>number2</replaceable>
62 where the possible values for <replaceable>op</replaceable>
63 are:</para>
64 <para>+,-,/,*,%,&lt;&lt;,&gt;&gt;,^,AND,OR,XOR,&lt;,&gt;,&lt;=,&gt;=,== (and behave as their C equivalents)</para>
65 </parameter>
66 <parameter name="type">
67 <para>Wanted type of result:</para>
68 <para>f, float - float(default)</para>
69 <para>i, int - integer</para>
70 <para>h, hex - hex</para>
71 <para>c, char - char</para>
72 </parameter>
73 </syntax>
74 <description>
75 <para>Performs mathematical functions based on two parameters and an operator. The returned
76 value type is <replaceable>type</replaceable></para>
77 <example title="Sets var i to 11">
78 same => n,Set(i=${MATH(123%16,int)})
79 </example>
80 </description>
81 </function>
82 <function name="INC" language="en_US">
83 <since>
84 <version>1.8.0</version>
85 </since>
86 <synopsis>
87 Increments the value of a variable, while returning the updated value to the dialplan
88 </synopsis>
89 <syntax>
90 <parameter name="variable" required="true">
91 <para>
92 The variable name to be manipulated, without the braces.
93 </para>
94 </parameter>
95 </syntax>
96 <description>
97 <para>Increments the value of a variable, while returning the updated value to the dialplan</para>
98 <para>Example: INC(MyVAR) - Increments MyVar</para>
99 <para>Note: INC(${MyVAR}) - Is wrong, as INC expects the variable name, not its value</para>
100 </description>
101 </function>
102 <function name="DEC" language="en_US">
103 <since>
104 <version>1.8.0</version>
105 </since>
106 <synopsis>
107 Decrements the value of a variable, while returning the updated value to the dialplan
108 </synopsis>
109 <syntax>
110 <parameter name="variable" required="true">
111 <para>
112 The variable name to be manipulated, without the braces.
113 </para>
114 </parameter>
115 </syntax>
116 <description>
117 <para>Decrements the value of a variable, while returning the updated value to the dialplan</para>
118 <example title="Decrements MyVAR">
119 same => n,NoOp(${DEC(MyVAR)})
120 </example>
121 <note><para>DEC(${MyVAR}) is wrong, as DEC expects the variable name, not its value</para></note>
122 </description>
123 </function>
124 <function name="MIN" language="en_US">
125 <since>
126 <version>16.19.0</version>
127 <version>18.5.0</version>
128 </since>
129 <synopsis>
130 Returns the minimum of two numbers.
131 </synopsis>
132 <syntax>
133 <parameter name="num1" />
134 <parameter name="num2" />
135 </syntax>
136 <description>
137 <para>Returns the minimum of two numbers <replaceable>num1</replaceable> and <replaceable>num2</replaceable>.</para>
138 <example title="Sets the min variable equal to 4">
139 same => n,Set(min=${MIN(7,4)})
140 </example>
141 </description>
142 </function>
143 <function name="MAX" language="en_US">
144 <since>
145 <version>16.19.0</version>
146 <version>18.5.0</version>
147 </since>
148 <synopsis>
149 Returns the maximum of two numbers.
150 </synopsis>
151 <syntax>
152 <parameter name="num1" />
153 <parameter name="num2" />
154 </syntax>
155 <description>
156 <para>Returns the maximum of two numbers <replaceable>num1</replaceable> and <replaceable>num2</replaceable>.</para>
157 <example title="Sets the max variable equal to 13">
158 same => n,Set(max=${MAX(4,7)})
159 </example>
160 </description>
161 </function>
162 <function name="ABS" language="en_US">
163 <since>
164 <version>16.19.0</version>
165 <version>18.5.0</version>
166 </since>
167 <synopsis>
168 Returns absolute value of a number.
169 </synopsis>
170 <syntax>
171 <parameter name="num" />
172 </syntax>
173 <description>
174 <para>Returns the absolute value of a number <replaceable>num</replaceable>.</para>
175 <example title="Sets the absval variable equal to 13">
176 same => n,Set(absval=${ABS(-13)})
177 </example>
178 </description>
179 </function>
180 ***/
181
200
207
208static int math(struct ast_channel *chan, const char *cmd, char *parse,
209 char *buf, size_t len)
210{
211 double fnum1;
212 double fnum2;
213 double ftmp = 0;
214 char *op;
215 int iaction = -1;
216 int type_of_result = FLOAT_RESULT;
217 char *mvalue1, *mvalue2 = NULL, *mtype_of_result;
218 int negvalue1 = 0;
220 AST_APP_ARG(argv0);
221 AST_APP_ARG(argv1);
222 );
223
224 if (ast_strlen_zero(parse)) {
225 ast_log(LOG_WARNING, "Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
226 return -1;
227 }
228
230
231 if (args.argc < 1) {
232 ast_log(LOG_WARNING, "Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
233 return -1;
234 }
235
236 mvalue1 = args.argv0;
237
238 if (mvalue1[0] == '-') {
239 negvalue1 = 1;
240 mvalue1++;
241 }
242
243 if ((op = strchr(mvalue1, '*'))) {
244 iaction = MULTIPLYFUNCTION;
245 *op = '\0';
246 } else if ((op = strchr(mvalue1, '/'))) {
247 iaction = DIVIDEFUNCTION;
248 *op = '\0';
249 } else if ((op = strchr(mvalue1, '%'))) {
250 iaction = MODULUSFUNCTION;
251 *op = '\0';
252 } else if ((op = strchr(mvalue1, '^'))) {
253 iaction = POWFUNCTION;
254 *op = '\0';
255 } else if ((op = strstr(mvalue1, "AND"))) {
256 iaction = BITWISEANDFUNCTION;
257 *op = '\0';
258 op += 2;
259 } else if ((op = strstr(mvalue1, "XOR"))) {
260 iaction = BITWISEXORFUNCTION;
261 *op = '\0';
262 op += 2;
263 } else if ((op = strstr(mvalue1, "OR"))) {
264 iaction = BITWISEORFUNCTION;
265 *op = '\0';
266 ++op;
267 } else if ((op = strchr(mvalue1, '>'))) {
268 iaction = GTFUNCTION;
269 *op = '\0';
270 if (*(op + 1) == '=') {
271 iaction = GTEFUNCTION;
272 ++op;
273 } else if (*(op + 1) == '>') {
274 iaction = SHRIGHTFUNCTION;
275 ++op;
276 }
277 } else if ((op = strchr(mvalue1, '<'))) {
278 iaction = LTFUNCTION;
279 *op = '\0';
280 if (*(op + 1) == '=') {
281 iaction = LTEFUNCTION;
282 ++op;
283 } else if (*(op + 1) == '<') {
284 iaction = SHLEFTFUNCTION;
285 ++op;
286 }
287 } else if ((op = strchr(mvalue1, '='))) {
288 *op = '\0';
289 if (*(op + 1) == '=') {
290 iaction = EQFUNCTION;
291 ++op;
292 } else
293 op = NULL;
294 } else if ((op = strchr(mvalue1, '+'))) {
295 iaction = ADDFUNCTION;
296 *op = '\0';
297 } else if ((op = strchr(mvalue1, '-'))) { /* subtraction MUST always be last, in case we have a negative second number */
298 iaction = SUBTRACTFUNCTION;
299 *op = '\0';
300 }
301
302 if (op)
303 mvalue2 = op + 1;
304
305 /* detect wanted type of result */
306 mtype_of_result = args.argv1;
307 if (mtype_of_result) {
308 if (!strcasecmp(mtype_of_result, "float")
309 || !strcasecmp(mtype_of_result, "f"))
310 type_of_result = FLOAT_RESULT;
311 else if (!strcasecmp(mtype_of_result, "int")
312 || !strcasecmp(mtype_of_result, "i"))
313 type_of_result = INT_RESULT;
314 else if (!strcasecmp(mtype_of_result, "hex")
315 || !strcasecmp(mtype_of_result, "h"))
316 type_of_result = HEX_RESULT;
317 else if (!strcasecmp(mtype_of_result, "char")
318 || !strcasecmp(mtype_of_result, "c"))
319 type_of_result = CHAR_RESULT;
320 else {
321 ast_log(LOG_WARNING, "Unknown type of result requested '%s'.\n",
322 mtype_of_result);
323 return -1;
324 }
325 }
326
327 if (!mvalue2) {
329 "Supply all the parameters - just this once, please\n");
330 return -1;
331 }
332
333 if (sscanf(mvalue1, "%30lf", &fnum1) != 1) {
334 ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue1);
335 return -1;
336 }
337
338 if (sscanf(mvalue2, "%30lf", &fnum2) != 1) {
339 ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue2);
340 return -1;
341 }
342
343 if (negvalue1)
344 fnum1 = 0 - fnum1;
345
346 switch (iaction) {
347 case ADDFUNCTION:
348 ftmp = fnum1 + fnum2;
349 break;
350 case DIVIDEFUNCTION:
351 if (fnum2 <= 0)
352 ftmp = 0; /* can't do a divide by 0 */
353 else
354 ftmp = (fnum1 / fnum2);
355 break;
356 case MULTIPLYFUNCTION:
357 ftmp = (fnum1 * fnum2);
358 break;
359 case SUBTRACTFUNCTION:
360 ftmp = (fnum1 - fnum2);
361 break;
362 case MODULUSFUNCTION:
363 {
364 int inum1 = fnum1;
365 int inum2 = fnum2;
366
367 if (inum2 == 0) {
368 ftmp = 0;
369 } else {
370 ftmp = (inum1 % inum2);
371 }
372
373 break;
374 }
375 case POWFUNCTION:
376 ftmp = pow(fnum1, fnum2);
377 break;
378 case SHLEFTFUNCTION:
379 {
380 int inum1 = fnum1;
381 int inum2 = fnum2;
382
383 ftmp = (inum1 << inum2);
384 break;
385 }
386 case SHRIGHTFUNCTION:
387 {
388 int inum1 = fnum1;
389 int inum2 = fnum2;
390
391 ftmp = (inum1 >> inum2);
392 break;
393 }
395 {
396 int inum1 = fnum1;
397 int inum2 = fnum2;
398 ftmp = (inum1 & inum2);
399 break;
400 }
402 {
403 int inum1 = fnum1;
404 int inum2 = fnum2;
405 ftmp = (inum1 ^ inum2);
406 break;
407 }
409 {
410 int inum1 = fnum1;
411 int inum2 = fnum2;
412 ftmp = (inum1 | inum2);
413 break;
414 }
415 case GTFUNCTION:
416 ast_copy_string(buf, (fnum1 > fnum2) ? "TRUE" : "FALSE", len);
417 break;
418 case LTFUNCTION:
419 ast_copy_string(buf, (fnum1 < fnum2) ? "TRUE" : "FALSE", len);
420 break;
421 case GTEFUNCTION:
422 ast_copy_string(buf, (fnum1 >= fnum2) ? "TRUE" : "FALSE", len);
423 break;
424 case LTEFUNCTION:
425 ast_copy_string(buf, (fnum1 <= fnum2) ? "TRUE" : "FALSE", len);
426 break;
427 case EQFUNCTION:
428 ast_copy_string(buf, (fnum1 == fnum2) ? "TRUE" : "FALSE", len);
429 break;
430 default:
432 "Something happened that neither of us should be proud of %d\n",
433 iaction);
434 return -1;
435 }
436
437 if (iaction < GTFUNCTION || iaction > EQFUNCTION) {
438 if (type_of_result == FLOAT_RESULT)
439 snprintf(buf, len, "%f", ftmp);
440 else if (type_of_result == INT_RESULT)
441 snprintf(buf, len, "%i", (int) ftmp);
442 else if (type_of_result == HEX_RESULT)
443 snprintf(buf, len, "%x", (unsigned int) ftmp);
444 else if (type_of_result == CHAR_RESULT)
445 snprintf(buf, len, "%c", (unsigned char) ftmp);
446 }
447
448 return 0;
449}
450
451static int crement_function_read(struct ast_channel *chan, const char *cmd,
452 char *data, char *buf, size_t len)
453{
454 int ret = -1;
455 int int_value = 0;
456 int modify_orig = 0;
457 const char *var;
458 char endchar = 0, returnvar[12]; /* If you need a variable longer than 11 digits - something is way wrong */
459
460 if (ast_strlen_zero(data)) {
461 ast_log(LOG_WARNING, "Syntax: %s(<data>) - missing argument!\n", cmd);
462 return -1;
463 }
464
465 if (!chan) {
466 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
467 return -1;
468 }
469
470 ast_channel_lock(chan);
471
472 if (!(var = pbx_builtin_getvar_helper(chan, data))) {
473 ast_log(LOG_NOTICE, "Failed to obtain variable %s, bailing out\n", data);
474 ast_channel_unlock(chan);
475 return -1;
476 }
477
478 if (ast_strlen_zero(var)) {
479 ast_log(LOG_NOTICE, "Variable %s doesn't exist - are you sure you wrote it correctly?\n", data);
480 ast_channel_unlock(chan);
481 return -1;
482 }
483
484 if (sscanf(var, "%30d%1c", &int_value, &endchar) == 0 || endchar != 0) {
485 ast_log(LOG_NOTICE, "The content of ${%s} is not a numeric value - bailing out!\n", data);
486 ast_channel_unlock(chan);
487 return -1;
488 }
489
490 /* now we'll actually do something useful */
491 if (!strcasecmp(cmd, "INC")) { /* Increment variable */
492 int_value++;
493 modify_orig = 1;
494 } else if (!strcasecmp(cmd, "DEC")) { /* Decrement variable */
495 int_value--;
496 modify_orig = 1;
497 }
498
499 if (snprintf(returnvar, sizeof(returnvar), "%d", int_value) > 0) {
500 pbx_builtin_setvar_helper(chan, data, returnvar);
501 if (modify_orig) {
502 ast_copy_string(buf, returnvar, len);
503 }
504 ret = 0;
505 } else {
506 pbx_builtin_setvar_helper(chan, data, "0");
507 if (modify_orig) {
508 ast_copy_string(buf, "0", len);
509 }
510 ast_log(LOG_NOTICE, "Variable %s refused to be %sREMENTED, setting value to 0", data, cmd);
511 ret = 0;
512 }
513
514 ast_channel_unlock(chan);
515
516 return ret;
517}
518
519static int acf_min_exec(struct ast_channel *chan, const char *cmd,
520 char *parse, char *buffer, size_t buflen)
521{
522 double num1, num2, response_num = 0;
524 AST_APP_ARG(num1);
525 AST_APP_ARG(num2);
526 );
527
529
530 if (ast_strlen_zero(args.num1) && ast_strlen_zero(args.num2)) {
531 ast_log(LOG_ERROR, "Missing argument for number(s).");
532 return -1;
533 }
534
535 if (ast_strlen_zero(args.num1)) {
536 response_num = -1; /* couldn't read num1 successfully */
537 } else if (sscanf(args.num1, "%30lf", &num1) != 1) {
538 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num1);
539 return -1;
540 }
541
542 if (ast_strlen_zero(args.num2)) {
543 num2 = num1; /* num1 must be a valid integer here */
544 } else if (sscanf(args.num2, "%30lf", &num2) != 1) {
545 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num2);
546 return -1;
547 }
548
549 if (response_num == -1) { /* could only read num2 */
550 response_num = num2;
551 } else {
552 response_num = (num1 > num2) ? num2 : num1;
553 }
554
555 ast_debug(1, "%f is the minimum of [%f,%f]\n", response_num, num1, num2);
556 if ((int) response_num == response_num) {
557 snprintf(buffer, buflen, "%d", (int) response_num);
558 } else {
559 snprintf(buffer, buflen, "%f", response_num);
560 }
561
562 return 0;
563}
564
565static int acf_max_exec(struct ast_channel *chan, const char *cmd,
566 char *parse, char *buffer, size_t buflen)
567{
568 double num1, num2, response_num = 0;
570 AST_APP_ARG(num1);
571 AST_APP_ARG(num2);
572 );
573
575
576 if (ast_strlen_zero(args.num1) && ast_strlen_zero(args.num2)) {
577 ast_log(LOG_ERROR, "Missing argument for number(s).");
578 return -1;
579 }
580
581 if (ast_strlen_zero(args.num1)) {
582 response_num = -1; /* couldn't read num1 successfully */
583 } else if (sscanf(args.num1, "%30lf", &num1) != 1) {
584 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num1);
585 return -1;
586 }
587
588 if (ast_strlen_zero(args.num2)) {
589 num2 = num1; /* num1 must be a valid integer here */
590 } else if (sscanf(args.num2, "%30lf", &num2) != 1) {
591 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num2);
592 return -1;
593 }
594
595 if (response_num == -1) { /* could only read num2 */
596 response_num = num2;
597 } else {
598 response_num = (num1 < num2) ? num2 : num1;
599 }
600
601 ast_debug(1, "%f is the maximum of [%f,%f]\n", response_num, num1, num2);
602 if ((int) response_num == response_num) {
603 snprintf(buffer, buflen, "%d", (int) response_num);
604 } else {
605 snprintf(buffer, buflen, "%f", response_num);
606 }
607
608 return 0;
609}
610
611static int acf_abs_exec(struct ast_channel *chan, const char *cmd,
612 char *parse, char *buffer, size_t buflen)
613{
614 double num1, response_num;
616 AST_APP_ARG(num1);
617 );
618
620
621 if (ast_strlen_zero(args.num1) || sscanf(args.num1, "%30lf", &num1) != 1) {
622 ast_log(LOG_WARNING, "Bad or missing argument for number: %s", args.num1);
623 return -1;
624 }
625
626 response_num = fabs(num1);
627 ast_debug(1, "%f is the absolute value of %f\n", response_num, num1);
628 if ((int) response_num == response_num) {
629 snprintf(buffer, buflen, "%d", (int) response_num);
630 } else {
631 snprintf(buffer, buflen, "%f", response_num);
632 }
633
634 return 0;
635}
636
638 .name = "MATH",
639 .read = math
640};
641
643 .name = "INC",
644 .read = crement_function_read,
645};
646
648 .name = "DEC",
649 .read = crement_function_read,
650};
651
653 .name = "MIN",
654 .read = acf_min_exec,
655 .read_max = 12,
656};
657
659 .name = "MAX",
660 .read = acf_max_exec,
661 .read_max = 12,
662};
663
665 .name = "ABS",
666 .read = acf_abs_exec,
667 .read_max = 12,
668};
669
670#ifdef TEST_FRAMEWORK
671AST_TEST_DEFINE(test_MATH_function)
672{
674 struct ast_str *expr, *result;
675
676 switch (cmd) {
677 case TEST_INIT:
678 info->name = "test_MATH_function";
679 info->category = "/main/pbx/";
680 info->summary = "Test MATH function substitution";
681 info->description =
682 "Executes a series of variable substitutions using the MATH function and ensures that the expected results are received.";
683 return AST_TEST_NOT_RUN;
684 case TEST_EXECUTE:
685 break;
686 }
687
688 ast_test_status_update(test, "Testing MATH() substitution ...\n");
689
690 if (!(expr = ast_str_create(16))) {
691 return AST_TEST_FAIL;
692 }
693 if (!(result = ast_str_create(16))) {
694 ast_free(expr);
695 return AST_TEST_FAIL;
696 }
697
698 ast_str_set(&expr, 0, "${MATH(170 AND 63,i)}");
700 if (strcmp(ast_str_buffer(result), "42") != 0) {
701 ast_test_status_update(test, "Expected result '42' not returned! ('%s')\n",
703 res = AST_TEST_FAIL;
704 }
705
706 ast_str_set(&expr, 0, "${MATH(170AND63,i)}");
708 if (strcmp(ast_str_buffer(result), "42") != 0) {
709 ast_test_status_update(test, "Expected result '42' not returned! ('%s')\n",
711 res = AST_TEST_FAIL;
712 }
713
714 ast_free(expr);
716
717 return res;
718}
719#endif
720
721static int unload_module(void)
722{
723 int res = 0;
724
731 AST_TEST_UNREGISTER(test_MATH_function);
732
733 return res;
734}
735
736static int load_module(void)
737{
738 int res = 0;
739
746 AST_TEST_REGISTER(test_MATH_function);
747
748 return res;
749}
750
751AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Mathematical dialplan function");
#define var
Definition: ast_expr2f.c:605
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_log
Definition: astobj2.c:42
static PGresult * result
Definition: cel_pgsql.c:84
General Asterisk PBX channel definitions.
#define ast_channel_lock(chan)
Definition: channel.h:2970
#define ast_channel_unlock(chan)
Definition: channel.h:2971
Conversion utility functions.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int acf_abs_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition: func_math.c:611
TypeOfResult
Definition: func_math.c:201
@ CHAR_RESULT
Definition: func_math.c:205
@ INT_RESULT
Definition: func_math.c:203
@ FLOAT_RESULT
Definition: func_math.c:202
@ HEX_RESULT
Definition: func_math.c:204
TypeOfFunctions
Definition: func_math.c:182
@ EQFUNCTION
Definition: func_math.c:198
@ BITWISEORFUNCTION
Definition: func_math.c:193
@ BITWISEANDFUNCTION
Definition: func_math.c:191
@ LTEFUNCTION
Definition: func_math.c:197
@ SHRIGHTFUNCTION
Definition: func_math.c:190
@ POWFUNCTION
Definition: func_math.c:188
@ MODULUSFUNCTION
Definition: func_math.c:187
@ ADDFUNCTION
Definition: func_math.c:183
@ SHLEFTFUNCTION
Definition: func_math.c:189
@ GTEFUNCTION
Definition: func_math.c:196
@ BITWISEXORFUNCTION
Definition: func_math.c:192
@ DIVIDEFUNCTION
Definition: func_math.c:184
@ MULTIPLYFUNCTION
Definition: func_math.c:185
@ GTFUNCTION
Definition: func_math.c:194
@ LTFUNCTION
Definition: func_math.c:195
@ SUBTRACTFUNCTION
Definition: func_math.c:186
static struct ast_custom_function increment_function
Definition: func_math.c:642
static int math(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_math.c:208
static struct ast_custom_function math_function
Definition: func_math.c:637
static int acf_max_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition: func_math.c:565
static struct ast_custom_function decrement_function
Definition: func_math.c:647
static struct ast_custom_function acf_min
Definition: func_math.c:652
static int acf_min_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition: func_math.c:519
static struct ast_custom_function acf_abs
Definition: func_math.c:664
static int load_module(void)
Definition: func_math.c:736
static struct ast_custom_function acf_max
Definition: func_math.c:658
static int unload_module(void)
Definition: func_math.c:721
static int crement_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_math.c:451
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Configuration File Parser.
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
def info(msg)
Core PBX routines and definitions.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
#define NULL
Definition: resample.c:96
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
Support for dynamic strings.
Definition: strings.h:623
Test Framework API.
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128
#define AST_TEST_DEFINE(hdr)
Definition: test.h:126
ast_test_result_state
Definition: test.h:193
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_FAIL
Definition: test.h:196
@ AST_TEST_NOT_RUN
Definition: test.h:194
const char * args
Utility functions.