From a0f63f3f52a49dabcdb7cbc0a13f8b33f4114ef7 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 6 Sep 2018 07:50:04 -0400 Subject: [PATCH] TT#44000 support trashing of acc entries that are too old Change-Id: I9e402dba80fac82f0aeca0b1d78a079510430b83 --- cdr.c | 1 + config.c | 9 ++++++++- config.h | 1 + records.c | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cdr.c b/cdr.c index 6bb72db..ccfc546 100644 --- a/cdr.c +++ b/cdr.c @@ -158,6 +158,7 @@ int cdr_process_records(med_entry_t *records, uint64_t count, uint64_t *ext_coun L_DEBUG("No BYE message for callid '%s' found, skipping...", callid); */ + trash = 1; } } else diff --git a/config.c b/config.c index aea60ad..42610bf 100644 --- a/config.c +++ b/config.c @@ -42,6 +42,7 @@ med_stats_period_t config_stats_period = MEDIATOR_DEFAULT_STATSPERIOD; int config_maintenance = 0; int strict_leg_tokens = 0; +int config_max_acc_age = 0; med_loglevel_t config_loglevel = MEDIATOR_DEFAULT_LOGLEVEL; @@ -79,9 +80,10 @@ enum config_option { OPT_STATS_PERIOD = 'x', OPT_MAINTENANCE = 'm', OPT_LEG_TOKENS = 's', + OPT_MAX_ACC_AGE = 'M', }; -static const char options[] = "?a:c:e:D:i:dlL:h:u:p:b:o:H:U:P:B:O:S:t:T:r:R:A:N:Z:z:W:w:X:x:ms"; +static const char options[] = "?a:c:e:D:i:dlL:h:u:p:b:o:H:U:P:B:O:S:t:T:r:R:A:N:Z:z:W:w:X:x:msM:"; struct option long_options[] = { { "configfile", required_argument, NULL, OPT_CONFIGFILE }, @@ -117,6 +119,7 @@ struct option long_options[] = { { "stats-period", required_argument, NULL, OPT_STATS_PERIOD }, { "maintenance", no_argument, NULL, OPT_MAINTENANCE }, { "leg-tokens", no_argument, NULL, OPT_LEG_TOKENS }, + { "max-acc-age", required_argument, NULL, OPT_MAX_ACC_AGE }, { NULL, 0, NULL, 0 }, }; @@ -160,6 +163,7 @@ static void config_help(const char *self, int rc) " -r, --redis-db DB\tThe redis usrloc db number (default = '%d').\n" \ " -m, --maintenance\tMaintenance mode (do nothing, just sleep).\n" \ " -s, --leg-tokens\tStrict acc fields (move to trash otherwise).\n" \ +" -M, --max-acc-age\tMaximum age of acc records before trashing them (default = disabled).\n" \ " -?, --help\t\tDisplays this message.\n", MEDIATOR_VERSION, self, MEDIATOR_DEFAULT_CONFIG_FILE, MEDIATOR_DEFAULT_PIDPATH, MEDIATOR_DEFAULT_LOGLEVEL, @@ -296,6 +300,9 @@ static void config_set_option(enum config_option option, const char *value) case OPT_LEG_TOKENS: strict_leg_tokens = 1; break; + case OPT_MAX_ACC_AGE: + config_max_acc_age = atoi(value); + break; } } diff --git a/config.h b/config.h index 37b0b67..2d5b745 100644 --- a/config.h +++ b/config.h @@ -43,6 +43,7 @@ extern uint8_t config_dumpcdr; extern int config_maintenance; extern int strict_leg_tokens; +extern int config_max_acc_age; extern med_loglevel_t config_loglevel; diff --git a/records.c b/records.c index 1a24ae5..a76dc1f 100644 --- a/records.c +++ b/records.c @@ -1,5 +1,6 @@ #include "records.h" #include "config.h" +#include #define comp_ret(a_var, b_var) \ do { \ @@ -31,6 +32,13 @@ int records_complete(med_entry_t *records, uint64_t count) uint8_t has_bye = 0; uint8_t has_inv_200 = 0; + // if our records are old enough, we always consider them complete + if (count && config_max_acc_age) + { + if (time(NULL) - records[0].unix_timestamp > config_max_acc_age) + return 1; + } + for (uint64_t i = 0; i < count; i++) { med_entry_t *s = &records[i];