Browse code

acc: more meaningful array index names for building cdr attributes

Daniel-Constantin Mierla authored on 18/09/2022 19:33:25
Showing 1 changed files
... ...
@@ -130,8 +130,9 @@ static db_val_t *db_cdr_vals = NULL;
130 130
 static int db_write_cdr( struct dlg_cell* dialog,
131 131
 		struct sip_msg* message)
132 132
 {
133
-	int m = 0;
134
-	int n = 0;
133
+	int attr_cnt = 0;
134
+	int core_cnt = 0;
135
+	int extra_cnt = 0;
135 136
 	int i;
136 137
 	db_func_t *df=NULL;
137 138
 	db1_con_t *dh=NULL;
... ...
@@ -155,12 +156,13 @@ static int db_write_cdr( struct dlg_cell* dialog,
155 156
 	dh = (db1_con_t*)vh;
156 157
 
157 158
 	/* get default values */
158
-	m = cdr_core2strar( dialog,
159
+	core_cnt = cdr_core2strar( dialog,
159 160
 			cdr_value_array,
160 161
 			cdr_int_array,
161 162
 			cdr_type_array);
163
+	attr_cnt += core_cnt;
162 164
 
163
-	for(i=0; i<m; i++) {
165
+	for(i=0; i<core_cnt; i++) {
164 166
 		db_cdr_keys[i] = &cdr_attrs[i];
165 167
 		/* reset errno, some strtoX don't reset it */
166 168
 		errno = 0;
... ...
@@ -219,24 +221,24 @@ static int db_write_cdr( struct dlg_cell* dialog,
219 221
 	/* get extra values */
220 222
 	if (message)
221 223
 	{
222
-		n += extra2strar( cdr_extra,
224
+		extra_cnt = extra2strar( cdr_extra,
223 225
 				message,
224
-				cdr_value_array + m,
225
-				cdr_int_array + m,
226
-				cdr_type_array + m);
227
-		m += n;
226
+				cdr_value_array + attr_cnt,
227
+				cdr_int_array + attr_cnt,
228
+				cdr_type_array + attr_cnt);
229
+		attr_cnt += extra_cnt;;
228 230
 	} else if (cdr_expired_dlg_enable){
229 231
 		LM_WARN( "fallback to dlg_only search because of message doesn't exist.\n");
230
-		n += extra2strar_dlg_only( cdr_extra,
232
+		extra_cnt = extra2strar_dlg_only( cdr_extra,
231 233
 				dialog,
232
-				cdr_value_array + m,
233
-				cdr_int_array + m,
234
-				cdr_type_array +m,
234
+				cdr_value_array + attr_cnt,
235
+				cdr_int_array + attr_cnt,
236
+				cdr_type_array + attr_cnt,
235 237
 				&dlgb);
236
-		m += n;
238
+		attr_cnt += extra_cnt;
237 239
 	}
238 240
 
239
-	for( ; i<m; i++) {
241
+	for( ; i<attr_cnt; i++) {
240 242
 		db_cdr_keys[i] = &cdr_attrs[i];
241 243
 
242 244
 		if (cdr_extra_nullable == 1 && cdr_type_array[i] == TYPE_NULL) {
... ...
@@ -254,29 +256,31 @@ static int db_write_cdr( struct dlg_cell* dialog,
254 256
 	}
255 257
 
256 258
 	if(acc_db_insert_mode==1 && df->insert_delayed!=NULL) {
257
-		if (df->insert_delayed(dh, db_cdr_keys, db_cdr_vals, m) < 0) {
259
+		if (df->insert_delayed(dh, db_cdr_keys, db_cdr_vals, attr_cnt) < 0) {
258 260
 			LM_ERR("failed to insert delayed into database\n");
259 261
 			goto error;
260 262
 		}
261 263
 	} else if(acc_db_insert_mode==2 && df->insert_async!=NULL) {
262
-		if (df->insert_async(dh, db_cdr_keys, db_cdr_vals, m) < 0) {
264
+		if (df->insert_async(dh, db_cdr_keys, db_cdr_vals, attr_cnt) < 0) {
263 265
 			LM_ERR("failed to insert async into database\n");
264 266
 			goto error;
265 267
 		}
266 268
 	} else {
267
-		if (df->insert(dh, db_cdr_keys, db_cdr_vals, m) < 0) {
269
+		if (df->insert(dh, db_cdr_keys, db_cdr_vals, attr_cnt) < 0) {
268 270
 			LM_ERR("failed to insert into database\n");
269 271
 			goto error;
270 272
 		}
271 273
 	}
272 274
 
273 275
 	/* Free memory allocated by acc_extra.c/extra2strar */
274
-	free_strar_mem( &(cdr_type_array[m-n]), &(cdr_value_array[m-n]), n, m);
276
+	free_strar_mem( &(cdr_type_array[core_cnt]), &(cdr_value_array[core_cnt]),
277
+			extra_cnt, attr_cnt);
275 278
 	return 0;
276 279
 
277 280
 error:
278 281
 	/* Free memory allocated by acc_extra.c/extra2strar */
279
-	free_strar_mem( &(cdr_type_array[m-n]), &(cdr_value_array[m-n]), n, m);
282
+	free_strar_mem( &(cdr_type_array[core_cnt]), &(cdr_value_array[core_cnt]),
283
+			extra_cnt, attr_cnt);
280 284
 	return -1;
281 285
 }
282 286