Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mc: move dnd from core to module multicast #55

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 71 additions & 22 deletions modules/multicast/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ struct mccfg {
char iface[128];
};

static struct mccfg mccfg = {
0,
1,
125,
""
struct mc {
bool dnd;
struct mccfg cfg;
};

static struct mc mc = {
false,
{
0,
1,
125,
"",
}
};

/**
* Decode IP-address <IP>:<PORT>
Expand Down Expand Up @@ -117,7 +124,18 @@ static int check_rtp_pt(struct aucodec *ac)
*/
uint8_t multicast_callprio(void)
{
return mccfg.callprio;
return mc.cfg.callprio;
}


/**
* Set the do not disturb flag
*
* @param v true if incoming calls should be rejected
*/
void multicast_set_dnd(bool v)
{
mc.dnd = v;
}


Expand All @@ -128,7 +146,7 @@ uint8_t multicast_callprio(void)
*/
uint8_t multicast_ttl(void)
{
return mccfg.ttl;
return mc.cfg.ttl;
}


Expand All @@ -139,7 +157,7 @@ uint8_t multicast_ttl(void)
*/
uint32_t multicast_fade_time(void)
{
return mccfg.tfade;
return mc.cfg.tfade;
}


Expand Down Expand Up @@ -317,12 +335,12 @@ static int cmd_mcreg(struct re_printf *pf, void *arg)
}

#ifdef HAVE_GETIFADDRS
if (str_isset(mccfg.iface)) {
if (str_isset(mc.cfg.iface)) {
unsigned int if_index;
if_index = if_nametoindex(mccfg.iface);
if_index = if_nametoindex(mc.cfg.iface);
if (!if_index) {
warning("multicast: could not find interface %s\n",
&mccfg.iface);
&mc.cfg.iface);
if (sa_af(&addr) == AF_INET6) {
err = EINVAL;
goto out;
Expand Down Expand Up @@ -658,20 +676,21 @@ static int module_read_config(void)
int err = 0, prio = 1;
struct sa laddr;

(void)conf_get_u32(conf_cur(), "multicast_call_prio", &mccfg.callprio);
if (mccfg.callprio > 255)
mccfg.callprio = 255;
(void)conf_get_u32(conf_cur(), "multicast_call_prio",
&mc.cfg.callprio);
if (mc.cfg.callprio > 255)
mc.cfg.callprio = 255;

(void)conf_get_u32(conf_cur(), "multicast_ttl", &mccfg.ttl);
if (mccfg.ttl > 255)
mccfg.ttl = 255;
(void)conf_get_u32(conf_cur(), "multicast_ttl", &mc.cfg.ttl);
if (mc.cfg.ttl > 255)
mc.cfg.ttl = 255;

(void)conf_get_u32(conf_cur(), "multicast_fade_time", &mccfg.tfade);
if (mccfg.tfade > 2000)
mccfg.tfade = 2000;
(void)conf_get_u32(conf_cur(), "multicast_fade_time", &mc.cfg.tfade);
if (mc.cfg.tfade > 2000)
mc.cfg.tfade = 2000;

(void)conf_get_str(conf_cur(), "multicast_iface", mccfg.iface,
sizeof(mccfg.iface));
(void)conf_get_str(conf_cur(), "multicast_iface", mc.cfg.iface,
sizeof(mc.cfg.iface));

sa_init(&laddr, AF_INET);
err = conf_apply(conf_cur(), "multicast_listener",
Expand Down Expand Up @@ -705,12 +724,41 @@ static const struct cmd cmdv[] = {
};


static void event_handler(enum ua_event ev, struct bevent *event, void *arg)
{
(void)arg;
const struct sip_msg *msg = bevent_get_msg(event);

switch (ev) {

case UA_EVENT_SIPSESS_CONN:
if (mc.dnd) {
(void)sip_treply(NULL, uag_sip(), msg, 480,
"Temporarily Unavailable");
info("menu: incoming call from %r <%r> rejected: "
"480 Temporarily Unavailable\n",
&msg->from.dname, &msg->from.auri);
bevent_stop(event);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO for baresip repo: use bevent_stop() also in baresip

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break;
}

break;

default:
break;
}
}


static int module_init(void)
{
int err = 0;

err = module_read_config();
err |= cmd_register(baresip_commands(), cmdv, RE_ARRAY_SIZE(cmdv));
err |= bevent_register(event_handler, NULL);
if (err)
return err;

err |= mcsource_init();
err |= mcplayer_init();
Expand All @@ -727,6 +775,7 @@ static int module_close(void)
mcsender_stopall();
mcreceiver_unregall();

bevent_unregister(event_handler);
cmd_unregister(baresip_commands(), cmdv);

mcsource_terminate();
Expand Down
1 change: 1 addition & 0 deletions modules/multicast/multicast.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum {
uint8_t multicast_callprio(void);
uint8_t multicast_ttl(void);
uint32_t multicast_fade_time(void);
void multicast_set_dnd(bool v);


/* Sender */
Expand Down
4 changes: 2 additions & 2 deletions modules/multicast/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void resume_uag_state(void)
}

if (h > multicast_callprio()) {
uag_set_dnd(false);
multicast_set_dnd(false);
uag_set_nodial(false);
uag_hold_resume(NULL);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ static int prio_handling(struct mcreceiver *mcreceiver, uint32_t ssrc)
struct le *leua;
struct ua *ua;

uag_set_dnd(true);
multicast_set_dnd(true);
uag_set_nodial(true);

for (leua = list_head(uag_list()); leua; leua = leua->next) {
Expand Down
Loading