Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
func_math.c File Reference

Math related dialplan function. More...

#include "asterisk.h"
#include <math.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/conversions.h"
#include "asterisk/app.h"
#include "asterisk/config.h"
#include "asterisk/test.h"
Include dependency graph for func_math.c:

Go to the source code of this file.

Enumerations

enum  TypeOfFunctions {
  ADDFUNCTION , DIVIDEFUNCTION , MULTIPLYFUNCTION , SUBTRACTFUNCTION ,
  MODULUSFUNCTION , POWFUNCTION , SHLEFTFUNCTION , SHRIGHTFUNCTION ,
  BITWISEANDFUNCTION , BITWISEXORFUNCTION , BITWISEORFUNCTION , GTFUNCTION ,
  LTFUNCTION , GTEFUNCTION , LTEFUNCTION , EQFUNCTION
}
 
enum  TypeOfResult { FLOAT_RESULT , INT_RESULT , HEX_RESULT , CHAR_RESULT }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int acf_abs_exec (struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
 
static int acf_digit_sum_exec (struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
 
static int acf_max_exec (struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
 
static int acf_min_exec (struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int crement_function_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int load_module (void)
 
static int math (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Mathematical dialplan function" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static struct ast_custom_function acf_abs
 
static struct ast_custom_function acf_digit_sum
 
static struct ast_custom_function acf_max
 
static struct ast_custom_function acf_min
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function decrement_function
 
static struct ast_custom_function increment_function
 
static struct ast_custom_function math_function
 

Detailed Description

Math related dialplan function.

Author
Andy Powell
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Nir Simionovich nirs@.nosp@m.gree.nosp@m.nfiel.nosp@m.dtec.nosp@m.h.net
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org

Definition in file func_math.c.

Enumeration Type Documentation

◆ TypeOfFunctions

Enumerator
ADDFUNCTION 
DIVIDEFUNCTION 
MULTIPLYFUNCTION 
SUBTRACTFUNCTION 
MODULUSFUNCTION 
POWFUNCTION 
SHLEFTFUNCTION 
SHRIGHTFUNCTION 
BITWISEANDFUNCTION 
BITWISEXORFUNCTION 
BITWISEORFUNCTION 
GTFUNCTION 
LTFUNCTION 
GTEFUNCTION 
LTEFUNCTION 
EQFUNCTION 

Definition at line 204 of file func_math.c.

204 {
221};
@ EQFUNCTION
Definition func_math.c:220
@ BITWISEORFUNCTION
Definition func_math.c:215
@ BITWISEANDFUNCTION
Definition func_math.c:213
@ LTEFUNCTION
Definition func_math.c:219
@ SHRIGHTFUNCTION
Definition func_math.c:212
@ POWFUNCTION
Definition func_math.c:210
@ MODULUSFUNCTION
Definition func_math.c:209
@ ADDFUNCTION
Definition func_math.c:205
@ SHLEFTFUNCTION
Definition func_math.c:211
@ GTEFUNCTION
Definition func_math.c:218
@ BITWISEXORFUNCTION
Definition func_math.c:214
@ DIVIDEFUNCTION
Definition func_math.c:206
@ MULTIPLYFUNCTION
Definition func_math.c:207
@ GTFUNCTION
Definition func_math.c:216
@ LTFUNCTION
Definition func_math.c:217
@ SUBTRACTFUNCTION
Definition func_math.c:208

◆ TypeOfResult

Enumerator
FLOAT_RESULT 
INT_RESULT 
HEX_RESULT 
CHAR_RESULT 

Definition at line 223 of file func_math.c.

223 {
228};
@ CHAR_RESULT
Definition func_math.c:227
@ INT_RESULT
Definition func_math.c:225
@ FLOAT_RESULT
Definition func_math.c:224
@ HEX_RESULT
Definition func_math.c:226

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 801 of file func_math.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 801 of file func_math.c.

◆ acf_abs_exec()

static int acf_abs_exec ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buffer,
size_t  buflen 
)
static

Definition at line 633 of file func_math.c.

635{
636 double num1, response_num;
638 AST_APP_ARG(num1);
639 );
640
642
643 if (ast_strlen_zero(args.num1) || sscanf(args.num1, "%30lf", &num1) != 1) {
644 ast_log(LOG_WARNING, "Bad or missing argument for number: %s", args.num1);
645 return -1;
646 }
647
648 response_num = fabs(num1);
649 ast_debug(1, "%f is the absolute value of %f\n", response_num, num1);
650 if ((int) response_num == response_num) {
651 snprintf(buffer, buflen, "%d", (int) response_num);
652 } else {
653 snprintf(buffer, buflen, "%f", response_num);
654 }
655
656 return 0;
657}
#define ast_log
Definition astobj2.c:42
#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.
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_WARNING
static struct @519 args
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65

References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strlen_zero(), and LOG_WARNING.

◆ acf_digit_sum_exec()

static int acf_digit_sum_exec ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buffer,
size_t  buflen 
)
static

Definition at line 659 of file func_math.c.

661{
662 int sum = 0;
663
664 if (ast_strlen_zero(parse)) {
665 ast_log(LOG_WARNING, "Missing argument for number\n");
666 return -1;
667 }
668
669 for (; *parse; parse++) {
670 if (*parse < '0' || *parse > '9') {
671 continue;
672 }
673 sum += (*parse - '0');
674 }
675
676 snprintf(buffer, buflen, "%d", sum);
677 return 0;
678}

References ast_log, ast_strlen_zero(), and LOG_WARNING.

◆ acf_max_exec()

static int acf_max_exec ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buffer,
size_t  buflen 
)
static

Definition at line 587 of file func_math.c.

589{
590 double num1, num2, response_num = 0;
592 AST_APP_ARG(num1);
593 AST_APP_ARG(num2);
594 );
595
597
598 if (ast_strlen_zero(args.num1) && ast_strlen_zero(args.num2)) {
599 ast_log(LOG_ERROR, "Missing argument for number(s).");
600 return -1;
601 }
602
603 if (ast_strlen_zero(args.num1)) {
604 response_num = -1; /* couldn't read num1 successfully */
605 } else if (sscanf(args.num1, "%30lf", &num1) != 1) {
606 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num1);
607 return -1;
608 }
609
610 if (ast_strlen_zero(args.num2)) {
611 num2 = num1; /* num1 must be a valid integer here */
612 } else if (sscanf(args.num2, "%30lf", &num2) != 1) {
613 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num2);
614 return -1;
615 }
616
617 if (response_num == -1) { /* could only read num2 */
618 response_num = num2;
619 } else {
620 response_num = (num1 < num2) ? num2 : num1;
621 }
622
623 ast_debug(1, "%f is the maximum of [%f,%f]\n", response_num, num1, num2);
624 if ((int) response_num == response_num) {
625 snprintf(buffer, buflen, "%d", (int) response_num);
626 } else {
627 snprintf(buffer, buflen, "%f", response_num);
628 }
629
630 return 0;
631}
#define LOG_ERROR

