Module: kamailio
Branch: master
Commit: 5bc7bd99305b1341c6d0a6a4d2d3138432b14819
URL:
https://github.com/kamailio/kamailio/commit/5bc7bd99305b1341c6d0a6a4d2d3138…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-02-27T10:07:42+01:00
pv: exported functions for $var(...) management
---
Modified: src/modules/pv/pv.c
Modified: src/modules/pv/pv_svar.c
Modified: src/modules/pv/pv_svar.h
---
Diff:
https://github.com/kamailio/kamailio/commit/5bc7bd99305b1341c6d0a6a4d2d3138…
Patch:
https://github.com/kamailio/kamailio/commit/5bc7bd99305b1341c6d0a6a4d2d3138…
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 78f7398b0b..a233a684cf 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -1811,6 +1811,21 @@ static sr_kemi_t sr_kemi_pvx_exports[] = {
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("pvx"), str_init("var_seti"),
+ SR_KEMIP_INT, ki_var_seti,
+ { SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("pvx"), str_init("var_sets"),
+ SR_KEMIP_INT, ki_var_sets,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("pvx"), str_init("var_get"),
+ SR_KEMIP_XVAL, ki_var_get,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ str_init("pvx"), str_init("shv_seti"),
SR_KEMIP_INT, ki_shv_seti,
{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
diff --git a/src/modules/pv/pv_svar.c b/src/modules/pv/pv_svar.c
index 1245cef7f5..255f9f2040 100644
--- a/src/modules/pv/pv_svar.c
+++ b/src/modules/pv/pv_svar.c
@@ -239,3 +239,84 @@ void destroy_vars(void)
destroy_vars_list(script_vars);
destroy_vars_list(script_vars_null);
}
+
+/**
+ *
+ */
+int ki_var_seti(sip_msg_t *msg, str *vname, int ival)
+{
+ int_str isv;
+ script_var_t *var = NULL;
+
+ var = add_var(vname, VAR_TYPE_ZERO);
+
+ if(var==NULL) {
+ LM_ERR("$var(%.*s) is not defined\n", vname->len, vname->s);
+ return -1;
+ }
+
+ isv.n = ival;
+ if(set_var_value(var, &isv, 0)==NULL) {
+ LM_ERR("error - cannot set $var(%.*s) to ival\n", vname->len,
vname->s);
+ return -1;
+ }
+
+ return 1;
+}
+
+/**
+ *
+ */
+int ki_var_sets(sip_msg_t *msg, str *vname, str *sval)
+{
+ int_str isv;
+ script_var_t *var = NULL;
+
+ var = add_var(vname, VAR_TYPE_ZERO);
+
+ if(var==NULL) {
+ LM_ERR("$var(%.*s) is not defined\n", vname->len, vname->s);
+ return -1;
+ }
+
+ isv.s = *sval;
+ if(set_var_value(var, &isv, VAR_VAL_STR)==NULL) {
+ LM_ERR("error - cannot set $var(%.*s) to sval\n", vname->len,
vname->s);
+ return -1;
+ }
+ return 1;
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t _sr_kemi_var_xval = {0};
+
+/**
+ *
+ */
+sr_kemi_xval_t* ki_var_get(sip_msg_t *msg, str *vname)
+{
+ script_var_t *var = NULL;
+
+ memset(&_sr_kemi_var_xval, 0, sizeof(sr_kemi_xval_t));
+
+ var = get_var_by_name(vname);
+ if(var==NULL) {
+ LM_WARN("$var(%.*s) is not defined - return value 0\n",
+ vname->len, vname->s);
+ _sr_kemi_var_xval.vtype = SR_KEMIP_INT;
+ _sr_kemi_var_xval.v.n = 0;
+ return &_sr_kemi_var_xval;
+ }
+
+ if(var->v.flags&VAR_VAL_STR) {
+ _sr_kemi_var_xval.vtype = SR_KEMIP_STR;
+ _sr_kemi_var_xval.v.s = var->v.value.s;
+ return &_sr_kemi_var_xval;
+ } else {
+ _sr_kemi_var_xval.v.n = var->v.value.n;
+ _sr_kemi_var_xval.vtype = SR_KEMIP_INT;
+ return &_sr_kemi_var_xval;
+ }
+}
diff --git a/src/modules/pv/pv_svar.h b/src/modules/pv/pv_svar.h
index 9e2e9d6e8d..b9f78ab749 100644
--- a/src/modules/pv/pv_svar.h
+++ b/src/modules/pv/pv_svar.h
@@ -27,6 +27,7 @@
#ifndef _PV_SVAR_H_
#define _PV_SVAR_H_
+#include "../../core/kemi.h"
#include "../../core/usr_avp.h"
#define VAR_VAL_INT (0) /* value is INT (other flags not set) */
@@ -57,5 +58,9 @@ void reset_vars(void);
void destroy_vars(void);
void destroy_vars_list(script_var_t *svl);
+int ki_var_seti(sip_msg_t *msg, str *vname, int ival);
+int ki_var_sets(sip_msg_t *msg, str *vname, str *sval);
+sr_kemi_xval_t* ki_var_get(sip_msg_t *msg, str *vname);
+
#endif