From: Daniel-Constantin Mierla <miconda@gmail.com>
Date: Fri, 20 May 2022 16:07:56 +0200
Subject: [PATCH] dialog: reworked kemi export for dlg_get_var()

- return SR_KEMIP_XVAL type
---
 src/modules/dialog/dialog.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/modules/dialog/dialog.c b/src/modules/dialog/dialog.c
index fec9f5e..623db59 100644
--- a/src/modules/dialog/dialog.c
+++ b/src/modules/dialog/dialog.c
@@ -1514,7 +1514,7 @@ static int fixup_dlg_bridge(void** param, int param_no)
 	return 0;
 }
 
-static str *ki_dlg_get_var(sip_msg_t *msg, str *sc, str *sf, str *st, str *key)
+static str *ki_dlg_get_var_helper(sip_msg_t *msg, str *sc, str *sf, str *st, str *key)
 {
 	dlg_cell_t *dlg = NULL;
 	unsigned int dir = 0;
@@ -1541,6 +1541,30 @@ static str *ki_dlg_get_var(sip_msg_t *msg, str *sc, str *sf, str *st, str *key)
 	return val;
 }
 
+/**
+ *
+ */
+static sr_kemi_xval_t _sr_kemi_dialog_xval = {0};
+
+static sr_kemi_xval_t *ki_dlg_get_var(sip_msg_t *msg, str *sc, str *sf, str *st, str *key)
+{
+	str *val = NULL;
+
+	memset(&_sr_kemi_dialog_xval, 0, sizeof(sr_kemi_xval_t));
+
+	val = ki_dlg_get_var_helper(msg, &sc, &sf, &st, &k);
+	if(!val) {
+		sr_kemi_xval_null(&_sr_kemi_dialog_xval, SR_KEMI_XVAL_NULL_NONE);
+		return &_sr_kemi_dialog_xval;
+	}
+
+	_sr_kemi_dialog_xval.vtype = SR_KEMIP_STR;
+	_sr_kemi_dialog_xval.v.s = *pval;
+
+	return &_sr_kemi_dialog_xval;
+
+}
+
 static int w_dlg_get_var(struct sip_msg *msg, char *ci, char *ft, char *tt, char *key, char *pv)
 {
 	str sc = STR_NULL;
@@ -1585,7 +1609,7 @@ static int w_dlg_get_var(struct sip_msg *msg, char *ci, char *ft, char *tt, char
 		return -1;
 	}
 	dst_pv = (pv_spec_t *)pv;
-	val = ki_dlg_get_var(msg, &sc, &sf, &st, &k);
+	val = ki_dlg_get_var_helper(msg, &sc, &sf, &st, &k);
 	if(val) {
 		memset(&dst_val, 0, sizeof(pv_value_t));
 		dst_val.flags |= PV_VAL_STR;
@@ -2158,11 +2182,6 @@ static int ki_dlg_var_sets(sip_msg_t *msg, str *name, str *val)
 	return (ret==0)?1:ret;
 }
 
-/**
- *
- */
-static sr_kemi_xval_t _sr_kemi_dialog_xval = {0};
-
 /**
  *
  */
@@ -2292,7 +2311,7 @@ static sr_kemi_t sr_kemi_dialog_exports[] = {
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
 	{ str_init("dialog"), str_init("dlg_get_var"),
-		SR_KEMIP_STR, ki_dlg_get_var,
+		SR_KEMIP_XVAL, ki_dlg_get_var,
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
 			SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
