Browse code

dialog: added kemi functions to get/set dialog vars

Daniel-Constantin Mierla authored on 10/06/2019 07:45:01
Showing 1 changed files
... ...
@@ -1857,6 +1857,65 @@ static int w_dlg_db_load_extra(sip_msg_t *msg, char *p1, char *p2)
1857 1857
 /**
1858 1858
  *
1859 1859
  */
1860
+static int ki_dlg_var_sets(sip_msg_t *msg, str *name, str *val)
1861
+{
1862
+	dlg_cell_t *dlg;
1863
+	int ret;
1864
+
1865
+	dlg = dlg_get_msg_dialog(msg);
1866
+	ret = set_dlg_variable_unsafe(dlg, name, val);
1867
+	if(dlg) {
1868
+		dlg_release(dlg);
1869
+	}
1870
+
1871
+	return (ret==0)?1:ret;
1872
+}
1873
+
1874
+/**
1875
+ *
1876
+ */
1877
+static sr_kemi_xval_t _sr_kemi_dialog_xval = {0};
1878
+
1879
+/**
1880
+ *
1881
+ */
1882
+static sr_kemi_xval_t* ki_dlg_var_get_mode(sip_msg_t *msg, str *name, int rmode)
1883
+{
1884
+	dlg_cell_t *dlg;
1885
+	str *pval;
1886
+
1887
+	memset(&_sr_kemi_dialog_xval, 0, sizeof(sr_kemi_xval_t));
1888
+
1889
+	dlg = dlg_get_msg_dialog(msg);
1890
+	if(dlg==NULL) {
1891
+		sr_kemi_xval_null(&_sr_kemi_dialog_xval, rmode);
1892
+		return &_sr_kemi_dialog_xval;
1893
+	}
1894
+	pval = get_dlg_variable(dlg, name);
1895
+	if(pval==NULL || pval->s==NULL) {
1896
+		sr_kemi_xval_null(&_sr_kemi_dialog_xval, rmode);
1897
+		goto done;
1898
+	}
1899
+
1900
+	_sr_kemi_dialog_xval.vtype = SR_KEMIP_STR;
1901
+	_sr_kemi_dialog_xval.v.s = *pval;
1902
+
1903
+done:
1904
+	dlg_release(dlg);
1905
+	return &_sr_kemi_dialog_xval;
1906
+}
1907
+
1908
+/**
1909
+ *
1910
+ */
1911
+static sr_kemi_xval_t* ki_dlg_var_get(sip_msg_t *msg, str *name)
1912
+{
1913
+	return ki_dlg_var_get_mode(msg, name, SR_KEMI_XVAL_NULL_NONE);
1914
+}
1915
+
1916
+/**
1917
+ *
1918
+ */
1860 1919
 /* clang-format off */
1861 1920
 static sr_kemi_t sr_kemi_dialog_exports[] = {
1862 1921
 	{ str_init("dialog"), str_init("dlg_manage"),
... ...
@@ -1959,6 +2018,16 @@ static sr_kemi_t sr_kemi_dialog_exports[] = {
1959 1959
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1960 1960
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1961 1961
 	},
1962
+	{ str_init("dialog"), str_init("var_sets"),
1963
+		SR_KEMIP_INT, ki_dlg_var_sets,
1964
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
1965
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1966
+	},
1967
+	{ str_init("dialog"), str_init("var_get"),
1968
+		SR_KEMIP_XVAL, ki_dlg_var_get,
1969
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1970
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1971
+	},
1962 1972
 
1963 1973
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1964 1974
 };