References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.

◆ acf_min_exec()

static int acf_min_exec ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buffer,
size_t  buflen 
)
static

Definition at line 541 of file func_math.c.

543{
544 double num1, num2, response_num = 0;
546 AST_APP_ARG(num1);
547 AST_APP_ARG(num2);
548 );
549
551
552 if (ast_strlen_zero(args.num1) && ast_strlen_zero(args.num2)) {
553 ast_log(LOG_ERROR, "Missing argument for number(s).");
554 return -1;
555 }
556
557 if (ast_strlen_zero(args.num1)) {
558 response_num = -1; /* couldn't read num1 successfully */
559 } else if (sscanf(args.num1, "%30lf", &num1) != 1) {
560 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num1);
561 return -1;
562 }
563
564 if (ast_strlen_zero(args.num2)) {
565 num2 = num1; /* num1 must be a valid integer here */
566 } else if (sscanf(args.num2, "%30lf", &num2) != 1) {
567 ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num2);
568 return -1;
569 }
570
571 if (response_num == -1) { /* could only read num2 */
572 response_num = num2;
573 } else {
574 response_num = (num1 > num2) ? num2 : num1;
575 }
576
577 ast_debug(1, "%f is the minimum of [%f,%f]\n", response_num, num1, num2);
578 if ((int) response_num == response_num) {
579 snprintf(buffer, buflen, "%d", (int) response_num);
580 } else {
581 snprintf(buffer, buflen, "%f", response_num);
582 }
583
584 return 0;
585}

