Module: kamailio Branch: master Commit: 388a12b455da982c590472741b1007ef42cc8b91 URL: https://github.com/kamailio/kamailio/commit/388a12b455da982c590472741b1007ef...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2023-04-14T22:55:50+02:00
math: added math_sqrt() function
---
Modified: src/modules/math/math_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/388a12b455da982c590472741b1007ef... Patch: https://github.com/kamailio/kamailio/commit/388a12b455da982c590472741b1007ef...
---
diff --git a/src/modules/math/math_mod.c b/src/modules/math/math_mod.c index ae73a7bbc42..2ac7a977893 100644 --- a/src/modules/math/math_mod.c +++ b/src/modules/math/math_mod.c @@ -39,6 +39,7 @@ static int w_math_pow(sip_msg_t *msg, char *v1, char *v2, char *r); static int w_math_logN(sip_msg_t *msg, char *v1, char *r); static int w_math_log2(sip_msg_t *msg, char *v1, char *r); static int w_math_log10(sip_msg_t *msg, char *v1, char *r); +static int w_math_sqrt(sip_msg_t *msg, char *v1, char *r); static int fixup_math_p2(void **param, int param_no); static int fixup_math_p3(void **param, int param_no);
@@ -53,6 +54,8 @@ static cmd_export_t cmds[]={ 0, ANY_ROUTE}, {"math_log10", (cmd_function)w_math_log10, 2, fixup_math_p2, 0, ANY_ROUTE}, + {"math_sqrt", (cmd_function)w_math_sqrt, 2, fixup_math_p2, + 0, ANY_ROUTE},
{0, 0, 0, 0, 0, 0} }; @@ -189,6 +192,34 @@ static int w_math_log10(sip_msg_t *msg, char *v1, char *r) return 1; }
+/** + * + */ +static int w_math_sqrt(sip_msg_t *msg, char *v1, char *r) +{ + int vi1 = 0; + pv_spec_t *dst; + pv_value_t val = {0}; + + if(fixup_get_ivalue(msg, (gparam_t*)v1, &vi1)<0) { + LM_ERR("failed to get first parameter value\n"); + return -1; + } + + dst = (pv_spec_t *)r; + if(dst->setf==NULL) { + LM_ERR("target pv is not writable\n"); + return -1; + } + + val.ri = (long)sqrt((double)vi1); + val.flags = PV_TYPE_INT|PV_VAL_INT; + + dst->setf(msg, &dst->pvp, (int)EQ_T, &val); + + return 1; +} + /** * */