Module: kamailio
Branch: master
Commit: d616dc46b5373b1474bf855afde4c5687d2a2d09
URL:
https://github.com/kamailio/kamailio/commit/d616dc46b5373b1474bf855afde4c56…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-09-19T08:40:36+02:00
acc: clone dlg core attributes
- GH #3243
---
Modified: src/modules/acc/acc_cdr.c
---
Diff:
https://github.com/kamailio/kamailio/commit/d616dc46b5373b1474bf855afde4c56…
Patch:
https://github.com/kamailio/kamailio/commit/d616dc46b5373b1474bf855afde4c56…
---
diff --git a/src/modules/acc/acc_cdr.c b/src/modules/acc/acc_cdr.c
index 8c51881dd7..1efa6515e6 100644
--- a/src/modules/acc/acc_cdr.c
+++ b/src/modules/acc/acc_cdr.c
@@ -96,9 +96,8 @@ int cdr_core2strar( struct dlg_cell* dlg,
int* unused,
char* types)
{
- str* start = NULL;
- str* end = NULL;
- str* duration = NULL;
+ str* dlgvals[MAX_CDR_CORE]; /* start, end, duration */
+ int i;
if( !dlg || !values || !types)
{
@@ -106,18 +105,40 @@ int cdr_core2strar( struct dlg_cell* dlg,
return 0;
}
- start = dlgb.get_dlg_var( dlg, (str*)&cdr_start_str);
- end = dlgb.get_dlg_var( dlg, (str*)&cdr_end_str);
- duration = dlgb.get_dlg_var( dlg, (str*)&cdr_duration_str);
-
- values[0] = ( start != NULL ? *start : empty_string);
- types[0] = ( start != NULL ? TYPE_DATE : TYPE_NULL);
-
- values[1] = ( end != NULL ? *end : empty_string);
- types[1] = ( end != NULL ? TYPE_DATE : TYPE_NULL);
-
- values[2] = ( duration != NULL ? *duration : empty_string);
- types[2] = ( duration != NULL ? TYPE_DOUBLE : TYPE_NULL);
+ dlgvals[0] = dlgb.get_dlg_var( dlg, (str*)&cdr_start_str); /* start */
+ dlgvals[1] = dlgb.get_dlg_var( dlg, (str*)&cdr_end_str); /* end */
+ dlgvals[2] = dlgb.get_dlg_var( dlg, (str*)&cdr_duration_str); /* duration */
+
+ for(i=0; i<MAX_CDR_CORE; i++) {
+ if (dlgvals[i]!=NULL) {
+ values[i].s = (char *)pkg_malloc(dlgvals[i]->len + 1);
+ if (values[i].s == NULL ) {
+ PKG_MEM_ERROR;
+ /* cleanup already allocated memory and
+ * return that we didn't do anything */
+ for (i = i-1; i >= 0; i--) {
+ if (NULL != values[i].s){
+ pkg_free(values[i].s);
+ values[i].s = NULL;
+ }
+ }
+ return 0;
+ }
+ memcpy(values[i].s, dlgvals[i]->s, dlgvals[i]->len);
+ values[i].s[dlgvals[i]->len] = '\0';
+ values[i].len = dlgvals[i]->len;
+ if(i!=2) {
+ /* [0] - start; [1] - end */
+ types[i] = TYPE_DATE;
+ } else {
+ /* [2] - duration */
+ types[i] = TYPE_DOUBLE;
+ }
+ } else {
+ values[i] = empty_string;
+ types[i] = TYPE_NULL;
+ }
+ }
return MAX_CDR_CORE;
}
@@ -272,15 +293,15 @@ static int db_write_cdr( struct dlg_cell* dialog,
}
}
- /* Free memory allocated by acc_extra.c/extra2strar */
- free_strar_mem( &(cdr_type_array[core_cnt]), &(cdr_value_array[core_cnt]),
- extra_cnt, attr_cnt);
+ /* Free memory allocated by core+extra attrs */
+ free_strar_mem( &(cdr_type_array[0]), &(cdr_value_array[0]),
+ attr_cnt, attr_cnt);
return 0;
error:
- /* Free memory allocated by acc_extra.c/extra2strar */
- free_strar_mem( &(cdr_type_array[core_cnt]), &(cdr_value_array[core_cnt]),
- extra_cnt, attr_cnt);
+ /* Free memory allocated by core+extra attrs */
+ free_strar_mem( &(cdr_type_array[0]), &(cdr_value_array[0]),
+ attr_cnt, attr_cnt);
return -1;
}