References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 801 of file func_math.c.

◆ crement_function_read()

static int crement_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 473 of file func_math.c.

475{
476 int ret = -1;
477 int int_value = 0;
478 int modify_orig = 0;
479 const char *var;
480 char endchar = 0, returnvar[12]; /* If you need a variable longer than 11 digits - something is way wrong */
481
482 if (ast_strlen_zero(data)) {
483 ast_log(LOG_WARNING, "Syntax: %s(<data>) - missing argument!\n", cmd);
484 return -1;
485 }
486
487 if (!chan) {
488 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
489 return -1;
490 }
491
492 ast_channel_lock(chan);
493
494 if (!(var = pbx_builtin_getvar_helper(chan, data))) {
495 ast_log(LOG_NOTICE, "Failed to obtain variable %s, bailing out\n", data);
496 ast_channel_unlock(chan);
497 return -1;
498 }
499
500 if (ast_strlen_zero(var)) {
501 ast_log(LOG_NOTICE, "Variable %s doesn't exist - are you sure you wrote it correctly?\n", data);
502 ast_channel_unlock(chan);
503 return -1;
504 }
505
506 if (sscanf(var, "%30d%1c", &int_value, &endchar) == 0 || endchar != 0) {
507 ast_log(LOG_NOTICE, "The content of ${%s} is not a numeric value - bailing out!\n", data);
508 ast_channel_unlock(chan);
509 return -1;
510 }
511
512 /* now we'll actually do something useful */
513 if (!strcasecmp(cmd, "INC")) { /* Increment variable */
514 int_value++;
515 modify_orig = 1;
516 } else if (!strcasecmp(cmd, "DEC")) { /* Decrement variable */
517 int_value--;
518 modify_orig = 1;
519 }
520
521 if (snprintf(returnvar, sizeof(returnvar), "%d", int_value) > 0) {
522 pbx_builtin_setvar_helper(chan, data, returnvar);
523 if (modify_orig) {
524 ast_copy_string(buf, returnvar, len);
525 }
526 ret = 0;
527 } else {
528 pbx_builtin_setvar_helper(chan, data, "0");
529 if (modify_orig) {
530 ast_copy_string(buf, "0", len);
531 }
532 ast_log(LOG_NOTICE, "Variable %s refused to be %sREMENTED, setting value to 0", data, cmd);
533 ret = 0;
534 }
535
536 ast_channel_unlock(chan);
537
538 return ret;
539}
#define var
Definition ast_expr2f.c:605
#define ast_channel_lock(chan)
Definition channel.h:2982
#define ast_channel_unlock(chan)
Definition channel.h:2983
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_NOTICE
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
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.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425

References ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_log, ast_strlen_zero(), buf, len(), LOG_NOTICE, LOG_WARNING, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and var.

◆ load_module()

static int load_module ( void  )
static

Definition at line 785 of file func_math.c.

786{
787 int res = 0;
788
796 AST_TEST_REGISTER(test_MATH_function);
797
798 return res;
799}
static struct ast_custom_function increment_function
Definition func_math.c:685
static struct ast_custom_function math_function
Definition func_math.c:680
static struct ast_custom_function decrement_function
Definition func_math.c:690
static struct ast_custom_function acf_min
Definition func_math.c:695
static struct ast_custom_function acf_abs
Definition func_math.c:707
static struct ast_custom_function acf_max
Definition func_math.c:701
static struct ast_custom_function acf_digit_sum
Definition func_math.c:713
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562
#define AST_TEST_REGISTER(cb)
Definition test.h:127

