Browse code

acc: new parameter acc_extra_nullable

- if set to 1, set NULL db values for varaibles that are $null
- GH #2531

Daniel-Constantin Mierla authored on 03/11/2020 13:55:45
Showing 2 changed files
... ...
@@ -52,6 +52,7 @@ extern struct acc_extra *log_extra;
52 52
 extern struct acc_extra *leg_info;
53 53
 extern struct acc_enviroment acc_env;
54 54
 extern char *acc_time_format;
55
+extern int acc_extra_nullable;
55 56
 
56 57
 static db_func_t acc_dbf;
57 58
 static db1_con_t* db_handle=0;
... ...
@@ -458,8 +459,13 @@ int acc_db_request( struct sip_msg *rq)
458 459
 	o = extra2strar( db_extra, rq, val_arr+m, int_arr+m, type_arr+m);
459 460
 	m += o;
460 461
 
461
-	for( i++ ; i<m; i++)
462
-		VAL_STR(db_vals+i) = val_arr[i];
462
+	for( i++ ; i<m; i++) {
463
+		if (acc_extra_nullable == 1 && type_arr[i] == TYPE_NULL) {
464
+			VAL_NULL(db_vals + i) = 1;
465
+		} else {
466
+			VAL_STR(db_vals+i) = val_arr[i];
467
+		}
468
+	}
463 469
 
464 470
 	if (acc_dbf.use_table(db_handle, &acc_env.text/*table*/) < 0) {
465 471
 		LM_ERR("error in use_table\n");
... ...
@@ -488,8 +494,13 @@ int acc_db_request( struct sip_msg *rq)
488 494
 	} else {
489 495
 		n = legs2strar(leg_info,rq,val_arr+m,int_arr+m,type_arr+m,1);
490 496
 		do {
491
-			for (i=m; i<m+n; i++)
492
-				VAL_STR(db_vals+i)=val_arr[i];
497
+			for (i=m; i<m+n; i++) {
498
+			if (acc_extra_nullable == 1 && type_arr[i] == TYPE_NULL) {
499
+					VAL_NULL(db_vals + i) = 1;
500
+				} else {
501
+					VAL_STR(db_vals+i)=val_arr[i];
502
+				}
503
+			}
493 504
 			if(acc_db_insert_mode==1 && acc_dbf.insert_delayed!=NULL) {
494 505
 				if(acc_dbf.insert_delayed(db_handle,db_keys,db_vals,m+n)<0) {
495 506
 					LM_ERR("failed to insert delayed into database\n");
... ...
@@ -83,6 +83,7 @@ int acc_prepare_always = 0; /* prepare the request always for later acc */
83 83
 int acc_prepare_flag = -1; /*!< should the request be prepared for later acc */
84 84
 char *acc_time_format = "%Y-%m-%d %H:%M:%S";
85 85
 int reason_from_hf = 0; /*!< assign reason from reason hf if present */
86
+int acc_extra_nullable  = 0;
86 87
 
87 88
 /* ----- time mode variables ------- */
88 89
 /*! \name AccTimeModeVariables  Time Mode Variables */
... ...
@@ -199,6 +200,7 @@ static param_export_t params[] = {
199 200
 	{"acc_prepare_flag",        INT_PARAM, &acc_prepare_flag        },
200 201
 	{"acc_prepare_always",      INT_PARAM, &acc_prepare_always      },
201 202
 	{"reason_from_hf",          INT_PARAM, &reason_from_hf          },
203
+	{"acc_extra_nullable",      INT_PARAM, &acc_extra_nullable      },
202 204
 	/* syslog specific */
203 205
 	{"log_flag",             INT_PARAM, &log_flag             },
204 206
 	{"log_missed_flag",      INT_PARAM, &log_missed_flag      },