Browse code

dialog: api function to get the status if dlg var is set or not

Daniel-Constantin Mierla authored on 26/09/2022 10:30:06
Showing 3 changed files
... ...
@@ -63,6 +63,9 @@ typedef int (*get_dlg_varval_f)( struct dlg_cell* dlg,
63 63
 /* method to get a variable value pkg-allocated duplicate from a dialog */
64 64
 typedef int (*get_dlg_vardup_f)( struct dlg_cell* dlg,
65 65
                                     str* key, str* val);
66
+/* method to get if a variable value is set or not from a dialog */
67
+typedef int (*get_dlg_varstatus_f)( struct dlg_cell* dlg,
68
+                                    str* key);
66 69
 
67 70
 #define CONFIRMED_DIALOG_STATE 1
68 71
 
... ...
@@ -376,6 +376,31 @@ int get_dlg_vardup(struct dlg_cell *dlg, str *key, str *val)
376 376
 	return -2;
377 377
 }
378 378
 
379
+/**
380
+ * return the status if the dlg variable value is set or not
381
+ * - 1 - variable is set
382
+ * - 0 - variable is not set
383
+ */
384
+int get_dlg_varstatus(struct dlg_cell *dlg, str *key)
385
+{
386
+    str* var = NULL;
387
+    int ret = 0;
388
+
389
+    if( !dlg || !key || key->len<=0) {
390
+        LM_ERR("BUG - bad parameters\n");
391
+        return 0;
392
+    }
393
+
394
+    dlg_lock(d_table, &(d_table->entries[dlg->h_entry]));
395
+    var = get_dlg_variable_unsafe(dlg, key);
396
+	if(var && var->s) {
397
+		ret = 1;
398
+	}
399
+    dlg_unlock(d_table, &(d_table->entries[dlg->h_entry]));
400
+
401
+    return ret;
402
+}
403
+
379 404
 int get_dlg_variable_uintval(struct dlg_cell *dlg, str *key, unsigned int *uval)
380 405
 {
381 406
 	str* var = NULL;
... ...
@@ -62,6 +62,7 @@ typedef struct dlg_var {
62 62
 str* get_dlg_varref(dlg_cell_t *dlg, str *key);
63 63
 int get_dlg_varval(dlg_cell_t *dlg, str *key, str *val);
64 64
 int get_dlg_vardup(dlg_cell_t *dlg, str *key, str *val);
65
+int get_dlg_varstatus(dlg_cell_t *dlg, str *key);
65 66
 int set_dlg_variable(dlg_cell_t *dlg, str *key, str *val);
66 67
 
67 68
 int get_dlg_variable_uintval(struct dlg_cell *dlg, str *key, unsigned int *uval);