References acf_abs, acf_digit_sum, acf_max, acf_min, ast_custom_function_register, AST_TEST_REGISTER, decrement_function, increment_function, and math_function.

◆ math()

static int math ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
)
static

Definition at line 230 of file func_math.c.

232{
233 double fnum1;
234 double fnum2;
235 double ftmp = 0;
236 char *op;
237 int iaction = -1;
238 int type_of_result = FLOAT_RESULT;
239 char *mvalue1, *mvalue2 = NULL, *mtype_of_result;
240 int negvalue1 = 0;
242 AST_APP_ARG(argv0);
243 AST_APP_ARG(argv1);
244 );
245
246 if (ast_strlen_zero(parse)) {
247 ast_log(LOG_WARNING, "Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
248 return -1;
249 }
250
252
253 if (args.argc < 1) {
254 ast_log(LOG_WARNING, "Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
255 return -1;
256 }
257
258 mvalue1 = args.argv0;
259
260 if (mvalue1[0] == '-') {
261 negvalue1 = 1;
262 mvalue1++;
263 }
264
265 if ((op = strchr(mvalue1, '*'))) {
266 iaction = MULTIPLYFUNCTION;
267 *op = '\0';
268 } else if ((op = strchr(mvalue1, '/'))) {
269 iaction = DIVIDEFUNCTION;
270 *op = '\0';
271 } else if ((op = strchr(mvalue1, '%'))) {
272 iaction = MODULUSFUNCTION;
273 *op = '\0';
274 } else if ((op = strchr(mvalue1, '^'))) {
275 iaction = POWFUNCTION;
276 *op = '\0';
277 } else if ((op = strstr(mvalue1, "AND"))) {
278 iaction = BITWISEANDFUNCTION;
279 *op = '\0';
280 op += 2;
281 } else if ((op = strstr(mvalue1, "XOR"))) {
282 iaction = BITWISEXORFUNCTION;
283 *op = '\0';
284 op += 2;
285 } else if ((op = strstr(mvalue1, "OR"))) {
286 iaction = BITWISEORFUNCTION;
287 *op = '\0';
288 ++op;
289 } else if ((op = strchr(mvalue1, '>'))) {
290 iaction = GTFUNCTION;
291 *op = '\0';
292 if (*(op + 1) == '=') {
293 iaction = GTEFUNCTION;
294 ++op;
295 } else if (*(op + 1) == '>') {
296 iaction = SHRIGHTFUNCTION;
297 ++op;
298 }
299 } else if ((op = strchr(mvalue1, '<'))) {
300 iaction = LTFUNCTION;
301 *op = '\0';
302 if (*(op + 1) == '=') {
303 iaction = LTEFUNCTION;
304 ++op;
305 } else if (*(op + 1) == '<') {
306 iaction = SHLEFTFUNCTION;
307 ++op;
308 }
309 } else if ((op = strchr(mvalue1, '='))) {
310 *op = '\0';
311 if (*(op + 1) == '=') {
312 iaction = EQFUNCTION;
313 ++op;
314 } else
315 op = NULL;
316 } else if ((op = strchr(mvalue1, '+'))) {
317 iaction = ADDFUNCTION;
318 *op = '\0';
319 } else if ((op = strchr(mvalue1, '-'))) { /* subtraction MUST always be last, in case we have a negative second number */
320 iaction = SUBTRACTFUNCTION;
321 *op = '\0';
322 }
323
324 if (op)
325 mvalue2 = op + 1;
326
327 /* detect wanted type of result */
328 mtype_of_result = args.argv1;
329 if (mtype_of_result) {
330 if (!strcasecmp(mtype_of_result, "float")
331 || !strcasecmp(mtype_of_result, "f"))
332 type_of_result = FLOAT_RESULT;
333 else if (!strcasecmp(mtype_of_result, "int")
334 || !strcasecmp(mtype_of_result, "i"))
335 type_of_result = INT_RESULT;
336 else if (!strcasecmp(mtype_of_result, "hex")
337 || !strcasecmp(mtype_of_result, "h"))
338 type_of_result = HEX_RESULT;
339 else if (!strcasecmp(mtype_of_result, "char")
340 || !strcasecmp(mtype_of_result, "c"))
341 type_of_result = CHAR_RESULT;
342 else {
343 ast_log(LOG_WARNING, "Unknown type of result requested '%s'.\n",
344 mtype_of_result);
345 return -1;
346 }
347 }
348
349 if (!mvalue2) {
351 "Supply all the parameters - just this once, please\n");
352 return -1;
353 }
354
355 if (sscanf(mvalue1, "%30lf", &fnum1) != 1) {
356 ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue1);
357 return -1;
358 }
359
360 if (sscanf(mvalue2, "%30lf", &fnum2) != 1) {
361 ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue2);
362 return -1;
363 }
364
365 if (negvalue1)
366 fnum1 = 0 - fnum1;
367
368 switch (iaction) {
369 case ADDFUNCTION:
370 ftmp = fnum1 + fnum2;
371 break;
372 case DIVIDEFUNCTION:
373 if (fnum2 <= 0)
374 ftmp = 0; /* can't do a divide by 0 */
375 else
376 ftmp = (fnum1 / fnum2);
377 break;
378 case MULTIPLYFUNCTION:
379 ftmp = (fnum1 * fnum2);
380 break;
381 case SUBTRACTFUNCTION:
382 ftmp = (fnum1 - fnum2);
383 break;
384 case MODULUSFUNCTION:
385 {
386 int inum1 = fnum1;
387 int inum2 = fnum2;
388
389 if (inum2 == 0) {
390 ftmp = 0;
391 } else {
392 ftmp = (inum1 % inum2);
393 }
394
395 break;
396 }
397 case POWFUNCTION:
398 ftmp = pow(fnum1, fnum2);
399 break;
400 case SHLEFTFUNCTION:
401 {
402 int inum1 = fnum1;
403 int inum2 = fnum2;
404
405 ftmp = (inum1 << inum2);
406 break;
407 }
408 case SHRIGHTFUNCTION:
409 {
410 int inum1 = fnum1;
411 int inum2 = fnum2;
412
413 ftmp = (inum1 >> inum2);
414 break;
415 }
417 {
418 int inum1 = fnum1;
419 int inum2 = fnum2;
420 ftmp = (inum1 & inum2);
421 break;
422 }
424 {
425 int inum1 = fnum1;
426 int inum2 = fnum2;
427 ftmp = (inum1 ^ inum2);
428 break;
429 }
431 {
432 int inum1 = fnum1;
433 int inum2 = fnum2;
434 ftmp = (inum1 | inum2);
435 break;
436 }
437 case GTFUNCTION:
438 ast_copy_string(buf, (fnum1 > fnum2) ? "TRUE" : "FALSE", len);
439 break;
440 case LTFUNCTION:
441 ast_copy_string(buf, (fnum1 < fnum2) ? "TRUE" : "FALSE", len);
442 break;
443 case GTEFUNCTION:
444 ast_copy_string(buf, (fnum1 >= fnum2) ? "TRUE" : "FALSE", len);
445 break;
446 case LTEFUNCTION:
447 ast_copy_string(buf, (fnum1 <= fnum2) ? "TRUE" : "FALSE", len);
448 break;
449 case EQFUNCTION:
450 ast_copy_string(buf, (fnum1 == fnum2) ? "TRUE" : "FALSE", len);
451 break;
452 default:
454 "Something happened that neither of us should be proud of %d\n",
455 iaction);
456 return -1;
457 }
458
459 if (iaction < GTFUNCTION || iaction > EQFUNCTION) {
460 if (type_of_result == FLOAT_RESULT)
461 snprintf(buf, len, "%f", ftmp);
462 else if (type_of_result == INT_RESULT)
463 snprintf(buf, len, "%i", (int) ftmp);
464 else if (type_of_result == HEX_RESULT)
465 snprintf(buf, len, "%x", (unsigned int) ftmp);
466 else if (type_of_result == CHAR_RESULT)
467 snprintf(buf, len, "%c", (unsigned char) ftmp);
468 }
469
470 return 0;
471}
#define NULL
Definition resample.c:96

