Browse code

acc: clone dlg core attributes

- GH #3243

Daniel-Constantin Mierla authored on 19/09/2022 06:15:53
Showing 1 changed files
... ...
@@ -96,9 +96,8 @@ int cdr_core2strar( struct dlg_cell* dlg,
96 96
 		int* unused,
97 97
 		char* types)
98 98
 {
99
-	str* start = NULL;
100
-	str* end = NULL;
101
-	str* duration = NULL;
99
+	str* dlgvals[MAX_CDR_CORE]; /* start, end, duration */
100
+	int i;
102 101
 
103 102
 	if( !dlg || !values || !types)
104 103
 	{
... ...
@@ -106,18 +105,40 @@ int cdr_core2strar( struct dlg_cell* dlg,
106 105
 		return 0;
107 106
 	}
108 107
 
109
-	start = dlgb.get_dlg_var( dlg, (str*)&cdr_start_str);
110
-	end = dlgb.get_dlg_var( dlg, (str*)&cdr_end_str);
111
-	duration = dlgb.get_dlg_var( dlg, (str*)&cdr_duration_str);
112
-
113
-	values[0] = ( start != NULL ? *start : empty_string);
114
-	types[0] = ( start != NULL ? TYPE_DATE : TYPE_NULL);
115
-
116
-	values[1] = ( end != NULL ? *end : empty_string);
117
-	types[1] = ( end != NULL ? TYPE_DATE : TYPE_NULL);
118
-
119
-	values[2] = ( duration != NULL ? *duration : empty_string);
120
-	types[2] = ( duration != NULL ? TYPE_DOUBLE : TYPE_NULL);
108
+	dlgvals[0] = dlgb.get_dlg_var( dlg, (str*)&cdr_start_str); /* start */
109
+	dlgvals[1] = dlgb.get_dlg_var( dlg, (str*)&cdr_end_str); /* end */
110
+	dlgvals[2] = dlgb.get_dlg_var( dlg, (str*)&cdr_duration_str); /* duration */
111
+
112
+	for(i=0; i<MAX_CDR_CORE; i++) {
113
+		if (dlgvals[i]!=NULL) {
114
+			values[i].s = (char *)pkg_malloc(dlgvals[i]->len + 1);
115
+			if (values[i].s == NULL ) {
116
+				PKG_MEM_ERROR;
117
+				/* cleanup already allocated memory and
118
+				 * return that we didn't do anything */
119
+				for (i = i-1; i >= 0; i--) {
120
+					if (NULL != values[i].s){
121
+						pkg_free(values[i].s);
122
+						values[i].s = NULL;
123
+					}
124
+				}
125
+				return 0;
126
+			}
127
+			memcpy(values[i].s, dlgvals[i]->s, dlgvals[i]->len);
128
+			values[i].s[dlgvals[i]->len] = '\0';
129
+			values[i].len = dlgvals[i]->len;
130
+			if(i!=2) {
131
+				/* [0] - start; [1] - end */
132
+				types[i] = TYPE_DATE;
133
+			} else {
134
+				/* [2] - duration */
135
+				types[i] = TYPE_DOUBLE;
136
+			}
137
+		} else {
138
+			values[i] = empty_string;
139
+			types[i] = TYPE_NULL;
140
+		}
141
+	}
121 142
 
122 143
 	return MAX_CDR_CORE;
123 144
 }
... ...
@@ -272,15 +293,15 @@ static int db_write_cdr( struct dlg_cell* dialog,
272 293
 		}
273 294
 	}
274 295
 
275
-	/* Free memory allocated by acc_extra.c/extra2strar */
276
-	free_strar_mem( &(cdr_type_array[core_cnt]), &(cdr_value_array[core_cnt]),
277
-			extra_cnt, attr_cnt);
296
+	/* Free memory allocated by core+extra attrs */
297
+	free_strar_mem( &(cdr_type_array[0]), &(cdr_value_array[0]),
298
+			attr_cnt, attr_cnt);
278 299
 	return 0;
279 300
 
280 301
 error:
281
-	/* Free memory allocated by acc_extra.c/extra2strar */
282
-	free_strar_mem( &(cdr_type_array[core_cnt]), &(cdr_value_array[core_cnt]),
283
-			extra_cnt, attr_cnt);
302
+	/* Free memory allocated by core+extra attrs */
303
+	free_strar_mem( &(cdr_type_array[0]), &(cdr_value_array[0]),
304
+			attr_cnt, attr_cnt);
284 305
 	return -1;
285 306
 }
286 307