Skip to content

Commit

Permalink
Merge pull request #2891 from smititelu/increase_defines
Browse files Browse the repository at this point in the history
acc: increase extra and cdr variables
  • Loading branch information
miconda committed Nov 3, 2021
2 parents 579853e + d30d7e1 commit b1e0d41
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 22 deletions.
71 changes: 65 additions & 6 deletions src/modules/acc/acc.c
Expand Up @@ -61,9 +61,9 @@ extern struct acc_extra *db_extra;
/* arrays used to collect the values before being
* pushed to the storage backend (whatever used)
* (3 = datetime + max 2 from time_mode) */
static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
static str *val_arr = NULL;
static int *int_arr = NULL;
static char *type_arr = NULL;

#define ACC_TIME_FORMAT_SIZE 128
static char acc_time_format_buf[ACC_TIME_FORMAT_SIZE];
Expand Down Expand Up @@ -160,7 +160,7 @@ int core2strar(struct sip_msg *req, str *c_vals, int *i_vals, char *t_vals)
/********************************************
* LOG ACCOUNTING
********************************************/
static str log_attrs[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG];
static str *log_attrs = NULL;

#define SET_LOG_ATTR(_n,_atr) \
do { \
Expand Down Expand Up @@ -309,8 +309,8 @@ int acc_is_db_ready(void)

/* caution: keys need to be aligned to core format
* (3 = datetime + max 2 from time_mode) */
static db_key_t db_keys[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
static db_val_t db_vals[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
static db_key_t *db_keys = NULL;
static db_val_t *db_vals = NULL;


int acc_get_db_handlers(void **vf, void **vh) {
Expand Down Expand Up @@ -624,3 +624,62 @@ void acc_api_set_arrays(acc_info_t *inf)
inf->leg_info = leg_info;
}

int acc_arrays_alloc(void) {
if ((val_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) {
LM_ERR("failed to alloc val_arr\n");
return -1;
}

if ((int_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(int))) == NULL) {
LM_ERR("failed to alloc int_arr\n");
return -1;
}

if ((type_arr = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(char))) == NULL) {
LM_ERR("failed to alloc type_arr\n");
return -1;
}

if ((log_attrs = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(str))) == NULL) {
LM_ERR("failed to alloc log_attrs\n");
return -1;
}

if ((db_keys = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_key_t))) == NULL) {
LM_ERR("failed to alloc db_keys\n");
return -1;
}

if ((db_vals = pkg_malloc((ACC_CORE_LEN + acc_extra_size + MAX_ACC_LEG + 3) * sizeof(db_val_t))) == NULL) {
LM_ERR("failed to alloc db_vals\n");
return -1;
}

return 1;
}

void acc_arrays_free(void) {
if (val_arr) {
pkg_free(val_arr);
}

if (int_arr) {
pkg_free(int_arr);
}

if (type_arr) {
pkg_free(type_arr);
}

if (log_attrs) {
pkg_free(log_attrs);
}

if (db_keys) {
pkg_free(db_keys);
}

if (db_vals) {
pkg_free(db_vals);
}
}
5 changes: 5 additions & 0 deletions src/modules/acc/acc.h
Expand Up @@ -72,6 +72,8 @@
*/
#define FL_REQ_UPSTREAM (1<<29)

extern int acc_extra_size;

void acc_log_init(void);
int acc_log_request( struct sip_msg *req);

Expand All @@ -88,4 +90,7 @@ int acc_get_db_handlers(void **vf, void **vh);
int is_eng_acc_on(sip_msg_t *msg);
int is_eng_mc_on(sip_msg_t *msg);

int acc_arrays_alloc(void);
void acc_arrays_free(void);

#endif
74 changes: 68 additions & 6 deletions src/modules/acc/acc_cdr.c
Expand Up @@ -75,10 +75,10 @@ static char time_buffer[ TIME_BUFFER_LENGTH];
static const str empty_string = { "", 0};

