Browse code

acc: increase acc and cdr extra values

Stefan Mititelu authored on 21/10/2021 08:33:59
Showing 7 changed files
... ...
@@ -36,7 +36,6 @@
36 36
 #include "../../core/mem/mem.h"
37 37
 #include "../../core/usr_avp.h"
38 38
 #include "../../core/async_task.h"
39
-#include "../../lib/srdb1/db.h"
40 39
 #include "../../core/parser/hf.h"
41 40
 #include "../../core/parser/msg_parser.h"
42 41
 #include "../../core/parser/parse_from.h"
... ...
@@ -61,9 +60,9 @@ extern struct acc_extra *db_extra;
61 60
 /* arrays used to collect the values before being
62 61
  * pushed to the storage backend (whatever used)
63 62
  * (3 = datetime + max 2 from time_mode) */
64
-static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
65
-static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
66
-static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
63
+str *val_arr;
64
+int *int_arr;
65
+char *type_arr;
67 66
 
68 67
 #define ACC_TIME_FORMAT_SIZE	128
69 68
 static char acc_time_format_buf[ACC_TIME_FORMAT_SIZE];
... ...
@@ -160,7 +159,7 @@ int core2strar(struct sip_msg *req, str *c_vals, int *i_vals, char *t_vals)
160 159
 /********************************************
161 160
  *        LOG  ACCOUNTING
162 161
  ********************************************/
163
-static str log_attrs[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG];
162
+str *log_attrs;
164 163
 
165 164
 #define SET_LOG_ATTR(_n,_atr)  \
166 165
 	do { \
... ...
@@ -306,11 +305,10 @@ int acc_is_db_ready(void)
306 305
 
307 306
 	return 0;
308 307
 }
309
-
310 308
 /* caution: keys need to be aligned to core format
311 309
  * (3 = datetime + max 2 from time_mode) */
