[sr-dev] git:master:3647cc1a: app_jsdt: implemented kemi KSR.pv.getw(...)

Daniel-Constantin Mierla miconda at gmail.com
Mon May 21 11:59:26 CEST 2018


Module: kamailio
Branch: master
Commit: 3647cc1a9b2e85e71657ba3dd3bba21c6bdc5ff5
URL: https://github.com/kamailio/kamailio/commit/3647cc1a9b2e85e71657ba3dd3bba21c6bdc5ff5

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-05-20T21:17:47+02:00

app_jsdt: implemented kemi KSR.pv.getw(...)

---

Modified: src/modules/app_jsdt/app_jsdt_api.c

---

Diff:  https://github.com/kamailio/kamailio/commit/3647cc1a9b2e85e71657ba3dd3bba21c6bdc5ff5.diff
Patch: https://github.com/kamailio/kamailio/commit/3647cc1a9b2e85e71657ba3dd3bba21c6bdc5ff5.patch

---

diff --git a/src/modules/app_jsdt/app_jsdt_api.c b/src/modules/app_jsdt/app_jsdt_api.c
index 8f4f3de18c..ef86d51165 100644
--- a/src/modules/app_jsdt/app_jsdt_api.c
+++ b/src/modules/app_jsdt/app_jsdt_api.c
@@ -155,11 +155,23 @@ int sr_kemi_jsdt_return_int(duk_context *J, sr_kemi_t *ket, int rc)
 	return app_jsdt_return_false(J);
 }
 
+/**
+ *
+ */
+static int jsdt_sr_return_none(duk_context *J, int rmode)
+{
+	if(rmode) {
+		duk_push_lstring(J, "<<null>>", 8);
+		return 1;
+	} else {
+		return 0;
+	}
+}
 
 /**
  *
  */
-static int jsdt_sr_pv_get(duk_context *J)
+static int jsdt_sr_pv_get_mode(duk_context *J, int rmode)
 {
 	str pvn;
 	pv_spec_t *pvs;
@@ -171,28 +183,32 @@ static int jsdt_sr_pv_get(duk_context *J)
 
 	pvn.s = (char*)duk_to_string(J, 0);
 	if(pvn.s==NULL || env_J->msg==NULL)
-		return 0;
+		return jsdt_sr_return_none(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 jsdt_sr_return_none(J, rmode);
 	}
 	pvs = pv_cache_get(&pvn);
 	if(pvs==NULL) {
 		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
-		return 0;
+		return jsdt_sr_return_none(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 jsdt_sr_return_none(J, rmode);
 	}
 	if(val.flags&PV_VAL_NULL) {
-		duk_push_string(J, NULL);
-		return 1;
+		if(rmode) {
+			jsdt_sr_return_none(J, rmode);
+		} else {
+			duk_push_string(J, NULL);
+			return 1;
+		}
 	}
 	if(val.flags&PV_TYPE_INT) {
 		duk_push_int(J, val.ri);
@@ -202,6 +218,22 @@ static int jsdt_sr_pv_get(duk_context *J)
 	return 1;
 }
 
+/**
+ *
+ */
+static int jsdt_sr_pv_get(duk_context *J)
+{
+	return jsdt_sr_pv_get_mode(J, 0);
+}
+
+/**
+ *
+ */
+static int jsdt_sr_pv_getw(duk_context *J)
+{
+	return jsdt_sr_pv_get_mode(J, 1);
+}
+
 /**
  *
  */




More information about the sr-dev mailing list