// buffers which are used to collect the crd data for writing
static str cdr_attrs[ MAX_CDR_CORE + MAX_CDR_EXTRA];
static str cdr_value_array[ MAX_CDR_CORE + MAX_CDR_EXTRA];
static int cdr_int_array[ MAX_CDR_CORE + MAX_CDR_EXTRA];
static char cdr_type_array[ MAX_CDR_CORE + MAX_CDR_EXTRA];
static str *cdr_attrs = NULL;
static str *cdr_value_array = NULL;
static int *cdr_int_array = NULL;
static char *cdr_type_array = NULL;

extern struct tm_binds tmb;
extern str cdr_start_str;
Expand Down Expand Up @@ -123,8 +123,8 @@ int cdr_core2strar( struct dlg_cell* dlg,
}

/* caution: keys need to be aligned to core format */
static db_key_t db_cdr_keys[ MAX_CDR_CORE + MAX_CDR_EXTRA];
static db_val_t db_cdr_vals[ MAX_CDR_CORE + MAX_CDR_EXTRA];
static db_key_t *db_cdr_keys = NULL;
static db_val_t *db_cdr_vals = NULL;

/* collect all crd data and write it to a syslog */
static int db_write_cdr( struct dlg_cell* dialog,
Expand Down Expand Up @@ -997,3 +997,65 @@ void cdr_api_set_arrays(cdr_info_t *inf)
inf->iarr = cdr_int_array;
inf->tarr = cdr_type_array;
}

int cdr_arrays_alloc(void) {
if ((cdr_attrs = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) == NULL) {
LM_ERR("failed to alloc cdr_attrs\n");
return -1;
}

if ((cdr_value_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(str))) == NULL) {
LM_ERR("failed to alloc cdr_value_array\n");
return -1;
}

if ((cdr_int_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(int))) == NULL) {
LM_ERR("failed to alloc cdr_int_array\n");
return -1;
}

if ((cdr_type_array = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(char))) == NULL) {
LM_ERR("failed to alloc cdr_type_array\n");
return -1;
}

if ((db_cdr_keys = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_key_t))) == NULL) {
LM_ERR("failed to alloc db_cdr_keys\n");
return -1;
}

if ((db_cdr_vals = pkg_malloc((MAX_CDR_CORE + cdr_extra_size) * sizeof(db_val_t))) == NULL) {
LM_ERR("failed to alloc db_cdr_vals\n");
return -1;
}

return 1;
}

void cdr_arrays_free(void) {
if (cdr_attrs) {
pkg_free(cdr_attrs);
}

if (cdr_value_array) {
pkg_free(cdr_value_array);
}

if (cdr_int_array) {
pkg_free(cdr_int_array);
}

if (cdr_type_array) {
pkg_free(cdr_type_array);
}

if (db_cdr_keys) {
pkg_free(db_cdr_keys);
}

if (db_cdr_vals) {
pkg_free(db_cdr_vals);
}

return ;
}
3 changes: 3 additions & 0 deletions src/modules/acc/acc_cdr.h
Expand Up @@ -42,12 +42,15 @@
#define MAX_CDR_CORE 3
#define MAX_CDR_EXTRA 64

extern int cdr_extra_size;

int set_cdr_extra( char* cdr_extra_value);
int set_cdr_facility( char* cdr_facility);
int init_cdr_generation( void);
void destroy_cdr_generation( void);
int cdr_core2strar( struct dlg_cell* dlg, str* values, int* unused, char* types);

int cdr_arrays_alloc(void);
void cdr_arrays_free(void);

#endif
39 changes: 29 additions & 10 deletions src/modules/acc/acc_extra.c
Expand Up @@ -43,14 +43,8 @@
#define EQUAL '='
#define SEPARATOR ';'


#if MAX_ACC_EXTRA<MAX_ACC_LEG
#define MAX_ACC_INT_BUF MAX_ACC_LEG
#else
#define MAX_ACC_INT_BUF MAX_ACC_EXTRA
#endif
/* here we copy the strings returned by int2str (which uses a static buffer) */
static char int_buf[INT2STR_MAX_LEN*MAX_ACC_INT_BUF];
static char *int_buf = NULL;