312
-static db_key_t db_keys[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
313
-static db_val_t db_vals[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
310
+db_key_t *db_keys;
311
+db_val_t *db_vals;
314 312
 
315 313
 
316 314
 int acc_get_db_handlers(void **vf, void **vh) {
... ...
@@ -44,8 +44,6 @@
44 44
 #include "acc_extra.h"
45 45
 #include "acc.h"
46 46
 
47
-#include "../../lib/srdb1/db.h"
48
-
49 47
 #include <sys/time.h>
50 48
 
51 49
 /* Solaris does not provide timersub macro in <sys/time.h> */
... ...
@@ -75,10 +73,10 @@ static char time_buffer[ TIME_BUFFER_LENGTH];
75 73
 static const str empty_string = { "", 0};
76 74
 
77 75
 // buffers which are used to collect the crd data for writing
78
-static str cdr_attrs[ MAX_CDR_CORE + MAX_CDR_EXTRA];
79
-static str cdr_value_array[ MAX_CDR_CORE + MAX_CDR_EXTRA];
80
-static int cdr_int_array[ MAX_CDR_CORE + MAX_CDR_EXTRA];
81
-static char cdr_type_array[ MAX_CDR_CORE + MAX_CDR_EXTRA];
76
+str *cdr_attrs;
77
+str *cdr_value_array;
78
+int *cdr_int_array;
79
+char *cdr_type_array;
82 80
 
83 81
 extern struct tm_binds tmb;
84 82
 extern str cdr_start_str;
... ...
@@ -121,10 +119,9 @@ int cdr_core2strar( struct dlg_cell* dlg,
121 119
 
122 120
 	return MAX_CDR_CORE;
123 121
 }
124
-
125 122
 /* caution: keys need to be aligned to core format */
126
-static db_key_t db_cdr_keys[ MAX_CDR_CORE + MAX_CDR_EXTRA];
127
-static db_val_t db_cdr_vals[ MAX_CDR_CORE + MAX_CDR_EXTRA];
123
+db_key_t *db_cdr_keys;
124
+db_val_t *db_cdr_vals;
128 125
 
129 126
 /* collect all crd data and write it to a syslog */
130 127
 static int db_write_cdr( struct dlg_cell* dialog,
... ...
@@ -38,10 +38,17 @@
38 38
 #ifndef _ACC_CDR_H_
39 39
 #define _ACC_CDR_H_
40 40
 
41
+#include "../../lib/srdb1/db.h"
41 42
 
42 43
 #define MAX_CDR_CORE 3
43 44
 #define MAX_CDR_EXTRA 64
44 45
 
46
+extern str *cdr_attrs;
47
+extern str *cdr_value_array;
48
+extern int *cdr_int_array;
49
+extern char *cdr_type_array;
50
+extern db_key_t *db_cdr_keys;
51
+extern db_val_t *db_cdr_vals;
45 52
 
46 53
 int set_cdr_extra( char* cdr_extra_value);
47 54
 int set_cdr_facility( char* cdr_facility);
... ...
@@ -43,14 +43,8 @@
43 43
 #define EQUAL '='
44 44
 #define SEPARATOR ';'
45 45
 
46
-
47
-#if MAX_ACC_EXTRA<MAX_ACC_LEG
48
-#define MAX_ACC_INT_BUF MAX_ACC_LEG
49
-#else
50
-#define MAX_ACC_INT_BUF MAX_ACC_EXTRA
51
-#endif
52 46
 /* here we copy the strings returned by int2str (which uses a static buffer) */
53
-static char int_buf[INT2STR_MAX_LEN*MAX_ACC_INT_BUF];
47
+char *int_buf;
54 48
 
55 49
 struct acc_extra *parse_acc_leg(char *extra_str)
56 50
 {
... ...
@@ -109,7 +103,7 @@ struct acc_extra *parse_acc_extra(char *extra_str)
109 103
 		while (*s && isspace((int)*s))  s++;
110 104
 		if (*s==0)
111 105
 			goto parse_error;
112
-		if (n==MAX_ACC_EXTRA) {
106
+		if (n==acc_extra_size) {
113 107
 			LM_ERR("too many extras -> please increase the internal buffer\n");
114 108
 			goto error;
115 109
 		}
... ...
@@ -224,7 +218,7 @@ int extra2strar(struct acc_extra *extra, struct sip_msg *rq, str *val_arr,
224 218
 		}
225 219
 
226 220
 		/* check for overflow */
227
-		if (n==MAX_ACC_EXTRA) {
221
+		if (n==acc_extra_size) {
228 222
 			LM_WARN("array to short -> omitting extras for accounting\n");
229 223
 			goto done;
230 224
 		}
... ...
@@ -283,7 +277,7 @@ int extra2strar_dlg_only(struct acc_extra *extra, struct dlg_cell* dlg, str *val
283 277
 	while (extra) {
284 278
 
285 279
 		/* check for overflow */
286
-		if (n==MAX_ACC_EXTRA) {
280
+		if (n==acc_extra_size) {
287 281
 			LM_WARN("array to short -> omitting extras for accounting\n");
288 282
 			goto done;
289 283
 		}
... ...
@@ -37,6 +37,26 @@
37 37
 #include "../../core/parser/msg_parser.h"
38 38
 #include "../dialog/dlg_load.h"
39 39
 
40
+#include "../../lib/srdb1/db.h"
41
+
42
+/* arrays used to collect the values before being
43
+ * pushed to the storage backend (whatever used)
44
+ * (3 = datetime + max 2 from time_mode) */
45
+extern str *val_arr;
46
+extern int *int_arr;
47
+extern char *type_arr;
48
+extern str *log_attrs;
49
+
50
+/* caution: keys need to be aligned to core format
51
+ * (3 = datetime + max 2 from time_mode) */
52
+extern db_key_t *db_keys;
53
+extern db_val_t *db_vals;
54
+
55
+/* here we copy the strings returned by int2str (which uses a static buffer) */
56
+extern char *int_buf;
57
+
58
+extern int acc_extra_size;
59
+
40 60
 void init_acc_extra(void);
41 61
 
42 62
 struct acc_extra *parse_acc_extra(char *extra);
... ...
@@ -95,6 +95,10 @@ str acc_time_exten  = str_init("time_exten");
95 95
 int _acc_clone_msg  = 1;
96 96
 int _acc_cdr_on_failed = 1;
97 97
 
98
+int acc_int_buf_size = 0; // will be calculated before alloc
99
+int acc_extra_size = MAX_ACC_EXTRA;
100
+int cdr_extra_size = MAX_CDR_EXTRA;
101
+
98 102
 /*@}*/
99 103
 
100 104
 /* ----- SYSLOG acc variables ----------- */
... ...
@@ -242,6 +246,8 @@ static param_export_t params[] = {
242 246
 	{"time_format",          PARAM_STRING, &acc_time_format   },
243 247
 	{"clone_msg",            PARAM_INT, &_acc_clone_msg       },
244 248
 	{"cdr_on_failed",        PARAM_INT, &_acc_cdr_on_failed   },
249
+	{"acc_extra_size",       PARAM_INT, &acc_extra_size},
250
+	{"cdr_extra_size",       PARAM_INT, &cdr_extra_size},
245 251
 	{0,0,0}
246 252
 };
247 253
 
... ...
@@ -369,6 +375,66 @@ static int parse_failed_filter(char *s, unsigned short *failed_filter)
369 375
 
370 376
 static int mod_init( void )
371 377
 {
378
+	/* acc extra */
379
+	if ((val_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) {
380
+		LM_ERR("failed to alloc val_arr\n");
381
+	}
382
+
383
+	if ((int_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(int))) == NULL) {
384
+		LM_ERR("failed to alloc int_arr\n");
385
+	}
386
+
387
+	if ((type_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(char))) == NULL) {
388
+		LM_ERR("failed to alloc type_arr\n");
389
+	}
390
+
391
+	if ((log_attrs = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) {
392
+		LM_ERR("failed to alloc log_attrs\n");
393
+	}
394
+
395
+	if ((db_keys = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_key_t))) == NULL) {
396
+		LM_ERR("failed to alloc db_keys\n");
397
+	}
398
+
399
+	if ((db_vals = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_val_t))) == NULL) {
400
+		LM_ERR("failed to alloc db_vals\n");
401
+	}
402
+
403
+	if (acc_extra_size < MAX_ACC_LEG) {
404
+		acc_int_buf_size = MAX_ACC_LEG;
405
+	} else {
406
+		acc_int_buf_size = acc_extra_size;
407
+	}
408
+
409
+	if ((int_buf = pkg_malloc((INT2STR_MAX_LEN * acc_int_buf_size) * sizeof(char))) == NULL) {
410
+		LM_ERR("failed to alloc int_buf\n");
411
+	}
412
+
413
+	/* cdr extra */
414
+	if ((cdr_attrs = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) == NULL) {
415
+		LM_ERR("failed to alloc cdr_attrs\n");
416
+	}
417
+
418
+	if ((cdr_value_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) == NULL) {
419
+		LM_ERR("failed to alloc cdr_value_array\n");
420
+	}
421
+
422
+	if ((cdr_int_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(int))) == NULL) {
423
+		LM_ERR("failed to alloc cdr_int_array\n");
424
+	}
425
+
426
+	if ((cdr_type_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(char))) == NULL) {
427
+		LM_ERR("failed to alloc cdr_type_array\n");
428
+	}
429
+
430
+	if ((db_cdr_keys = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_key_t))) == NULL) {
431
+		LM_ERR("failed to alloc db_cdr_keys\n");
432
+	}
433
+
434
+	if ((db_cdr_vals = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_val_t))) == NULL) {
435
+		LM_ERR("failed to alloc db_cdr_vals\n");
436
+	}
437
+
372 438
 	if (db_url.s) {
373 439
 		if(db_url.len<=0) {
374 440
 			db_url.s = NULL;
... ...
@@ -600,6 +666,60 @@ static void destroy(void)
600 666
 	acc_db_close();
601 667
 	if (db_extra)
602 668
 		destroy_extras( db_extra);
669
+
670
+	/* acc extra free */
671
+	if (val_arr) {
672
+		pkg_free(val_arr);
673
+	}
674
+
675
+	if (int_arr) {
676
+		pkg_free(int_arr);
677
+	}
678
+
679
+	if (type_arr) {
680
+		pkg_free(type_arr);
681
+	}
682
+
683
+	if (log_attrs) {
684
+		pkg_free(log_attrs);
685
+	}
686
+
687
+	if (db_keys) {
688
+		pkg_free(db_keys);
689
+	}
690
+
691
+	if (db_vals) {
692
+		pkg_free(db_vals);
693
+	}
694
+
695
+	if (int_buf) {
696
+		pkg_free(int_buf);
697
+	}
698
+
699
+	/* cdr extra free */
700
+	if (cdr_attrs) {
701
+		pkg_free(cdr_attrs);
702
+	}
703
+
704
+	if (cdr_value_array) {
705
+		pkg_free(cdr_value_array);
706
+	}
707
+
708
+	if (cdr_int_array) {
709
+		pkg_free(cdr_int_array);
710
+	}
711
+
712
+	if (cdr_type_array) {
713
+		pkg_free(cdr_type_array);
714
+	}
715
+
716
+	if (db_cdr_keys) {
717
+		pkg_free(db_cdr_keys);
718
+	}
719
+
720
+	if (db_cdr_vals) {
721
+		pkg_free(db_cdr_vals);
722
+	}
603 723
 }
604 724
 
605 725
 
... ...
@@ -1437,6 +1437,43 @@ modparam("acc", "cdr_on_failed", 0)
1437 1437
 </programlisting>
1438 1438
 		</example>
1439 1439
 	</section>
1440
+
1441
+	<section id="acc.p.acc_extra_size">
1442
+		<title><varname>acc_extra_size</varname> (int)</title>
1443
+		<para>
1444
+		This parameter is meant to replace MAX_ACC_EXTRA fixed size with desired size.
1445
+		</para>
1446
+		<para>
1447
+		Default value is 64 (MAX_ACC_EXTRA).
1448
+		</para>
1449
+		<example>
1450
+		<title>acc_extra_size</title>
1451
+		<programlisting format="linespecific">
1452
+...
1453
+modparam("acc", "acc_extra_size", 100)
1454
+...
1455
+</programlisting>
1456
+		</example>
1457
+	</section>
1458
+
1459
+	<section id="acc.p.cdr_extra_size">
1460
+		<title><varname>cdr_extra_size</varname> (int)</title>
1461
+		<para>
1462
+		This parameter is meant to replace MAX_CDR_EXTRA fixed size with desired size.
1463
+		</para>
1464
+		<para>
1465
+		Default value is 64 (MAX_CDR_EXTRA).
1466
+		</para>
1467
+		<example>
1468
+		<title>cdr_extra_size</title>
1469
+		<programlisting format="linespecific">
1470
+...
1471
+modparam("acc", "cdr_extra_size", 100)
1472
+...
1473
+</programlisting>
1474
+		</example>
1475
+	</section>
1476
+
1440 1477
 	</section>
1441 1478
 
1442 1479
 	<section>