Skip to content

Commit

Permalink
ua,menu: move max calls check to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Dec 4, 2024
1 parent 4c0bee6 commit 9afe39a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
35 changes: 24 additions & 11 deletions modules/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}

Expand Down
10 changes: 0 additions & 10 deletions src/ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9afe39a

Please sign in to comment.