References ADDFUNCTION, args, AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strlen_zero(), BITWISEANDFUNCTION, BITWISEORFUNCTION, BITWISEXORFUNCTION, buf, CHAR_RESULT, DIVIDEFUNCTION, EQFUNCTION, FLOAT_RESULT, GTEFUNCTION, GTFUNCTION, HEX_RESULT, INT_RESULT, len(), LOG_WARNING, LTEFUNCTION, LTFUNCTION, MODULUSFUNCTION, MULTIPLYFUNCTION, NULL, POWFUNCTION, SHLEFTFUNCTION, SHRIGHTFUNCTION, and SUBTRACTFUNCTION.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 769 of file func_math.c.

770{
771 int res = 0;
772
780 AST_TEST_UNREGISTER(test_MATH_function);
781
782 return res;
783}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
#define AST_TEST_UNREGISTER(cb)
Definition test.h:128

References acf_abs, acf_digit_sum, acf_max, acf_min, ast_custom_function_unregister(), AST_TEST_UNREGISTER, decrement_function, increment_function, and math_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Mathematical dialplan function" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 801 of file func_math.c.

◆ acf_abs

struct ast_custom_function acf_abs
static
Initial value:
= {
.name = "ABS",
.read = acf_abs_exec,
.read_max = 12,
}
static int acf_abs_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition func_math.c:633