struct acc_extra *parse_acc_leg(char *extra_str)
{
Expand Down Expand Up @@ -109,7 +103,7 @@ struct acc_extra *parse_acc_extra(char *extra_str)
while (*s && isspace((int)*s)) s++;
if (*s==0)
goto parse_error;
if (n==MAX_ACC_EXTRA) {
if (n==acc_extra_size) {
LM_ERR("too many extras -> please increase the internal buffer\n");
goto error;
}
Expand Down Expand Up @@ -224,7 +218,7 @@ int extra2strar(struct acc_extra *extra, struct sip_msg *rq, str *val_arr,
}

/* check for overflow */
if (n==MAX_ACC_EXTRA) {
if (n==acc_extra_size) {
LM_WARN("array to short -> omitting extras for accounting\n");
goto done;
}
Expand Down Expand Up @@ -283,7 +277,7 @@ int extra2strar_dlg_only(struct acc_extra *extra, struct dlg_cell* dlg, str *val
while (extra) {

/* check for overflow */
if (n==MAX_ACC_EXTRA) {
if (n==acc_extra_size) {
LM_WARN("array to short -> omitting extras for accounting\n");
goto done;
}
Expand Down Expand Up @@ -366,3 +360,28 @@ int legs2strar( struct acc_extra *legs, struct sip_msg *rq, str *val_arr,
exit:
return 0;
}

int acc_extra_arrays_alloc(void) {
int acc_int_buf_size;

if (acc_extra_size < MAX_ACC_LEG) {
acc_int_buf_size = MAX_ACC_LEG;
} else {
acc_int_buf_size = acc_extra_size;
}

if ((int_buf = pkg_malloc((INT2STR_MAX_LEN * acc_int_buf_size) * sizeof(char))) == NULL) {
LM_ERR("failed to alloc int_buf\n");
return -1;
}

return 1;
}

void acc_extra_arrays_free(void) {
if (int_buf) {
pkg_free(int_buf);
}

return ;
}
6 changes: 6 additions & 0 deletions src/modules/acc/acc_extra.h
Expand Up @@ -37,6 +37,8 @@
#include "../../core/parser/msg_parser.h"
#include "../dialog/dlg_load.h"

extern int acc_extra_size;

void init_acc_extra(void);

struct acc_extra *parse_acc_extra(char *extra);
Expand Down Expand Up @@ -67,5 +69,9 @@ static inline void free_strar_mem( char* type_arr, str* alloc_arr, int dim_arr,
}
}
}

int acc_extra_arrays_alloc(void);
void acc_extra_arrays_free(void);

#endif

23 changes: 23 additions & 0 deletions src/modules/acc/acc_mod.c
Expand Up @@ -95,6 +95,9 @@ str acc_time_exten = str_init("time_exten");
int _acc_clone_msg = 1;
int _acc_cdr_on_failed = 1;

int acc_extra_size = MAX_ACC_EXTRA;
int cdr_extra_size = MAX_CDR_EXTRA;

/*@}*/

/* ----- SYSLOG acc variables ----------- */
Expand Down Expand Up @@ -242,6 +245,8 @@ static param_export_t params[] = {
{"time_format", PARAM_STRING, &acc_time_format },
{"clone_msg", PARAM_INT, &_acc_clone_msg },
{"cdr_on_failed", PARAM_INT, &_acc_cdr_on_failed },
{"acc_extra_size", PARAM_INT, &acc_extra_size},
{"cdr_extra_size", PARAM_INT, &cdr_extra_size},
{0,0,0}
};

Expand Down Expand Up @@ -369,6 +374,19 @@ static int parse_failed_filter(char *s, unsigned short *failed_filter)

static int mod_init( void )
{
/* arrays alloc */
if (acc_arrays_alloc() < 0) {
return -1;
}

if (acc_extra_arrays_alloc() < 0) {
return -1;
}

if (cdr_arrays_alloc() < 0) {
return -1;
}

if (db_url.s) {
if(db_url.len<=0) {
db_url.s = NULL;
Expand Down Expand Up @@ -600,6 +618,11 @@ static void destroy(void)
acc_db_close();
if (db_extra)
destroy_extras( db_extra);

/* arrays free */
acc_arrays_free();
acc_extra_arrays_free();
cdr_arrays_free();
}


Expand Down

0 comments on commit b1e0d41

Please sign in to comment.