From 9afe39a400f2d8d9fc66964983729b46e8529e42 Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Wed, 4 Dec 2024 12:47:59 +0100 Subject: [PATCH] ua,menu: move max calls check to menu --- modules/menu/menu.c | 35 ++++++++++++++++++++++++----------- src/ua.c | 10 ---------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/modules/menu/menu.c b/modules/menu/menu.c index 63c3770f0..71afac967 100644 --- a/modules/menu/menu.c +++ b/modules/menu/menu.c @@ -656,6 +656,20 @@ static void process_module_event(struct call *call, const char *prm) } +static void menu_reject_call(const struct sip_msg *msg, struct bevent *event, + uint16_t scode, const char *reason) +{ + (void)sip_treply(NULL, uag_sip(), msg, scode, reason); + + info("menu: incoming call from %r <%r> rejected: " + "%u %s\n", + &msg->from.dname, &msg->from.auri, scode, reason); + bevent_sip_msg_emit(UA_EVENT_MODULE, msg, + "menu,rejected,%u %s", scode, reason); + bevent_stop(event); +} + + static void event_handler(enum ua_event ev, struct bevent *event, void *arg) { struct call *call2 = NULL; @@ -670,6 +684,7 @@ static void event_handler(enum ua_event ev, struct bevent *event, void *arg) struct ua *ua = bevent_get_ua(event); const struct sip_msg *msg = bevent_get_msg(event); struct account *acc = ua_account(bevent_get_ua(event)); + struct config *config = conf_config(); int err; (void)arg; @@ -687,18 +702,16 @@ static void event_handler(enum ua_event ev, struct bevent *event, void *arg) case UA_EVENT_SIPSESS_CONN: - if (menu.dnd) { - const uint16_t scode = 480; - const char *reason = "Temporarily Unavailable"; - - (void)sip_treply(NULL, uag_sip(), msg, scode, reason); + if (config->call.max_calls && + uag_call_count() + 1 > config->call.max_calls) { + menu_reject_call(msg, event, + 486, "Max Calls"); + break; + } - info("menu: incoming call from %r <%r> rejected: " - "%u %s\n", - &msg->from.dname, &msg->from.auri, scode, reason); - bevent_sip_msg_emit(UA_EVENT_MODULE, msg, - "menu,rejected,%u %s", scode, reason); - bevent_stop(event); + if (menu.dnd) { + menu_reject_call(msg, event, + 480, "Temporarily Unavailable"); break; } diff --git a/src/ua.c b/src/ua.c index f94f311b7..325a75342 100644 --- a/src/ua.c +++ b/src/ua.c @@ -722,16 +722,6 @@ void sipsess_conn_handler(const struct sip_msg *msg, void *arg) return; } - /* handle multiple calls */ - if (config->call.max_calls && - uag_call_count() + 1 > config->call.max_calls) { - - info("ua: rejected call from %r (maximum %d calls)\n", - &msg->from.auri, config->call.max_calls); - (void)sip_treply(NULL, uag_sip(), msg, 486, "Max Calls"); - return; - } - /* Handle Require: header, check for any required extensions */ hdr = sip_msg_hdr_apply(msg, true, SIP_HDR_REQUIRE, require_handler, ua);