Module: kamailio Branch: master Commit: c2c3211cd31405188891abd16ef770c26a8ddd44 URL: https://github.com/kamailio/kamailio/commit/c2c3211cd31405188891abd16ef770c2...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2022-09-26T12:30:06+02:00
dialog: api function to get the status if dlg var is set or not
---
Modified: src/modules/dialog/dlg_cb.h Modified: src/modules/dialog/dlg_var.c Modified: src/modules/dialog/dlg_var.h
---
Diff: https://github.com/kamailio/kamailio/commit/c2c3211cd31405188891abd16ef770c2... Patch: https://github.com/kamailio/kamailio/commit/c2c3211cd31405188891abd16ef770c2...
---
diff --git a/src/modules/dialog/dlg_cb.h b/src/modules/dialog/dlg_cb.h index 86a85bb2e1..a685816306 100644 --- a/src/modules/dialog/dlg_cb.h +++ b/src/modules/dialog/dlg_cb.h @@ -63,6 +63,9 @@ typedef int (*get_dlg_varval_f)( struct dlg_cell* dlg, /* method to get a variable value pkg-allocated duplicate from a dialog */ typedef int (*get_dlg_vardup_f)( struct dlg_cell* dlg, str* key, str* val); +/* method to get if a variable value is set or not from a dialog */ +typedef int (*get_dlg_varstatus_f)( struct dlg_cell* dlg, + str* key);
#define CONFIRMED_DIALOG_STATE 1
diff --git a/src/modules/dialog/dlg_var.c b/src/modules/dialog/dlg_var.c index 8edde80f1b..473736b437 100644 --- a/src/modules/dialog/dlg_var.c +++ b/src/modules/dialog/dlg_var.c @@ -376,6 +376,31 @@ int get_dlg_vardup(struct dlg_cell *dlg, str *key, str *val) return -2; }
+/** + * return the status if the dlg variable value is set or not + * - 1 - variable is set + * - 0 - variable is not set + */ +int get_dlg_varstatus(struct dlg_cell *dlg, str *key) +{ + str* var = NULL; + int ret = 0; + + if( !dlg || !key || key->len<=0) { + LM_ERR("BUG - bad parameters\n"); + return 0; + } + + dlg_lock(d_table, &(d_table->entries[dlg->h_entry])); + var = get_dlg_variable_unsafe(dlg, key); + if(var && var->s) { + ret = 1; + } + dlg_unlock(d_table, &(d_table->entries[dlg->h_entry])); + + return ret; +} + int get_dlg_variable_uintval(struct dlg_cell *dlg, str *key, unsigned int *uval) { str* var = NULL; diff --git a/src/modules/dialog/dlg_var.h b/src/modules/dialog/dlg_var.h index 52f2a01a60..292e9f701b 100644 --- a/src/modules/dialog/dlg_var.h +++ b/src/modules/dialog/dlg_var.h @@ -62,6 +62,7 @@ typedef struct dlg_var { str* get_dlg_varref(dlg_cell_t *dlg, str *key); int get_dlg_varval(dlg_cell_t *dlg, str *key, str *val); int get_dlg_vardup(dlg_cell_t *dlg, str *key, str *val); +int get_dlg_varstatus(dlg_cell_t *dlg, str *key); int set_dlg_variable(dlg_cell_t *dlg, str *key, str *val);
int get_dlg_variable_uintval(struct dlg_cell *dlg, str *key, unsigned int *uval);