[sr-dev] git:master:7d8ee6fc: dialog: added kemi functions to get/set dialog vars

Daniel-Constantin Mierla miconda at gmail.com
Tue Jun 11 12:11:42 CEST 2019


Module: kamailio
Branch: master
Commit: 7d8ee6fc4860b77bd7c9920ea6db6fb2e44bd2b5
URL: https://github.com/kamailio/kamailio/commit/7d8ee6fc4860b77bd7c9920ea6db6fb2e44bd2b5

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-06-11T09:45:01+02:00

dialog: added kemi functions to get/set dialog vars

---

Modified: src/modules/dialog/dialog.c

---

Diff:  https://github.com/kamailio/kamailio/commit/7d8ee6fc4860b77bd7c9920ea6db6fb2e44bd2b5.diff
Patch: https://github.com/kamailio/kamailio/commit/7d8ee6fc4860b77bd7c9920ea6db6fb2e44bd2b5.patch

---

diff --git a/src/modules/dialog/dialog.c b/src/modules/dialog/dialog.c
index 497176a760..a28daae1c2 100644
--- a/src/modules/dialog/dialog.c
+++ b/src/modules/dialog/dialog.c
@@ -1854,6 +1854,65 @@ static int w_dlg_db_load_extra(sip_msg_t *msg, char *p1, char *p2)
 	return ki_dlg_db_load_extra(msg);
 }
 
+/**
+ *
+ */
+static int ki_dlg_var_sets(sip_msg_t *msg, str *name, str *val)
+{
+	dlg_cell_t *dlg;
+	int ret;
+
+	dlg = dlg_get_msg_dialog(msg);
+	ret = set_dlg_variable_unsafe(dlg, name, val);
+	if(dlg) {
+		dlg_release(dlg);
+	}
+
+	return (ret==0)?1:ret;
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t _sr_kemi_dialog_xval = {0};
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_dlg_var_get_mode(sip_msg_t *msg, str *name, int rmode)
+{
+	dlg_cell_t *dlg;
+	str *pval;
+
+	memset(&_sr_kemi_dialog_xval, 0, sizeof(sr_kemi_xval_t));
+
+	dlg = dlg_get_msg_dialog(msg);
+	if(dlg==NULL) {
+		sr_kemi_xval_null(&_sr_kemi_dialog_xval, rmode);
+		return &_sr_kemi_dialog_xval;
+	}
+	pval = get_dlg_variable(dlg, name);
+	if(pval==NULL || pval->s==NULL) {
+		sr_kemi_xval_null(&_sr_kemi_dialog_xval, rmode);
+		goto done;
+	}
+
+	_sr_kemi_dialog_xval.vtype = SR_KEMIP_STR;
+	_sr_kemi_dialog_xval.v.s = *pval;
+
+done:
+	dlg_release(dlg);
+	return &_sr_kemi_dialog_xval;
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_dlg_var_get(sip_msg_t *msg, str *name)
+{
+	return ki_dlg_var_get_mode(msg, name, SR_KEMI_XVAL_NULL_NONE);
+}
+
 /**
  *
  */
@@ -1959,6 +2018,16 @@ static sr_kemi_t sr_kemi_dialog_exports[] = {
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("dialog"), str_init("var_sets"),
+		SR_KEMIP_INT, ki_dlg_var_sets,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("dialog"), str_init("var_get"),
+		SR_KEMIP_XVAL, ki_dlg_var_get,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };




More information about the sr-dev mailing list