Browse code

acc: Allow nullable cdr extra fields

- allow custom cdr fields defined with cdr_extra modparam to be saved
as null. Before this change, cdr_extra variables not defined in config
operation (or set to $null) were saved as empty string (''). This commit makes
possible to save them as NULL value.

- new modparam to make this behaviour configurable: cdr_extra_nullable.
Set it to 1 to enable this new behaviour (default value: 0)

Carlos Cruz authored on 22/12/2017 16:29:12
Showing 4 changed files
... ...
@@ -238,9 +238,14 @@ static int db_write_cdr( struct dlg_cell* dialog,
238 238
 
239 239
 	for( ; i<m; i++) {
240 240
 		db_cdr_keys[i] = &cdr_attrs[i];
241
-		VAL_TYPE(db_cdr_vals+i)=DB1_STR;
242
-		VAL_NULL(db_cdr_vals+i)=0;
243
-		VAL_STR(db_cdr_vals+i) = cdr_value_array[i];
241
+
242
+		if (cdr_extra_nullable == 1 && cdr_type_array[i] == TYPE_NULL) {
243
+			VAL_NULL(db_cdr_vals + i) = 1;
244
+		} else {
245
+			VAL_TYPE(db_cdr_vals+i)=DB1_STR;
246
+			VAL_NULL(db_cdr_vals+i)=0;
247
+			VAL_STR(db_cdr_vals+i) = cdr_value_array[i];
248
+		}
244 249
 	}
245 250
 
246 251
 	if (df->use_table(dh, &acc_cdrs_table /*table*/) < 0) {
... ...
@@ -115,6 +115,7 @@ struct acc_extra *log_extra = 0; /*!< Log extra attributes */
115 115
 /*@{*/
116 116
 
117 117
 int cdr_enable  = 0;
118
+int cdr_extra_nullable  = 0;
118 119
 int cdr_log_enable  = 1;
119 120
 int cdr_start_on_confirmed = 0;
120 121
 int cdr_expired_dlg_enable = 0;
... ...
@@ -204,6 +205,7 @@ static param_export_t params[] = {
204 205
 	{"cdr_start_on_confirmed", INT_PARAM, &cdr_start_on_confirmed   },
205 206
 	{"cdr_facility",         PARAM_STRING, &cdr_facility_str           },
206 207
 	{"cdr_extra",            PARAM_STRING, &cdr_log_extra_str          },
208
+	{"cdr_extra_nullable",   INT_PARAM, &cdr_extra_nullable            },
207 209
 	{"cdr_start_id",	 PARAM_STR, &cdr_start_str		},
208 210
 	{"cdr_end_id",		 PARAM_STR, &cdr_end_str		},
209 211
 	{"cdr_duration_id",	 PARAM_STR, &cdr_duration_str	},
... ...
@@ -474,6 +476,12 @@ static int mod_init( void )
474 476
 		return -1;
475 477
 	}
476 478
 
479
+	if( cdr_extra_nullable < 0 || cdr_extra_nullable > 1)
480
+	{
481
+		LM_ERR("cdr_extra_nullable is out of range\n");
482
+		return -1;
483
+	}
484
+
477 485
 	if( cdr_expired_dlg_enable < 0 || cdr_expired_dlg_enable > 1)
478 486
 	{
479 487
 		LM_ERR("cdr_expired_dlg_enable is out of range\n");
... ...
@@ -49,6 +49,7 @@ extern int log_flag;
49 49
 extern int log_missed_flag;
50 50
 
51 51
 extern int cdr_enable;
52
+extern int cdr_extra_nullable;
52 53
 extern int cdr_start_on_confirmed;
53 54
 extern int cdr_log_facility;
54 55
 extern int cdr_expired_dlg_enable;
... ...
@@ -1194,6 +1194,28 @@ modparam("acc", "cdr_facility", "LOG_DAEMON")
1194 1194
 ...
1195 1195
 modparam("acc", "cdr_extra", "c1=$dlg_var(caller);c2=$dlg_var(callee)"
1196 1196
 ...
1197
+</programlisting>
1198
+		</example>
1199
+	</section>
1200
+	<section id="acc.p.cdr_extra_nullable">
1201
+		<title><varname>cdr_extra_nullable</varname> (integer)</title>
1202
+		<para>
1203
+		Should custom CDR fields be saved as NULL?
1204
+		</para>
1205
+		<para>
1206
+		If set to 0, custom CDR fields not defined in config operation (or set to $null) will be saved as empty string.
1207
+		If set to 1, custom CDR fields not defined in config operation (or set to $null) will be saved as NULL.
1208
+		</para>
1209
+		<para>
1210
+		Default value is 0.
1211
+		</para>
1212
+		</para>
1213
+		<example>
1214
+		<title>cdr_extra_nullable example</title>
1215
+		<programlisting format="linespecific">
1216
+...
1217
+modparam("acc", "cdr_extra_nullable", 1)
1218
+...
1197 1219
 </programlisting>
1198 1220
 		</example>
1199 1221
 	</section>