Module: kamailio
Branch: master
Commit: cb97be77664625a4fb454bdd6d5c84c8a2c7adb3
URL:
https://github.com/kamailio/kamailio/commit/cb97be77664625a4fb454bdd6d5c84c…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-05-19T19:33:56+02:00
app_sqlang: added KSR.pv.getw(...)
---
Modified: src/modules/app_sqlang/app_sqlang_api.c
---
Diff:
https://github.com/kamailio/kamailio/commit/cb97be77664625a4fb454bdd6d5c84c…
Patch:
https://github.com/kamailio/kamailio/commit/cb97be77664625a4fb454bdd6d5c84c…
---
diff --git a/src/modules/app_sqlang/app_sqlang_api.c
b/src/modules/app_sqlang/app_sqlang_api.c
index 624e13908f..77d98ddc3d 100644
--- a/src/modules/app_sqlang/app_sqlang_api.c
+++ b/src/modules/app_sqlang/app_sqlang_api.c
@@ -275,7 +275,20 @@ static int sqlang_gettype(HSQUIRRELVM J, int idx)
/**
*
*/
-static SQInteger sqlang_sr_pv_get(HSQUIRRELVM J)
+static SQInteger sqlang_sr_get_str_null(HSQUIRRELVM J, int rmode)
+{
+ if(rmode) {
+ sqlang_pushlstring(J, "<<null>>", 8);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ *
+ */
+static SQInteger sqlang_sr_pv_get_mode(HSQUIRRELVM J, int rmode)
{
str pvn;
pv_spec_t *pvs;
@@ -287,24 +300,24 @@ static SQInteger sqlang_sr_pv_get(HSQUIRRELVM J)
pvn.s = (char*)sqlang_to_string(J, 0);
if(pvn.s==NULL || env_J->msg==NULL)
- return 0;
+ return sqlang_sr_get_str_null(J, rmode);
pvn.len = strlen(pvn.s);
LM_DBG("pv get: %s\n", pvn.s);
pl = pv_locate_name(&pvn);
if(pl != pvn.len) {
LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
- return 0;
+ return sqlang_sr_get_str_null(J, rmode);
}
pvs = pv_cache_get(&pvn);
if(pvs==NULL) {
LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
- return 0;
+ return sqlang_sr_get_str_null(J, rmode);
}
memset(&val, 0, sizeof(pv_value_t));
if(pv_get_spec_value(env_J->msg, pvs, &val) != 0) {
LM_ERR("unable to get pv value for [%s]\n", pvn.s);
- return 0;
+ return sqlang_sr_get_str_null(J, rmode);
}
if(val.flags&PV_VAL_NULL) {
sqlang_pushstring(J, NULL);
@@ -318,6 +331,22 @@ static SQInteger sqlang_sr_pv_get(HSQUIRRELVM J)
return 1;
}
+/**
+ *
+ */
+static SQInteger sqlang_sr_pv_get(HSQUIRRELVM J)
+{
+ return sqlang_sr_pv_get_mode(J, 0);
+}
+
+/**
+ *
+ */
+static SQInteger sqlang_sr_pv_getw(HSQUIRRELVM J)
+{
+ return sqlang_sr_pv_get_mode(J, 1);
+}
+
/**
*
*/
@@ -508,6 +537,7 @@ static SQInteger sqlang_sr_pv_is_null (HSQUIRRELVM J)
const SQRegFunction _sr_kemi_pv_J_Map[] = {
{ "get", sqlang_sr_pv_get, 2 /* 1 args */, NULL },
+ { "getw", sqlang_sr_pv_getw, 2 /* 1 args */, NULL },
{ "seti", sqlang_sr_pv_seti, 3 /* 2 args */, NULL },
{ "sets", sqlang_sr_pv_sets, 4 /* 2 args */, NULL },
{ "unset", sqlang_sr_pv_unset, 2 /* 1 args */, NULL },