From fe744fb3ef074f5b59b106d3dff335fad8a93fc8 Mon Sep 17 00:00:00 2001 From: Alessio Garzi Date: Wed, 14 Jun 2023 08:52:07 +0200 Subject: [PATCH] MT#57281 New acc field "acc_dont_clean_suffix" If acc is generated with flag acc_dont_clean_suffix dont strip suffix since the originally generated call was generated with _pbx-1 suffix and removing it would result in leftovers on redis db. Change-Id: I0ac2cba7fa625470e6801180e63118b2c3a6daa0 (cherry picked from commit 6f156a0aec0724a29cab68bda15955569ee748cd) --- medredis.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/medredis.c b/medredis.c index f60d27f..be0018a 100644 --- a/medredis.c +++ b/medredis.c @@ -537,7 +537,8 @@ gboolean medredis_fetch_callids(GQueue *output) { unsigned int cursor = 0; size_t i = 0; redisReply *reply = NULL; - char *cmd = "SSCAN acc:meth::INVITE %u COUNT 1000"; + static const char cmd[] = "SSCAN acc:meth::INVITE %u COUNT 1000"; + static const char cmd_get_dont_clean_suffix[] = "HGET %s dont_clean_suffix"; GHashTable *cid_table; char buffer[256]; char *tmp; @@ -579,7 +580,7 @@ gboolean medredis_fetch_callids(GQueue *output) { break; } - for (i= 0; i < reply->element[1]->elements; ++i) { + for (i = 0; i < reply->element[1]->elements; ++i) { char *cid; redisReply *entry = reply->element[1]->element[i]; if (!entry) { @@ -605,7 +606,20 @@ gboolean medredis_fetch_callids(GQueue *output) { *tmp = '\0'; } - cdr_truncate_call_id_suffix(cid); + int truncate_callid = 1; + snprintf(buffer, sizeof(buffer), cmd_get_dont_clean_suffix, entry->str); + redisReply *reply_get_dont_clean_suffix = medredis_command(buffer); + medredis_check_reply(buffer, reply_get_dont_clean_suffix, err); + if (reply_get_dont_clean_suffix->type == REDIS_REPLY_STRING && reply_get_dont_clean_suffix->str) { + if (!strcmp(reply_get_dont_clean_suffix->str,"1")) { + truncate_callid = 0; + L_WARNING("Preventing callid to be truncated since the original CALLID coming from endpoint has already more _pbx-1 suffixes\n"); + } + } + medredis_free_reply(&reply_get_dont_clean_suffix); + + if (truncate_callid) + cdr_truncate_call_id_suffix(cid); if (g_hash_table_insert(cid_table, cid, cid)) { g_queue_push_tail(output, cid);