From 245778265bb1019bbda1c8b7e60ba1daf6065787 Mon Sep 17 00:00:00 2001 From: Marco Capetta Date: Thu, 27 Aug 2020 16:57:13 +0200 Subject: [PATCH] TT#90650 Fix CDRs generations in case of blind transfers Due to the movement of call transfer handling from sems pbx to standard sems, in case of blind call transfer the BYE ACC is generated with call_id suffix '_pbx-1_xfer-1' instead of '_xfer-1'. To be more precise, currently we creates 2 ACCs for INVITEs: - one without any suffix - one with '_xfer-1" suffix and just one for the BYE: - with '_xfer-1' suffix Mediator is able to use the BYE to close both the INVITEs With the new implementation we creats 2 ACCs for INVITEs: - one without any suffix - one with '_pbx-1_xfer-1" suffix and just one for the BYE: - with '_pbx-1_xfer-1' suffix The sinlge BYE record is not used to close both the ACC INVITEs. Change-Id: Id7a68fab8d84ffe987084e925fecc1e051cbaccd --- medmysql.c | 8 +++++++- medredis.c | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/medmysql.c b/medmysql.c index a1a8d6a..46c0600 100644 --- a/medmysql.c +++ b/medmysql.c @@ -24,6 +24,11 @@ "(select distinct sip_code, sip_reason, method, callid, time, time_hires, " \ "src_leg, dst_leg, branch_id, id " \ "from acc where method = 'BYE' and callid in ('%s', '%s"XFERSUFFIX"') " \ + "order by length(callid) asc, time_hires asc) " \ + "union all " \ + "(select distinct sip_code, sip_reason, method, callid, time, time_hires, " \ + "src_leg, dst_leg, branch_id, id " \ + "from acc where method = 'BYE' and callid in ('%s', '%s"PBXSUFFIX""XFERSUFFIX"') " \ "order by length(callid) asc, time_hires asc)" #define MED_LOAD_PEER_QUERY "select h.ip, h.host, g.peering_contract_id, h.id " \ @@ -679,7 +684,7 @@ int medmysql_fetch_records(med_callid_t *callid, { MYSQL_RES *res; MYSQL_ROW row; - char query[strlen(MED_FETCH_QUERY) + sizeof(callid->value) * 5 + 1]; + char query[strlen(MED_FETCH_QUERY) + sizeof(callid->value) * 7 + 1]; size_t entry_size; uint64_t i = 0; int ret = 0; @@ -694,6 +699,7 @@ int medmysql_fetch_records(med_callid_t *callid, len = snprintf(query, sizeof(query), MED_FETCH_QUERY, esc_callid, esc_callid, esc_callid, + esc_callid, esc_callid, esc_callid, esc_callid); assert(len > 0 && (size_t)len < sizeof(query)); /* truncated - internal bug */ diff --git a/medredis.c b/medredis.c index cef65e6..a5a0ec7 100644 --- a/medredis.c +++ b/medredis.c @@ -649,8 +649,9 @@ int medredis_fetch_records(med_callid_t *callid, 1. fetch from acc:cid::$cid 2. fetch from acc:cid::$cidPBXSUFFIX 3. fetch from acc:cid::$cidXFERSUFFIX - 4. combine all in list sorted by time_hires - 5. skip if INVITE/200 and no BYE + 4. fetch from acc:cid::$cidPBXSUFFIXXFERSUFFIX + 5. combine all in list sorted by time_hires + 6. skip if INVITE/200 and no BYE */ char buffer[512]; @@ -660,7 +661,7 @@ int medredis_fetch_records(med_callid_t *callid, redisReply *reply = NULL; - char *cids[3]; + char *cids[4]; GList *records; GList *keys; @@ -691,13 +692,19 @@ int medredis_fetch_records(med_callid_t *callid, L_ERROR("Failed to allocate memory for callid with xfersuffix\n"); goto err; } + snprintf(buffer, sizeof(buffer), "%s%s%s", callid->value, PBXSUFFIX, XFERSUFFIX); + cids[3] = strdup(buffer); + if (!cids[3]) { + L_ERROR("Failed to allocate memory for callid with pbxsuffix and xfersuffix\n"); + goto err; + } *count = 0; *entries = NULL; L_DEBUG("Fetching records from redis\n"); - for (i = 0; i < 3; ++i) { + for (i = 0; i < 4; ++i) { char *cid = cids[i]; snprintf(buffer, sizeof(buffer), "acc:cid::%s", cid); cid_set_argv[1] = buffer; @@ -709,7 +716,7 @@ int medredis_fetch_records(med_callid_t *callid, cids[i] = NULL; } - for (i = 0; i < 3; ++i) { + for (i = 0; i < 4; ++i) { if (medredis_get_reply(&reply) != 0) { L_ERROR("Failed to get redis reply for command to fetch entries for cid '%s'\n", callid->value); goto err; @@ -804,7 +811,7 @@ err: if (reply) freeReplyObject(reply); *count = (uint64_t) -1; - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 4; ++i) { if (cids[i]) free(cids[i]); }