diff --git a/cdr.c b/cdr.c index 4232c0f..19431c6 100644 --- a/cdr.c +++ b/cdr.c @@ -1638,3 +1638,29 @@ void cdr_parse_entry(med_entry_t *e) e->method = MED_UNRECOGNIZED; } } + +// try strip one suffix and return whether it was done +static inline int cdr_truncate_suffix(char *callid, size_t *len, const char *suffix) { + size_t slen = strlen(suffix); + if (*len < slen) + return 0; + if (memcmp(&callid[*len - slen], suffix, slen) != 0) + return 0; + callid[*len - slen] = '\0'; + *len -= slen; + return 1; +} + +// strip (potentially chained) suffices +void cdr_truncate_call_id_suffix(char *callid) +{ + size_t len = strlen(callid); + + while (1) { + if (cdr_truncate_suffix(callid, &len, PBXSUFFIX)) + continue; + if (cdr_truncate_suffix(callid, &len, XFERSUFFIX)) + continue; + break; + }; +} diff --git a/cdr.h b/cdr.h index 595580e..64a9168 100644 --- a/cdr.h +++ b/cdr.h @@ -63,6 +63,7 @@ typedef struct { int cdr_process_records(GQueue *records, uint64_t *cdr_count, struct medmysql_batches *, int do_intermediate); void cdr_parse_entry(med_entry_t *); +void cdr_truncate_call_id_suffix(char *); #endif /* _CDR_H */ diff --git a/medredis.c b/medredis.c index 085c6d3..9f7b360 100644 --- a/medredis.c +++ b/medredis.c @@ -584,11 +584,7 @@ gboolean medredis_fetch_callids(GQueue *output) { *tmp = '\0'; } - // strip (potentially chained) suffices - if ((tmp = strstr(entry->str, PBXSUFFIX)) || - (tmp = strstr(entry->str, XFERSUFFIX))) { - *tmp = '\0'; - } + cdr_truncate_call_id_suffix(cid); if (g_hash_table_insert(cid_table, cid, cid)) { g_queue_push_tail(output, cid);