From 31d28a3babd352956149c9fb36be7606282566f3 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 30 Nov 2015 10:23:59 -0500 Subject: [PATCH] MT#16783 support via-branch matching in `delete` messages Change-Id: I8383742ec11983d82ab4e2e92f1e20cbda798d71 --- daemon/call.c | 60 +++++++++++++++++++++++----------------- daemon/call_interfaces.c | 3 +- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 4e35a0b69..0e830a694 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2416,13 +2416,14 @@ static int monologue_destroy(struct call_monologue *ml) { __monologue_destroy(ml); if (!g_hash_table_size(c->tags)) { - ilog(LOG_INFO, "Call branch '"STR_FORMAT"' deleted, no more branches remaining", - STR_FMT(&ml->tag)); + ilog(LOG_INFO, "Call branch '"STR_FORMAT"' (via-branch '"STR_FORMAT"') " + "deleted, no more branches remaining", + STR_FMT(&ml->tag), STR_FMT0(&ml->viabranch)); return 1; /* destroy call */ } - ilog(LOG_INFO, "Call branch "STR_FORMAT" deleted", - STR_FMT(&ml->tag)); + ilog(LOG_INFO, "Call branch '"STR_FORMAT"' (via-branch '"STR_FORMAT"') deleted", + STR_FMT(&ml->tag), STR_FMT0(&ml->viabranch)); return 0; } @@ -2575,46 +2576,55 @@ int call_delete_branch(struct callmaster *m, const str *callid, const str *branc ml->term_reason = REGULAR; } - if (!fromtag || !fromtag->s || !fromtag->len) + if (!fromtag || !fromtag->len) goto del_all; - match_tag = (totag && totag->s && totag->len) ? totag : fromtag; + if ((!totag || !totag->len) && branch && branch->len) { + // try a via-branch match + ml = g_hash_table_lookup(c->viabranches, branch); + if (ml) + goto do_delete; + } + + match_tag = (totag && totag->len) ? totag : fromtag; ml = g_hash_table_lookup(c->tags, match_tag); if (!ml) { + if (branch && branch->len) { + // also try a via-branch match here + ml = g_hash_table_lookup(c->viabranches, branch); + if (ml) + goto do_delete; + } + + // last resort: try the from-tag if we tried the to-tag before and see + // if the associated dialogue has an empty tag (unknown) + if (match_tag == totag) { + ml = g_hash_table_lookup(c->tags, fromtag); + if (ml && ml->active_dialogue && ml->active_dialogue->tag.len == 0) + goto do_delete; + } + ilog(LOG_INFO, "Tag '"STR_FORMAT"' in delete message not found, ignoring", STR_FMT(match_tag)); goto err; } +do_delete: if (output) ng_call_stats(c, fromtag, totag, output, NULL); -/* - if (branch && branch->len) { - if (!g_hash_table_remove(c->branches, branch)) { - ilog(LOG_INFO, LOG_PREFIX_CI "Branch to delete doesn't exist", STR_FMT(&c->callid), STR_FMT(branch)); - goto err; - } - - ilog(LOG_INFO, LOG_PREFIX_CI "Branch deleted", LOG_PARAMS_CI(c)); - if (g_hash_table_size(c->branches)) - goto success_unlock; - else - DBG("no branches left, deleting full call"); - } -*/ - if (delete_delay > 0) { - ilog(LOG_INFO, "Scheduling deletion of call branch '"STR_FORMAT"' in %d seconds", - STR_FMT(&ml->tag), delete_delay); + ilog(LOG_INFO, "Scheduling deletion of call branch '"STR_FORMAT"' " + "(via-branch '"STR_FORMAT"') in %d seconds", + STR_FMT(&ml->tag), STR_FMT0(branch), delete_delay); ml->deleted = poller_now + delete_delay; if (!c->ml_deleted || c->ml_deleted > ml->deleted) c->ml_deleted = ml->deleted; } else { - ilog(LOG_INFO, "Deleting call branch '"STR_FORMAT"'", - STR_FMT(&ml->tag)); + ilog(LOG_INFO, "Deleting call branch '"STR_FORMAT"' (via-branch '"STR_FORMAT"')", + STR_FMT(&ml->tag), STR_FMT0(branch)); if (monologue_destroy(ml)) goto del_all; } diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 7824ae718..6991e5539 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -776,8 +776,7 @@ const char *call_delete_ng(bencode_item_t *input, struct callmaster *m, bencode_ if (!bencode_dictionary_get_str(input, "call-id", &callid)) return "No call-id in message"; - if (!bencode_dictionary_get_str(input, "from-tag", &fromtag)) - return "No from-tag in message"; + bencode_dictionary_get_str(input, "from-tag", &fromtag); bencode_dictionary_get_str(input, "to-tag", &totag); bencode_dictionary_get_str(input, "via-branch", &viabranch);