Browse code

acc: use get_dlg_varval() to get values for dialog variables

Daniel-Constantin Mierla authored on 23/09/2022 11:42:18
Showing 2 changed files
... ...
@@ -96,7 +96,7 @@ int cdr_core2strar( struct dlg_cell* dlg,
96 96
 		int* unused,
97 97
 		char* types)
98 98
 {
99
-	str* dlgvals[MAX_CDR_CORE]; /* start, end, duration */
99
+	str dlgvals[MAX_CDR_CORE]; /* start, end, duration */
100 100
 	int i;
101 101
 
102 102
 	if( !dlg || !values || !types)
... ...
@@ -105,13 +105,13 @@ int cdr_core2strar( struct dlg_cell* dlg,
105 105
 		return 0;
106 106
 	}
107 107
 
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 */
108
+	dlgb.get_dlg_varval(dlg, &cdr_start_str, &dlgvals[0]); /* start */
109
+	dlgb.get_dlg_varval(dlg, &cdr_end_str, &dlgvals[1]); /* end */
110
+	dlgb.get_dlg_varval(dlg, &cdr_duration_str, &dlgvals[2]); /* duration */
111 111
 
112 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);
113
+		if (dlgvals[i].s!=NULL) {
114
+			values[i].s = (char *)pkg_malloc(dlgvals[i].len + 1);
115 115
 			if (values[i].s == NULL ) {
116 116
 				PKG_MEM_ERROR;
117 117
 				/* cleanup already allocated memory and
... ...
@@ -124,9 +124,9 @@ int cdr_core2strar( struct dlg_cell* dlg,
124 124
 				}
125 125
 				return 0;
126 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;
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 130
 			if(i!=2) {
131 131
 				/* [0] - start; [1] - end */
132 132
 				types[i] = TYPE_DATE;
... ...
@@ -420,9 +420,9 @@ static int write_cdr( struct dlg_cell* dialog,
420 420
 
421 421
 	/* Skip cdr if cdr_skip dlg_var exists */
422 422
 	if (cdr_skip.len > 0) {
423
-		str* nocdr_val = 0;
424
-		nocdr_val = dlgb.get_dlg_var( dialog, &cdr_skip);
425
-		if ( nocdr_val ){
423
+		str nocdr_val = {0};
424
+		dlgb.get_dlg_varval(dialog, &cdr_skip, &nocdr_val);
425
+		if (nocdr_val.s){
426 426
 			LM_DBG( "cdr_skip dlg_var set, skip cdr!");
427 427
 			return 0;
428 428
 		}
... ...
@@ -440,7 +440,7 @@ static int string2time( str* time_str, struct timeval* time_value)
440 440
 	int dot_position = -1;
441 441
 	char zero_terminated_value[TIME_STR_BUFFER_SIZE];
442 442
 
443
-	if( !time_str)
443
+	if(!time_str || !time_str->s)
444 444
 	{
445 445
 		LM_ERR( "time_str is empty!");
446 446
 		return -1;
... ...
@@ -517,18 +517,20 @@ static int set_duration( struct dlg_cell* dialog)
517 517
 	struct timeval end_time;
518 518
 	struct timeval duration_time;
519 519
 	str duration_str;
520
+	str dval = {0};
520 521
 
521
-	if( !dialog)
522
-	{
522
+	if( !dialog) {
523 523
 		LM_ERR("dialog is empty!\n");
524 524
 		return -1;
525 525
 	}
526 526
 
527
-	if ( string2time( dlgb.get_dlg_var( dialog, (str*)&cdr_start_str), &start_time) < 0) {
527
+	dlgb.get_dlg_varval(dialog, &cdr_start_str, &dval);
528
+	if (string2time(&dval, &start_time) < 0) {
528 529
 		LM_ERR( "failed to extract start time\n");
529 530
 		return -1;
530 531
 	}
531
-	if ( string2time( dlgb.get_dlg_var( dialog, (str*)&cdr_end_str), &end_time) < 0) {
532
+	dlgb.get_dlg_varval( dialog, &cdr_end_str, &dval);
533
+	if ( string2time(&dval, &end_time) < 0) {
532 534
 		LM_ERR( "failed to extract end time\n");
533 535
 		return -1;
534 536
 	}
... ...
@@ -540,10 +542,7 @@ static int set_duration( struct dlg_cell* dialog)
540 542
 		return -1;
541 543
 	}
542 544
 
543
-	if( dlgb.set_dlg_var( dialog,
544
-				(str*)&cdr_duration_str,
545
-				(str*)&duration_str) != 0)
546
-	{
545
+	if( dlgb.set_dlg_var(dialog, &cdr_duration_str, &duration_str) != 0) {
547 546
 		LM_ERR( "failed to set duration time");
548 547
 		return -1;
549 548
 	}
... ...
@@ -266,7 +266,7 @@ int extra2strar_dlg_only(struct acc_extra *extra, struct dlg_cell* dlg, str *val
266 266
 		int *int_arr, char *type_arr, const struct dlg_binds* p_dlgb)
267 267
 {
268 268
 	//string value;
269
-	str* value = 0;
269
+	str dval = {0};
270 270
 	int n=0;
271 271
 	int i;
272 272
 
... ...
@@ -289,16 +289,14 @@ int extra2strar_dlg_only(struct acc_extra *extra, struct dlg_cell* dlg, str *val
289 289
 		type_arr[n] = TYPE_NULL;
290 290
 
291 291
 		str key = extra->spec.pvp.pvn.u.isname.name.s;
292
-		if ( key.len == 0 || !key.s)
293
-		{
292
+		if (key.len == 0 || !key.s) {
294 293
 			n++; extra = extra->next; continue;
295 294
 		}
296
-		/* get the value */
297
-		value = p_dlgb->get_dlg_var( dlg, &key);
295
+		/* get the dialog var value */
296
+		p_dlgb->get_dlg_varval(dlg, &key, &dval);
298 297
 
299
-		if (value)
300
-		{
301
-			val_arr[n].s = (char *)pkg_malloc(value->len + 1);
298
+		if (dval.s) {
299
+			val_arr[n].s = (char *)pkg_malloc(dval.len + 1);
302 300
 			if (val_arr[n].s == NULL ) {
303 301
 				PKG_MEM_ERROR;
304 302
 				/* cleanup already allocated memory and
... ...
@@ -312,9 +310,9 @@ int extra2strar_dlg_only(struct acc_extra *extra, struct dlg_cell* dlg, str *val
312 310
 				n = 0;
313 311
 				goto done;
314 312
 			}
315
-			memcpy(val_arr[n].s, value->s, value->len);
316
-			val_arr[n].s[value->len] = '\0';
317
-			val_arr[n].len = value->len;
313
+			memcpy(val_arr[n].s, dval.s, dval.len);
314
+			val_arr[n].s[dval.len] = '\0';
315
+			val_arr[n].len = dval.len;
318 316
 			type_arr[n] = TYPE_STR;
319 317
 		}
320 318