... | ... |
@@ -61,9 +61,9 @@ extern struct acc_extra *db_extra; |
61 | 61 |
/* arrays used to collect the values before being |
62 | 62 |
* pushed to the storage backend (whatever used) |
63 | 63 |
* (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]; |
|
64 |
+static str *val_arr = NULL; |
|
65 |
+static int *int_arr = NULL; |
|
66 |
+static char *type_arr = NULL; |
|
67 | 67 |
|
68 | 68 |
#define ACC_TIME_FORMAT_SIZE 128 |
69 | 69 |
static char acc_time_format_buf[ACC_TIME_FORMAT_SIZE]; |
... | ... |
@@ -160,7 +160,7 @@ int core2strar(struct sip_msg *req, str *c_vals, int *i_vals, char *t_vals) |
160 | 160 |
/******************************************** |
161 | 161 |
* LOG ACCOUNTING |
162 | 162 |
********************************************/ |
163 |
-static str log_attrs[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG]; |
|
163 |
+static str *log_attrs = NULL; |
|
164 | 164 |
|
165 | 165 |
#define SET_LOG_ATTR(_n,_atr) \ |
166 | 166 |
do { \ |
... | ... |
@@ -309,8 +309,8 @@ int acc_is_db_ready(void) |
309 | 309 |
|
310 | 310 |
/* caution: keys need to be aligned to core format |
311 | 311 |
* (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]; |
|
312 |
+static db_key_t *db_keys = NULL; |
|
313 |
+static db_val_t *db_vals = NULL; |
|
314 | 314 |
|
315 | 315 |
|
316 | 316 |
int acc_get_db_handlers(void **vf, void **vh) { |
... | ... |
@@ -624,3 +624,62 @@ void acc_api_set_arrays(acc_info_t *inf) |
624 | 624 |
inf->leg_info = leg_info; |
625 | 625 |
} |
626 | 626 |
|
627 |
+int acc_arrays_alloc(void) { |
|
628 |
+ if ((val_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) { |
|
629 |
+ LM_ERR("failed to alloc val_arr\n"); |
|
630 |
+ return -1; |
|
631 |
+ } |
|
632 |
+ |
|
633 |
+ if ((int_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(int))) == NULL) { |
|
634 |
+ LM_ERR("failed to alloc int_arr\n"); |
|
635 |
+ return -1; |
|
636 |
+ } |
|
637 |
+ |
|
638 |
+ if ((type_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(char))) == NULL) { |
|
639 |
+ LM_ERR("failed to alloc type_arr\n"); |
|
640 |
+ return -1; |
|
641 |
+ } |
|
642 |
+ |
|
643 |
+ if ((log_attrs = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) { |
|
644 |
+ LM_ERR("failed to alloc log_attrs\n"); |
|
645 |
+ return -1; |
|
646 |
+ } |
|
647 |
+ |
|
648 |
+ if ((db_keys = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_key_t))) == NULL) { |
|
649 |
+ LM_ERR("failed to alloc db_keys\n"); |
|
650 |
+ return -1; |
|
651 |
+ } |
|
652 |
+ |
|
653 |
+ if ((db_vals = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_val_t))) == NULL) { |
|
654 |
+ LM_ERR("failed to alloc db_vals\n"); |
|
655 |
+ return -1; |
|
656 |
+ } |
|
657 |
+ |
|
658 |
+ return 1; |
|
659 |
+} |
|
660 |
+ |
|
661 |
+void acc_arrays_free(void) { |
|
662 |
+ if (val_arr) { |
|
663 |
+ pkg_free(val_arr); |
|
664 |
+ } |
|
665 |
+ |
|
666 |
+ if (int_arr) { |
|
667 |
+ pkg_free(int_arr); |
|
668 |
+ } |
|
669 |
+ |
|
670 |
+ if (type_arr) { |
|
671 |
+ pkg_free(type_arr); |
|
672 |
+ } |
|
673 |
+ |
|
674 |
+ if (log_attrs) { |
|
675 |
+ pkg_free(log_attrs); |
|
676 |
+ } |
|
677 |
+ |
|
678 |
+ if (db_keys) { |
|
679 |
+ pkg_free(db_keys); |
|
680 |
+ } |
|
681 |
+ |
|
682 |
+ if (db_vals) { |
|
683 |
+ pkg_free(db_vals); |
|
684 |
+ } |
|
685 |
+} |
... | ... |
@@ -72,6 +72,8 @@ |
72 | 72 |
*/ |
73 | 73 |
#define FL_REQ_UPSTREAM (1<<29) |
74 | 74 |
|
75 |
+extern int acc_extra_size; |
|
76 |
+ |
|
75 | 77 |
void acc_log_init(void); |
76 | 78 |
int acc_log_request( struct sip_msg *req); |
77 | 79 |
|
... | ... |
@@ -88,4 +90,7 @@ int acc_get_db_handlers(void **vf, void **vh); |
88 | 90 |
int is_eng_acc_on(sip_msg_t *msg); |
89 | 91 |
int is_eng_mc_on(sip_msg_t *msg); |
90 | 92 |
|
93 |
+int acc_arrays_alloc(void); |
|
94 |
+void acc_arrays_free(void); |
|
95 |
+ |
|
91 | 96 |
#endif |
... | ... |
@@ -75,10 +75,10 @@ static char time_buffer[ TIME_BUFFER_LENGTH]; |
75 | 75 |
static const str empty_string = { "", 0}; |
76 | 76 |
|
77 | 77 |
// 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]; |
|
78 |
+static str *cdr_attrs = NULL; |
|
79 |
+static str *cdr_value_array = NULL; |
|
80 |
+static int *cdr_int_array = NULL; |
|
81 |
+static char *cdr_type_array = NULL; |
|
82 | 82 |
|
83 | 83 |
extern struct tm_binds tmb; |
84 | 84 |
extern str cdr_start_str; |
... | ... |
@@ -123,8 +123,8 @@ int cdr_core2strar( struct dlg_cell* dlg, |
123 | 123 |
} |
124 | 124 |
|
125 | 125 |
/* 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]; |
|
126 |
+static db_key_t *db_cdr_keys = NULL; |
|
127 |
+static db_val_t *db_cdr_vals = NULL; |
|
128 | 128 |
|
129 | 129 |
/* collect all crd data and write it to a syslog */ |
130 | 130 |
static int db_write_cdr( struct dlg_cell* dialog, |
... | ... |
@@ -997,3 +997,65 @@ void cdr_api_set_arrays(cdr_info_t *inf) |
997 | 997 |
inf->iarr = cdr_int_array; |
998 | 998 |
inf->tarr = cdr_type_array; |
999 | 999 |
} |
1000 |
+ |
|
1001 |
+int cdr_arrays_alloc(void) { |
|
1002 |
+ if ((cdr_attrs = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) == NULL) { |
|
1003 |
+ LM_ERR("failed to alloc cdr_attrs\n"); |
|
1004 |
+ return -1; |
|
1005 |
+ } |
|
1006 |
+ |
|
1007 |
+ if ((cdr_value_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) == NULL) { |
|
1008 |
+ LM_ERR("failed to alloc cdr_value_array\n"); |
|
1009 |
+ return -1; |
|
1010 |
+ } |
|
1011 |
+ |
|
1012 |
+ if ((cdr_int_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(int))) == NULL) { |
|
1013 |
+ LM_ERR("failed to alloc cdr_int_array\n"); |
|
1014 |
+ return -1; |
|
1015 |
+ } |
|
1016 |
+ |
|
1017 |
+ if ((cdr_type_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(char))) == NULL) { |
|
1018 |
+ LM_ERR("failed to alloc cdr_type_array\n"); |
|
1019 |
+ return -1; |
|
1020 |
+ } |
|
1021 |
+ |
|
1022 |
+ if ((db_cdr_keys = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_key_t))) == NULL) { |
|
1023 |
+ LM_ERR("failed to alloc db_cdr_keys\n"); |
|
1024 |
+ return -1; |
|
1025 |
+ } |
|
1026 |
+ |
|
1027 |
+ if ((db_cdr_vals = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_val_t))) == NULL) { |
|
1028 |
+ LM_ERR("failed to alloc db_cdr_vals\n"); |
|
1029 |
+ return -1; |
|
1030 |
+ } |
|
1031 |
+ |
|
1032 |
+ return 1; |
|
1033 |
+} |
|
1034 |
+ |
|
1035 |
+void cdr_arrays_free(void) { |
|
1036 |
+ if (cdr_attrs) { |
|
1037 |
+ pkg_free(cdr_attrs); |
|
1038 |
+ } |
|
1039 |
+ |
|
1040 |
+ if (cdr_value_array) { |
|
1041 |
+ pkg_free(cdr_value_array); |
|
1042 |
+ } |
|
1043 |
+ |
|
1044 |
+ if (cdr_int_array) { |
|
1045 |
+ pkg_free(cdr_int_array); |
|
1046 |
+ } |
|
1047 |
+ |
|
1048 |
+ if (cdr_type_array) { |
|
1049 |
+ pkg_free(cdr_type_array); |
|
1050 |
+ } |
|
1051 |
+ |
|
1052 |
+ if (db_cdr_keys) { |
|
1053 |
+ pkg_free(db_cdr_keys); |
|
1054 |
+ } |
|
1055 |
+ |
|
1056 |
+ if (db_cdr_vals) { |
|
1057 |
+ pkg_free(db_cdr_vals); |
|
1058 |
+ } |
|
1059 |
+ |
|
1060 |
+ return ; |
|
1061 |
+} |
... | ... |
@@ -42,6 +42,7 @@ |
42 | 42 |
#define MAX_CDR_CORE 3 |
43 | 43 |
#define MAX_CDR_EXTRA 64 |
44 | 44 |
|
45 |
+extern int cdr_extra_size; |
|
45 | 46 |
|
46 | 47 |
int set_cdr_extra( char* cdr_extra_value); |
47 | 48 |
int set_cdr_facility( char* cdr_facility); |
... | ... |
@@ -49,5 +50,7 @@ int init_cdr_generation( void); |
49 | 50 |
void destroy_cdr_generation( void); |
50 | 51 |
int cdr_core2strar( struct dlg_cell* dlg, str* values, int* unused, char* types); |
51 | 52 |
|
53 |
+int cdr_arrays_alloc(void); |
|
54 |
+void cdr_arrays_free(void); |
|
52 | 55 |
|
53 | 56 |
#endif |
... | ... |
@@ -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 |
+static char *int_buf = NULL; |
|
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 |
} |
... | ... |
@@ -366,3 +360,28 @@ int legs2strar( struct acc_extra *legs, struct sip_msg *rq, str *val_arr, |
366 | 360 |
exit: |
367 | 361 |
return 0; |
368 | 362 |
} |
363 |
+ |
|
364 |
+int acc_extra_arrays_alloc(void) { |
|
365 |
+ int acc_int_buf_size; |
|
366 |
+ |
|
367 |
+ if (acc_extra_size < MAX_ACC_LEG) { |
|
368 |
+ acc_int_buf_size = MAX_ACC_LEG; |
|
369 |
+ } else { |
|
370 |
+ acc_int_buf_size = acc_extra_size; |
|
371 |
+ } |
|
372 |
+ |
|
373 |
+ if ((int_buf = pkg_malloc((INT2STR_MAX_LEN * acc_int_buf_size) * sizeof(char))) == NULL) { |
|
374 |
+ LM_ERR("failed to alloc int_buf\n"); |
|
375 |
+ return -1; |
|
376 |
+ } |
|
377 |
+ |
|
378 |
+ return 1; |
|
379 |
+} |
|
380 |
+ |
|
381 |
+void acc_extra_arrays_free(void) { |
|
382 |
+ if (int_buf) { |
|
383 |
+ pkg_free(int_buf); |
|
384 |
+ } |
|
385 |
+ |
|
386 |
+ return ; |
|
387 |
+} |
... | ... |
@@ -37,6 +37,8 @@ |
37 | 37 |
#include "../../core/parser/msg_parser.h" |
38 | 38 |
#include "../dialog/dlg_load.h" |
39 | 39 |
|
40 |
+extern int acc_extra_size; |
|
41 |
+ |
|
40 | 42 |
void init_acc_extra(void); |
41 | 43 |
|
42 | 44 |
struct acc_extra *parse_acc_extra(char *extra); |
... | ... |
@@ -67,5 +69,9 @@ static inline void free_strar_mem( char* type_arr, str* alloc_arr, int dim_arr, |
67 | 69 |
} |
68 | 70 |
} |
69 | 71 |
} |
72 |
+ |
|
73 |
+int acc_extra_arrays_alloc(void); |
|
74 |
+void acc_extra_arrays_free(void); |
|
75 |
+ |
|
70 | 76 |
#endif |
71 | 77 |
|
... | ... |
@@ -95,6 +95,9 @@ 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_extra_size = MAX_ACC_EXTRA; |
|
99 |
+int cdr_extra_size = MAX_CDR_EXTRA; |
|
100 |
+ |
|
98 | 101 |
/*@}*/ |
99 | 102 |
|
100 | 103 |
/* ----- SYSLOG acc variables ----------- */ |
... | ... |
@@ -242,6 +245,8 @@ static param_export_t params[] = { |
242 | 245 |
{"time_format", PARAM_STRING, &acc_time_format }, |
243 | 246 |
{"clone_msg", PARAM_INT, &_acc_clone_msg }, |
244 | 247 |
{"cdr_on_failed", PARAM_INT, &_acc_cdr_on_failed }, |
248 |
+ {"acc_extra_size", PARAM_INT, &acc_extra_size}, |
|
249 |
+ {"cdr_extra_size", PARAM_INT, &cdr_extra_size}, |
|
245 | 250 |
{0,0,0} |
246 | 251 |
}; |
247 | 252 |
|
... | ... |
@@ -369,6 +374,19 @@ static int parse_failed_filter(char *s, unsigned short *failed_filter) |
369 | 374 |
|
370 | 375 |
static int mod_init( void ) |
371 | 376 |
{ |
377 |
+ /* arrays alloc */ |
|
378 |
+ if (acc_arrays_alloc() < 0) { |
|
379 |
+ return -1; |
|
380 |
+ } |
|
381 |
+ |
|
382 |
+ if (acc_extra_arrays_alloc() < 0) { |
|
383 |
+ return -1; |
|
384 |
+ } |
|
385 |
+ |
|
386 |
+ if (cdr_arrays_alloc() < 0) { |
|
387 |
+ return -1; |
|
388 |
+ } |
|
389 |
+ |
|
372 | 390 |
if (db_url.s) { |
373 | 391 |
if(db_url.len<=0) { |
374 | 392 |
db_url.s = NULL; |
... | ... |
@@ -600,6 +618,11 @@ static void destroy(void) |
600 | 618 |
acc_db_close(); |
601 | 619 |
if (db_extra) |
602 | 620 |
destroy_extras( db_extra); |
621 |
+ |
|
622 |
+ /* arrays free */ |
|
623 |
+ acc_arrays_free(); |
|
624 |
+ acc_extra_arrays_free(); |
|
625 |
+ cdr_arrays_free(); |
|
603 | 626 |
} |
604 | 627 |
|
605 | 628 |
|
... | ... |
@@ -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> |