Module: kamailio
Branch: master
Commit: 13512f48e03a2ef99847edf639582aaf3b4dfeb3
URL:
https://github.com/kamailio/kamailio/commit/13512f48e03a2ef99847edf639582aa…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-09-26T11:57:02+02:00
dialog: api function get pkg-allocated duplicate of dlg var value
---
Modified: src/modules/dialog/dlg_cb.h
Modified: src/modules/dialog/dlg_load.h
Modified: src/modules/dialog/dlg_var.c
Modified: src/modules/dialog/dlg_var.h
---
Diff:
https://github.com/kamailio/kamailio/commit/13512f48e03a2ef99847edf639582aa…
Patch:
https://github.com/kamailio/kamailio/commit/13512f48e03a2ef99847edf639582aa…
---
diff --git a/src/modules/dialog/dlg_cb.h b/src/modules/dialog/dlg_cb.h
index d049875308..91064ee9e0 100644
--- a/src/modules/dialog/dlg_cb.h
+++ b/src/modules/dialog/dlg_cb.h
@@ -42,7 +42,7 @@ struct dlg_cb_params {
};
/* callback function prototype */
-typedef void (dialog_cb) (struct dlg_cell* dlg, int type,
+typedef void (dialog_cb) (struct dlg_cell* dlg, int type,
struct dlg_cb_params * params);
/* function to free the callback param */
typedef void (param_free_cb) (void *param);
@@ -60,6 +60,9 @@ typedef str* (*get_dlg_varref_f)( struct dlg_cell* dlg,
/* method to get a variable from a dialog */
typedef int (*get_dlg_varval_f)( struct dlg_cell* dlg,
str* key, str* val);
+/* method to get a variable value duplicate from a dialog */
+typedef int (*get_dlg_vardup_f)( struct dlg_cell* dlg,
+ str* key, str* val);
#define CONFIRMED_DIALOG_STATE 1
diff --git a/src/modules/dialog/dlg_load.h b/src/modules/dialog/dlg_load.h
index 2a3273ce84..16fb568ef3 100644
--- a/src/modules/dialog/dlg_load.h
+++ b/src/modules/dialog/dlg_load.h
@@ -48,6 +48,7 @@ struct dlg_binds {
set_dlg_variable_f set_dlg_var;
get_dlg_varref_f get_dlg_varref;
get_dlg_varval_f get_dlg_varval;
+ get_dlg_vardup_f get_dlg_vardup;
get_dlg_f get_dlg;
release_dlg_f release_dlg;
};
diff --git a/src/modules/dialog/dlg_var.c b/src/modules/dialog/dlg_var.c
index 0a16d18296..8edde80f1b 100644
--- a/src/modules/dialog/dlg_var.c
+++ b/src/modules/dialog/dlg_var.c
@@ -342,6 +342,40 @@ int get_dlg_varval(struct dlg_cell *dlg, str *key, str *val)
return -2;
}
+/**
+ * set *val to a pkg-allocated buffer where the dlg value is cloned
+ * - val->s has to be pkg-freed after use
+ */
+int get_dlg_vardup(struct dlg_cell *dlg, str *key, str *val)
+{
+ str *var = NULL;
+
+ val->s = NULL;
+ val->len = 0;
+
+ if( !dlg || !key || key->len<=0) {
+ LM_ERR("BUG - bad parameters\n");
+ return -1;
+ }
+
+ dlg_lock(d_table, &(d_table->entries[dlg->h_entry]));
+ var = get_dlg_variable_unsafe(dlg, key);
+ if(var && var->s) {
+ val->s = (char*)pkg_malloc(var->len + 1);
+ if(val->s!=NULL) {
+ memcpy(val->s, var->s, var->len);
+ val->len = var->len;
+ val->s[val->len] = '\0';
+ }
+ }
+ dlg_unlock(d_table, &(d_table->entries[dlg->h_entry]));
+
+ if(val->s) {
+ return 0;
+ }
+ return -2;
+}
+
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 05060997f0..52f2a01a60 100644
--- a/src/modules/dialog/dlg_var.h
+++ b/src/modules/dialog/dlg_var.h
@@ -61,6 +61,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 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);