Definition at line 707 of file func_math.c.

707 {
708 .name = "ABS",
709 .read = acf_abs_exec,
710 .read_max = 12,
711};

Referenced by load_module(), and unload_module().

◆ acf_digit_sum

struct ast_custom_function acf_digit_sum
static
Initial value:
= {
.name = "DIGIT_SUM",
}
static int acf_digit_sum_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition func_math.c:659

Definition at line 713 of file func_math.c.

713 {
714 .name = "DIGIT_SUM",
715 .read = acf_digit_sum_exec,
716};

Referenced by load_module(), and unload_module().

◆ acf_max

struct ast_custom_function acf_max
static
Initial value:
= {
.name = "MAX",
.read = acf_max_exec,
.read_max = 12,
}
static int acf_max_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition func_math.c:587

Definition at line 701 of file func_math.c.

701 {
702 .name = "MAX",
703 .read = acf_max_exec,
704 .read_max = 12,
705};

Referenced by load_module(), and unload_module().

◆ acf_min

struct ast_custom_function acf_min
static
Initial value:
= {
.name = "MIN",
.read = acf_min_exec,
.read_max = 12,
}
static int acf_min_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition func_math.c:541

Definition at line 695 of file func_math.c.

695 {
696 .name = "MIN",
697 .read = acf_min_exec,
698 .read_max = 12,
699};

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 801 of file func_math.c.

◆ decrement_function

struct ast_custom_function decrement_function
static
Initial value:
= {
.name = "DEC",
}
static int crement_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition func_math.c:473

Definition at line 690 of file func_math.c.

690 {
691 .name = "DEC",
692 .read = crement_function_read,
693};

Referenced by load_module(), and unload_module().

◆ increment_function

struct ast_custom_function increment_function
static
Initial value:
= {
.name = "INC",
}

Definition at line 685 of file func_math.c.

685 {
686 .name = "INC",
687 .read = crement_function_read,
688};

Referenced by load_module(), and unload_module().

◆ math_function

struct ast_custom_function math_function
static
Initial value:
= {
.name = "MATH",
.read = math
}
static int math(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition func_math.c:230

Definition at line 680 of file func_math.c.

680 {
681 .name = "MATH",
682 .read = math
683};

Referenced by load_module(), and unload_module().